~ubuntu-branches/debian/jessie/gman/jessie

« back to all changes in this revision

Viewing changes to .pc/pre-0.9.3-5.1.patch/menu.c

  • Committer: Package Import Robot
  • Author(s): Osamu Aoki
  • Date: 2012-01-04 00:48:23 UTC
  • Revision ID: package-import@ubuntu.com-20120104004823-wbo6r3f2eslbt1ln
Tags: 0.9.3-5.2
* Non-maintainer upload.
* Switched from mozilla to sensible-browser.
* Added evince as choice since this is gnome/GTK+ app.
* Updated manpath default values to current situation.
* Updated policy version, used 3.0 (quilt) format, and
  made some lintian touch-ups.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/********************** modified from t2.c *******************/
 
2
/********************* menu.c ********************************/
 
3
 
 
4
#include <stdio.h>
 
5
#include <string.h>
 
6
#include <strings.h>
 
7
#include <sys/types.h>
 
8
#ifdef SYS_DIR
 
9
#include <sys_dir.h>
 
10
#else
 
11
#ifdef NDIR
 
12
#include <ndir.h>
 
13
#else
 
14
#include <dirent.h>
 
15
#endif
 
16
#endif
 
17
 
 
18
#include <sys/stat.h>
 
19
#include <unistd.h>
 
20
#include <errno.h>
 
21
 
 
22
#include <stdlib.h>
 
23
 
 
24
#include <gtk/gtk.h>
 
25
 
 
26
#include <libintl.h>
 
27
 
 
28
#include "mandata.h"
 
29
#include "util.h"
 
30
#include "gman.h"
 
31
#include "list.h"
 
32
#include "task.h"
 
33
#include "window2.h"
 
34
#include "taskfunc.h"
 
35
 
 
36
static int print_hello(GtkWidget *w, gpointer data);
 
37
static int test_callback(GtkWidget *w, gpointer data);
 
38
static int window_resize_callback(GtkWidget *w, GtkAllocation *size, gpointer data);
 
39
static int section_policy_callback(GtkWidget *w, gpointer data);
 
40
static int section_select_callback(GtkWidget *w, gpointer data);
 
41
static int status_bar_callback (GtkWidget *widget, gpointer   data);
 
42
static int search_mode_callback (GtkWidget *widget, gpointer   data);
 
43
static int show_mode_callback(GtkWidget *w, gpointer data);
 
44
static void app_quit(GtkWidget *w, gpointer data);
 
45
static void select_row_callback(GtkWidget *, gint, gint, GdkEventButton *, gpointer);
 
46
static void select_row_callback3(GtkWidget *, gint, gint, GdkEventButton *, gpointer);
 
47
static void entry_activate_callback(GtkWidget *,gpointer);
 
48
static void entry_changed_callback(GtkWidget *,gpointer);
 
49
static void window_help_about_callback (GtkWidget *widget, gpointer   data);
 
50
static void entry4_activate_callback(GtkWidget *,gpointer);
 
51
static void entry4_changed_callback(GtkWidget *,gpointer);
 
52
static int button_clicked_callback(GtkWidget *,gpointer);
 
53
 
 
54
#define MAX_PATHS 10
 
55
 
 
56
#define MENU_DISPLAY_POSITION 201
 
57
#define MENU_NEXT_POSITION 202
 
58
 
 
59
#define _(string) gettext(string)
 
