Bug 61152 - sort by user doesn't work in the right way
Summary: sort by user doesn't work in the right way
Status: RESOLVED FIXED
Alias: None
Product: atlantik
Classification: Applications
Component: general (show other bugs)
Version: unspecified
Platform: unspecified Linux
: NOR normal (vote)
Target Milestone: ---
Assignee: Rob Kaper
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-07-12 22:39 UTC by cerebro84
Modified: 2003-07-13 01:16 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description cerebro84 2003-07-12 22:39:31 UTC
Version:            (using KDE 3.1.9)
Compiler:          gcc version 3.2.2 (Mandrake Linux 9.1 3.2.2-3mdk)
OS:          Linux (i686) release 2.4.21-0.13mdkcustom

Clicking on the user field doesn't sort by number of users, but alphabetically: so after 1, there's 10 and not 2.

How to reproduce: just download server list and click on the user field
expected behavior: order 0,0,0,0,0,0,0,1,1,1,2,3,4,11 and not 0,0,0,0,0,0,0,1,1,1,11,2,3,4
Comment 1 Rob Kaper 2003-07-13 01:16:50 UTC
Subject: KDE_3_1_BRANCH: kdegames/atlantik

CVS commit by kaper: 

backport to kde 3.1 branch, fix #61152: sort by user doesn't work in the
right way

CCMAIL: 61152-done@bugs.kde.org


  M +1 -0      ChangeLog   1.121.4.19
  M +19 -0     client/monopigator.cpp   1.9.8.5
  M +8 -0      client/monopigator.h   1.8.8.5
  M +2 -3      client/selectserver_widget.cpp   1.18.6.5


--- kdegames/atlantik/ChangeLog  #1.121.4.18:1.121.4.19
@@ -12,4 +12,5 @@
 - make use of trade revisions (monopd >= 0.8.2 recommended)
 - don't tell game has started when it has not
+- sort user column in server list by number, not alphabetically
 
 0.5.2

--- kdegames/atlantik/client/monopigator.cpp  #1.9.8.4:1.9.8.5
@@ -103,2 +103,21 @@ void Monopigator::processData(const QByt
         }
 }
+
+MonopigatorEntry::MonopigatorEntry(QListView *parent, QString host, QString version, QString users, QString port) : QListViewItem(parent, host, version, users, port)
+{
+}
+
+int MonopigatorEntry::compare(QListViewItem *i, int col, bool ascending) const
+{
+        if (col == 2)
+        {
+                int myVal = text(col).toInt(), iVal = i->text(col).toInt();
+                if (myVal == iVal)
+                        return 0;
+                else if (myVal > iVal)
+                        return 1;
+                else
+                        return -1;
+        }
+        return key( col, ascending ).compare( i->key( col, ascending) );
+}

--- kdegames/atlantik/client/monopigator.h  #1.8.8.4:1.8.8.5
@@ -20,4 +20,5 @@
 #include <qobject.h>
 #include <qbuffer.h>
+#include <qlistview.h>
 #include <qtimer.h>
 
@@ -50,4 +51,11 @@ private:
         QTimer *m_timer;
         KIO::Job *m_job;
+};
+
+class MonopigatorEntry : public QListViewItem
+{
+public:
+        MonopigatorEntry(QListView *parent, QString host, QString version, QString users, QString port);
+        int compare(QListViewItem *i, int col, bool ascending) const;
 };
 

--- kdegames/atlantik/client/selectserver_widget.cpp  #1.18.6.4:1.18.6.5
@@ -115,5 +115,5 @@ void SelectServer::checkLocalServer()
 void SelectServer::slotMonopigatorAdd(QString host, QString port, QString version, int users)
 {
-        QListViewItem *item = new QListViewItem(m_serverList, host, version, (users == -1) ? i18n("unknown") : QString::number(users), port);
+        MonopigatorEntry *item = new MonopigatorEntry(m_serverList, host, version, (users == -1) ? i18n("unknown") : QString::number(users), port);
         item->setPixmap(0, BarIcon("atlantik", KIcon::SizeSmall));
         validateConnectButton();
@@ -124,7 +124,6 @@ void SelectServer::slotLocalConnected()
         m_localServerAvailable = true;
 
-        QListViewItem *item = new QListViewItem(m_serverList, "localhost", i18n("unknown"), i18n("unknown"), QString::number(1234));
+        MonopigatorEntry *item = new MonopigatorEntry(m_serverList, "localhost", i18n("unknown"), i18n("unknown"), QString::number(1234));
         item->setPixmap(0, BarIcon("atlantik", KIcon::SizeSmall));
-
         validateConnectButton();
 }