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