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;
53
static gchar *obc_theme_install = NULL;
54
static gchar *obc_theme_archive = NULL;
58
extern gboolean plugin_load(LXAppearance* app, GtkBuilder* lxappearance_builder);
59
extern void plugin_unload(LXAppearance* app) ;
62
void obconf_error(gchar *msg, gboolean modal)
66
d = gtk_message_dialog_new(mainwin ? GTK_WINDOW(mainwin) : NULL,
67
GTK_DIALOG_DESTROY_WITH_PARENT,
71
gtk_window_set_title(GTK_WINDOW(d), "ObConf Error");
73
gtk_dialog_run(GTK_DIALOG(d));
75
g_signal_connect_swapped(GTK_WIDGET(d), "response",
76
G_CALLBACK(gtk_widget_destroy),
82
static gboolean get_all(Window win, Atom prop, Atom type, gint size,
83
guchar **data, guint *num)
90
gulong ret_items, bytes_left;
92
res = XGetWindowProperty(GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), win, prop, 0l, G_MAXLONG,
93
FALSE, type, &ret_type, &ret_size,
94
&ret_items, &bytes_left, &xdata);
96
if (ret_size == size && ret_items > 0) {
99
*data = g_malloc(ret_items * (size / 8));
100
for (i = 0; i < ret_items; ++i)
103
(*data)[i] = xdata[i];
106
((guint16*)*data)[i] = ((gushort*)xdata)[i];
109
((guint32*)*data)[i] = ((gulong*)xdata)[i];
112
g_assert_not_reached(); /* unhandled size */
122
static gboolean prop_get_string_utf8(Window win, Atom prop, gchar **ret)
128
if (get_all(win, prop,
129
gdk_x11_get_xatom_by_name("UTF8_STRING"),
130
8,(guchar**)&raw, &num))
132
str = g_strndup(raw, num); /* grab the first string from the list */
134
if (g_utf8_validate(str, -1, NULL)) {
143
static void on_response(GtkDialog* dlg, int res, LXAppearance* app)
145
if(res == GTK_RESPONSE_APPLY)
151
/* int main(int argc, char **argv) */
152
extern gboolean plugin_load(LXAppearance* app, GtkBuilder* lxappearance_builder)
154
gboolean exit_with_error = FALSE;
156
/* ABI compatibility check. */
157
if(app->abi_version > LXAPPEARANCE_ABI_VERSION)
161
const char* wm_name = gdk_x11_screen_get_window_manager_name(gtk_widget_get_screen(app->dlg));
162
if(g_strcmp0(wm_name, "Openbox"))
163
return FALSE; /* don't load the plugin if openbox is not in use. */
166
bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR);
167
bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
172
builder = gtk_builder_new();
173
gtk_builder_set_translation_domain(builder, GETTEXT_PACKAGE);
174
g_debug(GLADEDIR"/obconf.glade");
175
if(!gtk_builder_add_from_file(builder, GLADEDIR"/obconf.glade", NULL))
177
obconf_error(_("Failed to load the obconf.glade interface file. ObConf is probably not installed correctly."), TRUE);
178
exit_with_error = TRUE;
180
gtk_builder_connect_signals(builder, NULL);
181
gtk_box_pack_start( GTK_BOX(app->wm_page), get_widget("obconf_vbox"), TRUE, TRUE, 0);
182
gtk_widget_show_all(app->wm_page);
184
g_signal_connect(app->dlg, "response", G_CALLBACK(on_response), app);
186
paths = obt_paths_new();
187
xml_i = obt_xml_instance_new();
189
if (!obc_config_file) {
192
if (prop_get_string_utf8(GDK_ROOT_WINDOW(),
193
gdk_x11_get_xatom_by_name("_OB_CONFIG_FILE"),
196
obc_config_file = g_filename_from_utf8(p, -1, NULL, NULL, NULL);
201
xmlIndentTreeOutput = 1;
203
/* if (!obt_xml_load_config_file(xml_i,
206
obc_config_file : "rc.xml"),
207
"openbox_config")) */
208
if(!obt_xml_load_config_file(xml_i,
213
obconf_error(_("Failed to load an rc.xml. Openbox is probably not installed correctly."), TRUE);
214
exit_with_error = TRUE;
217
doc = obt_xml_doc(xml_i);
218
root = obt_xml_root(xml_i);
221
/* look for parsing errors */
223
xmlErrorPtr e = xmlGetLastError();
225
char *a = g_strdup_printf
226
(_("Error while parsing the Openbox configuration file. Your configuration file is not valid XML.\n\nMessage: %s"),
228
obconf_error(a, TRUE);
230
exit_with_error = TRUE;
234
rrinst = RrInstanceNew(GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), gdk_x11_get_default_screen());
235
if (!exit_with_error) {
237
appearance_setup_tab();
240
return !exit_with_error;
243
extern void plugin_unload(LXAppearance* app)
245
preview_update_set_active_font(NULL);
246
preview_update_set_inactive_font(NULL);
247
preview_update_set_menu_header_font(NULL);
248
preview_update_set_menu_item_font(NULL);
249
preview_update_set_active_osd_font(NULL);
250
preview_update_set_inactive_osd_font(NULL);
251
preview_update_set_title_layout(NULL);
253
RrInstanceFree(rrinst);
254
obt_xml_instance_unref(xml_i);
255
obt_paths_unref(paths);