Mercurial > pidgin-audacious
annotate pidgin-audacious.c @ 19:12d809123d69
- revised signed_on_cb() so that it calls purple_util_set_current_song().
- new debug macros.
- removed watchdog_func().
- added connect_purple_signals().
- renamed is_app_running() as is_app_playing().
| author | Yoshiki Yazawa <yaz@honeyplanet.jp> |
|---|---|
| date | Sat, 04 Oct 2008 12:06:45 +0900 |
| parents | dc3aa0bf24c0 |
| children | 4aa711530489 |
| rev | line source |
|---|---|
| 13 | 1 /* Pidgin-Audacious plugin. |
| 0 | 2 * |
| 3 * This program is free software; you can redistribute it and/or | |
| 4 * modify it under the terms of the GNU General Public License as | |
| 5 * published by the Free Software Foundation; either version 2 of the | |
| 6 * License, or (at your option) any later version. | |
| 7 * | |
| 8 * This program is distributed in the hope that it will be useful, but | |
| 9 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 11 * General Public License for more details. | |
| 12 * | |
| 13 * You should have received a copy of the GNU General Public License | |
| 14 * along with this program; if not, write to the Free Software | |
| 15 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA | |
| 16 * 02111-1307, USA. | |
| 17 */ | |
| 18 #define PURPLE_PLUGINS 1 | |
| 19 | |
| 20 #include <stdio.h> | |
| 21 #include <stdlib.h> | |
| 22 #include <string.h> | |
| 23 #include <glib.h> | |
| 18 | 24 #include <dbus/dbus.h> |
| 25 #include <dbus/dbus-glib.h> | |
| 0 | 26 |
| 27 #include "gtkplugin.h" | |
| 28 #include "util.h" | |
| 29 #include "debug.h" | |
| 30 #include "connection.h" | |
| 31 #include "version.h" | |
|
10
7c9624c8a109
added /song command which sends name of currently playing song.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
9
diff
changeset
|
32 #include "cmds.h" |
| 18 | 33 #include "savedstatuses.h" |
| 0 | 34 |
| 13 | 35 #define PIDGINAUD_PLUGIN_ID "pidgin_audacious" |
|
19
12d809123d69
- revised signed_on_cb() so that it calls purple_util_set_current_song().
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
18
diff
changeset
|
36 #define PLUGIN_NAME "Pidgin-Audacious" |
|
11
43cb653de212
paste template has been implemented.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
10
diff
changeset
|
37 #define OPT_PIDGINAUD "/plugins/pidgin_audacious" |
|
43cb653de212
paste template has been implemented.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
10
diff
changeset
|
38 #define OPT_PROCESS_STATUS OPT_PIDGINAUD "/process_status" |
|
43cb653de212
paste template has been implemented.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
10
diff
changeset
|
39 #define OPT_PROCESS_USERINFO OPT_PIDGINAUD "/process_userinfo" |
| 18 | 40 #define OPT_SONG_TEMPLATE OPT_PIDGINAUD "/song_template" |
|
11
43cb653de212
paste template has been implemented.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
10
diff
changeset
|
41 #define OPT_PASTE_TEMPLATE OPT_PIDGINAUD "/paste_template" |
|
19
12d809123d69
- revised signed_on_cb() so that it calls purple_util_set_current_song().
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
18
diff
changeset
|
42 #define OPT_LOG_OUTPUT OPT_PIDGINAUD "/log_output" |
| 0 | 43 |
| 18 | 44 #define DEFAULT_SONG_TEMPLATE "%artist - %title" |
| 13 | 45 #define SONG_TOKEN "%song" |
| 46 #define NO_SONG_MESSAGE "No song being played." | |
| 0 | 47 |
| 18 | 48 #define DBUS_TYPE_G_STRING_VALUE_HASHTABLE (dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, G_TYPE_VALUE)) |
| 49 | |
|
19
12d809123d69
- revised signed_on_cb() so that it calls purple_util_set_current_song().
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
18
diff
changeset
|
50 #define aud_debug(fmt, ...) do { if(purple_prefs_get_bool(OPT_LOG_OUTPUT)) purple_debug(PURPLE_DEBUG_INFO, PLUGIN_NAME, "%s():%4d: " fmt, __FUNCTION__, (int)__LINE__, ## __VA_ARGS__); } while(0); |
|
12d809123d69
- revised signed_on_cb() so that it calls purple_util_set_current_song().
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
18
diff
changeset
|
51 |
|
12d809123d69
- revised signed_on_cb() so that it calls purple_util_set_current_song().
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
18
diff
changeset
|
52 #define aud_error(fmt, ...) do { if(purple_prefs_get_bool(OPT_LOG_OUTPUT)) purple_debug(PURPLE_DEBUG_ERROR, PLUGIN_NAME, "%s():%4d: " fmt, __FUNCTION__, (int)__LINE__, ## __VA_ARGS__); } while(0); |
|
12d809123d69
- revised signed_on_cb() so that it calls purple_util_set_current_song().
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
18
diff
changeset
|
53 |
| 18 | 54 /* xxx move up */ |
| 55 #define TITLE "%title" | |
| 56 #define ARTIST "%artist" | |
| 57 #define ALBUM "%album" | |
| 58 #define GENRE "%genre" | |
| 0 | 59 |
| 18 | 60 typedef struct song_tuple { |
| 61 gchar *title; | |
| 62 gchar *artist; | |
| 63 gchar *album; | |
| 64 gchar *genre; | |
| 65 } song_tuple; | |
| 66 | |
| 0 | 67 |
| 18 | 68 /* globals */ |
| 69 static GHashTable *seed_status; | |
| 70 static GHashTable *seed_userinfo; | |
| 71 static GHashTable *pushed_status; | |
| 72 static GHashTable *pushed_userinfo; | |
| 73 static DBusGConnection *connection = NULL; | |
| 74 static DBusGProxy *session = NULL; | |
|
10
7c9624c8a109
added /song command which sends name of currently playing song.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
9
diff
changeset
|
75 static PurpleCmdId cmdid_paste_current_song; |
|
7c9624c8a109
added /song command which sends name of currently playing song.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
9
diff
changeset
|
76 |
| 18 | 77 /* prototypes */ |
| 78 extern gchar *botch_utf(const gchar *msg, gsize len, gsize *newlen) __attribute__ ((weak)); | |
| 0 | 79 static void aud_process(gchar *aud_info); |
| 18 | 80 static void track_signal_cb(DBusGProxy *player_proxy, GHashTable *table, gpointer data); |
| 81 static void status_signal_cb(DBusGProxy *player_proxy, gint status, gpointer data); | |
|
19
12d809123d69
- revised signed_on_cb() so that it calls purple_util_set_current_song().
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
18
diff
changeset
|
82 static gboolean is_app_playing(void); |
| 18 | 83 static GHashTable *get_song_table(void); |
| 84 static song_tuple *get_song_tuple(GHashTable *table); | |
|
19
12d809123d69
- revised signed_on_cb() so that it calls purple_util_set_current_song().
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
18
diff
changeset
|
85 static void signed_on_cb(PurpleConnection *gc, void *data); |
|
12d809123d69
- revised signed_on_cb() so that it calls purple_util_set_current_song().
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
18
diff
changeset
|
86 static void prefs_cb(const char *name, PurplePrefType type, gconstpointer value, gpointer data); |
| 18 | 87 |
| 88 | |
| 89 /* implementation */ | |
| 0 | 90 |
|
12
79f081cdfb19
- fixed potential memory leaks.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
11
diff
changeset
|
91 static DBusGProxy * |
| 18 | 92 get_dbus_session(void) |
| 0 | 93 { |
| 94 GError *error = NULL; | |
| 18 | 95 DBusGProxy *proxy; |
| 0 | 96 connection = dbus_g_bus_get(DBUS_BUS_SESSION, &error); |
| 97 g_clear_error(&error); | |
| 98 | |
| 18 | 99 proxy = dbus_g_proxy_new_for_name(connection, |
| 100 "org.mpris.audacious", | |
| 101 "/Player", | |
| 102 "org.freedesktop.MediaPlayer"); | |
| 0 | 103 |
| 104 g_clear_error(&error); | |
| 18 | 105 return proxy; |
| 106 } | |
| 107 | |
| 108 | |
| 109 static void | |
| 110 connect_dbus_signals() | |
| 111 { | |
| 112 dbus_g_proxy_add_signal(session, | |
| 113 "TrackChange", | |
| 114 DBUS_TYPE_G_STRING_VALUE_HASHTABLE, | |
| 115 G_TYPE_INVALID); | |
| 116 | |
| 117 dbus_g_proxy_connect_signal(session, | |
| 118 "TrackChange", | |
| 119 G_CALLBACK(track_signal_cb), | |
| 120 NULL, NULL); | |
| 121 | |
| 122 dbus_g_proxy_add_signal(session, | |
| 123 "StatusChange", | |
| 124 G_TYPE_INT, G_TYPE_INVALID); | |
| 125 | |
| 126 dbus_g_proxy_connect_signal(session, | |
| 127 "StatusChange", | |
| 128 G_CALLBACK(status_signal_cb), | |
| 129 NULL, NULL); | |
| 130 } | |
| 131 | |
|
19
12d809123d69
- revised signed_on_cb() so that it calls purple_util_set_current_song().
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
18
diff
changeset
|
132 static void |
|
12d809123d69
- revised signed_on_cb() so that it calls purple_util_set_current_song().
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
18
diff
changeset
|
133 connect_purple_signals(PurplePlugin *plugin) |
|
12d809123d69
- revised signed_on_cb() so that it calls purple_util_set_current_song().
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
18
diff
changeset
|
134 { |
|
12d809123d69
- revised signed_on_cb() so that it calls purple_util_set_current_song().
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
18
diff
changeset
|
135 purple_signal_connect(purple_connections_get_handle(), |
|
12d809123d69
- revised signed_on_cb() so that it calls purple_util_set_current_song().
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
18
diff
changeset
|
136 "signed-on", |
|
12d809123d69
- revised signed_on_cb() so that it calls purple_util_set_current_song().
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
18
diff
changeset
|
137 plugin, |
|
12d809123d69
- revised signed_on_cb() so that it calls purple_util_set_current_song().
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
18
diff
changeset
|
138 PURPLE_CALLBACK(signed_on_cb), |
|
12d809123d69
- revised signed_on_cb() so that it calls purple_util_set_current_song().
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
18
diff
changeset
|
139 NULL); |
|
12d809123d69
- revised signed_on_cb() so that it calls purple_util_set_current_song().
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
18
diff
changeset
|
140 |
|
12d809123d69
- revised signed_on_cb() so that it calls purple_util_set_current_song().
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
18
diff
changeset
|
141 purple_signal_connect(purple_savedstatuses_get_handle(), |
|
12d809123d69
- revised signed_on_cb() so that it calls purple_util_set_current_song().
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
18
diff
changeset
|
142 "savedstatus-changed", |
|
12d809123d69
- revised signed_on_cb() so that it calls purple_util_set_current_song().
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
18
diff
changeset
|
143 plugin, |
|
12d809123d69
- revised signed_on_cb() so that it calls purple_util_set_current_song().
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
18
diff
changeset
|
144 PURPLE_CALLBACK(signed_on_cb), |
|
12d809123d69
- revised signed_on_cb() so that it calls purple_util_set_current_song().
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
18
diff
changeset
|
145 NULL); |
|
12d809123d69
- revised signed_on_cb() so that it calls purple_util_set_current_song().
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
18
diff
changeset
|
146 |
|
12d809123d69
- revised signed_on_cb() so that it calls purple_util_set_current_song().
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
18
diff
changeset
|
147 purple_prefs_connect_callback(purple_prefs_get_handle(), |
|
12d809123d69
- revised signed_on_cb() so that it calls purple_util_set_current_song().
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
18
diff
changeset
|
148 OPT_PIDGINAUD, |
|
12d809123d69
- revised signed_on_cb() so that it calls purple_util_set_current_song().
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
18
diff
changeset
|
149 prefs_cb, |
|
12d809123d69
- revised signed_on_cb() so that it calls purple_util_set_current_song().
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
18
diff
changeset
|
150 NULL); |
|
12d809123d69
- revised signed_on_cb() so that it calls purple_util_set_current_song().
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
18
diff
changeset
|
151 } |
|
12d809123d69
- revised signed_on_cb() so that it calls purple_util_set_current_song().
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
18
diff
changeset
|
152 |
| 18 | 153 static GHashTable * |
| 154 get_song_table(void) | |
| 155 { | |
| 156 GHashTable *table = NULL; | |
| 157 | |
|
19
12d809123d69
- revised signed_on_cb() so that it calls purple_util_set_current_song().
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
18
diff
changeset
|
158 if(is_app_playing()) { |
| 18 | 159 dbus_g_proxy_call(session, |
| 160 "GetMetadata", | |
| 161 NULL, | |
| 162 G_TYPE_INVALID, | |
| 163 DBUS_TYPE_G_STRING_VALUE_HASHTABLE, | |
| 164 &table, | |
| 165 G_TYPE_INVALID); | |
| 166 } | |
| 167 | |
| 168 return table; | |
| 169 } | |
| 170 | |
| 171 static song_tuple * | |
| 172 get_song_tuple(GHashTable *table) | |
| 173 { | |
| 174 song_tuple *t = NULL; | |
| 175 GValue *value; | |
| 176 | |
| 177 if(!table) | |
| 178 return NULL; | |
| 179 | |
| 180 t = g_new0(song_tuple, 1); | |
| 181 | |
| 182 value = (GValue *) g_hash_table_lookup(table, "title"); | |
| 183 if (value && G_VALUE_HOLDS_STRING(value)) { | |
| 184 t->title = g_value_dup_string(value); | |
| 185 } | |
| 186 value = (GValue *) g_hash_table_lookup(table, "artist"); | |
| 187 if (value != NULL && G_VALUE_HOLDS_STRING(value)) { | |
| 188 t->artist = g_value_dup_string(value); | |
| 189 } | |
| 190 value = (GValue *) g_hash_table_lookup(table, "album"); | |
| 191 if (value != NULL && G_VALUE_HOLDS_STRING(value)) { | |
| 192 t->album = g_value_dup_string(value); | |
| 193 } | |
| 194 value = (GValue *) g_hash_table_lookup(table, "genre"); | |
| 195 if (value != NULL && G_VALUE_HOLDS_STRING(value)) { | |
| 196 t->genre = g_value_dup_string(value); | |
| 197 } | |
| 198 | |
| 199 return t; | |
| 0 | 200 } |
| 201 | |
| 18 | 202 void |
| 203 free_song_tuple(song_tuple *t) | |
| 204 { | |
| 205 g_free(t->title); | |
| 206 g_free(t->artist); | |
| 207 g_free(t->album); | |
| 208 g_free(t->genre); | |
| 209 | |
| 210 g_free(t); | |
| 211 } | |
| 212 | |
| 213 | |
| 214 static gchar * | |
| 215 format_song_info(song_tuple *tuple) | |
| 216 { | |
| 217 gchar *song_info = NULL, *tmp = NULL; | |
| 218 | |
| 219 if(!tuple) | |
| 220 return NULL; | |
| 221 | |
| 222 song_info = g_strdup(purple_prefs_get_string(OPT_SONG_TEMPLATE)); | |
| 223 if(!song_info) | |
| 224 return NULL; | |
| 225 | |
| 226 if(tuple->title && strstr(song_info, TITLE)) { | |
| 227 tmp = purple_strreplace(song_info, TITLE, tuple->title); | |
| 228 g_free(song_info); | |
| 229 song_info = tmp; | |
| 230 } | |
| 231 if(tuple->artist && strstr(song_info, ARTIST)) { | |
| 232 tmp = purple_strreplace(song_info, ARTIST, tuple->artist); | |
| 233 g_free(song_info); | |
| 234 song_info = tmp; | |
| 235 } | |
| 236 if(tuple->album && strstr(song_info, ALBUM)) { | |
| 237 tmp = purple_strreplace(song_info, ALBUM, tuple->album); | |
| 238 g_free(song_info); | |
| 239 song_info = tmp; | |
| 240 } | |
| 241 if(tuple->genre && strstr(song_info, GENRE)) { | |
| 242 tmp = purple_strreplace(song_info, GENRE, tuple->genre); | |
| 243 g_free(song_info); | |
| 244 song_info = tmp; | |
| 245 } | |
| 246 | |
| 247 return song_info; | |
| 248 } | |
| 249 | |
| 250 | |
| 251 | |
| 252 static void | |
| 253 track_signal_cb(DBusGProxy *player_proxy, GHashTable *table, gpointer data) | |
| 254 { | |
| 255 gchar *song_info = NULL; | |
| 256 song_tuple *tuple = get_song_tuple(table); | |
| 257 | |
| 258 /* set current song */ | |
| 259 purple_util_set_current_song(tuple->title ? tuple->title : "", | |
| 260 tuple->artist ? tuple->artist : "", | |
| 261 tuple->album ? tuple->album : ""); | |
| 262 | |
| 263 song_info = format_song_info(tuple); | |
| 264 | |
| 265 aud_process(song_info); | |
| 266 free_song_tuple(tuple); | |
| 267 g_free(song_info); | |
| 268 } | |
| 269 | |
| 270 | |
| 271 static void | |
| 272 status_signal_cb(DBusGProxy *player_proxy, gint status, gpointer data) | |
| 273 { | |
| 274 aud_debug("StatusChange %d\n", status); | |
| 275 | |
| 276 if (status != 0) { | |
| 277 aud_process(""); | |
| 278 | |
| 279 /* clear current song */ | |
| 280 purple_util_set_current_song(NULL, NULL, NULL); | |
| 281 | |
| 282 } | |
| 283 } | |
| 284 | |
| 285 | |
| 0 | 286 static void |
| 287 aud_process_status(PurpleConnection *gc, gchar *aud_info) | |
| 288 { | |
| 13 | 289 gchar *new = NULL, *key = NULL; |
| 290 const gchar *current, *seed, *pushed, *proto; | |
| 291 PurpleAccount *account; | |
| 292 PurplePresence *presence; | |
| 293 PurplePlugin *prpl; | |
| 294 PurplePluginProtocolInfo *prpl_info; | |
| 295 PurpleStatus *status; | |
| 0 | 296 |
| 13 | 297 account = purple_connection_get_account(gc); |
| 298 presence = purple_account_get_presence(account); | |
| 0 | 299 |
| 13 | 300 proto = purple_account_get_protocol_id(account); |
| 301 prpl = purple_find_prpl(proto); | |
| 302 g_return_if_fail(prpl != NULL); | |
| 0 | 303 |
| 13 | 304 prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(prpl); |
| 305 g_return_if_fail(prpl_info != NULL && prpl_info->set_status != NULL); | |
| 0 | 306 |
| 13 | 307 status = purple_presence_get_active_status(presence); |
| 308 g_return_if_fail(status != NULL); | |
| 0 | 309 |
| 13 | 310 /* generate key for hash table */ |
| 311 key = g_strdup_printf("%s %s", account->username, account->protocol_id); | |
| 0 | 312 |
|
1
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
313 /* retrieve current user status */ |
| 13 | 314 current = purple_status_get_attr_string(status, "message"); |
| 315 aud_debug("status current = %s\n", current); | |
| 0 | 316 |
|
1
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
317 /* invalidate pushded status on auto away etc. */ |
| 13 | 318 if(current == NULL || strlen(current) == 0) { |
| 319 g_hash_table_replace(pushed_status, g_strdup(key), g_strdup("")); | |
| 320 g_free(key); | |
|
1
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
321 return; |
|
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
322 } |
|
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
323 |
|
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
324 /* pop pushed_status */ |
|
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
325 pushed = (gchar *)g_hash_table_lookup(pushed_status, key); |
|
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
326 |
| 13 | 327 /* if current status differs from pushed_status or |
| 328 contains token, replace hashes with current. */ | |
| 329 if((pushed && g_ascii_strcasecmp(current, pushed)) || | |
| 330 strstr(current, SONG_TOKEN)) { | |
| 331 g_hash_table_replace(seed_status, g_strdup(key), g_strdup(current)); | |
|
1
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
332 g_hash_table_replace(pushed_status, g_strdup(key), g_strdup(current)); |
| 0 | 333 } |
| 334 | |
| 13 | 335 /* construct new status message */ |
| 336 seed = (gchar *)g_hash_table_lookup(seed_status, key); | |
| 337 if(!seed) { | |
| 338 g_free(key); | |
| 339 return; | |
| 340 } | |
| 341 aud_debug("status seed = %s\n", seed); | |
| 0 | 342 |
| 13 | 343 if(strstr(seed, SONG_TOKEN)) { |
| 344 if(aud_info){ | |
| 345 new = purple_strreplace(seed, SONG_TOKEN, aud_info); | |
| 346 } | |
| 347 else { | |
| 348 new = g_strdup(NO_SONG_MESSAGE); | |
| 349 } | |
| 350 } | |
|
12
79f081cdfb19
- fixed potential memory leaks.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
11
diff
changeset
|
351 |
| 13 | 352 if(!new) { |
| 353 g_free(key); | |
| 354 return; | |
| 355 } | |
| 0 | 356 |
| 13 | 357 /* set status message only if text has been changed */ |
| 358 pushed = (gchar *)g_hash_table_lookup(pushed_status, key); | |
| 359 aud_debug("status pushed = %s\n", pushed); | |
| 0 | 360 |
| 13 | 361 if (!pushed || g_ascii_strcasecmp(pushed, new)) { |
| 362 g_hash_table_replace(pushed_status, g_strdup(key), g_strdup(new)); | |
| 363 purple_status_set_attr_string(status, "message", new); | |
| 364 prpl_info->set_status(account, status); | |
| 365 } | |
| 366 g_free(key); | |
| 367 g_free(new); | |
| 0 | 368 } |
| 369 | |
| 370 | |
| 371 static void | |
| 372 aud_process_userinfo(PurpleConnection *gc, gchar *aud_info) | |
| 373 { | |
| 13 | 374 gchar *new = NULL, *key = NULL; |
| 375 const gchar *current, *seed, *pushed, *proto; | |
| 376 PurpleAccount *account; | |
| 377 PurplePlugin *prpl; | |
| 378 PurplePluginProtocolInfo *prpl_info; | |
| 0 | 379 |
| 13 | 380 account = purple_connection_get_account(gc); |
| 0 | 381 |
| 13 | 382 proto = purple_account_get_protocol_id(account); |
| 383 prpl = purple_find_prpl(proto); | |
| 384 g_return_if_fail(prpl != NULL); | |
| 0 | 385 |
| 13 | 386 prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(prpl); |
| 387 g_return_if_fail(prpl_info != NULL && prpl_info->set_info != NULL); | |
| 0 | 388 |
| 13 | 389 /* generate key for hash table*/ |
| 390 key = g_strdup_printf("%s %s", account->username, account->protocol_id); | |
| 0 | 391 |
| 13 | 392 /* retrieve current user info */ |
| 393 current = purple_account_get_user_info(account); /* from account.xml */ | |
| 394 aud_debug("userinfo current = %s\n", current); | |
|
1
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
395 |
| 13 | 396 /* invalidate pushded status on auto away etc. */ |
| 397 if(current == NULL || strlen(current) == 0) { | |
| 398 g_hash_table_replace(pushed_userinfo, g_strdup(key), g_strdup("")); | |
| 399 g_free(key); | |
| 400 return; | |
| 401 } | |
|
1
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
402 |
| 13 | 403 /* pop pushed_userinfo */ |
| 404 pushed = g_hash_table_lookup(pushed_userinfo, key); | |
| 0 | 405 |
|
17
14de631fa929
drop outdated alias support
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
16
diff
changeset
|
406 /* if current userinfo differs from pushed_userinfo or contains |
|
14de631fa929
drop outdated alias support
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
16
diff
changeset
|
407 token, replace seed with this. */ |
| 13 | 408 if((pushed && g_ascii_strcasecmp(current, pushed)) || |
| 409 strstr(current, SONG_TOKEN)) { | |
| 410 g_hash_table_replace(seed_userinfo, g_strdup(key), | |
| 411 g_strdup(current)); | |
| 412 g_hash_table_replace(pushed_userinfo, g_strdup(key), | |
| 413 g_strdup(current)); | |
| 414 } | |
| 0 | 415 |
| 13 | 416 /* construct new status message */ |
| 417 seed = (gchar *)g_hash_table_lookup(seed_userinfo, key); | |
| 418 if(!seed) { | |
| 419 g_free(key); | |
| 420 return; | |
| 421 } | |
| 422 aud_debug("userinfo seed = %s\n", seed); | |
| 0 | 423 |
| 13 | 424 if(strstr(seed, SONG_TOKEN)) { |
| 425 if(aud_info){ | |
| 426 new = purple_strreplace(seed, SONG_TOKEN, aud_info); | |
| 427 } | |
| 428 else { | |
| 429 new = g_strdup(NO_SONG_MESSAGE); | |
| 430 } | |
| 431 } | |
|
12
79f081cdfb19
- fixed potential memory leaks.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
11
diff
changeset
|
432 |
| 13 | 433 if(!new) { |
| 434 g_free(key); | |
| 435 return; | |
| 436 } | |
| 0 | 437 |
| 13 | 438 /* set user info only if text has been changed */ |
| 439 pushed = (gchar *)g_hash_table_lookup(pushed_userinfo, key); | |
| 440 aud_debug("userinfo pushed = %s\n", pushed); | |
| 0 | 441 |
| 13 | 442 if (!pushed || g_ascii_strcasecmp(pushed, new) != 0) { |
| 443 g_hash_table_replace(pushed_userinfo, g_strdup(key), | |
| 444 g_strdup(new)); | |
| 445 prpl_info->set_info(gc, new); | |
| 446 } | |
| 447 g_free(key); | |
| 448 g_free(new); | |
| 0 | 449 } |
| 450 | |
| 451 | |
| 452 static void | |
| 453 aud_process(gchar *aud_info) | |
| 454 { | |
| 13 | 455 GList *l; |
| 456 PurpleConnection *gc; | |
| 0 | 457 |
| 13 | 458 for (l = purple_connections_get_all(); l != NULL; l = l->next) { |
| 459 gc = (PurpleConnection *) l->data; | |
| 0 | 460 |
| 13 | 461 /* make sure we're connected */ |
| 462 if (purple_connection_get_state(gc) != PURPLE_CONNECTED) { | |
| 463 continue; | |
| 464 } | |
| 0 | 465 |
| 13 | 466 if (purple_prefs_get_bool(OPT_PROCESS_USERINFO)) { |
| 467 aud_process_userinfo(gc, aud_info); | |
| 468 } | |
| 0 | 469 |
| 13 | 470 if (purple_prefs_get_bool(OPT_PROCESS_STATUS)) { |
| 471 aud_process_status(gc, aud_info); | |
| 472 } | |
| 18 | 473 } |
| 0 | 474 |
| 475 } | |
| 18 | 476 |
| 0 | 477 static void |
| 478 removekey(gpointer data) | |
| 479 { | |
| 13 | 480 g_free(data); |
| 0 | 481 } |
| 482 | |
| 483 static void | |
| 484 removeval(gpointer data) | |
| 485 { | |
| 13 | 486 g_free(data); |
| 0 | 487 } |
| 488 | |
|
10
7c9624c8a109
added /song command which sends name of currently playing song.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
9
diff
changeset
|
489 static PurpleCmdRet |
| 13 | 490 paste_current_song(PurpleConversation *conv, const gchar *cmd, |
| 491 gchar **args, gchar **error, void *data) | |
|
10
7c9624c8a109
added /song command which sends name of currently playing song.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
9
diff
changeset
|
492 { |
| 13 | 493 gchar *song = NULL, *tmp = NULL, *tmp2 = NULL; |
|
10
7c9624c8a109
added /song command which sends name of currently playing song.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
9
diff
changeset
|
494 PurpleConversationType type = purple_conversation_get_type(conv); |
| 13 | 495 size_t dummy; |
|
11
43cb653de212
paste template has been implemented.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
10
diff
changeset
|
496 const gchar *template = NULL; |
|
10
7c9624c8a109
added /song command which sends name of currently playing song.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
9
diff
changeset
|
497 |
| 13 | 498 /* audacious isn't playing */ |
|
19
12d809123d69
- revised signed_on_cb() so that it calls purple_util_set_current_song().
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
18
diff
changeset
|
499 if(!is_app_playing()) { |
|
10
7c9624c8a109
added /song command which sends name of currently playing song.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
9
diff
changeset
|
500 return PURPLE_CMD_RET_OK; |
|
7c9624c8a109
added /song command which sends name of currently playing song.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
9
diff
changeset
|
501 } |
|
7c9624c8a109
added /song command which sends name of currently playing song.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
9
diff
changeset
|
502 |
| 18 | 503 /* dbus lookup */ |
| 504 GHashTable *table = get_song_table(); | |
| 505 song_tuple *tuple = get_song_tuple(table); | |
| 506 tmp = format_song_info(tuple); | |
| 507 free_song_tuple(tuple); | |
| 508 g_hash_table_destroy(table); | |
|
10
7c9624c8a109
added /song command which sends name of currently playing song.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
9
diff
changeset
|
509 |
|
11
43cb653de212
paste template has been implemented.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
10
diff
changeset
|
510 template = purple_prefs_get_string(OPT_PASTE_TEMPLATE); |
|
43cb653de212
paste template has been implemented.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
10
diff
changeset
|
511 |
|
43cb653de212
paste template has been implemented.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
10
diff
changeset
|
512 if(template && strstr(template, SONG_TOKEN)) { |
|
43cb653de212
paste template has been implemented.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
10
diff
changeset
|
513 tmp2 = purple_strreplace(template, SONG_TOKEN, tmp); |
|
43cb653de212
paste template has been implemented.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
10
diff
changeset
|
514 g_free(tmp); |
|
43cb653de212
paste template has been implemented.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
10
diff
changeset
|
515 tmp = NULL; |
|
43cb653de212
paste template has been implemented.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
10
diff
changeset
|
516 } |
|
43cb653de212
paste template has been implemented.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
10
diff
changeset
|
517 else { |
|
43cb653de212
paste template has been implemented.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
10
diff
changeset
|
518 tmp2 = tmp; |
|
43cb653de212
paste template has been implemented.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
10
diff
changeset
|
519 } |
|
43cb653de212
paste template has been implemented.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
10
diff
changeset
|
520 |
|
43cb653de212
paste template has been implemented.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
10
diff
changeset
|
521 if(tmp2) { |
|
43cb653de212
paste template has been implemented.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
10
diff
changeset
|
522 if(botch_utf) { |
|
43cb653de212
paste template has been implemented.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
10
diff
changeset
|
523 song = (gchar *) botch_utf(tmp2, strlen(tmp2), &dummy); |
|
43cb653de212
paste template has been implemented.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
10
diff
changeset
|
524 g_free(tmp2); |
|
43cb653de212
paste template has been implemented.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
10
diff
changeset
|
525 tmp2 = NULL; |
|
43cb653de212
paste template has been implemented.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
10
diff
changeset
|
526 } |
|
10
7c9624c8a109
added /song command which sends name of currently playing song.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
9
diff
changeset
|
527 else |
|
11
43cb653de212
paste template has been implemented.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
10
diff
changeset
|
528 song = tmp2; |
|
10
7c9624c8a109
added /song command which sends name of currently playing song.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
9
diff
changeset
|
529 } |
|
7c9624c8a109
added /song command which sends name of currently playing song.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
9
diff
changeset
|
530 |
|
7c9624c8a109
added /song command which sends name of currently playing song.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
9
diff
changeset
|
531 if(type == PURPLE_CONV_TYPE_CHAT) { |
|
7c9624c8a109
added /song command which sends name of currently playing song.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
9
diff
changeset
|
532 PurpleConvChat *chat = purple_conversation_get_chat_data(conv); |
|
7c9624c8a109
added /song command which sends name of currently playing song.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
9
diff
changeset
|
533 if (chat && song) |
|
7c9624c8a109
added /song command which sends name of currently playing song.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
9
diff
changeset
|
534 purple_conv_chat_send(chat, song); |
|
7c9624c8a109
added /song command which sends name of currently playing song.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
9
diff
changeset
|
535 } |
|
7c9624c8a109
added /song command which sends name of currently playing song.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
9
diff
changeset
|
536 else if(type == PURPLE_CONV_TYPE_IM) { |
|
7c9624c8a109
added /song command which sends name of currently playing song.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
9
diff
changeset
|
537 PurpleConvIm *im = purple_conversation_get_im_data(conv); |
|
7c9624c8a109
added /song command which sends name of currently playing song.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
9
diff
changeset
|
538 if(im && song) |
|
7c9624c8a109
added /song command which sends name of currently playing song.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
9
diff
changeset
|
539 purple_conv_im_send(im, song); |
|
7c9624c8a109
added /song command which sends name of currently playing song.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
9
diff
changeset
|
540 } |
|
7c9624c8a109
added /song command which sends name of currently playing song.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
9
diff
changeset
|
541 |
|
7c9624c8a109
added /song command which sends name of currently playing song.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
9
diff
changeset
|
542 g_free(song); |
|
7c9624c8a109
added /song command which sends name of currently playing song.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
9
diff
changeset
|
543 return PURPLE_CMD_RET_OK; |
|
7c9624c8a109
added /song command which sends name of currently playing song.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
9
diff
changeset
|
544 } |
| 0 | 545 |
| 18 | 546 static gboolean |
|
19
12d809123d69
- revised signed_on_cb() so that it calls purple_util_set_current_song().
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
18
diff
changeset
|
547 is_app_playing(void) |
| 18 | 548 { |
| 549 gchar *player_name = g_strconcat("org.mpris.", "audacious", NULL); | |
| 550 | |
| 551 #if 0 | |
| 552 if(g_strcasecmp(pidginmpris->player_name, player_name) != 0) { | |
| 553 pidginmpris->player_name = g_strdup(player_name); | |
| 554 g_object_unref(pidginmpris->player); | |
| 555 mpris_connect_dbus_signals(); | |
| 556 } | |
| 557 #endif | |
| 558 | |
| 559 DBusGProxy *player = | |
| 560 dbus_g_proxy_new_for_name_owner(connection, | |
| 561 player_name, | |
| 562 "/Player", | |
| 563 "org.freedesktop.MediaPlayer", | |
| 564 NULL); | |
| 565 | |
| 566 if(!player) | |
| 567 return FALSE; | |
| 568 | |
| 569 g_object_unref(player); | |
| 570 g_free(player_name); | |
| 571 return TRUE; | |
| 572 } | |
| 573 | |
| 574 static void | |
| 575 signed_on_cb(PurpleConnection *gc, void *data) | |
| 576 { | |
| 577 gchar *song_info = NULL; | |
| 578 GHashTable *table = NULL; | |
| 579 song_tuple *tuple = NULL; | |
| 580 | |
|
19
12d809123d69
- revised signed_on_cb() so that it calls purple_util_set_current_song().
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
18
diff
changeset
|
581 aud_debug("called\n"); |
|
12d809123d69
- revised signed_on_cb() so that it calls purple_util_set_current_song().
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
18
diff
changeset
|
582 |
| 18 | 583 table = get_song_table(); |
| 584 tuple = get_song_tuple(table); | |
|
19
12d809123d69
- revised signed_on_cb() so that it calls purple_util_set_current_song().
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
18
diff
changeset
|
585 g_hash_table_destroy(table); |
|
12d809123d69
- revised signed_on_cb() so that it calls purple_util_set_current_song().
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
18
diff
changeset
|
586 |
|
12d809123d69
- revised signed_on_cb() so that it calls purple_util_set_current_song().
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
18
diff
changeset
|
587 /* set current song */ |
|
12d809123d69
- revised signed_on_cb() so that it calls purple_util_set_current_song().
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
18
diff
changeset
|
588 purple_util_set_current_song(tuple->title ? tuple->title : "", |
|
12d809123d69
- revised signed_on_cb() so that it calls purple_util_set_current_song().
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
18
diff
changeset
|
589 tuple->artist ? tuple->artist : "", |
|
12d809123d69
- revised signed_on_cb() so that it calls purple_util_set_current_song().
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
18
diff
changeset
|
590 tuple->album ? tuple->album : ""); |
| 18 | 591 |
| 592 song_info = format_song_info(tuple); | |
| 593 free_song_tuple(tuple); | |
| 594 | |
|
19
12d809123d69
- revised signed_on_cb() so that it calls purple_util_set_current_song().
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
18
diff
changeset
|
595 aud_process(song_info); |
| 18 | 596 g_free(song_info); |
| 597 } | |
| 598 | |
| 599 | |
|
19
12d809123d69
- revised signed_on_cb() so that it calls purple_util_set_current_song().
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
18
diff
changeset
|
600 static void |
|
12d809123d69
- revised signed_on_cb() so that it calls purple_util_set_current_song().
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
18
diff
changeset
|
601 prefs_cb(const char *name, PurplePrefType type, |
| 18 | 602 gconstpointer value, gpointer data) |
| 603 { | |
| 604 aud_debug("settings change detected at %s\n", name); | |
| 605 signed_on_cb(NULL, NULL); | |
| 606 } | |
| 607 | |
| 0 | 608 static gboolean |
| 609 load_plugin(PurplePlugin *plugin) | |
| 610 { | |
| 13 | 611 seed_status = g_hash_table_new_full(g_str_hash, g_str_equal, |
| 612 removekey, removeval); | |
| 613 seed_userinfo = g_hash_table_new_full(g_str_hash, g_str_equal, | |
| 614 removekey, removeval); | |
| 0 | 615 |
| 13 | 616 pushed_status = g_hash_table_new_full(g_str_hash, g_str_equal, |
| 617 removekey, removeval); | |
| 618 pushed_userinfo = g_hash_table_new_full(g_str_hash, g_str_equal, | |
| 619 removekey, removeval); | |
| 0 | 620 |
| 18 | 621 |
| 622 session = get_dbus_session(); | |
| 623 | |
| 624 /* connect to mpris signals */ | |
| 625 connect_dbus_signals(); | |
| 626 | |
| 627 /* connect to purple signals */ | |
|
19
12d809123d69
- revised signed_on_cb() so that it calls purple_util_set_current_song().
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
18
diff
changeset
|
628 connect_purple_signals(plugin); |
| 18 | 629 |
| 630 status_signal_cb(NULL, -1, NULL); | |
| 631 | |
| 632 | |
| 633 /* register /song command */ | |
|
10
7c9624c8a109
added /song command which sends name of currently playing song.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
9
diff
changeset
|
634 cmdid_paste_current_song = |
|
7c9624c8a109
added /song command which sends name of currently playing song.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
9
diff
changeset
|
635 purple_cmd_register("song", "", PURPLE_CMD_P_DEFAULT, |
|
7c9624c8a109
added /song command which sends name of currently playing song.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
9
diff
changeset
|
636 PURPLE_CMD_FLAG_IM | PURPLE_CMD_FLAG_CHAT, |
|
7c9624c8a109
added /song command which sends name of currently playing song.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
9
diff
changeset
|
637 NULL, paste_current_song, |
|
7c9624c8a109
added /song command which sends name of currently playing song.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
9
diff
changeset
|
638 "song: Paste currently plaing song", NULL); |
| 0 | 639 |
| 13 | 640 return TRUE; |
| 0 | 641 } |
| 642 | |
| 643 static gboolean | |
| 644 unload_plugin(PurplePlugin *plugin) | |
| 645 { | |
| 13 | 646 aud_debug("pidgin-audacious unload called\n"); |
| 0 | 647 |
| 13 | 648 g_hash_table_destroy(seed_status); |
| 649 g_hash_table_destroy(seed_userinfo); | |
| 0 | 650 |
| 13 | 651 g_hash_table_destroy(pushed_status); |
| 652 g_hash_table_destroy(pushed_userinfo); | |
| 0 | 653 |
|
10
7c9624c8a109
added /song command which sends name of currently playing song.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
9
diff
changeset
|
654 purple_cmd_unregister(cmdid_paste_current_song); |
|
7c9624c8a109
added /song command which sends name of currently playing song.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
9
diff
changeset
|
655 |
| 18 | 656 if(session) { |
| 657 g_object_unref(session); | |
| 658 session = NULL; | |
| 659 } | |
|
14
89bd98990fff
now it tries to get dbus proxy if session is NULL.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
13
diff
changeset
|
660 |
|
16
9e37b72309d4
- clear current song if audacious is not playing.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
15
diff
changeset
|
661 if(connection) { |
|
9e37b72309d4
- clear current song if audacious is not playing.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
15
diff
changeset
|
662 dbus_g_connection_unref(connection); |
|
9e37b72309d4
- clear current song if audacious is not playing.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
15
diff
changeset
|
663 connection = NULL; |
|
9e37b72309d4
- clear current song if audacious is not playing.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
15
diff
changeset
|
664 } |
|
9e37b72309d4
- clear current song if audacious is not playing.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
15
diff
changeset
|
665 |
| 13 | 666 return TRUE; |
| 0 | 667 } |
| 668 | |
| 669 static PurplePluginPrefFrame * | |
| 670 get_plugin_pref_frame(PurplePlugin *plugin) | |
| 671 { | |
| 13 | 672 PurplePluginPref *pref; |
| 673 PurplePluginPrefFrame *frame = purple_plugin_pref_frame_new(); | |
| 0 | 674 |
| 13 | 675 /* create gtk elements for the plugin preferences */ |
| 676 pref = purple_plugin_pref_new_with_label( | |
| 677 "Pidgin-Audacious Configuration"); | |
| 678 purple_plugin_pref_frame_add(frame, pref); | |
|
9
d5702f04b19c
Fixed a bug that disabling this plugin while watch dog function has been hooked causes crash.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
679 |
| 13 | 680 pref = purple_plugin_pref_new_with_name_and_label( |
| 681 OPT_PROCESS_STATUS, | |
| 682 "Expand " SONG_TOKEN " to song info in the status message"); | |
| 683 purple_plugin_pref_frame_add(frame, pref); | |
|
9
d5702f04b19c
Fixed a bug that disabling this plugin while watch dog function has been hooked causes crash.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
684 |
| 13 | 685 pref = purple_plugin_pref_new_with_name_and_label( |
| 686 OPT_PROCESS_USERINFO, | |
| 687 "Expand " SONG_TOKEN " to song info in the user info"); | |
| 688 purple_plugin_pref_frame_add(frame, pref); | |
| 0 | 689 |
| 18 | 690 /* song template */ |
| 691 pref = purple_plugin_pref_new_with_name_and_label( | |
| 692 OPT_SONG_TEMPLATE, | |
| 693 "Song template"); | |
| 694 purple_plugin_pref_frame_add(frame, pref); | |
| 695 | |
|
11
43cb653de212
paste template has been implemented.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
10
diff
changeset
|
696 /* paste template */ |
| 13 | 697 pref = purple_plugin_pref_new_with_name_and_label( |
| 698 OPT_PASTE_TEMPLATE, | |
| 699 "Paste template"); | |
| 700 purple_plugin_pref_frame_add(frame, pref); | |
|
11
43cb653de212
paste template has been implemented.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
10
diff
changeset
|
701 |
| 13 | 702 return frame; |
| 0 | 703 } |
| 704 | |
| 705 static PurplePluginUiInfo pref_info = | |
| 706 { | |
| 13 | 707 get_plugin_pref_frame |
| 0 | 708 }; |
| 709 | |
| 710 static PurplePluginInfo info = | |
| 711 { | |
| 13 | 712 PURPLE_PLUGIN_MAGIC, |
| 713 PURPLE_MAJOR_VERSION, | |
| 714 PURPLE_MINOR_VERSION, | |
| 715 PURPLE_PLUGIN_STANDARD, /**< type */ | |
| 716 NULL, /**< ui_req */ | |
| 717 0, /**< flags */ | |
| 718 NULL, /**< deps */ | |
| 719 PURPLE_PRIORITY_DEFAULT, /**< priority */ | |
| 720 PIDGINAUD_PLUGIN_ID, /**< id */ | |
| 721 "Pidgin-Audacious", /**< name */ | |
|
19
12d809123d69
- revised signed_on_cb() so that it calls purple_util_set_current_song().
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
18
diff
changeset
|
722 "3.0.0d1", /**< version */ |
| 13 | 723 "Automatically updates your Pidgin status info with the currently " |
| 724 "playing music in Audacious.", /** summary */ | |
| 725 "Automatically updates your Pidgin status info with the currently " | |
| 726 "playing music in Audacious.", /** desc */ | |
| 727 "Yoshiki Yazawa (yaz@honeyplanet.jp)", /**< author */ | |
| 728 "http://www.honeyplanet.jp", /**< homepage */ | |
| 729 load_plugin, /**< load */ | |
| 730 unload_plugin, /**< unload */ | |
| 731 NULL, /**< destroy */ | |
| 732 NULL, /**< ui_info */ | |
| 733 NULL, /**< extra_info */ | |
| 734 &pref_info, /**< pref info */ | |
| 735 NULL | |
| 0 | 736 }; |
| 737 | |
| 738 static void | |
| 739 init_plugin(PurplePlugin *plugin) | |
| 740 { | |
| 13 | 741 g_type_init(); |
| 0 | 742 |
| 13 | 743 /* add plugin preferences */ |
| 744 purple_prefs_add_none(OPT_PIDGINAUD); | |
| 745 purple_prefs_add_bool(OPT_PROCESS_STATUS, TRUE); | |
| 746 purple_prefs_add_bool(OPT_PROCESS_USERINFO, TRUE); | |
| 18 | 747 purple_prefs_add_string(OPT_SONG_TEMPLATE, DEFAULT_SONG_TEMPLATE); |
|
11
43cb653de212
paste template has been implemented.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
10
diff
changeset
|
748 purple_prefs_add_string(OPT_PASTE_TEMPLATE, SONG_TOKEN); |
|
19
12d809123d69
- revised signed_on_cb() so that it calls purple_util_set_current_song().
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
18
diff
changeset
|
749 purple_prefs_add_bool(OPT_LOG_OUTPUT, TRUE); |
| 0 | 750 |
| 751 } | |
| 752 | |
| 753 PURPLE_INIT_PLUGIN(pidgin_audacious, init_plugin, info) |
