libtdepim

broadcaststatus.cpp
1 /*
2  broadcaststatus.cpp
3 
4  This file is part of TDEPIM.
5 
6  Author: Don Sanders <sanders@kde.org>
7 
8  Copyright (C) 2000 Don Sanders <sanders@kde.org>
9 
10  License GPL
11 */
12 
13 #ifdef HAVE_CONFIG_H
14 #include <config.h>
15 #endif
16 
17 #include <tqdatetime.h>
18 
19 #include <tdelocale.h>
20 #include <tdeglobal.h>
21 #include <kstaticdeleter.h>
22 
23 #include "broadcaststatus.h"
24 #include "progressmanager.h"
25 
26 KPIM::BroadcastStatus* KPIM::BroadcastStatus::instance_ = 0;
27 static KStaticDeleter<KPIM::BroadcastStatus> broadcasStatusDeleter;
28 
29 namespace KPIM {
30 
32 {
33  if (!instance_)
34  broadcasStatusDeleter.setObject( instance_, new BroadcastStatus() );
35 
36  return instance_;
37 }
38 
39 BroadcastStatus::BroadcastStatus()
40  :mTransientActive( false )
41 {
42 }
43 
44 BroadcastStatus::~BroadcastStatus()
45 {
46  instance_ = 0;
47 }
48 
49 void BroadcastStatus::setStatusMsg( const TQString& message )
50 {
51  mStatusMsg = message;
52  if( !mTransientActive )
53  emit statusMsg( message );
54 }
55 
56 void BroadcastStatus::setStatusMsgWithTimestamp( const TQString& message )
57 {
58  TDELocale* locale = TDEGlobal::locale();
59  setStatusMsg( i18n( "%1 is a time, %2 is a status message", "[%1] %2" )
60  .arg( locale->formatTime( TQTime::currentTime(),
61  true /* with seconds */ ) )
62  .arg( message ) );
63 }
64 
66  int numBytes,
67  int numBytesRead,
68  int numBytesToRead,
69  bool mLeaveOnServer,
70  KPIM::ProgressItem* item )
71 {
72  TQString statusMsg;
73  if( numMessages > 0 ) {
74  if( numBytes != -1 ) {
75  if( ( numBytesToRead != numBytes ) && mLeaveOnServer )
76  statusMsg = i18n( "Transmission complete. %n new message in %1 KB "
77  "(%2 KB remaining on the server).",
78  "Transmission complete. %n new messages in %1 KB "
79  "(%2 KB remaining on the server).",
80  numMessages )
81  .arg( numBytesRead / 1024 )
82  .arg( numBytes / 1024 );
83  else
84  statusMsg = i18n( "Transmission complete. %n message in %1 KB.",
85  "Transmission complete. %n messages in %1 KB.",
86  numMessages )
87  .arg( numBytesRead / 1024 );
88  }
89  else
90  statusMsg = i18n( "Transmission complete. %n new message.",
91  "Transmission complete. %n new messages.",
92  numMessages );
93  }
94  else
95  statusMsg = i18n( "Transmission complete. No new messages." );
96 
98  if ( item )
99  item->setStatus( statusMsg );
100 }
101 
102 void BroadcastStatus::setStatusMsgTransmissionCompleted( const TQString& account,
103  int numMessages,
104  int numBytes,
105  int numBytesRead,
106  int numBytesToRead,
107  bool mLeaveOnServer,
108  KPIM::ProgressItem* item )
109 {
110  TQString statusMsg;
111  if( numMessages > 0 ) {
112  if( numBytes != -1 ) {
113  if( ( numBytesToRead != numBytes ) && mLeaveOnServer )
114  statusMsg = i18n( "Transmission for account %3 complete. "
115  "%n new message in %1 KB "
116  "(%2 KB remaining on the server).",
117  "Transmission for account %3 complete. "
118  "%n new messages in %1 KB "
119  "(%2 KB remaining on the server).",
120  numMessages )
121  .arg( numBytesRead / 1024 )
122  .arg( numBytes / 1024 )
123  .arg( account );
124  else
125  statusMsg = i18n( "Transmission for account %2 complete. "
126  "%n message in %1 KB.",
127  "Transmission for account %2 complete. "
128  "%n messages in %1 KB.",
129  numMessages )
130  .arg( numBytesRead / 1024 )
131  .arg( account );
132  }
133  else
134  statusMsg = i18n( "Transmission for account %1 complete. "
135  "%n new message.",
136  "Transmission for account %1 complete. "
137  "%n new messages.",
138  numMessages )
139  .arg( account );
140  }
141  else
142  statusMsg = i18n( "Transmission for account %1 complete. No new messages.")
143  .arg( account );
144 
146  if ( item )
147  item->setStatus( statusMsg );
148 }
149 
150 void BroadcastStatus::setTransienStatusMsg( const TQString& msg )
151 {
152  mTransientActive = true;
153  emit statusMsg( msg );
154 }
155 
157 {
158  mTransientActive = false;
159  // restore
160  emit statusMsg( mStatusMsg );
161 }
162 
163 }
164 
165 #include "broadcaststatus.moc"
Provides a singleton which broadcasts status messages by emitting signals.
void setStatusMsgWithTimestamp(const TQString &message)
Sets a status bar message with timestamp.
void setTransienStatusMsg(const TQString &msg)
Set a status message that will go away again with the next call of reset().
void reset()
Reset the status message to what ever non-transient message was last active or has since been set.
void setStatusMsg(const TQString &message)
Emit an update status bar signal.
void setStatusMsgTransmissionCompleted(int numMessages, int numBytes=-1, int numBytesRead=-1, int numBytesToRead=-1, bool mLeaveOnServer=false, KPIM::ProgressItem *progressItem=0)
Sets a transmission completed status bar message.
TQString statusMsg() const
Return the last status message from setStatusMsg()
static BroadcastStatus * instance()
Return the instance of the singleton object for this class.
TDEPIM classes for drag and drop of mails.