From 8c2c13faf2b428ac09e2af8aebd8f89636de2164 Mon Sep 17 00:00:00 2001 From: fgerlits Date: Fri, 24 Feb 2006 17:12:25 +0000 Subject: [PATCH] progress towards #1617 (displays keyboard shortcuts, can't be edited yet) --- .../src/products/gLiveSupport/etc/Makefile.in | 1 + .../gLiveSupport/etc/gLiveSupport.xml | 145 ++++++------- .../etc/gLiveSupport.xml.template | 145 ++++++------- .../etc/gLiveSupport.xml.user-template | 145 ++++++------- .../gLiveSupport/src/GLiveSupport.cxx | 72 +++---- .../products/gLiveSupport/src/GLiveSupport.h | 56 ++++- .../gLiveSupport/src/KeyboardShortcut.cxx | 42 ++-- .../gLiveSupport/src/KeyboardShortcut.h | 40 +++- .../src/KeyboardShortcutContainer.cxx | 2 +- .../src/KeyboardShortcutContainer.h | 30 ++- .../gLiveSupport/src/KeyboardShortcutList.cxx | 100 +++++++++ .../gLiveSupport/src/KeyboardShortcutList.h | 194 ++++++++++++++++++ .../gLiveSupport/src/MasterPanelWindow.cxx | 2 +- .../gLiveSupport/src/OptionsWindow.cxx | 83 +++++++- .../products/gLiveSupport/src/OptionsWindow.h | 63 ++++++ .../src/products/gLiveSupport/var/root.txt | 45 ++-- 16 files changed, 858 insertions(+), 307 deletions(-) create mode 100644 livesupport/src/products/gLiveSupport/src/KeyboardShortcutList.cxx create mode 100644 livesupport/src/products/gLiveSupport/src/KeyboardShortcutList.h diff --git a/livesupport/src/products/gLiveSupport/etc/Makefile.in b/livesupport/src/products/gLiveSupport/etc/Makefile.in index 5d369e6fd..b2d5d0747 100644 --- a/livesupport/src/products/gLiveSupport/etc/Makefile.in +++ b/livesupport/src/products/gLiveSupport/etc/Makefile.in @@ -259,6 +259,7 @@ G_LIVESUPPORT_OBJS = ${TMP_DIR}/GLiveSupport.o \ ${TMP_DIR}/CuePlayer.o \ ${TMP_DIR}/KeyboardShortcut.o \ ${TMP_DIR}/KeyboardShortcutContainer.o \ + ${TMP_DIR}/KeyboardShortcutList.o \ ${TMP_DIR}/OptionsWindow.o G_LIVESUPPORT_RES = ${TMP_DIR}/${PACKAGE_NAME}_root.res \ diff --git a/livesupport/src/products/gLiveSupport/etc/gLiveSupport.xml b/livesupport/src/products/gLiveSupport/etc/gLiveSupport.xml index aa3eaccee..a374544c8 100644 --- a/livesupport/src/products/gLiveSupport/etc/gLiveSupport.xml +++ b/livesupport/src/products/gLiveSupport/etc/gLiveSupport.xml @@ -11,7 +11,7 @@ cuePlayer, stationLogo, metadataTypeContainer, - keyboardShortcutContainer*) > + keyboardShortcutList) > @@ -98,6 +98,7 @@ + @@ -340,79 +341,81 @@ /> - - masterPanelWindow - - playAudio - X - Space - - - pauseAudio - V - - - stopAudio - C - - - nextTrack - B - - + + + masterPanelWindow + + playAudio + X + Space + + + pauseAudio + V + + + stopAudio + C + + + nextTrack + B + + - - liveModeWindow - - moveItemUp - Alt-Up - - - moveItemDown - Alt-Down - - - removeItem - Delete - - - playAudio - X - Space - - + + liveModeWindow + + moveItemUp + Alt-Up + + + moveItemDown + Alt-Down + + + removeItem + Delete + + + playAudio + X + Space + + - - scratchpadWindow - - moveItemUp - Alt-Up - - - moveItemDown - Alt-Down - - - removeItem - Delete - - + + scratchpadWindow + + moveItemUp + Alt-Up + + + moveItemDown + Alt-Down + + + removeItem + Delete + + - - simplePlaylistManagementWindow - - moveItemUp - Alt-Up - - - moveItemDown - Alt-Down - - - removeItem - Delete - - + + simplePlaylistManagementWindow + + moveItemUp + Alt-Up + + + moveItemDown + Alt-Down + + + removeItem + Delete + + + diff --git a/livesupport/src/products/gLiveSupport/etc/gLiveSupport.xml.template b/livesupport/src/products/gLiveSupport/etc/gLiveSupport.xml.template index c8fb78b54..3603f68db 100644 --- a/livesupport/src/products/gLiveSupport/etc/gLiveSupport.xml.template +++ b/livesupport/src/products/gLiveSupport/etc/gLiveSupport.xml.template @@ -11,7 +11,7 @@ cuePlayer, stationLogo, metadataTypeContainer, - keyboardShortcutContainer*) > + keyboardShortcutList) > @@ -98,6 +98,7 @@ + @@ -340,79 +341,81 @@ /> - - masterPanelWindow - - playAudio - X - Space - - - pauseAudio - V - - - stopAudio - C - - - nextTrack - B - - + + + masterPanelWindow + + playAudio + X + Space + + + pauseAudio + V + + + stopAudio + C + + + nextTrack + B + + - - liveModeWindow - - moveItemUp - Alt-Up - - - moveItemDown - Alt-Down - - - removeItem - Delete - - - playAudio - X - Space - - + + liveModeWindow + + moveItemUp + Alt-Up + + + moveItemDown + Alt-Down + + + removeItem + Delete + + + playAudio + X + Space + + - - scratchpadWindow - - moveItemUp - Alt-Up - - - moveItemDown - Alt-Down - - - removeItem - Delete - - + + scratchpadWindow + + moveItemUp + Alt-Up + + + moveItemDown + Alt-Down + + + removeItem + Delete + + - - simplePlaylistManagementWindow - - moveItemUp - Alt-Up - - - moveItemDown - Alt-Down - - - removeItem - Delete - - + + simplePlaylistManagementWindow + + moveItemUp + Alt-Up + + + moveItemDown + Alt-Down + + + removeItem + Delete + + + diff --git a/livesupport/src/products/gLiveSupport/etc/gLiveSupport.xml.user-template b/livesupport/src/products/gLiveSupport/etc/gLiveSupport.xml.user-template index 0b791f01e..b9281df49 100644 --- a/livesupport/src/products/gLiveSupport/etc/gLiveSupport.xml.user-template +++ b/livesupport/src/products/gLiveSupport/etc/gLiveSupport.xml.user-template @@ -11,7 +11,7 @@ cuePlayer, stationLogo, metadataTypeContainer, - keyboardShortcutContainer*) > + keyboardShortcutList) > @@ -98,6 +98,7 @@ + @@ -340,79 +341,81 @@ /> - - masterPanelWindow - - playAudio - X - Space - - - pauseAudio - V - - - stopAudio - C - - - nextTrack - B - - + + + masterPanelWindow + + playAudio + X + Space + + + pauseAudio + V + + + stopAudio + C + + + nextTrack + B + + - - liveModeWindow - - moveItemUp - Alt-Up - - - moveItemDown - Alt-Down - - - removeItem - Delete - - - playAudio - X - Space - - + + liveModeWindow + + moveItemUp + Alt-Up + + + moveItemDown + Alt-Down + + + removeItem + Delete + + + playAudio + X + Space + + - - scratchpadWindow - - moveItemUp - Alt-Up - - - moveItemDown - Alt-Down - - - removeItem - Delete - - + + scratchpadWindow + + moveItemUp + Alt-Up + + + moveItemDown + Alt-Down + + + removeItem + Delete + + - - simplePlaylistManagementWindow - - moveItemUp - Alt-Up - - - moveItemDown - Alt-Down - - - removeItem - Delete - - + + simplePlaylistManagementWindow + + moveItemUp + Alt-Up + + + moveItemDown + Alt-Down + + + removeItem + Delete + + + diff --git a/livesupport/src/products/gLiveSupport/src/GLiveSupport.cxx b/livesupport/src/products/gLiveSupport/src/GLiveSupport.cxx index 7eccd3b50..89b89224d 100644 --- a/livesupport/src/products/gLiveSupport/src/GLiveSupport.cxx +++ b/livesupport/src/products/gLiveSupport/src/GLiveSupport.cxx @@ -196,7 +196,7 @@ GLiveSupport :: configure(const xmlpp::Element & element) if (nodes.size() < 1) { throw std::invalid_argument("no supportedLanguages element"); } - configSupportedLanguages(*((const xmlpp::Element*) *(nodes.begin())) ); + configSupportedLanguages(*((const xmlpp::Element*) nodes.front())); // configure the resource bundle nodes = element.get_children(LocalizedObject::getConfigElementName()); @@ -204,7 +204,7 @@ GLiveSupport :: configure(const xmlpp::Element & element) throw std::invalid_argument("no resourceBundle element"); } LocalizedConfigurable::configure( - *((const xmlpp::Element*) *(nodes.begin()))); + *((const xmlpp::Element*) nodes.front())); // configure the AuthenticationClientFactory nodes = element.get_children( @@ -214,7 +214,7 @@ GLiveSupport :: configure(const xmlpp::Element & element) } Ptr::Ref acf = AuthenticationClientFactory::getInstance(); - acf->configure( *((const xmlpp::Element*) *(nodes.begin())) ); + acf->configure( *((const xmlpp::Element*) nodes.front()) ); authentication = acf->getAuthenticationClient(); @@ -224,7 +224,7 @@ GLiveSupport :: configure(const xmlpp::Element & element) throw std::invalid_argument("no storageClientFactory element"); } Ptr::Ref stcf = StorageClientFactory::getInstance(); - stcf->configure( *((const xmlpp::Element*) *(nodes.begin())) ); + stcf->configure( *((const xmlpp::Element*) nodes.front()) ); storage = stcf->getStorageClient(); @@ -234,7 +234,7 @@ GLiveSupport :: configure(const xmlpp::Element & element) throw std::invalid_argument("no widgetFactory element"); } widgetFactory = WidgetFactory::getInstance(); - widgetFactory->configure( *((const xmlpp::Element*) *(nodes.begin())) ); + widgetFactory->configure( *((const xmlpp::Element*) nodes.front()) ); // configure the SchedulerClientFactory nodes = element.get_children( @@ -244,7 +244,7 @@ GLiveSupport :: configure(const xmlpp::Element & element) } Ptr::Ref schcf = SchedulerClientFactory::getInstance(); - schcf->configure( *((const xmlpp::Element*) *(nodes.begin())) ); + schcf->configure( *((const xmlpp::Element*) nodes.front()) ); scheduler = schcf->getSchedulerClient(); @@ -261,7 +261,7 @@ GLiveSupport :: configure(const xmlpp::Element & element) throw std::invalid_argument("no audioPlayer element"); } apf = AudioPlayerFactory::getInstance(); - apf->configure( *((const xmlpp::Element*) *(nodes.begin())) ); + apf->configure( *((const xmlpp::Element*) nodes.front()) ); outputPlayer = apf->getAudioPlayer(); outputPlayer->initialize(); @@ -278,7 +278,7 @@ GLiveSupport :: configure(const xmlpp::Element & element) throw std::invalid_argument("no audioPlayer element"); } apf = AudioPlayerFactory::getInstance(); - apf->configure( *((const xmlpp::Element*) *(nodes.begin())) ); + apf->configure( *((const xmlpp::Element*) nodes.front()) ); cuePlayer = apf->getAudioPlayer(); cuePlayer->initialize(); @@ -304,26 +304,20 @@ GLiveSupport :: configure(const xmlpp::Element & element) if (nodes.size() < 1) { throw std::invalid_argument("no metadataTypeContainer element"); } - Ptr::Ref metadataBundle; - try { - metadataBundle = getBundle("metadataTypes"); - } catch (std::invalid_argument &e) { - throw std::invalid_argument(e.what()); - } + Ptr::Ref metadataBundle = getBundle("metadataTypes"); metadataTypeContainer.reset(new MetadataTypeContainer(metadataBundle)); metadataTypeContainer->configure( - *((const xmlpp::Element*) *(nodes.begin())) ); + *((const xmlpp::Element*) nodes.front()) ); - // configure the KeyboardShortcutContainer classes + // configure the KeyboardShortcutList nodes = element.get_children( - KeyboardShortcutContainer::getConfigElementName()); - xmlpp::Node::NodeList::const_iterator it = nodes.begin(); - while (it != nodes.end()) { - Ptr::Ref ksc(new KeyboardShortcutContainer); - ksc->configure(*((const xmlpp::Element*) *it)); - keyboardShortcutList[*ksc->getWindowName()] = ksc; - ++it; + KeyboardShortcutList::getConfigElementName()); + if (nodes.size() < 1) { + throw std::invalid_argument("no keyboardShortcutList element"); } + keyboardShortcutList.reset(new KeyboardShortcutList); + keyboardShortcutList->configure( + *((const xmlpp::Element*) nodes.front()) ); // save the configuration so we can modify it later // TODO: move configuration code to the OptionsContainer class? @@ -1333,22 +1327,28 @@ GLiveSupport :: getStationLogoImage(void) throw() /*------------------------------------------------------------------------------ - * Find the action triggered by the given key in the given window. + * Get the localized name of the keyboard shortcut action. *----------------------------------------------------------------------------*/ -KeyboardShortcut::Action +Ptr::Ref LiveSupport :: GLiveSupport :: -GLiveSupport :: findAction(const Glib::ustring & windowName, - unsigned int modifiers, - unsigned int key) const throw () +GLiveSupport :: getLocalizedKeyboardActionName( + Ptr::Ref actionName) + throw (std::invalid_argument) { - KeyboardShortcutListType::const_iterator it = keyboardShortcutList.find( - windowName); - if (it != keyboardShortcutList.end()) { - Ptr::Ref ksc = it->second; - return ksc->findAction(modifiers, key); - } else { - return KeyboardShortcut::noAction; - } + return getResourceUstring("keyboardShortcuts", actionName->c_str()); +} + + +/*------------------------------------------------------------------------------ + * Get the localized name of the window. + *----------------------------------------------------------------------------*/ +Ptr::Ref +LiveSupport :: GLiveSupport :: +GLiveSupport :: getLocalizedWindowName( + Ptr::Ref windowName) + throw (std::invalid_argument) +{ + return getResourceUstring(windowName->c_str(), "windowTitle"); } diff --git a/livesupport/src/products/gLiveSupport/src/GLiveSupport.h b/livesupport/src/products/gLiveSupport/src/GLiveSupport.h index 98011e5b8..8150128c6 100644 --- a/livesupport/src/products/gLiveSupport/src/GLiveSupport.h +++ b/livesupport/src/products/gLiveSupport/src/GLiveSupport.h @@ -55,7 +55,7 @@ #include "LiveSupport/SchedulerClient/SchedulerClientInterface.h" #include "LiveSupport/PlaylistExecutor/AudioPlayerInterface.h" #include "LiveSupport/Widgets/WidgetFactory.h" -#include "KeyboardShortcutContainer.h" +#include "KeyboardShortcutList.h" namespace LiveSupport { @@ -287,17 +287,10 @@ class GLiveSupport : public LocalizedConfigurable, void uncachePlaylist(Ptr::Ref id) throw (); - /** - * The type for storing the keyboard shortcuts. - */ - typedef std::map::Ref> - KeyboardShortcutListType; - /** * The list of keyboard shortcuts for the various windows. */ - KeyboardShortcutListType keyboardShortcutList; + Ptr::Ref keyboardShortcutList; /** * The type for a single window position. @@ -986,7 +979,50 @@ class GLiveSupport : public LocalizedConfigurable, KeyboardShortcut::Action findAction(const Glib::ustring & windowName, unsigned int modifiers, - unsigned int key) const throw (); + unsigned int key) const throw () + { + return keyboardShortcutList->findAction(windowName, modifiers, key); + } + + /** + * The list of all KeyboardShortcutContainer objects. + * Used in the Key bindings section of the OptionsWindow class. + * + * @return a const pointer to the list (implemented as a std::map). + */ + Ptr::Ref + getKeyboardShortcutList(void) throw () + { + return keyboardShortcutList; + } + + /** + * Get the localized name of the window. + * Used in the Key bindings section of the OptionsWindow class. + * + * @param windowName the name of the window. + * @return the localized name. + * @exception std::invalid_argument if the resource bundle is + * not found + */ + Ptr::Ref + getLocalizedWindowName(Ptr::Ref windowName) + throw (std::invalid_argument); + + /** + * Get the localized name of the keyboard shortcut action. + * Used in the Key bindings section of the OptionsWindow class. + * + * @param actionName the name of the action. + * @return the localized name. + * @exception std::invalid_argument if the resource bundle is + * not found + * @see KeyboardShortcut::getActionString() + */ + Ptr::Ref + getLocalizedKeyboardActionName( + Ptr::Ref actionName) + throw (std::invalid_argument); /** * Save the position and size of the window. diff --git a/livesupport/src/products/gLiveSupport/src/KeyboardShortcut.cxx b/livesupport/src/products/gLiveSupport/src/KeyboardShortcut.cxx index 189b478fb..668ac5042 100644 --- a/livesupport/src/products/gLiveSupport/src/KeyboardShortcut.cxx +++ b/livesupport/src/products/gLiveSupport/src/KeyboardShortcut.cxx @@ -83,11 +83,11 @@ static const unsigned int modifiersChecked = GDK_SHIFT_MASK * Add a shortcut key for this object. *----------------------------------------------------------------------------*/ void -KeyboardShortcut :: addKey(const Glib::ustring & modifiedKeyName) +KeyboardShortcut :: addKey(Ptr::Ref modifiedKeyName) throw (std::invalid_argument) { Ptr::Ref inputString(new Glib::ustring( - modifiedKeyName )); + *modifiedKeyName )); Ptr::Ref keyName = getToken(inputString); if (!keyName) { @@ -142,13 +142,13 @@ KeyboardShortcut :: configure(const xmlpp::Element & element) } const xmlpp::Element* actionElement = dynamic_cast( children.front()); - const Glib::ustring actionString = actionElement->get_child_text() - ->get_content(); + actionString.reset(new Glib::ustring(actionElement->get_child_text() + ->get_content() )); try { action = stringToAction(actionString); } catch (std::invalid_argument &e) { std::string eMsg = "Invalid action specification "; - eMsg += actionString; + eMsg += *actionString; eMsg += "."; throw std::invalid_argument(eMsg); } @@ -159,19 +159,25 @@ KeyboardShortcut :: configure(const xmlpp::Element & element) throw std::invalid_argument("missing " + keyElementName + " element"); } + bool firstRun = true; xmlpp::Node::NodeList::const_iterator it; for (it = children.begin(); it != children.end(); ++it) { const xmlpp::Element* keyElement = dynamic_cast(*it); - const Glib::ustring keyString = keyElement->get_child_text() - ->get_content(); + Ptr::Ref keyString(new Glib::ustring( + keyElement->get_child_text() + ->get_content() )); + if (firstRun) { + firstKeyString = keyString; + firstRun = false; + } try { addKey(keyString); } catch (std::invalid_argument &e) { std::string eMsg = "Invalid key specification "; - eMsg += keyString; + eMsg += *keyString; eMsg += " for action "; - eMsg += actionString; + eMsg += *actionString; eMsg += "."; throw std::invalid_argument(eMsg); } @@ -208,24 +214,24 @@ KeyboardShortcut :: isTriggeredBy(unsigned int modifiers, * Convert an action name string to an enumeration value. *----------------------------------------------------------------------------*/ KeyboardShortcut::Action -KeyboardShortcut :: stringToAction(const Glib::ustring & actionName) +KeyboardShortcut :: stringToAction(Ptr::Ref actionName) throw (std::invalid_argument) { - if (actionName == "playAudio") { + if (*actionName == "playAudio") { return playAudio; - } else if (actionName == "pauseAudio") { + } else if (*actionName == "pauseAudio") { return pauseAudio; - } else if (actionName == "stopAudio") { + } else if (*actionName == "stopAudio") { return stopAudio; - } else if (actionName == "nextTrack") { + } else if (*actionName == "nextTrack") { return nextTrack; - } else if (actionName == "fadeOut") { + } else if (*actionName == "fadeOut") { return fadeOut; - } else if (actionName == "moveItemUp") { + } else if (*actionName == "moveItemUp") { return moveItemUp; - } else if (actionName == "moveItemDown") { + } else if (*actionName == "moveItemDown") { return moveItemDown; - } else if (actionName == "removeItem") { + } else if (*actionName == "removeItem") { return removeItem; } else { throw std::invalid_argument(""); diff --git a/livesupport/src/products/gLiveSupport/src/KeyboardShortcut.h b/livesupport/src/products/gLiveSupport/src/KeyboardShortcut.h index 0d6c1ab12..d90e146b1 100644 --- a/livesupport/src/products/gLiveSupport/src/KeyboardShortcut.h +++ b/livesupport/src/products/gLiveSupport/src/KeyboardShortcut.h @@ -63,9 +63,6 @@ using namespace LiveSupport::Core; /* =============================================================== data types */ -// class KeyboardShortcutContainer; // TODO: remove or activate - - /** * A class for representing a keyboard shortcut. * @@ -139,6 +136,11 @@ class KeyboardShortcut : public Configurable */ Action action; + /** + * A string representation of the action. + */ + Ptr::Ref actionString; + /** * The type for storing key and modifier values. */ @@ -163,6 +165,11 @@ class KeyboardShortcut : public Configurable */ KeyListType keyList; + /** + * A string representation of the first item in the key list. + */ + Ptr::Ref firstKeyString; + /** * Convert an action name string to an enumeration value. * If no matching enumeration value is found, noAction is returned. @@ -170,7 +177,7 @@ class KeyboardShortcut : public Configurable * @param actionName a string containing the name of the action. */ Action - stringToAction(const Glib::ustring & actionName) + stringToAction(Ptr::Ref actionName) throw(std::invalid_argument); /** @@ -238,7 +245,7 @@ class KeyboardShortcut : public Configurable * key description. */ void - addKey(const Glib::ustring & modifiedKeyName) + addKey(Ptr::Ref modifiedKeyName) throw (std::invalid_argument); /** @@ -306,6 +313,29 @@ class KeyboardShortcut : public Configurable bool isTriggeredBy(unsigned int modifiers, unsigned int key) const throw (); + + /** + * Return a string corresponding to the action of this shortcut. + * + * @return a string representing the action of this shortcut. + */ + Ptr::Ref + getActionString(void) const throw () + { + return actionString; + } + + /** + * Return the first key associated with this shortcut. + * + * @return a string representing the first modifier-key pair of + * this shortcut. + */ + Ptr::Ref + getKeyString(void) const throw () + { + return firstKeyString; + } }; diff --git a/livesupport/src/products/gLiveSupport/src/KeyboardShortcutContainer.cxx b/livesupport/src/products/gLiveSupport/src/KeyboardShortcutContainer.cxx index 55ea88bf5..b3b7b2351 100644 --- a/livesupport/src/products/gLiveSupport/src/KeyboardShortcutContainer.cxx +++ b/livesupport/src/products/gLiveSupport/src/KeyboardShortcutContainer.cxx @@ -106,7 +106,7 @@ KeyboardShortcutContainer :: configure(const xmlpp::Element & element) *----------------------------------------------------------------------------*/ KeyboardShortcut::Action KeyboardShortcutContainer :: findAction(unsigned int modifiers, - unsigned int key) throw () + unsigned int key) const throw () { ShortcutListType::const_iterator it = shortcutList.begin(); diff --git a/livesupport/src/products/gLiveSupport/src/KeyboardShortcutContainer.h b/livesupport/src/products/gLiveSupport/src/KeyboardShortcutContainer.h index 34e267d69..04fc3ef77 100644 --- a/livesupport/src/products/gLiveSupport/src/KeyboardShortcutContainer.h +++ b/livesupport/src/products/gLiveSupport/src/KeyboardShortcutContainer.h @@ -105,7 +105,7 @@ class KeyboardShortcutContainer : public Configurable /** * A vector type holding contant KeyboardShortcut references. */ - typedef std::vector::Ref> + typedef std::vector::Ref> ShortcutListType; /** @@ -168,7 +168,7 @@ class KeyboardShortcutContainer : public Configurable * @return the action; or noAction if none is found. */ KeyboardShortcut::Action - findAction(unsigned int modifiers, unsigned int key) throw (); + findAction(unsigned int modifiers, unsigned int key) const throw (); /** * Return the name of the window the shortcuts are for. @@ -177,10 +177,34 @@ class KeyboardShortcutContainer : public Configurable * the object has not been configured yet. */ Ptr::Ref - getWindowName(void) throw () + getWindowName(void) const throw () { return windowName; } + + /** + * The iterator for cycling through the keyboard shortcuts. + * Dereference an iterator to get a Ptr::Ref. + */ + typedef ShortcutListType::const_iterator iterator; + + /** + * The first item in the list. + */ + iterator + begin(void) const throw () + { + return shortcutList.begin(); + } + + /** + * One after the last item in the list. + */ + iterator + end(void) const throw () + { + return shortcutList.end(); + } }; diff --git a/livesupport/src/products/gLiveSupport/src/KeyboardShortcutList.cxx b/livesupport/src/products/gLiveSupport/src/KeyboardShortcutList.cxx new file mode 100644 index 000000000..39cb639b4 --- /dev/null +++ b/livesupport/src/products/gLiveSupport/src/KeyboardShortcutList.cxx @@ -0,0 +1,100 @@ +/*------------------------------------------------------------------------------ + + Copyright (c) 2004 Media Development Loan Fund + + This file is part of the LiveSupport project. + http://livesupport.campware.org/ + To report bugs, send an e-mail to bugs@campware.org + + LiveSupport is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + LiveSupport 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 LiveSupport; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + + Author : $Author$ + Version : $Revision$ + Location : $URL$ + +------------------------------------------------------------------------------*/ + +/* ============================================================ include files */ + +#ifdef HAVE_CONFIG_H +#include "configure.h" +#endif + +#include "KeyboardShortcutList.h" + + +using namespace LiveSupport::Core; +using namespace LiveSupport::GLiveSupport; + +/* =================================================== local data structures */ + + +/* ================================================ local constants & macros */ + +/** + * The name of the config element for this class + */ +const std::string KeyboardShortcutList::configElementName + = "keyboardShortcutList"; + + +/* =============================================== local function prototypes */ + + +/* ============================================================= module code */ + +/*------------------------------------------------------------------------------ + * Create a metadata type container element object based on an XML element. + *----------------------------------------------------------------------------*/ +void +KeyboardShortcutList :: configure(const xmlpp::Element & element) + throw (std::invalid_argument) +{ + if (element.get_name() != configElementName) { + throw std::invalid_argument("bad coniguration element " + + element.get_name()); + } + + xmlpp::Node::NodeList nodes = element.get_children( + KeyboardShortcutContainer::getConfigElementName()); + xmlpp::Node::NodeList::const_iterator it = nodes.begin(); + while (it != nodes.end()) { + Ptr::Ref ksc(new KeyboardShortcutContainer); + ksc->configure(*((const xmlpp::Element*) *it)); + containerList.push_back(ksc); + ++it; + } +} + +/*------------------------------------------------------------------------------ + * Find the action triggered by the given key in the given window. + *----------------------------------------------------------------------------*/ +KeyboardShortcut::Action +KeyboardShortcutList :: findAction(const Glib::ustring & windowName, + unsigned int modifiers, + unsigned int key) const + throw () +{ + for (iterator it = begin(); it != end(); ++it) { + Ptr::Ref ksc = *it; + if (*ksc->getWindowName() == windowName) { + return ksc->findAction(modifiers, key); + } + } + + return KeyboardShortcut::noAction; +} + diff --git a/livesupport/src/products/gLiveSupport/src/KeyboardShortcutList.h b/livesupport/src/products/gLiveSupport/src/KeyboardShortcutList.h new file mode 100644 index 000000000..e97dc6b29 --- /dev/null +++ b/livesupport/src/products/gLiveSupport/src/KeyboardShortcutList.h @@ -0,0 +1,194 @@ +/*------------------------------------------------------------------------------ + + Copyright (c) 2004 Media Development Loan Fund + + This file is part of the LiveSupport project. + http://livesupport.campware.org/ + To report bugs, send an e-mail to bugs@campware.org + + LiveSupport is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + LiveSupport 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 LiveSupport; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + + Author : $Author$ + Version : $Revision$ + Location : $URL$ + +------------------------------------------------------------------------------*/ +#ifndef LiveSupport_GLiveSupport_KeyboardShortcutList_h +#define LiveSupport_GLiveSupport_KeyboardShortcutList_h + +#ifndef __cplusplus +#error This is a C++ include file +#endif + + +/* ============================================================ include files */ + +#ifdef HAVE_CONFIG_H +#include "configure.h" +#endif + +#include +#include // TODO: REMOVE ME + +#include "LiveSupport/Core/Ptr.h" +#include "LiveSupport/Core/Configurable.h" + +#include "KeyboardShortcutContainer.h" + + +namespace LiveSupport { +namespace GLiveSupport { + +using namespace LiveSupport::Core; + +/* ================================================================ constants */ + + +/* =================================================================== macros */ + + +/* =============================================================== data types */ + +/** + * A list of KeyboardShortcutContainer objects. + * + * This object has to be configured with an XML configuration element + * called keyboardShortcutList. + * + * The DTD for the expected XML element is the following: + *

