Mercurial > pidgin.yaz
comparison console/gntaccount.c @ 13907:cc60d0861337
[gaim-migrate @ 16402]
This commit has 1234 lines of diff :)
Windows can now be moved (alt+m, then the arrow keys, then escape/enter).
Add a window to enable/disable accounts. But the 'add' etc. buttons don't
have any callbacks yet. I am going to need to do some more widgets (checkbox,
combobox) before I do anything else.
I have also updated the test programs to work with the changes in libgnt.
committer: Tailor Script <tailor@pidgin.im>
author | Sadrul Habib Chowdhury <imadil@gmail.com> |
---|---|
date | Sun, 02 Jul 2006 22:13:06 +0000 |
parents | |
children | fdf2dbed6faa |
comparison
equal
deleted
inserted
replaced
13906:b986b6e2441b | 13907:cc60d0861337 |
---|---|
1 #include <gnt.h> | |
2 #include <gntbox.h> | |
3 #include <gntbutton.h> | |
4 #include <gntlabel.h> | |
5 #include <gnttree.h> | |
6 | |
7 #include <connection.h> | |
8 #include <notify.h> | |
9 #include <request.h> | |
10 | |
11 #include "gntaccount.h" | |
12 #include "gntgaim.h" | |
13 | |
14 typedef struct | |
15 { | |
16 GntWidget *window; | |
17 GntWidget *tree; | |
18 } GGAccountList; | |
19 | |
20 static GGAccountList accounts; | |
21 | |
22 static void | |
23 account_toggled(GntWidget *widget, void *key, gpointer null) | |
24 { | |
25 GaimAccount *account = key; | |
26 | |
27 gaim_account_set_enabled(account, GAIM_GNT_UI, gnt_tree_get_choice(GNT_TREE(widget), key)); | |
28 } | |
29 | |
30 void gg_accounts_init() | |
31 { | |
32 GList *iter; | |
33 GntWidget *box, *button; | |
34 | |
35 accounts.window = gnt_box_new(TRUE, TRUE); | |
36 gnt_box_set_toplevel(GNT_BOX(accounts.window), TRUE); | |
37 gnt_box_set_title(GNT_BOX(accounts.window), _("Accounts")); | |
38 gnt_widget_set_name(accounts.window, "accounts"); | |
39 | |
40 gnt_box_add_widget(GNT_BOX(accounts.window), | |
41 gnt_label_new(_("You can enable/disable accounts from the follwing list."))); | |
42 | |
43 accounts.tree = gnt_tree_new(); | |
44 GNT_WIDGET_SET_FLAGS(accounts.tree, GNT_WIDGET_NO_BORDER); | |
45 | |
46 for (iter = gaim_accounts_get_all(); iter; iter = iter->next) | |
47 { | |
48 GaimAccount *account = iter->data; | |
49 char *str = g_strdup_printf("%s (%s)", | |
50 gaim_account_get_username(account), gaim_account_get_protocol_id(account)); | |
51 | |
52 gnt_tree_add_choice(GNT_TREE(accounts.tree), account, | |
53 str, NULL, NULL); | |
54 gnt_tree_set_choice(GNT_TREE(accounts.tree), account, | |
55 gaim_account_get_enabled(account, GAIM_GNT_UI)); | |
56 g_free(str); | |
57 } | |
58 | |
59 g_signal_connect(G_OBJECT(accounts.tree), "toggled", G_CALLBACK(account_toggled), NULL); | |
60 | |
61 gnt_widget_set_size(accounts.tree, 40, 15); | |
62 gnt_box_add_widget(GNT_BOX(accounts.window), accounts.tree); | |
63 | |
64 box = gnt_box_new(FALSE, FALSE); | |
65 | |
66 button = gnt_button_new(_("Add")); | |
67 gnt_box_add_widget(GNT_BOX(box), button); | |
68 | |
69 button = gnt_button_new(_("Modify")); | |
70 gnt_box_add_widget(GNT_BOX(box), button); | |
71 | |
72 button = gnt_button_new(_("Delete")); | |
73 gnt_box_add_widget(GNT_BOX(box), button); | |
74 | |
75 gnt_box_add_widget(GNT_BOX(accounts.window), box); | |
76 | |
77 gnt_widget_show(accounts.window); | |
78 } | |
79 | |
80 void gg_accounts_uninit() | |
81 { | |
82 gnt_widget_destroy(accounts.window); | |
83 } | |
84 | |
85 #if 0 | |
86 /* The following uiops stuff are copied from gtkaccount.c */ | |
87 /* Need to do some work on notify- and request-ui before this works */ | |
88 typedef struct | |
89 { | |
90 GaimAccount *account; | |
91 char *username; | |
92 char *alias; | |
93 } AddUserData; | |
94 | |
95 static char * | |
96 make_info(GaimAccount *account, GaimConnection *gc, const char *remote_user, | |
97 const char *id, const char *alias, const char *msg) | |
98 { | |
99 if (msg != NULL && *msg == '\0') | |
100 msg = NULL; | |
101 | |
102 return g_strdup_printf(_("%s%s%s%s has made %s his or her buddy%s%s"), | |
103 remote_user, | |
104 (alias != NULL ? " (" : ""), | |
105 (alias != NULL ? alias : ""), | |
106 (alias != NULL ? ")" : ""), | |
107 (id != NULL | |
108 ? id | |
109 : (gaim_connection_get_display_name(gc) != NULL | |
110 ? gaim_connection_get_display_name(gc) | |
111 : gaim_account_get_username(account))), | |
112 (msg != NULL ? ": " : "."), | |
113 (msg != NULL ? msg : "")); | |
114 } | |
115 | |
116 static void | |
117 notify_added(GaimAccount *account, const char *remote_user, | |
118 const char *id, const char *alias, | |
119 const char *msg) | |
120 { | |
121 char *buffer; | |
122 GaimConnection *gc; | |
123 | |
124 gc = gaim_account_get_connection(account); | |
125 | |
126 buffer = make_info(account, gc, remote_user, id, alias, msg); | |
127 | |
128 gaim_notify_info(NULL, NULL, buffer, NULL); | |
129 | |
130 g_free(buffer); | |
131 } | |
132 | |
133 static void | |
134 request_add(GaimAccount *account, const char *remote_user, | |
135 const char *id, const char *alias, | |
136 const char *msg) | |
137 { | |
138 char *buffer; | |
139 GaimConnection *gc; | |
140 AddUserData *data; | |
141 | |
142 gc = gaim_account_get_connection(account); | |
143 | |
144 data = g_new0(AddUserData, 1); | |
145 data->account = account; | |
146 data->username = g_strdup(remote_user); | |
147 data->alias = (alias != NULL ? g_strdup(alias) : NULL); | |
148 | |
149 buffer = make_info(account, gc, remote_user, id, alias, msg); | |
150 #if 0 | |
151 gaim_request_action(NULL, NULL, _("Add buddy to your list?"), | |
152 buffer, GAIM_DEFAULT_ACTION_NONE, data, 2, | |
153 _("Add"), G_CALLBACK(add_user_cb), | |
154 _("Cancel"), G_CALLBACK(free_add_user_data)); | |
155 #endif | |
156 g_free(buffer); | |
157 } | |
158 | |
159 static GaimAccountUiOps ui_ops = | |
160 { | |
161 .notify_added = notify_added, | |
162 .status_changed = NULL, | |
163 .request_add = request_add | |
164 }; | |
165 #else | |
166 | |
167 static GaimAccountUiOps ui_ops = | |
168 { | |
169 .notify_added = NULL, | |
170 .status_changed = NULL, | |
171 .request_add = NULL | |
172 }; | |
173 | |
174 #endif | |
175 | |
176 GaimAccountUiOps *gg_accounts_get_ui_ops() | |
177 { | |
178 return &ui_ops; | |
179 } | |
180 |