[SCM] Kaboom - Debian KDE 3->4 migration tool branch, master, updated. 87446012f77962a6bf454b39b94362cb64613dcb

Modestas Vainius modax-guest at alioth.debian.org
Sun Mar 1 08:58:50 UTC 2009


The following commit has been merged in the master branch:
commit e6330a446171a656b4228e1b9821495d5233b58a
Author: Modestas Vainius <modestas at vainius.eu>
Date:   Sat Feb 28 19:55:55 2009 +0200

    Add kaboomsettings singleton class.
    
    At the moment the class provides a single point to get KDEHOME paths,
    generates "pretty" paths (with $HOME path replaced with ~), adds support
    for --kdehome, --kde4home and --kde3backup command line options.
    
    Signed-off-by: Modestas Vainius <modestas at vainius.eu>

diff --git a/kaboom.pro b/kaboom.pro
index 912866d..13a029d 100644
--- a/kaboom.pro
+++ b/kaboom.pro
@@ -16,6 +16,7 @@ TRANSLATIONS += \
 
 # Input
 HEADERS += \
+      kaboomsettings.h \
       choicepage.h \
       intropage.h \
       migrationpage.h \
@@ -29,6 +30,7 @@ HEADERS += \
 
 
 SOURCES += \
+      kaboomsettings.cpp \ 
       choicepage.cpp \
       intropage.cpp \
       main.cpp \
