Upstream tarball 20080603
[amule.git] / src / ServerListCtrl.cpp
bloba913fcc85207207ccc3002f30ba0bb81ba6de94e
1 //
2 // This file is part of the aMule Project.
3 //
4 // Copyright (c) 2003-2008 aMule Team ( admin@amule.org / http://www.amule.org )
5 // Copyright (c) 2002 Merkur ( devs@emule-project.net / http://www.emule-project.net )
6 //
7 // Any parts of this program derived from the xMule, lMule or eMule project,
8 // or contributed by third-party developers are copyrighted by their
9 // respective authors.
11 // This program is free software; you can redistribute it and/or modify
12 // it under the terms of the GNU General Public License as published by
13 // the Free Software Foundation; either version 2 of the License, or
14 // (at your option) any later version.
16 // This program is distributed in the hope that it will be useful,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 // GNU General Public License for more details.
20 //
21 // You should have received a copy of the GNU General Public License
22 // along with this program; if not, write to the Free Software
23 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 #include "ServerListCtrl.h" // Interface declarations
28 #include <common/MenuIDs.h>
30 #include <wx/menu.h>
31 #include <wx/stattext.h>
32 #include <wx/msgdlg.h>
33 #include <wx/settings.h>
35 #include "amule.h" // Needed for theApp
36 #include "DownloadQueue.h" // Needed for CDownloadQueue
37 #ifdef ENABLE_IP2COUNTRY
38 #include "IP2Country.h" // Needed for IP2Country
39 #include "amuleDlg.h" // Needed for IP2Country
40 #endif
41 #include "ServerList.h" // Needed for CServerList
42 #include "ServerConnect.h" // Needed for CServerConnect
43 #include "Server.h" // Needed for CServer and SRV_PR_*
44 #include "Logger.h"
45 #include <common/Format.h> // Needed for CFormat
46 #include <common/TextFile.h> // Needed for CTextFile
49 #define SYSCOLOR(x) (wxSystemSettings::GetColour(x))
52 BEGIN_EVENT_TABLE(CServerListCtrl,CMuleListCtrl)
53 EVT_LIST_ITEM_RIGHT_CLICK( -1, CServerListCtrl::OnItemRightClicked)
54 EVT_LIST_ITEM_ACTIVATED( -1, CServerListCtrl::OnItemActivated )
56 EVT_MENU( MP_PRIOLOW, CServerListCtrl::OnPriorityChange )
57 EVT_MENU( MP_PRIONORMAL, CServerListCtrl::OnPriorityChange )
58 EVT_MENU( MP_PRIOHIGH, CServerListCtrl::OnPriorityChange )
60 EVT_MENU( MP_ADDTOSTATIC, CServerListCtrl::OnStaticChange )
61 EVT_MENU( MP_REMOVEFROMSTATIC, CServerListCtrl::OnStaticChange )
63 EVT_MENU( MP_CONNECTTO, CServerListCtrl::OnConnectToServer )
65 EVT_MENU( MP_REMOVE, CServerListCtrl::OnRemoveServers )
66 EVT_MENU( MP_REMOVEALL, CServerListCtrl::OnRemoveServers )
68 EVT_MENU( MP_GETED2KLINK, CServerListCtrl::OnGetED2kURL )
70 EVT_CHAR( CServerListCtrl::OnKeyPressed )
71 END_EVENT_TABLE()
75 CServerListCtrl::CServerListCtrl( wxWindow *parent, wxWindowID winid, const wxPoint& pos, const wxSize& size,
76 long style, const wxValidator& validator, const wxString& name )
77 : CMuleListCtrl( parent, winid, pos, size, style, validator, name )
79 // Setting the sorter function.
80 SetSortFunc( SortProc );
82 // Set the table-name (for loading and saving preferences).
83 SetTableName( wxT("Server") );
85 m_connected = 0;
87 InsertColumn( COLUMN_SERVER_NAME, _("Server Name"), wxLIST_FORMAT_LEFT, 150);
88 InsertColumn( COLUMN_SERVER_ADDR, _("Address"), wxLIST_FORMAT_LEFT, 140);
89 InsertColumn( COLUMN_SERVER_PORT, _("Port"), wxLIST_FORMAT_LEFT, 25);
90 InsertColumn( COLUMN_SERVER_DESC, _("Description"), wxLIST_FORMAT_LEFT, 150);
91 InsertColumn( COLUMN_SERVER_PING, _("Ping"), wxLIST_FORMAT_LEFT, 25);
92 InsertColumn( COLUMN_SERVER_USERS, _("Users"), wxLIST_FORMAT_LEFT, 40);
93 InsertColumn( COLUMN_SERVER_FILES, _("Files"), wxLIST_FORMAT_LEFT, 45);
94 InsertColumn( COLUMN_SERVER_PRIO, _("Priority"), wxLIST_FORMAT_LEFT, 60);
95 InsertColumn( COLUMN_SERVER_FAILS, _("Failed"), wxLIST_FORMAT_LEFT, 40);
96 InsertColumn( COLUMN_SERVER_STATIC, _("Static"), wxLIST_FORMAT_LEFT, 40);
97 InsertColumn( COLUMN_SERVER_VERSION, _("Version"), wxLIST_FORMAT_LEFT, 80);
98 #ifdef __DEBUG__
99 InsertColumn( COLUMN_SERVER_TCPFLAGS, wxT("TCP Flags"), wxLIST_FORMAT_LEFT, 80);
100 InsertColumn( COLUMN_SERVER_UDPFLAGS, wxT("UDP Flags"), wxLIST_FORMAT_LEFT, 80);
101 #endif
104 LoadSettings();
108 CServerListCtrl::~CServerListCtrl()
114 void CServerListCtrl::AddServer( CServer* toadd )
116 // RefreshServer will add the server.
117 // This also means that we have simple duplicity checking. ;)
118 RefreshServer( toadd );
120 ShowServerCount();
124 void CServerListCtrl::RemoveServer(CServer* server)
126 long result = FindItem(-1, reinterpret_cast<wxUIntPtr>(server));
127 if ( result != -1 ) {
128 DeleteItem(result);
129 ShowServerCount();
134 void CServerListCtrl::RemoveAllServers(int state)
136 int pos = GetNextItem( -1, wxLIST_NEXT_ALL, state);
137 bool connected = theApp->IsConnectedED2K() ||
138 theApp->serverconnect->IsConnecting();
140 while ( pos != -1 ) {
141 CServer* server = (CServer*)GetItemData(pos);
143 if (reinterpret_cast<wxUIntPtr>(server) == m_connected && connected) {
144 wxMessageBox(_("You are connected to a server you are trying to delete. Please disconnect first. The server was NOT deleted."), _("Info"), wxOK, this);
145 ++pos;
146 } else if (server->IsStaticMember()) {
147 const wxString name = (!server->GetListName() ? wxString(_("(Unknown name)")) : server->GetListName());
149 if (wxMessageBox(CFormat(_("Are you sure you want to delete the static server %s")) % name, _("Cancel"), wxICON_QUESTION | wxYES_NO, this) == wxYES) {
150 SetStaticServer(server, false);
151 DeleteItem( pos );
152 theApp->serverlist->RemoveServer( server );
153 } else {
154 ++pos;
156 } else {
157 DeleteItem( pos );
158 theApp->serverlist->RemoveServer( server );
161 pos = GetNextItem(pos - 1, wxLIST_NEXT_ALL, state);
164 ShowServerCount();
168 void CServerListCtrl::RefreshServer( CServer* server )
170 // Cant really refresh a NULL server
171 if (!server) {
172 return;
175 wxUIntPtr ptr = reinterpret_cast<wxUIntPtr>(server);
176 long itemnr = FindItem( -1, ptr );
177 if ( itemnr == -1 ) {
178 // We are not at the sure that the server isn't in the list, so we can re-add
179 itemnr = InsertItem( GetInsertPos( ptr ), server->GetListName() );
180 SetItemPtrData( itemnr, ptr );
182 wxListItem item;
183 item.SetId( itemnr );
184 item.SetBackgroundColour(SYSCOLOR(wxSYS_COLOUR_LISTBOX));
185 SetItem( item );
188 wxString serverName;
189 #ifdef ENABLE_IP2COUNTRY
190 // Get the country name
191 const CountryData& countrydata = theApp->amuledlg->m_IP2Country->GetCountryData(server->GetFullIP());
192 serverName << countrydata.Name;
193 serverName << wxT(" - ");
194 #endif // ENABLE_IP2COUNTRY
195 serverName << server->GetListName();
196 SetItem(itemnr, COLUMN_SERVER_NAME, serverName);
197 SetItem(itemnr, COLUMN_SERVER_ADDR, server->GetAddress());
198 if (server->GetAuxPortsList().IsEmpty()) {
199 SetItem( itemnr, COLUMN_SERVER_PORT,
200 wxString::Format(wxT("%u"), server->GetPort()));
201 } else {
202 SetItem( itemnr, COLUMN_SERVER_PORT,
203 wxString::Format(wxT("%u ("),
204 server->GetPort()) + server->GetAuxPortsList() + wxT(")") );
206 SetItem( itemnr, COLUMN_SERVER_DESC, server->GetDescription() );
208 if ( server->GetPing() ) {
209 SetItem( itemnr, COLUMN_SERVER_PING,
210 CastSecondsToHM(server->GetPing()/1000, server->GetPing() % 1000 ) );
211 } else {
212 SetItem( itemnr, COLUMN_SERVER_PING, wxEmptyString );
215 if ( server->GetUsers() ) {
216 SetItem( itemnr, COLUMN_SERVER_USERS,
217 wxString::Format( wxT("%u"), server->GetUsers() ) );
218 } else {
219 SetItem( itemnr, COLUMN_SERVER_USERS, wxEmptyString );
222 if ( server->GetFiles() ) {
223 SetItem( itemnr, COLUMN_SERVER_FILES,
224 wxString::Format( wxT("%u"), server->GetFiles() ) );
225 } else {
226 SetItem( itemnr, COLUMN_SERVER_FILES, wxEmptyString );
229 switch ( server->GetPreferences() ) {
230 case SRV_PR_LOW: SetItem(itemnr, COLUMN_SERVER_PRIO, _("Low")); break;
231 case SRV_PR_NORMAL: SetItem(itemnr, COLUMN_SERVER_PRIO, _("Normal")); break;
232 case SRV_PR_HIGH: SetItem(itemnr, COLUMN_SERVER_PRIO, _("High") ); break;
233 default: SetItem(itemnr, COLUMN_SERVER_PRIO, wxT("---")); // this should never happen
236 SetItem( itemnr, COLUMN_SERVER_FAILS, wxString::Format( wxT("%u"),server->GetFailedCount() ) );
237 SetItem( itemnr, COLUMN_SERVER_STATIC, ( server->IsStaticMember() ? _("Yes") : _("No") ) );
238 SetItem( itemnr, COLUMN_SERVER_VERSION, server->GetVersion() );
240 #ifdef __DEBUG__
241 wxString flags;
242 /* TCP */
243 if (server->GetTCPFlags() & SRV_TCPFLG_COMPRESSION) {
244 flags += wxT("c");
246 if (server->GetTCPFlags() & SRV_TCPFLG_NEWTAGS) {
247 flags += wxT("n");
249 if (server->GetTCPFlags() & SRV_TCPFLG_UNICODE) {
250 flags += wxT("u");
252 if (server->GetTCPFlags() & SRV_TCPFLG_RELATEDSEARCH) {
253 flags += wxT("r");
255 if (server->GetTCPFlags() & SRV_TCPFLG_TYPETAGINTEGER) {
256 flags += wxT("t");
258 if (server->GetTCPFlags() & SRV_TCPFLG_LARGEFILES) {
259 flags += wxT("l");
261 if (server->GetTCPFlags() & SRV_TCPFLG_TCPOBFUSCATION) {
262 flags += wxT("o");
265 SetItem( itemnr, COLUMN_SERVER_TCPFLAGS, flags );
267 /* UDP */
268 flags = wxEmptyString;
269 if (server->GetUDPFlags() & SRV_UDPFLG_EXT_GETSOURCES) {
270 flags += wxT("g");
272 if (server->GetUDPFlags() & SRV_UDPFLG_EXT_GETFILES) {
273 flags += wxT("f");
275 if (server->GetUDPFlags() & SRV_UDPFLG_NEWTAGS) {
276 flags += wxT("n");
278 if (server->GetUDPFlags() & SRV_UDPFLG_UNICODE) {
279 flags += wxT("u");
281 if (server->GetUDPFlags() & SRV_UDPFLG_EXT_GETSOURCES2) {
282 flags += wxT("G");
284 if (server->GetUDPFlags() & SRV_UDPFLG_LARGEFILES) {
285 flags += wxT("l");
287 if (server->GetUDPFlags() & SRV_UDPFLG_UDPOBFUSCATION) {
288 flags += wxT("o");
290 if (server->GetUDPFlags() & SRV_UDPFLG_TCPOBFUSCATION) {
291 flags += wxT("O");
293 SetItem( itemnr, COLUMN_SERVER_UDPFLAGS, flags );
295 #endif
297 // Deletions of items causes rather large ammount of flicker, so to
298 // avoid this, we resort the list to ensure correct ordering.
299 if (!IsItemSorted(itemnr)) {
300 SortList();
305 void CServerListCtrl::HighlightServer( const CServer* server, bool highlight )
307 // Unset the old highlighted server if we are going to set a new one
308 if ( m_connected && highlight ) {
309 // A recursive call to do the real work.
310 HighlightServer( (CServer*)m_connected, false );
312 m_connected = 0;
315 long itemnr = FindItem( -1, reinterpret_cast<wxUIntPtr>(server) );
316 if ( itemnr > -1 ) {
317 wxListItem item;
318 item.SetId( itemnr );
320 if ( GetItem( item ) ) {
321 wxFont font = GetFont();
323 if ( highlight ) {
324 font.SetWeight( wxBOLD );
326 m_connected = reinterpret_cast<wxUIntPtr>(server);
329 item.SetFont( font );
331 SetItem( item );
336 //#warning Kry TODO: Dude, this gotta be moved to core
337 bool CServerListCtrl::SetStaticServer( CServer* server, bool isStatic )
339 server->SetIsStaticMember( isStatic );
340 RefreshServer( server );
342 wxString filename = theApp->ConfigDir + wxT("staticservers.dat");
344 CTextFile file;
345 if (!file.Open(filename, CTextFile::write)) {
346 AddLogLineM( false, CFormat( _("Failed to open '%s'") ) % filename );
347 return false;
350 for (int i = 0; i < GetItemCount(); ++i) {
351 server = reinterpret_cast<CServer*>(GetItemData(i));
353 if (server->IsStaticMember()) {
354 file.WriteLine(CFormat(wxT("%s:%u,%u,%s"))
355 % server->GetAddress() % server->GetPort()
356 % server->GetPreferences() % server->GetListName());
360 return true;
364 void CServerListCtrl::ShowServerCount()
366 wxStaticText* label = CastByName( wxT("serverListLabel"), GetParent(), wxStaticText );
368 if ( label ) {
369 label->SetLabel( wxString::Format( _("Servers (%i)"), GetItemCount() ) );
370 label->GetParent()->Layout();
375 void CServerListCtrl::OnItemActivated( wxListEvent& event )
377 // Unselect all items but the activated one
378 long item = GetNextItem( -1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED );
379 while ( item > -1 ) {
380 SetItemState( item, 0, wxLIST_STATE_SELECTED);
382 item = GetNextItem( item, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED );
385 SetItemState( event.GetIndex(), wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED );
387 wxCommandEvent nulEvt;
388 OnConnectToServer( nulEvt );
392 void CServerListCtrl::OnItemRightClicked(wxListEvent& event)
394 // Check if clicked item is selected. If not, unselect all and select it.
395 long index = CheckSelection(event);
397 bool enable_reconnect = false;
398 bool enable_static_on = false;
399 bool enable_static_off = false;
401 // Gather information on the selected items
402 while ( index > -1 ) {
403 CServer* server = (CServer*)GetItemData( index );
405 // The current server is selected, so we might display the reconnect option
406 if ( reinterpret_cast<wxUIntPtr>(server) == m_connected )
407 enable_reconnect = true;
409 // We want to know which options should be enabled, either one or both
410 enable_static_on |= !server->IsStaticMember();
411 enable_static_off |= server->IsStaticMember();
413 index = GetNextItem( index, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED );
417 wxMenu* serverMenu = new wxMenu(_("Server"));
418 wxMenu* serverPrioMenu = new wxMenu();
419 serverPrioMenu->Append( MP_PRIOLOW, _("Low") );
420 serverPrioMenu->Append( MP_PRIONORMAL, _("Normal") );
421 serverPrioMenu->Append( MP_PRIOHIGH, _("High") );
422 serverMenu->Append( MP_CONNECTTO, _("Connect to server") );
423 serverMenu->Append( 12345, _("Priority"), serverPrioMenu );
425 serverMenu->AppendSeparator();
427 if (GetSelectedItemCount() == 1) {
428 serverMenu->Append( MP_ADDTOSTATIC, _("Mark server as static") );
429 serverMenu->Append( MP_REMOVEFROMSTATIC, _("Mark server as non-static") );
430 } else {
431 serverMenu->Append( MP_ADDTOSTATIC, _("Mark servers as static") );
432 serverMenu->Append( MP_REMOVEFROMSTATIC, _("Mark servers as non-static") );
435 serverMenu->AppendSeparator();
437 if (GetSelectedItemCount() == 1) {
438 serverMenu->Append( MP_REMOVE, _("Remove server") );
439 } else {
440 serverMenu->Append( MP_REMOVE, _("Remove servers") );
442 serverMenu->Append( MP_REMOVEALL, _("Remove all servers") );
444 serverMenu->AppendSeparator();
446 if (GetSelectedItemCount() == 1) {
447 serverMenu->Append( MP_GETED2KLINK, _("Copy ED2k link to clipboard") );
448 } else {
449 serverMenu->Append( MP_GETED2KLINK, _("Copy ED2k links to clipboard") );
452 serverMenu->Enable( MP_REMOVEFROMSTATIC, enable_static_off );
453 serverMenu->Enable( MP_ADDTOSTATIC, enable_static_on );
455 if ( GetSelectedItemCount() == 1 ) {
456 if ( enable_reconnect )
457 serverMenu->SetLabel( MP_CONNECTTO, _("Reconnect to server") );
458 } else {
459 serverMenu->Enable( MP_CONNECTTO, false );
463 PopupMenu( serverMenu, event.GetPoint() );
467 void CServerListCtrl::OnPriorityChange( wxCommandEvent& event )
469 int priority = 0;
471 switch ( event.GetId() ) {
472 case MP_PRIOLOW: priority = SRV_PR_LOW; break;
473 case MP_PRIONORMAL: priority = SRV_PR_NORMAL; break;
474 case MP_PRIOHIGH: priority = SRV_PR_HIGH; break;
476 default:
477 return;
481 ItemDataList items = GetSelectedItems();
483 for ( unsigned int i = 0; i < items.size(); ++i ) {
484 CServer* server = (CServer*)items[ i ];
486 server->SetPreference( priority );
487 RefreshServer( server );
492 void CServerListCtrl::OnStaticChange( wxCommandEvent& event )
494 bool isStatic = ( event.GetId() == MP_ADDTOSTATIC );
496 ItemDataList items = GetSelectedItems();
498 for ( unsigned int i = 0; i < items.size(); ++i ) {
499 CServer* server = (CServer*)items[ i ];
501 // Only update items that have the wrong setting
502 if ( server->IsStaticMember() != isStatic ) {
503 if ( !SetStaticServer( server, isStatic ) ) {
504 wxASSERT( false );
506 return;
509 server->SetIsStaticMember( isStatic );
510 RefreshServer( server );
516 void CServerListCtrl::OnConnectToServer( wxCommandEvent& WXUNUSED(event) )
518 int item = GetNextItem( -1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED );
520 if ( item > -1 ) {
521 if ( theApp->IsConnectedED2K() ) {
522 theApp->serverconnect->Disconnect();
525 theApp->serverconnect->ConnectToServer( (CServer*)GetItemData( item ) );
530 void CServerListCtrl::OnGetED2kURL( wxCommandEvent& WXUNUSED(event) )
532 int pos = GetNextItem( -1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED );
534 wxString URL;
536 while ( pos != -1 ) {
537 CServer* server = (CServer*)GetItemData(pos);
539 URL += wxT("ed2k://|server|") + server->GetFullIP() + wxString::Format(wxT("|%d|"), server->GetPort()) + wxT("/\n");
541 pos = GetNextItem( pos, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED );
544 URL.RemoveLast();
546 theApp->CopyTextToClipboard( URL );
550 void CServerListCtrl::OnRemoveServers( wxCommandEvent& event )
552 if ( event.GetId() == MP_REMOVEALL ) {
553 if ( GetItemCount() ) {
554 wxString question = _("Are you sure that you wish to delete all servers?");
556 if ( wxMessageBox( question, _("Cancel"), wxICON_QUESTION | wxYES_NO, this) == wxYES ) {
557 if ( theApp->serverconnect->IsConnecting() ) {
558 theApp->downloadqueue->StopUDPRequests();
559 theApp->serverconnect->StopConnectionTry();
560 theApp->serverconnect->Disconnect();
563 RemoveAllServers(wxLIST_STATE_DONTCARE);
566 } else if ( event.GetId() == MP_REMOVE ) {
567 if ( GetSelectedItemCount() ) {
568 wxString question;
569 if (GetSelectedItemCount() == 1) {
570 question = _("Are you sure that you wish to delete the selected server?");
571 } else {
572 question = _("Are you sure that you wish to delete the selected servers?");
575 if ( wxMessageBox( question, _("Cancel"), wxICON_QUESTION | wxYES_NO, this) == wxYES ) {
576 RemoveAllServers(wxLIST_STATE_SELECTED);
583 void CServerListCtrl::OnKeyPressed( wxKeyEvent& event )
585 // Check if delete was pressed
586 if ((event.GetKeyCode() == WXK_DELETE) || (event.GetKeyCode() == WXK_NUMPAD_DELETE)) {
587 wxCommandEvent evt;
588 evt.SetId( MP_REMOVE );
589 OnRemoveServers( evt );
590 } else {
591 event.Skip();
596 int CServerListCtrl::SortProc(wxUIntPtr item1, wxUIntPtr item2, long sortData)
598 CServer* server1 = (CServer*)item1;
599 CServer* server2 = (CServer*)item2;
601 int mode = (sortData & CMuleListCtrl::SORT_DES) ? -1 : 1;
603 switch (sortData & CMuleListCtrl::COLUMN_MASK) {
604 // Sort by server-name
605 case COLUMN_SERVER_NAME:
606 return mode * server1->GetListName().CmpNoCase(server2->GetListName());
608 // Sort by address
609 case COLUMN_SERVER_ADDR:
611 if ( server1->HasDynIP() && server2->HasDynIP()) {
612 return mode * server1->GetDynIP().CmpNoCase( server2->GetDynIP() );
613 } else if (server1->HasDynIP()) {
614 return mode * -1;
615 } else if (server2->HasDynIP()) {
616 return mode * 1;
617 } else {
618 uint32 a = wxUINT32_SWAP_ALWAYS(server1->GetIP());
619 uint32 b = wxUINT32_SWAP_ALWAYS(server2->GetIP());
620 return mode * CmpAny(a, b);
623 // Sort by port
624 case COLUMN_SERVER_PORT: return mode * CmpAny( server1->GetPort(), server2->GetPort() );
625 // Sort by description
626 case COLUMN_SERVER_DESC: return mode * server1->GetDescription().CmpNoCase( server2->GetDescription() );
627 // Sort by Ping
628 // The -1 ensures that a value of zero (no ping known) is sorted last.
629 case COLUMN_SERVER_PING: return mode * CmpAny( server1->GetPing() - 1, server2->GetPing() -1 );
630 // Sort by user-count
631 case COLUMN_SERVER_USERS: return mode * CmpAny( server1->GetUsers(), server2->GetUsers() );
632 // Sort by file-count
633 case COLUMN_SERVER_FILES: return mode * CmpAny( server1->GetFiles(), server2->GetFiles() );
634 // Sort by priority
635 case COLUMN_SERVER_PRIO:
637 uint32 srv_pr1 = server1->GetPreferences();
638 uint32 srv_pr2 = server2->GetPreferences();
639 switch ( srv_pr1 ) {
640 case SRV_PR_HIGH: srv_pr1 = SRV_PR_MAX; break;
641 case SRV_PR_NORMAL: srv_pr1 = SRV_PR_MID; break;
642 case SRV_PR_LOW: srv_pr1 = SRV_PR_MIN; break;
643 default: return 0;
645 switch ( srv_pr2 ) {
646 case SRV_PR_HIGH: srv_pr2 = SRV_PR_MAX; break;
647 case SRV_PR_NORMAL: srv_pr2 = SRV_PR_MID; break;
648 case SRV_PR_LOW: srv_pr2 = SRV_PR_MIN; break;
649 default: return 0;
651 return mode * CmpAny( srv_pr1, srv_pr2 );
653 // Sort by failure-count
654 case COLUMN_SERVER_FAILS: return mode * CmpAny( server1->GetFailedCount(), server2->GetFailedCount() );
655 // Sort by static servers
656 case COLUMN_SERVER_STATIC:
658 return mode * CmpAny( server2->IsStaticMember(), server1->IsStaticMember() );
660 // Sort by version
661 case COLUMN_SERVER_VERSION: return mode * FuzzyStrCmp(server1->GetVersion(), server2->GetVersion());
663 default:
664 return 0;
667 // File_checked_for_headers