Bug 58187

Summary: Bizarre sort order in Terminal Sessions Menu
Product: [Applications] konsole Reporter: Justin Sheckler <justin>
Component: generalAssignee: Konsole Developer <konsole-devel>
Status: RESOLVED FIXED    
Severity: normal    
Priority: NOR    
Version: unspecified   
Target Milestone: ---   
Platform: Slackware   
OS: Linux   
Latest Commit: Version Fixed In:

Description Justin Sheckler 2003-05-06 21:59:52 UTC
Version:            (using KDE KDE 3.1.1)
Installed from:    Slackware Packages
OS:          Linux

The sort order for Kicker's "Terminal Session Menu" doesn't match Konsole's own Sessions menu.  In Konsole, all of my user sessions are nicely sorted, but in the Kicker button they're randomized.  For instance, where I work we have servers named things like "ts5" and "p4."  When I click on the Kicker sessions button, I see a list like this:

p1
Root Console
ts10
e1
ts4
p3
[etc...]

instead of:

p1
p2
p3
p4
ts1
ts2
ts3
[etc...]

This makes it really hard to find what I'm looking for.
Comment 1 Waldo Bastian 2003-05-07 23:11:53 UTC
Subject: kdebase/kicker/menuext/konsole

CVS commit by waba: 

CCMAIL: 58187-done@bugs.kde.org
Bring kicker's konsole menu in sync with the one in konsole. (BR58187)


  M +37 -7     konsole_mnu.cpp   1.5


--- kdebase/kicker/menuext/konsole/konsole_mnu.cpp  #1.4:1.5
@@ -63,13 +63,42 @@ KonsoleMenu::~KonsoleMenu()
 }
 
+static void insertItemSorted(KPopupMenu *menu, const QIconSet &iconSet, const QString &txt, int id)
+{
+  const int defaultId = 1; // The id of the 'new' item.
+  int index = menu->indexOf(defaultId);
+  int count = menu->count();
+  if (index >= 0)
+  {
+     index++; // Skip separator
+     while(true)
+     {
+        index++;
+        if (index >= count)
+        {
+           index = -1; // Insert at end
+           break;
+        }
+        if (menu->text(menu->idAt(index)) > txt)
+           break; // Insert before this item
+     }
+  }
+  menu->insertItem(iconSet, txt, id, index);
+}
+
+
 void KonsoleMenu::initialize()
 {
     QStringList list = KGlobal::dirs()->findAllResources("data", "konsole/*.desktop", false, true);
 
-    int id = 0;
+    QString defaultShell = locate("data", "konsole/shell.desktop");
+    list.prepend(defaultShell);
+
+    int id = 1;
 
     sessionList.clear();
     for (QStringList::ConstIterator it = list.begin(); it != list.end(); ++it)
     {
+        if ((*it == defaultShell) && (id != 1))
+           continue;
         KSimpleConfig conf(*it, true /* read only */);
         conf.setDesktopGroup();
@@ -82,9 +111,5 @@ void KonsoleMenu::initialize()
         }
 
-        int pos = exec.find(' ');
-        if (pos > 0) {
-             exec = exec.left(pos);
-        }
-
+        exec = KRun::binaryName(exec, false);
         QString pexec = KGlobal::dirs()->findExe(exec);
         if (text.isEmpty() || conf.readEntry("Type") != "KonsoleApplication"
@@ -93,10 +118,14 @@ void KonsoleMenu::initialize()
             continue;
         }
-        insertItem(SmallIconSet(conf.readEntry("Icon", "konsole")), text, id++);
+        insertItemSorted(this, SmallIconSet(conf.readEntry("Icon", "openterm")), text, id++);
         QFileInfo fi(*it);
         sessionList.append(fi.baseName());
+        
+        if (id == 2)
+           insertSeparator();
     }
     bookmarkHandlerSession = new KonsoleBookmarkHandler( this, false );
     m_bookmarksSession = bookmarkHandlerSession->menu();
+    insertSeparator();
     insertItem(SmallIconSet("keditbookmarks"),
                         i18n("New Session at Bookmark"), m_bookmarksSession);
@@ -138,4 +167,5 @@ void KonsoleMenu::initialize()
 void KonsoleMenu::slotExec(int id)
 {
+    id--;
     if (id >= 0)
     {