Mercurial > pidgin.yaz
comparison console/gntnotify.c @ 13952:841a5ffbfee4
[gaim-migrate @ 16500]
uiops for GaimConnections. This only shows an error message for a disconnect.
uiops for GaimNotify. I have not done the notifications for searchresults
yet. That will require multi-column GntTree's, which will also allow for
improved email-notifications. I hope to complete it by next week.
committer: Tailor Script <tailor@pidgin.im>
author | Sadrul Habib Chowdhury <imadil@gmail.com> |
---|---|
date | Mon, 17 Jul 2006 03:45:24 +0000 |
parents | |
children | 8b2306c64efa |
comparison
equal
deleted
inserted
replaced
13951:614c56622453 | 13952:841a5ffbfee4 |
---|---|
1 #include <gnt.h> | |
2 #include <gntbox.h> | |
3 #include <gntbutton.h> | |
4 #include <gntlabel.h> | |
5 | |
6 #include <util.h> | |
7 | |
8 #include "gntnotify.h" | |
9 #include "gntgaim.h" | |
10 | |
11 static void * | |
12 gg_notify_message(GaimNotifyMsgType type, const char *title, | |
13 const char *primary, const char *secondary) | |
14 { | |
15 GntWidget *window, *button; | |
16 GntTextFormatFlags pf = 0, sf = 0; | |
17 | |
18 switch (type) | |
19 { | |
20 case GAIM_NOTIFY_MSG_ERROR: | |
21 sf |= GNT_TEXT_FLAG_BOLD; | |
22 case GAIM_NOTIFY_MSG_WARNING: | |
23 pf |= GNT_TEXT_FLAG_UNDERLINE; | |
24 case GAIM_NOTIFY_MSG_INFO: | |
25 pf |= GNT_TEXT_FLAG_BOLD; | |
26 break; | |
27 } | |
28 | |
29 window = gnt_box_new(FALSE, TRUE); | |
30 gnt_box_set_toplevel(GNT_BOX(window), TRUE); | |
31 gnt_box_set_title(GNT_BOX(window), title); | |
32 | |
33 if (primary) | |
34 gnt_box_add_widget(GNT_BOX(window), | |
35 gnt_label_new_with_format(primary, pf)); | |
36 if (secondary) | |
37 gnt_box_add_widget(GNT_BOX(window), | |
38 gnt_label_new_with_format(secondary, sf)); | |
39 | |
40 button = gnt_button_new(_("OK")); | |
41 gnt_box_add_widget(GNT_BOX(window), button); | |
42 g_signal_connect_swapped(G_OBJECT(button), "activate", G_CALLBACK(gnt_widget_destroy), window); | |
43 | |
44 gnt_widget_show(window); | |
45 return window; | |
46 } | |
47 | |
48 /* handle is, in all/most occasions, a GntWidget * */ | |
49 static void gg_close_notify(GaimNotifyType type, void *handle) | |
50 { | |
51 gnt_widget_destroy(GNT_WIDGET(handle)); | |
52 } | |
53 | |
54 static void *gg_notify_formatted(const char *title, const char *primary, | |
55 const char *secondary, const char *text) | |
56 { | |
57 /* XXX: For now, simply strip the html and use _notify_message. For future use, | |
58 * there should be some way of parsing the makrups from GntTextView */ | |
59 char *unformat = gaim_markup_strip_html(text); | |
60 char *t = g_strdup_printf("%s%s%s", | |
61 secondary ? secondary : "", | |
62 secondary ? "\n" : "", | |
63 unformat ? unformat : ""); | |
64 | |
65 void *ret = gg_notify_message(GAIM_NOTIFY_MSG_INFO, title, primary, t); | |
66 | |
67 g_free(t); | |
68 g_free(unformat); | |
69 | |
70 return ret; | |
71 } | |
72 | |
73 static void * | |
74 gg_notify_emails(GaimConnection *gc, size_t count, gboolean detailed, | |
75 const char **subjects, const char **froms, const char **tos, | |
76 const char **urls) | |
77 { | |
78 GaimAccount *account = gaim_connection_get_account(gc); | |
79 GString *message = g_string_new(NULL); | |
80 void *ret; | |
81 | |
82 if (!detailed) | |
83 { | |
84 g_string_append_printf(message, | |
85 ngettext("%s (%s) has %d new message.", | |
86 "%s (%s) has %d new messages.", | |
87 (int)count), | |
88 tos ? *tos : gaim_account_get_username(account), | |
89 gaim_account_get_protocol_name(account), (int)count); | |
90 } | |
91 else | |
92 { | |
93 /* XXX: Yes, yes. I know, the combined dialog thing. Maybe later. */ | |
94 g_string_append_printf(message, | |
95 _("You have received a mail \"%s\""), *subjects); | |
96 if (froms && *froms && **froms) | |
97 g_string_append_printf(message, _("\nfrom %s"), *froms); | |
98 g_string_append_printf(message, _(" to %s (%s)"), | |
99 tos ? *tos : gaim_account_get_username(account), | |
100 gaim_account_get_protocol_name(account)); | |
101 } | |
102 | |
103 ret = gg_notify_message(GAIM_NOTIFY_MSG_INFO, _("New Mail"), _("You have mail!"), message->str); | |
104 g_string_free(message, TRUE); | |
105 return ret; | |
106 } | |
107 | |
108 static void * | |
109 gg_notify_email(GaimConnection *gc, const char *subject, const char *from, | |
110 const char *to, const char *url) | |
111 { | |
112 return gg_notify_emails(gc, 1, subject != NULL, | |
113 subject ? &subject : NULL, | |
114 from ? &from : NULL, | |
115 to ? &to : NULL, | |
116 url ? &url : NULL); | |
117 } | |
118 | |
119 static void * | |
120 gg_notify_userinfo(GaimConnection *gc, const char *who, const char *text) | |
121 { | |
122 /* Xeroxed from gtknotify.c */ | |
123 char *primary; | |
124 void *ui_handle; | |
125 | |
126 primary = g_strdup_printf(_("Info for %s"), who); | |
127 ui_handle = gg_notify_formatted(_("Buddy Information"), primary, NULL, text); | |
128 g_free(primary); | |
129 return ui_handle; | |
130 } | |
131 | |
132 static GaimNotifyUiOps ops = | |
133 { | |
134 .notify_message = gg_notify_message, | |
135 .close_notify = gg_close_notify, /* The rest of the notify-uiops return a GntWidget. | |
136 These widgets should be destroyed from here. */ | |
137 .notify_formatted = gg_notify_formatted, | |
138 .notify_email = gg_notify_email, | |
139 .notify_emails = gg_notify_emails, | |
140 .notify_userinfo = gg_notify_userinfo, | |
141 | |
142 .notify_searchresults = NULL, /* We are going to need multi-column GntTree's for this */ | |
143 .notify_searchresults_new_rows = NULL, | |
144 .notify_uri = NULL /* This is of low-priority to me */ | |
145 }; | |
146 | |
147 GaimNotifyUiOps *gg_notify_get_ui_ops() | |
148 { | |
149 return &ops; | |
150 } | |
151 | |
152 void gg_notify_init() | |
153 { | |
154 } | |
155 | |
156 void gg_notify_uninit() | |
157 { | |
158 } | |
159 | |
160 |