Changeset 72:fc91522ef9be in SMSSender


Ignore:
Timestamp:
Feb 9, 2010 9:47:21 PM (9 years ago)
Author:
Sämy Zehnder <saemy.zehnder@…>
Branch:
3.0
Convert:
svn:3639001d-8e34-449c-bb86-3782b86c4877/branches/3.0@71
Message:
  • Started exception handling
  • Fixed several bugs from the removal of the iloginaccount gateway
Files:
1 added
1 deleted
34 edited

Legend:

Unmodified
Added
Removed
  • gateways/SwisscomXtraZone/src/business/BCAccount.cpp

    r71 r72  
    8383    posts.insert("isiwebpasswd", password());
    8484
    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    }
    8688
    8789    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());
    8991    }
    9092
    9193    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());
    9395    }
    9496
     
    99101    qDebug() << "Starting logout";
    100102
    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    }
    102108    httpHelper_->cookieManager()->clearCookies();
    103109
     
    108114    qDebug() << "Starting still-logged-in-check";
    109115
    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);
    111125
    112126    qDebug() << "Ended still-logged-in-check";
     
    128142    }
    129143
    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    }
    131147
    132148    rx.setPattern("<span.*id=\"CobYouthSMSSenden_lblErrorBox\".*>(.*)</span>");
     
    145161    BCGateway* gtwy = static_cast<BCGateway*>(gateway());
    146162
    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());
    164184    }
    165185    setFreeSMSCount(rx.cap(1).toInt());
     
    173193    posts.insert("CobYouthSMSSenden:RecipientsDG:_ctl2:_ctl0", "");
    174194
    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());
    177201    }
    178202    qDebug() << "Recipients removed";
     
    186210    posts.insert("CobYouthSMSSenden:txtNewReceiver", recipient->number().toString("aaau"));
    187211
    188     _doPost(posts);
     212    try {
     213        _doPost(posts);
     214    } catch (EException e) {
     215        throw EException(tr("Could not add a recipient: ") + e.what());
     216    }
    189217    qDebug() << "Recipient added";
    190218}
    191219
    192220void BCAccount::_sendSMS(const QString& text) {
    193     qDebug() << "Starting sending part of SMS";
     221    qDebug() << "Start of sending part of SMS";
    194222
    195223    QString txt = text;
     
    201229    posts.insert("CobYouthSMSSenden:txtMessage", txt);
    202230
    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    }
    204236
    205237    qDebug() << "Part of SMS sent";
     
    231263        setProgress(0);
    232264
    233     uncancelSendingSMS();
    234 
    235     try {
    236         setStatus(LoginAccount::Status::Login);
    237         login();
    238     }catch (...) {
    239         // TODO
    240         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 recipients
    267             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);
    300332
    301333    }catch (EException e) {
    302334        // TODO
    303         qDebug() << "An error occured: " + QString::fromLatin1(e.what());
     335        qDebug() << "An error occured: " + e.what();
    304336        setStatus(LoginAccount::Status::Error);
    305337    }
  • gateways/SwisscomXtraZone/src/ui/vcsettingswidget.cpp

    r71 r72  
    1818
    1919void 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!");
    2523    }
    2624
     
    3028
    3129void 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!");
    3833    }
    3934
  • lib/libdatatypes/datatypes.pro

    r71 r72  
    4646    src/abstract/persistence/abstractstorageofficer.h \
    4747    src/exceptions/eexception.h \
    48     src/exceptions/ehttpreadexception.h \
    4948    src/exceptions/elibraryloadexception.h \
    5049    src/exceptions/eloginaccountloginexception.h \
     
    7877    src/interfaces/persistence/istorageofficer.h \
    7978    src/eventmappers/eventinterfaces.h \
    80     src/eventmappers/saccounteventmapper.h \   
     79    src/eventmappers/saccounteventmapper.h \
    8180    src/eventmappers/scontacteventmapper.h \
    8281    src/eventmappers/sgroupeventmapper.h \
     
    9998    src/abstract/persistence/abstractloginaccountstorageofficer.cpp \
    10099    src/abstract/persistence/abstractstorageofficer.cpp \
     100    src/exceptions/eexception.cpp \
    101101    src/interfaces/iaccount.cpp \
    102102    src/interfaces/inumber.cpp \
  • lib/libdatatypes/src/abstract/abstractaccount.h

    r71 r72  
    1111#include "iaccount.h"
    1212#include "persistence/istorageofficer.h"
    13 
    14 #include "eventmappers/saccounteventmapper.h"
    1513
    1614class AbstractAccount: public QObject, public IAccount {
  • lib/libdatatypes/src/abstract/abstractloginaccount.cpp

    r71 r72  
    1919}
    2020ILoginAccountEvents* AbstractLoginAccount::accountEvents() const {
    21     return static_cast<ILoginAccountEvents*>(eventMapper());
     21    return static_cast<SLoginAccountEventMapper*>(eventMapper());
    2222}
    2323
  • lib/libdatatypes/src/abstract/persistence/abstractaccountstorageofficer.cpp

    r71 r72  
    2121                  "); ");
    2222    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());
    2425    }
    2526}
     
    3233                 "WHERE (accountId = '" + QString::number(account()->id()) + "'); ");
    3334    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());
    3537    }
    3638
     
    5658        query.bindValue(":gatewayName", account()->gateway()->name());
    5759        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());
    5963        }
    6064
     
    6468                     "WHERE (name = '" + account()->name() + "'); ");
    6569        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());
    6773        }
    6874        account()->setId(query.value(0).toInt());
     
    7985        if (!query.exec()) {
    8086            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());
    8290        }
    8391    }
     
    92100                    "WHERE (accountId = '" + QString::number(account()->id()) + "'); ");
    93101    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());
    95105    }
    96106
  • lib/libdatatypes/src/eventmappers/saccounteventmapper.h

    r71 r72  
    2424      : account_(account)
    2525    {};
    26     IAccount* account() const { return account_; }
     26    virtual IAccount* account() const { return account_; }
    2727
    2828signals:
  • lib/libdatatypes/src/eventmappers/scontacteventmapper.h

    r71 r72  
    1616
    1717class SContactEventMapper: public QObject,
    18                            virtual public IContactEvents {
     18                           public IContactEvents {
    1919    Q_OBJECT
    2020    Q_INTERFACES(IContactEvents)
  • lib/libdatatypes/src/eventmappers/sgroupeventmapper.h

    r71 r72  
    1717
    1818class SGroupEventMapper: public QObject,
    19                          virtual public IGroupEvents {
     19                         public IGroupEvents {
    2020    Q_OBJECT
    2121    Q_INTERFACES(IGroupEvents)
  • lib/libdatatypes/src/eventmappers/sloginaccounteventmapper.h

    r71 r72  
    2020
    2121public:
    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)
    2424    {};
    25     AbstractLoginAccount* account() const { return reinterpret_cast<AbstractLoginAccount*>(SAccountEventMapper::account()); }
    2625
    2726signals:
    2827    void loggedIn();
    2928    void loggedOut();
    30 
    31 private:
    32     AbstractLoginAccount* account_;
    3329};
    3430
  • lib/libdatatypes/src/exceptions/eexception.h

    r71 r72  
    99#define EEXCEPTION_H_
    1010
    11 #include <stdexcept>
     11#include <QList>
     12#include <QMap>
    1213#include <QString>
     14#include <QStringList>
    1315
    14 class EException: public std::runtime_error {
     16class EException {
    1517public:
    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
     40private:
     41    QString         message_;
     42    QStringList     debugInfos_;
     43    EException*     chainedException_;
    1744};
    1845
  • lib/libdatatypes/src/exceptions/elibraryloadexception.h

    r71 r72  
    2020            InvalidLibraryFile,
    2121            VersionMismatch,
     22            Other,
    2223            Unknown
    2324        };
    2425
    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        {};
    2933
    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        }
    3151
    3252    private:
    3353        Purpose purpose_;
     54        QString msgStr_;
    3455    };
    3556}
  • lib/libdatatypes/src/exceptions/eloginaccountloginexception.h

    r71 r72  
    1818    public:
    1919        enum Purpose {
     20            RequestError,
    2021            InvalidLoginData,
     22            Other,
    2123            Unknown
    2224        };
    2325
     26        explicit ELoginException(const QString& msg) {
     27            purpose_ = Other;
     28            msgStr_  = msg;
     29        };
    2430        explicit ELoginException(const Purpose& purpose)
    25             : EException("")
    26             , purpose_(purpose)
    27         {}
     31            : purpose_(purpose)
     32        {};
    2833
    29         explicit ELoginException(const Purpose& purpose, const QString& msg)
    30             : EException(msg)
    31             , purpose_ (purpose)
    32         {}
     34        Purpose purpose() const throw() { return purpose_; }
    3335
    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        }
    3550
    3651    private:
    3752        Purpose purpose_;
     53        QString msgStr_;
    3854    };
    3955}
  • lib/libdatatypes/src/exceptions/httpexceptions.h

    r71 r72  
    66 */
    77
    8 #include "ehttpreadexception.h"
     8
     9#include "eexception.h"
     10
     11#include <QList>
     12#include <QSslError>
     13
     14namespace 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  
    1616#include "ivalidatable.h"
    1717
     18#include "eventmappers/saccounteventmapper.h"
     19
    1820class IContact;
    1921class IGateway;
    20 class SAccountEventMapper;
    2122
    2223namespace Account {
     
    8182#include "icontact.h"
    8283#include "igateway.h"
    83 #include "eventmappers/saccounteventmapper.h"
    8484
    8585#endif /* IACCOUNT_H_ */
  • lib/libdatatypes/src/shttphelper.cpp

    r71 r72  
    66#include <QThread>
    77#include <QUrl>
    8 
    9 #include "exceptions/httpexceptions.h"
    108
    119SHttpHelper::SHttpHelper() {
     
    5048}
    5149
    52 QString SHttpHelper::get(const QString& destination, const QMap<QString, QString>& requests /* = QMap<QString, QString>() */) {
     50bool SHttpHelper::get(const QString& destination, QString& requestResult, const QMap<QString, QString>& requests /* = QMap<QString, QString>() */) {
    5351    waitForRequest(false); // Wait until a running request has been finished
    5452
    5553    startRequest("GET", destination, requests, QMap<QString, QString>());
    5654    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
     60bool SHttpHelper::post(const QString& destination, QString& requestResult, const QMap<QString, QString>& requests /* = QMap<QString, QString>() */,
    6161        const QMap<QString, QString>& posts /* = QMap<QString, QString>() */)
    6262{
     
    6565    startRequest("POST", destination, requests, posts);
    6666    waitForRequest();
    67     return getRequestResult();
     67    requestResult = this->requestResult();
     68
     69    return !errorOccured();
    6870}
    6971
     
    7173        const QMap<QString, QString>& posts /* = QMap<QString, QString>() */)
    7274{
    73     requestResult_ = "";
     75    requestResult_   = "";
     76    requestHadError_ = false;
     77    lastError_       = EException("");
    7478
    7579    QUrl url_ = QUrl(destination);
     
    142146}
    143147
    144 /*bool HttpAccountHelper::isRequestFinished(const int& requestId) const {
    145     return finishedRequests_.contains(requestId);
    146 }*/
    147 
    148148void SHttpHelper::waitForRequest(bool createLoopIfNotExisting) {
    149149    if (!requestLoop_.isRunning() && !createLoopIfNotExisting){
     
    152152
    153153    qDebug() << "Waiting for the request to finish...";
    154     while (!request_.finished && thread()->isRunning()) {
    155         thread()->wait(100);
    156     }
    157154/*    while (!request_.finished && thread()->isRunning()) {
    158155        thread()->wait(100);
    159156    }*/
    160 //    requestLoop_.exec(QEventLoop::ExcludeUserInputEvents|QEventLoop::ExcludeSocketNotifiers|QEventLoop::WaitForMoreEvents);
     157    requestLoop_.exec(QEventLoop::WaitForMoreEvents/*QEventLoop::ExcludeUserInputEvents|QEventLoop::ExcludeSocketNotifiers|QEventLoop::WaitForMoreEvents*/);
    161158    qDebug() << "The request finished -> continuing";
    162159/*    while (!request_.finished) {
     
    168165}
    169166
    170 QString SHttpHelper::getRequestResult() const {
     167QString SHttpHelper::requestResult() const {
    171168    return requestResult_;
    172169}
     170bool SHttpHelper::errorOccured() const {
     171    return requestHadError_;
     172}
     173EException SHttpHelper::lastError() const {
     174    return lastError_;
     175}
     176QString SHttpHelper::lastErrorStr() const {
     177    return lastError_.toString();
     178}
     179
     180void 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}
    173190
    174191void SHttpHelper::responseHeaderReceived(const QHttpResponseHeader& responseHeader) {
    175     //qDebug() << responseHeader.statusCode() << " " << responseHeader.reasonPhrase();
    176     //qDebug() << responseHeader.values();
     192    if (http()->currentId() != request_.httpRequestId)
     193        return;
    177194
    178195    switch (responseHeader.statusCode()) {
     
    187204
    188205            request_.httpRequestId = -1; // To avoid error in httpRequestFinished
    189             http_->abort();
    190206
    191207            // Since the responseHeaderReceived-Slot could eventually not be called yet in cookieManager -> this would lead to a wrong header in doRequest
    192208            cookieManager_->processResponseHeader(responseHeader);
    193209
    194             //cookiemanager has not handled the response yet...
    195210            doRequest(responseHeader.value("location")); // Do the redirect
    196211            break;
    197212
    198213        default:
    199             throw Http::EReadException("Unknown response code!");
     214            errorOccured(http_->currentId(), Http::EReadException(tr("Unknown response code")));
     215            http()->abort();
    200216            break;
    201217    }
     
    208224     }
    209225
    210      qDebug() << "Quitting request loop";
    211      requestLoop_.quit();
    212226     request_.finished = true;
    213 
    214227     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()));
    217229     } else {
    218230         qDebug() << "Request [" + QString::number(httpRequestId) + "] finished";
    219          requestResult_ = /*request.buffer.readAll()*/ http_->readAll();
    220          //qDebug() << requestResult_;
     231         requestResult_ = http_->readAll();
    221232     }
    222 
    223      requestLoop_.processEvents();
     233     qDebug() << "Quitting request loop";
     234     requestLoop_.exit(errorOccured() ? 1 : 0);
    224235 }
    225236
    226237void 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  
    1616
    1717#include <iaccount.h>
     18#include "exceptions/httpexceptions.h"
    1819
    1920#include "shttpcookiemanager.h"
     
    4142    ~SHttpHelper();
    4243
    43     virtual QHttp*             http() const;
    44     virtual SHttpCookieManager* cookieManager() const;
     44    QHttp*                     http() const;
     45    SHttpCookieManager*        cookieManager() const;
    4546
    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;
    4853
    4954protected:
    5055    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;
    5756
    5857private:
     
    6059    QHttpRequestHeader* defaultHeader_;
    6160
    62     SHttpCookieManager*  cookieManager_;
     61    SHttpCookieManager* cookieManager_;
    6362
    64     SHttpRequest         request_;
     63    SHttpRequest        request_;
     64    QEventLoop          requestLoop_;
    6565    QString             requestResult_;
    66     QEventLoop          requestLoop_;
     66    bool                requestHadError_;
     67    EException          lastError_;
    6768
    6869    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);
    6976
    7077private slots:
  • lib/libdatatypes/src/snumber.cpp

    r71 r72  
    4242}
    4343SNumber::SNumber(const SNumber& other) {
    44     fromString(other.toString("ccaaau"), "ccaaau");
     44    setNumber(other.toString("ccaaau"), "ccaaau");
    4545}
    4646
     
    7575    if (format == SNumber::GuessFormat) {
    7676        QStringList formats;
     77        formats.append("ccaaau");         // 410792436866
    7778        formats.append("'+'cc' 'aaa' 'u");// +41 079 1234567
    7879        formats.append("'+'cc' 'aa' 'u"); // +41 79 1234567
  • src/business/BCAccountLoadManager.cpp

    r36 r72  
    2626
    2727         BCAccountLoadThread* alt = i.value();
    28          QObject::disconnect(alt, SIGNAL(loadStateChanged(IAccount*, AccountLoadState)),
    29                              this, SLOT(accountLoadThreadLoadStateChanged(IAccount*, AccountLoadState)));
    30          QObject::disconnect(alt, SIGNAL(loaded(IAccount*)),
    31                              this, SLOT(accountLoadThreadLoaded(IAccount*)));
    32          QObject::disconnect(alt, SIGNAL(loadingFinished(IAccount*, AccountLoadState)),
    33                              this, SLOT(accountLoadThreadLoadingFinished(IAccount*, AccountLoadState)));
    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&)));
    3636         delete alt;
    3737     }
     
    7676    if (!accountLoadThreads_.contains(account)) {
    7777        BCAccountLoadThread* alt = new BCAccountLoadThread(account);
    78         QObject::connect(alt, SIGNAL(loadStateChanged(IAccount*, AccountLoadState)),
    79                          this, SLOT(accountLoadThreadLoadStateChanged(IAccount*, AccountLoadState)));
    80         QObject::connect(alt, SIGNAL(loaded(IAccount*)),
    81                          this, SLOT(accountLoadThreadLoaded(IAccount*)));
    82         QObject::connect(alt, SIGNAL(loadingFinished(IAccount*, AccountLoadState)),
    83                          this, SLOT(accountLoadThreadLoadingFinished(IAccount*, AccountLoadState)));
    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&)));
    8686
    8787        accountLoadThreads_.insert(account, alt);
     
    9393
    9494void BCAccountLoadManager::accountLoadThreadLoadStateChanged(IAccount* account, AccountLoadState state) {
    95     accountLoadStateChanged(account, state);
     95    emit accountLoadStateChanged(account, state);
    9696}
    9797void BCAccountLoadManager::accountLoadThreadLoaded(IAccount* account) {
    98     accountLoaded(account);
     98    emit accountLoaded(account);
    9999}
    100100void BCAccountLoadManager::accountLoadThreadLoadingFinished(IAccount* account, AccountLoadState state) {
    101     accountLoadingFinished(account, state);
     101    emit accountLoadingFinished(account, state);
    102102}
    103 void BCAccountLoadManager::accountLoadThreadLoadingFailed(IAccount* account, EException* exception) {
    104     accountLoadingFailed(account, exception);
     103void BCAccountLoadManager::accountLoadThreadLoadingFailed(IAccount* account, const EException& exception) {
     104    emit accountLoadingFailed(account, exception);
    105105}
  • src/business/BCAccountLoadManager.h

    r71 r72  
    3434    void accountLoaded(IAccount* account);
    3535    void accountLoadingFinished(IAccount* account, AccountLoadState state);
    36     void accountLoadingFailed(IAccount* account, EException* exception);
     36    void accountLoadingFailed(IAccount* account, const EException& exception);
    3737
    3838protected:
     
    4646    void accountLoadThreadLoaded(IAccount* account);
    4747    void accountLoadThreadLoadingFinished(IAccount* account, AccountLoadState state);
    48     void accountLoadThreadLoadingFailed(IAccount* account, EException* exception);
     48    void accountLoadThreadLoadingFailed(IAccount* account, const EException& exception);
    4949
    5050
  • src/business/BCAccountLoadThread.cpp

    r67 r72  
    2323        try {
    2424            account_->initialize();
    25         } catch (EException* exception) {
     25        } catch (EException e) {
    2626            setLoadState(Failed);
    27             emit loadingFailed(account(), exception); // Signal
     27            emit loadingFailed(account(), EException(tr("Initializing account failed")).chain(e)); // Signal
    2828        } catch (...) {
    2929        setLoadState(Failed);
    30             emit loadingFailed(account(), new EException("Unknown error occured while loading an account.")); // Signal
     30            emit loadingFailed(account(), EException("Unknown error occured while loading an account.")); // Signal
    3131        }
    3232
  • src/business/BCAccountLoadThread.h

    r71 r72  
    3434    void loaded(IAccount* account);
    3535    void loadingFinished(IAccount* account, AccountLoadState state);
    36     void loadingFailed(IAccount* account, EException* exception);
     36    void loadingFailed(IAccount* account, const EException& exception);
    3737
    3838
  • src/business/BCAccountManager.cpp

    r71 r72  
    99
    1010#include "../persistence/PersistenceFactory.h"
     11
     12#include <QDebug>
    1113
    1214BCAccountManager* BCAccountManager::instance_=0;
     
    100102}
    101103void 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)
    103105    IAccount* account = eventMapper->account();
    104106    Q_ASSERT(account);
  • src/business/BCLibraryLoader.cpp

    r71 r72  
    3838    }
    3939
    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);
    4344
    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";
    5359            }
    54 
    55             return lib;
    5660        } 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();
    5862        }
    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);
    6167    }
    6268    return NULL;
  • src/persistence/storage/DAAccountListManager.cpp

    r71 r72  
    3030                 "WHERE (accountId = '" + QString::number(accountId) + "'); ");
    3131    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);
    3334    }
    3435
  • src/persistence/storage/DAStorage.cpp

    r71 r72  
    4040    if (!dbConnection_.open()) {
    4141        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
    4646    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());
    6572    }
    6673}
     
    133140                    "WHERE (contactId = '" + QString::number(contactId) + "'); ");
    134141    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());
    136145    }
    137146
     
    156165                    "WHERE (groupId = '" + QString::number(groupId) + "'); ");
    157166    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());
    159170    }
    160171
     
    234245
    235246    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());
    237252    }
    238253
     
    255270
    256271        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);
    258275        }
    259276
     
    294311        query.bindValue(":number", contact->number().toString());
    295312        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());
    297316        }
    298317
     
    302321                     "WHERE (name = '" + contact->name() + "'); ");
    303322        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());
    305326        }
    306327        contact->setId(query.value(0).toInt());
     
    316337
    317338        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());
    319342        }
    320343    }
     
    346369        query.bindValue(":name", group->name());
    347370        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());
    349374        }
    350375
     
    354379                     "WHERE (name = '" + group->name() + "'); ");
    355380        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());
    357384        }
    358385        group->setId(query.value(0).toInt());
     
    366393
    367394        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());
    369398        }
    370399    }
     
    395424                      "AND (key = '" + key + "'); ");
    396425    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());
    398430    }
    399431}
     
    404436                    "WHERE (namespace = '" + _namespace + "'); ");
    405437    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());
    407441    }
    408442}
     
    419453                        "WHERE (contactId = '" + QString::number(contactId) + "'); ");
    420454        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);
    425461    }
    426462}
     
    436472                        "WHERE (groupId = '" + QString::number(groupId) + "'); ");
    437473        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  
    66
    77#include "../VCEditAccount/vceditaccount.h"
    8 
    9 #include "../UIHelper.h"
    108
    119#include <inumber.h>
  • src/ui/VCAddressBook/vcaddressbook.cpp

    r71 r72  
    88#include "../VCEditContact/vceditcontact.h"
    99#include "../VCEditGroup/vceditgroup.h"
    10 
    11 #include "../UIHelper.h"
    1210
    1311#include <scontact.h>
  • src/ui/VCEditContact/vceditcontact.cpp

    r56 r72  
    99#include <QStringList>
    1010#include <QSortFilterProxyModel>
    11 
    12 #include "../UIHelper.h"
    1311
    1412#include <snumber.h>
  • src/ui/VCEditGroup/vceditgroup.cpp

    r43 r72  
    22
    33#include "../../business/BCContactManager.h"
    4 
    5 #include "../UIHelper.h"
    64
    75#include <QFileDialog>
  • src/ui/VCMain/vcmain.cpp

    r71 r72  
    1919#include "../../business/BCContactManager.h"
    2020#include "../../business/BCGroupManager.h"
    21 
    22 #include "../UIHelper.h"
    2321
    2422#include "../VCAccountList/vcaccountlist.h"
     
    4543        accountFilterModel_->sort(AccountTreeModel::ColName, Qt::AscendingOrder);
    4644        ui.lstAccounts->setModel(accountFilterModel_);
     45        ui.lstAccounts->setModelColumn(AccountTreeModel::ColGatewayName);
    4746
    4847        /* Contact / Groups */
     
    7574    connect(BCAccountLoadManager::instance(), SIGNAL(accountLoaded(IAccount*)),
    7675            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&)));
    7978
    8079
     
    9594IContact* VCMain::getContactOfNode(const QTreeWidgetItem* node){
    9695    if (!isContactNode(node)){
    97         return (IContact*)0;
     96        return NULL;
    9897    } else {
    9998        return nodeToContact[const_cast<QTreeWidgetItem*>(node)];
     
    102101IGroup* VCMain::getGroupOfNode(const QTreeWidgetItem* node){
    103102    if (!isGroupNode(node)){
    104         return (IGroup*)0;
     103        return NULL;
    105104    } else {
    106105        return nodeToGroup[const_cast<QTreeWidgetItem*>(node)];
     
    397396
    398397void VCMain::on_accountLoaded(IAccount* account) {
     398    Q_UNUSED(account);
     399    enableSendBtnIfAllFilled();
     400}
     401
     402void 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);
    399407    reloadAccountList();
    400408}
    401409
    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  
    8585    void on_accountLoadStateChanged(IAccount* account, AccountLoadState state);
    8686    void on_accountLoaded(IAccount* account);
    87     void on_accountLoadingFailed(IAccount* account, EException* exception);
     87    void on_accountLoadingFailed(IAccount* account, const EException& exception);
    8888};
    8989
  • src/ui/models/accounttreemodel.cpp

    r67 r72  
    3232
    3333    QModelIndex idx_start = index(row, 0);
    34     QModelIndex idx_end   = index(row, columnCount());
     34    QModelIndex idx_end   = index(row, columnCount()-1);
    3535
    3636    if (idx_start.isValid() && idx_end.isValid()) {
  • src/ui/models/loadedaccountmodel.cpp

    r67 r72  
    1414    const QModelIndex& idx     = srcModel->index(source_row, 0, source_parent);
    1515    if (idx.isValid()) {
    16         IAccount* account          = srcModel->dataObject(idx);
     16        IAccount* account      = srcModel->dataObject(idx);
    1717
    1818        return (account != NULL) && account->isInitialized() && account->isEnabled();
Note: See TracChangeset for help on using the changeset viewer.