60
 
 
61
static GtkItemFactoryEntry menu_items[] = {
 
62
  {"/_File",         NULL,         NULL, 0, "<Branch>"},
 
63
  {"/File/_Quit",     "<control>Q", (void (*)(...))app_quit, 0, NULL},
 
64
  {"/_Sections",                 NULL,         NULL, 0, "<Branch>"},
 
65
  {"/Sections/tearoff1", NULL,      NULL,       0, "<Tearoff>" },
 
66
  {"/Sections/_All",    NULL,                   (void (*)(...))section_policy_callback, 0, "<RadioItem>"},
 
67
  {"/Sections/all _But",   NULL,                (void (*)(...))section_policy_callback, 1, "/Sections/All"},
 
68
  {"/Sections/_Only",   NULL,                   (void (*)(...))section_policy_callback, 2, "/Sections/All"},
 
69
  {"/Sections/sep1",    NULL,                   NULL,           0,                      "<Separator>"},
 
70
  {"/Sections/_1: User Commands",       NULL,   (void (*)(...))section_select_callback, 1<<0,   "<CheckItem>"},
 
71
  {"/Sections/_2: System Calls",        NULL,   (void (*)(...))section_select_callback, 1<<1,   "<CheckItem>"},
 
72
  {"/Sections/_3: Subroutines",         NULL,   (void (*)(...))section_select_callback, 1<<2,   "<CheckItem>"},
 
73
  {"/Sections/_4: Devices",                     NULL,   (void (*)(...))section_select_callback, 1<<3,   "<CheckItem>"},
 
74
  {"/Sections/_5: File Formats",        NULL,   (void (*)(...))section_select_callback, 1<<4,   "<CheckItem>"},
 
75
  {"/Sections/_6: Games",                       NULL,   (void (*)(...))section_select_callback, 1<<5,   "<CheckItem>"},
 
76
  {"/Sections/_7: Miscellaneous",       NULL,   (void (*)(...))section_select_callback, 1<<6,   "<CheckItem>"},
 
77
  {"/Sections/_8: Sys.Administration",NULL,     (void (*)(...))section_select_callback, 1<<7,   "<CheckItem>"},
 
78
  {"/Sections/_l: Local",                       NULL,   (void (*)(...))section_select_callback, 1<<8,   "<CheckItem>"},
 
79
  {"/Sections/_n: New",                         NULL,   (void (*)(...))section_select_callback, 1<<9,   "<CheckItem>"},
 
80
  {"/_View",      NULL,         NULL, 0, "<Branch>"},
 
81
  {"/View/x_Term",              "<control>T",   (void (*)(...))show_mode_callback, 0,   "<RadioItem>"},
 
82
  {"/View/_GhostView",          "<control>G",   (void (*)(...))show_mode_callback, 1,   "/View/xTerm"},
 
83
  {"/View/_LocalBrowse",                "<control>L",   (void (*)(...))show_mode_callback, 2,   "/View/xTerm"},
 
84
  {"/View/_NetBrowse",          "<control>N",   (void (*)(...))show_mode_callback, 3,   "/View/xTerm"},
 
85
  {"/_Options",      NULL,         NULL, 0, "<Branch>"},
 
86
  {"/Options/Status bar",               NULL,   (void (*)(...))status_bar_callback, 0,  "<CheckItem>"},
 
87
  {"/Options/sep1",     NULL,         NULL, 0, "<Separator>"},
 
88
  {"/Options/_Index search",    "<control>I",   (void (*)(...))search_mode_callback, 0, "<RadioItem>"},
 
89
  {"/Options/_Key word search",   "<control>K", (void (*)(...))search_mode_callback, 1, "/Options/Index search"},
 
90
  {"/Options/sep2",     NULL,         NULL, 0, "<Separator>"},
 
91
  {"/Options/Man _Paths...",    NULL,   (void (*)(...))edit_paths_callback, 0, NULL},
 
92
  //  {"/Options/Test",  NULL,         (void (*)(...))test_callback, 0, NULL},
 
93
  {"/_Help",         NULL,         NULL, 0, "<LastBranch>"},
 
94
  {"/_Help/About",   NULL,         GTK_SIGNAL_FUNC(window_help_about_callback),0,NULL}
 
95
};
 
96
 
 
97
/********************* init_main_window *************************/
 
98
 
 
99
GtkWidget * clist;
 
100
GtkWidget * entry;
 
101
GtkWidget * clist3;
 
102
GtkWidget * window;             //main window
 
103
GtkTooltips * tooltips;
 
104
 
 
105
GtkWidget * section_buttons[MAX_MAN_SECTION];
 
106
GtkWidget * section_select[3];
 
107
GtkWidget * searching_mode_buttons[2];
 
108
GtkWidget * show_mode_buttons[4];
 
109
GtkWidget * status_bar_button;
 
110
 
 
111
int signal_select_row;  //used by select_row_callback() to decide whether to active man pages
 
112
int signal_entry_change; //used by entry_changed_callback() to decide whether to refresh list
 
113
int signal_menu_change; //used by menu_item callback to decide whether to take action or not
 
114
Dictionary * man_paths;
 
115
char * *man_items_buffer;
 
116
int man_items_count;
 
117
int clist_selected_row;
 
118
List * man_paths_to_be_load;
 
119
char * keyword;
 
120
 
 
121
void updata_menu_buttons(int);
 
