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.
|
|
|
|
*/
|
|
|
|
|
2014-07-11 02:31:24 +04:00
|
|
|
#include "folderstatusmodel.h"
|
2015-03-27 13:46:03 +03:00
|
|
|
#include "folderman.h"
|
2015-04-27 20:09:48 +03:00
|
|
|
#include "accountstate.h"
|
2014-07-11 02:31:24 +04:00
|
|
|
#include "utility.h"
|
2015-03-27 13:46:03 +03:00
|
|
|
#include <theme.h>
|
|
|
|
#include <account.h>
|
2013-07-04 21:59:40 +04:00
|
|
|
|
2015-06-02 21:01:13 +03:00
|
|
|
#include <QFileIconProvider>
|
|
|
|
#include <QPainter>
|
|
|
|
#include <QApplication>
|
2013-07-04 21:59:40 +04:00
|
|
|
|
2015-03-27 13:46:03 +03:00
|
|
|
Q_DECLARE_METATYPE(QPersistentModelIndex)
|
|
|
|
|
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
|
|
|
static const char propertyParentIndexC[] = "oc_parentIndex";
|
|
|
|
|
|
|
|
FolderStatusModel::FolderStatusModel(QObject *parent)
|
|
|
|
:QAbstractItemModel(parent)
|
2013-07-04 21:59:40 +04:00
|
|
|
{
|
2015-03-27 13:46:03 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
FolderStatusModel::~FolderStatusModel()
|
|
|
|
{ }
|
|
|
|
|
2013-07-04 21:59:40 +04:00
|
|
|
|
2015-03-27 13:46:03 +03:00
|
|
|
void FolderStatusModel::setAccount(const AccountPtr& account)
|
|
|
|
{
|
|
|
|
beginResetModel();
|
|
|
|
_dirty = false;
|
|
|
|
_folders.clear();
|
|
|
|
_account = account;
|
2015-04-27 20:09:48 +03:00
|
|
|
|
|
|
|
auto folders = FolderMan::instance()->map();
|
|
|
|
foreach (auto f, folders) {
|
|
|
|
if (f->accountState()->account() != account)
|
|
|
|
continue;
|
|
|
|
SubFolderInfo info;
|
|
|
|
info._pathIdx << _folders.size();
|
|
|
|
info._name = f->alias();
|
|
|
|
info._path = "/";
|
|
|
|
info._folder = f;
|
|
|
|
_folders << info;
|
2015-06-02 20:45:23 +03:00
|
|
|
|
|
|
|
connect(f, SIGNAL(progressInfo(ProgressInfo)), this, SLOT(slotSetProgress(ProgressInfo)), Qt::UniqueConnection);
|
|
|
|
connect(f, SIGNAL(syncStateChange()), this, SLOT(slotFolderSyncStateChange()), Qt::UniqueConnection);
|
2015-04-27 20:09:48 +03:00
|
|
|
}
|
|
|
|
|
2015-03-27 13:46:03 +03:00
|
|
|
endResetModel();
|
2013-07-04 21:59:40 +04:00
|
|
|
}
|
|
|
|
|
2015-03-27 13:46:03 +03:00
|
|
|
|
|
|
|
Qt::ItemFlags FolderStatusModel::flags ( const QModelIndex &index ) const
|
2013-07-04 21:59:40 +04:00
|
|
|
{
|
2015-03-27 13:46:03 +03:00
|
|
|
switch (classify(index)) {
|
|
|
|
case AddButton:
|
|
|
|
return Qt::ItemIsEnabled;
|
|
|
|
case RootFolder:
|
|
|
|
return Qt::ItemIsSelectable | Qt::ItemIsEnabled;
|
|
|
|
case SubFolder:
|
|
|
|
return Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsUserCheckable;
|
|
|
|
}
|
|
|
|
return 0;
|
2013-07-04 21:59:40 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
QVariant FolderStatusModel::data(const QModelIndex &index, int role) const
|
|
|
|
{
|
|
|
|
if (!index.isValid())
|
|
|
|
return QVariant();
|
|
|
|
|
|
|
|
if (role == Qt::EditRole)
|
|
|
|
return QVariant();
|
2015-03-27 13:46:03 +03:00
|
|
|
|
|
|
|
switch(classify(index)) {
|
|
|
|
case AddButton:
|
|
|
|
if (role == FolderStatusDelegate::AddButton)
|
|
|
|
return QVariant(true);
|
|
|
|
return QVariant();
|
|
|
|
case SubFolder:
|
|
|
|
{
|
|
|
|
const auto &x = static_cast<SubFolderInfo *>(index.internalPointer())->_subs[index.row()];
|
|
|
|
switch (role) {
|
|
|
|
case Qt::ToolTipRole:
|
|
|
|
case Qt::DisplayRole:
|
|
|
|
return x._name;
|
|
|
|
case Qt::CheckStateRole:
|
|
|
|
return x._checked;
|
|
|
|
case Qt::DecorationRole:
|
|
|
|
return QFileIconProvider().icon(QFileIconProvider::Folder);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return QVariant();
|
|
|
|
case RootFolder:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-04-27 20:09:48 +03:00
|
|
|
auto f = _folders.at(index.row())._folder;
|
2015-03-27 13:46:03 +03:00
|
|
|
if (!f)
|
|
|
|
return QVariant();
|
|
|
|
|
|
|
|
bool accountConnected = true; // FIXME
|
|
|
|
|
|
|
|
switch (role) {
|
|
|
|
case FolderStatusDelegate::FolderPathRole : return f->nativePath();
|
|
|
|
case FolderStatusDelegate::FolderSecondPathRole : return f->remotePath();
|
|
|
|
case FolderStatusDelegate::FolderAliasRole : return f->alias();
|
|
|
|
case FolderStatusDelegate::FolderSyncPaused : return f->syncPaused();
|
|
|
|
case FolderStatusDelegate::FolderAccountConnected : return accountConnected;
|
|
|
|
case Qt::ToolTipRole:
|
|
|
|
return Theme::instance()->statusHeaderText(f->syncResult().status());
|
|
|
|
case FolderStatusDelegate::FolderStatusIconRole:
|
|
|
|
if ( accountConnected ) {
|
|
|
|
auto theme = Theme::instance();
|
|
|
|
auto status = f->syncResult().status();
|
|
|
|
if( f->syncPaused() ) {
|
|
|
|
return theme->folderDisabledIcon( );
|
|
|
|
} else {
|
|
|
|
if( status == SyncResult::SyncPrepare ) {
|
|
|
|
return theme->syncStateIcon(SyncResult::SyncRunning);
|
|
|
|
} else if( status == SyncResult::Undefined ) {
|
|
|
|
return theme->syncStateIcon( SyncResult::SyncRunning);
|
|
|
|
} else {
|
|
|
|
// kepp the previous icon for the prepare phase.
|
|
|
|
if( status == SyncResult::Problem) {
|
|
|
|
return theme->syncStateIcon( SyncResult::Success);
|
|
|
|
} else {
|
|
|
|
return theme->syncStateIcon( status );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return Theme::instance()->folderOfflineIcon();
|
|
|
|
}
|
2015-04-09 13:06:47 +03:00
|
|
|
case FolderStatusDelegate::AddProgressSpace:
|
2015-06-02 20:45:23 +03:00
|
|
|
return !_folders.value(index.row())._progress.isNull();
|
2015-04-09 13:06:47 +03:00
|
|
|
case FolderStatusDelegate::SyncProgressItemString:
|
2015-06-02 20:45:23 +03:00
|
|
|
return _folders.value(index.row())._progress._progressString;
|
2015-04-09 13:06:47 +03:00
|
|
|
case FolderStatusDelegate::WarningCount:
|
2015-06-02 20:45:23 +03:00
|
|
|
return _folders.value(index.row())._progress._warningCount;
|
2015-04-09 13:06:47 +03:00
|
|
|
case FolderStatusDelegate::SyncProgressOverallPercent:
|
2015-06-02 20:45:23 +03:00
|
|
|
return _folders.value(index.row())._progress._overallPercent;
|
2015-04-09 13:06:47 +03:00
|
|
|
case FolderStatusDelegate::SyncProgressOverallString:
|
2015-06-02 20:45:23 +03:00
|
|
|
return _folders.value(index.row())._progress._overallSyncString;
|
2015-03-27 13:46:03 +03:00
|
|
|
}
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool FolderStatusModel::setData(const QModelIndex& index, const QVariant& value, int role)
|
|
|
|
{
|
|
|
|
if(role == Qt::CheckStateRole) {
|
|
|
|
auto info = infoForIndex(index);
|
|
|
|
Qt::CheckState checked = static_cast<Qt::CheckState>(value.toInt());
|
|
|
|
|
|
|
|
if (info && info->_checked != checked) {
|
|
|
|
info->_checked = checked;
|
|
|
|
if (checked == Qt::Checked) {
|
|
|
|
// If we are checked, check that we may need to check the parent as well if
|
|
|
|
// all the sibilings are also checked
|
|
|
|
QModelIndex parent = index.parent();
|
|
|
|
auto parentInfo = infoForIndex(parent);
|
|
|
|
if (parentInfo && parentInfo->_checked != Qt::Checked) {
|
|
|
|
bool hasUnchecked = false;
|
|
|
|
foreach(const auto &sub, parentInfo->_subs) {
|
|
|
|
if (sub._checked != Qt::Checked) {
|
|
|
|
hasUnchecked = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!hasUnchecked) {
|
|
|
|
setData(parent, Qt::Checked, Qt::CheckStateRole);
|
|
|
|
} else if (parentInfo->_checked == Qt::Unchecked) {
|
|
|
|
setData(parent, Qt::PartiallyChecked, Qt::CheckStateRole);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// also check all the children
|
|
|
|
for (int i = 0; i < info->_subs.count(); ++i) {
|
|
|
|
if (info->_subs[i]._checked != Qt::Checked) {
|
|
|
|
setData(index.child(i, 0), Qt::Checked, Qt::CheckStateRole);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (checked == Qt::Unchecked) {
|
|
|
|
QModelIndex parent = index.parent();
|
|
|
|
auto parentInfo = infoForIndex(parent);
|
|
|
|
if (parentInfo && parentInfo->_checked == Qt::Checked) {
|
|
|
|
setData(parent, Qt::PartiallyChecked, Qt::CheckStateRole);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Uncheck all the children
|
|
|
|
for (int i = 0; i < info->_subs.count(); ++i) {
|
|
|
|
if (info->_subs[i]._checked != Qt::Unchecked) {
|
|
|
|
setData(index.child(i, 0), Qt::Unchecked, Qt::CheckStateRole);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (checked == Qt::PartiallyChecked) {
|
|
|
|
QModelIndex parent = index.parent();
|
|
|
|
auto parentInfo = infoForIndex(parent);
|
|
|
|
if (parentInfo && parentInfo->_checked != Qt::PartiallyChecked) {
|
|
|
|
setData(parent, Qt::PartiallyChecked, Qt::CheckStateRole);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
_dirty = true;
|
|
|
|
emit dirtyChanged();
|
2015-06-02 20:57:41 +03:00
|
|
|
emit dataChanged(index, index, QVector<int>() << role);
|
2015-03-27 13:46:03 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return QAbstractItemModel::setData(index, value, role);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int FolderStatusModel::columnCount(const QModelIndex&) const
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int FolderStatusModel::rowCount(const QModelIndex& parent) const
|
|
|
|
{
|
|
|
|
if (!parent.isValid()) {
|
2015-04-27 20:09:48 +03:00
|
|
|
return _folders.count() + 1;
|
2015-03-27 13:46:03 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
auto info = infoForIndex(parent);
|
|
|
|
if (!info)
|
|
|
|
return 0;
|
|
|
|
return info->_subs.count();
|
|
|
|
}
|
|
|
|
|
|
|
|
FolderStatusModel::ItemType FolderStatusModel::classify(const QModelIndex& index) const
|
|
|
|
{
|
|
|
|
if (index.internalPointer()) {
|
|
|
|
return SubFolder;
|
|
|
|
}
|
2015-04-27 20:09:48 +03:00
|
|
|
if (index.row() < _folders.count()) {
|
2015-03-27 13:46:03 +03:00
|
|
|
return RootFolder;
|
|
|
|
}
|
|
|
|
return AddButton;
|
2013-07-04 21:59:40 +04:00
|
|
|
}
|
|
|
|
|
2015-03-27 13:46:03 +03:00
|
|
|
FolderStatusModel::SubFolderInfo* FolderStatusModel::infoForIndex(const QModelIndex& index) const
|
|
|
|
{
|
|
|
|
if (!index.isValid())
|
|
|
|
return 0;
|
|
|
|
if (auto parentInfo = index.internalPointer()) {
|
|
|
|
return &static_cast<SubFolderInfo*>(parentInfo)->_subs[index.row()];
|
|
|
|
} else {
|
2015-04-27 20:09:48 +03:00
|
|
|
if (index.row() >= _folders.count()) {
|
2015-03-27 13:46:03 +03:00
|
|
|
// AddButton
|
|
|
|
return 0;
|
|
|
|
}
|
2015-04-27 20:09:48 +03:00
|
|
|
return const_cast<SubFolderInfo *>(&_folders[index.row()]);
|
2015-03-27 13:46:03 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QModelIndex FolderStatusModel::index(int row, int column, const QModelIndex& parent) const
|
|
|
|
{
|
|
|
|
if (!parent.isValid()) {
|
|
|
|
return createIndex(row, column, nullptr);
|
|
|
|
}
|
|
|
|
switch(classify(parent)) {
|
|
|
|
case AddButton: return QModelIndex();
|
|
|
|
case RootFolder:
|
|
|
|
if (_folders.count() <= parent.row())
|
|
|
|
return QModelIndex(); // should not happen
|
|
|
|
return createIndex(row, column, const_cast<SubFolderInfo *>(&_folders[parent.row()]));
|
|
|
|
case SubFolder:
|
|
|
|
//return QModelIndex();
|
|
|
|
if (static_cast<SubFolderInfo*>(parent.internalPointer())->_subs.count() <= parent.row())
|
|
|
|
return QModelIndex(); // should not happen
|
|
|
|
if (static_cast<SubFolderInfo*>(parent.internalPointer())->_subs.at(parent.row())._subs.count() <= row)
|
|
|
|
return QModelIndex(); // should not happen
|
|
|
|
return createIndex(row, column, &static_cast<SubFolderInfo*>(parent.internalPointer())->_subs[parent.row()]);
|
|
|
|
}
|
|
|
|
return QModelIndex();
|
|
|
|
}
|
|
|
|
|
|
|
|
QModelIndex FolderStatusModel::parent(const QModelIndex& child) const
|
|
|
|
{
|
|
|
|
if (!child.isValid()) {
|
|
|
|
return QModelIndex();
|
|
|
|
}
|
|
|
|
switch(classify(child)) {
|
|
|
|
case RootFolder:
|
|
|
|
case AddButton:
|
|
|
|
return QModelIndex();
|
|
|
|
case SubFolder:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
auto pathIdx = static_cast<SubFolderInfo*>(child.internalPointer())->_subs[child.row()]._pathIdx;
|
|
|
|
int i = 1;
|
|
|
|
Q_ASSERT(pathIdx.at(0) < _folders.count());
|
|
|
|
if (pathIdx.count() == 2) {
|
|
|
|
return createIndex(pathIdx.at(0), 0, nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
const SubFolderInfo *info = &_folders[pathIdx.at(0)];
|
|
|
|
while (i < pathIdx.count() - 2) {
|
|
|
|
Q_ASSERT(pathIdx.at(i) < info->_subs.count());
|
|
|
|
info = &info->_subs[pathIdx.at(i)];
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
return createIndex(pathIdx.at(i), 0, const_cast<SubFolderInfo *>(info));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool FolderStatusModel::hasChildren(const QModelIndex& parent) const
|
|
|
|
{
|
|
|
|
if (!parent.isValid())
|
|
|
|
return true;
|
|
|
|
|
|
|
|
auto info = infoForIndex(parent);
|
|
|
|
if (!info)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (!info->_fetched)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if (info->_subs.isEmpty())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool FolderStatusModel::canFetchMore(const QModelIndex& parent) const
|
|
|
|
{
|
|
|
|
auto info = infoForIndex(parent);
|
|
|
|
if (!info || info->_fetched || info->_fetching)
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void FolderStatusModel::fetchMore(const QModelIndex& parent)
|
|
|
|
{
|
|
|
|
auto info = infoForIndex(parent);
|
2015-06-02 21:15:16 +03:00
|
|
|
|
2015-03-27 13:46:03 +03:00
|
|
|
if (!info || info->_fetched || info->_fetching)
|
|
|
|
return;
|
|
|
|
|
|
|
|
info->_fetching = true;
|
|
|
|
LsColJob *job = new LsColJob(_account, info->_folder->remotePath() + "/" + info->_path, this);
|
|
|
|
job->setProperties(QList<QByteArray>() << "resourcetype" << "quota-used-bytes");
|
2015-06-02 21:15:16 +03:00
|
|
|
job->setTimeout(5 * 1000);
|
2015-03-27 13:46:03 +03:00
|
|
|
connect(job, SIGNAL(directoryListingSubfolders(QStringList)),
|
|
|
|
SLOT(slotUpdateDirectories(QStringList)));
|
2015-06-02 21:15:16 +03:00
|
|
|
connect(job, SIGNAL(finishedWithError(QNetworkReply*)),
|
|
|
|
this, SLOT(slotLscolFinishedWithError(QNetworkReply*)));
|
2015-03-27 13:46:03 +03:00
|
|
|
job->start();
|
|
|
|
job->setProperty(propertyParentIndexC , QVariant::fromValue<QPersistentModelIndex>(parent));
|
|
|
|
}
|
|
|
|
|
|
|
|
void FolderStatusModel::slotUpdateDirectories(const QStringList &list_)
|
|
|
|
{
|
|
|
|
auto job = qobject_cast<LsColJob *>(sender());
|
|
|
|
Q_ASSERT(job);
|
|
|
|
QModelIndex idx = qvariant_cast<QPersistentModelIndex>(job->property(propertyParentIndexC));
|
|
|
|
if (!idx.isValid()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
auto parentInfo = infoForIndex(idx);
|
|
|
|
|
|
|
|
auto list = list_;
|
|
|
|
list.removeFirst(); // remove the parent item
|
|
|
|
|
|
|
|
beginInsertRows(idx, 0, list.count());
|
|
|
|
|
|
|
|
QUrl url = parentInfo->_folder->remoteUrl();
|
|
|
|
QString pathToRemove = url.path();
|
|
|
|
if (!pathToRemove.endsWith('/'))
|
|
|
|
pathToRemove += '/';
|
|
|
|
|
|
|
|
parentInfo->_fetched = true;
|
|
|
|
parentInfo->_fetching = false;
|
|
|
|
|
|
|
|
int i = 0;
|
|
|
|
foreach (QString path, list) {
|
|
|
|
SubFolderInfo newInfo;
|
|
|
|
newInfo._folder = parentInfo->_folder;
|
|
|
|
newInfo._pathIdx = parentInfo->_pathIdx;
|
|
|
|
newInfo._pathIdx << i++;
|
|
|
|
auto size = job ? job->_sizes.value(path) : 0;
|
|
|
|
newInfo._size = size;
|
|
|
|
path.remove(pathToRemove);
|
|
|
|
newInfo._path = path;
|
|
|
|
newInfo._name = path.split('/', QString::SkipEmptyParts).last();
|
|
|
|
|
|
|
|
if (path.isEmpty())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (parentInfo->_checked == Qt::Unchecked) {
|
|
|
|
newInfo._checked = Qt::Unchecked;
|
|
|
|
} else {
|
2015-04-27 20:09:48 +03:00
|
|
|
auto *f = _folders.at(parentInfo->_pathIdx.first())._folder;
|
2015-03-27 13:46:03 +03:00
|
|
|
foreach(const QString &str , f->selectiveSyncBlackList()) {
|
|
|
|
if (str == path || str == QLatin1String("/")) {
|
|
|
|
newInfo._checked = Qt::Unchecked;
|
|
|
|
break;
|
|
|
|
} else if (str.startsWith(path)) {
|
|
|
|
newInfo._checked = Qt::PartiallyChecked;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
parentInfo->_subs.append(newInfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
endInsertRows();
|
|
|
|
}
|
|
|
|
|
2015-06-02 21:15:16 +03:00
|
|
|
void FolderStatusModel::slotLscolFinishedWithError(QNetworkReply* r)
|
2015-03-27 13:46:03 +03:00
|
|
|
{
|
2015-06-02 21:15:16 +03:00
|
|
|
/*
|
2015-03-27 13:46:03 +03:00
|
|
|
if (r->error() == QNetworkReply::ContentNotFoundError) {
|
|
|
|
_loading->setText(tr("No subfolders currently on the server."));
|
|
|
|
} else {
|
|
|
|
_loading->setText(tr("An error occured while loading the list of sub folders."));
|
|
|
|
}
|
|
|
|
_loading->resize(_loading->sizeHint()); // because it's not in a layout
|
2015-06-02 21:15:16 +03:00
|
|
|
*/
|
|
|
|
auto job = qobject_cast<LsColJob *>(sender());
|
|
|
|
Q_ASSERT(job);
|
|
|
|
QModelIndex idx = qvariant_cast<QPersistentModelIndex>(job->property(propertyParentIndexC));
|
|
|
|
if (!idx.isValid()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
auto parentInfo = infoForIndex(idx);
|
|
|
|
if (parentInfo) {
|
|
|
|
parentInfo->_fetching = false;
|
|
|
|
if (r->error() == QNetworkReply::ContentNotFoundError) {
|
|
|
|
parentInfo->_fetched = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-03-27 13:46:03 +03:00
|
|
|
|
|
|
|
QStringList FolderStatusModel::createBlackList(FolderStatusModel::SubFolderInfo *root,
|
|
|
|
const QStringList &oldBlackList) const
|
|
|
|
{
|
|
|
|
if (!root) return QStringList();
|
|
|
|
|
|
|
|
switch(root->_checked) {
|
|
|
|
case Qt::Unchecked:
|
|
|
|
return QStringList(root->_path);
|
|
|
|
case Qt::Checked:
|
|
|
|
return QStringList();
|
|
|
|
case Qt::PartiallyChecked:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
QStringList result;
|
|
|
|
if (root->_fetched) {
|
|
|
|
for (int i = 0; i < root->_subs.count(); ++i) {
|
|
|
|
result += createBlackList(&root->_subs[i], oldBlackList);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// We did not load from the server so we re-use the one from the old black list
|
|
|
|
QString path = root->_path;
|
|
|
|
foreach (const QString & it, oldBlackList) {
|
|
|
|
if (it.startsWith(path))
|
|
|
|
result += it;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2015-06-02 20:45:23 +03:00
|
|
|
void FolderStatusModel::slotUpdateFolderState(Folder *folder)
|
|
|
|
{
|
|
|
|
if( ! folder ) return;
|
|
|
|
for (int i = 0; i < _folders.count(); ++i) {
|
|
|
|
if (_folders.at(i)._folder == folder) {
|
|
|
|
emit dataChanged(index(i), index(i),
|
|
|
|
QVector<int>() << FolderStatusDelegate::AddProgressSpace);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-27 13:46:03 +03:00
|
|
|
void FolderStatusModel::slotApplySelectiveSync()
|
|
|
|
{
|
|
|
|
if (!_dirty)
|
|
|
|
return;
|
|
|
|
|
2015-04-27 20:09:48 +03:00
|
|
|
for (int i = 0; i < _folders.count(); ++i) {
|
2015-03-27 13:46:03 +03:00
|
|
|
if (!_folders[i]._fetched) continue;
|
2015-04-27 20:09:48 +03:00
|
|
|
auto folder = _folders.at(i)._folder;
|
2015-03-27 13:46:03 +03:00
|
|
|
|
|
|
|
auto oldBlackList = folder->selectiveSyncBlackList();
|
|
|
|
QStringList blackList = createBlackList(&_folders[i], oldBlackList);
|
|
|
|
folder->setSelectiveSyncBlackList(blackList);
|
|
|
|
|
|
|
|
FolderMan *folderMan = FolderMan::instance();
|
|
|
|
auto blackListSet = blackList.toSet();
|
|
|
|
auto oldBlackListSet = oldBlackList.toSet();
|
|
|
|
auto changes = (oldBlackListSet - blackListSet) + (blackListSet - oldBlackListSet);
|
|
|
|
if (!changes.isEmpty()) {
|
|
|
|
if (folder->isBusy()) {
|
|
|
|
folder->slotTerminateSync();
|
|
|
|
}
|
|
|
|
//The part that changed should not be read from the DB on next sync because there might be new folders
|
|
|
|
// (the ones that are no longer in the blacklist)
|
|
|
|
foreach(const auto &it, changes) {
|
|
|
|
folder->journalDb()->avoidReadFromDbOnNextSync(it);
|
|
|
|
}
|
2015-04-28 16:13:39 +03:00
|
|
|
folderMan->slotScheduleSync(folder);
|
2015-03-27 13:46:03 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
resetFolders();
|
|
|
|
}
|
|
|
|
|
2015-06-02 20:45:23 +03:00
|
|
|
static QString shortenFilename( Folder *f, const QString& file )
|
|
|
|
{
|
|
|
|
// strip off the server prefix from the file name
|
|
|
|
QString shortFile(file);
|
|
|
|
if( shortFile.isEmpty() ) {
|
|
|
|
return QString::null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(shortFile.startsWith(QLatin1String("ownclouds://")) ||
|
|
|
|
shortFile.startsWith(QLatin1String("owncloud://")) ) {
|
|
|
|
// rip off the whole ownCloud URL.
|
|
|
|
if( f ) {
|
|
|
|
QString remotePathUrl = f->remoteUrl().toString();
|
|
|
|
shortFile.remove(Utility::toCSyncScheme(remotePathUrl));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return shortFile;
|
|
|
|
}
|
|
|
|
|
|
|
|
void FolderStatusModel::slotSetProgress(const ProgressInfo &progress)
|
|
|
|
{
|
|
|
|
auto par = qobject_cast<QWidget*>(QObject::parent());
|
|
|
|
if (!par->isVisible()) {
|
|
|
|
return; // for https://github.com/owncloud/client/issues/2648#issuecomment-71377909
|
|
|
|
}
|
|
|
|
|
|
|
|
Folder *f = qobject_cast<Folder*>(sender());
|
|
|
|
if( !f ) { return; }
|
|
|
|
|
|
|
|
int folderIndex = -1;
|
|
|
|
for (int i = 0; i < _folders.count(); ++i) {
|
|
|
|
if (_folders.at(i)._folder == f) {
|
|
|
|
folderIndex = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (folderIndex < 0) { return; }
|
|
|
|
|
|
|
|
auto *pi = &_folders[folderIndex]._progress;
|
|
|
|
|
|
|
|
QVector<int> roles;
|
|
|
|
roles << FolderStatusDelegate::AddProgressSpace << FolderStatusDelegate::SyncProgressItemString
|
|
|
|
<< FolderStatusDelegate::WarningCount;
|
|
|
|
|
|
|
|
if (!progress._currentDiscoveredFolder.isEmpty()) {
|
|
|
|
pi->_progressString = tr("Discovering '%1'").arg(progress._currentDiscoveredFolder);
|
|
|
|
emit dataChanged(index(folderIndex), index(folderIndex), roles);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!progress._lastCompletedItem.isEmpty()
|
|
|
|
&& Progress::isWarningKind(progress._lastCompletedItem._status)) {
|
|
|
|
pi->_warningCount++;
|
|
|
|
}
|
|
|
|
|
|
|
|
// find the single item to display: This is going to be the bigger item, or the last completed
|
|
|
|
// item if no items are in progress.
|
|
|
|
SyncFileItem curItem = progress._lastCompletedItem;
|
|
|
|
qint64 curItemProgress = -1; // -1 means finished
|
|
|
|
quint64 biggerItemSize = -1;
|
|
|
|
foreach(const ProgressInfo::ProgressItem &citm, progress._currentItems) {
|
|
|
|
if (curItemProgress == -1 || (ProgressInfo::isSizeDependent(citm._item)
|
|
|
|
&& biggerItemSize < citm._item._size)) {
|
|
|
|
curItemProgress = citm._progress.completed();
|
|
|
|
curItem = citm._item;
|
|
|
|
biggerItemSize = citm._item._size;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (curItemProgress == -1) {
|
|
|
|
curItemProgress = curItem._size;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString itemFileName = shortenFilename(f, curItem._file);
|
|
|
|
QString kindString = Progress::asActionString(curItem);
|
|
|
|
|
|
|
|
QString fileProgressString;
|
|
|
|
if (ProgressInfo::isSizeDependent(curItem)) {
|
|
|
|
QString s1 = Utility::octetsToString( curItemProgress );
|
|
|
|
QString s2 = Utility::octetsToString( curItem._size );
|
|
|
|
quint64 estimatedBw = progress.fileProgress(curItem).estimatedBandwidth;
|
|
|
|
if (estimatedBw) {
|
|
|
|
//: Example text: "uploading foobar.png (1MB of 2MB) time left 2 minutes at a rate of 24Kb/s"
|
|
|
|
fileProgressString = tr("%1 %2 (%3 of %4) %5 left at a rate of %6/s")
|
|
|
|
.arg(kindString, itemFileName, s1, s2,
|
|
|
|
Utility::timeToDescriptiveString(progress.fileProgress(curItem).estimatedEta, 3, " ", true),
|
|
|
|
Utility::octetsToString(estimatedBw) );
|
|
|
|
} else {
|
|
|
|
//: Example text: "uploading foobar.png (2MB of 2MB)"
|
|
|
|
fileProgressString = tr("%1 %2 (%3 of %4)") .arg(kindString, itemFileName, s1, s2);
|
|
|
|
}
|
|
|
|
} else if (!kindString.isEmpty()) {
|
|
|
|
//: Example text: "uploading foobar.png"
|
|
|
|
fileProgressString = tr("%1 %2").arg(kindString, itemFileName);
|
|
|
|
}
|
|
|
|
pi->_progressString = fileProgressString;
|
|
|
|
|
|
|
|
// overall progress
|
|
|
|
quint64 completedSize = progress.completedSize();
|
|
|
|
quint64 completedFile = progress.completedFiles();
|
|
|
|
quint64 currentFile = progress.currentFile();
|
|
|
|
if (currentFile == ULLONG_MAX)
|
|
|
|
currentFile = 0;
|
|
|
|
quint64 totalSize = qMax(completedSize, progress.totalSize());
|
|
|
|
quint64 totalFileCount = qMax(currentFile, progress.totalFiles());
|
|
|
|
QString overallSyncString;
|
|
|
|
if (totalSize > 0) {
|
|
|
|
QString s1 = Utility::octetsToString( completedSize );
|
|
|
|
QString s2 = Utility::octetsToString( totalSize );
|
|
|
|
overallSyncString = tr("%1 of %2, file %3 of %4\nTotal time left %5")
|
|
|
|
.arg(s1, s2)
|
|
|
|
.arg(currentFile).arg(totalFileCount)
|
|
|
|
.arg( Utility::timeToDescriptiveString(progress.totalProgress().estimatedEta, 3, " ", true) );
|
|
|
|
} else if (totalFileCount > 0) {
|
|
|
|
// Don't attemt to estimate the time left if there is no kb to transfer.
|
|
|
|
overallSyncString = tr("file %1 of %2") .arg(currentFile).arg(totalFileCount);
|
|
|
|
}
|
|
|
|
|
|
|
|
pi->_overallSyncString = overallSyncString;
|
|
|
|
|
|
|
|
int overallPercent = 0;
|
|
|
|
if( totalFileCount > 0 ) {
|
|
|
|
// Add one 'byte' for each files so the percentage is moving when deleting or renaming files
|
|
|
|
overallPercent = qRound(double(completedSize + completedFile)/double(totalSize + totalFileCount) * 100.0);
|
|
|
|
}
|
|
|
|
pi->_overallPercent = qBound(0, overallPercent, 100);
|
|
|
|
emit dataChanged(index(folderIndex), index(folderIndex), roles);
|
|
|
|
}
|
|
|
|
|
|
|
|
void FolderStatusModel::slotHideProgress()
|
|
|
|
{
|
|
|
|
auto folderIndex = sender()->property("owncloud_folderIndex").toInt();
|
|
|
|
if (folderIndex < 0 || _folders.size() <= folderIndex) { return; }
|
|
|
|
|
|
|
|
_folders[folderIndex]._progress = SubFolderInfo::Progress();
|
|
|
|
emit dataChanged(index(folderIndex), index(folderIndex),
|
|
|
|
QVector<int>() << FolderStatusDelegate::AddProgressSpace);
|
|
|
|
}
|
|
|
|
|
|
|
|
void FolderStatusModel::slotFolderSyncStateChange()
|
|
|
|
{
|
|
|
|
Folder *f = qobject_cast<Folder*>(sender());
|
|
|
|
if( !f ) { return; }
|
|
|
|
int folderIndex = -1;
|
|
|
|
for (int i = 0; i < _folders.count(); ++i) {
|
|
|
|
if (_folders.at(i)._folder == f) {
|
|
|
|
folderIndex = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (folderIndex < 0) { return; }
|
|
|
|
|
|
|
|
SyncResult::Status state = f->syncResult().status();
|
|
|
|
if (state == SyncResult::SyncPrepare) {
|
|
|
|
_folders[folderIndex]._progress = SubFolderInfo::Progress();
|
|
|
|
} else if (state == SyncResult::Success || state == SyncResult::Problem) {
|
|
|
|
// start a timer to stop the progress display
|
|
|
|
QTimer *timer;
|
|
|
|
timer = new QTimer(this);
|
|
|
|
connect(timer, SIGNAL(timeout()), this, SLOT(slotHideProgress()));
|
|
|
|
connect(timer, SIGNAL(timeout()), timer, SLOT(deleteLater()));
|
|
|
|
timer->setSingleShot(true);
|
|
|
|
timer->setProperty("owncloud_folderIndex", folderIndex);
|
|
|
|
timer->start(5000);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-27 13:46:03 +03:00
|
|
|
|
|
|
|
void FolderStatusModel::resetFolders()
|
|
|
|
{
|
|
|
|
setAccount(_account);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-07-04 21:59:40 +04:00
|
|
|
// ====================================================================================
|
|
|
|
|
|
|
|
FolderStatusDelegate::FolderStatusDelegate()
|
|
|
|
:QStyledItemDelegate()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
FolderStatusDelegate::~FolderStatusDelegate()
|
|
|
|
{
|
|
|
|
// TODO Auto-generated destructor stub
|
|
|
|
}
|
|
|
|
|
|
|
|
//alocate each item size in listview.
|
|
|
|
QSize FolderStatusDelegate::sizeHint(const QStyleOptionViewItem & option ,
|
|
|
|
const QModelIndex & index) const
|
|
|
|
{
|
2015-03-27 13:46:03 +03:00
|
|
|
|
|
|
|
if (static_cast<const FolderStatusModel *>(index.model())->classify(index) != FolderStatusModel::RootFolder) {
|
|
|
|
return QStyledItemDelegate::sizeHint(option, index);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-07-04 21:59:40 +04:00
|
|
|
Q_UNUSED(option)
|
|
|
|
QFont aliasFont = option.font;
|
|
|
|
QFont font = option.font;
|
|
|
|
aliasFont.setPointSize( font.pointSize() +2 );
|
|
|
|
|
|
|
|
QFontMetrics fm(font);
|
|
|
|
QFontMetrics aliasFm(aliasFont);
|
|
|
|
|
|
|
|
int aliasMargin = aliasFm.height()/2;
|
|
|
|
int margin = fm.height()/4;
|
|
|
|
|
|
|
|
// calc height
|
|
|
|
|
|
|
|
int h = aliasMargin; // margin to top
|
|
|
|
h += aliasFm.height(); // alias
|
|
|
|
h += margin; // between alias and local path
|
|
|
|
h += fm.height(); // local path
|
|
|
|
h += margin; // between local and remote path
|
|
|
|
h += fm.height(); // remote path
|
|
|
|
h += aliasMargin; // bottom margin
|
|
|
|
|
|
|
|
// add some space to show an error condition.
|
2013-09-05 21:25:59 +04:00
|
|
|
if( ! qvariant_cast<QStringList>(index.data(FolderErrorMsg)).isEmpty() ) {
|
|
|
|
QStringList errMsgs = qvariant_cast<QStringList>(index.data(FolderErrorMsg));
|
|
|
|
h += aliasMargin*2 + errMsgs.count()*fm.height();
|
2013-07-04 21:59:40 +04:00
|
|
|
}
|
|
|
|
|
2013-07-18 00:32:47 +04:00
|
|
|
if( qvariant_cast<bool>(index.data(AddProgressSpace)) ) {
|
|
|
|
int margin = fm.height()/4;
|
|
|
|
h += (5 * margin); // All the margins
|
|
|
|
h += 2* fm.boundingRect(tr("File")).height();
|
|
|
|
}
|
|
|
|
|
2013-07-04 21:59:40 +04:00
|
|
|
return QSize( 0, h);
|
|
|
|
}
|
|
|
|
|
|
|
|
void FolderStatusDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
|
2013-07-18 00:32:47 +04:00
|
|
|
const QModelIndex &index) const
|
2013-07-04 21:59:40 +04:00
|
|
|
{
|
2015-03-27 13:46:03 +03:00
|
|
|
if (qvariant_cast<bool>(index.data(AddButton))) {
|
|
|
|
painter->drawText(option.rect, "[+ Add Folder]");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-07-04 21:59:40 +04:00
|
|
|
QStyledItemDelegate::paint(painter,option,index);
|
|
|
|
|
2015-03-27 13:46:03 +03:00
|
|
|
if (static_cast<const FolderStatusModel *>(index.model())->classify(index) != FolderStatusModel::RootFolder) {
|
|
|
|
return;
|
|
|
|
}
|
2013-07-04 21:59:40 +04:00
|
|
|
painter->save();
|
|
|
|
|
|
|
|
QFont aliasFont = option.font;
|
|
|
|
QFont subFont = option.font;
|
|
|
|
QFont errorFont = subFont;
|
2013-07-18 00:32:47 +04:00
|
|
|
QFont progressFont = subFont;
|
2013-07-04 21:59:40 +04:00
|
|
|
|
2014-04-27 01:48:12 +04:00
|
|
|
progressFont.setPointSize( subFont.pointSize()-2);
|
2013-07-04 21:59:40 +04:00
|
|
|
//font.setPixelSize(font.weight()+);
|
|
|
|
aliasFont.setBold(true);
|
|
|
|
aliasFont.setPointSize( subFont.pointSize()+2 );
|
|
|
|
|
|
|
|
QFontMetrics subFm( subFont );
|
|
|
|
QFontMetrics aliasFm( aliasFont );
|
2013-07-22 14:57:58 +04:00
|
|
|
QFontMetrics progressFm( progressFont );
|
2013-07-04 21:59:40 +04:00
|
|
|
|
|
|
|
int aliasMargin = aliasFm.height()/2;
|
|
|
|
int margin = subFm.height()/4;
|
|
|
|
|
2013-08-02 16:22:01 +04:00
|
|
|
QIcon statusIcon = qvariant_cast<QIcon>(index.data(FolderStatusIconRole));
|
|
|
|
QString aliasText = qvariant_cast<QString>(index.data(FolderAliasRole));
|
|
|
|
QString pathText = qvariant_cast<QString>(index.data(FolderPathRole));
|
|
|
|
QString remotePath = qvariant_cast<QString>(index.data(FolderSecondPathRole));
|
2013-09-05 21:25:59 +04:00
|
|
|
QStringList errorTexts= qvariant_cast<QStringList>(index.data(FolderErrorMsg));
|
2013-07-22 14:57:58 +04:00
|
|
|
|
2013-07-24 16:40:34 +04:00
|
|
|
int overallPercent = qvariant_cast<int>(index.data(SyncProgressOverallPercent));
|
|
|
|
QString overallString = qvariant_cast<QString>(index.data(SyncProgressOverallString));
|
|
|
|
QString itemString = qvariant_cast<QString>(index.data(SyncProgressItemString));
|
2013-08-02 16:22:01 +04:00
|
|
|
int warningCount = qvariant_cast<int>(index.data(WarningCount));
|
|
|
|
bool syncOngoing = qvariant_cast<bool>(index.data(SyncRunning));
|
2014-08-19 16:06:28 +04:00
|
|
|
|
2013-07-04 21:59:40 +04:00
|
|
|
// QString statusText = qvariant_cast<QString>(index.data(FolderStatus));
|
2014-08-19 16:06:28 +04:00
|
|
|
bool syncEnabled = index.data(FolderAccountConnected).toBool();
|
2013-07-04 21:59:40 +04:00
|
|
|
// QString syncStatus = syncEnabled? tr( "Enabled" ) : tr( "Disabled" );
|
|
|
|
|
|
|
|
QRect iconRect = option.rect;
|
|
|
|
QRect aliasRect = option.rect;
|
|
|
|
|
2015-03-27 13:46:03 +03:00
|
|
|
iconRect.setLeft( option.rect.left() + aliasMargin );
|
2013-07-04 21:59:40 +04:00
|
|
|
iconRect.setTop( iconRect.top() + aliasMargin ); // (iconRect.height()-iconsize.height())/2);
|
|
|
|
|
2013-07-07 03:24:42 +04:00
|
|
|
// alias box
|
2013-07-04 21:59:40 +04:00
|
|
|
aliasRect.setTop(aliasRect.top() + aliasMargin );
|
|
|
|
aliasRect.setBottom(aliasRect.top() + aliasFm.height());
|
|
|
|
aliasRect.setRight(aliasRect.right() - aliasMargin );
|
|
|
|
|
|
|
|
// remote directory box
|
2013-07-07 03:24:42 +04:00
|
|
|
QRect remotePathRect = aliasRect;
|
|
|
|
remotePathRect.setTop(aliasRect.bottom() + margin );
|
|
|
|
remotePathRect.setBottom(remotePathRect.top() + subFm.height());
|
2013-07-04 21:59:40 +04:00
|
|
|
|
2013-07-07 03:24:42 +04:00
|
|
|
// local directory box
|
|
|
|
QRect localPathRect = remotePathRect;
|
|
|
|
localPathRect.setTop( remotePathRect.bottom() + margin );
|
|
|
|
localPathRect.setBottom( localPathRect.top() + subFm.height());
|
|
|
|
|
|
|
|
iconRect.setBottom(localPathRect.bottom());
|
2013-07-04 21:59:40 +04:00
|
|
|
iconRect.setWidth(iconRect.height());
|
|
|
|
|
|
|
|
int nextToIcon = iconRect.right()+aliasMargin;
|
|
|
|
aliasRect.setLeft(nextToIcon);
|
|
|
|
localPathRect.setLeft(nextToIcon);
|
|
|
|
remotePathRect.setLeft(nextToIcon);
|
|
|
|
|
|
|
|
int iconSize = iconRect.width();
|
|
|
|
|
|
|
|
QPixmap pm = statusIcon.pixmap(iconSize, iconSize, syncEnabled ? QIcon::Normal : QIcon::Disabled );
|
|
|
|
painter->drawPixmap(QPoint(iconRect.left(), iconRect.top()), pm);
|
|
|
|
|
2013-08-02 16:22:01 +04:00
|
|
|
// only show the warning icon if the sync is running. Otherwise its
|
|
|
|
// encoded in the status icon.
|
|
|
|
if( warningCount > 0 && syncOngoing) {
|
|
|
|
QRect warnRect;
|
|
|
|
warnRect.setLeft(iconRect.left());
|
|
|
|
warnRect.setTop(iconRect.bottom()-17);
|
|
|
|
warnRect.setWidth(16);
|
|
|
|
warnRect.setHeight(16);
|
|
|
|
|
2015-02-12 21:44:30 +03:00
|
|
|
QIcon warnIcon(":/client/resources/warning");
|
2013-08-02 16:22:01 +04:00
|
|
|
QPixmap pm = warnIcon.pixmap(16,16, syncEnabled ? QIcon::Normal : QIcon::Disabled );
|
|
|
|
painter->drawPixmap(QPoint(warnRect.left(), warnRect.top()),pm );
|
|
|
|
}
|
|
|
|
|
2015-01-05 14:17:05 +03:00
|
|
|
auto palette = option.palette;
|
|
|
|
|
|
|
|
if (qApp->style()->inherits("QWindowsVistaStyle")) {
|
|
|
|
// Hack: Windows Vista's light blue is not contrasting enough for white
|
|
|
|
|
|
|
|
// (code from QWindowsVistaStyle::drawControl for CE_ItemViewItem)
|
|
|
|
palette.setColor(QPalette::All, QPalette::HighlightedText, palette.color(QPalette::Active, QPalette::Text));
|
|
|
|
palette.setColor(QPalette::All, QPalette::Highlight, palette.base().color().darker(108));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QPalette::ColorGroup cg = option.state & QStyle::State_Enabled
|
|
|
|
? QPalette::Normal : QPalette::Disabled;
|
|
|
|
if (cg == QPalette::Normal && !(option.state & QStyle::State_Active))
|
|
|
|
cg = QPalette::Inactive;
|
|
|
|
|
|
|
|
if (option.state & QStyle::State_Selected) {
|
|
|
|
painter->setPen(palette.color(cg, QPalette::HighlightedText));
|
2013-07-04 21:59:40 +04:00
|
|
|
} else {
|
2015-01-05 14:17:05 +03:00
|
|
|
painter->setPen(palette.color(cg, QPalette::Text));
|
2013-07-04 21:59:40 +04:00
|
|
|
}
|
|
|
|
QString elidedAlias = aliasFm.elidedText(aliasText, Qt::ElideRight, aliasRect.width());
|
|
|
|
painter->setFont(aliasFont);
|
|
|
|
painter->drawText(aliasRect, elidedAlias);
|
|
|
|
|
|
|
|
painter->setFont(subFont);
|
2013-07-07 03:24:42 +04:00
|
|
|
QString elidedRemotePathText;
|
|
|
|
|
|
|
|
if (remotePath.isEmpty() || remotePath == QLatin1String("/")) {
|
2013-07-22 20:06:27 +04:00
|
|
|
elidedRemotePathText = subFm.elidedText(tr("Syncing all files in your account with"),
|
2013-07-07 03:24:42 +04:00
|
|
|
Qt::ElideRight, remotePathRect.width());
|
|
|
|
} else {
|
|
|
|
elidedRemotePathText = subFm.elidedText(tr("Remote path: %1").arg(remotePath),
|
|
|
|
Qt::ElideMiddle, remotePathRect.width());
|
|
|
|
}
|
|
|
|
painter->drawText(remotePathRect, elidedRemotePathText);
|
|
|
|
|
2013-07-04 21:59:40 +04:00
|
|
|
QString elidedPathText = subFm.elidedText(pathText, Qt::ElideMiddle, localPathRect.width());
|
|
|
|
painter->drawText(localPathRect, elidedPathText);
|
|
|
|
|
|
|
|
// paint an error overlay if there is an error string
|
2013-07-19 19:05:35 +04:00
|
|
|
|
|
|
|
int h = iconRect.bottom();
|
2013-09-05 21:25:59 +04:00
|
|
|
if( !errorTexts.isEmpty() ) {
|
2013-08-15 13:30:39 +04:00
|
|
|
h += aliasMargin;
|
2013-07-04 21:59:40 +04:00
|
|
|
QRect errorRect = localPathRect;
|
|
|
|
errorRect.setLeft( iconRect.left());
|
2013-07-19 19:05:35 +04:00
|
|
|
errorRect.setTop( h );
|
2013-09-05 21:25:59 +04:00
|
|
|
errorRect.setHeight(errorTexts.count() * subFm.height()+aliasMargin);
|
2013-07-04 21:59:40 +04:00
|
|
|
errorRect.setRight( option.rect.right()-aliasMargin );
|
|
|
|
|
|
|
|
painter->setBrush( QColor(0xbb, 0x4d, 0x4d) );
|
|
|
|
painter->setPen( QColor(0xaa, 0xaa, 0xaa));
|
|
|
|
painter->drawRoundedRect( errorRect, 4, 4 );
|
|
|
|
|
|
|
|
painter->setPen( Qt::white );
|
|
|
|
painter->setFont(errorFont);
|
|
|
|
QRect errorTextRect = errorRect;
|
2013-09-05 21:25:59 +04:00
|
|
|
errorTextRect.setLeft( errorTextRect.left()+aliasMargin );
|
2013-07-04 21:59:40 +04:00
|
|
|
errorTextRect.setTop( errorTextRect.top()+aliasMargin/2 );
|
|
|
|
|
2013-09-05 21:25:59 +04:00
|
|
|
int x = errorTextRect.left();
|
|
|
|
int y = errorTextRect.top()+aliasMargin/2 + subFm.height()/2;
|
|
|
|
|
|
|
|
foreach( QString eText, errorTexts ) {
|
|
|
|
painter->drawText(x, y, subFm.elidedText( eText, Qt::ElideLeft, errorTextRect.width()-2*aliasMargin));
|
|
|
|
y += subFm.height();
|
2013-07-04 21:59:40 +04:00
|
|
|
}
|
2013-07-19 19:05:35 +04:00
|
|
|
|
|
|
|
h = errorRect.bottom();
|
2013-07-04 21:59:40 +04:00
|
|
|
}
|
2013-07-19 19:05:35 +04:00
|
|
|
h += aliasMargin;
|
|
|
|
|
2013-07-22 14:57:58 +04:00
|
|
|
// Sync File Progress Bar: Show it if syncFile is not empty.
|
2014-08-15 17:00:10 +04:00
|
|
|
if( !overallString.isEmpty() || !itemString.isEmpty()) {
|
2013-07-19 19:05:35 +04:00
|
|
|
int fileNameTextHeight = subFm.boundingRect(tr("File")).height();
|
2014-04-28 19:49:27 +04:00
|
|
|
int barHeight = qMax(fileNameTextHeight, aliasFm.height()+4); ;
|
2013-07-19 19:05:35 +04:00
|
|
|
int overallWidth = option.rect.width()-2*aliasMargin;
|
|
|
|
|
|
|
|
painter->save();
|
2013-07-04 21:59:40 +04:00
|
|
|
|
2013-07-19 19:05:35 +04:00
|
|
|
// Sizes-Text
|
2014-07-23 16:09:28 +04:00
|
|
|
QRect octetRect = progressFm.boundingRect(QRect(), 0, overallString );
|
2013-10-15 16:57:14 +04:00
|
|
|
int progressTextWidth = octetRect.width() + 2;
|
2013-07-19 19:05:35 +04:00
|
|
|
|
2013-07-22 14:57:58 +04:00
|
|
|
// Overall Progress Bar.
|
2013-07-19 19:05:35 +04:00
|
|
|
QRect pBRect;
|
|
|
|
pBRect.setTop( h );
|
|
|
|
pBRect.setLeft( iconRect.left());
|
|
|
|
pBRect.setHeight(barHeight);
|
|
|
|
pBRect.setWidth( overallWidth - progressTextWidth - margin );
|
|
|
|
|
|
|
|
QStyleOptionProgressBarV2 pBarOpt;
|
2013-08-18 00:56:02 +04:00
|
|
|
|
2013-07-19 19:05:35 +04:00
|
|
|
pBarOpt.state = option.state | QStyle::State_Horizontal;
|
|
|
|
pBarOpt.minimum = 0;
|
|
|
|
pBarOpt.maximum = 100;
|
|
|
|
pBarOpt.progress = overallPercent;
|
|
|
|
pBarOpt.orientation = Qt::Horizontal;
|
2015-01-05 14:17:05 +03:00
|
|
|
pBarOpt.palette = palette;
|
2013-07-19 19:05:35 +04:00
|
|
|
pBarOpt.rect = pBRect;
|
|
|
|
|
|
|
|
QApplication::style()->drawControl( QStyle::CE_ProgressBar, &pBarOpt, painter );
|
|
|
|
|
|
|
|
// Overall Progress Text
|
|
|
|
QRect overallProgressRect;
|
|
|
|
overallProgressRect.setTop( pBRect.top() );
|
|
|
|
overallProgressRect.setHeight( pBRect.height() );
|
|
|
|
overallProgressRect.setLeft( pBRect.right()+margin);
|
|
|
|
overallProgressRect.setWidth( progressTextWidth );
|
|
|
|
painter->setFont(progressFont);
|
2013-08-08 12:42:46 +04:00
|
|
|
|
2013-10-15 16:57:14 +04:00
|
|
|
painter->drawText( overallProgressRect, Qt::AlignRight+Qt::AlignVCenter, overallString);
|
2013-08-18 00:56:02 +04:00
|
|
|
// painter->drawRect(overallProgressRect);
|
2013-07-19 19:05:35 +04:00
|
|
|
|
2013-07-22 14:57:58 +04:00
|
|
|
// Individual File Progress
|
2013-07-19 19:05:35 +04:00
|
|
|
QRect fileRect;
|
|
|
|
fileRect.setTop( pBRect.bottom() + margin);
|
|
|
|
fileRect.setLeft( iconRect.left());
|
2013-07-22 14:57:58 +04:00
|
|
|
fileRect.setWidth(overallWidth);
|
2013-07-19 19:05:35 +04:00
|
|
|
fileRect.setHeight(fileNameTextHeight);
|
2013-10-15 16:57:14 +04:00
|
|
|
QString elidedText = progressFm.elidedText(itemString, Qt::ElideLeft, fileRect.width());
|
2013-07-18 00:32:47 +04:00
|
|
|
|
2013-08-08 12:42:46 +04:00
|
|
|
painter->drawText( fileRect, Qt::AlignLeft+Qt::AlignVCenter, elidedText);
|
2013-07-18 00:32:47 +04:00
|
|
|
|
2013-07-19 13:07:47 +04:00
|
|
|
painter->restore();
|
2013-07-18 00:32:47 +04:00
|
|
|
}
|
2015-03-27 13:46:03 +03:00
|
|
|
|
2013-07-24 16:40:34 +04:00
|
|
|
painter->restore();
|
2013-07-04 21:59:40 +04:00
|
|
|
}
|
|
|
|
|
2015-03-27 13:46:03 +03:00
|
|
|
bool FolderStatusDelegate::editorEvent ( QEvent * event, QAbstractItemModel * model,
|
|
|
|
const QStyleOptionViewItem & option, const QModelIndex & index )
|
2013-07-04 21:59:40 +04:00
|
|
|
{
|
2015-03-27 13:46:03 +03:00
|
|
|
return QStyledItemDelegate::editorEvent(event, model, option, index);
|
2013-07-04 21:59:40 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-11-10 00:34:07 +03:00
|
|
|
} // namespace OCC
|