Changeset 320:31a4f0f7f542 in SMSSender


Ignore:
Timestamp:
Feb 26, 2014 5:41:37 PM (6 years ago)
Author:
Sämy Zehnder <saemy.zehnder@…>
Branch:
separation-frontend-backend
Message:
  • Separates the frontend and backend parts of the contact importers.
Files:
10 added
4 deleted
29 edited
3 copied
8 moved

Legend:

Unmodified
Added
Removed
  • common/business/icontactimporter.h

    r316 r320  
    11/*
    2  smssender - A frontend for fast and easy SMS sending over different gateways.
    3  Copyright (C) 2007-2014, gorrión. See http://smssender.gorrion.ch
     2  smssender - A frontend for fast and easy SMS sending over different gateways.
     3  Copyright (C) 2007-2014, gorrión. See http://smssender.gorrion.ch
    44
    5  This program is free software: you can redistribute it and/or modify
    6  it under the terms of the GNU General Public License as published by
    7  the Free Software Foundation, either version 3 of the License, or
    8  (at your option) any later version.
     5  This program is free software: you can redistribute it and/or modify
     6  it under the terms of the GNU General Public License as published by
     7  the Free Software Foundation, either version 3 of the License, or
     8  (at your option) any later version.
    99
    10  This program is distributed in the hope that it will be useful,
    11  but WITHOUT ANY WARRANTY; without even the implied warranty of
    12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    13  GNU General Public License for more details.
     10  This program is distributed in the hope that it will be useful,
     11  but WITHOUT ANY WARRANTY; without even the implied warranty of
     12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     13  GNU General Public License for more details.
    1414
    15  You should have received a copy of the GNU General Public License
    16  along with this program.  If not, see <http://www.gnu.org/licenses/>.
    17  */
     15  You should have received a copy of the GNU General Public License
     16  along with this program.  If not, see <http://www.gnu.org/licenses/>.
     17*/
    1818#ifndef COMMON_ICONTACTIMPORTER_H
    1919#define COMMON_ICONTACTIMPORTER_H
     
    2323#endif
    2424
    25 #endif // COMMON_ICONTACTIMPORTER_H
     25#endif /* COMMON_ICONTACTIMPORTER_H */
  • common/business/icontactimporter_base.h

    r316 r320  
    2424#include <QString>
    2525
     26class IContactImporter;
    2627class SContact;
    2728
    2829class IBaseContactImporter {
    2930public:
    30     virtual QString describingName() const =0;
    31     virtual bool isApplicable() const =0;
     31    virtual void importContacts(QSet<SContact *> *contacts) =0;
    3232
    33     virtual void init() =0;
     33    class Builder {
     34    public:
     35        virtual ~Builder() {}
    3436
    35     // Caller takes ownership of contacts.
    36     virtual void importContacts(QSet<SContact*> *contacts) =0;
     37        virtual QString description() const =0;
     38        virtual bool isApplicable() const =0;
     39
     40        virtual void init() {}
     41
     42        virtual void createImporters(QSet<IContactImporter *> *importers) =0;
     43    };
    3744
    3845public:
  • common/business/ilibrary.h

    r316 r320  
    2424#include <QTranslator>
    2525
     26#include "common/business/icontactimporter.h"
     27#include "common/business/igateway.h"
    2628#include "common/business/iintegration.h"
    2729#include "common/domain/sversion.h"
    2830#include "common/global.h"
    29 
    30 class IContactImporter;
    31 class IGateway;
    3231
    3332class COMMON_EXPORT ILibrary {
     
    5554
    5655    virtual QSet<QTranslator*> translators() const =0;
    57     virtual QSet<IContactImporter*> contactImporters() const =0;
     56    virtual QSet<IContactImporter::Builder *> contactImporters() const =0;
    5857    /**
    5958     * @brief Returns the gateway which is defined in this library.
  • common/common-base.pro

    r315 r320  
    6868    business/igateway.h \
    6969    domain/scontact.h \
    70     business/icontactimporter_base.h \
    71     business/icontactimporter.h \
    7270    business/iintegration_base.h \
    7371    business/iintegration.h \
     
    7775    persistence/impl/encryptedstoragehelper.h \
    7876    persistence/impl/storageconnectionhelper.h \
    79     persistence/impl/storageconnectionhelper_p.h
     77    persistence/impl/storageconnectionhelper_p.h \
     78    business/icontactimporter_base.h \
     79    business/icontactimporter.h
    8080SOURCES += domain/scontact.cpp \
    8181    domain/sdatatypes.cpp \
  • common/gui/business/icontactimporter.h

    r316 r320  
    2525
    2626class COMMON_GUI_EXPORT IContactImporter : public IBaseContactImporter {
     27    Q_INTERFACES(IBaseContactImporter)
     28
    2729public:
    28     /**
    29      * Returns pages that should be shown before contacts are imported.
    30      * This can be used to let the user specify some importer specific
    31      * configuration.
    32      * The caller DOES NOT take ownership of the pages.
    33      * @return
    34      */
    35     virtual QList<QWizardPage*> preImportPages() =0;
     30    class Builder : public IBaseContactImporter::Builder {
     31        Q_INTERFACES(IBaseContactImporter::Builder)
     32
     33    public:
     34        /**
     35         * Returns pages that should be shown before contacts are imported.
     36         * This can be used to let the user specify some importer specific
     37         * configuration.
     38         *
     39         * @param pages The preimport pages. The caller takes ownership.
     40         */
     41        virtual void createPreImportPages(QList<QWizardPage *> *pages) {
     42            Q_UNUSED(pages);
     43        }
     44    };
    3645};
    37 Q_DECLARE_INTERFACE(IContactImporter, "ch.gorrion.smssender.IContactImporter/1.0")
     46Q_DECLARE_INTERFACE(IContactImporter,
     47                    "ch.gorrion.smssender.IContactImporter/1.0")
    3848
    3949#endif // COMMON_GUI_ICONTACTIMPORTER_H
  • frontend/business/contactimporter/contactfilesimporter.cpp

    r316 r320  
    1717 */
    1818#include "contactfilesimporter.h"
     19#include "contactfilesimporter_p.h"
    1920
    2021#include <QDebug>
     
    2425#include "common/domain/snumber.h"
    2526
    26 ContactFilesImporter::ContactFilesImporter()
    27     : m_dataManager(new ContactFilesImporterDataManager)
     27BaseContactFilesImporter::BaseContactFilesImporter(const QString &filename)
     28    : m_filename(filename)
    2829{
    2930}
    3031
    31 QString ContactFilesImporter::describingName() const {
     32void BaseContactFilesImporter::importContacts(QSet<SContact*> *contacts) {
     33    QFileInfo fi(m_filename);
     34    if (!fi.isReadable()) {
     35        return;
     36    }
     37
     38    QScopedPointer<IContactImporter> importer;
     39    if (fi.completeSuffix().toLower() == "ini") {
     40        QSettings ini(fi.absoluteFilePath(), QSettings::IniFormat);
     41        if (ini.childGroups().contains("contacts")) {
     42            // V1 contacts file
     43            importer.reset(new ContactFilesImporterV1(fi.absoluteFilePath()));
     44        } else {
     45            // V2 contacts file
     46            importer.reset(new ContactFilesImporterV2(fi.absoluteFilePath()));
     47        }
     48    } else if (fi.completeSuffix().toLower() == "db") {
     49        // V3 contacts file
     50        // TODO: Import V3 contacts file
     51
     52    } else if (fi.completeSuffix().toLower() == "csv") {
     53        importer.reset(new ContactFilesImporterCSV(fi.absoluteFilePath()));
     54    }
     55
     56    if (importer) {
     57        importer->importContacts(contacts);
     58    }
     59}
     60
     61
     62/********************************** BUILDER ***********************************/
     63
     64
     65QString BaseContactFilesImporter::Builder::description() const {
    3266    return QObject::tr("Import contacts from contact files (Old smssender contact files, CSV).");
    3367}
    3468
    35 bool ContactFilesImporter::isApplicable() const {
     69bool BaseContactFilesImporter::Builder::isApplicable() const {
    3670    return true;
    3771}
    3872
    39 
    40 void ContactFilesImporter::init() {
    41 }
    42 
    43 /*QList<IContactImporter::Page*> ContactFilesImporter::preImportPages() {
    44     QList<QWizardPage*> pages;
    45     pages.append(new UI::CFI::PageConfig(parent, m_dataManager.data()));
    46 
    47     return pages;
    48 }*/
    49 
    50 void ContactFilesImporter::importContacts(QSet<SContact*> *contacts) {
    51     const QMap<QString, bool> &selectedFilesMap = m_dataManager->selectionMap();
    52     for (QMap<QString, bool>::ConstIterator it = selectedFilesMap.begin(); it != selectedFilesMap.end(); ++it) {
    53         if (!it.value()) continue; // Not selected
    54 
    55         QFileInfo fi(it.key());
    56         if (!fi.isReadable()) continue;
    57 
    58         if (fi.completeSuffix().toLower() == "ini") {
    59             QSettings ini(fi.fileName(), QSettings::IniFormat);
    60             if (ini.childGroups().contains("contacts")) {
    61                 // V1 contacts file
    62                 readV1ContactsFile(ini, contacts);
    63             } else {
    64                 // V2 contacts file
    65                 readV2ContactsFile(ini, contacts);
    66             }
    67 
    68         } else if (fi.completeSuffix().toLower() == "db") {
    69             // V3 contacts file
    70             // TODO: Import V3 contacts file
    71 
    72         } else if (fi.completeSuffix().toLower() == "csv") {
    73             CSVFile csv = parseCSV(fi.fileName());
    74             readCSV(csv, contacts);
    75         }
    76     }
    77 }
    78 
    79 
    80 /*QStringList ContactFilesImporter::defaultContactsFiles() const {
    81     QStringList r;
    82 
    83     _addDefaultFile(r, QDesktopServices::storageLocation(QDesktopServices::DataLocation) + "/gorrion/SMSSender/contacts.ini");
    84     _addDefaultFile(r, QDesktopServices::storageLocation(QDesktopServices::ApplicationsLocation) + "/gorrion/SMSSender/contacts.ini");
    85 
    86     return r;
    87 }*/
    88 
    89 void ContactFilesImporter::readV1ContactsFile(const QSettings& ini, QSet<SContact *> *contacts) const {
     73void BaseContactFilesImporter::Builder::init() {
     74    // Selects default files.
     75    m_contactFiles.clear();
     76    setDefaultContactFiles();
     77}
     78
     79void BaseContactFilesImporter::Builder::createImporters(QSet<IContactImporter*> *importers) {
     80    foreach (QString filename, m_contactFiles.selectedContactFiles()) {
     81        importers->insert(new ContactFilesImporter(filename));
     82    }
     83}
     84
     85/************************************* V1 *************************************/
     86
     87void ContactFilesImporterV1::importContacts(QSet<SContact *> *contacts) {
    9088    int i = 0;
    91     while (ini.contains("contacts/contact_" + QString::number(i) + "_nr")) {
    92         QString name = ini.value("contacts/contact_" + QString::number(i) + "_name").toString();
    93         SNumber number(ini.value("contacts/contact_" + QString::number(i) + "_nr").toString());
     89    while (m_file.contains("contacts/contact_" + QString::number(i) + "_nr")) {
     90        QString name = m_file.value("contacts/contact_" + QString::number(i) + "_name").toString();
     91        SNumber number(m_file.value("contacts/contact_" + QString::number(i) + "_nr").toString());
    9492        if (!name.trimmed().isEmpty() && number.isValid()) {
    9593            QScopedPointer<SContact> contact(new SContact);
     
    104102}
    105103
    106 void ContactFilesImporter::readV2ContactsFile(const QSettings& ini, QSet<SContact *> *contacts) const {
    107     foreach (QString name, ini.childGroups()) {
    108         SNumber number(ini.value(name + "/" + "number").toString());
     104/************************************* V2 *************************************/
     105
     106void ContactFilesImporterV2::importContacts(QSet<SContact *> *contacts) {
     107    foreach (QString name, m_file.childGroups()) {
     108        SNumber number(m_file.value(name + "/" + "number").toString());
    109109        if (!name.trimmed().isEmpty() && number.isValid()) {
    110110            QScopedPointer<SContact> contact(new SContact);
     
    117117}
    118118
    119 
    120 QStringList parseLine(const QString& line) {
    121     QStringList s;
    122     QRegExp rx("(\"([^\"]*)\"|)(,|$)");
    123 
    124     int pos = 0;
    125     while ((pos = rx.indexIn(line, pos)) != -1) {
    126         if (pos == line.length()) break;
    127 
    128         pos += rx.matchedLength();
    129 
    130         qDebug() << rx.capturedTexts();
    131         s.append(rx.cap(2));
    132     }
    133     return s;
    134 }
    135 
    136 ContactFilesImporter::CSVFile ContactFilesImporter::parseCSV(const QString& filename) const {
     119/************************************* CSV ************************************/
     120
     121void ContactFilesImporterCSV::importContacts(QSet<SContact *> *contacts) {
     122    const CSVFile &csv = parseCSV();
     123    readCSV(csv, contacts);
     124}
     125
     126ContactFilesImporterCSV::CSVFile ContactFilesImporterCSV::parseCSV() const {
    137127    CSVFile csv;
    138128
    139     QFile file(filename);
     129    QFile file(m_filename);
    140130    if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
    141131        return csv;
     
    165155}
    166156
    167 void ContactFilesImporter::readCSV(const CSVFile& csv, QSet<SContact*> *contacts) const {
     157QStringList ContactFilesImporterCSV::parseLine(const QString& line) const {
     158    QStringList s;
     159    QRegExp rx("(\"([^\"]*)\"|)(,|$)");
     160
     161    int pos = 0;
     162    while ((pos = rx.indexIn(line, pos)) != -1) {
     163        if (pos == line.length()) break;
     164
     165        pos += rx.matchedLength();
     166
     167        qDebug() << rx.capturedTexts();
     168        s.append(rx.cap(2));
     169    }
     170    return s;
     171}
     172
     173void ContactFilesImporterCSV::readCSV(
     174        const ContactFilesImporterCSV::CSVFile& csv,
     175        QSet<SContact*> *contacts) const {
    168176    QStringList nameKeys;
    169     nameKeys.append("[Name]");      // Google CSV
    170     nameKeys.append("[Yomi Name]"); // Google CSV
    171     nameKeys.append("[Title][First Name][Middle Name][Last Name]"); // Outlook CSV
    172     nameKeys.append("[Nickname]");  // Google CSV
     177
     178    // Google CSV
     179    nameKeys.append("[Name]");
     180    nameKeys.append("[Yomi Name]");
     181    nameKeys.append("[Nickname]");
     182
     183    // Outlook CSV
     184    nameKeys.append("[Title][First Name][Middle Name][Last Name]");
    173185
    174186    for (int i = 0; i < csv.values.count(); ++i) {
     
    207219
    208220        int j = 1;
    209         while (csv.keys.contains(QString("Phone %1 - Type").arg(j)) && !number.isValid()) {
    210             if (csvLine.value(QString("Phone %1 - Type").arg(j)) != "Mobile") continue;
    211 
    212             QStringList numberStrings = csvLine.value(QString("Phone %1 - Value").arg(j)).split(":::");
     221        while (csv.keys.contains(QString("Phone %1 - Type").arg(j)) &&
     222               !number.isValid()) {
     223            if (csvLine.value(QString("Phone %1 - Type").arg(j)) != "Mobile") {
     224                continue;
     225            }
     226
     227            QStringList numberStrings =
     228                    csvLine.value(QString("Phone %1 - Value").arg(j))
     229                    .split(":::");
    213230            int k = 0;
    214231            while (!number.isValid() && (k < numberStrings.count())) {
     
    231248    }
    232249}
    233 
    234 ContactFilesImporterDataManager *ContactFilesImporter::dataManager() const {
    235     return m_dataManager.data();
    236 }
    237 
    238 // *************************** DataManager *************************** //
    239 
    240 void ContactFilesImporterDataManager::addContactFile(const QString &path) {
    241     QFileInfo fi(path);
    242     if (!fi.isReadable()) return;
    243 
    244     setContactFileSelected(path, true);
    245 }
    246 
    247 void ContactFilesImporterDataManager::setContactFileSelected(const QString &path, bool selected) {
    248     m_selectedFileMap[path] = selected;
    249     emit dataChanged();
    250 }
    251 
    252 bool ContactFilesImporterDataManager::isContactFileSelected(const QString &path) const {
    253     return m_selectedFileMap.value(path, false);
    254 }
    255 
    256 const QMap<QString, bool> &ContactFilesImporterDataManager::selectionMap() const {
    257     return m_selectedFileMap;
    258 }
    259 
  • frontend/business/contactimporter/contactfilesimporter.h

    r319 r320  
    1919#define FRONTEND_CONTACTIMPORTER_CONTACTFILESIMPORTER_H
    2020
    21 #include <QMap>
    22 #include <QSettings>
    23 #include <QString>
    24 #include <QStringList>
     21#ifdef FRONTEND_GUI
     22#include "frontend/gui/business/contactfilesimporter.h"
     23#endif
    2524
    26 #include "common/business/icontactimporter.h"
    27 
    28 class ContactFilesImporterDataManager;
    29 class ContactFilesImporter : public IContactImporter {
    30     Q_INTERFACES(IContactImporter)
    31 
    32 public:
    33     ContactFilesImporter();
    34 
    35     QString describingName() const;
    36     bool isApplicable() const;
    37 
    38     void init();
    39 
    40     // Caller takes ownership of contacts.
    41     void importContacts(QSet<SContact*> *contacts);
    42 
    43     ContactFilesImporterDataManager *dataManager() const;
    44 
    45 private:
    46     struct CSVFile {
    47         QStringList keys;
    48         QList<QMap<QString, QString> > values; // key => value
    49     };
    50 
    51 private:
    52     const QScopedPointer<ContactFilesImporterDataManager> m_dataManager;
    53 
    54     // Caller takes ownership of contacts.
    55     void readV1ContactsFile(const QSettings& ini, QSet<SContact*> *contacts) const;
    56 
    57     // Caller takes ownership of contacts.
    58     void readV2ContactsFile(const QSettings& ini, QSet<SContact*> *contacts) const;
    59 
    60     CSVFile parseCSV(const QString& filename) const;
    61     void readCSV(const CSVFile& csv, QSet<SContact*> *contacts) const;
    62 };
    63 
    64 class ContactFilesImporterDataManager : public QObject {
    65     Q_OBJECT
    66 
    67 public:
    68     ContactFilesImporterDataManager() {}
    69 
    70     void addContactFile(const QString &path);
    71     void setContactFileSelected(const QString &path, bool selected);
    72 
    73     bool isContactFileSelected(const QString &path) const;
    74     const QMap<QString, bool> &selectionMap() const;
    75 
    76 signals:
    77     void dataChanged();
    78 
    79 private:
    80     QMap<QString, bool> m_selectedFileMap;
    81 };
    82 
    83 #endif /* FRONTEND_CONTACTIMPORTER_CONTACTFILESIMPORTER_H */
     25#endif // FRONTEND_CONTACTIMPORTER_CONTACTFILESIMPORTER_H
  • frontend/business/contactimporter/contactfilesimporter_base.h

    r319 r320  
    1616 along with this program.  If not, see <http://www.gnu.org/licenses/>.
    1717 */
    18 #ifndef FRONTEND_CONTACTIMPORTER_CONTACTFILESIMPORTER_H
    19 #define FRONTEND_CONTACTIMPORTER_CONTACTFILESIMPORTER_H
     18#ifndef FRONTEND_CONTACTIMPORTER_CONTACTFILESIMPORTER_BASE_H
     19#define FRONTEND_CONTACTIMPORTER_CONTACTFILESIMPORTER_BASE_H
    2020
    2121#include <QMap>
     
    2525
    2626#include "common/business/icontactimporter.h"
     27#include "frontend/business/contactimporter/contactfilelist.h"
    2728
    28 class ContactFilesImporterDataManager;
    29 class ContactFilesImporter : public IContactImporter {
     29class BaseContactFilesImporter : public IContactImporter {
    3030    Q_INTERFACES(IContactImporter)
    3131
    3232public:
    33     ContactFilesImporter();
     33    explicit BaseContactFilesImporter(const QString &filename);
    3434
    35     QString describingName() const;
    36     bool isApplicable() const;
    37 
    38     void init();
    39 
    40     // Caller takes ownership of contacts.
     35public: /* IContactImporter */
    4136    void importContacts(QSet<SContact*> *contacts);
    4237
    43     ContactFilesImporterDataManager *dataManager() const;
     38    class Builder : public IContactImporter::Builder {
     39    public: /* IContactImporter */
     40        QString description() const;
     41        bool isApplicable() const;
    4442
    45 private:
    46     struct CSVFile {
    47         QStringList keys;
    48         QList<QMap<QString, QString> > values; // key => value
     43        void init();
     44        void createImporters(QSet<IContactImporter *> *importers);
     45
     46    protected:
     47        virtual void setDefaultContactFiles() =0;
     48
     49        ContactFileList m_contactFiles;
    4950    };
    5051
    5152private:
    52     const QScopedPointer<ContactFilesImporterDataManager> m_dataManager;
    53 
    54     // Caller takes ownership of contacts.
    55     void readV1ContactsFile(const QSettings& ini, QSet<SContact*> *contacts) const;
    56 
    57     // Caller takes ownership of contacts.
    58     void readV2ContactsFile(const QSettings& ini, QSet<SContact*> *contacts) const;
    59 
    60     CSVFile parseCSV(const QString& filename) const;
    61     void readCSV(const CSVFile& csv, QSet<SContact*> *contacts) const;
     53    QString m_filename;
    6254};
    6355
    64 class ContactFilesImporterDataManager : public QObject {
    65     Q_OBJECT
    66 
    67 public:
    68     ContactFilesImporterDataManager() {}
    69 
    70     void addContactFile(const QString &path);
    71     void setContactFileSelected(const QString &path, bool selected);
    72 
    73     bool isContactFileSelected(const QString &path) const;
    74     const QMap<QString, bool> &selectionMap() const;
    75 
    76 signals:
    77     void dataChanged();
    78 
    79 private:
    80     QMap<QString, bool> m_selectedFileMap;
    81 };
    82 
    83 #endif /* FRONTEND_CONTACTIMPORTER_CONTACTFILESIMPORTER_H */
     56#endif /* FRONTEND_CONTACTIMPORTER_CONTACTFILESIMPORTER_BASE_H */
  • frontend/business/contactimportermanager.cpp

    r316 r320  
    2424}
    2525
    26 void ContactImporterManager::registerContactImporter(IContactImporter *importer) {
     26void ContactImporterManager::registerContactImporter(
     27        IContactImporter::Builder *importer) {
    2728    m_importers.insert(importer);
    2829}
    2930
    30 void ContactImporterManager::registerManagedContactImporter(IContactImporter *importer) {
     31void ContactImporterManager::registerManagedContactImporter(
     32        IContactImporter::Builder *importer) {
    3133    m_managedImporters.insert(importer);
    3234    registerContactImporter(importer);
    3335}
    3436
    35 void ContactImporterManager::unregisterContactImporter(IContactImporter *importer) {
     37void ContactImporterManager::unregisterContactImporter(
     38        IContactImporter::Builder *importer) {
    3639    m_importers.remove(importer);
    3740    m_managedImporters.remove(importer);
    3841}
    3942
    40 QSet<IContactImporter *> ContactImporterManager::contactImporters() const {
     43QSet<IContactImporter::Builder *> ContactImporterManager::contactImporters() const {
    4144    return m_importers;
    4245}
  • frontend/business/contactimportermanager.h

    r319 r320  
    3232     * @param importer Does not take ownership.
    3333     */
    34     void registerContactImporter(IContactImporter *importer);
     34    void registerContactImporter(IContactImporter::Builder *importer);
    3535
    3636    /**
    3737     * @param importer Takes ownership.
    3838     */
    39     void registerManagedContactImporter(IContactImporter *importer);
     39    void registerManagedContactImporter(IContactImporter::Builder *importer);
    4040
    4141    /**
     
    4444     * @param importer The to be removed importer
    4545     */
    46     void unregisterContactImporter(IContactImporter *importer);
     46    void unregisterContactImporter(IContactImporter::Builder *importer);
    4747
    48     QSet<IContactImporter*> contactImporters() const;
     48    QSet<IContactImporter::Builder *> contactImporters() const;
    4949
    5050private:
    51     QSet<IContactImporter*> m_managedImporters;
    52     QSet<IContactImporter*> m_importers;
     51    QSet<IContactImporter::Builder *> m_managedImporters;
     52    QSet<IContactImporter::Builder *> m_importers;
    5353
    5454    Q_DISABLE_COPY(ContactImporterManager)
  • frontend/business/libraryloader_base.cpp

    r316 r320  
    9595                    m_gatewayManager->registerGateway(gateway);
    9696                }
    97                 foreach (IContactImporter *importer, lib->contactImporters()) {
     97                foreach (IContactImporter::Builder *importer, lib->contactImporters()) {
    9898                    m_contactImporterManager->registerContactImporter(importer);
    9999                }
  • frontend/frontend-base.pro

    r315 r320  
    4444    business/erroraccount.h \
    4545    business/accountintegrationhelper.h \
    46     business/contactimporter/abstractgooglecontactimporter.h \
    4746    persistence/accountmanager.h \
    4847    persistence/groupmanager.h \
    4948    persistence/database.h \
    5049    persistence/contactmanager.h \
    51     business/contactimporter/contactfilesimporter.h \
    5250    persistence/persistenceintegrationhelper.h \
    5351    business/settings_base.h \
     
    5553    business/libraryloader_base.h \
    5654    persistence/mainstorage_base.h \
    57     persistence/restrictedmainstorage.h
     55    persistence/restrictedmainstorage.h \
     56    business/contactimporter/contactfilelist.h \
     57    business/contactimporter/contactfilesimporter_p.h \
     58    business/contactimporter/contactfilesimporter_base.h \
     59    business/contactimporter/contactfilesimporter.h \
     60    business/contactimporter/googlecontactimporter_base.h \
     61    business/contactimporter/googlecontactimporter.h
    5862SOURCES += business/accountinitmanager.cpp \
    5963    business/accountmanager.cpp \
     
    6569    business/updatemanager.cpp \
    6670    business/erroraccount.cpp \
    67     business/contactimporter/abstractgooglecontactimporter.cpp \
    6871    business/accountintegrationhelper.cpp \
    6972    persistence/pers_accountmanager.cpp \
     
    7477    persistence/pers_contactmanager_storage.cpp \
    7578    persistence/pers_groupmanager_storage.cpp \
    76     business/contactimporter/contactfilesimporter.cpp \
     79    business/contactimporter/contactfilelist.cpp \
    7780    persistence/persistenceintegrationhelper.cpp \
    7881    business/settings_base.cpp \
     
    8083    persistence/mainstorage_base.cpp \
    8184    persistence/mainstorage_base_storage.cpp \
    82     persistence/restrictedmainstorage.cpp
     85    persistence/restrictedmainstorage.cpp \
     86    business/contactimporter/contactfilesimporter.cpp \
     87    business/contactimporter/googlecontactimporter.cpp
    8388RESOURCES += \
    8489    lib/frontend.qrc
  • frontend/gui/business/managerfactory.cpp

    r316 r320  
    2727#include "frontend/business/suffixmanager.h"
    2828#include "frontend/business/updatemanager.h"
     29#include "frontend/gui/business/contactfilesimporter.h"
     30#include "frontend/gui/business/googlecontactimporter.h"
    2931#include "frontend/gui/business/integrationhelper.h"
    3032#include "frontend/gui/persistence/persistencefactory.h"
     
    4850    , m_guiManager(new UI::GuiManager(m_settingsManager.data()))
    4951{
     52    m_contactImporterManager->registerManagedContactImporter(new ContactFilesImporter::Builder);
     53    m_contactImporterManager->registerManagedContactImporter(new GoogleContactImporter::Builder);
    5054}
    5155ManagerFactory::~ManagerFactory() {
  • frontend/gui/frontend-gui.pro

    r317 r320  
    7373    ui/importcontacts/importcontacts_page_import.h \
    7474    ui/importcontacts/importcontacts_page_intro.h \
    75     ui/importcontacts/importerpages/contactfilesmodel.h \
    76     ui/importcontacts/importerpages/file_page_config.h \
    77     ui/importcontacts/importerpages/google_page_config.h \
     75    ui/importcontacts/pages/contactfilesmodel.h \
     76    ui/importcontacts/pages/google_page_config.h \
    7877    ui/main.h \
    7978    ui/sendingdialog.h \
     
    8786    business/libraryloader.h \
    8887    persistence/mainstorage.h \
    89     business/settings.h
     88    business/settings.h \
     89    ui/importcontacts/pages/contactfiles_page_config.h \
     90    business/contactfilesimporter.h \
     91    business/googlecontactimporter.h
    9092SOURCES += \
    9193    business/managerfactory.cpp \
     
    118120    ui/importcontacts/importcontacts_page_import.cpp \
    119121    ui/importcontacts/importcontacts_page_intro.cpp \
    120     ui/importcontacts/importerpages/contactfilesmodel.cpp \
    121     ui/importcontacts/importerpages/file_page_config.cpp \
    122     ui/importcontacts/importerpages/google_page_config.cpp \
     122    ui/importcontacts/pages/google_page_config.cpp \
    123123    ui/main.cpp \
    124124    ui/sendingdialog.cpp \
     
    132132    business/libraryloader.cpp \
    133133    persistence/pers_mainstorage.cpp \
    134     business/settings.cpp
     134    business/settings.cpp \
     135    ui/importcontacts/pages/contactfiles_page_config.cpp \
     136    ui/importcontacts/pages/contactfilesmodel.cpp \
     137    business/contactfilesimporter.cpp \
     138    business/googlecontactimporter.cpp
    135139FORMS += \
    136140    ui/about.ui \
     
    144148    ui/importcontacts/importcontacts_page_import.ui \
    145149    ui/importcontacts/importcontacts_page_intro.ui \
    146     ui/importcontacts/importerpages/file_page_config.ui \
    147     ui/importcontacts/importerpages/google_page_config.ui \
     150    ui/importcontacts/pages/google_page_config.ui \
    148151    ui/main.ui \
    149152    ui/sendingdialog.ui \
    150153    ui/settingsdialog.ui \
    151     ui/updatedialog.ui
     154    ui/updatedialog.ui \
     155    ui/importcontacts/pages/contactfiles_page_config.ui
    152156RESOURCES += \
    153157    lib/frontend-gui.qrc
  • frontend/gui/ui/importcontacts/importcontacts_datamanager.cpp

    r316 r320  
    2626}
    2727
    28 QSet<IContactImporter *> ImportContactsDataManager::activatedImporters() const {
     28QSet<IContactImporter::Builder *> ImportContactsDataManager::activatedImporters() const {
    2929    return m_importers;
    3030}
     
    3333}
    3434
    35 void ImportContactsDataManager::setActivatedImporters(const QSet<IContactImporter *> &importers) {
     35void ImportContactsDataManager::setActivatedImporters(const QSet<IContactImporter::Builder *> &importers) {
    3636    m_importers = importers;
    3737}
  • frontend/gui/ui/importcontacts/importcontacts_datamanager.h

    r319 r320  
    3333
    3434public:
    35     QSet<IContactImporter*> activatedImporters() const;
     35    QSet<IContactImporter::Builder *> activatedImporters() const;
    3636    QSet<SContact *> importedContacts() const;
    3737
    3838    // Does not take ownership
    39     void setActivatedImporters(const QSet<IContactImporter*> &importers);
     39    void setActivatedImporters(const QSet<IContactImporter::Builder *> &importers);
    4040    void setImportedContacts(const QSet<SContact *> &contacts);
    4141
     
    5050
    5151private:
    52     QSet<IContactImporter*> m_importers;
     52    QSet<IContactImporter::Builder *> m_importers;
    5353    QSet<SContact*> m_contacts;
    5454    QSet<SContact*> m_noimportContacts;
  • frontend/gui/ui/importcontacts/importcontacts_importedcontacttablemodel.cpp

    r316 r320  
    150150    importedContacts_ = m_dataManager->importedContacts().toList();
    151151    foreach (const SContact *contact, importedContacts_) {
    152         connect(contact, SIGNAL(dataChanged(SContact)),
     152        connect(contact, SIGNAL(dataChanged(SContact *)),
    153153                this, SLOT(contactListAltered()));
    154154    }
  • frontend/gui/ui/importcontacts/importcontacts_page_import.cpp

    r316 r320  
    5858
    5959    m_runningTasks = 0;
    60     foreach (IContactImporter *importer, m_dataManager->activatedImporters()) {
    61         ImportTask *importTask = new ImportTask(importer);
    62         connect(importTask, SIGNAL(finished(STask*)), this, SLOT(importTaskFinished(STask*)), Qt::DirectConnection);
    63         ++m_runningTasks;
    64         importTask->start();
     60    foreach (IContactImporter::Builder *builder, m_dataManager->activatedImporters()) {
     61        QSet<IContactImporter *> importers;
     62        builder->createImporters(&importers);
     63
     64        foreach (IContactImporter *importer, importers) {
     65            ImportTask *importTask = new ImportTask(importer);
     66            connect(importTask, SIGNAL(finished(STask*)),
     67                    this, SLOT(importTaskFinished(STask*)), Qt::DirectConnection);
     68            ++m_runningTasks;
     69            importTask->start();
     70        }
    6571    }
    6672
     
    133139        if (someDataDiffers) {
    134140            QScopedPointer<SContact> clone(new SContact); // Make a copy to not really change it
    135             clone->setId(contact->id());
    136             clone->setName(contact->name());
    137             clone->setAliases(contact->aliases());
    138             clone->setImage(contact->image());
     141            clone->setId(existing->id());
     142            clone->setName(existing->name());
     143            clone->setNumber(existing->number());
     144            clone->setAliases(existing->aliases());
     145            clone->setImage(existing->image());
    139146
    140147            _addImportedContact(clone.take());
     
    191198        }
    192199    } else {
    193         m_importedContacts.insert(contact->number().toString(), contact.take());
     200        SContact *ctct = contact.take();
     201        m_importedContacts.insert(ctct->number().toString(), ctct);
    194202    }
    195203}
  • frontend/gui/ui/importcontacts/importcontacts_page_import.h

    r319 r320  
    8282
    8383public:
     84    // Takes ownership.
    8485    explicit ImportTask(IContactImporter *importer);
    8586    ~ImportTask();
     
    9394
    9495private:
    95     IContactImporter * const m_importer;
     96    QScopedPointer<IContactImporter> m_importer;
    9697    QSet<SContact*> m_importedContacts;
    9798};
  • frontend/gui/ui/importcontacts/importcontacts_page_intro.cpp

    r316 r320  
    2525namespace UI {
    2626
    27 ImportContactsPageIntro::ImportContactsPageIntro(QWidget* parent, ImportContactsDataManager* dataManager,
    28                                                  const QSet<IContactImporter*> &contactImporters)
     27ImportContactsPageIntro::ImportContactsPageIntro(
     28        QWidget* parent, ImportContactsDataManager* dataManager,
     29        const QSet<IContactImporter::Builder *> &contactImporters)
    2930    : QWizardPage(parent)
    3031    , m_dataManager(dataManager)
     
    3839    m_importers.clear();
    3940
    40     foreach (IContactImporter *importer, m_contactImporters) {
    41             QListWidgetItem* i = new QListWidgetItem(importer->describingName());
     41    foreach (IContactImporter::Builder *importer, m_contactImporters) {
     42        QListWidgetItem* i = new QListWidgetItem(importer->description());
    4243            i->setCheckState(Qt::Unchecked);
    4344            i->setFlags(Qt::ItemIsSelectable | Qt::ItemIsUserCheckable);
     
    6970
    7071void ImportContactsPageIntro::setActivatedImporters() {
    71     QSet<IContactImporter*> activatedImporters;
     72    QSet<IContactImporter::Builder *> activatedImporters;
    7273    for (int i = 0; i < ui.lstImporters->count(); ++i) {
    7374        QListWidgetItem *item = ui.lstImporters->item(i);
  • frontend/gui/ui/importcontacts/importcontacts_page_intro.h

    r319 r320  
    2424#include <QWizardPage>
    2525
    26 class IContactImporter;
     26#include "common/business/icontactimporter.h"
    2727
    2828namespace UI {
     
    3434public:
    3535    ImportContactsPageIntro(QWidget* parent, ImportContactsDataManager* dataManager,
    36                             const QSet<IContactImporter*> &contactImporters);
     36                            const QSet<IContactImporter::Builder *> &contactImporters);
    3737
    3838public: /* QWizardPage */
     
    4242private:
    4343    ImportContactsDataManager * const m_dataManager;
    44     QSet<IContactImporter*> m_contactImporters;
     44    QSet<IContactImporter::Builder *> m_contactImporters;
    4545    Ui::ImportContactsPageIntroClass ui;
    4646
    47     QList<IContactImporter*> m_importers;
     47    QList<IContactImporter::Builder *> m_importers;
    4848
    4949private slots:
  • frontend/gui/ui/importcontacts/importcontactswizard.cpp

    r316 r320  
    2828namespace UI {
    2929
    30 ImportContactsWizard::ImportContactsWizard(QWidget* parent, const QSet<IContactImporter*> &contactImporters,
    31                                            ContactManager *contactManager, const GroupManager &groupManager,
    32                                            GuiManager *guiManager)
     30ImportContactsWizard::ImportContactsWizard(
     31        QWidget* parent,
     32        const QSet<IContactImporter::Builder *> &contactImporters,
     33        ContactManager *contactManager, const GroupManager &groupManager,
     34        GuiManager *guiManager)
    3335    : QWizard(parent)
    3436    , m_dataManager(new ImportContactsDataManager)
     
    4446    addPage(new ImportContactsPageIntro(this, m_dataManager.data(), contactImporters));
    4547
    46     foreach (IContactImporter *importer, contactImporters) {
    47         importer->init();
     48    foreach (IContactImporter::Builder *builder, contactImporters) {
     49        builder->init();
    4850
    49         foreach(QWizardPage* page, importer->preImportPages()) {
    50             m_preImportPageIds.insertMulti(importer, addPage(page));
     51        QList<QWizardPage *> pages;
     52        builder->createPreImportPages(&pages);
     53
     54        foreach(QWizardPage* page, pages) {
     55            m_preImportPageIds.insertMulti(builder, addPage(page));
    5156        }
    5257    }
  • frontend/gui/ui/importcontacts/importcontactswizard.h

    r319 r320  
    3737
    3838public:
    39     ImportContactsWizard(QWidget* parent, const QSet<IContactImporter*> &contactImporters,
    40                          ContactManager *contactManager, const GroupManager &groupManager, GuiManager *guiManager);
     39    ImportContactsWizard(
     40            QWidget* parent,
     41            const QSet<IContactImporter::Builder *> &contactImporters,
     42            ContactManager *contactManager, const GroupManager &groupManager,
     43            GuiManager *guiManager);
    4144    ~ImportContactsWizard();
    4245
     
    4750    const QScopedPointer<ImportContactsDataManager> m_dataManager;
    4851
    49     QMap<IContactImporter*, int> m_preImportPageIds;
     52    QMap<IContactImporter::Builder *, int> m_preImportPageIds;
    5053};
    5154
  • frontend/gui/ui/importcontacts/pages/contactfiles_page_config.cpp

    r317 r320  
    1616 along with this program.  If not, see <http://www.gnu.org/licenses/>.
    1717 */
    18 #include "file_page_config.h"
     18#include "contactfiles_page_config.h"
    1919
     20#include <QDesktopServices>
    2021#include <QFileDialog>
    2122
     
    2526namespace CFI {
    2627
    27 PageConfig::PageConfig(QWidget* parent, ContactFilesImporterDataManager *dataManager)
    28     : QWizardPage(parent)
    29     , m_dataManager(dataManager)
     28PageConfig::PageConfig(ContactFileList *contactFileList)
     29    : QWizardPage()
     30    , m_contactFiles(contactFileList)
    3031{
    3132        ui.setupUi(this);
    3233
    33     m_contactFilesModel.reset(new ContactFilesModel(m_dataManager));
     34    m_contactFilesModel.reset(new ContactFilesModel(m_contactFiles));
    3435    ui.tblViewContactFiles->setModel(m_contactFilesModel.data());
    3536    ui.tblViewContactFiles->resizeRowsToContents();
     
    4243
    4344void PageConfig::on_btnAddContactsFile_clicked() {
    44     QString filename = QFileDialog::getOpenFileName(this, tr("Select the contacts file"));
    45     m_dataManager->addContactFile(filename);
     45    const QString &filename =
     46            QFileDialog::getOpenFileName(this, tr("Select the contacts file"));
     47    m_contactFiles->addContactFile(filename);
    4648}
     49
    4750
    4851} // namespace CFI
  • frontend/gui/ui/importcontacts/pages/contactfiles_page_config.h

    r319 r320  
    1616 along with this program.  If not, see <http://www.gnu.org/licenses/>.
    1717 */
    18 #ifndef FRONTEND_GUI_UI_IMPORTCONTACTS_IMPORTERPAGES_FILE_PAGE_CONFIG_H
    19 #define FRONTEND_GUI_UI_IMPORTCONTACTS_IMPORTERPAGES_FILE_PAGE_CONFIG_H
     18#ifndef FRONTEND_GUI_UI_IMPORTCONTACTS_PAGES_CONTACTFILES_PAGE_CONFIG_H
     19#define FRONTEND_GUI_UI_IMPORTCONTACTS_PAGES_CONTACTFILES_PAGE_CONFIG_H
    2020
    21 #include "ui_file_page_config.h"
     21#include "ui_contactfiles_page_config.h"
    2222
    2323#include <QAbstractTableModel>
     
    2525#include <QWizardPage>
    2626
    27 #include "frontend/business/contactimporter/contactfilesimporter.h"
     27#include "frontend/business/contactimporter/contactfilelist.h"
    2828
    2929namespace UI {
     
    3434
    3535public:
    36     PageConfig(QWidget *parent, ContactFilesImporterDataManager *dataManager);
     36    explicit PageConfig(ContactFileList *contactFileList);
    3737
    3838private slots:
     
    4040
    4141private:
    42     ContactFilesImporterDataManager * const m_dataManager;
    4342    ::CFI::Ui::PageConfigClass ui;
    4443
     44    ContactFileList * const m_contactFiles;
    4545    QScopedPointer<QAbstractTableModel> m_contactFilesModel;
    4646};
     
    4949} // namespace UI
    5050
    51 #endif // FRONTEND_GUI_UI_IMPORTCONTACTS_IMPORTERPAGES_FILE_PAGE_CONFIG_H
     51#endif // FRONTEND_GUI_UI_IMPORTCONTACTS_PAGES_CONTACTFILES_PAGE_CONFIG_H
  • frontend/gui/ui/importcontacts/pages/contactfilesmodel.cpp

    r317 r320  
    2121namespace CFI {
    2222
    23 ContactFilesModel::ContactFilesModel(ContactFilesImporterDataManager *dataManager)
     23ContactFilesModel::ContactFilesModel(ContactFileList *contactFiles)
    2424    : QAbstractTableModel()
    25     , m_dataManager(dataManager)
     25    , m_contactFiles(contactFiles)
    2626{
    27     connect(m_dataManager, SIGNAL(dataChanged()), this, SLOT(onDataChanged()));
     27    connect(m_contactFiles, SIGNAL(dataChanged()), this, SLOT(onDataChanged()));
    2828}
    2929
     
    4444
    4545QString ContactFilesModel::dataObject(const QModelIndex& index) const {
    46     if (!index.isValid() || (index.row() >= m_dataManager->selectionMap().size())) {
     46    if (!index.isValid() || (index.row() >= m_contactFiles->selectionMap().size())) {
    4747        return NULL;
    4848    } else {
    49         return m_dataManager->selectionMap().keys().at(index.row());
     49        return m_contactFiles->selectionMap().keys().at(index.row());
    5050    }
    5151}
    5252
    5353QVariant ContactFilesModel::data(const QModelIndex& index, int role) const {
    54     if (!index.isValid() || index.row() < 0 || index.row() >= m_dataManager->selectionMap().size())
     54    if (!index.isValid() || index.row() < 0 || index.row() >= m_contactFiles->selectionMap().size())
    5555        return QVariant();
    5656
    5757
    5858    if (role == Qt::DisplayRole) {
    59         QString filename = m_dataManager->selectionMap().keys().at(index.row());
     59        QString filename = m_contactFiles->selectionMap().keys().at(index.row());
    6060
    6161        switch (index.column()) {
     
    6767    }
    6868    if (role == Qt::CheckStateRole) {
    69         bool checked = m_dataManager->selectionMap().values().at(index.row());
     69        bool checked = m_contactFiles->selectionMap().values().at(index.row());
    7070
    7171        switch (index.column()) {
     
    8888
    8989            const Qt::CheckState cs = static_cast<Qt::CheckState>(value.toInt());
    90             m_dataManager->setContactFileSelected(filename, cs == Qt::Checked);
     90            m_contactFiles->setContactFileSelected(filename, cs == Qt::Checked);
    9191            return true;
    9292        }
     
    111111
    112112int ContactFilesModel::rowCount(const QModelIndex& parent) const {
    113     return (parent.isValid()) ? 0 : m_dataManager->selectionMap().size();
     113    return (parent.isValid()) ? 0 : m_contactFiles->selectionMap().size();
    114114}
    115115
  • frontend/gui/ui/importcontacts/pages/contactfilesmodel.h

    r319 r320  
    1616 along with this program.  If not, see <http://www.gnu.org/licenses/>.
    1717 */
    18 #ifndef FRONTEND_GUI_UI_IMPORTCONTACTS_IMPORTERPAGES_CONTACTFILESMODEL_H
    19 #define FRONTEND_GUI_UI_IMPORTCONTACTS_IMPORTERPAGES_CONTACTFILESMODEL_H
     18#ifndef FRONTEND_GUI_UI_IMPORTCONTACTS_PAGES_CONTACTFILESMODEL_H
     19#define FRONTEND_GUI_UI_IMPORTCONTACTS_PAGES_CONTACTFILESMODEL_H
    2020
    2121#include <QAbstractTableModel>
     
    2323#include <QString>
    2424
    25 #include "frontend/business/contactimporter/contactfilesimporter.h"
     25#include "frontend/business/contactimporter/contactfilelist.h"
    2626
    2727namespace UI {
     
    3939    };
    4040
    41     explicit ContactFilesModel(ContactFilesImporterDataManager *m_dataManager);
     41    explicit ContactFilesModel(ContactFileList *contactFiles);
    4242
    4343public: /* QAbstractTableModel */
     
    5555
    5656private:
    57     ContactFilesImporterDataManager * const m_dataManager;
     57    ContactFileList * const m_contactFiles;
    5858};
    5959
     
    6161} // namespace UI
    6262
    63 #endif /* FRONTEND_GUI_UI_IMPORTCONTACTS_IMPORTERPAGES_CONTACTFILESMODEL_H */
     63#endif /* FRONTEND_GUI_UI_IMPORTCONTACTS_PAGES_CONTACTFILESMODEL_H */
  • frontend/gui/ui/importcontacts/pages/google_page_config.cpp

    r317 r320  
    2121namespace GCI {
    2222
    23 PageConfig::PageConfig(QWidget* parent)
    24     : QWizardPage(parent)
     23PageConfig::PageConfig(BaseGoogleContactImporter::AuthData *authData)
     24    : QWizardPage()
     25    , m_authData(authData)
    2526{
    2627        ui.setupUi(this);
    2728
    2829    connect(ui.edtUsername, SIGNAL(textChanged(const QString&)),
    29             this, SIGNAL(completeChanged()));
     30            this, SLOT(dataChanged()));
    3031    connect(ui.edtPassword, SIGNAL(textChanged(const QString&)),
    31             this, SIGNAL(completeChanged()));
     32            this, SLOT(dataChanged()));
    3233}
    3334
    34 QString PageConfig::username() const {
    35     return ui.edtUsername->text();
    36 }
    37 QString PageConfig::password() const {
    38     return ui.edtPassword->text();
     35void PageConfig::dataChanged() {
     36    m_authData->username = ui.edtUsername->text();
     37    m_authData->password = ui.edtPassword->text();
     38
     39    emit completeChanged();
    3940}
    4041
    41 
    4242bool PageConfig::isComplete() const {
    43     return !ui.edtUsername->text().isEmpty() && !ui.edtPassword->text().isEmpty();
     43    return !ui.edtUsername->text().isEmpty() &&
     44           !ui.edtPassword->text().isEmpty();
    4445}
    4546
  • frontend/gui/ui/importcontacts/pages/google_page_config.h

    r319 r320  
    1616 along with this program.  If not, see <http://www.gnu.org/licenses/>.
    1717 */
    18 #ifndef FRONTEND_GUI_UI_IMPORTCONTACTS_IMPORTERPAGES_GOOGLE_PAGE_CONFIG_H
    19 #define FRONTEND_GUI_UI_IMPORTCONTACTS_IMPORTERPAGES_GOOGLE_PAGE_CONFIG_H
     18#ifndef FRONTEND_GUI_UI_IMPORTCONTACTS_PAGES_GOOGLE_PAGE_CONFIG_H
     19#define FRONTEND_GUI_UI_IMPORTCONTACTS_PAGES_GOOGLE_PAGE_CONFIG_H
    2020
    2121#include "ui_google_page_config.h"
    2222
    2323#include <QWizardPage>
     24
     25#include "frontend/business/contactimporter/googlecontactimporter.h"
    2426
    2527namespace UI {
     
    3032
    3133public:
    32     PageConfig(QWidget* parent);
    33 
    34     QString username() const;
    35     QString password() const;
     34    explicit PageConfig(GoogleContactImporter::AuthData *authData);
    3635
    3736public: /* QWizardPage */
    38     bool    isComplete() const;
     37    bool isComplete() const;
     38
     39private slots:
     40    void dataChanged();
    3941
    4042private:
    4143    ::GCI::Ui::PageConfigClass ui;
     44
     45    GoogleContactImporter::AuthData * const m_authData;
    4246};
    4347
     
    4549} // namespace UI
    4650
    47 #endif // FRONTEND_GUI_UI_IMPORTCONTACTS_IMPORTERPAGES_GOOGLE_PAGE_CONFIG_H
     51#endif // FRONTEND_GUI_UI_IMPORTCONTACTS_PAGES_GOOGLE_PAGE_CONFIG_H
  • gateways/Schoolnet/business/account.h

    r319 r320  
    3636
    3737    friend class AccountLoginTask; // reloadOnlineParams(), httpHelper()
    38     friend class BaseContactImporter; // httpHelper()
     38//    friend class ContactImporter::Builder; // httpHelper()
    3939    friend class SMSSendTask; // reloadOnlineParams(), httpHelper()
    4040
    41     friend class DeepThought::AnswerToSchoolnetTask; // httpHelper()
    42     friend class DeepThought::CheckQuestionStatusAtSchoolnetTask; // httpHelper()
     41    friend class DeepThought::AnswerToSchoolnetTask; // reloadOnlineParams(), httpHelper()
     42//    friend class DeepThought::CheckQuestionStatusAtSchoolnetTask; // httpHelper()
    4343
    4444public:
     
    7777    void setDeepThoughtQuestionLanguages(const QStringList& languages);
    7878
     79    HttpHelper *httpHelper() const;
     80
    7981protected:
    8082    IAccountInitTask *doCreateInitTask();
     
    9092    void fetchFreeSMSCount(const QString& html);
    9193    bool tryFetchFreeSMSCount(const QString& html);
    92 
    93     HttpHelper *httpHelper() const;
    9494
    9595private slots:
  • gateways/Schoolnet/business/contactimporter/contactimporter.cpp

    r316 r320  
    1616 along with this program.  If not, see <http://www.gnu.org/licenses/>.
    1717 */
    18 #include "contactimporter_base.h"
     18#include "contactimporter.h"
    1919#include "contactimporter_p.h"
    2020
     
    2929namespace Schoolnet {
    3030
    31 const QString BaseContactImporter::URL_CONTACT_LIST = "http://www.schoolnet.ch/schoolnet/AddressBookSchoolnet/AddressbookDetails.aspx?culture=de-CH";
     31const QString ContactImporter::URL_CONTACT_LIST =
     32        "http://www.schoolnet.ch/schoolnet/AddressBookSchoolnet/AddressbookDetails.aspx?culture=de-CH";
    3233
    33 BaseContactImporter::BaseContactImporter(IAccountIntegrationHelper *accountHelper)
    34     : m_dataManager(new ContactImporterDataManager)
    35     , m_accountHelper(accountHelper)
     34ContactImporter::ContactImporter(HttpHelper *httpHelper)
     35    : m_httpHelper(httpHelper)
    3636{
    3737}
    38 BaseContactImporter::~BaseContactImporter() {
     38
     39void ContactImporter::importContacts(QSet<SContact*> *contacts) {
     40    /* Get the first page */
     41    QString html = QString::fromUtf8(m_httpHelper->syncGet(URL_CONTACT_LIST));
     42
     43    QStringList processedContacts;
     44    bool continueProcessing = true;
     45    while (continueProcessing) {
     46        // Only the addressbook table is of interest
     47        QRegExp rx("<table.*id=\"dgAddressbook\".*>(.*)</table>");
     48        rx.setMinimal(true);
     49        rx.setCaseSensitivity(Qt::CaseInsensitive);
     50
     51        if (rx.indexIn(html) == -1) {
     52            qWarning("No address book data could be found.");
     53            break;
     54        }
     55        QString addressBookData = rx.cap(1);
     56
     57        // Read the contacts
     58        rx.setPattern("<tr class=\"(?:schoolnetAppABItem|schoolnetAppABAlternative)\".*>.*"
     59                      "<td.*>.*</td>\\s*"
     60                      "<td.*>\\s*<input type=\"image\".*src=\"([^\"]+)\".*/>\\s*</td>\\s*" // img
     61                      "<td.*>.*</td>\\s*"
     62                      "<td.*>(.*)</td>\\s*" // name
     63                      "<td.*>(.*)</td>\\s*" // phone no
     64                      "<td.*>.*</td>\\s*"
     65                      "<td.*>.*</td>\\s*"
     66                      "</tr>");
     67        int pos = 0;
     68        while ((pos = rx.indexIn(addressBookData, pos)) != -1) {
     69            QString name = rx.cap(2);
     70            if (processedContacts.contains(name)) {
     71                continueProcessing = false;
     72                break;
     73            }
     74            processedContacts.append(name);
     75
     76            QScopedPointer<SContact> contact(new SContact);
     77            contact->setName(name);
     78
     79#ifdef FRONTEND_GUI
     80            QString imgAddr = rx.cap(1);
     81            if (imgAddr != "../images/anonymous.gif") {
     82                QImage img = QImage::fromData(m_httpHelper->syncGet(imgAddr));
     83                contact->setImage(img);
     84            }
     85#endif
     86
     87            contact->setNumber(SNumber(rx.cap(3), "'+'ccaa' 'u"));
     88            contacts->insert(contact.take());
     89
     90            pos += rx.matchedLength();
     91        }
     92
     93        // Load next page
     94        if (continueProcessing) {
     95            QList<IParam*> posts;
     96            posts.append(new SKeyValueParam("__EVENTTARGET", ""));
     97            posts.append(new SKeyValueParam("__EVENTARGUMENT", ""));
     98            posts.append(new SKeyValueParam("btnNext", ">>"));
     99
     100            rx.setPattern("<input.*name=\"__VIEWSTATE\".*value=\"(.*)\".*/?>");
     101            if (rx.indexIn(html) == -1) {
     102                EException("Could not get the viewstate.")
     103                        .raise();
     104            }
     105            posts.append(new SKeyValueParam("__VIEWSTATE", rx.cap(1).toUtf8()));
     106
     107            html = QString::fromUtf8(m_httpHelper->syncPost(URL_CONTACT_LIST, posts));
     108        }
     109    }
    39110}
    40111
    41 QString BaseContactImporter::describingName() const {
     112/********************************** Builder ***********************************/
     113
     114ContactImporter::Builder::Builder(IAccountIntegrationHelper *accountHelper)
     115    : m_accountHelper(accountHelper)
     116{
     117}
     118
     119QString ContactImporter::Builder::description() const {
    42120    if (isApplicable()) {
    43121        return QObject::tr("Import contacts from the Schoolnet website.");
     
    47125}
    48126
    49 bool BaseContactImporter::isApplicable() const {
     127bool ContactImporter::Builder::isApplicable() const {
    50128    return m_accountHelper->hasLoggedInAccounts();
    51129}
    52130
     131void ContactImporter::Builder::createImporters(QSet<IContactImporter *> *importers) {
     132    foreach (IAccount *iaccount, m_accountHelper->loggedInAccounts()) {
     133        Account *account = static_cast<Account*>(iaccount);
    53134
    54 void BaseContactImporter::init() {
    55     const QSet<IAccount*> &loggedInIAccounts = m_accountHelper->loggedInAccounts();
    56 
    57     const QSet<Account*> &loggedInAccounts = reinterpret_cast<const QSet<Account*> &>(loggedInIAccounts);
    58     m_dataManager->setSelectedAccounts(loggedInAccounts);
    59 }
    60 void BaseContactImporter::importContacts(QSet<SContact*> *contacts) {
    61     QString html;
    62     foreach (Account *account, m_dataManager->selectedAccounts()) {
    63         if (!account->isLoggedIn()) continue;
    64 
    65         /* Get the first page */
    66         html = QString::fromUtf8(account->httpHelper()->syncGet(URL_CONTACT_LIST));
    67 
    68         QStringList processedContacts;
    69         bool continueProcessing = true;
    70         while (continueProcessing) {
    71             // Only the addressbook table is of interest
    72             QRegExp rx("<table.*id=\"dgAddressbook\".*>(.*)</table>");
    73             rx.setMinimal(true);
    74             rx.setCaseSensitivity(Qt::CaseInsensitive);
    75 
    76             if (rx.indexIn(html) == -1) {
    77                 qWarning("No address book data could be found.");
    78                 break;
    79             }
    80             QString addressBookData = rx.cap(1);
    81 
    82             // Read the contacts
    83             rx.setPattern("<tr class=\"(?:schoolnetAppABItem|schoolnetAppABAlternative)\".*>.*"
    84                                 "<td.*>.*</td>\\s*"
    85                                 "<td.*>\\s*<input type=\"image\".*src=\"([^\"]+)\".*/>\\s*</td>\\s*" // img
    86                                 "<td.*>.*</td>\\s*"
    87                                 "<td.*>(.*)</td>\\s*" // name
    88                                 "<td.*>(.*)</td>\\s*" // phone no
    89                                 "<td.*>.*</td>\\s*"
    90                                 "<td.*>.*</td>\\s*"
    91                           "</tr>");
    92             int pos = 0;
    93             while ((pos = rx.indexIn(addressBookData, pos)) != -1) {
    94                 QString name = rx.cap(2);
    95                 if (processedContacts.contains(name)) {
    96                     continueProcessing = false;
    97                     break;
    98                 }
    99                 processedContacts.append(name);
    100 
    101                 QScopedPointer<SContact> contact(new SContact);
    102                 contact->setName(name);
    103 
    104 #ifdef FRONTEND_GUI
    105                 QString imgAddr = rx.cap(1);
    106                 if (imgAddr != "../images/anonymous.gif") {
    107                     QImage img = QImage::fromData(account->httpHelper()->syncGet(imgAddr));
    108                     contact->setImage(img);
    109                 }
    110 #endif
    111 
    112                 contact->setNumber(SNumber(rx.cap(3), "'+'ccaa' 'u"));
    113                 contacts->insert(contact.take());
    114 
    115                 pos += rx.matchedLength();
    116             }
    117 
    118             // Load next page
    119             if (continueProcessing) {
    120                 QList<IParam*> posts;
    121                 posts.append(new SKeyValueParam("__EVENTTARGET", ""));
    122                 posts.append(new SKeyValueParam("__EVENTARGUMENT", ""));
    123                 posts.append(new SKeyValueParam("btnNext", ">>"));
    124 
    125                 rx.setPattern("<input.*name=\"__VIEWSTATE\".*value=\"(.*)\".*/?>");
    126                 if (rx.indexIn(html) == -1) {
    127                     EException("Could not get the viewstate.")
    128                             .raise();
    129                 }
    130                 posts.append(new SKeyValueParam("__VIEWSTATE", rx.cap(1).toUtf8()));
    131 
    132                 html = QString::fromUtf8(account->httpHelper()->syncPost(URL_CONTACT_LIST, posts));
    133             }
    134         }
    135      }
     135        importers->insert(new ContactImporter(account->httpHelper()));
     136    }
    136137}
    137138
  • gateways/Schoolnet/business/contactimporter/contactimporter.h

    r319 r320  
    1616 along with this program.  If not, see <http://www.gnu.org/licenses/>.
    1717 */
    18 #ifndef SCHOOLNET_CONTACTIMPORTER_CONTACTIMPORTER_BASE_H
    19 #define SCHOOLNET_CONTACTIMPORTER_CONTACTIMPORTER_BASE_H
     18#ifndef SCHOOLNET_CONTACTIMPORTER_CONTACTIMPORTER_H
     19#define SCHOOLNET_CONTACTIMPORTER_CONTACTIMPORTER_H
    2020
    2121#include <QScopedPointer>
     
    2424#include "common/business/iintegration.h"
    2525#include "common/domain/scontact.h"
     26#include "gateways/Schoolnet/business/account.h"
    2627
    2728namespace Schoolnet {
    2829
    29 class ContactImporterDataManager;
    30 
    31 class BaseContactImporter : public IContactImporter {
     30class ContactImporter : public IContactImporter {
    3231public:
    33     explicit BaseContactImporter(IAccountIntegrationHelper *accountHelper);
    34     ~BaseContactImporter();
     32    explicit ContactImporter(HttpHelper *httpHelper);
    3533
    3634public: /* IContactImporter */
    37     QString describingName() const;
    38     bool isApplicable() const;
     35    void importContacts(QSet<SContact *> *contacts);
    3936
    40     void init();
    41     void importContacts(QSet<SContact *> *contacts);
     37
     38    class Builder : public IContactImporter::Builder {
     39    public:
     40        explicit Builder(IAccountIntegrationHelper *accountHelper);
     41
     42    public: /* IContactImporter::Builder */
     43        QString description() const;
     44        bool isApplicable() const;
     45
     46        void createImporters(QSet<IContactImporter *> *importers);
     47
     48    private:
     49        IAccountIntegrationHelper *m_accountHelper;
     50
     51        Q_DISABLE_COPY(Builder)
     52    };
    4253
    4354private:
    4455    static const QString URL_CONTACT_LIST;
    4556
    46 private:
    47     QScopedPointer<ContactImporterDataManager> m_dataManager;
    48     IAccountIntegrationHelper * const m_accountHelper;
     57    HttpHelper * const m_httpHelper;
     58
     59    Q_DISABLE_COPY(ContactImporter)
    4960};
    5061
    5162}
    5263
    53 #endif /* SCHOOLNET_CONTACTIMPORTER_CONTACTIMPORTER_BASE_H */
     64#endif /* SCHOOLNET_CONTACTIMPORTER_CONTACTIMPORTER_H */
  • gateways/Schoolnet/gui/schoolnet-gui.pro

    r318 r320  
    2424    ui/questionlistintegration.h \
    2525    ui/senddialogintegration.h \
    26     business/contactimporter.h \
    2726    ui/senddialogintegration_p.h \
    2827    schoolnet.h
     
    3736    ui/questionlistintegration.cpp \
    3837    ui/senddialogintegration.cpp \
    39     business/contactimporter.cpp \
    4038    business/gateway.cpp \
    4139    schoolnet.cpp
  • gateways/Schoolnet/gui/schoolnet.cpp

    r316 r320  
    2222
    2323#include "common/domain/sversion.h"
     24#include "gateways/Schoolnet/business/contactimporter/contactimporter.h"
    2425#include "gateways/Schoolnet/business/deepthought/deepthoughthelper.h"
    2526#include "gateways/Schoolnet/business/gateway.h"
    26 #include "gateways/Schoolnet/gui/business/contactimporter.h"
    2727
    2828namespace Schoolnet {
     
    3131}
    3232
    33 bool Library::doInit(const IBaseIntegrationHelper::Factory &integrationHelperFactory, QSet<QTranslator*> *translators, IGateway **gateway,
    34                      QSet<IContactImporter*> *contactImporters)
     33bool Library::doInit(
     34        const IBaseIntegrationHelper::Factory &integrationHelperFactory,
     35        QSet<QTranslator*> *translators, IGateway **gateway,
     36        QSet<IContactImporter::Builder *> *contactImporters)
    3537{
    3638    // Translators
     
    4648
    4749    // Contact importer
    48     contactImporters->insert(new ContactImporter(m_integrationHelper->accountHelper()));
     50    contactImporters->insert(new ContactImporter::Builder(
     51                                 m_integrationHelper->accountHelper()));
    4952
    5053    // Initialize DeepThought
  • gateways/Schoolnet/gui/schoolnet.h

    r319 r320  
    4040    bool doInit(const IIntegrationHelper::Factory &integrationHelperFactory,
    4141                QSet<QTranslator*> *translators, IGateway **gateway,
    42                 QSet<IContactImporter*> *contactImporters);
     42                QSet<IContactImporter::Builder *> *contactImporters);
    4343
    4444private:
  • gateways/Schoolnet/schoolnet-base.pro

    r318 r320  
    2020    business/deepthought/deepthoughthelper.h \
    2121    business/deepthought/questionmanager.h \
    22     business/contactimporter/contactimporter_p.h \
    2322    network/httphelper.h \
    2423    business/account_tasks.h \
     
    2726    persistence/accountstoragehelper.h \
    2827    business/account.h \
    29     business/contactimporter/contactimporter_base.h \
    3028    business/deepthought/daemons.h \
    31     business/deepthought/tasks.h
     29    business/deepthought/tasks.h \
     30    business/contactimporter/contactimporter.h
    3231SOURCES += \
    3332    business/deepthought/datatypes.cpp \
     
    4241    persistence/accountstoragehelper.cpp \
    4342    business/account.cpp \
    44     business/contactimporter/contactimporter_base.cpp \
    4543    business/deepthought/daemon_deepthought.cpp \
    4644    business/deepthought/daemon_schoolnet.cpp \
     
    4846    business/deepthought/task_answertoschoolnet.cpp \
    4947    business/deepthought/task_check_questionstatus_at_schoolnet.cpp \
    50     business/deepthought/task_fetchdatafromdeepthought.cpp
     48    business/deepthought/task_fetchdatafromdeepthought.cpp \
     49    business/contactimporter/contactimporter.cpp
    5150RESOURCES += lib/schoolnet.qrc
  • gateways/common/business/baselibrary.cpp

    r315 r320  
    3737    return m_translators;
    3838}
    39 QSet<IContactImporter*> BaseLibrary::contactImporters() const {
     39QSet<IContactImporter::Builder *> BaseLibrary::contactImporters() const {
    4040    return m_contactImporters;
    4141}
  • gateways/common/business/baselibrary.h

    r319 r320  
    11/*
    22 smssender - A frontend for fast and easy SMS sending over different gateways.
    3  Copyright (C) 2007-2012, gorrión. See http://smssender.gorrion.ch
     3 Copyright (C) 2007-2014, gorrión. See http://smssender.gorrion.ch
    44
    55 This program is free software: you can redistribute it and/or modify
     
    4848    virtual bool init(const IIntegrationHelper::Factory &integrationHelperFactory);
    4949
    50     virtual QSet<QTranslator*> translators() const;
    51     virtual QSet<IContactImporter*> contactImporters() const;
     50    virtual QSet<QTranslator *> translators() const;
     51    virtual QSet<IContactImporter::Builder *> contactImporters() const;
    5252    virtual IGateway *gateway() const;
    5353
     
    6767    virtual bool doInit(const IIntegrationHelper::Factory &integrationHelperFactory,
    6868                        QSet<QTranslator*> *translators, IGateway **gateways,
    69                         QSet<IContactImporter*> *contactImporters) =0;
     69                        QSet<IContactImporter::Builder *> *contactImporters) =0;
    7070
    7171private:
    72     QSet<QTranslator*> m_translators;
     72    QSet<QTranslator *> m_translators;
    7373    QScopedPointer<IGateway> m_gateway;
    74     QSet<IContactImporter*> m_contactImporters;
     74    QSet<IContactImporter::Builder *> m_contactImporters;
    7575};
    7676
Note: See TracChangeset for help on using the changeset viewer.