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