1
/* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
3
main.c for ObConf, the configuration tool for Openbox
4
Copyright (c) 2003-2008 Dana Jansens
5
Copyright (c) 2003 Tim Riley
7
Copyright (C) 2010 Hong Jen Yee (PCMan) <pcman.tw@gmail.com>
9
This program is free software; you can redistribute it and/or modify
10
it under the terms of the GNU General Public License as published by
11
the Free Software Foundation; either version 2 of the License, or
12
(at your option) any later version.
14
This program is distributed in the hope that it will be useful,
15
but WITHOUT ANY WARRANTY; without even the implied warranty of
16
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
GNU General Public License for more details.
19
See the COPYING file for a copy of the GNU General Public License.
22
/* This file is part of ObConf. It's taken by Hong Jen Yee on
23
* 2010-08-07 and some modifications were done to make it a loadable
24
* module of LXAppearance. */
33
#include "appearance.h"
34
#include "preview_update.h"
36
#include <glib/gi18n-lib.h>
38
#include "lxappearance/lxappearance.h"
42
GtkWidget *mainwin = NULL;
48
gchar *obc_config_file = NULL;
50
static gchar *obc_theme_install = NULL;
51
static gchar *obc_theme_archive = NULL;
53
void obconf_error(gchar *msg, gboolean modal)
57
d = gtk_message_dialog_new(mainwin ? GTK_WINDOW(mainwin) : NULL,
58
GTK_DIALOG_DESTROY_WITH_PARENT,
62
gtk_window_set_title(GTK_WINDOW(d), "ObConf Error");
64
gtk_dialog_run(GTK_DIALOG(d));
66
g_signal_connect_swapped(GTK_OBJECT(d), "response",
67
G_CALLBACK(gtk_widget_destroy),
73
static gboolean get_all(Window win, Atom prop, Atom type, gint size,
74
guchar **data, guint *num)
81
gulong ret_items, bytes_left;
83
res = XGetWindowProperty(GDK_DISPLAY(), win, prop, 0l, G_MAXLONG,
84
FALSE, type, &ret_type, &ret_size,
85
&ret_items, &bytes_left, &xdata);
87
if (ret_size == size && ret_items > 0) {
90
*data = g_malloc(ret_items * (size / 8));
91
for (i = 0; i < ret_items; ++i)
94
(*data)[i] = xdata[i];
97
((guint16*)*data)[i] = ((gushort*)xdata)[i];
100
((guint32*)*data)[i] = ((gulong*)xdata)[i];
103
g_assert_not_reached(); /* unhandled size */
113
static gboolean prop_get_string_utf8(Window win, Atom prop, gchar **ret)
119
if (get_all(win, prop,
120
gdk_x11_get_xatom_by_name("UTF8_STRING"),
121
8,(guchar**)&raw, &num))
123
str = g_strndup(raw, num); /* grab the first string from the list */
125
if (g_utf8_validate(str, -1, NULL)) {
134
static void on_response(GtkDialog* dlg, int res, LXAppearance* app)
136
if(res == GTK_RESPONSE_APPLY)
142
/* int main(int argc, char **argv) */
143
extern gboolean plugin_load(LXAppearance* app, GtkBuilder* lxappearance_builder)
146
gboolean exit_with_error = FALSE;
148
/* ABI compatibility check. */
149
if(app->abi_version > LXAPPEARANCE_ABI_VERSION)
153
const char* wm_name = gdk_x11_screen_get_window_manager_name(gtk_widget_get_screen(app->dlg));
154
if(g_strcmp0(wm_name, "Openbox"))
155
return FALSE; /* don't load the plugin if openbox is not in use. */
158
bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR);
159
bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
164
builder = gtk_builder_new();
165
gtk_builder_set_translation_domain(builder, GETTEXT_PACKAGE);
166
g_debug(GLADEDIR"/obconf.glade");
167
if(!gtk_builder_add_from_file(builder, GLADEDIR"/obconf.glade", NULL))
169
obconf_error(_("Failed to load the obconf.glade interface file. ObConf is probably not installed correctly."), TRUE);
170
exit_with_error = TRUE;
172
gtk_builder_connect_signals(builder, NULL);
173
gtk_box_pack_start(app->wm_page, get_widget("obconf_vbox"), TRUE, TRUE, 0);
174
gtk_widget_show_all(app->wm_page);
176
g_signal_connect(app->dlg, "response", G_CALLBACK(on_response), app);
178
parse_paths_startup();
180
if (!obc_config_file) {
183
if (prop_get_string_utf8(GDK_ROOT_WINDOW(),
184
gdk_x11_get_xatom_by_name("_OB_CONFIG_FILE"),
187
obc_config_file = g_filename_from_utf8(p, -1, NULL, NULL, NULL);
192
xmlIndentTreeOutput = 1;
193
if (!parse_load_rc(obc_config_file, &doc, &root)) {
194
obconf_error(_("Failed to load an rc.xml. Openbox is probably not installed correctly."), TRUE);
195
exit_with_error = TRUE;
198
/* look for parsing errors */
200
xmlErrorPtr e = xmlGetLastError();
202
char *a = g_strdup_printf
203
(_("Error while parsing the Openbox configuration file. Your configuration file is not valid XML.\n\nMessage: %s"),
205
obconf_error(a, TRUE);
207
exit_with_error = TRUE;
211
rrinst = RrInstanceNew(GDK_DISPLAY(), gdk_x11_get_default_screen());
212
if (!exit_with_error) {
214
appearance_setup_tab();
217
return !exit_with_error;
220
extern void plugin_unload(LXAppearance* app)
222
preview_update_set_active_font(NULL);
223
preview_update_set_inactive_font(NULL);
224
preview_update_set_menu_header_font(NULL);
225
preview_update_set_menu_item_font(NULL);
226
preview_update_set_osd_font(NULL);
227
preview_update_set_title_layout(NULL);
229
RrInstanceFree(rrinst);
230
parse_paths_shutdown();