r4302: fixed all of the annoying gtk warnings. The code all seems to still work, but
[samba.git] / source4 / 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 "dynconfig.h"
24 #include "registry.h"
25 #include "lib/cmdline/popt_common.h"
26 #include "gtk/common/select.h"
27 #include "gtk/common/gtk-smb.h"
28
29 GtkWidget *openfilewin;
30 GtkWidget *savefilewin;
31 GtkTreeStore *store_keys;
32 GtkListStore *store_vals;
33 GtkWidget *tree_keys;
34 GtkWidget *mainwin;
35 GtkWidget *mnu_add_key, *mnu_add_value, *mnu_del_key, *mnu_del_value, *mnu_find;
36 TALLOC_CTX *mem_ctx; /* FIXME: Split up */
37
38 GtkWidget *save;
39 GtkWidget *save_as;
40 static GtkWidget* create_openfilewin (void);
41 static GtkWidget* create_savefilewin (void);
42 struct registry_context *registry = NULL;
43
44 static GtkWidget* create_FindDialog (void)
45 {
46   GtkWidget *FindDialog;
47   GtkWidget *dialog_vbox2;
48   GtkWidget *vbox1;
49   GtkWidget *hbox1;
50   GtkWidget *label6;
51   GtkWidget *entry_pattern;
52   GtkWidget *frame3;
53   GtkWidget *alignment3;
54   GtkWidget *vbox2;
55   GtkWidget *checkbutton1;
56   GtkWidget *checkbutton2;
57   GtkWidget *checkbutton3;
58   GtkWidget *label7;
59   GtkWidget *dialog_action_area2;
60   GtkWidget *cancelbutton2;
61   GtkWidget *okbutton2;
62
63   FindDialog = gtk_dialog_new ();
64   gtk_window_set_title (GTK_WINDOW (FindDialog), "Find Key or Value");
65   gtk_window_set_resizable (GTK_WINDOW (FindDialog), FALSE);
66   gtk_window_set_type_hint (GTK_WINDOW (FindDialog), GDK_WINDOW_TYPE_HINT_DIALOG);
67
68   dialog_vbox2 = GTK_DIALOG (FindDialog)->vbox;
69
70   vbox1 = gtk_vbox_new (FALSE, 0);
71   gtk_box_pack_start (GTK_BOX (dialog_vbox2), vbox1, TRUE, TRUE, 0);
72
73   hbox1 = gtk_hbox_new (FALSE, 0);
74   gtk_box_pack_start (GTK_BOX (vbox1), hbox1, TRUE, TRUE, 0);
75
76   label6 = gtk_label_new ("Find String");
77   gtk_box_pack_start (GTK_BOX (hbox1), label6, FALSE, FALSE, 0);
78
79   entry_pattern = gtk_entry_new ();
80   gtk_box_pack_start (GTK_BOX (hbox1), entry_pattern, TRUE, TRUE, 0);
81
82   frame3 = gtk_frame_new (NULL);
83   gtk_box_pack_start (GTK_BOX (vbox1), frame3, TRUE, TRUE, 0);
84   gtk_frame_set_shadow_type (GTK_FRAME (frame3), GTK_SHADOW_NONE);
85
86   alignment3 = gtk_alignment_new (0.5, 0.5, 1, 1);
87   gtk_container_add (GTK_CONTAINER (frame3), alignment3);
88   gtk_alignment_set_padding (GTK_ALIGNMENT (alignment3), 0, 0, 12, 0);
89
90   vbox2 = gtk_vbox_new (FALSE, 0);
91   gtk_container_add (GTK_CONTAINER (alignment3), vbox2);
92
93   checkbutton1 = gtk_check_button_new_with_mnemonic ("_Key Names");
94   gtk_box_pack_start (GTK_BOX (vbox2), checkbutton1, FALSE, FALSE, 0);
95
96   checkbutton2 = gtk_check_button_new_with_mnemonic ("_Value Names");
97   gtk_box_pack_start (GTK_BOX (vbox2), checkbutton2, FALSE, FALSE, 0);
98
99   checkbutton3 = gtk_check_button_new_with_mnemonic ("Value _Data");
100   gtk_box_pack_start (GTK_BOX (vbox2), checkbutton3, FALSE, FALSE, 0);
101
102   label7 = gtk_label_new ("<b>Search in</b>");
103   gtk_frame_set_label_widget (GTK_FRAME (frame3), label7);
104   gtk_label_set_use_markup (GTK_LABEL (label7), TRUE);
105
106   dialog_action_area2 = GTK_DIALOG (FindDialog)->action_area;
107   gtk_button_box_set_layout (GTK_BUTTON_BOX (dialog_action_area2), GTK_BUTTONBOX_END);
108
109   cancelbutton2 = gtk_button_new_from_stock ("gtk-cancel");
110   gtk_dialog_add_action_widget (GTK_DIALOG (FindDialog), cancelbutton2, GTK_RESPONSE_CANCEL);
111   GTK_WIDGET_SET_FLAGS (cancelbutton2, GTK_CAN_DEFAULT);
112
113   okbutton2 = gtk_button_new_from_stock ("gtk-ok");
114   gtk_dialog_add_action_widget (GTK_DIALOG (FindDialog), okbutton2, GTK_RESPONSE_OK);
115   GTK_WIDGET_SET_FLAGS (okbutton2, GTK_CAN_DEFAULT);
116
117   gtk_widget_show_all (dialog_vbox2);
118
119   return FindDialog;
120 }
121
122 static GtkWidget* create_SetValueDialog (void)
123 {
124   GtkWidget *SetValueDialog;
125   GtkWidget *dialog_vbox1;
126   GtkWidget *table1;
127   GtkWidget *label3;
128   GtkWidget *label4;
129   GtkWidget *label5;
130   GtkWidget *entry_value_name;
131   GtkWidget *value_data;
132   GtkWidget *combo_data_type;
133   GtkWidget *dialog_action_area1;
134   GtkWidget *cancelbutton1;
135   GtkWidget *okbutton1;
136
137   SetValueDialog = gtk_dialog_new ();
138   gtk_window_set_title (GTK_WINDOW (SetValueDialog), "Set Registry Value");
139   gtk_window_set_position (GTK_WINDOW (SetValueDialog), GTK_WIN_POS_CENTER);
140   gtk_window_set_resizable (GTK_WINDOW (SetValueDialog), FALSE);
141   gtk_window_set_type_hint (GTK_WINDOW (SetValueDialog), GDK_WINDOW_TYPE_HINT_DIALOG);
142
143   dialog_vbox1 = GTK_DIALOG (SetValueDialog)->vbox;
144
145   table1 = gtk_table_new (3, 2, FALSE);
146   gtk_box_pack_start (GTK_BOX (dialog_vbox1), table1, TRUE, TRUE, 0);
147
148   label3 = gtk_label_new ("Value name:");
149   gtk_table_attach (GTK_TABLE (table1), label3, 0, 1, 0, 1,
150                     (GtkAttachOptions) (GTK_FILL),
151                     (GtkAttachOptions) (0), 0, 0);
152   gtk_misc_set_alignment (GTK_MISC (label3), 0, 0.5);
153
154   label4 = gtk_label_new ("Data Type:");
155   gtk_table_attach (GTK_TABLE (table1), label4, 0, 1, 1, 2,
156                     (GtkAttachOptions) (GTK_FILL),
157                     (GtkAttachOptions) (0), 0, 0);
158   gtk_misc_set_alignment (GTK_MISC (label4), 0, 0.5);
159
160   label5 = gtk_label_new ("Data:");
161   gtk_table_attach (GTK_TABLE (table1), label5, 0, 1, 2, 3,
162                     (GtkAttachOptions) (GTK_FILL),
163                     (GtkAttachOptions) (0), 0, 0);
164   gtk_misc_set_alignment (GTK_MISC (label5), 0, 0.5);
165
166   entry_value_name = gtk_entry_new ();
167   gtk_table_attach (GTK_TABLE (table1), entry_value_name, 1, 2, 0, 1,
168                     (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
169                     (GtkAttachOptions) (0), 0, 0);
170
171   value_data = gtk_entry_new ();
172   gtk_table_attach (GTK_TABLE (table1), value_data, 1, 2, 2, 3,
173                     (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
174                     (GtkAttachOptions) (0), 0, 0);
175
176   combo_data_type = gtk_combo_box_entry_new_text ();
177   gtk_table_attach (GTK_TABLE (table1), combo_data_type, 1, 2, 1, 2,
178                     (GtkAttachOptions) (GTK_FILL),
179                     (GtkAttachOptions) (GTK_FILL), 0, 0);
180
181   dialog_action_area1 = GTK_DIALOG (SetValueDialog)->action_area;
182   gtk_button_box_set_layout (GTK_BUTTON_BOX (dialog_action_area1), GTK_BUTTONBOX_END);
183
184   cancelbutton1 = gtk_button_new_from_stock ("gtk-cancel");
185   gtk_dialog_add_action_widget (GTK_DIALOG (SetValueDialog), cancelbutton1, GTK_RESPONSE_CANCEL);
186   GTK_WIDGET_SET_FLAGS (cancelbutton1, GTK_CAN_DEFAULT);
187
188   okbutton1 = gtk_button_new_from_stock ("gtk-ok");
189   gtk_dialog_add_action_widget (GTK_DIALOG (SetValueDialog), okbutton1, GTK_RESPONSE_OK);
190   GTK_WIDGET_SET_FLAGS (okbutton1, GTK_CAN_DEFAULT);
191
192   gtk_widget_show_all (dialog_vbox1);
193
194   return SetValueDialog;
195 }
196
197 static GtkWidget* create_NewKeyDialog (void)
198 {
199   GtkWidget *NewKeyDialog;
200   GtkWidget *dialog_vbox2;
201   GtkWidget *hbox1;
202   GtkWidget *label6;
203   GtkWidget *entry_key_name;
204   GtkWidget *dialog_action_area2;
205   GtkWidget *cancelbutton2;
206   GtkWidget *okbutton2;
207
208   NewKeyDialog = gtk_dialog_new ();
209   gtk_window_set_title (GTK_WINDOW (NewKeyDialog), "New Registry Key");
210   gtk_window_set_position (GTK_WINDOW (NewKeyDialog), GTK_WIN_POS_CENTER);
211   gtk_window_set_resizable (GTK_WINDOW (NewKeyDialog), FALSE);
212   gtk_window_set_type_hint (GTK_WINDOW (NewKeyDialog), GDK_WINDOW_TYPE_HINT_DIALOG);
213
214   dialog_vbox2 = GTK_DIALOG (NewKeyDialog)->vbox;
215
216   hbox1 = gtk_hbox_new (FALSE, 0);
217   gtk_box_pack_start (GTK_BOX (dialog_vbox2), hbox1, TRUE, TRUE, 0);
218
219   label6 = gtk_label_new ("Name:");
220   gtk_box_pack_start (GTK_BOX (hbox1), label6, FALSE, FALSE, 0);
221
222   entry_key_name = gtk_entry_new ();
223   gtk_box_pack_start (GTK_BOX (hbox1), entry_key_name, TRUE, TRUE, 0);
224
225   dialog_action_area2 = GTK_DIALOG (NewKeyDialog)->action_area;
226   gtk_button_box_set_layout (GTK_BUTTON_BOX (dialog_action_area2), GTK_BUTTONBOX_END);
227
228   cancelbutton2 = gtk_button_new_from_stock ("gtk-cancel");
229   gtk_dialog_add_action_widget (GTK_DIALOG (NewKeyDialog), cancelbutton2, GTK_RESPONSE_CANCEL);
230   GTK_WIDGET_SET_FLAGS (cancelbutton2, GTK_CAN_DEFAULT);
231
232   okbutton2 = gtk_button_new_from_stock ("gtk-ok");
233   gtk_dialog_add_action_widget (GTK_DIALOG (NewKeyDialog), okbutton2, GTK_RESPONSE_OK);
234   GTK_WIDGET_SET_FLAGS (okbutton2, GTK_CAN_DEFAULT);
235
236   gtk_widget_show_all (dialog_vbox2);
237
238   return NewKeyDialog;
239 }
240
241
242 static void expand_key(GtkTreeView *treeview, GtkTreeIter *parent, GtkTreePath *arg2)
243 {
244         GtkTreeIter firstiter, iter, tmpiter;
245         struct registry_key *k, *sub;
246         char *name;
247         WERROR error;
248         int i;
249
250     gtk_tree_model_iter_children(GTK_TREE_MODEL(store_keys), &firstiter, parent);
251
252     /* See if this row has ever had a name gtk_tree_store_set()'ed to it.
253        If not, read the directory contents */
254     gtk_tree_model_get(GTK_TREE_MODEL(store_keys), &firstiter, 0, &name, -1);
255
256         if(name) return;
257
258         gtk_tree_model_get(GTK_TREE_MODEL(store_keys), parent, 1, &k, -1);
259
260         g_assert(k);
261         
262         for(i = 0; W_ERROR_IS_OK(error = reg_key_get_subkey_by_index(mem_ctx, k, i, &sub)); i++) {
263                 int count;
264                 /* Replace the blank child with the first directory entry
265            You may be tempted to remove the blank child node and then 
266            append a new one.  Don't.  If you remove the blank child 
267            node GTK gets confused and won't expand the parent row. */
268
269                 if(i == 0) {
270                         iter = firstiter;
271                 } else {
272                         gtk_tree_store_append(store_keys, &iter, parent);
273                 }
274                 gtk_tree_store_set (store_keys,
275                                             &iter, 
276                                                 0,
277                                                 sub->name,
278                                                 1, 
279                                                 sub,
280                                                 -1);
281                 
282                 if(W_ERROR_IS_OK(reg_key_num_subkeys(sub, &count)) && count > 0) 
283                         gtk_tree_store_append(store_keys, &tmpiter, &iter);
284         }
285
286         if(!W_ERROR_EQUAL(error, WERR_NO_MORE_ITEMS)) gtk_show_werror(mainwin, error);
287 }
288
289 static void registry_load_hive(struct registry_key *root)
290 {
291         GtkTreeIter iter, tmpiter;
292         /* Add the root */
293         gtk_tree_store_append(store_keys, &iter, NULL);
294         gtk_tree_store_set (store_keys,
295                                     &iter, 
296                                         0,
297                                         root->name?root->name:"",
298                                         1,
299                                         root,
300                                         -1);
301
302         gtk_tree_store_append(store_keys, &tmpiter, &iter);
303
304         gtk_widget_set_sensitive( save, True );
305         gtk_widget_set_sensitive( save_as, True );
306 }
307
308 static void registry_load_root(void) 
309 {
310         struct registry_key *root;
311         uint32_t i = 0;
312         if(!registry) return;
313
314         gtk_tree_store_clear(store_keys);
315
316         for(i = HKEY_CLASSES_ROOT; i <= HKEY_PERFORMANCE_NLSTEXT; i++) 
317         {
318                 if (!W_ERROR_IS_OK(reg_get_predefined_key(registry, i, &root))) { continue; }
319
320                 registry_load_hive(root);
321         }
322 }
323
324 static void on_open_file_activate (GtkMenuItem *menuitem, gpointer user_data)
325 {
326         gint result = gtk_dialog_run(GTK_DIALOG(create_openfilewin()));
327         char *filename, *tmp;
328         struct registry_key *root;
329         WERROR error;
330         switch(result) {
331         case GTK_RESPONSE_OK:
332                 filename = strdup(gtk_file_selection_get_filename(GTK_FILE_SELECTION(openfilewin)));
333                 error = reg_open_hive(NULL, user_data, filename, NULL, &root);
334                 if(!W_ERROR_IS_OK(error)) {
335                         gtk_show_werror(mainwin, error);
336                         break;
337                 }
338
339                 tmp = g_strdup_printf("Registry Editor - %s", filename);
340                 gtk_window_set_title (GTK_WINDOW (mainwin), tmp);
341                 g_free(tmp);
342                 gtk_tree_store_clear(store_keys);
343                 registry_load_hive(root);
344                 break;
345         default:
346                 break;
347         }
348
349         gtk_widget_destroy(openfilewin);
350 }
351
352 static void on_open_gconf_activate                       (GtkMenuItem     *menuitem,
353                                                       gpointer         user_data)
354 {
355         struct registry_key *root;
356         WERROR error = reg_open_hive(NULL, "gconf", NULL, NULL, &root);
357         if(!W_ERROR_IS_OK(error)) {
358                 gtk_show_werror(mainwin, error);
359                 return;
360         }
361
362         gtk_window_set_title (GTK_WINDOW (mainwin), "Registry Editor - GConf");
363
364         gtk_tree_store_clear(store_keys);
365         registry_load_hive(root);
366 }
367
368 static void on_open_remote_activate(GtkMenuItem *menuitem, gpointer user_data)
369 {
370         char *tmp;
371         GtkWidget *rpcwin = GTK_WIDGET(gtk_rpc_binding_dialog_new(FALSE, NULL));
372         gint result = gtk_dialog_run(GTK_DIALOG(rpcwin));
373         WERROR error;
374         
375         if(result != GTK_RESPONSE_ACCEPT)
376         {
377                 gtk_widget_destroy(rpcwin);
378                 return;
379         }
380
381         error = reg_open_remote(&registry, 
382                                 gtk_rpc_binding_dialog_get_username(GTK_RPC_BINDING_DIALOG(rpcwin)), 
383                                 gtk_rpc_binding_dialog_get_password(GTK_RPC_BINDING_DIALOG(rpcwin)), 
384                                 gtk_rpc_binding_dialog_get_binding_string(GTK_RPC_BINDING_DIALOG(rpcwin), mem_ctx));
385
386         if(!W_ERROR_IS_OK(error)) {
387                 gtk_show_werror(mainwin, error);
388                 gtk_widget_destroy(rpcwin);
389                 return;
390         }
391
392         tmp = g_strdup_printf("Registry Editor - Remote Registry at %s", gtk_rpc_binding_dialog_get_host(GTK_RPC_BINDING_DIALOG(rpcwin)));
393         gtk_window_set_title (GTK_WINDOW (mainwin), tmp);
394         g_free(tmp);
395
396         registry_load_root();
397
398
399         gtk_widget_destroy(rpcwin);
400 }
401
402
403 static void on_save_activate                       (GtkMenuItem     *menuitem,
404                                                                                                         gpointer         user_data)
405 {
406         WERROR error = reg_save(registry, NULL);
407         if(!W_ERROR_IS_OK(error)) {
408                 gtk_show_werror(mainwin, error);
409         }
410 }
411
412
413 static void on_save_as_activate                    (GtkMenuItem     *menuitem,
414                                                                                 gpointer         user_data)
415 {
416         gint result;
417         WERROR error;
418         create_savefilewin();
419         result = gtk_dialog_run(GTK_DIALOG(savefilewin));
420         switch(result) {
421         case GTK_RESPONSE_OK:
422                 error = reg_save(registry, gtk_file_selection_get_filename(GTK_FILE_SELECTION(savefilewin)));
423                 if(!W_ERROR_IS_OK(error)) {
424                         gtk_show_werror(mainwin, error);
425                 }
426                 break;
427
428         default:
429                 break;
430
431         }
432         gtk_widget_destroy(savefilewin);
433 }
434
435
436 static void on_quit_activate                       (GtkMenuItem     *menuitem,
437                                                                                 gpointer         user_data)
438 {
439         gtk_main_quit();
440 }
441
442
443 static void on_delete_activate                     (GtkMenuItem     *menuitem,
444                                                                                 gpointer         user_data)
445 {
446         /* FIXME */
447 }
448
449 static void on_add_key_activate                     (GtkMenuItem     *menuitem,
450                                                                                 gpointer         user_data)
451 {
452         GtkDialog *addwin = GTK_DIALOG(create_NewKeyDialog());
453         gtk_dialog_run(addwin);
454         /* FIXME */
455         gtk_widget_destroy(GTK_WIDGET(addwin));
456 }
457
458 static void on_add_value_activate                     (GtkMenuItem     *menuitem,
459                                                                                 gpointer         user_data)
460 {
461         GtkDialog *addwin = GTK_DIALOG(create_SetValueDialog());
462         gtk_dialog_run(addwin);
463         /* FIXME */
464         gtk_widget_destroy(GTK_WIDGET(addwin));
465 }
466
467 static void on_find_activate                     (GtkMenuItem     *menuitem,
468                                                                                 gpointer         user_data)
469 {
470         GtkDialog *findwin = GTK_DIALOG(create_FindDialog());
471         gtk_dialog_run(findwin);
472         /* FIXME */
473         gtk_widget_destroy(GTK_WIDGET(findwin));
474 }
475
476 static void on_about_activate                      (GtkMenuItem     *menuitem,
477                                                                                 gpointer         user_data)
478 {
479         GtkDialog *aboutwin = GTK_DIALOG(create_gtk_samba_about_dialog("gregedit"));
480         gtk_dialog_run(aboutwin);
481         gtk_widget_destroy(GTK_WIDGET(aboutwin));
482 }
483
484 gboolean on_key_activate(GtkTreeSelection *selection,
485                                              GtkTreeModel *model,
486                                              GtkTreePath *path,
487                                              gboolean path_currently_selected,
488                                              gpointer data)
489 {
490         int i;
491         struct registry_key *k;
492         struct registry_value *val;
493         WERROR error;
494         GtkTreeIter parent;
495
496         gtk_widget_set_sensitive(mnu_add_key, !path_currently_selected);
497         gtk_widget_set_sensitive(mnu_add_value, !path_currently_selected);
498         gtk_widget_set_sensitive(mnu_del_key, !path_currently_selected);
499         gtk_widget_set_sensitive(mnu_del_value, !path_currently_selected);
500         gtk_widget_set_sensitive(mnu_find, !path_currently_selected);
501
502         if(path_currently_selected) { return TRUE; }
503
504         gtk_tree_model_get_iter(GTK_TREE_MODEL(store_keys), &parent, path);
505         gtk_tree_model_get(GTK_TREE_MODEL(store_keys), &parent, 1, &k, -1);
506
507         g_assert(k);
508
509         gtk_list_store_clear(store_vals);
510
511         for(i = 0; W_ERROR_IS_OK(error = reg_key_get_value_by_index(mem_ctx, k, i, &val)); i++) {
512                 GtkTreeIter iter;
513                 gtk_list_store_append(store_vals, &iter);
514                 gtk_list_store_set (store_vals,
515                                             &iter, 
516                                                 0,
517                                                 val->name,
518                                                 1,
519                                                 str_regtype(val->data_type),
520                                                 2,
521                                                 reg_val_data_string(mem_ctx, val),
522                                                 3, 
523                                                 val,
524                                                 -1);
525         }
526
527         if(!W_ERROR_EQUAL(error, WERR_NO_MORE_ITEMS)) {
528                  gtk_show_werror(mainwin, error);
529                  return FALSE;
530         }
531         return TRUE;
532 }
533
534 static GtkWidget* create_mainwin (void)
535 {
536         GtkWidget *vbox1;
537         GtkWidget *menubar;
538         GtkWidget *menu_file;
539         GtkWidget *menu_file_menu;
540         GtkWidget *open_nt4;
541         GtkWidget *open_ldb;
542         GtkWidget *open_w95;
543         GtkWidget *open_gconf;
544         GtkWidget *open_remote;
545         GtkWidget *separatormenuitem1;
546         GtkWidget *quit;
547         GtkWidget *men_key;
548         GtkWidget *men_key_menu;
549         GtkCellRenderer *renderer;
550         GtkTreeViewColumn *curcol;
551         GtkWidget *help;
552         GtkWidget *help_menu;
553         GtkWidget *about;
554         GtkWidget *hbox1;
555         GtkWidget *scrolledwindow1;
556         GtkWidget *scrolledwindow2;
557         GtkWidget *tree_vals;
558         GtkWidget *statusbar;
559         GtkAccelGroup *accel_group;
560
561         accel_group = gtk_accel_group_new ();
562
563         mainwin = gtk_window_new (GTK_WINDOW_TOPLEVEL);
564         gtk_window_set_title (GTK_WINDOW (mainwin), "Registry editor");
565         gtk_window_set_default_size (GTK_WINDOW (mainwin), 642, 562);
566
567         vbox1 = gtk_vbox_new (FALSE, 0);
568         gtk_container_add (GTK_CONTAINER (mainwin), vbox1);
569
570         menubar = gtk_menu_bar_new ();
571         gtk_box_pack_start (GTK_BOX (vbox1), menubar, FALSE, FALSE, 0);
572
573         menu_file = gtk_menu_item_new_with_mnemonic ("_File");
574         gtk_container_add (GTK_CONTAINER (menubar), menu_file);
575
576         menu_file_menu = gtk_menu_new ();
577         gtk_menu_item_set_submenu (GTK_MENU_ITEM (menu_file), menu_file_menu);
578
579         if(reg_has_backend("nt4")) {
580                 open_nt4 = gtk_image_menu_item_new_with_mnemonic("Open _NT4 file");
581                 gtk_container_add (GTK_CONTAINER (menu_file_menu), open_nt4);
582
583                 g_signal_connect(open_nt4, "activate",
584                                  G_CALLBACK (on_open_file_activate),
585                                  discard_const_p(char, "nt4"));
586         }
587
588         if(reg_has_backend("w95")) {
589                 open_w95 = gtk_image_menu_item_new_with_mnemonic("Open Win_9x file");
590                 gtk_container_add (GTK_CONTAINER (menu_file_menu), open_w95);
591
592                 g_signal_connect (open_w95, "activate",
593                                   G_CALLBACK (on_open_file_activate),
594                                   discard_const_p(char, "w95"));
595         }
596
597         if(reg_has_backend("gconf")) {
598                 open_gconf = gtk_image_menu_item_new_with_mnemonic ("Open _GConf");
599                 gtk_container_add (GTK_CONTAINER (menu_file_menu), open_gconf);
600
601                 g_signal_connect ((gpointer) open_gconf, "activate",
602                                                   G_CALLBACK (on_open_gconf_activate),
603                                                   NULL);
604         }
605
606         if(reg_has_backend("rpc")) {
607                 open_remote = gtk_menu_item_new_with_mnemonic ("Open _Remote");
608                 gtk_container_add (GTK_CONTAINER (menu_file_menu), open_remote);
609
610                 g_signal_connect ((gpointer) open_remote, "activate",
611                                                   G_CALLBACK (on_open_remote_activate),
612                                                   NULL);
613         }
614
615         if(reg_has_backend("ldb")) {
616                 open_ldb = gtk_image_menu_item_new_with_mnemonic("Open _LDB file");
617                 gtk_container_add (GTK_CONTAINER (menu_file_menu), open_ldb);
618
619                 g_signal_connect(open_ldb, "activate",
620                                  G_CALLBACK (on_open_file_activate),
621                                  discard_const_p(char, "ldb"));
622         }
623
624         save = gtk_image_menu_item_new_from_stock ("gtk-save", accel_group);
625         gtk_widget_set_sensitive( save, False );
626         gtk_container_add (GTK_CONTAINER (menu_file_menu), save);
627
628         save_as = gtk_image_menu_item_new_from_stock ("gtk-save-as", accel_group);
629         gtk_widget_set_sensitive( save_as, False );
630         gtk_container_add (GTK_CONTAINER (menu_file_menu), save_as);
631
632         separatormenuitem1 = gtk_menu_item_new ();
633         gtk_container_add (GTK_CONTAINER (menu_file_menu), separatormenuitem1);
634         gtk_widget_set_sensitive (separatormenuitem1, FALSE);
635
636         quit = gtk_image_menu_item_new_from_stock ("gtk-quit", accel_group);
637         gtk_container_add (GTK_CONTAINER (menu_file_menu), quit);
638
639         men_key = gtk_menu_item_new_with_mnemonic ("_Key");
640         gtk_container_add (GTK_CONTAINER (menubar), men_key);
641
642         men_key_menu = gtk_menu_new ();
643         gtk_menu_item_set_submenu (GTK_MENU_ITEM (men_key), men_key_menu);
644
645         mnu_add_key = gtk_image_menu_item_new_with_mnemonic("Add _Subkey");
646         gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (mnu_add_key), gtk_image_new_from_stock ("gtk-add", GTK_ICON_SIZE_MENU));
647
648         gtk_widget_set_sensitive(mnu_add_key, False);
649         gtk_container_add (GTK_CONTAINER (men_key_menu), mnu_add_key);
650
651         mnu_add_value = gtk_image_menu_item_new_with_mnemonic("Add _Value");
652         gtk_widget_set_sensitive(mnu_add_value, False);
653         gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (mnu_add_value), gtk_image_new_from_stock ("gtk-add", GTK_ICON_SIZE_MENU));
654         gtk_container_add (GTK_CONTAINER (men_key_menu), mnu_add_value);
655
656         mnu_find = gtk_image_menu_item_new_from_stock ("gtk-find", accel_group);
657         gtk_widget_set_sensitive(mnu_find, False);
658         gtk_container_add (GTK_CONTAINER (men_key_menu), mnu_find);
659
660         mnu_del_key = gtk_image_menu_item_new_with_mnemonic ("Delete Key"); 
661         gtk_widget_set_sensitive(mnu_del_key, False);
662         gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (mnu_del_value), gtk_image_new_from_stock ("gtk-delete", GTK_ICON_SIZE_MENU));
663         gtk_container_add (GTK_CONTAINER (men_key_menu), mnu_del_key);
664
665         mnu_del_value = gtk_image_menu_item_new_with_mnemonic ("Delete Value"); 
666         gtk_widget_set_sensitive(mnu_del_value, False);
667         gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (mnu_del_value), gtk_image_new_from_stock ("gtk-delete", GTK_ICON_SIZE_MENU));
668         gtk_container_add (GTK_CONTAINER (men_key_menu), mnu_del_value);
669
670
671         help = gtk_menu_item_new_with_mnemonic ("_Help");
672         gtk_container_add (GTK_CONTAINER (menubar), help);
673
674         help_menu = gtk_menu_new ();
675         gtk_menu_item_set_submenu (GTK_MENU_ITEM (help), help_menu);
676
677         about = gtk_menu_item_new_with_mnemonic ("_About");
678         gtk_container_add (GTK_CONTAINER (help_menu), about);
679
680         hbox1 = gtk_hbox_new (FALSE, 0);
681         gtk_box_pack_start (GTK_BOX (vbox1), hbox1, TRUE, TRUE, 0);
682
683         scrolledwindow1 = gtk_scrolled_window_new (NULL, NULL);
684         gtk_box_pack_start (GTK_BOX (hbox1), scrolledwindow1, TRUE, TRUE, 0);
685
686         tree_keys = gtk_tree_view_new ();
687
688         /* Column names */
689         curcol = gtk_tree_view_column_new ();
690         gtk_tree_view_column_set_title(curcol, "Name");
691         renderer = gtk_cell_renderer_text_new();
692         gtk_tree_view_column_pack_start(curcol, renderer, True);
693
694         gtk_tree_view_append_column(GTK_TREE_VIEW(tree_keys), curcol);
695
696         gtk_tree_view_column_add_attribute(curcol, renderer, "text", 0);
697         gtk_container_add (GTK_CONTAINER (scrolledwindow1), tree_keys);
698         store_keys = gtk_tree_store_new(2, G_TYPE_STRING, G_TYPE_POINTER);
699         gtk_tree_view_set_model(GTK_TREE_VIEW(tree_keys), GTK_TREE_MODEL(store_keys));
700         g_object_unref(store_keys);
701
702         gtk_tree_selection_set_select_function (gtk_tree_view_get_selection(GTK_TREE_VIEW(tree_keys)), on_key_activate, NULL, NULL);
703
704         g_signal_connect ((gpointer) tree_keys, "row-expanded",
705                                           G_CALLBACK (expand_key),
706                                           NULL);
707
708
709         scrolledwindow2 = gtk_scrolled_window_new (NULL, NULL);
710         gtk_box_pack_start (GTK_BOX (hbox1), scrolledwindow2, TRUE, TRUE, 0);
711
712         tree_vals = gtk_tree_view_new ();
713         /* Column names */
714
715         curcol = gtk_tree_view_column_new ();
716         gtk_tree_view_column_set_title(curcol, "Name");
717         renderer = gtk_cell_renderer_text_new();
718         gtk_tree_view_column_pack_start(curcol, renderer, True);
719         gtk_tree_view_append_column(GTK_TREE_VIEW(tree_vals), curcol);
720         gtk_tree_view_column_add_attribute(curcol, renderer, "text", 0);
721
722         curcol = gtk_tree_view_column_new ();
723         gtk_tree_view_column_set_title(curcol, "Type");
724         renderer = gtk_cell_renderer_text_new();
725         gtk_tree_view_column_pack_start(curcol, renderer, True);
726         gtk_tree_view_append_column(GTK_TREE_VIEW(tree_vals), curcol);
727         gtk_tree_view_column_add_attribute(curcol, renderer, "text", 1);
728
729         curcol = gtk_tree_view_column_new ();
730         gtk_tree_view_column_set_title(curcol, "Value");
731         renderer = gtk_cell_renderer_text_new();
732         gtk_tree_view_column_pack_start(curcol, renderer, True);
733         gtk_tree_view_append_column(GTK_TREE_VIEW(tree_vals), curcol);
734         gtk_tree_view_column_add_attribute(curcol, renderer, "text", 2);
735
736
737         gtk_container_add (GTK_CONTAINER (scrolledwindow2), tree_vals);
738
739         store_vals = gtk_list_store_new(4, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_POINTER);
740         gtk_tree_view_set_model(GTK_TREE_VIEW(tree_vals), GTK_TREE_MODEL(store_vals));
741         g_object_unref(store_vals);
742
743         statusbar = gtk_statusbar_new ();
744         gtk_box_pack_start (GTK_BOX (vbox1), statusbar, FALSE, FALSE, 0);
745         gtk_statusbar_set_has_resize_grip (GTK_STATUSBAR (statusbar), FALSE);
746
747         g_signal_connect ((gpointer) save, "activate",
748                                           G_CALLBACK (on_save_activate),
749                                           NULL);
750         g_signal_connect ((gpointer) save_as, "activate",
751                                           G_CALLBACK (on_save_as_activate),
752                                           NULL);
753         g_signal_connect ((gpointer) quit, "activate",
754                                           G_CALLBACK (on_quit_activate),
755                                           NULL);
756         g_signal_connect ((gpointer) mnu_add_key, "activate",
757                                           G_CALLBACK (on_add_key_activate),
758                                           NULL);
759         g_signal_connect ((gpointer) mnu_add_value, "activate",
760                                           G_CALLBACK (on_add_value_activate),
761                                           NULL);
762         g_signal_connect ((gpointer) mnu_find, "activate",
763                                           G_CALLBACK (on_find_activate),
764                                           NULL);
765         g_signal_connect ((gpointer) mnu_del_key, "activate",
766                                           G_CALLBACK (on_delete_activate),
767                                           NULL);
768         g_signal_connect ((gpointer) about, "activate",
769                                           G_CALLBACK (on_about_activate),
770                                           NULL);
771
772         gtk_window_add_accel_group (GTK_WINDOW (mainwin), accel_group);
773
774         return mainwin;
775 }
776
777 static GtkWidget* create_openfilewin (void)
778 {
779         GtkWidget *ok_button;
780         GtkWidget *cancel_button;
781
782         openfilewin = gtk_file_selection_new ("Select File");
783         gtk_container_set_border_width (GTK_CONTAINER (openfilewin), 10);
784
785         ok_button = GTK_FILE_SELECTION (openfilewin)->ok_button;
786         GTK_WIDGET_SET_FLAGS (ok_button, GTK_CAN_DEFAULT);
787
788         cancel_button = GTK_FILE_SELECTION (openfilewin)->cancel_button;
789         GTK_WIDGET_SET_FLAGS (cancel_button, GTK_CAN_DEFAULT);
790
791         return openfilewin;
792 }
793
794 static GtkWidget* create_savefilewin (void)
795 {
796         GtkWidget *ok_button;
797         GtkWidget *cancel_button;
798
799         savefilewin = gtk_file_selection_new ("Select File");
800         gtk_container_set_border_width (GTK_CONTAINER (savefilewin), 10);
801
802         ok_button = GTK_FILE_SELECTION (savefilewin)->ok_button;
803         GTK_WIDGET_SET_FLAGS (ok_button, GTK_CAN_DEFAULT);
804
805         cancel_button = GTK_FILE_SELECTION (savefilewin)->cancel_button;
806         GTK_WIDGET_SET_FLAGS (cancel_button, GTK_CAN_DEFAULT);
807
808         return savefilewin;
809 }
810
811  int main(int argc, char *argv[])
812 {
813         poptContext pc;
814         WERROR error;
815         int opt;
816         struct poptOption long_options[] = {
817                 POPT_AUTOHELP
818                 POPT_TABLEEND
819         };
820
821         gregedit_init_subsystems;
822
823         lp_load(dyn_CONFIGFILE,True,False,False);
824         load_interfaces();
825
826         gtk_init (&argc, &argv);
827         mem_ctx = talloc_init("gregedit");
828
829         pc = poptGetContext(argv[0], argc, (const char **) argv, long_options,0);
830
831         while((opt = poptGetNextOpt(pc)) != -1) {
832         }
833
834         error = reg_open_local(&registry);
835         if(!W_ERROR_IS_OK(error)) {
836                 gtk_show_werror(mainwin, error);
837                 return -1;
838         }
839         mainwin = create_mainwin ();
840         registry_load_root();
841
842         gtk_widget_show_all (mainwin);
843
844         gtk_main ();
845
846         talloc_destroy(mem_ctx);
847         return 0;
848 }
849
850