fix .desktop file
[gconf-editor] / src / main.c
1 /*
2  * Copyright (C) 2001, 2002 Anders Carlsson <andersca@gnu.org>
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License as
6  * published by the Free Software Foundation; either version 2 of the
7  * License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17  */
18
19 #include <config.h>
20
21 #include <stdlib.h>
22 #include <glib/gi18n.h>
23 #include <gconf/gconf.h>
24
25 #include "gconf-editor-application.h"
26 #include "gconf-stock-icons.h"
27 #include "gconf-editor-window.h"
28
29 static char *
30 build_accel_filename (void)
31 {
32         return g_build_filename (g_get_home_dir (), ".gnome2", "accels", PACKAGE, NULL);
33 }
34
35 static void
36 load_accel_map (void)
37 {
38         char *map;
39
40         map = build_accel_filename ();
41         gtk_accel_map_load (map);
42
43         g_free (map);
44 }
45
46 static void
47 save_accel_map (void)
48 {
49         char *map;
50
51         map = build_accel_filename ();
52         gtk_accel_map_save (map);
53
54         g_free (map);
55 }
56
57 gint
58 main (gint argc, gchar **argv)
59 {
60         GOptionContext *context;
61         GtkWidget *window;
62         GError *error = NULL;
63
64         static gchar **remaining_args = NULL;
65         gchar *initial_key = NULL;
66                 
67         const GOptionEntry entries[] = 
68         {
69           { G_OPTION_REMAINING, '\0', 0, G_OPTION_ARG_STRING_ARRAY, &remaining_args, NULL, N_("[KEY]") },
70           { NULL }
71         };
72
73         bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
74         bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
75         textdomain (GETTEXT_PACKAGE);
76
77         context = g_option_context_new (N_("- Directly edit your entire configuration database"));
78
79         g_option_context_set_translation_domain (context, GETTEXT_PACKAGE);
80         g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE);
81         g_option_context_add_group (context, gtk_get_option_group (TRUE));
82
83         if (!g_option_context_parse (context, &argc, &argv, &error)) {
84                 g_critical ("Failed to parse arguments: %s", error->message);
85                 g_error_free (error);
86                 g_option_context_free (context);
87                 exit (1);
88         }
89
90         g_option_context_free (context);
91
92         /* Register our stock icons */
93         gtk_icon_theme_append_search_path (gtk_icon_theme_get_default (), ICONDIR);
94         gconf_stock_icons_register ();
95         load_accel_map ();
96
97         gtk_window_set_default_icon_name ("gconf-editor");
98
99         window = gconf_editor_application_create_editor_window (GCONF_EDITOR_WINDOW_TYPE_NORMAL);
100         gtk_widget_show_now (window);
101
102         /* get the key specified on the command line if any. Ignore the rest */
103         initial_key = remaining_args != NULL ? remaining_args[0] : NULL;
104
105         if (initial_key != NULL)
106                 gconf_editor_window_go_to (GCONF_EDITOR_WINDOW (window),initial_key);
107         
108         gtk_main ();
109
110         save_accel_map ();
111         g_strfreev (remaining_args);
112
113         return 0;
114 }