r168: - Cleanups in rpc backend
[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 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 iter, tmpiter;
69         REG_KEY *k, *sub;
70         char *name;
71         GValue value;
72         WERROR error;
73         int i;
74
75     /* See if this row has ever had a name gtk_tree_store_set()'ed to it.
76        If not, read the directory contents */
77     gtk_tree_model_get(GTK_TREE_MODEL(store_keys), parent,
78                        0, &name, -1);
79
80         if(!name) return;
81
82         gtk_tree_model_get(GTK_TREE_MODEL(store_keys), parent, 1, &k, -1);
83
84         g_assert(k);
85         
86         for(i = 0; W_ERROR_IS_OK(error = reg_key_get_subkey_by_index(k, i, &sub)); i++) {
87                 int count;
88                 /* Replace the blank child with the first directory entry
89            You may be tempted to remove the blank child node and then 
90            append a new one.  Don't.  If you remove the blank child 
91            node GTK gets confused and won't expand the parent row. */
92
93                 if(i == 0) {
94                     gtk_tree_model_iter_children(GTK_TREE_MODEL(store_keys), 
95                                      &iter, parent);
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_nt4_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("nt4", 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_gconf;
411         GtkWidget *open_remote;
412         GtkWidget *separatormenuitem1;
413         GtkWidget *quit;
414         GtkWidget *men_edit;
415         GtkWidget *men_edit_menu;
416         GtkWidget *cut;
417         GtkWidget *copy;
418         GtkWidget *paste;
419         GtkWidget *delete;
420         GtkCellRenderer *renderer;
421         GtkTreeViewColumn *curcol;
422         GtkWidget *help;
423         GtkWidget *help_menu;
424         GtkWidget *about;
425         GtkWidget *hbox1;
426         GtkWidget *scrolledwindow1;
427         GtkWidget *scrolledwindow2;
428         GtkWidget *tree_vals;
429         GtkWidget *statusbar;
430         GtkAccelGroup *accel_group;
431         GtkTreeIter iter, child;
432
433         accel_group = gtk_accel_group_new ();
434
435         mainwin = gtk_window_new (GTK_WINDOW_TOPLEVEL);
436         gtk_window_set_title (GTK_WINDOW (mainwin), "Registry editor");
437         gtk_window_set_default_size (GTK_WINDOW (mainwin), 642, 562);
438
439         vbox1 = gtk_vbox_new (FALSE, 0);
440         gtk_widget_show (vbox1);
441         gtk_container_add (GTK_CONTAINER (mainwin), vbox1);
442
443         menubar = gtk_menu_bar_new ();
444         gtk_widget_show (menubar);
445         gtk_box_pack_start (GTK_BOX (vbox1), menubar, FALSE, FALSE, 0);
446
447         menu_file = gtk_menu_item_new_with_mnemonic ("_File");
448         gtk_widget_show (menu_file);
449         gtk_container_add (GTK_CONTAINER (menubar), menu_file);
450
451         menu_file_menu = gtk_menu_new ();
452         gtk_menu_item_set_submenu (GTK_MENU_ITEM (menu_file), menu_file_menu);
453
454         open_nt4 = gtk_image_menu_item_new_with_mnemonic("_Open NT4 file");
455         gtk_widget_show (open_nt4);
456         gtk_container_add (GTK_CONTAINER (menu_file_menu), open_nt4);
457
458         open_gconf = gtk_image_menu_item_new_with_mnemonic ("_Open GConf");
459         gtk_widget_show (open_gconf);
460         gtk_container_add (GTK_CONTAINER (menu_file_menu), open_gconf);
461
462         open_remote = gtk_menu_item_new_with_mnemonic ("_Open Remote");
463         gtk_widget_show (open_remote);
464         gtk_container_add (GTK_CONTAINER (menu_file_menu), open_remote);
465
466         save = gtk_image_menu_item_new_from_stock ("gtk-save", accel_group);
467         gtk_widget_show (save);
468         gtk_widget_set_sensitive( save, False );
469         gtk_container_add (GTK_CONTAINER (menu_file_menu), save);
470
471         save_as = gtk_image_menu_item_new_from_stock ("gtk-save-as", accel_group);
472         gtk_widget_show (save_as);
473         gtk_widget_set_sensitive( save_as, False );
474         gtk_container_add (GTK_CONTAINER (menu_file_menu), save_as);
475
476         separatormenuitem1 = gtk_menu_item_new ();
477         gtk_widget_show (separatormenuitem1);
478         gtk_container_add (GTK_CONTAINER (menu_file_menu), separatormenuitem1);
479         gtk_widget_set_sensitive (separatormenuitem1, FALSE);
480
481         quit = gtk_image_menu_item_new_from_stock ("gtk-quit", accel_group);
482         gtk_widget_show (quit);
483         gtk_container_add (GTK_CONTAINER (menu_file_menu), quit);
484
485         men_edit = gtk_menu_item_new_with_mnemonic ("_Edit");
486         gtk_widget_show (men_edit);
487         gtk_container_add (GTK_CONTAINER (menubar), men_edit);
488
489   men_edit_menu = gtk_menu_new ();
490   gtk_menu_item_set_submenu (GTK_MENU_ITEM (men_edit), men_edit_menu);
491
492   cut = gtk_image_menu_item_new_from_stock ("gtk-cut", accel_group);
493   gtk_widget_show (cut);
494   gtk_widget_set_sensitive(cut, False);
495   gtk_container_add (GTK_CONTAINER (men_edit_menu), cut);
496
497   copy = gtk_image_menu_item_new_from_stock ("gtk-copy", accel_group);
498   gtk_widget_show (copy);
499   gtk_widget_set_sensitive(copy, False);
500   gtk_container_add (GTK_CONTAINER (men_edit_menu), copy);
501
502   paste = gtk_image_menu_item_new_from_stock ("gtk-paste", accel_group);
503   gtk_widget_show (paste);
504   gtk_widget_set_sensitive(paste, False);
505   gtk_container_add (GTK_CONTAINER (men_edit_menu), paste);
506
507   delete = gtk_image_menu_item_new_from_stock ("gtk-delete", accel_group);
508   gtk_widget_show (delete);
509   gtk_widget_set_sensitive(delete, False);
510   gtk_container_add (GTK_CONTAINER (men_edit_menu), delete);
511
512   help = gtk_menu_item_new_with_mnemonic ("_Help");
513   gtk_widget_show (help);
514   gtk_container_add (GTK_CONTAINER (menubar), help);
515
516   help_menu = gtk_menu_new ();
517   gtk_menu_item_set_submenu (GTK_MENU_ITEM (help), help_menu);
518
519   about = gtk_menu_item_new_with_mnemonic ("_About");
520   gtk_widget_show (about);
521   gtk_container_add (GTK_CONTAINER (help_menu), about);
522
523   hbox1 = gtk_hbox_new (FALSE, 0);
524   gtk_widget_show (hbox1);
525   gtk_box_pack_start (GTK_BOX (vbox1), hbox1, TRUE, TRUE, 0);
526
527   scrolledwindow1 = gtk_scrolled_window_new (NULL, NULL);
528   gtk_widget_show (scrolledwindow1);
529   gtk_box_pack_start (GTK_BOX (hbox1), scrolledwindow1, TRUE, TRUE, 0);
530
531   tree_keys = gtk_tree_view_new ();
532
533   /* Column names */
534   curcol = gtk_tree_view_column_new ();
535   gtk_tree_view_column_set_title(curcol, "Name");
536   renderer = gtk_cell_renderer_text_new();
537   gtk_tree_view_column_pack_start(curcol, renderer, True);
538
539   gtk_tree_view_append_column(GTK_TREE_VIEW(tree_keys), curcol);
540
541   gtk_tree_view_column_add_attribute(curcol, renderer, "text", 0);
542   gtk_widget_show (tree_keys);
543   gtk_container_add (GTK_CONTAINER (scrolledwindow1), tree_keys);
544   store_keys = gtk_tree_store_new(2, G_TYPE_STRING, G_TYPE_POINTER);
545   gtk_tree_view_set_model(GTK_TREE_VIEW(tree_keys), GTK_TREE_MODEL(store_keys));
546   g_object_unref(store_keys);
547
548   g_signal_connect ((gpointer) tree_keys, "row-activated",
549                     G_CALLBACK (on_key_activate),
550                     NULL);
551
552   g_signal_connect ((gpointer) tree_keys, "row-expanded",
553                     G_CALLBACK (expand_key),
554                     NULL);
555
556   scrolledwindow2 = gtk_scrolled_window_new (NULL, NULL);
557   gtk_widget_show (scrolledwindow2);
558   gtk_box_pack_start (GTK_BOX (hbox1), scrolledwindow2, TRUE, TRUE, 0);
559
560   tree_vals = gtk_tree_view_new ();
561     /* Column names */
562
563   curcol = gtk_tree_view_column_new ();
564   gtk_tree_view_column_set_title(curcol, "Name");
565   renderer = gtk_cell_renderer_text_new();
566   gtk_tree_view_column_pack_start(curcol, renderer, True);
567   gtk_tree_view_append_column(GTK_TREE_VIEW(tree_vals), curcol);
568   gtk_tree_view_column_add_attribute(curcol, renderer, "text", 0);
569
570   curcol = gtk_tree_view_column_new ();
571   gtk_tree_view_column_set_title(curcol, "Type");
572   renderer = gtk_cell_renderer_text_new();
573   gtk_tree_view_column_pack_start(curcol, renderer, True);
574   gtk_tree_view_append_column(GTK_TREE_VIEW(tree_vals), curcol);
575   gtk_tree_view_column_add_attribute(curcol, renderer, "text", 1);
576
577   curcol = gtk_tree_view_column_new ();
578   gtk_tree_view_column_set_title(curcol, "Value");
579   renderer = gtk_cell_renderer_text_new();
580   gtk_tree_view_column_pack_start(curcol, renderer, True);
581   gtk_tree_view_append_column(GTK_TREE_VIEW(tree_vals), curcol);
582   gtk_tree_view_column_add_attribute(curcol, renderer, "text", 2);
583
584   
585   gtk_widget_show (tree_vals);
586   gtk_container_add (GTK_CONTAINER (scrolledwindow2), tree_vals);
587
588   store_vals = gtk_list_store_new(4, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_POINTER);
589   gtk_tree_view_set_model(GTK_TREE_VIEW(tree_vals), GTK_TREE_MODEL(store_vals));
590   g_object_unref(store_vals);
591
592   statusbar = gtk_statusbar_new ();
593   gtk_widget_show (statusbar);
594   gtk_box_pack_start (GTK_BOX (vbox1), statusbar, FALSE, FALSE, 0);
595   gtk_statusbar_set_has_resize_grip (GTK_STATUSBAR (statusbar), FALSE);
596
597   g_signal_connect ((gpointer) open_nt4, "activate",
598                     G_CALLBACK (on_open_nt4_activate),
599                     NULL);
600   g_signal_connect ((gpointer) open_gconf, "activate",
601                     G_CALLBACK (on_open_gconf_activate),
602                     NULL);
603   g_signal_connect ((gpointer) open_remote, "activate",
604                     G_CALLBACK (on_open_remote_activate),
605                     NULL);
606   g_signal_connect ((gpointer) save, "activate",
607                     G_CALLBACK (on_save_activate),
608                     NULL);
609   g_signal_connect ((gpointer) save_as, "activate",
610                     G_CALLBACK (on_save_as_activate),
611                     NULL);
612   g_signal_connect ((gpointer) quit, "activate",
613                     G_CALLBACK (on_quit_activate),
614                     NULL);
615   g_signal_connect ((gpointer) cut, "activate",
616                     G_CALLBACK (on_cut_activate),
617                     NULL);
618   g_signal_connect ((gpointer) copy, "activate",
619                     G_CALLBACK (on_copy_activate),
620                     NULL);
621   g_signal_connect ((gpointer) paste, "activate",
622                     G_CALLBACK (on_paste_activate),
623                     NULL);
624   g_signal_connect ((gpointer) delete, "activate",
625                     G_CALLBACK (on_delete_activate),
626                     NULL);
627   g_signal_connect ((gpointer) about, "activate",
628                     G_CALLBACK (on_about_activate),
629                     NULL);
630
631   gtk_window_add_accel_group (GTK_WINDOW (mainwin), accel_group);
632
633   return mainwin;
634 }
635
636 static GtkWidget* create_aboutwin (void)
637 {
638   GtkWidget *dialog_vbox1;
639   GtkWidget *image1;
640   GtkWidget *label1;
641   GtkWidget *label2;
642   GtkWidget *dialog_action_area1;
643   GtkWidget *closebutton1;
644
645   aboutwin = gtk_dialog_new ();
646   gtk_window_set_title (GTK_WINDOW (aboutwin), "About GRegEdit");
647   gtk_window_set_resizable (GTK_WINDOW (aboutwin), FALSE);
648
649   dialog_vbox1 = GTK_DIALOG (aboutwin)->vbox;
650   gtk_widget_show (dialog_vbox1);
651
652   /* FIXME: Samba logo ? 
653   image1 = create_pixmap (aboutwin, "samba.png");
654   gtk_widget_show (image1);
655   gtk_box_pack_start (GTK_BOX (dialog_vbox1), image1, FALSE, TRUE, 0); */
656
657   label1 = gtk_label_new ("GRegEdit 0.1");
658   gtk_widget_show (label1);
659   gtk_box_pack_start (GTK_BOX (dialog_vbox1), label1, FALSE, FALSE, 0);
660   gtk_label_set_use_markup (GTK_LABEL (label1), TRUE);
661
662   label2 = gtk_label_new_with_mnemonic ("(C) 2004 Jelmer Vernooij <jelmer@samba.org>\nPart of Samba\nhttp://www.samba.org/\n");
663   gtk_widget_show (label2);
664   gtk_box_pack_start (GTK_BOX (dialog_vbox1), label2, TRUE, FALSE, 0);
665   gtk_label_set_use_markup (GTK_LABEL (label2), TRUE);
666
667   dialog_action_area1 = GTK_DIALOG (aboutwin)->action_area;
668   gtk_widget_show (dialog_action_area1);
669   gtk_button_box_set_layout (GTK_BUTTON_BOX (dialog_action_area1), GTK_BUTTONBOX_END);
670
671   closebutton1 = gtk_button_new_from_stock ("gtk-close");
672   gtk_widget_show (closebutton1);
673   gtk_dialog_add_action_widget (GTK_DIALOG (aboutwin), closebutton1, GTK_RESPONSE_CLOSE);
674   GTK_WIDGET_SET_FLAGS (closebutton1, GTK_CAN_DEFAULT);
675
676   return aboutwin;
677 }
678
679
680 GtkWidget* create_openfilewin (void)
681 {
682   GtkWidget *ok_button;
683   GtkWidget *cancel_button;
684
685   openfilewin = gtk_file_selection_new ("Select File");
686   gtk_container_set_border_width (GTK_CONTAINER (openfilewin), 10);
687
688   ok_button = GTK_FILE_SELECTION (openfilewin)->ok_button;
689   gtk_widget_show (ok_button);
690   GTK_WIDGET_SET_FLAGS (ok_button, GTK_CAN_DEFAULT);
691
692   cancel_button = GTK_FILE_SELECTION (openfilewin)->cancel_button;
693   gtk_widget_show (cancel_button);
694   GTK_WIDGET_SET_FLAGS (cancel_button, GTK_CAN_DEFAULT);
695
696   return openfilewin;
697 }
698
699 GtkWidget* create_savefilewin (void)
700 {
701   GtkWidget *ok_button;
702   GtkWidget *cancel_button;
703
704   savefilewin = gtk_file_selection_new ("Select File");
705   gtk_container_set_border_width (GTK_CONTAINER (savefilewin), 10);
706
707   ok_button = GTK_FILE_SELECTION (savefilewin)->ok_button;
708   gtk_widget_show (ok_button);
709   GTK_WIDGET_SET_FLAGS (ok_button, GTK_CAN_DEFAULT);
710
711   cancel_button = GTK_FILE_SELECTION (savefilewin)->cancel_button;
712   gtk_widget_show (cancel_button);
713   GTK_WIDGET_SET_FLAGS (cancel_button, GTK_CAN_DEFAULT);
714
715   return savefilewin;
716 }
717
718 int main (int argc, char *argv[])
719 {
720   poptContext pc;
721   const char *backend = NULL, *credentials = NULL, *location;
722   int opt;
723   struct poptOption long_options[] = {
724        POPT_AUTOHELP
725        {"backend", 'b', POPT_ARG_STRING, &backend, 0, "backend to use", NULL},
726            {"credentials", 'c', POPT_ARG_STRING, &credentials, 0, "credentials (user%%password)", NULL},
727        POPT_TABLEEND
728     };
729                                                                               
730     gtk_init (&argc, &argv);
731
732     pc = poptGetContext(argv[0], argc, (const char **) argv, long_options,0);
733                                                                               
734     while((opt = poptGetNextOpt(pc)) != -1) {
735     }
736
737         location = poptGetArg(pc);
738
739         if(location) {
740                 WERROR error;
741
742                 if(!backend) {
743                         if(credentials)backend = "rpc";
744                         else backend = "nt4";
745                 }
746                 
747                 error = reg_open(backend, location, credentials, &registry);
748                 if(!W_ERROR_IS_OK(error)) {
749                         gtk_show_werror(error);
750                         return -1;
751                 }
752                 mainwin = create_mainwin ();
753                 registry_load_root();
754         } else 
755                 mainwin = create_mainwin ();
756
757         gtk_widget_show (mainwin);
758
759         gtk_main ();
760
761         if(registry)reg_free(registry);
762         return 0;
763 }