Merged pidgin/main into default
[pidgin-git.git] / libpurple / plugins / psychic.c
blob4b5213d9c855c38a558665de1a33a5867164fb9d
3 #include "internal.h"
5 #include "account.h"
6 #include "buddylist.h"
7 #include "conversation.h"
8 #include "debug.h"
9 #include "signals.h"
10 #include "status.h"
11 #include "version.h"
13 #include "plugins.h"
14 #include "pluginpref.h"
15 #include "prefs.h"
18 #define PLUGIN_ID "core-psychic"
19 #define PLUGIN_NAME N_("Psychic Mode")
20 #define PLUGIN_CATEGORY N_("Utility")
21 #define PLUGIN_SUMMARY N_("Psychic mode for incoming conversation")
22 #define PLUGIN_DESC N_("Causes conversation windows to appear as other" \
23 " users begin to message you. This works for" \
24 " AIM, ICQ, XMPP, and Sametime")
25 #define PLUGIN_AUTHORS { "Christopher O'Brien <siege@preoccupied.net>", NULL }
28 #define PREFS_BASE "/plugins/core/psychic"
29 #define PREF_BUDDIES PREFS_BASE "/buddies_only"
30 #define PREF_NOTICE PREFS_BASE "/show_notice"
31 #define PREF_STATUS PREFS_BASE "/activate_online"
32 #define PREF_RAISE PREFS_BASE "/raise_conv"
35 static void
36 buddy_typing_cb(PurpleAccount *acct, const char *name, void *data) {
37 PurpleIMConversation *im;
39 if(purple_prefs_get_bool(PREF_STATUS) &&
40 ! purple_status_is_available(purple_account_get_active_status(acct))) {
41 purple_debug_info("psychic", "not available, doing nothing\n");
42 return;
45 if(purple_prefs_get_bool(PREF_BUDDIES) &&
46 ! purple_blist_find_buddy(acct, name)) {
47 purple_debug_info("psychic", "not in blist, doing nothing\n");
48 return;
51 if(FALSE == purple_account_privacy_check(acct, name)) {
52 purple_debug_info("psychic", "user %s is blocked\n", name);
53 return;
56 im = purple_conversations_find_im_with_account(name, acct);
57 if(! im) {
58 purple_debug_info("psychic", "no previous conversation exists\n");
59 im = purple_im_conversation_new(acct, name);
61 if(purple_prefs_get_bool(PREF_RAISE)) {
62 purple_conversation_present(PURPLE_CONVERSATION(im));
65 if(purple_prefs_get_bool(PREF_NOTICE)) {
67 /* This is a quote from Star Wars. You should probably not
68 translate it literally. If you can't find a fitting cultural
69 reference in your language, consider translating something
70 like this instead: "You feel a new message coming." */
71 purple_conversation_write_system_message(PURPLE_CONVERSATION(im),
72 _("You feel a disturbance in the force..."),
73 PURPLE_MESSAGE_NO_LOG | PURPLE_MESSAGE_ACTIVE_ONLY);
76 /* Necessary because we may be creating a new conversation window. */
77 purple_im_conversation_set_typing_state(im, PURPLE_IM_TYPING);
82 static PurplePluginPrefFrame *
83 get_plugin_pref_frame(PurplePlugin *plugin) {
85 PurplePluginPrefFrame *frame;
86 PurplePluginPref *pref;
88 frame = purple_plugin_pref_frame_new();
90 pref = purple_plugin_pref_new_with_name(PREF_BUDDIES);
91 purple_plugin_pref_set_label(pref, _("Only enable for users on"
92 " the buddy list"));
93 purple_plugin_pref_frame_add(frame, pref);
95 pref = purple_plugin_pref_new_with_name(PREF_STATUS);
96 purple_plugin_pref_set_label(pref, _("Disable when away"));
97 purple_plugin_pref_frame_add(frame, pref);
99 pref = purple_plugin_pref_new_with_name(PREF_NOTICE);
100 purple_plugin_pref_set_label(pref, _("Display notification message in"
101 " conversations"));
102 purple_plugin_pref_frame_add(frame, pref);
104 pref = purple_plugin_pref_new_with_name(PREF_RAISE);
105 purple_plugin_pref_set_label(pref, _("Raise psychic conversations"));
106 purple_plugin_pref_frame_add(frame, pref);
108 return frame;
112 static PurplePluginInfo *
113 plugin_query(GError **error) {
115 const gchar * const authors[] = PLUGIN_AUTHORS;
117 return purple_plugin_info_new(
118 "id", PLUGIN_ID,
119 "name", PLUGIN_NAME,
120 "version", DISPLAY_VERSION,
121 "category", PLUGIN_CATEGORY,
122 "summary", PLUGIN_SUMMARY,
123 "description", PLUGIN_DESC,
124 "authors", authors,
125 "website", PURPLE_WEBSITE,
126 "abi-version", PURPLE_ABI_VERSION,
127 "pref-frame-cb", get_plugin_pref_frame,
128 NULL
133 static gboolean
134 plugin_load(PurplePlugin *plugin, GError **error) {
136 void *convs_handle;
138 purple_prefs_add_none(PREFS_BASE);
139 purple_prefs_add_bool(PREF_BUDDIES, FALSE);
140 purple_prefs_add_bool(PREF_NOTICE, TRUE);
141 purple_prefs_add_bool(PREF_STATUS, TRUE);
143 convs_handle = purple_conversations_get_handle();
145 purple_signal_connect(convs_handle, "buddy-typing", plugin,
146 PURPLE_CALLBACK(buddy_typing_cb), NULL);
148 return TRUE;
152 static gboolean
153 plugin_unload(PurplePlugin *plugin, GError **error) {
155 return TRUE;
159 PURPLE_PLUGIN_INIT(psychic, plugin_query, plugin_load, plugin_unload);