~ubuntu-branches/ubuntu/raring/lxappearance-obconf/raring

« back to all changes in this revision

Viewing changes to .pc/03-openbox-3.5.patch/src/main.c

  • Committer: Bazaar Package Importer
  • Author(s): Julien Lavergne
  • Date: 2011-08-24 21:51:41 UTC
  • Revision ID: james.westby@ubuntu.com-20110824215141-o2r98rkwimai8r0k
Tags: 0.0.1-0ubuntu2
* debian/patches:
 - 0*-openbox-3.5.patch: Apply several patches from upstream to fix building
   with openbox 3.5 (LP: #831095).
 - 99-fix-translations.patch: Fix build with above patches.
* debian/rules:
 - Use autoreconf with 01-openbox-3.5.patch.
 - Create missing m4/ folder.
* debian/control:
 - Bump build-depends on openbox (>= 3.5.0).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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-2008   Dana Jansens
 
5
   Copyright (c) 2003        Tim Riley
 
6
 
 
7
   Copyright (C) 2010        Hong Jen Yee (PCMan) <pcman.tw@gmail.com>
 
8
 
 
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.
 
13
 
 
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.
 
18
 
 
19
   See the COPYING file for a copy of the GNU General Public License.
 
20
*/
 
21
 
 
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. */
 
25
 
 
26
#ifdef HAVE_CONFIG_H
 
27
#include <config.h>
 
28
#endif
 
29
 
 
30
#include "main.h"
 
31
#include "archive.h"
 
32
#include "theme.h"
 
33
#include "appearance.h"
 
34
#include "preview_update.h"
 
35
#include "tree.h"
 
36
#include <glib/gi18n-lib.h>
 
37
 
 
38
#include "lxappearance/lxappearance.h"
 
39
 
 
40
#include <gdk/gdkx.h>
 
41
 
 
42
GtkWidget *mainwin = NULL;
 
43
 
 
44
GtkBuilder* builder;
 
45
xmlDocPtr doc;
 
46
xmlNodePtr root;
 
47
RrInstance *rrinst;
 
48
gchar *obc_config_file = NULL;
 
49
ObtPaths *paths;
 
50
ObtXmlInst *xml_i;
 
51
 
 
52
/* Disable, not used
 
53
static gchar *obc_theme_install = NULL;
 
54
static gchar *obc_theme_archive = NULL;
 
55
*/
 
56
 
 
57
/* Forwarded */
 
58
extern gboolean plugin_load(LXAppearance* app, GtkBuilder* lxappearance_builder);
 
59
extern void plugin_unload(LXAppearance* app) ;
 
60
/* End Forwarded */
 
61
 
 
62
void obconf_error(gchar *msg, gboolean modal)
 
63
{
 
64
    GtkWidget *d;
 
65
 
 
66
    d = gtk_message_dialog_new(mainwin ? GTK_WINDOW(mainwin) : NULL,
 
67
                               GTK_DIALOG_DESTROY_WITH_PARENT,
 
68
                               GTK_MESSAGE_ERROR,
 
69
                               GTK_BUTTONS_CLOSE,
 
70
                               "%s", msg);
 
71
    gtk_window_set_title(GTK_WINDOW(d), "ObConf Error");
 
72
    if (modal)
 
73
        gtk_dialog_run(GTK_DIALOG(d));
 
74
    else {
 
75
        g_signal_connect_swapped(GTK_WIDGET(d), "response",
 
76
                                 G_CALLBACK(gtk_widget_destroy),
 
77
                                 GTK_WIDGET(d));
 
78
        gtk_widget_show(d);
 
79
    }
 
80
}
 
81
 
 
82
static gboolean get_all(Window win, Atom prop, Atom type, gint size,
 
83
                        guchar **data, guint *num)
 
84
{
 
85
    gboolean ret = FALSE;
 
86
    gint res;
 
87
    guchar *xdata = NULL;
 
88
    Atom ret_type;
 
89
    gint ret_size;
 
90
    gulong ret_items, bytes_left;
 
91
 
 
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);
 
95
    if (res == Success) {
 
96
        if (ret_size == size && ret_items > 0) {
 
97
            guint i;
 
98
 
 
99
            *data = g_malloc(ret_items * (size / 8));
 
100
            for (i = 0; i < ret_items; ++i)
 
101
                switch (size) {
 
102
                case 8:
 
103
                    (*data)[i] = xdata[i];
 
104
                    break;
 
105
                case 16:
 
106
                    ((guint16*)*data)[i] = ((gushort*)xdata)[i];
 
107
                    break;
 
108
                case 32:
 
109
                    ((guint32*)*data)[i] = ((gulong*)xdata)[i];
 
110
                    break;
 
111
                default:
 
112
                    g_assert_not_reached(); /* unhandled size */
 
113
                }
 
114
            *num = ret_items;
 
115
            ret = TRUE;
 
116
        }
 
117
        XFree(xdata);
 
118
    }
 
119
    return ret;
 
120
}
 
