diff options
author | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
---|---|---|
committer | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
commit | 460c52653ab0dcca6f19a4f492ed2c5e4e963ab0 (patch) | |
tree | 67208f7c145782a7e90b123b982ca78d88cc2c87 /libkdepim/broadcaststatus.cpp | |
download | tdepim-460c52653ab0dcca6f19a4f492ed2c5e4e963ab0.tar.gz tdepim-460c52653ab0dcca6f19a4f492ed2c5e4e963ab0.zip |
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdepim@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'libkdepim/broadcaststatus.cpp')
-rw-r--r-- | libkdepim/broadcaststatus.cpp | 165 |
1 files changed, 165 insertions, 0 deletions
diff --git a/libkdepim/broadcaststatus.cpp b/libkdepim/broadcaststatus.cpp new file mode 100644 index 000000000..5d0af0d13 --- /dev/null +++ b/libkdepim/broadcaststatus.cpp @@ -0,0 +1,165 @@ +/* + broadcaststatus.cpp + + This file is part of KDEPIM. + + Author: Don Sanders <sanders@kde.org> + + Copyright (C) 2000 Don Sanders <sanders@kde.org> + + License GPL +*/ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include <qdatetime.h> + +#include <klocale.h> +#include <kglobal.h> +#include <kstaticdeleter.h> + +#include "broadcaststatus.h" +#include "progressmanager.h" + +KPIM::BroadcastStatus* KPIM::BroadcastStatus::instance_ = 0; +static KStaticDeleter<KPIM::BroadcastStatus> broadcastStatusDeleter; + +namespace KPIM { + +BroadcastStatus* BroadcastStatus::instance() +{ + if (!instance_) + broadcastStatusDeleter.setObject( instance_, new BroadcastStatus() ); + + return instance_; +} + +BroadcastStatus::BroadcastStatus() + :mTransientActive( false ) +{ +} + +BroadcastStatus::~BroadcastStatus() +{ + instance_ = 0; +} + +void BroadcastStatus::setStatusMsg( const QString& message ) +{ + mStatusMsg = message; + if( !mTransientActive ) + emit statusMsg( message ); +} + +void BroadcastStatus::setStatusMsgWithTimestamp( const QString& message ) +{ + KLocale* locale = KGlobal::locale(); + setStatusMsg( i18n( "%1 is a time, %2 is a status message", "[%1] %2" ) + .arg( locale->formatTime( QTime::currentTime(), + true /* with seconds */ ) ) + .arg( message ) ); +} + +void BroadcastStatus::setStatusMsgTransmissionCompleted( int numMessages, + int numBytes, + int numBytesRead, + int numBytesToRead, + bool mLeaveOnServer, + KPIM::ProgressItem* item ) +{ + QString statusMsg; + if( numMessages > 0 ) { + if( numBytes != -1 ) { + if( ( numBytesToRead != numBytes ) && mLeaveOnServer ) + statusMsg = i18n( "Transmission complete. %n new message in %1 KB " + "(%2 KB remaining on the server).", + "Transmission complete. %n new messages in %1 KB " + "(%2 KB remaining on the server).", + numMessages ) + .arg( numBytesRead / 1024 ) + .arg( numBytes / 1024 ); + else + statusMsg = i18n( "Transmission complete. %n message in %1 KB.", + "Transmission complete. %n messages in %1 KB.", + numMessages ) + .arg( numBytesRead / 1024 ); + } + else + statusMsg = i18n( "Transmission complete. %n new message.", + "Transmission complete. %n new messages.", + numMessages ); + } + else + statusMsg = i18n( "Transmission complete. No new messages." ); + + setStatusMsgWithTimestamp( statusMsg ); + if ( item ) + item->setStatus( statusMsg ); +} + +void BroadcastStatus::setStatusMsgTransmissionCompleted( const QString& account, + int numMessages, + int numBytes, + int numBytesRead, + int numBytesToRead, + bool mLeaveOnServer, + KPIM::ProgressItem* item ) +{ + QString statusMsg; + if( numMessages > 0 ) { + if( numBytes != -1 ) { + if( ( numBytesToRead != numBytes ) && mLeaveOnServer ) + statusMsg = i18n( "Transmission for account %3 complete. " + "%n new message in %1 KB " + "(%2 KB remaining on the server).", + "Transmission for account %3 complete. " + "%n new messages in %1 KB " + "(%2 KB remaining on the server).", + numMessages ) + .arg( numBytesRead / 1024 ) + .arg( numBytes / 1024 ) + .arg( account ); + else + statusMsg = i18n( "Transmission for account %2 complete. " + "%n message in %1 KB.", + "Transmission for account %2 complete. " + "%n messages in %1 KB.", + numMessages ) + .arg( numBytesRead / 1024 ) + .arg( account ); + } + else + statusMsg = i18n( "Transmission for account %1 complete. " + "%n new message.", + "Transmission for account %1 complete. " + "%n new messages.", + numMessages ) + .arg( account ); + } + else + statusMsg = i18n( "Transmission for account %1 complete. No new messages.") + .arg( account ); + + setStatusMsgWithTimestamp( statusMsg ); + if ( item ) + item->setStatus( statusMsg ); +} + +void BroadcastStatus::setTransientStatusMsg( const QString& msg ) +{ + mTransientActive = true; + emit statusMsg( msg ); +} + +void BroadcastStatus::reset() +{ + mTransientActive = false; + // restore + emit statusMsg( mStatusMsg ); +} + +} + +#include "broadcaststatus.moc" |