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