From 1bfa7f3207419296364a4f8e7ad226b4fcc7ce46 Mon Sep 17 00:00:00 2001 From: fgerlits Date: Wed, 23 May 2007 11:40:04 +0000 Subject: [PATCH] fixed #2234; also: made the contents of the window stored at logout and restored at startup --- .../gLiveSupport/src/GLiveSupport.cxx | 2 +- .../gLiveSupport/src/LiveModeWindow.cxx | 105 +++++++++++++++++- .../gLiveSupport/src/LiveModeWindow.h | 59 +++++++++- .../gLiveSupport/src/MasterPanelWindow.cxx | 2 + .../src/products/gLiveSupport/var/es.txt | 1 + .../src/products/gLiveSupport/var/hu.txt | 1 + .../src/products/gLiveSupport/var/nl.txt | 1 + .../src/products/gLiveSupport/var/root.txt | 1 + .../src/products/gLiveSupport/var/sr_CS.txt | 1 + .../gLiveSupport/var/sr_CS_CYRILLIC.txt | 1 + 10 files changed, 171 insertions(+), 3 deletions(-) diff --git a/campcaster/src/products/gLiveSupport/src/GLiveSupport.cxx b/campcaster/src/products/gLiveSupport/src/GLiveSupport.cxx index 439780cc9..6923ae692 100644 --- a/campcaster/src/products/gLiveSupport/src/GLiveSupport.cxx +++ b/campcaster/src/products/gLiveSupport/src/GLiveSupport.cxx @@ -705,7 +705,7 @@ GLiveSupport :: loadWindowContents(ContentsStorable * window) << std::endl; return; } catch (std::invalid_argument &e) { - // no scratchpad stored for this user yet; no problem + // no preferences stored for this user yet; no problem return; } diff --git a/campcaster/src/products/gLiveSupport/src/LiveModeWindow.cxx b/campcaster/src/products/gLiveSupport/src/LiveModeWindow.cxx index 06de98497..fab1a25ea 100644 --- a/campcaster/src/products/gLiveSupport/src/LiveModeWindow.cxx +++ b/campcaster/src/products/gLiveSupport/src/LiveModeWindow.cxx @@ -61,6 +61,11 @@ namespace { */ const Glib::ustring windowName = "liveModeWindow"; +/*------------------------------------------------------------------------------ + * The name of the user preference for storing contents of the window. + *----------------------------------------------------------------------------*/ +const Glib::ustring userPreferencesKeyName = "liveModeContents"; + } /* =============================================== local function prototypes */ @@ -150,6 +155,16 @@ LiveModeWindow :: LiveModeWindow (Ptr::Ref gLiveSupport, Gtk::HBox * cueAudioButtonsBox = Gtk::manage(new Gtk::HBox); cueAudioButtons = Gtk::manage(new CuePlayer( gLiveSupport, treeView, modelColumns )); + + Gtk::HBox * autoPlayNextBox = Gtk::manage(new Gtk::HBox); + try { + autoPlayNext = Gtk::manage(new Gtk::CheckButton( + *getResourceUstring("autoPlayNextLabel") )); + } catch (std::invalid_argument &e) { + std::cerr << e.what() << std::endl; + std::exit(1); + } + autoPlayNextBox->pack_start(*autoPlayNext, Gtk::PACK_SHRINK, 10); topButtonBox->pack_start(*outputPlayButton, Gtk::PACK_EXPAND_PADDING, 10); topButtonBox->pack_start(*cueAudioBox, Gtk::PACK_EXPAND_PADDING, 10); @@ -165,6 +180,7 @@ LiveModeWindow :: LiveModeWindow (Ptr::Ref gLiveSupport, bottomButtonBox->pack_start(*removeButton); vBox.pack_start(*topButtonBox, Gtk::PACK_SHRINK, 5); + vBox.pack_start(*autoPlayNextBox, Gtk::PACK_SHRINK, 5); vBox.pack_start(scrolledWindow, Gtk::PACK_EXPAND_WIDGET, 5); vBox.pack_start(*bottomButtonBox, Gtk::PACK_SHRINK, 5); add(vBox); @@ -181,6 +197,8 @@ LiveModeWindow :: LiveModeWindow (Ptr::Ref gLiveSupport, audioClipContextMenu = constructAudioClipContextMenu(); playlistContextMenu = constructPlaylistContextMenu(); + userPreferencesKey.reset(new const Glib::ustring(userPreferencesKeyName)); + // show set_name(windowName); set_default_size(400, 500); @@ -251,6 +269,26 @@ LiveModeWindow :: addItem(Gtk::TreeModel::iterator iter, } +/*------------------------------------------------------------------------------ + * Add an item to the Live Mode window, by ID. + *----------------------------------------------------------------------------*/ +void +LiveModeWindow :: addItem(Ptr::Ref id) + throw () +{ + Ptr::Ref playable; + try { + playable = gLiveSupport->acquirePlayable(id); + } catch (XmlRpcException &e) { + std::cerr << "could not acquire playable in LiveModeWindow: " + << e.what() << std::endl; + return; + } + + addItem(playable); +} + + /*------------------------------------------------------------------------------ * "Pop" the first item from the top of the Live Mode Window. *----------------------------------------------------------------------------*/ @@ -258,8 +296,11 @@ Ptr::Ref LiveModeWindow :: popTop(void) throw () { Ptr::Ref playable; + if (!autoPlayNext->get_active()) { + return playable; // return a 0 pointer if auto is set to off + } + Gtk::TreeModel::iterator iter = treeModel->children().begin(); - if (iter) { playable = (*iter)[modelColumns.playableColumn]; treeModel->erase(iter); @@ -706,6 +747,68 @@ LiveModeWindow :: updateStrings(void) throw () } +/*------------------------------------------------------------------------------ + * Return the contents of the Scratchpad. + *----------------------------------------------------------------------------*/ +Ptr::Ref +LiveModeWindow :: getContents(void) throw () +{ + std::ostringstream contentsStream; + + contentsStream << int(autoPlayNext->get_active()) << " "; + + Gtk::TreeModel::const_iterator it; + for (it = treeModel->children().begin(); + it != treeModel->children().end(); ++it) { + Gtk::TreeRow row = *it; + Ptr::Ref playable = row[modelColumns.playableColumn]; + contentsStream << playable->getId()->getId() << " "; + } + + Ptr::Ref contents(new Glib::ustring( + contentsStream.str() )); + return contents; +} + + +/*------------------------------------------------------------------------------ + * Restore the contents of the Scratchpad. + *----------------------------------------------------------------------------*/ +void +LiveModeWindow :: setContents(Ptr::Ref contents) + throw () +{ + std::istringstream contentsStream(*contents); + if (contentsStream.eof()) { + return; + } + + int autoPlayNextValue; + contentsStream >> autoPlayNextValue; + autoPlayNext->set_active(autoPlayNextValue); + + std::vector contentsVector; + while (!contentsStream.eof()) { + UniqueId::IdType nextItem; + contentsStream >> nextItem; + if (contentsStream.fail()) { + contentsStream.clear(); + contentsStream.ignore(); + } else { + contentsVector.push_back(nextItem); + } + } + + treeModel->clear(); + std::vector::reverse_iterator it; + + for (it = contentsVector.rbegin(); it != contentsVector.rend(); ++it) { + Ptr::Ref id(new const UniqueId(*it)); + addItem(id); + } +} + + /*------------------------------------------------------------------------------ * Event handler called when the the window gets hidden. *----------------------------------------------------------------------------*/ diff --git a/campcaster/src/products/gLiveSupport/src/LiveModeWindow.h b/campcaster/src/products/gLiveSupport/src/LiveModeWindow.h index 0c5b7ee59..470cdfc62 100644 --- a/campcaster/src/products/gLiveSupport/src/LiveModeWindow.h +++ b/campcaster/src/products/gLiveSupport/src/LiveModeWindow.h @@ -52,6 +52,7 @@ #include "LiveSupport/Widgets/ZebraTreeView.h" #include "LiveSupport/Widgets/PlayableTreeModelColumnRecord.h" #include "GuiWindow.h" +#include "ContentsStorable.h" #include "CuePlayer.h" #include "GLiveSupport.h" #include "ExportPlaylistWindow.h" @@ -78,7 +79,8 @@ using namespace LiveSupport::Widgets; * @author $Author$ * @version $Revision$ */ -class LiveModeWindow : public GuiWindow +class LiveModeWindow : public GuiWindow, + public ContentsStorable { private: /** @@ -91,6 +93,11 @@ class LiveModeWindow : public GuiWindow */ bool isDeleting; + /** + * The user preferences key. + */ + Ptr::Ref userPreferencesKey; + /** * The Export Playlist pop-up window. */ @@ -121,6 +128,12 @@ class LiveModeWindow : public GuiWindow */ Button * removeButton; + /** + * If checked, the top item in the window will start playing + * automatically after the current one finishes. + */ + Gtk::CheckButton * autoPlayNext; + /** * Construct the right-click context menu for local audio clips. * @@ -363,6 +376,15 @@ class LiveModeWindow : public GuiWindow addItem(Gtk::TreeModel::iterator iter, Ptr::Ref playable) throw (); + /** + * Add an item to the top of the Live Mode Window, by ID. + * + * @param id the id of the item to add. + * @see setContents(). + */ + void + addItem(Ptr::Ref id) throw (); + /** * "Pop" the first item from the top of the Live Mode Window. * @@ -409,6 +431,41 @@ class LiveModeWindow : public GuiWindow */ void updateStrings(void) throw (); + + /** + * Return the contents of the Live Mode window. + * This means the list of audio files, plus the state of the + * autoPlayNext checkbox. + * + * @return 0 or 1, followed by a space-separated list of the + * unique IDs, in base 10. + */ + Ptr::Ref + getContents(void) throw (); + + /** + * Restore the contents of the Scratchpad. + * The current contents are discarded, and replaced with the items + * listed in the 'contents' parameter. + * + * @param contents 0 or 1, followed by a space-separated list of the + * unique IDs, in base 10. + */ + void + setContents(Ptr::Ref contents) throw (); + + /** + * Return the user preferences key. + * The contents of the window will be stored in the user preferences + * under this key. + * + * @return the user preference key. + */ + Ptr::Ref + getUserPreferencesKey(void) throw () + { + return userPreferencesKey; + } }; /* ================================================= external data structures */ diff --git a/campcaster/src/products/gLiveSupport/src/MasterPanelWindow.cxx b/campcaster/src/products/gLiveSupport/src/MasterPanelWindow.cxx index 3d9def658..83521cb63 100644 --- a/campcaster/src/products/gLiveSupport/src/MasterPanelWindow.cxx +++ b/campcaster/src/products/gLiveSupport/src/MasterPanelWindow.cxx @@ -467,6 +467,7 @@ MasterPanelWindow :: updateLiveModeWindow(Ptr::Ref playable) liveModeWindow.reset(new LiveModeWindow(gLiveSupport, bundle, liveModeButton)); + gLiveSupport->loadWindowContents(liveModeWindow); } liveModeWindow->present(); @@ -678,6 +679,7 @@ MasterPanelWindow :: showAnonymousUI(void) throw () optionsButton->hide(); if (liveModeWindow.get()) { + gLiveSupport->storeWindowContents(liveModeWindow); if (liveModeWindow->is_visible()) { liveModeWindow->hide(); } diff --git a/campcaster/src/products/gLiveSupport/var/es.txt b/campcaster/src/products/gLiveSupport/var/es.txt index 528fdc079..c6f0fd71e 100644 --- a/campcaster/src/products/gLiveSupport/var/es.txt +++ b/campcaster/src/products/gLiveSupport/var/es.txt @@ -257,6 +257,7 @@ es:table uploadToHubMenuItem:string { "Upload to Network Hub" } cuePlayerLabel:string { "Previsualizar" } + autoPlayNextLabel:string { "#Play the next item automatically#" } clearListButtonLabel:string { "Clear list" } removeButtonLabel:string { "Remove item(s)" } diff --git a/campcaster/src/products/gLiveSupport/var/hu.txt b/campcaster/src/products/gLiveSupport/var/hu.txt index a67dc8ea4..4c4f6b3ac 100644 --- a/campcaster/src/products/gLiveSupport/var/hu.txt +++ b/campcaster/src/products/gLiveSupport/var/hu.txt @@ -254,6 +254,7 @@ hu:table uploadToHubMenuItem:string { "Upload to Network Hub" } cuePlayerLabel:string { "Belehallgatni" } + autoPlayNextLabel:string { "#Play the next item automatically#" } clearListButtonLabel:string { "Clear list" } removeButtonLabel:string { "Remove item(s)" } diff --git a/campcaster/src/products/gLiveSupport/var/nl.txt b/campcaster/src/products/gLiveSupport/var/nl.txt index fc0233277..e761fe028 100644 --- a/campcaster/src/products/gLiveSupport/var/nl.txt +++ b/campcaster/src/products/gLiveSupport/var/nl.txt @@ -256,6 +256,7 @@ nl:table uploadToHubMenuItem:string { "Upload to Network Hub" } cuePlayerLabel:string { "Cue" } + autoPlayNextLabel:string { "#Play the next item automatically#" } clearListButtonLabel:string { "Clear list" } removeButtonLabel:string { "Remove item(s)" } diff --git a/campcaster/src/products/gLiveSupport/var/root.txt b/campcaster/src/products/gLiveSupport/var/root.txt index b25934793..ac9df8335 100644 --- a/campcaster/src/products/gLiveSupport/var/root.txt +++ b/campcaster/src/products/gLiveSupport/var/root.txt @@ -256,6 +256,7 @@ root:table uploadToHubMenuItem:string { "Upload to Network Hub" } cuePlayerLabel:string { "Preview" } + autoPlayNextLabel:string { "Play the next item automatically" } clearListButtonLabel:string { "Clear list" } removeButtonLabel:string { "Remove item(s)" } diff --git a/campcaster/src/products/gLiveSupport/var/sr_CS.txt b/campcaster/src/products/gLiveSupport/var/sr_CS.txt index 5fc9089e1..59a9c131d 100644 --- a/campcaster/src/products/gLiveSupport/var/sr_CS.txt +++ b/campcaster/src/products/gLiveSupport/var/sr_CS.txt @@ -251,6 +251,7 @@ sr_CS:table uploadToHubMenuItem:string { "Uputi na centralni server" } cuePlayerLabel:string { "Proba" } + autoPlayNextLabel:string { "#Play the next item automatically#" } clearListButtonLabel:string { "Očisti listu" } removeButtonLabel:string { "Ukloni" } diff --git a/campcaster/src/products/gLiveSupport/var/sr_CS_CYRILLIC.txt b/campcaster/src/products/gLiveSupport/var/sr_CS_CYRILLIC.txt index d65ee48bb..c080c68f1 100644 --- a/campcaster/src/products/gLiveSupport/var/sr_CS_CYRILLIC.txt +++ b/campcaster/src/products/gLiveSupport/var/sr_CS_CYRILLIC.txt @@ -251,6 +251,7 @@ sr_CS_CYRILLIC:table uploadToHubMenuItem:string { "Упути на централни сервер" } cuePlayerLabel:string { "Проба" } + autoPlayNextLabel:string { "#Play the next item automatically#" } clearListButtonLabel:string { "Очисти листу" } removeButtonLabel:string { "Уклони" }