Mercurial > pidgin
comparison plugins/psychic.c @ 12859:02e1ef5bc3d5
[gaim-migrate @ 15210]
adding a psychic mode plugin, replacing a preference which gaim-meanwhile used to offer
committer: Tailor Script <tailor@pidgin.im>
author | Christopher O'Brien <siege@pidgin.im> |
---|---|
date | Fri, 13 Jan 2006 17:30:20 +0000 |
parents | |
children | 6cc43e23ad36 |
comparison
equal
deleted
inserted
replaced
12858:b1c85bf2dab3 | 12859:02e1ef5bc3d5 |
---|---|
1 | |
2 | |
3 #include "internal.h" | |
4 | |
5 #include "blist.h" | |
6 #include "conversation.h" | |
7 #include "debug.h" | |
8 #include "signals.h" | |
9 #include "version.h" | |
10 | |
11 #include "plugin.h" | |
12 #include "pluginpref.h" | |
13 #include "prefs.h" | |
14 | |
15 | |
16 #define DEBUG_INFO(a...) gaim_debug_info("psychic", a) | |
17 | |
18 | |
19 #define PLUGIN_ID "core-psychic" | |
20 #define PLUGIN_NAME N_("Psychic Mode") | |
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") | |
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 | |
31 | |
32 static void | |
33 buddy_typing_cb(GaimAccount *acct, const char *name, void *data) { | |
34 GaimConversation *gconv; | |
35 | |
36 if(gaim_prefs_get_bool(PREF_BUDDIES)) { | |
37 if(! gaim_find_buddy(acct, name)) { | |
38 DEBUG_INFO("not in blist, doing nothing\n"); | |
39 return; | |
40 } | |
41 } | |
42 | |
43 gconv = gaim_find_conversation_with_account(GAIM_CONV_TYPE_IM, name, acct); | |
44 if(! gconv) { | |
45 DEBUG_INFO("no previous conversation exists\n"); | |
46 gconv = gaim_conversation_new(GAIM_CONV_TYPE_IM, acct, name); | |
47 gaim_conversation_present(gconv); | |
48 | |
49 if(gaim_prefs_get_bool(PREF_NOTICE)) { | |
50 gaim_conversation_write(gconv, NULL, _("Psychic mode"), | |
51 GAIM_MESSAGE_NO_LOG, time(NULL)); | |
52 } | |
53 } | |
54 } | |
55 | |
56 | |
57 static GaimPluginPrefFrame * | |
58 get_plugin_pref_frame(GaimPlugin *plugin) { | |
59 | |
60 GaimPluginPrefFrame *frame; | |
61 GaimPluginPref *pref; | |
62 | |
63 frame = gaim_plugin_pref_frame_new(); | |
64 | |
65 pref = gaim_plugin_pref_new_with_name(PREF_BUDDIES); | |
66 gaim_plugin_pref_set_label(pref, _("Only enable for users in buddy list")); | |
67 gaim_plugin_pref_frame_add(frame, pref); | |
68 | |
69 pref = gaim_plugin_pref_new_with_name(PREF_NOTICE); | |
70 gaim_plugin_pref_set_label(pref, _("Display notification message in" | |
71 " conversations")); | |
72 gaim_plugin_pref_frame_add(frame, pref); | |
73 | |
74 return frame; | |
75 } | |
76 | |
77 | |
78 static gboolean | |
79 plugin_load(GaimPlugin *plugin) { | |
80 | |
81 void *convs_handle; | |
82 convs_handle = gaim_conversations_get_handle(); | |
83 | |
84 gaim_signal_connect(convs_handle, "buddy-typing", plugin, | |
85 GAIM_CALLBACK(buddy_typing_cb), NULL); | |
86 | |
87 return TRUE; | |
88 } | |
89 | |
90 | |
91 static GaimPluginUiInfo prefs_info = { | |
92 get_plugin_pref_frame, | |
93 0, /* page_num (Reserved) */ | |
94 NULL, /* frame (Reserved) */ | |
95 }; | |
96 | |
97 | |
98 static GaimPluginInfo info = { | |
99 GAIM_PLUGIN_MAGIC, | |
100 GAIM_MAJOR_VERSION, | |
101 GAIM_MINOR_VERSION, | |
102 GAIM_PLUGIN_STANDARD, /**< type */ | |
103 NULL, /**< ui_requirement */ | |
104 0, /**< flags */ | |
105 NULL, /**< dependencies */ | |
106 GAIM_PRIORITY_DEFAULT, /**< priority */ | |
107 | |
108 PLUGIN_ID, /**< id */ | |
109 PLUGIN_NAME, /**< name */ | |
110 VERSION, /**< version */ | |
111 PLUGIN_SUMMARY, /**< summary */ | |
112 PLUGIN_DESC, /**< description */ | |
113 PLUGIN_AUTHOR, /**< author */ | |
114 GAIM_WEBSITE, /**< homepage */ | |
115 | |
116 plugin_load, /**< load */ | |
117 NULL, /**< unload */ | |
118 NULL, /**< destroy */ | |
119 | |
120 NULL, /**< ui_info */ | |
121 NULL, /**< extra_info */ | |
122 &prefs_info, /**< prefs_info */ | |
123 NULL, /**< actions */ | |
124 }; | |
125 | |
126 | |
127 static void | |
128 init_plugin(GaimPlugin *plugin) { | |
129 gaim_prefs_add_none(PREFS_BASE); | |
130 gaim_prefs_add_bool(PREF_BUDDIES, FALSE); | |
131 gaim_prefs_add_bool(PREF_NOTICE, TRUE); | |
132 } | |
133 | |
134 | |
135 GAIM_INIT_PLUGIN(psychic, init_plugin, info) |