Make return clearer
[pidgin-git.git] / libpurple / plugins / psychic.c
blob4d6f89b6d762e73adadc90795762b4706be186af
1 /*
2 * This program is free software; you can redistribute it and/or
3 * modify it under the terms of the GNU General Public License as
4 * published by the Free Software Foundation; either version 2 of the
5 * License, or (at your option) any later version.
7 * This program is distributed in the hope that it will be useful, but
8 * WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 * General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
15 * 02111-1301, USA.
18 #include "internal.h"
19 #include <purple.h>
21 #define PLUGIN_ID "core-psychic"
22 #define PLUGIN_NAME N_("Psychic Mode")
23 #define PLUGIN_CATEGORY N_("Utility")
24 #define PLUGIN_SUMMARY N_("Psychic mode for incoming conversation")
25 #define PLUGIN_DESC N_("Causes conversation windows to appear as other" \
26 " users begin to message you. This works for" \
27 " AIM, ICQ, XMPP, and Sametime")
28 #define PLUGIN_AUTHORS { "Christopher O'Brien <siege@preoccupied.net>", NULL }
31 #define PREFS_BASE "/plugins/core/psychic"
32 #define PREF_BUDDIES PREFS_BASE "/buddies_only"
33 #define PREF_NOTICE PREFS_BASE "/show_notice"
34 #define PREF_STATUS PREFS_BASE "/activate_online"
35 #define PREF_RAISE PREFS_BASE "/raise_conv"
38 static void
39 buddy_typing_cb(PurpleAccount *acct, const char *name, void *data) {
40 PurpleIMConversation *im;
42 if(purple_prefs_get_bool(PREF_STATUS) &&
43 ! purple_status_is_available(purple_account_get_active_status(acct))) {
44 purple_debug_info("psychic", "not available, doing nothing\n");
45 return;
48 if(purple_prefs_get_bool(PREF_BUDDIES) &&
49 ! purple_blist_find_buddy(acct, name)) {
50 purple_debug_info("psychic", "not in blist, doing nothing\n");
51 return;
54 if(FALSE == purple_account_privacy_check(acct, name)) {
55 purple_debug_info("psychic", "user %s is blocked\n", name);
56 return;
59 im = purple_conversations_find_im_with_account(name, acct);
60 if(! im) {
61 purple_debug_info("psychic", "no previous conversation exists\n");
62 im = purple_im_conversation_new(acct, name);
64 if(purple_prefs_get_bool(PREF_RAISE)) {
65 purple_conversation_present(PURPLE_CONVERSATION(im));
68 if(purple_prefs_get_bool(PREF_NOTICE)) {
70 /* This is a quote from Star Wars. You should probably not
71 translate it literally. If you can't find a fitting cultural
72 reference in your language, consider translating something
73 like this instead: "You feel a new message coming." */
74 purple_conversation_write_system_message(PURPLE_CONVERSATION(im),
75 _("You feel a disturbance in the force..."),
76 PURPLE_MESSAGE_NO_LOG | PURPLE_MESSAGE_ACTIVE_ONLY);
79 /* Necessary because we may be creating a new conversation window. */
80 purple_im_conversation_set_typing_state(im, PURPLE_IM_TYPING);
85 static PurplePluginPrefFrame *
86 get_plugin_pref_frame(PurplePlugin *plugin) {
88 PurplePluginPrefFrame *frame;
89 PurplePluginPref *pref;
91 frame = purple_plugin_pref_frame_new();
93 pref = purple_plugin_pref_new_with_name(PREF_BUDDIES);
94 purple_plugin_pref_set_label(pref, _("Only enable for users on"
95 " the buddy list"));
96 purple_plugin_pref_frame_add(frame, pref);
98 pref = purple_plugin_pref_new_with_name(PREF_STATUS);
99 purple_plugin_pref_set_label(pref, _("Disable when away"));
100 purple_plugin_pref_frame_add(frame, pref);
102 pref = purple_plugin_pref_new_with_name(PREF_NOTICE);
103 purple_plugin_pref_set_label(pref, _("Display notification message in"
104 " conversations"));
105 purple_plugin_pref_frame_add(frame, pref);
107 pref = purple_plugin_pref_new_with_name(PREF_RAISE);
108 purple_plugin_pref_set_label(pref, _("Raise psychic conversations"));
109 purple_plugin_pref_frame_add(frame, pref);
111 return frame;
115 static PurplePluginInfo *
116 plugin_query(GError **error) {
118 const gchar * const authors[] = PLUGIN_AUTHORS;
120 return purple_plugin_info_new(
121 "id", PLUGIN_ID,
122 "name", PLUGIN_NAME,
123 "version", DISPLAY_VERSION,
124 "category", PLUGIN_CATEGORY,
125 "summary", PLUGIN_SUMMARY,
126 "description", PLUGIN_DESC,
127 "authors", authors,
128 "website", PURPLE_WEBSITE,
129 "abi-version", PURPLE_ABI_VERSION,
130 "pref-frame-cb", get_plugin_pref_frame,
131 NULL
136 static gboolean
137 plugin_load(PurplePlugin *plugin, GError **error) {
139 void *convs_handle;
141 purple_prefs_add_none(PREFS_BASE);
142 purple_prefs_add_bool(PREF_BUDDIES, FALSE);
143 purple_prefs_add_bool(PREF_NOTICE, TRUE);
144 purple_prefs_add_bool(PREF_STATUS, TRUE);
146 convs_handle = purple_conversations_get_handle();
148 purple_signal_connect(convs_handle, "buddy-typing", plugin,
149 PURPLE_CALLBACK(buddy_typing_cb), NULL);
151 return TRUE;
155 static gboolean
156 plugin_unload(PurplePlugin *plugin, GError **error) {
158 return TRUE;
162 PURPLE_PLUGIN_INIT(psychic, plugin_query, plugin_load, plugin_unload);