major refactoring of the settings dialog; SLAList class is renamed to SettingsPageWit...
[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/gtknotebook.h>
19 #include <gtk/gtklabel.h>
20
21 #include "settings-dialog.h"
22 #include "settings-page-entries.h"
23
24 #define SL_APPLET_SETTINGS_ICON_SIZE  26
25
26 SettingsDialog::SettingsDialog(GtkWindow *parent, LauncherItems& items, GConfBooleanOption& transparent, GConfIntegerOption& icon_size):
27   myTransparent(transparent, "Transparent background:"),
28   myIconSize(icon_size, "Icon Size:", 26, 64) {
29   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));
30
31   myNotebook = GTK_NOTEBOOK(gtk_notebook_new());
32
33   gtk_container_add(GTK_CONTAINER(myDialog->vbox), GTK_WIDGET(myNotebook));
34
35   SettingsPageWithEntries *uiPage = new SettingsPageWithEntries();
36   uiPage->addEntry(&myTransparent);
37   uiPage->addEntry(&myIconSize);
38
39   SettingsPageWithItems *itemsPage = new SettingsPageWithItems(SL_APPLET_SETTINGS_ICON_SIZE, items);
40
41   addPage("UI", uiPage);
42   addPage("Items", itemsPage);
43
44   gtk_widget_set_size_request(GTK_WIDGET(myDialog), 540, 324);
45 }
46
47 SettingsDialog::~SettingsDialog() {
48   for (std::vector<SettingsPage *>::iterator it = myPages.begin(); it != myPages.end() ; ++it) {
49     delete *it;
50   }
51
52   myPages.resize(0);
53
54   gtk_widget_destroy(GTK_WIDGET(myDialog));
55 }
56
57 void SettingsDialog::addPage(const std::string& name, SettingsPage *page) {
58   myPages.push_back(page);
59
60   GtkWidget *label = gtk_label_new(name.c_str());
61
62   gtk_notebook_append_page(myNotebook, page->getWidget(), label);
63 }
64
65 gint SettingsDialog::run() {
66   gtk_widget_show_all(GTK_WIDGET(myDialog));
67   gtk_notebook_set_current_page(myNotebook, 0);
68
69   return gtk_dialog_run(myDialog);
70 }
71
72 void SettingsDialog::updateValues() {
73   myTransparent.updateValue();
74   myIconSize.updateValue();
75 }
76
77 // vim:ts=2:sw=2:et