2013-07-04 21:59:40 +04:00
|
|
|
/*
|
|
|
|
* Copyright (C) by Klaas Freitag <freitag@kde.org>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
|
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* for more details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef FOLDERSTATUSMODEL_H
|
|
|
|
#define FOLDERSTATUSMODEL_H
|
|
|
|
|
2015-03-27 13:46:03 +03:00
|
|
|
#include <accountfwd.h>
|
2015-06-15 15:16:21 +03:00
|
|
|
#include <QAbstractItemModel>
|
2017-05-09 15:24:11 +03:00
|
|
|
#include <QLoggingCategory>
|
2015-06-16 13:14:04 +03:00
|
|
|
#include <QVector>
|
2015-10-13 15:10:52 +03:00
|
|
|
#include <QElapsedTimer>
|
2018-03-27 13:17:29 +03:00
|
|
|
#include <QPointer>
|
2015-03-27 13:46:03 +03:00
|
|
|
|
2015-06-02 21:15:16 +03:00
|
|
|
class QNetworkReply;
|
2014-11-10 00:34:07 +03:00
|
|
|
namespace OCC {
|
2013-07-04 21:59:40 +04:00
|
|
|
|
2017-05-09 15:24:11 +03:00
|
|
|
Q_DECLARE_LOGGING_CATEGORY(lcFolderStatus)
|
|
|
|
|
2015-03-27 13:46:03 +03:00
|
|
|
class Folder;
|
2015-06-02 20:45:23 +03:00
|
|
|
class ProgressInfo;
|
2018-03-27 13:17:29 +03:00
|
|
|
class LsColJob;
|
2015-03-27 13:46:03 +03:00
|
|
|
|
2015-06-29 19:56:09 +03:00
|
|
|
/**
|
|
|
|
* @brief The FolderStatusModel class
|
|
|
|
* @ingroup gui
|
2015-06-26 18:07:47 +03:00
|
|
|
*/
|
2015-03-27 13:46:03 +03:00
|
|
|
class FolderStatusModel : public QAbstractItemModel
|
2013-07-04 21:59:40 +04:00
|
|
|
{
|
2015-03-27 13:46:03 +03:00
|
|
|
Q_OBJECT
|
2013-07-04 21:59:40 +04:00
|
|
|
public:
|
2017-08-25 15:12:27 +03:00
|
|
|
enum {FileIdRole = Qt::UserRole+1};
|
|
|
|
|
2018-11-11 12:56:22 +03:00
|
|
|
FolderStatusModel(QObject *parent = nullptr);
|
2021-08-17 13:39:31 +03:00
|
|
|
~FolderStatusModel() override;
|
2017-05-17 11:55:42 +03:00
|
|
|
void setAccountState(const AccountState *accountState);
|
2015-03-27 13:46:03 +03:00
|
|
|
|
2022-09-30 20:12:08 +03:00
|
|
|
[[nodiscard]] Qt::ItemFlags flags(const QModelIndex &) const override;
|
|
|
|
[[nodiscard]] QVariant data(const QModelIndex &index, int role) const override;
|
2018-11-11 13:09:29 +03:00
|
|
|
bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
|
2022-09-30 20:12:08 +03:00
|
|
|
[[nodiscard]] int columnCount(const QModelIndex &parent = QModelIndex()) const override;
|
|
|
|
[[nodiscard]] int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
|
|
|
[[nodiscard]] QModelIndex index(int row, int column = 0, const QModelIndex &parent = QModelIndex()) const override;
|
|
|
|
[[nodiscard]] QModelIndex parent(const QModelIndex &child) const override;
|
|
|
|
[[nodiscard]] bool canFetchMore(const QModelIndex &parent) const override;
|
2018-11-11 13:09:29 +03:00
|
|
|
void fetchMore(const QModelIndex &parent) override;
|
2020-02-04 17:35:14 +03:00
|
|
|
void resetAndFetch(const QModelIndex &parent);
|
2022-09-30 20:12:08 +03:00
|
|
|
[[nodiscard]] bool hasChildren(const QModelIndex &parent = QModelIndex()) const override;
|
2017-05-17 11:55:42 +03:00
|
|
|
|
|
|
|
struct SubFolderInfo
|
|
|
|
{
|
2020-05-21 02:43:34 +03:00
|
|
|
Folder *_folder = nullptr;
|
2021-01-29 21:00:21 +03:00
|
|
|
QString _name; // Folder name to be displayed in the UI
|
|
|
|
QString _path; // Sub-folder path that should always point to a local filesystem's folder
|
|
|
|
QString _e2eMangledName; // Mangled name that needs to be used when making fetch requests and should not be used for displaying in the UI
|
2015-03-27 13:46:03 +03:00
|
|
|
QVector<int> _pathIdx;
|
2015-06-11 16:46:01 +03:00
|
|
|
QVector<SubFolderInfo> _subs;
|
2020-05-21 02:43:34 +03:00
|
|
|
qint64 _size = 0;
|
|
|
|
bool _isExternal = false;
|
2020-12-07 21:12:21 +03:00
|
|
|
bool _isEncrypted = false;
|
2015-10-13 15:10:52 +03:00
|
|
|
|
2020-05-21 02:43:34 +03:00
|
|
|
bool _fetched = false; // If we did the LSCOL for this folder already
|
2018-03-27 13:17:29 +03:00
|
|
|
QPointer<LsColJob> _fetchingJob; // Currently running LsColJob
|
2020-05-21 02:43:34 +03:00
|
|
|
bool _hasError = false; // If the last fetching job ended in an error
|
2016-09-06 12:11:03 +03:00
|
|
|
QString _lastErrorString;
|
2020-05-21 02:43:34 +03:00
|
|
|
bool _fetchingLabel = false; // Whether a 'fetching in progress' label is shown.
|
2017-04-28 11:03:49 +03:00
|
|
|
// undecided folders are the big folders that the user has not accepted yet
|
2020-05-21 02:43:34 +03:00
|
|
|
bool _isUndecided = false;
|
2017-08-25 14:56:13 +03:00
|
|
|
QByteArray _fileId; // the file id for this folder on the server.
|
2015-10-13 15:10:52 +03:00
|
|
|
|
2020-05-21 02:43:34 +03:00
|
|
|
Qt::CheckState _checked = Qt::Checked;
|
2015-06-02 20:45:23 +03:00
|
|
|
|
2022-12-07 21:43:27 +03:00
|
|
|
bool _isNonDecryptable = false;
|
|
|
|
|
2015-10-13 15:10:52 +03:00
|
|
|
// Whether this has a FetchLabel subrow
|
2022-09-30 20:12:08 +03:00
|
|
|
[[nodiscard]] bool hasLabel() const;
|
2015-10-13 15:10:52 +03:00
|
|
|
|
2023-03-29 10:22:22 +03:00
|
|
|
[[nodiscard]] bool isEncrypted() const { return _isEncrypted; }
|
|
|
|
|
2015-10-13 15:10:52 +03:00
|
|
|
// Reset all subfolders and fetch status
|
2017-05-17 11:55:42 +03:00
|
|
|
void resetSubs(FolderStatusModel *model, QModelIndex index);
|
|
|
|
|
|
|
|
struct Progress
|
|
|
|
{
|
2022-09-30 20:12:08 +03:00
|
|
|
[[nodiscard]] bool isNull() const
|
2017-05-17 11:55:42 +03:00
|
|
|
{
|
|
|
|
return _progressString.isEmpty() && _warningCount == 0 && _overallSyncString.isEmpty();
|
|
|
|
}
|
2015-06-02 20:45:23 +03:00
|
|
|
QString _progressString;
|
|
|
|
QString _overallSyncString;
|
2020-05-21 02:43:34 +03:00
|
|
|
int _warningCount = 0;
|
|
|
|
int _overallPercent = 0;
|
2015-06-02 20:45:23 +03:00
|
|
|
};
|
|
|
|
Progress _progress;
|
2015-03-27 13:46:03 +03:00
|
|
|
};
|
|
|
|
|
2015-04-27 20:09:48 +03:00
|
|
|
QVector<SubFolderInfo> _folders;
|
2013-07-04 21:59:40 +04:00
|
|
|
|
2017-05-17 11:55:42 +03:00
|
|
|
enum ItemType { RootFolder,
|
|
|
|
SubFolder,
|
|
|
|
AddButton,
|
|
|
|
FetchLabel };
|
2022-09-30 20:12:08 +03:00
|
|
|
[[nodiscard]] ItemType classify(const QModelIndex &index) const;
|
|
|
|
[[nodiscard]] SubFolderInfo *infoForIndex(const QModelIndex &index) const;
|
|
|
|
[[nodiscard]] bool isAnyAncestorEncrypted(const QModelIndex &index) const;
|
2015-04-27 20:09:48 +03:00
|
|
|
// If the selective sync check boxes were changed
|
2015-03-27 13:46:03 +03:00
|
|
|
bool isDirty() { return _dirty; }
|
|
|
|
|
2015-08-31 11:12:45 +03:00
|
|
|
/**
|
|
|
|
* return a QModelIndex for the given path within the given folder.
|
2015-10-05 07:21:19 +03:00
|
|
|
* Note: this method returns an invalid index if the path was not fetched from the server before
|
2015-08-31 11:12:45 +03:00
|
|
|
*/
|
|
|
|
QModelIndex indexForPath(Folder *f, const QString &path) const;
|
|
|
|
|
2015-03-27 13:46:03 +03:00
|
|
|
public slots:
|
2022-10-24 17:00:50 +03:00
|
|
|
void slotUpdateFolderState(OCC::Folder *);
|
2015-03-27 13:46:03 +03:00
|
|
|
void slotApplySelectiveSync();
|
|
|
|
void resetFolders();
|
2016-09-23 14:47:57 +03:00
|
|
|
void slotSyncAllPendingBigFolders();
|
|
|
|
void slotSyncNoPendingBigFolders();
|
2022-10-24 17:00:50 +03:00
|
|
|
void slotSetProgress(const OCC::ProgressInfo &progress);
|
2022-12-07 21:43:27 +03:00
|
|
|
void e2eInitializationFinished(bool isNewMnemonicGenerated);
|
2015-03-27 13:46:03 +03:00
|
|
|
|
|
|
|
private slots:
|
|
|
|
void slotUpdateDirectories(const QStringList &);
|
2017-05-17 11:55:42 +03:00
|
|
|
void slotGatherPermissions(const QString &name, const QMap<QString, QString> &properties);
|
2020-12-07 21:12:21 +03:00
|
|
|
void slotGatherEncryptionStatus(const QString &href, const QMap<QString, QString> &properties);
|
2015-06-02 21:15:16 +03:00
|
|
|
void slotLscolFinishedWithError(QNetworkReply *r);
|
2022-10-24 17:00:50 +03:00
|
|
|
void slotFolderSyncStateChange(OCC::Folder *f);
|
2015-09-04 11:33:48 +03:00
|
|
|
void slotFolderScheduleQueueChanged();
|
2015-08-05 13:51:49 +03:00
|
|
|
void slotNewBigFolder();
|
2015-03-27 13:46:03 +03:00
|
|
|
|
2015-10-13 15:10:52 +03:00
|
|
|
/**
|
|
|
|
* "In progress" labels for fetching data from the server are only
|
|
|
|
* added after some time to avoid popping.
|
|
|
|
*/
|
|
|
|
void slotShowFetchProgress();
|
|
|
|
|
2015-03-27 13:46:03 +03:00
|
|
|
private:
|
2022-09-30 20:12:08 +03:00
|
|
|
[[nodiscard]] QStringList createBlackList(const OCC::FolderStatusModel::SubFolderInfo &root,
|
2017-05-17 11:55:42 +03:00
|
|
|
const QStringList &oldBlackList) const;
|
2020-05-28 17:59:24 +03:00
|
|
|
const AccountState *_accountState = nullptr;
|
|
|
|
bool _dirty = false; // If the selective sync checkboxes were changed
|
2015-03-27 13:46:03 +03:00
|
|
|
|
2022-09-06 14:36:29 +03:00
|
|
|
bool _isSyncRunningForAwhile = false;
|
|
|
|
|
2015-10-13 15:10:52 +03:00
|
|
|
/**
|
|
|
|
* Keeps track of items that are fetching data from the server.
|
|
|
|
*
|
|
|
|
* See slotShowPendingFetchProgress()
|
|
|
|
*/
|
|
|
|
QMap<QPersistentModelIndex, QElapsedTimer> _fetchingItems;
|
|
|
|
|
2015-03-27 13:46:03 +03:00
|
|
|
signals:
|
|
|
|
void dirtyChanged();
|
2017-04-28 11:03:49 +03:00
|
|
|
|
|
|
|
// Tell the view that this item should be expanded because it has an undecided item
|
|
|
|
void suggestExpand(const QModelIndex &);
|
2015-10-15 18:27:29 +03:00
|
|
|
friend struct SubFolderInfo;
|
2013-07-04 21:59:40 +04:00
|
|
|
};
|
|
|
|
|
2014-11-10 00:34:07 +03:00
|
|
|
} // namespace OCC
|
2013-07-04 21:59:40 +04:00
|
|
|
|
2020-12-08 20:05:29 +03:00
|
|
|
Q_DECLARE_METATYPE(OCC::FolderStatusModel::SubFolderInfo*)
|
|
|
|
|
2013-07-04 21:59:40 +04:00
|
|
|
#endif // FOLDERSTATUSMODEL_H
|