[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [plasma-desktop/andriy/keyboard] kcms/keyboard: port layout restore to kf5
From:       Andriy Rysin <arysin () gmail ! com>
Date:       2014-10-06 16:26:15
Message-ID: E1XbB71-0004ji-ML () scm ! kde ! org
[Download RAW message or body]

Git commit 5000255d76fc3d1becb87b443c923ce9e9fd47f7 by Andriy Rysin.
Committed on 06/10/2014 at 14:52.
Pushed by rysin into branch 'andriy/keyboard'.

port layout restore to kf5

M  +2    -2    kcms/keyboard/keyboard_daemon.cpp
M  +15   -10   kcms/keyboard/layout_memory_persister.cpp
M  +2    -2    kcms/keyboard/layout_memory_persister.h

http://commits.kde.org/plasma-desktop/5000255d76fc3d1becb87b443c923ce9e9fd47f7

diff --git a/kcms/keyboard/keyboard_daemon.cpp b/kcms/keyboard/keyboard_daemon.cpp
index 3363fc5..9446ec1 100644
--- a/kcms/keyboard/keyboard_daemon.cpp
+++ b/kcms/keyboard/keyboard_daemon.cpp
@@ -61,7 +61,7 @@ KeyboardDaemon::KeyboardDaemon(QObject *parent, const QList<QVariant>&)
 	registerListeners();
 
 	LayoutMemoryPersister layoutMemoryPersister(layoutMemory);
-	if( layoutMemoryPersister.restore("kxkb") ) {
+	if( layoutMemoryPersister.restore() ) {
 		if( layoutMemoryPersister.getGlobalLayout().isValid() ) {
 			X11Helper::setLayout(layoutMemoryPersister.getGlobalLayout());
 		}
@@ -72,7 +72,7 @@ KeyboardDaemon::~KeyboardDaemon()
 {
 	LayoutMemoryPersister layoutMemoryPersister(layoutMemory);
 	layoutMemoryPersister.setGlobalLayout(X11Helper::getCurrentLayout());
-	layoutMemoryPersister.save("kxkb");
+	layoutMemoryPersister.save();
 
     QDBusConnection dbus = QDBusConnection::sessionBus();
     dbus.disconnect(QString(), KEYBOARD_DBUS_OBJECT_PATH, KEYBOARD_DBUS_SERVICE_NAME, \
                KEYBOARD_DBUS_CONFIG_RELOAD_MESSAGE, this, SLOT(configureKeyboard()));
diff --git a/kcms/keyboard/layout_memory_persister.cpp b/kcms/keyboard/layout_memory_persister.cpp
index 378655f..da48739 100644
--- a/kcms/keyboard/layout_memory_persister.cpp
+++ b/kcms/keyboard/layout_memory_persister.cpp
@@ -20,9 +20,9 @@
 
 #include <kconfiggroup.h>
 #include <ksharedconfig.h>
-#include <kstandarddirs.h>
 
 #include <QFile>
+#include <QDir>
 #include <QStandardPaths>
 #include <qdom.h>
 #include <qxml.h>
@@ -43,7 +43,7 @@ static const char LAYOUTS_ATTRIBUTE[] = "layouts";
 
 static const char LIST_SEPARATOR_LM[] = ",";
 
-static const char REL_SESSION_FILE_PATH[] = "/session/keyboard/layout_memory.xml";
+static const char REL_SESSION_FILE_PATH[] = "/keyboard/session/layout_memory.xml";
 
 QString LayoutMemoryPersister::getLayoutMapAsString()
 {
@@ -93,23 +93,28 @@ static bool isRestoreSession()
     return loginMode != "default" && loginMode != "restoreSavedSession";	// we don't know how to restore \
saved session - only previous one  }
 
-bool LayoutMemoryPersister::save(const QString& moduleName)
+bool LayoutMemoryPersister::save()
 {
 	if( isRestoreSession() ) {
-    	QString relPath = moduleName + REL_SESSION_FILE_PATH;
-        QFile file(KStandardDirs::locateLocal("data", relPath));
-//    	QFile file(QStandardPaths::writableLocation(QStandardPaths::DataLocation) + '/' + relPath);
+        QFileInfo fileInfo(QStandardPaths::writableLocation(QStandardPaths::DataLocation) + \
REL_SESSION_FILE_PATH); +
+        QDir baseDir(fileInfo.absoluteDir());
+        if( ! baseDir.exists() ) {
+            if( ! QDir().mkpath(baseDir.absolutePath()) ) {
+                qWarning() << "Failed to create directory" << baseDir.absolutePath();
+            }
+        }
+
+        QFile file(fileInfo.absoluteFilePath());
     	return saveToFile(file);
     }
     return false;
 }
 
-bool LayoutMemoryPersister::restore(const QString& moduleName)
+bool LayoutMemoryPersister::restore()
 {
 	if( isRestoreSession() ) {
-    	QString relPath = moduleName + REL_SESSION_FILE_PATH;
-        QFile file(KStandardDirs::locateLocal("data", relPath));
-//    	QFile file(QStandardPaths::writableLocation(QStandardPaths::DataLocation) + '/' + relPath);
+        QFile file(QStandardPaths::writableLocation(QStandardPaths::DataLocation) + \
REL_SESSION_FILE_PATH);  return restoreFromFile(file);
     }
     return false;
diff --git a/kcms/keyboard/layout_memory_persister.h b/kcms/keyboard/layout_memory_persister.h
index 8bbb93a..04b6cad 100644
--- a/kcms/keyboard/layout_memory_persister.h
+++ b/kcms/keyboard/layout_memory_persister.h
@@ -38,8 +38,8 @@ public:
 	bool saveToFile(const QFile& file);
 	bool restoreFromFile(const QFile& file);
 
-	bool save(const QString& moduleName);
-	bool restore(const QString& moduleName);
+	bool save();
+	bool restore();
 
 	LayoutUnit getGlobalLayout() const { return globalLayout; }
 	void setGlobalLayout(const LayoutUnit& layout) { globalLayout = layout; }


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic