Sophie

Sophie

distrib > Mandriva > 2010.2 > i586 > by-pkgid > ce2e75decdd057e5c961fad858af3221 > files > 14

kdebase4-workspace-4.4.5-0.2mdv2010.2.src.rpm

diff -Naur kdebase-workspace-4.3.2/migrate/CMakeLists.txt kdebase-workspace-4.3.2-migra/migrate/CMakeLists.txt
--- kdebase-workspace-4.3.2/migrate/CMakeLists.txt	1970-01-01 01:00:00.000000000 +0100
+++ kdebase-workspace-4.3.2-migra/migrate/CMakeLists.txt	2009-11-05 15:57:08.000000000 +0100
@@ -0,0 +1,13 @@
+project(migrate)
+
+cmake_minimum_required(VERSION 2.4.5)
+
+set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/cmake/modules )
+
+# search packages used by KDE
+find_package(KDE4 REQUIRED)
+include (KDE4Defaults)
+include (MacroLibrary)
+include(MacroOptionalAddSubdirectory)
+
+macro_optional_add_subdirectory(migrate)
diff -Naur kdebase-workspace-4.3.2/migrate/migrate/AppsList.cpp kdebase-workspace-4.3.2-migra/migrate/migrate/AppsList.cpp
--- kdebase-workspace-4.3.2/migrate/migrate/AppsList.cpp	1970-01-01 01:00:00.000000000 +0100
+++ kdebase-workspace-4.3.2-migra/migrate/migrate/AppsList.cpp	2009-11-05 15:57:08.000000000 +0100
@@ -0,0 +1,92 @@
+/*  This file is part of the KDE project
+    Copyright (C) 2008 Dirk Mueller <mueller@kde.org>
+
+    This program is free software; you can redistribute it and/or
+    modify it under the terms of the GNU General Public
+    License as published by the Free Software Foundation; either
+    version 2 of the License, or (at your option) any later version.
+
+    This library 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
+    Library General Public License for more details.
+
+    You should have received a copy of the GNU Library General Public License
+    along with this library; see the file COPYING.LIB.  If not, write to
+    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+    Boston, MA 02110-1301, USA.
+
+*/
+
+#include <QtCore/QDebug>
+#include <QtCore/QDir>
+
+#include "AppsList.h"
+
+const char* const blackList[] = {
+    "RecentDocuments",
+    "default_desktop",
+    "kbabel",
+    "kbabeldict",
+    "kbfx",
+    "kconf_update",
+    "kdeprint",
+    "kdesktop",
+    "kfm",
+    "kicker",
+    "knemo",
+    "kssl",
+    NULL
+};
+
+static bool is_blacklisted(const QByteArray& appname)
+{
+    const char* const* begin = &blackList[0];
+    const char* const* end = &blackList[sizeof(blackList)/sizeof(*blackList)]-1;
+
+    // ### binary search
+    return qBinaryFind(begin, end, appname.data()) != end;
+}
+
+AppList::AppList()
+{
+
+}
+
+void AppList::generateAppList()
+{
+    appLists.clear();
+
+    // list all portable kde3 apps
+    QDir kde3path( QDir::homePath() + "/.kde/share/apps");
+
+    QByteArray kdehome = qgetenv("KDEHOME");
+    if (kdehome.isEmpty())
+        kdehome = QDir::homePath().toUtf8() + "/.kde4/";
+
+    QDir kde4path( kdehome + "/share/apps");
+
+    for (QStringListIterator it(kde3path.entryList()); it.hasNext();) {
+        QByteArray app = QFile::encodeName(it.next());
+
+        if (app[0] == '.')
+            continue;
+
+        qDebug() << "looking at" << app;
+
+        bool blacklisted = is_blacklisted(app);
+        if (blacklisted)
+            continue;
+
+        qDebug() << "candidate: " << app;
+        AppListItem item;
+        item.appName = app;
+        item.dir = kde3path.path() + "/" + QFile::decodeName(app);
+        appLists << item;
+    }
+
+}
+
+#include "AppsList.h"
+
+
diff -Naur kdebase-workspace-4.3.2/migrate/migrate/AppsList.h kdebase-workspace-4.3.2-migra/migrate/migrate/AppsList.h
--- kdebase-workspace-4.3.2/migrate/migrate/AppsList.h	1970-01-01 01:00:00.000000000 +0100
+++ kdebase-workspace-4.3.2-migra/migrate/migrate/AppsList.h	2009-11-05 15:57:08.000000000 +0100
@@ -0,0 +1,44 @@
+/*  This file is part of the KDE project
+    Copyright (C) 2008 Dirk Mueller <mueller@kde.org>
+
+    This program is free software; you can redistribute it and/or
+    modify it under the terms of the GNU General Public
+    License as published by the Free Software Foundation; either
+    version 2 of the License, or (at your option) any later version.
+
+    This library 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
+    Library General Public License for more details.
+
+    You should have received a copy of the GNU Library General Public License
+    along with this library; see the file COPYING.LIB.  If not, write to
+    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+    Boston, MA 02110-1301, USA.
+
+*/
+
+#ifndef APPSLIST_H
+#define APPSLIST_H
+
+class AppListItem {
+
+public:
+
+    QString dir;
+    QString appName;
+};
+
+class AppList {
+
+public:
+    AppList();
+
+    QList<AppListItem> appLists;
+
+//private:
+    void generateAppList();
+
+};
+
+#endif
diff -Naur kdebase-workspace-4.3.2/migrate/migrate/CMakeLists.txt kdebase-workspace-4.3.2-migra/migrate/migrate/CMakeLists.txt
--- kdebase-workspace-4.3.2/migrate/migrate/CMakeLists.txt	1970-01-01 01:00:00.000000000 +0100
+++ kdebase-workspace-4.3.2-migra/migrate/migrate/CMakeLists.txt	2009-11-05 15:57:08.000000000 +0100
@@ -0,0 +1,13 @@
+include_directories(
+    ${QT_INCLUDES}
+)
+
+set(kde4migrate_SRCS
+    main.cpp
+    QuickMigrate.cpp
+)
+
+kde4_add_executable(kde4-migrate ${kde4migrate_SRCS})
+target_link_libraries(kde4-migrate ${QT_QTCORE_LIBRARY} ${KDE4_KIO_LIBS} )
+
+install(TARGETS kde4-migrate DESTINATION ${BIN_INSTALL_DIR})
diff -Naur kdebase-workspace-4.3.2/migrate/migrate/QuickMigrate.cpp kdebase-workspace-4.3.2-migra/migrate/migrate/QuickMigrate.cpp
--- kdebase-workspace-4.3.2/migrate/migrate/QuickMigrate.cpp	1970-01-01 01:00:00.000000000 +0100
+++ kdebase-workspace-4.3.2-migra/migrate/migrate/QuickMigrate.cpp	2009-11-05 15:57:08.000000000 +0100
@@ -0,0 +1,215 @@
+/*  This file is part of openSUSE
+    Copyright (C) 2008 Dirk Mueller <dmueller@suse.de>
+    Copyright (C) 2009 Nicolas Lécureuil <nlecureuil@mandriva.com>
+
+    This program is free software; you can redistribute it and/or
+    modify it under the terms of the GNU General Public
+    License as published by the Free Software Foundation; either
+    version 2 of the License, or (at your option) any later version.
+
+    This library 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
+    Library General Public License for more details.
+
+    You should have received a copy of the GNU Library General Public License
+    along with this library; see the file COPYING.LIB.  If not, write to
+    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+    Boston, MA 02110-1301, USA.
+
+*/
+
+// Own includes
+#include "QuickMigrate.h"
+
+// Qt includes
+#include <QtCore/QFile>
+#include <QtCore/QFileInfo>
+#include <QtCore/QDir>
+#include <QtCore/QDebug>
+#include <QThread>
+
+//KDE includes
+#include <kio/copyjob.h>
+
+// System includes
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
+static const char* const migrate_list[] = {
+    "share/apps/kabc/*.vcf",
+    "share/apps/akregator/data/feeds.opml",
+    "share/apps/kcookiejar/cookies",
+    "share/apps/kfile/bookmarks.xml",
+    "share/apps/khtml/formcompletions",
+    "share/apps/konqueror/bookmarks.xml",
+    "share/apps/konsole/bookmarks.xml",
+    "share/apps/kopete/contactlist.xml",
+    "share/apps/kopete/logs/*",
+    "share/apps/konversation/logs/*",
+    "share/apps/krdc/bookmarks.xml",
+    "share/apps/kwallet/*.kwl",
+    "share/apps/RecentDocuments/*.desktop",
+    "share/config/akregatorrc",
+    "share/config/colors/*",
+    "share/config/cryptodefaults",
+    "share/config/jukrc",
+    "share/config/katerc",
+    "share/config/kateschemarc",
+    "share/config/kcookiejarrc",
+    "share/config/kcmrandrrc",
+    "share/config/kcminputrc",
+    "share/config/kcmfonts",
+    "share/config/kio_*rc",
+    "share/config/klipperrc",
+    "share/config/knoderc",
+    "share/config/konq_history",
+    "share/config/konsolerc",
+    "share/config/konversationrc",
+    "share/config/kopeterc",
+    "share/config/kpgprc",
+    "share/config/kppprc",
+    "share/config/ksslpolicies",
+    "share/config/kstarsrc",
+    "share/config/ksysguardrc",
+    "share/config/kwalletrc",
+    NULL
+};
+
+// Fixme: is it really needed to use this function instead of QFile::mkdir ?
+static bool makeDir(const QString& dir, int mode)
+{
+    // we want an absolute path
+    if (QDir::isRelativePath(dir))
+        return false;
+
+    QString target = dir;
+    uint len = target.length();
+
+    // append trailing slash if missing
+    if (dir.at(len - 1) != '/')
+        target += '/';
+
+    QString base("");
+    uint i = 1;
+
+    while( i < len )
+    {
+        struct stat st;
+        int pos = target.indexOf('/', i);
+        base += target.mid(i - 1, pos - i + 1);
+        QByteArray baseEncoded = QFile::encodeName(base);
+        // bail out if we encountered a problem
+        if (stat(baseEncoded, &st) != 0)
+        {
+            // Directory does not exist....
+            // Or maybe a dangling symlink ?
+            if (lstat(baseEncoded, &st) == 0)
+                (void)unlink(baseEncoded); // try removing
+
+            if (mkdir(baseEncoded, static_cast<mode_t>(mode)) != 0) {
+                baseEncoded.prepend( "trying to create local folder " );
+                perror(baseEncoded.data());
+                return false; // Couldn't create it :-(
+            }
+        }
+        i = pos + 1;
+    }
+    return true;
+}
+
+static bool migrateOneFile(const QString& from, const QString& to)
+{
+    if (QFile::exists(to)) {
+        return true;
+    }
+
+    QFileInfo fi(from);
+    if (!fi.exists() || fi.isSymLink())
+        return true;
+
+    QFile f(from);
+    if (!f.exists())
+        return true;
+
+    qDebug() << "migrating " << from << "->" << to;
+    QString todir = QFileInfo(to).path();
+
+    // create destination directory if missing
+    if (!QFileInfo(todir).exists())
+        makeDir(todir, 0777);
+
+    KIO::CopyJob* job;
+    qDebug()<< from << "from" ;
+    qDebug()<< to << "to" ;
+    job = KIO::copy(from, to, KIO::HideProgressInfo);
+    job->setUiDelegate(0);
+    // we need to manually use exec because this is a non gui application
+    job->exec();
+
+    //TODO: Handle when copy failed
+    return true;
+}
+
+bool QuickMigrate::migrateMultipleFiles(const QString& filepat)
+{
+
+    QFileInfo finfo(filepat);
+    QString fpath = finfo.path();
+    QString fname = finfo.baseName();
+
+
+    Q_ASSERT(!fpath.contains('*'));
+    Q_ASSERT(fname.contains('*'));
+
+    QDir dir(m_kde3path + fpath);
+    dir.setFilter(QDir::Files | QDir::Dirs | QDir::NoSymLinks | QDir::NoDotAndDotDot | QDir::Hidden | QDir::Readable);
+    dir.setNameFilters(QStringList(fname));
+
+    bool state = true;
+
+    QStringList matches = dir.entryList();
+    
+    Q_FOREACH(const QString& match, matches)
+	    state &= migrateOneFile(m_kde3path + fpath + "/" + match, m_kde4path + fpath + "/" + match);
+
+    return state;
+}
+
+QuickMigrate::QuickMigrate()
+{
+    m_kde3path = QDir::homePath() + "/.kde/";
+
+    QByteArray kdehome = qgetenv("KDEHOME");
+    if (kdehome.isEmpty())
+        kdehome = QDir::homePath().toUtf8() + "/.kde4/";
+
+    m_kde4path = kdehome;
+
+    if (!m_kde4path.endsWith("/"))
+        m_kde4path += "/";
+
+    QFileInfo fi(m_kde4path);
+
+    if (!fi.exists() || !fi.isDir())
+        makeDir(m_kde4path, 0700);
+}
+
+int QuickMigrate::exec()
+{
+    int fails = 0;
+    for (const char* const* f = &migrate_list[0]; *f; ++f) {
+
+        if (QByteArray(*f).contains('*')) {
+           fails += migrateMultipleFiles(*f);
+           continue;
+        }
+
+        QString oldfile = m_kde3path + *f;
+
+        if (!migrateOneFile(oldfile, m_kde4path + *f))
+            ++fails;
+    }
+    return fails;
+}
diff -Naur kdebase-workspace-4.3.2/migrate/migrate/QuickMigrate.h kdebase-workspace-4.3.2-migra/migrate/migrate/QuickMigrate.h
--- kdebase-workspace-4.3.2/migrate/migrate/QuickMigrate.h	1970-01-01 01:00:00.000000000 +0100
+++ kdebase-workspace-4.3.2-migra/migrate/migrate/QuickMigrate.h	2009-11-05 15:57:08.000000000 +0100
@@ -0,0 +1,41 @@
+/*  This file is part of openSUSE
+    Copyright (C) 2008 Dirk Mueller <dmueller@suse.de>
+
+    This program is free software; you can redistribute it and/or
+    modify it under the terms of the GNU General Public
+    License as published by the Free Software Foundation; either
+    version 2 of the License, or (at your option) any later version.
+
+    This library 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
+    Library General Public License for more details.
+
+    You should have received a copy of the GNU Library General Public License
+    along with this library; see the file COPYING.LIB.  If not, write to
+    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+    Boston, MA 02110-1301, USA.
+
+*/
+
+#ifndef QuickMigrate_h
+#define QuickMigrate_h
+
+#include <QtCore/QString>
+
+class QuickMigrate {
+
+public:
+
+    QuickMigrate();
+
+    int exec();
+
+private:
+    bool migrateMultipleFiles(const QString& fpattern);
+
+    QString m_kde3path;
+    QString m_kde4path;
+};
+
+#endif
diff -Naur kdebase-workspace-4.3.2/migrate/migrate/main.cpp kdebase-workspace-4.3.2-migra/migrate/migrate/main.cpp
--- kdebase-workspace-4.3.2/migrate/migrate/main.cpp	1970-01-01 01:00:00.000000000 +0100
+++ kdebase-workspace-4.3.2-migra/migrate/migrate/main.cpp	2009-11-05 15:57:08.000000000 +0100
@@ -0,0 +1,33 @@
+/*  This file is part of the KDE project
+    Copyright (C) 2008 Dirk Mueller <mueller@kde.org>
+    Copyright (C) 2009 Nicolas Lécureuil <nlecureuil@mandriva.com>
+
+    This program is free software; you can redistribute it and/or
+    modify it under the terms of the GNU General Public
+    License as published by the Free Software Foundation; either
+    version 2 of the License, or (at your option) any later version.
+
+    This library 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
+    Library General Public License for more details.
+
+    You should have received a copy of the GNU Library General Public License
+    along with this library; see the file COPYING.LIB.  If not, write to
+    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+    Boston, MA 02110-1301, USA.
+
+*/
+
+#include <qstring.h>
+#include <QApplication>
+
+#include "QuickMigrate.h"
+#include <QCoreApplication>
+
+int main (int argc, char *argv[])
+{
+    // Needed for KIO::copy
+    QCoreApplication app(argc, argv);
+    return QuickMigrate().exec();
+}
--- kdebase-workspace-4.3.90/CMakeLists.txt.old	2010-01-09 23:54:43.000000000 +0100
+++ kdebase-workspace-4.3.90/CMakeLists.txt	2010-01-09 23:55:02.000000000 +0100
@@ -140,6 +140,7 @@
 endif(NOT WIN32)
 macro_optional_add_subdirectory( klipper )
 macro_optional_add_subdirectory( krunner )
+macro_optional_add_subdirectory( migrate )
 macro_optional_add_subdirectory( solid )
 macro_optional_add_subdirectory( kmenuedit )
 macro_optional_add_subdirectory( plasma )