@@ -1,9 +1,6 @@
2 * Copyright (C) 2013 Canonical, Ltd.
2 * Copyright (C) 2013 Canonical, Ltd.
5− * Michał Sawicz <michal.sawicz@canonical.com>
7 * This program is free software; you can redistribute it and/or modify
4 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
5 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 3.
6 * the Free Software Foundation; version 3.
@@ -15,6 +12,8 @@
16 * You should have received a copy of the GNU General Public License
13 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16+ * Author: Nick Dedekind <nick.dedekind@canonical.com>
20#include "indicatorsmanager.h"
19#include "indicatorsmanager.h"
@@ -29,9 +28,9 @@ class IndicatorsManager::IndicatorData
31 IndicatorData(const QString& name, const QFileInfo& fileInfo)
30 IndicatorData(const QString& name, const QFileInfo& fileInfo)
32− : m_name(name)
31+ : m_name(name)
33− , m_fileInfo(fileInfo)
32+ , m_fileInfo(fileInfo)
34− , m_verified (true)
33+ , m_verified (true)
37 QString m_name;
36 QString m_name;
@@ -42,8 +41,8 @@ public:
44IndicatorsManager::IndicatorsManager(QObject* parent)
43IndicatorsManager::IndicatorsManager(QObject* parent)
45−: QObject(parent)
44+ : QObject(parent)
46−, m_loaded(false)
45+ , m_loaded(false)
@@ -68,7 +67,7 @@ void IndicatorsManager::load()
68 // watch folder for changes.
67 // watch folder for changes.
69 m_fsWatcher->addPath(indicator_path);
68 m_fsWatcher->addPath(indicator_path);
71− load(indicator_dir);
70+ loadDir(indicator_dir);
@@ -77,9 +76,9 @@ void IndicatorsManager::load()
77 setLoaded(true);
76 setLoaded(true);
80−void IndicatorsManager::onDirectoryChanged(const QString& direcory)
79+void IndicatorsManager::onDirectoryChanged(const QString& directory)
82− load(QDir(direcory));
81+ loadDir(QDir(directory));
85void IndicatorsManager::onFileChanged(const QString& file)
84void IndicatorsManager::onFileChanged(const QString& file)
@@ -87,29 +86,29 @@ void IndicatorsManager::onFileChanged(const QString& file)
87 QFileInfo file_info(file);
86 QFileInfo file_info(file);
88 if (!file_info.exists())
87 if (!file_info.exists())
90− unload(file_info);
89+ unloadFile(file_info);
95− load(QFileInfo(file));
94+ loadFile(QFileInfo(file));
99−void IndicatorsManager::load(const QDir& dir)
98+void IndicatorsManager::loadDir(const QDir& dir)
101 startVerify(dir.canonicalPath());
100 startVerify(dir.canonicalPath());
103 QFileInfoList indicator_files = dir.entryInfoList(QStringList(), QDir::Files|QDir::NoDotAndDotDot);
102 QFileInfoList indicator_files = dir.entryInfoList(QStringList(), QDir::Files|QDir::NoDotAndDotDot);
104 Q_FOREACH(const QFileInfo& indicator_file, indicator_files)
103 Q_FOREACH(const QFileInfo& indicator_file, indicator_files)
106− load(indicator_file);
105+ loadFile(indicator_file);
109 endVerify(dir.canonicalPath());
108 endVerify(dir.canonicalPath());
112−void IndicatorsManager::load(const QFileInfo& file_info)
111+void IndicatorsManager::loadFile(const QFileInfo& file_info)
114 QSettings indicator_settings(file_info.absoluteFilePath(), QSettings::IniFormat, this);
113 QSettings indicator_settings(file_info.absoluteFilePath(), QSettings::IniFormat, this);
115 QString name = indicator_settings.value("Indicator Service/Name").toString();
114 QString name = indicator_settings.value("Indicator Service/Name").toString();
@@ -128,18 +127,24 @@ void IndicatorsManager::load(const QFileInfo& file_info)
129 // if we've already got this indicator, we need to make sure we're not overwriting data which is
128 // if we've already got this indicator, we need to make sure we're not overwriting data which is
130 // from a lower priority standard path
129 // from a lower priority standard path
131− QStringList xdgLocations = QStandardPaths::standardLocations(QStandardPaths::GenericDataLocation);
130+ QStringList xdgLocations = shellDataDirs();
132 for (int i = 0; i < xdgLocations.size(); i++)
131 for (int i = 0; i < xdgLocations.size(); i++)
134 QString indicatorDir = QDir::cleanPath(xdgLocations[i] + "/unity/indicators");
133 QString indicatorDir = QDir::cleanPath(xdgLocations[i] + "/unity/indicators");
136 if (newFileInfoDir == indicatorDir)
135 if (newFileInfoDir == indicatorDir)
137− file_info_location = i;
137+ file_info_location = i;
138 if (currentDataDir == indicatorDir)
139 if (currentDataDir == indicatorDir)
139 current_data_location = i;
141 current_data_location = i;
141 if (file_info_location != -1 && current_data_location != -1)
144 if (file_info_location != -1 && current_data_location != -1)
145 // file location is higher (or of equal) priority. overwrite.
150 // file location is higher (or of equal) priority. overwrite.
@@ -174,7 +179,7 @@ void IndicatorsManager::unload()
174 setLoaded(false);
179 setLoaded(false);
177−void IndicatorsManager::unload(const QFileInfo& file)
182+void IndicatorsManager::unloadFile(const QFileInfo& file)
179 QMutableHashIterator<QString, IndicatorData*> iter(m_indicatorsData);
184 QMutableHashIterator<QString, IndicatorData*> iter(m_indicatorsData);
180 while(iter.hasNext())
185 while(iter.hasNext())
@@ -214,7 +219,9 @@ void IndicatorsManager::startVerify(const QString& path)
214 iter.next();
219 iter.next();
215 IndicatorData* data = iter.value();
220 IndicatorData* data = iter.value();
216 if (data->m_fileInfo.canonicalPath() == path)
221 if (data->m_fileInfo.canonicalPath() == path)
217 data->m_verified = false;
223 data->m_verified = false;
@@ -249,7 +256,9 @@ Indicator::Ptr IndicatorsManager::indicator(const QString& indicator)
250 IndicatorData *data = m_indicatorsData[indicator];
257 IndicatorData *data = m_indicatorsData[indicator];
251 if (data->m_indicator)
258 if (data->m_indicator)
252 return data->m_indicator;
260 return data->m_indicator;
254 Indicator::Ptr plugin(new Indicator(this));
263 Indicator::Ptr plugin(new Indicator(this));
255 data->m_indicator = plugin;
264 data->m_indicator = plugin;