Changeset 376:0d8179eea17f in SMSSender


Ignore:
Timestamp:
Apr 14, 2014 1:28:38 PM (4 years ago)
Author:
Sämy Zehnder <saemy.zehnder@…>
Branch:
separation-frontend-backend
Message:
  • Separates backend and frontend code in the Post gateway.
Location:
gateways
Files:
10 added
3 deleted
2 edited
1 copied
18 moved

Legend:

Unmodified
Added
Removed
  • gateways/Post/business/account.cpp

    r315 r376  
    11/*
    22  Swiss Post gateway plugin - The smssender plugin for the Swiss Post platform.
    3   Copyright (C) 2011-2012, gorrión. See http://smssender.gorrion.ch
     3  Copyright (C) 2011-2014, gorrión. See http://smssender.gorrion.ch
    44
    55  This program is free software: you can redistribute it and/or modify
     
    2222
    2323#include <QDebug>
    24 #include <QDialog>
    2524#include <QThread>
    2625
    27 #include <business/impl/defaultlogininittask.h>
    28 #include <domain/snumber.h>
    29 #include <exceptions/stdexceptions.h>
    30 #include <exceptions/loginaccountexceptions.h>
    31 #include <network/snetworkreply.h>
    32 #include <persistence/impl/defaultaccountstoragehelper.h>
    33 #include <validation/defaultaccountvalidator.h>
    34 
    35 #include "business/account_tasks.h"
    36 #include "business/gateway.h"
    37 #include "library.h"
     26#include "common/domain/snumber.h"
     27#include "common/exceptions/loginaccountexceptions.h"
     28#include "common/exceptions/stdexceptions.h"
     29#include "common/network/snetworkreply.h"
     30#include "common/validation/defaultaccountvalidator.h"
     31#include "gateways/common/business/defaultlogininittask.h"
     32#include "gateways/common/persistence/defaultaccountstoragehelper.h"
     33#include "gateways/Post/business/account_tasks.h"
     34#include "gateways/Post/business/gateway.h"
    3835
    3936namespace Post {
    4037
    4138Account::Account(IGateway *gateway)
    42     : AbstractAccount(gateway)
     39    : BaseAccount(gateway)
    4340    , m_httpHelper(new SNetworkHelper)
    4441    , m_longSMSLength(435) // Default value from post.ch
    4542{
    46     m_httpHelper->addTrustedCA(":/certs/VerisignCA3.crt");
     43    m_httpHelper->addTrustedCA(":/certs/Verisign_class3_root.crt");
     44    m_httpHelper->addTrustedCA(":/certs/VerisignCA_G3.crt");
     45    m_httpHelper->addTrustedCA(":/certs/VerisignCA_G5.crt");
    4746
    4847    connect(this, SIGNAL(initStateChanged(IAccount*)),
     
    5049}
    5150
    52 Persistence::IStorageHelper* Account::createStorageHelper(Persistence::IMainStorage *storage) {
    53     return new Persistence::DefaultAccountStorageHelper(this, storage, "s2uh98dWe9D_wf98h23:*EOnqei8D");
     51Persistence::IStorageHelper* Account::createStorageHelper(
     52        Persistence::IMainStorage *storage) {
     53    return new Persistence::DefaultAccountStorageHelper(
     54                this, storage, "s2uh98dWe9D_wf98h23:*EOnqei8D");
    5455}
    5556IValidator* Account::createValidator() const {
     
    6364    return new AccountLoginTask(this);
    6465}
    65 ISMSSendTask* Account::doCreateSMSSendTask(const QString &message, const QSet<SContact> &recipients) {
     66ISMSSendTask* Account::doCreateSMSSendTask(
     67        const QString &message, const QSet<const SContact *> &recipients)
     68{
    6669    return new SMSSendTask(this, message, recipients);
    6770}
     
    8689        result = html.contains("Error", Qt::CaseSensitive);
    8790    } catch (EException &e) {
    88         qWarning() << "Error while checking if we are still logged in: " + e.what();
    89         qWarning() << "But ignoring it, since we just do a new login attempt.";
     91        qWarning() << "Error while checking if we are still logged in: "
     92                   << e.what()
     93                   << "But ignoring it, since we just do a new login attempt.";
    9094        result = false;
    9195    }
     
    104108}
    105109void Account::reloadLongSMSLength(QString html) {
    106     /*<textarea name="sms_body" style="width: 100%; height: 117px" cols=2 rows=2 maxlength="435" onKeyUp="left_char(this)"></textarea>*/
     110    /*<textarea name="sms_body" style="width: 100%; height: 117px" cols=2 rows=2
     111     *    maxlength="435" onKeyUp="left_char(this)"></textarea>*/
    107112
    108113    QRegExp rx("<textarea name=\"sms_body\"[^>]*maxlength=\"(\\d+)\"");
     
    119124    /*<td class="label">50 von 50 TextSMS im Monat xxx</td> */
    120125
    121     QRegExp rx("<td class=\"label\">(\\d+) von \\d+ TextSMS im Monat [a-zA-Zäöü]+</td>");
    122     rx.setCaseSensitivity(Qt::CaseSensitive);
    123     if (rx.indexIn(html) == -1) {
    124         EException(tr("Could not get the free sms count."))
    125                 .addDebugInfo("html", html)
    126                 .raise(); // Will be made userfriendly in parsePage
     126    QRegExp rx("TextSMS-Kontingent von \\d+ SMS verbraucht!");
     127    rx.setCaseSensitivity(Qt::CaseInsensitive);
     128    if (rx.indexIn(html) != -1) {
     129        setFreeSMSCount(0);
     130    } else {
     131        rx.setPattern("<td class=\"label\">(\\d+) von \\d+ TextSMS im Monat [a-zA-Zäöü]+</td>");
     132        if (rx.indexIn(html) == -1) {
     133            EException(tr("Could not get the free sms count."))
     134                    .addDebugInfo("html", html)
     135                    .raise(); // Will be made userfriendly in parsePage
     136        }
     137        setFreeSMSCount(rx.cap(1).toInt());
    127138    }
    128     setFreeSMSCount(rx.cap(1).toInt());
    129139    qDebug() << "  Free SMS count: " + rx.cap(1);
    130140}
  • gateways/Post/business/account.h

    r315 r376  
    11/*
    22  Swiss Post gateway plugin - The smssender plugin for the Swiss Post platform.
    3   Copyright (C) 2011-2012, gorrión. See http://smssender.gorrion.ch
     3  Copyright (C) 2011-2014, gorrión. See http://smssender.gorrion.ch
    44
    55  This program is free software: you can redistribute it and/or modify
     
    1616  along with this program.  If not, see <http://www.gnu.org/licenses/>.
    1717*/
    18 #ifndef POST_BCACCOUNT_H_
    19 #define POST_BCACCOUNT_H_
     18#ifndef POST_ACCOUNT_H
     19#define POST_ACCOUNT_H
    2020
    2121#include <QScopedPointer>
    2222
    23 #include <business/impl/abstractaccount.h>
    24 #include <network/snetworkhelper.h>
    25 #include <persistence/imainstorage.h>
     23#include "common/network/snetworkhelper.h"
     24#include "gateways/common/business/baseaccount.h"
    2625
    2726namespace Post {
    2827
    29 class Account : public AbstractAccount {
     28class Account : public BaseAccount {
    3029    Q_OBJECT
    3130
    32     friend class ContactImporter; // networkHelper()
    33     friend class AccountLoginTask; // reloadOnlineParams(), httpHelper()
    34     friend class SMSSendTask; // reloadOnlineParams(), httpHelper()
     31    friend class AccountLoginTask; // reloadOnlineParams
     32    friend class SMSSendTask; // reloadOnlineParams
    3533
    3634public:
     
    3836
    3937public: /* IAccount */
    40     Persistence::IStorageHelper* createStorageHelper(Persistence::IMainStorage *storage);
    41     IValidator* createValidator() const;
     38    Persistence::IStorageHelper *createStorageHelper(
     39            Persistence::IMainStorage *storage);
     40    IValidator *createValidator() const;
    4241
    4342public: /* IAccount - SMS sending */
    44     void               cancelSMSSending();
     43    void cancelSMSSending();
    4544
    4645public: /* IAccount - costs */
    47     int                costsForText(const QString &text) const;
    48     int                fragmentSize() const;
     46    int costsForText(const QString &text) const;
     47    int fragmentSize() const;
    4948
    50 public: /* Properties */
     49public:
     50    SNetworkHelper *httpHelper() const;
    5151
    5252protected: /* AbstractAccount */
    53     IAccountInitTask*  doCreateInitTask();
    54     IAccountLoginTask* doCreateLoginTask();
    55     ISMSSendTask*      doCreateSMSSendTask(const QString& message, const QSet<SContact>& recipients);
     53    IAccountInitTask *doCreateInitTask();
     54    IAccountLoginTask *doCreateLoginTask();
     55    ISMSSendTask *doCreateSMSSendTask(const QString& message,
     56                                      const QSet<const SContact *>& recipients);
    5657
    5758protected: /* AbstractLoginAccount */
    58     bool               checkStillLoggedIn();
     59    bool checkStillLoggedIn();
    5960
    6061private:
    61     int                longSMSLength() const;
    62     void               setLongSMSLength(int longSMSLength);
     62    int longSMSLength() const;
     63    void setLongSMSLength(int longSMSLength);
    6364
    6465private:
    65     void               reloadOnlineParams();
    66     void               reloadOnlineParams(QString html);
     66    void reloadOnlineParams();
     67    void reloadOnlineParams(QString html);
    6768
    68     void               reloadLongSMSLength(QString html);
    69     void               reloadFreeSMSCount(QString html);
    70 
    71 private:
    72     SNetworkHelper *httpHelper() const; // TODO: dependency injection -> remove friends
     69    void reloadLongSMSLength(QString html);
     70    void reloadFreeSMSCount(QString html);
    7371
    7472private slots:
    75     void               onInitStateChanged();
     73    void onInitStateChanged();
    7674
    7775private:
     
    8482}
    8583
    86 #endif /* POST_BCACCOUNT_H_ */
     84#endif /* POST_ACCOUNT_H */
  • gateways/Post/business/account_costs.cpp

    r315 r376  
    11/*
    22  Swiss Post gateway plugin - The smssender plugin for the Swiss Post platform.
    3   Copyright (C) 2011-2012, gorrión. See http://smssender.gorrion.ch
     3  Copyright (C) 2011-2014, gorrión. See http://smssender.gorrion.ch
    44
    55  This program is free software: you can redistribute it and/or modify
  • gateways/Post/business/account_task_login.cpp

    r315 r376  
    11/*
    22  Swiss Post gateway plugin - The smssender plugin for the Swiss Post platform.
    3   Copyright (C) 2011-2012, gorrión. See http://smssender.gorrion.ch
     3  Copyright (C) 2011-2014, gorrión. See http://smssender.gorrion.ch
    44
    55  This program is free software: you can redistribute it and/or modify
     
    1818#include "account_tasks.h"
    1919
    20 #include <exceptions/eloginaccountloginexception.h>
    21 #include <network/snetworkreply.h>
    22 
    23 #include "business/gateway.h"
    24 #include "library.h"
     20#include "common/exceptions/eloginaccountloginexception.h"
     21#include "common/network/snetworkreply.h"
     22#include "gateways/Post/business/gateway.h"
    2523
    2624namespace Post {
    2725
    2826AccountLoginTask::AccountLoginTask(Account *account)
    29     : AbstractAccountLoginTask(account)
     27    : BaseAccountLoginTask(account)
    3028{
    3129}
     
    6967}
    7068
    71 QString AccountLoginTask::postSamlRequest(QString lastHtml) {
     69QString AccountLoginTask::postSamlRequest(const QString &lastHtml) {
    7270    /* Find URL */
    73     QRegExp rx("<form method=\"post\" action=\"([^\"]+)\">");
     71    QRegExp rx("<form.*action=\"([^\"]+)\".*>");
     72    rx.setMinimal(true);
    7473    if (rx.indexIn(lastHtml) == -1) {
    7574        LoginAccount::ELoginException(LoginAccount::ELoginException::RequestError)
     
    109108}
    110109
    111 QString AccountLoginTask::postSamlResponse(QString lastHtml) {
     110QString AccountLoginTask::postSamlResponse(const QString &lastHtml) {
    112111    /*
    113112                <form id="saml_form" action="https://organizer.sso.post.ch/sso-navi/assertion_consumer.php" method="POST" enctype="application/x-www-form-urlencoded">
     
    117116    */
    118117    /* Find URL */
    119     QRegExp rx("<form id=\"saml_form\" action=\"([^\"]+)\"");
     118    QRegExp rx("<form.*action=\"([^\"]+)\".*");
     119    rx.setMinimal(true);
    120120    if (rx.indexIn(lastHtml) == -1) {
    121121        LoginAccount::ELoginException(LoginAccount::ELoginException::RequestError)
     
    157157
    158158Account* AccountLoginTask::account() const {
    159     return static_cast<Account*>(AbstractAccountLoginTask::account());
     159    return static_cast<Account*>(BaseAccountLoginTask::account());
    160160}
    161161
  • gateways/Post/business/account_task_sendsms.cpp

    r315 r376  
    11/*
    22  Swiss Post gateway plugin - The smssender plugin for the Swiss Post platform.
    3   Copyright (C) 2011-2012, gorrión. See http://smssender.gorrion.ch
     3  Copyright (C) 2011-2014, gorrión. See http://smssender.gorrion.ch
    44
    55  This program is free software: you can redistribute it and/or modify
     
    2020#include <math.h>
    2121
    22 #include <business/impl/abstractaccount_utils.h>
    23 #include <domain/sdatatypes.h>
    24 #include <domain/snumber.h>
    25 #include <network/snetworkreply.h>
    26 
    27 #include "business/gateway.h"
     22#include "common/domain/sdatatypes.h"
     23#include "common/domain/snumber.h"
     24#include "common/network/snetworkreply.h"
     25#include "gateways/common/business/baseaccount_utils.h"
     26#include "gateways/Post/business/gateway.h"
    2827
    2928namespace Post {
    3029
    31 SMSSendTask::SMSSendTask(Account* account, const QString &message, const QSet<SContact> &recipients)
    32     : AbstractSMSSendTask(account, message, recipients)
     30SMSSendTask::SMSSendTask(Account *account, const QString &message,
     31                         const QSet<const SContact *> &recipients)
     32    : BaseSMSSendTask(account, message, recipients)
    3333{
    3434}
     
    6464
    6565            int percent_per_sms = 70 / (longSMSList.size() * ceil(recipients().size() / (double)MAX_RECIPIENTS_PER_SMS));
    66             QSetIterator<SContact> i(recipients());
     66            QSetIterator<const SContact *> i(recipients());
    6767            foreach (QString msgPart, longSMSList) {
    6868                i.toFront();
     
    7373                    int recipientsCount = 0;
    7474                    while (i.hasNext() && (recipientsCount < MAX_RECIPIENTS_PER_SMS)) {
    75                         addRecipient(i.next(), &recipientsStr);
     75                        addRecipient(*i.next(), &recipientsStr);
    7676                        ++recipientsCount;
    7777                    }
     
    146146
    147147Account* SMSSendTask::account() const {
    148     return static_cast<Account*>(AbstractSMSSendTask::account());
     148    return static_cast<Account*>(BaseSMSSendTask::account());
    149149}
    150150
  • gateways/Post/business/account_tasks.h

    r315 r376  
    11/*
    22  Swiss Post gateway plugin - The smssender plugin for the Swiss Post platform.
    3   Copyright (C) 2011-2012, gorrión. See http://smssender.gorrion.ch
     3  Copyright (C) 2011-2014, gorrión. See http://smssender.gorrion.ch
    44
    55  This program is free software: you can redistribute it and/or modify
     
    1616  along with this program.  If not, see <http://www.gnu.org/licenses/>.
    1717*/
    18 #ifndef POST_BCACCOUNT_TASKS_H_
    19 #define POST_BCACCOUNT_TASKS_H_
     18#ifndef POST_ACCOUNT_TASKS_H
     19#define POST_ACCOUNT_TASKS_H
    2020
    21 #include <business/impl/abstractaccount_tasks.h>
    22 
    23 #include "business/account.h"
     21#include "gateways/common/business/baseaccount_tasks.h"
     22#include "gateways/Post/business/account.h"
    2423
    2524namespace Post {
    2625
    27 class AccountLoginTask : public AbstractAccountLoginTask {
     26class AccountLoginTask : public BaseAccountLoginTask {
    2827    Q_OBJECT
    2928
     
    3332protected: /* AbstractAccountLoginTask */
    3433    void doLogin();
    35     Account* account() const;
     34    Account *account() const;
    3635
    3736private:
     
    4039private:
    4140    QString postLogin();
    42     QString postSamlRequest(QString lastHtml);
    43     QString postSamlResponse(QString lastHtml);
     41    QString postSamlRequest(const QString &lastHtml);
     42    QString postSamlResponse(const QString &lastHtml);
    4443};
    4544
    4645
    47 class SMSSendTask : public AbstractSMSSendTask {
     46class SMSSendTask : public BaseSMSSendTask {
    4847    Q_OBJECT
    4948
    5049public:
    51     SMSSendTask(Account *account, const QString &message, const QSet<SContact> &recipients);
     50    SMSSendTask(Account *account, const QString &message,
     51                const QSet<const SContact *> &recipients);
    5252
    5353protected: /* AbstractAccountSendSMSTask */
    5454    void doSendSMS();
    55     Account* account() const;
     55    Account *account() const;
    5656
    5757private:
     
    6565} // namespace Post
    6666
    67 #endif /* POST_BCACCOUNT_TASKS_H_ */
     67#endif /* POST_ACCOUNT_TASKS_H */
  • gateways/Post/business/contactimporter/contactimporter.cpp

    r315 r376  
    11/*
    22  Swiss Post gateway plugin - The smssender plugin for the Swiss Post platform.
    3   Copyright (C) 2011-2012, gorrión. See http://smssender.gorrion.ch
     3  Copyright (C) 2011-2014, gorrión. See http://smssender.gorrion.ch
    44
    55  This program is free software: you can redistribute it and/or modify
     
    1717 */
    1818#include "contactimporter.h"
    19 #include "contactimporter_p.h"
    2019
    21 #include <domain/scontact.h>
    22 #include <domain/snumber.h>
    23 #include <network/snetworkreply.h>
    24 
    25 #include "business/account.h"
    26 #include "business/gateway.h"
     20#include "common/domain/scontact.h"
     21#include "common/domain/snumber.h"
     22#include "common/network/snetworkreply.h"
     23#include "gateways/Post/business/account.h"
     24#include "gateways/Post/business/gateway.h"
    2725
    2826namespace Post {
    2927
    30 const QString ContactImporter::URL_EXPORT_CONTACTS = "https://organizer.sso.post.ch/addresses/adr_csv_export_action.html";
     28const QString ContactImporter::URL_EXPORT_CONTACTS =
     29        "https://organizer.sso.post.ch/addresses/adr_csv_export_action.html";
    3130
    32 ContactImporter::ContactImporter(const IAccountIntegrationHelper *accountHelper)
    33     : m_dataManager(new ContactImporterDataManager)
    34     , m_accountHelper(accountHelper)
     31ContactImporter::ContactImporter(Account *account)
     32    : m_account(account)
    3533{
    3634}
    3735
    38 QString ContactImporter::describingName() const {
     36void ContactImporter::importContacts(QSet<SContact *> *contacts) {
     37    // Fetch the contacts
     38    QString csv =
     39            m_account->httpHelper()->syncGet(URL_EXPORT_CONTACTS)->readAll();
     40    csv.replace("\r", "");
     41
     42    // Split csv into rows
     43    QStringList rows = csv.split('\n', QString::SkipEmptyParts);
     44
     45    // Get the interresting columns
     46    QString columnDescriptorRow = rows.takeFirst();
     47    QStringList columnDescriptor = splitIntoCells(columnDescriptorRow);
     48    int prenameCol = columnDescriptor.indexOf(QRegExp("^Vorname$"));
     49    int lastnameCol = columnDescriptor.indexOf(QRegExp("^Nachname$"));
     50    int mobileCol = columnDescriptor.indexOf(QRegExp("^Mobil-Nummer$"));
     51    int mobileCol2 = columnDescriptor.indexOf(QRegExp("^Mobil-Nummer at$"));
     52
     53
     54    // Parse the contacts
     55    foreach (QString row, rows) {
     56        QStringList contactData = splitIntoCells(row);
     57
     58        QString name = QString("%1 %2")
     59                .arg(contactData.value(prenameCol))
     60                .arg(contactData.value(lastnameCol))
     61                .trimmed();
     62        SNumber number(contactData.value(mobileCol));
     63        if (!number.isValid()) {
     64            number = SNumber(contactData.value(mobileCol2));
     65        }
     66
     67        if (!name.isEmpty() && number.isValid()) {
     68            QScopedPointer<SContact> contact(new SContact);
     69            contact->setName(name);
     70            contact->setNumber(number);
     71
     72            contacts->insert(contact.take());
     73        }
     74    }
     75}
     76
     77QStringList ContactImporter::splitIntoCells(QString csvRow) {
     78    csvRow = csvRow.mid(1, csvRow.length()-2); // Remove first and last "
     79    return csvRow.split(QRegExp("\";\""), QString::KeepEmptyParts);
     80}
     81
     82/********************************** Builder ***********************************/
     83
     84ContactImporter::Builder::Builder(IAccountIntegrationHelper *accountHelper)
     85    : m_accountHelper(accountHelper)
     86{
     87}
     88
     89QString ContactImporter::Builder::description() const {
    3990    if (isApplicable()) {
    4091        return QObject::tr("Import contacts from the Post website.");
     
    4495}
    4596
    46 bool ContactImporter::isApplicable() const {
     97bool ContactImporter::Builder::isApplicable() const {
    4798    return m_accountHelper->hasLoggedInAccounts();
    4899}
    49100
     101void ContactImporter::Builder::createImporters(QSet<IContactImporter *> *importers) {
     102    foreach (IAccount *iaccount, m_accountHelper->loggedInAccounts()) {
     103        Account *account = static_cast<Account*>(iaccount);
    50104
    51 void ContactImporter::init() {
    52     const QSet<IAccount*> &loggedInIAccounts = m_accountHelper->loggedInAccounts();
    53 
    54     // FIXME: is this cast save?
    55     const QSet<Account*> &loggedInAccounts = reinterpret_cast<const QSet<Account*> &>(loggedInIAccounts);
    56     m_dataManager->setSelectedAccounts(loggedInAccounts);
    57 }
    58 QList<QWizardPage*> ContactImporter::preImportPages(QWidget *parent) {
    59     Q_UNUSED(parent)
    60     return QList<QWizardPage*>();
    61 }
    62 QSet<SContact> ContactImporter::importContacts() {
    63     QSet<SContact> contacts;
    64 
    65     foreach (Account *account, m_dataManager->selectedAccounts()) {
    66         if (!account->isLoggedIn()) continue;
    67 
    68         // Fetch the contacts
    69         QString csv = account->httpHelper()->syncGet(URL_EXPORT_CONTACTS)->readAll();
    70         csv.replace("\r", "");
    71 
    72         // Split csv into rows
    73         QStringList rows = csv.split('\n', QString::SkipEmptyParts);
    74 
    75         // Get the interresting columns
    76         QString columnDescriptorRow = rows.takeFirst();
    77         QStringList columnDescriptor = splitIntoCells(columnDescriptorRow);
    78         int prenameCol = columnDescriptor.indexOf(QRegExp("^Vorname$"));
    79         int lastnameCol = columnDescriptor.indexOf(QRegExp("^Nachname$"));
    80         int mobileCol = columnDescriptor.indexOf(QRegExp("^Mobil-Nummer$"));
    81         int mobileCol2 = columnDescriptor.indexOf(QRegExp("^Mobil-Nummer at$"));
    82 
    83 
    84         // Parse the contacts
    85         foreach (QString row, rows) {
    86             QStringList contactData = splitIntoCells(row);
    87 
    88             QString name = QString(contactData.value(prenameCol) + " " + contactData.value(lastnameCol)).trimmed();
    89             SNumber number(contactData.value(mobileCol));
    90             if (!number.isValid()) {
    91                 number = SNumber(contactData.value(mobileCol2));
    92             }
    93 
    94             if (!name.isEmpty() && number.isValid()) {
    95                 SContact contact;
    96                 contact.setName(name);
    97                 contact.setNumber(number);
    98 
    99                 contacts.insert(contact);
    100             }
    101         }
     105        importers->insert(new ContactImporter(account));
    102106    }
    103 
    104     return contacts;
    105 }
    106 
    107 QStringList ContactImporter::splitIntoCells(QString csvRow) {
    108     csvRow = csvRow.mid(1, csvRow.length()-2); // Remove first and last "
    109     return csvRow.split(QRegExp("\";\""), QString::KeepEmptyParts);
    110107}
    111108
  • gateways/Post/business/contactimporter/contactimporter.h

    r315 r376  
    11/*
    22  Swiss Post gateway plugin - The smssender plugin for the Swiss Post platform.
    3   Copyright (C) 2011-2012, gorrión. See http://smssender.gorrion.ch
     3  Copyright (C) 2011-2014, gorrión. See http://smssender.gorrion.ch
    44
    55  This program is free software: you can redistribute it and/or modify
     
    1616  along with this program.  If not, see <http://www.gnu.org/licenses/>.
    1717 */
    18 
    19 #ifndef POST_BCCONTACTIMPORTER_H_
    20 #define POST_BCCONTACTIMPORTER_H_
     18#ifndef POST_CONTACTIMPORTER_CONTACTIMPORTER_H
     19#define POST_CONTACTIMPORTER_CONTACTIMPORTER_H
    2120
    2221#include <QScopedPointer>
    2322#include <QString>
    2423
    25 #include <business/icontactimporter.h>
    26 #include <business/iintegration.h>
    27 #include <domain/scontact.h>
     24#include "common/business/icontactimporter.h"
     25#include "common/business/iintegration.h"
     26#include "common/domain/scontact.h"
     27#include "gateways/Post/business/account.h"
    2828
    29 class IAccountManager2;
    3029class IGateway;
    3130
     
    3635class ContactImporter : public IContactImporter {
    3736public:
    38     explicit ContactImporter(const IAccountIntegrationHelper *accountHelper);
     37    explicit ContactImporter(Account *account);
    3938
    4039public: /* IContactImporter */
    41     QString describingName() const;
    42     bool    isApplicable() const;
     40    void importContacts(QSet<SContact *> *contacts);
    4341
    44     void                init();
    45     QList<QWizardPage*> preImportPages(QWidget* parent);
    46     QSet<SContact>      importContacts();
     42    class Builder : public IContactImporter::Builder {
     43    public:
     44        explicit Builder(IAccountIntegrationHelper *accountHelper);
     45
     46    public: /* IContactImporter::Builder */
     47        QString description() const;
     48        bool isApplicable() const;
     49
     50        void createImporters(QSet<IContactImporter *> *importers);
     51
     52    private:
     53        IAccountIntegrationHelper *m_accountHelper;
     54
     55        Q_DISABLE_COPY(Builder)
     56    };
    4757
    4858private:
     
    5262    static const QString URL_EXPORT_CONTACTS;
    5363
    54     const QScopedPointer<ContactImporterDataManager> m_dataManager;
    55     const IAccountIntegrationHelper * const m_accountHelper;
     64    Account * const m_account;
     65
     66    Q_DISABLE_COPY(ContactImporter)
    5667};
    5768
    58 }
     69} // namespace Post
    5970
    60 #endif /* POST_BCCONTACTIMPORTER_H_ */
     71#endif /* POST_CONTACTIMPORTER_CONTACTIMPORTER_H */
  • gateways/Post/business/gateway.cpp

    r315 r376  
    11/*
    22  Swiss Post gateway plugin - The smssender plugin for the Swiss Post platform.
    3   Copyright (C) 2011-2012, gorrión. See http://smssender.gorrion.ch
     3  Copyright (C) 2011-2014, gorrión. See http://smssender.gorrion.ch
    44
    55  This program is free software: you can redistribute it and/or modify
     
    1818#include "gateway.h"
    1919
    20 #include "business/account.h"
    21 #include "ui/settingswidget.h"
     20#include "gateways/Post/business/account.h"
    2221
    2322namespace Post {
     
    2524QString Gateway::name() const {
    2625    return "Post";
    27 }
    28 
    29 QImage Gateway::icon() const {
    30     return QImage(":/images/Post.ico");
    3126}
    3227
     
    6055}
    6156
    62 IAccountSettingsWidget* Gateway::createAccountSettingsWidget(QWidget *parent) const {
    63     return new UI::SettingsWidget(parent);
    64 }
    65 
    66 ::Persistence::IStorageHelper *Gateway::createStorageHelper(Persistence::IMainStorage *storage) {
     57::Persistence::IStorageHelper *Gateway::createStorageHelper(
     58        Persistence::IMainStorage *storage) {
    6759    Q_UNUSED(storage);
    6860    return NULL;
  • gateways/Post/business/gateway.h

    r315 r376  
    11/*
    22  Swiss Post gateway plugin - The smssender plugin for the Swiss Post platform.
    3   Copyright (C) 2011-2012, gorrión. See http://smssender.gorrion.ch
     3  Copyright (C) 2011-2014, gorrión. See http://smssender.gorrion.ch
    44
    55  This program is free software: you can redistribute it and/or modify
     
    1616  along with this program.  If not, see <http://www.gnu.org/licenses/>.
    1717*/
    18 #ifndef POST_BCGATEWAY_H_
    19 #define POST_BCGATEWAY_H_
     18#ifndef POST_GATEWAY_H
     19#define POST_GATEWAY_H
    2020
    2121#include <QSet>
    2222
    23 #include <business/igateway.h>
    24 #include <utils/smacros.h>
     23#include "common/business/igateway.h"
     24
     25#ifdef FRONTEND_GUI
     26class QIcon;
     27#endif
    2528
    2629namespace Post {
     
    3841public: /* IGateway */
    3942    QString name() const;
    40     QImage icon() const;
     43
     44#ifdef FRONTEND_GUI
     45    QIcon icon() const;
     46    IAccountSettingsWidget *createAccountSettingsWidget(QWidget *parent) const;
     47#endif
    4148
    4249public: /* IGateway */
    43     QList<int>   validRecipientCountryCodes() const;
     50    QList<int> validRecipientCountryCodes() const;
    4451    QList<QChar> doublePriceChars() const;
    4552    QList<QChar> disAllowedChars() const;
    4653
    4754public: /* IGateway */
    48     IAccountSettingsWidget* createAccountSettingsWidget(QWidget *parent) const;
    49     IAccount*               createAccountInstance();
     55    IAccount *createAccountInstance();
    5056
    5157public: /* IStorable */
    52     ::Persistence::IStorageHelper *createStorageHelper(Persistence::IMainStorage *storage);
     58    ::Persistence::IStorageHelper *createStorageHelper(
     59            Persistence::IMainStorage *storage);
    5360};
    5461
    5562}
    5663
    57 #endif /* POST_BCGATEWAY_H_ */
     64#endif /* POSTATEWAY_H */
  • gateways/Post/gui/post.cpp

    r315 r376  
    11/*
    22  Swiss Post gateway plugin - The smssender plugin for the Swiss Post platform.
    3   Copyright (C) 2011-2012, gorrión. See http://smssender.gorrion.ch
     3  Copyright (C) 2011-2014, gorrión. See http://smssender.gorrion.ch
    44
    55  This program is free software: you can redistribute it and/or modify
     
    1616  along with this program.  If not, see <http://www.gnu.org/licenses/>.
    1717*/
    18 #include "library.h"
     18#include "post.h"
    1919
    2020#include <QLocale>
    21 #include <QScopedPointer>
    2221
    23 #include <domain/sversion.h>
    24 
    25 #include "business/contactimporter/contactimporter.h"
    26 #include "business/gateway.h"
     22#include "common/domain/sversion.h"
     23#include "gateways/Post/business/contactimporter/contactimporter.h"
     24#include "gateways/Post/business/gateway.h"
    2725
    2826namespace Post {
    2927
    30 QString Library::compatibilityVersion() const {
    31     return COMPATIBILITY_VERSION;
     28Library::Library() {
    3229}
    3330
    34 QString Library::identificationKey() const {
    35     return "Post";
    36 }
    37 SVersion Library::version() const {
    38     return SVersion(LIB_VERSION);
    39 }
    40 
    41 bool Library::doInit(QSet<QTranslator*> *translators, IGateway **gateway,
    42                      QSet<IContactImporter*> *contactImporters)
     31bool Library::doInit(
     32        const IBaseIntegrationHelper::Factory &integrationHelperFactory,
     33        IGateway **gateway, QSet<IContactImporter::Builder *> *contactImporters)
    4334{
    44     // Translators
    45     QLocale l; // Loads default locale
    46     QScopedPointer<QTranslator> t(new QTranslator);
    47     if (t->load("post-" + l.name(), ":/locale")) {
    48         translators->insert(t.take());
    49     }
    50 
    5135    // Gateway
    5236    *gateway = new Gateway;
     37    m_integrationHelper.reset(
     38                integrationHelperFactory.createIntegrationHelper(*gateway));
    5339
    5440    // Contact importer
    55     contactImporters->insert(new ContactImporter(integrationHelper()->accountHelper()));
     41    contactImporters->insert(new ContactImporter::Builder(
     42                                 m_integrationHelper->accountHelper()));
    5643
    5744    return true;
  • gateways/Post/gui/post.h

    r315 r376  
    11/*
    22  Swiss Post gateway plugin - The smssender plugin for the Swiss Post platform.
    3   Copyright (C) 2011-2012, gorrión. See http://smssender.gorrion.ch
     3  Copyright (C) 2011-2014, gorrión. See http://smssender.gorrion.ch
    44
    55  This program is free software: you can redistribute it and/or modify
     
    1616  along with this program.  If not, see <http://www.gnu.org/licenses/>.
    1717*/
    18 #ifndef POST_MAIN_H_
    19 #define POST_MAIN_H_
     18#ifndef POST_GUI_POST_H
     19#define POST_GUI_POST_H
    2020
    21 #include <business/impl/abstractlibrary.h>
     21#include "gateways/common/business/baselibrary.h"
    2222
    2323namespace Post {
    2424
    25 class Library : public AbstractLibrary {
    26 public: /* ILibrary */
    27     QString compatibilityVersion() const;
     25class Library : public BaseLibrary {
     26    S_LIBRARY("Post")
    2827
    29     QString identificationKey() const;
    30     SVersion version() const;
     28public:
     29    Library();
    3130
    3231protected:
    33     bool doInit(QSet<QTranslator*> *translators, IGateway **gateway,
    34                 QSet<IContactImporter*> *contactImporters);
     32    bool doInit(const IIntegrationHelper::Factory &integrationHelperFactory,
     33                IGateway **gateway,
     34                QSet<IContactImporter::Builder *> *contactImporters);
     35
     36private:
     37    QScopedPointer<IIntegrationHelper> m_integrationHelper;
    3538};
    3639
    3740} // namespace Post
    3841
    39 #endif /* POST_MAIN_H_ */
     42#endif /* POST_GUI_POST_H */
  • gateways/Post/gui/ui/settingswidget.cpp

    r315 r376  
    11/*
    22  Swiss Post gateway plugin - The smssender plugin for the Swiss Post platform.
    3   Copyright (C) 2011-2012, gorrión. See http://smssender.gorrion.ch
     3  Copyright (C) 2011-2014, gorrión. See http://smssender.gorrion.ch
    44
    55  This program is free software: you can redistribute it and/or modify
     
    1919
    2020#include <QString>
    21 #include <QMessageBox>
    2221
    23 #include <stdexceptions.h>
    24 
    25 #include "business/account.h"
    26 #include "business/gateway.h"
     22#include "common/exceptions/stdexceptions.h"
     23#include "gateways/Post/business/account.h"
     24#include "gateways/Post/business/gateway.h"
    2725
    2826namespace Post {
  • gateways/Post/gui/ui/settingswidget.h

    r315 r376  
    11/*
    22  Swiss Post gateway plugin - The smssender plugin for the Swiss Post platform.
    3   Copyright (C) 2011-2012, gorrión. See http://smssender.gorrion.ch
     3  Copyright (C) 2011-2014, gorrión. See http://smssender.gorrion.ch
    44
    55  This program is free software: you can redistribute it and/or modify
     
    1616  along with this program.  If not, see <http://www.gnu.org/licenses/>.
    1717*/
    18 #ifndef POST_VCSETTINGSWIDGET_H
    19 #define POSt_VCSETTINGSWIDGET_H
     18#ifndef POST_GUI_UI_SETTINGSWIDGET_H
     19#define POST_GUI_UI_SETTINGSWIDGET_H
    2020
    2121#include <QtGui/QWidget>
    2222#include "ui_settingswidget.h"
    2323
    24 #include <ui/iaccountsettingswidget.h>
     24#include "common/gui/ui/iaccountsettingswidget.h"
    2525
    2626namespace Post {
     
    3232
    3333public:
    34     SettingsWidget(QWidget* parent);
     34    SettingsWidget(QWidget *parent);
    3535
    3636public:
     
    4646} // namespace Post
    4747
    48 #endif // POST_VCSETTINGSWIDGET_H
     48#endif // POST_GUI_UI_SETTINGSWIDGET_H
  • gateways/Post/lib/post.qrc

    r151 r376  
    11<RCC>
    22    <qresource prefix="/certs">
    3         <file>VerisignCA3.crt</file>
    4     </qresource>
    5     <qresource prefix="/images">
    6         <file>Post.ico</file>
     3        <file>Verisign_class3_root.crt</file>
     4        <file>VerisignCA_G3.crt</file>
     5        <file>VerisignCA_G5.crt</file>
    76    </qresource>
    87    <qresource prefix="/locale">
    9         <file alias="post-de.qm">../locale/de.qm</file>
    10         <file alias="post-fr.qm">../locale/fr.qm</file>
    11         <file alias="post-it.qm">../locale/it.qm</file>
    12         <file alias="post-de_CH.qm">../locale/de_CH.qm</file>
     8        <file alias="post-base.de.qm">../locale/de.qm</file>
     9        <file alias="post-base.de_CH.qm">../locale/de_CH.qm</file>
     10        <file alias="post-base.fr.qm">../locale/fr.qm</file>
     11        <file alias="post-base.it.qm">../locale/it.qm</file>
    1312    </qresource>
    1413</RCC>
  • gateways/Post/post-base.pro

    r315 r376  
    1 BASE_VERSION = 1.0
    2 !include(../gateways.pri):!include(/usr/include/smssender/gateways.pri):error("Could not include gateways.pri")
    3 TARGET = Post
    4 include(locale/locale.pri)
     1include(../../smssender-base.pri)
     2
     3QT += \
     4    core \
     5    network \
     6    sql
     7
    58HEADERS += \
    6     src/library.h \
    7     src/business/contactimporter/contactimporter.h \
    8     src/business/contactimporter/contactimporter_p.h \
    9     src/business/account.h \
    10     src/business/account_tasks.h \
    11     src/business/gateway.h \
    12     src/ui/settingswidget.h
     9    business/account.h \
     10    business/account_tasks.h \
     11    business/contactimporter/contactimporter.h \
     12    business/gateway.h \
     13
    1314SOURCES += \
    14     src/library.cpp \
    15     src/business/contactimporter/contactimporter.cpp \
    16     src/business/gateway.cpp \
    17     src/business/account_task_sendsms.cpp \
    18     src/business/account.cpp \
    19     src/business/account_costs.cpp \
    20     src/business/account_task_login.cpp \
    21     src/ui/settingswidget.cpp
    22 FORMS += \
    23     src/ui/settingswidget.ui
    24 RESOURCES += lib/Post.qrc
     15    business/account.cpp \
     16    business/account_costs.cpp \
     17    business/account_task_login.cpp \
     18    business/account_task_sendsms.cpp \
     19    business/contactimporter/contactimporter.cpp \
     20    business/gateway.cpp \
     21
     22RESOURCES += \
     23    lib/post.qrc
     24
     25install-dev-files:unix {
     26    ADDITIONAL_INSTALLS = $$HEADERS
     27    ADDITIONAL_INSTALLS_BASE = /usr/include/smssender/gateways/Post
     28    include(../../additional_installs.pri)
     29}
  • gateways/Post/post.pro

    r315 r376  
    1 BASE_VERSION = 1.0
    2 !include(../gateways.pri):!include(/usr/include/smssender/gateways.pri):error("Could not include gateways.pri")
    3 TARGET = Post
    4 include(locale/locale.pri)
    5 HEADERS += \
    6     src/library.h \
    7     src/business/contactimporter/contactimporter.h \
    8     src/business/contactimporter/contactimporter_p.h \
    9     src/business/account.h \
    10     src/business/account_tasks.h \
    11     src/business/gateway.h \
    12     src/ui/settingswidget.h
    13 SOURCES += \
    14     src/library.cpp \
    15     src/business/contactimporter/contactimporter.cpp \
    16     src/business/gateway.cpp \
    17     src/business/account_task_sendsms.cpp \
    18     src/business/account.cpp \
    19     src/business/account_costs.cpp \
    20     src/business/account_task_login.cpp \
    21     src/ui/settingswidget.cpp
    22 FORMS += \
    23     src/ui/settingswidget.ui
    24 RESOURCES += lib/Post.qrc
     1TEMPLATE = subdirs
     2
     3your-princess-is-in-another-castle {
     4    SUBDIRS = post-base
     5    post-base.file = post-base.pro
     6}
     7
     8build-frontend-gui {
     9    SUBDIRS += post-gui
     10    post-gui.file = gui/post-gui.pro
     11}
     12
  • gateways/gateways.pro

    r349 r376  
    55\
    66    ethz \
     7    post \
    78    schoolnet \
    89    smartphone \
     
    1415ethz.depends = gateways-common
    1516
    16 #post.file = Post/post.pro
     17post.file = Post/post.pro
     18post.depends = gateways-common
    1719
    1820schoolnet.file = Schoolnet/schoolnet.pro
Note: See TracChangeset for help on using the changeset viewer.