Mercurial > pidgin
annotate plugins/dbus-example.c @ 13980:c9509bd42d7a
[gaim-migrate @ 16542]
Show the mail-notification checkbox in the account-dialog only if
the prpl has support for it.
committer: Tailor Script <tailor@pidgin.im>
author | Sadrul Habib Chowdhury <imadil@gmail.com> |
---|---|
date | Sun, 23 Jul 2006 02:03:19 +0000 |
parents | b43aec5fa9eb |
children | 8bda65b88e49 |
rev | line source |
---|---|
13555
a7b24ba66570
[gaim-migrate @ 15933]
Richard Laager <rlaager@wiktel.com>
parents:
11200
diff
changeset
|
1 /* |
a7b24ba66570
[gaim-migrate @ 15933]
Richard Laager <rlaager@wiktel.com>
parents:
11200
diff
changeset
|
2 * This is an example of a gaim dbus plugin. After enabling this |
a7b24ba66570
[gaim-migrate @ 15933]
Richard Laager <rlaager@wiktel.com>
parents:
11200
diff
changeset
|
3 * plugin, the following commands should work from the command line: |
a7b24ba66570
[gaim-migrate @ 15933]
Richard Laager <rlaager@wiktel.com>
parents:
11200
diff
changeset
|
4 * |
a7b24ba66570
[gaim-migrate @ 15933]
Richard Laager <rlaager@wiktel.com>
parents:
11200
diff
changeset
|
5 * prompt$ gaim-send DbusExampleGetHelloObject |
a7b24ba66570
[gaim-migrate @ 15933]
Richard Laager <rlaager@wiktel.com>
parents:
11200
diff
changeset
|
6 * |
a7b24ba66570
[gaim-migrate @ 15933]
Richard Laager <rlaager@wiktel.com>
parents:
11200
diff
changeset
|
7 * returns, say: int32 74 |
a7b24ba66570
[gaim-migrate @ 15933]
Richard Laager <rlaager@wiktel.com>
parents:
11200
diff
changeset
|
8 * |
a7b24ba66570
[gaim-migrate @ 15933]
Richard Laager <rlaager@wiktel.com>
parents:
11200
diff
changeset
|
9 * prompt$ gaim-send DbusExampleGetText int32:74 |
a7b24ba66570
[gaim-migrate @ 15933]
Richard Laager <rlaager@wiktel.com>
parents:
11200
diff
changeset
|
10 * |
a7b24ba66570
[gaim-migrate @ 15933]
Richard Laager <rlaager@wiktel.com>
parents:
11200
diff
changeset
|
11 * returns: string "Hello." |
a7b24ba66570
[gaim-migrate @ 15933]
Richard Laager <rlaager@wiktel.com>
parents:
11200
diff
changeset
|
12 * |
a7b24ba66570
[gaim-migrate @ 15933]
Richard Laager <rlaager@wiktel.com>
parents:
11200
diff
changeset
|
13 * prompt$ gaim-send DbusExampleSetText int32:74 string:Bye! |
a7b24ba66570
[gaim-migrate @ 15933]
Richard Laager <rlaager@wiktel.com>
parents:
11200
diff
changeset
|
14 * |
a7b24ba66570
[gaim-migrate @ 15933]
Richard Laager <rlaager@wiktel.com>
parents:
11200
diff
changeset
|
15 * prompt$ gaim-send DbusExampleGetText int32:74 |
a7b24ba66570
[gaim-migrate @ 15933]
Richard Laager <rlaager@wiktel.com>
parents:
11200
diff
changeset
|
16 * |
a7b24ba66570
[gaim-migrate @ 15933]
Richard Laager <rlaager@wiktel.com>
parents:
11200
diff
changeset
|
17 * returns: string "Bye!" |
a7b24ba66570
[gaim-migrate @ 15933]
Richard Laager <rlaager@wiktel.com>
parents:
11200
diff
changeset
|
18 * |
a7b24ba66570
[gaim-migrate @ 15933]
Richard Laager <rlaager@wiktel.com>
parents:
11200
diff
changeset
|
19 * Gaim is the legal property of its developers, whose names are too numerous |
a7b24ba66570
[gaim-migrate @ 15933]
Richard Laager <rlaager@wiktel.com>
parents:
11200
diff
changeset
|
20 * to list here. Please refer to the COPYRIGHT file distributed with this |
a7b24ba66570
[gaim-migrate @ 15933]
Richard Laager <rlaager@wiktel.com>
parents:
11200
diff
changeset
|
21 * source distribution. |
a7b24ba66570
[gaim-migrate @ 15933]
Richard Laager <rlaager@wiktel.com>
parents:
11200
diff
changeset
|
22 * |
a7b24ba66570
[gaim-migrate @ 15933]
Richard Laager <rlaager@wiktel.com>
parents:
11200
diff
changeset
|
23 * This program is free software; you can redistribute it and/or modify |
a7b24ba66570
[gaim-migrate @ 15933]
Richard Laager <rlaager@wiktel.com>
parents:
11200
diff
changeset
|
24 * it under the terms of the GNU General Public License as published by |
a7b24ba66570
[gaim-migrate @ 15933]
Richard Laager <rlaager@wiktel.com>
parents:
11200
diff
changeset
|
25 * the Free Software Foundation; either version 2 of the License, or |
a7b24ba66570
[gaim-migrate @ 15933]
Richard Laager <rlaager@wiktel.com>
parents:
11200
diff
changeset
|
26 * (at your option) any later version. |
a7b24ba66570
[gaim-migrate @ 15933]
Richard Laager <rlaager@wiktel.com>
parents:
11200
diff
changeset
|
27 * |
a7b24ba66570
[gaim-migrate @ 15933]
Richard Laager <rlaager@wiktel.com>
parents:
11200
diff
changeset
|
28 * This program is distributed in the hope that it will be useful, |
a7b24ba66570
[gaim-migrate @ 15933]
Richard Laager <rlaager@wiktel.com>
parents:
11200
diff
changeset
|
29 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
a7b24ba66570
[gaim-migrate @ 15933]
Richard Laager <rlaager@wiktel.com>
parents:
11200
diff
changeset
|
30 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
a7b24ba66570
[gaim-migrate @ 15933]
Richard Laager <rlaager@wiktel.com>
parents:
11200
diff
changeset
|
31 * GNU General Public License for more details. |
a7b24ba66570
[gaim-migrate @ 15933]
Richard Laager <rlaager@wiktel.com>
parents:
11200
diff
changeset
|
32 * |
a7b24ba66570
[gaim-migrate @ 15933]
Richard Laager <rlaager@wiktel.com>
parents:
11200
diff
changeset
|
33 * You should have received a copy of the GNU General Public License |
a7b24ba66570
[gaim-migrate @ 15933]
Richard Laager <rlaager@wiktel.com>
parents:
11200
diff
changeset
|
34 * along with this program; if not, write to the Free Software |
a7b24ba66570
[gaim-migrate @ 15933]
Richard Laager <rlaager@wiktel.com>
parents:
11200
diff
changeset
|
35 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
11173 | 36 */ |
37 | |
38 #include "internal.h" | |
39 | |
13955 | 40 #include "blist.h" |
41 #include "notify.h" | |
11173 | 42 #include "plugin.h" |
43 #include "version.h" | |
44 | |
45 #include <stdio.h> | |
46 #include <stdlib.h> | |
47 #include <string.h> | |
48 | |
49 #define DBUS_API_SUBJECT_TO_CHANGE | |
50 #include "dbus-maybe.h" | |
51 #include "dbus-bindings.h" | |
52 | |
53 typedef struct { | |
54 char *text; | |
55 } GaimText; | |
56 | |
57 /* This makes the structure GaimText visible to the gaim-dbus type | |
58 system. It defines GaimText as a type with no parent. From now | |
59 on, we will be able to register pointers to structures of this | |
60 type. You to dbus-define types you want to be directly accessible | |
61 by external applications. */ | |
62 GAIM_DBUS_DEFINE_TYPE(GaimText) | |
63 | |
64 /* Here we make four functions accessible to other applications by | |
65 DBus. These functions can access types defined in gaim proper | |
66 (GaimBuddy) as well as the types defined in the plugin (GaimText). */ | |
67 DBUS_EXPORT GaimText* dbus_example_get_hello_object(void); | |
68 DBUS_EXPORT void dbus_example_set_text(GaimText *obj, const char *text); | |
69 DBUS_EXPORT const char *dbus_example_get_text(GaimText *obj); | |
70 DBUS_EXPORT const char *dbus_example_get_buddy_name(GaimBuddy *buddy); | |
71 | |
72 /* This file has been generated by the #dbus-analize-functions.py | |
73 script. It contains dbus wrappers for the four functions declared | |
74 above. */ | |
75 #include "dbus-example-bindings.c" | |
76 | |
77 /* This is the GaimText object we want to make publicly visible. */ | |
78 static GaimText hello; | |
79 | |
80 /* Here come the definitions of the four exported functions. */ | |
81 GaimText* dbus_example_get_hello_object(void) | |
82 { | |
83 return &hello; | |
84 } | |
85 | |
86 void dbus_example_set_text(GaimText *obj, const char *text) | |
87 { | |
88 if (obj != NULL) { | |
89 g_free(obj->text); | |
90 obj->text = g_strdup(text); | |
91 } | |
92 } | |
93 | |
94 const char *dbus_example_get_text(GaimText *obj) | |
95 { | |
96 if (obj != NULL) | |
97 return obj->text; | |
98 else | |
99 return NULL; | |
100 } | |
101 | |
102 const char *dbus_example_get_buddy_name(GaimBuddy *buddy) | |
103 { | |
104 return gaim_buddy_get_name(buddy); | |
105 } | |
106 | |
107 /* And now standard plugin stuff */ | |
108 | |
109 static gboolean | |
110 plugin_load(GaimPlugin *plugin) | |
111 { | |
13956 | 112 GAIM_DBUS_RETURN_FALSE_IF_DISABLED(plugin); |
13955 | 113 |
11173 | 114 /* First, we have to register our four exported functions with the |
115 main gaim dbus loop. Without this statement, the gaim dbus | |
116 code wouldn't know about our functions. */ | |
117 GAIM_DBUS_REGISTER_BINDINGS(plugin); | |
118 | |
119 /* Then, we register the hello object of type GaimText. Note that | |
120 pointer registrations / unregistrations are completely dynamic; | |
121 they don't have to be made when the plugin is loaded / | |
122 unloaded. Without this statement the dbus gaim code wouldn't | |
123 know about the hello object. */ | |
124 GAIM_DBUS_REGISTER_POINTER(&hello, GaimText); | |
125 | |
126 hello.text = g_strdup("Hello."); | |
127 | |
128 return TRUE; | |
129 } | |
130 | |
131 | |
132 static gboolean | |
133 plugin_unload(GaimPlugin *plugin) | |
134 { | |
135 g_free(hello.text); | |
136 | |
137 /* It is necessary to unregister all pointers registered by the module. */ | |
138 GAIM_DBUS_UNREGISTER_POINTER(&hello); | |
139 | |
140 return TRUE; | |
141 } | |
142 | |
143 static GaimPluginInfo info = | |
144 { | |
145 GAIM_PLUGIN_MAGIC, | |
146 GAIM_MAJOR_VERSION, | |
147 GAIM_MINOR_VERSION, | |
148 GAIM_PLUGIN_STANDARD, /**< type */ | |
149 NULL, /**< ui_requirement */ | |
150 0, /**< flags */ | |
151 NULL, /**< dependencies */ | |
152 GAIM_PRIORITY_DEFAULT, /**< priority */ | |
153 | |
154 "dbus-example", /**< id */ | |
13962 | 155 N_("DBus Example"), /**< name */ |
11173 | 156 VERSION, /**< version */ |
157 /** summary */ | |
158 N_("DBus Plugin Example"), | |
159 /** description */ | |
160 N_("DBus Plugin Example"), | |
161 "Piotr Zielinski (http://cl.cam.ac.uk/~pz215)", /**< author */ | |
162 GAIM_WEBSITE, /**< homepage */ | |
163 | |
164 plugin_load, /**< load */ | |
165 plugin_unload, /**< unload */ | |
166 NULL, /**< destroy */ | |
167 | |
168 NULL, /**< ui_info */ | |
169 NULL, /**< extra_info */ | |
170 NULL, /**< prefs_info */ | |
171 NULL | |
172 }; | |
173 | |
174 static void init_plugin(GaimPlugin *plugin) | |
175 { | |
176 } | |
177 | |
178 GAIM_INIT_PLUGIN(dbus_example, init_plugin, info) |