grim/guifications3

some updates for the removal of gf_gtk_intl.h
cmake
2010-12-13, Gary Kramlich
41894a7595ee
some updates for the removal of gf_gtk_intl.h
/*
* Guifications - The end-all, be-all notification framework
* Copyright (C) 2003-2009 Gary Kramlich <grim@reaperworld.com>
*
* 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 3 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, see <http://www.gnu.org/licenses/>.
*/
#ifdef HAVE_CONFIG_H
# include <gf_config.h>
#endif
#include <math.h>
#include <gflib/gf_lib.h>
/* purple includes */
#ifndef PURPLE_PLUGINS
# define PURPLE_PLUGINS
#endif /* PURPLE_PLUGINS */
#include <plugin.h>
#include <debug.h>
#include <eventloop.h>
#include <version.h>
#include "events.h"
#ifdef ENABLE_NLS
# include <locale.h>
# include <libintl.h>
# define _(x) dgettext(GF_PACKAGE, x)
# ifdef dgettext_noop
# define N_(String) dgettext_noop (GF_PACKAGE, String)
# else
# define N_(String) (String)
# endif
#else
# include <locale.h>
# define N_(String) (String)
# define _(x) (x)
# define ngettext(Singular, Plural, Number) ((Number == 1) ? (Singular) : (Plural))
#endif
/* starting with a retry_factory of 1, we get:
* 2 ^ 1 = 2 * 15000 = 30000 which is 30 seconds. This number
* will grow exponentially, to 60, 120, 240 seconds and so on.
*/
#define CALC_RETRY (15000 * pow(2, retry_factor))
/******************************************************************************
* globals
*****************************************************************************/
static GfClientConnection *connection = NULL;
static GfFeed *feed = NULL, *session_feed = NULL;
static guint connect_id = 0;
static gint retry_factor = 1;
/******************************************************************************
* Helpers
*****************************************************************************/
/* ick prototype, but needed... */
static void connect(void);
static gboolean
reconnect_cb(gpointer data) {
connect();
return FALSE;
}
static void
schedule_reconnect(void) {
if(connect_id == 0)
return;
connect_id = purple_timeout_add(CALC_RETRY, reconnect_cb, NULL);
retry_factor++;
}
static void
connect(void) {
GError *error = NULL;
if(!gf_client_connection_connect(connection, &error)) {
purple_debug_info("guifications",
"Failed to connect to guifications daemon: %s",
(error) ? error->message : "Unknown Error");
connect_id = 0;
schedule_reconnect();
}
}
static void
connected_cb(GfConnection *connection, gpointer data) {
GfFeedManager *manager = NULL;
manager = gf_connection_get_feed_manager(connection);
g_return_if_fail(GF_IS_FEED_MANAGER(manager));
session_feed = gf_feed_manager_register_feed(manager, feed);
}
/******************************************************************************
* Plugin stuff
*****************************************************************************/
static gboolean
gf_load(PurplePlugin *plugin) {
GfImage *image = NULL;
gchar *path;
path = g_build_filename(DATADIR, "pixmaps", "guifications", "purple",
"pidgin.png", NULL);
image = gf_image_new_from_file(path);
g_free(path);
feed = gf_feed_new("Purple", image, _("Purple"),
_("A feed for notifications from the Instant Message "
"library Purple."));
g_object_unref(image);
purple_gf_events_init(feed);
connection = gf_connection_manager_get_default();
if(!connection) {
purple_debug_info("guifications",
"Failed to get the default client connection!\n");
return FALSE;
}
g_signal_connect(G_OBJECT(connection), "connected",
G_CALLBACK(connected_cb), NULL);
connect();
return TRUE;
}
static gboolean
gf_unload(PurplePlugin *plugin) {
return FALSE;
}
static void
gf_destroy(PurplePlugin *plugin) {
GfFeedManager *manager = gf_connection_get_feed_manager(GF_CONNECTION(connection));
gf_feed_manager_unregister_feed(manager, session_feed);
g_object_unref(G_OBJECT(session_feed));
g_object_unref(G_OBJECT(feed));
gf_connection_disconnect(GF_CONNECTION(connection), NULL);
gf_lib_uninit();
}
static PurplePluginInfo gf_info = {
PURPLE_PLUGIN_MAGIC,
PURPLE_MAJOR_VERSION,
PURPLE_MINOR_VERSION,
PURPLE_PLUGIN_STANDARD,
NULL,
0,
NULL,
PURPLE_PRIORITY_DEFAULT,
"core-guifications",
NULL,
GF_VERSION,
NULL,
NULL,
"Gary Kramlich <grim@reaperworld.com>",
GUIFICATIONS_WEBSITE,
gf_load,
gf_unload,
gf_destroy,
NULL,
NULL,
NULL,
NULL,
};
static void
init_plugin(PurplePlugin *plugin) {
#ifdef ENABLE_NLS
bindtextdomain(GF_PACKAGE, LOCALEDIR);
bind_textdomain_codeset(GF_PACKAGE, "UTF-8");
#endif /* ENABLE_NLS */
gf_info.name = _("Guifications 3");
gf_info.summary = _("Guifications 3 Feed Plugin");
gf_info.description = _("Guifications 3 Feed Plugin");
gf_lib_init(NULL, NULL);
}
PURPLE_INIT_PLUGIN(guifications3, init_plugin, gf_info)