]> icculus.org git repositories - dana/obconf.git/blob - src/main.c
add --install and --archive
[dana/obconf.git] / src / main.c
1 /* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
2
3    main.c for ObConf, the configuration tool for Openbox
4    Copyright (c) 2003-2007   Dana Jansens
5    Copyright (c) 2003        Tim Riley
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    See the COPYING file for a copy of the GNU General Public License.
18 */
19
20 #include "main.h"
21 #include "handlers.h"
22 #include "theme.h"
23 #include "gettext.h"
24
25 #include <gdk/gdkx.h>
26 #define SN_API_NOT_YET_FROZEN
27 #include <libsn/sn.h>
28 #undef SN_API_NOT_YET_FROZEN
29
30 GtkWidget *mainwin = NULL;
31
32 GladeXML *glade;
33 xmlDocPtr doc;
34 xmlNodePtr root;
35
36 static gchar *obc_theme_install = NULL;
37 static gchar *obc_theme_archive = NULL;
38
39 void obconf_error(gchar *msg)
40 {
41     GtkWidget *d;
42
43     d = gtk_message_dialog_new(mainwin ? GTK_WINDOW(mainwin) : NULL,
44                                GTK_DIALOG_DESTROY_WITH_PARENT,
45                                GTK_MESSAGE_ERROR,
46                                GTK_BUTTONS_CLOSE,
47                                "%s", msg);
48     g_signal_connect_swapped(GTK_OBJECT(d), "response",
49                              G_CALLBACK(gtk_widget_destroy),
50                              GTK_OBJECT(d));
51     gtk_widget_show(d);
52 }
53
54 static void parse_args(int argc, char **argv)
55 {
56     int i;
57
58     for (i = 1; i < argc; ++i) {
59         if (!strcmp(argv[i], "--install")) {
60             if (i == argc - 1) /* no args left */
61                 g_printerr(_("--install requires an argument\n"));
62             else
63                 obc_theme_install = argv[++i];
64         }
65         else if (!strcmp(argv[i], "--archive")) {
66             if (i == argc - 1) /* no args left */
67                 g_printerr(_("--archive requires an argument\n"));
68             else
69                 obc_theme_archive = argv[++i];
70         }
71     }
72 }
73
74 int main(int argc, char **argv)
75 {
76     SnDisplay *sn_d;
77     SnLauncheeContext *sn_cx;
78     gchar *p;
79
80     gtk_init(&argc, &argv);
81     parse_args(argc, argv);
82
83     if (obc_theme_archive) {
84         theme_archive(obc_theme_archive);
85         return;
86     }
87
88     parse_paths_startup();
89
90     p = g_build_filename(GLADEDIR, "obconf.glade", NULL);
91     glade = glade_xml_new(p, NULL, NULL);
92     g_free(p);
93
94     if (!glade) {
95         obconf_error("Failed to load the obconf.glade interface file. You "
96                      "have probably failed to install ObConf properly.");
97         return 1;
98     }
99
100     xmlIndentTreeOutput = 1;
101     if (!parse_load_rc(NULL, &doc, &root)) {
102         obconf_error("Failed to load an rc.xml. You have probably failed to "
103                      "install Openbox properly.");
104         return 1;
105     }
106
107     glade_xml_signal_autoconnect(glade);
108
109     {
110         gchar *s = g_strdup_printf
111             ("<span weight=\"bold\" size=\"xx-large\">ObConf %s</span>",
112              PACKAGE_VERSION);
113         gtk_label_set_markup(GTK_LABEL
114                              (glade_xml_get_widget(glade, "title_label")), s);
115         g_free(s);
116     }
117
118     setup_behavior_tab();
119     setup_dock_tab();
120     setup_focus_mouse(glade_xml_get_widget(glade, "focus_mouse"));
121     setup_focus_raise(glade_xml_get_widget(glade, "focus_raise"));
122     setup_focus_last(glade_xml_get_widget(glade, "focus_raise"));
123     setup_focus_delay(glade_xml_get_widget(glade, "focus_delay"));
124     setup_focus_new(glade_xml_get_widget(glade, "focus_new"));
125     setup_place_mouse(glade_xml_get_widget(glade, "place_mouse"));
126     setup_resist_window(glade_xml_get_widget(glade, "resist_window"));
127     setup_resist_edge(glade_xml_get_widget(glade, "resist_edge"));
128     setup_resize_contents(glade_xml_get_widget(glade, "resize_contents"));
129     setup_dock_position(glade_xml_get_widget(glade, "dock_position"));
130     setup_dock_float_x(glade_xml_get_widget(glade, "dock_float_x"));
131     setup_dock_float_y(glade_xml_get_widget(glade, "dock_float_y"));
132     setup_dock_stacking(glade_xml_get_widget(glade, "dock_stack_top"),
133                         glade_xml_get_widget(glade, "dock_stack_normal"),
134                         glade_xml_get_widget(glade, "dock_stack_bottom"));
135     setup_dock_direction(glade_xml_get_widget(glade, "dock_direction"));
136     setup_dock_hide(glade_xml_get_widget(glade, "dock_hide"));
137     setup_dock_hide_delay(glade_xml_get_widget(glade, "dock_hide_delay"));
138     setup_theme_names(glade_xml_get_widget(glade, "theme_names"));
139     setup_title_layout(glade_xml_get_widget(glade, "title_layout"));
140     setup_desktop_num(glade_xml_get_widget(glade, "desktop_num"));
141     setup_desktop_names(glade_xml_get_widget(glade, "desktop_names"));
142     setup_window_border(glade_xml_get_widget(glade, "window_border"));
143     setup_font_active(glade_xml_get_widget(glade, "font_active"));
144     setup_font_inactive(glade_xml_get_widget(glade, "font_inactive"));
145     setup_font_menu_header(glade_xml_get_widget(glade, "font_menu_header"));
146     setup_font_menu_item(glade_xml_get_widget(glade, "font_menu_item"));
147     setup_font_display(glade_xml_get_widget(glade, "font_display"));
148
149     mainwin = glade_xml_get_widget(glade, "main_window");
150
151     sn_d = sn_display_new(GDK_DISPLAY_XDISPLAY(gdk_display_get_default()),
152                           NULL, NULL);
153
154     sn_cx = sn_launchee_context_new_from_environment
155         (sn_d, gdk_screen_get_number(gdk_display_get_default_screen
156                                      (gdk_display_get_default())));
157
158     if (sn_cx)
159         sn_launchee_context_setup_window
160             (sn_cx, GDK_WINDOW_XWINDOW(GDK_WINDOW(mainwin->window)));
161
162     gtk_widget_show_all(mainwin);
163
164     if (sn_cx)
165         sn_launchee_context_complete(sn_cx);
166
167     if (sn_cx)
168         sn_launchee_context_unref(sn_cx);
169     sn_display_unref(sn_d);
170
171     if (obc_theme_install)
172         handlers_install_theme(obc_theme_install);
173
174     gtk_main();
175
176     parse_paths_shutdown();
177
178     xmlFreeDoc(doc);
179     return 0;
180 }