added the ability to select UI language when logging in

This commit is contained in:
maroy 2004-12-20 14:04:34 +00:00
parent e9f5b6b04c
commit 633b1f2bed
17 changed files with 359 additions and 353 deletions

View file

@ -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

View file

@ -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<GLiveSupport>::Ref gLiveSupport,
Ptr<ResourceBundle>::Ref bundle)
throw ()
: GtkLocalizedObject(bundle)
: LocalizedObject(bundle)
{
this->gLiveSupport = gLiveSupport;

View file

@ -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 <gtkmm.h>
#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
{

View file

@ -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 <stdexcept>
#include <gtkmm/main.h>
#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<std::string, Ptr<UnicodeString>::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<Glib::ustring>::Ref uName(new Glib::ustring(nameAttr->get_value()));
Ptr<UnicodeString>::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<MasterPanelWindow>::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<const std::string>::Ref locale)
throw ()
{
changeLocale(*locale);
if (masterPanel.get()) {
masterPanel->changeLanguage(getBundle());
}
}
/*------------------------------------------------------------------------------
* Authenticate the user
*----------------------------------------------------------------------------*/

View file

@ -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 <unicode/resbund.h>
#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<GLiveSupport>
{
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<const UnicodeString>::Ref, the names of the languages.
*/
typedef std::map<const std::string,
Ptr<const UnicodeString>::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<ResourceBundle>::Ref resourceBundle;
/**
* The authentication client used by the application.
*/
@ -129,10 +139,14 @@ class GLiveSupport : public Configurable,
Ptr<SessionId>::Ref sessionId;
/**
* The map of supported language.
* The map of supported languages.
*/
Ptr<std::map<std::string, Ptr<UnicodeString>::Ref> >::Ref
supportedLanguages;
Ptr<LanguageMap>::Ref supportedLanguages;
/**
* The master panel window.
*/
Ptr<MasterPanelWindow>::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<const std::string>::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<const LanguageMap>::Ref
getSupportedLanguages(void) const throw ()
{
return supportedLanguages;
}
};
/* ================================================= external data structures */

View file

@ -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<Glib::ustring>::Ref
GtkLocalizedObject :: unicodeStringToUstring(
Ptr<const UnicodeString>::Ref unicodeString)
throw ()
{
const UChar * uchars = unicodeString->getBuffer();
int32_t length = unicodeString->length();
Ptr<Glib::ustring>::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<UnicodeString>::Ref
GtkLocalizedObject :: ustringToUnicodeString(
Ptr<const Glib::ustring>::Ref gString)
throw ()
{
Ptr<UnicodeString>::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;
}

View file

@ -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 <glibmm/ustring.h>
#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<ResourceBundle>::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<Glib::ustring>::Ref
unicodeStringToUstring(Ptr<const UnicodeString>::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<UnicodeString>::Ref
ustringToUnicodeString(Ptr<const Glib::ustring>::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<Glib::ustring>::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<Glib::ustring>::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

View file

@ -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<ResourceBundle>::Ref bundle)
LoginWindow :: LoginWindow (Ptr<GLiveSupport>::Ref gLiveSupport,
Ptr<ResourceBundle>::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<ResourceBundle>::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<ResourceBundle>::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<const GLiveSupport::LanguageMap>::Ref languages;
languages = gLiveSupport->getSupportedLanguages();
GLiveSupport::LanguageMap::const_iterator lang = languages->begin();
GLiveSupport::LanguageMap::const_iterator end = languages->end();
Ptr<Glib::ustring>::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<const UnicodeString>::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<ResourceBundle>::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<Glib::ustring>::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);
}

View file

@ -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 <gtkmm/label.h>
#include <gtkmm/entry.h>
#include <gtkmm/table.h>
#include <gtkmm/combo.h>
#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<GLiveSupport>::Ref gLiveSupport;
/**
* The table, which provides the layout for the window.
*/
@ -101,6 +108,11 @@ class LoginWindow : public Gtk::Window, public GtkLocalizedObject
*/
Ptr<Gtk::Entry>::Ref passwordEntry;
/**
* The drop-down list to select the desired language.
*/
Ptr<Gtk::Combo>::Ref languageList;
/**
* The OK button.
*/
@ -116,21 +128,48 @@ class LoginWindow : public Gtk::Window, public GtkLocalizedObject
*/
Ptr<Glib::ustring>::Ref passwordText;
/**
* The locale / language selected by the user.
*/
Ptr<std::string>::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<Glib::ustring>::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<ResourceBundle>::Ref bundle) throw ();
LoginWindow(Ptr<GLiveSupport>::Ref gLiveSupport,
Ptr<ResourceBundle>::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<const std::string>::Ref
getSelectedLocale(void) const throw ()
{
return selectedLocale;
}
};
/* ================================================= external data structures */

View file

@ -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<GLiveSupport>::Ref gLiveSupport,
Ptr<ResourceBundle>::Ref bundle)
throw ()
: GtkLocalizedObject(bundle)
: LocalizedObject(bundle)
{
this->gLiveSupport = gLiveSupport;
loggedIn = false;
Ptr<Glib::ustring>::Ref loginButtonLabel;
Ptr<Glib::ustring>::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<Glib::ustring>::Ref notLoggedInMsg;
Ptr<Glib::ustring>::Ref loginButtonLabel;
@ -138,38 +134,77 @@ void
MasterPanelUserInfoWidget :: onLoginButtonClicked (void) throw ()
{
Ptr<ResourceBundle>::Ref loginBundle;
Ptr<Glib::ustring>::Ref logoutButtonLabel;
try {
loginBundle = getBundle("loginWindow");
logoutButtonLabel = getResourceUstring("logoutButtonLabel");
} catch (std::invalid_argument &e) {
std::cerr << e.what() << std::endl;
return;
}
Ptr<LoginWindow>::Ref loginWindow(new LoginWindow(loginBundle));
Ptr<LoginWindow>::Ref loginWindow(new LoginWindow(gLiveSupport,
loginBundle));
Gtk::Main::run(*loginWindow);
Ptr<const Glib::ustring>::Ref login = loginWindow->getLogin();
Ptr<const Glib::ustring>::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<UnicodeString>::Ref uLogin = ustringToUnicodeString(login);
Formattable arguments[] = { *uLogin };
Ptr<Glib::ustring>::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<const std::string>::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<ResourceBundle>::Ref bundle)
throw ()
{
setBundle(bundle);
updateStrings();
}
/*------------------------------------------------------------------------------
* Update the strings in the widget.
*----------------------------------------------------------------------------*/
void
MasterPanelUserInfoWidget :: updateStrings(void)
throw (std::invalid_argument)
{
Ptr<Glib::ustring>::Ref loggedInMsg;
Ptr<Glib::ustring>::Ref loginButtonLabel;
if (!loggedIn) {
loginButtonLabel = getResourceUstring("loginButtonLabel");
loggedInMsg = getResourceUstring("notLoggedInMsg");
} else {
Ptr<UnicodeString>::Ref uLogin = ustringToUnicodeString(login);
Formattable arguments[] = { *uLogin };
loggedInMsg = formatMessageUstring("loggedInMsg", arguments, 1);
loginButtonLabel = getResourceUstring("logoutButtonLabel");
}
userInfoLabel->set_label(*loggedInMsg);
logInOutButton->set_label(*loginButtonLabel);
}

View file

@ -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 <gtkmm/table.h>
#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<const Glib::ustring>::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<ResourceBundle>::Ref bundle) throw ();
};
/* ================================================= external data structures */

