コード例 #1
0
bool SeasideProxyModel::filterAcceptsRow(int source_row,
                                  const QModelIndex& source_parent) const
{
    // TODO: add communication history
    //if (!QSortFilterProxyModel::filterAcceptsRow(source_row, source_parent))
    //    return false;

    // TODO: it may be better to filter this in SeasidePeopleModel, instead
    // of constantly doing it on refilter.
    SeasidePeopleModel *model = static_cast<SeasidePeopleModel *>(sourceModel());
    SeasidePerson *person = model->personByRow(source_row);
    if (person->id() == model->manager()->selfContactId())
        return false;

    if (priv->filterType == FilterAll) {
        // TODO: this should not be here
        qDebug("fastscroll: emitting countChanged");
        emit const_cast<SeasideProxyModel*>(this)->countChanged();
        return true;
    }

    if (priv->filterType == FilterFavorites) {
        if (person->favorite()) {
            // TODO: this should not be here
            qDebug("fastscroll: emitting countChanged");
            emit const_cast<SeasideProxyModel*>(this)->countChanged();
            return true;
        }

        return false;
    } else {
        qWarning() << "[SeasideProxyModel] invalid filter type";
        return false;
    }
}
コード例 #2
0
QVariantMap SeasideProxyModel::get(int row) const
{
    // needed for SectionScroller.
    QVariantMap m;
    SeasidePerson *p = personByRow(row);
    m["sectionBucket"] = p->sectionBucket();
    return m;
}
コード例 #3
0
bool SeasideProxyModel::filterAcceptsRow(int source_row,
                                  const QModelIndex& source_parent) const
{
    // TODO: add communication history
    //if (!QSortFilterProxyModel::filterAcceptsRow(source_row, source_parent))
    //    return false;

    // TODO: it may be better to filter this in SeasidePeopleModel, instead
    // of constantly doing it on refilter.
    SeasidePeopleModel *model = static_cast<SeasidePeopleModel *>(sourceModel());
    SeasidePerson *person = model->personByRow(source_row);
    if (person->id() == model->manager()->selfContactId())
        return false;

    if (priv->searchPattern.length() > 0 ) {
        bool result = true;
        bool found = false;
        QStringList labelList = person->displayLabel().split(" ");
        QStringList filterList = priv->searchPattern.split(" ");
        int j = 0;
        for (int i = 0; i < filterList.size() && result != false; i++) {
            found = false;
            for (; j < labelList.size(); j++) {
                if (labelList.at(j).startsWith(filterList.at(i), Qt::CaseInsensitive)) {
                    found = true;
                    j++;
                    break;
                }
            }
            result = result && found;
        }

        if (result == false)
            return false;
    }

    if (priv->filterType == FilterAll) {
        // TODO: this should not be here
        qDebug("fastscroll: emitting countChanged");
        emit const_cast<SeasideProxyModel*>(this)->countChanged();
        return true;
    }

    if (priv->filterType == FilterFavorites) {
        if (person->favorite()) {
            // TODO: this should not be here
            qDebug("fastscroll: emitting countChanged");
            emit const_cast<SeasideProxyModel*>(this)->countChanged();
            return true;
        }
        return false;
    } else {
        qWarning() << "[SeasideProxyModel] invalid filter type";
        return false;
    }
}
コード例 #4
0
bool SeasideProxyModel::lessThan(const QModelIndex& left,
                          const QModelIndex& right) const
{
    SeasidePeopleModel *model = static_cast<SeasidePeopleModel *>(sourceModel());

    SeasidePerson *leftPerson = model->personByRow(left.row());
    SeasidePerson *rightPerson = model->personByRow(right.row());

    if (!leftPerson)
        return false;
    else if (!rightPerson)
        return true;

    return priv->localeHelper->isLessThan(leftPerson->displayLabel(),
                                          rightPerson->displayLabel());
}
コード例 #5
0
QString SeasidePeopleModel::exportContacts() const
{
    QVersitContactExporter exporter;

    QList<QContact> contacts;
    contacts.reserve(priv->contactIds.size());

    foreach (const QContactLocalId &contactId, priv->contactIds) {
        SeasidePerson *p = personById(contactId);

        if (p->id() == manager()->selfContactId())
            continue;

        contacts.append(p->contact());
    }

    if (!exporter.exportContacts(contacts)) {
        qWarning() << Q_FUNC_INFO << "Failed to export contacts: " << exporter.errorMap();
        return QString();
    }

    QFile
        vcard(QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation)
              + QDir::separator()
              + QDateTime::currentDateTime().toString("ss_mm_hh_dd_mm_yyyy")
              + ".vcf");

    if (!vcard.open(QIODevice::WriteOnly)) {
        qWarning() << "Cannot open " << vcard.fileName();
        return QString();
    }

    QVersitWriter writer(&vcard);
    if (!writer.startWriting(exporter.documents())) {
        qWarning() << Q_FUNC_INFO << "Can't start writing vcards " << writer.error();
        return QString();
    }

    // TODO: thread
    writer.waitForFinished();
    return vcard.fileName();
}
コード例 #6
0
QVariant SeasidePeopleModel::data(const QModelIndex& index, int role) const
{
    SeasidePerson *aperson = personByRow(index.row());
    if (!aperson)
        return QVariant();

    switch (role) {
        case Qt::DisplayRole:
            return aperson->displayLabel();
        case FirstNameRole:
            return aperson->firstName();
        case LastNameRole:
            return aperson->lastName();
        case SectionBucketRole:
            return aperson->sectionBucket();
        case PersonRole:
            return QVariant::fromValue<SeasidePerson *>(aperson);
        default:
            return QVariant();
    }
}