Mercurial > pidgin
comparison src/gtkstatusselector.c @ 10199:76e296e16def
[gaim-migrate @ 11316]
This lets you set your away message or available message or whatever by
typing into the box and then waiting for the timeout to kick in.
committer: Tailor Script <tailor@pidgin.im>
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Wed, 17 Nov 2004 05:41:10 +0000 |
parents | 7369bf2bf593 |
children | 9d03dd6ccc9a |
comparison
equal
deleted
inserted
replaced
10198:137a880153ba | 10199:76e296e16def |
---|---|
39 GtkWidget *frame; | 39 GtkWidget *frame; |
40 | 40 |
41 #if GTK_CHECK_VERSION(2,4,0) | 41 #if GTK_CHECK_VERSION(2,4,0) |
42 GtkListStore *model; | 42 GtkListStore *model; |
43 #endif | 43 #endif |
44 | |
45 guint entry_timer; | |
44 }; | 46 }; |
45 | 47 |
46 #if GTK_CHECK_VERSION(2,4,0) | 48 #if GTK_CHECK_VERSION(2,4,0) |
47 enum | 49 enum |
48 { | 50 { |
56 static void gaim_gtk_status_selector_class_init(GaimGtkStatusSelectorClass *klass); | 58 static void gaim_gtk_status_selector_class_init(GaimGtkStatusSelectorClass *klass); |
57 static void gaim_gtk_status_selector_init(GaimGtkStatusSelector *selector); | 59 static void gaim_gtk_status_selector_init(GaimGtkStatusSelector *selector); |
58 static void gaim_gtk_status_selector_finalize(GObject *obj); | 60 static void gaim_gtk_status_selector_finalize(GObject *obj); |
59 static void gaim_gtk_status_selector_destroy(GtkObject *obj); | 61 static void gaim_gtk_status_selector_destroy(GtkObject *obj); |
60 static void status_switched_cb(GtkWidget *combo, GaimGtkStatusSelector *selector); | 62 static void status_switched_cb(GtkWidget *combo, GaimGtkStatusSelector *selector); |
63 static gboolean key_press_cb(GtkWidget *entry, GdkEventKey *event, gpointer user_data); | |
61 static void signed_on_off_cb(GaimConnection *gc, GaimGtkStatusSelector *selector); | 64 static void signed_on_off_cb(GaimConnection *gc, GaimGtkStatusSelector *selector); |
62 static void rebuild_list(GaimGtkStatusSelector *selector); | 65 static void rebuild_list(GaimGtkStatusSelector *selector); |
63 | 66 |
64 static GtkVBox *parent_class = NULL; | 67 static GtkVBox *parent_class = NULL; |
65 | 68 |
156 selector->priv->frame = frame; | 159 selector->priv->frame = frame; |
157 gtk_widget_set_name(entry, "gaim_gtkstatusselector_imhtml"); | 160 gtk_widget_set_name(entry, "gaim_gtkstatusselector_imhtml"); |
158 gtk_box_pack_start(GTK_BOX(selector), frame, TRUE, TRUE, 0); | 161 gtk_box_pack_start(GTK_BOX(selector), frame, TRUE, TRUE, 0); |
159 gtk_widget_hide(toolbar); | 162 gtk_widget_hide(toolbar); |
160 | 163 |
164 g_signal_connect(G_OBJECT(entry), "key_press_event", | |
165 G_CALLBACK(key_press_cb), selector); | |
166 | |
161 gaim_signal_connect(gaim_connections_get_handle(), "signed-on", | 167 gaim_signal_connect(gaim_connections_get_handle(), "signed-on", |
162 selector, GAIM_CALLBACK(signed_on_off_cb), | 168 selector, GAIM_CALLBACK(signed_on_off_cb), |
163 selector); | 169 selector); |
164 gaim_signal_connect(gaim_connections_get_handle(), "signed-off", | 170 gaim_signal_connect(gaim_connections_get_handle(), "signed-off", |
165 selector, GAIM_CALLBACK(signed_on_off_cb), | 171 selector, GAIM_CALLBACK(signed_on_off_cb), |
204 status_switched_cb(GtkWidget *combo, GaimGtkStatusSelector *selector) | 210 status_switched_cb(GtkWidget *combo, GaimGtkStatusSelector *selector) |
205 { | 211 { |
206 GtkTreeIter iter; | 212 GtkTreeIter iter; |
207 const char *status_type_id; | 213 const char *status_type_id; |
208 const char *text; | 214 const char *text; |
209 GList *l; | |
210 | 215 |
211 if (!gtk_combo_box_get_active_iter(GTK_COMBO_BOX(selector->priv->combo), | 216 if (!gtk_combo_box_get_active_iter(GTK_COMBO_BOX(selector->priv->combo), |
212 &iter)) | 217 &iter)) |
213 { | 218 { |
214 return; | 219 return; |
226 /* TODO */ | 231 /* TODO */ |
227 } | 232 } |
228 } | 233 } |
229 else | 234 else |
230 { | 235 { |
231 const char *message = text; | 236 /* |
237 * If the chosen status does not require a message, then set the | |
238 * status immediately. Otherwise just register a timeout and the | |
239 * status will be set whenever the user stops typing the message. | |
240 */ | |
241 GList *l; | |
232 GtkTextBuffer *buffer; | 242 GtkTextBuffer *buffer; |
233 gboolean allow_message = FALSE; | 243 gboolean allow_message = FALSE; |
234 | 244 |
235 buffer = | 245 buffer = |
236 gtk_text_view_get_buffer(GTK_TEXT_VIEW(selector->priv->entry)); | 246 gtk_text_view_get_buffer(GTK_TEXT_VIEW(selector->priv->entry)); |
237 | 247 |
238 gtk_text_buffer_set_text(buffer, message, -1); | 248 gtk_text_buffer_set_text(buffer, text, -1); |
239 | 249 |
240 for (l = gaim_connections_get_all(); l != NULL; l = l->next) | 250 for (l = gaim_connections_get_all(); l != NULL; l = l->next) |
241 { | 251 { |
242 GaimConnection *gc = (GaimConnection *)l->data; | 252 GaimConnection *gc = (GaimConnection *)l->data; |
243 GaimAccount *account = gaim_connection_get_account(gc); | 253 GaimAccount *account = gaim_connection_get_account(gc); |
249 if (status_type == NULL) | 259 if (status_type == NULL) |
250 continue; | 260 continue; |
251 | 261 |
252 if (gaim_status_type_get_attr(status_type, "message") != NULL) | 262 if (gaim_status_type_get_attr(status_type, "message") != NULL) |
253 { | 263 { |
254 gaim_account_set_status(account, | |
255 status_type_id, TRUE, | |
256 "message", message, | |
257 NULL); | |
258 | |
259 allow_message = TRUE; | 264 allow_message = TRUE; |
260 } | 265 } |
261 else | 266 else |
262 { | 267 { |
263 gaim_account_set_status(account, | 268 gaim_account_set_status(account, |
265 NULL); | 270 NULL); |
266 } | 271 } |
267 } | 272 } |
268 | 273 |
269 if (allow_message) | 274 if (allow_message) |
275 { | |
270 gtk_widget_show(selector->priv->frame); | 276 gtk_widget_show(selector->priv->frame); |
277 key_press_cb(NULL, NULL, selector); | |
278 } | |
271 else | 279 else |
272 gtk_widget_hide(selector->priv->frame); | 280 gtk_widget_hide(selector->priv->frame); |
273 } | 281 } |
282 } | |
283 | |
284 static gboolean | |
285 insert_text_timeout_cb(gpointer data) | |
286 { | |
287 GaimGtkStatusSelector *selector = (GaimGtkStatusSelector *)data; | |
288 GtkTreeIter iter; | |
289 const char *status_type_id; | |
290 const char *text; | |
291 | |
292 if (!gtk_combo_box_get_active_iter(GTK_COMBO_BOX(selector->priv->combo), | |
293 &iter)) | |
294 { | |
295 return FALSE; | |
296 } | |
297 | |
298 gtk_tree_model_get(GTK_TREE_MODEL(selector->priv->model), &iter, | |
299 COLUMN_NAME, &text, | |
300 COLUMN_STATUS_TYPE_ID, &status_type_id, | |
301 -1); | |
302 | |
303 if (status_type_id == NULL) | |
304 { | |
305 if (!strcmp(text, _("New Status"))) | |
306 { | |
307 /* TODO */ | |
308 } | |
309 } | |
310 else | |
311 { | |
312 gchar *message; | |
313 GList *l; | |
314 | |
315 message = gtk_imhtml_get_markup(GTK_IMHTML(selector->priv->entry)); | |
316 | |
317 for (l = gaim_connections_get_all(); l != NULL; l = l->next) | |
318 { | |
319 GaimConnection *gc = (GaimConnection *)l->data; | |
320 GaimAccount *account = gaim_connection_get_account(gc); | |
321 GaimStatusType *status_type; | |
322 | |
323 status_type = gaim_account_get_status_type(account, | |
324 status_type_id); | |
325 | |
326 if (status_type == NULL) | |
327 continue; | |
328 | |
329 if (gaim_status_type_get_attr(status_type, "message") != NULL) | |
330 { | |
331 gaim_account_set_status(account, | |
332 status_type_id, TRUE, | |
333 "message", message, | |
334 NULL); | |
335 } | |
336 } | |
337 } | |
338 | |
339 return FALSE; | |
340 } | |
341 | |
342 /** | |
343 * The user typed in the IMHTML entry widget. If the user is finished | |
344 * typing then we want to set the appropriate status message. So let's | |
345 * wait 3 seconds, and if they haven't typed anything else then set the | |
346 * status message. | |
347 */ | |
348 static gboolean | |
349 key_press_cb(GtkWidget *entry, GdkEventKey *event, gpointer user_data) | |
350 { | |
351 GaimGtkStatusSelector *selector = (GaimGtkStatusSelector *)user_data; | |
352 | |
353 if (selector->priv->entry_timer != 0) { | |
354 gaim_timeout_remove(selector->priv->entry_timer); | |
355 } | |
356 | |
357 selector->priv->entry_timer = gaim_timeout_add(3000, insert_text_timeout_cb, | |
358 selector); | |
359 | |
360 return FALSE; | |
274 } | 361 } |
275 | 362 |
276 static void | 363 static void |
277 signed_on_off_cb(GaimConnection *gc, GaimGtkStatusSelector *selector) | 364 signed_on_off_cb(GaimConnection *gc, GaimGtkStatusSelector *selector) |
278 { | 365 { |