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>
|
|
|
|
|
|
|
|
#include "mirall/itemprogressdialog.h"
|
|
|
|
#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-08-01 16:34:31 +04:00
|
|
|
|
|
|
|
#include "ui_itemprogressdialog.h"
|
|
|
|
|
|
|
|
namespace Mirall {
|
|
|
|
|
2013-08-02 13:33:45 +04:00
|
|
|
ItemProgressDialog::ItemProgressDialog(Application*, QWidget *parent) :
|
2013-08-01 16:34:31 +04:00
|
|
|
QDialog(parent),
|
2013-08-07 16:51:31 +04:00
|
|
|
ErrorIndicatorRole( Qt::UserRole +1 ),
|
|
|
|
_ui(new Ui::ItemProgressDialog)
|
2013-08-01 16:34:31 +04:00
|
|
|
{
|
|
|
|
_ui->setupUi(this);
|
|
|
|
connect(_ui->_dialogButtonBox->button(QDialogButtonBox::Close), SIGNAL(clicked()),
|
|
|
|
this, SLOT(accept()));
|
|
|
|
|
|
|
|
connect(ProgressDispatcher::instance(), SIGNAL(progressInfo(QString,Progress::Info)),
|
|
|
|
this, SLOT(slotProgressInfo(QString,Progress::Info)));
|
|
|
|
connect(ProgressDispatcher::instance(), SIGNAL(progressSyncProblem(const QString&,const Progress::SyncProblem&)),
|
|
|
|
this, SLOT(slotProgressErrors(const QString&, const Progress::SyncProblem&)));
|
|
|
|
|
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-08-01 16:34:31 +04:00
|
|
|
|
|
|
|
connect(this, SIGNAL(guiLog(QString,QString)), Logger::instance(), SIGNAL(guiLog(QString,QString)));
|
|
|
|
|
|
|
|
QPushButton *copyBtn = _ui->_dialogButtonBox->addButton(tr("Copy"), QDialogButtonBox::ActionRole);
|
|
|
|
connect(copyBtn, SIGNAL(clicked()), SLOT(copyToClipboard()));
|
|
|
|
|
|
|
|
setWindowTitle(tr("Sync Protocol"));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-08-06 20:06:05 +04:00
|
|
|
void ItemProgressDialog::setSyncResultStatus(const SyncResult& result )
|
|
|
|
{
|
2013-08-15 14:17:01 +04:00
|
|
|
if( result.errorStrings().count() ) {
|
2013-08-06 20:06:05 +04:00
|
|
|
_ui->_errorLabel->setVisible(true);
|
|
|
|
_ui->_errorLabel->setTextFormat(Qt::RichText);
|
2013-08-15 14:17:01 +04:00
|
|
|
|
2013-08-06 20:06:05 +04:00
|
|
|
QString errStr;
|
2013-08-15 14:17:01 +04:00
|
|
|
QStringList errors = result.errorStrings();
|
|
|
|
int cnt = errors.size();
|
|
|
|
bool appendDots = false;
|
|
|
|
if( cnt > 3 ) {
|
|
|
|
cnt = 3;
|
|
|
|
appendDots = true;
|
2013-08-06 20:06:05 +04:00
|
|
|
}
|
|
|
|
|
2013-08-15 14:17:01 +04:00
|
|
|
for( int i = 0; i < cnt; i++) {
|
|
|
|
errStr.append(QString("%1<br/>").arg(errors.at(i)));
|
|
|
|
}
|
|
|
|
if( appendDots ) {
|
|
|
|
errStr.append(QString("..."));
|
|
|
|
}
|
2013-08-06 20:06:05 +04:00
|
|
|
_ui->_errorLabel->setText(errStr);
|
|
|
|
} else {
|
|
|
|
_ui->_errorLabel->setText(QString::null);
|
|
|
|
_ui->_errorLabel->setVisible(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void ItemProgressDialog::setSyncResult( const SyncResult& result )
|
|
|
|
{
|
|
|
|
setSyncResultStatus(result);
|
|
|
|
|
|
|
|
const QString& folder = result.folder();
|
|
|
|
qDebug() << "Setting sync result for folder " << folder;
|
|
|
|
|
|
|
|
SyncFileItemVector::const_iterator i;
|
|
|
|
const SyncFileItemVector& items = result.syncFileItemVector();
|
2013-08-13 18:53:39 +04:00
|
|
|
QDateTime dt = QDateTime::currentDateTime();
|
2013-08-06 20:06:05 +04:00
|
|
|
|
|
|
|
for (i = items.begin(); i != items.end(); ++i) {
|
|
|
|
const SyncFileItem& item = *i;
|
2013-08-07 14:15:28 +04:00
|
|
|
QString errMsg;
|
2013-08-17 19:57:16 +04:00
|
|
|
QString tooltip;
|
2013-08-15 10:15:30 +04:00
|
|
|
// handle ignored files here.
|
2013-08-17 19:57:16 +04:00
|
|
|
|
|
|
|
if( item._instruction == CSYNC_INSTRUCTION_IGNORE
|
|
|
|
|| item._instruction == CSYNC_INSTRUCTION_CONFLICT ) {
|
2013-08-06 20:06:05 +04:00
|
|
|
QStringList columns;
|
2013-08-13 18:53:39 +04:00
|
|
|
QString timeStr = timeString(dt);
|
|
|
|
QString longTimeStr = timeString(dt, QLocale::LongFormat);
|
2013-08-06 20:06:05 +04:00
|
|
|
|
|
|
|
columns << timeStr;
|
|
|
|
columns << item._file;
|
2013-08-14 20:23:40 +04:00
|
|
|
columns << folder;
|
2013-08-17 19:57:16 +04:00
|
|
|
if( item._instruction == CSYNC_INSTRUCTION_IGNORE) {
|
2013-09-02 19:25:07 +04:00
|
|
|
if( item._type == SyncFileItem::SoftLink ) {
|
2013-09-02 19:37:16 +04:00
|
|
|
errMsg = tr("Soft Link ignored");
|
2013-08-17 19:57:16 +04:00
|
|
|
tooltip = tr("Softlinks break the semantics of synchronization.\nPlease do not "
|
2013-09-02 19:37:16 +04:00
|
|
|
"use them in synced directories");
|
2013-08-17 19:57:16 +04:00
|
|
|
} else {
|
2013-09-02 19:25:07 +04:00
|
|
|
QString obj = tr("file");
|
|
|
|
if( item._type == SyncFileItem::Directory ) {
|
|
|
|
obj = tr("directory");
|
|
|
|
}
|
|
|
|
tooltip = tr("The %1 was ignored because it is listed in the clients ignore list\n"
|
|
|
|
"or the %1 name contains characters that are not syncable\nin a cross platform "
|
2013-09-02 19:37:16 +04:00
|
|
|
"environment").arg(obj);
|
|
|
|
errMsg = tr("Item ignored");
|
2013-09-02 19:25:07 +04:00
|
|
|
if( item._errorString == QLatin1String("File listed on ignore list.") ) {
|
2013-09-02 19:37:16 +04:00
|
|
|
errMsg = tr("%1 on ignore list").arg(obj);
|
|
|
|
tooltip = tr("The %1 was skipped because it is listed on the clients\n"
|
|
|
|
"list of names to ignore").arg(obj);
|
2013-09-02 19:25:07 +04:00
|
|
|
} else if( item._errorString == QLatin1String("File contains invalid characters.") ) {
|
2013-09-02 19:37:16 +04:00
|
|
|
errMsg = tr("Invalid characters");
|
2013-09-02 19:25:07 +04:00
|
|
|
tooltip = tr("The %1 name contains one or more invalid characters which break\n"
|
2013-09-02 19:37:16 +04:00
|
|
|
"syncing in a cross platform environment").arg(obj);
|
2013-09-02 19:25:07 +04:00
|
|
|
}
|
2013-08-17 19:57:16 +04:00
|
|
|
}
|
|
|
|
} else if( item._instruction == CSYNC_INSTRUCTION_CONFLICT ) {
|
|
|
|
errMsg = tr("Conflict file.");
|
|
|
|
tooltip = tr("The file was changed on server and local repository and as a result it\n"
|
|
|
|
"created a so called conflict. The local change is copied to the conflict\n"
|
|
|
|
"file while the file from the server side is available under the original\n"
|
|
|
|
"name");
|
2013-08-07 14:15:28 +04:00
|
|
|
} else {
|
2013-08-17 19:57:16 +04:00
|
|
|
Q_ASSERT(!"unhandled instruction.");
|
2013-08-07 14:15:28 +04:00
|
|
|
}
|
2013-08-06 20:06:05 +04:00
|
|
|
columns << errMsg;
|
|
|
|
|
2013-08-14 20:23:40 +04:00
|
|
|
QTreeWidgetItem *twitem = new QTreeWidgetItem(columns);
|
2013-08-07 14:15:28 +04:00
|
|
|
twitem->setData(0, ErrorIndicatorRole, QVariant(true) );
|
2013-08-13 18:53:39 +04:00
|
|
|
twitem->setToolTip(0, longTimeStr);
|
2013-08-17 19:57:16 +04:00
|
|
|
twitem->setToolTip(3, tooltip);
|
2013-08-07 14:15:28 +04:00
|
|
|
twitem->setIcon(0, Theme::instance()->syncStateIcon(SyncResult::Problem, true));
|
2013-08-26 19:25:33 +04:00
|
|
|
_ui->_treeWidget->insertTopLevelItem(0, twitem);
|
2013-08-06 20:06:05 +04:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-01 16:34:31 +04:00
|
|
|
void ItemProgressDialog::setupList()
|
|
|
|
{
|
2013-08-02 14:16:21 +04:00
|
|
|
// get the folders to set up the top level list.
|
|
|
|
Folder::Map map = FolderMan::instance()->map();
|
2013-08-06 20:06:05 +04:00
|
|
|
SyncResult lastResult;
|
|
|
|
QDateTime dt;
|
|
|
|
bool haveSyncResult = false;
|
|
|
|
|
2013-08-02 14:16:21 +04:00
|
|
|
foreach( Folder *f, map.values() ) {
|
2013-08-06 20:06:05 +04:00
|
|
|
if( f->syncResult().syncTime() > dt ) {
|
|
|
|
dt = f->syncResult().syncTime();
|
|
|
|
lastResult = f->syncResult();
|
|
|
|
haveSyncResult = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( haveSyncResult ) {
|
|
|
|
setSyncResult(lastResult);
|
2013-08-02 14:16:21 +04:00
|
|
|
}
|
|
|
|
|
2013-08-01 16:34:31 +04:00
|
|
|
QList<Progress::Info> progressList = ProgressDispatcher::instance()->recentChangedItems(0); // All.
|
|
|
|
|
|
|
|
QHash <QString, int> folderHash;
|
|
|
|
|
|
|
|
foreach( Progress::Info info, progressList ) {
|
|
|
|
slotProgressInfo( info.folder, info );
|
|
|
|
folderHash[info.folder] = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
QList<Progress::SyncProblem> problemList = ProgressDispatcher::instance()->recentProblems(0);
|
|
|
|
foreach( Progress::SyncProblem prob, problemList ) {
|
|
|
|
slotProgressErrors(prob.folder, prob);
|
|
|
|
folderHash[prob.folder] = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ItemProgressDialog::~ItemProgressDialog()
|
|
|
|
{
|
|
|
|
delete _ui;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ItemProgressDialog::copyToClipboard()
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
emit guiLog(tr("Copied to clipboard"), tr("The sync protocol has been copied to the clipboard."));
|
|
|
|
}
|
|
|
|
|
|
|
|
void ItemProgressDialog::accept()
|
|
|
|
{
|
|
|
|
QDialog::accept();
|
|
|
|
}
|
|
|
|
|
2013-08-14 20:23:40 +04:00
|
|
|
void ItemProgressDialog::cleanErrors( const QString& /* folder */ ) // FIXME: Use the folder to detect which errors can be deleted.
|
2013-08-01 16:34:31 +04:00
|
|
|
{
|
2013-08-14 20:23:40 +04:00
|
|
|
_problemCounter = 0;
|
|
|
|
QList<QTreeWidgetItem*> wipeList;
|
2013-08-01 16:34:31 +04:00
|
|
|
|
2013-08-14 20:23:40 +04:00
|
|
|
int itemCnt = _ui->_treeWidget->topLevelItemCount();
|
2013-08-01 16:34:31 +04:00
|
|
|
|
2013-08-14 20:23:40 +04:00
|
|
|
for( int cnt = 0; cnt < itemCnt; cnt++ ) {
|
|
|
|
QTreeWidgetItem *item = _ui->_treeWidget->topLevelItem(cnt);
|
|
|
|
bool isErrorItem = item->data(0, ErrorIndicatorRole).toBool();
|
|
|
|
if( isErrorItem ) {
|
|
|
|
wipeList.append(item);
|
|
|
|
}
|
2013-08-01 16:34:31 +04:00
|
|
|
}
|
2013-08-14 20:23:40 +04:00
|
|
|
qDeleteAll(wipeList.begin(), wipeList.end());
|
2013-08-01 16:34:31 +04:00
|
|
|
}
|
|
|
|
|
2013-08-13 18:53:39 +04:00
|
|
|
QString ItemProgressDialog::timeString(QDateTime dt, QLocale::FormatType format) const
|
|
|
|
{
|
|
|
|
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-08-01 16:34:31 +04:00
|
|
|
void ItemProgressDialog::slotProgressErrors( const QString& folder, const Progress::SyncProblem& problem )
|
|
|
|
{
|
|
|
|
QStringList columns;
|
2013-08-13 18:53:39 +04:00
|
|
|
QString timeStr = timeString(problem.timestamp);
|
|
|
|
QString longTimeStr = timeString(problem.timestamp, QLocale::LongFormat);
|
2013-08-01 16:34:31 +04:00
|
|
|
|
|
|
|
columns << timeStr;
|
|
|
|
columns << problem.current_file;
|
2013-08-14 20:23:40 +04:00
|
|
|
columns << folder;
|
2013-08-01 16:34:31 +04:00
|
|
|
QString errMsg = tr("Problem: %1").arg(problem.error_message);
|
2013-08-15 10:15:30 +04:00
|
|
|
#if 0
|
2013-08-14 20:23:40 +04:00
|
|
|
if( problem.error_code == 507 ) {
|
|
|
|
errMsg = tr("No more storage space available on server.");
|
|
|
|
}
|
2013-08-15 10:15:30 +04:00
|
|
|
#endif
|
2013-08-01 16:34:31 +04:00
|
|
|
columns << errMsg;
|
|
|
|
|
2013-08-14 20:23:40 +04:00
|
|
|
QTreeWidgetItem *item = new QTreeWidgetItem(columns);
|
2013-08-01 16:34:31 +04:00
|
|
|
item->setData(0, ErrorIndicatorRole, QVariant(true) );
|
2013-08-15 10:15:30 +04:00
|
|
|
// Maybe we should not set the error icon for all problems but distinguish
|
|
|
|
// by error_code. A quota problem is considered an error, others might not??
|
|
|
|
item->setIcon(0, Theme::instance()->syncStateIcon(SyncResult::Error, true));
|
2013-08-13 18:53:39 +04:00
|
|
|
item->setToolTip(0, longTimeStr);
|
2013-08-26 19:25:33 +04:00
|
|
|
_ui->_treeWidget->insertTopLevelItem(0, item);
|
2013-08-01 16:34:31 +04:00
|
|
|
Q_UNUSED(item);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ItemProgressDialog::slotProgressInfo( const QString& folder, const Progress::Info& progress )
|
|
|
|
{
|
|
|
|
if( progress.kind == Progress::StartSync ) {
|
|
|
|
cleanErrors( folder );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( progress.kind == Progress::EndSync ) {
|
2013-08-14 20:23:40 +04:00
|
|
|
// decorateFolderItem( folder );
|
2013-08-01 16:34:31 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Ingore other events than finishing an individual up- or download.
|
2013-08-03 23:33:19 +04:00
|
|
|
if( !(progress.kind == Progress::EndDownload || progress.kind == Progress::EndUpload || progress.kind == Progress::EndDelete)) {
|
2013-08-01 16:34:31 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QStringList columns;
|
2013-08-13 18:53:39 +04:00
|
|
|
QString timeStr = timeString(progress.timestamp);
|
|
|
|
QString longTimeStr = timeString(progress.timestamp, QLocale::LongFormat);
|
2013-08-01 16:34:31 +04:00
|
|
|
|
|
|
|
columns << timeStr;
|
|
|
|
columns << progress.current_file;
|
2013-08-14 20:23:40 +04:00
|
|
|
columns << progress.folder;
|
2013-08-06 20:06:05 +04:00
|
|
|
columns << Progress::asResultString(progress.kind);
|
2013-08-01 16:34:31 +04:00
|
|
|
columns << Utility::octetsToString( progress.file_size );
|
|
|
|
|
2013-08-14 20:23:40 +04:00
|
|
|
QTreeWidgetItem *item = new QTreeWidgetItem(columns);
|
2013-08-13 18:53:39 +04:00
|
|
|
item->setToolTip(0, longTimeStr);
|
2013-08-26 19:25:33 +04:00
|
|
|
_ui->_treeWidget->insertTopLevelItem(0, item);
|
2013-08-01 16:34:31 +04:00
|
|
|
Q_UNUSED(item);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|