~nick-dedekind/unity8/side-stage-redesign-tutorial

« back to all changes in this revision

Viewing changes to plugins/Unity/Indicators/indicatorsmanager.cpp

  • Committer: Nick Dedekind
  • Date: 2015-12-14 18:06:18 UTC
  • mfrom: (1998.1.101 unity8)
  • Revision ID: nick.dedekind@canonical.com-20151214180618-men18zbauv1r153m
merged with trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
51
51
IndicatorsManager::~IndicatorsManager()
52
52
{
53
53
    unload();
54
 
 
55
54
}
56
55
 
57
56
void IndicatorsManager::load()
58
57
{
59
58
    unload();
60
59
 
61
 
    QStringList xdgLocations = shellDataDirs();//QStandardPaths::standardLocations(QStandardPaths::GenericDataLocation);
 
60
    const QStringList xdgLocations = shellDataDirs();
62
61
 
63
62
    m_fsWatcher.reset(new QFileSystemWatcher(this));
64
63
 
65
64
    Q_FOREACH(const QString& xdgLocation, xdgLocations)
66
65
    {
67
 
        QString indicator_path = QDir::cleanPath(xdgLocation + "/unity/indicators");
 
66
        const QString indicator_path = QDir::cleanPath(xdgLocation + "/unity/indicators");
68
67
        QDir indicator_dir(indicator_path);
69
68
        if (indicator_dir.exists())
70
69
        {
103
102
{
104
103
    startVerify(dir.canonicalPath());
105
104
 
106
 
    QFileInfoList indicator_files = dir.entryInfoList(QStringList(), QDir::Files|QDir::NoDotAndDotDot);
 
105
    const QFileInfoList indicator_files = dir.entryInfoList(QStringList(), QDir::Files|QDir::NoDotAndDotDot);
107
106
    Q_FOREACH(const QFileInfo& indicator_file, indicator_files)
108
107
    {
109
108
        loadFile(indicator_file);
115
114
void IndicatorsManager::loadFile(const QFileInfo& file_info)
116
115
{
117
116
    QSettings indicator_settings(file_info.absoluteFilePath(), QSettings::IniFormat, this);
118
 
    QString name = indicator_settings.value(QStringLiteral("Indicator Service/Name")).toString();
119
 
 
120
 
    auto iter = m_indicatorsData.find(name);
121
 
    if (iter != m_indicatorsData.end())
 
117
    const QString name = indicator_settings.value(QStringLiteral("Indicator Service/Name")).toString();
 
118
 
 
119
    if (m_platform.isPC() && name == "indicator-keyboard") {
 
120
        return; // convergence: skip this indicator until it works in Mir
 
121
    }
 
122
 
 
123
    auto iter = m_indicatorsData.constFind(name);
 
124
    if (iter != m_indicatorsData.constEnd())
122
125
    {
123
 
        QString newFileInfoDir = QDir::cleanPath(file_info.canonicalPath());
 
126
        const QString newFileInfoDir = QDir::cleanPath(file_info.canonicalPath());
124
127
        IndicatorData* currentData = (*iter);
125
128
        currentData->m_verified = true;
126
129
 
127
130
        int file_info_location = -1;
128
131
        int current_data_location = -1;
129
132
 
130
 
        QString currentDataDir = QDir::cleanPath(currentData->m_fileInfo.canonicalPath());
 
133
        const QString currentDataDir = QDir::cleanPath(currentData->m_fileInfo.canonicalPath());
131
134
 
132
135
        // if we've already got this indicator, we need to make sure we're not overwriting data which is
133
136
        // from a lower priority standard path
134
137
        QStringList xdgLocations = shellDataDirs();
135
138
        for (int i = 0; i < xdgLocations.size(); i++)
136
139
        {
137
 
            QString indicatorDir = QDir::cleanPath(xdgLocations[i] + "/unity/indicators");
 
140
            const QString indicatorDir = QDir::cleanPath(xdgLocations[i] + "/unity/indicators");
138
141
 
139
142
            if (newFileInfoDir == indicatorDir)
140
143
            {
194
197
        {
195
198
            if (!data->m_verified)
196
199
            {
197
 
                QString name = data->m_name;
 
200
                const QString name = data->m_name;
198
201
                Q_EMIT indicatorAboutToBeUnloaded(name);
199
202
 
200
203
                delete data;
253
256
        {
254
257
            if (!data->m_verified)
255
258
            {
256
 
                QString name = data->m_name;
 
259
                const QString name = data->m_name;
257
260
                Q_EMIT indicatorAboutToBeUnloaded(name);
258
261
 
259
262
                delete data;
271
274
        return Indicator::Ptr();
272
275
    }
273
276
 
274
 
    IndicatorData *data = m_indicatorsData[indicator_name];
 
277
    IndicatorData *data = m_indicatorsData.value(indicator_name);
275
278
    if (data->m_indicator)
276
279
    {
277
280
        return data->m_indicator;
281
284
    data->m_indicator = new_indicator;
282
285
    QSettings settings(data->m_fileInfo.absoluteFilePath(), QSettings::IniFormat, this);
283
286
    new_indicator->init(data->m_fileInfo.fileName(), settings);
284
 
    new_indicator->setProfile(m_profile);
 
287
 
 
288
    // convergence:
 
289
    // 1) enable session indicator conditionally, typically when running in a multisession/multiuser environment
 
290
    // 2) on a PC, switch the battery/power indicator to desktop mode,
 
291
    //    can't control brightness for now and phone-on-desktop broken (FIXME)
 
292
    //
 
293
    // The rest of the indicators respect their default profile (which is "phone", even on desktop PCs)
 
294
    if ((new_indicator->identifier() == QStringLiteral("indicator-session") && m_platform.isMultiSession())
 
295
            || (new_indicator->identifier() == QStringLiteral("indicator-power") && m_platform.isPC())) {
 
296
        new_indicator->setProfile("desktop");
 
297
    } else {
 
298
        new_indicator->setProfile(m_profile);
 
299
    }
 
300
 
285
301
    QObject::connect(this, &IndicatorsManager::profileChanged, new_indicator.data(), &Indicator::setProfile);
286
302
    return new_indicator;
287
303
}