122
 
 
123
void get_main_menu(GtkWidget *window, GtkWidget ** menubar) {
 
124
        int nmenu_items = sizeof(menu_items) / sizeof(menu_items[0]);
 
125
        GtkItemFactory *item_factory;
 
126
        GtkAccelGroup *accel_group;
 
127
 
 
128
        accel_group = gtk_accel_group_new();
 
129
 
 
130
        /* This function initializes the item factory.
 
131
           Param 1: The type of menu - can be GTK_TYPE_MENU_BAR, GTK_TYPE_MENU,
 
132
                    or GTK_TYPE_OPTION_MENU.
 
133
                Param 2: The path of the menu.
 
134
                Param 3: A pointer to a gtk_accel_group.  The item factory sets up
 
135
              the accelerator table while generating menus.
 
136
        */
 
137
 
 
138
        item_factory = gtk_item_factory_new(GTK_TYPE_MENU_BAR, "<main>", 
 
139
                                                                                accel_group);
 
140
 
 
141
  /* This function generates the menu items. Pass the item factory,
 
142
     the number of items in the array, the array itself, and any
 
143
     callback data for the the menu items. */
 
144
        gtk_item_factory_create_items(item_factory, nmenu_items, menu_items, NULL);
 
145
 
 
146
  /* Attach the new accelerator group to the window. */
 
147
        gtk_accel_group_attach (accel_group, GTK_OBJECT (window));
 
148
 
 
149
        if (menubar)
 
150
        /* Finally, return the actual menu bar created by the item factory. */ 
 
151
                *menubar = gtk_item_factory_get_widget(item_factory, "<main>");
 
152
        section_select[0] = gtk_item_factory_get_widget(item_factory, "/Sections/All");
 
153
        section_select[1] = gtk_item_factory_get_widget(item_factory, "/Sections/all But");
 
154
        section_select[2] = gtk_item_factory_get_widget(item_factory, "/Sections/Only");
 
155
        section_buttons[0] = gtk_item_factory_get_widget(item_factory, "/Sections/1: User Commands");
 
156
        section_buttons[1] = gtk_item_factory_get_widget(item_factory, "/Sections/2: System Calls");
 
157
        section_buttons[2] = gtk_item_factory_get_widget(item_factory, "/Sections/3: Subroutines");
 
158
        section_buttons[3] = gtk_item_factory_get_widget(item_factory, "/Sections/4: Devices");
 
159
        section_buttons[4] = gtk_item_factory_get_widget(item_factory, "/Sections/5: File Formats");
 
160
        section_buttons[5] = gtk_item_factory_get_widget(item_factory, "/Sections/6: Games");
 
161
        section_buttons[6] = gtk_item_factory_get_widget(item_factory, "/Sections/7: Miscellaneous");
 
162
        section_buttons[7] = gtk_item_factory_get_widget(item_factory, "/Sections/8: Sys.Administration");
 
163
        section_buttons[8] = gtk_item_factory_get_widget(item_factory, "/Sections/l: Local");
 
164
        section_buttons[9] = gtk_item_factory_get_widget(item_factory, "/Sections/n: New");
 
165
        searching_mode_buttons[0] = gtk_item_factory_get_widget(item_factory, "/Options/Index search");
 
166
        searching_mode_buttons[1] = gtk_item_factory_get_widget(item_factory, "/Options/Key word search");
 
167
        show_mode_buttons[0] = gtk_item_factory_get_widget(item_factory, "/View/xTerm");
 
168
        show_mode_buttons[1] = gtk_item_factory_get_widget(item_factory, "/View/GhostView");
 
169
        show_mode_buttons[2] = gtk_item_factory_get_widget(item_factory, "/View/LocalBrowse");
 
170
        show_mode_buttons[3] = gtk_item_factory_get_widget(item_factory, "/View/NetBrowse");
 
171
        status_bar_button = gtk_item_factory_get_widget(item_factory, "/Options/Status bar");
 
172
        //  gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(section_buttons[4]),1);
 
173
        updata_menu_buttons(0);
 
174
}
 
175
 
 
176
/*flag = 0 means not to invoke call backs when changing the states of buttons.*/
 
177
void updata_menu_buttons(int flag) 
 
178
{
 
179
        int i,j,k,k2;
 
180
        k = (int)context->get_value("display_section_policy");
 
181
        if(k>0 && k<=2)
 
182
                if(!((GtkCheckMenuItem*)(section_select[k]))->active){
 
183
                        if(!flag) signal_menu_change++;
 
184
                        gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(section_select[k]),1);
 
185
                }
 
186
        k = (int)context->get_value("display_section");
 
187
        for (i = 0;i<10;i++)
 
188
                if(!(k&(1<<i)) != !(((GtkCheckMenuItem*)(section_buttons[i]))->active)) {
 
189
                        if(!flag) signal_menu_change++;
 
190
                        gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(section_buttons[i]),k&(1<<i));
 
191
                }
 
192
        k = (int)context->get_value("searching_mode");
 
193
        if(k>0 && k<=1)
 
194
                if(!(((GtkCheckMenuItem*)(searching_mode_buttons[k]))->active)) {
 
195
                        if(!flag) signal_menu_change++;
 
196
                        gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(searching_mode_buttons[k]),1);
 
197
                }
 
198
        k = (int)context->get_value("show_mode");
 
199
        if(k>0 && k<=3)
 
200
                if(!(((GtkCheckMenuItem*)(show_mode_buttons[k]))->active)) {
 
201
                        if(!flag) signal_menu_change++;
 
202
                        gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(show_mode_buttons[k]),1);
 
203
                }
 
204
        k2 = (int)context->get_value("show_status_bar");
 
205
        i = k2&(1<<k);
 
206
        j = (((GtkCheckMenuItem*)(status_bar_button))->active);
 
207
        if((i&&!j) || (!i&&j)) {
 
208
                if(!flag) signal_menu_change++;
 
209
                gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(status_bar_button),i);
 
