Changeset 336:af6c0fecdf95 in SMSSender


Ignore:
Timestamp:
Mar 13, 2014 9:55:49 PM (6 years ago)
Author:
Sämy Zehnder <saemy.zehnder@…>
Branch:
separation-frontend-backend
amend_source:
643a75a1335e9c306050db34c8144a8446d8a531
Message:
  • Separates backend and frontend code in the Smartphone gateway.
  • Adds clone() to SContact.
Files:
3 added
1 deleted
6 edited
1 copied
49 moved

Legend:

Unmodified
Added
Removed
  • common/domain/scontact.cpp

    r316 r336  
    2121}
    2222SContact::~SContact() {
     23}
     24
     25SContact *SContact::clone() const {
     26    QScopedPointer<SContact> c(new SContact);
     27    c->setId(id());
     28    c->setName(name());
     29    c->setNumber(number());
     30    c->setAliases(aliases());
     31
     32#ifdef FRONTEND_GUI
     33    c->setImage(image());
     34#endif
     35
     36    return c.take();
    2337}
    2438
  • common/domain/scontact.h

    r319 r336  
    5151#endif
    5252
     53    /**
     54     * Creates an exact copy of this contact. The caller takes ownership.
     55     * @return The copy
     56     */
     57    SContact *clone() const;
     58
    5359signals:
    5460    void idChanged(SContact *contact, int oldId);
  • gateways/Smartphone/business/account.cpp

    r315 r336  
    11/*
    22  Smartphone plugin - The smssender plugin for connecting to smartphones.
    3   Copyright (C) 2012, gorrión. See http://smssender.gorrion.ch
     3  Copyright (C) 2012-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 "business/account.h"
    19 #include "business/account_tasks.h"
     18#include "account.h"
    2019
    2120#include <algorithm>
     
    2322
    2423#include <QDebug>
    25 #include <QDialog>
    2624#include <QThread>
    2725
    28 #include <exceptions/stdexceptions.h>
    29 #include <exceptions/loginaccountexceptions.h>
    30 
    31 #include <domain/snumber.h>
    32 #include <network/snetworkreply.h>
    33 #include <business/impl/defaultlogininittask.h>
    34 
    35 #include "business/accountvalidator.h"
    36 #include "business/connectionhandler.h"
    37 #include "business/gateway.h"
    38 #include "business/smartphoneconnector.h"
    39 #include "business/smartphonemanager.h"
    40 #include "persistence/accountstoragehelper.h"
    41 #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 "gateways/common/business/defaultlogininittask.h"
     31#include "gateways/Smartphone/business/account_tasks.h"
     32#include "gateways/Smartphone/business/accountvalidator.h"
     33#include "gateways/Smartphone/business/connectionhandler.h"
     34#include "gateways/Smartphone/business/gateway.h"
     35#include "gateways/Smartphone/business/smartphoneconnector.h"
     36#include "gateways/Smartphone/business/smartphonemanager.h"
     37#include "gateways/Smartphone/persistence/accountstoragehelper.h"
    4238
    4339namespace Smartphone {
    4440
    4541Account::Account(Gateway *gateway, SmartphoneManager *smartphoneManager)
    46     : AbstractAccount(gateway)
     42    : BaseAccount(gateway)
    4743    , m_smartphoneManager(smartphoneManager)
    4844{
     
    7167    return NULL;
    7268}
    73 ISMSSendTask* Account::doCreateSMSSendTask(const QString& message, const QSet<SContact>& recipients) {
     69ISMSSendTask* Account::doCreateSMSSendTask(const QString& message,
     70                                           const QSet<const SContact*> &recipients) {
    7471    return new SMSSendTask(*m_smartphoneManager->connector(),
    7572                           this, message, recipients);
  • gateways/Smartphone/business/account.h

    r315 r336  
    11/*
    22  Smartphone plugin - The smssender plugin for connecting to smartphones.
    3   Copyright (C) 2012, gorrión. See http://smssender.gorrion.ch
     3  Copyright (C) 2012-2014-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 SMARTPHONE_BCACCOUNT_H_
    19 #define SMARTPHONE_BCACCOUNT_H_
     18#ifndef SMARTPHONE_ACCOUNT_H
     19#define SMARTPHONE_ACCOUNT_H
    2020
    21 #include <business/impl/abstractaccount.h>
    22 #include <network/snetworkhelper.h>
    23 #include <persistence/imainstorage.h>
    24 #include <persistence/istoragehelper.h>
    25 
    26 #include "business/datatypes.h"
     21#include "gateways/common/business/baseaccount.h"
     22#include "gateways/Smartphone/business/datatypes.h"
    2723
    2824namespace Smartphone {
     
    3127class SmartphoneManager;
    3228
    33 class Account : public AbstractAccount {
     29class Account : public BaseAccount {
    3430    Q_OBJECT
    3531
    36     friend class ContactImporter; // networkHelper()
    37     friend class AccountLoginTask; // reloadOnlineParams(), networkHelper()
    38     friend class SMSSendTask; // reloadOnlineParams(), networkHelper()
     32//    friend class ContactImporter; // networkHelper()
     33//    friend class AccountLoginTask; // reloadOnlineParams(), networkHelper()
     34//    friend class SMSSendTask; // reloadOnlineParams(), networkHelper()
    3935
    4036public:
    4137    enum Property {
    42         Device = AbstractAccount::LastProperty,
     38        Device = BaseAccount::LastProperty,
    4339
    4440        LastProperty = Device
     
    6662    IAccountInitTask *doCreateInitTask();
    6763    IAccountLoginTask *doCreateLoginTask();
    68     ISMSSendTask *doCreateSMSSendTask(const QString &message, const QSet<SContact> &recipients);
     64    ISMSSendTask *doCreateSMSSendTask(const QString &message,
     65                                      const QSet<const SContact *> &recipients);
    6966
    7067protected: /* AbstractLoginAccount */
     
    7673
    7774private:
    78     Q_DISABLE_COPY(Account)
    79 
    80 private:
    8175    SmartphoneManager * const m_smartphoneManager;
    8276
    8377    Smartphone m_device;
     78
     79    Q_DISABLE_COPY(Account)
    8480};
    8581
    8682}
    8783
    88 #endif /* SMARTPHONE_BCACCOUNT_H_ */
     84#endif /* SMARTPHONE_ACCOUNT_H */
  • gateways/Smartphone/business/account_costs.cpp

    r315 r336  
    11/*
    22  Smartphone plugin - The smssender plugin for connecting to smartphones.
    3   Copyright (C) 2012, gorrión. See http://smssender.gorrion.ch
     3  Copyright (C) 2012-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 "business/account.h"
     18#include "account.h"
    1919
    2020#include "math.h"
    2121
    22 #include "business/gateway.h"
     22#include "gateways/Smartphone/business/gateway.h"
    2323
    2424namespace Smartphone {
  • gateways/Smartphone/business/account_task_sendsms.cpp

    r315 r336  
    11/*
    22  Smartphone plugin - The smssender plugin for connecting to smartphones.
    3   Copyright (C) 2012, gorrión. See http://smssender.gorrion.ch
     3  Copyright (C) 2012-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 "business/account_tasks.h"
     18#include "account_tasks.h"
    1919
    2020#include <math.h>
    2121
    22 #include <domain/snumber.h>
    23 #include <network/snetworkreply.h>
    24 #include <utils/sutils.h>
    25 
    26 #include "business/connectionhandler.h"
    27 #include "business/gateway.h"
    28 #include "business/smartphoneconnector.h"
    29 #include "business/smartphonemanager.h"
     22#include "common/domain/snumber.h"
     23#include "common/network/snetworkreply.h"
     24#include "common/utils/sutils.h"
     25#include "gateways/Smartphone/business/connectionhandler.h"
     26#include "gateways/Smartphone/business/gateway.h"
     27#include "gateways/Smartphone/business/smartphoneconnector.h"
     28#include "gateways/Smartphone/business/smartphonemanager.h"
    3029
    3130namespace Smartphone {
    3231
    3332SMSSendTask::SMSSendTask(const SmartphoneConnector &smartphoneConnector,
    34                          Account *account, const QString &message, const QSet<SContact> &recipients)
    35     : AbstractSMSSendTask(account, message, recipients)
     33                         Account *account, const QString &message,
     34                         const QSet<const SContact *> &recipients)
     35    : BaseSMSSendTask(account, message, recipients)
    3636    , m_smartphoneConnector(smartphoneConnector)
    3737{
     
    4141    Q_ASSERT(!message().isEmpty());
    4242    Q_ASSERT(!recipients().isEmpty());
    43     Q_ASSERT(results_.isEmpty()); // You cannot reuse a sms-send task
     43    Q_ASSERT(m_results.isEmpty()); // You cannot reuse a sms-send task
    4444
    4545    qDebug() << "Start sending SMS";
     
    5252
    5353    // Start sending the sms
    54     remainingReplies_ = recipients().count();
    55     foreach (SContact recipient, recipients()) {
     54    m_remainingReplies = recipients().count();
     55    foreach (const SContact *recipient, recipients()) {
    5656        sendSMS(connectionHandler, recipient, message());
    5757    }
    5858
    5959    // Wait for all replies
    60     QMutexLocker locker(&identsMutex_);
    61     waitForReplies_.wait(&identsMutex_, 20000); // Wait at most 20s
     60    QMutexLocker locker(&m_identsMutex);
     61    m_waitForReplies.wait(&m_identsMutex, 20000); // Wait at most 20s
    6262
    63     if (smsIdents_.size() > 0) {
     63    if (m_smsIdents.size() > 0) {
    6464        // Timeout occured -> set result
    65         foreach (QString smsIdent, smsIdents_) {
    66             results_.insert(smsIdent, Timeout);
     65        foreach (QString smsIdent, m_smsIdents) {
     66            m_results.insert(smsIdent, Timeout);
    6767        }
    6868    }
     
    8787}
    8888
    89 void SMSSendTask::sendSMS(const ConnectionHandler *connectionHandler, const SContact &recipient, const QString &message) {
    90     QMutexLocker locker(&identsMutex_);
     89void SMSSendTask::sendSMS(const ConnectionHandler *connectionHandler,
     90                          const SContact *recipient, const QString &message) {
     91    QMutexLocker locker(&m_identsMutex);
    9192
    9293    QString smsIdent = SUtils::getRandomString(10);
    93     smsIdents_.insert(smsIdent);
    94     smsIdentToRecipient_.insert(smsIdent, recipient);
     94    m_smsIdents.insert(smsIdent);
     95    m_smsIdentToRecipient.insert(smsIdent, recipient);
    9596
    96     connectionHandler->sendSms(smsIdent, recipient.number(), message);
     97    connectionHandler->sendSms(smsIdent, recipient->number(), message);
    9798}
    9899
    99 void SMSSendTask::onSmsSendResultReceived(QString smsIdent, SendSmsResultHandlerV1::Error error) {
    100     QMutexLocker locker(&identsMutex_);
     100void SMSSendTask::onSmsSendResultReceived(QString smsIdent,
     101                                          SendSmsResultHandlerV1::Error error) {
     102    QMutexLocker locker(&m_identsMutex);
    101103
    102     if (!smsIdents_.contains(smsIdent)) {
     104    if (!m_smsIdents.contains(smsIdent)) {
    103105        return;
    104106    }
    105107
    106     smsIdents_.remove(smsIdent);
    107     --remainingReplies_;
    108     results_.insert(smsIdent, error);
     108    m_smsIdents.remove(smsIdent);
     109    --m_remainingReplies;
     110    m_results.insert(smsIdent, error);
    109111
    110     int finished = results_.size();
    111     int totalReplies = remainingReplies_ + finished;
     112    int finished = m_results.size();
     113    int totalReplies = m_remainingReplies + finished;
    112114    setProgress(100 * finished / totalReplies);
    113115
    114     if (remainingReplies_ == 0) {
    115         waitForReplies_.wakeAll();
     116    if (m_remainingReplies == 0) {
     117        m_waitForReplies.wakeAll();
    116118    }
    117119}
     
    131133    int firstE = -1;
    132134
    133     QHashIterator<QString, int> it(results_);
     135    QHashIterator<QString, int> it(m_results);
    134136    while (it.hasNext()) {
    135137        it.next();
     
    157159        *sameError = errorMsg;
    158160
    159         if (smsIdentToRecipient_.size() > 1) {
    160             ret += QString("%1: %2\n").arg(smsIdentToRecipient_.value(it.key()).name()).arg(errorMsg);
     161        if (m_smsIdentToRecipient.size() > 1) {
     162            ret += QString("%1: %2\n")
     163                    .arg(m_smsIdentToRecipient.value(it.key())->name())
     164                    .arg(errorMsg);
    161165        } else {
    162166            ret = errorMsg;
     
    168172
    169173Account* SMSSendTask::account() const {
    170     return static_cast<Account*>(AbstractSMSSendTask::account());
     174    return static_cast<Account*>(BaseSMSSendTask::account());
    171175}
    172176
  • gateways/Smartphone/business/account_tasks.h

    r315 r336  
    11/*
    22  Smartphone plugin - The smssender plugin for connecting to smartphones.
    3   Copyright (C) 2012, gorrión. See http://smssender.gorrion.ch
     3  Copyright (C) 2012-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 SMARTPHONE_BCACCOUNT_TASKS_H_
    19 #define SMARTPHONE_BCACCOUNT_TASKS_H_
     18#ifndef SMARTPHONE_ACCOUNT_TASKS_H
     19#define SMARTPHONE_ACCOUNT_TASKS_H
    2020
    2121#include <QMutex>
     
    2323#include <QString>
    2424
    25 #include <business/impl/abstractaccount_tasks.h>
    26 
    27 #include "business/account.h"
    28 #include "business/datahandler/sendsmsresponsehandler_v1.h"
     25#include "gateways/common/business/baseaccount_tasks.h"
     26#include "gateways/Smartphone/business/account.h"
     27#include "gateways/Smartphone/business/datahandler/sendsmsresponsehandler_v1.h"
    2928
    3029namespace Smartphone {
     
    3332class SmartphoneConnector;
    3433
    35 class SMSSendTask : public AbstractSMSSendTask {
     34class SMSSendTask : public BaseSMSSendTask {
    3635    Q_OBJECT
    3736
    3837public:
    3938    SMSSendTask(const SmartphoneConnector &smartphoneConnector,
    40                 Account *account, const QString &message, const QSet<SContact> &recipients);
     39                Account *account, const QString &message,
     40                const QSet<const SContact *> &recipients);
    4141
    4242protected: /* AbstractAccountSendSMSTask */
     
    4545
    4646private:
    47     void sendSMS(const ConnectionHandler *connectionHandler, const SContact &recipient, const QString &message);
     47    void sendSMS(const ConnectionHandler *connectionHandler,
     48                 const SContact *recipient, const QString &message);
    4849    QString errorString(bool *hasError, bool *allSame, QString *sameError) const;
    4950
    5051private slots:
    51     void onSmsSendResultReceived(QString smsIdent, SendSmsResultHandlerV1::Error error);
     52    void onSmsSendResultReceived(QString smsIdent,
     53                                 SendSmsResultHandlerV1::Error error);
    5254
    5355private:
     
    6163    const SmartphoneConnector &m_smartphoneConnector;
    6264
    63     QMutex identsMutex_;
    64     QSet<QString> smsIdents_;
    65     int remainingReplies_;
    66     QWaitCondition waitForReplies_;
     65    QMutex m_identsMutex;
     66    QSet<QString> m_smsIdents;
     67    int m_remainingReplies;
     68    QWaitCondition m_waitForReplies;
    6769
    68     QHash<QString, SContact> smsIdentToRecipient_;
    69     QHash<QString, int> results_;
     70    QHash<QString, const SContact*> m_smsIdentToRecipient;
     71    QHash<QString, int> m_results;
    7072};
    7173
    7274}
    7375
    74 #endif /* SMARTPHONE_BCACCOUNT_TASKS_H_ */
     76#endif /* SMARTPHONE_ACCOUNT_TASKS_H */
  • gateways/Smartphone/business/accountvalidator.cpp

    r315 r336  
    11/*
    22  Smartphone plugin - The smssender plugin for connecting to smartphones.
    3   Copyright (C) 2012, gorrión. See http://smssender.gorrion.ch
     3  Copyright (C) 2012-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 "business/accountvalidator.h"
     18#include "accountvalidator.h"
    1919
    2020#include <QObject>
    2121
    22 #include <validation/svalidationresult.h>
    23 
    24 #include "business/account.h"
     22#include "common/validation/svalidationresult.h"
     23#include "gateways/Smartphone/business/account.h"
    2524
    2625namespace Smartphone {
  • gateways/Smartphone/business/accountvalidator.h

    r315 r336  
    11/*
    22  Smartphone plugin - The smssender plugin for connecting to smartphones.
    3   Copyright (C) 2012, gorrión. See http://smssender.gorrion.ch
     3  Copyright (C) 2012-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 SMARTPHONE_BCACCOUNTVALIDATOR_H
    19 #define SMARTPHONE_BCACCOUNTVALIDATOR_H
     18#ifndef SMARTPHONE_ACCOUNTVALIDATOR_H
     19#define SMARTPHONE_ACCOUNTVALIDATOR_H
    2020
    21 #include <business/ivalidator.h>
     21#include "common/business/ivalidator.h"
    2222
    2323namespace Smartphone {
     
    3838} // namespace Smartphone
    3939
    40 #endif // SMARTPHONE_BCACCOUNTVALIDATOR_H
     40#endif // SMARTPHONE_ACCOUNTVALIDATOR_H
  • gateways/Smartphone/business/connectionhandler.cpp

    r315 r336  
    11/*
    22  Smartphone plugin - The smssender plugin for connecting to smartphones.
    3   Copyright (C) 2012, gorrión. See http://smssender.gorrion.ch
     3  Copyright (C) 2012-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 "business/connectionhandler.h"
     18#include "connectionhandler.h"
     19
     20#include <cryptopp/aes.h>
     21#include <cryptopp/eax.h>
     22#include <cryptopp/osrng.h>
    1923
    2024#include <QDebug>
     
    2226#include <QtXml/QDomDocument>
    2327
    24 #include <cryptopp/aes.h>
    25 #include <cryptopp/eax.h>
    26 #include <cryptopp/osrng.h>
    27 
    28 #include <exceptions/eexception.h>
    29 #include <utils/sutils.h>
    30 
    31 #include "business/datahandler/contactsresponsehandler_v1.h"
    32 #include "business/datahandler/hellohandler_v1.h"
    33 #include "business/datahandler/pinghandler_v1.h"
    34 #include "business/packages/packagewizard.h"
    35 #include "business/smartphoneconnector.h"
    36 #include "business/smartphonemanager.h"
     28#include "common/exceptions/eexception.h"
     29#include "common/utils/sutils.h"
     30#include "gateways/Smartphone/business/datahandler/contactsresponsehandler_v1.h"
     31#include "gateways/Smartphone/business/datahandler/hellohandler_v1.h"
     32#include "gateways/Smartphone/business/datahandler/pinghandler_v1.h"
     33#include "gateways/Smartphone/business/packages/packagewizard.h"
     34#include "gateways/Smartphone/business/smartphoneconnector.h"
     35#include "gateways/Smartphone/business/smartphonemanager.h"
    3736
    3837namespace Smartphone {
     
    5352
    5453    ContactsResponseHandlerV1 *contactsResponseHandler = new ContactsResponseHandlerV1;
    55     connect(contactsResponseHandler, SIGNAL(contactsArrived(QList<SContact>)),
    56             this, SIGNAL(contactsArrived(QList<SContact>)));
     54    connect(contactsResponseHandler, SIGNAL(contactsArrived(QList<const SContact *>)),
     55            this, SIGNAL(contactsArrived(QList<const SContact *>)),
     56            Qt::DirectConnection); // contacts are deleted after emit
    5757    m_dataHandlers.insert(contactsResponseHandler);
    5858
     
    8686    emit aboutToFinish(this);
    8787
    88     foreach (IDataHandler *dataHandler, m_dataHandlers) {
    89         delete dataHandler;
    90     }
     88    qDeleteAll(m_dataHandlers);
    9189    m_dataHandlers.clear();
    9290}
  • gateways/Smartphone/business/connectionhandler.h

    r315 r336  
    11/*
    22  Smartphone plugin - The smssender plugin for connecting to smartphones.
    3   Copyright (C) 2012, gorrión. See http://smssender.gorrion.ch
     3  Copyright (C) 2012-2014, gorrión. See http://smssender.gorrion.ch
    44
    55  This program is free software: you can redistribute it and/or modify
     
    2626#include <QTcpSocket>
    2727
    28 #include <domain/scontact.h>
    29 #include <domain/snumber.h>
    30 
    31 #include "business/datatypes.h"
    32 #include "business/datahandler/sendsmsresponsehandler_v1.h"
     28#include "common/domain/scontact.h"
     29#include "common/domain/snumber.h"
     30#include "gateways/Smartphone/business/datahandler/sendsmsresponsehandler_v1.h"
     31#include "gateways/Smartphone/business/datatypes.h"
    3332
    3433namespace Smartphone {
     
    4342
    4443public:
     44    // Takes ownership of cSocket
    4545    ConnectionHandler(SmartphoneManager *smartphoneManager, QTcpSocket *cSocket, const Smartphone &peerDevice);
    4646    ~ConnectionHandler();
     
    6161signals:
    6262    void peerIdentified(ConnectionHandler *connectionHandler);
    63     void contactsArrived(const QList<SContact> &contacts);
     63    void contactsArrived(const QList<const SContact *> &contacts);
    6464    void smsSendResultReceived(const QString &smsIdent, SendSmsResultHandlerV1::Error error);
    6565    void aboutToFinish(ConnectionHandler *connectionHandler);
  • gateways/Smartphone/business/contactimporter/contactimporter.cpp

    r315 r336  
    11/*
    22  Smartphone plugin - The smssender plugin for connecting to smartphones.
    3   Copyright (C) 2012, gorrión. See http://smssender.gorrion.ch
     3  Copyright (C) 2012-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 "business/contactimporter/contactimporter.h"
    19 #include "business/contactimporter/contactimporter_p.h"
     18#include "contactimporter.h"
    2019
    21 #include <domain/scontact.h>
    22 #include <domain/snumber.h>
    23 #include <network/snetworkreply.h>
    24 
    25 #include "business/connectionhandler.h"
    26 #include "business/gateway.h"
    27 #include "business/smartphoneconnector.h"
    28 #include "business/smartphonemanager.h"
     20#include "common/domain/scontact.h"
     21#include "common/domain/snumber.h"
     22#include "common/network/snetworkreply.h"
     23#include "gateways/Smartphone/business/connectionhandler.h"
     24#include "gateways/Smartphone/business/gateway.h"
     25#include "gateways/Smartphone/business/smartphoneconnector.h"
     26#include "gateways/Smartphone/business/smartphonemanager.h"
    2927
    3028namespace Smartphone {
    3129
    32 ContactImporter::ContactImporter(IAccountIntegrationHelper *accountHelper,
    33                                  const SmartphoneConnector &smartphoneConnector)
    34     : m_dataManager(new ContactImporterDataManager)
    35     , m_accountHelper(accountHelper)
     30ContactImporter::ContactImporter(Account *account,
     31                                 const SmartphoneConnector *smartphoneConnector)
     32    : m_account(account)
    3633    , m_smartphoneConnector(smartphoneConnector)
    3734{
    3835}
    3936
    40 QString ContactImporter::describingName() const {
     37void ContactImporter::importContacts(QSet<SContact *> *contacts) {
     38    Q_ASSERT(m_account->isLoggedIn());
     39
     40    const ConnectionHandler *connectionHandler =
     41            m_smartphoneConnector->connectionHandler(m_account->device());
     42    Q_ASSERT(connectionHandler != NULL);
     43
     44    // Prepares the eventloop.
     45    QEventLoop eventLoop;
     46    m_eventLoop = &eventLoop;
     47    connect(connectionHandler, SIGNAL(contactsArrived(QList<const SContact *>)),
     48            this, SLOT(onContactsArrived(QList<const SContact *>)),
     49            Qt::DirectConnection); // contacts are deleted afterwards.
     50    connect(connectionHandler, SIGNAL(aboutToFinish(ConnectionHandler*)),
     51            &eventLoop, SLOT(quit()));
     52
     53    // Sets a timeout of 30 seconds.
     54    QTimer t;
     55    t.singleShot(30 * 1000, &eventLoop, SLOT(quit()));
     56
     57    // Starts the import.
     58    connectionHandler->sendContactsRequest();
     59
     60    // Waits for the import to finish.
     61    eventLoop.exec(QEventLoop::WaitForMoreEvents |
     62                   QEventLoop::ExcludeUserInputEvents);
     63
     64    m_eventLoop = NULL;
     65
     66    // Processes the imported contacts.
     67    contacts->unite(m_importedContacts.toSet());
     68}
     69
     70void ContactImporter::onContactsArrived(const QList<const SContact *> &contacts) {
     71    if (m_eventLoop) {
     72        foreach (const SContact *contact, contacts) {
     73            m_importedContacts.append(contact->clone());
     74        }
     75        m_eventLoop->quit();
     76    }
     77}
     78
     79/********************************** Builder ***********************************/
     80
     81ContactImporter::Builder::Builder(IAccountIntegrationHelper *accountHelper,
     82                                  SmartphoneConnector *smartphoneConnector)
     83    : m_accountHelper(accountHelper)
     84    , m_smartphoneConnector(smartphoneConnector)
     85{
     86}
     87
     88QString ContactImporter::Builder::description() const {
    4189    if (isApplicable()) {
    4290        return QObject::tr("Import contacts from a smartphone.");
     
    4694}
    4795
    48 bool ContactImporter::isApplicable() const {
     96bool ContactImporter::Builder::isApplicable() const {
    4997    return m_accountHelper->hasLoggedInAccounts();
    5098}
    5199
    52100
    53 void ContactImporter::init() {
    54     const QSet<IAccount*> &loggedInIAccounts = m_accountHelper->loggedInAccounts();
    55 
    56     // FIXME: is this cast save?
    57     const QSet<Account*> &loggedInAccounts = reinterpret_cast<const QSet<Account*> &>(loggedInIAccounts);
    58     m_dataManager->setSelectedAccounts(loggedInAccounts);
    59 }
    60 QList<QWizardPage*> ContactImporter::createPreImportPages(QWidget* parent) {
    61     Q_UNUSED(parent)
    62     return QList<QWizardPage*>();
    63 }
    64 
    65 
    66 class ContactImportWaitForContact : public QObject {
    67     Q_OBJECT
    68 
    69 public:
    70     QList<SContact> waitForContactsToArrive(const ConnectionHandler &connectionHandler) {
    71         QEventLoop eventLoop;
    72         m_eventLoop = &eventLoop;
    73         connect(&connectionHandler, SIGNAL(contactsArrived(QList<SContact>)), this, SLOT(onContactsArrived(QList<SContact>)));
    74         connect(&connectionHandler, SIGNAL(aboutToFinish(ConnectionHandler*)), m_eventLoop, SLOT(quit()));
    75 
    76         // Send the request
    77         connectionHandler.sendContactsRequest();
    78 
    79         // Wait for them to arrive
    80         eventLoop.exec(QEventLoop::WaitForMoreEvents | QEventLoop::ExcludeUserInputEvents);
    81 
    82         return m_importedContacts;
     101void ContactImporter::Builder::createImporters(QSet<IContactImporter *> *importers) {
     102    foreach (IAccount *account, m_accountHelper->accounts()) {
     103        if (account->isLoggedIn()) {
     104            importers->insert(new ContactImporter(static_cast<Account *>(account),
     105                                                  m_smartphoneConnector));
     106        }
    83107    }
    84 
    85 private slots:
    86     void onContactsArrived(const QList<SContact> &contacts) {
    87         m_importedContacts = contacts;
    88         m_eventLoop->quit();
    89     }
    90 
    91 private:
    92     QList<SContact> m_importedContacts;
    93     QEventLoop *m_eventLoop;
    94 };
    95 
    96 QSet<SContact> ContactImporter::importContacts() {
    97     QList<SContact> importedContacts;
    98 
    99     foreach (Account *account, m_dataManager->selectedAccounts()) {
    100         if (!account->isLoggedIn()) continue;
    101 
    102         const ConnectionHandler *connectionHandler = m_smartphoneConnector.connectionHandler(account->device());
    103         Q_ASSERT(connectionHandler != NULL);
    104 
    105         // wait for the import to finish
    106         ContactImportWaitForContact ciwfc;
    107         importedContacts.append(ciwfc.waitForContactsToArrive(*connectionHandler));
    108     }
    109 
    110     return importedContacts.toSet();
    111108}
    112109
  • gateways/Smartphone/business/contactimporter/contactimporter.h

    r315 r336  
    11/*
    22  Smartphone plugin - The smssender plugin for connecting to smartphones.
    3   Copyright (C) 2012, gorrión. See http://smssender.gorrion.ch
     3  Copyright (C) 2012-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 SMARTPHONE_BCCONTACTIMPORTER_H_
    19 #define SMARTPHONE_BCCONTACTIMPORTER_H_
     18#ifndef SMARTPHONE_CONTACTIMPORTER_CONTACTIMPORTER_H
     19#define SMARTPHONE_CONTACTIMPORTER_CONTACTIMPORTER_H
    2020
    2121#include <QEventLoop>
     
    2323#include <QScopedPointer>
    2424
    25 #include <business/iaccount.h>
    26 #include <business/icontactimporter.h>
    27 #include <business/iintegration.h>
    28 
    29 #include "business/account.h"
     25#include "common/business/iaccount.h"
     26#include "common/business/icontactimporter.h"
     27#include "common/business/iintegration.h"
     28#include "gateways/Smartphone/business/account.h"
    3029
    3130namespace Smartphone {
     
    3635class SmartphoneConnector;
    3736
    38 class ContactImporter : public IContactImporter {
    39 public:
    40     ContactImporter(IAccountIntegrationHelper *accountHelper, const SmartphoneConnector &smartphoneConnector);
     37class ContactImporter : public QObject, public IContactImporter {
     38    Q_OBJECT
     39    Q_INTERFACES(IContactImporter)
    4140
    4241public: /* IContactImporter */
    43     QString describingName() const;
    44     bool    isApplicable() const;
     42    ContactImporter(Account *account,
     43                    const SmartphoneConnector *smartphoneConnector);
    4544
    46     void                init();
    47     QList<QWizardPage*> preImportPages(QWidget* parent);
    48     QSet<SContact>      importContacts();
     45    void importContacts(QSet<SContact *> *contacts);
     46
     47    class Builder : public IContactImporter::Builder {
     48    public:
     49        Builder(IAccountIntegrationHelper *accountHelper,
     50                SmartphoneConnector *smartphoneConnector);
     51
     52    public:
     53        QString description() const;
     54        bool isApplicable() const;
     55
     56        void createImporters(QSet<IContactImporter *> *importers);
     57
     58    private:
     59        IAccountIntegrationHelper * const m_accountHelper;
     60    const SmartphoneConnector * const m_smartphoneConnector;
     61
     62        Q_DISABLE_COPY(Builder)
     63    };
     64
     65private slots:
     66    void onContactsArrived(const QList<const SContact *> &contacts);
    4967
    5068private:
    51     QScopedPointer<ContactImporterDataManager> m_dataManager;
    52     IAccountIntegrationHelper * const m_accountHelper;
    53     const SmartphoneConnector &m_smartphoneConnector;
     69    Account * const m_account;
     70    const SmartphoneConnector * const m_smartphoneConnector;
     71
     72    QEventLoop *m_eventLoop;
     73    QList<SContact *> m_importedContacts;
     74
     75    Q_DISABLE_COPY(ContactImporter)
    5476};
    5577
    5678}
    5779
    58 #endif /* SMARTPHONE_BCCONTACTIMPORTER_H_ */
     80#endif /* SMARTPHONE_CONTACTIMPORTER_CONTACTIMPORTER_H */
  • gateways/Smartphone/business/datahandler/abstractdatahandler.cpp

    r315 r336  
    11/*
    22  Smartphone plugin - The smssender plugin for connecting to smartphones.
    3   Copyright (C) 2012, gorrión. See http://smssender.gorrion.ch
     3  Copyright (C) 2012-2014, gorrión. See http://smssender.gorrion.ch
    44
    55  This program is free software: you can redistribute it and/or modify
     
    2323
    2424AbstractDataHandler::AbstractDataHandler(AbstractDataHandler::EncryptionNeeds encryptionNeeds)
    25     : encryptionNeeds_(encryptionNeeds)
     25    : m_encryptionNeeds(encryptionNeeds)
    2626{
    2727}
     
    3030    QDomElement root = data.documentElement();
    3131
    32     if ((encryptionNeeds_ != NoEncryptionNeeded) && !encrypted) {
     32    if ((m_encryptionNeeds != NoEncryptionNeeded) && !encrypted) {
    3333        return false; // Should have been encrypted
    3434    }
  • gateways/Smartphone/business/datahandler/abstractdatahandler.h

    r315 r336  
    11/*
    22  Smartphone plugin - The smssender plugin for connecting to smartphones.
    3   Copyright (C) 2012, gorrión. See http://smssender.gorrion.ch
     3  Copyright (C) 2012-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 SMARTPHONE_ABSTRACTDATAHANDLER_H
    19 #define SMARTPHONE_ABSTRACTDATAHANDLER_H
     18#ifndef SMARTPHONE_DATAHANDLER_ABSTRACTDATAHANDLER_H
     19#define SMARTPHONE_DATAHANDLER_ABSTRACTDATAHANDLER_H
    2020
    2121#include "idatahandler.h"
     
    4242
    4343private:
    44     EncryptionNeeds encryptionNeeds_;
     44    EncryptionNeeds m_encryptionNeeds;
    4545};
    4646
    4747} // namespace Smartphone
    4848
    49 #endif // SMARTPHONE_ABSTRACTDATAHANDLER_H
     49#endif // SMARTPHONE_DATAHANDLER_ABSTRACTDATAHANDLER_H
  • gateways/Smartphone/business/datahandler/contactsresponsehandler_v1.cpp

    r315 r336  
    11/*
    22  Smartphone plugin - The smssender plugin for connecting to smartphones.
    3   Copyright (C) 2012, gorrión. See http://smssender.gorrion.ch
     3  Copyright (C) 2012-2014, gorrión. See http://smssender.gorrion.ch
    44
    55  This program is free software: you can redistribute it and/or modify
     
    4747      </contactsResponse>
    4848      */
    49     QList<SContact> contacts;
     49    QList<const SContact *> contacts;
    5050
    5151    QDomElement root = data.documentElement();
     
    5454    QDomElement contactNode = contactsNode.firstChildElement("contact");
    5555    while (!contactNode.isNull()) {
    56         QList<SContact> parsedContacts = parseContact(contactNode);
     56        QList<const SContact *> parsedContacts = parseContact(contactNode);
    5757        contacts.append(parsedContacts);
    5858
     
    6262    emit contactsArrived(contacts);
    6363
     64    qDeleteAll(contacts);
     65
    6466    return true;
    6567}
    6668
    67 QList<SContact> ContactsResponseHandlerV1::parseContact(const QDomElement &contactNode) {
    68     QList<SContact> contacts;
     69QList<const SContact *> ContactsResponseHandlerV1::parseContact(
     70        const QDomElement &contactNode) {
     71    QList<const SContact *> contacts;
    6972
    7073    // Parse names
     
    8588    // Create for each number a seperate contact
    8689    foreach (SNumber number, numbers) {
    87         SContact contact;
     90        QScopedPointer<SContact> contact(new SContact);
    8891
    89         contact.setName(name);
    90         contact.setAliases(aliases);
    91         contact.setNumber(number);
    92         contact.setImage(image);
     92        contact->setName(name);
     93        contact->setAliases(aliases);
     94        contact->setNumber(number);
     95        contact->setImage(image);
    9396
    94         contacts.append(contact);
     97        contacts.append(contact.take());
    9598    }
    9699
  • gateways/Smartphone/business/datahandler/contactsresponsehandler_v1.h

    r315 r336  
    11/*
    22  Smartphone plugin - The smssender plugin for connecting to smartphones.
    3   Copyright (C) 2012, gorrión. See http://smssender.gorrion.ch
     3  Copyright (C) 2012-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 SMARTPHONE_CONTACTSRESPONSEHANDLER_V1_H
    19 #define SMARTPHONE_CONTACTSRESPONSEHANDLER_V1_H
    20 
    21 #include "abstractdatahandler.h"
     18#ifndef SMARTPHONE_DATAHANDLER_CONTACTSRESPONSEHANDLER_V1_H
     19#define SMARTPHONE_DATAHANDLER_CONTACTSRESPONSEHANDLER_V1_H
    2220
    2321#include <QDomElement>
    2422#include <QList>
    2523
    26 #include <domain/scontact.h>
    27 #include <domain/snumber.h>
     24#include "common/domain/scontact.h"
     25#include "common/domain/snumber.h"
     26#include "gateways/Smartphone/business/datahandler/abstractdatahandler.h"
    2827
    2928namespace Smartphone {
     
    3938
    4039signals:
    41     void contactsArrived(const QList<SContact> &contacts);
     40    // Needs to be connected directly, since contacts are deleted after emit.
     41    void contactsArrived(const QList<const SContact *> &contacts);
    4242
    4343protected:
     
    4646
    4747private:
    48     QList<SContact> parseContact(const QDomElement &contactNode);
     48    QList<const SContact *> parseContact(const QDomElement &contactNode);
    4949    QStringList parseNames(const QDomElement &namesNode);
    5050    QList<SNumber> parseNumbers(const QDomElement &numbersNode);
     
    5353} // namespace Smartphone
    5454
    55 #endif // SMARTPHONE_CONTACTSRESPONSEHANDLER_V1_H
     55#endif // SMARTPHONE_DATAHANDLER_CONTACTSRESPONSEHANDLER_V1_H
  • gateways/Smartphone/business/datahandler/hellohandler_v1.cpp

    r315 r336  
    11/*
    22  Smartphone plugin - The smssender plugin for connecting to smartphones.
    3   Copyright (C) 2012, gorrión. See http://smssender.gorrion.ch
     3  Copyright (C) 2012-2014, gorrión. See http://smssender.gorrion.ch
    44
    55  This program is free software: you can redistribute it and/or modify
     
    1818#include "hellohandler_v1.h"
    1919
    20 #include "business/connectionhandler.h"
    21 #include "business/smartphonemanager.h"
    22 #include "business/smartphoneconnector.h"
     20#include "gateways/Smartphone/business/connectionhandler.h"
     21#include "gateways/Smartphone/business/smartphonemanager.h"
     22#include "gateways/Smartphone/business/smartphoneconnector.h"
    2323
    2424namespace Smartphone {
  • gateways/Smartphone/business/datahandler/hellohandler_v1.h

    r315 r336  
    11/*
    22  Smartphone plugin - The smssender plugin for connecting to smartphones.
    3   Copyright (C) 2012, gorrión. See http://smssender.gorrion.ch
     3  Copyright (C) 2012-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 SMARTPHONE_HELLOHANDLER_V1_H
    19 #define SMARTPHONE_HELLOHANDLER_V1_H
     18#ifndef SMARTPHONE_DATAHANDLER_HELLOHANDLER_V1_H
     19#define SMARTPHONE_DATAHANDLER_HELLOHANDLER_V1_H
    2020
    2121#include <QObject>
    2222
    23 #include "business/datahandler/abstractdatahandler.h"
    24 #include "business/datatypes.h"
     23#include "gateways/Smartphone/business/datahandler/abstractdatahandler.h"
     24#include "gateways/Smartphone/business/datatypes.h"
    2525
    2626namespace Smartphone {
     
    5151} // namespace Smartphone
    5252
    53 #endif // SMARTPHONE_HELLOHANDLER_V1_H
     53#endif // SMARTPHONE_DATAHANDLER_HELLOHANDLER_V1_H
  • gateways/Smartphone/business/datahandler/idatahandler.h

    r315 r336  
    11/*
    22  Smartphone plugin - The smssender plugin for connecting to smartphones.
    3   Copyright (C) 2012, gorrión. See http://smssender.gorrion.ch
     3  Copyright (C) 2012-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 SMARTPHONE_IDATAHANDLER_H
    19 #define SMARTPHONE_IDATAHANDLER_H
     18#ifndef SMARTPHONE_DATAHANDLER_IDATAHANDLER_H
     19#define SMARTPHONE_DATAHANDLER_IDATAHANDLER_H
    2020
    2121#include <QObject>
     
    3434}
    3535
    36 #endif // SMARTPHONE_IDATAHANDLER_H
     36#endif // SMARTPHONE_DATAHANDLER_IDATAHANDLER_H
  • gateways/Smartphone/business/datahandler/pinghandler_v1.cpp

    r315 r336  
    11/*
    22  Smartphone plugin - The smssender plugin for connecting to smartphones.
    3   Copyright (C) 2012, gorrión. See http://smssender.gorrion.ch
     3  Copyright (C) 2012-2014, gorrión. See http://smssender.gorrion.ch
    44
    55  This program is free software: you can redistribute it and/or modify
  • gateways/Smartphone/business/datahandler/pinghandler_v1.h

    r315 r336  
    11/*
    22  Smartphone plugin - The smssender plugin for connecting to smartphones.
    3   Copyright (C) 2012, gorrión. See http://smssender.gorrion.ch
     3  Copyright (C) 2012-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 SMARTPHONE_PINGHANDLER_V1_H
    19 #define SMARTPHONE_PINGHANDLER_V1_H
     18#ifndef SMARTPHONE_DATAHANDLER_PINGHANDLER_V1_H
     19#define SMARTPHONE_DATAHANDLER_PINGHANDLER_V1_H
    2020
    21 #include "business/datatypes.h"
    22 
    23 #include "abstractdatahandler.h"
     21#include "gateways/Smartphone/business/datahandler/abstractdatahandler.h"
     22#include "gateways/Smartphone/business/datatypes.h"
    2423
    2524namespace Smartphone {
     
    4140} // namespace Smartphone
    4241
    43 #endif // SMARTPHONE_PINGHANDLER_V1_H
     42#endif // SMARTPHONE_DATAHANDLER_PINGHANDLER_V1_H
  • gateways/Smartphone/business/datahandler/sendsmsresponsehandler_v1.cpp

    r315 r336  
    11/*
    22  Smartphone plugin - The smssender plugin for connecting to smartphones.
    3   Copyright (C) 2012, gorrión. See http://smssender.gorrion.ch
     3  Copyright (C) 2012-2014, gorrión. See http://smssender.gorrion.ch
    44
    55  This program is free software: you can redistribute it and/or modify
  • gateways/Smartphone/business/datahandler/sendsmsresponsehandler_v1.h

    r315 r336  
    11/*
    22  Smartphone plugin - The smssender plugin for connecting to smartphones.
    3   Copyright (C) 2012, gorrión. See http://smssender.gorrion.ch
     3  Copyright (C) 2012-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 SMARTPHONE_SENDSMSRESPONSEHANDLER_V1_H
    19 #define SMARTPHONE_SENDSMSRESPONSEHANDLER_V1_H
     18#ifndef SMARTPHONE_DATAHANDLER_SENDSMSRESPONSEHANDLER_V1_H
     19#define SMARTPHONE_DATAHANDLER_SENDSMSRESPONSEHANDLER_V1_H
    2020
    21 #include "abstractdatahandler.h"
     21#include "gateways/Smartphone/business/datahandler/abstractdatahandler.h"
    2222
    2323namespace Smartphone {
     
    6262} // namespace Smartphone
    6363
    64 #endif // SMARTPHONE_SENDSMSRESPONSEHANDLER_V1_H
     64#endif // SMARTPHONE_DATAHANDLER_SENDSMSRESPONSEHANDLER_V1_H
  • gateways/Smartphone/business/datatypes.cpp

    r315 r336  
    11/*
    22  Smartphone plugin - The smssender plugin for connecting to smartphones.
    3   Copyright (C) 2012, gorrión. See http://smssender.gorrion.ch
     3  Copyright (C) 2012-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 "business/datatypes.h"
    19 #include "business/datatypes_p.h"
     18#include "datatypes.h"
     19#include "datatypes_p.h"
    2020
    2121#include <cryptopp/aes.h>
  • gateways/Smartphone/business/datatypes.h

    r315 r336  
    11/*
    22  Smartphone plugin - The smssender plugin for connecting to smartphones.
    3   Copyright (C) 2012, gorrión. See http://smssender.gorrion.ch
     3  Copyright (C) 2012-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 SMARTPHONE_SMARTPHONE_H
    19 #define SMARTPHONE_SMARTPHONE_H
     18#ifndef SMARTPHONE_DATATYPES_H
     19#define SMARTPHONE_DATATYPES_H
     20
     21#include <cryptopp/secblock.h>
    2022
    2123#include <QHostAddress>
    2224#include <QString>
    2325
    24 #include <cryptopp/secblock.h>
    25 
    26 #include <utils/smacros.h>
    27 #include <utils/sshared.h>
     26#include "common/utils/smacros.h"
     27#include "common/utils/sshared.h"
    2828
    2929namespace Smartphone {
     
    100100}
    101101
    102 #endif // SMARTPHONE_SMARTPHONE_H
     102#endif // SMARTPHONE_DATATYPES_H
  • gateways/Smartphone/business/datatypes_p.h

    r315 r336  
    11/*
    22  Smartphone plugin - The smssender plugin for connecting to smartphones.
    3   Copyright (C) 2012, gorrión. See http://smssender.gorrion.ch
     3  Copyright (C) 2012-2014, gorrión. See http://smssender.gorrion.ch
    44
    55  This program is free software: you can redistribute it and/or modify
     
    1919#define SMARTPHONE_DATATYPES_P_H
    2020
     21#include <cryptopp/secblock.h>
     22
    2123#include <QHostAddress>
    2224#include <QString>
    2325
    24 #include <cryptopp/secblock.h>
    25 
    26 #include <utils/sshared.h>
     26#include "common/utils/sshared.h"
    2727
    2828namespace Smartphone {
  • gateways/Smartphone/business/gateway.cpp

    r315 r336  
    11/*
    22  Smartphone plugin - The smssender plugin for connecting to smartphones.
    3   Copyright (C) 2012, gorrión. See http://smssender.gorrion.ch
     3  Copyright (C) 2012-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 "business/gateway.h"
     18#include "gateway.h"
    1919
    20 #include "business/account.h"
    21 #include "business/smartphonemanager.h"
    22 #include "persistence/gatewaystoragehelper.h"
    23 #include "ui/settingswidget.h"
    24 #include "library.h"
     20#include "gateways/Smartphone/business/account.h"
     21#include "gateways/Smartphone/business/smartphonemanager.h"
     22#include "gateways/Smartphone/persistence/gatewaystoragehelper.h"
    2523
    2624namespace Smartphone {
     
    3533QString Gateway::name() const {
    3634    return "Smartphone";
    37 }
    38 
    39 QImage Gateway::icon() const {
    40     return QImage(":/images/smartphone.ico");
    4135}
    4236
     
    6155}
    6256
    63 IAccountSettingsWidget* Gateway::createAccountSettingsWidget(QWidget* parent) const {
    64     return new UI::SettingsWidget(parent, m_smartphoneManager);
    65 }
    66 
    6757::Persistence::IStorageHelper *Gateway::createStorageHelper(::Persistence::IMainStorage *storage) {
    6858    return new Persistence::GatewayStorageHelper(this, storage, m_smartphoneManager);
  • gateways/Smartphone/business/gateway.h

    r315 r336  
    11/*
    22  Smartphone plugin - The smssender plugin for connecting to smartphones.
    3   Copyright (C) 2012, gorrión. See http://smssender.gorrion.ch
     3  Copyright (C) 2012-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 SMARTPHONE_BCGATEWAY_H_
    19 #define SMARTPHONE_BCGATEWAY_H_
     18#ifndef SMARTPHONE_GATEWAY_H
     19#define SMARTPHONE_GATEWAY_H
    2020
    2121#include <QScopedPointer>
    2222#include <QSet>
    2323
    24 #include <utils/smacros.h>
    25 #include <business/igateway.h>
    26 
    27 namespace Persistence {
    28 class IStorageHelper;
    29 } // namespace Persistence
     24#include "common/business/igateway.h"
     25#include "common/utils/smacros.h"
    3026
    3127namespace Smartphone {
     
    4541
    4642public: /* IGateway */
    47     QString        name() const;
    48     QImage         icon() const;
     43    QString name() const;
     44
     45#ifdef FRONTEND_GUI
     46    QIcon icon() const;
     47    IAccountSettingsWidget *createAccountSettingsWidget(QWidget* parent) const;
     48#endif
    4949
    5050public: /* IGateway */
    51     IAccountSettingsWidget* createAccountSettingsWidget(QWidget* parent) const;
    52     IAccount*               createAccountInstance();
     51    IAccount *createAccountInstance();
    5352
    5453public: /* IGateway */
    55     QList<int>     validRecipientCountryCodes() const;
    56     QList<QChar>   doublePriceChars() const;
    57     QList<QChar>   disAllowedChars() const;
     54    QList<int> validRecipientCountryCodes() const;
     55    QList<QChar> doublePriceChars() const;
     56    QList<QChar> disAllowedChars() const;
    5857
    5958public: /* IStorable */
     
    6867}
    6968
    70 #endif /* SMARTPHONE_BCGATEWAY_H_ */
     69#endif /* SMARTPHONE_GATEWAY_H */
  • gateways/Smartphone/business/packages/packagewizard.cpp

    r279 r336  
    11/*
    22  Smartphone plugin - The smssender plugin for connecting to smartphones.
    3   Copyright (C) 2012, gorrión. See http://smssender.gorrion.ch
     3  Copyright (C) 2012-2014, gorrión. See http://smssender.gorrion.ch
    44
    55  This program is free software: you can redistribute it and/or modify
  • gateways/Smartphone/business/packages/packagewizard.h

    r315 r336  
    11/*
    22  Smartphone plugin - The smssender plugin for connecting to smartphones.
    3   Copyright (C) 2012, gorrión. See http://smssender.gorrion.ch
     3  Copyright (C) 2012-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 SMARTPHONE_PACKAGEWIZARD_H
    19 #define SMARTPHONE_PACKAGEWIZARD_H
     18#ifndef SMARTPHONE_PACKAGES_PACKAGEWIZARD_H
     19#define SMARTPHONE_PACKAGES_PACKAGEWIZARD_H
    2020
    2121#include <QObject>
    2222
    23 #include <domain/snumber.h>
    24 
    25 #include "business/datatypes.h"
     23#include "common/domain/snumber.h"
     24#include "gateways/Smartphone/business/datatypes.h"
    2625
    2726namespace Smartphone {
     
    4140} // namespace Smartphone
    4241
    43 #endif // SMARTPHONE_PACKAGEWIZARD_H
     42#endif // SMARTPHONE_PACKAGES_PACKAGEWIZARD_H
  • gateways/Smartphone/business/smartphoneconnector.cpp

    r315 r336  
    11/*
    22  Smartphone plugin - The smssender plugin for connecting to smartphones.
    3   Copyright (C) 2012, gorrión. See http://smssender.gorrion.ch
     3  Copyright (C) 2012-2014, gorrión. See http://smssender.gorrion.ch
    44
    55  This program is free software: you can redistribute it and/or modify
     
    2020#include <QNetworkInterface>
    2121
    22 #include <exceptions/eexception.h>
    23 
    24 #include "business/packages/packagewizard.h"
    25 #include "business/connectionhandler.h"
    26 #include "business/smartphonemanager.h"
    27 #include "library.h"
     22#include "common/exceptions/eexception.h"
     23#include "gateways/Smartphone/business/connectionhandler.h"
     24#include "gateways/Smartphone/business/packages/packagewizard.h"
     25#include "gateways/Smartphone/business/smartphonemanager.h"
    2826
    2927namespace Smartphone {
     
    5149}
    5250SmartphoneConnector::~SmartphoneConnector() {
     51    qDeleteAll(m_connections.values());
    5352    m_deviceConnections.clear();
    5453}
     
    8281    if (m_connections.contains(peerAddress)) {
    8382        cSocket->close(); // Do not open multiple sockets to the same device
     83        delete cSocket;
    8484        return;
    8585    }
  • gateways/Smartphone/business/smartphoneconnector.h

    r315 r336  
    11/*
    22  Smartphone plugin - The smssender plugin for connecting to smartphones.
    3   Copyright (C) 2012, gorrión. See http://smssender.gorrion.ch
     3  Copyright (C) 2012-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 SMARTPHONE_BCSMARTPHONECONNECTOR_H
    19 #define SMARTPHONE_BCSMARTPHONECONNECTOR_H
     18#ifndef SMARTPHONE_SMARTPHONECONNECTOR_H
     19#define SMARTPHONE_SMARTPHONECONNECTOR_H
    2020
    2121#include <QHash>
     
    2525#include <QTimer>
    2626
    27 #include "datatypes.h"
     27#include "gateways/Smartphone/business/datatypes.h"
    2828
    2929namespace Smartphone {
     
    6161private slots:
    6262    void acceptConnection();
     63    // Takes ownership of cSocket.
    6364    void handleSocket(QTcpSocket *cSocket);
     65    // Takes ownership of cSocket.
    6466    void handleSocket(QTcpSocket *cSocket, const Smartphone &peerDevice);
    6567
     
    8486}
    8587
    86 #endif // SMARTPHONE_BCSMARTPHONECONNECTOR_H
     88#endif // SMARTPHONE_SMARTPHONECONNECTOR_H
  • gateways/Smartphone/business/smartphoneconnector_p.h

    r315 r336  
    11/*
    22  Smartphone plugin - The smssender plugin for connecting to smartphones.
    3   Copyright (C) 2012, gorrión. See http://smssender.gorrion.ch
     3  Copyright (C) 2012-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 SMARTPHONE_BCSMARTPHONECONNECTOR_P_H
    19 #define SMARTPHONE_BCSMARTPHONECONNECTOR_P_H
     18#ifndef SMARTPHONE_SMARTPHONECONNECTOR_P_H
     19#define SMARTPHONE_SMARTPHONECONNECTOR_P_H
    2020
    2121#include <QObject>
     
    2323#include <QTcpSocket>
    2424
    25 #include "business/datatypes.h"
     25#include "gateways/Smartphone/business/datatypes.h"
    2626
    2727namespace Smartphone {
     
    4242
    4343signals:
     44    // Releases ownership of cSocket and therefore the (single) slot must take it.
    4445    void connected(QTcpSocket *cSocket, const Smartphone &device);
     46
    4547    void finished(DevicePoller *poller);
    4648
     
    5961}
    6062
    61 #endif // SMARTPHONE_BCSMARTPHONECONNECTOR_P_H
     63#endif // SMARTPHONE_SMARTPHONECONNECTOR_P_H
    6264
  • gateways/Smartphone/business/smartphoneconnector_poll.cpp

    r315 r336  
    11/*
    22  Smartphone plugin - The smssender plugin for connecting to smartphones.
    3   Copyright (C) 2012, gorrión. See http://smssender.gorrion.ch
     3  Copyright (C) 2012-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 "business/smartphoneconnector.h"
    19 #include "business/smartphoneconnector_p.h"
     18#include "smartphoneconnector.h"
     19#include "smartphoneconnector_p.h"
    2020
    21 #include "business/smartphonemanager.h"
     21#include "gateways/Smartphone/business/smartphonemanager.h"
    2222
    2323namespace Smartphone {
     
    6969    , m_connection(connection)
    7070{
    71     m_cSocket.reset(new QTcpSocket); // FIXME: check ownership, since this socket gets populated via signal
     71    m_cSocket.reset(new QTcpSocket);
    7272    connect(m_cSocket.data(), SIGNAL(connected()), this, SLOT(onConnected()));
    7373    connect(m_cSocket.data(), SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(onError(QAbstractSocket::SocketError)));
     
    7979
    8080void DevicePoller::onConnected() {
    81     emit connected(m_cSocket.data(), m_device);
     81    QTcpSocket *socket = m_cSocket.take();
     82    m_cSocket.reset(new QTcpSocket);
     83
     84    // TODO Releases ownership via message. This might be done better.
     85
     86    emit connected(socket, m_device);
    8287    emit finished(this);
    8388}
  • gateways/Smartphone/business/smartphonemanager.cpp

    r315 r336  
    11/*
    22  Smartphone plugin - The smssender plugin for connecting to smartphones.
    3   Copyright (C) 2012, gorrión. See http://smssender.gorrion.ch
     3  Copyright (C) 2012-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 "business/smartphonemanager.h"
     18#include "smartphonemanager.h"
    1919
    20 #include <utils/sutils.h>
    21 #include <persistence/istoragehelper.h>
    22 
    23 #include "business/connectionhandler.h"
    24 #include "business/gateway.h"
    25 #include "business/smartphoneconnector.h"
     20#include "common/utils/sutils.h"
     21#include "common/persistence/istoragehelper.h"
     22#include "gateways/Smartphone/business/connectionhandler.h"
     23#include "gateways/Smartphone/business/gateway.h"
     24#include "gateways/Smartphone/business/smartphoneconnector.h"
    2625
    2726namespace Smartphone {
     
    6968    return m_pcIdent;
    7069}
     70void SmartphoneManager::setPcIdent(const QString &pcIdent) {
     71    SET_IF_DIFFERENT(m_pcIdent, pcIdent);
     72}
     73
    7174QString SmartphoneManager::pcName() const {
    7275    return m_pcName;
  • gateways/Smartphone/business/smartphonemanager.h

    r315 r336  
    11/*
    22  Smartphone plugin - The smssender plugin for connecting to smartphones.
    3   Copyright (C) 2012, gorrión. See http://smssender.gorrion.ch
     3  Copyright (C) 2012-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 SMARTPHONE_BCSMARTPHONEMANAGER_H
    19 #define SMARTPHONE_BCSMARTPHONEMANAGER_H
     18#ifndef SMARTPHONE_SMARTPHONEMANAGER_H
     19#define SMARTPHONE_SMARTPHONEMANAGER_H
    2020
    2121#include <QHash>
     
    2626#include <QString>
    2727
    28 #include <utils/smacros.h>
    29 
    30 #include "business/datatypes.h"
     28#include "common/utils/smacros.h"
     29#include "gateways/Smartphone/business/datatypes.h"
    3130
    3231namespace Smartphone {
     
    7675
    7776private:
     77    void setPcIdent(const QString &pcIdent);
     78
    7879    void init();
    7980
     
    9697} // namespace Smartphone
    9798
    98 #endif // SMARTPHONE_BCSMARTPHONEMANAGER_H
     99#endif // SMARTPHONE_SMARTPHONEMANAGER_H
  • gateways/Smartphone/gui/smartphone.cpp

    r315 r336  
    11/*
    22  Smartphone plugin - The smssender plugin for connecting to smartphones.
    3   Copyright (C) 2012, gorrión. See http://smssender.gorrion.ch
     3  Copyright (C) 2012-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 "smartphone.h"
    1919
    2020#include <QCoreApplication>
    2121#include <QDir>
    2222
    23 #include <domain/sversion.h>
    24 
    25 #include "business/contactimporter/contactimporter.h"
    26 #include "business/gateway.h"
    27 #include "business/smartphonemanager.h"
     23#include "common/domain/sversion.h"
     24#include "gateways/Smartphone/business/contactimporter/contactimporter.h"
     25#include "gateways/Smartphone/business/gateway.h"
     26#include "gateways/Smartphone/business/smartphonemanager.h"
    2827
    2928namespace Smartphone {
    3029
    31 bool Library::doInit(QSet<QTranslator*> *translators, IGateway **gateway,
    32                      QSet<IContactImporter*> *contactImporters)
     30bool Library::doInit(
     31        const IBaseIntegrationHelper::Factory &integrationHelperFactory,
     32        QSet<QTranslator*> *translators, IGateway **gateway,
     33        QSet<IContactImporter::Builder *> *contactImporters)
    3334{
    3435    // Translators
     
    4445    // Gateway
    4546    *gateway = new Gateway(m_smartphoneManager.data());
     47    m_integrationHelper.reset(integrationHelperFactory.createIntegrationHelper(*gateway));
    4648
    4749    // Contact importer
    48     contactImporters->insert(new ContactImporter(integrationHelper()->accountHelper(),
    49                                                  *m_smartphoneManager->connector()));
     50    contactImporters->insert(new ContactImporter::Builder(
     51                                 m_integrationHelper->accountHelper(),
     52                                 m_smartphoneManager->connector()));
    5053
    5154    return true;
  • gateways/Smartphone/gui/smartphone.h

    r315 r336  
    11/*
    22  Smartphone plugin - The smssender plugin for connecting to smartphones.
    3   Copyright (C) 2012, gorrión. See http://smssender.gorrion.ch
     3  Copyright (C) 2012-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 SMARTPHONE_MAIN_H_
    19 #define SMARTPHONE_MAIN_H_
     18#ifndef SMARTPHONE_GUI_SMARTPHONE_H
     19#define SMARTPHONE_GUI_SMARTPHONE_H
    2020
    2121#include <QScopedPointer>
    2222
    23 #include <business/icontactimporter.h>
    24 #include <business/igateway.h>
    25 #include <business/impl/abstractlibrary.h>
    26 #include <utils/smacros.h>
     23#include "common/business/icontactimporter.h"
     24#include "common/business/igateway.h"
     25#include "common/utils/smacros.h"
     26#include "gateways/common/business/baselibrary.h"
    2727
    2828namespace Smartphone {
    2929class SmartphoneManager;
    3030
    31 class Library : public AbstractLibrary {
     31class Library : public BaseLibrary {
    3232    S_LIBRARY("Smartphone")
    3333
    34 protected: /* AbstractLibrary */
    35     bool doInit(QSet<QTranslator*> *translators, IGateway **gateway,
    36                 QSet<IContactImporter*> *contactImporters);
     34protected: /* BaseLibrary */
     35    bool doInit(const IIntegrationHelper::Factory &integrationHelperFactory,
     36                QSet<QTranslator*> *translators, IGateway **gateway,
     37                QSet<IContactImporter::Builder *> *contactImporters);
    3738
    3839private:
     40    QScopedPointer<IIntegrationHelper> m_integrationHelper;
    3941    QScopedPointer<SmartphoneManager> m_smartphoneManager;
    4042};
     
    4244} // namespace Smartphone
    4345
    44 #endif /* SMARTPHONE_MAIN_H_ */
     46#endif /* SMARTPHONE_GUI_SMARTPHONE_H */
  • gateways/Smartphone/gui/ui/components/qrcode.cpp

    r276 r336  
    11/*
    22  Smartphone plugin - The smssender plugin for connecting to smartphones.
    3   Copyright (C) 2012, gorrión. See http://smssender.gorrion.ch
     3  Copyright (C) 2012-2014, gorrión. See http://smssender.gorrion.ch
    44
    55  This program is free software: you can redistribute it and/or modify
     
    1818#include "qrcode.h"
    1919
    20 #include "math.h"
     20#include <math.h>
     21#include <qrencode.h>
     22
    2123#include <QPaintEngine>
    22 
    23 #include <qrencode.h>
    2424
    2525namespace Smartphone {
     
    3535
    3636QBitArray QRCode::code() const {
    37     return qrData_;
     37    return m_qrData;
    3838}
    3939void QRCode::setCode(const QBitArray &code) {
    40     qrData_ = code;
    41     qrWidth_ = sqrt(code.size());
     40    m_qrData = code;
     41    m_qrWidth = sqrt(code.size());
    4242
    4343    setMinimumSize(codeSize(), codeSize());
     
    4747
    4848void QRCode::paintEvent(QPaintEvent *) {
    49     if (qrData_.isNull()) {
     49    if (m_qrData.isNull()) {
    5050        return;
    5151    }
     
    5454    painter.fillRect(0, 0, codeSize(), codeSize(), Qt::white);
    5555
    56     for (int i = 0; i < qrWidth_; ++i) {
    57         for (int j = 0; j < qrWidth_; ++j) {
     56    for (int i = 0; i < m_qrWidth; ++i) {
     57        for (int j = 0; j < m_qrWidth; ++j) {
    5858            int x = j*PIXEL_SIZE + QUIET_ZONE_WIDTH;
    5959            int y = i*PIXEL_SIZE + QUIET_ZONE_WIDTH;
    6060
    61             if (qrData_.at(i*qrWidth_ + j)) {
     61            if (m_qrData.at(i*m_qrWidth + j)) {
    6262                painter.fillRect(x, y, PIXEL_SIZE, PIXEL_SIZE, Qt::black);
    6363            }
     
    6767
    6868int QRCode::codeSize() const {
    69     return qrWidth_*PIXEL_SIZE + 2*QUIET_ZONE_WIDTH;
     69    return m_qrWidth*PIXEL_SIZE + 2*QUIET_ZONE_WIDTH;
    7070}
    7171
  • gateways/Smartphone/gui/ui/components/qrcode.h

    r276 r336  
    11/*
    22  Smartphone plugin - The smssender plugin for connecting to smartphones.
    3   Copyright (C) 2012, gorrión. See http://smssender.gorrion.ch
     3  Copyright (C) 2012-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 SMARTPHONE_QRCODE_H
    19 #define SMARTPHONE_QRCODE_H
     18#ifndef SMARTPHONE_GUI_UI_COMPONENTS_QRCODE_H
     19#define SMARTPHONE_GUI_UI_COMPONENTS_QRCODE_H
    2020
    2121#include <QBitArray>
     
    4747    static short QUIET_ZONE_WIDTH;
    4848
    49     int qrWidth_;
    50     QBitArray qrData_;
     49    int m_qrWidth;
     50    QBitArray m_qrData;
    5151};
    5252
    5353}
    5454
    55 #endif // SMARTPHONE_QRCODE_H
     55#endif // SMARTPHONE_GUI_UI_COMPONENTS_QRCODE_H
     56
  • gateways/Smartphone/gui/ui/settingswidget.cpp

    r315 r336  
    11/*
    22  Smartphone plugin - The smssender plugin for connecting to smartphones.
    3   Copyright (C) 2012, gorrión. See http://smssender.gorrion.ch
     3  Copyright (C) 2012-2014, gorrión. See http://smssender.gorrion.ch
    44
    55  This program is free software: you can redistribute it and/or modify
     
    1818#include "ui/settingswidget.h"
    1919
     20#include <qrencode.h>
     21
    2022#include <QBitArray>
    2123#include <QInputDialog>
     
    2426#include <QMessageBox>
    2527
    26 #include <qrencode.h>
    27 
    28 #include <exceptions/stdexceptions.h>
    29 
    30 #include "business/account.h"
    31 #include "business/gateway.h"
    32 #include "business/smartphoneconnector.h"
    33 #include "business/smartphonemanager.h"
     28#include "common/exceptions/stdexceptions.h"
     29#include "gateways/Smartphone/business/account.h"
     30#include "gateways/Smartphone/business/gateway.h"
     31#include "gateways/Smartphone/business/smartphoneconnector.h"
     32#include "gateways/Smartphone/business/smartphonemanager.h"
    3433
    3534namespace Smartphone {
     
    5655
    5756void SettingsWidget::generateQRCode() {
    58     if (initialDevice_.secret().isNull()) {
    59         initialDevice_.setSecret(m_smartphoneManager->generateUnidentifiedSecret());
     57    if (m_initialDevice.secret().isNull()) {
     58        m_initialDevice.setSecret(m_smartphoneManager->generateUnidentifiedSecret());
    6059    }
    6160
    62     QString data = m_smartphoneManager->connector()->createConnectionRequestPackage(initialDevice_);
     61    QString data = m_smartphoneManager->connector()->createConnectionRequestPackage(m_initialDevice);
    6362
    6463    // create the QR code
     
    7574
    7675void SettingsWidget::onDeviceRegistered(const Smartphone &device) {
    77     if (!initialDevice_.isNull()) {
     76    if (!m_initialDevice.isNull()) {
    7877        return; // Do not listen to different devices if one was already linked to this account
    7978    }
    8079
    81     SET_IF_DIFFERENT(device_, device);
     80    SET_IF_DIFFERENT(m_device, device);
    8281}
    8382void SettingsWidget::onDeviceConnected(const Smartphone &device) {
    84     if (!initialDevice_.isNull()) {
    85         if (device != device_) {
     83    if (!m_initialDevice.isNull()) {
     84        if (device != m_device) {
    8685            return;
    8786        }
    8887    }
    89     device_ = device;
     88    m_device = device;
    9089
    91     ui.lblConnectionStatus->setText(tr("Connected to %1").arg(device_.name()));
     90    ui.lblConnectionStatus->setText(tr("Connected to %1").arg(m_device.name()));
    9291    ui.lblConnectionStatus->setStyleSheet("background: url(\":/images/connected.png\") left middle no-repeat; padding-left: 16px;");
    9392}
    9493void SettingsWidget::onDeviceDisconnected(const Smartphone &device) {
    95     if (device != device_) {
     94    if (device != m_device) {
    9695        return;
    9796    }
    9897
    99     if (initialDevice_.isNull() || initialDevice_.name().isEmpty()) {
     98    if (m_initialDevice.isNull() || m_initialDevice.name().isEmpty()) {
    10099        ui.lblConnectionStatus->setText(tr("No connection to your phone"));
    101100    } else {
    102         ui.lblConnectionStatus->setText(tr("No connection to %1").arg(initialDevice_.name()));
     101        ui.lblConnectionStatus->setText(tr("No connection to %1").arg(m_initialDevice.name()));
    103102    }
    104103    ui.lblConnectionStatus->setStyleSheet("background: url(\":/images/disconnected.png\") left middle no-repeat; padding-left: 16px;");
     
    111110    const Account &acc = static_cast<const Account&>(*account);
    112111
    113     device_ = acc.device();
    114     initialDevice_ = device_;
    115     if (m_smartphoneManager->connector()->isDeviceConnected(device_)) {
    116         onDeviceConnected(device_);
     112    m_device = acc.device();
     113    m_initialDevice = m_device;
     114    if (m_smartphoneManager->connector()->isDeviceConnected(m_device)) {
     115        onDeviceConnected(m_device);
    117116    } else {
    118         onDeviceDisconnected(device_);
     117        onDeviceDisconnected(m_device);
    119118    }
    120119
     
    127126    Account* acc = static_cast<Account*>(account);
    128127
    129     acc->setDevice(device_);
     128    acc->setDevice(m_device);
    130129}
    131130
  • gateways/Smartphone/gui/ui/settingswidget.h

    r315 r336  
    11/*
    22  Smartphone plugin - The smssender plugin for connecting to smartphones.
    3   Copyright (C) 2012, gorrión. See http://smssender.gorrion.ch
     3  Copyright (C) 2012-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 SMARTPHONE_VCSETTINGSWIDGET_H
    19 #define SMARTPHONE_VCSETTINGSWIDGET_H
     18#ifndef SMARTPHONE_GUI_UI_SETTINGSWIDGET_H
     19#define SMARTPHONE_GUI_UI_SETTINGSWIDGET_H
    2020
    2121#include <QtGui/QWidget>
    22 #include "ui_vcsettingswidget.h"
     22#include "ui_settingswidget.h"
    2323
    24 #include "business/datatypes.h"
    25 #include <ui/iaccountsettingswidget.h>
     24#include "common/gui/ui/iaccountsettingswidget.h"
     25#include "gateways/Smartphone/business/datatypes.h"
    2626
    2727namespace Smartphone {
     28
    2829class Account;
    2930class SmartphoneManager;
     
    5354    SmartphoneManager * const m_smartphoneManager;
    5455
    55     Ui::VCSettingsWidgetClass ui;
    56     Smartphone device_;
    57     Smartphone initialDevice_;
     56    Ui::SettingsWidgetClass ui;
     57    Smartphone m_device;
     58    Smartphone m_initialDevice;
    5859};
    5960
     
    6162} // namespace Smartphone
    6263
    63 #endif // SMARTPHONE_VCSETTINGSWIDGET_H
     64#endif // SMARTPHONE_GUI_UI_SETTINGSWIDGET_H
  • gateways/Smartphone/gui/ui/settingswidget.ui

    r276 r336  
    11<?xml version="1.0" encoding="UTF-8"?>
    22<ui version="4.0">
    3  <class>VCSettingsWidgetClass</class>
    4  <widget class="QWidget" name="VCSettingsWidgetClass">
     3 <class>SettingsWidgetClass</class>
     4 <widget class="QWidget" name="SettingsWidgetClass">
    55  <property name="geometry">
    66   <rect>
     
    2424    <widget class="QLabel" name="label">
    2525     <property name="text">
    26       <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Please install the SMSSender App on your smartphone. Use &lt;span style=&quot; font-weight:600;&quot;&gt;initiate connection&lt;/span&gt; in the App and scan the following code to establish a link between SMSSender and your smartphone.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
     26      <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p align=&quot;justify&quot;&gt;Please install the SMSSender app on your smartphone. Use &lt;span style=&quot; font-weight:600;&quot;&gt;initiate connection&lt;/span&gt; in the app and scan the following code to establish a link between SMSSender and your device.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
    2727     </property>
    2828     <property name="wordWrap">
     
    3232   </item>
    3333   <item>
    34     <widget class="Smartphone::QRCode" name="qrCode" native="true"/>
     34    <layout class="QHBoxLayout" name="horizontalLayout">
     35     <item>
     36      <spacer name="horizontalSpacer_2">
     37       <property name="orientation">
     38        <enum>Qt::Horizontal</enum>
     39       </property>
     40       <property name="sizeHint" stdset="0">
     41        <size>
     42         <width>40</width>
     43         <height>20</height>
     44        </size>
     45       </property>
     46      </spacer>
     47     </item>
     48     <item>
     49      <widget class="Smartphone::QRCode" name="qrCode" native="true"/>
     50     </item>
     51     <item>
     52      <spacer name="horizontalSpacer">
     53       <property name="orientation">
     54        <enum>Qt::Horizontal</enum>
     55       </property>
     56       <property name="sizeHint" stdset="0">
     57        <size>
     58         <width>40</width>
     59         <height>20</height>
     60        </size>
     61       </property>
     62      </spacer>
     63     </item>
     64    </layout>
    3565   </item>
    3666   <item>
  • gateways/Smartphone/lib/smartphone.qrc

    r276 r336  
    11<RCC>
    22    <qresource prefix="/certs"/>
    3     <qresource prefix="/images">
    4         <file>smartphone.ico</file>
    5         <file>connected.png</file>
    6         <file>disconnected.png</file>
    7     </qresource>
    83    <qresource prefix="/locale">
    94        <file alias="smartphone-de.qm">../locale/de.qm</file>
  • gateways/Smartphone/locale/locale.pri

    r276 r336  
    2020updateqm.CONFIG += no_link target_predeps
    2121QMAKE_EXTRA_COMPILERS += updateqm
    22 system($$QMAKE_LRELEASE -silent $$PWD/../*.pro)
     22system($$QMAKE_LRELEASE -silent $$PWD/../smartphone-base.pro)
  • gateways/Smartphone/persistence/accountstoragehelper.cpp

    r315 r336  
    11/*
    22  Smartphone plugin - The smssender plugin for connecting to smartphones.
    3   Copyright (C) 2012, gorrión. See http://smssender.gorrion.ch
     3  Copyright (C) 2012-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 "persistence/accountstoragehelper.h"
     18#include "accountstoragehelper.h"
    1919
    20 #include "business/account.h"
    21 #include "business/gateway.h"
    22 #include "business/smartphonemanager.h"
     20#include "gateways/Smartphone/business/account.h"
     21#include "gateways/Smartphone/business/gateway.h"
     22#include "gateways/Smartphone/business/smartphonemanager.h"
    2323
    2424namespace Smartphone {
     
    3333
    3434
    35 void AccountStorageHelper::load() {
     35void AccountStorageHelper::load() const {
    3636    ::Persistence::DefaultAccountStorageHelper::load();
    3737
  • gateways/Smartphone/persistence/accountstoragehelper.h

    r315 r336  
    11/*
    22  Smartphone plugin - The smssender plugin for connecting to smartphones.
    3   Copyright (C) 2012, gorrión. See http://smssender.gorrion.ch
     3  Copyright (C) 2012-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 SMARTPHONE_DAACCOUNTSTORAGEOFFICER_H_
    19 #define SMARTPHONE_DAACCOUNTSTORAGEOFFICER_H_
     18#ifndef SMARTPHONE_PERSISTENCE_ACCOUNTSTORAGEHELPER_H
     19#define SMARTPHONE_PERSISTENCE_ACCOUNTSTORAGEHELPER_H
    2020
    21 #include <persistence/impl/defaultaccountstoragehelper.h>
     21#include "gateways/common/persistence/defaultaccountstoragehelper.h"
    2222
    2323namespace Smartphone {
     24
    2425class Account;
    2526class SmartphoneManager;
     
    3233
    3334public: /* DefaultAccountStorageHelper */
    34     void load();
     35    void load() const;
    3536    void save() const;
    3637
     
    4243} // namespace Smartphone
    4344
    44 #endif /* SMARTPHONE_DAACCOUNTSTORAGEOFFICER_H_ */
     45#endif /* SMARTPHONE_DAACCOUNTSTORAGEHELPER_H */
  • gateways/Smartphone/persistence/gatewaystoragehelper.cpp

    r315 r336  
    11/*
    22  Smartphone plugin - The smssender plugin for connecting to smartphones.
    3   Copyright (C) 2012, gorrión. See http://smssender.gorrion.ch
     3  Copyright (C) 2012-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 "persistence/gatewaystoragehelper.h"
     18#include "gatewaystoragehelper.h"
    1919
    20 #include "business/gateway.h"
    21 #include "business/smartphoneconnector.h"
    22 #include "business/smartphonemanager.h"
     20#include <QtGlobal>
     21#include <QTime>
     22
     23#include "gateways/Smartphone/business/gateway.h"
     24#include "gateways/Smartphone/business/smartphoneconnector.h"
     25#include "gateways/Smartphone/business/smartphonemanager.h"
    2326
    2427namespace Smartphone {
     
    3134    , m_smartphoneManager(smartphoneManager)
    3235{
     36    qsrand(QTime::currentTime().msec());
    3337}
    3438
    3539void GatewayStorageHelper::load() const {
    36     ::Persistence::EncryptedStorageHelper::load();
    37 
    3840    QString randomStr = getRandomString(32);
    3941    // FIXME: We need an account-independent namespace here!
    40     m_smartphoneManager->m_pcIdent = storage()->readString("", "pcIdent", randomStr);
    41     m_smartphoneManager->m_pcName = storage()->readString("", "pcName", QString());
     42    m_smartphoneManager->setPcIdent(storage()->readString("", "pcIdent", randomStr));
     43    m_smartphoneManager->setPcName(storage()->readString("", "pcName", QString()));
    4244
    4345    if (m_smartphoneManager->pcIdent() == randomStr) {
     
    6769
    6870void GatewayStorageHelper::save() const {
    69     ::Persistence::EncryptedStorageHelper::save();
    70 
    7171    storage()->writeString("", "pcIdent", m_smartphoneManager->pcIdent());
    7272    storage()->writeString("", "pcName", m_smartphoneManager->pcName());
     
    101101
    102102QString GatewayStorageHelper::getDeviceNamespace(int i) const {
    103     return "device" + QString::number(i);
     103    return QString("device%1").arg(i);
    104104}
    105105
  • gateways/Smartphone/persistence/gatewaystoragehelper.h

    r315 r336  
    11/*
    22  Smartphone plugin - The smssender plugin for connecting to smartphones.
    3   Copyright (C) 2012, gorrión. See http://smssender.gorrion.ch
     3  Copyright (C) 2012-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 SMARTPHONE_DAGATEWAYSTORAGEOFFICER_H
    19 #define SMARTPHONE_DAGATEWAYSTORAGEOFFICER_H
     18#ifndef SMARTPHONE_PERSISTENCE_GATEWAYSTORAGEHELPER_H
     19#define SMARTPHONE_PERSISTENCE_GATEWAYSTORAGEHELPER_H
    2020
    21 #include <persistence/impl/encryptedstoragehelper.h>
     21#include "common/persistence/impl/encryptedstoragehelper.h"
    2222
    2323namespace Smartphone {
     24
    2425class Gateway;
    2526class SmartphoneManager;
     
    4849} // namespace Smartphone
    4950
    50 #endif // SMARTPHONE_DAGATEWAYSTORAGEOFFICER_H
     51#endif // SMARTPHONE_PERSISTENCE_GATEWAYSTORAGEHELPER_H
  • gateways/Smartphone/smartphone-base.pro

    r315 r336  
     1include(../../smssender.pri)
     2
    13BASE_VERSION = 1.0
    2 !include(../gateways.pri):!include(/usr/include/smssender/gateways.pri):error("Could not include gateways.pri")
    3 TARGET = Smartphone
     4
     5TARGET = smartphone-base
     6
     7TEMPLATE = lib
     8CONFIG += \
     9    staticlib
     10
     11QT = \
     12    core\
     13    network \
     14    sql \
     15    xml
     16
     17LIBS += \
     18    -L../../ -lcommon$$LIB_SUFFIX \
     19    -L../../ -lgateways-common$$LIB_SUFFIX \
     20
     21# Needed so that this target gets rebuilt if they change,
     22PRE_TARGETDEPS += \
     23    ../../libgateways-common$${LIB_SUFFIX}.$$EXT_DYNAMICLIB \
     24    ../../libcommon$${LIB_SUFFIX}.$$EXT_DYNAMICLIB
     25
    426include(locale/locale.pri)
     27HEADERS += \
     28    business/account.h \
     29    business/account_tasks.h \
     30    business/accountvalidator.h \
     31    business/connectionhandler.h \
     32    business/contactimporter/contactimporter.h \
     33    business/datahandler/abstractdatahandler.h \
     34    business/datahandler/contactsresponsehandler_v1.h \
     35    business/datahandler/hellohandler_v1.h \
     36    business/datahandler/idatahandler.h \
     37    business/datahandler/pinghandler_v1.h \
     38    business/datahandler/sendsmsresponsehandler_v1.h \
     39    business/datatypes.h \
     40    business/datatypes_p.h \
     41    business/gateway.h \
     42    business/packages/packagewizard.h \
     43    business/smartphoneconnector.h \
     44    business/smartphoneconnector_p.h \
     45    business/smartphonemanager.h \
     46    persistence/accountstoragehelper.h \
     47    persistence/gatewaystoragehelper.h \
    548
    6 QT += xml
    7 LIBS += -Llib/ -lqrencode
     49SOURCES += \
     50    business/account.cpp \
     51    business/account_costs.cpp \
     52    business/account_task_sendsms.cpp \
     53    business/accountvalidator.cpp \
     54    business/connectionhandler.cpp \
     55    business/contactimporter/contactimporter.cpp \
     56    business/datahandler/abstractdatahandler.cpp \
     57    business/datahandler/contactsresponsehandler_v1.cpp \
     58    business/datahandler/hellohandler_v1.cpp \
     59    business/datahandler/pinghandler_v1.cpp \
     60    business/datahandler/sendsmsresponsehandler_v1.cpp \
     61    business/datatypes.cpp \
     62    business/gateway.cpp \
     63    business/packages/packagewizard.cpp \
     64    business/smartphoneconnector.cpp \
     65    business/smartphoneconnector_poll.cpp \
     66    business/smartphonemanager.cpp \
     67    persistence/accountstoragehelper.cpp \
     68    persistence/gatewaystoragehelper.cpp \
    869
    9 INCLUDEPATH += include/ \
    10     include/qrencode/ \
    11     src/ui/components/
    12 
    13 unix {
    14     # Search path for libqrencode.so
    15     CONFIG(debug, debug|release): QMAKE_RPATHDIR += lib
    16     CONFIG(release, debug|release): QMAKE_RPATHDIR += /usr/lib/smssender
    17 }
    18 
    19 HEADERS += \
    20     src/business/datahandler/abstractdatahandler.h \
    21     src/business/datahandler/contactsresponsehandler_v1.h \
    22     src/business/datahandler/hellohandler_v1.h \
    23     src/business/datahandler/idatahandler.h \
    24     src/business/datahandler/pinghandler_v1.h \
    25     src/business/datahandler/sendsmsresponsehandler_v1.h \
    26     src/business/packages/packagewizard.h \
    27     src/business/datatypes.h \
    28     src/business/datatypes_p.h \
    29     src/ui/components/qrcode.h \
    30     src/library.h \
    31     src/business/contactimporter/contactimporter.h \
    32     src/business/contactimporter/contactimporter_p.h \
    33     src/business/account.h \
    34     src/business/account_tasks.h \
    35     src/business/accountvalidator.h \
    36     src/business/connectionhandler.h \
    37     src/business/gateway.h \
    38     src/business/smartphoneconnector.h \
    39     src/business/smartphoneconnector_p.h \
    40     src/business/smartphonemanager.h \
    41     src/persistence/gatewaystoragehelper.h \
    42     src/persistence/accountstoragehelper.h \
    43     src/ui/settingswidget.h
    44 SOURCES += \
    45     src/business/datahandler/abstractdatahandler.cpp \
    46     src/business/datahandler/contactsresponsehandler_v1.cpp \
    47     src/business/datahandler/hellohandler_v1.cpp \
    48     src/business/datahandler/pinghandler_v1.cpp \
    49     src/business/datahandler/sendsmsresponsehandler_v1.cpp \
    50     src/business/packages/packagewizard.cpp \
    51     src/business/datatypes.cpp \
    52     src/ui/components/qrcode.cpp \
    53     src/library.cpp \
    54     src/business/contactimporter/contactimporter.cpp \
    55     src/business/account.cpp \
    56     src/business/account_costs.cpp \
    57     src/business/account_task_sendsms.cpp \
    58     src/business/accountvalidator.cpp \
    59     src/business/connectionhandler.cpp \
    60     src/business/gateway.cpp \
    61     src/business/smartphoneconnector_poll.cpp \
    62     src/business/smartphoneconnector.cpp \
    63     src/business/smartphonemanager.cpp \
    64     src/ui/settingswidget.cpp \
    65     src/persistence/gatewaystoragehelper.cpp \
    66     src/persistence/accountstoragehelper.cpp
    67 FORMS += src/ui/vcsettingswidget.ui
    68 RESOURCES += lib/smartphone.qrc
     70RESOURCES +=\
     71    lib/smartphone.qrc
  • gateways/Smartphone/smartphone.pro

    r315 r336  
    1 BASE_VERSION = 1.0
    2 !include(../gateways.pri):!include(/usr/include/smssender/gateways.pri):error("Could not include gateways.pri")
    3 TARGET = Smartphone
    4 include(locale/locale.pri)
     1TEMPLATE = subdirs
    52
    6 QT += xml
    7 LIBS += -Llib/ -lqrencode
     3SUBDIRS = smartphone-base
     4smartphone-base.file = smartphone-base.pro
    85
    9 INCLUDEPATH += include/ \
    10     include/qrencode/ \
    11     src/ui/components/
     6contains(DEFINES, FRONTEND_GUI) {
     7    SUBDIRS += smartphone-gui
    128
    13 unix {
    14     # Search path for libqrencode.so
    15     CONFIG(debug, debug|release): QMAKE_RPATHDIR += lib
    16     CONFIG(release, debug|release): QMAKE_RPATHDIR += /usr/lib/smssender
     9    smartphone-gui.file = gui/smartphone-gui.pro
     10    smartphone-gui.depends = smartphone-base
    1711}
    1812
    19 HEADERS += \
    20     src/business/datahandler/abstractdatahandler.h \
    21     src/business/datahandler/contactsresponsehandler_v1.h \
    22     src/business/datahandler/hellohandler_v1.h \
    23     src/business/datahandler/idatahandler.h \
    24     src/business/datahandler/pinghandler_v1.h \
    25     src/business/datahandler/sendsmsresponsehandler_v1.h \
    26     src/business/packages/packagewizard.h \
    27     src/business/datatypes.h \
    28     src/business/datatypes_p.h \
    29     src/ui/components/qrcode.h \
    30     src/library.h \
    31     src/business/contactimporter/contactimporter.h \
    32     src/business/contactimporter/contactimporter_p.h \
    33     src/business/account.h \
    34     src/business/account_tasks.h \
    35     src/business/accountvalidator.h \
    36     src/business/connectionhandler.h \
    37     src/business/gateway.h \
    38     src/business/smartphoneconnector.h \
    39     src/business/smartphoneconnector_p.h \
    40     src/business/smartphonemanager.h \
    41     src/persistence/gatewaystoragehelper.h \
    42     src/persistence/accountstoragehelper.h \
    43     src/ui/settingswidget.h
    44 SOURCES += \
    45     src/business/datahandler/abstractdatahandler.cpp \
    46     src/business/datahandler/contactsresponsehandler_v1.cpp \
    47     src/business/datahandler/hellohandler_v1.cpp \
    48     src/business/datahandler/pinghandler_v1.cpp \
    49     src/business/datahandler/sendsmsresponsehandler_v1.cpp \
    50     src/business/packages/packagewizard.cpp \
    51     src/business/datatypes.cpp \
    52     src/ui/components/qrcode.cpp \
    53     src/library.cpp \
    54     src/business/contactimporter/contactimporter.cpp \
    55     src/business/account.cpp \
    56     src/business/account_costs.cpp \
    57     src/business/account_task_sendsms.cpp \
    58     src/business/accountvalidator.cpp \
    59     src/business/connectionhandler.cpp \
    60     src/business/gateway.cpp \
    61     src/business/smartphoneconnector_poll.cpp \
    62     src/business/smartphoneconnector.cpp \
    63     src/business/smartphonemanager.cpp \
    64     src/ui/settingswidget.cpp \
    65     src/persistence/gatewaystoragehelper.cpp \
    66     src/persistence/accountstoragehelper.cpp
    67 FORMS += src/ui/vcsettingswidget.ui
    68 RESOURCES += lib/smartphone.qrc
  • gateways/gateways.pro

    r330 r336  
    22
    33#SUBDIRS += ethz orange post schoolnet sunrise smartphone
    4 SUBDIRS += gateways-common schoolnet sunrise
     4SUBDIRS += gateways-common schoolnet sunrise smartphone
    55
    66gateways-common.file = common/gateways-common.pro
     
    1111schoolnet.file = Schoolnet/schoolnet.pro
    1212sunrise.file = Sunrise/sunrise.pro
    13 #smartphone.file = Smartphone/smartphone.pro
     13smartphone.file = Smartphone/smartphone.pro
Note: See TracChangeset for help on using the changeset viewer.