diff --git a/kaboomsettings.cpp b/kaboomsettings.cpp
new file mode 100644
index 0000000..02fd542
--- /dev/null
+++ b/kaboomsettings.cpp
@@ -0,0 +1,121 @@
+/*
+    Copyright (C) 2009 Modestas Vainius <modestas at vainius.eu>
+                  2009 Sune Vuorela <sune at vuorela.dk>
+
+    This library is free software; you can redistribute it and/or modify
+    it under the terms of the GNU Lesser General Public License as published
+    by the Free Software Foundation; either version 2.1 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU Lesser General Public License
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
+#include <QtCore/QStringList>
+#include <QtCore/QDebug>
+#include <cstring>
+
+#include "kaboomsettings.h"
+
+#define DEFAULT_KDEDIR "/tmp/dirstructure/kde"
+#define DEFAULT_KDE4DIR "/tmp/dirstructure/kde4"
+#define DEFAULT_KDE3BACKUPDIR "/tmp/dirstructure/kde3-backup"
+
+KaboomSettings* KaboomSettings::s_instance = 0;
+
+KaboomSettings& KaboomSettings::instance()
+{
+    return *s_instance;
+}
+
+void KaboomSettings::initDefaults()
+{
+    const QString& homedir = QDir::homePath();
+    s_instance = this;
+
+    setKdehomePath(KdeHome, homedir + DEFAULT_KDEDIR);
+    setKdehomePath(Kde4Home, homedir + DEFAULT_KDE4DIR);
+    setKdehomePath(Kde3Backup, homedir + DEFAULT_KDE3BACKUPDIR);
+}
+
+KaboomSettings::KaboomSettings()
+{
+    initDefaults();
+}
+
+KaboomSettings::KaboomSettings(int argc, char** argv)
+{
+    initDefaults();
+
+    for (int i = 1; i < argc; i++) {
+        if (strcmp(argv[i], "--kdehome") == 0 && i+1 < argc) {
+            setKdehomePath(KdeHome, QString::fromLocal8Bit(argv[++i]));
+        } else if (strcmp(argv[i], "--kde4home") == 0 && i+1 < argc) {
+            setKdehomePath(Kde4Home, QString::fromLocal8Bit(argv[++i]));
+        } else if (strcmp(argv[i], "--kde3backup") == 0 && i+1 < argc) {
+            setKdehomePath(Kde3Backup, QString::fromLocal8Bit(argv[++i]));
+        } else if (strcmp(argv[i], "--help") == 0) {
+            // TODO: show help
+        }
+    }
+}
+
+void KaboomSettings::dump()
+{
+    qDebug() << "---- Kaboom Settings Dump ----";
+    qDebug() << "kdehome -" << kdehomeDir().path() << "- exists?:" <<
+        ((kdehomeDir().exists()) ? "YES" : "NO");
+    qDebug() << "kde4home -" << kde4homeDir().path() << "- exists?:" <<
+        ((kde4homeDir().exists()) ? "YES" : "NO");
+    qDebug() << "kde3backup -" << kde3backupDir().path() << "- exists?:" <<
+        ((kde3backupDir().exists()) ? "YES" : "NO");
+    qDebug() << "kaboom stamp -" << "exists?: " << ((stampExists()) ? "YES" : "NO");
+    qDebug() << "---- -------------------- ----";
+}
+
+void KaboomSettings::setKdehomePath(KdeHomeType type, const QString & path)
+{
+    QDir dir(path);
+    m_kdehomes[type] = dir;
+    m_prettyKdehomes[type] = path;
+
+    if (dir.exists()) {
+        /* Determine pretty path (replace $HOME with ~) */
+        QStringList paths;
+        QString homepath = QDir::homePath();
+
+        paths.append(dir.absolutePath());
+        paths.append(dir.canonicalPath());
+        foreach (QString path, paths) {
+            if (path.indexOf(homepath) == 0) {
+                path.replace(0, homepath.length(), "~");
+                m_prettyKdehomes[type] = path;
+                break;
+            }
+        }
+    }
+}
+
+const QDir& KaboomSettings::kdehomeDir(KdeHomeType type) const
+{
+    return m_kdehomes[type];
+}
+
+QString KaboomSettings::kdehomePrettyPath(KdeHomeType type) const
+{
+    return m_prettyKdehomes[type];
+}
+
+bool KaboomSettings::stampExists() const
+{
+    return (QFile::exists(QDir::homePath()+"/.local/kdebian3to4"));
+}
+
+void KaboomSettings::touchStamp()
+{
+    QFile(QDir::homePath()+"/.local/kdebian3to4").open(QIODevice::WriteOnly);
+}
diff --git a/kaboomsettings.h b/kaboomsettings.h
new file mode 100644
index 0000000..c9b3d0d
--- /dev/null
+++ b/kaboomsettings.h
@@ -0,0 +1,63 @@
+/*
+    Copyright (C) 2009 Modestas Vainius <modestas at vainius.eu>
+
+    This library is free software; you can redistribute it and/or modify
+    it under the terms of the GNU Lesser General Public License as published
+    by the Free Software Foundation; either version 2.1 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU Lesser General Public License
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
+#ifndef KABOOMSETTINGS_H
+#define KABOOMSETTINGS_H
+
+#include <QtCore/QString>
+#include <QtCore/QDir>
+
+#define KDEHOMES_COUNT      3
+
+class KaboomSettings {
+
+  public:
+    enum KdeHomeType {
+        KdeHome = 0x0,
+        Kde4Home = 0x1,
+        Kde3Backup = 0x2,
+    };
+
+    explicit KaboomSettings(int argc, char** argv);
+    explicit KaboomSettings();
+
+    static KaboomSettings& instance();
+
+    const QDir & kdehomeDir(KdeHomeType type=KdeHome) const;
+    QString kdehomePrettyPath(KdeHomeType type=KdeHome) const;
+    void setKdehomePath(KdeHomeType type, const QString & path);
+
+    /* Convenience methods */
+    const QDir& kde4homeDir() const { return kdehomeDir(Kde4Home); }
+    QString kde4homePrettyPath() const { return kdehomePrettyPath(Kde4Home); }
+    const QDir& kde3backupDir() const { return kdehomeDir(Kde3Backup); }
+
+    /* Stamp handling */
+    bool stampExists() const;
+    void touchStamp();
+
+    /* Debugging */
+    void dump();
+
+  private:
+    static KaboomSettings* s_instance;
+
+    QDir m_kdehomes[KDEHOMES_COUNT];
+    QString m_prettyKdehomes[KDEHOMES_COUNT];
+    void initDefaults();
+};
+
+#endif

-- 
Kaboom - Debian KDE 3->4 migration tool



More information about the pkg-kde-commits mailing list