210
        }
 
211
        gtk_widget_hide(status_bar_button);
 
212
}
 
213
 
 
214
static  GtkWidget *index_search_vbox;
 
215
static  GtkWidget *keyword_search_vbox;
 
216
static  GtkWidget *hbox4;
 
217
static  GtkWidget *hbox_status;
 
218
static  GtkWidget *entry4;
 
219
GtkWidget *search_button;
 
220
GtkWidget *stop_button;
 
221
static  GtkWidget *statusbar1;
 
222
static  GtkWidget *statusbar2;
 
223
 
 
224
static void updata_widget_show(int flag)
 
225
{       
 
226
        int k,k2;
 
227
        
 
228
        k = (int)context->get_value("searching_mode");
 
229
        k2 = (int)context->get_value("show_status_bar");
 
230
 
 
231
        if(k2&(1<<k)) 
 
232
                gtk_widget_show(hbox_status);
 
233
        else
 
234
                gtk_widget_hide(hbox_status);
 
235
        gtk_widget_hide(!k?keyword_search_vbox:index_search_vbox);
 
236
        gtk_widget_show(k?keyword_search_vbox:index_search_vbox);
 
237
        if(k2 & (1<<k)) gtk_widget_show (hbox_status);
 
238
}
 
239
 
 
240
 
 
241
void init_main_window(GtkWidget * window)
 
242
{
 
243
        GtkWidget *     main_vbox;
 
244
        GtkWidget *     menubar;
 
245
        GtkWidget *     swindow;
 
246
        GtkWidget *     swindow2;
 
247
        GtkWidget * focus;
 
248
 
 
249
        int k,k2;
 
250
 
 
251
        ::window = window;
 
252
        gchar *titles[2] = { "Name", "Section" };
 
253
        gchar *titles2[3] = { "Name", "Section", "Description"};
 
254
        signal_select_row = 0;
 
255
        signal_entry_change = 0;
 
256
        
 
257
        tooltips = gtk_tooltips_new();
 
258
 
 
259
        gtk_signal_connect(GTK_OBJECT(window), "destroy", 
 
260
                                           GTK_SIGNAL_FUNC(app_quit), 
 
261
                                           0);
 
262
 
 
263
        gtk_window_set_title(GTK_WINDOW(window), "G-man");
 
264
        gtk_window_set_policy( GTK_WINDOW( window ), FALSE, TRUE, FALSE );
 
265
        gtk_window_set_default_size(GTK_WINDOW(window),
 
266
                                                                (int)context->get_value("h_size"),
 
267
                                                                (int)context->get_value("v_size"));
 
268
        
 
269
        gtk_widget_set_usize(GTK_WIDGET(window),200,150);
 
270
        main_vbox = gtk_vbox_new(FALSE, 1);
 
271
        gtk_container_border_width(GTK_CONTAINER(main_vbox), 1);
 
272
        gtk_container_add(GTK_CONTAINER(window), main_vbox);
 
273
        gtk_widget_show(main_vbox);
 
274
 
 
275
        get_main_menu(window, &menubar);
 
276
        gtk_box_pack_start(GTK_BOX(main_vbox), menubar, FALSE, TRUE, 0);
 
277
        gtk_widget_show(menubar);
 
278
 
 
279
        gtk_signal_connect(GTK_OBJECT(window),"size_allocate",GTK_SIGNAL_FUNC(window_resize_callback),NULL);
 
280
 
 
281
        //keyword_search_vbox
 
282
        keyword_search_vbox = gtk_vbox_new(FALSE,1);
 
283
        gtk_box_pack_start(GTK_BOX(main_vbox), keyword_search_vbox, TRUE, TRUE, 0);
 
284
        
 
285
        hbox4 = gtk_hbox_new (FALSE, 1);
 
286
        gtk_object_set_data (GTK_OBJECT (window), "hbox4", hbox4);
 
287
        gtk_box_pack_start (GTK_BOX (keyword_search_vbox), hbox4, FALSE, TRUE, 0);
 
288
        gtk_widget_show (hbox4);
 
289
 
 
290
        stop_button = gtk_button_new_with_label ("Stop");
 
291
        gtk_object_set_data (GTK_OBJECT (window), "stop_button", stop_button);
 
292
        gtk_widget_set_sensitive(stop_button,0);
 
293
        gtk_signal_connect (GTK_OBJECT(stop_button),"clicked",(GtkSignalFunc)button_clicked_callback,(void*)1);
 
294
        gtk_widget_show (stop_button);
 
295
        gtk_box_pack_start (GTK_BOX (hbox4), stop_button, FALSE, TRUE, 0);
 
296
        gtk_widget_set_usize (stop_button, 40, -2);
 
297
        
 
298
        entry4 = gtk_entry_new ();
 
299
        gtk_object_set_data (GTK_OBJECT (window), "entry4", entry4);
 
300
        gtk_widget_show (entry4);
 
301
        gtk_tooltips_set_tip (tooltips, entry4, "Key word search", NULL);
 
302
        gtk_box_pack_start (GTK_BOX (hbox4), entry4, TRUE, TRUE, 0);
 
303
    gtk_signal_connect(GTK_OBJECT(entry4), "activate",
 
304
                       GTK_SIGNAL_FUNC(entry4_activate_callback),NULL);
 
305
    gtk_signal_connect(GTK_OBJECT(entry4), "changed",
 
306
                       GTK_SIGNAL_FUNC(entry4_changed_callback),NULL);
 
307
        
 
308
        search_button = gtk_button_new_with_label ("Search");
 
309
        gtk_object_set_data (GTK_OBJECT (window), "search_button", search_button);
 
310
        gtk_widget_set_sensitive(search_button,0);
 
311
        gtk_signal_connect (GTK_OBJECT(stop_button),"clicked",(GtkSignalFunc)button_clicked_callback,(void*)2);
 
312
        gtk_widget_show (search_button);
 
313
        gtk_box_pack_start (GTK_BOX (hbox4), search_button, FALSE, TRUE, 0);
 
314
        gtk_widget_set_usize (search_button, 60, -2);
 
315
 
 
316
        
 
317
    clist3 = gtk_clist_new_with_titles( 3, titles2);
 
318
        swindow2 = gtk_scrolled_window_new (NULL, NULL);
 
319
        gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (swindow2),
 
320
                                        GTK_POLICY_AUTOMATIC,
 
321
                                        GTK_POLICY_AUTOMATIC);
 
