comparison src/gtkaccount.c @ 5569:5d2911d6d38e

[gaim-migrate @ 5971] The accounts dialog is getting there.. committer: Tailor Script <tailor@pidgin.im>
author Christian Hammond <chipx86@chipx86.com>
date Fri, 30 May 2003 19:59:27 +0000
parents cc9ddec20010
children 5e7de337a053
comparison
equal deleted inserted replaced
5568:fb4f7bd7525c 5569:5d2911d6d38e
22 */ 22 */
23 #include "gtkaccount.h" 23 #include "gtkaccount.h"
24 #include "account.h" 24 #include "account.h"
25 #include "prefs.h" 25 #include "prefs.h"
26 #include "stock.h" 26 #include "stock.h"
27 #include "gtkblist.h"
28
29 enum
30 {
31 COLUMN_ICON,
32 COLUMN_SCREENNAME,
33 COLUMN_ONLINE,
34 COLUMN_AUTOLOGIN,
35 COLUMN_PROTOCOL,
36 COLUMN_DATA,
37 NUM_COLUMNS
38 };
27 39
28 typedef struct 40 typedef struct
29 { 41 {
30 GtkWidget *window; 42 GtkWidget *window;
31 43
44 GtkListStore *model;
45
32 } AccountsDialog; 46 } AccountsDialog;
33 47
34 static AccountsDialog *accounts_dialog = NULL; 48 static AccountsDialog *accounts_dialog = NULL;
49
50 static char *
51 proto_name(int proto)
52 {
53 GaimPlugin *p = gaim_find_prpl(proto);
54
55 return ((p && p->info->name) ? _(p->info->name) : _("Unknown"));
56 }
35 57
36 static gint 58 static gint
37 __window_destroy_cb(GtkWidget *w, GdkEvent *event, void *unused) 59 __window_destroy_cb(GtkWidget *w, GdkEvent *event, void *unused)
38 { 60 {
39 g_free(accounts_dialog); 61 g_free(accounts_dialog);
51 } 73 }
52 74
53 return FALSE; 75 return FALSE;
54 } 76 }
55 77
78 static void
79 __add_account_cb(GtkWidget *w, AccountsDialog *dialog)
80 {
81
82 }
83
84 static void
85 __modify_account_cb(GtkWidget *w, AccountsDialog *dialog)
86 {
87
88 }
89
90 static void
91 __delete_account_cb(GtkWidget *w, AccountsDialog *dialog)
92 {
93
94 }
95
96 static void
97 __close_accounts_cb(GtkWidget *w, AccountsDialog *dialog)
98 {
99
100 }
101
102 static void
103 __online_cb(GtkCellRendererToggle *renderer, gchar *path_str, gpointer data)
104 {
105
106 }
107
108 static void
109 __autologin_cb(GtkCellRendererToggle *renderer, gchar *path_str,
110 gpointer data)
111 {
112
113 }
114
115 static void
116 __add_columns(GtkWidget *treeview, AccountsDialog *dialog)
117 {
118 GtkCellRenderer *renderer;
119
120 /* Protocol Icon */
121 renderer = gtk_cell_renderer_pixbuf_new();
122 gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(treeview),
123 -1, "",
124 renderer,
125 "pixbuf", COLUMN_ICON,
126 NULL);
127
128 /* Screennames */
129 renderer = gtk_cell_renderer_text_new();
130 gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(treeview),
131 -1, _("Screenname"),
132 renderer,
133 "text", COLUMN_SCREENNAME,
134 NULL);
135
136 /* Online? */
137 renderer = gtk_cell_renderer_toggle_new();
138
139 g_signal_connect(G_OBJECT(renderer), "toggled",
140 G_CALLBACK(__online_cb), dialog);
141
142 gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(treeview),
143 -1, _("Online"),
144 renderer,
145 "text", COLUMN_ONLINE,
146 NULL);
147
148
149 /* Auto-login? */
150 renderer = gtk_cell_renderer_toggle_new();
151
152 g_signal_connect(G_OBJECT(renderer), "toggled",
153 G_CALLBACK(__autologin_cb), dialog);
154
155 gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(treeview),
156 -1, _("Auto-login"),
157 renderer,
158 "text", COLUMN_AUTOLOGIN,
159 NULL);
160
161
162 /* Protocol description */
163 renderer = gtk_cell_renderer_text_new();
164 gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(treeview),
165 -1, _("Protocol"),
166 renderer,
167 "text", COLUMN_PROTOCOL,
168 NULL);
169 }
170
171 static void
172 __populate_accounts_list(AccountsDialog *dialog)
173 {
174 GList *l;
175 GaimAccount *account;
176 GtkTreeIter iter;
177 GdkPixbuf *pixbuf;
178 GdkPixbuf *scale;
179
180 gtk_list_store_clear(dialog->model);
181
182 for (l = gaim_accounts_get_all(); l != NULL; l = l->next) {
183 account = l->data;
184
185 pixbuf = create_prpl_icon(account);
186 scale = gdk_pixbuf_scale_simple(pixbuf, 16, 16, GDK_INTERP_BILINEAR);
187
188 gtk_list_store_append(dialog->model, &iter);
189 gtk_list_store_set(dialog->model, &iter,
190 COLUMN_ICON, scale,
191 COLUMN_SCREENNAME, gaim_account_get_username(account),
192 COLUMN_ONLINE, gaim_account_is_connected(account),
193 COLUMN_AUTOLOGIN, FALSE,
194 COLUMN_PROTOCOL, proto_name(gaim_account_get_protocol(account)),
195 COLUMN_DATA, account,
196 -1);
197
198 g_object_unref(G_OBJECT(pixbuf));
199 g_object_unref(G_OBJECT(scale));
200 }
201 }
202
56 static GtkWidget * 203 static GtkWidget *
57 __create_accounts_list(void) 204 __create_accounts_list(AccountsDialog *dialog)
58 { 205 {
59 return NULL; 206 GtkWidget *sw;
207 GtkWidget *treeview;
208
209 /* Create the scrolled window. */
210 sw = gtk_scrolled_window_new(0, 0);
211 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw),
212 GTK_POLICY_AUTOMATIC,
213 GTK_POLICY_ALWAYS);
214 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(sw),
215 GTK_SHADOW_IN);
216 gtk_widget_show(sw);
217
218 /* Create the list model. */
219 dialog->model = gtk_list_store_new(NUM_COLUMNS, G_TYPE_POINTER,
220 G_TYPE_STRING, G_TYPE_BOOLEAN,
221 G_TYPE_BOOLEAN, G_TYPE_STRING,
222 G_TYPE_POINTER);
223
224 /* And now the actual treeview */
225 treeview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(dialog->model));
226 gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(treeview), TRUE);
227 gtk_tree_view_set_reorderable(GTK_TREE_VIEW(treeview), TRUE);
228 gtk_tree_selection_set_mode(
229 gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview)),
230 GTK_SELECTION_MULTIPLE);
231
232 __add_columns(treeview, dialog);
233
234 gtk_container_add(GTK_CONTAINER(sw), treeview);
235 gtk_widget_show(treeview);
236
237 __populate_accounts_list(dialog);
238
239 return sw;
60 } 240 }
61 241
62 void 242 void
63 gaim_gtk_account_dialog_show(void) 243 gaim_gtk_account_dialog_show(void)
64 { 244 {
72 int width, height; 252 int width, height;
73 253
74 if (accounts_dialog != NULL) 254 if (accounts_dialog != NULL)
75 return; 255 return;
76 256
77 dialog = g_new0(AccountsDialog, 1); 257 accounts_dialog = dialog = g_new0(AccountsDialog, 1);
78 258
79 width = gaim_prefs_get_int("/gaim/gtk/accounts/dialog/width"); 259 width = gaim_prefs_get_int("/gaim/gtk/accounts/dialog/width");
80 height = gaim_prefs_get_int("/gaim/gtk/accounts/dialog/height"); 260 height = gaim_prefs_get_int("/gaim/gtk/accounts/dialog/height");
81 261
82 win = accounts_dialog->window; 262 win = dialog->window;
83 263
84 GAIM_DIALOG(win); 264 GAIM_DIALOG(win);
85 gtk_window_set_default_size(GTK_WINDOW(win), width, height); 265 gtk_window_set_default_size(GTK_WINDOW(win), width, height);
86 gtk_window_set_role(GTK_WINDOW(win), "accounts"); 266 gtk_window_set_role(GTK_WINDOW(win), "accounts");
87 gtk_window_set_title(GTK_WINDOW(win), "Accounts"); 267 gtk_window_set_title(GTK_WINDOW(win), "Accounts");
96 vbox = gtk_vbox_new(FALSE, 12); 276 vbox = gtk_vbox_new(FALSE, 12);
97 gtk_container_add(GTK_CONTAINER(win), vbox); 277 gtk_container_add(GTK_CONTAINER(win), vbox);
98 gtk_widget_show(vbox); 278 gtk_widget_show(vbox);
99 279
100 /* Setup the scrolled window that will contain the list of accounts. */ 280 /* Setup the scrolled window that will contain the list of accounts. */
101 #if 0 281 sw = __create_accounts_list(dialog);
102 sw = __create_accounts_list();
103 gtk_box_pack_start(GTK_BOX(vbox), sw, TRUE, TRUE, 0); 282 gtk_box_pack_start(GTK_BOX(vbox), sw, TRUE, TRUE, 0);
104 gtk_widget_show(sw); 283 gtk_widget_show(sw);
105 #endif
106 284
107 /* Separator... */ 285 /* Separator... */
108 sep = gtk_hseparator_new(); 286 sep = gtk_hseparator_new();
109 gtk_box_pack_start(GTK_BOX(vbox), sep, FALSE, FALSE, 0); 287 gtk_box_pack_start(GTK_BOX(vbox), sep, FALSE, FALSE, 0);
110 gtk_widget_show(sep); 288 gtk_widget_show(sep);
112 /* Button box. */ 290 /* Button box. */
113 bbox = gtk_hbutton_box_new(); 291 bbox = gtk_hbutton_box_new();
114 gtk_box_set_spacing(GTK_BOX(bbox), 6); 292 gtk_box_set_spacing(GTK_BOX(bbox), 6);
115 gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_END); 293 gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_END);
116 gtk_box_pack_end(GTK_BOX(vbox), bbox, FALSE, TRUE, 0); 294 gtk_box_pack_end(GTK_BOX(vbox), bbox, FALSE, TRUE, 0);
117 gtk_widget_show(vbox); 295 gtk_widget_show(bbox);
118 296
119 /* Add button */ 297 /* Add button */
120 button = gtk_button_new_from_stock(GTK_STOCK_ADD); 298 button = gtk_button_new_from_stock(GTK_STOCK_ADD);
121 gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0); 299 gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0);
122 gtk_widget_show(button); 300 gtk_widget_show(button);
123 301
302 g_signal_connect(G_OBJECT(button), "clicked",
303 G_CALLBACK(__add_account_cb), dialog);
304
124 /* Modify button */ 305 /* Modify button */
125 button = gtk_button_new_from_stock(GAIM_STOCK_MODIFY); 306 button = gtk_button_new_from_stock(GAIM_STOCK_MODIFY);
126 gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0); 307 gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0);
127 gtk_widget_show(button); 308 gtk_widget_show(button);
128 309
310 g_signal_connect(G_OBJECT(button), "clicked",
311 G_CALLBACK(__modify_account_cb), dialog);
312
129 /* Delete button */ 313 /* Delete button */
130 button = gtk_button_new_from_stock(GTK_STOCK_DELETE); 314 button = gtk_button_new_from_stock(GTK_STOCK_DELETE);
131 gtk_box_pack_start(GTK_BOX(button), button, FALSE, FALSE, 0); 315 gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0);
132 gtk_widget_show(button); 316 gtk_widget_show(button);
317
318 g_signal_connect(G_OBJECT(button), "clicked",
319 G_CALLBACK(__delete_account_cb), dialog);
133 320
134 /* Close button */ 321 /* Close button */
135 button = gtk_button_new_from_stock(GTK_STOCK_CLOSE); 322 button = gtk_button_new_from_stock(GTK_STOCK_CLOSE);
136 gtk_box_pack_start(GTK_BOX(button), button, FALSE, FALSE, 0); 323 gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0);
137 gtk_widget_show(button); 324 gtk_widget_show(button);
138 325
326 g_signal_connect(G_OBJECT(button), "clicked",
327 G_CALLBACK(__close_accounts_cb), dialog);
328
139 gtk_widget_show(win); 329 gtk_widget_show(win);
140 } 330 }
141 331