Tue, 16 Nov 2004 02:22:16 +0000
[gaim-migrate @ 11306]
Minor changes to the status selector:
-Use the imhtml creation helper thing
-Change the if (new status) to check the type_id instead of the type name
(which could theoretically be NULL)
-Only attempt to set away if the away state was chosen
This definitely still doesn't work for oscar. Just by looking at the
code I don't believe the message input works for anything, as is.
Setting "away" apparently works for MSN, maybe other stuff.
| 10178 | 1 | /** |
| 2 | * @file gtkstatusselector.c Status selector widget | |
| 3 | * @ingroup gtkui | |
| 4 | * | |
| 5 | * gaim | |
| 6 | * | |
| 7 | * Gaim is the legal property of its developers, whose names are too numerous | |
| 8 | * to list here. Please refer to the COPYRIGHT file distributed with this | |
| 9 | * source distribution. | |
| 10 | * | |
| 11 | * This program is free software; you can redistribute it and/or modify | |
| 12 | * it under the terms of the GNU General Public License as published by | |
| 13 | * the Free Software Foundation; either version 2 of the License, or | |
| 14 | * (at your option) any later version. | |
| 15 | * | |
| 16 | * This program is distributed in the hope that it will be useful, | |
| 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 19 | * GNU General Public License for more details. | |
| 20 | * | |
| 21 | * You should have received a copy of the GNU General Public License | |
| 22 | * along with this program; if not, write to the Free Software | |
| 23 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| 24 | */ | |
| 25 | #include "internal.h" | |
| 26 | #include "gtkgaim.h" | |
| 27 | #include "gtkimhtml.h" | |
| 28 | #include "gtkstatusselector.h" | |
| 29 | #include "gtkutils.h" | |
| 30 | ||
| 31 | #include "account.h" | |
| 32 | #include "debug.h" | |
| 33 | #include "prefs.h" | |
| 34 | ||
| 35 | struct _GaimGtkStatusSelectorPrivate | |
| 36 | { | |
| 37 | GtkWidget *combo; | |
| 38 | GtkWidget *entry; | |
|
10191
d6fae5c19e96
[gaim-migrate @ 11306]
Mark Doliner <markdoliner@pidgin.im>
parents:
10188
diff
changeset
|
39 | GtkWidget *frame; |
| 10178 | 40 | |
| 41 | #if GTK_CHECK_VERSION(2,4,0) | |
| 42 | GtkListStore *model; | |
| 43 | #endif | |
| 44 | }; | |
| 45 | ||
| 46 | #if GTK_CHECK_VERSION(2,4,0) | |
| 47 | enum | |
| 48 | { | |
| 49 | COLUMN_STATUS_TYPE_ID, | |
| 50 | COLUMN_ICON, | |
| 51 | COLUMN_NAME, | |
| 52 | NUM_COLUMNS | |
| 53 | }; | |
| 54 | #endif /* GTK >= 2.4.0 */ | |
| 55 | ||
| 56 | static void gaim_gtk_status_selector_class_init(GaimGtkStatusSelectorClass *klass); | |
| 57 | static void gaim_gtk_status_selector_init(GaimGtkStatusSelector *selector); | |
| 58 | static void gaim_gtk_status_selector_finalize(GObject *obj); | |
| 59 | static void gaim_gtk_status_selector_destroy(GtkObject *obj); | |
| 60 | static void status_switched_cb(GtkWidget *combo, GaimGtkStatusSelector *selector); | |
| 61 | static void signed_on_off_cb(GaimConnection *gc, GaimGtkStatusSelector *selector); | |
| 62 | static void rebuild_list(GaimGtkStatusSelector *selector); | |
| 63 | ||
| 64 | static GtkVBox *parent_class = NULL; | |
| 65 | ||
| 66 | GType | |
| 67 | gaim_gtk_status_selector_get_type(void) | |
| 68 | { | |
| 69 | static GType type = 0; | |
| 70 | ||
| 71 | if (!type) | |
| 72 | { | |
| 73 | static const GTypeInfo info = | |
| 74 | { | |
| 75 | sizeof(GaimGtkStatusSelectorClass), | |
| 76 | NULL, | |
| 77 | NULL, | |
| 78 | (GClassInitFunc)gaim_gtk_status_selector_class_init, | |
| 79 | NULL, | |
| 80 | NULL, | |
| 81 | sizeof(GaimGtkStatusSelector), | |
| 82 | 0, | |
| 83 | (GInstanceInitFunc)gaim_gtk_status_selector_init | |
| 84 | }; | |
| 85 | ||
| 86 | type = g_type_register_static(GTK_TYPE_VBOX, | |
| 87 | "GaimGtkStatusSelector", &info, 0); | |
| 88 | } | |
| 89 | ||
| 90 | return type; | |
| 91 | } | |
| 92 | ||
| 93 | static void | |
| 94 | gaim_gtk_status_selector_class_init(GaimGtkStatusSelectorClass *klass) | |
| 95 | { | |
| 96 | GObjectClass *gobject_class; | |
| 97 | GtkObjectClass *object_class; | |
| 98 | ||
| 99 | parent_class = g_type_class_peek_parent(klass); | |
| 100 | ||
| 101 | gobject_class = G_OBJECT_CLASS(klass); | |
| 102 | object_class = GTK_OBJECT_CLASS(klass); | |
| 103 | ||
| 104 | gobject_class->finalize = gaim_gtk_status_selector_finalize; | |
| 105 | ||
| 106 | object_class->destroy = gaim_gtk_status_selector_destroy; | |
| 107 | } | |
| 108 | ||
| 109 | static void | |
| 110 | gaim_gtk_status_selector_init(GaimGtkStatusSelector *selector) | |
| 111 | { | |
| 112 | GtkWidget *combo; | |
| 113 | GtkWidget *entry; | |
|
10191
d6fae5c19e96
[gaim-migrate @ 11306]
Mark Doliner <markdoliner@pidgin.im>
parents:
10188
diff
changeset
|
114 | GtkWidget *toolbar; |
|
d6fae5c19e96
[gaim-migrate @ 11306]
Mark Doliner <markdoliner@pidgin.im>
parents:
10188
diff
changeset
|
115 | GtkWidget *frame; |
| 10178 | 116 | #if GTK_CHECK_VERSION(2,4,0) |
| 117 | GtkCellRenderer *renderer; | |
| 118 | #endif | |
| 119 | ||
| 120 | selector->priv = g_new0(GaimGtkStatusSelectorPrivate, 1); | |
| 121 | ||
| 122 | #if GTK_CHECK_VERSION(2,4,0) | |
| 123 | selector->priv->model = gtk_list_store_new(NUM_COLUMNS, G_TYPE_POINTER, | |
| 124 | GDK_TYPE_PIXBUF, G_TYPE_STRING); | |
| 125 | ||
| 126 | combo = gtk_combo_box_new_with_model(GTK_TREE_MODEL(selector->priv->model)); | |
| 127 | selector->priv->combo = combo; | |
| 128 | ||
| 129 | g_object_unref(G_OBJECT(selector->priv->model)); | |
| 130 | ||
| 131 | renderer = gtk_cell_renderer_pixbuf_new(); | |
| 132 | gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combo), renderer, FALSE); | |
| 133 | gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(combo), renderer, | |
| 134 | "pixbuf", COLUMN_ICON, | |
| 135 | NULL); | |
| 136 | ||
| 137 | renderer = gtk_cell_renderer_text_new(); | |
| 138 | gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combo), renderer, TRUE); | |
| 139 | gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(combo), renderer, | |
| 140 | "text", COLUMN_NAME, | |
| 141 | NULL); | |
| 142 | ||
| 143 | g_signal_connect(G_OBJECT(combo), "changed", | |
| 144 | G_CALLBACK(status_switched_cb), selector); | |
| 145 | #else /* GTK < 2.4.0 */ | |
| 146 | ||
| 147 | /* TODO */ | |
| 148 | ||
| 149 | #endif /* GTK < 2.4.0 */ | |
| 150 | ||
| 151 | gtk_widget_show(combo); | |
| 152 | gtk_box_pack_start(GTK_BOX(selector), combo, FALSE, FALSE, 0); | |
| 153 | ||
|
10191
d6fae5c19e96
[gaim-migrate @ 11306]
Mark Doliner <markdoliner@pidgin.im>
parents:
10188
diff
changeset
|
154 | frame = gaim_gtk_create_imhtml(TRUE, &entry, &toolbar); |
|
d6fae5c19e96
[gaim-migrate @ 11306]
Mark Doliner <markdoliner@pidgin.im>
parents:
10188
diff
changeset
|
155 | selector->priv->entry = entry; |
|
d6fae5c19e96
[gaim-migrate @ 11306]
Mark Doliner <markdoliner@pidgin.im>
parents:
10188
diff
changeset
|
156 | selector->priv->frame = frame; |
|
d6fae5c19e96
[gaim-migrate @ 11306]
Mark Doliner <markdoliner@pidgin.im>
parents:
10188
diff
changeset
|
157 | gtk_widget_set_name(entry, "gaim_gtkstatusselector_imhtml"); |
|
d6fae5c19e96
[gaim-migrate @ 11306]
Mark Doliner <markdoliner@pidgin.im>
parents:
10188
diff
changeset
|
158 | gtk_box_pack_start(GTK_BOX(selector), frame, TRUE, TRUE, 0); |
|
d6fae5c19e96
[gaim-migrate @ 11306]
Mark Doliner <markdoliner@pidgin.im>
parents:
10188
diff
changeset
|
159 | gtk_widget_hide(toolbar); |
| 10178 | 160 | |
| 161 | gaim_signal_connect(gaim_connections_get_handle(), "signed-on", | |
| 162 | selector, GAIM_CALLBACK(signed_on_off_cb), | |
| 163 | selector); | |
| 164 | gaim_signal_connect(gaim_connections_get_handle(), "signed-off", | |
| 165 | selector, GAIM_CALLBACK(signed_on_off_cb), | |
| 166 | selector); | |
| 167 | ||
| 168 | rebuild_list(selector); | |
| 169 | } | |
| 170 | ||
| 171 | static void | |
| 172 | gaim_gtk_status_selector_finalize(GObject *obj) | |
| 173 | { | |
| 174 | GaimGtkStatusSelector *selector; | |
| 175 | ||
| 176 | g_return_if_fail(obj != NULL); | |
| 177 | g_return_if_fail(GAIM_GTK_IS_STATUS_SELECTOR(obj)); | |
| 178 | ||
| 179 | selector = GAIM_GTK_STATUS_SELECTOR(obj); | |
| 180 | ||
| 181 | g_free(selector->priv); | |
| 182 | ||
| 183 | if (G_OBJECT_CLASS(parent_class)->finalize) | |
| 184 | G_OBJECT_CLASS(parent_class)->finalize(obj); | |
| 185 | } | |
| 186 | ||
| 187 | static void | |
| 188 | gaim_gtk_status_selector_destroy(GtkObject *obj) | |
| 189 | { | |
| 190 | GaimGtkStatusSelector *selector; | |
| 191 | ||
| 192 | g_return_if_fail(obj != NULL); | |
| 193 | g_return_if_fail(GAIM_GTK_IS_STATUS_SELECTOR(obj)); | |
| 194 | ||
| 195 | selector = GAIM_GTK_STATUS_SELECTOR(obj); | |
| 196 | ||
|
10187
fbb77006d747
[gaim-migrate @ 11302]
Mark Doliner <markdoliner@pidgin.im>
parents:
10183
diff
changeset
|
197 | gaim_signals_disconnect_by_handle(selector); |
|
fbb77006d747
[gaim-migrate @ 11302]
Mark Doliner <markdoliner@pidgin.im>
parents:
10183
diff
changeset
|
198 | |
| 10178 | 199 | if (GTK_OBJECT_CLASS(parent_class)->destroy) |
| 200 | GTK_OBJECT_CLASS(parent_class)->destroy(obj); | |
| 201 | } | |
| 202 | ||
| 203 | static void | |
| 204 | status_switched_cb(GtkWidget *combo, GaimGtkStatusSelector *selector) | |
| 205 | { | |
| 206 | GtkTreeIter iter; | |
|
10188
e900c432d1ce
[gaim-migrate @ 11303]
Mark Doliner <markdoliner@pidgin.im>
parents:
10187
diff
changeset
|
207 | const char *status_type_id; |
|
10191
d6fae5c19e96
[gaim-migrate @ 11306]
Mark Doliner <markdoliner@pidgin.im>
parents:
10188
diff
changeset
|
208 | const char *text; |
|
10188
e900c432d1ce
[gaim-migrate @ 11303]
Mark Doliner <markdoliner@pidgin.im>
parents:
10187
diff
changeset
|
209 | GList *l; |
| 10178 | 210 | |
|
10188
e900c432d1ce
[gaim-migrate @ 11303]
Mark Doliner <markdoliner@pidgin.im>
parents:
10187
diff
changeset
|
211 | if (!gtk_combo_box_get_active_iter(GTK_COMBO_BOX(selector->priv->combo), |
| 10178 | 212 | &iter)) |
| 213 | { | |
|
10188
e900c432d1ce
[gaim-migrate @ 11303]
Mark Doliner <markdoliner@pidgin.im>
parents:
10187
diff
changeset
|
214 | return; |
|
e900c432d1ce
[gaim-migrate @ 11303]
Mark Doliner <markdoliner@pidgin.im>
parents:
10187
diff
changeset
|
215 | } |
|
e900c432d1ce
[gaim-migrate @ 11303]
Mark Doliner <markdoliner@pidgin.im>
parents:
10187
diff
changeset
|
216 | |
|
e900c432d1ce
[gaim-migrate @ 11303]
Mark Doliner <markdoliner@pidgin.im>
parents:
10187
diff
changeset
|
217 | gtk_tree_model_get(GTK_TREE_MODEL(selector->priv->model), &iter, |
|
e900c432d1ce
[gaim-migrate @ 11303]
Mark Doliner <markdoliner@pidgin.im>
parents:
10187
diff
changeset
|
218 | COLUMN_NAME, &text, |
|
e900c432d1ce
[gaim-migrate @ 11303]
Mark Doliner <markdoliner@pidgin.im>
parents:
10187
diff
changeset
|
219 | COLUMN_STATUS_TYPE_ID, &status_type_id, |
|
e900c432d1ce
[gaim-migrate @ 11303]
Mark Doliner <markdoliner@pidgin.im>
parents:
10187
diff
changeset
|
220 | -1); |
| 10178 | 221 | |
|
10191
d6fae5c19e96
[gaim-migrate @ 11306]
Mark Doliner <markdoliner@pidgin.im>
parents:
10188
diff
changeset
|
222 | if (status_type_id == NULL) |
|
d6fae5c19e96
[gaim-migrate @ 11306]
Mark Doliner <markdoliner@pidgin.im>
parents:
10188
diff
changeset
|
223 | { |
|
d6fae5c19e96
[gaim-migrate @ 11306]
Mark Doliner <markdoliner@pidgin.im>
parents:
10188
diff
changeset
|
224 | if (!strcmp(text, _("New Status"))) |
|
d6fae5c19e96
[gaim-migrate @ 11306]
Mark Doliner <markdoliner@pidgin.im>
parents:
10188
diff
changeset
|
225 | { |
|
d6fae5c19e96
[gaim-migrate @ 11306]
Mark Doliner <markdoliner@pidgin.im>
parents:
10188
diff
changeset
|
226 | /* TODO */ |
|
d6fae5c19e96
[gaim-migrate @ 11306]
Mark Doliner <markdoliner@pidgin.im>
parents:
10188
diff
changeset
|
227 | } |
|
d6fae5c19e96
[gaim-migrate @ 11306]
Mark Doliner <markdoliner@pidgin.im>
parents:
10188
diff
changeset
|
228 | } |
|
d6fae5c19e96
[gaim-migrate @ 11306]
Mark Doliner <markdoliner@pidgin.im>
parents:
10188
diff
changeset
|
229 | else if (!strcmp(status_type_id, "available")) |
|
10188
e900c432d1ce
[gaim-migrate @ 11303]
Mark Doliner <markdoliner@pidgin.im>
parents:
10187
diff
changeset
|
230 | { |
|
e900c432d1ce
[gaim-migrate @ 11303]
Mark Doliner <markdoliner@pidgin.im>
parents:
10187
diff
changeset
|
231 | /* TODO */ |
|
e900c432d1ce
[gaim-migrate @ 11303]
Mark Doliner <markdoliner@pidgin.im>
parents:
10187
diff
changeset
|
232 | } |
|
10191
d6fae5c19e96
[gaim-migrate @ 11306]
Mark Doliner <markdoliner@pidgin.im>
parents:
10188
diff
changeset
|
233 | else if (!strcmp(status_type_id, "away")) |
|
10188
e900c432d1ce
[gaim-migrate @ 11303]
Mark Doliner <markdoliner@pidgin.im>
parents:
10187
diff
changeset
|
234 | { |
|
e900c432d1ce
[gaim-migrate @ 11303]
Mark Doliner <markdoliner@pidgin.im>
parents:
10187
diff
changeset
|
235 | const char *message = ""; |
|
e900c432d1ce
[gaim-migrate @ 11303]
Mark Doliner <markdoliner@pidgin.im>
parents:
10187
diff
changeset
|
236 | GtkTextBuffer *buffer; |
|
e900c432d1ce
[gaim-migrate @ 11303]
Mark Doliner <markdoliner@pidgin.im>
parents:
10187
diff
changeset
|
237 | gboolean allow_message = FALSE; |
| 10178 | 238 | |
|
10188
e900c432d1ce
[gaim-migrate @ 11303]
Mark Doliner <markdoliner@pidgin.im>
parents:
10187
diff
changeset
|
239 | buffer = |
|
e900c432d1ce
[gaim-migrate @ 11303]
Mark Doliner <markdoliner@pidgin.im>
parents:
10187
diff
changeset
|
240 | gtk_text_view_get_buffer(GTK_TEXT_VIEW(selector->priv->entry)); |
|
e900c432d1ce
[gaim-migrate @ 11303]
Mark Doliner <markdoliner@pidgin.im>
parents:
10187
diff
changeset
|
241 | |
|
e900c432d1ce
[gaim-migrate @ 11303]
Mark Doliner <markdoliner@pidgin.im>
parents:
10187
diff
changeset
|
242 | gtk_text_buffer_set_text(buffer, message, -1); |
|
e900c432d1ce
[gaim-migrate @ 11303]
Mark Doliner <markdoliner@pidgin.im>
parents:
10187
diff
changeset
|
243 | |
|
e900c432d1ce
[gaim-migrate @ 11303]
Mark Doliner <markdoliner@pidgin.im>
parents:
10187
diff
changeset
|
244 | for (l = gaim_connections_get_all(); l != NULL; l = l->next) |
| 10178 | 245 | { |
|
10188
e900c432d1ce
[gaim-migrate @ 11303]
Mark Doliner <markdoliner@pidgin.im>
parents:
10187
diff
changeset
|
246 | GaimConnection *gc = (GaimConnection *)l->data; |
|
e900c432d1ce
[gaim-migrate @ 11303]
Mark Doliner <markdoliner@pidgin.im>
parents:
10187
diff
changeset
|
247 | GaimAccount *account = gaim_connection_get_account(gc); |
|
e900c432d1ce
[gaim-migrate @ 11303]
Mark Doliner <markdoliner@pidgin.im>
parents:
10187
diff
changeset
|
248 | GaimStatusType *status_type; |
| 10178 | 249 | |
|
10188
e900c432d1ce
[gaim-migrate @ 11303]
Mark Doliner <markdoliner@pidgin.im>
parents:
10187
diff
changeset
|
250 | status_type = gaim_account_get_status_type(account, |
|
e900c432d1ce
[gaim-migrate @ 11303]
Mark Doliner <markdoliner@pidgin.im>
parents:
10187
diff
changeset
|
251 | status_type_id); |
| 10178 | 252 | |
|
10188
e900c432d1ce
[gaim-migrate @ 11303]
Mark Doliner <markdoliner@pidgin.im>
parents:
10187
diff
changeset
|
253 | if (status_type == NULL) |
|
e900c432d1ce
[gaim-migrate @ 11303]
Mark Doliner <markdoliner@pidgin.im>
parents:
10187
diff
changeset
|
254 | continue; |
| 10178 | 255 | |
|
10188
e900c432d1ce
[gaim-migrate @ 11303]
Mark Doliner <markdoliner@pidgin.im>
parents:
10187
diff
changeset
|
256 | if (gaim_status_type_get_attr(status_type, "message") != NULL) |
| 10178 | 257 | { |
|
10188
e900c432d1ce
[gaim-migrate @ 11303]
Mark Doliner <markdoliner@pidgin.im>
parents:
10187
diff
changeset
|
258 | gaim_account_set_status(account, |
|
e900c432d1ce
[gaim-migrate @ 11303]
Mark Doliner <markdoliner@pidgin.im>
parents:
10187
diff
changeset
|
259 | "away", TRUE, |
|
e900c432d1ce
[gaim-migrate @ 11303]
Mark Doliner <markdoliner@pidgin.im>
parents:
10187
diff
changeset
|
260 | "message", message, |
|
e900c432d1ce
[gaim-migrate @ 11303]
Mark Doliner <markdoliner@pidgin.im>
parents:
10187
diff
changeset
|
261 | NULL); |
| 10178 | 262 | |
|
10188
e900c432d1ce
[gaim-migrate @ 11303]
Mark Doliner <markdoliner@pidgin.im>
parents:
10187
diff
changeset
|
263 | allow_message = TRUE; |
|
e900c432d1ce
[gaim-migrate @ 11303]
Mark Doliner <markdoliner@pidgin.im>
parents:
10187
diff
changeset
|
264 | } |
|
e900c432d1ce
[gaim-migrate @ 11303]
Mark Doliner <markdoliner@pidgin.im>
parents:
10187
diff
changeset
|
265 | else |
|
e900c432d1ce
[gaim-migrate @ 11303]
Mark Doliner <markdoliner@pidgin.im>
parents:
10187
diff
changeset
|
266 | { |
|
e900c432d1ce
[gaim-migrate @ 11303]
Mark Doliner <markdoliner@pidgin.im>
parents:
10187
diff
changeset
|
267 | gaim_account_set_status(account, |
|
e900c432d1ce
[gaim-migrate @ 11303]
Mark Doliner <markdoliner@pidgin.im>
parents:
10187
diff
changeset
|
268 | "away", TRUE, |
|
e900c432d1ce
[gaim-migrate @ 11303]
Mark Doliner <markdoliner@pidgin.im>
parents:
10187
diff
changeset
|
269 | NULL); |
|
e900c432d1ce
[gaim-migrate @ 11303]
Mark Doliner <markdoliner@pidgin.im>
parents:
10187
diff
changeset
|
270 | } |
|
e900c432d1ce
[gaim-migrate @ 11303]
Mark Doliner <markdoliner@pidgin.im>
parents:
10187
diff
changeset
|
271 | } |
| 10178 | 272 | |
|
10188
e900c432d1ce
[gaim-migrate @ 11303]
Mark Doliner <markdoliner@pidgin.im>
parents:
10187
diff
changeset
|
273 | if (allow_message) |
|
10191
d6fae5c19e96
[gaim-migrate @ 11306]
Mark Doliner <markdoliner@pidgin.im>
parents:
10188
diff
changeset
|
274 | gtk_widget_show(selector->priv->frame); |
|
10188
e900c432d1ce
[gaim-migrate @ 11303]
Mark Doliner <markdoliner@pidgin.im>
parents:
10187
diff
changeset
|
275 | else |
|
10191
d6fae5c19e96
[gaim-migrate @ 11306]
Mark Doliner <markdoliner@pidgin.im>
parents:
10188
diff
changeset
|
276 | gtk_widget_hide(selector->priv->frame); |
| 10178 | 277 | } |
| 278 | } | |
| 279 | ||
| 280 | static void | |
| 281 | signed_on_off_cb(GaimConnection *gc, GaimGtkStatusSelector *selector) | |
| 282 | { | |
| 283 | rebuild_list(selector); | |
| 284 | } | |
| 285 | ||
| 286 | static GdkPixbuf * | |
| 287 | load_icon(const char *basename) | |
| 288 | { | |
| 289 | char *filename; | |
| 290 | GdkPixbuf *pixbuf, *scale = NULL; | |
| 291 | ||
| 292 | if (!strcmp(basename, "available.png")) | |
| 293 | basename = "online.png"; | |
| 294 | else if (!strcmp(basename, "hidden.png")) | |
| 295 | basename = "invisible.png"; | |
| 296 | ||
| 297 | filename = g_build_filename(DATADIR, "pixmaps", "gaim", "icons", | |
| 298 | basename, NULL); | |
| 299 | pixbuf = gdk_pixbuf_new_from_file(filename, NULL); | |
| 300 | g_free(filename); | |
| 301 | ||
| 302 | if (pixbuf != NULL) | |
| 303 | { | |
| 304 | scale = gdk_pixbuf_scale_simple(pixbuf, 16, 16, | |
| 305 | GDK_INTERP_BILINEAR); | |
| 306 | ||
| 307 | g_object_unref(G_OBJECT(pixbuf)); | |
| 308 | } | |
| 309 | else | |
| 310 | { | |
| 311 | filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", | |
| 312 | "default", basename, NULL); | |
| 313 | scale = gdk_pixbuf_new_from_file(filename, NULL); | |
| 314 | g_free(filename); | |
| 315 | } | |
| 316 | ||
| 317 | return scale; | |
| 318 | } | |
| 319 | ||
| 320 | static void | |
| 321 | add_item(GaimGtkStatusSelector *selector, const char *status_type_id, | |
| 322 | const char *text, GdkPixbuf *pixbuf) | |
| 323 | { | |
| 324 | GtkTreeIter iter; | |
| 325 | ||
| 326 | gtk_list_store_append(selector->priv->model, &iter); | |
| 327 | gtk_list_store_set(selector->priv->model, &iter, | |
| 328 | COLUMN_STATUS_TYPE_ID, status_type_id, | |
| 329 | COLUMN_ICON, pixbuf, | |
| 330 | COLUMN_NAME, text, | |
| 331 | -1); | |
| 332 | ||
| 333 | if (pixbuf != NULL) | |
| 334 | g_object_unref(G_OBJECT(pixbuf)); | |
| 335 | } | |
| 336 | ||
| 337 | static void | |
| 338 | rebuild_list(GaimGtkStatusSelector *selector) | |
| 339 | { | |
| 340 | gboolean single_prpl = TRUE; | |
| 341 | GaimAccount *first_account = NULL; | |
| 342 | const char *first_prpl_type = NULL; | |
| 343 | GList *l; | |
| 344 | ||
| 345 | g_return_if_fail(selector != NULL); | |
| 346 | g_return_if_fail(GAIM_GTK_IS_STATUS_SELECTOR(selector)); | |
| 347 | ||
| 348 | gtk_list_store_clear(selector->priv->model); | |
| 349 | ||
| 350 | /* | |
| 351 | * If the user only has one IM account or one type of IM account | |
| 352 | * connected, they'll see all their statuses. This is ideal for those | |
| 353 | * who use only one account, or one single protocol. Everyone else | |
| 354 | * gets Available and Away and a list of saved statuses. | |
| 355 | */ | |
| 356 | for (l = gaim_connections_get_all(); l != NULL && single_prpl; l = l->next) | |
| 357 | { | |
| 358 | GaimConnection *gc = (GaimConnection *)l->data; | |
| 359 | GaimAccount *account = gaim_connection_get_account(gc); | |
| 360 | GaimPluginProtocolInfo *prpl_info; | |
| 361 | const char *basename; | |
| 362 | ||
| 363 | prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl); | |
| 364 | basename = prpl_info->list_icon(account, NULL); | |
| 365 | ||
| 366 | if (first_prpl_type == NULL) | |
| 367 | { | |
| 368 | first_prpl_type = basename; | |
| 369 | first_account = account; | |
| 370 | } | |
|
10179
1709e59b2f2c
[gaim-migrate @ 11294]
Christian Hammond <chipx86@chipx86.com>
parents:
10178
diff
changeset
|
371 | else if (strcmp(first_prpl_type, basename)) |
| 10178 | 372 | single_prpl = FALSE; |
| 373 | } | |
| 374 | ||
| 375 | if (single_prpl) | |
| 376 | { | |
| 377 | const GList *l; | |
| 378 | ||
| 379 | for (l = gaim_account_get_status_types(first_account); | |
| 380 | l != NULL; | |
| 381 | l = l->next) | |
| 382 | { | |
| 383 | GaimStatusType *status_type = (GaimStatusType *)l->data; | |
| 384 | char filename[BUFSIZ]; | |
| 385 | ||
| 386 | if (!gaim_status_type_is_user_settable(status_type)) | |
| 387 | continue; | |
| 388 | ||
| 389 | g_snprintf(filename, sizeof(filename), "%s.png", | |
| 390 | gaim_status_type_get_id(status_type)); | |
| 391 | ||
| 392 | add_item(selector, | |
| 393 | gaim_status_type_get_id(status_type), | |
| 394 | gaim_status_type_get_name(status_type), | |
| 395 | load_icon(filename)); | |
| 396 | } | |
| 397 | } | |
| 398 | else | |
| 399 | { | |
| 400 | add_item(selector, "available", _("Available"), | |
| 401 | load_icon("online.png")); | |
| 402 | add_item(selector, "away", _("Away"), load_icon("away.png")); | |
| 403 | } | |
| 404 | ||
|
10191
d6fae5c19e96
[gaim-migrate @ 11306]
Mark Doliner <markdoliner@pidgin.im>
parents:
10188
diff
changeset
|
405 | /* TODO: Add saved statuses here? */ |
|
d6fae5c19e96
[gaim-migrate @ 11306]
Mark Doliner <markdoliner@pidgin.im>
parents:
10188
diff
changeset
|
406 | |
| 10178 | 407 | add_item(selector, NULL, _("New Status"), |
| 408 | gtk_widget_render_icon(GTK_WIDGET(selector), GTK_STOCK_NEW, | |
| 409 | GTK_ICON_SIZE_MENU, NULL)); | |
| 410 | } | |
| 411 | ||
| 412 | GtkWidget * | |
| 413 | gaim_gtk_status_selector_new(void) | |
| 414 | { | |
| 415 | GaimGtkStatusSelector *selector; | |
| 416 | ||
| 417 | selector = g_object_new(GAIM_GTK_TYPE_STATUS_SELECTOR, NULL); | |
| 418 | ||
| 419 | return GTK_WIDGET(selector); | |
| 420 | } |