322
 
 
323
        
 
324
        gtk_clist_set_column_width(GTK_CLIST(clist3),0,100);
 
325
        gtk_clist_set_selection_mode(GTK_CLIST(clist3),GTK_SELECTION_SINGLE);
 
326
        gtk_clist_column_titles_passive(GTK_CLIST(clist3));
 
327
        gtk_clist_set_column_auto_resize (GTK_CLIST(clist3),2,1);
 
328
 
 
329
        gtk_container_add (GTK_CONTAINER (swindow2), clist3);
 
330
        gtk_box_pack_start (GTK_BOX (keyword_search_vbox), swindow2, TRUE, TRUE, 0);
 
331
        gtk_widget_show_all(GTK_WIDGET(swindow2));
 
332
 
 
333
        gtk_signal_connect(GTK_OBJECT(clist3),"select_row",
 
334
                                           GTK_SIGNAL_FUNC(select_row_callback3),NULL);
 
335
        
 
336
        //index_search_vbox
 
337
        index_search_vbox = gtk_vbox_new(FALSE,1);
 
338
        gtk_box_pack_start(GTK_BOX(main_vbox), index_search_vbox, TRUE, TRUE, 0);
 
339
    entry = gtk_entry_new_with_max_length (50);
 
340
    clist = gtk_clist_new_with_titles( 2, titles);
 
341
    gtk_signal_connect(GTK_OBJECT(entry), "activate",
 
342
                       GTK_SIGNAL_FUNC(entry_activate_callback),
 
343
                       (gpointer)clist);
 
344
    gtk_signal_connect(GTK_OBJECT(entry), "changed",
 
345
                       GTK_SIGNAL_FUNC(entry_changed_callback),
 
346
                       (gpointer)clist);
 
347
    gtk_box_pack_start (GTK_BOX (index_search_vbox), entry, FALSE, TRUE, 0);
 
348
        gtk_tooltips_set_tip (tooltips, entry, "index search", NULL);
 
349
        gtk_widget_show(entry);
 
350
 
 
351
        swindow = gtk_scrolled_window_new (NULL, NULL);
 
352
        gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (swindow),
 
353
                                        GTK_POLICY_AUTOMATIC,
 
354
                                        GTK_POLICY_AUTOMATIC);
 
355
 
 
356
 
 
357
        gtk_clist_set_column_width(GTK_CLIST(clist),0,200);
 
358
        gtk_clist_set_selection_mode(GTK_CLIST(clist),GTK_SELECTION_SINGLE);
 
359
        gtk_clist_column_titles_passive(GTK_CLIST(clist));
 
360
        gtk_container_add (GTK_CONTAINER (swindow), clist);
 
361
        gtk_box_pack_start (GTK_BOX (index_search_vbox), swindow, TRUE, TRUE, 0);
 
362
 
 
363
        gtk_signal_connect(GTK_OBJECT(clist),"select_row",
 
364
                                           GTK_SIGNAL_FUNC(select_row_callback),NULL);
 
365
 
 
366
        focus = entry;
 
367
        gtk_widget_grab_focus (focus);
 
368
        gtk_widget_show_all (swindow);
 
369
 
 
370
        hbox_status = gtk_hbox_new (FALSE, 0);
 
