comparison console/libgnt/gntmain.c @ 14405:8375ecb6152b

[gaim-migrate @ 17113] Pressing Alt+a will bring up a list of available 'actions', which you can use show the buddylist/accounts/debug etc. windows. Pressing ctrl+o in the buddylist will toggle showing online/offline users. committer: Tailor Script <tailor@pidgin.im>
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Fri, 01 Sep 2006 12:06:51 +0000
parents d4a26ada1971
children 76d345643ba4
comparison
equal deleted inserted replaced
14404:8ff8f1c897b5 14405:8375ecb6152b
44 44
45 static gboolean ascii_only; 45 static gboolean ascii_only;
46 static gboolean mouse_enabled; 46 static gboolean mouse_enabled;
47 47
48 static GMainLoop *loop; 48 static GMainLoop *loop;
49
49 static struct 50 static struct
50 { 51 {
51 GntWidget *window; 52 GntWidget *window;
52 GntWidget *tree; 53 GntWidget *tree;
53 } window_list; 54 } _list, *window_list, *action_list;
54 55
55 typedef struct 56 typedef struct
56 { 57 {
57 GntWidget *me; 58 GntWidget *me;
58 59
74 static void draw_taskbar(gboolean reposition); 75 static void draw_taskbar(gboolean reposition);
75 static void bring_on_top(GntWidget *widget); 76 static void bring_on_top(GntWidget *widget);
76 77
77 static gboolean refresh_screen(); 78 static gboolean refresh_screen();
78 static const GList *list_all_windows(); 79 static const GList *list_all_windows();
80
81 static void show_actions_list();
79 82
80 static GntWM wm = 83 static GntWM wm =
81 { 84 {
82 NULL, /* new_window */ 85 NULL, /* new_window */
83 NULL, /* close_window */ 86 NULL, /* close_window */
172 175
173 gnt_widget_set_focus(widget, TRUE); 176 gnt_widget_set_focus(widget, TRUE);
174 gnt_widget_draw(widget); 177 gnt_widget_draw(widget);
175 top_panel(node->panel); 178 top_panel(node->panel);
176 179
177 if (window_list.window) 180 if (_list.window)
178 { 181 {
179 GntNode *nd = g_hash_table_lookup(nodes, window_list.window); 182 GntNode *nd = g_hash_table_lookup(nodes, _list.window);
180 top_panel(nd->panel); 183 top_panel(nd->panel);
181 } 184 }
182 update_screen(NULL); 185 update_screen(NULL);
183 draw_taskbar(FALSE); 186 draw_taskbar(FALSE);
184 } 187 }
186 static void 189 static void
187 update_window_in_list(GntWidget *wid) 190 update_window_in_list(GntWidget *wid)
188 { 191 {
189 GntTextFormatFlags flag = 0; 192 GntTextFormatFlags flag = 0;
190 193
191 if (window_list.window == NULL) 194 if (window_list == NULL)
192 return; 195 return;
193 196
194 if (wid == ordered->data) 197 if (wid == ordered->data)
195 flag |= GNT_TEXT_FLAG_DIM; 198 flag |= GNT_TEXT_FLAG_DIM;
196 else if (GNT_WIDGET_IS_FLAG_SET(wid, GNT_WIDGET_URGENT)) 199 else if (GNT_WIDGET_IS_FLAG_SET(wid, GNT_WIDGET_URGENT))
197 flag |= GNT_TEXT_FLAG_BOLD; 200 flag |= GNT_TEXT_FLAG_BOLD;
198 201
199 gnt_tree_set_row_flags(GNT_TREE(window_list.tree), wid, flag); 202 gnt_tree_set_row_flags(GNT_TREE(window_list->tree), wid, flag);
200 } 203 }
201 204
202 static void 205 static void
203 draw_taskbar(gboolean reposition) 206 draw_taskbar(gboolean reposition)
204 { 207 {
325 gnt_widget_set_focus(old, FALSE); 328 gnt_widget_set_focus(old, FALSE);
326 } 329 }
327 } 330 }
328 331
329 static void 332 static void
333 setup__list()
334 {
335 GntWidget *tree, *win;
336 win = _list.window = gnt_box_new(FALSE, FALSE);
337 gnt_box_set_toplevel(GNT_BOX(win), TRUE);
338 gnt_box_set_pad(GNT_BOX(win), 0);
339
340 tree = _list.tree = gnt_tree_new();
341 gnt_box_add_widget(GNT_BOX(win), tree);
342 }
343
344 static void
330 show_window_list() 345 show_window_list()
331 { 346 {
332 GntWidget *tree, *win; 347 GntWidget *tree, *win;
333 GList *iter; 348 GList *iter;
334 349
335 if (window_list.window) 350 if (window_list)
336 return; 351 return;
337 352
338 win = window_list.window = gnt_box_new(FALSE, FALSE); 353 setup__list();
339 gnt_box_set_toplevel(GNT_BOX(win), TRUE); 354
355 window_list = &_list;
356
357 win = window_list->window;
358 tree = window_list->tree;
359
340 gnt_box_set_title(GNT_BOX(win), "Window List"); 360 gnt_box_set_title(GNT_BOX(win), "Window List");
341 gnt_box_set_pad(GNT_BOX(win), 0);
342
343 tree = window_list.tree = gnt_tree_new();
344 361
345 for (iter = focus_list; iter; iter = iter->next) 362 for (iter = focus_list; iter; iter = iter->next)
346 { 363 {
347 GntBox *box = GNT_BOX(iter->data); 364 GntBox *box = GNT_BOX(iter->data);
348 365
350 gnt_tree_create_row(GNT_TREE(tree), box->title), NULL); 367 gnt_tree_create_row(GNT_TREE(tree), box->title), NULL);
351 update_window_in_list(GNT_WIDGET(box)); 368 update_window_in_list(GNT_WIDGET(box));
352 } 369 }
353 370
354 gnt_tree_set_selected(GNT_TREE(tree), ordered->data); 371 gnt_tree_set_selected(GNT_TREE(tree), ordered->data);
355 gnt_box_add_widget(GNT_BOX(win), tree); 372 g_signal_connect(G_OBJECT(tree), "activate", G_CALLBACK(window_list_activate), NULL);
356 373
357 gnt_tree_set_col_width(GNT_TREE(tree), 0, getmaxx(stdscr) / 3); 374 gnt_tree_set_col_width(GNT_TREE(tree), 0, getmaxx(stdscr) / 3);
358 gnt_widget_set_size(tree, 0, getmaxy(stdscr) / 2); 375 gnt_widget_set_size(tree, 0, getmaxy(stdscr) / 2);
359 gnt_widget_set_position(win, getmaxx(stdscr) / 3, getmaxy(stdscr) / 4); 376 gnt_widget_set_position(win, getmaxx(stdscr) / 3, getmaxy(stdscr) / 4);
360 377
361 lock_focus_list = 1; 378 lock_focus_list = 1;
362 gnt_widget_show(win); 379 gnt_widget_show(win);
363 lock_focus_list = 0; 380 lock_focus_list = 0;
364
365 g_signal_connect(G_OBJECT(tree), "activate", G_CALLBACK(window_list_activate), NULL);
366 } 381 }
367 382
368 static void 383 static void
369 shift_window(GntWidget *widget, int dir) 384 shift_window(GntWidget *widget, int dir)
370 { 385 {
718 { 733 {
719 /* Window list */ 734 /* Window list */
720 mode = GNT_KP_MODE_WINDOW_LIST; 735 mode = GNT_KP_MODE_WINDOW_LIST;
721 show_window_list(); 736 show_window_list();
722 } 737 }
738 else if (strcmp(buffer + 1, "a") == 0)
739 {
740 mode = GNT_KP_MODE_WINDOW_LIST;
741 show_actions_list();
742 }
723 else if (strcmp(buffer + 1, "r") == 0 && focus_list) 743 else if (strcmp(buffer + 1, "r") == 0 && focus_list)
724 { 744 {
725 /* Resize window */ 745 /* Resize window */
726 mode = GNT_KP_MODE_RESIZE; 746 mode = GNT_KP_MODE_RESIZE;
727 } 747 }
808 else if (*buffer == '\r') 828 else if (*buffer == '\r')
809 { 829 {
810 mode = GNT_KP_MODE_NORMAL; 830 mode = GNT_KP_MODE_NORMAL;
811 } 831 }
812 } 832 }
813 else if (mode == GNT_KP_MODE_WINDOW_LIST && window_list.window) 833 else if (mode == GNT_KP_MODE_WINDOW_LIST && _list.window)
814 { 834 {
815 gnt_widget_key_pressed(window_list.window, buffer); 835 gnt_widget_key_pressed(_list.window, buffer);
816 836
817 if (buffer[0] == '\r' || (buffer[0] == 27 && buffer[1] == 0)) 837 if (buffer[0] == '\r' || (buffer[0] == 27 && buffer[1] == 0))
818 { 838 {
819 mode = GNT_KP_MODE_NORMAL; 839 mode = GNT_KP_MODE_NORMAL;
820 lock_focus_list = 1; 840 lock_focus_list = 1;
821 gnt_widget_destroy(window_list.window); 841 gnt_widget_destroy(_list.window);
822 window_list.window = NULL; 842 _list.window = NULL;
823 window_list.tree = NULL; 843 _list.tree = NULL;
824 lock_focus_list = 0; 844 lock_focus_list = 0;
845 window_list = NULL;
846 action_list = NULL;
825 } 847 }
826 } 848 }
827 else if (mode == GNT_KP_MODE_RESIZE) 849 else if (mode == GNT_KP_MODE_RESIZE)
828 { 850 {
829 if (buffer[0] == '\r' || (buffer[0] == 27 && buffer[1] == 0)) 851 if (buffer[0] == '\r' || (buffer[0] == 27 && buffer[1] == 0))
1052 1074
1053 g_hash_table_replace(nodes, widget, node); 1075 g_hash_table_replace(nodes, widget, node);
1054 1076
1055 refresh_node(widget, node, NULL); 1077 refresh_node(widget, node, NULL);
1056 1078
1057 if (window_list.window) 1079 if (window_list)
1058 { 1080 {
1059 if ((GNT_IS_BOX(widget) && GNT_BOX(widget)->title) && window_list.window != widget 1081 if ((GNT_IS_BOX(widget) && GNT_BOX(widget)->title) && window_list->window != widget
1060 && GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_CAN_TAKE_FOCUS)) 1082 && GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_CAN_TAKE_FOCUS))
1061 { 1083 {
1062 gnt_tree_add_row_last(GNT_TREE(window_list.tree), widget, 1084 gnt_tree_add_row_last(GNT_TREE(window_list->tree), widget,
1063 gnt_tree_create_row(GNT_TREE(window_list.tree), GNT_BOX(widget)->title), 1085 gnt_tree_create_row(GNT_TREE(window_list->tree), GNT_BOX(widget)->title),
1064 NULL); 1086 NULL);
1065 update_window_in_list(widget); 1087 update_window_in_list(widget);
1066 } 1088 }
1067 } 1089 }
1068 1090
1079 if (node == NULL) /* Yay! Nothing to do. */ 1101 if (node == NULL) /* Yay! Nothing to do. */
1080 return; 1102 return;
1081 1103
1082 g_hash_table_remove(nodes, widget); 1104 g_hash_table_remove(nodes, widget);
1083 1105
1084 if (window_list.window) 1106 if (window_list)
1085 { 1107 {
1086 gnt_tree_remove(GNT_TREE(window_list.tree), widget); 1108 gnt_tree_remove(GNT_TREE(window_list->tree), widget);
1087 } 1109 }
1088 1110
1089 update_screen(NULL); 1111 update_screen(NULL);
1090 } 1112 }
1091 1113
1098 1120
1099 gnt_box_sync_children(GNT_BOX(widget)); 1121 gnt_box_sync_children(GNT_BOX(widget));
1100 node = g_hash_table_lookup(nodes, widget); 1122 node = g_hash_table_lookup(nodes, widget);
1101 if (node && !node->panel) 1123 if (node && !node->panel)
1102 { 1124 {
1103 if (wm.new_window) 1125 if (wm.new_window && node->me != _list.window)
1104 node->panel = wm.new_window(node->me); 1126 node->panel = wm.new_window(node->me);
1105 else 1127 else
1106 node->panel = new_panel(node->me->window); 1128 node->panel = new_panel(node->me->window);
1107 if (!GNT_WIDGET_IS_FLAG_SET(node->me, GNT_WIDGET_TRANSIENT)) 1129 if (!GNT_WIDGET_IS_FLAG_SET(node->me, GNT_WIDGET_TRANSIENT))
1108 { 1130 {
1109 bottom_panel(node->panel); /* New windows should not grab focus */ 1131 bottom_panel(node->panel); /* New windows should not grab focus */
1110 gnt_widget_set_urgent(node->me); 1132 gnt_widget_set_urgent(node->me);
1111 } 1133 }
1112 } 1134 }
1113 1135
1114 if (window_list.window) 1136 if (_list.window)
1115 { 1137 {
1116 GntNode *nd = g_hash_table_lookup(nodes, window_list.window); 1138 GntNode *nd = g_hash_table_lookup(nodes, _list.window);
1117 top_panel(nd->panel); 1139 top_panel(nd->panel);
1118 } 1140 }
1119 1141
1120 update_screen(NULL); 1142 update_screen(NULL);
1121 } 1143 }
1129 w = widget; 1151 w = widget;
1130 1152
1131 while (widget->parent) 1153 while (widget->parent)
1132 widget = widget->parent; 1154 widget = widget->parent;
1133 1155
1134 if (widget == window_list.window) 1156 if (widget == _list.window)
1135 return TRUE; 1157 return TRUE;
1136 1158
1137 if (ordered && ordered->data == widget) 1159 if (ordered && ordered->data == widget)
1138 { 1160 {
1139 if (GNT_IS_BOX(widget) && 1161 if (GNT_IS_BOX(widget) &&
1224 } 1246 }
1225 1247
1226 draw_taskbar(FALSE); 1248 draw_taskbar(FALSE);
1227 } 1249 }
1228 1250
1251 /**
1252 * An application can register actions which will show up in a 'start-menu' like popup
1253 */
1254 typedef struct _GnAction
1255 {
1256 const char *label;
1257 void (*callback)();
1258 } GntAction;
1259
1260 static GList *actions;
1261
1262 void gnt_register_action(const char *label, void (*callback)())
1263 {
1264 GntAction *action = g_new0(GntAction, 1);
1265 action->label = g_strdup(label);
1266 action->callback = callback;
1267
1268 actions = g_list_append(actions, action);
1269 }
1270
1271 static void
1272 action_list_activate(GntTree *tree, gpointer null)
1273 {
1274 GntAction *action = gnt_tree_get_selection_data(tree);
1275 action->callback();
1276 }
1277
1278 static int
1279 compare_action(gconstpointer p1, gconstpointer p2)
1280 {
1281 const GntAction *a1 = p1;
1282 const GntAction *a2 = p2;
1283
1284 return g_utf8_collate(a1->label, a2->label);
1285 }
1286
1287 static void
1288 show_actions_list()
1289 {
1290 GntWidget *tree, *win;
1291 GList *iter;
1292 int h;
1293
1294 if (action_list)
1295 return;
1296
1297 setup__list();
1298 action_list = &_list;
1299 win = action_list->window;
1300 tree = action_list->tree;
1301
1302 gnt_box_set_title(GNT_BOX(win), "Available Actions");
1303 GNT_WIDGET_SET_FLAGS(tree, GNT_WIDGET_NO_BORDER);
1304 /* XXX: Do we really want this? */
1305 gnt_tree_set_compare_func(GNT_TREE(tree), compare_action);
1306
1307 for (iter = actions; iter; iter = iter->next) {
1308 GntAction *action = iter->data;
1309 gnt_tree_add_row_last(GNT_TREE(tree), action,
1310 gnt_tree_create_row(GNT_TREE(tree), action->label), NULL);
1311 }
1312 g_signal_connect(G_OBJECT(tree), "activate", G_CALLBACK(action_list_activate), NULL);
1313 gnt_widget_set_size(tree, 0, g_list_length(actions));
1314 gnt_widget_get_size(win, NULL, &h);
1315 gnt_widget_set_position(win, 0, getmaxy(stdscr) - 1 - h);
1316
1317 lock_focus_list = 1;
1318 gnt_widget_show(win);
1319 lock_focus_list = 0;
1320 }
1321