author | harlekin <harlekin> | 2003-02-12 11:40:53 (UTC) |
---|---|---|
committer | harlekin <harlekin> | 2003-02-12 11:40:53 (UTC) |
commit | d5ca5bf9f6fc8d47c2786af80342b13036f14d36 (patch) (side-by-side diff) | |
tree | 83b131e59306b2a387f893bc13491fbae6357702 | |
parent | d9f46624eff7817ea46a4cb2f9bd4e908308df45 (diff) | |
download | opie-d5ca5bf9f6fc8d47c2786af80342b13036f14d36.zip opie-d5ca5bf9f6fc8d47c2786af80342b13036f14d36.tar.gz opie-d5ca5bf9f6fc8d47c2786af80342b13036f14d36.tar.bz2 |
now plugins should be translatable too
-rw-r--r-- | core/pim/today/plugins/datebook/datebookevent.cpp | 4 | ||||
-rw-r--r-- | core/pim/today/today.cpp | 25 |
2 files changed, 24 insertions, 5 deletions
diff --git a/core/pim/today/plugins/datebook/datebookevent.cpp b/core/pim/today/plugins/datebook/datebookevent.cpp index 48f204e..3c1e97a 100644 --- a/core/pim/today/plugins/datebook/datebookevent.cpp +++ b/core/pim/today/plugins/datebook/datebookevent.cpp @@ -1,118 +1,118 @@ /* * datebookevent.cpp * * copyright : (c) 2002 by Maximilian Reiß * email : harlekin@handhelds.org * */ /*************************************************************************** * * * This program 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. * * * ***************************************************************************/ #include "datebookevent.h" #include <qpe/config.h> #include <qpe/timestring.h> #include <qpe/qcopenvelope_qws.h> #include <qpe/qpeapplication.h> #include <opie/odevice.h> using namespace Opie; DateBookEvent::DateBookEvent(const EffectiveEvent &ev, QWidget* parent, bool show_location, bool show_notes, int maxCharClip, const char* name, WFlags fl) : OClickableLabel(parent,name,fl), event(ev) { // setAlignment( AlignTop ); QString msg; Config config( "qpe" ); config.setGroup( "Time" ); // if 24 h format ampm = config.readBoolEntry( "AMPM", TRUE ); msg += "<B>" + (ev).description() + "</B>"; if ( (ev).event().hasAlarm() ) { - msg += " <b>[with alarm]</b>"; + msg += " <b>" + tr("[with alarm]") +"</b>"; } // include location or not if ( show_location ) { msg += "<BR><i>" + (ev).location() + "</i>"; } if ( ( TimeString::timeString( QTime( (ev).event().start().time() ) ) == "00:00" ) && ( TimeString::timeString( QTime( (ev).event().end().time() ) ) == "23:59" ) ) { msg += "<br>All day"; } else { // start time of event QDate tempDate = (ev).event().start().date(); msg += "<br>" + ampmTime( QTime( (ev).event().start().time() ) ) // end time of event + "<b> - </b>" + ampmTime( QTime( (ev).event().end().time() ) ) + differDate( tempDate ); } // include possible note or not if ( show_notes ) { - msg += "<br> <i>note</i>:" +( (ev).notes() ).mid( 0, maxCharClip ); + msg += "<br> <i>" + tr("note") + "</i>:" +( (ev).notes() ).mid( 0, maxCharClip ); } setText( msg ); connect( this, SIGNAL( clicked() ), this, SLOT( editMe() ) ); } DateBookEvent::~DateBookEvent() { } /** * AM/PM timestring conversion. * @param tm the timestring * @return formatted to am/pm is system is set to it */ QString DateBookEvent::ampmTime( QTime tm ) { QString s; if( ampm ) { int hour = tm.hour(); if ( hour == 0 ) { hour = 12; } if ( hour > 12 ) { hour -= 12; } s.sprintf( "%2d:%02d %s", hour, tm.minute(), (tm.hour() >= 12) ? "PM" : "AM" ); return s; } else { s.sprintf( "%2d:%02d", tm.hour(), tm.minute() ); return s; } } QString DateBookEvent::differDate( QDate date ) { QDate currentDate = QDate::currentDate(); QString returnText = "<font color = #407DD9><b> "; int differDate = currentDate.daysTo( date ); if ( currentDate.dayOfWeek() == date.dayOfWeek() ) { returnText += "" ; // not working right for recurring events //} else if ( differDate == 1 ) { //returnText += tr( "tomorrow" ); } else { //returnText += tr( "in %1 days" ).arg( differDate ); returnText += " [ " + date.dayName( date.dayOfWeek() ) + " ] "; } returnText += "</b></font>"; return returnText; } diff --git a/core/pim/today/today.cpp b/core/pim/today/today.cpp index 2f6907d..2497ee1 100644 --- a/core/pim/today/today.cpp +++ b/core/pim/today/today.cpp @@ -1,87 +1,90 @@ /* * today.cpp * * copyright : (c) 2002,2003 by Maximilian Reiß * email : harlekin@handhelds.org * */ /*************************************************************************** * * * This program 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. * * * ***************************************************************************/ + +#define QTOPIA_INTERNAL_LANGLIST + #include "today.h" #include <opie/todayconfigwidget.h> #include <qpe/config.h> #include <qpe/qcopenvelope_qws.h> #include <qpe/resource.h> #include <qpe/global.h> #include <qpe/qpeapplication.h> #include <qpe/contact.h> #include <qdir.h> #include <qfile.h> #include <qpushbutton.h> #include <qlabel.h> #include <qtimer.h> #include <qpixmap.h> #include <qlayout.h> #include <qhbox.h> #include <opie/otabwidget.h> #include <qdialog.h> #include <qwhatsthis.h> - +#include <qtranslator.h> struct TodayPlugin { TodayPlugin() : library( 0 ), iface( 0 ), guiPart( 0 ), guiBox( 0 ) {} QLibrary *library; QInterfacePtr<TodayPluginInterface> iface; TodayPluginObject *guiPart; QWidget *guiBox; QString name; bool active; bool excludeRefresh; int pos; }; static QValueList<TodayPlugin> pluginList; Today::Today( QWidget* parent, const char* name, WFlags fl ) : TodayBase( parent, name, fl ) { QObject::connect( (QObject*)ConfigButton, SIGNAL( clicked() ), this, SLOT( startConfig() ) ); QObject::connect( (QObject*)OwnerField, SIGNAL( clicked() ), this, SLOT( editCard() ) ); #if defined(Q_WS_QWS) #if !defined(QT_NO_COP) QCopChannel *todayChannel = new QCopChannel( "QPE/Today" , this ); connect ( todayChannel, SIGNAL( received( const QCString &, const QByteArray &) ), this, SLOT ( channelReceived( const QCString &, const QByteArray &) ) ); #endif #endif setOwnerField(); m_refreshTimer = new QTimer( this ); connect( m_refreshTimer, SIGNAL( timeout() ), this, SLOT( refresh() ) ); m_refreshTimer->start( 15000 ); //init(); loadPlugins(); showMaximized(); } /** * Qcop receive method. */ void Today::channelReceived( const QCString &msg, const QByteArray & data ) { QDataStream stream( data, IO_ReadOnly ); if ( msg == "message(QString)" ) { QString message; stream >> message; setOwnerField( message ); } @@ -116,125 +119,139 @@ void Today::setOwnerField() { /** * Set the owner field with a given QString, for example per qcop. */ void Today::setOwnerField( QString &message ) { if ( !message.isEmpty() ) { OwnerField->setText( "<b>" + message + "</b>" ); } } /** * Init stuff needed for today. Reads the config file. */ void Today::init() { // read config Config cfg( "today" ); cfg.setGroup( "Plugins" ); m_excludeApplets = cfg.readListEntry( "ExcludeApplets", ',' ); m_allApplets = cfg.readListEntry( "AllApplets", ',' ); cfg.setGroup( "General" ); m_iconSize = cfg.readNumEntry( "IconSize", 18 ); setRefreshTimer( cfg.readNumEntry( "checkinterval", 15000 ) ); // set the date in top label QDate date = QDate::currentDate(); QString time = ( tr( date.toString() ) ); DateLabel->setText( QString( "<font color=#FFFFFF>" + time + "</font>" ) ); if ( layout ) { delete layout; } layout = new QVBoxLayout( this ); layout->addWidget( Frame ); layout->addWidget( OwnerField ); } /** * Load the plugins */ void Today::loadPlugins() { init(); QValueList<TodayPlugin>::Iterator tit; if ( !pluginList.isEmpty() ) { for ( tit = pluginList.begin(); tit != pluginList.end(); ++tit ) { (*tit).guiBox->hide(); (*tit).guiBox->reparent( 0, QPoint( 0, 0 ) ); - (*tit).library->unload(); delete (*tit).guiBox; + (*tit).library->unload(); delete (*tit).library; } pluginList.clear(); } QString path = QPEApplication::qpeDir() + "/plugins/today"; QDir dir( path, "lib*.so" ); QStringList list = dir.entryList(); QStringList::Iterator it; QMap<QString, TodayPlugin> tempList; for ( it = list.begin(); it != list.end(); ++it ) { QInterfacePtr<TodayPluginInterface> iface; QLibrary *lib = new QLibrary( path + "/" + *it ); qDebug( "querying: %s", QString( path + "/" + *it ).latin1() ); if ( lib->queryInterface( IID_TodayPluginInterface, (QUnknownInterface**)&iface ) == QS_OK ) { qDebug( "accepted: %s", QString( path + "/" + *it ).latin1() ); qDebug( QString(*it) ); TodayPlugin plugin; plugin.library = lib; plugin.iface = iface; plugin.name = QString(*it); + QString type = (*it).left( (*it).find(".") ); + QStringList langs = Global::languageList(); + for (QStringList::ConstIterator lit = langs.begin(); lit!=langs.end(); ++lit) { + QString lang = *lit; + qDebug( "Languages: " + lang ); + QTranslator * trans = new QTranslator( qApp ); + QString tfn = QPEApplication::qpeDir()+"/i18n/" + lang + "/" + type + ".qm"; + if ( trans->load( tfn ) ) { + qApp->installTranslator( trans ); + } else { + delete trans; + } + } + // find out if plugins should be shown if ( m_excludeApplets.grep( *it ).isEmpty() ) { plugin.active = true; } else { plugin.active = false; } plugin.guiPart = plugin.iface->guiPart(); plugin.excludeRefresh = plugin.guiPart->excludeFromRefresh(); // package the whole thing into a qwidget so it can be shown and hidden plugin.guiBox = new QWidget( this ); QHBoxLayout *boxLayout = new QHBoxLayout( plugin.guiBox ); QPixmap plugPix; plugPix.convertFromImage( Resource::loadImage( plugin.guiPart->pixmapNameWidget() ).smoothScale( m_iconSize, m_iconSize ), 0 ); OClickableLabel* plugIcon = new OClickableLabel( plugin.guiBox ); plugIcon->setPixmap( plugPix ); QWhatsThis::add( plugIcon, tr("Click here to launch the associated app") ); plugIcon->setName( plugin.guiPart->appName() ); connect( plugIcon, SIGNAL( clicked() ), this, SLOT( startApplication() ) ); // a scrollview for each plugin QScrollView* sv = new QScrollView( plugin.guiBox ); QWidget *plugWidget = plugin.guiPart->widget( sv->viewport() ); // not sure if that is good .-) sv->setMinimumHeight( 12 ); sv->setResizePolicy( QScrollView::AutoOneFit ); sv->setHScrollBarMode( QScrollView::AlwaysOff ); sv->setFrameShape( QFrame::NoFrame ); sv->addChild( plugWidget ); // make sure the icon is on the top alligned boxLayout->addWidget( plugIcon, 0, AlignTop ); boxLayout->addWidget( sv, 0, AlignTop ); boxLayout->setStretchFactor( plugIcon, 1 ); boxLayout->setStretchFactor( sv, 9 ); // "prebuffer" it in one more list, to get the sorting done tempList.insert( plugin.name, plugin ); // on first start the list is off course empty if ( m_allApplets.isEmpty() ) { layout->addWidget( plugin.guiBox ); pluginList.append( plugin ); } // if plugin is not yet in the list, add it to the layout too else if ( !m_allApplets.contains( plugin.name ) ) { layout->addWidget( plugin.guiBox ); pluginList.append( plugin ); } @@ -258,116 +275,118 @@ void Today::loadPlugins() { } draw(); } /** * Repaint method. Reread all fields. */ void Today::draw() { if ( pluginList.count() == 0 ) { QLabel *noPlugins = new QLabel( this ); noPlugins->setText( tr( "No plugins found" ) ); layout->addWidget( noPlugins ); return; } uint count = 0; TodayPlugin plugin; for ( uint i = 0; i < pluginList.count(); i++ ) { plugin = pluginList[i]; if ( plugin.active ) { // qDebug( plugin.name + " is ACTIVE " ); plugin.guiBox->show(); } else { // qDebug( plugin.name + " is INACTIVE" ); plugin.guiBox->hide(); } count++; } if ( count == 0 ) { QLabel *noPluginsActive = new QLabel( this ); noPluginsActive->setText( tr( "No plugins activated" ) ); layout->addWidget( noPluginsActive ); } layout->addStretch(0); } /** * The method for the configuration dialog. */ void Today::startConfig() { // disconnect timer to prevent problems while being on config dialog disconnect( m_refreshTimer, SIGNAL( timeout() ), this, SLOT( refresh() ) ); + m_refreshTimer->stop( ); TodayConfig conf( this, "dialog", true ); TodayPlugin plugin; QList<TodayConfigWidget> configWidgetList; for ( int i = pluginList.count() - 1 ; i >= 0; i-- ) { plugin = pluginList[i]; // load the config widgets in the tabs if ( plugin.guiPart->configWidget( this ) != 0l ) { TodayConfigWidget* widget = plugin.guiPart->configWidget( conf.TabWidget3 ); configWidgetList.append( widget ); conf.TabWidget3->addTab( widget, plugin.guiPart->pixmapNameConfig() , plugin.guiPart->appName() ); } // set the order/activate tab conf.pluginManagement( plugin.name, plugin.guiPart->pluginName(), Resource::loadPixmap( plugin.guiPart->pixmapNameWidget() ) ); } if ( conf.exec() == QDialog::Accepted ) { conf.writeConfig(); TodayConfigWidget *confWidget; for ( confWidget = configWidgetList.first(); confWidget != 0; confWidget = configWidgetList.next() ) { confWidget->writeConfig(); } loadPlugins(); } else { // since refresh is not called in that case , reconnect the signal - connect( m_refreshTimer, SIGNAL( timeout() ), this, SLOT( refresh() ) ); + m_refreshTimer->start( 15000 ); // get the config value in here later + connect( m_refreshTimer, SIGNAL( timeout() ), this, SLOT( refresh() ) ); } } /** * Refresh for the view. Reload all applets * */ void Today::refresh() { init(); QValueList<TodayPlugin>::Iterator it; for ( it = pluginList.begin(); it != pluginList.end(); ++it ) { if ( !(*it).excludeRefresh ) { (*it).guiPart->refresh(); qDebug( "refresh" ); } } } void Today::startApplication() { QCopEnvelope e( "QPE/System", "execute(QString)" ); e << QString( sender()->name() ); } /** * launch addressbook (personal card) */ void Today::editCard() { QCopEnvelope env( "QPE/Application/addressbook", "editPersonalAndClose()" ); } Today::~Today() { } |