comparison pidgin/gtknotify.c @ 27338:c245c583a1a6

Remove a few layers of evil abstraction.
author Paul Aurich <paul@darkrain42.org>
date Fri, 03 Jul 2009 02:33:30 +0000
parents 357405dc8b2c
children c7768f23f519
comparison
equal deleted inserted replaced
27337:357405dc8b2c 27338:c245c583a1a6
103 typedef struct _PidginNotifyDialog PidginNotifyDialog; 103 typedef struct _PidginNotifyDialog PidginNotifyDialog;
104 typedef PidginNotifyDialog PidginMailDialog; 104 typedef PidginNotifyDialog PidginMailDialog;
105 105
106 struct _PidginNotifyDialog 106 struct _PidginNotifyDialog
107 { 107 {
108 /*
109 * This must be first so PidginNotifyDialog can masquerade as the
110 * dialog widget.
111 */
108 GtkWidget *dialog; 112 GtkWidget *dialog;
109 GtkWidget *treeview; 113 GtkWidget *treeview;
110 GtkTreeStore *treemodel; 114 GtkTreeStore *treemodel;
111 GtkLabel *label; 115 GtkLabel *label;
112 GtkWidget *open_button; 116 GtkWidget *open_button;
124 } PidginNotifyType; 128 } PidginNotifyType;
125 129
126 static PidginNotifyDialog *mail_dialog = NULL; 130 static PidginNotifyDialog *mail_dialog = NULL;
127 static PidginNotifyDialog *pounce_dialog = NULL; 131 static PidginNotifyDialog *pounce_dialog = NULL;
128 132
129 static GtkWidget *pidgin_get_notification_dialog(PidginNotifyType type); 133 static PidginNotifyDialog *pidgin_get_notification_dialog(PidginNotifyType type);
130 static void *pidgin_notify_emails(PurpleConnection *gc, size_t count, gboolean detailed, 134 static void *pidgin_notify_emails(PurpleConnection *gc, size_t count, gboolean detailed,
131 const char **subjects, 135 const char **subjects,
132 const char **froms, const char **tos, 136 const char **froms, const char **tos,
133 const char **urls); 137 const char **urls);
134 138
292 296
293 297
294 } 298 }
295 299
296 static void 300 static void
301 reset_mail_dialog(GtkDialog *unused)
302 {
303 if (mail_dialog->in_use)
304 return;
305 gtk_widget_destroy(mail_dialog->dialog);
306 g_free(mail_dialog);
307 mail_dialog = NULL;
308 }
309
310 static void
297 email_response_cb(GtkDialog *dlg, gint id, PidginMailDialog *dialog) 311 email_response_cb(GtkDialog *dlg, gint id, PidginMailDialog *dialog)
298 { 312 {
299 PidginNotifyMailData *data = NULL; 313 PidginNotifyMailData *data = NULL;
300 GtkTreeIter iter; 314 GtkTreeIter iter;
301 315
340 purple_notify_close(PURPLE_NOTIFY_EMAILS, data); 354 purple_notify_close(PURPLE_NOTIFY_EMAILS, data);
341 else 355 else
342 pidgin_close_notify(PURPLE_NOTIFY_EMAILS, data); 356 pidgin_close_notify(PURPLE_NOTIFY_EMAILS, data);
343 } 357 }
344 } 358 }
345 gtk_widget_destroy(dialog->dialog); 359
346 g_free(dialog); 360 reset_mail_dialog(NULL);
347 mail_dialog = NULL;
348 } 361 }
349 362
350 static void email_row_activated_cb(GtkTreeView *tv, GtkTreePath *path, GtkTreeViewColumn *col, gpointer data) { 363 static void email_row_activated_cb(GtkTreeView *tv, GtkTreePath *path, GtkTreeViewColumn *col, gpointer data) {
351 email_response_cb(GTK_DIALOG(mail_dialog->dialog), GTK_RESPONSE_YES, mail_dialog); 364 email_response_cb(GTK_DIALOG(mail_dialog->dialog), GTK_RESPONSE_YES, mail_dialog);
352 }
353
354 static void
355 reset_mail_dialog(GtkDialog *dialog)
356 {
357 if (mail_dialog->in_use)
358 return;
359 gtk_widget_destroy(mail_dialog->dialog);
360 g_free(mail_dialog);
361 mail_dialog = NULL;
362 } 365 }
363 366
364 static gboolean 367 static gboolean
365 formatted_close_cb(GtkWidget *win, GdkEvent *event, void *user_data) 368 formatted_close_cb(GtkWidget *win, GdkEvent *event, void *user_data)
366 { 369 {
522 static int 525 static int
523 mail_window_focus_cb(GtkWidget *widget, GdkEventFocus *focus, gpointer null) 526 mail_window_focus_cb(GtkWidget *widget, GdkEventFocus *focus, gpointer null)
524 { 527 {
525 pidgin_set_urgent(GTK_WINDOW(widget), FALSE); 528 pidgin_set_urgent(GTK_WINDOW(widget), FALSE);
526 return 0; 529 return 0;
527 }
528
529 static GtkWidget *
530 pidgin_get_mail_dialog(void)
531 {
532 return pidgin_get_notification_dialog(PIDGIN_NOTIFY_MAIL);
533 } 530 }
534 531
535 /* count == 0 means this is a detailed mail notification. 532 /* count == 0 means this is a detailed mail notification.
536 * count > 0 mean non-detailed. 533 * count > 0 mean non-detailed.
537 */ 534 */
611 static void * 608 static void *
612 pidgin_notify_emails(PurpleConnection *gc, size_t count, gboolean detailed, 609 pidgin_notify_emails(PurpleConnection *gc, size_t count, gboolean detailed,
613 const char **subjects, const char **froms, 610 const char **subjects, const char **froms,
614 const char **tos, const char **urls) 611 const char **tos, const char **urls)
615 { 612 {
616 GtkWidget *dialog = NULL; 613 PidginNotifyDialog *notification_dialog;
614 GtkWidget *dialog;
617 char *notification; 615 char *notification;
618 PurpleAccount *account; 616 PurpleAccount *account;
619 PidginNotifyMailData *data = NULL, *data2; 617 PidginNotifyMailData *data = NULL, *data2;
620 gboolean new_data = FALSE; 618 gboolean new_data = FALSE;
621 619
622 /* Don't bother updating if there aren't new emails and we don't have any displayed currently */ 620 /* Don't bother updating if there aren't new emails and we don't have any displayed currently */
623 if (count == 0 && mail_dialog == NULL) 621 if (count == 0 && mail_dialog == NULL)
624 return NULL; 622 return NULL;
625 623
626 account = purple_connection_get_account(gc); 624 account = purple_connection_get_account(gc);
627 dialog = pidgin_get_mail_dialog(); /* This creates mail_dialog if necessary */ 625 /* This creates the mail dialog (mail_dialog) if necessary */
626 notification_dialog = pidgin_get_notification_dialog(PIDGIN_NOTIFY_MAIL);
627 dialog = notification_dialog->dialog;
628 628
629 mail_dialog->total_count += count; 629 mail_dialog->total_count += count;
630 if (detailed) { 630 if (detailed) {
631 while (count--) { 631 while (count--) {
632 char *to_text = NULL; 632 char *to_text = NULL;
1342 #endif /* !_WIN32 */ 1342 #endif /* !_WIN32 */
1343 1343
1344 return NULL; 1344 return NULL;
1345 } 1345 }
1346 1346
1347 static GtkWidget * 1347 void
1348 pidgin_get_dialog(PidginNotifyType type, GtkTreeStore *treemodel) 1348 pidgin_notify_pounce_add(PurpleAccount *account, PurplePounce *pounce,
1349 { 1349 const char *alias, const char *event, const char *message, const char *date)
1350 {
1351 PidginNotifyDialog *notification_dialog;
1352 GtkWidget *dialog;
1353 GdkPixbuf *icon;
1354 GtkTreeIter iter;
1355 PidginNotifyPounceData *pounce_data;
1356
1357 notification_dialog = pidgin_get_notification_dialog(PIDGIN_NOTIFY_POUNCE);
1358 dialog = notification_dialog->dialog;
1359
1360 icon = pidgin_create_prpl_icon(account, PIDGIN_PRPL_ICON_SMALL);
1361
1362 pounce_data = g_new(PidginNotifyPounceData, 1);
1363
1364 pounce_data->account = account;
1365 pounce_data->pounce = pounce;
1366
1367 gtk_tree_store_append(pounce_dialog->treemodel, &iter, NULL);
1368
1369 gtk_tree_store_set(pounce_dialog->treemodel, &iter,
1370 PIDGIN_POUNCE_ICON, icon,
1371 PIDGIN_POUNCE_ALIAS, alias,
1372 PIDGIN_POUNCE_EVENT, event,
1373 PIDGIN_POUNCE_TEXT, (message != NULL)? message : _("No message"),
1374 PIDGIN_POUNCE_DATE, date,
1375 PIDGIN_POUNCE_DATA, pounce_data,
1376 -1);
1377
1378 if (icon)
1379 g_object_unref(icon);
1380
1381 gtk_widget_show_all(dialog);
1382
1383 return;
1384 }
1385
1386 static PidginNotifyDialog *
1387 pidgin_get_notification_dialog(PidginNotifyType type)
1388 {
1389 GtkTreeStore *model = NULL;
1350 GtkWidget *dialog = NULL; 1390 GtkWidget *dialog = NULL;
1351 GtkWidget *label = NULL; 1391 GtkWidget *label = NULL;
1352 GtkWidget *sw; 1392 GtkWidget *sw;
1353 GtkCellRenderer *rend; 1393 GtkCellRenderer *rend;
1354 GtkTreeViewColumn *column; 1394 GtkTreeViewColumn *column;
1357 GtkTreeSelection *sel; 1397 GtkTreeSelection *sel;
1358 PidginNotifyDialog *spec_dialog = NULL; 1398 PidginNotifyDialog *spec_dialog = NULL;
1359 1399
1360 g_return_val_if_fail(type < PIDGIN_NOTIFY_TYPES, NULL); 1400 g_return_val_if_fail(type < PIDGIN_NOTIFY_TYPES, NULL);
1361 1401
1402 if (type == PIDGIN_NOTIFY_MAIL) {
1403 if (mail_dialog != NULL)
1404 return mail_dialog;
1405
1406 model = gtk_tree_store_new(COLUMNS_PIDGIN_MAIL,
1407 GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_POINTER);
1408
1409 } else if (type == PIDGIN_NOTIFY_POUNCE) {
1410
1411 if (pounce_dialog != NULL)
1412 return pounce_dialog;
1413
1414 model = gtk_tree_store_new(PIDGIN_POUNCE_COLUMNS,
1415 GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING,
1416 G_TYPE_STRING, G_TYPE_POINTER);
1417 }
1418
1362 dialog = gtk_dialog_new_with_buttons(NULL, NULL, 0, 1419 dialog = gtk_dialog_new_with_buttons(NULL, NULL, 0,
1363 GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE, 1420 GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
1364 NULL); 1421 NULL);
1365 1422
1366 /* Setup the dialog */ 1423 /* Setup the dialog */
1380 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw), GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS); 1437 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw), GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS);
1381 1438
1382 spec_dialog = g_new0(PidginNotifyDialog, 1); 1439 spec_dialog = g_new0(PidginNotifyDialog, 1);
1383 spec_dialog->dialog = dialog; 1440 spec_dialog->dialog = dialog;
1384 1441
1385 spec_dialog->treemodel = treemodel; 1442 spec_dialog->treemodel = model;
1386 spec_dialog->treeview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(spec_dialog->treemodel)); 1443 spec_dialog->treeview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(model));
1387 g_object_unref(G_OBJECT(spec_dialog->treemodel)); 1444 g_object_unref(G_OBJECT(model));
1388 1445
1389 gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(spec_dialog->treeview), TRUE); 1446 gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(spec_dialog->treeview), TRUE);
1390 gtk_container_add(GTK_CONTAINER(sw), spec_dialog->treeview); 1447 gtk_container_add(GTK_CONTAINER(sw), spec_dialog->treeview);
1391 1448
1392 if (type == PIDGIN_NOTIFY_MAIL) { 1449 if (type == PIDGIN_NOTIFY_MAIL) {
1498 mail_dialog = spec_dialog; 1555 mail_dialog = spec_dialog;
1499 else if (type == PIDGIN_NOTIFY_POUNCE) { 1556 else if (type == PIDGIN_NOTIFY_POUNCE) {
1500 pounce_dialog = spec_dialog; 1557 pounce_dialog = spec_dialog;
1501 } 1558 }
1502 1559
1503 return spec_dialog->dialog; 1560 return spec_dialog;
1504
1505 }
1506
1507 void
1508 pidgin_notify_pounce_add(PurpleAccount *account, PurplePounce *pounce,
1509 const char *alias, const char *event, const char *message, const char *date)
1510 {
1511 GtkWidget *dialog;
1512 GdkPixbuf *icon;
1513 GtkTreeIter iter;
1514 PidginNotifyPounceData *pounce_data;
1515
1516 dialog = pidgin_get_notification_dialog(PIDGIN_NOTIFY_POUNCE);
1517
1518 icon = pidgin_create_prpl_icon(account, PIDGIN_PRPL_ICON_SMALL);
1519
1520 pounce_data = g_new(PidginNotifyPounceData, 1);
1521
1522 pounce_data->account = account;
1523 pounce_data->pounce = pounce;
1524
1525 gtk_tree_store_append(pounce_dialog->treemodel, &iter, NULL);
1526
1527 gtk_tree_store_set(pounce_dialog->treemodel, &iter,
1528 PIDGIN_POUNCE_ICON, icon,
1529 PIDGIN_POUNCE_ALIAS, alias,
1530 PIDGIN_POUNCE_EVENT, event,
1531 PIDGIN_POUNCE_TEXT, (message != NULL)? message : _("No message"),
1532 PIDGIN_POUNCE_DATE, date,
1533 PIDGIN_POUNCE_DATA, pounce_data,
1534 -1);
1535
1536 if (icon)
1537 g_object_unref(icon);
1538
1539 gtk_widget_show_all(dialog);
1540
1541 return;
1542 }
1543
1544 static GtkWidget *
1545 pidgin_get_notification_dialog(PidginNotifyType type)
1546 {
1547 GtkTreeStore *model = NULL;
1548
1549 if (type == PIDGIN_NOTIFY_MAIL) {
1550 if (mail_dialog != NULL)
1551 return mail_dialog->dialog;
1552
1553 model = gtk_tree_store_new(COLUMNS_PIDGIN_MAIL,
1554 GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_POINTER);
1555
1556 } else if (type == PIDGIN_NOTIFY_POUNCE) {
1557
1558 if (pounce_dialog != NULL)
1559 return pounce_dialog->dialog;
1560
1561 model = gtk_tree_store_new(PIDGIN_POUNCE_COLUMNS,
1562 GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING,
1563 G_TYPE_STRING, G_TYPE_POINTER);
1564 }
1565
1566 return pidgin_get_dialog(type, model);
1567 } 1561 }
1568 1562
1569 static void 1563 static void
1570 signed_off_cb(PurpleConnection *gc, gpointer unused) 1564 signed_off_cb(PurpleConnection *gc, gpointer unused)
1571 { 1565 {