View file

@ -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 <gtkmm/label.h>
#include "LiveSupport/Core/TimeConversion.h"
#include "MasterPanelUserInfoWidget.h"
#include "MasterPanelWindow.h"
@ -61,16 +60,10 @@ using namespace LiveSupport::GLiveSupport;
MasterPanelWindow :: MasterPanelWindow (Ptr<GLiveSupport>::Ref gLiveSupport,
Ptr<ResourceBundle>::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<GLiveSupport>::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<ResourceBundle>::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
*----------------------------------------------------------------------------*/

View file

@ -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 <gtkmm/window.h>
#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;
* </code></pre>
*
* @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<Gtk::Widget>::Ref userInfoWidget;
Ptr<MasterPanelUserInfoWidget>::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<ResourceBundle>::Ref bundle) throw ();
};
/* ================================================= external data structures */

View file

@ -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<GLiveSupport>::Ref gLiveSupport,
Ptr<ResourceBundle>::Ref bundle)
throw ()
: GtkLocalizedObject(bundle)
: LocalizedObject(bundle)
{
this->gLiveSupport = gLiveSupport;

View file

@ -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 <gtkmm.h>
#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;
* </pre></code>
*
* @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
{

View file

@ -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<GLiveSupport>::Ref gLiveSupport,
Ptr<ResourceBundle>::Ref bundle)
throw ()
: GtkLocalizedObject(bundle)
: LocalizedObject(bundle)
{
this->gLiveSupport = gLiveSupport;
@ -200,7 +200,8 @@ UiTestMainWindow :: onLoginButtonClicked (void) throw ()
return;
}
Ptr<LoginWindow>::Ref loginWindow(new LoginWindow(loginBundle));
Ptr<LoginWindow>::Ref loginWindow(new LoginWindow(gLiveSupport,
loginBundle));
Gtk::Main::run(*loginWindow);

View file

@ -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 <gtkmm/window.h>
#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:
/**