a fix to issue #810

see http://bugs.campware.org/view.php?id=810
This commit is contained in:
maroy 2005-04-15 12:54:32 +00:00
parent a0d4eb8d8c
commit 47d6dc0ede
22 changed files with 1791 additions and 86 deletions

View file

@ -22,7 +22,7 @@
Author : $Author: maroy $ Author : $Author: maroy $
Version : $Revision: 1.5 $ Version : $Revision: 1.6 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/core/include/LiveSupport/Core/LocalizedObject.h,v $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/core/include/LiveSupport/Core/LocalizedObject.h,v $
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
@ -64,7 +64,7 @@ namespace Core {
* to make localized life easier. * to make localized life easier.
* *
* @author $Author: maroy $ * @author $Author: maroy $
* @version $Revision: 1.5 $ * @version $Revision: 1.6 $
*/ */
class LocalizedObject class LocalizedObject
{ {
@ -236,12 +236,99 @@ class LocalizedObject
* specified by patternKey * specified by patternKey
* @see http://oss.software.ibm.com/icu/apiref/classMessageFormat.html * @see http://oss.software.ibm.com/icu/apiref/classMessageFormat.html
*/ */
virtual Ptr<UnicodeString>::Ref virtual Ptr<Glib::ustring>::Ref
formatMessage(const char * patternKey, formatMessage(const char * patternKey,
Formattable * arguments, Formattable * arguments,
unsigned int nArguments) unsigned int nArguments)
throw (std::invalid_argument); throw (std::invalid_argument);
/**
* 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
* @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
formatMessage(const std::string & patternKey,
Formattable * arguments,
unsigned int nArguments)
throw (std::invalid_argument)
{
return formatMessage(patternKey.c_str(), arguments, nArguments);
}
/**
* A convenience function to format a message, based on a pattern
* loaded from a resource, with one argument.
* For more information, see the ICU MessageFormat class
* documentation.
*
* @param patternKey the key of the pattern to format
* @param argument1 the single argument to the message.
* @return the formatted string
* @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
formatMessage(const std::string & patternKey,
const Glib::ustring & argument1)
throw (std::invalid_argument);
/**
* A convenience function to format a message, based on a pattern
* loaded from a resource, with two arguments.
* For more information, see the ICU MessageFormat class
* documentation.
*
* @param patternKey the key of the pattern to format
* @param argument1 the first argument to the message.
* @param argument2 the second argument to the message.
* @return the formatted string
* @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
formatMessage(const std::string & patternKey,
const Glib::ustring & argument1,
const Glib::ustring & argument2)
throw (std::invalid_argument);
/**
* A convenience function to format a message, based on a pattern
* loaded from a resource, with three arguments.
* For more information, see the ICU MessageFormat class
* documentation.
*
* @param patternKey the key of the pattern to format
* @param argument1 the first argument to the message.
* @param argument2 the second argument to the message.
* @param argument3 the second argument to the message.
* @return the formatted string
* @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
formatMessage(const std::string & patternKey,
const Glib::ustring & argument1,
const Glib::ustring & argument2,
const Glib::ustring & argument3)
throw (std::invalid_argument);
/** /**
* Convert an ICU unicode string to a Glib ustring. * Convert an ICU unicode string to a Glib ustring.
* *
@ -262,6 +349,16 @@ class LocalizedObject
ustringToUnicodeString(Ptr<const Glib::ustring>::Ref gString) ustringToUnicodeString(Ptr<const Glib::ustring>::Ref gString)
throw (); 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(const Glib::ustring & gString)
throw ();
/** /**
* Get a string from the resource bundle, as a Glib ustring. * Get a string from the resource bundle, as a Glib ustring.
* *
@ -278,30 +375,20 @@ class LocalizedObject
} }
/** /**
* A convenience function to format a message, based on a pattern * Get a string from the resource bundle, as a Glib ustring.
* loaded from a resource.
* For more information, see the ICU MessageFormat class
* documentation.
* *
* @param patternKey the key of the pattern to format * @param key the key identifying the requested string.
* @param arguments the arguments to use in the formatting * @return the requested string
* @param nArguments the number of arguments supplied * @exception std::invalid_argument if there is no string for the
* @return the formatted string, in Glib ustring form * specified key.
* @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 Ptr<Glib::ustring>::Ref
formatMessageUstring(const char * patternKey, getResourceUstring(const std::string &key)
Formattable * arguments,
unsigned int nArguments)
throw (std::invalid_argument) throw (std::invalid_argument)
{ {
return unicodeStringToUstring(formatMessage(patternKey, return unicodeStringToUstring(getResourceString(key.c_str()));
arguments,
nArguments));
} }
}; };
/* ================================================= external data structures */ /* ================================================= external data structures */

View file

@ -22,7 +22,7 @@
Author : $Author: maroy $ Author : $Author: maroy $
Version : $Revision: 1.6 $ Version : $Revision: 1.7 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/core/src/LocalizedObject.cxx,v $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/core/src/LocalizedObject.cxx,v $
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
@ -171,13 +171,70 @@ LocalizedObject :: formatMessage(Ptr<const UnicodeString>::Ref pattern,
/*------------------------------------------------------------------------------ /*------------------------------------------------------------------------------
* Format a message, based on a resource key for its pattern * Format a message, based on a resource key for its pattern
*----------------------------------------------------------------------------*/ *----------------------------------------------------------------------------*/
Ptr<UnicodeString>::Ref Ptr<Glib::ustring>::Ref
LocalizedObject :: formatMessage(const char * patternKey, LocalizedObject :: formatMessage(const char * patternKey,
Formattable * arguments, Formattable * arguments,
unsigned int nArguments) unsigned int nArguments)
throw (std::invalid_argument) throw (std::invalid_argument)
{ {
return formatMessage(getResourceString(patternKey), arguments, nArguments); return unicodeStringToUstring(
formatMessage(getResourceString(patternKey), arguments, nArguments));
}
/*------------------------------------------------------------------------------
* Format a message, based on a resource key for its pattern
* and one argument for formatting.
*----------------------------------------------------------------------------*/
Ptr<Glib::ustring>::Ref
LocalizedObject :: formatMessage(const std::string & patternKey,
const Glib::ustring & argument1)
throw (std::invalid_argument)
{
Ptr<UnicodeString>::Ref uArgument1 = ustringToUnicodeString(argument1);
Formattable arguments[] = { *uArgument1 };
return formatMessage(patternKey, arguments, 1);
}
/*------------------------------------------------------------------------------
* Format a message, based on a resource key for its pattern
* and two arguments for formatting.
*----------------------------------------------------------------------------*/
Ptr<Glib::ustring>::Ref
LocalizedObject :: formatMessage(const std::string & patternKey,
const Glib::ustring & argument1,
const Glib::ustring & argument2)
throw (std::invalid_argument)
{
Ptr<UnicodeString>::Ref uArgument1 = ustringToUnicodeString(argument1);
Ptr<UnicodeString>::Ref uArgument2 = ustringToUnicodeString(argument2);
Formattable arguments[] = { *uArgument1,
*uArgument2 };
return formatMessage(patternKey, arguments, 2);
}
/*------------------------------------------------------------------------------
* Format a message, based on a resource key for its pattern
* and one argument for formatting.
*----------------------------------------------------------------------------*/
Ptr<Glib::ustring>::Ref
LocalizedObject :: formatMessage(const std::string & patternKey,
const Glib::ustring & argument1,
const Glib::ustring & argument2,
const Glib::ustring & argument3)
throw (std::invalid_argument)
{
Ptr<UnicodeString>::Ref uArgument1 = ustringToUnicodeString(argument1);
Ptr<UnicodeString>::Ref uArgument2 = ustringToUnicodeString(argument2);
Ptr<UnicodeString>::Ref uArgument3 = ustringToUnicodeString(argument3);
Formattable arguments[] = { *uArgument1,
*uArgument2,
*uArgument3 };
return formatMessage(patternKey, arguments, 3);
} }
@ -212,7 +269,7 @@ LocalizedObject :: ustringToUnicodeString(
{ {
Ptr<UnicodeString>::Ref uString(new UnicodeString()); Ptr<UnicodeString>::Ref uString(new UnicodeString());
Glib::ustring::const_iterator it = gString->begin(); Glib::ustring::const_iterator it = gString->begin();
Glib::ustring::const_iterator end = gString->end(); Glib::ustring::const_iterator end = gString->end();
while (it < end) { while (it < end) {
uString->append((UChar32) *it++); uString->append((UChar32) *it++);
@ -221,3 +278,22 @@ LocalizedObject :: ustringToUnicodeString(
return uString; return uString;
} }
/*------------------------------------------------------------------------------
* Create an ICU UnicodeString from a Glib ustring
*----------------------------------------------------------------------------*/
Ptr<UnicodeString>::Ref
LocalizedObject :: ustringToUnicodeString(const Glib::ustring & 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

@ -22,7 +22,7 @@
Author : $Author: maroy $ Author : $Author: maroy $
Version : $Revision: 1.5 $ Version : $Revision: 1.6 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/core/src/LocalizedObjectTest.cxx,v $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/core/src/LocalizedObjectTest.cxx,v $
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
@ -207,7 +207,7 @@ LocalizedObjectTest :: formatMessageTest(void)
CPPUNIT_ASSERT(U_SUCCESS(status)); CPPUNIT_ASSERT(U_SUCCESS(status));
try { try {
Ptr<UnicodeString>::Ref message; Ptr<Glib::ustring>::Ref message;
Ptr<LocalizedObject>::Ref locObj(new LocalizedObject(bundle)); Ptr<LocalizedObject>::Ref locObj(new LocalizedObject(bundle));
Ptr<LocalizedObject>::Ref messages(new LocalizedObject( Ptr<LocalizedObject>::Ref messages(new LocalizedObject(
locObj->getBundle("messages"))); locObj->getBundle("messages")));
@ -215,14 +215,22 @@ LocalizedObjectTest :: formatMessageTest(void)
// test formatting through a key // test formatting through a key
message = messages->formatMessage("aMessage", arguments, 2); message = messages->formatMessage("aMessage", arguments, 2);
CPPUNIT_ASSERT( CPPUNIT_ASSERT(*message == "parameter 0: p1, parameter 1: p2");
message->compare("parameter 0: p1, parameter 1: p2" == 0));
// test formatting through an explicit pattern // test formatting through an explicit pattern
Ptr<UnicodeString>::Ref uMessage;
Ptr<UnicodeString>::Ref pattern(new UnicodeString( Ptr<UnicodeString>::Ref pattern(new UnicodeString(
"only 1 parameter: {0}")); "only 1 parameter: {0}"));
message = LocalizedObject::formatMessage(pattern, arguments, 1); uMessage = LocalizedObject::formatMessage(pattern, arguments, 1);
CPPUNIT_ASSERT(message->compare("only 1 parameter: p1") == 0); CPPUNIT_ASSERT(uMessage->compare("only 1 parameter: p1") == 0);
// test formatting through a key, and a fixed number of parameters
message = messages->formatMessage("aMessage3Args", "p0");
CPPUNIT_ASSERT(*message == "p0: p0, p2: {2}, p1: {1}");
message = messages->formatMessage("aMessage3Args", "p0", "p1");
CPPUNIT_ASSERT(*message == "p0: p0, p2: {2}, p1: p1");
message = messages->formatMessage("aMessage3Args", "p0", "p1", "p2");
CPPUNIT_ASSERT(*message == "p0: p0, p2: p2, p1: p1");
} catch (std::invalid_argument &e) { } catch (std::invalid_argument &e) {
CPPUNIT_FAIL(e.what()); CPPUNIT_FAIL(e.what());
@ -299,7 +307,7 @@ LocalizedObjectTest :: ustringTest(void)
Formattable arguments[] = { "p1", "p2" }; Formattable arguments[] = { "p1", "p2" };
// test formatting through a key // test formatting through a key
message = messages->formatMessageUstring("aMessage", arguments, 2); message = messages->formatMessage("aMessage", arguments, 2);
CPPUNIT_ASSERT(*message == "parameter 0: p1, parameter 1: p2"); CPPUNIT_ASSERT(*message == "parameter 0: p1, parameter 1: p2");
} catch (std::invalid_argument &e) { } catch (std::invalid_argument &e) {

View file

@ -8,7 +8,8 @@ root:table
messages:table messages:table
{ {
aMessage:string { "parameter 0: {0}, parameter 1: {1}" } aMessage:string { "parameter 0: {0}, parameter 1: {1}" }
aMessage3Args:string { "p0: {0}, p2: {2}, p1: {1}" }
} }
} }

View file

@ -20,8 +20,8 @@
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
# #
# #
# Author : $Author: fgerlits $ # Author : $Author: maroy $
# Version : $Revision: 1.12 $ # Version : $Revision: 1.13 $
# Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/widgets/etc/Makefile.in,v $ # Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/widgets/etc/Makefile.in,v $
# #
# @configure_input@ # @configure_input@
@ -119,7 +119,8 @@ WIDGETS_LIB_OBJS = ${TMP_DIR}/ImageButton.o \
${TMP_DIR}/WidgetFactory.o \ ${TMP_DIR}/WidgetFactory.o \
${TMP_DIR}/ZebraTreeView.o \ ${TMP_DIR}/ZebraTreeView.o \
${TMP_DIR}/ZebraCellRenderer.o \ ${TMP_DIR}/ZebraCellRenderer.o \
${TMP_DIR}/Colors.o ${TMP_DIR}/Colors.o \
${TMP_DIR}/MessageWindow.o
TEST_EXE_OBJS = ${TMP_DIR}/TestWindow.o \ TEST_EXE_OBJS = ${TMP_DIR}/TestWindow.o \
${TMP_DIR}/main.o ${TMP_DIR}/main.o

File diff suppressed because it is too large Load diff

View file

@ -21,8 +21,8 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Author : $Author: fgerlits $ Author : $Author: maroy $
Version : $Revision: 1.10 $ Version : $Revision: 1.11 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/widgets/include/LiveSupport/Widgets/WhiteWindow.h,v $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/widgets/include/LiveSupport/Widgets/WhiteWindow.h,v $
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
@ -69,10 +69,33 @@ using namespace LiveSupport::Core;
/* =============================================================== data types */ /* =============================================================== data types */
/** /**
* A container holding exactly one child, habing a light blue border to it. * A container holding exactly one child, having a light blue border to it.
* *
* @author $Author: fgerlits $ * To create a white window, subclass your window class from WhiteWindow,
* @version $Revision: 1.10 $ * and supply appropriate parameters to the WhiteWindow constructor,
* upon construction.
*
* For example:
* <code><pre>
* class MyWindow : public WhiteWindow
* {
* MyWindow(void);
* ...
* };
*
* MyWindow::MyWindow(void)
* : WhiteWindow("window title",
* Colors::White,
* WidgetFactory::getInstance()->getWhiteWindowCorners())
* {
* ...
* }
* </code></pre>
*
* @author $Author: maroy $
* @version $Revision: 1.11 $
* @see WidgetFactory
* @see WidgetFactory#getWhiteWindowCorners
*/ */
class WhiteWindow : public Gtk::Window class WhiteWindow : public Gtk::Window
{ {

View file

@ -21,8 +21,8 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Author : $Author: fgerlits $ Author : $Author: maroy $
Version : $Revision: 1.13 $ Version : $Revision: 1.14 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/widgets/include/LiveSupport/Widgets/WidgetFactory.h,v $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/widgets/include/LiveSupport/Widgets/WidgetFactory.h,v $
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
@ -68,6 +68,8 @@ using namespace LiveSupport::Core;
/* =============================================================== data types */ /* =============================================================== data types */
class WhiteWindow;
/** /**
* A factory to provide access to LiveSupport Widgets. * A factory to provide access to LiveSupport Widgets.
* *
@ -86,8 +88,8 @@ using namespace LiveSupport::Core;
* <!ATTLIST widgetFactory path CDATA #REQUIRED > * <!ATTLIST widgetFactory path CDATA #REQUIRED >
* </code></pre> * </code></pre>
* *
* @author $Author: fgerlits $ * @author $Author: maroy $
* @version $Revision: 1.13 $ * @version $Revision: 1.14 $
*/ */
class WidgetFactory : class WidgetFactory :
virtual public Configurable virtual public Configurable
@ -334,6 +336,17 @@ class WidgetFactory :
ZebraTreeView * ZebraTreeView *
createTreeView(Glib::RefPtr<Gtk::TreeModel> treeModel) createTreeView(Glib::RefPtr<Gtk::TreeModel> treeModel)
throw (); throw ();
/**
* Create a window with a single line of text, and an OK button.
* Good for displaying error messages.
* It is the reponsibility of the caller to dispose of the created
* object properly.
*
* @param message the message to include in the window.
*/
WhiteWindow *
createMessageWindow(Ptr<Glib::ustring>::Ref message) throw ();
}; };

View file

@ -0,0 +1,99 @@
/*------------------------------------------------------------------------------
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.1 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/widgets/src/MessageWindow.cxx,v $
------------------------------------------------------------------------------*/
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#include "LiveSupport/Widgets/WidgetFactory.h"
#include "LiveSupport/Widgets/Colors.h"
#include "MessageWindow.h"
using namespace LiveSupport::Widgets;
/* =================================================== local data structures */
/* ================================================ local constants & macros */
/* =============================================== local function prototypes */
/* ============================================================= module code */
/*------------------------------------------------------------------------------
* Constructor.
*----------------------------------------------------------------------------*/
MessageWindow :: MessageWindow (Ptr<Glib::ustring>::Ref message)
throw ()
: WhiteWindow(*message,
Colors::White,
WidgetFactory::getInstance()->getWhiteWindowCorners())
{
Ptr<WidgetFactory>::Ref widgetFactory = WidgetFactory::getInstance();
messageLabel = Gtk::manage(new Gtk::Label(*message));
// init the okButton
// TODO: localize the OK text on the button
okButton = Gtk::manage(widgetFactory->createButton("OK"));
okButton->signal_clicked().connect(sigc::mem_fun(*this,
&MessageWindow::onOkButtonClicked));
layout = Gtk::manage(new Gtk::VBox());
layout->pack_start(*messageLabel, true, true);
layout->pack_start(*okButton);
add(*layout);
show_all();
}
/*------------------------------------------------------------------------------
* Destructor.
*----------------------------------------------------------------------------*/
MessageWindow :: ~MessageWindow (void) throw ()
{
}
/*------------------------------------------------------------------------------
* Event handler for the OK button clicked
*----------------------------------------------------------------------------*/
void
MessageWindow :: onOkButtonClicked(void) throw ()
{
hide();
}

View file

@ -0,0 +1,121 @@
/*------------------------------------------------------------------------------
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.1 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/widgets/src/MessageWindow.h,v $
------------------------------------------------------------------------------*/
#ifndef MessageWindow_h
#define MessageWindow_h
#ifndef __cplusplus
#error This is a C++ include file
#endif
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#include <gtkmm/box.h>
#include <gtkmm/label.h>
#include "LiveSupport/Core/Ptr.h"
#include "LiveSupport/Widgets/WhiteWindow.h"
namespace LiveSupport {
namespace Widgets {
using namespace LiveSupport::Core;
/* ================================================================ constants */
/* =================================================================== macros */
/* =============================================================== data types */
/**
* A message window, displaying a single line of message, with an OK
* button.
*
* @author $Author: maroy $
* @version $Revision: 1.1 $
*/
class MessageWindow : public WhiteWindow
{
protected:
/**
* The vertical box holding the message and the button.
*/
Gtk::Box * layout;
/**
* The message.
*/
Gtk::Label * messageLabel;
/**
* The OK button.
*/
Button * okButton;
/**
* The event handler for the OK button clicked.
*/
virtual void
onOkButtonClicked(void) throw ();
public:
/**
* Constructor.
*
* @param message the message to display in the window
*/
MessageWindow(Ptr<Glib::ustring>::Ref message) throw ();
/**
* Virtual destructor.
*/
virtual
~MessageWindow(void) throw ();
};
/* ================================================= external data structures */
/* ====================================================== function prototypes */
} // namespace Widgets
} // namespace LiveSupport
#endif // MessageWindow_h

View file

@ -21,8 +21,8 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Author : $Author: fgerlits $ Author : $Author: maroy $
Version : $Revision: 1.15 $ Version : $Revision: 1.16 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/widgets/src/TestWindow.cxx,v $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/widgets/src/TestWindow.cxx,v $
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
@ -33,7 +33,7 @@
#include "configure.h" #include "configure.h"
#endif #endif
#include <iostream> #include <gtkmm/main.h>
#include "LiveSupport/Widgets/WidgetFactory.h" #include "LiveSupport/Widgets/WidgetFactory.h"
#include "LiveSupport/Widgets/Colors.h" #include "LiveSupport/Widgets/Colors.h"
@ -78,6 +78,8 @@ TestWindow :: TestWindow (void)
// create a button // create a button
button = Gtk::manage(widgetFactory->createButton("Hello, World!")); button = Gtk::manage(widgetFactory->createButton("Hello, World!"));
button->signal_clicked().connect(sigc::mem_fun(*this,
&TestWindow::onButtonClicked));
// create a combo box // create a combo box
comboBoxText = Gtk::manage(widgetFactory->createComboBoxText()); comboBoxText = Gtk::manage(widgetFactory->createComboBoxText());
@ -119,6 +121,21 @@ TestWindow :: ~TestWindow (void) throw ()
} }
/*------------------------------------------------------------------------------
* Event handler for the button being clicked.
*----------------------------------------------------------------------------*/
void
TestWindow :: onButtonClicked(void) throw ()
{
Ptr<WidgetFactory>::Ref wf = WidgetFactory::getInstance();
Ptr<Glib::ustring>::Ref message(new Glib::ustring("Hello, World!"));
WhiteWindow * helloWindow = wf->createMessageWindow(message);
Gtk::Main::run(*helloWindow);
delete helloWindow;
}
/*------------------------------------------------------------------------------ /*------------------------------------------------------------------------------
* Change the image from "play" to "stop" on the button when pressed. * Change the image from "play" to "stop" on the button when pressed.
*----------------------------------------------------------------------------*/ *----------------------------------------------------------------------------*/

View file

@ -21,8 +21,8 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Author : $Author: fgerlits $ Author : $Author: maroy $
Version : $Revision: 1.9 $ Version : $Revision: 1.10 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/widgets/src/TestWindow.h,v $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/widgets/src/TestWindow.h,v $
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
@ -71,8 +71,8 @@ using namespace LiveSupport::Core;
/** /**
* A window, enabling interactive testing of UI components. * A window, enabling interactive testing of UI components.
* *
* @author $Author: fgerlits $ * @author $Author: maroy $
* @version $Revision: 1.9 $ * @version $Revision: 1.10 $
*/ */
class TestWindow : public WhiteWindow class TestWindow : public WhiteWindow
{ {
@ -140,6 +140,12 @@ class TestWindow : public WhiteWindow
*/ */
BlueBin * blueBin; BlueBin * blueBin;
/**
* Event handler for the button being clicked.
*/
virtual void
onButtonClicked(void) throw ();
public: public:
/** /**

View file

@ -22,7 +22,7 @@
Author : $Author: maroy $ Author : $Author: maroy $
Version : $Revision: 1.12 $ Version : $Revision: 1.13 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/widgets/src/WhiteWindow.cxx,v $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/widgets/src/WhiteWindow.cxx,v $
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
@ -352,7 +352,7 @@ WhiteWindow :: set_title(const Glib::ustring & title) throw ()
Glib::ustring Glib::ustring
WhiteWindow :: get_title(void) const throw () WhiteWindow :: get_title(void) const throw ()
{ {
titleLabel->get_label(); return titleLabel->get_label();
} }

View file

@ -21,8 +21,8 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Author : $Author: fgerlits $ Author : $Author: maroy $
Version : $Revision: 1.15 $ Version : $Revision: 1.16 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/widgets/src/WidgetFactory.cxx,v $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/widgets/src/WidgetFactory.cxx,v $
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
@ -36,8 +36,9 @@
#include <gtkmm/entry.h> #include <gtkmm/entry.h>
#include "LiveSupport/Widgets/Colors.h" #include "LiveSupport/Widgets/Colors.h"
#include "LiveSupport/Widgets/WidgetFactory.h" #include "LiveSupport/Widgets/WidgetFactory.h"
#include "MessageWindow.h"
using namespace LiveSupport::Core; using namespace LiveSupport::Core;
using namespace LiveSupport::Widgets; using namespace LiveSupport::Widgets;
@ -425,3 +426,14 @@ WidgetFactory :: createTreeView(Glib::RefPtr<Gtk::TreeModel> treeModel)
return new ZebraTreeView(treeModel); return new ZebraTreeView(treeModel);
} }
/*------------------------------------------------------------------------------
* Create a message window.
*----------------------------------------------------------------------------*/
WhiteWindow *
WidgetFactory :: createMessageWindow(Ptr<Glib::ustring>::Ref message)
throw ()
{
return new MessageWindow(message);
}

View file

@ -22,7 +22,7 @@
Author : $Author: maroy $ Author : $Author: maroy $
Version : $Revision: 1.27 $ Version : $Revision: 1.28 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/gLiveSupport/src/GLiveSupport.cxx,v $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/gLiveSupport/src/GLiveSupport.cxx,v $
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
@ -54,6 +54,7 @@ using namespace LiveSupport::Core;
using namespace LiveSupport::Authentication; using namespace LiveSupport::Authentication;
using namespace LiveSupport::Storage; using namespace LiveSupport::Storage;
using namespace LiveSupport::SchedulerClient; using namespace LiveSupport::SchedulerClient;
using namespace LiveSupport::Widgets;
using namespace LiveSupport::GLiveSupport; using namespace LiveSupport::GLiveSupport;
@ -93,6 +94,15 @@ static const std::string nameAttrName = "name";
*----------------------------------------------------------------------------*/ *----------------------------------------------------------------------------*/
static const std::string scratchpadContentsKey = "scratchpadContents"; static const std::string scratchpadContentsKey = "scratchpadContents";
/*------------------------------------------------------------------------------
* Static constant for the key of the scheduler not available key
*----------------------------------------------------------------------------*/
static const std::string schedulerNotReachableKey = "schedulerNotReachableMsg";
/*------------------------------------------------------------------------------
* Static constant for the key of the locale not available key
*----------------------------------------------------------------------------*/
static const std::string localeNotAvailableKey = "localeNotAvailableMsg";
/* =============================================== local function prototypes */ /* =============================================== local function prototypes */
@ -221,6 +231,67 @@ GLiveSupport :: configSupportedLanguages(const xmlpp::Element & element)
} }
/*------------------------------------------------------------------------------
* Check all configured resources
*----------------------------------------------------------------------------*/
bool
LiveSupport :: GLiveSupport ::
GLiveSupport :: checkConfiguration(void) throw ()
{
// first, check if resources are available for all configured languages
LanguageMap::iterator it = supportedLanguages->begin();
try {
LanguageMap::iterator end = supportedLanguages->end();
while (it != end) {
changeLocale((*it).second);
++it;
}
changeLocale("");
} catch (std::invalid_argument &e) {
Ptr<Glib::ustring>::Ref language(new Glib::ustring((*it).first));
Ptr<UnicodeString>::Ref uLanguage = ustringToUnicodeString(language);
Ptr<Glib::ustring>::Ref msg = formatMessage(localeNotAvailableKey,
(*it).first);
displayMessageWindow(msg);
changeLocale("");
return false;
}
// TODO: check if the authentication server is available
// TODO: check if the storage server is available
// no need to check the widget factory
// check the scheduler client
try {
scheduler->getVersion();
} catch (XmlRpcException &e) {
displayMessageWindow(getResourceUstring(schedulerNotReachableKey));
return false;
}
// TODO: check the audio player?
return true;
}
/*------------------------------------------------------------------------------
* Display a message window.
*----------------------------------------------------------------------------*/
void
LiveSupport :: GLiveSupport ::
GLiveSupport :: displayMessageWindow(Ptr<Glib::ustring>::Ref message)
throw ()
{
WhiteWindow * window = widgetFactory->createMessageWindow(message);
Gtk::Main::run(*window);
delete window;
}
/*------------------------------------------------------------------------------ /*------------------------------------------------------------------------------
* Show the main window. * Show the main window.
*----------------------------------------------------------------------------*/ *----------------------------------------------------------------------------*/
@ -243,7 +314,7 @@ GLiveSupport :: show(void) throw ()
void void
LiveSupport :: GLiveSupport :: LiveSupport :: GLiveSupport ::
GLiveSupport :: changeLanguage(Ptr<const std::string>::Ref locale) GLiveSupport :: changeLanguage(Ptr<const std::string>::Ref locale)
throw () throw (std::invalid_argument)
{ {
changeLocale(*locale); changeLocale(*locale);

View file

@ -21,8 +21,8 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Author : $Author: fgerlits $ Author : $Author: maroy $
Version : $Revision: 1.24 $ Version : $Revision: 1.25 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/gLiveSupport/src/GLiveSupport.h,v $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/gLiveSupport/src/GLiveSupport.h,v $
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
@ -99,8 +99,8 @@ class MasterPanelWindow;
* <code>schedulerClientFactory</code> elements see their * <code>schedulerClientFactory</code> elements see their
* respective documentation. * respective documentation.
* *
* @author $Author: fgerlits $ * @author $Author: maroy $
* @version $Revision: 1.24 $ * @version $Revision: 1.25 $
* @see LocalizedObject#getBundle(const xmlpp::Element &) * @see LocalizedObject#getBundle(const xmlpp::Element &)
* @see AuthenticationClientFactory * @see AuthenticationClientFactory
* @see StorageClientFactory * @see StorageClientFactory
@ -265,6 +265,25 @@ class GLiveSupport : public LocalizedConfigurable,
throw (std::invalid_argument, throw (std::invalid_argument,
std::logic_error); std::logic_error);
/**
* A function to check the configuration of this object.
* Checks all resources configured by configure()
*
* @retun true if all resources are accessible and working,
* false otherwise
*/
bool
checkConfiguration(void) throw ();
/**
* Display a message window.
* This function only returns after the message window is closed.
*
* @param message the message to display
*/
void
displayMessageWindow(Ptr<Glib::ustring>::Ref message) throw ();
/** /**
* Show the main window, and run the application. * Show the main window, and run the application.
* This call will only return after the main window has been closed. * This call will only return after the main window has been closed.
@ -276,9 +295,12 @@ class GLiveSupport : public LocalizedConfigurable,
* Change the language of the application. * Change the language of the application.
* *
* @param locale the new locale of the appliction. * @param locale the new locale of the appliction.
* @exception std::invalid_argument if the specified locale is not
* available
*/ */
void void
changeLanguage(Ptr<const std::string>::Ref locale) throw (); changeLanguage(Ptr<const std::string>::Ref locale)
throw (std::invalid_argument);
/** /**
* Perform authentication for the user of the application. * Perform authentication for the user of the application.

View file

@ -22,7 +22,7 @@
Author : $Author: maroy $ Author : $Author: maroy $
Version : $Revision: 1.7 $ Version : $Revision: 1.8 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/gLiveSupport/src/MasterPanelUserInfoWidget.cxx,v $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/gLiveSupport/src/MasterPanelUserInfoWidget.cxx,v $
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
@ -227,10 +227,7 @@ MasterPanelUserInfoWidget :: updateStrings(void)
loginButtonLabel = getResourceUstring("loginButtonLabel"); loginButtonLabel = getResourceUstring("loginButtonLabel");
loggedInMsg = getResourceUstring("notLoggedInMsg"); loggedInMsg = getResourceUstring("notLoggedInMsg");
} else { } else {
Ptr<UnicodeString>::Ref uLogin = ustringToUnicodeString(login); loggedInMsg = formatMessage("loggedInMsg", *login);
Formattable arguments[] = { *uLogin };
loggedInMsg = formatMessageUstring("loggedInMsg", arguments, 1);
loginButtonLabel = getResourceUstring("logoutButtonLabel"); loginButtonLabel = getResourceUstring("logoutButtonLabel");
} }

View file

@ -22,7 +22,7 @@
Author : $Author: maroy $ Author : $Author: maroy $
Version : $Revision: 1.7 $ Version : $Revision: 1.8 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/gLiveSupport/src/SimplePlaylistManagementWindow.cxx,v $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/gLiveSupport/src/SimplePlaylistManagementWindow.cxx,v $
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
@ -155,13 +155,9 @@ SimplePlaylistManagementWindow :: onSaveButtonClicked (void) throw ()
playlist = gLiveSupport->savePlaylist(); playlist = gLiveSupport->savePlaylist();
Ptr<UnicodeString>::Ref uTitle = ustringToUnicodeString( Ptr<Glib::ustring>::Ref statusText = formatMessage(
playlist->getTitle());
Formattable arguments[] = { *uTitle };
Ptr<Glib::ustring>::Ref statusText = formatMessageUstring(
"playlistSavedMessage", "playlistSavedMessage",
arguments, *playlist->getTitle());
1);
statusBar->set_text(*statusText); statusBar->set_text(*statusText);
gLiveSupport->releaseEditedPlaylist(); gLiveSupport->releaseEditedPlaylist();

View file

@ -21,8 +21,8 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Author : $Author: fgerlits $ Author : $Author: maroy $
Version : $Revision: 1.6 $ Version : $Revision: 1.7 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/gLiveSupport/src/UploadFileWindow.cxx,v $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/gLiveSupport/src/UploadFileWindow.cxx,v $
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
@ -293,13 +293,9 @@ UploadFileWindow :: onUploadButtonClicked(void) throw ()
gLiveSupport->uploadFile(audioClip); gLiveSupport->uploadFile(audioClip);
// display success in the status bar // display success in the status bar
Ptr<UnicodeString>::Ref uTitle = ustringToUnicodeString( Ptr<Glib::ustring>::Ref statusText = formatMessage(
audioClip->getTitle());
Formattable arguments[] = { *uTitle };
Ptr<Glib::ustring>::Ref statusText = formatMessageUstring(
"clipUploadedMessage", "clipUploadedMessage",
arguments, *audioClip->getTitle());
1);
statusBar->set_text(*statusText); statusBar->set_text(*statusText);
// clean the entry fields // clean the entry fields

View file

@ -22,7 +22,7 @@
Author : $Author: maroy $ Author : $Author: maroy $
Version : $Revision: 1.6 $ Version : $Revision: 1.7 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/gLiveSupport/src/main.cxx,v $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/gLiveSupport/src/main.cxx,v $
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
@ -167,6 +167,15 @@ int main ( int argc,
std::cerr << "error parsing configuration file" << std::endl std::cerr << "error parsing configuration file" << std::endl
<< e.what() << std::endl; << e.what() << std::endl;
return 1; return 1;
} catch (std::logic_error &e) {
std::cerr << "error configuring..." << std::endl
<< e.what() << std::endl;
return 1;
}
if (!gLiveSupport->checkConfiguration()) {
std::cerr << "some problem with the configuration" << std::endl;
return 1;
} }
gLiveSupport->show(); gLiveSupport->show();

View file

@ -10,6 +10,9 @@ hu:table
simplePlaylistMgmtButtonLabel:string { "egyszerű playlist kezelés" } simplePlaylistMgmtButtonLabel:string { "egyszerű playlist kezelés" }
schedulerButtonLabel:string { "időzítő" } schedulerButtonLabel:string { "időzítő" }
localeNotAvailableMsg:string { "A {0} nyelv nem elérhető" }
schedulerNotReachableMsg:string { "Az időzitő szerver nem elérhető" }
loginWindow:table loginWindow:table
{ {
windowTitle:string { "Belépés" } windowTitle:string { "Belépés" }

View file

@ -10,6 +10,9 @@ root:table
simplePlaylistMgmtButtonLabel:string { "simple playlist management" } simplePlaylistMgmtButtonLabel:string { "simple playlist management" }
schedulerButtonLabel:string { "scheduler" } schedulerButtonLabel:string { "scheduler" }
localeNotAvailableMsg:string { "Locale {0} not available" }
schedulerNotReachableMsg:string { "Scheduler server not available" }
loginWindow:table loginWindow:table
{ {
windowTitle:string { "LOGIN" } windowTitle:string { "LOGIN" }