f7f5b3528aa3e1b753a4de0cb738559a20f86aa9
[samba.git] / source / gtk / 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 #include "includes.h"
23 #include "gtk/common/gtk-smb.h"
24
25 GtkWidget *openfilewin;
26 GtkWidget *savefilewin;
27 GtkTreeStore *store_keys;
28 GtkListStore *store_vals;
29 GtkWidget *tree_keys;
30 GtkWidget *mainwin;
31 TALLOC_CTX *mem_ctx; /* FIXME: Split up */
32
33 GtkWidget *save;
34 GtkWidget *save_as;
35 static GtkWidget* create_openfilewin (void);
36 static GtkWidget* create_savefilewin (void);
37 struct registry_context *registry = NULL;
38
39 static void expand_key(GtkTreeView *treeview, GtkTreeIter *parent, GtkTreePath *arg2)
40 {
41         GtkTreeIter firstiter, iter, tmpiter;
42         struct registry_key *k, *sub;
43         char *name;
44         WERROR error;
45         int i;
46
47     gtk_tree_model_iter_children(GTK_TREE_MODEL(store_keys), &firstiter, parent);
48
49     /* See if this row has ever had a name gtk_tree_store_set()'ed to it.
50        If not, read the directory contents */
51     gtk_tree_model_get(GTK_TREE_MODEL(store_keys), &firstiter, 0, &name, -1);
52
53         if(name) return;
54
55         gtk_tree_model_get(GTK_TREE_MODEL(store_keys), parent, 1, &k, -1);
56
57         g_assert(k);
58         
59         for(i = 0; W_ERROR_IS_OK(error = reg_key_get_subkey_by_index(mem_ctx, k, i, &sub)); i++) {
60                 int count;
61                 /* Replace the blank child with the first directory entry
62            You may be tempted to remove the blank child node and then 
63            append a new one.  Don't.  If you remove the blank child 
64            node GTK gets confused and won't expand the parent row. */
65
66                 if(i == 0) {
67                         iter = firstiter;
68                 } else {
69                         gtk_tree_store_append(store_keys, &iter, parent);
70                 }
71                 gtk_tree_store_set (store_keys,
72                                             &iter, 
73                                                 0,
74                                                 sub->name,
75                                                 1, 
76                                                 sub,
77                                                 -1);
78                 
79                 if(W_ERROR_IS_OK(reg_key_num_subkeys(sub, &count)) && count > 0) 
80                         gtk_tree_store_append(store_keys, &tmpiter, &iter);
81         }
82
83         if(!W_ERROR_EQUAL(error, WERR_NO_MORE_ITEMS)) gtk_show_werror(mainwin, error);
84 }
85
86 static void registry_load_root(void) 
87 {
88         struct registry_key *root;
89         GtkTreeIter iter, tmpiter;
90         int i = 0;
91         if(!registry) return;
92
93         gtk_tree_store_clear(store_keys);
94
95         for(i = 0; i < registry->num_hives; i++) 
96         {
97                 root = registry->hives[i]->root;
98
99                 /* Add the root */
100                 gtk_tree_store_append(store_keys, &iter, NULL);
101                 gtk_tree_store_set (store_keys,
102                                             &iter, 
103                                                 0,
104                                                 root->hive->name?root->hive->name:"",
105                                                 1,
106                                                 root,
107                                                 -1);
108
109                 gtk_tree_store_append(store_keys, &tmpiter, &iter);
110         }
111
112         gtk_widget_set_sensitive( save, True );
113         gtk_widget_set_sensitive( save_as, True );
114 }
115
116 static void on_open_file_activate (GtkMenuItem *menuitem, gpointer user_data)
117 {
118         gint result = gtk_dialog_run(GTK_DIALOG(create_openfilewin()));
119         char *filename, *tmp;
120         WERROR error;
121         switch(result) {
122         case GTK_RESPONSE_OK:
123                 filename = strdup(gtk_file_selection_get_filename(GTK_FILE_SELECTION(openfilewin)));
124                 error = reg_open(&registry, user_data, filename, NULL);
125                 if(!W_ERROR_IS_OK(error)) {
126                         gtk_show_werror(mainwin, error);
127                         break;
128                 }
129
130                 tmp = g_strdup_printf("Registry Editor - %s", filename);
131                 gtk_window_set_title (GTK_WINDOW (mainwin), tmp);
132                 g_free(tmp);
133                 registry_load_root();
134                 break;
135         default:
136                 break;
137         }
138
139         gtk_widget_destroy(openfilewin);
140 }
141
142 static void on_open_gconf_activate                       (GtkMenuItem     *menuitem,
143                                                       gpointer         user_data)
144 {
145         WERROR error = reg_open(&registry, "gconf", NULL, NULL);
146         if(!W_ERROR_IS_OK(error)) {
147                 gtk_show_werror(mainwin, error);
148                 return;
149         }
150
151         gtk_window_set_title (GTK_WINDOW (mainwin), "Registry Editor - GConf");
152
153         registry_load_root();
154 }
155
156 static void on_open_remote_activate(GtkMenuItem *menuitem, gpointer user_data)
157 {
158         char *credentials;
159         const char *location;
160         char *tmp;
161         GtkWidget *rpcwin = GTK_WIDGET(gtk_rpc_binding_dialog_new(TRUE));
162         gint result = gtk_dialog_run(GTK_DIALOG(rpcwin));
163         WERROR error;
164         
165         if(result != GTK_RESPONSE_ACCEPT)
166         {
167                 gtk_widget_destroy(rpcwin);
168                 return;
169         }
170
171         location = gtk_rpc_binding_dialog_get_binding(GTK_RPC_BINDING_DIALOG(rpcwin), NULL);
172         asprintf(&credentials, "%s%%%s", gtk_rpc_binding_dialog_get_username(GTK_RPC_BINDING_DIALOG(rpcwin)), gtk_rpc_binding_dialog_get_password(GTK_RPC_BINDING_DIALOG(rpcwin)));
173         error = reg_open(&registry, "rpc", location, credentials);
174
175         if(!W_ERROR_IS_OK(error)) {
176                 gtk_show_werror(mainwin, error);
177                 gtk_widget_destroy(rpcwin);
178                 return;
179         }
180         free(credentials);
181
182         tmp = g_strdup_printf("Registry Editor - Remote Registry at %s", gtk_rpc_binding_dialog_get_host(GTK_RPC_BINDING_DIALOG(rpcwin)));
183         gtk_window_set_title (GTK_WINDOW (mainwin), tmp);
184         g_free(tmp);
185
186         registry_load_root();
187
188
189         gtk_widget_destroy(rpcwin);
190 }
191
192
193 static void on_save_activate                       (GtkMenuItem     *menuitem,
194                                                                                                         gpointer         user_data)
195 {
196         WERROR error = reg_save(registry, NULL);
197         if(!W_ERROR_IS_OK(error)) {
198                 gtk_show_werror(mainwin, error);
199         }
200 }
201
202
203 static void on_save_as_activate                    (GtkMenuItem     *menuitem,
204                                                                                 gpointer         user_data)
205 {
206         gint result;
207         WERROR error;
208         create_savefilewin();
209         result = gtk_dialog_run(GTK_DIALOG(savefilewin));
210         switch(result) {
211         case GTK_RESPONSE_OK:
212                 error = reg_save(registry, gtk_file_selection_get_filename(GTK_FILE_SELECTION(savefilewin)));
213                 if(!W_ERROR_IS_OK(error)) {
214                         gtk_show_werror(mainwin, error);
215                 }
216                 break;
217
218         default:
219                 break;
220
221         }
222         gtk_widget_destroy(savefilewin);
223 }
224
225
226 static void on_quit_activate                       (GtkMenuItem     *menuitem,
227                                                                                 gpointer         user_data)
228 {
229         gtk_main_quit();
230 }
231
232
233 static void on_cut_activate                        (GtkMenuItem     *menuitem,
234                                                                                 gpointer         user_data)
235 {
236         /* FIXME */
237 }
238
239
240 static void on_copy_activate                       (GtkMenuItem     *menuitem,
241                                                                                 gpointer         user_data)
242 {
243         /* FIXME */
244 }
245
246
247 static void on_paste_activate                      (GtkMenuItem     *menuitem,
248                                                                                 gpointer         user_data)
249 {
250         /* FIXME */
251 }
252
253
254 static void on_delete_activate                     (GtkMenuItem     *menuitem,
255                                                                                 gpointer         user_data)
256 {
257         /* FIXME */
258 }
259
260
261 static void on_about_activate                      (GtkMenuItem     *menuitem,
262                                                                                 gpointer         user_data)
263 {
264         GtkDialog *aboutwin = GTK_DIALOG(create_gtk_samba_about_dialog("gregedit"));
265         gtk_dialog_run(aboutwin);
266         gtk_widget_destroy(GTK_WIDGET(aboutwin));
267 }
268
269 gboolean on_key_activate(GtkTreeSelection *selection,
270                                              GtkTreeModel *model,
271                                              GtkTreePath *path,
272                                              gboolean path_currently_selected,
273                                              gpointer data)
274 {
275         int i;
276         struct registry_key *k;
277         struct registry_value *val;
278         WERROR error;
279         GtkTreeIter parent;
280         if(path_currently_selected)return TRUE;
281
282         gtk_tree_model_get_iter(GTK_TREE_MODEL(store_keys), &parent, path);
283         gtk_tree_model_get(GTK_TREE_MODEL(store_keys), &parent, 1, &k, -1);
284
285         g_assert(k);
286
287         gtk_list_store_clear(store_vals);
288
289         for(i = 0; W_ERROR_IS_OK(error = reg_key_get_value_by_index(mem_ctx, k, i, &val)); i++) {
290                 GtkTreeIter iter;
291                 gtk_list_store_append(store_vals, &iter);
292                 gtk_list_store_set (store_vals,
293                                             &iter, 
294                                                 0,
295                                                 val->name,
296                                                 1,
297                                                 str_regtype(val->data_type),
298                                                 2,
299                                                 reg_val_data_string(mem_ctx, val),
300                                                 3, 
301                                                 val,
302                                                 -1);
303         }
304
305         if(!W_ERROR_EQUAL(error, WERR_NO_MORE_ITEMS)) {
306                  gtk_show_werror(mainwin, error);
307                  return FALSE;
308         }
309         return TRUE;
310 }
311
312 static GtkWidget* create_mainwin (void)
313 {
314         GtkWidget *vbox1;
315         GtkWidget *menubar;
316         GtkWidget *menu_file;
317         GtkWidget *menu_file_menu;
318         GtkWidget *open_nt4;
319         GtkWidget *open_ldb;
320         GtkWidget *open_w95;
321         GtkWidget *open_gconf;
322         GtkWidget *open_remote;
323         GtkWidget *separatormenuitem1;
324         GtkWidget *quit;
325         GtkWidget *men_edit;
326         GtkWidget *men_edit_menu;
327         GtkWidget *cut;
328         GtkWidget *copy;
329         GtkWidget *paste;
330         GtkWidget *delete;
331         GtkCellRenderer *renderer;
332         GtkTreeViewColumn *curcol;
333         GtkWidget *help;
334         GtkWidget *help_menu;
335         GtkWidget *about;
336         GtkWidget *hbox1;
337         GtkWidget *scrolledwindow1;
338         GtkWidget *scrolledwindow2;
339         GtkWidget *tree_vals;
340         GtkWidget *statusbar;
341         GtkAccelGroup *accel_group;
342
343         accel_group = gtk_accel_group_new ();
344
345         mainwin = gtk_window_new (GTK_WINDOW_TOPLEVEL);
346         gtk_window_set_title (GTK_WINDOW (mainwin), "Registry editor");
347         gtk_window_set_default_size (GTK_WINDOW (mainwin), 642, 562);
348
349         vbox1 = gtk_vbox_new (FALSE, 0);
350         gtk_widget_show (vbox1);
351         gtk_container_add (GTK_CONTAINER (mainwin), vbox1);
352
353         menubar = gtk_menu_bar_new ();
354         gtk_widget_show (menubar);
355         gtk_box_pack_start (GTK_BOX (vbox1), menubar, FALSE, FALSE, 0);
356
357         menu_file = gtk_menu_item_new_with_mnemonic ("_File");
358         gtk_widget_show (menu_file);
359         gtk_container_add (GTK_CONTAINER (menubar), menu_file);
360
361         menu_file_menu = gtk_menu_new ();
362         gtk_menu_item_set_submenu (GTK_MENU_ITEM (menu_file), menu_file_menu);
363
364         if(reg_has_backend("nt4")) {
365                 open_nt4 = gtk_image_menu_item_new_with_mnemonic("Open _NT4 file");
366                 gtk_widget_show (open_nt4);
367                 gtk_container_add (GTK_CONTAINER (menu_file_menu), open_nt4);
368
369                 g_signal_connect ((gpointer) open_nt4, "activate",
370                                                   G_CALLBACK (on_open_file_activate),
371                                                   (gconstpointer)"nt4");
372         }
373
374         if(reg_has_backend("w95")) {
375                 open_w95 = gtk_image_menu_item_new_with_mnemonic("Open Win_9x file");
376                 gtk_widget_show (open_w95);
377                 gtk_container_add (GTK_CONTAINER (menu_file_menu), open_w95);
378
379                 g_signal_connect ((gpointer) open_w95, "activate",
380                                                   G_CALLBACK (on_open_file_activate),
381                                                   (gconstpointer)"w95");
382         }
383
384         if(reg_has_backend("gconf")) {
385                 open_gconf = gtk_image_menu_item_new_with_mnemonic ("Open _GConf");
386                 gtk_widget_show (open_gconf);
387                 gtk_container_add (GTK_CONTAINER (menu_file_menu), open_gconf);
388
389                 g_signal_connect ((gpointer) open_gconf, "activate",
390                                                   G_CALLBACK (on_open_gconf_activate),
391                                                   NULL);
392         }
393
394         if(reg_has_backend("rpc")) {
395                 open_remote = gtk_menu_item_new_with_mnemonic ("Open _Remote");
396                 gtk_widget_show (open_remote);
397                 gtk_container_add (GTK_CONTAINER (menu_file_menu), open_remote);
398
399                 g_signal_connect ((gpointer) open_remote, "activate",
400                                                   G_CALLBACK (on_open_remote_activate),
401                                                   NULL);
402         }
403
404         if(reg_has_backend("ldb")) {
405                 open_ldb = gtk_image_menu_item_new_with_mnemonic("Open _LDB file");
406                 gtk_widget_show (open_ldb);
407                 gtk_container_add (GTK_CONTAINER (menu_file_menu), open_ldb);
408
409                 g_signal_connect ((gpointer) open_ldb, "activate",
410                                                   G_CALLBACK (on_open_file_activate),
411                                                   (gconstpointer)"ldb");
412         }
413
414         save = gtk_image_menu_item_new_from_stock ("gtk-save", accel_group);
415         gtk_widget_show (save);
416         gtk_widget_set_sensitive( save, False );
417         gtk_container_add (GTK_CONTAINER (menu_file_menu), save);
418
419         save_as = gtk_image_menu_item_new_from_stock ("gtk-save-as", accel_group);
420         gtk_widget_show (save_as);
421         gtk_widget_set_sensitive( save_as, False );
422         gtk_container_add (GTK_CONTAINER (menu_file_menu), save_as);
423
424         separatormenuitem1 = gtk_menu_item_new ();
425         gtk_widget_show (separatormenuitem1);
426         gtk_container_add (GTK_CONTAINER (menu_file_menu), separatormenuitem1);
427         gtk_widget_set_sensitive (separatormenuitem1, FALSE);
428
429         quit = gtk_image_menu_item_new_from_stock ("gtk-quit", accel_group);
430         gtk_widget_show (quit);
431         gtk_container_add (GTK_CONTAINER (menu_file_menu), quit);
432
433         men_edit = gtk_menu_item_new_with_mnemonic ("_Edit");
434         gtk_widget_show (men_edit);
435         gtk_container_add (GTK_CONTAINER (menubar), men_edit);
436
437         men_edit_menu = gtk_menu_new ();
438         gtk_menu_item_set_submenu (GTK_MENU_ITEM (men_edit), men_edit_menu);
439
440         cut = gtk_image_menu_item_new_from_stock ("gtk-cut", accel_group);
441         gtk_widget_show (cut);
442         gtk_widget_set_sensitive(cut, False);
443         gtk_container_add (GTK_CONTAINER (men_edit_menu), cut);
444
445         copy = gtk_image_menu_item_new_from_stock ("gtk-copy", accel_group);
446         gtk_widget_show (copy);
447         gtk_widget_set_sensitive(copy, False);
448         gtk_container_add (GTK_CONTAINER (men_edit_menu), copy);
449
450         paste = gtk_image_menu_item_new_from_stock ("gtk-paste", accel_group);
451         gtk_widget_show (paste);
452         gtk_widget_set_sensitive(paste, False);
453         gtk_container_add (GTK_CONTAINER (men_edit_menu), paste);
454
455         delete = gtk_image_menu_item_new_from_stock ("gtk-delete", accel_group);
456         gtk_widget_show (delete);
457         gtk_widget_set_sensitive(delete, False);
458         gtk_container_add (GTK_CONTAINER (men_edit_menu), delete);
459
460         help = gtk_menu_item_new_with_mnemonic ("_Help");
461         gtk_widget_show (help);
462         gtk_container_add (GTK_CONTAINER (menubar), help);
463
464         help_menu = gtk_menu_new ();
465         gtk_menu_item_set_submenu (GTK_MENU_ITEM (help), help_menu);
466
467         about = gtk_menu_item_new_with_mnemonic ("_About");
468         gtk_widget_show (about);
469         gtk_container_add (GTK_CONTAINER (help_menu), about);
470
471         hbox1 = gtk_hbox_new (FALSE, 0);
472         gtk_widget_show (hbox1);
473         gtk_box_pack_start (GTK_BOX (vbox1), hbox1, TRUE, TRUE, 0);
474
475         scrolledwindow1 = gtk_scrolled_window_new (NULL, NULL);
476         gtk_widget_show (scrolledwindow1);
477         gtk_box_pack_start (GTK_BOX (hbox1), scrolledwindow1, TRUE, TRUE, 0);
478
479         tree_keys = gtk_tree_view_new ();
480
481         /* Column names */
482         curcol = gtk_tree_view_column_new ();
483         gtk_tree_view_column_set_title(curcol, "Name");
484         renderer = gtk_cell_renderer_text_new();
485         gtk_tree_view_column_pack_start(curcol, renderer, True);
486
487         gtk_tree_view_append_column(GTK_TREE_VIEW(tree_keys), curcol);
488
489         gtk_tree_view_column_add_attribute(curcol, renderer, "text", 0);
490         gtk_widget_show (tree_keys);
491         gtk_container_add (GTK_CONTAINER (scrolledwindow1), tree_keys);
492         store_keys = gtk_tree_store_new(2, G_TYPE_STRING, G_TYPE_POINTER);
493         gtk_tree_view_set_model(GTK_TREE_VIEW(tree_keys), GTK_TREE_MODEL(store_keys));
494         g_object_unref(store_keys);
495
496         gtk_tree_selection_set_select_function (gtk_tree_view_get_selection(GTK_TREE_VIEW(tree_keys)), on_key_activate, NULL, NULL);
497
498         g_signal_connect ((gpointer) tree_keys, "row-expanded",
499                                           G_CALLBACK (expand_key),
500                                           NULL);
501
502
503         scrolledwindow2 = gtk_scrolled_window_new (NULL, NULL);
504         gtk_widget_show (scrolledwindow2);
505         gtk_box_pack_start (GTK_BOX (hbox1), scrolledwindow2, TRUE, TRUE, 0);
506
507         tree_vals = gtk_tree_view_new ();
508         /* Column names */
509
510         curcol = gtk_tree_view_column_new ();
511         gtk_tree_view_column_set_title(curcol, "Name");
512         renderer = gtk_cell_renderer_text_new();
513         gtk_tree_view_column_pack_start(curcol, renderer, True);
514         gtk_tree_view_append_column(GTK_TREE_VIEW(tree_vals), curcol);
515         gtk_tree_view_column_add_attribute(curcol, renderer, "text", 0);
516
517         curcol = gtk_tree_view_column_new ();
518         gtk_tree_view_column_set_title(curcol, "Type");
519         renderer = gtk_cell_renderer_text_new();
520         gtk_tree_view_column_pack_start(curcol, renderer, True);
521         gtk_tree_view_append_column(GTK_TREE_VIEW(tree_vals), curcol);
522         gtk_tree_view_column_add_attribute(curcol, renderer, "text", 1);
523
524         curcol = gtk_tree_view_column_new ();
525         gtk_tree_view_column_set_title(curcol, "Value");
526         renderer = gtk_cell_renderer_text_new();
527         gtk_tree_view_column_pack_start(curcol, renderer, True);
528         gtk_tree_view_append_column(GTK_TREE_VIEW(tree_vals), curcol);
529         gtk_tree_view_column_add_attribute(curcol, renderer, "text", 2);
530
531
532         gtk_widget_show (tree_vals);
533         gtk_container_add (GTK_CONTAINER (scrolledwindow2), tree_vals);
534
535         store_vals = gtk_list_store_new(4, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_POINTER);
536         gtk_tree_view_set_model(GTK_TREE_VIEW(tree_vals), GTK_TREE_MODEL(store_vals));
537         g_object_unref(store_vals);
538
539         statusbar = gtk_statusbar_new ();
540         gtk_widget_show (statusbar);
541         gtk_box_pack_start (GTK_BOX (vbox1), statusbar, FALSE, FALSE, 0);
542         gtk_statusbar_set_has_resize_grip (GTK_STATUSBAR (statusbar), FALSE);
543
544         g_signal_connect ((gpointer) save, "activate",
545                                           G_CALLBACK (on_save_activate),
546                                           NULL);
547         g_signal_connect ((gpointer) save_as, "activate",
548                                           G_CALLBACK (on_save_as_activate),
549                                           NULL);
550         g_signal_connect ((gpointer) quit, "activate",
551                                           G_CALLBACK (on_quit_activate),
552                                           NULL);
553         g_signal_connect ((gpointer) cut, "activate",
554                                           G_CALLBACK (on_cut_activate),
555                                           NULL);
556         g_signal_connect ((gpointer) copy, "activate",
557                                           G_CALLBACK (on_copy_activate),
558                                           NULL);
559         g_signal_connect ((gpointer) paste, "activate",
560                                           G_CALLBACK (on_paste_activate),
561                                           NULL);
562         g_signal_connect ((gpointer) delete, "activate",
563                                           G_CALLBACK (on_delete_activate),
564                                           NULL);
565         g_signal_connect ((gpointer) about, "activate",
566                                           G_CALLBACK (on_about_activate),
567                                           NULL);
568
569         gtk_window_add_accel_group (GTK_WINDOW (mainwin), accel_group);
570
571         return mainwin;
572 }
573
574 static GtkWidget* create_openfilewin (void)
575 {
576         GtkWidget *ok_button;
577         GtkWidget *cancel_button;
578
579         openfilewin = gtk_file_selection_new ("Select File");
580         gtk_container_set_border_width (GTK_CONTAINER (openfilewin), 10);
581
582         ok_button = GTK_FILE_SELECTION (openfilewin)->ok_button;
583         gtk_widget_show (ok_button);
584         GTK_WIDGET_SET_FLAGS (ok_button, GTK_CAN_DEFAULT);
585
586         cancel_button = GTK_FILE_SELECTION (openfilewin)->cancel_button;
587         gtk_widget_show (cancel_button);
588         GTK_WIDGET_SET_FLAGS (cancel_button, GTK_CAN_DEFAULT);
589
590         return openfilewin;
591 }
592
593 static GtkWidget* create_savefilewin (void)
594 {
595         GtkWidget *ok_button;
596         GtkWidget *cancel_button;
597
598         savefilewin = gtk_file_selection_new ("Select File");
599         gtk_container_set_border_width (GTK_CONTAINER (savefilewin), 10);
600
601         ok_button = GTK_FILE_SELECTION (savefilewin)->ok_button;
602         gtk_widget_show (ok_button);
603         GTK_WIDGET_SET_FLAGS (ok_button, GTK_CAN_DEFAULT);
604
605         cancel_button = GTK_FILE_SELECTION (savefilewin)->cancel_button;
606         gtk_widget_show (cancel_button);
607         GTK_WIDGET_SET_FLAGS (cancel_button, GTK_CAN_DEFAULT);
608
609         return savefilewin;
610 }
611
612  int main(int argc, char *argv[])
613 {
614         poptContext pc;
615         const char *backend = NULL;
616         const char *credentials = NULL;
617         const char *location;
618         int opt;
619         struct poptOption long_options[] = {
620                 POPT_AUTOHELP
621                 {"backend", 'b', POPT_ARG_STRING, &backend, 0, "backend to use", NULL},
622                 {"credentials", 'c', POPT_ARG_STRING, &credentials, 0, "credentials (user%%password)", NULL},
623                 POPT_TABLEEND
624         };
625
626         lp_load(dyn_CONFIGFILE,True,False,False);
627         load_interfaces();
628
629         gtk_init (&argc, &argv);
630         mem_ctx = talloc_init("gregedit");
631
632         pc = poptGetContext(argv[0], argc, (const char **) argv, long_options,0);
633
634         while((opt = poptGetNextOpt(pc)) != -1) {
635         }
636
637         location = poptGetArg(pc);
638
639         if(location) {
640                 WERROR error;
641
642                 if(!backend) {
643                         if(credentials)backend = "rpc";
644                         else backend = "nt4";
645                 }
646
647                 error = reg_open(&registry, backend, location, credentials);
648                 if(!W_ERROR_IS_OK(error)) {
649                         gtk_show_werror(mainwin, error);
650                         return -1;
651                 }
652                 mainwin = create_mainwin ();
653                 registry_load_root();
654         } else {
655                 mainwin = create_mainwin ();
656         }
657
658         gtk_widget_show (mainwin);
659
660         gtk_main ();
661
662         if(registry)talloc_destroy(registry->mem_ctx);
663         talloc_destroy(mem_ctx);
664         return 0;
665 }