| 1 | /* |
|---|
| 2 | Copyright (c) 2007 Cyrus Daboo. All rights reserved. |
|---|
| 3 | |
|---|
| 4 | Licensed under the Apache License, Version 2.0 (the "License"); |
|---|
| 5 | you may not use this file except in compliance with the License. |
|---|
| 6 | You may obtain a copy of the License at |
|---|
| 7 | |
|---|
| 8 | http://www.apache.org/licenses/LICENSE-2.0 |
|---|
| 9 | |
|---|
| 10 | Unless required by applicable law or agreed to in writing, software |
|---|
| 11 | distributed under the License is distributed on an "AS IS" BASIS, |
|---|
| 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|---|
| 13 | See the License for the specific language governing permissions and |
|---|
| 14 | limitations under the License. |
|---|
| 15 | */ |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | // Source for CStatusWindow class |
|---|
| 19 | |
|---|
| 20 | |
|---|
| 21 | #include "CStatusWindow.h" |
|---|
| 22 | #include "CMailControl.h" |
|---|
| 23 | #include "CMulberryApp.h" |
|---|
| 24 | #include "CTaskClasses.h" |
|---|
| 25 | #include "CXStringResources.h" |
|---|
| 26 | |
|---|
| 27 | #include <stdio.h> |
|---|
| 28 | |
|---|
| 29 | // __________________________________________________________________________________________________ |
|---|
| 30 | // C L A S S __ C S T A T U S W I N D O W |
|---|
| 31 | // __________________________________________________________________________________________________ |
|---|
| 32 | |
|---|
| 33 | // C O N S T R U C T I O N / D E S T R U C T I O N M E T H O D S |
|---|
| 34 | |
|---|
| 35 | CUTF8StatusBar* CStatusWindow::sStatusBar = NULL; |
|---|
| 36 | cdstring CStatusWindow::sIdleStatus; |
|---|
| 37 | cdstring CStatusWindow::sIMAPStatus; |
|---|
| 38 | cdstring CStatusWindow::sSMTPStatus; |
|---|
| 39 | bool CStatusWindow::sStatusLock = false; |
|---|
| 40 | bool CStatusWindow::sChangeOnce = false; |
|---|
| 41 | |
|---|
| 42 | // O T H E R M E T H O D S ____________________________________________________________________________ |
|---|
| 43 | |
|---|
| 44 | #define SBPF_UPDATE 0x0001 // pending update of text |
|---|
| 45 | |
|---|
| 46 | struct AFX_STATUSPANE |
|---|
| 47 | { |
|---|
| 48 | UINT nID; // IDC of indicator: 0 => normal text area |
|---|
| 49 | int cxText; // width of string area in pixels |
|---|
| 50 | // on both sides there is a 3 pixel gap and |
|---|
| 51 | // a one pixel border, making a pane 6 pixels wider |
|---|
| 52 | UINT nStyle; // style flags (SBPS_*) |
|---|
| 53 | UINT nFlags; // state flags (SBPF_*) |
|---|
| 54 | CString strText; // text in the pane |
|---|
| 55 | }; |
|---|
| 56 | |
|---|
| 57 | BOOL CUTF8StatusBar::SetPaneTextUTF8(int nIndex, const char* utf8, BOOL bUpdate) |
|---|
| 58 | { |
|---|
| 59 | // Don't call into CWnd code if this thread doesn't own this CWnd |
|---|
| 60 | if (!FromHandlePermanent(GetSafeHwnd())) |
|---|
| 61 | return FALSE; |
|---|
| 62 | #ifdef _UNICODE |
|---|
| 63 | cdustring utf16(utf8); |
|---|
| 64 | return SetPaneText(nIndex, utf16, bUpdate); |
|---|
| 65 | #else |
|---|
| 66 | ASSERT_VALID(this); |
|---|
| 67 | ASSERT(::IsWindow(m_hWnd)); |
|---|
| 68 | |
|---|
| 69 | AFX_STATUSPANE* pSBP = _GetPanePtr(nIndex); |
|---|
| 70 | |
|---|
| 71 | if (!(pSBP->nFlags & SBPF_UPDATE) && |
|---|
| 72 | ((utf8 == NULL && pSBP->strText.IsEmpty()) || |
|---|
| 73 | (utf8 != NULL && pSBP->strText.Compare(utf8) == 0))) |
|---|
| 74 | { |
|---|
| 75 | // nothing to change |
|---|
| 76 | return TRUE; |
|---|
| 77 | } |
|---|
| 78 | |
|---|
| 79 | TRY |
|---|
| 80 | { |
|---|
| 81 | if (utf8 != NULL) |
|---|
| 82 | pSBP->strText = utf8; |
|---|
| 83 | else |
|---|
| 84 | pSBP->strText.Empty(); |
|---|
| 85 | } |
|---|
| 86 | CATCH_ALL(e) |
|---|
| 87 | { |
|---|
| 88 | // Note: DELETE_EXCEPTION(e) not required |
|---|
| 89 | return FALSE; |
|---|
| 90 | } |
|---|
| 91 | END_CATCH_ALL |
|---|
| 92 | |
|---|
| 93 | if (!bUpdate) |
|---|
| 94 | { |
|---|
| 95 | // can't update now, wait until later |
|---|
| 96 | pSBP->nFlags |= SBPF_UPDATE; |
|---|
| 97 | return TRUE; |
|---|
| 98 | } |
|---|
| 99 | |
|---|
| 100 | pSBP->nFlags &= ~SBPF_UPDATE; |
|---|
| 101 | cdustring utf16(utf8); |
|---|
| 102 | DefWindowProc(SB_SETTEXTW, ((WORD)pSBP->nStyle)|nIndex, |
|---|
| 103 | (pSBP->nStyle & SBPS_DISABLED) ? NULL : |
|---|
| 104 | (LPARAM)(LPCTSTR)utf16.c_str()); |
|---|
| 105 | |
|---|
| 106 | return TRUE; |
|---|
| 107 | #endif |
|---|
| 108 | } |
|---|
| 109 | |
|---|
| 110 | BOOL CUTF8StatusBar::RedrawWindow(LPCRECT lpRectUpdate, |
|---|
| 111 | CRgn* prgnUpdate, |
|---|
| 112 | UINT flags) |
|---|
| 113 | { |
|---|
| 114 | // Don't call into CWnd code if this thread doesn't own this CWnd |
|---|
| 115 | return FromHandlePermanent(GetSafeHwnd()) ? CStatusBar::RedrawWindow(lpRectUpdate, prgnUpdate, flags) : FALSE; |
|---|
| 116 | } |
|---|
| 117 | |
|---|
| 118 | // Init status |
|---|
| 119 | void CStatusWindow::InitStatusBar(CUTF8StatusBar* statusBar) |
|---|
| 120 | { |
|---|
| 121 | sStatusBar = statusBar; |
|---|
| 122 | |
|---|
| 123 | // Set widths |
|---|
| 124 | sStatusBar->SetPaneInfo(0, ID_SEPARATOR, SBPS_NOBORDERS, 350); |
|---|
| 125 | sStatusBar->SetPaneInfo(1, ID_SEPARATOR, SBPS_NOBORDERS, 50); |
|---|
| 126 | sStatusBar->SetPaneInfo(2, ID_SEPARATOR, SBPS_NOBORDERS, 150); |
|---|
| 127 | sStatusBar->SetPaneInfo(2, ID_SEPARATOR, SBPS_STRETCH, 150); |
|---|
| 128 | |
|---|
| 129 | sIMAPStatus = rsrc::GetString("Status::IMAP"); |
|---|
| 130 | sSMTPStatus = rsrc::GetString("Status::SMTP"); |
|---|
| 131 | sIdleStatus = rsrc::GetString("Status::IDLE"); |
|---|
| 132 | |
|---|
| 133 | sStatusBar->SetPaneTextUTF8(0, sIdleStatus); |
|---|
| 134 | //sStatusBar->SendMessage(WM_PAINT); |
|---|
| 135 | sStatusBar->RedrawWindow(); |
|---|
| 136 | } |
|---|
| 137 | |
|---|
| 138 | // Fill status |
|---|
| 139 | void CStatusWindow::SetDefaultStatus(void) |
|---|
| 140 | { |
|---|
| 141 | // Determine SMTP status |
|---|
| 142 | SetSMTPStatus("Status::IDLE"); |
|---|
| 143 | |
|---|
| 144 | // Determine IMAP status |
|---|
| 145 | SetIMAPStatus("Status::IDLE"); |
|---|
| 146 | } |
|---|
| 147 | |
|---|
| 148 | // Fill status |
|---|
| 149 | void CStatusWindow::SetDefaultProgress(void) |
|---|
| 150 | { |
|---|
| 151 | // Empty both progress |
|---|
| 152 | SetSMTPProgress(-1); |
|---|
| 153 | SetIMAPProgress(-1); |
|---|
| 154 | } |
|---|
| 155 | |
|---|
| 156 | // Set SMTP status string |
|---|
| 157 | void CStatusWindow::SetSMTPStatusStr(const cdstring& str) |
|---|
| 158 | { |
|---|
| 159 | sStatusBar->SetPaneTextUTF8(0, str.c_str()); |
|---|
| 160 | sStatusBar->RedrawWindow(); |
|---|
| 161 | } |
|---|
| 162 | |
|---|
| 163 | // Set SMTP status string |
|---|
| 164 | void CStatusWindow::SetSMTPStatus(const char* rsrcid) |
|---|
| 165 | { |
|---|
| 166 | cdstring s = rsrc::GetString(rsrcid); |
|---|
| 167 | s = sSMTPStatus + s; |
|---|
| 168 | |
|---|
| 169 | // Change status using task in case of call from worker thread |
|---|
| 170 | CSMTPStatusTask* task = new CSMTPStatusTask(s); |
|---|
| 171 | task->Go(); |
|---|
| 172 | } |
|---|
| 173 | |
|---|
| 174 | // Set SMTP status string with numbers |
|---|
| 175 | void CStatusWindow::SetSMTPStatus2(const char* rsrcid, long num1, long num2) |
|---|
| 176 | { |
|---|
| 177 | // Get the string |
|---|
| 178 | cdstring rsrc_str = rsrc::GetString(rsrcid); |
|---|
| 179 | |
|---|
| 180 | // Write numbers into it |
|---|
| 181 | cdstring status; |
|---|
| 182 | status.reserve(256); |
|---|
| 183 | ::snprintf(status.c_str_mod(), 256, rsrc_str, num1, num2); |
|---|
| 184 | status = sSMTPStatus + status; |
|---|
| 185 | |
|---|
| 186 | // Change status using task in case of call from worker thread |
|---|
| 187 | CSMTPStatusTask* task = new CSMTPStatusTask(status); |
|---|
| 188 | task->Go(); |
|---|
| 189 | } |
|---|
| 190 | |
|---|
| 191 | // Set SMTP status string |
|---|
| 192 | void CStatusWindow::SetIMAPStatusStr(const cdstring& str) |
|---|
| 193 | { |
|---|
| 194 | sStatusBar->SetPaneTextUTF8(0, str.c_str()); |
|---|
| 195 | sStatusBar->RedrawWindow(); |
|---|
| 196 | } |
|---|
| 197 | |
|---|
| 198 | // Set IMAP status string |
|---|
| 199 | void CStatusWindow::SetIMAPStatus(const char* rsrcid) |
|---|
| 200 | { |
|---|
| 201 | if (sStatusLock && !sChangeOnce) |
|---|
| 202 | return; |
|---|
| 203 | sChangeOnce = false; |
|---|
| 204 | |
|---|
| 205 | cdstring status = rsrc::GetString(rsrcid); |
|---|
| 206 | status = sIMAPStatus + status; |
|---|
| 207 | |
|---|
| 208 | // Change status using task in case of call from worker thread |
|---|
| 209 | CIMAPStatusTask* task = new CIMAPStatusTask(status); |
|---|
| 210 | task->Go(); |
|---|
| 211 | } |
|---|
| 212 | |
|---|
| 213 | // Set IMAP status string with a number |
|---|
| 214 | void CStatusWindow::SetIMAPStatus1(const char* rsrcid, long num1) |
|---|
| 215 | { |
|---|
| 216 | if (sStatusLock && !sChangeOnce) |
|---|
| 217 | return; |
|---|
| 218 | sChangeOnce = false; |
|---|
| 219 | |
|---|
| 220 | // Get the string |
|---|
| 221 | cdstring rsrc_str = rsrc::GetString(rsrcid); |
|---|
| 222 | |
|---|
| 223 | // Write numbers into it |
|---|
| 224 | cdstring status; |
|---|
| 225 | status.reserve(256); |
|---|
| 226 | ::snprintf(status.c_str_mod(), 256, rsrc_str, num1); |
|---|
| 227 | |
|---|
| 228 | status = sIMAPStatus + status; |
|---|
| 229 | |
|---|
| 230 | // Change status using task in case of call from worker thread |
|---|
| 231 | CIMAPStatusTask* task = new CIMAPStatusTask(status); |
|---|
| 232 | task->Go(); |
|---|
| 233 | } |
|---|
| 234 | |
|---|
| 235 | // Set IMAP status string with numbers |
|---|
| 236 | void CStatusWindow::SetIMAPStatus2(const char* rsrcid, long num1, long num2) |
|---|
| 237 | { |
|---|
| 238 | if (sStatusLock && !sChangeOnce) |
|---|
| 239 | return; |
|---|
| 240 | sChangeOnce = false; |
|---|
| 241 | |
|---|
| 242 | // Get the string |
|---|
| 243 | cdstring rsrc_str = rsrc::GetString(rsrcid); |
|---|
| 244 | |
|---|
| 245 | // Write numbers into it |
|---|
| 246 | cdstring status; |
|---|
| 247 | status.reserve(256); |
|---|
| 248 | ::snprintf(status.c_str_mod(), 256, rsrc_str, num1, num2); |
|---|
| 249 | status = sIMAPStatus + status; |
|---|
| 250 | |
|---|
| 251 | // Change status using task in case of call from worker thread |
|---|
| 252 | CIMAPStatusTask* task = new CIMAPStatusTask(status); |
|---|
| 253 | task->Go(); |
|---|
| 254 | } |
|---|
| 255 | |
|---|
| 256 | // Set SMTP progress string |
|---|
| 257 | void CStatusWindow::SetSMTPProgressStr(const cdstring& str) |
|---|
| 258 | { |
|---|
| 259 | // Set the caption's text |
|---|
| 260 | sStatusBar->SetPaneTextUTF8(1, str.c_str()); |
|---|
| 261 | sStatusBar->RedrawWindow(); |
|---|
| 262 | } |
|---|
| 263 | |
|---|
| 264 | // Set SMTP progress string |
|---|
| 265 | void CStatusWindow::SetSMTPProgress(long progress) |
|---|
| 266 | { |
|---|
| 267 | // Set up string |
|---|
| 268 | cdstring status; |
|---|
| 269 | status.reserve(256); |
|---|
| 270 | |
|---|
| 271 | // Set up the string |
|---|
| 272 | if ((progress >= 0) && (progress <= 100)) |
|---|
| 273 | ::snprintf(status.c_str_mod(), 256, "%d%%", progress); |
|---|
| 274 | else if (progress > 100) |
|---|
| 275 | ::snprintf(status.c_str_mod(), 256, "%d%%", 100); |
|---|
| 276 | |
|---|
| 277 | // Set the caption's text |
|---|
| 278 | sStatusBar->SetPaneTextUTF8(1, status); |
|---|
| 279 | sStatusBar->RedrawWindow(); |
|---|
| 280 | } |
|---|
| 281 | |
|---|
| 282 | // Set IMAP progress string |
|---|
| 283 | void CStatusWindow::SetIMAPProgressStr(const cdstring& str) |
|---|
| 284 | { |
|---|
| 285 | if (sStatusLock && !sChangeOnce) |
|---|
| 286 | return; |
|---|
| 287 | sChangeOnce = false; |
|---|
| 288 | |
|---|
| 289 | // Set the caption's text |
|---|
| 290 | sStatusBar->SetPaneTextUTF8(1, str.c_str()); |
|---|
| 291 | sStatusBar->RedrawWindow(); |
|---|
| 292 | } |
|---|
| 293 | |
|---|
| 294 | // Set IMAP progress string |
|---|
| 295 | void CStatusWindow::SetIMAPProgress(long progress) |
|---|
| 296 | { |
|---|
| 297 | if (sStatusLock && !sChangeOnce) |
|---|
| 298 | return; |
|---|
| 299 | sChangeOnce = false; |
|---|
| 300 | |
|---|
| 301 | // Set up string |
|---|
| 302 | // Set up string |
|---|
| 303 | cdstring status; |
|---|
| 304 | status.reserve(256); |
|---|
| 305 | |
|---|
| 306 | // Set up the string |
|---|
| 307 | if ((progress >= 0) && (progress <= 100)) |
|---|
| 308 | ::snprintf(status.c_str_mod(), 256, "%d%%", progress); |
|---|
| 309 | else if (progress > 100) |
|---|
| 310 | ::snprintf(status.c_str_mod(), 256, "%d%%", 100); |
|---|
| 311 | |
|---|
| 312 | |
|---|
| 313 | // Set the caption's text |
|---|
| 314 | sStatusBar->SetPaneTextUTF8(1, status); |
|---|
| 315 | sStatusBar->RedrawWindow(); |
|---|
| 316 | } |
|---|
| 317 | |
|---|
| 318 | #pragma mark - |
|---|
| 319 | |
|---|
| 320 | // __________________________________________________________________________________________________ |
|---|
| 321 | // C L A S S __ C S M T P A T T A C H P R O G R E S S |
|---|
| 322 | // __________________________________________________________________________________________________ |
|---|
| 323 | |
|---|
| 324 | // C O N S T R U C T I O N / D E S T R U C T I O N M E T H O D S |
|---|
| 325 | |
|---|
| 326 | // Default constructor |
|---|
| 327 | CSMTPAttachProgress::CSMTPAttachProgress() |
|---|
| 328 | { |
|---|
| 329 | } |
|---|
| 330 | |
|---|
| 331 | // Default destructor |
|---|
| 332 | CSMTPAttachProgress::~CSMTPAttachProgress() |
|---|
| 333 | { |
|---|
| 334 | // Make sure progress text is removed |
|---|
| 335 | CStatusWindow::SetSMTPProgress(-1); |
|---|
| 336 | } |
|---|
| 337 | |
|---|
| 338 | // O T H E R M E T H O D S ____________________________________________________________________________ |
|---|
| 339 | |
|---|
| 340 | void CSMTPAttachProgress::SetPercentage(unsigned long percentage) |
|---|
| 341 | { |
|---|
| 342 | CProgress::SetPercentage(percentage); |
|---|
| 343 | |
|---|
| 344 | CStatusWindow::SetSMTPProgress(mPercentage); |
|---|
| 345 | } |
|---|
| 346 | |
|---|
| 347 | void CSMTPAttachProgress::SetCount(unsigned long count) |
|---|
| 348 | { |
|---|
| 349 | CProgress::SetCount(count); |
|---|
| 350 | |
|---|
| 351 | // Set status with numbers |
|---|
| 352 | CStatusWindow::SetSMTPStatus2("Status::SMTP::AttachSend", mCount, mTotal); |
|---|
| 353 | } |
|---|
| 354 | |
|---|
| 355 | #pragma mark - |
|---|
| 356 | |
|---|
| 357 | // __________________________________________________________________________________________________ |
|---|
| 358 | // C L A S S __ C N E T W O R K A T T A C H P R O G R E S S |
|---|
| 359 | // __________________________________________________________________________________________________ |
|---|
| 360 | |
|---|
| 361 | // C O N S T R U C T I O N / D E S T R U C T I O N M E T H O D S |
|---|
| 362 | |
|---|
| 363 | // Default constructor |
|---|
| 364 | CNetworkAttachProgress::CNetworkAttachProgress() |
|---|
| 365 | { |
|---|
| 366 | } |
|---|
| 367 | |
|---|
| 368 | // Default destructor |
|---|
| 369 | CNetworkAttachProgress::~CNetworkAttachProgress() |
|---|
| 370 | { |
|---|
| 371 | // Make sure progress text is removed |
|---|
| 372 | CStatusWindow::SetIMAPProgress(-1); |
|---|
| 373 | } |
|---|
| 374 | |
|---|
| 375 | // O T H E R M E T H O D S ____________________________________________________________________________ |
|---|
| 376 | |
|---|
| 377 | void CNetworkAttachProgress::SetPercentage(unsigned long percentage) |
|---|
| 378 | { |
|---|
| 379 | CProgress::SetPercentage(percentage); |
|---|
| 380 | |
|---|
| 381 | CStatusWindow::SetIMAPProgress(mPercentage); |
|---|
| 382 | } |
|---|
| 383 | |
|---|
| 384 | void CNetworkAttachProgress::SetCount(unsigned long count) |
|---|
| 385 | { |
|---|
| 386 | CProgress::SetCount(count); |
|---|
| 387 | |
|---|
| 388 | // Set status with numbers |
|---|
| 389 | CStatusWindow::SetIMAPStatus2("Status::IMAP::Processing", mCount, mTotal); |
|---|
| 390 | } |
|---|
| 391 | |
|---|