source: SMSSender/lib/libdatatypes/src/abstract/abstractaccount.cpp @ 71:415b45c71663

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