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
|
#include "internal.h"
#include "account.h"
#include "blist.h"
#include "conversation.h"
#include "debug.h"
#include "signals.h"
#include "status.h"
#include "version.h"
#include "privacy.h"
#include "plugin.h"
#include "pluginpref.h"
#include "prefs.h"
#define PLUGIN_ID "core-psychic"
#define PLUGIN_NAME N_("Psychic Mode")
#define PLUGIN_SUMMARY N_("Psychic mode for incoming conversation")
#define PLUGIN_DESC N_("Causes conversation windows to appear as other" \
" users begin to message you. This works for" \
" AIM, ICQ, XMPP, Sametime, and Yahoo!")
#define PLUGIN_AUTHOR "Christopher O'Brien <siege@preoccupied.net>"
#define PREFS_BASE "/plugins/core/psychic"
#define PREF_BUDDIES PREFS_BASE "/buddies_only"
#define PREF_NOTICE PREFS_BASE "/show_notice"
#define PREF_STATUS PREFS_BASE "/activate_online"
#define PREF_RAISE PREFS_BASE "/raise_conv"
static void
buddy_typing_cb(PurpleAccount *acct, const char *name, void *data) {
PurpleConversation *gconv;
if(purple_prefs_get_bool(PREF_STATUS) &&
! purple_status_is_available(purple_account_get_active_status(acct))) {
purple_debug_info("psychic", "not available, doing nothing\n");
return;
}
if(purple_prefs_get_bool(PREF_BUDDIES) &&
! purple_find_buddy(acct, name)) {
purple_debug_info("psychic", "not in blist, doing nothing\n");
return;
}
if(FALSE == purple_privacy_check(acct, name)) {
purple_debug_info("psychic", "user %s is blocked\n", name);
return;
}
gconv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM, name, acct);
if(! gconv) {
purple_debug_info("psychic", "no previous conversation exists\n");
gconv = purple_conversation_new(PURPLE_CONV_TYPE_IM, acct, name);
if(purple_prefs_get_bool(PREF_RAISE)) {
purple_conversation_present(gconv);
}
if(purple_prefs_get_bool(PREF_NOTICE)) {
/* This is a quote from Star Wars. You should probably not
translate it literally. If you can't find a fitting cultural
reference in your language, consider translating something
like this instead: "You feel a new message coming." */
purple_conversation_write(gconv, NULL,
_("You feel a disturbance in the force..."),
PURPLE_MESSAGE_SYSTEM | PURPLE_MESSAGE_NO_LOG | PURPLE_MESSAGE_ACTIVE_ONLY,
time(NULL));
}
/* Necessary because we may be creating a new conversation window. */
purple_conv_im_set_typing_state(PURPLE_CONV_IM(gconv), PURPLE_TYPING);
}
}
static PurplePluginPrefFrame *
get_plugin_pref_frame(PurplePlugin *plugin) {
PurplePluginPrefFrame *frame;
PurplePluginPref *pref;
frame = purple_plugin_pref_frame_new();
pref = purple_plugin_pref_new_with_name(PREF_BUDDIES);
purple_plugin_pref_set_label(pref, _("Only enable for users on"
" the buddy list"));
purple_plugin_pref_frame_add(frame, pref);
pref = purple_plugin_pref_new_with_name(PREF_STATUS);
purple_plugin_pref_set_label(pref, _("Disable when away"));
purple_plugin_pref_frame_add(frame, pref);
pref = purple_plugin_pref_new_with_name(PREF_NOTICE);
purple_plugin_pref_set_label(pref, _("Display notification message in"
" conversations"));
purple_plugin_pref_frame_add(frame, pref);
pref = purple_plugin_pref_new_with_name(PREF_RAISE);
purple_plugin_pref_set_label(pref, _("Raise psychic conversations"));
purple_plugin_pref_frame_add(frame, pref);
return frame;
}
static gboolean
plugin_load(PurplePlugin *plugin) {
void *convs_handle;
convs_handle = purple_conversations_get_handle();
purple_signal_connect(convs_handle, "buddy-typing", plugin,
PURPLE_CALLBACK(buddy_typing_cb), NULL);
return TRUE;
}
static PurplePluginUiInfo prefs_info = {
get_plugin_pref_frame,
0, /* page_num (Reserved) */
NULL, /* frame (Reserved) */
/* padding */
NULL,
NULL,
NULL,
NULL
};
static PurplePluginInfo info = {
PURPLE_PLUGIN_MAGIC,
PURPLE_MAJOR_VERSION,
PURPLE_MINOR_VERSION,
PURPLE_PLUGIN_STANDARD, /**< type */
NULL, /**< ui_requirement */
0, /**< flags */
NULL, /**< dependencies */
PURPLE_PRIORITY_DEFAULT, /**< priority */
PLUGIN_ID, /**< id */
PLUGIN_NAME, /**< name */
DISPLAY_VERSION, /**< version */
PLUGIN_SUMMARY, /**< summary */
PLUGIN_DESC, /**< description */
PLUGIN_AUTHOR, /**< author */
PURPLE_WEBSITE, /**< homepage */
plugin_load, /**< load */
NULL, /**< unload */
NULL, /**< destroy */
NULL, /**< ui_info */
NULL, /**< extra_info */
&prefs_info, /**< prefs_info */
NULL, /**< actions */
/* padding */
NULL,
NULL,
NULL,
NULL
};
static void
init_plugin(PurplePlugin *plugin) {
purple_prefs_add_none(PREFS_BASE);
purple_prefs_add_bool(PREF_BUDDIES, FALSE);
purple_prefs_add_bool(PREF_NOTICE, TRUE);
purple_prefs_add_bool(PREF_STATUS, TRUE);
}
PURPLE_INIT_PLUGIN(psychic, init_plugin, info)
|