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