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; } }
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; } }
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(); }