pidgin/quail/qpurple

Add a file type to the ignore list

2013-07-01, Phil Hannent
666792219b0e
Add a file type to the ignore list
#include <QMap>
#include <QDebug>
#include "qpurple.h"
#include "qpurpleionotifier.h"
#include "qpurpletimer.h"
namespace QPurple {
QPurpleCore* myPCore;
/* unique handle for our input events (QPurpleIONotifiers and QPurpleTimers) */
unsigned int unique_handle = 0;
QMap< int , QPurpleIONotifier* > notifierMap;
QMap< int , QPurpleTimer* > timerMap;
QPurpleCore::QPurpleCore()
{
myPCore = this;
}
/* Event loop functions */
guint
QPurpleCore::qpurple_input_add(gint fd,
PurpleInputCondition condition,
PurpleInputFunction function,
gpointer data)
{
PurpleGLibIOClosure *closure = g_new0(PurpleGLibIOClosure, 1);
int handle;
closure->function = function;
closure->data = data;
/* modified from the nullclient source to integrate with Qt */
handle = unique_handle++; /* this will be unique, certainly */
notifierMap[handle] = new QPurpleIONotifier(fd, closure, condition);
return handle;
}
gboolean
QPurpleCore::qpurple_input_remove(guint handle)
{
int toReturn = 0;
QPurpleIONotifier *tmp = notifierMap.take(handle);
if (!tmp->defaultConstructed) {
toReturn = 1;
delete tmp; }
return toReturn;
}
guint
QPurpleCore::qpurple_timer_add(guint interval,
GSourceFunc function,
gpointer data)
{
int handle = unique_handle++;
timerMap[handle] = new QPurpleTimer(function, data, interval);
return handle;
}
guint
QPurpleCore::qpurple_timer_add_seconds(guint interval,
GSourceFunc function,
gpointer data)
{
qDebug() << "qpurple_timer_add_seconds()";
return qpurple_timer_add(interval * 1000,function, data);
}
gboolean
QPurpleCore::qpurple_timer_remove(guint handle)
{
qDebug() << "qpurple_timer_remove()";
int toReturn = 0;
QPurpleTimer *tmp = timerMap.take(handle);
if (!tmp->defaultConstructed) { /* we removed something */
toReturn = 1;
delete tmp; }
return toReturn;
}
static PurpleEventLoopUiOps qpurple_eventloops =
{
&QPurpleCore::qpurple_timer_add,
&QPurpleCore::qpurple_timer_remove,
&QPurpleCore::qpurple_input_add,
&QPurpleCore::qpurple_input_remove,
NULL,
&QPurpleCore::qpurple_timer_add_seconds,
/* padding */
NULL,
NULL,
NULL
};
void
QPurpleCore::qpurple_write_conv(PurpleConversation *conv,
const char *who,
const char *alias,
const char *message,
PurpleMessageFlags flags,
time_t mtime)
{
qDebug() << "qpurple_write_conv()";
Q_UNUSED(alias)
Q_UNUSED(flags)
printf("(%s) %s %s: %s\n", purple_conversation_get_name(conv),
purple_utf8_strftime("(%H:%M:%S)", localtime(&mtime)),
who, message);
}
static PurpleConversationUiOps qpurple_conv_uiops =
{
NULL, /* create_conversation */
NULL, /* destroy_conversation */
NULL, /* write_chat */
NULL, /* write_im */
&QPurpleCore::qpurple_write_conv, /* write_conv */
NULL, /* chat_add_users */
NULL, /* chat_rename_user */
NULL, /* chat_remove_users */
NULL, /* chat_update_user */
NULL, /* present */
NULL, /* has_focus */
NULL, /* custom_smiley_add */
NULL, /* custom_smiley_write */
NULL, /* custom_smiley_close */
NULL, /* send_confirm */
NULL,
NULL,
NULL,
NULL
};
static PurpleBlistUiOps qpurple_blist_ui_ops =
{
&QPurpleCore::qpurple_blist_new_list,
&QPurpleCore::qpurple_blist_new_node,
&QPurpleCore::qpurple_blist_show,
&QPurpleCore::qpurple_blist_update,
&QPurpleCore::qpurple_blist_remove,
&QPurpleCore::qpurple_blist_destroy,
&QPurpleCore::qpurple_blist_set_visible,
&QPurpleCore::qpurple_blist_request_add_buddy,
&QPurpleCore::qpurple_blist_request_add_chat,
&QPurpleCore::qpurple_blist_request_add_group,
NULL,
NULL,
NULL,
NULL
};
void QPurpleCore::qpurple_blist_new_list(PurpleBuddyList *blist)
{
qDebug() << "qpurple_blist_new_list";
myPCore->emit_signal_blist_new_list(blist);
}
void QPurpleCore::qpurple_blist_new_node(PurpleBlistNode *node)
{
qDebug() << "qpurple_blist_new_node";
myPCore->emit_signal_blist_new_node(node);
}
void QPurpleCore::qpurple_blist_show(PurpleBuddyList *list)
{
qDebug() << "qpurple_blist_show";
myPCore->emit_signal_blist_show(list);
}
void QPurpleCore::qpurple_blist_update(PurpleBuddyList *list, PurpleBlistNode *node)
{
qDebug() << "qpurple_blist_update";
myPCore->emit_signal_blist_update(list, node);
}
void QPurpleCore::qpurple_blist_remove(PurpleBuddyList *list, PurpleBlistNode *node)
{
qDebug() << "qpurple_blist_remove";
myPCore->emit_signal_blist_remove(list, node);
}
void QPurpleCore::qpurple_blist_destroy(PurpleBuddyList *list)
{
qDebug() << "qpurple_blist_destroy";
myPCore->emit_signal_blist_destroy(list);
}
void QPurpleCore::qpurple_blist_set_visible(PurpleBuddyList *list, gboolean show)
{
qDebug() << "qpurple_blist_set_visible";
myPCore->emit_signal_blist_set_visible(list, show);
}
void QPurpleCore::qpurple_blist_request_add_buddy(PurpleAccount *account, const char *username,
const char *group, const char *alias)
{
qDebug() << "qpurple_blist_request_add_buddy";
myPCore->emit_signal_blist_request_add_buddy(account, username, group, alias);
}
void QPurpleCore::qpurple_blist_request_add_chat(PurpleAccount *account, PurpleGroup *group,
const char *alias, const char *name)
{
qDebug() << "qpurple_blist_request_add_chat";
myPCore->emit_signal_blist_request_add_chat(account, group, alias, name);
}
void QPurpleCore::qpurple_blist_request_add_group(void)
{
qDebug() << "qpurple_blist_request_add_group";
myPCore->emit_signal_blist_request_add_group();
}
void
QPurpleCore::qpurple_ui_init(void)
{
qDebug() << "qpurple_ui_init()";
/**
* This should initialize the UI components for all the modules. Here we
* just initialize the UI for conversations.
*/
purple_conversations_set_ui_ops(&qpurple_conv_uiops);
purple_blist_set_ui_ops(&qpurple_blist_ui_ops);
}
static PurpleCoreUiOps qpurple_core_uiops =
{
NULL, /* ui_prefs_init */
NULL, /* debug_ui_init */
&QPurpleCore::qpurple_ui_init,
NULL, /* quit */
NULL, /* get_ui_info */
/* padding */
NULL,
NULL,
NULL
};
void
QPurpleCore::_init_libpurple(void)
{
qDebug() << "_init_libpurple()";
/* Set a custom user directory (optional) */
purple_util_set_user_dir(CUSTOM_USER_DIRECTORY);
/* We do not want any debugging for now to keep the noise to a minimum. */
purple_debug_set_enabled(FALSE);
/* Set the core-uiops, which is used to
* - initialize the ui specific preferences.
* - initialize the debug ui.
* - initialize the ui components for all the modules.
* - uninitialize the ui components for all the modules when the core terminates.
*/
purple_core_set_ui_ops(&qpurple_core_uiops);
qDebug() << "qpurple_init().purple_core_set_ui_ops";
/* Set the uiops for the eventloop. If your client is glib-based,
* you can safely copy this verbatim. */
purple_eventloop_set_ui_ops(&qpurple_eventloops);
qDebug() << "qpurple_init().purple_eventloop_set_ui_ops";
/* Set path to search for plugins. The core (libpurple) takes care of loading the
* core-plugins, which includes the protocol-plugins. So it is not essential to add
* any path here, but it might be desired, especially for ui-specific plugins. */
purple_plugins_add_search_path(CUSTOM_PLUGIN_PATH);
/* Now that all the essential stuff has been set, let's try to init the core. It's
* necessary to provide a non-NULL name for the current ui to the core. This name
* is used by stuff that depends on this ui, for example the ui-specific plugins. */
if (!purple_core_init(UI_ID)) {
/* Initializing the core failed. Terminate. */
qDebug() << "qpurple_init() Initializing the core failed. Terminate";
fprintf(stderr,
"libpurple initialization failed. Dumping core.\n"
"Please report this!\n");
abort();
}
/* Create and load the buddylist. */
purple_set_blist(purple_blist_new());
purple_blist_load();
/* Load the preferences. */
purple_prefs_load();
/* Load the desired plugins. The client should save the list of loaded plugins in
* the preferences using purple_plugins_save_loaded(PLUGIN_SAVE_PREF) */
purple_plugins_load_saved(PLUGIN_SAVE_PREF);
/* Load the pounces. */
//purple_pounces_load();
}
void
QPurpleCore::qpurple_init() {
qDebug() << "qpurple_init()";
emit signalDebugMessages("qpurple_init()");
QPurpleCore::_init_libpurple();
}
}