121
 
 
122
static gboolean prop_get_string_utf8(Window win, Atom prop, gchar **ret)
 
123
{
 
124
    gchar *raw;
 
125
    gchar *str;
 
126
    guint num;
 
127
 
 
128
    if (get_all(win, prop,
 
129
                gdk_x11_get_xatom_by_name("UTF8_STRING"),
 
130
                8,(guchar**)&raw, &num))
 
131
    {
 
132
        str = g_strndup(raw, num); /* grab the first string from the list */
 
133
        g_free(raw);
 
134
        if (g_utf8_validate(str, -1, NULL)) {
 
135
            *ret = str;
 
136
            return TRUE;
 
137
        }
 
138
        g_free(str);
 
139
    }
 
140
    return FALSE;
 
141
}
 
142
 
 
143
static void on_response(GtkDialog* dlg, int res, LXAppearance* app)
 
144
{
 
145
    if(res == GTK_RESPONSE_APPLY)
 
146
    {
 
147
        tree_apply();
 
148
    }
 
149
}
 
150
 
 
151
/* int main(int argc, char **argv) */
 
152
extern gboolean plugin_load(LXAppearance* app, GtkBuilder* lxappearance_builder)
 
153
{
 
154
    gboolean exit_with_error = FALSE;
 
155
 
 
156
    /* ABI compatibility check. */
 
157
    if(app->abi_version > LXAPPEARANCE_ABI_VERSION)
 
158
        return FALSE;
 
159
 
 
160
    /* detect openbox */
 
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. */
 
164
 
 
165
#ifdef ENABLE_NLS
 
166
    bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR);
 
167
    bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
 
168
#endif
 
169
 
 
170
    mainwin = app->dlg;
 
171
 
 
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))
 
176
    {
 
177
        obconf_error(_("Failed to load the obconf.glade interface file. ObConf is probably not installed correctly."), TRUE);
 
178
        exit_with_error = TRUE;
 
179
    }
 
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);
 
183
 
 
184
    g_signal_connect(app->dlg, "response", G_CALLBACK(on_response), app);
 
185
 
 
186
    paths = obt_paths_new();
 
187
    xml_i = obt_xml_instance_new();
 
188
 
 
189
    if (!obc_config_file) {
 
190
        gchar *p;
 
191
 
 
192
        if (prop_get_string_utf8(GDK_ROOT_WINDOW(),
 
193
                                 gdk_x11_get_xatom_by_name("_OB_CONFIG_FILE"),
 
194
                                 &p))
 
195
        {
 
196
            obc_config_file = g_filename_from_utf8(p, -1, NULL, NULL, NULL);
 
197
            g_free(p);
 
198
        }
 
199
    }
 
200
 
 
201
    xmlIndentTreeOutput = 1;
 
202
 
 
203
    /* if (!obt_xml_load_config_file(xml_i,
 
204
                                    "openbox",
 
205
                                    (obc_config_file ?
 
206
                                     obc_config_file : "rc.xml"),
 
207
                                    "openbox_config")) */
 
208
     if(!obt_xml_load_config_file(xml_i,
 
209
                                  "openbox",
 
210
                                  "rc.xml",
 
211
                                  "openbox_config"))
 
212
    {
 
213
        obconf_error(_("Failed to load an rc.xml. Openbox is probably not installed correctly."), TRUE);
 
214
        exit_with_error = TRUE;
 
215
    }
 
216
    else {
 
217
        doc = obt_xml_doc(xml_i);
 
218
        root = obt_xml_root(xml_i);
 
219
    }
 
220
 
 
221
    /* look for parsing errors */
 
222
    {
 
223
        xmlErrorPtr e = xmlGetLastError();
 
224
        if (e) {
 
225
            char *a = g_strdup_printf
 
226
                (_("Error while parsing the Openbox configuration file. Your configuration file is not valid XML.\n\nMessage: %s"),
 
227
                 e->message);
 
228
            obconf_error(a, TRUE);
 
229
            g_free(a);
 
230
            exit_with_error = TRUE;
 
231
        }
 
232
    }
 
233
 
 
234
    rrinst = RrInstanceNew(GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), gdk_x11_get_default_screen());
 
235
    if (!exit_with_error) {
 
236
        theme_setup_tab();
 
237
        appearance_setup_tab();
 
238
        theme_load_all();
 
239
    }
 
240
    return !exit_with_error;
 
241
}
 
242
 
 
243
extern void plugin_unload(LXAppearance* app)
 
244
{
 
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);
 
252
 
 
253
    RrInstanceFree(rrinst);
 
254
    obt_xml_instance_unref(xml_i);
 
255
    obt_paths_unref(paths);
 
256
 
 
257
    xmlFreeDoc(doc);
 
258
}