From 89fc941937d92818a74a52327e6867094deb017e Mon Sep 17 00:00:00 2001 From: fgerlits Date: Mon, 15 Jan 2007 12:07:41 +0000 Subject: [PATCH] made the Cancel button work correctly for RDS entries (part of #722) --- .../src/modules/core/src/OptionsContainer.cxx | 2 +- .../gLiveSupport/src/OptionsWindow.cxx | 11 +++++ .../products/gLiveSupport/src/OptionsWindow.h | 6 +++ .../products/gLiveSupport/src/RdsEntry.cxx | 11 +++++ .../src/products/gLiveSupport/src/RdsEntry.h | 6 +++ .../src/products/gLiveSupport/src/RdsView.cxx | 48 +++++++++++-------- .../src/products/gLiveSupport/src/RdsView.h | 14 +++++- 7 files changed, 76 insertions(+), 22 deletions(-) diff --git a/campcaster/src/modules/core/src/OptionsContainer.cxx b/campcaster/src/modules/core/src/OptionsContainer.cxx index 543798596..7dc2cf464 100644 --- a/campcaster/src/modules/core/src/OptionsContainer.cxx +++ b/campcaster/src/modules/core/src/OptionsContainer.cxx @@ -344,7 +344,7 @@ void OptionsContainer :: writeToFile(void) throw () { if (configFileName) { - if (rdsContainer) { + if (rdsContainer && rdsContainer->isTouched()) { xmlpp::Element * rootNode = optionsDocument.get_root_node(); xmlpp::Node::NodeList nodes = rootNode->get_children( RdsContainer::getConfigElementName()); diff --git a/campcaster/src/products/gLiveSupport/src/OptionsWindow.cxx b/campcaster/src/products/gLiveSupport/src/OptionsWindow.cxx index e234b5fff..ba5856efb 100644 --- a/campcaster/src/products/gLiveSupport/src/OptionsWindow.cxx +++ b/campcaster/src/products/gLiveSupport/src/OptionsWindow.cxx @@ -183,6 +183,7 @@ OptionsWindow :: onCancelButtonClicked(void) throw () { resetEntries(); resetKeyBindings(); + resetRds(); onCloseButtonClicked(false); } @@ -907,6 +908,16 @@ OptionsWindow :: resetKeyBindings(void) throw () } +/*------------------------------------------------------------------------------ + * Reset the RDS settings to their saved state. + *----------------------------------------------------------------------------*/ +void +OptionsWindow :: resetRds(void) throw () +{ + rdsView->reset(); +} + + /*------------------------------------------------------------------------------ * Event handler for clicking on a row in the key bindings table. *----------------------------------------------------------------------------*/ diff --git a/campcaster/src/products/gLiveSupport/src/OptionsWindow.h b/campcaster/src/products/gLiveSupport/src/OptionsWindow.h index cdbf97b43..d46ea1bc7 100644 --- a/campcaster/src/products/gLiveSupport/src/OptionsWindow.h +++ b/campcaster/src/products/gLiveSupport/src/OptionsWindow.h @@ -165,6 +165,12 @@ class OptionsWindow : public GuiWindow void resetKeyBindings(void) throw (); + /** + * Reset the RDS settings to their saved state. + */ + void + resetRds(void) throw (); + /** * Fill the key bindings model from the KeyboardShortcutList. */ diff --git a/campcaster/src/products/gLiveSupport/src/RdsEntry.cxx b/campcaster/src/products/gLiveSupport/src/RdsEntry.cxx index dbfe551a5..07111e37d 100644 --- a/campcaster/src/products/gLiveSupport/src/RdsEntry.cxx +++ b/campcaster/src/products/gLiveSupport/src/RdsEntry.cxx @@ -125,3 +125,14 @@ RdsEntry :: saveChanges(Ptr::Ref gLiveSupport) throw () } } + +/*------------------------------------------------------------------------------ + * Clear the entries of the widget. + *----------------------------------------------------------------------------*/ +void +RdsEntry :: reset(void) throw () +{ + Ptr::Ref empty(new const Glib::ustring("")); + setOptions(false, empty); +} + diff --git a/campcaster/src/products/gLiveSupport/src/RdsEntry.h b/campcaster/src/products/gLiveSupport/src/RdsEntry.h index 4c792fd6a..3d3543935 100644 --- a/campcaster/src/products/gLiveSupport/src/RdsEntry.h +++ b/campcaster/src/products/gLiveSupport/src/RdsEntry.h @@ -156,6 +156,12 @@ class RdsEntry : public Gtk::HBox, */ bool saveChanges(Ptr::Ref gLiveSupport) throw (); + + /** + * Clear the entries of the widget. + */ + void + reset(void) throw (); }; diff --git a/campcaster/src/products/gLiveSupport/src/RdsView.cxx b/campcaster/src/products/gLiveSupport/src/RdsView.cxx index 472cd7fcc..1ef712263 100644 --- a/campcaster/src/products/gLiveSupport/src/RdsView.cxx +++ b/campcaster/src/products/gLiveSupport/src/RdsView.cxx @@ -72,6 +72,34 @@ RdsView :: RdsView (Ptr::Ref gLiveSupport, pack_start(*piEntry, Gtk::PACK_SHRINK, 0); pack_start(*rtEntry, Gtk::PACK_SHRINK, 10); + reset(); +} + + +/*------------------------------------------------------------------------------ + * Save the changes made by the user. + *----------------------------------------------------------------------------*/ +bool +RdsView :: saveChanges(void) throw () +{ + bool touched = false; + + RdsEntryListType::const_iterator it; + for (it = rdsEntryList.begin(); it != rdsEntryList.end(); ++it) { + Ptr::Ref rdsEntry = *it; + touched |= rdsEntry->saveChanges(gLiveSupport); + } + + return touched; +} + + +/*------------------------------------------------------------------------------ + * Reset the widget to its saved state. + *----------------------------------------------------------------------------*/ +void +RdsView :: reset(void) throw () +{ RdsEntryListType::const_iterator it; for (it = rdsEntryList.begin(); it != rdsEntryList.end(); ++it) { fillEntry(*it); @@ -95,26 +123,8 @@ RdsView :: fillEntry(Ptr::Ref entry) throw () value = options->getRdsValue(type); entry->setOptions(enabled, value); } catch (std::invalid_argument &e) { - // there is no such RDS option; it's OK + entry->reset(); } } } - -/*------------------------------------------------------------------------------ - * Save the changes made by the user. - *----------------------------------------------------------------------------*/ -bool -RdsView :: saveChanges(void) throw () -{ - bool touched = false; - - RdsEntryListType::const_iterator it; - for (it = rdsEntryList.begin(); it != rdsEntryList.end(); ++it) { - Ptr::Ref rdsEntry = *it; - touched |= rdsEntry->saveChanges(gLiveSupport); - } - - return touched; -} - diff --git a/campcaster/src/products/gLiveSupport/src/RdsView.h b/campcaster/src/products/gLiveSupport/src/RdsView.h index 518523383..c84dcac30 100644 --- a/campcaster/src/products/gLiveSupport/src/RdsView.h +++ b/campcaster/src/products/gLiveSupport/src/RdsView.h @@ -66,8 +66,7 @@ using namespace LiveSupport::Widgets; /** * The RDS view, a subclass of Gtk::VBox. - * This will be contained in another window, most likely - * as the contents of a notebook tab. + * This will be contained in another window, currently in the OptionsWindow. * * The layout of the view is roughly the following: *

@@ -83,6 +82,11 @@ using namespace LiveSupport::Widgets;
  *  
* where each item has a checkbox [x] with which one can enable or disable it. * + * On construction, the entries are filled in using the OptionsContainer + * object found in the GLiveSupport object. The OptionsContainer can be + * updated to the new contents of the entries using saveChanges(), and the + * entries can be re-initialized from the OptionsContainer using reset(). + * * @author $Author$ * @version $Revision$ */ @@ -144,6 +148,12 @@ class RdsView : public Gtk::VBox, */ bool saveChanges(void) throw (); + + /** + * Reset the widget to its saved state. + */ + void + reset(void) throw (); }; /* ================================================= external data structures */