Use more portable Qt and qtxdg header names
[lxde/liblxqt.git] / lxqtplugininfo.h
1 /* BEGIN_COMMON_COPYRIGHT_HEADER
2 * (c)LGPL2+
3 *
4 * LXDE-Qt - a lightweight, Qt based, desktop toolset
5 * http://razor-qt.org
6 *
7 * Copyright: 2010-2011 Razor team
8 * Authors:
9 * Alexander Sokoloff <sokoloff.a@gmail.com>
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
14 * version 2.1 of the License, or (at your option) any later version.
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
29 #ifndef LXQTPLUGININFO_H
30 #define LXQTPLUGININFO_H
31
32 #include <QString>
33 #include <QList>
34
35 #include <QFileInfo>
36 #include <QtAlgorithms>
37 #include <QDebug>
38 #include "lxqtglobals.h"
39
40 #include <XdgDesktopFile>
41
42 class QLibrary;
43
44 namespace LxQt
45 {
46
47 /*!
48 Every plugin needs a .desktop file that describes it. The basename of this file must
49 be same as the basename of the plugin library.
50
51 lxqtpanel_clock2.desktop file
52
53 [Desktop Entry]
54 Type=Service
55 ServiceTypes=LxQtPanel/Plugin
56 Name=Clock
57 Comment=Clock and calendar
58
59 PluginInfo class gives the interface for reading the values from the plugin .desktop file.
60 This is a pure virtual class, you must implement libraryDir(), translationDir(), and instance() methods.
61 */
62 class LXQT_API PluginInfo: public XdgDesktopFile
63 {
64 public:
65 /// Constructs a PluginInfo object for accessing the info stored in the .desktop file.
66 explicit PluginInfo();
67
68 //! Reimplemented from XdgDesktopFile.
69 virtual bool load(const QString& fileName);
70
71
72 //! Reimplemented from XdgDesktopFile.
73 //PluginInfo& operator=(const PluginInfo& other);
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.
86 @parm libDir directory where placed the plugin .so file. */
87 QLibrary* loadLibrary(const QString& libDir) const;
88
89
90 /*! Returns a list of PluginInfo objects for the matched files in the directories.
91 @param desktopFilesDirs - scanned directories names.
92 @param serviceType - type of the plugin, for example "LxQtPanel/Plugin".
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 */
97 static QList<PluginInfo> search(const QStringList& desktopFilesDirs, const QString& serviceType, const QString& nameFilter="*");
98
99 /// This function is provided for convenience. It's equivalent to new calling search(QString(desktopFilesDir), serviceType, nameFilter)
100 static QList<PluginInfo> search(const QString& desktopFilesDir, const QString& serviceType, const QString& nameFilter="*");
101
102 private:
103 QString mId;
104 };
105
106 typedef QList<PluginInfo> PluginInfoList;
107
108 } // namespace LxQt
109
110 QDebug operator<<(QDebug dbg, const LxQt::PluginInfo& pi);
111 QDebug operator<<(QDebug dbg, const LxQt::PluginInfo* const pi);
112
113 QDebug operator<<(QDebug dbg, const LxQt::PluginInfoList& list);
114 QDebug operator<<(QDebug dbg, const LxQt::PluginInfoList* const pluginInfoList);
115
116 #endif // LXQTPLUGININFO_H