Updated Russian translation
[lxde/liblxqt.git] / lxqtplugininfo.cpp
CommitLineData
4ef6cee9 1/* BEGIN_COMMON_COPYRIGHT_HEADER
c4af778e 2 * (c)LGPL2+
4ef6cee9 3 *
b9223fe7 4 * LXQt - a lightweight, Qt based, desktop toolset
4ef6cee9 5 * http://razor-qt.org
6 *
7 * Copyright: 2010-2011 Razor team
8 * Authors:
626f1f31 9 * Alexander Sokoloff <sokoloff.a@gmail.com>
4ef6cee9 10 *
11 * This program or library is free software; you can redistribute it
12 * and/or modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation; either
c4af778e 14 * version 2.1 of the License, or (at your option) any later version.
4ef6cee9 15 *
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
20
21 * You should have received a copy of the GNU Lesser General
22 * Public License along with this library; if not, write to the
23 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24 * Boston, MA 02110-1301 USA
25 *
26 * END_COMMON_COPYRIGHT_HEADER */
27
28
191d2d13 29#include "lxqtplugininfo.h"
e6389bfc
HJYP
30#include <QObject>
31#include <QFileInfo>
32#include <QDir>
33#include <QTranslator>
34#include <QCoreApplication>
4ef6cee9 35#include <QLibrary>
36#include <QDebug>
37
f05ba5af 38using namespace LXQt;
4ef6cee9 39
40/************************************************
41
42 ************************************************/
191d2d13 43PluginInfo::PluginInfo():
17bfc61e 44 XdgDesktopFile()
4ef6cee9 45{
4ef6cee9 46
4ef6cee9 47}
48
49
50/************************************************
51
52 ************************************************/
191d2d13 53bool PluginInfo::load(const QString& fileName)
4ef6cee9 54{
17bfc61e
AS
55 XdgDesktopFile::load(fileName);
56 mId = QFileInfo(fileName).completeBaseName();
57 return isValid();
4ef6cee9 58}
59
60
61/************************************************
62
63 ************************************************/
191d2d13 64bool PluginInfo::isValid() const
4ef6cee9 65{
17bfc61e 66 return XdgDesktopFile::isValid();
4ef6cee9 67}
68
69
70/************************************************
71
72 ************************************************/
191d2d13 73QLibrary* PluginInfo::loadLibrary(const QString& libDir) const
4ef6cee9 74{
75 QString baseName, path;
17bfc61e
AS
76 QFileInfo fi = QFileInfo(fileName());
77 path = fi.canonicalPath();
f05ba5af 78 baseName = value("X-LXQt-Library", fi.completeBaseName()).toString();
4ef6cee9 79
12f4fe09 80 QString soPath = QDir(libDir).filePath(QString("lib%2.so").arg(baseName));
4ef6cee9 81 QLibrary* library = new QLibrary(soPath);
82
83 if (!library->load())
84 {
85 qWarning() << QString("Can't load plugin lib \"%1\"").arg(soPath) << library->errorString();
86 delete library;
87 return 0;
88 }
89
90 QString locale = QLocale::system().name();
91 QTranslator* translator = new QTranslator(library);
92
93 translator->load(QString("%1/%2/%2_%3.qm").arg(path, baseName, locale));
94 qApp->installTranslator(translator);
95
96 return library;
97}
98
99
100/************************************************
101
102 ************************************************/
191d2d13 103PluginInfoList PluginInfo::search(const QStringList& desktopFilesDirs, const QString& serviceType, const QString& nameFilter)
4ef6cee9 104{
191d2d13 105 QList<PluginInfo> res;
040e9d7f 106 QSet<QString> processed;
4ef6cee9 107
040e9d7f 108 foreach (QString desktopFilesDir, desktopFilesDirs)
4ef6cee9 109 {
040e9d7f
AS
110 QDir dir(desktopFilesDir);
111 QFileInfoList files = dir.entryInfoList(QStringList(nameFilter), QDir::Files | QDir::Readable);
112 foreach (QFileInfo file, files)
113 {
114 if (processed.contains(file.fileName()))
115 continue;
4ef6cee9 116
040e9d7f
AS
117 processed << file.fileName();
118
191d2d13 119 PluginInfo item;
040e9d7f 120 item.load(file.canonicalFilePath());
4ef6cee9 121
040e9d7f
AS
122 if (item.isValid() && item.serviceType() == serviceType)
123 res.append(item);
124 }
125 }
17bfc61e 126 return res;
4ef6cee9 127}
128
129
040e9d7f
AS
130/************************************************
131
132 ************************************************/
191d2d13 133PluginInfoList PluginInfo::search(const QString& desktopFilesDir, const QString& serviceType, const QString& nameFilter)
040e9d7f
AS
134{
135 return search(QStringList(desktopFilesDir), serviceType, nameFilter);
136}
4ef6cee9 137
138
139/************************************************
140
141 ************************************************/
f05ba5af 142QDebug operator<<(QDebug dbg, const LXQt::PluginInfo &pluginInfo)
4ef6cee9 143{
144 dbg.nospace() << QString("%1").arg(pluginInfo.id());
145 return dbg.space();
146}
147
148
149/************************************************
150
151 ************************************************/
f05ba5af 152QDebug operator<<(QDebug dbg, const LXQt::PluginInfo * const pluginInfo)
4ef6cee9 153{
154 return operator<<(dbg, *pluginInfo);
155}
156
157
4ef6cee9 158/************************************************
159
160 ************************************************/
191d2d13 161QDebug operator<<(QDebug dbg, const PluginInfoList& list)
4ef6cee9 162{
163 dbg.nospace() << '(';
164 for (int i=0; i<list.size(); ++i)
165 {
166 if (i) dbg.nospace() << ", ";
167 dbg << list.at(i);
168 }
169 dbg << ')';
170 return dbg.space();
171}
172
173
174/************************************************
175
176 ************************************************/
191d2d13 177QDebug operator<<(QDebug dbg, const PluginInfoList* const pluginInfoList)
4ef6cee9 178{
179 return operator<<(dbg, *pluginInfoList);
180}