Fix the file count in the progress

And clear the ignored files between syncs
This commit is contained in:
Olivier Goffart 2014-03-14 18:29:23 +01:00
parent f9b82d852c
commit d744b5e481
3 changed files with 25 additions and 45 deletions

View file

@ -311,20 +311,6 @@ int CSyncThread::treewalkFile( TREE_WALK_FILE *file, bool remote )
int re = 0; int re = 0;
switch(file->instruction) {
case CSYNC_INSTRUCTION_NONE:
break;
case CSYNC_INSTRUCTION_NEW:
case CSYNC_INSTRUCTION_SYNC:
case CSYNC_INSTRUCTION_CONFLICT:
case CSYNC_INSTRUCTION_RENAME:
case CSYNC_INSTRUCTION_REMOVE:
_progressInfo._totalFileCount++;
_progressInfo._totalSize += file->size;
//fall trough
default:
_needsUpdate = true;
}
switch(file->instruction) { switch(file->instruction) {
case CSYNC_INSTRUCTION_UPDATED: case CSYNC_INSTRUCTION_UPDATED:
// We need to update the database. // We need to update the database.
@ -376,8 +362,16 @@ int CSyncThread::treewalkFile( TREE_WALK_FILE *file, bool remote )
&& file->instruction != CSYNC_INSTRUCTION_REMOVE) { && file->instruction != CSYNC_INSTRUCTION_REMOVE) {
_hasFiles = true; _hasFiles = true;
} }
_syncedItems.append(item);
if (!item._isDirectory) {
_progressInfo._totalFileCount++;
if (Progress::isSizeDependent(file->instruction)) {
_progressInfo._totalSize += file->size;
}
}
_needsUpdate = true;
_syncedItems.append(item);
emit syncItemDisconvered(item); emit syncItemDisconvered(item);
return re; return re;
} }
@ -537,7 +531,6 @@ void CSyncThread::slotUpdateFinished(int updateResult)
_progressInfo = Progress::Info(); _progressInfo = Progress::Info();
emit transmissionProgress(Progress::StartSync, _progressInfo);
_hasFiles = false; _hasFiles = false;
bool walkOk = true; bool walkOk = true;
@ -557,6 +550,8 @@ void CSyncThread::slotUpdateFinished(int updateResult)
it->_file = adjustRenamedPath(it->_file); it->_file = adjustRenamedPath(it->_file);
} }
emit transmissionProgress(Progress::StartSync, _progressInfo);
if (!_hasFiles && !_syncedItems.isEmpty()) { if (!_hasFiles && !_syncedItems.isEmpty()) {
qDebug() << Q_FUNC_INFO << "All the files are going to be removed, asking the user"; qDebug() << Q_FUNC_INFO << "All the files are going to be removed, asking the user";
bool cancel = false; bool cancel = false;

View file

@ -32,7 +32,7 @@ namespace Mirall {
ProtocolWidget::ProtocolWidget(QWidget *parent) : ProtocolWidget::ProtocolWidget(QWidget *parent) :
QWidget(parent), QWidget(parent),
ErrorIndicatorRole( Qt::UserRole +1 ), IgnoredIndicatorRole( Qt::UserRole +1 ),
_ui(new Ui::ProtocolWidget) _ui(new Ui::ProtocolWidget)
{ {
_ui->setupUi(this); _ui->setupUi(this);
@ -125,29 +125,17 @@ void ProtocolWidget::slotClearBlacklist()
folderMan->slotScheduleAllFolders(); folderMan->slotScheduleAllFolders();
} }
QList<QTreeWidgetItem*> ProtocolWidget::errorItems( const QString& folder ) void ProtocolWidget::cleanIgnoreItems(const QString& folder)
{ {
QList<QTreeWidgetItem*> list;
int itemCnt = _ui->_treeWidget->topLevelItemCount(); int itemCnt = _ui->_treeWidget->topLevelItemCount();
for( int cnt = itemCnt-1; cnt >=0 ; cnt-- ) {
for( int cnt = 0; cnt < itemCnt; cnt++ ) {
QTreeWidgetItem *item = _ui->_treeWidget->topLevelItem(cnt); QTreeWidgetItem *item = _ui->_treeWidget->topLevelItem(cnt);
bool isErrorItem = item->data(0, ErrorIndicatorRole).toBool(); bool isErrorItem = item->data(0, IgnoredIndicatorRole).toBool();
QString itemFolder = item->data(2, Qt::DisplayRole).toString(); QString itemFolder = item->data(2, Qt::DisplayRole).toString();
if( isErrorItem && itemFolder == folder ) { if( isErrorItem && itemFolder == folder ) {
list.append(item); delete item;
} }
} }
return list;
}
void ProtocolWidget::cleanErrorItems( const QString& folder ) // FIXME: Use the folder to detect which errors can be deleted.
{
QList<QTreeWidgetItem*> wipeList = errorItems(folder);
if( wipeList.count() > 0 ) {
qDeleteAll(wipeList.begin(), wipeList.end());
}
} }
QString ProtocolWidget::timeString(QDateTime dt, QLocale::FormatType format) const QString ProtocolWidget::timeString(QDateTime dt, QLocale::FormatType format) const
@ -215,7 +203,7 @@ QTreeWidgetItem* ProtocolWidget::createCompletedTreewidgetItem(const QString& fo
QTreeWidgetItem *twitem = new QTreeWidgetItem(columns); QTreeWidgetItem *twitem = new QTreeWidgetItem(columns);
if (item._status == SyncFileItem::FileIgnored) { if (item._status == SyncFileItem::FileIgnored) {
// Tell that we want to remove it on the next sync. // Tell that we want to remove it on the next sync.
twitem->setData(0, ErrorIndicatorRole, true); twitem->setData(0, IgnoredIndicatorRole, true);
} }
twitem->setIcon(0, icon); twitem->setIcon(0, icon);
@ -247,16 +235,14 @@ void ProtocolWidget::computeResyncButtonEnabled()
void ProtocolWidget::slotProgressInfo( const QString& folder, const Progress::Info& progress ) void ProtocolWidget::slotProgressInfo( const QString& folder, const Progress::Info& progress )
{ {
/* if( progress._completedFileCount == 0 ) {
if( progress.kind == Progress::StartSync ) { // The sync is restarting, clean the old items
cleanErrorItems( folder ); cleanIgnoreItems(folder);
_clearBlacklistBtn->setEnabled(false); computeResyncButtonEnabled();
} } else if (progress._totalFileCount == progress._completedFileCount) {
//Sync completed
if( progress.kind == Progress::EndSync ) {
computeResyncButtonEnabled(); computeResyncButtonEnabled();
} }
*/
SyncFileItem last = progress._lastCompletedItem; SyncFileItem last = progress._lastCompletedItem;
if (last.isEmpty()) return; if (last.isEmpty()) return;

View file

@ -54,15 +54,14 @@ signals:
private: private:
void setSyncResultStatus(const SyncResult& result ); void setSyncResultStatus(const SyncResult& result );
void cleanErrorItems( const QString& folder ); void cleanIgnoreItems( const QString& folder );
void computeResyncButtonEnabled(); void computeResyncButtonEnabled();
QTreeWidgetItem* createCompletedTreewidgetItem(const QString &folder, const SyncFileItem &item ); QTreeWidgetItem* createCompletedTreewidgetItem(const QString &folder, const SyncFileItem &item );
QList<QTreeWidgetItem*> errorItems(const QString &folder);
QString timeString(QDateTime dt, QLocale::FormatType format = QLocale::NarrowFormat) const; QString timeString(QDateTime dt, QLocale::FormatType format = QLocale::NarrowFormat) const;
const int ErrorIndicatorRole; const int IgnoredIndicatorRole;
Ui::ProtocolWidget *_ui; Ui::ProtocolWidget *_ui;
QPushButton *_clearBlacklistBtn; QPushButton *_clearBlacklistBtn;
}; };