Changeset 1884
- Timestamp:
- Fri Jan 20 22:22:32 2006
- Files:
-
- trunk/livesupport/src/products/gLiveSupport/src/OptionsWindow.cxx (modified) (diff)
- trunk/livesupport/src/products/gLiveSupport/src/OptionsContainer.cxx (modified) (diff)
- trunk/livesupport/src/products/gLiveSupport/src/GLiveSupport.cxx (modified) (diff)
- trunk/livesupport/src/products/gLiveSupport/src/OptionsWindow.h (modified) (diff)
- trunk/livesupport/src/products/gLiveSupport/src/OptionsContainer.h (modified) (diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
trunk/livesupport/src/products/gLiveSupport/src/OptionsWindow.cxx
r1881 r1884 89 89 // build up the notepad for the various sections 90 90 mainNotebook = Gtk::manage(new ScrolledNotebook); 91 Gtk::Box * aboutSectionBox = constructAboutSection();92 91 Gtk::Box * soundSectionBox = constructSoundSection(); 92 Gtk::Box * aboutSectionBox = constructAboutSection(); 93 93 94 94 try { 95 mainNotebook->appendPage(*aboutSectionBox,96 *getResourceUstring("aboutSectionLabel"));97 95 mainNotebook->appendPage(*soundSectionBox, 98 96 *getResourceUstring("soundSectionLabel")); 97 mainNotebook->appendPage(*aboutSectionBox, 98 *getResourceUstring("aboutSectionLabel")); 99 99 100 100 } catch (std::invalid_argument &e) { … … 157 157 OptionsWindow :: onCancelButtonClicked(void) throw () 158 158 { 159 onCloseButtonClicked(); 159 onCloseButtonClicked(false); 159 159 } 160 160 … … 167 167 OptionsWindow :: onApplyButtonClicked(void) throw () 168 168 { 169 Ptr<OptionsContainer>::Ref 170 optionsContainer = gLiveSupport->getOptionsContainer(); 171 172 // check for changes in the Sound tab 173 Ptr<const Glib::ustring>::Ref 174 oldCueDevice = optionsContainer->getOptionItem( 175 OptionsContainer::cuePlayerDeviceName ); 176 Ptr<const Glib::ustring>::Ref 177 newCueDevice(new Glib::ustring(cuePlayerEntry->get_text())); 178 179 if (*oldCueDevice != *newCueDevice) { 180 optionsContainer->setOptionItem( 181 OptionsContainer::cuePlayerDeviceName, 182 newCueDevice ); 183 } 184 185 Ptr<const Glib::ustring>::Ref 186 oldOutputDevice = optionsContainer->getOptionItem( 187 OptionsContainer::outputPlayerDeviceName ); 188 Ptr<const Glib::ustring>::Ref 189 newOutputDevice(new Glib::ustring(outputPlayerEntry->get_text())); 190 191 if (*oldOutputDevice != *newOutputDevice) { 192 optionsContainer->setOptionItem( 193 OptionsContainer::outputPlayerDeviceName, 194 newOutputDevice ); 195 } 169 196 } 170 197 … … 176 203 OptionsWindow :: onOkButtonClicked(void) throw () 177 204 { 178 onCloseButtonClicked(); 205 onApplyButtonClicked(); 206 onCloseButtonClicked(false); 179 207 } 180 208 … … 184 212 *----------------------------------------------------------------------------*/ 185 213 void 186 OptionsWindow :: onCloseButtonClicked( void)throw ()214 OptionsWindow :: onCloseButtonClicked(bool needConfirm) throw () 186 214 { 215 if (needConfirm) { 216 //TODO: add confirmation dialog 217 } 187 218 gLiveSupport->putWindowPosition(shared_from_this()); 188 219 hide(); … … 249 280 audioDeviceTable->attach(*cuePlayerLabel, 0, 1, 0, 1); 250 281 251 EntryBin *cuePlayerEntry = Gtk::manage(wf->createEntryBin());282 cuePlayerEntry = Gtk::manage(wf->createEntryBin()); 251 282 cuePlayerEntry->set_text(*optionsContainer->getOptionItem( 252 283 OptionsContainer::cuePlayerDeviceName )); 268 299 audioDeviceTable->attach(*outputPlayerLabel, 0, 1, 1, 2); 269 300 270 EntryBin *outputPlayerEntry = Gtk::manage(wf->createEntryBin());301 outputPlayerEntry = Gtk::manage(wf->createEntryBin()); 270 301 outputPlayerEntry->set_text(*optionsContainer->getOptionItem( 271 302 OptionsContainer::outputPlayerDeviceName )); 272 303 audioDeviceTable->attach(*outputPlayerEntry, 1, 2, 1, 2); 273 304 274 // TODO: remove this275 Gtk::Label * notFinishedWarning = Gtk::manage(new Gtk::Label(276 "Note: device settings can not be edited (yet)." ));277 278 305 // make a new box and pack the components into it 279 306 Gtk::VBox * section = Gtk::manage(new Gtk::VBox); 280 307 section->pack_start(*audioDeviceTable, Gtk::PACK_SHRINK, 5); 281 section->pack_start(*notFinishedWarning, Gtk::PACK_SHRINK, 20);282 308 283 309 return section; -
trunk/livesupport/src/products/gLiveSupport/src/OptionsContainer.cxx
r1882 r1884 35 35 36 36 #include <iostream> 37 #include <fstream> 37 38 38 39 #include "OptionsContainer.h" … … 56 57 * Constructor. 57 58 *----------------------------------------------------------------------------*/ 58 OptionsContainer :: OptionsContainer(const xmlpp::Element & optionsElement) 59 OptionsContainer :: OptionsContainer( 60 const xmlpp::Element & optionsElement, 61 Ptr<const Glib::ustring>::Ref configFileName) 59 62 throw () 63 : configFileName(configFileName), 64 changed(false) 60 65 { 61 66 optionsDocument.create_root_node_by_import(&optionsElement, true); … … 77 82 switch (optionItem) { 78 83 case outputPlayerDeviceName : 79 targetNode = getNode(" /outputPlayer/audioPlayer/gstreamerPlayer/"84 targetNode = getNode("outputPlayer/audioPlayer/gstreamerPlayer/" 79 84 "@audioDevice"); 80 85 isAttribute = true; … … 83 88 84 89 case cuePlayerDeviceName : 85 targetNode = getNode(" /cuePlayer/audioPlayer/gstreamerPlayer/"90 targetNode = getNode("cuePlayer/audioPlayer/gstreamerPlayer/" 85 90 "@audioDevice"); 86 91 isAttribute = true; … … 93 98 if (attr != 0) { 94 99 attr->set_value(*value); 100 changed = true; 95 101 return; 96 102 } … … 99 105 if (text != 0) { 100 106 text->set_content(*value); 107 changed = true; 101 108 return; 102 109 } 178 185 } 179 186 187 188 /*------------------------------------------------------------------------------ 189 * Save the options to a file. 190 *----------------------------------------------------------------------------*/ 191 void 192 OptionsContainer :: writeToFile(void) throw () 193 { 194 if (configFileName) { 195 std::ofstream file(configFileName->c_str()); 196 optionsDocument.write_to_stream_formatted(file, "utf-8"); 197 file.close(); 198 changed = false; 199 } 200 } 201 -
trunk/livesupport/src/products/gLiveSupport/src/GLiveSupport.cxx
r1881 r1884 34 34 #endif 35 35 36 #ifdef HAVE_PWD_H 37 #include <pwd.h> 38 #else 39 #error need pwd.h 40 #endif 41 42 #ifdef HAVE_SYS_STAT_H 43 #include <sys/stat.h> 44 #else 45 #error need sys/stat.h 46 #endif 47 36 48 #include <stdexcept> 37 49 #include <gtkmm/main.h> … … 72 84 73 85 /*------------------------------------------------------------------------------ 86 * The name of the configuration file for this class 87 *----------------------------------------------------------------------------*/ 88 const std::string configFileDirStr = "/.livesupport/"; 89 90 /*------------------------------------------------------------------------------ 91 * The name of the configuration file for this class 92 *----------------------------------------------------------------------------*/ 93 const std::string configFileNameStr = "gLiveSupport.xml"; 94 95 /*------------------------------------------------------------------------------ 74 96 * The name of the config element for the list of supported languages 75 97 *----------------------------------------------------------------------------*/ … … 299 321 } 300 322 301 // save the config fileso we can modify it later323 // save the configuration so we can modify it later 301 323 // TODO: move configuration code to the OptionsContainer class? 302 optionsContainer.reset(new OptionsContainer(element)); 324 Ptr<Glib::ustring>::Ref configFileName(new Glib::ustring); 325 struct passwd * pwd = getpwuid(getuid()); 326 if (pwd) { 327 configFileName->append(pwd->pw_dir); 328 } else { 329 throw std::logic_error("this never happens: getpwuid() returned 0"); 330 } 331 configFileName->append(configFileDirStr); 332 mkdir(configFileName->c_str(), 0700); // create dir if does not exist 333 configFileName->append(configFileNameStr); 334 optionsContainer.reset(new OptionsContainer(element, configFileName)); 303 335 } 304 336 532 564 sessionId.reset(); 533 565 566 if (optionsContainer->isChanged()) { 567 optionsContainer->writeToFile(); 568 } 569 534 570 return true; 535 571 } -
trunk/livesupport/src/products/gLiveSupport/src/OptionsWindow.h
r1881 r1884 94 94 class OptionsWindow : public WhiteWindow, public LocalizedObject 95 95 { 96 pr otected:96 private: 96 96 /** 97 97 * The notepad holding the different sections. … … 121 121 122 122 /** 123 * The entry field for the cue player device's name. 124 */ 125 EntryBin * cuePlayerEntry; 126 127 /** 128 * The entry field for the output player device's name. 129 */ 130 EntryBin * outputPlayerEntry; 131 132 /** 123 133 * The gLiveSupport object, handling the logic of the application. 124 134 */ … … 131 141 132 142 /** 143 * Construct the "About" section. 144 * 145 * @return a pointer to the new box (already Gtk::manage()'ed) 146 */ 147 Gtk::VBox* 148 constructAboutSection(void) throw (); 149 150 /** 151 * Construct the "Sound" section. 152 * 153 * @return a pointer to the new box (already Gtk::manage()'ed) 154 */ 155 Gtk::VBox* 156 constructSoundSection(void) throw (); 157 158 159 protected: 160 /** 133 161 * Event handler for the Cancel button. 134 162 */ 151 179 * Event handler for the Close button. 152 180 * 153 * @see WhiteWindow::onCloseButtonClicked() 181 * @param needConfirm if true, we check if changes has been 182 * made to the input fields, and if yes, then 183 * a "save changes?" dialog is displayed 184 * @see WhiteWindow::onCloseButtonClicked() 154 185 */ 155 186 virtual void 156 onCloseButtonClicked(void) throw (); 157 158 /** 159 * Construct the "About" section. 160 * 161 * @return a pointer to the new box (already Gtk::manage()'ed) 162 */ 163 Gtk::VBox* 164 constructAboutSection(void) throw (); 165 166 /** 167 * Construct the "Sound" section. 168 * 169 * @return a pointer to the new box (already Gtk::manage()'ed) 170 */ 171 Gtk::VBox* 172 constructSoundSection(void) throw (); 173 187 onCloseButtonClicked(bool needConfirm = true) throw (); 174 188 189 175 190 public: 176 191 /** -
trunk/livesupport/src/products/gLiveSupport/src/OptionsContainer.h
r1881 r1884 73 73 * The XML document containing the options. 74 74 */ 75 xmlpp::Document optionsDocument; 75 xmlpp::Document optionsDocument; 76 77 /** 78 * The file name (including path) used by writeToFile(). 79 */ 80 Ptr<const Glib::ustring>::Ref configFileName; 81 82 /** 83 * Remember if we have been changed. 84 */ 85 bool changed; 76 86 77 87 /** … … 100 110 * 101 111 * @param optionsElement the XML element containing the options 112 * @param configFileName the name (with path) of the configuration 113 * file used by writeToFile() 114 * @see writeToFile() 102 115 */ 103 OptionsContainer(const xmlpp::Element & optionsElement) throw (); 116 OptionsContainer(const xmlpp::Element & optionsElement, 117 Ptr<const Glib::ustring>::Ref configFileName) 118 throw (); 104 119 105 120 /** 121 * Report if the object has been changed. 122 * 123 * It returns true if there has been any calls to setOptionItem() 124 * since its construction or the last call to writeToFile(). 125 * 126 * @return whether the options have been changed 127 */ 128 bool 129 isChanged(void) throw () 130 { 131 return changed; 132 } 133 134 /** 106 135 * The list of string options one can set. 107 136 * 134 163 getOptionItem(OptionItemString optionItem) 135 164 throw (std::invalid_argument); 165 166 /** 167 * Save the options to a file. 168 * 169 * This writes the options in XML format to the file specified in the 170 * constructor, under $HOME/.livesupport. If the directory does not 171 * exist, it is created. 172 */ 173 void 174 writeToFile(void) throw (); 136 175 }; 137 176