| 1 |
|
| 2 |
|
| 3 #include "internal.h" |
|
| 4 |
|
| 5 #include "account.h" |
|
| 6 #include "blist.h" |
|
| 7 #include "conversation.h" |
|
| 8 #include "debug.h" |
|
| 9 #include "signals.h" |
|
| 10 #include "status.h" |
|
| 11 #include "version.h" |
|
| 12 |
|
| 13 #include "plugin.h" |
|
| 14 #include "pluginpref.h" |
|
| 15 #include "prefs.h" |
|
| 16 |
|
| 17 |
|
| 18 #define PLUGIN_ID "core-psychic" |
|
| 19 #define PLUGIN_NAME N_("Psychic Mode") |
|
| 20 #define PLUGIN_SUMMARY N_("Psychic mode for incoming conversation") |
|
| 21 #define PLUGIN_DESC N_("Causes conversation windows to appear as other" \ |
|
| 22 " users begin to message you. This works for" \ |
|
| 23 " AIM, ICQ, Jabber, Sametime, and Yahoo!") |
|
| 24 #define PLUGIN_AUTHOR "Christopher O'Brien <siege@preoccupied.net>" |
|
| 25 |
|
| 26 |
|
| 27 #define PREFS_BASE "/plugins/core/psychic" |
|
| 28 #define PREF_BUDDIES PREFS_BASE "/buddies_only" |
|
| 29 #define PREF_NOTICE PREFS_BASE "/show_notice" |
|
| 30 #define PREF_STATUS PREFS_BASE "/activate_online" |
|
| 31 |
|
| 32 |
|
| 33 static void |
|
| 34 buddy_typing_cb(GaimAccount *acct, const char *name, void *data) { |
|
| 35 GaimConversation *gconv; |
|
| 36 |
|
| 37 if(gaim_prefs_get_bool(PREF_STATUS) && |
|
| 38 ! gaim_status_is_available(gaim_account_get_active_status(acct))) { |
|
| 39 gaim_debug_info("psychic", "not available, doing nothing\n"); |
|
| 40 return; |
|
| 41 } |
|
| 42 |
|
| 43 if(gaim_prefs_get_bool(PREF_BUDDIES) && |
|
| 44 ! gaim_find_buddy(acct, name)) { |
|
| 45 gaim_debug_info("psychic", "not in blist, doing nothing\n"); |
|
| 46 return; |
|
| 47 } |
|
| 48 |
|
| 49 gconv = gaim_find_conversation_with_account(GAIM_CONV_TYPE_IM, name, acct); |
|
| 50 if(! gconv) { |
|
| 51 gaim_debug_info("psychic", "no previous conversation exists\n"); |
|
| 52 gconv = gaim_conversation_new(GAIM_CONV_TYPE_IM, acct, name); |
|
| 53 gaim_conversation_present(gconv); |
|
| 54 |
|
| 55 if(gaim_prefs_get_bool(PREF_NOTICE)) { |
|
| 56 gaim_conversation_write(gconv, NULL, |
|
| 57 /* This is a quote from Star Wars. You should |
|
| 58 probably not translate it literally. If |
|
| 59 you can't find a fitting cultural reference |
|
| 60 in your language, consider translating |
|
| 61 something like this instead: |
|
| 62 "You feel a new message coming." */ |
|
| 63 _("You feel a disturbance in the force..."), |
|
| 64 GAIM_MESSAGE_SYSTEM | GAIM_MESSAGE_NO_LOG | GAIM_MESSAGE_ACTIVE_ONLY, |
|
| 65 time(NULL)); |
|
| 66 } |
|
| 67 |
|
| 68 gaim_conv_im_set_typing_state(GAIM_CONV_IM(gconv), GAIM_TYPING); |
|
| 69 } |
|
| 70 } |
|
| 71 |
|
| 72 |
|
| 73 static GaimPluginPrefFrame * |
|
| 74 get_plugin_pref_frame(GaimPlugin *plugin) { |
|
| 75 |
|
| 76 GaimPluginPrefFrame *frame; |
|
| 77 GaimPluginPref *pref; |
|
| 78 |
|
| 79 frame = gaim_plugin_pref_frame_new(); |
|
| 80 |
|
| 81 pref = gaim_plugin_pref_new_with_name(PREF_BUDDIES); |
|
| 82 gaim_plugin_pref_set_label(pref, _("Only enable for users on" |
|
| 83 " the buddy list")); |
|
| 84 gaim_plugin_pref_frame_add(frame, pref); |
|
| 85 |
|
| 86 pref = gaim_plugin_pref_new_with_name(PREF_STATUS); |
|
| 87 gaim_plugin_pref_set_label(pref, _("Disable when away")); |
|
| 88 gaim_plugin_pref_frame_add(frame, pref); |
|
| 89 |
|
| 90 pref = gaim_plugin_pref_new_with_name(PREF_NOTICE); |
|
| 91 gaim_plugin_pref_set_label(pref, _("Display notification message in" |
|
| 92 " conversations")); |
|
| 93 gaim_plugin_pref_frame_add(frame, pref); |
|
| 94 |
|
| 95 return frame; |
|
| 96 } |
|
| 97 |
|
| 98 |
|
| 99 static gboolean |
|
| 100 plugin_load(GaimPlugin *plugin) { |
|
| 101 |
|
| 102 void *convs_handle; |
|
| 103 convs_handle = gaim_conversations_get_handle(); |
|
| 104 |
|
| 105 gaim_signal_connect(convs_handle, "buddy-typing", plugin, |
|
| 106 GAIM_CALLBACK(buddy_typing_cb), NULL); |
|
| 107 |
|
| 108 return TRUE; |
|
| 109 } |
|
| 110 |
|
| 111 |
|
| 112 static GaimPluginUiInfo prefs_info = { |
|
| 113 get_plugin_pref_frame, |
|
| 114 0, /* page_num (Reserved) */ |
|
| 115 NULL, /* frame (Reserved) */ |
|
| 116 }; |
|
| 117 |
|
| 118 |
|
| 119 static GaimPluginInfo info = { |
|
| 120 GAIM_PLUGIN_MAGIC, |
|
| 121 GAIM_MAJOR_VERSION, |
|
| 122 GAIM_MINOR_VERSION, |
|
| 123 GAIM_PLUGIN_STANDARD, /**< type */ |
|
| 124 NULL, /**< ui_requirement */ |
|
| 125 0, /**< flags */ |
|
| 126 NULL, /**< dependencies */ |
|
| 127 GAIM_PRIORITY_DEFAULT, /**< priority */ |
|
| 128 |
|
| 129 PLUGIN_ID, /**< id */ |
|
| 130 PLUGIN_NAME, /**< name */ |
|
| 131 VERSION, /**< version */ |
|
| 132 PLUGIN_SUMMARY, /**< summary */ |
|
| 133 PLUGIN_DESC, /**< description */ |
|
| 134 PLUGIN_AUTHOR, /**< author */ |
|
| 135 GAIM_WEBSITE, /**< homepage */ |
|
| 136 |
|
| 137 plugin_load, /**< load */ |
|
| 138 NULL, /**< unload */ |
|
| 139 NULL, /**< destroy */ |
|
| 140 |
|
| 141 NULL, /**< ui_info */ |
|
| 142 NULL, /**< extra_info */ |
|
| 143 &prefs_info, /**< prefs_info */ |
|
| 144 NULL, /**< actions */ |
|
| 145 }; |
|
| 146 |
|
| 147 |
|
| 148 static void |
|
| 149 init_plugin(GaimPlugin *plugin) { |
|
| 150 gaim_prefs_add_none(PREFS_BASE); |
|
| 151 gaim_prefs_add_bool(PREF_BUDDIES, FALSE); |
|
| 152 gaim_prefs_add_bool(PREF_NOTICE, TRUE); |
|
| 153 gaim_prefs_add_bool(PREF_STATUS, TRUE); |
|
| 154 } |
|
| 155 |
|
| 156 |
|
| 157 GAIM_INIT_PLUGIN(psychic, init_plugin, info) |
|