Changeset 72:fc91522ef9be in SMSSender
- Timestamp:
- Feb 9, 2010 9:47:21 PM (11 years ago)
- Branch:
- 3.0
- Convert:
- svn:3639001d-8e34-449c-bb86-3782b86c4877/branches/3.0@71
- Files:
-
- 1 added
- 1 deleted
- 34 edited
Legend:
- Unmodified
- Added
- Removed
-
gateways/SwisscomXtraZone/src/business/BCAccount.cpp
r71 r72 83 83 posts.insert("isiwebpasswd", password()); 84 84 85 lastHtml_ = httpHelper_->post(LOGIN_PAGE, QMap<QString, QString>(), posts); 85 if (!httpHelper_->post(LOGIN_PAGE, lastHtml_, QMap<QString, QString>(), posts)) { 86 throw LoginAccount::ELoginException(LoginAccount::ELoginException::RequestError).chain(httpHelper_->lastError()); 87 } 86 88 87 89 if (lastHtml_.contains("Begin error region content", Qt::CaseInsensitive)) { 88 throw LoginAccount::ELoginException(LoginAccount::ELoginException::InvalidLoginData) ;90 throw LoginAccount::ELoginException(LoginAccount::ELoginException::InvalidLoginData).chain(httpHelper_->lastError()); 89 91 } 90 92 91 93 if (!lastHtml_.contains("CobYouthSMSSenden:txtMessage", Qt::CaseInsensitive)) { 92 throw LoginAccount::ELoginException( LoginAccount::ELoginException::Unknown, "The returned page contains no message field.");94 throw LoginAccount::ELoginException("The returned page contains no message field.").chain(httpHelper_->lastError()); 93 95 } 94 96 … … 99 101 qDebug() << "Starting logout"; 100 102 101 httpHelper_->get(LOGOUT_PAGE); 103 QString requestResult; 104 if (!httpHelper_->get(LOGOUT_PAGE, requestResult)) { 105 qWarning() << tr("Error during logout: ") + httpHelper_->lastError().chainedWhat(); 106 qWarning() << tr("But ignoring it, since we clear the cookies and are therefore also logged out"); 107 } 102 108 httpHelper_->cookieManager()->clearCookies(); 103 109 … … 108 114 qDebug() << "Starting still-logged-in-check"; 109 115 110 bool result = httpHelper_->get(MAIN_PAGE).contains("CobYouthSMSSenden:txtMessage", Qt::CaseInsensitive); 116 QString requestResult; 117 bool result = true; 118 if (!httpHelper_->get(MAIN_PAGE, requestResult)) { 119 result = false; 120 qWarning() << tr("Error while checking if we are still logged in: ") + httpHelper_->lastError().chainedWhat(); 121 qWarning() << tr("But ignoring it, since we just do a new login attempt."); 122 } 123 result = result && 124 requestResult.contains("CobYouthSMSSenden:txtMessage", Qt::CaseInsensitive); 111 125 112 126 qDebug() << "Ended still-logged-in-check"; … … 128 142 } 129 143 130 lastHtml_ = httpHelper_->post(MAIN_PAGE, QMap<QString, QString>(), posts_); 144 if (!httpHelper_->post(MAIN_PAGE, lastHtml_, QMap<QString, QString>(), posts_)) { 145 throw Http::EReadException(tr("Error while doing a post")).addDebugInfos(posts_).chain(httpHelper_->lastError()); 146 } 131 147 132 148 rx.setPattern("<span.*id=\"CobYouthSMSSenden_lblErrorBox\".*>(.*)</span>"); … … 145 161 BCGateway* gtwy = static_cast<BCGateway*>(gateway()); 146 162 147 rx.setPattern("<input.*id=\"CobYouthSMSSenden_txtMessageDisabled\".*value=\"(.*)\".*/>"); 148 if (rx.indexIn(lastHtml_) == -1) { 149 throw EException(tr("Could not get the addon text!")); 150 } 151 gtwy->setAddonText(rx.cap(1)); 152 qDebug() << " Addon text: " + rx.cap(1); 153 154 rx.setPattern("<input.*id=\"lblcounter\".*value='(\\d*)'.*/?>"); 155 if (rx.indexIn(lastHtml_) == -1){ 156 throw EException(tr("Could not get the longSMSLength!")); 157 } 158 gtwy->setLongSMSLength(rx.cap(1).toInt() + gtwy->addonText().length()); 159 qDebug() << " Long SMS lenght: " + rx.cap(1); 160 161 rx.setPattern("<span.*id=\"CobYouthMMSSMSKonto_lblGuthaben\">(\\d*)</span>"); 162 if (rx.indexIn(lastHtml_) == -1) { 163 throw EException(tr("Could not get the free sms count!")); 163 try { 164 rx.setPattern("<input.*id=\"CobYouthSMSSenden_txtMessageDisabled\".*value=\"(.*)\".*/>"); 165 if (rx.indexIn(lastHtml_) == -1) { 166 throw EException(tr("Could not get the addon text!")); 167 } 168 gtwy->setAddonText(rx.cap(1)); 169 qDebug() << " Addon text: " + rx.cap(1); 170 171 rx.setPattern("<input.*id=\"lblcounter\".*value='(\\d*)'.*/?>"); 172 if (rx.indexIn(lastHtml_) == -1){ 173 throw EException(tr("Could not get the longSMSLength!")); 174 } 175 gtwy->setLongSMSLength(rx.cap(1).toInt() + gtwy->addonText().length()); 176 qDebug() << " Long SMS lenght: " + rx.cap(1); 177 178 rx.setPattern("<span.*id=\"CobYouthMMSSMSKonto_lblGuthaben\">(\\d*)</span>"); 179 if (rx.indexIn(lastHtml_) == -1) { 180 throw EException(tr("Could not get the free sms count!")); 181 } 182 } catch (EException e) { 183 throw EException(tr("Error while parsing the sms-page: ") + e.unchainedWhat()); 164 184 } 165 185 setFreeSMSCount(rx.cap(1).toInt()); … … 173 193 posts.insert("CobYouthSMSSenden:RecipientsDG:_ctl2:_ctl0", ""); 174 194 175 while (lastHtml_.contains("CobYouthSMSSenden:RecipientsDG:_ctl2:_ctl0", Qt::CaseInsensitive)){ 176 _doPost(posts); 195 try { 196 while (lastHtml_.contains("CobYouthSMSSenden:RecipientsDG:_ctl2:_ctl0", Qt::CaseInsensitive)){ 197 _doPost(posts); 198 } 199 } catch (EException e) { 200 throw EException(tr("Could not remove old recipients: ") + e.unchainedWhat()); 177 201 } 178 202 qDebug() << "Recipients removed"; … … 186 210 posts.insert("CobYouthSMSSenden:txtNewReceiver", recipient->number().toString("aaau")); 187 211 188 _doPost(posts); 212 try { 213 _doPost(posts); 214 } catch (EException e) { 215 throw EException(tr("Could not add a recipient: ") + e.what()); 216 } 189 217 qDebug() << "Recipient added"; 190 218 } 191 219 192 220 void BCAccount::_sendSMS(const QString& text) { 193 qDebug() << "Start ingsending part of SMS";221 qDebug() << "Start of sending part of SMS"; 194 222 195 223 QString txt = text; … … 201 229 posts.insert("CobYouthSMSSenden:txtMessage", txt); 202 230 203 _doPost(posts); 231 try { 232 _doPost(posts); 233 } catch (EException e) { 234 throw EException(tr("A part of the sms could not be sent to all recipients! ") + e.what()); 235 } 204 236 205 237 qDebug() << "Part of SMS sent"; … … 231 263 setProgress(0); 232 264 233 uncancelSendingSMS();234 235 try {236 setStatus(LoginAccount::Status::Login);237 login();238 }catch (...) {239 // TODO240 setStatus(LoginAccount::Status::Error);241 }242 243 _parseMainPage();244 245 QList<QString> longSMSLst = gateway()->splitTextToLongSMS(message);246 QList<QString> shortSMSLst = gateway()->splitTextToShortSMS(message);247 248 int freeSMSNeeded = shortSMSLst.size() * recipients.size();249 if (freeSMSNeeded > freeSMSCount()) {250 throw EException(tr("You have only %1 SMS for free. (You need at least %2 SMS left to send this message!)").arg(freeSMSCount()).arg(freeSMSNeeded));251 }252 253 setProgress(10);254 255 256 int percent_per_sms = 80 / longSMSLst.size();257 258 int x = 0;259 QListIterator<QString> i(longSMSLst);260 while (i.hasNext()) {261 int y = 0;262 263 QSetIterator<IContact*> j(recipients);264 do {265 setStatus(LoginAccount::Status::RemovingRecipients);266 _removeRecipients(); // Remove all recipients267 setProgress(percent_per_sms * 20/100, IncProgress);268 269 270 int recipientsNum = std::min(recipients.size(), (y+1)*MAX_MOBILE);271 setStatus(LoginAccount::Status::AddingRecipients.arg(y*MAX_MOBILE + 1).arg(recipientsNum).arg(recipients.size()));272 273 274 int percent_per_contact = (percent_per_sms * 60/100) / recipientsNum;275 276 int ix = 0;277 while (j.hasNext() && (ix < MAX_MOBILE)) {278 _addRecipient(j.next());279 setProgress(percent_per_contact, IncProgress);280 281 ix++;282 }283 284 setStatus(LoginAccount::Status::SendingSMS.arg(x+1).arg(longSMSLst.size()));285 _sendSMS(i.next());286 setStatus(LoginAccount::Status::SMSSent, percent_per_sms * 20/100, IncProgress);287 288 y++;289 } while ((y * MAX_MOBILE) < recipients.size()); // Repeat this step until the sms is sent to all recipients (if there are more than allowed to be addressed at once)290 291 x++;292 }293 294 _parseMainPage();295 setStatus(LoginAccount::Status::Logout, 90);296 logout();297 298 // TODO: check if sending was cancelled -> set status to "user abort"299 setStatus(LoginAccount::Status::SMSSent, 100);265 uncancelSendingSMS(); 266 267 try { 268 setStatus(LoginAccount::Status::Login); 269 login(); 270 }catch (...) { 271 // TODO 272 setStatus(LoginAccount::Status::Error); 273 } 274 275 _parseMainPage(); 276 277 QList<QString> longSMSLst = gateway()->splitTextToLongSMS(message); 278 QList<QString> shortSMSLst = gateway()->splitTextToShortSMS(message); 279 280 int freeSMSNeeded = shortSMSLst.size() * recipients.size(); 281 if (freeSMSNeeded > freeSMSCount()) { 282 throw EException(tr("You have only %1 SMS for free. (You need at least %2 SMS left to send this message!)").arg(freeSMSCount()).arg(freeSMSNeeded)); 283 } 284 285 setProgress(10); 286 287 288 int percent_per_sms = 80 / longSMSLst.size(); 289 290 int x = 0; 291 QListIterator<QString> i(longSMSLst); 292 while (i.hasNext()) { 293 int y = 0; 294 295 QSetIterator<IContact*> j(recipients); 296 do { 297 setStatus(LoginAccount::Status::RemovingRecipients); 298 _removeRecipients(); // Remove all recipients 299 setProgress(percent_per_sms * 20/100, IncProgress); 300 301 302 int recipientsNum = std::min(recipients.size(), (y+1)*MAX_MOBILE); 303 setStatus(LoginAccount::Status::AddingRecipients.arg(y*MAX_MOBILE + 1).arg(recipientsNum).arg(recipients.size())); 304 305 306 int percent_per_contact = (percent_per_sms * 60/100) / recipientsNum; 307 308 int ix = 0; 309 while (j.hasNext() && (ix < MAX_MOBILE)) { 310 _addRecipient(j.next()); 311 setProgress(percent_per_contact, IncProgress); 312 313 ix++; 314 } 315 316 setStatus(LoginAccount::Status::SendingSMS.arg(x+1).arg(longSMSLst.size())); 317 _sendSMS(i.next()); 318 setStatus(LoginAccount::Status::SMSSent, percent_per_sms * 20/100, IncProgress); 319 320 y++; 321 } while ((y * MAX_MOBILE) < recipients.size()); // Repeat this step until the sms is sent to all recipients (if there are more than allowed to be addressed at once) 322 323 x++; 324 } 325 326 _parseMainPage(); 327 setStatus(LoginAccount::Status::Logout, 90); 328 logout(); 329 330 // TODO: check if sending was cancelled -> set status to "user abort" 331 setStatus(LoginAccount::Status::SMSSent, 100); 300 332 301 333 }catch (EException e) { 302 334 // TODO 303 qDebug() << "An error occured: " + QString::fromLatin1(e.what());335 qDebug() << "An error occured: " + e.what(); 304 336 setStatus(LoginAccount::Status::Error); 305 337 } -
gateways/SwisscomXtraZone/src/ui/vcsettingswidget.cpp
r71 r72 18 18 19 19 void VCSettingsWidget::loadFromAccount(IAccount* account) { 20 BCAccount* account_; 21 try { 22 account_ = dynamic_cast<BCAccount*>(account); 23 } catch (...) { 24 throw new EException("Invalid account given!"); 20 BCAccount* account_ = dynamic_cast<BCAccount*>(account); 21 if (account_ == NULL) { 22 throw EException("Invalid account given!"); 25 23 } 26 24 … … 30 28 31 29 void VCSettingsWidget::saveToAccount(IAccount* account) { 32 BCAccount* account_; 33 try { 34 // TODO: this gives no error... 35 account_ = dynamic_cast<BCAccount*>(account); 36 } catch (...) { 37 throw new EException("Invalid account given!"); 30 BCAccount* account_ = dynamic_cast<BCAccount*>(account); 31 if (account_ == NULL) { 32 throw EException("Invalid account given!"); 38 33 } 39 34 -
lib/libdatatypes/datatypes.pro
r71 r72 46 46 src/abstract/persistence/abstractstorageofficer.h \ 47 47 src/exceptions/eexception.h \ 48 src/exceptions/ehttpreadexception.h \49 48 src/exceptions/elibraryloadexception.h \ 50 49 src/exceptions/eloginaccountloginexception.h \ … … 78 77 src/interfaces/persistence/istorageofficer.h \ 79 78 src/eventmappers/eventinterfaces.h \ 80 src/eventmappers/saccounteventmapper.h \ 79 src/eventmappers/saccounteventmapper.h \ 81 80 src/eventmappers/scontacteventmapper.h \ 82 81 src/eventmappers/sgroupeventmapper.h \ … … 99 98 src/abstract/persistence/abstractloginaccountstorageofficer.cpp \ 100 99 src/abstract/persistence/abstractstorageofficer.cpp \ 100 src/exceptions/eexception.cpp \ 101 101 src/interfaces/iaccount.cpp \ 102 102 src/interfaces/inumber.cpp \ -
lib/libdatatypes/src/abstract/abstractaccount.h
r71 r72 11 11 #include "iaccount.h" 12 12 #include "persistence/istorageofficer.h" 13 14 #include "eventmappers/saccounteventmapper.h"15 13 16 14 class AbstractAccount: public QObject, public IAccount { -
lib/libdatatypes/src/abstract/abstractloginaccount.cpp
r71 r72 19 19 } 20 20 ILoginAccountEvents* AbstractLoginAccount::accountEvents() const { 21 return static_cast< ILoginAccountEvents*>(eventMapper());21 return static_cast<SLoginAccountEventMapper*>(eventMapper()); 22 22 } 23 23 -
lib/libdatatypes/src/abstract/persistence/abstractaccountstorageofficer.cpp
r71 r72 21 21 "); "); 22 22 if (!query.exec()) { 23 throw Storage::EWriteException(tr("Could not create the account table in the database.")); 23 throw Storage::EWriteException(tr("Could not create the account table in the database.")) 24 .addDebugInfo("sql-error", query.lastError().text()); 24 25 } 25 26 } … … 32 33 "WHERE (accountId = '" + QString::number(account()->id()) + "'); "); 33 34 if (!query.next()) { 34 throw Storage::EReadException(tr("No such account in the database! [accountId: %1]").arg(account()->id())); 35 throw Storage::EReadException(tr("No such account in the database!")) 36 .addDebugInfo("accountId", account()->id()); 35 37 } 36 38 … … 56 58 query.bindValue(":gatewayName", account()->gateway()->name()); 57 59 if (!query.exec()) { 58 throw Storage::EWriteException(tr("The account could not have been written to the database.")); 60 throw Storage::EWriteException(tr("The account could not have been written to the database.")) 61 .addDebugInfo("accountId", account()->id()) 62 .addDebugInfo("sql-error", query.lastError().text()); 59 63 } 60 64 … … 64 68 "WHERE (name = '" + account()->name() + "'); "); 65 69 if (!query.next()) { 66 throw Storage::EWriteException(tr("The account could not have been written to the database.")); 70 throw Storage::EWriteException(tr("The account could not have been written to the database.")) 71 .addDebugInfo("accountId", account()->id()) 72 .addDebugInfo("sql-error", query.lastError().text()); 67 73 } 68 74 account()->setId(query.value(0).toInt()); … … 79 85 if (!query.exec()) { 80 86 qCritical() << query.lastError().text(); 81 throw Storage::EWriteException(tr("The account could not have been written to the database.")); 87 throw Storage::EWriteException(tr("The account could not have been written to the database.")) 88 .addDebugInfo("accountId", account()->id()) 89 .addDebugInfo("sql-error", query.lastError().text()); 82 90 } 83 91 } … … 92 100 "WHERE (accountId = '" + QString::number(account()->id()) + "'); "); 93 101 if (!query.exec()) { 94 throw Storage::EWriteException(tr("Could not remove the account from the database.")); 102 throw Storage::EWriteException(tr("Could not remove the account from the database.")) 103 .addDebugInfo("accountId", account()->id()) 104 .addDebugInfo("sql-error", query.lastError().text()); 95 105 } 96 106 -
lib/libdatatypes/src/eventmappers/saccounteventmapper.h
r71 r72 24 24 : account_(account) 25 25 {}; 26 IAccount* account() const { return account_; }26 virtual IAccount* account() const { return account_; } 27 27 28 28 signals: -
lib/libdatatypes/src/eventmappers/scontacteventmapper.h
r71 r72 16 16 17 17 class SContactEventMapper: public QObject, 18 virtualpublic IContactEvents {18 public IContactEvents { 19 19 Q_OBJECT 20 20 Q_INTERFACES(IContactEvents) -
lib/libdatatypes/src/eventmappers/sgroupeventmapper.h
r71 r72 17 17 18 18 class SGroupEventMapper: public QObject, 19 virtualpublic IGroupEvents {19 public IGroupEvents { 20 20 Q_OBJECT 21 21 Q_INTERFACES(IGroupEvents) -
lib/libdatatypes/src/eventmappers/sloginaccounteventmapper.h
r71 r72 20 20 21 21 public: 22 explicit SLoginAccountEventMapper( AbstractLoginAccount* account)23 : SAccountEventMapper( reinterpret_cast<IAccount*>(account)) // Because of circular reference...22 explicit SLoginAccountEventMapper(IAccount* account) // Has to be an instance of AbstractLoginAccount! 23 : SAccountEventMapper(account) 24 24 {}; 25 AbstractLoginAccount* account() const { return reinterpret_cast<AbstractLoginAccount*>(SAccountEventMapper::account()); }26 25 27 26 signals: 28 27 void loggedIn(); 29 28 void loggedOut(); 30 31 private:32 AbstractLoginAccount* account_;33 29 }; 34 30 -
lib/libdatatypes/src/exceptions/eexception.h
r71 r72 9 9 #define EEXCEPTION_H_ 10 10 11 #include <stdexcept> 11 #include <QList> 12 #include <QMap> 12 13 #include <QString> 14 #include <QStringList> 13 15 14 class EException : public std::runtime_error{16 class EException { 15 17 public: 16 explicit EException(const QString& msg) : std::runtime_error(msg.toStdString()) {} 18 EException() 19 : chainedException_(NULL) 20 {}; 21 explicit EException(const QString& msg); 22 ~EException() throw(){}; 23 24 EException addDebugInfo(const QString& value) throw(); 25 EException addDebugInfo(const QString& key, int value) throw(); 26 EException addDebugInfo(const QString& key, const QString& value) throw(); 27 EException addDebugInfos(const QList<QString>& debugInfos) throw(); 28 EException addDebugInfos(const QMap<QString, QString>& debugInfos) throw(); 29 QList<QString> debugInfos() const throw(); 30 31 EException chain(const EException& exception) throw(); 32 EException chainedException() const throw(); 33 34 void setMessage(const QString& msg) throw(); 35 QString what(bool chained = true) const throw(); 36 QString chainedWhat() const throw(); 37 QString unchainedWhat() const throw(); 38 virtual QString toString() const throw(); 39 40 private: 41 QString message_; 42 QStringList debugInfos_; 43 EException* chainedException_; 17 44 }; 18 45 -
lib/libdatatypes/src/exceptions/elibraryloadexception.h
r71 r72 20 20 InvalidLibraryFile, 21 21 VersionMismatch, 22 Other, 22 23 Unknown 23 24 }; 24 25 25 explicit ELoadException(const Purpose& purpose, const QString& message = "") 26 : EException(message) 27 , purpose_ (purpose) 28 {} 26 explicit ELoadException(const QString& message) 27 : purpose_(Other) 28 , msgStr_(message) 29 {}; 30 explicit ELoadException(const Purpose& purpose) 31 : purpose_ (purpose) 32 {}; 29 33 30 Purpose purpose(){ return purpose_; } 34 Purpose purpose() const throw() { return purpose_; } 35 QString toString() const throw() { 36 QString msg = QObject::tr("Loading the library failed: "); 37 switch (purpose()) { 38 case FileNotFound: 39 return msg + QObject::tr("Could not find the file"); 40 case InvalidLibraryFile: 41 return msg + QObject::tr("The given file is no library"); 42 case VersionMismatch: 43 return msg + QObject::tr("The given library has an invalid version"); 44 case Other: 45 return msg + msgStr_; 46 case Unknown: 47 default: 48 return msg + QObject::tr("Unknown error"); 49 } 50 } 31 51 32 52 private: 33 53 Purpose purpose_; 54 QString msgStr_; 34 55 }; 35 56 } -
lib/libdatatypes/src/exceptions/eloginaccountloginexception.h
r71 r72 18 18 public: 19 19 enum Purpose { 20 RequestError, 20 21 InvalidLoginData, 22 Other, 21 23 Unknown 22 24 }; 23 25 26 explicit ELoginException(const QString& msg) { 27 purpose_ = Other; 28 msgStr_ = msg; 29 }; 24 30 explicit ELoginException(const Purpose& purpose) 25 : EException("") 26 , purpose_(purpose) 27 {} 31 : purpose_(purpose) 32 {}; 28 33 29 explicit ELoginException(const Purpose& purpose, const QString& msg) 30 : EException(msg) 31 , purpose_ (purpose) 32 {} 34 Purpose purpose() const throw() { return purpose_; } 33 35 34 Purpose purpose(){ return purpose_; } 36 QString toString() const throw() { 37 QString msg = QObject::tr("Login failed: "); 38 switch (purpose()) { 39 case RequestError: 40 return msg + QObject::tr("Request error"); 41 case InvalidLoginData: 42 return msg + QObject::tr("Your login data might be wrong"); 43 case Other: 44 return msg + msgStr_; 45 case Unknown: 46 default: 47 return msg + QObject::tr("Unknown error"); 48 } 49 } 35 50 36 51 private: 37 52 Purpose purpose_; 53 QString msgStr_; 38 54 }; 39 55 } -
lib/libdatatypes/src/exceptions/httpexceptions.h
r71 r72 6 6 */ 7 7 8 #include "ehttpreadexception.h" 8 9 #include "eexception.h" 10 11 #include <QList> 12 #include <QSslError> 13 14 namespace Http { 15 class EReadException: public EException { 16 public: 17 explicit EReadException(const QString& msg) : EException(msg) {} 18 }; 19 20 class ESSLException: public EException { 21 public: 22 explicit ESSLException(const QList<QSslError>& errors) 23 : EException("") 24 , errors_(errors) 25 { 26 QString errorMsg = QObject::tr("SSL-Errors: "); 27 foreach (QSslError error, errors) { 28 errorMsg += error.errorString() + '\n'; 29 } 30 errorMsg.left(errorMsg.length()-1); 31 32 EException::setMessage(errorMsg); 33 } 34 35 QList<QSslError> sslErrors() const { return errors_; } 36 37 private: 38 QList<QSslError> errors_; 39 }; 40 } -
lib/libdatatypes/src/interfaces/iaccount.h
r71 r72 16 16 #include "ivalidatable.h" 17 17 18 #include "eventmappers/saccounteventmapper.h" 19 18 20 class IContact; 19 21 class IGateway; 20 class SAccountEventMapper;21 22 22 23 namespace Account { … … 81 82 #include "icontact.h" 82 83 #include "igateway.h" 83 #include "eventmappers/saccounteventmapper.h"84 84 85 85 #endif /* IACCOUNT_H_ */ -
lib/libdatatypes/src/shttphelper.cpp
r71 r72 6 6 #include <QThread> 7 7 #include <QUrl> 8 9 #include "exceptions/httpexceptions.h"10 8 11 9 SHttpHelper::SHttpHelper() { … … 50 48 } 51 49 52 QString SHttpHelper::get(const QString& destination, const QMap<QString, QString>& requests /* = QMap<QString, QString>() */) {50 bool SHttpHelper::get(const QString& destination, QString& requestResult, const QMap<QString, QString>& requests /* = QMap<QString, QString>() */) { 53 51 waitForRequest(false); // Wait until a running request has been finished 54 52 55 53 startRequest("GET", destination, requests, QMap<QString, QString>()); 56 54 waitForRequest(); 57 return getRequestResult(); 58 } 59 60 QString SHttpHelper::post(const QString& destination, const QMap<QString, QString>& requests /* = QMap<QString, QString>() */, 55 requestResult = this->requestResult(); 56 57 return !errorOccured(); 58 } 59 60 bool SHttpHelper::post(const QString& destination, QString& requestResult, const QMap<QString, QString>& requests /* = QMap<QString, QString>() */, 61 61 const QMap<QString, QString>& posts /* = QMap<QString, QString>() */) 62 62 { … … 65 65 startRequest("POST", destination, requests, posts); 66 66 waitForRequest(); 67 return getRequestResult(); 67 requestResult = this->requestResult(); 68 69 return !errorOccured(); 68 70 } 69 71 … … 71 73 const QMap<QString, QString>& posts /* = QMap<QString, QString>() */) 72 74 { 73 requestResult_ = ""; 75 requestResult_ = ""; 76 requestHadError_ = false; 77 lastError_ = EException(""); 74 78 75 79 QUrl url_ = QUrl(destination); … … 142 146 } 143 147 144 /*bool HttpAccountHelper::isRequestFinished(const int& requestId) const {145 return finishedRequests_.contains(requestId);146 }*/147 148 148 void SHttpHelper::waitForRequest(bool createLoopIfNotExisting) { 149 149 if (!requestLoop_.isRunning() && !createLoopIfNotExisting){ … … 152 152 153 153 qDebug() << "Waiting for the request to finish..."; 154 while (!request_.finished && thread()->isRunning()) {155 thread()->wait(100);156 }157 154 /* while (!request_.finished && thread()->isRunning()) { 158 155 thread()->wait(100); 159 156 }*/ 160 // requestLoop_.exec(QEventLoop::ExcludeUserInputEvents|QEventLoop::ExcludeSocketNotifiers|QEventLoop::WaitForMoreEvents);157 requestLoop_.exec(QEventLoop::WaitForMoreEvents/*QEventLoop::ExcludeUserInputEvents|QEventLoop::ExcludeSocketNotifiers|QEventLoop::WaitForMoreEvents*/); 161 158 qDebug() << "The request finished -> continuing"; 162 159 /* while (!request_.finished) { … … 168 165 } 169 166 170 QString SHttpHelper:: getRequestResult() const {167 QString SHttpHelper::requestResult() const { 171 168 return requestResult_; 172 169 } 170 bool SHttpHelper::errorOccured() const { 171 return requestHadError_; 172 } 173 EException SHttpHelper::lastError() const { 174 return lastError_; 175 } 176 QString SHttpHelper::lastErrorStr() const { 177 return lastError_.toString(); 178 } 179 180 void SHttpHelper::errorOccured(int httpRequestId, const EException& exception) { 181 if (httpRequestId != request_.httpRequestId) { 182 qWarning() << "Request [" + QString::number(httpRequestId) + "] finished with an error (it is ignored, since this request is detached): " + exception.what(); 183 return; 184 } 185 186 requestHadError_ = true; 187 lastError_ = exception; 188 qWarning() << "Request [" + QString::number(httpRequestId) + "] finished with an error: " + lastError().what(); 189 } 173 190 174 191 void SHttpHelper::responseHeaderReceived(const QHttpResponseHeader& responseHeader) { 175 //qDebug() << responseHeader.statusCode() << " " << responseHeader.reasonPhrase();176 //qDebug() << responseHeader.values();192 if (http()->currentId() != request_.httpRequestId) 193 return; 177 194 178 195 switch (responseHeader.statusCode()) { … … 187 204 188 205 request_.httpRequestId = -1; // To avoid error in httpRequestFinished 189 http_->abort();190 206 191 207 // Since the responseHeaderReceived-Slot could eventually not be called yet in cookieManager -> this would lead to a wrong header in doRequest 192 208 cookieManager_->processResponseHeader(responseHeader); 193 209 194 //cookiemanager has not handled the response yet...195 210 doRequest(responseHeader.value("location")); // Do the redirect 196 211 break; 197 212 198 213 default: 199 throw Http::EReadException("Unknown response code!"); 214 errorOccured(http_->currentId(), Http::EReadException(tr("Unknown response code"))); 215 http()->abort(); 200 216 break; 201 217 } … … 208 224 } 209 225 210 qDebug() << "Quitting request loop";211 requestLoop_.quit();212 226 request_.finished = true; 213 214 227 if (error) { 215 qDebug() << "Request [" + QString::number(httpRequestId) + "] finished with an error: " + http_->errorString(); 216 throw Http::EReadException(http_->errorString()); // TODO: Perhaps this error has to be thrown in the waitForRequest by passing a status value to requestLoop_.exit() 228 errorOccured(httpRequestId, Http::EReadException(http_->errorString())); 217 229 } else { 218 230 qDebug() << "Request [" + QString::number(httpRequestId) + "] finished"; 219 requestResult_ = /*request.buffer.readAll()*/ http_->readAll(); 220 //qDebug() << requestResult_; 231 requestResult_ = http_->readAll(); 221 232 } 222 223 requestLoop_. processEvents();233 qDebug() << "Quitting request loop"; 234 requestLoop_.exit(errorOccured() ? 1 : 0); 224 235 } 225 236 226 237 void SHttpHelper::sslErrors(const QList<QSslError>& errors) { 227 QListIterator<QSslError> i(errors); 228 while (i.hasNext()){ 229 QSslError err = i.next(); 230 qDebug() << "SSL-error: " + err.errorString(); 231 } 232 } 238 errorOccured(http()->currentId(), Http::ESSLException(errors)); 239 } -
lib/libdatatypes/src/shttphelper.h
r71 r72 16 16 17 17 #include <iaccount.h> 18 #include "exceptions/httpexceptions.h" 18 19 19 20 #include "shttpcookiemanager.h" … … 41 42 ~SHttpHelper(); 42 43 43 virtual QHttp*http() const;44 virtual SHttpCookieManager*cookieManager() const;44 QHttp* http() const; 45 SHttpCookieManager* cookieManager() const; 45 46 46 virtual QString get(const QString& destination, const QMap<QString, QString>& requests = (QMap<QString, QString>())); 47 virtual QString post(const QString& destination, const QMap<QString, QString>& requests = (QMap<QString, QString>()), const QMap<QString, QString>& posts = (QMap<QString, QString>())); 47 bool get(const QString& destination, QString& requestResult, const QMap<QString, QString>& requests = (QMap<QString, QString>())); 48 bool post(const QString& destination, QString& requestResult, const QMap<QString, QString>& requests = (QMap<QString, QString>()), const QMap<QString, QString>& posts = (QMap<QString, QString>())); 49 50 bool errorOccured() const; 51 EException lastError() const; 52 QString lastErrorStr() const; 48 53 49 54 protected: 50 55 virtual QHttpRequestHeader defaultHeader(const QUrl& url) const; 51 52 virtual void startRequest(const QString& method, const QString& destination, const QMap<QString, QString>& requests = (QMap<QString, QString>()), const QMap<QString, QString>& posts = (QMap<QString, QString>()));53 virtual int doRequest(const QString& destination);54 //virtual bool isRequestFinished() const;55 virtual void waitForRequest(bool createIfNotExisting = true);56 virtual QString getRequestResult() const;57 56 58 57 private: … … 60 59 QHttpRequestHeader* defaultHeader_; 61 60 62 SHttpCookieManager* 61 SHttpCookieManager* cookieManager_; 63 62 64 SHttpRequest request_; 63 SHttpRequest request_; 64 QEventLoop requestLoop_; 65 65 QString requestResult_; 66 QEventLoop requestLoop_; 66 bool requestHadError_; 67 EException lastError_; 67 68 68 69 QString getParamStr(const QMap<QString, QString>& params); 70 QString requestResult() const; 71 void startRequest(const QString& method, const QString& destination, const QMap<QString, QString>& requests = (QMap<QString, QString>()), const QMap<QString, QString>& posts = (QMap<QString, QString>())); 72 int doRequest(const QString& destination); 73 void waitForRequest(bool createIfNotExisting = true); 74 75 void errorOccured(int requestId, const EException& exception); 69 76 70 77 private slots: -
lib/libdatatypes/src/snumber.cpp
r71 r72 42 42 } 43 43 SNumber::SNumber(const SNumber& other) { 44 fromString(other.toString("ccaaau"), "ccaaau");44 setNumber(other.toString("ccaaau"), "ccaaau"); 45 45 } 46 46 … … 75 75 if (format == SNumber::GuessFormat) { 76 76 QStringList formats; 77 formats.append("ccaaau"); // 410792436866 77 78 formats.append("'+'cc' 'aaa' 'u");// +41 079 1234567 78 79 formats.append("'+'cc' 'aa' 'u"); // +41 79 1234567 -
src/business/BCAccountLoadManager.cpp
r36 r72 26 26 27 27 BCAccountLoadThread* alt = i.value(); 28 QObject::disconnect(alt, SIGNAL(loadStateChanged(IAccount*, AccountLoadState)),29 30 QObject::disconnect(alt, SIGNAL(loaded(IAccount*)),31 32 QObject::disconnect(alt, SIGNAL(loadingFinished(IAccount*, AccountLoadState)),33 34 QObject::disconnect(alt, SIGNAL(loadingFailed(IAccount*, EException*)),35 this, SLOT(accountLoadThreadLoadingFailed(IAccount*, EException*)));28 disconnect(alt, SIGNAL(loadStateChanged(IAccount*, AccountLoadState)), 29 this, SLOT(accountLoadThreadLoadStateChanged(IAccount*, AccountLoadState))); 30 disconnect(alt, SIGNAL(loaded(IAccount*)), 31 this, SLOT(accountLoadThreadLoaded(IAccount*))); 32 disconnect(alt, SIGNAL(loadingFinished(IAccount*, AccountLoadState)), 33 this, SLOT(accountLoadThreadLoadingFinished(IAccount*, AccountLoadState))); 34 disconnect(alt, SIGNAL(loadingFailed(IAccount*, const EException&)), 35 this, SLOT(accountLoadThreadLoadingFailed(IAccount*, const EException&))); 36 36 delete alt; 37 37 } … … 76 76 if (!accountLoadThreads_.contains(account)) { 77 77 BCAccountLoadThread* alt = new BCAccountLoadThread(account); 78 QObject::connect(alt, SIGNAL(loadStateChanged(IAccount*, AccountLoadState)),79 80 QObject::connect(alt, SIGNAL(loaded(IAccount*)),81 82 QObject::connect(alt, SIGNAL(loadingFinished(IAccount*, AccountLoadState)),83 84 QObject::connect(alt, SIGNAL(loadingFailed(IAccount*, EException*)),85 this, SLOT(accountLoadThreadLoadingFailed(IAccount*, EException*)));78 connect(alt, SIGNAL(loadStateChanged(IAccount*, AccountLoadState)), 79 this, SLOT(accountLoadThreadLoadStateChanged(IAccount*, AccountLoadState))); 80 connect(alt, SIGNAL(loaded(IAccount*)), 81 this, SLOT(accountLoadThreadLoaded(IAccount*))); 82 connect(alt, SIGNAL(loadingFinished(IAccount*, AccountLoadState)), 83 this, SLOT(accountLoadThreadLoadingFinished(IAccount*, AccountLoadState))); 84 connect(alt, SIGNAL(loadingFailed(IAccount*, const EException&)), 85 this, SLOT(accountLoadThreadLoadingFailed(IAccount*, const EException&))); 86 86 87 87 accountLoadThreads_.insert(account, alt); … … 93 93 94 94 void BCAccountLoadManager::accountLoadThreadLoadStateChanged(IAccount* account, AccountLoadState state) { 95 accountLoadStateChanged(account, state);95 emit accountLoadStateChanged(account, state); 96 96 } 97 97 void BCAccountLoadManager::accountLoadThreadLoaded(IAccount* account) { 98 accountLoaded(account);98 emit accountLoaded(account); 99 99 } 100 100 void BCAccountLoadManager::accountLoadThreadLoadingFinished(IAccount* account, AccountLoadState state) { 101 accountLoadingFinished(account, state);101 emit accountLoadingFinished(account, state); 102 102 } 103 void BCAccountLoadManager::accountLoadThreadLoadingFailed(IAccount* account, EException*exception) {104 accountLoadingFailed(account, exception);103 void BCAccountLoadManager::accountLoadThreadLoadingFailed(IAccount* account, const EException& exception) { 104 emit accountLoadingFailed(account, exception); 105 105 } -
src/business/BCAccountLoadManager.h
r71 r72 34 34 void accountLoaded(IAccount* account); 35 35 void accountLoadingFinished(IAccount* account, AccountLoadState state); 36 void accountLoadingFailed(IAccount* account, EException*exception);36 void accountLoadingFailed(IAccount* account, const EException& exception); 37 37 38 38 protected: … … 46 46 void accountLoadThreadLoaded(IAccount* account); 47 47 void accountLoadThreadLoadingFinished(IAccount* account, AccountLoadState state); 48 void accountLoadThreadLoadingFailed(IAccount* account, EException*exception);48 void accountLoadThreadLoadingFailed(IAccount* account, const EException& exception); 49 49 50 50 -
src/business/BCAccountLoadThread.cpp
r67 r72 23 23 try { 24 24 account_->initialize(); 25 } catch (EException * exception) {25 } catch (EException e) { 26 26 setLoadState(Failed); 27 emit loadingFailed(account(), exception); // Signal27 emit loadingFailed(account(), EException(tr("Initializing account failed")).chain(e)); // Signal 28 28 } catch (...) { 29 29 setLoadState(Failed); 30 emit loadingFailed(account(), newEException("Unknown error occured while loading an account.")); // Signal30 emit loadingFailed(account(), EException("Unknown error occured while loading an account.")); // Signal 31 31 } 32 32 -
src/business/BCAccountLoadThread.h
r71 r72 34 34 void loaded(IAccount* account); 35 35 void loadingFinished(IAccount* account, AccountLoadState state); 36 void loadingFailed(IAccount* account, EException*exception);36 void loadingFailed(IAccount* account, const EException& exception); 37 37 38 38 -
src/business/BCAccountManager.cpp
r71 r72 9 9 10 10 #include "../persistence/PersistenceFactory.h" 11 12 #include <QDebug> 11 13 12 14 BCAccountManager* BCAccountManager::instance_=0; … … 100 102 } 101 103 void BCAccountManager::accountDataChanged() { 102 SAccountEventMapper* eventMapper = static_cast<SAccountEventMapper*>(sender()); //TODO: this is wrong... (sender() is not the eventManager)104 SAccountEventMapper* eventMapper = qobject_cast<SAccountEventMapper*>(sender()); //TODO: this is wrong... (sender() is not the eventManager) 103 105 IAccount* account = eventMapper->account(); 104 106 Q_ASSERT(account); -
src/business/BCLibraryLoader.cpp
r71 r72 38 38 } 39 39 40 QLibrary library; 41 library.setLoadHints(QLibrary::ResolveAllSymbolsHint | QLibrary::ExportExternalSymbolsHint); 42 library.setFileName(filename); 40 try { 41 QLibrary library; 42 library.setLoadHints(QLibrary::ResolveAllSymbolsHint | QLibrary::ExportExternalSymbolsHint); 43 library.setFileName(filename); 43 44 44 typedef ILibrary* (*GetLibraryFunc)(); 45 GetLibraryFunc getLibrary = (GetLibraryFunc)library.resolve("getLibrary"); 46 if (getLibrary) { 47 ILibrary* lib = getLibrary(); 48 if (lib != NULL) { 49 libraries_.insert(filename, lib); 50 IGateway* gateway = lib->getGateway(); 51 if (gateway != NULL) { 52 gateways_.insert(lib, gateway); 45 typedef ILibrary* (*GetLibraryFunc)(); 46 GetLibraryFunc getLibrary = (GetLibraryFunc)library.resolve("getLibrary"); 47 if (getLibrary) { 48 ILibrary* lib = getLibrary(); 49 if (lib != NULL) { 50 libraries_.insert(filename, lib); 51 IGateway* gateway = lib->getGateway(); 52 if (gateway != NULL) { 53 gateways_.insert(lib, gateway); 54 } 55 56 return lib; 57 } else { 58 qWarning() << "The library could not have been loaded: The returned library object was NULL"; 53 59 } 54 55 return lib;56 60 } else { 57 qWarning() << "The library could not have been loaded: The returned library object was NULL";61 qWarning() << "The library could not have been loaded: " + library.errorString(); 58 62 } 59 } else { 60 qWarning() << "The library could not have been loaded: " + library.errorString(); 63 } catch (EException e) { 64 throw EException(tr("Could not load the library")) 65 .addDebugInfo("filename", filename) 66 .chain(e); 61 67 } 62 68 return NULL; -
src/persistence/storage/DAAccountListManager.cpp
r71 r72 30 30 "WHERE (accountId = '" + QString::number(accountId) + "'); "); 31 31 if (!query.next()) { 32 throw Storage::EReadException(tr("No such account in the database! [accountId: %1]").arg(accountId)); 32 throw Storage::EReadException(tr("No such account in the database!")) 33 .addDebugInfo("accountId", accountId); 33 34 } 34 35 -
src/persistence/storage/DAStorage.cpp
r71 r72 40 40 if (!dbConnection_.open()) { 41 41 qCritical() << dbConnection_.lastError().text(); 42 throw Storage::EReadException(tr("Can't open the database!")) ;43 }44 45 bool somethingFailed = false; 42 throw Storage::EReadException(tr("Can't open the database!")) 43 .addDebugInfo("sql-error", dbConnection_.lastError().text()); 44 } 45 46 46 QSqlQuery query; 47 somethingFailed |= !query.exec("CREATE TABLE IF NOT EXISTS t_contacts (" 48 "contactId INTEGER PRIMARY KEY AUTOINCREMENT, " 49 "name TEXT NOT NULL UNIQUE, " 50 "number TEXT NOT NULL UNIQUE " 51 "); "); 52 somethingFailed |= !query.exec("CREATE TABLE IF NOT EXISTS t_groups (" 53 "groupId INTEGER PRIMARY KEY AUTOINCREMENT, " 54 "name TEXT NOT NULL UNIQUE " 55 "); "); 56 somethingFailed |= !query.exec("CREATE TABLE IF NOT EXISTS t_settings (" 57 "namespace TEXT NOT NULL, " 58 "key TEXT NOT NULL, " 59 "value BLOB, " 60 "PRIMARY KEY(namespace, key) " 61 "); "); 62 63 if (somethingFailed) { 64 throw Storage::EWriteException(tr("Could not write the table definitions to the database.")); 47 try { 48 if (!query.exec("CREATE TABLE IF NOT EXISTS t_contacts (" 49 "contactId INTEGER PRIMARY KEY AUTOINCREMENT, " 50 "name TEXT NOT NULL UNIQUE, " 51 "number TEXT NOT NULL UNIQUE " 52 "); ")) { 53 throw EException(query.lastError().text()); 54 } 55 if (!query.exec("CREATE TABLE IF NOT EXISTS t_groups (" 56 "groupId INTEGER PRIMARY KEY AUTOINCREMENT, " 57 "name TEXT NOT NULL UNIQUE " 58 "); ")) { 59 throw EException(query.lastError().text()); 60 } 61 if (!query.exec("CREATE TABLE IF NOT EXISTS t_settings (" 62 "namespace TEXT NOT NULL, " 63 "key TEXT NOT NULL, " 64 "value BLOB, " 65 "PRIMARY KEY(namespace, key) " 66 "); ")) { 67 throw EException(query.lastError().text()); 68 } 69 } catch (EException e) { 70 throw Storage::EWriteException(tr("Could not write the table definitions to the database")) 71 .addDebugInfo("sql-error", e.unchainedWhat()); 65 72 } 66 73 } … … 133 140 "WHERE (contactId = '" + QString::number(contactId) + "'); "); 134 141 if (!query.next()) { 135 throw Storage::EReadException(tr("No such contact in the database! [contactId: %1]").arg(contactId)); 142 throw Storage::EReadException(tr("No such contact in the database!")) 143 .addDebugInfo("contactId", QString::number(contactId)) 144 .addDebugInfo("sql-error", query.lastError().text()); 136 145 } 137 146 … … 156 165 "WHERE (groupId = '" + QString::number(groupId) + "'); "); 157 166 if (!query.next()) { 158 throw Storage::EReadException(tr("No such group in the database! [groupId: %1]").arg(groupId)); 167 throw Storage::EReadException(tr("No such group in the database!")) 168 .addDebugInfo("groupId", QString::number(groupId)) 169 .addDebugInfo("sql-error", query.lastError().text()); 159 170 } 160 171 … … 234 245 235 246 if (!query.exec()) { 236 throw Storage::EWriteException(tr("Could not write setting to the database.")); 247 throw Storage::EWriteException(tr("Could not write setting to the database.")) 248 .addDebugInfo("namespace", _namespace) 249 .addDebugInfo("key", key) 250 .addDebugInfo("value", value.toString()) 251 .addDebugInfo("sql-error", query.lastError().text()); 237 252 } 238 253 … … 255 270 256 271 if (x > 10) { 257 throw Storage::EWriteException(tr("Could not write an encrypted string to the database. [%1, %2]").arg(_namespace).arg(key)); 272 throw Storage::EWriteException(tr("Could not write an encrypted string to the database - maximum attemps reached.")) 273 .addDebugInfo("namespace", _namespace) 274 .addDebugInfo("key", key); 258 275 } 259 276 … … 294 311 query.bindValue(":number", contact->number().toString()); 295 312 if (!query.exec()) { 296 throw Storage::EWriteException(tr("The contact could not have been written to the database.")); 313 throw Storage::EWriteException(tr("The contact could not have been written to the database.")) 314 .addDebugInfo("contactId", contact->id()) 315 .addDebugInfo("sql-error", query.lastError().text()); 297 316 } 298 317 … … 302 321 "WHERE (name = '" + contact->name() + "'); "); 303 322 if (!query.next()) { 304 throw Storage::EWriteException(tr("The contact could not have been written to the database.")); 323 throw Storage::EWriteException(tr("The contact could not have been written to the database.")) 324 .addDebugInfo("contactId", contact->id()) 325 .addDebugInfo("sql-error", query.lastError().text()); 305 326 } 306 327 contact->setId(query.value(0).toInt()); … … 316 337 317 338 if (!query.exec()) { 318 throw Storage::EWriteException(tr("The contact could not have been written to the database.")); 339 throw Storage::EWriteException(tr("The contact could not have been written to the database.")) 340 .addDebugInfo("contactId", contact->id()) 341 .addDebugInfo("sql-error", query.lastError().text()); 319 342 } 320 343 } … … 346 369 query.bindValue(":name", group->name()); 347 370 if (!query.exec()) { 348 throw Storage::EWriteException(tr("The group could not have been written to the database.")); 371 throw Storage::EWriteException(tr("The group could not have been written to the database.")) 372 .addDebugInfo("groupId", group->id()) 373 .addDebugInfo("sql-error", query.lastError().text()); 349 374 } 350 375 … … 354 379 "WHERE (name = '" + group->name() + "'); "); 355 380 if (!query.next()) { 356 throw Storage::EWriteException(tr("The group could not have been written to the database.")); 381 throw Storage::EWriteException(tr("The group could not have been written to the database.")) 382 .addDebugInfo("groupId", group->id()) 383 .addDebugInfo("sql-error", query.lastError().text()); 357 384 } 358 385 group->setId(query.value(0).toInt()); … … 366 393 367 394 if (!query.exec()) { 368 throw Storage::EWriteException(tr("The group could not have been written to the database.")); 395 throw Storage::EWriteException(tr("The group could not have been written to the database.")) 396 .addDebugInfo("groupId", group->id()) 397 .addDebugInfo("sql-error", query.lastError().text()); 369 398 } 370 399 } … … 395 424 "AND (key = '" + key + "'); "); 396 425 if (!query.exec()) { 397 throw Storage::EWriteException(tr("Could not remove the setting from the database.")); 426 throw Storage::EWriteException(tr("Could not remove the setting from the database.")) 427 .addDebugInfo("namespace", _namespace) 428 .addDebugInfo("key", key) 429 .addDebugInfo("sql-error", query.lastError().text()); 398 430 } 399 431 } … … 404 436 "WHERE (namespace = '" + _namespace + "'); "); 405 437 if (!query.exec()) { 406 throw Storage::EWriteException(tr("Could not remove the settings from the database.")); 438 throw Storage::EWriteException(tr("Could not remove the settings from the database.")) 439 .addDebugInfo("namespace", _namespace) 440 .addDebugInfo("sql-error", query.lastError().text()); 407 441 } 408 442 } … … 419 453 "WHERE (contactId = '" + QString::number(contactId) + "'); "); 420 454 if (!query.exec()) { 421 throw; 422 } 423 } catch (...) { 424 throw Storage::EWriteException(tr("Could not remove the contact from the database.")); 455 throw EException(query.lastError().text()); 456 } 457 } catch (EException e) { 458 throw Storage::EWriteException(tr("Could not remove the contact from the database")) 459 .addDebugInfo("contactId", contactId) 460 .chain(e); 425 461 } 426 462 } … … 436 472 "WHERE (groupId = '" + QString::number(groupId) + "'); "); 437 473 if (!query.exec()) { 438 throw; 439 } 440 } catch (...) { 441 throw Storage::EWriteException(tr("Could not remove the group from the database.")); 442 } 443 } 474 throw EException(query.lastError().text()); 475 } 476 } catch (EException e) { 477 throw Storage::EWriteException(tr("Could not remove the group from the database")) 478 .addDebugInfo("groupId", groupId) 479 .chain(e); 480 } 481 } -
src/ui/VCAccountList/vcaccountlist.cpp
r56 r72 6 6 7 7 #include "../VCEditAccount/vceditaccount.h" 8 9 #include "../UIHelper.h"10 8 11 9 #include <inumber.h> -
src/ui/VCAddressBook/vcaddressbook.cpp
r71 r72 8 8 #include "../VCEditContact/vceditcontact.h" 9 9 #include "../VCEditGroup/vceditgroup.h" 10 11 #include "../UIHelper.h"12 10 13 11 #include <scontact.h> -
src/ui/VCEditContact/vceditcontact.cpp
r56 r72 9 9 #include <QStringList> 10 10 #include <QSortFilterProxyModel> 11 12 #include "../UIHelper.h"13 11 14 12 #include <snumber.h> -
src/ui/VCEditGroup/vceditgroup.cpp
r43 r72 2 2 3 3 #include "../../business/BCContactManager.h" 4 5 #include "../UIHelper.h"6 4 7 5 #include <QFileDialog> -
src/ui/VCMain/vcmain.cpp
r71 r72 19 19 #include "../../business/BCContactManager.h" 20 20 #include "../../business/BCGroupManager.h" 21 22 #include "../UIHelper.h"23 21 24 22 #include "../VCAccountList/vcaccountlist.h" … … 45 43 accountFilterModel_->sort(AccountTreeModel::ColName, Qt::AscendingOrder); 46 44 ui.lstAccounts->setModel(accountFilterModel_); 45 ui.lstAccounts->setModelColumn(AccountTreeModel::ColGatewayName); 47 46 48 47 /* Contact / Groups */ … … 75 74 connect(BCAccountLoadManager::instance(), SIGNAL(accountLoaded(IAccount*)), 76 75 this, SLOT(on_accountLoaded(IAccount*))); 77 connect(BCAccountLoadManager::instance(), SIGNAL(accountLoadingFailed(IAccount*, EException*)),78 this, SLOT(on_accountLoadingFailed(IAccount*, EException*)));76 connect(BCAccountLoadManager::instance(), SIGNAL(accountLoadingFailed(IAccount*, const EException&)), 77 this, SLOT(on_accountLoadingFailed(IAccount*, const EException&))); 79 78 80 79 … … 95 94 IContact* VCMain::getContactOfNode(const QTreeWidgetItem* node){ 96 95 if (!isContactNode(node)){ 97 return (IContact*)0;96 return NULL; 98 97 } else { 99 98 return nodeToContact[const_cast<QTreeWidgetItem*>(node)]; … … 102 101 IGroup* VCMain::getGroupOfNode(const QTreeWidgetItem* node){ 103 102 if (!isGroupNode(node)){ 104 return (IGroup*)0;103 return NULL; 105 104 } else { 106 105 return nodeToGroup[const_cast<QTreeWidgetItem*>(node)]; … … 397 396 398 397 void VCMain::on_accountLoaded(IAccount* account) { 398 Q_UNUSED(account); 399 enableSendBtnIfAllFilled(); 400 } 401 402 void VCMain::on_accountLoadingFailed(IAccount* account, const EException& exception) { 403 QMessageBox::critical(this, tr("Error occured"), 404 tr("An error occured while loading an account: ") + "\n\n" 405 + tr("Account-Id: ") + account->id() + "\n" 406 + exception.chainedWhat(), QMessageBox::Ok, QMessageBox::Ok); 399 407 reloadAccountList(); 400 408 } 401 409 402 void VCMain::on_accountLoadingFailed(IAccount* account, EException* exception) {403 QMessageBox::critical(this, tr("Error occured"), tr("An unknown error has occured!") + "\n\n" + QString(exception->what()), QMessageBox::Ok, QMessageBox::Ok);404 reloadAccountList();405 }406 -
src/ui/VCMain/vcmain.h
r60 r72 85 85 void on_accountLoadStateChanged(IAccount* account, AccountLoadState state); 86 86 void on_accountLoaded(IAccount* account); 87 void on_accountLoadingFailed(IAccount* account, EException*exception);87 void on_accountLoadingFailed(IAccount* account, const EException& exception); 88 88 }; 89 89 -
src/ui/models/accounttreemodel.cpp
r67 r72 32 32 33 33 QModelIndex idx_start = index(row, 0); 34 QModelIndex idx_end = index(row, columnCount() );34 QModelIndex idx_end = index(row, columnCount()-1); 35 35 36 36 if (idx_start.isValid() && idx_end.isValid()) { -
src/ui/models/loadedaccountmodel.cpp
r67 r72 14 14 const QModelIndex& idx = srcModel->index(source_row, 0, source_parent); 15 15 if (idx.isValid()) { 16 IAccount* account 16 IAccount* account = srcModel->dataObject(idx); 17 17 18 18 return (account != NULL) && account->isInitialized() && account->isEnabled();
Note: See TracChangeset
for help on using the changeset viewer.