source: SMSSender/src/business/BCAccountLoadThread.cpp @ 62:36700a2f4007

3.0
Last change on this file since 62:36700a2f4007 was 62:36700a2f4007, checked in by Sämy Zehnder <saemy.zehnder@…>, 12 years ago
File size: 1.9 KB
Line 
1#include "BCAccountLoadThread.h"
2
3/*short const AccountLoadThread::State::Unloaded   = 0;
4short const AccountLoadThread::State::Loading    = 1;
5short const AccountLoadThread::State::Loaded     = 2;
6short const AccountLoadThread::State::Cancelling = 3;
7short const AccountLoadThread::State::Cancelled  = 4;
8short const AccountLoadThread::State::Failed     = 5;*/
9
10BCAccountLoadThread::BCAccountLoadThread(IAccount* account, QObject* parent /* = 0 */)
11    : QThread(parent)
12    , account_(account)
13{
14    qRegisterMetaType<AccountLoadState>("AccountLoadState");
15    loadState_ = Unloaded;
16}
17
18
19void BCAccountLoadThread::run() {
20        if (account_->isInitialized()) {
21            setLoadState(Loaded);
22            loaded(account()); // Signal
23            loadingFinished(account(), loadState()); // Signal
24
25            return;
26        }
27
28        setLoadState(Loading);
29
30        try {
31            account_->initialize();
32        } catch (EException* exception) {
33            setLoadState(Failed);
34            loadingFailed(account(), exception); // Signal
35        } catch (...) {
36        setLoadState(Failed);
37            loadingFailed(account(), new EException("Unknown error occured while loading an account.")); // Signal
38        }
39
40        switch (loadState()) {
41        case  Cancelling:
42            setLoadState(Cancelled);
43            break;
44        case Loaded:
45        case Failed:
46            break;
47        default:
48            setLoadState(Loaded);
49            loaded(account()); // Signal
50            break;
51        }
52        loadingFinished(account(), loadState()); // Signal
53}
54
55void BCAccountLoadThread::cancelLoading() {
56    account_->stopInitializing();
57    setLoadState(Cancelling);
58}
59
60
61void BCAccountLoadThread::setLoadState(AccountLoadState loadState) {
62    if (loadState_ != loadState) {
63        loadState_ = loadState;
64
65        loadStateChanged(account(), this->loadState()); // Signal
66    }
67}
68
69IAccount* BCAccountLoadThread::account() {
70    return account_;
71}
72AccountLoadState BCAccountLoadThread::loadState() {
73    return loadState_;
74}
Note: See TracBrowser for help on using the repository browser.