Mercurial > pidgin.yaz
annotate plugins/dbus-example.c @ 14088:223570831b0b
[gaim-migrate @ 16711]
Get rid of an assert when editing an account that has no icon
committer: Tailor Script <tailor@pidgin.im>
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Sat, 12 Aug 2006 10:06:15 +0000 |
parents | 8bda65b88e49 |
children |
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 { | |
14035 | 54 char *text; |
11173 | 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. */ | |
14035 | 62 GAIM_DBUS_DEFINE_TYPE(GaimText) |
11173 | 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. */ | |
14035 | 81 GaimText* dbus_example_get_hello_object(void) |
11173 | 82 { |
14035 | 83 return &hello; |
11173 | 84 } |
85 | |
14035 | 86 void dbus_example_set_text(GaimText *obj, const char *text) |
11173 | 87 { |
14035 | 88 if (obj != NULL) { |
89 g_free(obj->text); | |
90 obj->text = g_strdup(text); | |
91 } | |
11173 | 92 } |
93 | |
14035 | 94 const char *dbus_example_get_text(GaimText *obj) |
11173 | 95 { |
14035 | 96 if (obj != NULL) |
97 return obj->text; | |
98 else | |
99 return NULL; | |
11173 | 100 } |
101 | |
14035 | 102 const char *dbus_example_get_buddy_name(GaimBuddy *buddy) |
11173 | 103 { |
14035 | 104 return gaim_buddy_get_name(buddy); |
11173 | 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 |
14035 | 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); | |
11173 | 118 |
14035 | 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); | |
11173 | 125 |
14035 | 126 hello.text = g_strdup("Hello."); |
127 | |
128 return TRUE; | |
11173 | 129 } |
130 | |
131 | |
132 static gboolean | |
133 plugin_unload(GaimPlugin *plugin) | |
134 { | |
14035 | 135 g_free(hello.text); |
11173 | 136 |
14035 | 137 /* It is necessary to unregister all pointers registered by the module. */ |
138 GAIM_DBUS_UNREGISTER_POINTER(&hello); | |
11173 | 139 |
14035 | 140 return TRUE; |
11173 | 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) |