~ubuntu-branches/ubuntu/wily/kwin/wily-proposed

« back to all changes in this revision

Viewing changes to tabbox/tabboxhandler.cpp

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2015-08-10 23:16:37 UTC
  • mfrom: (1.1.10)
  • Revision ID: package-import@ubuntu.com-20150810231637-5zb2tstjkez93hml
Tags: 4:5.3.95-0ubuntu1
new upstream beta release

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
#include "thumbnailitem.h"
31
31
#include "scripting/scripting.h"
32
32
#include "switcheritem.h"
 
33
#include "tabbox_logging.h"
33
34
// Qt
34
 
#include <QDebug>
35
35
#include <QKeyEvent>
36
36
#include <QModelIndex>
37
37
#include <QStandardPaths>
45
45
// KDE
46
46
#include <KLocalizedString>
47
47
#include <KProcess>
48
 
#include <KServiceTypeTrader>
 
48
#include <KPackage/Package>
 
49
#include <KPackage/PackageLoader>
49
50
 
50
51
namespace KWin
51
52
{
243
244
                                              .arg(config.layoutName())
244
245
                                              .arg(desktopMode ? QStringLiteral("desktopswitcher/DesktopSwitcher.qml") : QStringLiteral("windowswitcher/WindowSwitcher.qml")));
245
246
    if (file.isNull()) {
246
 
        auto findSwitcher = [this, desktopMode] {
247
 
            QString constraint = QStringLiteral("[X-KDE-PluginInfo-Name] == '%1'").arg(config.layoutName());
 
247
        const QString folderName = QStringLiteral(KWIN_NAME) + (desktopMode ? QStringLiteral("/desktoptabbox/") : QStringLiteral("/tabbox/"));
 
248
        auto findSwitcher = [this, desktopMode, folderName] {
248
249
            const QString type = desktopMode ? QStringLiteral("KWin/DesktopSwitcher") : QStringLiteral("KWin/WindowSwitcher");
249
 
            KService::List offers = KServiceTypeTrader::self()->query(type, constraint);
 
250
            auto offers = KPackage::PackageLoader::self()->findPackages(type,  folderName,
 
251
                [this] (const KPluginMetaData &data) {
 
252
                    return data.pluginId().compare(config.layoutName(), Qt::CaseInsensitive) == 0;
 
253
                }
 
254
            );
250
255
            if (offers.isEmpty()) {
251
256
                // load default
252
 
                constraint = QStringLiteral("[X-KDE-PluginInfo-Name] == '%1'").arg(QStringLiteral("informative"));
253
 
                offers = KServiceTypeTrader::self()->query(type, constraint);
 
257
                offers = KPackage::PackageLoader::self()->findPackages(type,  folderName,
 
258
                    [this] (const KPluginMetaData &data) {
 
259
                        return data.pluginId().compare(QStringLiteral("informative"), Qt::CaseInsensitive) == 0;
 
260
                    }
 
261
                );
254
262
                if (offers.isEmpty()) {
255
 
                    qDebug() << "could not find default window switcher layout";
256
 
                    return KService::Ptr();
 
263
                    qCDebug(KWIN_TABBOX) << "could not find default window switcher layout";
 
264
                    return KPluginMetaData();
257
265
                }
258
266
            }
259
267
            return offers.first();
260
268
        };
261
 
        KService::Ptr service = findSwitcher();
262
 
        if (!service) {
263
 
            return nullptr;
264
 
        }
265
 
        if (service->property(QStringLiteral("X-Plasma-API")).toString() != QStringLiteral("declarativeappletscript")) {
266
 
            qDebug() << "Window Switcher Layout is no declarativeappletscript";
267
 
            return nullptr;
268
 
        }
269
 
        auto findScriptFile = [desktopMode, service] {
270
 
            const QString pluginName = service->property(QStringLiteral("X-KDE-PluginInfo-Name")).toString();
271
 
            const QString scriptName = service->property(QStringLiteral("X-Plasma-MainScript")).toString();
272
 
            const QString type = desktopMode ? QStringLiteral("/desktoptabbox/") : QStringLiteral("/tabbox/");
273
 
            return QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral(KWIN_NAME) + type + pluginName + QStringLiteral("/contents/") + scriptName);
 
269
        auto service = findSwitcher();
 
270
        if (!service.isValid()) {
 
271
            return nullptr;
 
272
        }
 
273
        if (service.value(QStringLiteral("X-Plasma-API")) != QStringLiteral("declarativeappletscript")) {
 
274
            qCDebug(KWIN_TABBOX) << "Window Switcher Layout is no declarativeappletscript";
 
275
            return nullptr;
 
276
        }
 
277
        auto findScriptFile = [desktopMode, service, folderName] {
 
278
            const QString pluginName = service.pluginId();
 
279
            const QString scriptName = service.value(QStringLiteral("X-Plasma-MainScript"));
 
280
            return QStandardPaths::locate(QStandardPaths::GenericDataLocation, folderName + pluginName + QStringLiteral("/contents/") + scriptName);
274
281
        };
275
282
        file = findScriptFile();
276
283
    }
277
284
    if (file.isNull()) {
278
 
        qDebug() << "Could not find QML file for window switcher";
 
285
        qCDebug(KWIN_TABBOX) << "Could not find QML file for window switcher";
279
286
        return nullptr;
280
287
    }
281
288
    m_qmlComponent->loadUrl(QUrl::fromLocalFile(file));
282
289
    if (m_qmlComponent->isError()) {
283
 
        qDebug() << "Component failed to load: " << m_qmlComponent->errors();
 
290
        qCDebug(KWIN_TABBOX) << "Component failed to load: " << m_qmlComponent->errors();
284
291
        QStringList args;
285
292
        args << QStringLiteral("--passivepopup") << i18n("The Window Switcher installation is broken, resources are missing.\n"
286
293
                                            "Contact your distribution about this.") << QStringLiteral("20");