r165: Add support for viewing registry values in gregedit
[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                 /* Replace the blank child with the first directory entry
88            You may be tempted to remove the blank child node and then 
89            append a new one.  Don't.  If you remove the blank child 
90            node GTK gets confused and won't expand the parent row. */
91
92                 if(i == 0) {
93                     gtk_tree_model_iter_children(GTK_TREE_MODEL(store_keys), 
94                                      &iter, parent);
95                 } else {
96                         gtk_tree_store_append(store_keys, &iter, parent);
97                 }
98                 gtk_tree_store_set (store_keys,
99                                             &iter, 
100                                                 0,
101                                                 reg_key_name(sub),
102                                                 1, 
103                                                 sub,
104                                                 -1);
105                 
106                 gtk_tree_store_append(store_keys, &tmpiter, &iter);
107         }
108
109         /* Remove placeholder child */
110         if(i == 0) {
111             gtk_tree_model_iter_children(GTK_TREE_MODEL(store_keys), 
112                                      &iter, parent);
113                 gtk_tree_store_remove(store_keys, &iter);
114         }
115
116         if(!W_ERROR_EQUAL(error, WERR_NO_MORE_ITEMS)) gtk_show_werror(error);
117 }
118
119 static void registry_load_root() 
120 {
121         REG_KEY *root;
122         GtkTreeIter iter, tmpiter;
123         WERROR error;
124         if(!registry) return;
125
126         error = reg_get_root(registry, &root);
127         if(!W_ERROR_IS_OK(error)) {
128                 gtk_show_werror(error);
129                 return;
130         }
131
132         gtk_tree_store_clear(store_keys);
133
134         /* Add the root */
135         gtk_tree_store_append(store_keys, &iter, NULL);
136         gtk_tree_store_set (store_keys,
137                                             &iter, 
138                                                 0,
139                                                 reg_key_name(root),
140                                                 1,
141                                                 root,
142                                                 -1);
143
144         gtk_tree_store_append(store_keys, &tmpiter, &iter);
145
146         gtk_widget_set_sensitive( save, True );
147         gtk_widget_set_sensitive( save_as, True );
148 }
149
150 GtkWidget* create_rpcwin (void)
151 {
152   GtkWidget *dialog_vbox1;
153   GtkWidget *table1;
154   GtkWidget *label1;
155   GtkWidget *label2;
156   GtkWidget *label3;
157   GtkWidget *dialog_action_area1;
158   GtkWidget *cancelbutton1;
159   GtkWidget *okbutton1;
160
161   rpcwin = gtk_dialog_new ();
162   gtk_window_set_title (GTK_WINDOW (rpcwin), "Connect to remote server");
163
164   dialog_vbox1 = GTK_DIALOG (rpcwin)->vbox;
165   gtk_widget_show (dialog_vbox1);
166
167   table1 = gtk_table_new (3, 2, FALSE);
168   gtk_widget_show (table1);
169   gtk_box_pack_start (GTK_BOX (dialog_vbox1), table1, TRUE, TRUE, 0);
170
171   label1 = gtk_label_new ("Host:");
172   gtk_widget_show (label1);
173   gtk_table_attach (GTK_TABLE (table1), label1, 0, 1, 0, 1,
174                     (GtkAttachOptions) (GTK_FILL),
175                     (GtkAttachOptions) (0), 0, 0);
176   gtk_misc_set_alignment (GTK_MISC (label1), 0, 0.5);
177
178   label2 = gtk_label_new ("User:");
179   gtk_widget_show (label2);
180   gtk_table_attach (GTK_TABLE (table1), label2, 0, 1, 1, 2,
181                     (GtkAttachOptions) (GTK_FILL),
182                     (GtkAttachOptions) (0), 0, 0);
183   gtk_misc_set_alignment (GTK_MISC (label2), 0, 0.5);
184
185   label3 = gtk_label_new ("Password:");
186   gtk_widget_show (label3);
187   gtk_table_attach (GTK_TABLE (table1), label3, 0, 1, 2, 3,
188                     (GtkAttachOptions) (GTK_FILL),
189                     (GtkAttachOptions) (0), 0, 0);
190   gtk_misc_set_alignment (GTK_MISC (label3), 0, 0.5);
191
192   rpcwin_host = gtk_entry_new ();
193   gtk_widget_show (rpcwin_host);
194   gtk_table_attach (GTK_TABLE (table1), rpcwin_host, 1, 2, 0, 1,
195                     (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
196                     (GtkAttachOptions) (0), 0, 0);
197
198   rpcwin_user = gtk_entry_new ();
199   gtk_widget_show (rpcwin_user);
200   gtk_table_attach (GTK_TABLE (table1), rpcwin_user, 1, 2, 1, 2,
201                     (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
202                     (GtkAttachOptions) (0), 0, 0);
203
204   rpcwin_password = gtk_entry_new ();
205   gtk_widget_show (rpcwin_password);
206   gtk_table_attach (GTK_TABLE (table1), rpcwin_password, 1, 2, 2, 3,
207                     (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
208                     (GtkAttachOptions) (0), 0, 0);
209   gtk_entry_set_visibility (GTK_ENTRY (rpcwin_password), FALSE);
210
211   dialog_action_area1 = GTK_DIALOG (rpcwin)->action_area;
212   gtk_widget_show (dialog_action_area1);
213   gtk_button_box_set_layout (GTK_BUTTON_BOX (dialog_action_area1), GTK_BUTTONBOX_END);
214
215   cancelbutton1 = gtk_button_new_from_stock ("gtk-cancel");
216   gtk_widget_show (cancelbutton1);
217   gtk_dialog_add_action_widget (GTK_DIALOG (rpcwin), cancelbutton1, GTK_RESPONSE_CANCEL);
218   GTK_WIDGET_SET_FLAGS (cancelbutton1, GTK_CAN_DEFAULT);
219
220   okbutton1 = gtk_button_new_from_stock ("gtk-ok");
221   gtk_widget_show (okbutton1);
222   gtk_dialog_add_action_widget (GTK_DIALOG (rpcwin), okbutton1, GTK_RESPONSE_OK);
223   GTK_WIDGET_SET_FLAGS (okbutton1, GTK_CAN_DEFAULT);
224
225   return rpcwin;
226 }
227
228 static void on_open_nt4_activate (GtkMenuItem *menuitem, gpointer user_data)
229 {
230         gint result = gtk_dialog_run(GTK_DIALOG(create_openfilewin()));
231         char *filename;
232         WERROR error;
233         switch(result) {
234         case GTK_RESPONSE_OK:
235                 filename = strdup(gtk_file_selection_get_filename(GTK_FILE_SELECTION(openfilewin)));
236                 error = reg_open("nt4", filename, NULL, &registry);
237                 if(!W_ERROR_IS_OK(error)) {
238                         gtk_show_werror(error);
239                         break;
240                 }
241                 registry_load_root();
242                 break;
243         default:
244                 break;
245         }
246
247         gtk_widget_destroy(openfilewin);
248 }
249
250 void on_open_gconf_activate                       (GtkMenuItem     *menuitem,
251                                                       gpointer         user_data)
252 {
253         WERROR error = reg_open("gconf", NULL, NULL, &registry);
254         if(!W_ERROR_IS_OK(error)) {
255                 gtk_show_werror(error);
256                 return;
257         }
258
259         registry_load_root();
260 }
261
262 void
263 on_open_remote_activate                (GtkMenuItem     *menuitem,
264                                                                                 gpointer         user_data)
265 {
266         char *location, *credentials;
267         gint result = gtk_dialog_run(GTK_DIALOG(create_rpcwin()));
268         WERROR error;
269         switch(result) {
270         case GTK_RESPONSE_OK:
271                 asprintf(&location, "ncacn_np:%s", gtk_entry_get_text(GTK_ENTRY(rpcwin_host)));
272                 asprintf(&credentials, "%s%%%s", gtk_entry_get_text(GTK_ENTRY(rpcwin_user)), gtk_entry_get_text(GTK_ENTRY(rpcwin_password)));
273                 error = reg_open("rpc", location, credentials, &registry);
274                 if(!W_ERROR_IS_OK(error)) {
275                         gtk_show_werror(error);
276                         break;
277                 }
278                 free(location); free(credentials);
279                 registry_load_root();
280                 break;
281         default:
282                 break;
283         }
284
285         gtk_widget_destroy(rpcwin);
286 }
287
288
289 void
290 on_save_activate                       (GtkMenuItem     *menuitem,
291                                                                                 gpointer         user_data)
292 {
293         WERROR error = reg_save(registry, NULL);
294         if(!W_ERROR_IS_OK(error)) {
295                 gtk_show_werror(error);
296         }
297 }
298
299
300 void
301 on_save_as_activate                    (GtkMenuItem     *menuitem,
302                                                                                 gpointer         user_data)
303 {
304         gint result;
305         WERROR error;
306         create_savefilewin();
307         result = gtk_dialog_run(GTK_DIALOG(savefilewin));
308         switch(result) {
309         case GTK_RESPONSE_OK:
310                 error = reg_save(registry, gtk_file_selection_get_filename(GTK_FILE_SELECTION(savefilewin)));
311                 if(!W_ERROR_IS_OK(error)) {
312                         gtk_show_werror(error);
313                 }
314                 break;
315
316         default:
317                 break;
318
319         }
320         gtk_widget_destroy(savefilewin);
321 }
322
323
324 void
325 on_quit_activate                       (GtkMenuItem     *menuitem,
326                                                                                 gpointer         user_data)
327 {
328         gtk_main_quit();
329 }
330
331
332 void
333 on_cut_activate                        (GtkMenuItem     *menuitem,
334                                                                                 gpointer         user_data)
335 {
336         /* FIXME */
337 }
338
339
340 void
341 on_copy_activate                       (GtkMenuItem     *menuitem,
342                                                                                 gpointer         user_data)
343 {
344         /* FIXME */
345 }
346
347
348 void
349 on_paste_activate                      (GtkMenuItem     *menuitem,
350                                                                                 gpointer         user_data)
351 {
352         /* FIXME */
353 }
354
355
356 void
357 on_delete_activate                     (GtkMenuItem     *menuitem,
358                                                                                 gpointer         user_data)
359 {
360         /* FIXME */
361 }
362
363
364 void
365 on_about_activate                      (GtkMenuItem     *menuitem,
366                                                                                 gpointer         user_data)
367 {
368         gtk_dialog_run(GTK_DIALOG(create_aboutwin()));
369         gtk_widget_destroy(aboutwin);
370 }
371
372 void on_key_activate (GtkTreeView *treeview,
373                                           GtkTreePath *path,
374                                           gpointer user_data)
375 {
376         int i;
377         REG_KEY *k;
378         REG_VAL *val;
379         WERROR error;
380         GtkTreeIter parent;
381
382         gtk_tree_model_get_iter(GTK_TREE_MODEL(store_keys), &parent, path);
383         gtk_tree_model_get(GTK_TREE_MODEL(store_keys), &parent, 1, &k, -1);
384
385         g_assert(k);
386
387         gtk_list_store_clear(store_vals);
388
389         for(i = 0; W_ERROR_IS_OK(error = reg_key_get_value_by_index(k, i, &val)); i++) {
390                 GtkTreeIter iter;
391                 gtk_list_store_append(store_vals, &iter);
392                 gtk_list_store_set (store_vals,
393                                             &iter, 
394                                                 0,
395                                                 reg_val_name(val),
396                                                 1,
397                                                 str_regtype(reg_val_type(val)),
398                                                 2,
399                                                 reg_val_data_string(val),
400                                                 3, 
401                                                 val,
402                                                 -1);
403         }
404
405         if(!W_ERROR_EQUAL(error, WERR_NO_MORE_ITEMS)) gtk_show_werror(error);
406 }
407
408 GtkWidget* create_mainwin (void)
409 {
410         GtkWidget *vbox1;
411         GtkWidget *menubar;
412         GtkWidget *menu_file;
413         GtkWidget *menu_file_menu;
414         GtkWidget *open_nt4;
415         GtkWidget *open_gconf;
416         GtkWidget *open_remote;
417         GtkWidget *separatormenuitem1;
418         GtkWidget *quit;
419         GtkWidget *men_edit;
420         GtkWidget *men_edit_menu;
421         GtkWidget *cut;
422         GtkWidget *copy;
423         GtkWidget *paste;
424         GtkWidget *delete;
425         GtkCellRenderer *renderer;
426         GtkTreeViewColumn *curcol;
427         GtkWidget *help;
428         GtkWidget *help_menu;
429         GtkWidget *about;
430         GtkWidget *hbox1;
431         GtkWidget *scrolledwindow1;
432         GtkWidget *scrolledwindow2;
433         GtkWidget *tree_vals;
434         GtkWidget *statusbar;
435         GtkAccelGroup *accel_group;
436         GtkTreeIter iter, child;
437
438         accel_group = gtk_accel_group_new ();
439
440         mainwin = gtk_window_new (GTK_WINDOW_TOPLEVEL);
441         gtk_window_set_title (GTK_WINDOW (mainwin), "Registry editor");
442         gtk_window_set_default_size (GTK_WINDOW (mainwin), 642, 562);
443
444         vbox1 = gtk_vbox_new (FALSE, 0);
445         gtk_widget_show (vbox1);
446         gtk_container_add (GTK_CONTAINER (mainwin), vbox1);
447
448         menubar = gtk_menu_bar_new ();
449         gtk_widget_show (menubar);
450         gtk_box_pack_start (GTK_BOX (vbox1), menubar, FALSE, FALSE, 0);
451
452         menu_file = gtk_menu_item_new_with_mnemonic ("_File");
453         gtk_widget_show (menu_file);
454         gtk_container_add (GTK_CONTAINER (menubar), menu_file);
455
456         menu_file_menu = gtk_menu_new ();
457         gtk_menu_item_set_submenu (GTK_MENU_ITEM (menu_file), menu_file_menu);
458
459         open_nt4 = gtk_image_menu_item_new_with_mnemonic("_Open NT4 file");
460         gtk_widget_show (open_nt4);
461         gtk_container_add (GTK_CONTAINER (menu_file_menu), open_nt4);
462
463         open_gconf = gtk_image_menu_item_new_with_mnemonic ("_Open GConf");
464         gtk_widget_show (open_gconf);
465         gtk_container_add (GTK_CONTAINER (menu_file_menu), open_gconf);
466
467         open_remote = gtk_menu_item_new_with_mnemonic ("_Open Remote");
468         gtk_widget_show (open_remote);
469         gtk_container_add (GTK_CONTAINER (menu_file_menu), open_remote);
470
471         save = gtk_image_menu_item_new_from_stock ("gtk-save", accel_group);
472         gtk_widget_show (save);
473         gtk_widget_set_sensitive( save, False );
474         gtk_container_add (GTK_CONTAINER (menu_file_menu), save);
475
476         save_as = gtk_image_menu_item_new_from_stock ("gtk-save-as", accel_group);
477         gtk_widget_show (save_as);
478         gtk_widget_set_sensitive( save_as, False );
479         gtk_container_add (GTK_CONTAINER (menu_file_menu), save_as);
480
481         separatormenuitem1 = gtk_menu_item_new ();
482         gtk_widget_show (separatormenuitem1);
483         gtk_container_add (GTK_CONTAINER (menu_file_menu), separatormenuitem1);
484         gtk_widget_set_sensitive (separatormenuitem1, FALSE);
485
486         quit = gtk_image_menu_item_new_from_stock ("gtk-quit", accel_group);
487         gtk_widget_show (quit);
488         gtk_container_add (GTK_CONTAINER (menu_file_menu), quit);
489
490         men_edit = gtk_menu_item_new_with_mnemonic ("_Edit");
491         gtk_widget_show (men_edit);
492         gtk_container_add (GTK_CONTAINER (menubar), men_edit);
493
494   men_edit_menu = gtk_menu_new ();
495   gtk_menu_item_set_submenu (GTK_MENU_ITEM (men_edit), men_edit_menu);
496
497   cut = gtk_image_menu_item_new_from_stock ("gtk-cut", accel_group);
498   gtk_widget_show (cut);
499   gtk_widget_set_sensitive(cut, False);
500   gtk_container_add (GTK_CONTAINER (men_edit_menu), cut);
501
502   copy = gtk_image_menu_item_new_from_stock ("gtk-copy", accel_group);
503   gtk_widget_show (copy);
504   gtk_widget_set_sensitive(copy, False);
505   gtk_container_add (GTK_CONTAINER (men_edit_menu), copy);
506
507   paste = gtk_image_menu_item_new_from_stock ("gtk-paste", accel_group);
508   gtk_widget_show (paste);
509   gtk_widget_set_sensitive(paste, False);
510   gtk_container_add (GTK_CONTAINER (men_edit_menu), paste);
511
512   delete = gtk_image_menu_item_new_from_stock ("gtk-delete", accel_group);
513   gtk_widget_show (delete);
514   gtk_widget_set_sensitive(delete, False);
515   gtk_container_add (GTK_CONTAINER (men_edit_menu), delete);
516
517   help = gtk_menu_item_new_with_mnemonic ("_Help");
518   gtk_widget_show (help);
519   gtk_container_add (GTK_CONTAINER (menubar), help);
520
521   help_menu = gtk_menu_new ();
522   gtk_menu_item_set_submenu (GTK_MENU_ITEM (help), help_menu);
523
524   about = gtk_menu_item_new_with_mnemonic ("_About");
525   gtk_widget_show (about);
526   gtk_container_add (GTK_CONTAINER (help_menu), about);
527
528   hbox1 = gtk_hbox_new (FALSE, 0);
529   gtk_widget_show (hbox1);
530   gtk_box_pack_start (GTK_BOX (vbox1), hbox1, TRUE, TRUE, 0);
531
532   scrolledwindow1 = gtk_scrolled_window_new (NULL, NULL);
533   gtk_widget_show (scrolledwindow1);
534   gtk_box_pack_start (GTK_BOX (hbox1), scrolledwindow1, TRUE, TRUE, 0);
535
536   tree_keys = gtk_tree_view_new ();
537
538   /* Column names */
539   curcol = gtk_tree_view_column_new ();
540   gtk_tree_view_column_set_title(curcol, "Name");
541   renderer = gtk_cell_renderer_text_new();
542   gtk_tree_view_column_pack_start(curcol, renderer, True);
543
544   gtk_tree_view_append_column(GTK_TREE_VIEW(tree_keys), curcol);
545
546   gtk_tree_view_column_add_attribute(curcol, renderer, "text", 0);
547   gtk_widget_show (tree_keys);
548   gtk_container_add (GTK_CONTAINER (scrolledwindow1), tree_keys);
549   store_keys = gtk_tree_store_new(2, G_TYPE_STRING, G_TYPE_POINTER);
550   gtk_tree_view_set_model(GTK_TREE_VIEW(tree_keys), GTK_TREE_MODEL(store_keys));
551   g_object_unref(store_keys);
552
553   g_signal_connect ((gpointer) tree_keys, "row-activated",
554                     G_CALLBACK (on_key_activate),
555                     NULL);
556
557   g_signal_connect ((gpointer) tree_keys, "row-expanded",
558                     G_CALLBACK (expand_key),
559                     NULL);
560
561   scrolledwindow2 = gtk_scrolled_window_new (NULL, NULL);
562   gtk_widget_show (scrolledwindow2);
563   gtk_box_pack_start (GTK_BOX (hbox1), scrolledwindow2, TRUE, TRUE, 0);
564
565   tree_vals = gtk_tree_view_new ();
566     /* Column names */
567
568   curcol = gtk_tree_view_column_new ();
569   gtk_tree_view_column_set_title(curcol, "Name");
570   renderer = gtk_cell_renderer_text_new();
571   gtk_tree_view_column_pack_start(curcol, renderer, True);
572   gtk_tree_view_append_column(GTK_TREE_VIEW(tree_vals), curcol);
573   gtk_tree_view_column_add_attribute(curcol, renderer, "text", 0);
574
575   curcol = gtk_tree_view_column_new ();
576   gtk_tree_view_column_set_title(curcol, "Type");
577   renderer = gtk_cell_renderer_text_new();
578   gtk_tree_view_column_pack_start(curcol, renderer, True);
579   gtk_tree_view_append_column(GTK_TREE_VIEW(tree_vals), curcol);
580   gtk_tree_view_column_add_attribute(curcol, renderer, "text", 1);
581
582   curcol = gtk_tree_view_column_new ();
583   gtk_tree_view_column_set_title(curcol, "Value");
584   renderer = gtk_cell_renderer_text_new();
585   gtk_tree_view_column_pack_start(curcol, renderer, True);
586   gtk_tree_view_append_column(GTK_TREE_VIEW(tree_vals), curcol);
587   gtk_tree_view_column_add_attribute(curcol, renderer, "text", 2);
588
589   
590   gtk_widget_show (tree_vals);
591   gtk_container_add (GTK_CONTAINER (scrolledwindow2), tree_vals);
592
593   store_vals = gtk_list_store_new(4, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_POINTER);
594   gtk_tree_view_set_model(GTK_TREE_VIEW(tree_vals), GTK_TREE_MODEL(store_vals));
595   g_object_unref(store_vals);
596
597   statusbar = gtk_statusbar_new ();
598   gtk_widget_show (statusbar);
599   gtk_box_pack_start (GTK_BOX (vbox1), statusbar, FALSE, FALSE, 0);
600   gtk_statusbar_set_has_resize_grip (GTK_STATUSBAR (statusbar), FALSE);
601
602   g_signal_connect ((gpointer) open_nt4, "activate",
603                     G_CALLBACK (on_open_nt4_activate),
604                     NULL);
605   g_signal_connect ((gpointer) open_gconf, "activate",
606                     G_CALLBACK (on_open_gconf_activate),
607                     NULL);
608   g_signal_connect ((gpointer) open_remote, "activate",
609                     G_CALLBACK (on_open_remote_activate),
610                     NULL);
611   g_signal_connect ((gpointer) save, "activate",
612                     G_CALLBACK (on_save_activate),
613                     NULL);
614   g_signal_connect ((gpointer) save_as, "activate",
615                     G_CALLBACK (on_save_as_activate),
616                     NULL);
617   g_signal_connect ((gpointer) quit, "activate",
618                     G_CALLBACK (on_quit_activate),
619                     NULL);
620   g_signal_connect ((gpointer) cut, "activate",
621                     G_CALLBACK (on_cut_activate),
622                     NULL);
623   g_signal_connect ((gpointer) copy, "activate",
624                     G_CALLBACK (on_copy_activate),
625                     NULL);
626   g_signal_connect ((gpointer) paste, "activate",
627                     G_CALLBACK (on_paste_activate),
628                     NULL);
629   g_signal_connect ((gpointer) delete, "activate",
630                     G_CALLBACK (on_delete_activate),
631                     NULL);
632   g_signal_connect ((gpointer) about, "activate",
633                     G_CALLBACK (on_about_activate),
634                     NULL);
635
636   gtk_window_add_accel_group (GTK_WINDOW (mainwin), accel_group);
637
638   return mainwin;
639 }
640
641 static GtkWidget* create_aboutwin (void)
642 {
643   GtkWidget *dialog_vbox1;
644   GtkWidget *image1;
645   GtkWidget *label1;
646   GtkWidget *label2;
647   GtkWidget *dialog_action_area1;
648   GtkWidget *closebutton1;
649
650   aboutwin = gtk_dialog_new ();
651   gtk_window_set_title (GTK_WINDOW (aboutwin), "About GRegEdit");
652   gtk_window_set_resizable (GTK_WINDOW (aboutwin), FALSE);
653
654   dialog_vbox1 = GTK_DIALOG (aboutwin)->vbox;
655   gtk_widget_show (dialog_vbox1);
656
657   /* FIXME: Samba logo ? 
658   image1 = create_pixmap (aboutwin, "samba.png");
659   gtk_widget_show (image1);
660   gtk_box_pack_start (GTK_BOX (dialog_vbox1), image1, FALSE, TRUE, 0); */
661
662   label1 = gtk_label_new ("GRegEdit 0.1");
663   gtk_widget_show (label1);
664   gtk_box_pack_start (GTK_BOX (dialog_vbox1), label1, FALSE, FALSE, 0);
665   gtk_label_set_use_markup (GTK_LABEL (label1), TRUE);
666
667   label2 = gtk_label_new_with_mnemonic ("(C) 2004 Jelmer Vernooij <jelmer@samba.org>\nPart of Samba\nhttp://www.samba.org/\n");
668   gtk_widget_show (label2);
669   gtk_box_pack_start (GTK_BOX (dialog_vbox1), label2, TRUE, FALSE, 0);
670   gtk_label_set_use_markup (GTK_LABEL (label2), TRUE);
671
672   dialog_action_area1 = GTK_DIALOG (aboutwin)->action_area;
673   gtk_widget_show (dialog_action_area1);
674   gtk_button_box_set_layout (GTK_BUTTON_BOX (dialog_action_area1), GTK_BUTTONBOX_END);
675
676   closebutton1 = gtk_button_new_from_stock ("gtk-close");
677   gtk_widget_show (closebutton1);
678   gtk_dialog_add_action_widget (GTK_DIALOG (aboutwin), closebutton1, GTK_RESPONSE_CLOSE);
679   GTK_WIDGET_SET_FLAGS (closebutton1, GTK_CAN_DEFAULT);
680
681   return aboutwin;
682 }
683
684
685 GtkWidget* create_openfilewin (void)
686 {
687   GtkWidget *ok_button;
688   GtkWidget *cancel_button;
689
690   openfilewin = gtk_file_selection_new ("Select File");
691   gtk_container_set_border_width (GTK_CONTAINER (openfilewin), 10);
692
693   ok_button = GTK_FILE_SELECTION (openfilewin)->ok_button;
694   gtk_widget_show (ok_button);
695   GTK_WIDGET_SET_FLAGS (ok_button, GTK_CAN_DEFAULT);
696
697   cancel_button = GTK_FILE_SELECTION (openfilewin)->cancel_button;
698   gtk_widget_show (cancel_button);
699   GTK_WIDGET_SET_FLAGS (cancel_button, GTK_CAN_DEFAULT);
700
701   return openfilewin;
702 }
703
704 GtkWidget* create_savefilewin (void)
705 {
706   GtkWidget *ok_button;
707   GtkWidget *cancel_button;
708
709   savefilewin = gtk_file_selection_new ("Select File");
710   gtk_container_set_border_width (GTK_CONTAINER (savefilewin), 10);
711
712   ok_button = GTK_FILE_SELECTION (savefilewin)->ok_button;
713   gtk_widget_show (ok_button);
714   GTK_WIDGET_SET_FLAGS (ok_button, GTK_CAN_DEFAULT);
715
716   cancel_button = GTK_FILE_SELECTION (savefilewin)->cancel_button;
717   gtk_widget_show (cancel_button);
718   GTK_WIDGET_SET_FLAGS (cancel_button, GTK_CAN_DEFAULT);
719
720   return savefilewin;
721 }
722
723 int main (int argc, char *argv[])
724 {
725   poptContext pc;
726   const char *backend = NULL, *credentials = NULL, *location;
727   int opt;
728   struct poptOption long_options[] = {
729        POPT_AUTOHELP
730        {"backend", 'b', POPT_ARG_STRING, &backend, 0, "backend to use", NULL},
731            {"credentials", 'c', POPT_ARG_STRING, &credentials, 0, "credentials (user%%password)", NULL},
732        POPT_TABLEEND
733     };
734                                                                               
735     gtk_init (&argc, &argv);
736
737     pc = poptGetContext(argv[0], argc, (const char **) argv, long_options,0);
738                                                                               
739     while((opt = poptGetNextOpt(pc)) != -1) {
740     }
741
742         location = poptGetArg(pc);
743
744         if(location) {
745                 WERROR error;
746
747                 if(!backend) {
748                         if(credentials)backend = "rpc";
749                         else backend = "nt4";
750                 }
751                 
752                 error = reg_open(backend, location, credentials, &registry);
753                 if(!W_ERROR_IS_OK(error)) {
754                         gtk_show_werror(error);
755                         return -1;
756                 }
757                 mainwin = create_mainwin ();
758                 registry_load_root();
759         } else 
760                 mainwin = create_mainwin ();
761
762         gtk_widget_show (mainwin);
763
764         gtk_main ();
765
766         if(registry)reg_free(registry);
767         return 0;
768 }