r174: Win95 registry files (like USER.DAT) can now be partially parsed
[kai/samba.git] / source / 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 GtkWidget* create_openfilewin (void);
51 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 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 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 void
258 on_open_remote_activate                (GtkMenuItem     *menuitem,
259                                                                                 gpointer         user_data)
260 {
261         char *location, *credentials;
262         gint result = gtk_dialog_run(GTK_DIALOG(create_rpcwin()));
263         WERROR error;
264         switch(result) {
265         case GTK_RESPONSE_OK:
266                 asprintf(&location, "ncacn_np:%s", gtk_entry_get_text(GTK_ENTRY(rpcwin_host)));
267                 asprintf(&credentials, "%s%%%s", gtk_entry_get_text(GTK_ENTRY(rpcwin_user)), gtk_entry_get_text(GTK_ENTRY(rpcwin_password)));
268                 error = reg_open("rpc", location, credentials, &registry);
269                 if(!W_ERROR_IS_OK(error)) {
270                         gtk_show_werror(error);
271                         break;
272                 }
273                 free(location); free(credentials);
274                 registry_load_root();
275                 break;
276         default:
277                 break;
278         }
279
280         gtk_widget_destroy(rpcwin);
281 }
282
283
284 void
285 on_save_activate                       (GtkMenuItem     *menuitem,
286                                                                                 gpointer         user_data)
287 {
288         WERROR error = reg_save(registry, NULL);
289         if(!W_ERROR_IS_OK(error)) {
290                 gtk_show_werror(error);
291         }
292 }
293
294
295 void
296 on_save_as_activate                    (GtkMenuItem     *menuitem,
297                                                                                 gpointer         user_data)
298 {
299         gint result;
300         WERROR error;
301         create_savefilewin();
302         result = gtk_dialog_run(GTK_DIALOG(savefilewin));
303         switch(result) {
304         case GTK_RESPONSE_OK:
305                 error = reg_save(registry, gtk_file_selection_get_filename(GTK_FILE_SELECTION(savefilewin)));
306                 if(!W_ERROR_IS_OK(error)) {
307                         gtk_show_werror(error);
308                 }
309                 break;
310
311         default:
312                 break;
313
314         }
315         gtk_widget_destroy(savefilewin);
316 }
317
318
319 void
320 on_quit_activate                       (GtkMenuItem     *menuitem,
321                                                                                 gpointer         user_data)
322 {
323         gtk_main_quit();
324 }
325
326
327 void
328 on_cut_activate                        (GtkMenuItem     *menuitem,
329                                                                                 gpointer         user_data)
330 {
331         /* FIXME */
332 }
333
334
335 void
336 on_copy_activate                       (GtkMenuItem     *menuitem,
337                                                                                 gpointer         user_data)
338 {
339         /* FIXME */
340 }
341
342
343 void
344 on_paste_activate                      (GtkMenuItem     *menuitem,
345                                                                                 gpointer         user_data)
346 {
347         /* FIXME */
348 }
349
350
351 void
352 on_delete_activate                     (GtkMenuItem     *menuitem,
353                                                                                 gpointer         user_data)
354 {
355         /* FIXME */
356 }
357
358
359 void
360 on_about_activate                      (GtkMenuItem     *menuitem,
361                                                                                 gpointer         user_data)
362 {
363         gtk_dialog_run(GTK_DIALOG(create_aboutwin()));
364         gtk_widget_destroy(aboutwin);
365 }
366
367 void on_key_activate (GtkTreeView *treeview,
368                                           GtkTreePath *path,
369                                           gpointer user_data)
370 {
371         int i;
372         REG_KEY *k;
373         REG_VAL *val;
374         WERROR error;
375         GtkTreeIter parent;
376
377         gtk_tree_model_get_iter(GTK_TREE_MODEL(store_keys), &parent, path);
378         gtk_tree_model_get(GTK_TREE_MODEL(store_keys), &parent, 1, &k, -1);
379
380         g_assert(k);
381
382         gtk_list_store_clear(store_vals);
383
384         for(i = 0; W_ERROR_IS_OK(error = reg_key_get_value_by_index(k, i, &val)); i++) {
385                 GtkTreeIter iter;
386                 gtk_list_store_append(store_vals, &iter);
387                 gtk_list_store_set (store_vals,
388                                             &iter, 
389                                                 0,
390                                                 reg_val_name(val),
391                                                 1,
392                                                 str_regtype(reg_val_type(val)),
393                                                 2,
394                                                 reg_val_data_string(val),
395                                                 3, 
396                                                 val,
397                                                 -1);
398         }
399
400         if(!W_ERROR_EQUAL(error, WERR_NO_MORE_ITEMS)) gtk_show_werror(error);
401 }
402
403 GtkWidget* create_mainwin (void)
404 {
405         GtkWidget *vbox1;
406         GtkWidget *menubar;
407         GtkWidget *menu_file;
408         GtkWidget *menu_file_menu;
409         GtkWidget *open_nt4;
410         GtkWidget *open_w95;
411         GtkWidget *open_gconf;
412         GtkWidget *open_remote;
413         GtkWidget *separatormenuitem1;
414         GtkWidget *quit;
415         GtkWidget *men_edit;
416         GtkWidget *men_edit_menu;
417         GtkWidget *cut;
418         GtkWidget *copy;
419         GtkWidget *paste;
420         GtkWidget *delete;
421         GtkCellRenderer *renderer;
422         GtkTreeViewColumn *curcol;
423         GtkWidget *help;
424         GtkWidget *help_menu;
425         GtkWidget *about;
426         GtkWidget *hbox1;
427         GtkWidget *scrolledwindow1;
428         GtkWidget *scrolledwindow2;
429         GtkWidget *tree_vals;
430         GtkWidget *statusbar;
431         GtkAccelGroup *accel_group;
432         GtkTreeIter iter, child;
433
434         accel_group = gtk_accel_group_new ();
435
436         mainwin = gtk_window_new (GTK_WINDOW_TOPLEVEL);
437         gtk_window_set_title (GTK_WINDOW (mainwin), "Registry editor");
438         gtk_window_set_default_size (GTK_WINDOW (mainwin), 642, 562);
439
440         vbox1 = gtk_vbox_new (FALSE, 0);
441         gtk_widget_show (vbox1);
442         gtk_container_add (GTK_CONTAINER (mainwin), vbox1);
443
444         menubar = gtk_menu_bar_new ();
445         gtk_widget_show (menubar);
446         gtk_box_pack_start (GTK_BOX (vbox1), menubar, FALSE, FALSE, 0);
447
448         menu_file = gtk_menu_item_new_with_mnemonic ("_File");
449         gtk_widget_show (menu_file);
450         gtk_container_add (GTK_CONTAINER (menubar), menu_file);
451
452         menu_file_menu = gtk_menu_new ();
453         gtk_menu_item_set_submenu (GTK_MENU_ITEM (menu_file), menu_file_menu);
454
455         open_nt4 = gtk_image_menu_item_new_with_mnemonic("_Open NT4 file");
456         gtk_widget_show (open_nt4);
457         gtk_container_add (GTK_CONTAINER (menu_file_menu), open_nt4);
458
459         open_w95 = gtk_image_menu_item_new_with_mnemonic("_Open Win9x file");
460         gtk_widget_show (open_w95);
461         gtk_container_add (GTK_CONTAINER (menu_file_menu), open_w95);
462
463         open_gconf = gtk_image_menu_item_new_with_mnemonic ("_Open GConf");
464         gtk_widget_show (open_gconf);
465         gtk_container_add (GTK_CONTAINER (menu_file_menu), open_gconf);
466
467         open_remote = gtk_menu_item_new_with_mnemonic ("_Open Remote");
468         gtk_widget_show (open_remote);
469         gtk_container_add (GTK_CONTAINER (menu_file_menu), open_remote);
470
471         save = gtk_image_menu_item_new_from_stock ("gtk-save", accel_group);
472         gtk_widget_show (save);
473         gtk_widget_set_sensitive( save, False );
474         gtk_container_add (GTK_CONTAINER (menu_file_menu), save);
475
476         save_as = gtk_image_menu_item_new_from_stock ("gtk-save-as", accel_group);
477         gtk_widget_show (save_as);
478         gtk_widget_set_sensitive( save_as, False );
479         gtk_container_add (GTK_CONTAINER (menu_file_menu), save_as);
480
481         separatormenuitem1 = gtk_menu_item_new ();
482         gtk_widget_show (separatormenuitem1);
483         gtk_container_add (GTK_CONTAINER (menu_file_menu), separatormenuitem1);
484         gtk_widget_set_sensitive (separatormenuitem1, FALSE);
485
486         quit = gtk_image_menu_item_new_from_stock ("gtk-quit", accel_group);
487         gtk_widget_show (quit);
488         gtk_container_add (GTK_CONTAINER (menu_file_menu), quit);
489
490         men_edit = gtk_menu_item_new_with_mnemonic ("_Edit");
491         gtk_widget_show (men_edit);
492         gtk_container_add (GTK_CONTAINER (menubar), men_edit);
493
494   men_edit_menu = gtk_menu_new ();
495   gtk_menu_item_set_submenu (GTK_MENU_ITEM (men_edit), men_edit_menu);
496
497   cut = gtk_image_menu_item_new_from_stock ("gtk-cut", accel_group);
498   gtk_widget_show (cut);
499   gtk_widget_set_sensitive(cut, False);
500   gtk_container_add (GTK_CONTAINER (men_edit_menu), cut);
501
502   copy = gtk_image_menu_item_new_from_stock ("gtk-copy", accel_group);
503   gtk_widget_show (copy);
504   gtk_widget_set_sensitive(copy, False);
505   gtk_container_add (GTK_CONTAINER (men_edit_menu), copy);
506
507   paste = gtk_image_menu_item_new_from_stock ("gtk-paste", accel_group);
508   gtk_widget_show (paste);
509   gtk_widget_set_sensitive(paste, False);
510   gtk_container_add (GTK_CONTAINER (men_edit_menu), paste);
511
512   delete = gtk_image_menu_item_new_from_stock ("gtk-delete", accel_group);
513   gtk_widget_show (delete);
514   gtk_widget_set_sensitive(delete, False);
515   gtk_container_add (GTK_CONTAINER (men_edit_menu), delete);
516
517   help = gtk_menu_item_new_with_mnemonic ("_Help");
518   gtk_widget_show (help);
519   gtk_container_add (GTK_CONTAINER (menubar), help);
520
521   help_menu = gtk_menu_new ();
522   gtk_menu_item_set_submenu (GTK_MENU_ITEM (help), help_menu);
523
524   about = gtk_menu_item_new_with_mnemonic ("_About");
525   gtk_widget_show (about);
526   gtk_container_add (GTK_CONTAINER (help_menu), about);
527
528   hbox1 = gtk_hbox_new (FALSE, 0);
529   gtk_widget_show (hbox1);
530   gtk_box_pack_start (GTK_BOX (vbox1), hbox1, TRUE, TRUE, 0);
531
532   scrolledwindow1 = gtk_scrolled_window_new (NULL, NULL);
533   gtk_widget_show (scrolledwindow1);
534   gtk_box_pack_start (GTK_BOX (hbox1), scrolledwindow1, TRUE, TRUE, 0);
535
536   tree_keys = gtk_tree_view_new ();
537
538   /* Column names */
539   curcol = gtk_tree_view_column_new ();
540   gtk_tree_view_column_set_title(curcol, "Name");
541   renderer = gtk_cell_renderer_text_new();
542   gtk_tree_view_column_pack_start(curcol, renderer, True);
543
544   gtk_tree_view_append_column(GTK_TREE_VIEW(tree_keys), curcol);
545
546   gtk_tree_view_column_add_attribute(curcol, renderer, "text", 0);
547   gtk_widget_show (tree_keys);
548   gtk_container_add (GTK_CONTAINER (scrolledwindow1), tree_keys);
549   store_keys = gtk_tree_store_new(2, G_TYPE_STRING, G_TYPE_POINTER);
550   gtk_tree_view_set_model(GTK_TREE_VIEW(tree_keys), GTK_TREE_MODEL(store_keys));
551   g_object_unref(store_keys);
552
553   g_signal_connect ((gpointer) tree_keys, "row-activated",
554                     G_CALLBACK (on_key_activate),
555                     NULL);
556
557   g_signal_connect ((gpointer) tree_keys, "row-expanded",
558                     G_CALLBACK (expand_key),
559                     NULL);
560
561   scrolledwindow2 = gtk_scrolled_window_new (NULL, NULL);
562   gtk_widget_show (scrolledwindow2);
563   gtk_box_pack_start (GTK_BOX (hbox1), scrolledwindow2, TRUE, TRUE, 0);
564
565   tree_vals = gtk_tree_view_new ();
566     /* Column names */
567
568   curcol = gtk_tree_view_column_new ();
569   gtk_tree_view_column_set_title(curcol, "Name");
570   renderer = gtk_cell_renderer_text_new();
571   gtk_tree_view_column_pack_start(curcol, renderer, True);
572   gtk_tree_view_append_column(GTK_TREE_VIEW(tree_vals), curcol);
573   gtk_tree_view_column_add_attribute(curcol, renderer, "text", 0);
574
575   curcol = gtk_tree_view_column_new ();
576   gtk_tree_view_column_set_title(curcol, "Type");
577   renderer = gtk_cell_renderer_text_new();
578   gtk_tree_view_column_pack_start(curcol, renderer, True);
579   gtk_tree_view_append_column(GTK_TREE_VIEW(tree_vals), curcol);
580   gtk_tree_view_column_add_attribute(curcol, renderer, "text", 1);
581
582   curcol = gtk_tree_view_column_new ();
583   gtk_tree_view_column_set_title(curcol, "Value");
584   renderer = gtk_cell_renderer_text_new();
585   gtk_tree_view_column_pack_start(curcol, renderer, True);
586   gtk_tree_view_append_column(GTK_TREE_VIEW(tree_vals), curcol);
587   gtk_tree_view_column_add_attribute(curcol, renderer, "text", 2);
588
589   
590   gtk_widget_show (tree_vals);
591   gtk_container_add (GTK_CONTAINER (scrolledwindow2), tree_vals);
592
593   store_vals = gtk_list_store_new(4, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_POINTER);
594   gtk_tree_view_set_model(GTK_TREE_VIEW(tree_vals), GTK_TREE_MODEL(store_vals));
595   g_object_unref(store_vals);
596
597   statusbar = gtk_statusbar_new ();
598   gtk_widget_show (statusbar);
599   gtk_box_pack_start (GTK_BOX (vbox1), statusbar, FALSE, FALSE, 0);
600   gtk_statusbar_set_has_resize_grip (GTK_STATUSBAR (statusbar), FALSE);
601
602   g_signal_connect ((gpointer) open_nt4, "activate",
603                     G_CALLBACK (on_open_file_activate),
604                     "nt4");
605   g_signal_connect ((gpointer) open_w95, "activate",
606                     G_CALLBACK (on_open_file_activate),
607                     "w95");
608   g_signal_connect ((gpointer) open_gconf, "activate",
609                     G_CALLBACK (on_open_gconf_activate),
610                     NULL);
611   g_signal_connect ((gpointer) open_remote, "activate",
612                     G_CALLBACK (on_open_remote_activate),
613                     NULL);
614   g_signal_connect ((gpointer) save, "activate",
615                     G_CALLBACK (on_save_activate),
616                     NULL);
617   g_signal_connect ((gpointer) save_as, "activate",
618                     G_CALLBACK (on_save_as_activate),
619                     NULL);
620   g_signal_connect ((gpointer) quit, "activate",
621                     G_CALLBACK (on_quit_activate),
622                     NULL);
623   g_signal_connect ((gpointer) cut, "activate",
624                     G_CALLBACK (on_cut_activate),
625                     NULL);
626   g_signal_connect ((gpointer) copy, "activate",
627                     G_CALLBACK (on_copy_activate),
628                     NULL);
629   g_signal_connect ((gpointer) paste, "activate",
630                     G_CALLBACK (on_paste_activate),
631                     NULL);
632   g_signal_connect ((gpointer) delete, "activate",
633                     G_CALLBACK (on_delete_activate),
634                     NULL);
635   g_signal_connect ((gpointer) about, "activate",
636                     G_CALLBACK (on_about_activate),
637                     NULL);
638
639   gtk_window_add_accel_group (GTK_WINDOW (mainwin), accel_group);
640
641   return mainwin;
642 }
643
644 static GtkWidget* create_aboutwin (void)
645 {
646   GtkWidget *dialog_vbox1;
647   GtkWidget *image1;
648   GtkWidget *label1;
649   GtkWidget *label2;
650   GtkWidget *dialog_action_area1;
651   GtkWidget *closebutton1;
652
653   aboutwin = gtk_dialog_new ();
654   gtk_window_set_title (GTK_WINDOW (aboutwin), "About GRegEdit");
655   gtk_window_set_resizable (GTK_WINDOW (aboutwin), FALSE);
656
657   dialog_vbox1 = GTK_DIALOG (aboutwin)->vbox;
658   gtk_widget_show (dialog_vbox1);
659
660   /* FIXME: Samba logo ? 
661   image1 = create_pixmap (aboutwin, "samba.png");
662   gtk_widget_show (image1);
663   gtk_box_pack_start (GTK_BOX (dialog_vbox1), image1, FALSE, TRUE, 0); */
664
665   label1 = gtk_label_new ("GRegEdit 0.1");
666   gtk_widget_show (label1);
667   gtk_box_pack_start (GTK_BOX (dialog_vbox1), label1, FALSE, FALSE, 0);
668   gtk_label_set_use_markup (GTK_LABEL (label1), TRUE);
669
670   label2 = gtk_label_new_with_mnemonic ("(C) 2004 Jelmer Vernooij <jelmer@samba.org>\nPart of Samba\nhttp://www.samba.org/\n");
671   gtk_widget_show (label2);
672   gtk_box_pack_start (GTK_BOX (dialog_vbox1), label2, TRUE, FALSE, 0);
673   gtk_label_set_use_markup (GTK_LABEL (label2), TRUE);
674
675   dialog_action_area1 = GTK_DIALOG (aboutwin)->action_area;
676   gtk_widget_show (dialog_action_area1);
677   gtk_button_box_set_layout (GTK_BUTTON_BOX (dialog_action_area1), GTK_BUTTONBOX_END);
678
679   closebutton1 = gtk_button_new_from_stock ("gtk-close");
680   gtk_widget_show (closebutton1);
681   gtk_dialog_add_action_widget (GTK_DIALOG (aboutwin), closebutton1, GTK_RESPONSE_CLOSE);
682   GTK_WIDGET_SET_FLAGS (closebutton1, GTK_CAN_DEFAULT);
683
684   return aboutwin;
685 }
686
687
688 GtkWidget* create_openfilewin (void)
689 {
690   GtkWidget *ok_button;
691   GtkWidget *cancel_button;
692
693   openfilewin = gtk_file_selection_new ("Select File");
694   gtk_container_set_border_width (GTK_CONTAINER (openfilewin), 10);
695
696   ok_button = GTK_FILE_SELECTION (openfilewin)->ok_button;
697   gtk_widget_show (ok_button);
698   GTK_WIDGET_SET_FLAGS (ok_button, GTK_CAN_DEFAULT);
699
700   cancel_button = GTK_FILE_SELECTION (openfilewin)->cancel_button;
701   gtk_widget_show (cancel_button);
702   GTK_WIDGET_SET_FLAGS (cancel_button, GTK_CAN_DEFAULT);
703
704   return openfilewin;
705 }
706
707 GtkWidget* create_savefilewin (void)
708 {
709   GtkWidget *ok_button;
710   GtkWidget *cancel_button;
711
712   savefilewin = gtk_file_selection_new ("Select File");
713   gtk_container_set_border_width (GTK_CONTAINER (savefilewin), 10);
714
715   ok_button = GTK_FILE_SELECTION (savefilewin)->ok_button;
716   gtk_widget_show (ok_button);
717   GTK_WIDGET_SET_FLAGS (ok_button, GTK_CAN_DEFAULT);
718
719   cancel_button = GTK_FILE_SELECTION (savefilewin)->cancel_button;
720   gtk_widget_show (cancel_button);
721   GTK_WIDGET_SET_FLAGS (cancel_button, GTK_CAN_DEFAULT);
722
723   return savefilewin;
724 }
725
726 int main (int argc, char *argv[])
727 {
728   poptContext pc;
729   const char *backend = NULL, *credentials = NULL, *location;
730   int opt;
731   struct poptOption long_options[] = {
732        POPT_AUTOHELP
733        {"backend", 'b', POPT_ARG_STRING, &backend, 0, "backend to use", NULL},
734            {"credentials", 'c', POPT_ARG_STRING, &credentials, 0, "credentials (user%%password)", NULL},
735        POPT_TABLEEND
736     };
737                                                                               
738     gtk_init (&argc, &argv);
739
740     pc = poptGetContext(argv[0], argc, (const char **) argv, long_options,0);
741                                                                               
742     while((opt = poptGetNextOpt(pc)) != -1) {
743     }
744
745         location = poptGetArg(pc);
746
747         if(location) {
748                 WERROR error;
749
750                 if(!backend) {
751                         if(credentials)backend = "rpc";
752                         else backend = "nt4";
753                 }
754                 
755                 error = reg_open(backend, location, credentials, &registry);
756                 if(!W_ERROR_IS_OK(error)) {
757                         gtk_show_werror(error);
758                         return -1;
759                 }
760                 mainwin = create_mainwin ();
761                 registry_load_root();
762         } else 
763                 mainwin = create_mainwin ();
764
765         gtk_widget_show (mainwin);
766
767         gtk_main ();
768
769         if(registry)reg_free(registry);
770         return 0;
771 }