summaryrefslogtreecommitdiffstats
path: root/kicker/kicker/kicker-3.4-reverseLayout.cpp
diff options
context:
space:
mode:
authortoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
committertoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
commit4aed2c8219774f5d797760606b8489a92ddc5163 (patch)
tree3f8c130f7d269626bf6a9447407ef6c35954426a /kicker/kicker/kicker-3.4-reverseLayout.cpp
downloadtdebase-4aed2c8219774f5d797760606b8489a92ddc5163.tar.gz
tdebase-4aed2c8219774f5d797760606b8489a92ddc5163.zip
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdebase@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kicker/kicker/kicker-3.4-reverseLayout.cpp')
-rw-r--r--kicker/kicker/kicker-3.4-reverseLayout.cpp152
1 files changed, 152 insertions, 0 deletions
diff --git a/kicker/kicker/kicker-3.4-reverseLayout.cpp b/kicker/kicker/kicker-3.4-reverseLayout.cpp
new file mode 100644
index 000000000..bfcea5629
--- /dev/null
+++ b/kicker/kicker/kicker-3.4-reverseLayout.cpp
@@ -0,0 +1,152 @@
+#include <qfile.h>
+#include <qmap.h>
+#include <qregexp.h>
+#include <qstring.h>
+#include <qtextstream.h>
+
+#include <kapplication.h>
+#include <kcmdlineargs.h>
+#include <kglobal.h>
+#include <klocale.h>
+#include <kprocess.h>
+#include <ktempfile.h>
+
+struct AppletInfo
+{
+ double freeSpace;
+ QString configFile;
+ QString desktopFile;
+};
+typedef QMap<QString, AppletInfo> AppletInfoMap;
+
+int main(int argc, char** argv)
+{
+ // We must disguise as Kicker in order to obtain the correct reverseLayout setting.
+ KCmdLineArgs::init(argc, argv, "kicker", "", "", "", false);
+ KApplication app(false, false);
+
+ QStringList stretchableApplets;
+ stretchableApplets << "taskbarapplet.desktop";
+
+ QTextStream in (stdin, IO_ReadOnly);
+ QTextStream out(stdout, IO_WriteOnly);
+
+ QStringList appletIds;
+ AppletInfoMap applets;
+
+ QRegExp rxGroup("^\\[(.+)\\]$");
+ QRegExp rxKeyValue("([^=]+)=[ \t]*([^\n]+)");
+ QString currentGroup;
+
+ QString line;
+ while (!(line = in.readLine()).isNull())
+ {
+ if (rxGroup.search(line) != -1)
+ {
+ currentGroup = rxGroup.cap(1);
+ continue;
+ }
+
+ if (rxKeyValue.search(line) != -1)
+ {
+ QString key = rxKeyValue.cap(1);
+ QString value = rxKeyValue.cap(2);
+
+ if (key == "Applets")
+ {
+ appletIds = QStringList::split(",", value);
+ }
+ else if (key == "FreeSpace")
+ {
+ applets[currentGroup].freeSpace = value.toDouble();
+ }
+ else if (key == "ConfigFile")
+ {
+ applets[currentGroup].configFile = value;
+ }
+ else if (key == "DesktopFile")
+ {
+ applets[currentGroup].desktopFile = value;
+ }
+ }
+ }
+
+ if (QApplication::reverseLayout())
+ {
+ // Reverse appletIds
+ QStringList appletIdsRev;
+ QStringList::ConstIterator it;
+ for (it = appletIds.begin(); it != appletIds.end(); ++it)
+ {
+ appletIdsRev.prepend(*it);
+ }
+ appletIds = appletIdsRev;
+
+ // Adjust the FreeSpace values
+ for (it = appletIds.begin(); it != appletIds.end(); ++it)
+ {
+ applets[*it].freeSpace = 1 - applets[*it].freeSpace;
+
+ // Take care of stretchable applets.
+ if (stretchableApplets.contains(applets[*it].desktopFile))
+ {
+ if (it != appletIds.begin())
+ {
+ applets[*it].freeSpace = applets[*(--it)].freeSpace;
+ ++it;
+ }
+ else
+ {
+ applets[*it].freeSpace = 0;
+ }
+ }
+ }
+ }
+
+ // Write the changed entries to stdout.
+ if (!appletIds.empty())
+ {
+ out << "[General]" << endl;
+ out << "Applets2=" << appletIds.join(",") << endl;
+ QStringList::ConstIterator it;
+ for (it = appletIds.begin(); it != appletIds.end(); ++it)
+ {
+ out << "[" << *it << "]" << endl;
+ out << "FreeSpace2=" << applets[*it].freeSpace << endl;
+ }
+ }
+
+ // Build a list of childpanel config files.
+ QStringList childPanelConfigFiles;
+ AppletInfoMap::ConstIterator it2;
+ QStringList::ConstIterator it;
+ for (it2 = applets.begin(); it2 != applets.end(); ++it2)
+ {
+ if (it2.data().desktopFile == "childpanelextension.desktop")
+ {
+ childPanelConfigFiles << it2.data().configFile;
+ }
+ }
+
+ if (!childPanelConfigFiles.isEmpty())
+ {
+ // Create a temporary kconf_update .upd file for updating the childpanels
+ KTempFile tempFile(QString::null, ".upd");
+ QTextStream* upd = tempFile.textStream();
+ for (it = childPanelConfigFiles.begin(); it != childPanelConfigFiles.end(); ++it)
+ {
+ *upd << "Id=kde_3.4_reverseLayout" << endl;
+ *upd << "File=" << *it << endl;
+ *upd << "Script=kicker-3.4-reverseLayout" << endl;
+ *upd << endl;
+ }
+ tempFile.close();
+
+ // Run kconf_update on the childpanel config files.
+ KProcess kconf_update;
+ kconf_update << "kconf_update" << tempFile.name();
+ kconf_update.start(KProcess::Block);
+
+ tempFile.unlink();
+ }
+}