#include <QObject>
#include <QSettings>
#include "catalog.h"
Go to the source code of this file.
Data Structures | |
class | PluginInterface |
This is the class that a plugin must implement. More... | |
Defines | |
#define | DESKTOP_WINDOWS 0 |
#define | DESKTOP_GNOME 1 |
#define | DESKTOP_KDE 2 |
#define | MSG_GET_ID 0 |
This message asks the Plugin for its ID Number. | |
#define | MSG_GET_LABELS 1 |
This message asks the plugin if it would like to apply a label to the current search query. | |
#define | MSG_GET_RESULTS 2 |
Asks the plugin for any results to a query. | |
#define | MSG_GET_CATALOG 3 |
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). | |
#define | MSG_LAUNCH_ITEM 4 |
This message instructs the plugin that one of its own catalog items was selected by the user and should now be executed. | |
#define | MSG_INIT 5 |
This message informs the plugin that it's being loaded. | |
#define | MSG_HAS_DIALOG 6 |
This message asks the plugin if it has a dialog to display in the options menu. | |
#define | MSG_DO_DIALOG 7 |
This message tells the plugin that it's time to show its user interface. | |
#define | MSG_GET_NAME 8 |
This message asks the plugin for its string name. | |
#define | MSG_END_DIALOG 9 |
This message informs the plugin that it should close its dialog. | |
#define | MSG_LAUNCHY_SHOW 10 |
This message informs the plugin that Launchy is now visible on the screen. | |
#define | MSG_LAUNCHY_HIDE 11 |
This message informs the plugin that Launchy is no longer visible on the screen. | |
#define | MSG_CONTROL_OPTIONS 500 |
#define | MSG_CONTROL_EXIT 501 |
#define | MSG_CONTROL_REBUILD 502 |
Functions | |
void | runProgram (QString file, QString args) |
A convienience run function. | |
int | getDesktop () |
#define DESKTOP_WINDOWS 0 |
Definition at line 46 of file plugin_interface.h.
#define DESKTOP_GNOME 1 |
Definition at line 47 of file plugin_interface.h.
#define DESKTOP_KDE 2 |
Definition at line 48 of file plugin_interface.h.
#define MSG_GET_ID 0 |
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.
wParam | (uint*) That stores the resulting ID number. |
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; }
Definition at line 74 of file plugin_interface.h.
#define MSG_GET_LABELS 1 |
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.
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.
wParam | QList<InputData>* id | |
lParam | NULL |
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; }
Definition at line 130 of file plugin_interface.h.
#define MSG_GET_RESULTS 2 |
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.
wParam | (QList<InputData>*): The user's query | |
lParam | (QList<CatItem>*): The list of existing results for the query, you can append your own |
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; }
Definition at line 178 of file plugin_interface.h.
#define MSG_GET_CATALOG 3 |
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.
wParam | (QList<CatItem>*): The catalog that you append your new entries to (these will be copied over to the primary catalog) 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; } |
Definition at line 216 of file plugin_interface.h.
#define MSG_LAUNCH_ITEM 4 |
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.
wParam | (QList<InputData>*): The user's query | |
lParam | (CatItem*): The user selected catalog item |
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; }
Definition at line 285 of file plugin_interface.h.
#define MSG_INIT 5 |
This message informs the plugin that it's being loaded.
This is a good time to do any initialization work.
wParam | NULL | |
lParam | NULL |
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; }
Definition at line 317 of file plugin_interface.h.
#define MSG_HAS_DIALOG 6 |
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).
wParam | NULL | |
lParam | NULL |
int WebyPlugin::msg(int msgId, void* wParam, void* lParam) { bool handled = false; switch (msgId) { case MSG_HAS_DIALOG: handled = true; break; } return handled; }
Definition at line 343 of file plugin_interface.h.
#define MSG_DO_DIALOG 7 |
This message tells the plugin that it's time to show its user interface.
wParam | (QWidget*): The parent of the dialog to create | |
lParam | (QWidget**): Your plugin's new dialog is returned here for Launchy to keep tabs on it |
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; }
Definition at line 376 of file plugin_interface.h.
#define MSG_GET_NAME 8 |
This message asks the plugin for its string name.
wParam | (QString*) The destination for the name of your plugin | |
lParam | NULL |
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; }
Definition at line 406 of file plugin_interface.h.
#define MSG_END_DIALOG 9 |
This message informs the plugin that it should close its dialog.
wParam | (bool): Whether the plugin should accept changes made by the user while the dialog was open | |
lParam | NULL |
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; }
Definition at line 440 of file plugin_interface.h.
#define MSG_LAUNCHY_SHOW 10 |
This message informs the plugin that Launchy is now visible on the screen.
wParam | NULL | |
lParam | NULL |
Definition at line 449 of file plugin_interface.h.
#define MSG_LAUNCHY_HIDE 11 |
This message informs the plugin that Launchy is no longer visible on the screen.
wParam | NULL | |
lParam | NULL |
Definition at line 457 of file plugin_interface.h.
#define MSG_CONTROL_OPTIONS 500 |
Definition at line 461 of file plugin_interface.h.
#define MSG_CONTROL_EXIT 501 |
Definition at line 462 of file plugin_interface.h.
#define MSG_CONTROL_REBUILD 502 |
Definition at line 463 of file plugin_interface.h.
void runProgram | ( | QString | file, | |
QString | args | |||
) |
A convienience run function.
This function will run the program along with arguments and is platform independent.
file | The location of the file to run | |
args | The arguments to the command |
int getDesktop | ( | ) |