+ *  
+ *  
+ * + * For a description of the keyboardShortcutContainer XML element, + * see the documentation of the KeyboardShortcutContainer class. + * + * @author $Author$ + * @version $Revision$ + * @see KeyboardShortcut + */ +class KeyboardShortcutList : public Configurable +{ + private: + /** + * The name of the configuration XML element used by + * KeyboardShortcutList. + */ + static const std::string configElementName; + + /** + * The type for storing the keyboard shortcut containers. + */ + typedef std::vector::Ref> + ContainerListType; + + /** + * The list of keyboard shortcut containers for the various windows. + */ + ContainerListType containerList; + + + public: + /** + * Constructor. + */ + KeyboardShortcutList() throw () + { + } + + /** + * A virtual destructor, as this class has virtual functions. + */ + virtual + ~KeyboardShortcutList(void) throw () + { + } + + /** + * Return the name of the XML element this object expects + * to be sent to a call to configure(). + * + * @return the name of the expected XML configuration element. + */ + static const std::string + getConfigElementName(void) throw () + { + return configElementName; + } + + /** + * Configure the metadata object based on an XML configuration element. + * + * @param elemen the XML configuration element. + * @exception std::invalid_argument of the supplied XML element + * contains bad configuration information + */ + virtual void + configure(const xmlpp::Element &element) + throw (std::invalid_argument); + + /** + * Find the action triggered by the given key in the given window. + * + * @param windowName a string identifying the window (not localized). + * @param modifiers the gdktypes code for the Shift, Ctrl etc. + * modifier keys which are pressed. + * @param key the gdkkeysyms code for the key pressed. + * @return the associated action; or noAction, if none is found. + */ + KeyboardShortcut::Action + findAction(const Glib::ustring & windowName, + unsigned int modifiers, + unsigned int key) const throw (); + + /** + * The iterator for cycling through the keyboard shortcut containers. + * Dereference an iterator to get a + * Ptr::Ref. + */ + typedef ContainerListType::const_iterator iterator; + + /** + * The first item in the list. + */ + iterator + begin(void) const throw () + { + return containerList.begin(); + } + + /** + * One after the last item in the list. + */ + iterator + end(void) const throw () + { + return containerList.end(); + } +}; + + +/* ================================================= external data structures */ + + +/* ====================================================== function prototypes */ + + +} // namespace GLiveSupport +} // namespace LiveSupport + +#endif // LiveSupport_GLiveSupport_KeyboardShortcutList_h + diff --git a/livesupport/src/products/gLiveSupport/src/MasterPanelWindow.cxx b/livesupport/src/products/gLiveSupport/src/MasterPanelWindow.cxx index 86b507ecd..5b02e7c8c 100644 --- a/livesupport/src/products/gLiveSupport/src/MasterPanelWindow.cxx +++ b/livesupport/src/products/gLiveSupport/src/MasterPanelWindow.cxx @@ -247,7 +247,7 @@ MasterPanelWindow :: changeLanguage(Ptr::Ref bundle) } try { - set_title(*getResourceUstring("windowTitle")); + set_title(*getResourceUstring(windowName.c_str(), "windowTitle")); Ptr::Ref wf = WidgetFactory::getInstance(); diff --git a/livesupport/src/products/gLiveSupport/src/OptionsWindow.cxx b/livesupport/src/products/gLiveSupport/src/OptionsWindow.cxx index 0162d56a4..d4329e51a 100644 --- a/livesupport/src/products/gLiveSupport/src/OptionsWindow.cxx +++ b/livesupport/src/products/gLiveSupport/src/OptionsWindow.cxx @@ -89,17 +89,20 @@ OptionsWindow :: OptionsWindow (Ptr::Ref gLiveSupport, // build up the notepad for the various sections mainNotebook = Gtk::manage(new ScrolledNotebook); - Gtk::Box * soundSectionBox = constructSoundSection(); - Gtk::Box * serversSectionBox = constructServersSection(); - Gtk::Box * aboutSectionBox = constructAboutSection(); + Gtk::Box * soundSectionBox = constructSoundSection(); + Gtk::Box * keyBindingsSectionBox = constructKeyBindingsSection(); + Gtk::Box * serversSectionBox = constructServersSection(); + Gtk::Box * aboutSectionBox = constructAboutSection(); try { mainNotebook->appendPage(*soundSectionBox, - *getResourceUstring("soundSectionLabel")); + *getResourceUstring("soundSectionLabel")); + mainNotebook->appendPage(*keyBindingsSectionBox, + *getResourceUstring("keyBindingsSectionLabel")); mainNotebook->appendPage(*serversSectionBox, - *getResourceUstring("serversSectionLabel")); + *getResourceUstring("serversSectionLabel")); mainNotebook->appendPage(*aboutSectionBox, - *getResourceUstring("aboutSectionLabel")); + *getResourceUstring("aboutSectionLabel")); } catch (std::invalid_argument &e) { // TODO: signal error @@ -384,6 +387,74 @@ OptionsWindow :: constructSoundSection(void) throw () } +/*------------------------------------------------------------------------------ + * Construct the "Key bindings" section. + *----------------------------------------------------------------------------*/ +Gtk::VBox* +OptionsWindow :: constructKeyBindingsSection(void) throw () +{ + // create the TreeView + keyBindingsModel = Gtk::TreeStore::create(keyBindingsColumns); + Gtk::TreeView * keyBindingsView = Gtk::manage(new Gtk::TreeView( + keyBindingsModel )); + + keyBindingsView->append_column("", keyBindingsColumns.actionColumn); + keyBindingsView->append_column("", keyBindingsColumns.keyNameColumn); + + // fill in the data + Ptr::Ref + list = gLiveSupport->getKeyboardShortcutList(); + + try { + KeyboardShortcutList::iterator it; + for (it = list->begin(); it != list->end(); ++it) { + Ptr::Ref + container = *it; + Ptr::Ref + windowName = container->getWindowName(); + Gtk::TreeRow parent = *keyBindingsModel->append(); + parent[keyBindingsColumns.actionColumn] + = *gLiveSupport->getLocalizedWindowName(windowName); + + KeyboardShortcutContainer::iterator iter; + for (iter = container->begin(); iter != container->end(); ++iter) { + Ptr::Ref + shortcut = *iter; + Ptr::Ref + actionString = shortcut->getActionString(); + Ptr::Ref + keyString = shortcut->getKeyString(); + Gtk::TreeRow child + = *keyBindingsModel->append(parent.children()); + child[keyBindingsColumns.actionColumn] + = *gLiveSupport->getLocalizedKeyboardActionName( + actionString); + child[keyBindingsColumns.keyNameColumn] + = *keyString; // TODO: localize this? + } + } + } catch (std::invalid_argument &e) { + // TODO: signal error + std::cerr << e.what() << std::endl; + std::exit(1); + } + + // set TreeView properties + keyBindingsView->set_headers_visible(false); + keyBindingsView->set_rules_hint(true); + keyBindingsView->columns_autosize(); + keyBindingsView->expand_all(); + + // connect the callbacks + + // make a new box and pack the components into it + Gtk::VBox * section = Gtk::manage(new Gtk::VBox); + section->pack_start(*keyBindingsView, Gtk::PACK_SHRINK, 5); + + return section; +} + + /*------------------------------------------------------------------------------ * Construct the "Servers" section. *----------------------------------------------------------------------------*/ diff --git a/livesupport/src/products/gLiveSupport/src/OptionsWindow.h b/livesupport/src/products/gLiveSupport/src/OptionsWindow.h index 4743daaa5..17b430485 100644 --- a/livesupport/src/products/gLiveSupport/src/OptionsWindow.h +++ b/livesupport/src/products/gLiveSupport/src/OptionsWindow.h @@ -169,6 +169,14 @@ class OptionsWindow : public WhiteWindow, public LocalizedObject Gtk::VBox* constructSoundSection(void) throw (); + /** + * Construct the "Key bindings" section. + * + * @return a pointer to the new box (already Gtk::manage()'ed) + */ + Gtk::VBox* + constructKeyBindingsSection(void) throw (); + /** * Construct the "Servers" section. * @@ -226,6 +234,61 @@ class OptionsWindow : public WhiteWindow, public LocalizedObject virtual void onTestButtonClicked(const EntryBin * entry) throw (); + /** + * The columns model containing the data for the Key bindings section. + * + * @author $Author$ + * @version $Revision$ + */ + class ModelColumns : public Gtk::TreeModelColumnRecord + { + public: + /** + * The column for the name of the action. + * This contains the name of the window (for parent rows), + * or the name of the action (for child rows). + */ + Gtk::TreeModelColumn actionColumn; + + /** + * The column for the user readable name of the key bound. + * (Or "Disabled" if no key is bound to this action.) + */ + Gtk::TreeModelColumn keyNameColumn; + + /** + * The column for the gdkkeytypes.h code of the modifiers. + */ + Gtk::TreeModelColumn modifiersColumn; + + /** + * The column for the gdkkeysyms.h code of the key. + */ + Gtk::TreeModelColumn keyValueColumn; + + /** + * Constructor. + */ + ModelColumns(void) throw () + { + add(actionColumn); + add(keyNameColumn); + add(modifiersColumn); + add(keyValueColumn); + } + }; + + + /** + * The column model. + */ + ModelColumns keyBindingsColumns; + + /** + * The tree model, as a GTK reference. + */ + Glib::RefPtr keyBindingsModel; + public: /** diff --git a/livesupport/src/products/gLiveSupport/var/root.txt b/livesupport/src/products/gLiveSupport/var/root.txt index 049a62de7..ecdf01215 100644 --- a/livesupport/src/products/gLiveSupport/var/root.txt +++ b/livesupport/src/products/gLiveSupport/var/root.txt @@ -1,6 +1,5 @@ root:table { - windowTitle:string { "LiveSupport Master Panel" } notLoggedInMsg:string { "Not logged in" } loggedInMsg:string { "Logged in as {0}" } loginButtonLabel:string { "log in" } @@ -30,19 +29,24 @@ root:table audioErrorMsg { "Audio player error: " } sureToExitMsg:string { "Are you sure you want to exit?" } + masterPanelWindow:table + { + windowTitle:string { "Master Panel" } + } + loginWindow:table { - windowTitle:string { "LOGIN" } + windowTitle:string { "Login" } - loginLabel:string { "Login" } - passwordLabel:string { "Password" } + loginLabel:string { "User name:" } + passwordLabel:string { "Password:" } okButtonLabel:string { "OK" } cancelButtonLabel:string { "Cancel" } } audioClipListWindow:table { - windowTitle:string { "LiveSupport Audio Clip Window" } + windowTitle:string { "Audio Clip List" } idColumnLabel:string { "id" } lengthColumnLabel:string { "length" } @@ -54,7 +58,7 @@ root:table scratchpadWindow:table { - windowTitle:string { "LiveSupport Scratchpad" } + windowTitle:string { "Scratchpad" } typeColumnLabel:string { "Type" } titleColumnLabel:string { "Title" } @@ -81,7 +85,7 @@ root:table playlistListWindow:table { - windowTitle:string { "LiveSupport Playlist Window" } + windowTitle:string { "Playlist" } listBoxLabel { "Playlists" } detailBoxLabel { "Playlist details" } @@ -124,8 +128,7 @@ root:table simplePlaylistManagementWindow:table { - windowTitle:string { "LiveSupport Simple Playlist Management" - " Window" } + windowTitle:string { "Simple Playlist Management" } startColumnLabel:string { "Start" } titleColumnLabel:string { "Title" } @@ -151,7 +154,7 @@ root:table schedulerWindow:table { - windowTitle:string { "LiveSupport Scheduler Window" } + windowTitle:string { "Scheduler" } startColumnLabel:string { "start" } titleColumnLabel:string { "title" } @@ -164,7 +167,7 @@ root:table schedulePlaylistWindow:table { - windowTitle:string { "LiveSupport Schedule Playlist Window" } + windowTitle:string { "Schedule Playlist" } hourLabel:string { "hour: " } minuteLabel:string { "minute: " } @@ -174,7 +177,7 @@ root:table searchWindow:table { - windowTitle:string { "LiveSupport Search/Browse Window" } + windowTitle:string { "Search/Browse" } simpleSearchTab:string { "Search" } advancedSearchTab:string { "Advanced Search" } @@ -206,7 +209,7 @@ root:table liveModeWindow:table { - windowTitle:string { "LiveSupport Live Mode Window" } + windowTitle:string { "Live Mode" } cueMenuItem:string { "Pre_view" } upMenuItem:string { "Move _Up" } @@ -219,7 +222,7 @@ root:table optionsWindow:table { - windowTitle:string { "LiveSupport Options Window" } + windowTitle:string { "Options" } needToRestartMsg:string { "You will need to restart the " "application\nfor the new settings " @@ -227,6 +230,8 @@ root:table errorMsg:string { "Could not save the options: " } soundSectionLabel:string { "Sound" } + keyBindingsSectionLabel:string + { "Keyboard Shortcuts" } serversSectionLabel:string { "Servers" } aboutSectionLabel:string { "About" } @@ -290,5 +295,17 @@ root:table report_organizations:string { "Report organizations" } subject { "Subject" } } + + keyboardShortcuts:table + { + playAudio:string { Play } + pauseAudio:string { Pause } + stopAudio:string { Stop } + nextTrack:string { Next track } + fadeOut:string { Fade out } + moveItemUp:string { Move item up } + moveItemDown:string { Move item down } + removeItem:string { Remove item } + } }