Make lxqt globals a public header
[lxde/liblxqt.git] / lxqtplugininfo.h
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
AS
29#ifndef LXQTPLUGININFO_H
30#define LXQTPLUGININFO_H
4ef6cee9 31
e6389bfc
HJYP
32#include <QString>
33#include <QList>
4ef6cee9 34
e6389bfc
HJYP
35#include <QFileInfo>
36#include <QtAlgorithms>
37#include <QDebug>
f9cba1ba 38#include "lxqtglobals.h"
4ef6cee9 39
e6389bfc 40#include <XdgDesktopFile>
afd3b116 41
4ef6cee9 42class QLibrary;
43
f05ba5af 44namespace LXQt
191d2d13
AS
45{
46
4ef6cee9 47/*!
48Every plugin needs a .desktop file that describes it. The basename of this file must
49be same as the basename of the plugin library.
50
db4aaddf 51lxqtpanel_clock2.desktop file
4ef6cee9 52
53[Desktop Entry]
54 Type=Service
f05ba5af 55 ServiceTypes=LXQtPanel/Plugin
4ef6cee9 56 Name=Clock
57 Comment=Clock and calendar
58
191d2d13 59PluginInfo class gives the interface for reading the values from the plugin .desktop file.
4ef6cee9 60This is a pure virtual class, you must implement libraryDir(), translationDir(), and instance() methods.
61*/
f9cba1ba 62class LXQT_API PluginInfo: public XdgDesktopFile
4ef6cee9 63{
4ef6cee9 64public:
191d2d13
AS
65 /// Constructs a PluginInfo object for accessing the info stored in the .desktop file.
66 explicit PluginInfo();
4ef6cee9 67
68 //! Reimplemented from XdgDesktopFile.
17bfc61e
AS
69 virtual bool load(const QString& fileName);
70
4ef6cee9 71
72 //! Reimplemented from XdgDesktopFile.
191d2d13 73 //PluginInfo& operator=(const PluginInfo& other);
4ef6cee9 74
75
76 //! Returns identification string of this plugin, identified plugin type. Now id is part of the filename.
77 QString id() const { return mId; }
78
79 //! This function is provided for convenience. It's equivalent to calling value("ServiceTypes").toString().
80 QString serviceType() const { return value("ServiceTypes").toString(); }
81
82 //! Reimplemented from XdgDesktopFile.
83 virtual bool isValid() const;
84
85 /*! Loads the library and returns QLibrary object if the library was loaded successfully; otherwise returns 0.
17bfc61e 86 @parm libDir directory where placed the plugin .so file. */
4ef6cee9 87 QLibrary* loadLibrary(const QString& libDir) const;
88
4ef6cee9 89
191d2d13 90 /*! Returns a list of PluginInfo objects for the matched files in the directories.
040e9d7f 91 @param desktopFilesDirs - scanned directories names.
f05ba5af 92 @param serviceType - type of the plugin, for example "LXQtPanel/Plugin".
040e9d7f
AS
93 @param nameFilter - wildcard filter that understands * and ? wildcards.
94
95 If the same filename is located under multiple directories only the first file should be used.
96 */
191d2d13 97 static QList<PluginInfo> search(const QStringList& desktopFilesDirs, const QString& serviceType, const QString& nameFilter="*");
040e9d7f
AS
98
99 /// This function is provided for convenience. It's equivalent to new calling search(QString(desktopFilesDir), serviceType, nameFilter)
191d2d13 100 static QList<PluginInfo> search(const QString& desktopFilesDir, const QString& serviceType, const QString& nameFilter="*");
040e9d7f 101
17bfc61e
AS
102private:
103 QString mId;
4ef6cee9 104};
105
191d2d13 106typedef QList<PluginInfo> PluginInfoList;
17bfc61e 107
f05ba5af 108} // namespace LXQt
4ef6cee9 109
f05ba5af
PL
110QDebug operator<<(QDebug dbg, const LXQt::PluginInfo& pi);
111QDebug operator<<(QDebug dbg, const LXQt::PluginInfo* const pi);
4ef6cee9 112
f05ba5af
PL
113QDebug operator<<(QDebug dbg, const LXQt::PluginInfoList& list);
114QDebug operator<<(QDebug dbg, const LXQt::PluginInfoList* const pluginInfoList);
4ef6cee9 115
191d2d13 116#endif // LXQTPLUGININFO_H