r693: Make static
[kai/samba.git] / source4 / lib / registry / tools / gregedit.c
1 /* 
2    Unix SMB/CIFS implementation.
3    Gtk registry frontend
4    
5    Copyright (C) Jelmer Vernooij 2004
6
7    This program is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 2 of the License, or
10    (at your option) any later version.
11    
12    This program is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16    
17    You should have received a copy of the GNU General Public License
18    along with this program; if not, write to the Free Software
19    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */
21
22 #ifdef HAVE_CONFIG_H
23 #  include <config.h>
24 #endif
25
26 #include <sys/types.h>
27 #include <sys/stat.h>
28 #include <unistd.h>
29 #include <string.h>
30 #include <stdio.h>
31
32 #include <gdk/gdkkeysyms.h>
33 #include <gtk/gtk.h>
34 #include "includes.h"
35
36 GtkWidget *openfilewin;
37 GtkWidget *savefilewin;
38 GtkTreeStore *store_keys;
39 GtkListStore *store_vals;
40 GtkWidget *tree_keys;
41 GtkWidget *aboutwin;
42 GtkWidget *mainwin;
43
44 GtkWidget *rpcwin;
45 GtkWidget *rpcwin_host;
46 GtkWidget *rpcwin_user;
47 GtkWidget *rpcwin_password;
48 GtkWidget *save;
49 GtkWidget *save_as;
50 static GtkWidget* create_openfilewin (void);
51 static GtkWidget* create_savefilewin (void);
52 static GtkWidget* create_aboutwin (void);
53 REG_HANDLE *registry = NULL;
54
55 static void gtk_show_werror(WERROR err) 
56 {
57         GtkWidget *dialog = gtk_message_dialog_new( GTK_WINDOW(mainwin), 
58                  GTK_DIALOG_DESTROY_WITH_PARENT,
59          GTK_MESSAGE_ERROR,
60          GTK_BUTTONS_CLOSE,
61                  "Registry error: %s\n", win_errstr(err));
62         gtk_dialog_run (GTK_DIALOG (dialog));
63         gtk_widget_destroy (dialog);
64 }
65
66 static void expand_key(GtkTreeView *treeview, GtkTreeIter *parent, GtkTreePath *arg2)
67 {
68         GtkTreeIter firstiter, iter, tmpiter;
69         REG_KEY *k, *sub;
70         char *name;
71         GValue value;
72         WERROR error;
73         int i;
74
75     gtk_tree_model_iter_children(GTK_TREE_MODEL(store_keys), &firstiter, parent);
76
77     /* See if this row has ever had a name gtk_tree_store_set()'ed to it.
78        If not, read the directory contents */
79     gtk_tree_model_get(GTK_TREE_MODEL(store_keys), &firstiter, 0, &name, -1);
80
81         if(name) return;
82
83         gtk_tree_model_get(GTK_TREE_MODEL(store_keys), parent, 1, &k, -1);
84
85         g_assert(k);
86         
87         for(i = 0; W_ERROR_IS_OK(error = reg_key_get_subkey_by_index(k, i, &sub)); i++) {
88                 int count;
89                 /* Replace the blank child with the first directory entry
90            You may be tempted to remove the blank child node and then 
91            append a new one.  Don't.  If you remove the blank child 
92            node GTK gets confused and won't expand the parent row. */
93
94                 if(i == 0) {
95                         iter = firstiter;
96                 } else {
97                         gtk_tree_store_append(store_keys, &iter, parent);
98                 }
99                 gtk_tree_store_set (store_keys,
100                                             &iter, 
101                                                 0,
102                                                 reg_key_name(sub),
103                                                 1, 
104                                                 sub,
105                                                 -1);
106                 
107                 if(W_ERROR_IS_OK(reg_key_num_subkeys(sub, &count)) && count > 0) 
108                         gtk_tree_store_append(store_keys, &tmpiter, &iter);
109         }
110
111         if(!W_ERROR_EQUAL(error, WERR_NO_MORE_ITEMS)) gtk_show_werror(error);
112 }
113
114 static void registry_load_root() 
115 {
116         REG_KEY *root;
117         GtkTreeIter iter, tmpiter;
118         WERROR error;
119         if(!registry) return;
120
121         error = reg_get_root(registry, &root);
122         if(!W_ERROR_IS_OK(error)) {
123                 gtk_show_werror(error);
124                 return;
125         }
126
127         gtk_tree_store_clear(store_keys);
128
129         /* Add the root */
130         gtk_tree_store_append(store_keys, &iter, NULL);
131         gtk_tree_store_set (store_keys,
132                                             &iter, 
133                                                 0,
134                                                 reg_key_name(root),
135                                                 1,
136                                                 root,
137                                                 -1);
138
139         gtk_tree_store_append(store_keys, &tmpiter, &iter);
140
141         gtk_widget_set_sensitive( save, True );
142         gtk_widget_set_sensitive( save_as, True );
143 }
144
145 static GtkWidget* create_rpcwin (void)
146 {
147   GtkWidget *dialog_vbox1;
148   GtkWidget *table1;
149   GtkWidget *label1;
150   GtkWidget *label2;
151   GtkWidget *label3;
152   GtkWidget *dialog_action_area1;
153   GtkWidget *cancelbutton1;
154   GtkWidget *okbutton1;
155
156   rpcwin = gtk_dialog_new ();
157   gtk_window_set_title (GTK_WINDOW (rpcwin), "Connect to remote server");
158
159   dialog_vbox1 = GTK_DIALOG (rpcwin)->vbox;
160   gtk_widget_show (dialog_vbox1);
161
162   table1 = gtk_table_new (3, 2, FALSE);
163   gtk_widget_show (table1);
164   gtk_box_pack_start (GTK_BOX (dialog_vbox1), table1, TRUE, TRUE, 0);
165
166   label1 = gtk_label_new ("Host:");
167   gtk_widget_show (label1);
168   gtk_table_attach (GTK_TABLE (table1), label1, 0, 1, 0, 1,
169                     (GtkAttachOptions) (GTK_FILL),
170                     (GtkAttachOptions) (0), 0, 0);
171   gtk_misc_set_alignment (GTK_MISC (label1), 0, 0.5);
172
173   label2 = gtk_label_new ("User:");
174   gtk_widget_show (label2);
175   gtk_table_attach (GTK_TABLE (table1), label2, 0, 1, 1, 2,
176                     (GtkAttachOptions) (GTK_FILL),
177                     (GtkAttachOptions) (0), 0, 0);
178   gtk_misc_set_alignment (GTK_MISC (label2), 0, 0.5);
179
180   label3 = gtk_label_new ("Password:");
181   gtk_widget_show (label3);
182   gtk_table_attach (GTK_TABLE (table1), label3, 0, 1, 2, 3,
183                     (GtkAttachOptions) (GTK_FILL),
184                     (GtkAttachOptions) (0), 0, 0);
185   gtk_misc_set_alignment (GTK_MISC (label3), 0, 0.5);
186
187   rpcwin_host = gtk_entry_new ();
188   gtk_widget_show (rpcwin_host);
189   gtk_table_attach (GTK_TABLE (table1), rpcwin_host, 1, 2, 0, 1,
190                     (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
191                     (GtkAttachOptions) (0), 0, 0);
192
193   rpcwin_user = gtk_entry_new ();
194   gtk_widget_show (rpcwin_user);
195   gtk_table_attach (GTK_TABLE (table1), rpcwin_user, 1, 2, 1, 2,
196                     (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
197                     (GtkAttachOptions) (0), 0, 0);
198
199   rpcwin_password = gtk_entry_new ();
200   gtk_widget_show (rpcwin_password);
201   gtk_table_attach (GTK_TABLE (table1), rpcwin_password, 1, 2, 2, 3,
202                     (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
203                     (GtkAttachOptions) (0), 0, 0);
204   gtk_entry_set_visibility (GTK_ENTRY (rpcwin_password), FALSE);
205
206   dialog_action_area1 = GTK_DIALOG (rpcwin)->action_area;
207   gtk_widget_show (dialog_action_area1);
208   gtk_button_box_set_layout (GTK_BUTTON_BOX (dialog_action_area1), GTK_BUTTONBOX_END);
209
210   cancelbutton1 = gtk_button_new_from_stock ("gtk-cancel");
211   gtk_widget_show (cancelbutton1);
212   gtk_dialog_add_action_widget (GTK_DIALOG (rpcwin), cancelbutton1, GTK_RESPONSE_CANCEL);
213   GTK_WIDGET_SET_FLAGS (cancelbutton1, GTK_CAN_DEFAULT);
214
215   okbutton1 = gtk_button_new_from_stock ("gtk-ok");
216   gtk_widget_show (okbutton1);
217   gtk_dialog_add_action_widget (GTK_DIALOG (rpcwin), okbutton1, GTK_RESPONSE_OK);
218   GTK_WIDGET_SET_FLAGS (okbutton1, GTK_CAN_DEFAULT);
219
220   return rpcwin;
221 }
222
223 static void on_open_file_activate (GtkMenuItem *menuitem, gpointer user_data)
224 {
225         gint result = gtk_dialog_run(GTK_DIALOG(create_openfilewin()));
226         char *filename;
227         WERROR error;
228         switch(result) {
229         case GTK_RESPONSE_OK:
230                 filename = strdup(gtk_file_selection_get_filename(GTK_FILE_SELECTION(openfilewin)));
231                 error = reg_open(user_data, filename, NULL, &registry);
232                 if(!W_ERROR_IS_OK(error)) {
233                         gtk_show_werror(error);
234                         break;
235                 }
236                 registry_load_root();
237                 break;
238         default:
239                 break;
240         }
241
242         gtk_widget_destroy(openfilewin);
243 }
244
245 static void on_open_gconf_activate                       (GtkMenuItem     *menuitem,
246                                                       gpointer         user_data)
247 {
248         WERROR error = reg_open("gconf", NULL, NULL, &registry);
249         if(!W_ERROR_IS_OK(error)) {
250                 gtk_show_werror(error);
251                 return;
252         }
253
254         registry_load_root();
255 }
256
257 static void on_open_remote_activate                (GtkMenuItem     *menuitem,
258                                                                                 gpointer         user_data)
259 {
260         char *location, *credentials;
261         gint result = gtk_dialog_run(GTK_DIALOG(create_rpcwin()));
262         WERROR error;
263         switch(result) {
264         case GTK_RESPONSE_OK:
265                 asprintf(&location, "ncacn_np:%s", gtk_entry_get_text(GTK_ENTRY(rpcwin_host)));
266                 asprintf(&credentials, "%s%%%s", gtk_entry_get_text(GTK_ENTRY(rpcwin_user)), gtk_entry_get_text(GTK_ENTRY(rpcwin_password)));
267                 error = reg_open("rpc", location, credentials, &registry);
268                 if(!W_ERROR_IS_OK(error)) {
269                         gtk_show_werror(error);
270                         break;
271                 }
272                 free(location); free(credentials);
273                 registry_load_root();
274                 break;
275         default:
276                 break;
277         }
278
279         gtk_widget_destroy(rpcwin);
280 }
281
282
283 static void on_save_activate                       (GtkMenuItem     *menuitem,
284                                                                                 gpointer         user_data)
285 {
286         WERROR error = reg_save(registry, NULL);
287         if(!W_ERROR_IS_OK(error)) {
288                 gtk_show_werror(error);
289         }
290 }
291
292
293 static void on_save_as_activate                    (GtkMenuItem     *menuitem,
294                                                                                 gpointer         user_data)
295 {
296         gint result;
297         WERROR error;
298         create_savefilewin();
299         result = gtk_dialog_run(GTK_DIALOG(savefilewin));
300         switch(result) {
301         case GTK_RESPONSE_OK:
302                 error = reg_save(registry, gtk_file_selection_get_filename(GTK_FILE_SELECTION(savefilewin)));
303                 if(!W_ERROR_IS_OK(error)) {
304                         gtk_show_werror(error);
305                 }
306                 break;
307
308         default:
309                 break;
310
311         }
312         gtk_widget_destroy(savefilewin);
313 }
314
315
316 static void on_quit_activate                       (GtkMenuItem     *menuitem,
317                                                                                 gpointer         user_data)
318 {
319         gtk_main_quit();
320 }
321
322
323 static void on_cut_activate                        (GtkMenuItem     *menuitem,
324                                                                                 gpointer         user_data)
325 {
326         /* FIXME */
327 }
328
329
330 static void on_copy_activate                       (GtkMenuItem     *menuitem,
331                                                                                 gpointer         user_data)
332 {
333         /* FIXME */
334 }
335
336
337 static void on_paste_activate                      (GtkMenuItem     *menuitem,
338                                                                                 gpointer         user_data)
339 {
340         /* FIXME */
341 }
342
343
344 static void on_delete_activate                     (GtkMenuItem     *menuitem,
345                                                                                 gpointer         user_data)
346 {
347         /* FIXME */
348 }
349
350
351 static void on_about_activate                      (GtkMenuItem     *menuitem,
352                                                                                 gpointer         user_data)
353 {
354         gtk_dialog_run(GTK_DIALOG(create_aboutwin()));
355         gtk_widget_destroy(aboutwin);
356 }
357
358 static void on_key_activate (GtkTreeView *treeview,
359                                           GtkTreePath *path,
360                                           gpointer user_data)
361 {
362         int i;
363         REG_KEY *k;
364         REG_VAL *val;
365         WERROR error;
366         GtkTreeIter parent;
367
368         gtk_tree_model_get_iter(GTK_TREE_MODEL(store_keys), &parent, path);
369         gtk_tree_model_get(GTK_TREE_MODEL(store_keys), &parent, 1, &k, -1);
370
371         g_assert(k);
372
373         gtk_list_store_clear(store_vals);
374
375         for(i = 0; W_ERROR_IS_OK(error = reg_key_get_value_by_index(k, i, &val)); i++) {
376                 GtkTreeIter iter;
377                 gtk_list_store_append(store_vals, &iter);
378                 gtk_list_store_set (store_vals,
379                                             &iter, 
380                                                 0,
381                                                 reg_val_name(val),
382                                                 1,
383                                                 str_regtype(reg_val_type(val)),
384                                                 2,
385                                                 reg_val_data_string(val),
386                                                 3, 
387                                                 val,
388                                                 -1);
389         }
390
391         if(!W_ERROR_EQUAL(error, WERR_NO_MORE_ITEMS)) gtk_show_werror(error);
392 }
393
394 static GtkWidget* create_mainwin (void)
395 {
396         GtkWidget *vbox1;
397         GtkWidget *menubar;
398         GtkWidget *menu_file;
399         GtkWidget *menu_file_menu;
400         GtkWidget *open_nt4;
401         GtkWidget *open_w95;
402         GtkWidget *open_gconf;
403         GtkWidget *open_remote;
404         GtkWidget *separatormenuitem1;
405         GtkWidget *quit;
406         GtkWidget *men_edit;
407         GtkWidget *men_edit_menu;
408         GtkWidget *cut;
409         GtkWidget *copy;
410         GtkWidget *paste;
411         GtkWidget *delete;
412         GtkCellRenderer *renderer;
413         GtkTreeViewColumn *curcol;
414         GtkWidget *help;
415         GtkWidget *help_menu;
416         GtkWidget *about;
417         GtkWidget *hbox1;
418         GtkWidget *scrolledwindow1;
419         GtkWidget *scrolledwindow2;
420         GtkWidget *tree_vals;
421         GtkWidget *statusbar;
422         GtkAccelGroup *accel_group;
423         GtkTreeIter iter, child;
424
425         accel_group = gtk_accel_group_new ();
426
427         mainwin = gtk_window_new (GTK_WINDOW_TOPLEVEL);
428         gtk_window_set_title (GTK_WINDOW (mainwin), "Registry editor");
429         gtk_window_set_default_size (GTK_WINDOW (mainwin), 642, 562);
430
431         vbox1 = gtk_vbox_new (FALSE, 0);
432         gtk_widget_show (vbox1);
433         gtk_container_add (GTK_CONTAINER (mainwin), vbox1);
434
435         menubar = gtk_menu_bar_new ();
436         gtk_widget_show (menubar);
437         gtk_box_pack_start (GTK_BOX (vbox1), menubar, FALSE, FALSE, 0);
438
439         menu_file = gtk_menu_item_new_with_mnemonic ("_File");
440         gtk_widget_show (menu_file);
441         gtk_container_add (GTK_CONTAINER (menubar), menu_file);
442
443         menu_file_menu = gtk_menu_new ();
444         gtk_menu_item_set_submenu (GTK_MENU_ITEM (menu_file), menu_file_menu);
445
446         open_nt4 = gtk_image_menu_item_new_with_mnemonic("_Open NT4 file");
447         gtk_widget_show (open_nt4);
448         gtk_container_add (GTK_CONTAINER (menu_file_menu), open_nt4);
449
450         open_w95 = gtk_image_menu_item_new_with_mnemonic("_Open Win9x file");
451         gtk_widget_show (open_w95);
452         gtk_container_add (GTK_CONTAINER (menu_file_menu), open_w95);
453
454         open_gconf = gtk_image_menu_item_new_with_mnemonic ("_Open GConf");
455         gtk_widget_show (open_gconf);
456         gtk_container_add (GTK_CONTAINER (menu_file_menu), open_gconf);
457
458         open_remote = gtk_menu_item_new_with_mnemonic ("_Open Remote");
459         gtk_widget_show (open_remote);
460         gtk_container_add (GTK_CONTAINER (menu_file_menu), open_remote);
461
462         save = gtk_image_menu_item_new_from_stock ("gtk-save", accel_group);
463         gtk_widget_show (save);
464         gtk_widget_set_sensitive( save, False );
465         gtk_container_add (GTK_CONTAINER (menu_file_menu), save);
466
467         save_as = gtk_image_menu_item_new_from_stock ("gtk-save-as", accel_group);
468         gtk_widget_show (save_as);
469         gtk_widget_set_sensitive( save_as, False );
470         gtk_container_add (GTK_CONTAINER (menu_file_menu), save_as);
471
472         separatormenuitem1 = gtk_menu_item_new ();
473         gtk_widget_show (separatormenuitem1);
474         gtk_container_add (GTK_CONTAINER (menu_file_menu), separatormenuitem1);
475         gtk_widget_set_sensitive (separatormenuitem1, FALSE);
476
477         quit = gtk_image_menu_item_new_from_stock ("gtk-quit", accel_group);
478         gtk_widget_show (quit);
479         gtk_container_add (GTK_CONTAINER (menu_file_menu), quit);
480
481         men_edit = gtk_menu_item_new_with_mnemonic ("_Edit");
482         gtk_widget_show (men_edit);
483         gtk_container_add (GTK_CONTAINER (menubar), men_edit);
484
485   men_edit_menu = gtk_menu_new ();
486   gtk_menu_item_set_submenu (GTK_MENU_ITEM (men_edit), men_edit_menu);
487
488   cut = gtk_image_menu_item_new_from_stock ("gtk-cut", accel_group);
489   gtk_widget_show (cut);
490   gtk_widget_set_sensitive(cut, False);
491   gtk_container_add (GTK_CONTAINER (men_edit_menu), cut);
492
493   copy = gtk_image_menu_item_new_from_stock ("gtk-copy", accel_group);
494   gtk_widget_show (copy);
495   gtk_widget_set_sensitive(copy, False);
496   gtk_container_add (GTK_CONTAINER (men_edit_menu), copy);
497
498   paste = gtk_image_menu_item_new_from_stock ("gtk-paste", accel_group);
499   gtk_widget_show (paste);
500   gtk_widget_set_sensitive(paste, False);
501   gtk_container_add (GTK_CONTAINER (men_edit_menu), paste);
502
503   delete = gtk_image_menu_item_new_from_stock ("gtk-delete", accel_group);
504   gtk_widget_show (delete);
505   gtk_widget_set_sensitive(delete, False);
506   gtk_container_add (GTK_CONTAINER (men_edit_menu), delete);
507
508   help = gtk_menu_item_new_with_mnemonic ("_Help");
509   gtk_widget_show (help);
510   gtk_container_add (GTK_CONTAINER (menubar), help);
511
512   help_menu = gtk_menu_new ();
513   gtk_menu_item_set_submenu (GTK_MENU_ITEM (help), help_menu);
514
515   about = gtk_menu_item_new_with_mnemonic ("_About");
516   gtk_widget_show (about);
517   gtk_container_add (GTK_CONTAINER (help_menu), about);
518
519   hbox1 = gtk_hbox_new (FALSE, 0);
520   gtk_widget_show (hbox1);
521   gtk_box_pack_start (GTK_BOX (vbox1), hbox1, TRUE, TRUE, 0);
522
523   scrolledwindow1 = gtk_scrolled_window_new (NULL, NULL);
524   gtk_widget_show (scrolledwindow1);
525   gtk_box_pack_start (GTK_BOX (hbox1), scrolledwindow1, TRUE, TRUE, 0);
526
527   tree_keys = gtk_tree_view_new ();
528
529   /* Column names */
530   curcol = gtk_tree_view_column_new ();
531   gtk_tree_view_column_set_title(curcol, "Name");
532   renderer = gtk_cell_renderer_text_new();
533   gtk_tree_view_column_pack_start(curcol, renderer, True);
534
535   gtk_tree_view_append_column(GTK_TREE_VIEW(tree_keys), curcol);
536
537   gtk_tree_view_column_add_attribute(curcol, renderer, "text", 0);
538   gtk_widget_show (tree_keys);
539   gtk_container_add (GTK_CONTAINER (scrolledwindow1), tree_keys);
540   store_keys = gtk_tree_store_new(2, G_TYPE_STRING, G_TYPE_POINTER);
541   gtk_tree_view_set_model(GTK_TREE_VIEW(tree_keys), GTK_TREE_MODEL(store_keys));
542   g_object_unref(store_keys);
543
544   g_signal_connect ((gpointer) tree_keys, "row-activated",
545                     G_CALLBACK (on_key_activate),
546                     NULL);
547
548   g_signal_connect ((gpointer) tree_keys, "row-expanded",
549                     G_CALLBACK (expand_key),
550                     NULL);
551
552   scrolledwindow2 = gtk_scrolled_window_new (NULL, NULL);
553   gtk_widget_show (scrolledwindow2);
554   gtk_box_pack_start (GTK_BOX (hbox1), scrolledwindow2, TRUE, TRUE, 0);
555
556   tree_vals = gtk_tree_view_new ();
557     /* Column names */
558
559   curcol = gtk_tree_view_column_new ();
560   gtk_tree_view_column_set_title(curcol, "Name");
561   renderer = gtk_cell_renderer_text_new();
562   gtk_tree_view_column_pack_start(curcol, renderer, True);
563   gtk_tree_view_append_column(GTK_TREE_VIEW(tree_vals), curcol);
564   gtk_tree_view_column_add_attribute(curcol, renderer, "text", 0);
565
566   curcol = gtk_tree_view_column_new ();
567   gtk_tree_view_column_set_title(curcol, "Type");
568   renderer = gtk_cell_renderer_text_new();
569   gtk_tree_view_column_pack_start(curcol, renderer, True);
570   gtk_tree_view_append_column(GTK_TREE_VIEW(tree_vals), curcol);
571   gtk_tree_view_column_add_attribute(curcol, renderer, "text", 1);
572
573   curcol = gtk_tree_view_column_new ();
574   gtk_tree_view_column_set_title(curcol, "Value");
575   renderer = gtk_cell_renderer_text_new();
576   gtk_tree_view_column_pack_start(curcol, renderer, True);
577   gtk_tree_view_append_column(GTK_TREE_VIEW(tree_vals), curcol);
578   gtk_tree_view_column_add_attribute(curcol, renderer, "text", 2);
579
580   
581   gtk_widget_show (tree_vals);
582   gtk_container_add (GTK_CONTAINER (scrolledwindow2), tree_vals);
583
584   store_vals = gtk_list_store_new(4, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_POINTER);
585   gtk_tree_view_set_model(GTK_TREE_VIEW(tree_vals), GTK_TREE_MODEL(store_vals));
586   g_object_unref(store_vals);
587
588   statusbar = gtk_statusbar_new ();
589   gtk_widget_show (statusbar);
590   gtk_box_pack_start (GTK_BOX (vbox1), statusbar, FALSE, FALSE, 0);
591   gtk_statusbar_set_has_resize_grip (GTK_STATUSBAR (statusbar), FALSE);
592
593   g_signal_connect ((gpointer) open_nt4, "activate",
594                     G_CALLBACK (on_open_file_activate),
595                     "nt4");
596   g_signal_connect ((gpointer) open_w95, "activate",
597                     G_CALLBACK (on_open_file_activate),
598                     "w95");
599   g_signal_connect ((gpointer) open_gconf, "activate",
600                     G_CALLBACK (on_open_gconf_activate),
601                     NULL);
602   g_signal_connect ((gpointer) open_remote, "activate",
603                     G_CALLBACK (on_open_remote_activate),
604                     NULL);
605   g_signal_connect ((gpointer) save, "activate",
606                     G_CALLBACK (on_save_activate),
607                     NULL);
608   g_signal_connect ((gpointer) save_as, "activate",
609                     G_CALLBACK (on_save_as_activate),
610                     NULL);
611   g_signal_connect ((gpointer) quit, "activate",
612                     G_CALLBACK (on_quit_activate),
613                     NULL);
614   g_signal_connect ((gpointer) cut, "activate",
615                     G_CALLBACK (on_cut_activate),
616                     NULL);
617   g_signal_connect ((gpointer) copy, "activate",
618                     G_CALLBACK (on_copy_activate),
619                     NULL);
620   g_signal_connect ((gpointer) paste, "activate",
621                     G_CALLBACK (on_paste_activate),
622                     NULL);
623   g_signal_connect ((gpointer) delete, "activate",
624                     G_CALLBACK (on_delete_activate),
625                     NULL);
626   g_signal_connect ((gpointer) about, "activate",
627                     G_CALLBACK (on_about_activate),
628                     NULL);
629
630   gtk_window_add_accel_group (GTK_WINDOW (mainwin), accel_group);
631
632   return mainwin;
633 }
634
635 static GtkWidget* create_aboutwin (void)
636 {
637   GtkWidget *dialog_vbox1;
638   GtkWidget *image1;
639   GtkWidget *label1;
640   GtkWidget *label2;
641   GtkWidget *dialog_action_area1;
642   GtkWidget *closebutton1;
643
644   aboutwin = gtk_dialog_new ();
645   gtk_window_set_title (GTK_WINDOW (aboutwin), "About GRegEdit");
646   gtk_window_set_resizable (GTK_WINDOW (aboutwin), FALSE);
647
648   dialog_vbox1 = GTK_DIALOG (aboutwin)->vbox;
649   gtk_widget_show (dialog_vbox1);
650
651   /* FIXME: Samba logo ? 
652   image1 = create_pixmap (aboutwin, "samba.png");
653   gtk_widget_show (image1);
654   gtk_box_pack_start (GTK_BOX (dialog_vbox1), image1, FALSE, TRUE, 0); */
655
656   label1 = gtk_label_new ("GRegEdit 0.1");
657   gtk_widget_show (label1);
658   gtk_box_pack_start (GTK_BOX (dialog_vbox1), label1, FALSE, FALSE, 0);
659   gtk_label_set_use_markup (GTK_LABEL (label1), TRUE);
660
661   label2 = gtk_label_new_with_mnemonic ("(C) 2004 Jelmer Vernooij <jelmer@samba.org>\nPart of Samba\nhttp://www.samba.org/\n");
662   gtk_widget_show (label2);
663   gtk_box_pack_start (GTK_BOX (dialog_vbox1), label2, TRUE, FALSE, 0);
664   gtk_label_set_use_markup (GTK_LABEL (label2), TRUE);
665
666   dialog_action_area1 = GTK_DIALOG (aboutwin)->action_area;
667   gtk_widget_show (dialog_action_area1);
668   gtk_button_box_set_layout (GTK_BUTTON_BOX (dialog_action_area1), GTK_BUTTONBOX_END);
669
670   closebutton1 = gtk_button_new_from_stock ("gtk-close");
671   gtk_widget_show (closebutton1);
672   gtk_dialog_add_action_widget (GTK_DIALOG (aboutwin), closebutton1, GTK_RESPONSE_CLOSE);
673   GTK_WIDGET_SET_FLAGS (closebutton1, GTK_CAN_DEFAULT);
674
675   return aboutwin;
676 }
677
678
679 static GtkWidget* create_openfilewin (void)
680 {
681   GtkWidget *ok_button;
682   GtkWidget *cancel_button;
683
684   openfilewin = gtk_file_selection_new ("Select File");
685   gtk_container_set_border_width (GTK_CONTAINER (openfilewin), 10);
686
687   ok_button = GTK_FILE_SELECTION (openfilewin)->ok_button;
688   gtk_widget_show (ok_button);
689   GTK_WIDGET_SET_FLAGS (ok_button, GTK_CAN_DEFAULT);
690
691   cancel_button = GTK_FILE_SELECTION (openfilewin)->cancel_button;
692   gtk_widget_show (cancel_button);
693   GTK_WIDGET_SET_FLAGS (cancel_button, GTK_CAN_DEFAULT);
694
695   return openfilewin;
696 }
697
698 static GtkWidget* create_savefilewin (void)
699 {
700   GtkWidget *ok_button;
701   GtkWidget *cancel_button;
702
703   savefilewin = gtk_file_selection_new ("Select File");
704   gtk_container_set_border_width (GTK_CONTAINER (savefilewin), 10);
705
706   ok_button = GTK_FILE_SELECTION (savefilewin)->ok_button;
707   gtk_widget_show (ok_button);
708   GTK_WIDGET_SET_FLAGS (ok_button, GTK_CAN_DEFAULT);
709
710   cancel_button = GTK_FILE_SELECTION (savefilewin)->cancel_button;
711   gtk_widget_show (cancel_button);
712   GTK_WIDGET_SET_FLAGS (cancel_button, GTK_CAN_DEFAULT);
713
714   return savefilewin;
715 }
716
717  int main(int argc, char *argv[])
718 {
719   poptContext pc;
720   const char *backend = NULL;
721   const char *credentials = NULL;
722   const char *location;
723   int opt;
724   struct poptOption long_options[] = {
725        POPT_AUTOHELP
726        {"backend", 'b', POPT_ARG_STRING, &backend, 0, "backend to use", NULL},
727            {"credentials", 'c', POPT_ARG_STRING, &credentials, 0, "credentials (user%%password)", NULL},
728        POPT_TABLEEND
729     };
730                                                                               
731     gtk_init (&argc, &argv);
732
733     pc = poptGetContext(argv[0], argc, (const char **) argv, long_options,0);
734                                                                               
735     while((opt = poptGetNextOpt(pc)) != -1) {
736     }
737
738         location = poptGetArg(pc);
739
740         if(location) {
741                 WERROR error;
742
743                 if(!backend) {
744                         if(credentials)backend = "rpc";
745                         else backend = "nt4";
746                 }
747                 
748                 error = reg_open(backend, location, credentials, &registry);
749                 if(!W_ERROR_IS_OK(error)) {
750                         gtk_show_werror(error);
751                         return -1;
752                 }
753                 mainwin = create_mainwin ();
754                 registry_load_root();
755         } else 
756                 mainwin = create_mainwin ();
757
758         gtk_widget_show (mainwin);
759
760         gtk_main ();
761
762         if(registry)reg_free(registry);
763         return 0;
764 }