Trac is being migrated to new services! Issues can be found in our new YouTrack instance and WIKI pages can be found on our website.

Changes between Version 1 and Version 2 of CHowTo/NotifyAPIHowTo


Ignore:
Timestamp:
Sep 14, 2007, 2:32:30 AM (16 years ago)
Author:
John Bailey
Comment:

A preliminary notify API how-to.

Legend:

Unmodified
Added
Removed
Modified
  • CHowTo/NotifyAPIHowTo

    v1 v2  
    11= Notify API How-To =
    2 This page is a placeholder pending the completion of this document.
     2
     3This document will explain how to use the notify API to enable your libpurple plugins to notify the user of events or other pertinent information.  Again we will assume that you have completed the [wiki:CHowTo/BasicPluginHowto Basic C Plugin Howto].  We'll also continue to assume that you're using Pidgin 2.0.2 for these How-To documents as described there.
     4
     5[[TOC(inline,noheading)]]
     6
     7== About the Notify API ==
     8The notify API is a rather large API, which this plugin will ''not'' cover in its entirety.  The portions that we cover here allow your plugin to make the UI notify the user of some event or other noteworthy information.  Most of the functions that we'll explore here present dialogs in Pidgin, but one causes Pidgin to open a URI in the appropriate application.
     9
     10Surely by now, some readers are wondering why this How-To is leaving out sections of the notify API.  The purpose of this document is to introduce you to the basic toolset and allow you the opportunity to grow on your own, learning the API as you need it to do more advanced plugin development.  Additional How-To documents may appear in the future to cover the other sections of the notify API, as well.
     11
     12== Using This Part of the Notify API ==
     13If you read the API documentation for [http://developer.pidgin.im/doxygen/dev/html/notify_8h.html notify.h], you will see that most of the functions we explore here call for some common arguments.  Here is the list and their explanations:
     14 * '''`handle`''' - a UI-specific or plugin-specific handle for use by the notify API.  Generally, you will feed this argument the `PurplePlugin *` for your plugin.
     15 * '''`title`''' - the title for the notification.  The handling of this may vary depending on a number of factors.
     16 * '''`primary`''' - the primary text of the notification.  This text generally appears as larger and bold-faced when compared to the secondary text.  You will generally make this a concise message, such as "Error reading file!"
     17 * '''`secondary`''' - the secondary text of the notification.  This text generally appears as smaller and plain when compared to the primary text.  You will generally make this a more detailed message, such as "Couldn't open file /path/to/foo for reading: No such file or directory."
     18
     19== Writing the Example Plugin ==
     20For this document we're going to have yet another new example plugin.  This one will be called `notify_example.c` and will also live in `~/development/pidgin-2.0.2/libpurple/plugins`.  By now, the entirety of the plugin facilities used here, save for the `purple_notify_*` function calls, should be familiar to you, so we'll skip the fanfare and get to the meat of the plugin:
     21
     22{{{
     23#!c
     24#include <glib.h>
     25
     26# define PURPLE_PLUGINS
     27
     28#define PLUGIN_ID "core-notifyexample"
     29#define PLUGIN_AUTHOR "John Bailey <rekkanoryo@cpw.pidgin.im>"
     30
     31#include <notify.h>
     32#include <plugin.h>
     33#include <version.h>
     34
     35static PurplePlugin *notify_example = NULL;
     36
     37/* The next four functions and the calls within them should cause dialog boxes to appear
     38 * when you select the plugin action from the Tools->Notify Example menu */
     39static void
     40notify_error_cb(PurplePluginAction *action)
     41{
     42    purple_notify_error(notify_example, "Test Notification", "Test Notification",
     43        "This is a test error notification");
     44}
     45
     46static void
     47notify_info_cb(PurplePluginAction *action)
     48{
     49    purple_notify_info(notify_example, "Test Notification", "Test Notification",
     50        "This is a test informative notification");
     51}
     52
     53static void
     54notify_warn_cb(PurplePluginAction *action)
     55{
     56    purple_notify_warning(notify_example, "Test Notification", "Test Notification",
     57        "This is a test warning notification");
     58}
     59
     60static void
     61notify_format_cb(PurplePluginAction *action)
     62{
     63    purple_notify_formatted(notify_example, "Test Notification", "Test Notification",
     64        "Test Notification",
     65        "<I>This is a test notification with formatted text.</I>", NULL, NULL);
     66}
     67
     68static void
     69notify_uri_cb(PurplePluginAction *action)
     70{
     71    /* This one should open your web browser of choice. */
     72    purple_notify_uri(notify_example, "http://www.pidgin.im/");
     73}
     74
     75static GList *
     76plugin_actions(PurplePlugin *plugin, gpointer context)
     77{
     78    GList *actions = NULL;
     79
     80    /* Here we take advantage of return values to avoid the need for a temp variable */
     81    actions = g_list_prepend(actions,
     82        purple_plugin_action_new("Show Error Notification", notify_error_cb));
     83
     84    actions = g_list_prepend(actions,
     85        purple_plugin_action_new("Show Info Notification", notify_info_cb));
     86
     87    actions = g_list_prepend(actions,
     88        purple_plugin_action_new("Show Warning Notification", notify_warn_cb));
     89
     90    actions = g_list_prepend(actions,
     91        purple_plugin_action_new("Show Formatted Notification", notify_format_cb));
     92
     93    actions = g_list_prepend(actions,
     94        purple_plugin_action_new("Show URI Notification", notify_uri_cb));
     95
     96    return g_list_reverse(actions);
     97}
     98
     99static gboolean
     100plugin_load(PurplePlugin *plugin)
     101{
     102    notify_example = plugin;
     103
     104    return TRUE;
     105}
     106
     107static PurplePluginInfo info = {
     108    PURPLE_PLUGIN_MAGIC,        /* magic number */
     109    PURPLE_MAJOR_VERSION,       /* purple major */
     110    PURPLE_MINOR_VERSION,       /* purple minor */
     111    PURPLE_PLUGIN_STANDARD,     /* plugin type */
     112    NULL,                       /* UI requirement */
     113    0,                          /* flags */
     114    NULL,                       /* dependencies */
     115    PURPLE_PRIORITY_DEFAULT,    /* priority */
     116
     117    PLUGIN_ID,                  /* id */
     118    "Notify API Example",       /* name */
     119    VERSION,                    /* version */
     120    "Notify API Example",       /* summary */
     121    "Notify API Example",       /* description */
     122    PLUGIN_AUTHOR,              /* author */
     123    "http://pidgin.im",         /* homepage */
     124
     125    plugin_load,                /* load */
     126    NULL,                       /* unload */
     127    NULL,                       /* destroy */
     128
     129    NULL,                       /* ui info */
     130    NULL,                       /* extra info */
     131    NULL,                       /* prefs info */
     132    plugin_actions,             /* actions */
     133    NULL,                       /* reserved */
     134    NULL,                       /* reserved */
     135    NULL,                       /* reserved */
     136    NULL                        /* reserved */
     137};
     138
     139static void
     140init_plugin(PurplePlugin *plugin)
     141{
     142}
     143
     144PURPLE_INIT_PLUGIN(notifyexample, init_plugin, info)
     145}}}
     146
     147== Compiling, Installing, and Testing the Plugin ==
     148As before, run make notify_example.so (make -f Makefile.mingw notify_example.dll for you Windows types) to build the plugin. Copy the resulting notify_example.so to ~/.purple/plugins, or copy the resulting notify_example.dll to %APPDATA%\.purple\plugins.
     149
     150Once this is done, load the plugin in Pidgin, then go to Tools->Notify Example and look one by one at the dialogs resulting from selecting each action.  Dismiss them whenever you please.
     151
     152== Beyond the Notify API ==
     153The notify API provides a basic notification framework for plugins, which can be an extremely valuable resource to plugin authors.  The other areas we didn't cover here include much of the true power of the notify API, but we will leave those as an area for your exploration at least for now.  This document is done, but there are still others in the [wiki:CHowTo C Plugin How-To] for you to explore!
All information, including names and email addresses, entered onto this website or sent to mailing lists affiliated with this website will be public. Do not post confidential information, especially passwords!