~ubuntu-branches/ubuntu/utopic/kde-workspace/utopic-proposed

« back to all changes in this revision

Viewing changes to kcontrol/krdb/krdb_clearlibrarypath.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Michał Zając
  • Date: 2011-07-09 08:31:15 UTC
  • Revision ID: james.westby@ubuntu.com-20110709083115-ohyxn6z93mily9fc
Tags: upstream-4.6.90
Import upstream version 4.6.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*  This file is part of the KDE project
 
2
    Copyright (C) 2008 Matthias Kretz <kretz@kde.org>
 
3
    Copyright (C) 2011 David Faure <faure@kde.org>
 
4
 
 
5
    This library is free software; you can redistribute it and/or
 
6
    modify it under the terms of the GNU Lesser General Public
 
7
    License as published by the Free Software Foundation; either
 
8
    version 2.1 of the License, or (at your option) version 3, or any
 
9
    later version accepted by the membership of KDE e.V. (or its
 
10
    successor approved by the membership of KDE e.V.), Trolltech ASA 
 
11
    (or its successors, if any) and the KDE Free Qt Foundation, which shall
 
12
    act as a proxy defined in Section 6 of version 3 of the license.
 
13
 
 
14
    This library is distributed in the hope that it will be useful,
 
15
    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
16
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
17
    Lesser General Public License for more details.
 
18
 
 
19
    You should have received a copy of the GNU Lesser General Public 
 
20
    License along with this library.  If not, see <http://www.gnu.org/licenses/>.
 
21
 
 
22
*/
 
23
 
 
24
#include <QtCore/QCoreApplication>
 
25
#include <QtCore/QDir>
 
26
#include <QtCore/QSettings>
 
27
#include <QtCore/QStringList>
 
28
#include <kcomponentdata.h>
 
29
#include <kglobal.h>
 
30
#include <kstandarddirs.h>
 
31
 
 
32
int main(int argc, char **argv)
 
33
{
 
34
    QCoreApplication app(argc, argv);
 
35
    QSettings settings(QLatin1String("Trolltech"));
 
36
    QString qversion = qVersion();
 
37
    if (qversion.count('.') > 1) {
 
38
        qversion.truncate(qversion.lastIndexOf('.'));
 
39
    }
 
40
    if (qversion.contains('-')) {
 
41
        qversion.truncate(qversion.lastIndexOf('-'));
 
42
    }
 
43
    const QString &libPathKey = QString("/qt/%1/libraryPath").arg(qversion);
 
44
 
 
45
    QStringList kdeAdded;
 
46
    KComponentData kcd("krdb libraryPath fix");
 
47
    const QStringList &plugins = KGlobal::dirs()->resourceDirs("qtplugins");
 
48
    foreach (const QString &_path, plugins) {
 
49
        QString path = QDir(_path).canonicalPath();
 
50
        if (path.isEmpty() || kdeAdded.contains(path)) {
 
51
            continue;
 
52
        }
 
53
        kdeAdded.prepend(path);
 
54
        if (path.contains("/lib64/")) {
 
55
            path.replace("/lib64/", "/lib/");
 
56
            if (!kdeAdded.contains(path)) {
 
57
                kdeAdded.prepend(path);
 
58
            }
 
59
        }
 
60
    }
 
61
 
 
62
    // Don't use toStringList! That's a different storage format
 
63
    QStringList libraryPath = settings.value(libPathKey, QString())
 
64
        .toString().split(QLatin1Char(':'), QString::SkipEmptyParts);
 
65
 
 
66
    // Remove all KDE paths, not needed anymore, done by $QT_PLUGIN_PATH
 
67
    foreach (const QString &path, const_cast<const QStringList &>(kdeAdded)) {
 
68
        libraryPath.removeAll(path);
 
69
    }
 
70
 
 
71
    settings.remove("/qt/KDE/kdeAddedLibraryPaths");
 
72
    settings.setValue(libPathKey, libraryPath.join(QLatin1String(":")));
 
73
 
 
74
    return 0;
 
75
}