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);
|
2015-03-27 13:46:03 +03:00
|
|
|
~FolderStatusModel();
|
2015-07-03 16:03:18 +03:00
|
|
|
void setAccountState(const AccountState *accountState);
|
2015-03-27 13:46:03 +03:00
|
|
|
|
2018-11-11 13:09:29 +03:00
|
|
|
Qt::ItemFlags flags(const QModelIndex &) const override;
|
|
|
|
QVariant data(const QModelIndex &index, int role) const override;
|
|
|
|
bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
|
|
|
|
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
|
|
|
|
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
|
|
|
QModelIndex index(int row, int column = 0, const QModelIndex &parent = QModelIndex()) const override;
|
|
|
|
QModelIndex parent(const QModelIndex &child) const override;
|
|
|
|
bool canFetchMore(const QModelIndex &parent) const override;
|
|
|
|
void fetchMore(const QModelIndex &parent) override;
|
|
|
|
bool hasChildren(const QModelIndex &parent = QModelIndex()) const override;
|
2017-05-17 11:55:42 +03:00
|
|
|
|
2015-03-27 13:46:03 +03:00
|
|
|
struct SubFolderInfo
|
|
|
|
{
|
2020-05-21 02:43:34 +03:00
|
|
|
Folder *_folder = nullptr;
|
2015-03-27 13:46:03 +03:00
|
|
|
QString _name;
|
|
|
|
QString _path;
|
|
|
|
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;
|
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
|
|
|
|
2015-10-13 15:10:52 +03:00
|
|
|
// Whether this has a FetchLabel subrow
|
|
|
|
bool hasLabel() const;
|
|
|
|
|
|
|
|
// Reset all subfolders and fetch status
|
|
|
|
void resetSubs(FolderStatusModel *model, QModelIndex index);
|
2017-05-17 11:55:42 +03:00
|
|
|
|
2015-06-02 20:45:23 +03:00
|
|
|
struct Progress
|
|
|
|
{
|
|
|
|
bool isNull() const
|
|
|
|
{
|
|
|
|
return _progressString.isEmpty() && _warningCount == 0 && _overallSyncString.isEmpty();
|
|
|
|
}
|
|
|
|
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
|
|
|
|
2015-10-13 15:10:52 +03:00
|
|
|
enum ItemType { RootFolder,
|
|
|
|
SubFolder,
|
|
|
|
AddButton,
|
|
|
|
FetchLabel };
|
2015-03-27 13:46:03 +03:00
|
|
|
ItemType classify(const QModelIndex &index) const;
|
|
|
|
SubFolderInfo *infoForIndex(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:
|
2015-06-02 20:45:23 +03:00
|
|
|
void slotUpdateFolderState(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();
|
2015-06-02 20:45:23 +03:00
|
|
|
void slotSetProgress(const ProgressInfo &progress);
|
2015-03-27 13:46:03 +03:00
|
|
|
|
|
|
|
private slots:
|
|
|
|
void slotUpdateDirectories(const QStringList &);
|
2017-01-24 17:39:08 +03:00
|
|
|
void slotGatherPermissions(const QString &name, const QMap<QString, QString> &properties);
|
2015-06-02 21:15:16 +03:00
|
|
|
void slotLscolFinishedWithError(QNetworkReply *r);
|
2015-09-04 11:33:48 +03:00
|
|
|
void slotFolderSyncStateChange(Folder *f);
|
|
|
|
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:
|
|
|
|
QStringList createBlackList(OCC::FolderStatusModel::SubFolderInfo *root,
|
|
|
|
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
|
|
|
|
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
|
|
|
|
|
|
|
#endif // FOLDERSTATUSMODEL_H
|