Mercurial > pidgin.yaz
comparison src/gtkaccount.c @ 5620:c9724982ce45
[gaim-migrate @ 6027]
The new account dialog rocks.
committer: Tailor Script <tailor@pidgin.im>
author | Christian Hammond <chipx86@chipx86.com> |
---|---|
date | Sun, 01 Jun 2003 01:30:31 +0000 |
parents | feb012e01741 |
children | 69c92ae58876 |
comparison
equal
deleted
inserted
replaced
5619:117e23960e48 | 5620:c9724982ce45 |
---|---|
25 #include "event.h" | 25 #include "event.h" |
26 #include "prefs.h" | 26 #include "prefs.h" |
27 #include "stock.h" | 27 #include "stock.h" |
28 #include "gtkblist.h" | 28 #include "gtkblist.h" |
29 | 29 |
30 #ifdef _WIN32 | |
31 # include <gdk/gdkwin32.h> | |
32 #else | |
33 # include <unistd.h> | |
34 # include <gdk/gdkx.h> | |
35 #endif | |
36 | |
37 #include <string.h> | |
38 | |
30 enum | 39 enum |
31 { | 40 { |
32 COLUMN_ICON, | 41 COLUMN_ICON, |
33 COLUMN_PROTOCOL, | 42 COLUMN_PROTOCOL, |
34 COLUMN_SCREENNAME, | 43 COLUMN_SCREENNAME, |
45 | 54 |
46 GtkListStore *model; | 55 GtkListStore *model; |
47 | 56 |
48 GtkTreeViewColumn *screenname_col; | 57 GtkTreeViewColumn *screenname_col; |
49 | 58 |
59 GtkTreeIter drag_iter; | |
60 | |
50 } AccountsDialog; | 61 } AccountsDialog; |
51 | 62 |
52 static AccountsDialog *accounts_dialog = NULL; | 63 static AccountsDialog *accounts_dialog = NULL; |
53 | 64 |
54 static char * | 65 static char * |
69 | 80 |
70 if (gtk_tree_model_iter_nth_child(model, &iter, NULL, index)) { | 81 if (gtk_tree_model_iter_nth_child(model, &iter, NULL, index)) { |
71 gtk_list_store_set(dialog->model, &iter, | 82 gtk_list_store_set(dialog->model, &iter, |
72 COLUMN_ONLINE, gaim_account_is_connected(account), | 83 COLUMN_ONLINE, gaim_account_is_connected(account), |
73 -1); | 84 -1); |
85 } | |
86 } | |
87 | |
88 static void | |
89 __drag_data_get_cb(GtkWidget *widget, GdkDragContext *ctx, | |
90 GtkSelectionData *data, guint info, guint time, | |
91 AccountsDialog *dialog) | |
92 { | |
93 if (data->target == gdk_atom_intern("GAIM_ACCOUNT", FALSE)) { | |
94 GtkTreeRowReference *ref; | |
95 GtkTreePath *source_row; | |
96 GtkTreeIter iter; | |
97 GaimAccount *account = NULL; | |
98 GValue val = {0}; | |
99 | |
100 ref = g_object_get_data(G_OBJECT(ctx), "gtk-tree-view-source-row"); | |
101 source_row = gtk_tree_row_reference_get_path(ref); | |
102 | |
103 if (source_row == NULL) | |
104 return; | |
105 | |
106 gtk_tree_model_get_iter(GTK_TREE_MODEL(dialog->model), &iter, | |
107 source_row); | |
108 gtk_tree_model_get_value(GTK_TREE_MODEL(dialog->model), &iter, | |
109 COLUMN_DATA, &val); | |
110 | |
111 dialog->drag_iter = iter; | |
112 | |
113 account = g_value_get_pointer(&val); | |
114 | |
115 gtk_selection_data_set(data, gdk_atom_intern("GAIM_ACCOUNT", FALSE), | |
116 8, (void *)&account, sizeof(account)); | |
117 | |
118 gtk_tree_path_free(source_row); | |
119 } | |
120 } | |
121 | |
122 static void | |
123 __drag_data_received_cb(GtkWidget *widget, GdkDragContext *ctx, | |
124 guint x, guint y, GtkSelectionData *sd, | |
125 guint info, guint t, AccountsDialog *dialog) | |
126 { | |
127 if (sd->target == gdk_atom_intern("GAIM_ACCOUNT", FALSE) && sd->data) { | |
128 size_t dest_index; | |
129 GaimAccount *a = NULL; | |
130 GtkTreePath *path = NULL; | |
131 GtkTreeViewDropPosition position; | |
132 | |
133 memcpy(&a, sd->data, sizeof(a)); | |
134 | |
135 if (gtk_tree_view_get_dest_row_at_pos(GTK_TREE_VIEW(widget), x, y, | |
136 &path, &position)) { | |
137 | |
138 GtkTreeIter iter; | |
139 GaimAccount *account; | |
140 GValue val = {0}; | |
141 | |
142 gtk_tree_model_get_iter(GTK_TREE_MODEL(dialog->model), &iter, path); | |
143 gtk_tree_model_get_value(GTK_TREE_MODEL(dialog->model), &iter, | |
144 COLUMN_DATA, &val); | |
145 | |
146 account = g_value_get_pointer(&val); | |
147 | |
148 switch (position) { | |
149 case GTK_TREE_VIEW_DROP_AFTER: | |
150 case GTK_TREE_VIEW_DROP_INTO_OR_AFTER: | |
151 gaim_debug(GAIM_DEBUG_MISC, "gtkaccount", | |
152 "after\n"); | |
153 gtk_list_store_move_after(dialog->model, | |
154 &dialog->drag_iter, &iter); | |
155 dest_index = g_list_index(gaim_accounts_get_all(), | |
156 account) + 1; | |
157 break; | |
158 | |
159 case GTK_TREE_VIEW_DROP_BEFORE: | |
160 case GTK_TREE_VIEW_DROP_INTO_OR_BEFORE: | |
161 gaim_debug(GAIM_DEBUG_MISC, "gtkaccount", | |
162 "before\n"); | |
163 dest_index = g_list_index(gaim_accounts_get_all(), | |
164 account); | |
165 | |
166 gaim_debug(GAIM_DEBUG_MISC, "gtkaccount", | |
167 "iter = %p\n", &iter); | |
168 gaim_debug(GAIM_DEBUG_MISC, "gtkaccount", | |
169 "account = %s\n", | |
170 gaim_account_get_username(account)); | |
171 | |
172 /* | |
173 * Somebody figure out why inserting before the first | |
174 * account sometimes moves to the end, please :( | |
175 */ | |
176 if (dest_index == 0) { | |
177 gtk_list_store_move_after(dialog->model, | |
178 &dialog->drag_iter, &iter); | |
179 gtk_list_store_swap(dialog->model, &iter, | |
180 &dialog->drag_iter); | |
181 } | |
182 else { | |
183 gtk_list_store_move_before(dialog->model, | |
184 &dialog->drag_iter, &iter); | |
185 } | |
186 | |
187 break; | |
188 | |
189 default: | |
190 return; | |
191 } | |
192 | |
193 gaim_accounts_reorder(a, dest_index); | |
194 } | |
74 } | 195 } |
75 } | 196 } |
76 | 197 |
77 static gint | 198 static gint |
78 __window_destroy_cb(GtkWidget *w, GdkEvent *event, AccountsDialog *dialog) | 199 __window_destroy_cb(GtkWidget *w, GdkEvent *event, AccountsDialog *dialog) |
277 static GtkWidget * | 398 static GtkWidget * |
278 __create_accounts_list(AccountsDialog *dialog) | 399 __create_accounts_list(AccountsDialog *dialog) |
279 { | 400 { |
280 GtkWidget *sw; | 401 GtkWidget *sw; |
281 GtkWidget *treeview; | 402 GtkWidget *treeview; |
403 GtkTargetEntry gte[] = {{"GAIM_ACCOUNT", GTK_TARGET_SAME_APP, 0}}; | |
282 | 404 |
283 /* Create the scrolled window. */ | 405 /* Create the scrolled window. */ |
284 sw = gtk_scrolled_window_new(0, 0); | 406 sw = gtk_scrolled_window_new(0, 0); |
285 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw), | 407 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw), |
286 GTK_POLICY_AUTOMATIC, | 408 GTK_POLICY_AUTOMATIC, |
296 G_TYPE_BOOLEAN, G_TYPE_POINTER); | 418 G_TYPE_BOOLEAN, G_TYPE_POINTER); |
297 | 419 |
298 /* And now the actual treeview */ | 420 /* And now the actual treeview */ |
299 treeview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(dialog->model)); | 421 treeview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(dialog->model)); |
300 gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(treeview), TRUE); | 422 gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(treeview), TRUE); |
301 gtk_tree_view_set_reorderable(GTK_TREE_VIEW(treeview), TRUE); | |
302 gtk_tree_selection_set_mode( | 423 gtk_tree_selection_set_mode( |
303 gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview)), | 424 gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview)), |
304 GTK_SELECTION_MULTIPLE); | 425 GTK_SELECTION_MULTIPLE); |
305 | 426 |
306 gtk_container_add(GTK_CONTAINER(sw), treeview); | 427 gtk_container_add(GTK_CONTAINER(sw), treeview); |
307 gtk_widget_show(treeview); | 428 gtk_widget_show(treeview); |
308 | 429 |
309 __add_columns(treeview, dialog); | 430 __add_columns(treeview, dialog); |
310 | 431 |
311 __populate_accounts_list(dialog); | 432 __populate_accounts_list(dialog); |
433 | |
434 /* Setup DND. I wanna be an orc! */ | |
435 gtk_tree_view_enable_model_drag_source( | |
436 GTK_TREE_VIEW(treeview), GDK_BUTTON1_MASK, gte, | |
437 2, GDK_ACTION_COPY); | |
438 gtk_tree_view_enable_model_drag_dest( | |
439 GTK_TREE_VIEW(treeview), gte, 2, | |
440 GDK_ACTION_COPY | GDK_ACTION_MOVE); | |
441 | |
442 g_signal_connect(G_OBJECT(treeview), "drag-data-received", | |
443 G_CALLBACK(__drag_data_received_cb), dialog); | |
444 g_signal_connect(G_OBJECT(treeview), "drag-data-get", | |
445 G_CALLBACK(__drag_data_get_cb), dialog); | |
312 | 446 |
313 return sw; | 447 return sw; |
314 } | 448 } |
315 | 449 |
316 void | 450 void |