2013-08-01 16:34:31 +04:00
|
|
|
/*
|
|
|
|
* Copyright (C) by Klaas Freitag <freitag@owncloud.com>
|
|
|
|
*
|
|
|
|
* 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
|
2016-10-25 12:00:07 +03:00
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
2013-08-01 16:34:31 +04:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <QtGui>
|
2013-08-28 22:58:22 +04:00
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
|
|
|
|
#include <QtWidgets>
|
|
|
|
#endif
|
2013-08-01 16:34:31 +04:00
|
|
|
|
2014-07-11 02:31:24 +04:00
|
|
|
#include "protocolwidget.h"
|
2014-11-10 01:25:57 +03:00
|
|
|
#include "configfile.h"
|
2014-07-11 02:31:24 +04:00
|
|
|
#include "syncresult.h"
|
|
|
|
#include "logger.h"
|
|
|
|
#include "utility.h"
|
|
|
|
#include "theme.h"
|
|
|
|
#include "folderman.h"
|
|
|
|
#include "syncfileitem.h"
|
|
|
|
#include "folder.h"
|
2014-07-07 17:49:48 +04:00
|
|
|
#include "openfilemanager.h"
|
2015-08-11 14:31:19 +03:00
|
|
|
#include "owncloudpropagator.h"
|
2015-11-06 13:43:43 +03:00
|
|
|
#include "activityitemdelegate.h"
|
2013-08-01 16:34:31 +04:00
|
|
|
|
2013-10-08 16:12:05 +04:00
|
|
|
#include "ui_protocolwidget.h"
|
2013-08-01 16:34:31 +04:00
|
|
|
|
2014-10-09 13:03:07 +04:00
|
|
|
#include <climits>
|
|
|
|
|
2014-11-10 00:34:07 +03:00
|
|
|
namespace OCC {
|
2013-08-01 16:34:31 +04:00
|
|
|
|
2013-10-08 16:12:05 +04:00
|
|
|
ProtocolWidget::ProtocolWidget(QWidget *parent) :
|
|
|
|
QWidget(parent),
|
2014-03-14 21:29:23 +04:00
|
|
|
IgnoredIndicatorRole( Qt::UserRole +1 ),
|
2013-10-08 16:12:05 +04:00
|
|
|
_ui(new Ui::ProtocolWidget)
|
2013-08-01 16:34:31 +04:00
|
|
|
{
|
|
|
|
_ui->setupUi(this);
|
2013-10-08 16:12:05 +04:00
|
|
|
|
2015-01-30 15:36:20 +03:00
|
|
|
connect(ProgressDispatcher::instance(), SIGNAL(progressInfo(QString,ProgressInfo)),
|
|
|
|
this, SLOT(slotProgressInfo(QString,ProgressInfo)));
|
2015-08-11 14:45:02 +03:00
|
|
|
connect(ProgressDispatcher::instance(), SIGNAL(itemCompleted(QString,SyncFileItem,PropagatorJob)),
|
|
|
|
this, SLOT(slotItemCompleted(QString,SyncFileItem,PropagatorJob)));
|
2013-08-01 16:34:31 +04:00
|
|
|
|
2013-10-02 20:16:24 +04:00
|
|
|
connect(_ui->_treeWidget, SIGNAL(itemActivated(QTreeWidgetItem*,int)), SLOT(slotOpenFile(QTreeWidgetItem*,int)));
|
|
|
|
|
2013-09-30 16:12:59 +04:00
|
|
|
// Adjust copyToClipboard() when making changes here!
|
2013-08-01 16:34:31 +04:00
|
|
|
QStringList header;
|
2013-08-15 13:30:39 +04:00
|
|
|
header << tr("Time");
|
2013-08-01 16:34:31 +04:00
|
|
|
header << tr("File");
|
2013-08-14 20:23:40 +04:00
|
|
|
header << tr("Folder");
|
2013-08-01 16:34:31 +04:00
|
|
|
header << tr("Action");
|
|
|
|
header << tr("Size");
|
|
|
|
|
2016-05-12 11:22:05 +03:00
|
|
|
int timestampColumnExtra = 0;
|
|
|
|
#ifdef Q_OS_WIN
|
|
|
|
timestampColumnExtra = 20; // font metrics are broken on Windows, see #4721
|
|
|
|
#endif
|
|
|
|
|
2013-08-01 16:34:31 +04:00
|
|
|
_ui->_treeWidget->setHeaderLabels( header );
|
2016-04-28 08:36:50 +03:00
|
|
|
int timestampColumnWidth =
|
2016-05-12 11:22:05 +03:00
|
|
|
_ui->_treeWidget->fontMetrics().width(timeString(QDateTime::currentDateTime()))
|
|
|
|
+ timestampColumnExtra;
|
2016-04-28 08:36:50 +03:00
|
|
|
_ui->_treeWidget->setColumnWidth(0, timestampColumnWidth);
|
2013-08-01 16:34:31 +04:00
|
|
|
_ui->_treeWidget->setColumnWidth(1, 180);
|
2013-08-14 20:23:40 +04:00
|
|
|
_ui->_treeWidget->setColumnCount(5);
|
|
|
|
_ui->_treeWidget->setRootIsDecorated(false);
|
2013-12-05 19:40:37 +04:00
|
|
|
_ui->_treeWidget->setTextElideMode(Qt::ElideMiddle);
|
2013-12-12 18:16:19 +04:00
|
|
|
_ui->_treeWidget->header()->setObjectName("ActivityListHeader");
|
2014-02-14 06:02:59 +04:00
|
|
|
#if defined(Q_OS_MAC)
|
|
|
|
_ui->_treeWidget->setMinimumWidth(400);
|
|
|
|
#endif
|
2015-11-10 17:12:35 +03:00
|
|
|
_ui->_headerLabel->setText(tr("Local sync protocol"));
|
2013-08-01 16:34:31 +04:00
|
|
|
|
2015-11-10 17:12:35 +03:00
|
|
|
QPushButton *copyBtn = _ui->_dialogButtonBox->addButton(tr("Copy"), QDialogButtonBox::ActionRole);
|
|
|
|
copyBtn->setToolTip( tr("Copy the activity list to the clipboard."));
|
|
|
|
copyBtn->setEnabled(true);
|
|
|
|
connect(copyBtn, SIGNAL(clicked()), SIGNAL(copyToClipboard()));
|
2015-11-06 13:43:43 +03:00
|
|
|
|
2015-11-10 17:12:35 +03:00
|
|
|
// this view is used to display all errors such as real errors, soft errors and ignored files
|
|
|
|
// it is instantiated here, but made accessible via the method issueWidget() so that it can
|
|
|
|
// be embedded into another gui element.
|
2015-11-06 13:43:43 +03:00
|
|
|
_issueItemView = new QTreeWidget(this);
|
|
|
|
header.removeLast();
|
|
|
|
_issueItemView->setHeaderLabels( header );
|
2016-04-28 08:36:50 +03:00
|
|
|
timestampColumnWidth =
|
|
|
|
ActivityItemDelegate::rowHeight() // icon
|
2016-05-12 11:22:05 +03:00
|
|
|
+ _issueItemView->fontMetrics().width(timeString(QDateTime::currentDateTime()))
|
|
|
|
+ timestampColumnExtra;
|
2016-04-28 08:36:50 +03:00
|
|
|
_issueItemView->setColumnWidth(0, timestampColumnWidth);
|
2015-11-06 13:43:43 +03:00
|
|
|
_issueItemView->setColumnWidth(1, 180);
|
|
|
|
_issueItemView->setColumnCount(4);
|
|
|
|
_issueItemView->setRootIsDecorated(false);
|
|
|
|
_issueItemView->setTextElideMode(Qt::ElideMiddle);
|
|
|
|
_issueItemView->header()->setObjectName("ActivityErrorListHeader");
|
2016-11-18 18:19:36 +03:00
|
|
|
connect(_issueItemView, SIGNAL(itemActivated(QTreeWidgetItem*,int)),
|
|
|
|
SLOT(slotOpenFile(QTreeWidgetItem*,int)));
|
2013-08-06 20:06:05 +04:00
|
|
|
}
|
|
|
|
|
2013-10-08 16:12:05 +04:00
|
|
|
ProtocolWidget::~ProtocolWidget()
|
2013-08-01 16:34:31 +04:00
|
|
|
{
|
|
|
|
delete _ui;
|
|
|
|
}
|
|
|
|
|
2015-03-23 20:22:12 +03:00
|
|
|
void ProtocolWidget::showEvent(QShowEvent *ev)
|
|
|
|
{
|
|
|
|
ConfigFile cfg;
|
|
|
|
cfg.restoreGeometryHeader(_ui->_treeWidget->header());
|
|
|
|
QWidget::showEvent(ev);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ProtocolWidget::hideEvent(QHideEvent *ev)
|
|
|
|
{
|
|
|
|
ConfigFile cfg;
|
|
|
|
cfg.saveGeometryHeader(_ui->_treeWidget->header() );
|
|
|
|
QWidget::hideEvent(ev);
|
|
|
|
}
|
|
|
|
|
2016-01-06 20:39:32 +03:00
|
|
|
void ProtocolWidget::cleanItems(const QString& folder)
|
2013-12-03 17:03:45 +04:00
|
|
|
{
|
2016-01-06 20:39:32 +03:00
|
|
|
// The issue list is a state, clear it and let the next sync fill it
|
|
|
|
// with ignored files and propagation errors.
|
2016-06-17 20:06:39 +03:00
|
|
|
int itemCnt = _issueItemView->topLevelItemCount();
|
2016-01-07 18:14:12 +03:00
|
|
|
for( int cnt = itemCnt-1; cnt >=0 ; cnt-- ) {
|
|
|
|
QTreeWidgetItem *item = _issueItemView->topLevelItem(cnt);
|
|
|
|
QString itemFolder = item->data(2, Qt::UserRole).toString();
|
|
|
|
if( itemFolder == folder ) {
|
|
|
|
delete item;
|
|
|
|
}
|
|
|
|
}
|
2016-04-18 17:48:37 +03:00
|
|
|
// update the tabtext
|
|
|
|
emit( issueItemCountUpdated(_issueItemView->topLevelItemCount()) );
|
2013-08-01 16:34:31 +04:00
|
|
|
}
|
|
|
|
|
2013-10-08 16:12:05 +04:00
|
|
|
QString ProtocolWidget::timeString(QDateTime dt, QLocale::FormatType format) const
|
2013-08-13 18:53:39 +04:00
|
|
|
{
|
2015-03-27 11:07:21 +03:00
|
|
|
const QLocale loc = QLocale::system();
|
|
|
|
QString dtFormat = loc.dateTimeFormat(format);
|
2015-04-10 13:11:35 +03:00
|
|
|
static const QRegExp re("(HH|H|hh|h):mm(?!:s)");
|
|
|
|
dtFormat.replace(re, "\\1:mm:ss");
|
2015-03-27 11:07:21 +03:00
|
|
|
return loc.toString(dt, dtFormat);
|
2013-08-13 18:53:39 +04:00
|
|
|
}
|
|
|
|
|
2013-10-08 16:12:05 +04:00
|
|
|
void ProtocolWidget::slotOpenFile( QTreeWidgetItem *item, int )
|
2013-10-02 20:16:24 +04:00
|
|
|
{
|
2015-08-17 12:39:45 +03:00
|
|
|
QString folderName = item->data(2, Qt::UserRole).toString();
|
2013-10-02 20:16:24 +04:00
|
|
|
QString fileName = item->text(1);
|
|
|
|
|
|
|
|
Folder *folder = FolderMan::instance()->folder(folderName);
|
|
|
|
if (folder) {
|
2013-12-17 13:16:25 +04:00
|
|
|
// folder->path() always comes back with trailing path
|
|
|
|
QString fullPath = folder->path() + fileName;
|
2013-10-02 20:16:24 +04:00
|
|
|
if (QFile(fullPath).exists()) {
|
2014-07-07 17:49:48 +04:00
|
|
|
showInFileManager(fullPath);
|
2013-10-02 20:16:24 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-14 16:03:16 +04:00
|
|
|
QTreeWidgetItem* ProtocolWidget::createCompletedTreewidgetItem(const QString& folder, const SyncFileItem& item)
|
2013-11-26 15:22:28 +04:00
|
|
|
{
|
2015-08-17 12:39:45 +03:00
|
|
|
auto f = FolderMan::instance()->folder(folder);
|
|
|
|
if (!f) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-11-26 15:22:28 +04:00
|
|
|
QStringList columns;
|
2014-03-14 16:03:16 +04:00
|
|
|
QDateTime timestamp = QDateTime::currentDateTime();
|
|
|
|
const QString timeStr = timeString(timestamp);
|
|
|
|
const QString longTimeStr = timeString(timestamp, QLocale::LongFormat);
|
2013-11-26 15:22:28 +04:00
|
|
|
|
|
|
|
columns << timeStr;
|
2015-10-19 15:36:55 +03:00
|
|
|
columns << Utility::fileNameForGuiUse(item._originalFile);
|
2016-04-26 17:38:03 +03:00
|
|
|
columns << f->shortGuiLocalPath();
|
2014-03-14 20:18:26 +04:00
|
|
|
|
2015-03-12 11:32:44 +03:00
|
|
|
// If the error string is set, it's prefered because it is a useful user message.
|
|
|
|
QString message = item._errorString;
|
|
|
|
if (message.isEmpty()) {
|
|
|
|
message = Progress::asResultString(item);
|
|
|
|
}
|
|
|
|
columns << message;
|
|
|
|
|
|
|
|
QIcon icon;
|
|
|
|
if (item._status == SyncFileItem::NormalError
|
|
|
|
|| item._status == SyncFileItem::FatalError) {
|
|
|
|
icon = Theme::instance()->syncStateIcon(SyncResult::Error);
|
|
|
|
} else if (Progress::isWarningKind(item._status)) {
|
|
|
|
icon = Theme::instance()->syncStateIcon(SyncResult::Problem);
|
|
|
|
}
|
|
|
|
|
2015-01-30 15:36:20 +03:00
|
|
|
if (ProgressInfo::isSizeDependent(item)) {
|
2015-03-12 11:32:44 +03:00
|
|
|
columns << Utility::octetsToString( item._size );
|
2014-03-14 16:03:16 +04:00
|
|
|
}
|
2013-11-26 15:22:28 +04:00
|
|
|
|
2014-03-14 16:03:16 +04:00
|
|
|
QTreeWidgetItem *twitem = new QTreeWidgetItem(columns);
|
2014-03-14 20:18:26 +04:00
|
|
|
if (item._status == SyncFileItem::FileIgnored) {
|
|
|
|
// Tell that we want to remove it on the next sync.
|
2014-03-14 21:29:23 +04:00
|
|
|
twitem->setData(0, IgnoredIndicatorRole, true);
|
2014-03-14 20:18:26 +04:00
|
|
|
}
|
|
|
|
|
2015-11-06 13:43:43 +03:00
|
|
|
twitem->setData(0, Qt::SizeHintRole, QSize(0, ActivityItemDelegate::rowHeight()));
|
2014-03-14 20:18:26 +04:00
|
|
|
twitem->setIcon(0, icon);
|
2014-03-14 16:03:16 +04:00
|
|
|
twitem->setToolTip(0, longTimeStr);
|
2014-03-14 20:18:26 +04:00
|
|
|
twitem->setToolTip(1, item._file);
|
|
|
|
twitem->setToolTip(3, message );
|
2015-08-17 12:39:45 +03:00
|
|
|
twitem->setData(2, Qt::UserRole, folder);
|
2014-03-14 16:03:16 +04:00
|
|
|
return twitem;
|
2013-11-26 15:22:28 +04:00
|
|
|
}
|
|
|
|
|
2015-01-30 15:36:20 +03:00
|
|
|
void ProtocolWidget::slotProgressInfo( const QString& folder, const ProgressInfo& progress )
|
2013-08-01 16:34:31 +04:00
|
|
|
{
|
2016-05-20 16:07:54 +03:00
|
|
|
if( !progress.isUpdatingEstimates() ) {
|
2014-03-14 21:29:23 +04:00
|
|
|
// The sync is restarting, clean the old items
|
2016-01-06 20:39:32 +03:00
|
|
|
cleanItems(folder);
|
2015-01-30 15:36:20 +03:00
|
|
|
} else if (progress.completedFiles() >= progress.totalFiles()) {
|
2014-03-14 21:29:23 +04:00
|
|
|
//Sync completed
|
2013-08-01 16:34:31 +04:00
|
|
|
}
|
2015-08-11 14:31:19 +03:00
|
|
|
}
|
2013-08-01 16:34:31 +04:00
|
|
|
|
2015-08-11 14:45:02 +03:00
|
|
|
void ProtocolWidget::slotItemCompleted(const QString &folder, const SyncFileItem &item, const PropagatorJob &job)
|
2015-08-11 14:31:19 +03:00
|
|
|
{
|
|
|
|
if (qobject_cast<const PropagateDirectory*>(&job)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QTreeWidgetItem *line = createCompletedTreewidgetItem(folder, item);
|
|
|
|
if(line) {
|
2015-11-06 13:43:43 +03:00
|
|
|
if( item.hasErrorStatus() ) {
|
|
|
|
_issueItemView->insertTopLevelItem(0, line);
|
2016-04-05 14:57:38 +03:00
|
|
|
emit issueItemCountUpdated(_issueItemView->topLevelItemCount());
|
2015-11-06 13:43:43 +03:00
|
|
|
} else {
|
2016-06-17 20:06:39 +03:00
|
|
|
// Limit the number of items
|
|
|
|
int itemCnt = _ui->_treeWidget->topLevelItemCount();
|
|
|
|
while(itemCnt > 2000) {
|
|
|
|
delete _ui->_treeWidget->takeTopLevelItem(itemCnt - 1);
|
|
|
|
itemCnt--;
|
|
|
|
}
|
2015-11-06 13:43:43 +03:00
|
|
|
_ui->_treeWidget->insertTopLevelItem(0, line);
|
|
|
|
}
|
2015-11-10 17:12:35 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ProtocolWidget::storeSyncActivity(QTextStream& ts)
|
|
|
|
{
|
|
|
|
int topLevelItems = _ui->_treeWidget->topLevelItemCount();
|
|
|
|
|
|
|
|
for (int i = 0; i < topLevelItems; i++) {
|
|
|
|
QTreeWidgetItem *child = _ui->_treeWidget->topLevelItem(i);
|
2015-12-09 17:49:30 +03:00
|
|
|
ts << right
|
2015-11-10 17:12:35 +03:00
|
|
|
// time stamp
|
2015-12-09 17:49:30 +03:00
|
|
|
<< qSetFieldWidth(20)
|
2015-11-10 17:12:35 +03:00
|
|
|
<< child->data(0,Qt::DisplayRole).toString()
|
2015-12-09 17:49:30 +03:00
|
|
|
// separator
|
|
|
|
<< qSetFieldWidth(0) << ","
|
|
|
|
|
2015-11-10 17:12:35 +03:00
|
|
|
// file name
|
|
|
|
<< qSetFieldWidth(64)
|
|
|
|
<< child->data(1,Qt::DisplayRole).toString()
|
2015-12-09 17:49:30 +03:00
|
|
|
// separator
|
|
|
|
<< qSetFieldWidth(0) << ","
|
|
|
|
|
2015-11-10 17:12:35 +03:00
|
|
|
// folder
|
|
|
|
<< qSetFieldWidth(30)
|
|
|
|
<< child->data(2, Qt::DisplayRole).toString()
|
2015-12-09 17:49:30 +03:00
|
|
|
// separator
|
|
|
|
<< qSetFieldWidth(0) << ","
|
|
|
|
|
2015-11-10 17:12:35 +03:00
|
|
|
// action
|
|
|
|
<< qSetFieldWidth(15)
|
|
|
|
<< child->data(3, Qt::DisplayRole).toString()
|
2015-12-09 17:49:30 +03:00
|
|
|
// separator
|
|
|
|
<< qSetFieldWidth(0) << ","
|
|
|
|
|
2015-11-10 17:12:35 +03:00
|
|
|
// size
|
|
|
|
<< qSetFieldWidth(10)
|
|
|
|
<< child->data(4, Qt::DisplayRole).toString()
|
|
|
|
<< qSetFieldWidth(0)
|
|
|
|
<< endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ProtocolWidget::storeSyncIssues(QTextStream& ts)
|
|
|
|
{
|
|
|
|
int topLevelItems = _issueItemView->topLevelItemCount();
|
|
|
|
|
|
|
|
for (int i = 0; i < topLevelItems; i++) {
|
|
|
|
QTreeWidgetItem *child = _issueItemView->topLevelItem(i);
|
2015-12-09 17:49:30 +03:00
|
|
|
ts << right
|
2015-11-10 17:12:35 +03:00
|
|
|
// time stamp
|
2015-12-09 17:49:30 +03:00
|
|
|
<< qSetFieldWidth(20)
|
2015-11-10 17:12:35 +03:00
|
|
|
<< child->data(0,Qt::DisplayRole).toString()
|
2015-12-09 17:49:30 +03:00
|
|
|
// separator
|
|
|
|
<< qSetFieldWidth(0) << ","
|
|
|
|
|
2015-11-10 17:12:35 +03:00
|
|
|
// file name
|
|
|
|
<< qSetFieldWidth(64)
|
|
|
|
<< child->data(1,Qt::DisplayRole).toString()
|
2015-12-09 17:49:30 +03:00
|
|
|
// separator
|
|
|
|
<< qSetFieldWidth(0) << ","
|
|
|
|
|
2015-11-10 17:12:35 +03:00
|
|
|
// folder
|
|
|
|
<< qSetFieldWidth(30)
|
|
|
|
<< child->data(2, Qt::DisplayRole).toString()
|
2015-12-09 17:49:30 +03:00
|
|
|
// separator
|
|
|
|
<< qSetFieldWidth(0) << ","
|
|
|
|
|
2015-11-10 17:12:35 +03:00
|
|
|
// action
|
|
|
|
<< qSetFieldWidth(15)
|
|
|
|
<< child->data(3, Qt::DisplayRole).toString()
|
|
|
|
<< qSetFieldWidth(0)
|
|
|
|
<< endl;
|
2013-11-26 15:22:28 +04:00
|
|
|
}
|
2013-08-01 16:34:31 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|