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
|
|
|
|
* the Free Software Foundation; version 2 of the License.
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
2013-10-08 16:12:05 +04:00
|
|
|
#include "mirall/protocolwidget.h"
|
2013-12-12 18:16:19 +04:00
|
|
|
#include "mirall/mirallconfigfile.h"
|
2013-08-01 16:34:31 +04:00
|
|
|
#include "mirall/syncresult.h"
|
|
|
|
#include "mirall/logger.h"
|
|
|
|
#include "mirall/utility.h"
|
|
|
|
#include "mirall/theme.h"
|
2013-08-02 14:16:21 +04:00
|
|
|
#include "mirall/folderman.h"
|
2013-08-06 20:06:05 +04:00
|
|
|
#include "mirall/syncfileitem.h"
|
2013-12-03 17:03:45 +04:00
|
|
|
#include "mirall/folder.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
|
|
|
|
|
|
|
namespace Mirall {
|
|
|
|
|
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
|
|
|
|
2013-08-01 16:34:31 +04:00
|
|
|
connect(ProgressDispatcher::instance(), SIGNAL(progressInfo(QString,Progress::Info)),
|
|
|
|
this, SLOT(slotProgressInfo(QString,Progress::Info)));
|
|
|
|
|
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");
|
|
|
|
|
|
|
|
_ui->_treeWidget->setHeaderLabels( header );
|
|
|
|
_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");
|
2013-08-01 16:34:31 +04:00
|
|
|
|
|
|
|
connect(this, SIGNAL(guiLog(QString,QString)), Logger::instance(), SIGNAL(guiLog(QString,QString)));
|
|
|
|
|
2013-12-03 17:03:45 +04:00
|
|
|
_clearBlacklistBtn = _ui->_dialogButtonBox->addButton(tr("Retry Sync"), QDialogButtonBox::ActionRole);
|
|
|
|
_clearBlacklistBtn->setEnabled(false);
|
|
|
|
connect(_clearBlacklistBtn, SIGNAL(clicked()), SLOT(slotClearBlacklist()));
|
|
|
|
|
2013-08-01 16:34:31 +04:00
|
|
|
QPushButton *copyBtn = _ui->_dialogButtonBox->addButton(tr("Copy"), QDialogButtonBox::ActionRole);
|
2013-12-03 17:03:45 +04:00
|
|
|
copyBtn->setToolTip( tr("Copy the activity list to the clipboard."));
|
2013-08-01 16:34:31 +04:00
|
|
|
connect(copyBtn, SIGNAL(clicked()), SLOT(copyToClipboard()));
|
2013-12-03 17:03:45 +04:00
|
|
|
|
2013-12-12 18:16:19 +04:00
|
|
|
MirallConfigFile cfg;
|
|
|
|
cfg.restoreGeometryHeader(_ui->_treeWidget->header());
|
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
|
|
|
{
|
2013-12-12 18:16:19 +04:00
|
|
|
MirallConfigFile cfg;
|
|
|
|
cfg.saveGeometryHeader(_ui->_treeWidget->header() );
|
|
|
|
|
2013-08-01 16:34:31 +04:00
|
|
|
delete _ui;
|
|
|
|
}
|
|
|
|
|
2013-10-08 16:12:05 +04:00
|
|
|
void ProtocolWidget::copyToClipboard()
|
2013-08-01 16:34:31 +04:00
|
|
|
{
|
|
|
|
QString text;
|
|
|
|
QTextStream ts(&text);
|
|
|
|
|
|
|
|
int topLevelItems = _ui->_treeWidget->topLevelItemCount();
|
|
|
|
for (int i = 0; i < topLevelItems; i++) {
|
2013-08-22 18:20:04 +04:00
|
|
|
QTreeWidgetItem *child = _ui->_treeWidget->topLevelItem(i);
|
2013-09-30 16:12:59 +04:00
|
|
|
ts << left
|
|
|
|
// time stamp
|
|
|
|
<< qSetFieldWidth(10)
|
2013-08-22 18:20:04 +04:00
|
|
|
<< child->data(0,Qt::DisplayRole).toString()
|
|
|
|
// file name
|
|
|
|
<< qSetFieldWidth(64)
|
|
|
|
<< child->data(1,Qt::DisplayRole).toString()
|
2013-09-30 16:12:59 +04:00
|
|
|
// folder
|
|
|
|
<< qSetFieldWidth(15)
|
|
|
|
<< child->data(2, Qt::DisplayRole).toString()
|
2013-08-22 18:20:04 +04:00
|
|
|
// action
|
|
|
|
<< qSetFieldWidth(15)
|
|
|
|
<< child->data(3, Qt::DisplayRole).toString()
|
|
|
|
// size
|
|
|
|
<< qSetFieldWidth(10)
|
|
|
|
<< child->data(4, Qt::DisplayRole).toString()
|
|
|
|
<< qSetFieldWidth(0)
|
|
|
|
<< endl;
|
2013-08-01 16:34:31 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
QApplication::clipboard()->setText(text);
|
2013-11-19 18:27:07 +04:00
|
|
|
emit guiLog(tr("Copied to clipboard"), tr("The sync status has been copied to the clipboard."));
|
2013-08-01 16:34:31 +04:00
|
|
|
}
|
|
|
|
|
2013-12-03 17:03:45 +04:00
|
|
|
void ProtocolWidget::slotClearBlacklist()
|
2013-08-01 16:34:31 +04:00
|
|
|
{
|
2013-12-03 17:03:45 +04:00
|
|
|
FolderMan *folderMan = FolderMan::instance();
|
|
|
|
|
|
|
|
Folder::Map folders = folderMan->map();
|
|
|
|
|
|
|
|
foreach( Folder *f, folders ) {
|
|
|
|
int num = f->slotWipeBlacklist();
|
|
|
|
qDebug() << num << "entries were removed from"<< f->alias() << "blacklist";
|
|
|
|
}
|
|
|
|
|
|
|
|
folderMan->slotScheduleAllFolders();
|
|
|
|
}
|
|
|
|
|
2014-03-14 21:29:23 +04:00
|
|
|
void ProtocolWidget::cleanIgnoreItems(const QString& folder)
|
2013-12-03 17:03:45 +04:00
|
|
|
{
|
2013-08-14 20:23:40 +04:00
|
|
|
int itemCnt = _ui->_treeWidget->topLevelItemCount();
|
2014-03-14 21:29:23 +04:00
|
|
|
for( int cnt = itemCnt-1; cnt >=0 ; cnt-- ) {
|
2013-08-14 20:23:40 +04:00
|
|
|
QTreeWidgetItem *item = _ui->_treeWidget->topLevelItem(cnt);
|
2014-03-14 21:29:23 +04:00
|
|
|
bool isErrorItem = item->data(0, IgnoredIndicatorRole).toBool();
|
2013-10-02 20:24:03 +04:00
|
|
|
QString itemFolder = item->data(2, Qt::DisplayRole).toString();
|
|
|
|
if( isErrorItem && itemFolder == folder ) {
|
2014-03-14 21:29:23 +04:00
|
|
|
delete item;
|
2013-08-14 20:23:40 +04:00
|
|
|
}
|
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
|
|
|
{
|
|
|
|
QLocale loc = QLocale::system();
|
|
|
|
QString timeStr;
|
|
|
|
QDate today = QDate::currentDate();
|
|
|
|
|
|
|
|
if( format == QLocale::NarrowFormat ) {
|
|
|
|
if( dt.date().day() == today.day() ) {
|
|
|
|
timeStr = loc.toString(dt.time(), QLocale::NarrowFormat);
|
|
|
|
} else {
|
|
|
|
timeStr = loc.toString(dt, QLocale::NarrowFormat);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
timeStr = loc.toString(dt, format);
|
|
|
|
}
|
|
|
|
return timeStr;
|
|
|
|
}
|
|
|
|
|
2013-10-08 16:12:05 +04:00
|
|
|
void ProtocolWidget::slotOpenFile( QTreeWidgetItem *item, int )
|
2013-10-02 20:16:24 +04:00
|
|
|
{
|
|
|
|
QString folderName = item->text(2);
|
|
|
|
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-01-21 15:54:41 +04:00
|
|
|
Utility::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
|
|
|
{
|
|
|
|
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);
|
2014-03-14 20:18:26 +04:00
|
|
|
QIcon icon;
|
|
|
|
QString message;
|
2013-11-26 15:22:28 +04:00
|
|
|
|
|
|
|
columns << timeStr;
|
2014-03-14 16:03:16 +04:00
|
|
|
columns << item._file;
|
|
|
|
columns << folder;
|
2014-03-14 20:18:26 +04:00
|
|
|
if (Progress::isWarningKind(item._status)) {
|
|
|
|
message= item._errorString;
|
|
|
|
columns << message;
|
|
|
|
if (item._status == SyncFileItem::NormalError || item._status == SyncFileItem::FatalError) {
|
|
|
|
icon = Theme::instance()->syncStateIcon(SyncResult::Error);
|
|
|
|
} else {
|
|
|
|
icon = Theme::instance()->syncStateIcon(SyncResult::Problem);
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
message = Progress::asResultString(item);
|
|
|
|
columns << message;
|
|
|
|
if (Progress::isSizeDependent(item._instruction)) {
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
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 );
|
2014-03-14 16:03:16 +04:00
|
|
|
return twitem;
|
2013-11-26 15:22:28 +04:00
|
|
|
}
|
|
|
|
|
2013-12-03 17:48:38 +04:00
|
|
|
void ProtocolWidget::computeResyncButtonEnabled()
|
|
|
|
{
|
|
|
|
FolderMan *folderMan = FolderMan::instance();
|
|
|
|
Folder::Map folders = folderMan->map();
|
|
|
|
|
|
|
|
int cnt = 0;
|
|
|
|
foreach( Folder *f, folders ) {
|
|
|
|
cnt += f->blackListEntryCount();
|
|
|
|
}
|
2013-12-04 14:32:46 +04:00
|
|
|
|
|
|
|
QString t = tr("Currently no files are ignored because of previous errors.");
|
|
|
|
if(cnt > 0) {
|
|
|
|
t = tr("%1 files are ignored because of previous errors.\n Try to sync these again.").arg(cnt);
|
|
|
|
}
|
|
|
|
|
2013-12-03 17:48:38 +04:00
|
|
|
_clearBlacklistBtn->setEnabled(cnt > 0);
|
2013-12-04 14:32:46 +04:00
|
|
|
_clearBlacklistBtn->setToolTip(t);
|
2013-12-03 17:48:38 +04:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-10-08 16:12:05 +04:00
|
|
|
void ProtocolWidget::slotProgressInfo( const QString& folder, const Progress::Info& progress )
|
2013-08-01 16:34:31 +04:00
|
|
|
{
|
2014-03-14 21:29:23 +04:00
|
|
|
if( progress._completedFileCount == 0 ) {
|
|
|
|
// The sync is restarting, clean the old items
|
|
|
|
cleanIgnoreItems(folder);
|
|
|
|
computeResyncButtonEnabled();
|
|
|
|
} else if (progress._totalFileCount == progress._completedFileCount) {
|
|
|
|
//Sync completed
|
2013-12-03 17:48:38 +04:00
|
|
|
computeResyncButtonEnabled();
|
2013-08-01 16:34:31 +04:00
|
|
|
}
|
2014-03-14 16:03:16 +04:00
|
|
|
SyncFileItem last = progress._lastCompletedItem;
|
|
|
|
if (last.isEmpty()) return;
|
2013-08-01 16:34:31 +04:00
|
|
|
|
2014-03-14 16:03:16 +04:00
|
|
|
QTreeWidgetItem *item = createCompletedTreewidgetItem(folder, last);
|
2013-11-26 15:22:28 +04:00
|
|
|
if(item) {
|
|
|
|
_ui->_treeWidget->insertTopLevelItem(0, item);
|
|
|
|
}
|
2013-08-01 16:34:31 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|