~jonas-drange/ubuntu-system-settings/filepicker

« back to all changes in this revision

Viewing changes to plugins/launcher/plugin/launcher-plugin.cpp

  • Committer: Jonas G. Drange
  • Date: 2017-01-24 14:03:55 UTC
  • mfrom: (1673.1.84 ubuntu-system-settings)
  • Revision ID: jonas.drange@canonical.com-20170124140355-1srbozy3aczq1mct
syncs with trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * This file is part of system-settings
 
3
 *
 
4
 * Copyright (C) 2016 Canonical Ltd.
 
5
 *
 
6
 * This program is free software: you can redistribute it and/or modify it
 
7
 * under the terms of the GNU General Public License version 3, as published
 
8
 * by the Free Software Foundation.
 
9
 *
 
10
 * This program is distributed in the hope that it will be useful, but
 
11
 * WITHOUT ANY WARRANTY; without even the implied warranties of
 
12
 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
 
13
 * PURPOSE.  See the GNU General Public License for more details.
 
14
 *
 
15
 * You should have received a copy of the GNU General Public License along
 
16
 * with this program.  If not, see <http://www.gnu.org/licenses/>.
 
17
 *
 
18
 */
 
19
 
 
20
#include "launcher_impl.h"
 
21
#include "launcher-plugin.h"
 
22
 
 
23
#include <SystemSettings/ItemBase>
 
24
#include <QObject>
 
25
#include <QProcessEnvironment>
 
26
#include <QQmlComponent>
 
27
#include <QQmlEngine>
 
28
#include <QScopedPointer>
 
29
#include <QUrl>
 
30
 
 
31
using namespace SystemSettings;
 
32
 
 
33
class LauncherItem: public ItemBase
 
34
{
 
35
    Q_OBJECT
 
36
 
 
37
public:
 
38
    explicit LauncherItem(const QVariantMap &staticData, QObject *parent = 0);
 
39
    void setVisibility(bool visible);
 
40
};
 
41
 
 
42
LauncherItem::LauncherItem(const QVariantMap &staticData, QObject *parent):
 
43
    ItemBase(staticData, parent)
 
44
{
 
45
    // Unconditionally show if USS_SHOW_ALL_UI is set.
 
46
    QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
 
47
    if (env.contains(QLatin1String("USS_SHOW_ALL_UI"))) {
 
48
        QString showAllS = env.value("USS_SHOW_ALL_UI", QString());
 
49
 
 
50
        if(!showAllS.isEmpty()) {
 
51
            setVisibility(true);
 
52
            return;
 
53
        }
 
54
    }
 
55
 
 
56
    // Show only if some screen is larger than the threshold.
 
57
    QQmlEngine engine;
 
58
    LauncherPanelPluginImpl panel;
 
59
    QString folder(env.value("SNAP", QString()) + LAUNCHER_PLUGIN_QML_DIR);
 
60
    QQmlComponent guAccessorComponent(
 
61
        &engine, QUrl::fromLocalFile(folder + "/GuAccessor.qml")
 
62
    );
 
63
    QScopedPointer<QObject> guAccessor(guAccessorComponent.create());
 
64
    int largeScreenThreshold = guAccessor->property("largeScreenThreshold").toInt();
 
65
    for (int i = 0; i < panel.screens(); i++) {
 
66
        if (panel.screenGeometry(i).width() > largeScreenThreshold) {
 
67
            setVisibility(true);
 
68
            return;
 
69
        }
 
70
    }
 
71
 
 
72
    setVisibility(false);
 
73
}
 
74
 
 
75
void LauncherItem::setVisibility(bool visible)
 
76
{
 
77
    setVisible(visible);
 
78
}
 
79
 
 
80
ItemBase *LauncherPlugin::createItem(const QVariantMap &staticData,
 
81
                                     QObject *parent)
 
82
{
 
83
    return new LauncherItem(staticData, parent);
 
84
}
 
85
 
 
86
#include "launcher-plugin.moc"