diff --git a/livesupport/products/gLiveSupport/etc/Makefile.in b/livesupport/products/gLiveSupport/etc/Makefile.in index ef2368bd5..9e34dfe28 100644 --- a/livesupport/products/gLiveSupport/etc/Makefile.in +++ b/livesupport/products/gLiveSupport/etc/Makefile.in @@ -21,7 +21,7 @@ # # # Author : $Author: maroy $ -# Version : $Revision: 1.12 $ +# Version : $Revision: 1.13 $ # Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/gLiveSupport/etc/Makefile.in,v $ # # @configure_input@ @@ -146,7 +146,6 @@ G_LIVESUPPORT_OBJS = ${TMP_DIR}/GLiveSupport.o \ ${TMP_DIR}/UiTestMainWindow.o \ ${TMP_DIR}/MasterPanelWindow.o \ ${TMP_DIR}/MasterPanelUserInfoWidget.o \ - ${TMP_DIR}/GtkLocalizedObject.o \ ${TMP_DIR}/LoginWindow.o \ ${TMP_DIR}/AudioClipListWindow.o \ ${TMP_DIR}/PlaylistListWindow.o diff --git a/livesupport/products/gLiveSupport/src/AudioClipListWindow.cxx b/livesupport/products/gLiveSupport/src/AudioClipListWindow.cxx index 3478ea7bb..09712276f 100644 --- a/livesupport/products/gLiveSupport/src/AudioClipListWindow.cxx +++ b/livesupport/products/gLiveSupport/src/AudioClipListWindow.cxx @@ -22,7 +22,7 @@ Author : $Author: maroy $ - Version : $Revision: 1.2 $ + Version : $Revision: 1.3 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/gLiveSupport/src/Attic/AudioClipListWindow.cxx,v $ ------------------------------------------------------------------------------*/ @@ -62,7 +62,7 @@ AudioClipListWindow :: AudioClipListWindow ( Ptr::Ref gLiveSupport, Ptr::Ref bundle) throw () - : GtkLocalizedObject(bundle) + : LocalizedObject(bundle) { this->gLiveSupport = gLiveSupport; diff --git a/livesupport/products/gLiveSupport/src/AudioClipListWindow.h b/livesupport/products/gLiveSupport/src/AudioClipListWindow.h index 66385c62c..e3be5ec85 100644 --- a/livesupport/products/gLiveSupport/src/AudioClipListWindow.h +++ b/livesupport/products/gLiveSupport/src/AudioClipListWindow.h @@ -22,7 +22,7 @@ Author : $Author: maroy $ - Version : $Revision: 1.2 $ + Version : $Revision: 1.3 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/gLiveSupport/src/Attic/AudioClipListWindow.h,v $ ------------------------------------------------------------------------------*/ @@ -47,7 +47,7 @@ #include #include "LiveSupport/Core/Ptr.h" -#include "GtkLocalizedObject.h" +#include "LiveSupport/Core/LocalizedObject.h" #include "GLiveSupport.h" namespace LiveSupport { @@ -67,9 +67,9 @@ using namespace LiveSupport::Core; * A window, showing and handling audio clips. * * @author $Author: maroy $ - * @version $Revision: 1.2 $ + * @version $Revision: 1.3 $ */ -class AudioClipListWindow : public Gtk::Window, public GtkLocalizedObject +class AudioClipListWindow : public Gtk::Window, public LocalizedObject { protected: @@ -79,7 +79,7 @@ class AudioClipListWindow : public Gtk::Window, public GtkLocalizedObject * Lists one clip per row. * * @author $Author: maroy $ - * @version $Revision: 1.2 $ + * @version $Revision: 1.3 $ */ class ModelColumns : public Gtk::TreeModel::ColumnRecord { diff --git a/livesupport/products/gLiveSupport/src/GLiveSupport.cxx b/livesupport/products/gLiveSupport/src/GLiveSupport.cxx index 4fbf2f331..ca7d1b493 100644 --- a/livesupport/products/gLiveSupport/src/GLiveSupport.cxx +++ b/livesupport/products/gLiveSupport/src/GLiveSupport.cxx @@ -22,7 +22,7 @@ Author : $Author: maroy $ - Version : $Revision: 1.6 $ + Version : $Revision: 1.7 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/gLiveSupport/src/GLiveSupport.cxx,v $ ------------------------------------------------------------------------------*/ @@ -36,11 +36,11 @@ #include #include +#include "LiveSupport/Core/LocalizedObject.h" #include "LiveSupport/Authentication/AuthenticationClientFactory.h" #include "LiveSupport/Storage/StorageClientFactory.h" #include "LiveSupport/SchedulerClient/SchedulerClientFactory.h" -#include "GtkLocalizedObject.h" #include "MasterPanelWindow.h" #include "GLiveSupport.h" @@ -118,8 +118,8 @@ GLiveSupport :: configure(const xmlpp::Element & element) if (nodes.size() < 1) { throw std::invalid_argument("no resourceBundle element"); } - resourceBundle = LocalizedObject::getBundle( - *((const xmlpp::Element*) *(nodes.begin())) ); + LocalizedConfigurable::configure( + *((const xmlpp::Element*) *(nodes.begin()))); // configure the AuthenticationClientFactory nodes = element.get_children( @@ -169,8 +169,7 @@ GLiveSupport :: configSupportedLanguages(const xmlpp::Element & element) xmlpp::Node::NodeList::iterator begin; xmlpp::Node::NodeList::iterator end; - supportedLanguages.reset( - new std::map::Ref>()); + supportedLanguages.reset(new LanguageMap()); // read the list of supported languages nodes = element.get_children(languageElementName); @@ -185,7 +184,7 @@ GLiveSupport :: configSupportedLanguages(const xmlpp::Element & element) std::string locale = localeAttr->get_value().raw(); Ptr::Ref uName(new Glib::ustring(nameAttr->get_value())); Ptr::Ref name = - GtkLocalizedObject::ustringToUnicodeString(uName); + LocalizedObject::ustringToUnicodeString(uName); supportedLanguages->insert(std::make_pair(locale, name)); @@ -201,16 +200,29 @@ void LiveSupport :: GLiveSupport :: GLiveSupport :: show(void) throw () { - Ptr::Ref masterPanel; - - masterPanel.reset(new MasterPanelWindow(shared_from_this(), - resourceBundle)); + masterPanel.reset(new MasterPanelWindow(shared_from_this(), getBundle())); // Shows the window and returns when it is closed. Gtk::Main::run(*masterPanel); } +/*------------------------------------------------------------------------------ + * Change the language of the application + *----------------------------------------------------------------------------*/ +void +LiveSupport :: GLiveSupport :: +GLiveSupport :: changeLanguage(Ptr::Ref locale) + throw () +{ + changeLocale(*locale); + + if (masterPanel.get()) { + masterPanel->changeLanguage(getBundle()); + } +} + + /*------------------------------------------------------------------------------ * Authenticate the user *----------------------------------------------------------------------------*/ diff --git a/livesupport/products/gLiveSupport/src/GLiveSupport.h b/livesupport/products/gLiveSupport/src/GLiveSupport.h index cfcbd812f..717ff1459 100644 --- a/livesupport/products/gLiveSupport/src/GLiveSupport.h +++ b/livesupport/products/gLiveSupport/src/GLiveSupport.h @@ -22,7 +22,7 @@ Author : $Author: maroy $ - Version : $Revision: 1.8 $ + Version : $Revision: 1.9 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/gLiveSupport/src/GLiveSupport.h,v $ ------------------------------------------------------------------------------*/ @@ -46,7 +46,7 @@ #include #include "LiveSupport/Core/Ptr.h" -#include "LiveSupport/Core/Configurable.h" +#include "LiveSupport/Core/LocalizedConfigurable.h" #include "LiveSupport/Authentication/AuthenticationClientInterface.h" #include "LiveSupport/Storage/StorageClientInterface.h" #include "LiveSupport/SchedulerClient/SchedulerClientInterface.h" @@ -67,6 +67,10 @@ using namespace LiveSupport::Storage; /* =============================================================== data types */ + +class MasterPanelWindow; + + /** * The main application object for the gLiveSupport GUI. * @@ -88,26 +92,32 @@ using namespace LiveSupport::Storage; * respective documentation. * * @author $Author: maroy $ - * @version $Revision: 1.8 $ + * @version $Revision: 1.9 $ * @see LocalizedObject#getBundle(const xmlpp::Element &) * @see AuthenticationClientFactory * @see StorageClientFactory * @see SchedulerClientFactory */ -class GLiveSupport : public Configurable, +class GLiveSupport : public LocalizedConfigurable, public boost::enable_shared_from_this { + public: + /** + * A type for the map of supported languages. + * This is an STL map, containing const std::string as keys, which + * are the locale names of supported langauges. The values are + * Ptr::Ref, the names of the languages. + */ + typedef std::map::Ref> LanguageMap; + + private: /** * The name of the configuration XML elmenent used by Playlist. */ static const std::string configElementNameStr; - /** - * The resource bundle used by the applicaton. - */ - Ptr::Ref resourceBundle; - /** * The authentication client used by the application. */ @@ -129,10 +139,14 @@ class GLiveSupport : public Configurable, Ptr::Ref sessionId; /** - * The map of supported language. + * The map of supported languages. */ - Ptr::Ref> >::Ref - supportedLanguages; + Ptr::Ref supportedLanguages; + + /** + * The master panel window. + */ + Ptr::Ref masterPanel; /** * Read a supportedLanguages configuration element, @@ -198,6 +212,14 @@ class GLiveSupport : public Configurable, void show(void) throw (); + /** + * Change the language of the application. + * + * @param locale the new locale of the appliction. + */ + void + changeLanguage(Ptr::Ref locale) throw (); + /** * Perform authentication for the user of the application. * As a result, the user will be authenticated for later @@ -259,6 +281,18 @@ class GLiveSupport : public Configurable, { return storage; } + + /** + * Get the map of supported languages. + * + * @return the map of supported languages. + */ + Ptr::Ref + getSupportedLanguages(void) const throw () + { + return supportedLanguages; + } + }; /* ================================================= external data structures */ diff --git a/livesupport/products/gLiveSupport/src/GtkLocalizedObject.cxx b/livesupport/products/gLiveSupport/src/GtkLocalizedObject.cxx deleted file mode 100644 index 58d0deb4f..000000000 --- a/livesupport/products/gLiveSupport/src/GtkLocalizedObject.cxx +++ /dev/null @@ -1,92 +0,0 @@ -/*------------------------------------------------------------------------------ - - 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: maroy $ - Version : $Revision: 1.2 $ - Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/gLiveSupport/src/Attic/GtkLocalizedObject.cxx,v $ - -------------------------------------------------------------------------------*/ - -/* ============================================================ include files */ - -#ifdef HAVE_CONFIG_H -#include "configure.h" -#endif - -#include "GtkLocalizedObject.h" - - -using namespace LiveSupport::Core; -using namespace LiveSupport::GLiveSupport; - -/* =================================================== local data structures */ - - -/* ================================================ local constants & macros */ - - -/* =============================================== local function prototypes */ - - -/* ============================================================= module code */ - -/*------------------------------------------------------------------------------ - * Create a Glib ustring from an ICU UnicodeString - *----------------------------------------------------------------------------*/ -Ptr::Ref -GtkLocalizedObject :: unicodeStringToUstring( - Ptr::Ref unicodeString) - throw () -{ - const UChar * uchars = unicodeString->getBuffer(); - int32_t length = unicodeString->length(); - Ptr::Ref ustr(new Glib::ustring()); - ustr->reserve(length); - - while (length--) { - ustr->push_back((gunichar) (*(uchars++))); - } - - return ustr; -} - - -/*------------------------------------------------------------------------------ - * Create an ICU UnicodeString from a Glib ustring - *----------------------------------------------------------------------------*/ -Ptr::Ref -GtkLocalizedObject :: ustringToUnicodeString( - Ptr::Ref gString) - throw () -{ - Ptr::Ref uString(new UnicodeString()); - - Glib::ustring::const_iterator it = gString->begin(); - Glib::ustring::const_iterator end = gString->end(); - while (it < end) { - uString->append((UChar32) *it++); - } - - return uString; -} - diff --git a/livesupport/products/gLiveSupport/src/GtkLocalizedObject.h b/livesupport/products/gLiveSupport/src/GtkLocalizedObject.h deleted file mode 100644 index 17039fab6..000000000 --- a/livesupport/products/gLiveSupport/src/GtkLocalizedObject.h +++ /dev/null @@ -1,162 +0,0 @@ -/*------------------------------------------------------------------------------ - - 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: maroy $ - Version : $Revision: 1.2 $ - Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/gLiveSupport/src/Attic/GtkLocalizedObject.h,v $ - -------------------------------------------------------------------------------*/ -#ifndef GtkLocalizedObject_h -#define GtkLocalizedObject_h - -#ifndef __cplusplus -#error This is a C++ include file -#endif - - -/* ============================================================ include files */ - -#ifdef HAVE_CONFIG_H -#include "configure.h" -#endif - -#include - -#include "LiveSupport/Core/Ptr.h" -#include "LiveSupport/Core/LocalizedObject.h" - -namespace LiveSupport { -namespace GLiveSupport { - -using namespace LiveSupport::Core; - -/* ================================================================ constants */ - - -/* =================================================================== macros */ - - -/* =============================================================== data types */ - -/** - * Base class for localized objects, using GTK+ strings. - * - * @author $Author: maroy $ - * @version $Revision: 1.2 $ - */ -class GtkLocalizedObject : public LocalizedObject -{ - public: - /** - * Constructor. - * - * @param bundle the resource bundle holding the localized - * resources for this window - */ - GtkLocalizedObject(Ptr::Ref bundle) throw () - : LocalizedObject(bundle) - { - } - - /** - * Virtual destructor. - */ - virtual - ~GtkLocalizedObject(void) throw () - { - } - - /** - * Convert an ICU unicode string to a Glib ustring. - * - * @param unicodeString the ICU unicode string to convert. - * @return the same string as supplied, in Glib ustring form. - */ - static Ptr::Ref - unicodeStringToUstring(Ptr::Ref unicodeString) - throw (); - - /** - * Convert a Glib ustring to an ICU unicode string. - * - * @param gString the Glib ustring to convert - * @return the same string as supplied, in ICU unicode form. - */ - static Ptr::Ref - ustringToUnicodeString(Ptr::Ref gString) - throw (); - - /** - * Get a string from the resource bundle, as a Glib ustring. - * - * @param key the key identifying the requested string. - * @return the requested string - * @exception std::invalid_argument if there is no string for the - * specified key. - */ - Ptr::Ref - getResourceUstring(const char * key) - throw (std::invalid_argument) - { - return unicodeStringToUstring(getResourceString(key)); - } - - /** - * A convenience function to format a message, based on a pattern - * loaded from a resource. - * For more information, see the ICU MessageFormat class - * documentation. - * - * @param patternKey the key of the pattern to format - * @param arguments the arguments to use in the formatting - * @param nArguments the number of arguments supplied - * @return the formatted string, in Glib ustring form - * @exception std::invalid_argument if the pattern is bad, or - * the arguments do not match, or there is no resource - * specified by patternKey - * @see http://oss.software.ibm.com/icu/apiref/classMessageFormat.html - */ - virtual Ptr::Ref - formatMessageUstring(const char * patternKey, - Formattable * arguments, - unsigned int nArguments) - throw (std::invalid_argument) - { - return unicodeStringToUstring(formatMessage(patternKey, - arguments, - nArguments)); - } - -}; - -/* ================================================= external data structures */ - - -/* ====================================================== function prototypes */ - - -} // namespace Core -} // namespace LiveSupport - -#endif // GtkLocalizedObject_h - diff --git a/livesupport/products/gLiveSupport/src/LoginWindow.cxx b/livesupport/products/gLiveSupport/src/LoginWindow.cxx index a8fd2552b..f06e9bf8e 100644 --- a/livesupport/products/gLiveSupport/src/LoginWindow.cxx +++ b/livesupport/products/gLiveSupport/src/LoginWindow.cxx @@ -22,7 +22,7 @@ Author : $Author: maroy $ - Version : $Revision: 1.5 $ + Version : $Revision: 1.6 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/gLiveSupport/src/LoginWindow.cxx,v $ ------------------------------------------------------------------------------*/ @@ -58,10 +58,13 @@ using namespace LiveSupport::GLiveSupport; /*------------------------------------------------------------------------------ * Constructor. *----------------------------------------------------------------------------*/ -LoginWindow :: LoginWindow (Ptr::Ref bundle) +LoginWindow :: LoginWindow (Ptr::Ref gLiveSupport, + Ptr::Ref bundle) throw () - : GtkLocalizedObject(bundle) + : LocalizedObject(bundle) { + this->gLiveSupport = gLiveSupport; + try { set_title(*getResourceUstring("windowTitle")); loginLabel.reset(new Gtk::Label(*getResourceUstring("loginLabel"))); @@ -69,6 +72,7 @@ LoginWindow :: LoginWindow (Ptr::Ref bundle) *getResourceUstring("passwordLabel"))); loginEntry.reset(new Gtk::Entry()); passwordEntry.reset(new Gtk::Entry()); + languageList.reset(new Gtk::Combo()); okButton.reset(new Gtk::Button(*getResourceUstring("okButtonLabel"))); } catch (std::invalid_argument &e) { std::cerr << e.what() << std::endl; @@ -112,6 +116,38 @@ LoginWindow :: LoginWindow (Ptr::Ref bundle) passwordEntry->set_has_frame(true); passwordEntry->set_activates_default(true); + // set up the drop down list for available languages + languageList->set_name("languageList"); + languageList->set_flags(Gtk::CAN_FOCUS); + languageList->get_entry()->set_editable(false); + + // fill up the language list with the list of available languages + Ptr::Ref languages; + languages = gLiveSupport->getSupportedLanguages(); + GLiveSupport::LanguageMap::const_iterator lang = languages->begin(); + GLiveSupport::LanguageMap::const_iterator end = languages->end(); + Ptr::Ref uLanguage; + std::string locale; + + // insert the inital, 'default' language + locale = ""; + uLanguage.reset(new Glib::ustring("")); + insertLanguageItem(locale, uLanguage); + selectedLocale.reset(new std::string("")); + + while (lang != end) { + Ptr::Ref language = (*lang).second; + + locale = (*lang).first; + uLanguage = unicodeStringToUstring(language); + insertLanguageItem(locale, uLanguage); + + lang++; + } + + languageList->get_list()->signal_select_child().connect( + sigc::mem_fun(*this, &LoginWindow::onLanguageSelected)); + // set up the OK button okButton->set_name("okButton"); okButton->set_flags(Gtk::CAN_FOCUS|Gtk::CAN_DEFAULT|Gtk::HAS_DEFAULT); @@ -138,8 +174,11 @@ LoginWindow :: LoginWindow (Ptr::Ref bundle) table->attach(*passwordEntry, 1, 2, 1, 2, Gtk::EXPAND|Gtk::FILL, Gtk::AttachOptions(), 0, 0); - table->attach(*okButton, + table->attach(*languageList, 1, 2, 2, 3, + Gtk::EXPAND|Gtk::FILL, Gtk::AttachOptions(), 0, 0); + table->attach(*okButton, + 1, 2, 3, 4, Gtk::FILL, Gtk::AttachOptions(), 0, 0); // set up the window itself @@ -177,3 +216,31 @@ LoginWindow :: onOkButtonClicked (void) throw () } +/*------------------------------------------------------------------------------ + * Event handler for a language selected + *----------------------------------------------------------------------------*/ +void +LoginWindow :: onLanguageSelected (Gtk::Widget & widget) throw () +{ + Gtk::ComboDropDownItem * item = (Gtk::ComboDropDownItem*) &widget; + Gtk::Widget * label = *(item->get_children().begin()); + selectedLocale.reset(new std::string(label->get_name().raw())); +} + + +/*------------------------------------------------------------------------------ + * Insert an item into the language list + *----------------------------------------------------------------------------*/ +void +LoginWindow :: insertLanguageItem(std::string & itemName, + Ptr::Ref itemLabel) + throw () +{ + Gtk::ComboDropDownItem* item = Gtk::manage(new Gtk::ComboDropDownItem); + Gtk::Label * label = Gtk::manage(new Gtk::Label(*itemLabel)); + label->set_name(itemName); + item->add(*label); + item->show_all(); + languageList->get_list()->children().push_back(*item); +} + diff --git a/livesupport/products/gLiveSupport/src/LoginWindow.h b/livesupport/products/gLiveSupport/src/LoginWindow.h index c2bcdbc2e..4c9aa0095 100644 --- a/livesupport/products/gLiveSupport/src/LoginWindow.h +++ b/livesupport/products/gLiveSupport/src/LoginWindow.h @@ -22,7 +22,7 @@ Author : $Author: maroy $ - Version : $Revision: 1.3 $ + Version : $Revision: 1.4 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/gLiveSupport/src/LoginWindow.h,v $ ------------------------------------------------------------------------------*/ @@ -49,9 +49,11 @@ #include #include #include +#include #include "LiveSupport/Core/Ptr.h" -#include "GtkLocalizedObject.h" +#include "LiveSupport/Core/LocalizedObject.h" +#include "GLiveSupport.h" namespace LiveSupport { namespace GLiveSupport { @@ -70,12 +72,17 @@ using namespace LiveSupport::Core; * A window, handling user login. * * @author $Author: maroy $ - * @version $Revision: 1.3 $ + * @version $Revision: 1.4 $ */ -class LoginWindow : public Gtk::Window, public GtkLocalizedObject +class LoginWindow : public Gtk::Window, public LocalizedObject { protected: + /** + * The GLiveSupport object, containing all the vital info. + */ + Ptr::Ref gLiveSupport; + /** * The table, which provides the layout for the window. */ @@ -101,6 +108,11 @@ class LoginWindow : public Gtk::Window, public GtkLocalizedObject */ Ptr::Ref passwordEntry; + /** + * The drop-down list to select the desired language. + */ + Ptr::Ref languageList; + /** * The OK button. */ @@ -116,21 +128,48 @@ class LoginWindow : public Gtk::Window, public GtkLocalizedObject */ Ptr::Ref passwordText; + /** + * The locale / language selected by the user. + */ + Ptr::Ref selectedLocale; + /** * Signal handler for the ok button clicked. */ virtual void onOkButtonClicked(void) throw (); + /** + * Signal handler for a language being selected from the + * language drop-down menu. + * + * @param widget the item that has just been selected. + */ + void + onLanguageSelected(Gtk::Widget & widget) throw (); + + /** + * Insert an item into languageList + * + * @param itemName the name of the item. + * @param itemLabel the label of the item. + */ + void + insertLanguageItem(std::string & itemName, + Ptr::Ref itemLabel) throw (); + public: /** * Constructor. * + * @param gLiveSupport the gLiveSupport object, containing + * all the vital info. * @param bundle the resource bundle holding the localized * resources for this window */ - LoginWindow(Ptr::Ref bundle) throw (); + LoginWindow(Ptr::Ref gLiveSupport, + Ptr::Ref bundle) throw (); /** * Virtual destructor. @@ -159,6 +198,18 @@ class LoginWindow : public Gtk::Window, public GtkLocalizedObject { return passwordText; } + + /** + * Get the locale selected by the user. + * + * @return the locale selected by the user. if this is an empty + * string, the user selected the default locale. + */ + Ptr::Ref + getSelectedLocale(void) const throw () + { + return selectedLocale; + } }; /* ================================================= external data structures */ diff --git a/livesupport/products/gLiveSupport/src/MasterPanelUserInfoWidget.cxx b/livesupport/products/gLiveSupport/src/MasterPanelUserInfoWidget.cxx index 07159ed04..d1ae6d79a 100644 --- a/livesupport/products/gLiveSupport/src/MasterPanelUserInfoWidget.cxx +++ b/livesupport/products/gLiveSupport/src/MasterPanelUserInfoWidget.cxx @@ -22,7 +22,7 @@ Author : $Author: maroy $ - Version : $Revision: 1.1 $ + Version : $Revision: 1.2 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/gLiveSupport/src/MasterPanelUserInfoWidget.cxx,v $ ------------------------------------------------------------------------------*/ @@ -63,26 +63,19 @@ MasterPanelUserInfoWidget :: MasterPanelUserInfoWidget ( Ptr::Ref gLiveSupport, Ptr::Ref bundle) throw () - : GtkLocalizedObject(bundle) + : LocalizedObject(bundle) { this->gLiveSupport = gLiveSupport; + loggedIn = false; - Ptr::Ref loginButtonLabel; - Ptr::Ref notLoggedInMsg; - - try { - loginButtonLabel = getResourceUstring("loginButtonLabel"); - notLoggedInMsg = getResourceUstring("notLoggedInMsg"); - } catch (std::invalid_argument &e) { - std::cerr << e.what() << std::endl; - } - - logInOutButton.reset(new Gtk::Button(*loginButtonLabel)); + logInOutButton.reset(new Gtk::Button()); logInOutSignalConnection = logInOutButton->signal_clicked().connect(sigc::mem_fun(*this, &MasterPanelUserInfoWidget::onLoginButtonClicked)); - userInfoLabel.reset(new Gtk::Label(*notLoggedInMsg)); + userInfoLabel.reset(new Gtk::Label()); + + changeLanguage(bundle); // set up the main window, and show everything attach(*logInOutButton, 0, 1, 0, 1); @@ -109,6 +102,9 @@ MasterPanelUserInfoWidget :: onLogoutButtonClicked (void) throw () { gLiveSupport->logout(); + loggedIn = false; + login.reset(); + Ptr::Ref notLoggedInMsg; Ptr::Ref loginButtonLabel; @@ -138,38 +134,77 @@ void MasterPanelUserInfoWidget :: onLoginButtonClicked (void) throw () { Ptr::Ref loginBundle; - Ptr::Ref logoutButtonLabel; try { loginBundle = getBundle("loginWindow"); - logoutButtonLabel = getResourceUstring("logoutButtonLabel"); } catch (std::invalid_argument &e) { std::cerr << e.what() << std::endl; return; } - Ptr::Ref loginWindow(new LoginWindow(loginBundle)); + Ptr::Ref loginWindow(new LoginWindow(gLiveSupport, + loginBundle)); Gtk::Main::run(*loginWindow); - Ptr::Ref login = loginWindow->getLogin(); Ptr::Ref password = loginWindow->getPassword(); - bool loggedIn = gLiveSupport->login(login->raw(), password->raw()); + login = loginWindow->getLogin(); + loggedIn = gLiveSupport->login(login->raw(), password->raw()); if (loggedIn) { - Ptr::Ref uLogin = ustringToUnicodeString(login); - Formattable arguments[] = { *uLogin }; - Ptr::Ref msg = formatMessageUstring("loggedInMsg", - arguments, 1); - - userInfoLabel->set_label(*msg); + updateStrings(); // change the login button to a logout button - logInOutButton->set_label(*logoutButtonLabel); logInOutSignalConnection.disconnect(); logInOutSignalConnection = logInOutButton->signal_clicked().connect(sigc::mem_fun(*this, &MasterPanelUserInfoWidget::onLogoutButtonClicked)); + + Ptr::Ref locale = loginWindow->getSelectedLocale(); + if (locale->size() > 0) { + gLiveSupport->changeLanguage(locale); + } else { + // TODO: get and set default locale for user + } } } + +/*------------------------------------------------------------------------------ + * Change the language of the panel + *----------------------------------------------------------------------------*/ +void +MasterPanelUserInfoWidget :: changeLanguage(Ptr::Ref bundle) + throw () +{ + setBundle(bundle); + updateStrings(); +} + + +/*------------------------------------------------------------------------------ + * Update the strings in the widget. + *----------------------------------------------------------------------------*/ +void +MasterPanelUserInfoWidget :: updateStrings(void) + throw (std::invalid_argument) +{ + Ptr::Ref loggedInMsg; + Ptr::Ref loginButtonLabel; + + if (!loggedIn) { + loginButtonLabel = getResourceUstring("loginButtonLabel"); + loggedInMsg = getResourceUstring("notLoggedInMsg"); + } else { + Ptr::Ref uLogin = ustringToUnicodeString(login); + Formattable arguments[] = { *uLogin }; + loggedInMsg = formatMessageUstring("loggedInMsg", arguments, 1); + + loginButtonLabel = getResourceUstring("logoutButtonLabel"); + } + + userInfoLabel->set_label(*loggedInMsg); + logInOutButton->set_label(*loginButtonLabel); +} + + diff --git a/livesupport/products/gLiveSupport/src/MasterPanelUserInfoWidget.h b/livesupport/products/gLiveSupport/src/MasterPanelUserInfoWidget.h index 51eeaead1..a6f49c2a6 100644 --- a/livesupport/products/gLiveSupport/src/MasterPanelUserInfoWidget.h +++ b/livesupport/products/gLiveSupport/src/MasterPanelUserInfoWidget.h @@ -22,7 +22,7 @@ Author : $Author: maroy $ - Version : $Revision: 1.1 $ + Version : $Revision: 1.2 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/gLiveSupport/src/MasterPanelUserInfoWidget.h,v $ ------------------------------------------------------------------------------*/ @@ -44,8 +44,8 @@ #include #include "LiveSupport/Core/Ptr.h" +#include "LiveSupport/Core/LocalizedObject.h" -#include "GtkLocalizedObject.h" #include "GLiveSupport.h" namespace LiveSupport { @@ -67,10 +67,10 @@ using namespace LiveSupport::Core; * This widget handles login and login info display. * * @author $Author: maroy $ - * @version $Revision: 1.1 $ + * @version $Revision: 1.2 $ */ class MasterPanelUserInfoWidget : public Gtk::Table, - public GtkLocalizedObject + public LocalizedObject { protected: /** @@ -95,6 +95,16 @@ class MasterPanelUserInfoWidget : public Gtk::Table, */ sigc::connection logInOutSignalConnection; + /** + * Flag to indicate if the user is logged in or not. + */ + bool loggedIn; + + /** + * The user id logged in as. + */ + Ptr::Ref login; + /** * Signal handler for the login button clicked. */ @@ -107,6 +117,15 @@ class MasterPanelUserInfoWidget : public Gtk::Table, virtual void onLogoutButtonClicked(void) throw (); + /** + * Update the strings in the widget, including the localized strings. + * + * @exception std::invalid_argument if some localized resources + * could not be attained. + */ + void + updateStrings(void) throw (std::invalid_argument); + public: /** @@ -126,6 +145,19 @@ class MasterPanelUserInfoWidget : public Gtk::Table, virtual ~MasterPanelUserInfoWidget(void) throw (); + /** + * Change the user interface language of the application + * by providing a new resource bundle. + * This call assumes that only the MasterPanel is visilbe, + * and will only change the language of the currently open + * MasterPanel. No other open windows will be affected by + * this call, but subsequently opened windows are. + * + * @param bundle the new resource bundle. + */ + void + changeLanguage(Ptr::Ref bundle) throw (); + }; /* ================================================= external data structures */ diff --git a/livesupport/products/gLiveSupport/src/MasterPanelWindow.cxx b/livesupport/products/gLiveSupport/src/MasterPanelWindow.cxx index 78afa3424..b58bbaa29 100644 --- a/livesupport/products/gLiveSupport/src/MasterPanelWindow.cxx +++ b/livesupport/products/gLiveSupport/src/MasterPanelWindow.cxx @@ -22,7 +22,7 @@ Author : $Author: maroy $ - Version : $Revision: 1.1 $ + Version : $Revision: 1.2 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/gLiveSupport/src/MasterPanelWindow.cxx,v $ ------------------------------------------------------------------------------*/ @@ -38,7 +38,6 @@ #include #include "LiveSupport/Core/TimeConversion.h" -#include "MasterPanelUserInfoWidget.h" #include "MasterPanelWindow.h" @@ -61,16 +60,10 @@ using namespace LiveSupport::GLiveSupport; MasterPanelWindow :: MasterPanelWindow (Ptr::Ref gLiveSupport, Ptr::Ref bundle) throw () - : GtkLocalizedObject(bundle) + : LocalizedObject(bundle) { this->gLiveSupport = gLiveSupport; - try { - set_title(*getResourceUstring("windowTitle")); - } catch (std::invalid_argument &e) { - std::cerr << e.what() << std::endl; - } - lsLogoWidget.reset(new Gtk::Label("lsLogo")); nowPlayingWidget.reset(new Gtk::Label("now playing")); vuMeterWidget.reset(new Gtk::Label("VU meter")); @@ -98,6 +91,9 @@ MasterPanelWindow :: MasterPanelWindow (Ptr::Ref gLiveSupport, add(*layout); + // set the localized resources + changeLanguage(bundle); + // show everything show_all(); @@ -115,6 +111,25 @@ MasterPanelWindow :: ~MasterPanelWindow (void) throw () } +/*------------------------------------------------------------------------------ + * Change the language of the panel + *----------------------------------------------------------------------------*/ +void +MasterPanelWindow :: changeLanguage(Ptr::Ref bundle) + throw () +{ + setBundle(bundle); + + try { + set_title(*getResourceUstring("windowTitle")); + } catch (std::invalid_argument &e) { + std::cerr << e.what() << std::endl; + } + + userInfoWidget->changeLanguage(bundle); +} + + /*------------------------------------------------------------------------------ * Set the timer *----------------------------------------------------------------------------*/ diff --git a/livesupport/products/gLiveSupport/src/MasterPanelWindow.h b/livesupport/products/gLiveSupport/src/MasterPanelWindow.h index cdb36557d..a3e2992dd 100644 --- a/livesupport/products/gLiveSupport/src/MasterPanelWindow.h +++ b/livesupport/products/gLiveSupport/src/MasterPanelWindow.h @@ -22,7 +22,7 @@ Author : $Author: maroy $ - Version : $Revision: 1.1 $ + Version : $Revision: 1.2 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/gLiveSupport/src/MasterPanelWindow.h,v $ ------------------------------------------------------------------------------*/ @@ -45,9 +45,10 @@ #include #include "LiveSupport/Core/Ptr.h" +#include "LiveSupport/Core/LocalizedObject.h" -#include "GtkLocalizedObject.h" #include "GLiveSupport.h" +#include "MasterPanelUserInfoWidget.h" namespace LiveSupport { namespace GLiveSupport { @@ -78,9 +79,9 @@ using namespace LiveSupport::Core; * * * @author $Author: maroy $ - * @version $Revision: 1.1 $ + * @version $Revision: 1.2 $ */ -class MasterPanelWindow : public Gtk::Window, public GtkLocalizedObject +class MasterPanelWindow : public Gtk::Window, public LocalizedObject { protected: /** @@ -127,7 +128,7 @@ class MasterPanelWindow : public Gtk::Window, public GtkLocalizedObject /** * The user info widget. */ - Ptr::Ref userInfoWidget; + Ptr::Ref userInfoWidget; /** * The radio logo. @@ -185,6 +186,19 @@ class MasterPanelWindow : public Gtk::Window, public GtkLocalizedObject virtual ~MasterPanelWindow(void) throw (); + /** + * Change the user interface language of the application + * by providing a new resource bundle. + * This call assumes that only the MasterPanel is visilbe, + * and will only change the language of the currently open + * MasterPanel. No other open windows will be affected by + * this call, but subsequently opened windows are. + * + * @param bundle the new resource bundle. + */ + void + changeLanguage(Ptr::Ref bundle) throw (); + }; /* ================================================= external data structures */ diff --git a/livesupport/products/gLiveSupport/src/PlaylistListWindow.cxx b/livesupport/products/gLiveSupport/src/PlaylistListWindow.cxx index 3ba10db55..88eb989f7 100644 --- a/livesupport/products/gLiveSupport/src/PlaylistListWindow.cxx +++ b/livesupport/products/gLiveSupport/src/PlaylistListWindow.cxx @@ -22,7 +22,7 @@ Author : $Author: maroy $ - Version : $Revision: 1.3 $ + Version : $Revision: 1.4 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/gLiveSupport/src/Attic/PlaylistListWindow.cxx,v $ ------------------------------------------------------------------------------*/ @@ -63,7 +63,7 @@ PlaylistListWindow :: PlaylistListWindow ( Ptr::Ref gLiveSupport, Ptr::Ref bundle) throw () - : GtkLocalizedObject(bundle) + : LocalizedObject(bundle) { this->gLiveSupport = gLiveSupport; diff --git a/livesupport/products/gLiveSupport/src/PlaylistListWindow.h b/livesupport/products/gLiveSupport/src/PlaylistListWindow.h index 4692a1708..f96c1748b 100644 --- a/livesupport/products/gLiveSupport/src/PlaylistListWindow.h +++ b/livesupport/products/gLiveSupport/src/PlaylistListWindow.h @@ -22,7 +22,7 @@ Author : $Author: maroy $ - Version : $Revision: 1.3 $ + Version : $Revision: 1.4 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/gLiveSupport/src/Attic/PlaylistListWindow.h,v $ ------------------------------------------------------------------------------*/ @@ -47,7 +47,7 @@ #include #include "LiveSupport/Core/Ptr.h" -#include "GtkLocalizedObject.h" +#include "LiveSupport/Core/LocalizedObject.h" #include "GLiveSupport.h" namespace LiveSupport { @@ -84,9 +84,9 @@ using namespace LiveSupport::Core; * * * @author $Author: maroy $ - * @version $Revision: 1.3 $ + * @version $Revision: 1.4 $ */ -class PlaylistListWindow : public Gtk::Window, public GtkLocalizedObject +class PlaylistListWindow : public Gtk::Window, public LocalizedObject { private: @@ -120,7 +120,7 @@ class PlaylistListWindow : public Gtk::Window, public GtkLocalizedObject * Lists one playlist per row. * * @author $Author: maroy $ - * @version $Revision: 1.3 $ + * @version $Revision: 1.4 $ */ class ModelColumns : public Gtk::TreeModel::ColumnRecord { diff --git a/livesupport/products/gLiveSupport/src/UiTestMainWindow.cxx b/livesupport/products/gLiveSupport/src/UiTestMainWindow.cxx index 2034b935a..80b0dbea3 100644 --- a/livesupport/products/gLiveSupport/src/UiTestMainWindow.cxx +++ b/livesupport/products/gLiveSupport/src/UiTestMainWindow.cxx @@ -22,7 +22,7 @@ Author : $Author: maroy $ - Version : $Revision: 1.8 $ + Version : $Revision: 1.9 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/gLiveSupport/src/Attic/UiTestMainWindow.cxx,v $ ------------------------------------------------------------------------------*/ @@ -64,7 +64,7 @@ using namespace LiveSupport::GLiveSupport; UiTestMainWindow :: UiTestMainWindow (Ptr::Ref gLiveSupport, Ptr::Ref bundle) throw () - : GtkLocalizedObject(bundle) + : LocalizedObject(bundle) { this->gLiveSupport = gLiveSupport; @@ -200,7 +200,8 @@ UiTestMainWindow :: onLoginButtonClicked (void) throw () return; } - Ptr::Ref loginWindow(new LoginWindow(loginBundle)); + Ptr::Ref loginWindow(new LoginWindow(gLiveSupport, + loginBundle)); Gtk::Main::run(*loginWindow); diff --git a/livesupport/products/gLiveSupport/src/UiTestMainWindow.h b/livesupport/products/gLiveSupport/src/UiTestMainWindow.h index ae2846c22..e7ae2504b 100644 --- a/livesupport/products/gLiveSupport/src/UiTestMainWindow.h +++ b/livesupport/products/gLiveSupport/src/UiTestMainWindow.h @@ -22,7 +22,7 @@ Author : $Author: maroy $ - Version : $Revision: 1.7 $ + Version : $Revision: 1.8 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/gLiveSupport/src/Attic/UiTestMainWindow.h,v $ ------------------------------------------------------------------------------*/ @@ -45,8 +45,8 @@ #include #include "LiveSupport/Core/Ptr.h" +#include "LiveSupport/Core/LocalizedObject.h" -#include "GtkLocalizedObject.h" #include "GLiveSupport.h" namespace LiveSupport { @@ -66,9 +66,9 @@ using namespace LiveSupport::Core; * A window, enabling interactive testing of UI components. * * @author $Author: maroy $ - * @version $Revision: 1.7 $ + * @version $Revision: 1.8 $ */ -class UiTestMainWindow : public Gtk::Window, public GtkLocalizedObject +class UiTestMainWindow : public Gtk::Window, public LocalizedObject { protected: /**