371
        gtk_object_set_data (GTK_OBJECT (window), "hbox_status", hbox_status);
 
372
        gtk_box_pack_start (GTK_BOX (main_vbox), hbox_status, FALSE, TRUE, 0);
 
373
 
 
374
        updata_widget_show(0);
 
375
 
 
376
        statusbar1 = gtk_statusbar_new ();
 
377
        gtk_object_set_data (GTK_OBJECT (window), "statusbar1", statusbar1);
 
378
        gtk_widget_show (statusbar1);
 
379
        gtk_box_pack_start (GTK_BOX (hbox_status), statusbar1, TRUE, TRUE, 0);
 
380
 
 
381
        statusbar2 = gtk_statusbar_new ();
 
382
        gtk_object_set_data (GTK_OBJECT (window), "statusbar2", statusbar2);
 
383
        gtk_widget_show (statusbar2);
 
384
        gtk_box_pack_start (GTK_BOX (hbox_status), statusbar2, FALSE, TRUE, 0);
 
385
}
 
386
 
 
387
 
 
388
/******************* tools functions ******************/
 
389
int search_array_for_text(char ** array, int count, char * text)
 
390
{
 
391
        int i;
 
392
        for (i=0;i<count && strcmp(text,array[i])>0 ;i++);
 
393
        return (i >= count)? i-1:i;
 
394
}
 
395
 
 
396
/******************* call backs ***********************/
 
397
void select_row_callback(GtkWidget *widget,
 
398
                                                 gint row,
 
399
                                                 gint column,
 
400
                                                 GdkEventButton *event,
 
401
                                                 gpointer data)
 
402
{
 
403
        ManItem * item;
 
404
        if(signal_select_row>0) {signal_select_row--;return;}
 
405
        item = (ManItem*) gtk_clist_get_row_data(GTK_CLIST(widget),row);
 
406
        item->active_man_page();
 
407
        signal_entry_change++;
 
408
        gtk_entry_set_text(GTK_ENTRY(entry),man_items_buffer[row]);
 
409
}
 
410
void select_row_callback3(GtkWidget *widget,
 
411
                                                 gint row,
 
412
                                                 gint column,
 
413
                                                 GdkEventButton *event,
 
414
                                                 gpointer data)
 
415
{
 
416
        ManItem * item;
 
417
        if(signal_select_row>0) {signal_select_row--;return;}
 
418
        item = (ManItem*) gtk_clist_get_row_data(GTK_CLIST(widget),row);
 
419
        if(item) item->active_man_page();
 
420
}
 
421
void entry_activate_callback(GtkWidget * w,gpointer data)
 
422
{
 
423
        int i;
 
424
        GtkWidget * clist = (GtkWidget *)data;
 
425
        i = search_array_for_text(man_items_buffer, 
 
426
                                                          man_items_count, 
 
427
                                                          gtk_entry_get_text(GTK_ENTRY(w)));
 
428
        if (i == -1) return;
 
429
        gtk_clist_moveto(GTK_CLIST(clist),i,0,0.1,0.0);
 
430
        GTK_CLIST(clist)->focus_row = i;
 
431
        gtk_clist_select_row(GTK_CLIST(clist),i,0);
 
432
}
 
433
        
 
434
void entry_changed_callback(GtkWidget * w,gpointer data)
 
435
{
 
436
        int i;
 
437
        GtkWidget * clist = (GtkWidget *)data;
 
438
        if(signal_entry_change>0) {signal_entry_change--;return;}
 
439
        i = search_array_for_text(man_items_buffer, 
 
440
                                                          man_items_count, 
 
441
                                                          gtk_entry_get_text(GTK_ENTRY(w)));
 
442
        if (i == -1) return;
 
443
        signal_select_row++;
 
444
        gtk_clist_moveto(GTK_CLIST(clist),i,0,0.1,0.0);
 
445
        GTK_CLIST(clist)->focus_row = i;
 
446
        gtk_clist_select_row(GTK_CLIST(clist),i,0);
 
447
}
 
448
 
 
449
static int print_hello(GtkWidget *w, gpointer data) {
 
450
        if(signal_menu_change>0) {signal_menu_change--;return 1;}
 
451
        g_message("Hello, World! %x\n",data);
 
452
        return 0;
 
453
}
 
454
 
 
455
static int print_page(GtkWidget *w, gpointer data) {
 
456
        if(signal_menu_change>0) {signal_menu_change--;return 1;}
 
457
        g_message("Hello, World! %x\n",data);
 
458
        return 0;
 
459
}
 
460
 
 
461
static int test_callback(GtkWidget *w, gpointer data) {
 
462
        int i,j;
 
463
        if(signal_menu_change>0) {signal_menu_change--;return 1;}
 
464
        j = man_paths->get_size();
 
465
        for(i = 0;i<j;i++)
 
466
                delete ((ManPath*)(man_paths->get_value(i)));
 
467
        delete (man_paths);
 
468
        init_man_data();
 
469
        return 0;
 
470
}
 
