Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'jb47389' into 'master'
Apply folder sync options before sync See merge request mer-core/nemo-qml-plugin-email!65
- Loading branch information
Showing
8 changed files
with
303 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
/* | ||
* Copyright (c) 2020 Jolla Ltd. | ||
* Copyright (c) 2020 Open Mobile Platform LLC. | ||
* | ||
* This program is licensed under the terms and conditions of the | ||
* Apache License, version 2.0. The full text of the Apache License is at | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
*/ | ||
|
||
#include <QTimerEvent> | ||
|
||
#include "folderlistfiltertypemodel.h" | ||
#include "folderlistmodel.h" | ||
|
||
FolderListFilterTypeModel::FolderListFilterTypeModel(QObject *parent) : | ||
QSortFilterProxyModel(parent), | ||
m_count(0), | ||
m_syncFolderList(), | ||
updateSyncFolderListTimer(-1) | ||
{ | ||
// Default to email folders | ||
m_typeFilter << EmailFolder::NormalFolder << EmailFolder::InboxFolder; | ||
|
||
m_folderModel = new FolderListModel(this); | ||
setSourceModel(m_folderModel); | ||
connect(m_folderModel, &FolderListModel::accountKeyChanged, this, &FolderListFilterTypeModel::accountKeyChanged); | ||
connect(m_folderModel, &FolderListModel::rowsInserted, this, &FolderListFilterTypeModel::updateData); | ||
connect(m_folderModel, &FolderListModel::rowsRemoved, this, &FolderListFilterTypeModel::updateData); | ||
connect(m_folderModel, &FolderListModel::dataChanged, this, &FolderListFilterTypeModel::updateData); | ||
connect(m_folderModel, &FolderListModel::rowsMoved, this, &FolderListFilterTypeModel::updateData); | ||
connect(m_folderModel, &FolderListModel::modelReset, this, &FolderListFilterTypeModel::updateData); | ||
} | ||
|
||
bool FolderListFilterTypeModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const | ||
{ | ||
Q_UNUSED(source_parent) | ||
|
||
if (sourceModel()) { | ||
EmailFolder::FolderType type = static_cast<EmailFolder::FolderType> | ||
(sourceModel()->index(source_row, 0).data(FolderListModel::FolderType).toInt()); | ||
return m_typeFilter.contains(type); | ||
} | ||
return false; | ||
} | ||
|
||
int FolderListFilterTypeModel::count() const | ||
{ | ||
return m_count; | ||
} | ||
|
||
void FolderListFilterTypeModel::updateData() | ||
{ | ||
if (m_count != rowCount()) { | ||
m_count = rowCount(); | ||
emit countChanged(); | ||
} | ||
|
||
if (updateSyncFolderListTimer != -1) { | ||
killTimer(updateSyncFolderListTimer); | ||
} | ||
// Avoid updating the sync folder list on every signal | ||
updateSyncFolderListTimer = startTimer(100); | ||
} | ||
|
||
void FolderListFilterTypeModel::timerEvent(QTimerEvent * event) | ||
{ | ||
if (event->timerId() == updateSyncFolderListTimer) { | ||
killTimer(updateSyncFolderListTimer); | ||
updateSyncFolderListTimer = -1; | ||
updateSyncFolderList(); | ||
} | ||
} | ||
|
||
void FolderListFilterTypeModel::updateSyncFolderList() | ||
{ | ||
QStringList syncFolderList; | ||
for (int i = 0; i < sourceModel()->rowCount(); ++i) { | ||
bool sync = sourceModel()->index(i, 0).data(FolderListModel::FolderSyncEnabled).toBool(); | ||
if (sync) { | ||
EmailFolder::FolderType type = static_cast<EmailFolder::FolderType> | ||
(sourceModel()->index(i, 0).data(FolderListModel::FolderType).toInt()); | ||
if (m_typeFilter.contains(type)) { | ||
QString name = sourceModel()->index(i, 0).data(FolderListModel::FolderName).toString(); | ||
syncFolderList += name; | ||
} | ||
} | ||
} | ||
|
||
if (m_syncFolderList != syncFolderList) { | ||
m_syncFolderList = syncFolderList; | ||
emit syncFolderListChanged(); | ||
} | ||
} | ||
|
||
void FolderListFilterTypeModel::setAccountKey(int id) | ||
{ | ||
m_folderModel->setAccountKey(id); | ||
} | ||
|
||
int FolderListFilterTypeModel::accountKey() const | ||
{ | ||
return m_folderModel->accountKey(); | ||
} | ||
|
||
const QStringList & FolderListFilterTypeModel::syncFolderList() const | ||
{ | ||
return m_syncFolderList; | ||
} | ||
|
||
QList<int> FolderListFilterTypeModel::typeFilter() const | ||
{ | ||
QList<int> types; | ||
|
||
for (EmailFolder::FolderType type : m_typeFilter) { | ||
types << type; | ||
} | ||
|
||
return types; | ||
} | ||
|
||
void FolderListFilterTypeModel::setTypeFilter(QList<int> typeFilter) | ||
{ | ||
QSet<EmailFolder::FolderType> types; | ||
for (int type : typeFilter) { | ||
types << static_cast<EmailFolder::FolderType>(type); | ||
} | ||
|
||
if (types != m_typeFilter) { | ||
m_typeFilter = types; | ||
|
||
emit typeFilterChanged(); | ||
invalidateFilter(); | ||
updateData(); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
* Copyright (c) 2020 Jolla Ltd. | ||
* Copyright (c) 2020 Open Mobile Platform LLC. | ||
* | ||
* This program is licensed under the terms and conditions of the | ||
* Apache License, version 2.0. The full text of the Apache License is at | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
*/ | ||
|
||
#ifndef FOLDERLISTFILTERTYPEMODEL_H | ||
#define FOLDERLISTFILTERTYPEMODEL_H | ||
|
||
#include <QSet> | ||
#include <QStringList> | ||
#include <QSortFilterProxyModel> | ||
|
||
#include <emailfolder.h> | ||
|
||
class FolderListModel; | ||
|
||
// Filters the folder list by type | ||
// By default shows only the email folders | ||
class Q_DECL_EXPORT FolderListFilterTypeModel : public QSortFilterProxyModel | ||
{ | ||
Q_OBJECT | ||
Q_PROPERTY(int count READ count NOTIFY countChanged) | ||
Q_PROPERTY(QStringList syncFolderList READ syncFolderList NOTIFY syncFolderListChanged) | ||
Q_PROPERTY(int accountKey READ accountKey WRITE setAccountKey NOTIFY accountKeyChanged FINAL) | ||
Q_PROPERTY(QList<int> typeFilter READ typeFilter WRITE setTypeFilter NOTIFY typeFilterChanged FINAL) | ||
|
||
public: | ||
explicit FolderListFilterTypeModel(QObject *parent = 0); | ||
|
||
virtual bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const override; | ||
|
||
void setAccountKey(int id); | ||
int accountKey() const; | ||
int count() const; | ||
const QStringList &syncFolderList() const; | ||
QList<int> typeFilter() const; | ||
void setTypeFilter(QList<int> typeFilter); | ||
|
||
signals: | ||
void accountKeyChanged(); | ||
void countChanged(); | ||
void syncFolderListChanged(); | ||
void typeFilterChanged(); | ||
|
||
private slots: | ||
void updateData(); | ||
|
||
protected: | ||
void timerEvent(QTimerEvent * event) override; | ||
|
||
private: | ||
void updateSyncFolderList(); | ||
|
||
private: | ||
int m_count; | ||
QStringList m_syncFolderList; | ||
FolderListModel *m_folderModel; | ||
QSet<EmailFolder::FolderType> m_typeFilter; | ||
int updateSyncFolderListTimer; | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.