From 9146504fdd78c192f4287aeb0fe9e6587b2edf2b Mon Sep 17 00:00:00 2001
From: Michele Calgaro <michele.calgaro@yahoo.it>
Date: Tue, 14 Apr 2020 11:52:10 +0900
Subject: kicker's kate session menu extension: add support for new R14.1.0
 style Kate's session and make sure they are ordered accordingly to the order
 in Kate.

Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
---
 kicker/menuext/kate/katesessionmenu.cpp | 36 +++++++++++++++++++++++++++------
 1 file changed, 30 insertions(+), 6 deletions(-)

(limited to 'kicker/menuext/kate')

diff --git a/kicker/menuext/kate/katesessionmenu.cpp b/kicker/menuext/kate/katesessionmenu.cpp
index 854f4ce31..711d0968d 100644
--- a/kicker/menuext/kate/katesessionmenu.cpp
+++ b/kicker/menuext/kate/katesessionmenu.cpp
@@ -76,15 +76,39 @@ void KateSessionMenu::initialize()
 
   insertSeparator();
 
-  TQStringList list = TDEGlobal::dirs()->findAllResources( "data", "kate/sessions/*.katesession", false, true);
-  for (TQStringList::ConstIterator it = list.begin(); it != list.end(); ++it)
+  TQString configFile = locateLocal("data", "kate/sessions") + "/sessions.list";
+  if (TDEGlobal::dirs()->exists(configFile))
   {
-    KSimpleConfig config( *it, true );
-    config.setGroup( "General" );
-    m_sessions.append( config.readEntry( "Name" ) );
+    // Read new style configuration (from TDE R14.1.0)
+    KSimpleConfig *config = new KSimpleConfig(configFile, true);
+    config->setGroup("Sessions list");
+    int sessionsCount = config->readNumEntry("Sessions count", 0);
+    for (int i = 0;  i < sessionsCount;  ++i)
+    {
+      TQString urlStr = config->readEntry(TQString("URL_%1").arg(i));
+      if (!urlStr.isEmpty() && TDEGlobal::dirs()->exists(urlStr))
+      {
+        // Filter out empty URLs or non existing sessions
+        KSimpleConfig *sessionConfig = new KSimpleConfig(urlStr, true);
+        sessionConfig->setGroup("General");
+        // Session general properties
+        TQString sessionName = sessionConfig->readEntry("Name", i18n("Unnamed"));
+        m_sessions.append( sessionName );
+      }
+    }
+  }
+  else
+  {
+    TQStringList list = TDEGlobal::dirs()->findAllResources( "data", "kate/sessions/*.katesession", false, true);
+    for (TQStringList::ConstIterator it = list.begin(); it != list.end(); ++it)
+    {
+      KSimpleConfig config( *it, true );
+      config.setGroup( "General" );
+      m_sessions.append( config.readEntry( "Name" ) );
+    }
+    m_sessions.sort();
   }
 
-  m_sessions.sort();
 
   for ( TQStringList::ConstIterator it1 = m_sessions.begin(); it1 != m_sessions.end(); ++it1 )
   {
-- 
cgit v1.2.1