-
Notifications
You must be signed in to change notification settings - Fork 23
/
providers.h
374 lines (283 loc) · 8.24 KB
/
providers.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
/* BEGIN_COMMON_COPYRIGHT_HEADER
* (c)LGPL2+
*
* LXQt - a lightweight, Qt based, desktop toolset
* https://lxqt.org
*
* Copyright: 2010-2011 Razor team
* Authors:
* Alexander Sokoloff <[email protected]>
* Petr Vanek <[email protected]>
*
* This program or library is free software; you can redistribute it
* and/or modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General
* Public License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA
*
* END_COMMON_COPYRIGHT_HEADER */
#ifndef PROVIDERS_H
#define PROVIDERS_H
#include <QList>
#include <QRegularExpression>
#include <QDomElement>
#include <QString>
#include <QIcon>
#ifdef HAVE_MENU_CACHE
#include <menu-cache.h>
#endif
#define MAX_RANK 0xFFFF
/*! The CommandProviderItem class provides an item for use with CommandProvider.
Items usually contain title, comment, toolTip and icon.
*/
class CommandProviderItem: public QObject
{
Q_OBJECT
public:
CommandProviderItem(): QObject() {}
virtual ~CommandProviderItem() {}
virtual bool run() const = 0;
virtual bool compare(const QRegularExpression ®Exp) const = 0;
/// Returns the item's icon.
QIcon icon() const { return mIcon; }
/// Returns the item's title.
QString title() const { return mTitle; }
/// Returns the item's comment.
QString comment() const { return mComment; }
/// Returns the item's tooltip.
QString toolTip() const { return mToolTip; }
/*! The result of this function is used when searching for a apropriate item.
The item with the highest rank will be highlighted.
0 - not suitable.
MAX_RANK - an exact match.
In the most cases you can yse something like:
return stringRank(mTitle, pattern);
*/
virtual unsigned int rank(const QString &pattern) const = 0;
protected:
/// Helper function for the CommandProviderItem::rank
unsigned int stringRank(const QString str, const QString pattern) const;
QIcon mIcon;
QString mTitle;
QString mComment;
QString mToolTip;
};
/*! The CommandProvider class provides task for the lxqt-runner.
*/
class CommandProvider: public QObject, public QList<CommandProviderItem*>
{
Q_OBJECT
public:
CommandProvider();
virtual ~CommandProvider();
virtual void rebuild() {}
virtual bool isOutDated() const { return false; }
signals:
void aboutToBeChanged();
void changed();
};
/************************************************
* Application desktop files
************************************************/
class AppLinkItem: public CommandProviderItem
{
Q_OBJECT
public:
AppLinkItem(const QDomElement &element);
#ifdef HAVE_MENU_CACHE
AppLinkItem(MenuCacheApp* app);
#endif
bool run() const;
bool compare(const QRegularExpression ®Exp) const;
QString command() const { return mCommand; }
QString exec() const { return mExec; }
void operator=(const AppLinkItem &other);
virtual unsigned int rank(const QString &pattern) const;
private slots:
void updateIcon();
private:
void initExec();
private:
QString mDesktopFile;
QString mIconName;
QString mCommand;
QString mExec; //!< the expanded executable (full path) from desktop file Exec key
QString mProgram;
};
class XdgMenu;
class AppLinkProvider: public CommandProvider
{
Q_OBJECT
public:
AppLinkProvider();
virtual ~AppLinkProvider();
private slots:
void update();
private:
#ifdef HAVE_MENU_CACHE
MenuCache* mMenuCache;
MenuCacheNotifyId mMenuCacheNotify;
static void menuCacheReloadNotify(MenuCache* cache, gpointer user_data);
#else
XdgMenu *mXdgMenu;
#endif
};
/************************************************
* History
************************************************/
class HistoryItem: public CommandProviderItem
{
Q_OBJECT
public:
HistoryItem(const QString &command);
bool run() const;
bool compare(const QRegularExpression ®Exp) const;
QString command() const { return mCommand; }
virtual unsigned int rank(const QString &pattern) const;
private:
QString mCommand;
};
class QSettings;
class HistoryProvider: public CommandProvider
{
Q_OBJECT
public:
HistoryProvider();
virtual ~HistoryProvider();
void AddCommand(const QString &command);
void clearHistory();
private:
QSettings *mHistoryFile;
};
/************************************************
* Custom command
************************************************/
class CustomCommandProvider;
class CustomCommandItem: public CommandProviderItem
{
Q_OBJECT
public:
CustomCommandItem(CustomCommandProvider *provider);
bool run() const;
bool compare(const QRegularExpression ®Exp) const;
QString command() const { return mCommand; }
void setCommand(const QString &command);
QString exec() const { return mExec; }
virtual unsigned int rank(const QString &pattern) const;
private:
QString mCommand;
QString mExec; //!< the expanded executable (full path)
CustomCommandProvider *mProvider;
};
class QSettings;
class CustomCommandProvider: public CommandProvider
{
Q_OBJECT
public:
CustomCommandProvider();
QString command() const { return mItem->command(); }
void setCommand(const QString &command) { mItem->setCommand(command); }
HistoryProvider* historyProvider() const { return mHistoryProvider; }
void setHistoryProvider(HistoryProvider *historyProvider) { mHistoryProvider = historyProvider; }
private:
CustomCommandItem *mItem;
HistoryProvider *mHistoryProvider;
};
#ifdef MATH_ENABLED
/************************************************
* Mathematics
************************************************/
class MathItem: public CommandProviderItem
{
Q_OBJECT
public:
class Parser;
public:
MathItem();
~MathItem();
bool run() const;
bool compare(const QRegularExpression ®Exp) const;
virtual unsigned int rank(const QString &pattern) const;
private:
QScopedPointer<Parser> mParser;
mutable QString mCachedInput;
};
class MathProvider: public CommandProvider
{
Q_OBJECT
public:
MathProvider();
//virtual ~MathProvider();
};
#endif
#ifdef VBOX_ENABLED
#include <QDateTime>
#include <QDesktopServices>
#include <QFileInfo>
#include <QMap>
class VirtualBoxItem: public CommandProviderItem
{
Q_OBJECT
public:
VirtualBoxItem(const QString & MachineName , const QIcon & Icon);
void setRDEPort (const QString & portNum);
bool run() const;
bool compare(const QRegularExpression ®Exp) const;
virtual unsigned int rank(const QString &pattern) const;
private:
QString m_rdePortNum;
};
class VirtualBoxProvider: public CommandProvider
{
Q_OBJECT
public:
VirtualBoxProvider ();
void rebuild();
bool isOutDated() const;
private:
QFile fp;
QMap<QString,QString> osIcons;
QString virtualBoxConfig;
QDateTime timeStamp;
};
#endif
class ExternalProviderItem: public CommandProviderItem
{
Q_OBJECT
public:
ExternalProviderItem();
bool setData(QMap<QString, QString> & data);
bool run() const;
bool compare(const QRegularExpression & /*regExp*/) const {return true;} // We leave the decision to the external process
unsigned int rank(const QString &pattern) const;
QString mCommand;
};
class QProcess;
class YamlParser;
class ExternalProvider: public CommandProvider
{
Q_OBJECT
public:
ExternalProvider(const QString name, const QString externalProgram);
void setSearchTerm(const QString searchTerm);
signals:
void dataChanged();
private slots:
void readFromProcess();
void newListOfMaps(QList<QMap<QString, QString> > maps);
private:
QString mName;
QProcess *mExternalProcess;
QTextStream *mDataToProcess;
YamlParser *mYamlParser;
QByteArray mBuffer;
};
#endif // PROVIDERS_H