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 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579
|
/*
Launchy: Application Launcher
Copyright (C) 2007 Josh Karlin
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef PLUGIN_INTERFACE_H
#define PLUGIN_INTERFACE_H
#include <QObject>
#include <QSettings>
#include "catalog.h"
#ifdef Q_WS_WIN
#define VC_EXTRALEAN
#ifndef WINVER
#define WINVER 0x05100
#define _WIN32_WINNT 0x0510
#define _WIN32_WINDOWS 0x0510
#define _WIN32_IE 0x0600
#endif
#include <windows.h>
#include <shlobj.h>
#endif
#ifndef UNICODE
#define UNICODE
#endif
#define DESKTOP_WINDOWS 0
#define DESKTOP_GNOME 1
#define DESKTOP_KDE 2
/**
\brief This message asks the Plugin for its ID Number.
Launchy needs an unsigned int identification value for each loaded plugin. You supply your own here.
Typically, this is the result of hashing a string, as shown in the example below.
\param wParam (uint*) That stores the resulting ID number.
\warning Because we're hashing strings to integers.. it is theoretically possible that two plugin names will collide to the same plugin id.
\verbatim
int WebyPlugin::msg(int msgId, void* wParam, void* lParam)
{
bool handled = false;
switch (msgId)
{
case MSG_GET_ID:
*wParam = qHash(QString("Weby_Plugin"))
handled = true;
break;
}
return handled;
}
\endverbatim
*/
#define MSG_GET_ID 0
/**
\brief This message asks the plugin if it would like to apply a label to the current search query.
It is sometimes useful to label user queries with plugin-defined tags. For instance, the weby plugin
will tag input that contains "www" or ".com" or ".net" with the hash value of the string "HASH_WEBSITE". Then,
other plugins that see the query can know that the current search is for a website.\n\n
The InputData class stores the current user's query. It is in a List structure because each time "tab" is pressed by the user
a new InputData is formed and appended to the list. In other words, if the user typed "google <tab> this is my query" then
wParam would represent a list of 2 InputData classes, with the first representing "google", and the second, "this is my query". Each InputData
can be tagged individually.
\warning This is called each time the user changes a character in his or her query, so make sure it's fast.
\param wParam QList<InputData>* id
\param lParam NULL
\verbatim
void WebyPlugin::getLabels(QList<InputData>* id)
{
if (id->count() > 1)
return;
// Apply a "website" label if we think it's a website
QString & text = id->last().getText();
if (text.contains("http://", Qt::CaseInsensitive))
id->last().setLabel(HASH_WEBSITE);
else if (text.contains("https://", Qt::CaseInsensitive))
id->last().setLabel(HASH_WEBSITE);
else if (text.contains(".com", Qt::CaseInsensitive))
id->last().setLabel(HASH_WEBSITE);
else if (text.contains(".net", Qt::CaseInsensitive))
id->last().setLabel(HASH_WEBSITE);
else if (text.contains(".org", Qt::CaseInsensitive))
id->last().setLabel(HASH_WEBSITE);
else if (text.contains("www.", Qt::CaseInsensitive))
id->last().setLabel(HASH_WEBSITE);
}
int WebyPlugin::msg(int msgId, void* wParam, void* lParam)
{
bool handled = false;
switch (msgId)
{
case MSG_GET_LABELS:
getLabels((QList<InputData>*) wParam);
handled = true;
break;
}
return handled;
}
\endverbatim
*/
#define MSG_GET_LABELS 1
/**
\brief Asks the plugin for any results to a query
If your plugin returns catalog results on the fly to a query
(e.g. a website query for weby or a calculator result), then this is the place to do so.
The existing results are stored in the list of CatItem's (short for Catalog Items) passed in as
lParam and you can append your own results to it.
\param wParam (QList<InputData>*): The user's query
\param lParam (QList<CatItem>*): The list of existing results for the query, you can append your own
\verbatim
void WebyPlugin::getResults(QList<InputData>* id, QList<CatItem>* results)
{
// Is this query a website? If so create a new result for the website
if (id->last().hasLabel(HASH_WEBSITE)) {
QString & text = id->last().getText();
// This is a website, create an entry for it
results->push_front(CatItem(text + ".weby", text, HASH_WEBY, getIcon()));
}
// Is this query of form: website <tab> search_term?
if (id->count() > 1 && id->first().getTopResult().id == HASH_WEBY) {
QString & text = id->last().getText();
// This is user search text, create an entry for it
results->push_front(CatItem(text + ".weby", text, HASH_WEBY, getIcon()));
}
}
int WebyPlugin::msg(int msgId, void* wParam, void* lParam)
{
bool handled = false;
switch (msgId)
{
case MSG_GET_RESULTS:
getResults((QList<InputData>*) wParam, (QList<CatItem>*) lParam);
handled = true;
break;
}
return handled;
}
\endverbatim
*/
#define MSG_GET_RESULTS 2
/**
\brief Asks the plugin for a static catalog to be added to the primary catalog
Some plugins will add permanent entries to Launchy's primary catalog (until the catalog is rebuilt).
For instance, weby adds firefox bookmarks into the primary catalog. This is the function in which that is done.
\param wParam (QList<CatItem>*): The catalog that you append your new entries to (these will be copied over to the primary catalog)
\verbatim
void WebyPlugin::getCatalog(QList<CatItem>* items)
{
// Add the default websites to the catalog "google/amazon/etc.."
foreach(WebySite site, sites) {
items->push_back(CatItem(site.name + ".weby", site.name, HASH_WEBY, getIcon()));
}
// If we're supposed to index firefox, then do that there
if ((*settings)->value("weby/firefox", true).toBool()) {
QString path = getFirefoxPath();
indexFirefox(path, items);
}
}
int WebyPlugin::msg(int msgId, void* wParam, void* lParam)
{
bool handled = false;
switch (msgId)
{
case MSG_GET_CATALOG:
getCatalog((QList<CatItem>*) wParam);
handled = true;
break;
}
return handled;
}
\endverbatim
*/
#define MSG_GET_CATALOG 3
/**
\brief This message instructs the plugin that one of its own catalog items was selected by the user and should now be executed
If the plugin adds items to the catalog via MSG_GET_RESULTS or MSG_GET_CATALOG and one of those items is selected by the user
then it is up to the plugin to execute it when the user presses "enter". This is where you perform the action.
\param wParam (QList<InputData>*): The user's query
\param lParam (CatItem*): The user selected catalog item
\verbatim
void WebyPlugin::launchItem(QList<InputData>* id, CatItem* item)
{
QString file = "";
QString args = "";
if (id->count() == 2) {
args = id->last().getText();
args = QUrl::toPercentEncoding(args);
item = &id->first().getTopResult();
}
// Is it a Firefox shortcut?
if (item->fullPath.contains(".shortcut")) {
file = item->fullPath.mid(0, item->fullPath.count()-9);
file.replace("%s", args);
}
else { // It's a user-specific site
bool found = false;
foreach(WebySite site, sites) {
if (item->shortName == site.name) {
found = true;
file = site.base;
if (args != "") {
QString tmp = site.query;
tmp.replace("%s", args);
file += tmp;
}
break;
}
}
if (!found) {
file = item->shortName;
if (!file.contains("http://")) {
file = "http://" + file;
}
}
}
QUrl url(file);
runProgram(url.toEncoded(), "");
}
int WebyPlugin::msg(int msgId, void* wParam, void* lParam)
{
bool handled = false;
switch (msgId)
{
case MSG_LAUNCH_ITEM:
launchItem((QList<InputData>*) wParam, (CatItem*) lParam);
handled = true;
break;
}
return handled;
}
\endverbatim
*/
#define MSG_LAUNCH_ITEM 4
/**
\brief This message informs the plugin that it's being loaded. This is a good time to do any initialization work.
\param wParam NULL
\param lParam NULL
\verbatim
void calcyPlugin::init()
{
// Do some initialization here if necessary..
}
int CalcyPlugin::msg(int msgId, void* wParam, void* lParam)
{
bool handled = false;
switch (msgId)
{
case MSG_INIT:
init();
handled = true;
break;
}
return handled;
}
\endverbatim
*/
#define MSG_INIT 5
/**
\brief This message asks the plugin if it has a dialog to display in the options menu.
The result of the request is returned via the result of the msg function (handled).
\param wParam NULL
\param lParam NULL
\verbatim
int WebyPlugin::msg(int msgId, void* wParam, void* lParam)
{
bool handled = false;
switch (msgId)
{
case MSG_HAS_DIALOG:
handled = true;
break;
}
return handled;
}
\endverbatim
*/
#define MSG_HAS_DIALOG 6
/**
\brief This message tells the plugin that it's time to show its user interface
\param wParam (QWidget*): The parent of the dialog to create
\param lParam (QWidget**): Your plugin's new dialog is returned here for Launchy to keep tabs on it
\verbatim
void WebyPlugin::doDialog(QWidget* parent, QWidget** newDlg) {
// gui is a private member variable of class WebyPlugin
if (gui != NULL) return;
// class Gui is weby's user interface class
gui = new Gui(parent);
*newDlg = gui;
}
int WebyPlugin::msg(int msgId, void* wParam, void* lParam)
{
bool handled = false;
switch (msgId)
{
case MSG_DO_DIALOG:
doDialog((QWidget*) wParam, (QWidget**) lParam);
break;
}
return handled;
}
\endverbatim
*/
#define MSG_DO_DIALOG 7
/**
\brief This message asks the plugin for its string name
\param wParam (QString*) The destination for the name of your plugin
\param lParam NULL
\verbatim
void WebyPlugin::getName(QString* str)
{
*str = "Weby";
}
int WebyPlugin::msg(int msgId, void* wParam, void* lParam)
{
bool handled = false;
switch (msgId)
{
case MSG_GET_NAME:
getName((QString*) wParam);
handled = true;
break;
}
return handled;
}
\endverbatim
*/
#define MSG_GET_NAME 8
/**
\brief This message informs the plugin that it should close its dialog
\param wParam (bool): Whether the plugin should accept changes made by the user while the dialog was open
\param lParam NULL
\verbatim
void WebyPlugin::endDialog(bool accept) {
if (accept) {
gui->writeOptions();
init();
}
if (gui != NULL)
delete gui;
gui = NULL;
}
int WebyPlugin::msg(int msgId, void* wParam, void* lParam)
{
bool handled = false;
switch (msgId)
{
case MSG_END_DIALOG:
endDialog((bool) wParam);
break;
}
return handled;
}
\endverbatim
*/
#define MSG_END_DIALOG 9
/**
\brief This message informs the plugin that Launchy is now visible on the screen.
\param wParam NULL
\param lParam NULL
*/
#define MSG_LAUNCHY_SHOW 10
/**
\brief This message informs the plugin that Launchy is no longer visible on the screen.
\param wParam NULL
\param lParam NULL
*/
#define MSG_LAUNCHY_HIDE 11
#define MSG_CONTROL_OPTIONS 500
#define MSG_CONTROL_EXIT 501
#define MSG_CONTROL_REBUILD 502
/**
\brief This is the class that a plugin must implement.
The PluginInterface is the interface between Launchy and your plugin.
Launchy communicates with your plugin through the msg function. To store
any settings in Launchy's permanent configuration file, please
refer to the settings member variable.
*/
class PluginInterface
{
public:
virtual ~PluginInterface() {};
/**
\brief This is how messages are passed to the plugin
Here you handle the subset of messages that your plugin requires. At minimum, your plugin must
handle MSG_GET_ID and MSG_GET_NAME. For unhandled messages, return 0. For handled messages, return 1.
\param msgId The type of the message, such as show dialog, initialize, or get results
\param wParam If this message type requires any parameters, this will be the first and casted to void*
\param lParam If this message requires two parameters, this is the second, casted to void*
\return 1 means the message was handled, 0 means it was ignored
\verbatim
int WebyPlugin::msg(int msgId, void* wParam, void* lParam)
{
bool handled = false;
switch (msgId)
{
case MSG_INIT:
init();
handled = true;
break;
case MSG_GET_LABELS:
getLabels((QList<InputData>*) wParam);
handled = true;
break;
case MSG_GET_ID:
getID((uint*) wParam);
handled = true;
break;
case MSG_GET_NAME:
getName((QString*) wParam);
handled = true;
break;
case MSG_GET_RESULTS:
getResults((QList<InputData>*) wParam, (QList<CatItem>*) lParam);
handled = true;
break;
case MSG_GET_CATALOG:
getCatalog((QList<CatItem>*) wParam);
handled = true;
break;
case MSG_LAUNCH_ITEM:
launchItem((QList<InputData>*) wParam, (CatItem*) lParam);
handled = true;
break;
case MSG_HAS_DIALOG:
handled = true;
break;
case MSG_DO_DIALOG:
doDialog((QWidget*) wParam, (QWidget**) lParam);
break;
case MSG_END_DIALOG:
endDialog((bool) wParam);
break;
default:
break;
}
return handled;
}
\endverbatim
*/
virtual int msg(int msgId, void* wParam = NULL, void* lParam = NULL) = 0;
/** The setting manager in which you store your persistent data. More data can be found in QT's documentation for QSettings
Following is an example of using the settings variable:
\verbatim
QSettings* set = *settings;
// Write a value to the config file
set->setValue("weby/version", 1.0);
// Read a value from the config value
double value = set->value("weby/version", 0.0);
\endverbatim
*/
QSettings** settings;
};
/**
\brief A convienience run function
This function will run the program along with arguments and is platform independent.
\param file The location of the file to run
\param args The arguments to the command
*/
void runProgram(QString file, QString args);
int getDesktop();
Q_DECLARE_INTERFACE(PluginInterface,
"net.launchy.PluginInterface/1.0")
#endif
|