Пример #1
0
QString SerializerPluginSugarAccount::extractGid(const Item &item) const
{
    if (item.hasPayload<SugarAccount>()) {
        const SugarAccount sugarAccount = item.payload<SugarAccount>();
        return sugarAccount.id();
    }
    return QString();
}
Пример #2
0
QString AccountDataExtractor::idForItem(const Akonadi::Item &item) const
{
    if (item.hasPayload<SugarAccount>()) {
        const SugarAccount account = item.payload<SugarAccount>();
        return account.id();
    }
    return QString();
}
Пример #3
0
static bool accountMatchesFilter(const SugarAccount &account, const QString &filter)
{
    if (account.name().contains(filter, Qt::CaseInsensitive)) {
        return true;
    }
    if (account.billingAddressCity().contains(filter, Qt::CaseInsensitive) ||
            account.shippingAddressCity().contains(filter, Qt::CaseInsensitive) ||
            account.billingAddressStreet().contains(filter, Qt::CaseInsensitive) ||
            account.shippingAddressStreet().contains(filter, Qt::CaseInsensitive)) {
        return true;
    }
    if (account.email1().contains(filter, Qt::CaseInsensitive)) {
        return true;
    }
    if (account.billingAddressCountry().contains(filter, Qt::CaseInsensitive)) {
        return true;
    }
    if (account.phoneOffice().contains(filter, Qt::CaseInsensitive)) {
        return true;
    }
    if (account.postalCodeForGui().contains(filter, Qt::CaseInsensitive)) {
        return true;
    }
    return false;
}
Пример #4
0
bool ContactsImporter::importFile(const QString &fileName)
{
    QFile file(fileName);
    if (!file.open(QIODevice::ReadOnly))
        return false;

    QCsvStandardBuilder builder;
    QCsvReader reader(&builder);
    reader.setDelimiter(QLatin1Char(','));
    reader.setTextCodec(QTextCodec::codecForName("utf-8"));
    if (!reader.read(&file))
        return false;

    QMap<int, QString> accountColumns;
    accountColumns.insert(5, KDCRMFields::name());
    accountColumns.insert(6, KDCRMFields::billingAddressStreet());
    accountColumns.insert(7, KDCRMFields::billingAddressCity());
    accountColumns.insert(8, KDCRMFields::billingAddressPostalcode());
    accountColumns.insert(9, KDCRMFields::billingAddressState());
    accountColumns.insert(10, KDCRMFields::billingAddressCountry());

    const int rows = builder.rowCount();
    mAccounts.reserve(rows);
    for (int row = 1; row < rows; ++row) { // skip title row
        QMap<QString, QString> accountData;
        QMap<int, QString>::const_iterator it = accountColumns.constBegin();
        for ( ; it != accountColumns.end() ; ++it) {
            const QString value = builder.data(row, it.key());
            //qDebug() << it.key() << value << "->" << it.value();
            if (!value.isEmpty()) {
                accountData.insert(it.value(), value);
            }
        }
        SugarAccount account;
        account.setData(accountData);
        // Fast-path duplicate filtering, more will happen later
        if (!mAccounts.isEmpty() && mAccounts.at(0).isSameAccount(account))
            continue;
        mAccounts.append(account);
    }

    return true;
}
Пример #5
0
 void testImportingAccounts()
 {
     ContactsImporter importer;
     QTemporaryFile file;
     writeTempFile(file,
     "David,Faure,Mr,12345,[email protected],KDAB,\"32, street name\",Vedène,84000,,France,FR 12345");
     QVERIFY(importer.importFile(file.fileName()));
     const QVector<SugarAccount> accounts = importer.accounts();
     QCOMPARE(accounts.size(), 1);
     const SugarAccount account = accounts.at(0);
     QCOMPARE(account.name(), QString("KDAB"));
     QCOMPARE(account.billingAddressStreet(), QString::fromUtf8("32, street name"));
     QCOMPARE(account.billingAddressCity(), QString::fromUtf8("Vedène"));
     QCOMPARE(account.billingAddressCountry(), QString::fromUtf8("France"));
     QCOMPARE(account.billingAddressPostalcode(), QString::fromUtf8("84000"));
     QCOMPARE(account.billingAddressState(), QString());
 }
Пример #6
0
// The rule is: one account of a given name, in a given city.
// E.g. HP (city: Barcelona) != HP (city: Chicago) != HP (city: London)
bool SugarAccount::isSameAccount(const SugarAccount &other) const
{
    if (!d->mId.isEmpty() && !other.d->mId.isEmpty() && d->mId != other.d->mId) {
        return false;
    }

    if (cleanAccountName() != other.cleanAccountName()) {
        return false;
    }

    if (d->mBillingAddressCountry != other.d->mBillingAddressCountry) {
        return false;
    }

    if (d->mBillingAddressCity != other.d->mBillingAddressCity) {
        return false;
    }

    return true;
}