471
 
 
472
static int section_policy_callback(GtkWidget *w, gpointer data) {
 
473
        //      static int signal;
 
474
        int k,k2;
 
475
        k2 = (int) data;
 
476
        if(!((GtkCheckMenuItem*)(section_select[k2]))->active) return 1;
 
477
        //      g_message("Hello, World! %x\n signal = %d",data,signal_menu_change);
 
478
        if(signal_menu_change>0) {signal_menu_change--;return 1;}
 
479
        //if(!signal) {signal++;return 1;}
 
480
        //signal--;
 
481
        k = (int) context->get_value("display_section_policy");
 
482
        if(k == k2) return 1;
 
483
        pthread_mutex_lock(&context_lock);
 
484
        context->set_value("display_section_policy","int",(void*)k2);
 
485
        pthread_mutex_unlock(&context_lock);
 
486
        task_set_active(task_extract_man_data);
 
487
        task_set_active(task_add_data_to_clist);
 
488
}
 
489
 
 
490
static int section_select_callback(GtkWidget *w, gpointer data) {
 
491
        int var;
 
492
        if(signal_menu_change>0) {signal_menu_change--;return 1;}
 
493
 
 
494
        pthread_mutex_lock(&context_lock);
 
495
        var = (int)context->get_value("display_section");
 
496
        var ^= (int)data;
 
497
        context->set_value("display_section","int",(void*)var);
 
498
        if (context->get_value("display_section_policy")) {
 
499
                task_set_active(task_extract_man_data);
 
500
                task_set_active(task_add_data_to_clist);
 
501
        }
 
502
        pthread_mutex_unlock(&context_lock);
 
503
        //              g_message("Hello, World! %x\n",data);
 
504
}
 
505
 
 
506
static void app_quit(GtkWidget *w, gpointer data) {
 
507
  //    g_message("Bye, World! %x\n",data);
 
508
        char buffer[1024],*p;
 
509
        FILE * fd;
 
510
        int i,j;
 
511
        p = buffer;
 
512
        j = man_paths->get_size();
 
513
        for (i = 0;i<j;i++) {
 
514
                sprintf(p,i?":%s":"%s",man_paths->get_name(i));
 
515
                for(;*p;p++);
 
516
        }
 
517
        context->set_value("man_paths","char*",my_strdup(buffer));
 
518
        attach(buffer,getenv("HOME"),".gman");
 
519
        if((fd = fopen(buffer,"w"))) {
 
520
                context->save(fd,"automatically made by G-man");
 
521
                fclose(fd);
 
522
        }
 
523
        //      context->save(stdout,"automatically made by G-man");
 
524
        
 
525
        gtk_exit((int)data);
 
526
}
 
527
 
 
528
static int window_resize_callback(GtkWidget *w, GtkAllocation * size, gpointer data)
 
529
{
 
530
        /*
 
531
        g_message("x = %d, y = %d, width = %d, height = %d, data = %x\n",
 
532
        size->x,size->y,size->width,size->height,data); */
 
533
        context->set_value("h_size","int",(void*)size->width);
 
534
        context->set_value("v_size","int",(void*)size->height);
 
535
        return 0;
 
536
}
 
537
 
 
538
static void window_help_about_callback (GtkWidget *widget, gpointer   data)
 
539
{
 
540
        const gchar *authors[] = {"Xinkai Wang <aakwxk@hotmail.com>", NULL };
 
541
        static GtkWidget *about_window = NULL;
 
542
 
 
543
        if (!about_window)
 
544
        {
 
545
 
 
546
        GtkWidget *button;
 
547
        GdkFont *font;
 
548
 
 
549
        about_window = gtk_dialog_new ();
 
550
        gtk_window_set_position (GTK_WINDOW (about_window), GTK_WIN_POS_MOUSE);
 
551
        gtk_window_set_title (GTK_WINDOW (about_window), _("About gman"));
 
552
 
 
553
        gtk_signal_connect (GTK_OBJECT (about_window), "delete_event",
 
554
                  GTK_SIGNAL_FUNC (gtk_false), NULL);
 
555
        gtk_signal_connect (GTK_OBJECT (about_window), "destroy",
 
556
                  (GtkSignalFunc) gtk_widget_destroyed,
 
557
                  &about_window);
 
558
 
 
559
        button = gtk_button_new_with_label (_("Close"));
 
560
        gtk_widget_show (button);
 
561
        gtk_box_pack_start (GTK_BOX (GTK_DIALOG (about_window)->action_area),
 
562
                  button, TRUE, TRUE, 0);
 
563
        gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
 
564
                  (GtkSignalFunc) gtk_widget_destroy,
 
565
                  GTK_OBJECT (about_window));
 
566
 
 
567
        gtk_container_set_border_width (GTK_CONTAINER (GTK_DIALOG (about_window)->vbox), 5);
 
568
 
 
569
         /* TODO: we need a logo ;) */
 
570
 
 
571
        gtk_box_pack_start (GTK_BOX (GTK_DIALOG (about_window)->vbox),
 
572
                  gtk_label_new ("Gman - version " VERSION),
 
573
                  FALSE, FALSE, 5);
 
574
 
 
575
        gtk_box_pack_start (GTK_BOX (GTK_DIALOG (about_window)->vbox),
 
576
                  gtk_label_new ("Copyright (C) 1999 Xinkai Wang"),
 
577
                  FALSE, FALSE, 5);
 
578
 
 
579
        gtk_box_pack_start (GTK_BOX (GTK_DIALOG (about_window)->vbox),
 
580
                  gtk_label_new ("Comments and suggestions are extremely welcomed!"),
 
581
                  FALSE, FALSE, 5);
 
582
 
 
583
        gtk_box_pack_start (GTK_BOX (GTK_DIALOG (about_window)->vbox),
 
584
                  gtk_label_new ("Web: http://homex.coolconnect.com/user/xkwang/gman/"),
 
585
                  FALSE, FALSE, 5);
 
586
 
 
587
        if (!GTK_WIDGET_VISIBLE (about_window))
 
588
                  gtk_widget_show_all (about_window);
 
589
        else
 
590
                  gtk_widget_hide (about_window);
 
591
 
 
592
        }
 
