annotate console/gntrequest.c @ 13983:b7a99d54a5a9

[gaim-migrate @ 16552] Add a debug window. The scrolling doesn't seem to work properly. I will try to figure out what's wrong with it. Start the request-ui. The ui for request input, choice and action are mostly done. I am not handling multiline input requests yet. It's not too high in my todo-list either. committer: Tailor Script <tailor@pidgin.im>
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Sun, 23 Jul 2006 20:38:07 +0000
parents
children 19a1812e6c46
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
13983
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
1 #include <gnt.h>
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
2 #include <gntbox.h>
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
3 #include <gntbutton.h>
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
4 #include <gntcombobox.h>
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
5 #include <gntentry.h>
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
6 #include <gntlabel.h>
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
7
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
8 #include "gntrequest.h"
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
9
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
10 static GntWidget *
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
11 setup_request_window(const char *title, const char *primary,
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
12 const char *secondary)
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
13 {
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
14 GntWidget *window;
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
15
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
16 window = gnt_vbox_new(FALSE);
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
17 gnt_box_set_toplevel(GNT_BOX(window), TRUE);
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
18 gnt_box_set_title(GNT_BOX(window), title);
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
19 gnt_box_set_alignment(GNT_BOX(window), GNT_ALIGN_MID);
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
20
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
21 if (primary)
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
22 gnt_box_add_widget(GNT_BOX(window),
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
23 gnt_label_new_with_format(primary, GNT_TEXT_FLAG_BOLD));
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
24 if (secondary)
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
25 gnt_box_add_widget(GNT_BOX(window), gnt_label_new(secondary));
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
26
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
27 return window;
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
28 }
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
29
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
30 static GntWidget *
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
31 setup_button_box(gpointer userdata, gpointer cb, gpointer data, ...)
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
32 {
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
33 GntWidget *box, *button;
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
34 va_list list;
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
35 const char *text;
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
36 gpointer callback;
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
37
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
38 box = gnt_hbox_new(TRUE);
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
39
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
40 va_start(list, data);
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
41
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
42 while ((text = va_arg(list, const char *)))
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
43 {
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
44 callback = va_arg(list, gpointer);
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
45 button = gnt_button_new(text);
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
46 gnt_box_add_widget(GNT_BOX(box), button);
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
47 g_object_set_data(G_OBJECT(button), "activate-callback", callback);
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
48 g_object_set_data(G_OBJECT(button), "activate-userdata", userdata);
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
49 g_signal_connect(G_OBJECT(button), "activate", G_CALLBACK(cb), data);
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
50 }
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
51
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
52 va_end(list);
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
53 return box;
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
54 }
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
55
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
56 static void
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
57 notify_input_cb(GntWidget *button, GntWidget *entry)
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
58 {
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
59 GaimRequestInputCb callback = g_object_get_data(G_OBJECT(button), "activate-callback");
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
60 gpointer data = g_object_get_data(G_OBJECT(button), "activate-userdata");
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
61 const char *text = gnt_entry_get_text(GNT_ENTRY(entry));
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
62
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
63 if (callback)
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
64 callback(data, text);
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
65
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
66 while (button->parent)
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
67 button = button->parent;
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
68
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
69 gaim_request_close(GAIM_REQUEST_INPUT, button);
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
70 }
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
71
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
72 static void *
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
73 gg_request_input(const char *title, const char *primary,
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
74 const char *secondary, const char *default_value,
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
75 gboolean multiline, gboolean masked, gchar *hint,
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
76 const char *ok_text, GCallback ok_cb,
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
77 const char *cancel_text, GCallback cancel_cb,
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
78 void *user_data)
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
79 {
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
80 GntWidget *window, *box, *entry;
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
81
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
82 window = setup_request_window(title, primary, secondary);
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
83
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
84 entry = gnt_entry_new(default_value);
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
85 if (masked)
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
86 gnt_entry_set_masked(GNT_ENTRY(entry), TRUE);
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
87 gnt_box_add_widget(GNT_BOX(window), entry);
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
88
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
89 box = setup_button_box(user_data, notify_input_cb, entry,
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
90 ok_text, ok_cb, cancel_text, cancel_cb, NULL);
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
91 gnt_box_add_widget(GNT_BOX(window), box);
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
92
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
93 gnt_widget_show(window);
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
94
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
95 return window;
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
96 }
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
97
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
98 static void
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
99 gg_close_request(GaimRequestType type, gpointer ui_handle)
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
100 {
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
101 GntWidget *widget = GNT_WIDGET(ui_handle);
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
102 while (widget->parent)
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
103 widget = widget->parent;
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
104 gnt_widget_destroy(widget);
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
105 }
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
106
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
107 static void
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
108 request_choice_cb(GntWidget *button, GntComboBox *combo)
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
109 {
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
110 GaimRequestChoiceCb callback = g_object_get_data(G_OBJECT(button), "activate-callback");
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
111 gpointer data = g_object_get_data(G_OBJECT(button), "activate-userdata");
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
112 int choice = GPOINTER_TO_INT(gnt_combo_box_get_selected_data(GNT_COMBO_BOX(combo))) - 1;
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
113
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
114 if (callback)
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
115 callback(data, choice);
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
116
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
117 while (button->parent)
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
118 button = button->parent;
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
119
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
120 gaim_request_close(GAIM_REQUEST_INPUT, button);
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
121 }
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
122
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
123 static void *
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
124 gg_request_choice(const char *title, const char *primary,
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
125 const char *secondary, unsigned int default_value,
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
126 const char *ok_text, GCallback ok_cb,
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
127 const char *cancel_text, GCallback cancel_cb,
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
128 void *user_data, va_list choices)
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
129 {
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
130 GntWidget *window, *combo, *box;
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
131 const char *text;
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
132 int val;
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
133
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
134 window = setup_request_window(title, primary, secondary);
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
135
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
136 combo = gnt_combo_box_new();
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
137 gnt_box_add_widget(GNT_BOX(window), combo);
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
138 while ((text = va_arg(choices, const char *)))
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
139 {
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
140 val = va_arg(choices, int);
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
141 gnt_combo_box_add_data(GNT_COMBO_BOX(combo), GINT_TO_POINTER(val + 1), text);
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
142 }
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
143 gnt_combo_box_set_selected(GNT_COMBO_BOX(combo), GINT_TO_POINTER(default_value + 1));
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
144
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
145 box = setup_button_box(user_data, request_choice_cb, combo,
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
146 ok_text, ok_cb, cancel_text, cancel_cb, NULL);
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
147 gnt_box_add_widget(GNT_BOX(window), box);
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
148
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
149 gnt_widget_show(window);
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
150
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
151 return window;
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
152 }
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
153
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
154 static void
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
155 request_action_cb(GntWidget *button, GntWidget *window)
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
156 {
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
157 GaimRequestActionCb callback = g_object_get_data(G_OBJECT(button), "activate-callback");
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
158 gpointer data = g_object_get_data(G_OBJECT(button), "activate-userdata");
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
159 int id = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(button), "activate-id"));
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
160
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
161 callback(data, id);
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
162
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
163 gaim_request_close(GAIM_REQUEST_ACTION, window);
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
164 }
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
165
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
166 static void*
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
167 gg_request_action(const char *title, const char *primary,
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
168 const char *secondary, unsigned int default_value,
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
169 void *user_data, size_t actioncount,
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
170 va_list actions)
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
171 {
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
172 GntWidget *window, *box, *button;
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
173 int i;
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
174
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
175 window = setup_request_window(title, primary, secondary);
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
176
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
177 box = gnt_hbox_new(TRUE);
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
178 gnt_box_add_widget(GNT_BOX(window), box);
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
179 for (i = 0; i < actioncount; i++)
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
180 {
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
181 const char *text = va_arg(actions, const char *);
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
182 GaimRequestActionCb callback = va_arg(actions, GaimRequestActionCb);
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
183
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
184 button = gnt_button_new(text);
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
185 gnt_box_add_widget(GNT_BOX(box), button);
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
186
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
187 g_object_set_data(G_OBJECT(button), "activate-callback", callback);
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
188 g_object_set_data(G_OBJECT(button), "activate-userdata", user_data);
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
189 g_object_set_data(G_OBJECT(button), "activate-id", GINT_TO_POINTER(i));
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
190 g_signal_connect(G_OBJECT(button), "activate", G_CALLBACK(request_action_cb), window);
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
191 }
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
192
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
193 gnt_widget_show(window);
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
194
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
195 return window;
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
196 }
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
197
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
198 static GaimRequestUiOps uiops =
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
199 {
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
200 .request_input = gg_request_input,
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
201 .close_request = gg_close_request,
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
202 .request_choice = gg_request_choice,
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
203 .request_action = gg_request_action,
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
204 };
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
205
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
206 GaimRequestUiOps *gg_request_get_ui_ops()
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
207 {
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
208 return &uiops;
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
209 }
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
210
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
211 void gg_request_init()
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
212 {
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
213 }
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
214
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
215 void gg_request_uninit()
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
216 {
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
217 }
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
218