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
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 3.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * 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/>.
20#include "indicatorsmanager.h"
21#include "indicatorsfactory.h"
23#include <QStandardPaths>
28class IndicatorsManager::IndicatorData
31 IndicatorData(const QString& name, const QFileInfo& fileInfo)
33 , m_fileInfo(fileInfo)
41 IndicatorClientInterface::Ptr m_obj;
44IndicatorsManager::IndicatorsManager(QObject* parent)
46, m_factory(new IndicatorsFactory())
50IndicatorsManager::~IndicatorsManager()
55void IndicatorsManager::load()
58 QStringList xdgLocations = QStandardPaths::standardLocations(QStandardPaths::GenericDataLocation);
60 m_fsWatcher.reset(new QFileSystemWatcher(this));
62 Q_FOREACH(const QString& xdgLocation, xdgLocations)
64 QString indicator_path = QDir::cleanPath(xdgLocation + "/unity/indicators");
65 QDir indicator_dir(indicator_path);
66 if (indicator_dir.exists())
68 // watch folder for changes.
69 m_fsWatcher->addPath(indicator_path);
75 QObject::connect(m_fsWatcher.data(), SIGNAL(directoryChanged(const QString&)), this, SLOT(onDirectoryChanged(const QString&)));
76 QObject::connect(m_fsWatcher.data(), SIGNAL(fileChanged(const QString&)), this, SLOT(onFileChanged(const QString&)));
79void IndicatorsManager::onDirectoryChanged(const QString& direcory)
84void IndicatorsManager::onFileChanged(const QString& file)
86 QFileInfo file_info(file);
87 if (!file_info.exists())
94 load(QFileInfo(file));
98void IndicatorsManager::load(const QDir& dir)
100 startVerify(dir.canonicalPath());
102 QFileInfoList indicator_files = dir.entryInfoList(QStringList() << "*.indicator", QDir::Files);
103 Q_FOREACH(const QFileInfo& indicator_file, indicator_files)
105 load(indicator_file);
108 endVerify(dir.canonicalPath());
111void IndicatorsManager::load(const QFileInfo& file_info)
113 QSettings indicator_settings(file_info.absoluteFilePath(), QSettings::IniFormat, this);
114 indicator_settings.beginGroup("Indicator Service");
115 QString name = indicator_settings.value("Name").toString();
117 auto iter = m_indicatorsData.find(name);
118 if (iter != m_indicatorsData.end())
120 QString newFileInfoDir = QDir::cleanPath(file_info.canonicalPath());
121 IndicatorData* currentData = (*iter);
122 currentData->m_verified = true;
124 int file_info_location = -1;
125 int current_data_location = -1;
127 QString currentDataDir = QDir::cleanPath(currentData->m_fileInfo.canonicalPath());
129 // 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
131 QStringList xdgLocations = QStandardPaths::standardLocations(QStandardPaths::GenericDataLocation);
132 for (int i = 0; i < xdgLocations.size(); i++)
134 QString indicatorDir = QDir::cleanPath(xdgLocations[i] + "/unity/indicators");
136 if (newFileInfoDir == indicatorDir)
137 file_info_location = i;
138 if (currentDataDir == indicatorDir)
139 current_data_location = i;
141 if (file_info_location != -1 && current_data_location != -1)
145 // file location is higher (or of equal) priority. overwrite.
146 if (file_info_location <= current_data_location &&
147 file_info != currentData->m_fileInfo)
149 currentData->m_fileInfo = file_info;
155 IndicatorData* data = new IndicatorData(name, file_info);
156 data->m_verified = true;
157 m_indicatorsData[name]= data;
162void IndicatorsManager::unload()
164 QHashIterator<QString, IndicatorData*> iter(m_indicatorsData);
165 while(iter.hasNext())
168 Q_EMIT aboutToBeUnloaded(iter.key());
171 qDeleteAll(m_indicatorsData);
172 m_indicatorsData.clear();
175void IndicatorsManager::unload(const QFileInfo& file)
177 QMutableHashIterator<QString, IndicatorData*> iter(m_indicatorsData);
178 while(iter.hasNext())
181 IndicatorData* data = iter.value();
182 if (data->m_fileInfo.absoluteFilePath() == file.absoluteFilePath())
184 if (!data->m_verified)
186 QString name = data->m_name;
187 Q_EMIT aboutToBeUnloaded(name);
196void IndicatorsManager::startVerify(const QString& path)
198 QHashIterator<QString, IndicatorData*> iter(m_indicatorsData);
199 while(iter.hasNext())
202 IndicatorData* data = iter.value();
203 if (data->m_fileInfo.canonicalPath() == path)
204 data->m_verified = false;
208void IndicatorsManager::endVerify(const QString& path)
210 QMutableHashIterator<QString, IndicatorData*> iter(m_indicatorsData);
211 while(iter.hasNext())
214 IndicatorData* data = iter.value();
215 if (data->m_fileInfo.canonicalPath() == path)
217 if (!data->m_verified)
219 QString name = data->m_name;
220 Q_EMIT aboutToBeUnloaded(name);
229IndicatorClientInterface::Ptr IndicatorsManager::indicator(const QString& indicator)
231 if (!m_indicatorsData.contains(indicator)) {
232 qWarning() << Q_FUNC_INFO << "Invalid plugin name: " << indicator;
236 IndicatorData *data = m_indicatorsData[indicator];
240 IndicatorClientInterface::Ptr plugin = m_factory->create(indicator, this);
243 data->m_obj = plugin;
244 plugin->init(QSettings(data->m_fileInfo.absoluteFilePath(), QSettings::IniFormat, this));
249QList<IndicatorClientInterface::Ptr> IndicatorsManager::indicators()
251 QList<IndicatorClientInterface::Ptr> list;
252 Q_FOREACH(IndicatorData* data, m_indicatorsData)
254 IndicatorClientInterface::Ptr plugin = indicator(data->m_name);
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list