summaryrefslogtreecommitdiffstats
path: root/framework/domain
diff options
context:
space:
mode:
Diffstat (limited to 'framework/domain')
-rw-r--r--framework/domain/settings/accountsettings.cpp48
-rw-r--r--framework/domain/settings/accountsettings.h5
2 files changed, 41 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
37void AccountSettings::setAccountType(const QByteArray &type)
38{
39 mAccountType = type;
40}
41
42QByteArray AccountSettings::accountType() const
43{
44 return mAccountType;
45}
37 46
38void AccountSettings::setAccountIdentifier(const QByteArray &id) 47void AccountSettings::setAccountIdentifier(const QByteArray &id)
39{ 48{
@@ -134,18 +143,32 @@ QValidator *AccountSettings::smtpServerValidator() const
134 143
135void AccountSettings::saveAccount() 144void 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
151void AccountSettings::loadAccount() 174void 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();
diff --git a/framework/domain/settings/accountsettings.h b/framework/domain/settings/accountsettings.h
index 08215a32..f0cecf9b 100644
--- a/framework/domain/settings/accountsettings.h
+++ b/framework/domain/settings/accountsettings.h
@@ -25,6 +25,7 @@ class AccountSettings : public QObject
25{ 25{
26 Q_OBJECT 26 Q_OBJECT
27 Q_PROPERTY(QByteArray accountIdentifier READ accountIdentifier WRITE setAccountIdentifier) 27 Q_PROPERTY(QByteArray accountIdentifier READ accountIdentifier WRITE setAccountIdentifier)
28 Q_PROPERTY(QByteArray accountType READ accountType WRITE setAccountType)
28 Q_PROPERTY(QString icon MEMBER mIcon NOTIFY changed) 29 Q_PROPERTY(QString icon MEMBER mIcon NOTIFY changed)
29 Q_PROPERTY(QString accountName MEMBER mName NOTIFY changed) 30 Q_PROPERTY(QString accountName MEMBER mName NOTIFY changed)
30 31
@@ -50,6 +51,9 @@ public:
50 void setAccountIdentifier(const QByteArray &); 51 void setAccountIdentifier(const QByteArray &);
51 QByteArray accountIdentifier() const; 52 QByteArray accountIdentifier() const;
52 53
54 void setAccountType(const QByteArray &);
55 QByteArray accountType() const;
56
53 void setPath(const QUrl &); 57 void setPath(const QUrl &);
54 QUrl path() const; 58 QUrl path() const;
55 59
@@ -87,6 +91,7 @@ protected:
87 void removeIdentity(); 91 void removeIdentity();
88 92
89 QByteArray mAccountIdentifier; 93 QByteArray mAccountIdentifier;
94 QByteArray mAccountType;
90 QString mIcon; 95 QString mIcon;
91 QString mName; 96 QString mName;
92 97