root / widget_prpl.c @ cd75287ef15854838c5bd632a56eb0441c5e74ac
History | View | Annotate | Download (7.7 KB)
| 1 | /* File: widget_prpl.c
|
|---|---|
| 2 | Time-stamp: <2012-04-05 17:22:08 gawen> |
| 3 | |
| 4 | Copyright (C) 2010 David Hauweele <david@hauweele.net> |
| 5 | Copyright (C) 2008,2009 Craig Harding <craigwharding@gmail.com> |
| 6 | Wolter Hellmund <wolterh@gmail.com> |
| 7 | |
| 8 | This program is free software: you can redistribute it and/or modify |
| 9 | it under the terms of the GNU General Public License as published by |
| 10 | the Free Software Foundation, either version 3 of the License, or |
| 11 | (at your option) any later version. |
| 12 | |
| 13 | This program is distributed in the hope that it will be useful, |
| 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | GNU General Public License for more details. |
| 17 | |
| 18 | You should have received a copy of the GNU General Public License |
| 19 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
| 20 | |
| 21 | #include "common.h" |
| 22 | |
| 23 | #include "preferences.h" |
| 24 | #include "widget.h" |
| 25 | #include "widget_prpl.h" |
| 26 | #include "purple.h" |
| 27 | |
| 28 | static GList * append_attr(GList *list, const gchar *id, const gchar *value) |
| 29 | {
|
| 30 | list = g_list_append(list, (gpointer)id); |
| 31 | return g_list_append(list, (gpointer)value);
|
| 32 | } |
| 33 | |
| 34 | void cb_status(PurpleAccount *account, PurpleStatus *old, PurpleStatus *new)
|
| 35 | {
|
| 36 | g_return_if_fail(bar->installed); |
| 37 | |
| 38 | PurpleStatusPrimitive prim; |
| 39 | const gchar *stock, *pm;
|
| 40 | |
| 41 | PurpleSavedStatus *status = purple_savedstatus_get_current(); |
| 42 | if(purple_prefs_get_bool(PREF "/override-status")) { |
| 43 | pm = purple_prefs_get_string(PREF "/personal-message");
|
| 44 | purple_savedstatus_set_message(status,pm); |
| 45 | purple_savedstatus_activate(status); |
| 46 | } |
| 47 | else {
|
| 48 | const gchar *markup;
|
| 49 | markup = purple_prefs_get_string(PREF "/personal-message-markup");
|
| 50 | pm = purple_savedstatus_get_message(status); |
| 51 | if(!pm)
|
| 52 | pm = "";
|
| 53 | set_widget_pm(markup, pm); |
| 54 | purple_prefs_set_string(PREF "/personal-message", pm);
|
| 55 | } |
| 56 | |
| 57 | /* we should at least check for the current song,
|
| 58 | if it's different we just apply the new one */ |
| 59 | if(!is_same_song(old, new)) {
|
| 60 | GList *a_tune = NULL;
|
| 61 | const gchar *value;
|
| 62 | |
| 63 | value = purple_status_get_attr_string(new, PURPLE_TUNE_TITLE); |
| 64 | purple_prefs_set_string(PREF "/tune-title", value);
|
| 65 | append_attr(a_tune, PURPLE_TUNE_TITLE, value); |
| 66 | |
| 67 | value = purple_status_get_attr_string(new, PURPLE_TUNE_ALBUM); |
| 68 | purple_prefs_set_string(PREF "/tune-album", value);
|
| 69 | append_attr(a_tune, PURPLE_TUNE_ALBUM, value); |
| 70 | |
| 71 | value = purple_status_get_attr_string(new, PURPLE_TUNE_ARTIST); |
| 72 | purple_prefs_set_string(PREF "/tune-artist", value);
|
| 73 | append_attr(a_tune, PURPLE_TUNE_ARTIST, value); |
| 74 | |
| 75 | set_status_all("tune", a_tune);
|
| 76 | g_list_free(a_tune); |
| 77 | } |
| 78 | |
| 79 | prim = purple_savedstatus_get_type(status); |
| 80 | stock = pidgin_stock_id_from_status_primitive(prim); |
| 81 | set_widget_status(stock); |
| 82 | } |
| 83 | |
| 84 | void cb_signed_off(PurpleConnection *gc)
|
| 85 | {
|
| 86 | PurpleAccount *acct = purple_connection_get_account(gc); |
| 87 | update_available_features(acct, FALSE); |
| 88 | update_available_widgets(); |
| 89 | } |
| 90 | |
| 91 | void cb_signed_on(PurpleConnection *gc)
|
| 92 | {
|
| 93 | const gchar *name = purple_prefs_get_string(PREF "/nickname"); |
| 94 | PurpleAccount *account = purple_connection_get_account(gc); |
| 95 | set_display_name(account, name); |
| 96 | update_available_features(account, TRUE); |
| 97 | update_available_widgets(); |
| 98 | |
| 99 | purple_debug_info(NAME, "nickname changed to \"%s\" by signed-on account\n",
|
| 100 | name); |
| 101 | |
| 102 | if(gc && gc->flags & PURPLE_CONNECTION_SUPPORT_MOODS) {
|
| 103 | const gchar *mood = purple_prefs_get_string(PREF "/mood"); |
| 104 | set_status_with_mood(account, mood); |
| 105 | |
| 106 | purple_debug_info(NAME, "mood changed to \"%s\" by signed-on account\n",
|
| 107 | mood); |
| 108 | } |
| 109 | |
| 110 | /* load tune and stuff */
|
| 111 | GList *a_tune = NULL;
|
| 112 | GList *a_mood = NULL;
|
| 113 | |
| 114 | const struct attrs { |
| 115 | const gchar *pref;
|
| 116 | const gchar *attr;
|
| 117 | GList **list; |
| 118 | } attrs[] = {
|
| 119 | { PREF "/mood-message", PURPLE_MOOD_COMMENT, &a_mood },
|
| 120 | { PREF "/tune-title", PURPLE_TUNE_TITLE, &a_tune },
|
| 121 | { PREF "/tune-artist", PURPLE_TUNE_ARTIST, &a_tune },
|
| 122 | { PREF "/tune-album", PURPLE_TUNE_ALBUM, &a_tune },
|
| 123 | { PREF "/game-message", "game", &a_tune },
|
| 124 | { PREF "/office-message", "office", &a_tune },
|
| 125 | { NULL, NULL, NULL }
|
| 126 | }; const register struct attrs *a = attrs; |
| 127 | |
| 128 | for(; a->pref ; a++) {
|
| 129 | const gchar *value;
|
| 130 | |
| 131 | if(purple_prefs_get_bool(PREF "/reset-attrs")) |
| 132 | value = NULL;
|
| 133 | else
|
| 134 | value = purple_prefs_get_string(a->pref); |
| 135 | |
| 136 | if(value && !strcmp(value, "")) |
| 137 | value = NULL;
|
| 138 | else
|
| 139 | purple_debug_info(NAME, "%s message changed to \"%s\" by signed-on account\n",
|
| 140 | a->attr, value); |
| 141 | |
| 142 | *(a->list) = g_list_append(*(a->list), (gpointer)a->attr); |
| 143 | *(a->list) = g_list_append(*(a->list), (gpointer)value); |
| 144 | } |
| 145 | |
| 146 | const struct status_list { |
| 147 | const gchar *status_id;
|
| 148 | GList *list; |
| 149 | gboolean cont; |
| 150 | } status[] = {
|
| 151 | { "tune", a_tune, TRUE },
|
| 152 | { "mood", a_mood, TRUE },
|
| 153 | { NULL, NULL, FALSE}
|
| 154 | }; register const struct status_list *s = status; |
| 155 | |
| 156 | for(; s->cont ; s++) {
|
| 157 | purple_account_set_status_list(account, s->status_id, TRUE, s->list); |
| 158 | g_list_free(s->list); |
| 159 | } |
| 160 | } |
| 161 | |
| 162 | void cb_buddy_icon_update(const char *name, PurplePrefType type, |
| 163 | gconstpointer val, gpointer data) |
| 164 | {
|
| 165 | g_return_if_fail(bar->installed); |
| 166 | |
| 167 | GdkPixbuf *icon; |
| 168 | |
| 169 | icon = get_buddy_icon(); |
| 170 | set_widget_icon(icon); |
| 171 | } |
| 172 | |
| 173 | void cb_name_apply(PurpleAccount *account, const char *user_info) |
| 174 | {
|
| 175 | g_return_if_fail(bar->installed); |
| 176 | |
| 177 | const gchar *markup, *name;
|
| 178 | |
| 179 | name = user_info; |
| 180 | markup = purple_prefs_get_string(PREF "/nickname-markup");
|
| 181 | set_widget_name(markup, name); |
| 182 | |
| 183 | purple_prefs_set_string(PREF "/nickname", name);
|
| 184 | set_display_name_all(name); |
| 185 | |
| 186 | bar->name_dialog = FALSE; |
| 187 | |
| 188 | purple_debug_info(NAME, "nickname changed to \"%s\" by user\n", name);
|
| 189 | } |
| 190 | |
| 191 | void cb_name_cancel(PurpleAccount *account, const char *user_info) |
| 192 | {
|
| 193 | g_return_if_fail(bar->installed); |
| 194 | |
| 195 | bar->name_dialog = FALSE; |
| 196 | } |
| 197 | |
| 198 | void cb_pm_apply(gpointer data, PurpleRequestFields *fields)
|
| 199 | {
|
| 200 | g_return_if_fail(bar->installed); |
| 201 | |
| 202 | /* attrs */
|
| 203 | GList *a_tune = NULL;
|
| 204 | GList *a_mood = NULL;
|
| 205 | |
| 206 | /* just to update widget */
|
| 207 | const gchar *pm = purple_request_fields_get_string(fields, PREF "/personal-message"); |
| 208 | const gchar *markup = purple_prefs_get_string(PREF "/personal-message-markup"); |
| 209 | set_status_message(pm); |
| 210 | set_widget_pm(markup, pm); |
| 211 | purple_debug_info(NAME, "personal message changed to \"%s\" by user\n", pm);
|
| 212 | |
| 213 | const struct r_field { |
| 214 | const gchar *id;
|
| 215 | const gchar *attr;
|
| 216 | GList **list; |
| 217 | } r_fields[] = {
|
| 218 | { PREF "/mood-message", PURPLE_MOOD_COMMENT, &a_mood },
|
| 219 | { PREF "/tune-title", PURPLE_TUNE_TITLE, &a_tune },
|
| 220 | { PREF "/tune-artist", PURPLE_TUNE_ARTIST, &a_tune },
|
| 221 | { PREF "/tune-album", PURPLE_TUNE_ALBUM, &a_tune },
|
| 222 | { PREF "/game-message", "game", &a_tune },
|
| 223 | { PREF "/office-message", "office", &a_tune },
|
| 224 | { NULL, NULL, NULL }
|
| 225 | }; const register struct r_field *rf = r_fields; |
| 226 | |
| 227 | for(; rf->id ; rf++) {
|
| 228 | const gchar *value = purple_request_fields_get_string(fields, rf->id);
|
| 229 | |
| 230 | if(!purple_prefs_get_bool(PREF "/reset-attrs")) |
| 231 | purple_prefs_set_string(rf->id, value); |
| 232 | |
| 233 | if(value && !strcmp(value, "")) |
| 234 | value = NULL;
|
| 235 | else
|
| 236 | purple_debug_info(NAME, "%s message changed to \"%s\" by user\n",
|
| 237 | rf->attr, value); |
| 238 | |
| 239 | *(rf->list) = append_attr(*(rf->list), rf->attr, value); |
| 240 | } |
| 241 | |
| 242 | const struct status_list { |
| 243 | const gchar *status_id;
|
| 244 | GList *list; |
| 245 | gboolean cont; |
| 246 | } status[] = {
|
| 247 | { "tune", a_tune, TRUE },
|
| 248 | { "mood", a_mood, TRUE },
|
| 249 | { NULL, NULL, FALSE}
|
| 250 | }; register const struct status_list *s = status; |
| 251 | |
| 252 | for(; s->cont ; s++) {
|
| 253 | set_status_all(s->status_id, s->list); |
| 254 | g_list_free(s->list); |
| 255 | } |
| 256 | |
| 257 | bar->pm_dialog = FALSE; |
| 258 | } |
| 259 | |
| 260 | void cb_pm_cancel(gpointer data, PurpleRequestFields *fields)
|
| 261 | {
|
| 262 | g_return_if_fail(bar->installed); |
| 263 | |
| 264 | bar->pm_dialog = FALSE; |
| 265 | } |