forget canvas for a while (now it looks horrible)
[simple-launcher] / settings-dialog.cc
1 // This file is a part of Simple Launcher
2 //
3 // Copyright (C) 2006, 2007, Mikhail Sobolev
4 //
5 // Simple Launcher is free software; you can redistribute it and/or modify it
6 // under the terms of the GNU General Public License version 2 as published by
7 // the Free Software Foundation.
8 //
9 // This program is distributed in the hope that it will be useful, but WITHOUT
10 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 // FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
12 // more details.
13 //
14 // You should have received a copy of the GNU General Public License along with
15 // this program; if not, write to the Free Software Foundation, Inc., 51
16 // Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
17
18 #include <gtk/gtkvbox.h>
19 #include <gtk/gtkhbox.h>
20 #include <gtk/gtksizegroup.h>
21 #include <gtk/gtknotebook.h>
22 #include <gtk/gtklabel.h>
23 #include <gtk/gtkcheckbutton.h>
24
25 #include "settings-dialog.h"
26
27 #define SL_APPLET_SETTINGS_ICON_SIZE  26
28
29 // FIXME: UGLY!!!!
30
31 inline void addPage(GtkNotebook *notebook, const std::string& name, GtkWidget *widget) {
32   GtkWidget *label = gtk_label_new(name.c_str());
33
34   gtk_notebook_append_page(notebook, widget, label);
35 }
36
37 inline GtkWidget *packItTogether(GtkBox *parent, GtkSizeGroup *group, const std::string& name, GtkWidget *content) {
38   GtkWidget *box = gtk_hbox_new(false, 0);
39   GtkWidget *label = gtk_label_new(name.c_str());
40
41   gtk_size_group_add_widget(group, label);
42   gtk_box_pack_start(GTK_BOX(box), label, true, true, 0);
43   gtk_box_pack_start(GTK_BOX(box), content, true, true, 0);
44
45   gtk_box_pack_start(parent, box, false, false, 0);
46
47   return box;
48 }
49
50 inline GtkWidget *createUIPage() {
51   GtkSizeGroup *group = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
52   GtkWidget *vbox = gtk_vbox_new(true, 0);
53
54   // packItTogether(group, "Button Size:", <small/big>);
55   packItTogether(GTK_BOX(vbox), group, "Transparent background:", gtk_check_button_new());
56   packItTogether(GTK_BOX(vbox), group, "Show Infobanner:", gtk_check_button_new());
57
58   g_object_unref(G_OBJECT(group));
59
60   return vbox;
61 }
62
63 SettingsDialog::SettingsDialog(GtkWindow *parent, LauncherItems& items, GConfBooleanOption& transparent, GConfIntegerOption& icon_size):
64   myList(SL_APPLET_SETTINGS_ICON_SIZE, items),
65   myTransparent(transparent, "Transparent background:"), myIconSize(icon_size, "Icon Size:") {
66   myDialog = GTK_DIALOG(gtk_dialog_new_with_buttons("Launcher Settings", parent, (GtkDialogFlags)(GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT), "OK", GTK_RESPONSE_OK, "Cancel", GTK_RESPONSE_CANCEL, NULL));
67
68   GtkNotebook *notebook = GTK_NOTEBOOK(gtk_notebook_new());
69
70   gtk_container_add(GTK_CONTAINER(myDialog->vbox), GTK_WIDGET(notebook));
71
72   addPage(notebook, "UI", createUIPage());
73   addPage(notebook, "Items", myList.getWidget());
74
75   gtk_widget_set_size_request(GTK_WIDGET(myDialog), 540, 324);
76
77   gtk_widget_show_all(GTK_WIDGET(notebook));
78   gtk_notebook_set_current_page(notebook, 0);
79 }
80
81 SettingsDialog::~SettingsDialog() {
82   gtk_widget_destroy(GTK_WIDGET(myDialog));
83 }
84
85 gint SettingsDialog::run() {
86   gtk_widget_show_all(GTK_WIDGET(myDialog));
87
88   return gtk_dialog_run(myDialog);
89 }
90
91 void SettingsDialog::updateValues() {
92   myTransparent.updateValue();
93   myIconSize.updateValue();
94 }
95
96 // vim:ts=2:sw=2:et