diff options
Diffstat (limited to 'framework/domain/settings/accountsettings.cpp')
-rw-r--r-- | framework/domain/settings/accountsettings.cpp | 48 |
1 files changed, 36 insertions, 12 deletions
diff --git a/framework/domain/settings/accountsettings.cpp b/framework/domain/settings/accountsettings.cpp index d7c8c1c0..16791a7f 100644 --- a/framework/domain/settings/accountsettings.cpp +++ b/framework/domain/settings/accountsettings.cpp | |||
@@ -34,6 +34,15 @@ AccountSettings::AccountSettings(QObject *parent) | |||
34 | { | 34 | { |
35 | } | 35 | } |
36 | 36 | ||
37 | void AccountSettings::setAccountType(const QByteArray &type) | ||
38 | { | ||
39 | mAccountType = type; | ||
40 | } | ||
41 | |||
42 | QByteArray AccountSettings::accountType() const | ||
43 | { | ||
44 | return mAccountType; | ||
45 | } | ||
37 | 46 | ||
38 | void AccountSettings::setAccountIdentifier(const QByteArray &id) | 47 | void AccountSettings::setAccountIdentifier(const QByteArray &id) |
39 | { | 48 | { |
@@ -134,18 +143,32 @@ QValidator *AccountSettings::smtpServerValidator() const | |||
134 | 143 | ||
135 | void AccountSettings::saveAccount() | 144 | void AccountSettings::saveAccount() |
136 | { | 145 | { |
137 | qDebug() << "Saving account " << mAccountIdentifier << mMailtransportIdentifier; | 146 | if (mAccountIdentifier.isEmpty()) { |
138 | Q_ASSERT(!mAccountIdentifier.isEmpty()); | 147 | auto account = ApplicationDomainType::createEntity<SinkAccount>(); |
139 | SinkAccount account(mAccountIdentifier); | 148 | mAccountIdentifier = account.identifier(); |
140 | account.setAccountType("imap"); | 149 | Q_ASSERT(!mAccountType.isEmpty()); |
141 | account.setName(mName); | 150 | account.setAccountType(mAccountType); |
142 | account.setIcon(mIcon); | 151 | account.setName(mName); |
143 | Q_ASSERT(!account.identifier().isEmpty()); | 152 | account.setIcon(mIcon); |
144 | Store::modify(account) | 153 | Store::create(account) |
145 | .onError([](const KAsync::Error &error) { | 154 | .onError([](const KAsync::Error &error) { |
146 | qWarning() << "Error while creating account: " << error.errorMessage;; | 155 | qWarning() << "Error while creating account: " << error.errorMessage;; |
147 | }) | 156 | }) |
148 | .exec(); | 157 | .exec(); |
158 | } else { | ||
159 | qDebug() << "Saving account " << mAccountIdentifier << mMailtransportIdentifier; | ||
160 | Q_ASSERT(!mAccountIdentifier.isEmpty()); | ||
161 | SinkAccount account(mAccountIdentifier); | ||
162 | account.setAccountType(mAccountType); | ||
163 | account.setName(mName); | ||
164 | account.setIcon(mIcon); | ||
165 | Q_ASSERT(!account.identifier().isEmpty()); | ||
166 | Store::modify(account) | ||
167 | .onError([](const KAsync::Error &error) { | ||
168 | qWarning() << "Error while creating account: " << error.errorMessage;; | ||
169 | }) | ||
170 | .exec(); | ||
171 | } | ||
149 | } | 172 | } |
150 | 173 | ||
151 | void AccountSettings::loadAccount() | 174 | void AccountSettings::loadAccount() |
@@ -153,6 +176,7 @@ void AccountSettings::loadAccount() | |||
153 | Q_ASSERT(!mAccountIdentifier.isEmpty()); | 176 | Q_ASSERT(!mAccountIdentifier.isEmpty()); |
154 | Store::fetchOne<SinkAccount>(Query().filter(mAccountIdentifier)) | 177 | Store::fetchOne<SinkAccount>(Query().filter(mAccountIdentifier)) |
155 | .then([this](const SinkAccount &account) { | 178 | .then([this](const SinkAccount &account) { |
179 | mAccountType = account.getAccountType().toLatin1(); | ||
156 | mIcon = account.getIcon(); | 180 | mIcon = account.getIcon(); |
157 | mName = account.getName(); | 181 | mName = account.getName(); |
158 | emit changed(); | 182 | emit changed(); |