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>
|
2015-06-16 13:14:04 +03:00
|
|
|
#include <QVector>
|
|
|
|
|
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
|
|
|
|
2015-03-27 13:46:03 +03:00
|
|
|
class Folder;
|
2015-06-02 20:45:23 +03:00
|
|
|
class ProgressInfo;
|
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:
|
2015-03-27 13:46:03 +03:00
|
|
|
FolderStatusModel(QObject * parent = 0);
|
|
|
|
~FolderStatusModel();
|
2015-07-03 16:03:18 +03:00
|
|
|
void setAccountState(const AccountState* accountState);
|
2015-03-27 13:46:03 +03:00
|
|
|
|
|
|
|
Qt::ItemFlags flags( const QModelIndex& ) const Q_DECL_OVERRIDE;
|
2014-07-10 01:22:28 +04:00
|
|
|
QVariant data(const QModelIndex &index, int role) const Q_DECL_OVERRIDE;
|
2015-03-27 13:46:03 +03:00
|
|
|
bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole) Q_DECL_OVERRIDE;
|
|
|
|
int columnCount(const QModelIndex& parent = QModelIndex()) const Q_DECL_OVERRIDE;
|
|
|
|
int rowCount(const QModelIndex& parent = QModelIndex()) const Q_DECL_OVERRIDE;
|
|
|
|
QModelIndex index(int row, int column = 0, const QModelIndex& parent = QModelIndex()) const Q_DECL_OVERRIDE;
|
|
|
|
QModelIndex parent(const QModelIndex& child) const Q_DECL_OVERRIDE;
|
|
|
|
bool canFetchMore(const QModelIndex& parent) const Q_DECL_OVERRIDE;
|
|
|
|
void fetchMore(const QModelIndex& parent) Q_DECL_OVERRIDE;
|
|
|
|
bool hasChildren(const QModelIndex& parent = QModelIndex()) const Q_DECL_OVERRIDE;
|
|
|
|
|
|
|
|
struct SubFolderInfo {
|
2015-06-16 10:30:29 +03:00
|
|
|
SubFolderInfo()
|
|
|
|
: _folder(0), _size(0), _fetched(false), _fetching(false), _isUndecided(false),
|
2015-08-18 14:21:02 +03:00
|
|
|
_hasError(false), _checked(Qt::Checked) {}
|
2015-06-16 10:30:29 +03:00
|
|
|
Folder *_folder;
|
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;
|
2015-07-08 15:52:58 +03:00
|
|
|
qint64 _size;
|
2015-06-16 10:30:29 +03:00
|
|
|
bool _fetched; // If we did the LSCOL for this folder already
|
|
|
|
bool _fetching;
|
|
|
|
bool _isUndecided; // undecided folder are the big folder that the user has not accepted yet
|
2015-08-18 14:21:02 +03:00
|
|
|
bool _hasError; // If the last fetching job ended in an error
|
2015-06-16 10:30:29 +03:00
|
|
|
Qt::CheckState _checked;
|
2015-06-02 20:45:23 +03:00
|
|
|
|
|
|
|
struct Progress {
|
2015-06-16 10:30:29 +03:00
|
|
|
Progress() : _warningCount(0), _overallPercent(0) {}
|
2015-06-02 20:45:23 +03:00
|
|
|
bool isNull() const
|
|
|
|
{ return _progressString.isEmpty() && _warningCount == 0 && _overallSyncString.isEmpty(); }
|
|
|
|
QString _progressString;
|
|
|
|
QString _overallSyncString;
|
2015-06-16 10:30:29 +03:00
|
|
|
int _warningCount;
|
|
|
|
int _overallPercent;
|
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-08-18 14:21:02 +03:00
|
|
|
enum ItemType { RootFolder, SubFolder, AddButton, ErrorLabel };
|
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.
|
|
|
|
* Note: this method returns an invalid index if the path was not fetch from the server before
|
|
|
|
*/
|
|
|
|
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();
|
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 &);
|
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
|
|
|
|
|
|
|
private:
|
|
|
|
QStringList createBlackList(OCC::FolderStatusModel::SubFolderInfo* root,
|
|
|
|
const QStringList& oldBlackList) const;
|
2015-07-03 16:03:18 +03:00
|
|
|
const AccountState* _accountState;
|
2015-06-16 10:30:29 +03:00
|
|
|
bool _dirty; // If the selective sync checkboxes were changed
|
2015-03-27 13:46:03 +03:00
|
|
|
|
2015-06-02 20:57:41 +03:00
|
|
|
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
|
|
|
|
//the roles argument was added in Qt5
|
|
|
|
void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles = QVector<int>())
|
|
|
|
{ emit QAbstractItemModel::dataChanged(topLeft,bottomRight); }
|
|
|
|
#endif
|
|
|
|
|
2015-03-27 13:46:03 +03:00
|
|
|
signals:
|
|
|
|
void dirtyChanged();
|
2015-08-05 13:51:49 +03:00
|
|
|
void suggestExpand(const QModelIndex &); // Tell the view that this item should be expanded because it has a undecided item
|
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
|