source: SMSSender/lib/libgateway/src/business/AbstractAccount.cpp @ 67:578192d6fe64

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: 3.6 KB
Line 
1
2#include "AbstractAccount.h"
3
4AbstractAccount::AbstractAccount(IStorageOfficer* storageOfficer, IValidator* validator)
5    : id_(-1)
6
7    , enabled_(true)
8
9    , freeSMSCount_(-1)
10
11    , initializing_(false)
12    , initialized_(false)
13    , stoppingInitialization_(false)
14
15    , cancelSMSSending_(false)
16    , storageOfficer_(storageOfficer)
17    , validator_(validator)
18{
19    eventMapper_ = new AccountEventMapper(this);
20}
21
22AccountEventMapper* AbstractAccount::eventMapper() const {
23    return eventMapper_;
24}
25IAccountEvents* AbstractAccount::accountEvents() const {
26    return static_cast<IAccountEvents*>(eventMapper());
27}
28
29int AbstractAccount::id() const {
30    return id_;
31}
32void AbstractAccount::setId(int id) {
33    if (id_ == id) return;
34
35    int oldId = id_;
36    id_ = id;
37
38    emit accountEvents()->idChanged(oldId, id);
39    emit accountEvents()->dataChanged();
40}
41
42QString AbstractAccount::name() const {
43    return name_;
44}
45void AbstractAccount::setName(const QString& name) {
46    SET_IF_DIFFERENT(name_, name.trimmed());
47    emit accountEvents()->dataChanged();
48}
49
50
51void AbstractAccount::setStatus(const QString& status, int progress /* = -1 */, const ProgressMethod& progressMethod /* = SetProgress*/) {
52    if (status_ != status) {
53        status_ = status;
54
55        emit accountEvents()->statusChanged(status);
56    }
57
58    if (progress > -1) {
59        setProgress(progress, progressMethod);
60    }
61}
62void AbstractAccount::setProgress(int progress, const ProgressMethod& progressMethod /* = SetProgress */) {
63    switch (progressMethod) {
64        case IncProgress:
65            progress_ += progress;
66            break;
67
68        case SetProgress:
69            SET_IF_DIFFERENT(progress_, progress);
70            break;
71    }
72
73    emit accountEvents()->progressChanged(progress_);
74}
75
76bool AbstractAccount::isEnabled() const {
77    return enabled_;
78}
79void AbstractAccount::setEnabled(bool enabled) {
80    SET_IF_DIFFERENT(enabled_, enabled);
81    emit accountEvents()->dataChanged();
82
83    if (!enabled) {
84        unInitialize();
85    }
86}
87
88
89int AbstractAccount::freeSMSCount() const {
90    return freeSMSCount_;
91}
92void AbstractAccount::setFreeSMSCount(int freeSMSCount) {
93    SET_IF_DIFFERENT(freeSMSCount_, freeSMSCount);
94    emit accountEvents()->dataChanged();
95}
96
97IValidator* AbstractAccount::getValidator() const {
98    return validator_;
99}
100IStorageOfficer* AbstractAccount::getStorageOfficer() const {
101    return storageOfficer_;
102}
103
104
105
106void AbstractAccount::initialize(){
107    if (isInitializing() || isInitialized() || !isEnabled()) {
108        return;
109    }
110
111    /* TODO: Do this in a queue... */
112
113    while (stoppingInitialization_){
114        // TODO: sleep...
115    }
116
117    initializing_ = true;
118    try{
119        doInitialize();
120
121        if (!stoppingInitialization_)
122            setInitialized(true);
123    }catch (...) {
124        initializing_ = false;
125        throw;
126    }
127    initializing_ = false;
128    stoppingInitialization_ = false;
129}
130
131void AbstractAccount::stopInitializing() {
132    if (isInitializing())
133        stoppingInitialization_ = true;
134}
135
136bool AbstractAccount::isInitializing() {
137    return initializing_;
138}
139
140bool AbstractAccount::isInitialized() {
141    return initialized_;
142}
143
144void AbstractAccount::setInitialized(bool initialized) {
145    SET_IF_DIFFERENT(initialized_, initialized);
146    emit accountEvents()->dataChanged();
147}
148
149
150void AbstractAccount::unInitialize() {
151    if (isInitializing())
152        stopInitializing();
153
154    setInitialized(false);
155}
156
157
158void AbstractAccount::cancelSMSSending() {
159    cancelSMSSending_ = true;
160}
161
162bool AbstractAccount::isSendingCanceled() {
163    return cancelSMSSending_;
164}
165
166void AbstractAccount::uncancelSendingSMS() {
167    cancelSMSSending_ = false;
168}
Note: See TracBrowser for help on using the repository browser.