db156a4b46f6182b9796066140759714bf86dde5
[dana/openbox.git] / tools / obconf / main.c
1 #include "obconf.h"
2 #include "plugins.h"
3 #include "parser/parse.h"
4 #include "gettext.h"
5
6 #include <gtk/gtk.h>
7 #include <gdk-pixbuf/gdk-pixbuf.h>
8
9 #define OB_ICON "openbox-icon"
10
11 static GtkWidget *mainwin;
12 static GdkPixbuf *ob_icon;
13
14 static void obconf_error(GError *e)
15 {
16     GtkWidget *d;
17
18     d = gtk_message_dialog_new(mainwin ? GTK_WINDOW(mainwin) : NULL,
19                                GTK_DIALOG_DESTROY_WITH_PARENT,
20                                GTK_MESSAGE_ERROR,
21                                GTK_BUTTONS_CLOSE,
22                                "%s", e->message);
23     g_signal_connect_swapped(GTK_OBJECT(d), "response",
24                              G_CALLBACK(gtk_widget_destroy),
25                              GTK_OBJECT(d));
26     gtk_widget_show(d);
27 }
28
29 static void load_stock ()
30 {
31     GtkIconFactory *factory;
32     GError *e = NULL;
33
34     gtk_icon_factory_add_default (factory = gtk_icon_factory_new ());
35
36     ob_icon = gdk_pixbuf_new_from_file (PIXMAPDIR G_DIR_SEPARATOR_S
37                                         "openbox.png", &e);
38     if (!ob_icon) {
39         gchar *msg = g_strdup_printf 
40             (_("Failed to load the Openbox icon, Openbox is probably not "
41                "installed correctly. The error given was '%s'."),
42              e->message);
43         g_free (e->message);
44         e->message = msg;
45         obconf_error (e);
46     } else {
47         GtkIconSet *set;
48
49         set = gtk_icon_set_new_from_pixbuf (ob_icon);
50         gtk_icon_factory_add (factory, OB_ICON, set);
51         gtk_icon_set_unref (set);
52     }
53 }
54
55 int main(int argc, char **argv)
56 {
57     gtk_set_locale();
58     gtk_init(&argc, &argv);
59
60     mainwin = gtk_window_new(GTK_WINDOW_TOPLEVEL);
61     gtk_window_set_title(GTK_WINDOW(mainwin), "Obconf");
62     gtk_window_set_wmclass(GTK_WINDOW(mainwin), "obconf", "Obconf");
63     gtk_window_set_role(GTK_WINDOW(mainwin), "main window");
64
65     gtk_widget_show_all(mainwin);
66
67     load_stock();
68     if (ob_icon) gtk_window_set_icon(GTK_WINDOW(mainwin), ob_icon);
69
70     gtk_main();
71     return 0;
72 }
73
74 gboolean on_mainwindow_delete_event(GtkWidget *w, GdkEvent *e, gpointer d)
75 {
76     gtk_main_quit();
77     return FALSE;
78 }
79
80 void on_quit_activate(GtkMenuItem *item, gpointer d)
81 {
82     gtk_main_quit();
83 }
84
85 void on_applybutton_clicked(GtkButton *but, gpointer d)
86 {
87     g_message("apply\n");
88 }
89
90 void on_revertbutton_clicked(GtkButton *but, gpointer d)
91 {
92     g_message("revert\n");
93 }
94
95 void on_helpbutton_clicked(GtkButton *but, gpointer d)
96 {
97     g_message("help\n");
98 }
99
100 void on_sectiontree_row_activated(GtkTreeView *tree, GtkTreePath *path,
101                                   GtkTreeViewColumn *col, gpointer p)
102 {
103     g_message("activated\n");
104 }