From aa84cee2b7bb52f2c41b54a0f8dd9c76197ecab4 Mon Sep 17 00:00:00 2001 From: mishas Date: Sat, 14 Apr 2007 17:06:51 +0000 Subject: [PATCH] major refactoring of the settings dialog; SLAList class is renamed to SettingsPageWithItems (file names will follow) git-svn-id: file:///svnroot/simple-launcher/trunk@184 3ba93dab-e023-0410-b42a-de7732cf370a --- Makefile | 2 +- debian/changelog | 6 ++-- dialog-entry.cc | 19 +++++++++++++ dialog-entry.h | 28 ++++++++++++++----- settings-dialog.cc | 69 +++++++++++++++++----------------------------- settings-dialog.h | 8 +++++- settings-page-entries.cc | 47 +++++++++++++++++++++++++++++++ settings-page-entries.h | 42 ++++++++++++++++++++++++++++ settings-page.h | 32 +++++++++++++++++++++ sla-list.cc | 44 ++++++++++++++--------------- sla-list.h | 11 +++++--- 11 files changed, 227 insertions(+), 81 deletions(-) create mode 100644 settings-page-entries.cc create mode 100644 settings-page-entries.h create mode 100644 settings-page.h diff --git a/Makefile b/Makefile index e7b2109..978724a 100644 --- a/Makefile +++ b/Makefile @@ -20,7 +20,7 @@ all: $(TARGET) tests: test test1 test2 -$(TARGET): simple-launcher.o launchable-item.o launcher-item.o sla-list.o utils.o settings-dialog.o gconf-wrapper.o dialog-entry.o +$(TARGET): simple-launcher.o launchable-item.o launcher-item.o sla-list.o utils.o settings-dialog.o gconf-wrapper.o dialog-entry.o settings-page-entries.o $(LD) $(LDFLAGS) -o $@ $^ $(LIBS) test: test.o launcher-item.o diff --git a/debian/changelog b/debian/changelog index 674c7ec..a54133b 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,4 +1,4 @@ -simple-launcher (0.9.4~14) unstable; urgency=low +simple-launcher (0.9.4~15) unstable; urgency=low * NOT RELEASED YET * settings dialog is moved into a separate class @@ -17,8 +17,10 @@ simple-launcher (0.9.4~14) unstable; urgency=low * added dummy checkboxes and UI settings page * added a configurable canvas around button icons * added GConf*Options to SimpleLauncherApplet + * major refactoring of the settings dialog + * SLAList class is renamed to SettingsPageWithItems (file names will follow) - -- Mikhail Sobolev Thu, 12 Apr 2007 15:54:04 +0300 + -- Mikhail Sobolev Sat, 14 Apr 2007 20:05:45 +0300 simple-launcher (0.9.3) unstable; urgency=low diff --git a/dialog-entry.cc b/dialog-entry.cc index eadc878..2db6581 100644 --- a/dialog-entry.cc +++ b/dialog-entry.cc @@ -15,6 +15,25 @@ // this program; if not, write to the Free Software Foundation, Inc., 51 // Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +#include + #include "dialog-entry.h" +SettingsDialogBooleanEntry::SettingsDialogBooleanEntry(GConfBooleanOption& option, const std::string& name): SettingsDialogEntry(option, name) { + myWidget = gtk_check_button_new(); + + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(myWidget), option.value()); +} + +void SettingsDialogBooleanEntry::updateValue() { + ((GConfBooleanOption&)myOption).setValue(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(myWidget))); +} + +SettingsDialogIntegerEntry::SettingsDialogIntegerEntry(GConfIntegerOption& option, const std::string& name, int minValue, int maxValue): SettingsDialogEntry(option, name) { + mySpinBox = HILDON_NUMBER_EDITOR(hildon_number_editor_new(minValue, maxValue)); + hildon_number_editor_set_value(mySpinBox, option.value()); +} +void SettingsDialogIntegerEntry::updateValue() { + ((GConfIntegerOption&)myOption).setValue(hildon_number_editor_get_value(mySpinBox)); +} diff --git a/dialog-entry.h b/dialog-entry.h index 6a70aed..daa5e81 100644 --- a/dialog-entry.h +++ b/dialog-entry.h @@ -18,20 +18,25 @@ #ifndef _DIALOG_ENTRY_H_ #define _DIALOG_ENTRY_H_ +#include + +#include + #include "gconf-wrapper.h" class SettingsDialogEntry { public: virtual ~SettingsDialogEntry() {} -protected: - SettingsDialogEntry(GConfOption& option, const std::string& name): myOption(option), myName(name) {} - const std::string& name() const { return myName; } + virtual GtkWidget *getWidget() const = 0; virtual void updateValue() = 0; protected: + SettingsDialogEntry(GConfOption& option, const std::string& name): myOption(option), myName(name) {} + +protected: GConfOption& myOption; const std::string myName; }; @@ -41,20 +46,29 @@ public: SettingsDialogStringEntry(GConfStringOption& option, const std::string& name): SettingsDialogEntry(option, name) {} void updateValue(); + GtkWidget *getWidget() const; }; class SettingsDialogBooleanEntry : public SettingsDialogEntry { public: - SettingsDialogBooleanEntry(GConfBooleanOption& option, const std::string& name): SettingsDialogEntry(option, name) {} + SettingsDialogBooleanEntry(GConfBooleanOption& option, const std::string& name); + + void updateValue(); + GtkWidget *getWidget() const { return myWidget; } - void updateValue() {} +private: + GtkWidget *myWidget; }; class SettingsDialogIntegerEntry : public SettingsDialogEntry { public: - SettingsDialogIntegerEntry(GConfIntegerOption& option, const std::string& name): SettingsDialogEntry(option, name) {} + SettingsDialogIntegerEntry(GConfIntegerOption& option, const std::string& name, int minValue, int maxValue); + + void updateValue(); + GtkWidget *getWidget() const { return GTK_WIDGET(mySpinBox); } - void updateValue() {} +private: + HildonNumberEditor *mySpinBox; }; #endif diff --git a/settings-dialog.cc b/settings-dialog.cc index f0cdfe9..cb0b769 100644 --- a/settings-dialog.cc +++ b/settings-dialog.cc @@ -15,75 +15,56 @@ // this program; if not, write to the Free Software Foundation, Inc., 51 // Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -#include -#include -#include #include #include -#include #include "settings-dialog.h" +#include "settings-page-entries.h" #define SL_APPLET_SETTINGS_ICON_SIZE 26 -// FIXME: UGLY!!!! +SettingsDialog::SettingsDialog(GtkWindow *parent, LauncherItems& items, GConfBooleanOption& transparent, GConfIntegerOption& icon_size): + myTransparent(transparent, "Transparent background:"), + myIconSize(icon_size, "Icon Size:", 26, 64) { + 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)); -inline void addPage(GtkNotebook *notebook, const std::string& name, GtkWidget *widget) { - GtkWidget *label = gtk_label_new(name.c_str()); + myNotebook = GTK_NOTEBOOK(gtk_notebook_new()); - gtk_notebook_append_page(notebook, widget, label); -} + gtk_container_add(GTK_CONTAINER(myDialog->vbox), GTK_WIDGET(myNotebook)); -inline GtkWidget *packItTogether(GtkBox *parent, GtkSizeGroup *group, const std::string& name, GtkWidget *content) { - GtkWidget *box = gtk_hbox_new(false, 0); - GtkWidget *label = gtk_label_new(name.c_str()); + SettingsPageWithEntries *uiPage = new SettingsPageWithEntries(); + uiPage->addEntry(&myTransparent); + uiPage->addEntry(&myIconSize); - gtk_size_group_add_widget(group, label); - gtk_box_pack_start(GTK_BOX(box), label, true, true, 0); - gtk_box_pack_start(GTK_BOX(box), content, true, true, 0); + SettingsPageWithItems *itemsPage = new SettingsPageWithItems(SL_APPLET_SETTINGS_ICON_SIZE, items); - gtk_box_pack_start(parent, box, false, false, 0); + addPage("UI", uiPage); + addPage("Items", itemsPage); - return box; + gtk_widget_set_size_request(GTK_WIDGET(myDialog), 540, 324); } -inline GtkWidget *createUIPage() { - GtkSizeGroup *group = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL); - GtkWidget *vbox = gtk_vbox_new(true, 0); - - // packItTogether(group, "Button Size:", ); - packItTogether(GTK_BOX(vbox), group, "Transparent background:", gtk_check_button_new()); - packItTogether(GTK_BOX(vbox), group, "Show Infobanner:", gtk_check_button_new()); +SettingsDialog::~SettingsDialog() { + for (std::vector::iterator it = myPages.begin(); it != myPages.end() ; ++it) { + delete *it; + } - g_object_unref(G_OBJECT(group)); + myPages.resize(0); - return vbox; + gtk_widget_destroy(GTK_WIDGET(myDialog)); } -SettingsDialog::SettingsDialog(GtkWindow *parent, LauncherItems& items, GConfBooleanOption& transparent, GConfIntegerOption& icon_size): - myList(SL_APPLET_SETTINGS_ICON_SIZE, items), - myTransparent(transparent, "Transparent background:"), myIconSize(icon_size, "Icon Size:") { - 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)); - - GtkNotebook *notebook = GTK_NOTEBOOK(gtk_notebook_new()); - - gtk_container_add(GTK_CONTAINER(myDialog->vbox), GTK_WIDGET(notebook)); - - addPage(notebook, "UI", createUIPage()); - addPage(notebook, "Items", myList.getWidget()); - - gtk_widget_set_size_request(GTK_WIDGET(myDialog), 540, 324); +void SettingsDialog::addPage(const std::string& name, SettingsPage *page) { + myPages.push_back(page); - gtk_widget_show_all(GTK_WIDGET(notebook)); - gtk_notebook_set_current_page(notebook, 0); -} + GtkWidget *label = gtk_label_new(name.c_str()); -SettingsDialog::~SettingsDialog() { - gtk_widget_destroy(GTK_WIDGET(myDialog)); + gtk_notebook_append_page(myNotebook, page->getWidget(), label); } gint SettingsDialog::run() { gtk_widget_show_all(GTK_WIDGET(myDialog)); + gtk_notebook_set_current_page(myNotebook, 0); return gtk_dialog_run(myDialog); } diff --git a/settings-dialog.h b/settings-dialog.h index f990e53..42bda9c 100644 --- a/settings-dialog.h +++ b/settings-dialog.h @@ -18,12 +18,15 @@ #ifndef __SETTINGS_DIALOG_H_ #define __SETTINGS_DIALOG_H_ +#include + #include #include "gconf-wrapper.h" #include "sla-list.h" #include "launcher-item.h" #include "dialog-entry.h" +#include "settings-page.h" class SettingsDialog { public: @@ -34,10 +37,13 @@ public: void updateValues(); + void addPage(const std::string&, SettingsPage *); + private: - SLAList myList; + std::vector myPages; GtkDialog *myDialog; + GtkNotebook *myNotebook; SettingsDialogBooleanEntry myTransparent; SettingsDialogIntegerEntry myIconSize; diff --git a/settings-page-entries.cc b/settings-page-entries.cc new file mode 100644 index 0000000..914a31d --- /dev/null +++ b/settings-page-entries.cc @@ -0,0 +1,47 @@ +// This file is a part of Simple Launcher +// +// Copyright (C) 2006, 2007, Mikhail Sobolev +// +// Simple Launcher is free software; you can redistribute it and/or modify it +// under the terms of the GNU General Public License version 2 as published by +// the Free Software Foundation. +// +// This program is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +// more details. +// +// You should have received a copy of the GNU General Public License along with +// this program; if not, write to the Free Software Foundation, Inc., 51 +// Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +#include +#include +#include + +#include "settings-page-entries.h" + +SettingsPageWithEntries::SettingsPageWithEntries() { + myBox = gtk_vbox_new(false, 0); + myGroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL); +} + +SettingsPageWithEntries::~SettingsPageWithEntries() { + if (myGroup != NULL) { + g_object_unref(G_OBJECT(myGroup)); + myGroup = NULL; + } +} + +void SettingsPageWithEntries::addEntry(SettingsDialogEntry *entry) { + GtkWidget *box = gtk_hbox_new(false, 0); + GtkWidget *label = gtk_label_new(entry->name().c_str()); + + gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_RIGHT); + + gtk_size_group_add_widget(myGroup, label); + gtk_box_pack_start(GTK_BOX(box), label, false, false, 0); + gtk_box_pack_start(GTK_BOX(box), entry->getWidget(), false, false, 2); + + gtk_box_pack_start(GTK_BOX(myBox), box, false, false, 0); +} diff --git a/settings-page-entries.h b/settings-page-entries.h new file mode 100644 index 0000000..2c4f71f --- /dev/null +++ b/settings-page-entries.h @@ -0,0 +1,42 @@ +// This file is a part of Simple Launcher +// +// Copyright (C) 2006, 2007, Mikhail Sobolev +// +// Simple Launcher is free software; you can redistribute it and/or modify it +// under the terms of the GNU General Public License version 2 as published by +// the Free Software Foundation. +// +// This program is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +// more details. +// +// You should have received a copy of the GNU General Public License along with +// this program; if not, write to the Free Software Foundation, Inc., 51 +// Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +#ifndef _SETTINGS_PAGE_ENTRIES_H_ +#define _SETTINGS_PAGE_ENTRIES_H_ + +#include + +#include "dialog-entry.h" +#include "settings-page.h" + +class SettingsPageWithEntries : public SettingsPage { +public: + SettingsPageWithEntries(); + ~SettingsPageWithEntries(); + + GtkWidget *getWidget() const { return myBox; } + + void addEntry(SettingsDialogEntry *); + +private: + GtkWidget *myBox; + GtkSizeGroup *myGroup; +}; + +#endif + +// vim:ts=2:sw=2:et diff --git a/settings-page.h b/settings-page.h new file mode 100644 index 0000000..a6241c0 --- /dev/null +++ b/settings-page.h @@ -0,0 +1,32 @@ +// This file is a part of Simple Launcher +// +// Copyright (C) 2006, 2007, Mikhail Sobolev +// +// Simple Launcher is free software; you can redistribute it and/or modify it +// under the terms of the GNU General Public License version 2 as published by +// the Free Software Foundation. +// +// This program is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +// more details. +// +// You should have received a copy of the GNU General Public License along with +// this program; if not, write to the Free Software Foundation, Inc., 51 +// Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +#ifndef _SETTINGS_PAGE_H_ +#define _SETTINGS_PAGE_H_ + +#include + +class SettingsPage { +public: + virtual ~SettingsPage() {} + + virtual GtkWidget *getWidget() const = 0; +}; + +#endif + +// vim:ts=2:sw=2:et diff --git a/sla-list.cc b/sla-list.cc index bf101a6..6115ade 100644 --- a/sla-list.cc +++ b/sla-list.cc @@ -42,7 +42,7 @@ static GtkWidget *gtk_button_new_stock_image_only(const gchar *stock_id) { return button; } -SLAList::SLAList(int icon_size, LauncherItems& items): myWidget(NULL), myStore(NULL), myView(NULL), mySelection(NULL), myLastSelection(NULL), myItems(items) { +SettingsPageWithItems::SettingsPageWithItems(int icon_size, LauncherItems& items): myWidget(NULL), myStore(NULL), myView(NULL), mySelection(NULL), myLastSelection(NULL), myItems(items) { GtkTreeViewColumn *column; GtkCellRenderer *renderer; @@ -116,15 +116,15 @@ SLAList::SLAList(int icon_size, LauncherItems& items): myWidget(NULL), myStore(N } } -SLAList::~SLAList() { +SettingsPageWithItems::~SettingsPageWithItems() { // FIXME: do something! :) } -void SLAList::_selectionChanged(GtkTreeSelection *selection, void *self) { - ((SLAList *)self)->selectionChanged(selection); +void SettingsPageWithItems::_selectionChanged(GtkTreeSelection *selection, void *self) { + ((SettingsPageWithItems *)self)->selectionChanged(selection); } -void SLAList::selectionChanged(GtkTreeSelection *) { +void SettingsPageWithItems::selectionChanged(GtkTreeSelection *) { if (myLastSelection != NULL) { kickIt(myLastSelection); gtk_tree_iter_free(myLastSelection); @@ -140,7 +140,7 @@ void SLAList::selectionChanged(GtkTreeSelection *) { } } -void SLAList::kickIt(GtkTreeIter *iter) { +void SettingsPageWithItems::kickIt(GtkTreeIter *iter) { GtkTreePath *path = gtk_tree_model_get_path(GTK_TREE_MODEL(myStore), iter); if (path != NULL) { @@ -149,27 +149,27 @@ void SLAList::kickIt(GtkTreeIter *iter) { } } -void SLAList::_renderText(GtkTreeViewColumn *column, GtkCellRenderer *cell, GtkTreeModel *model, GtkTreeIter *iter, gpointer self) { - ((SLAList *)self)->renderText(column, cell, model, iter); +void SettingsPageWithItems::_renderText(GtkTreeViewColumn *column, GtkCellRenderer *cell, GtkTreeModel *model, GtkTreeIter *iter, gpointer self) { + ((SettingsPageWithItems *)self)->renderText(column, cell, model, iter); } -void SLAList::_renderBool(GtkTreeViewColumn *column, GtkCellRenderer *cell, GtkTreeModel *model, GtkTreeIter *iter, gpointer self) { - ((SLAList *)self)->renderBool(column, cell, model, iter); +void SettingsPageWithItems::_renderBool(GtkTreeViewColumn *column, GtkCellRenderer *cell, GtkTreeModel *model, GtkTreeIter *iter, gpointer self) { + ((SettingsPageWithItems *)self)->renderBool(column, cell, model, iter); } -void SLAList::_toggleBool(GtkCellRendererToggle *renderer, const gchar *path, void *self) { - ((SLAList *)self)->toggleBool(renderer, path); +void SettingsPageWithItems::_toggleBool(GtkCellRendererToggle *renderer, const gchar *path, void *self) { + ((SettingsPageWithItems *)self)->toggleBool(renderer, path); } -void SLAList::_moveUp(GtkButton *button, void *self) { - ((SLAList *)self)->moveUp(button); +void SettingsPageWithItems::_moveUp(GtkButton *button, void *self) { + ((SettingsPageWithItems *)self)->moveUp(button); } -void SLAList::_moveDown(GtkButton *button, void *self) { - ((SLAList *)self)->moveDown(button); +void SettingsPageWithItems::_moveDown(GtkButton *button, void *self) { + ((SettingsPageWithItems *)self)->moveDown(button); } -void SLAList::renderText(GtkTreeViewColumn *, GtkCellRenderer *cell, GtkTreeModel *model, GtkTreeIter *iter) { +void SettingsPageWithItems::renderText(GtkTreeViewColumn *, GtkCellRenderer *cell, GtkTreeModel *model, GtkTreeIter *iter) { int index; gtk_tree_model_get(GTK_TREE_MODEL(myStore), iter, SLA_STORE_COLUMN_INDEX, &index, -1); @@ -185,7 +185,7 @@ void SLAList::renderText(GtkTreeViewColumn *, GtkCellRenderer *cell, GtkTreeMode } } -void SLAList::renderBool(GtkTreeViewColumn *, GtkCellRenderer *cell, GtkTreeModel *model, GtkTreeIter *iter) { +void SettingsPageWithItems::renderBool(GtkTreeViewColumn *, GtkCellRenderer *cell, GtkTreeModel *model, GtkTreeIter *iter) { int index; gtk_tree_model_get(GTK_TREE_MODEL(myStore), iter, SLA_STORE_COLUMN_INDEX, &index, -1); @@ -193,7 +193,7 @@ void SLAList::renderBool(GtkTreeViewColumn *, GtkCellRenderer *cell, GtkTreeMode g_object_set(cell, "active", myItems[index]->isEnabled(), NULL); } -void SLAList::toggleBool(GtkCellRendererToggle *renderer, const gchar *spath) { +void SettingsPageWithItems::toggleBool(GtkCellRendererToggle *renderer, const gchar *spath) { GtkTreeIter iter; if (gtk_tree_model_get_iter_from_string(GTK_TREE_MODEL(myStore), &iter, spath)) { @@ -204,7 +204,7 @@ void SLAList::toggleBool(GtkCellRendererToggle *renderer, const gchar *spath) { } } -void SLAList::moveUp(GtkButton *) { +void SettingsPageWithItems::moveUp(GtkButton *) { GtkTreeModel *dummy; GtkTreeIter current; @@ -224,7 +224,7 @@ void SLAList::moveUp(GtkButton *) { } } -void SLAList::moveDown(GtkButton *) { +void SettingsPageWithItems::moveDown(GtkButton *) { GtkTreeModel *dummy; GtkTreeIter current; @@ -243,7 +243,7 @@ void SLAList::moveDown(GtkButton *) { } } -void SLAList::swap(GtkTreeIter& a, GtkTreeIter& b) { +void SettingsPageWithItems::swap(GtkTreeIter& a, GtkTreeIter& b) { int i1, i2; gtk_tree_model_get(GTK_TREE_MODEL(myStore), &a, SLA_STORE_COLUMN_INDEX, &i1, -1); diff --git a/sla-list.h b/sla-list.h index 7f93552..db56119 100644 --- a/sla-list.h +++ b/sla-list.h @@ -24,13 +24,16 @@ #include #include "launcher-item.h" +#include "settings-page.h" -class SLAList { +class SettingsPageWithItems : public SettingsPage { public: - SLAList(int, LauncherItems&); - ~SLAList(); + SettingsPageWithItems(int, LauncherItems&); + ~SettingsPageWithItems(); - GtkWidget *getWidget() { return myWidget; } + GtkWidget *getWidget() const { return myWidget; } + + void updateValues(); private: static void _selectionChanged(GtkTreeSelection *, gpointer); -- 1.7.9.5