593
}
 
594
 
 
595
static int status_bar_callback (GtkWidget *widget, gpointer   data)
 
596
{
 
597
        int k,k2;
 
598
        if(signal_menu_change>0) {signal_menu_change--;return 1;}
 
599
        k2 = (int) context->get_value("show_status_bar");
 
600
        k = (int) context->get_value("searching_mode");
 
601
        if(((GtkCheckMenuItem*)(status_bar_button))->active) k2 = k2 | (1<<k);
 
602
        else k2 = k2 & ~(1<<k);
 
603
        pthread_mutex_lock(&context_lock);
 
604
        context->set_value("show_status_bar","int",(void*)k2);
 
605
        pthread_mutex_unlock(&context_lock);
 
606
        updata_widget_show(0);
 
607
        return 0;
 
608
}
 
609
 
 
610
static int search_mode_callback (GtkWidget *widget, gpointer   data)
 
611
{
 
612
        int k,k2;
 
613
        k2 = (int) data;
 
614
        if(!((GtkCheckMenuItem*)(searching_mode_buttons[k2]))->active) return 1;
 
615
        if(signal_menu_change>0) {signal_menu_change--;return 1;}
 
616
        //if(!signal) {signal++;return 1;}
 
617
        //signal--;
 
618
        k = (int) context->get_value("searching_mode");
 
619
        if(k == k2) return 1;
 
620
        pthread_mutex_lock(&context_lock);
 
621
        context->set_value("searching_mode","int",(void*)k2);
 
622
        pthread_mutex_unlock(&context_lock);
 
623
        updata_widget_show(0);
 
624
        updata_menu_buttons(0);
 
625
        return 0;
 
626
}
 
627
 
 
628
static int show_mode_callback (GtkWidget *widget, gpointer   data)
 
629
{
 
630
        int k,k2;
 
631
        k2 = (int) data;
 
632
        if(!((GtkCheckMenuItem*)(show_mode_buttons[k2]))->active) return 1;
 
633
        if(signal_menu_change>0) {signal_menu_change--;return 1;}
 
634
        //if(!signal) {signal++;return 1;}
 
635
        //signal--;
 
636
        k = (int) context->get_value("show_mode");
 
637
        if(k == k2) return 1;
 
638
        pthread_mutex_lock(&context_lock);
 
639
        context->set_value("show_mode","int",(void*)k2);
 
640
        pthread_mutex_unlock(&context_lock);
 
641
        //updata_widget_show(0);
 
642
        //updata_menu_buttons(0);
 
643
        return 0;
 
644
}
 
645
 
 
646
static void entry4_activate_callback(GtkWidget *w,gpointer data)
 
647
{
 
648
        keyword = gtk_entry_get_text(GTK_ENTRY(entry4));
 
649
        task_set_active(task_key_word_search);
 
650
}
 
651
 
 
652
static void entry4_changed_callback(GtkWidget *w,gpointer data)
 
653
{
 
654
        char * tmp;
 
655
        tmp = gtk_entry_get_text(GTK_ENTRY(entry4));
 
656
        gtk_widget_set_sensitive(search_button,strlen(tmp) >= 3);
 
657
                
 
658
}
 
659
 
 
660
static int button_clicked_callback(GtkWidget * w,gpointer data)
 
661
{
 
662
        int i = (int) data;
 
663
        switch (i) {
 
664
        case 1: task_set_stop(task_key_word_search);break;
 
665
        case 2: task_set_active(task_key_word_search);break;
 
666
        }
 
667
}