Skip to content

Commit

Permalink
Wizard: Show the size of the folders that will be downloaded
Browse files Browse the repository at this point in the history
Part of #2580
  • Loading branch information
ogoffart committed Jan 14, 2015
1 parent 0af5574 commit da0f731
Show file tree
Hide file tree
Showing 5 changed files with 145 additions and 49 deletions.
39 changes: 39 additions & 0 deletions src/gui/selectivesyncdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ void SelectiveSyncTreeView::recursiveInsert(QTreeWidgetItem* parent, QStringList
item->setIcon(0, folderIcon);
item->setText(0, pathTrail.first());
item->setText(1, Utility::octetsToString(size));
item->setData(1, Qt::UserRole, size);
// item->setData(0, Qt::UserRole, pathTrail.first());
item->setChildIndicatorPolicy(QTreeWidgetItem::ShowIndicator);
}
Expand Down Expand Up @@ -259,6 +260,38 @@ QStringList SelectiveSyncTreeView::createBlackList(QTreeWidgetItem* root) const
return result;
}

qint64 SelectiveSyncTreeView::estimatedSize(QTreeWidgetItem* root)
{
if (!root) {
root = topLevelItem(0);
}
if (!root) return -1;


switch(root->checkState(0)) {
case Qt::Unchecked:
return 0;
case Qt::Checked:
return root->data(1, Qt::UserRole).toLongLong();
case Qt::PartiallyChecked:
break;
}

qint64 result = 0;
if (root->childCount()) {
for (int i = 0; i < root->childCount(); ++i) {
auto r = estimatedSize(root->child(i));
if (r < 0) return r;
result += r;
}
} else {
// We did not load from the server so we have no idea how much we will sync from this branch
return -1;
}
return result;
}


SelectiveSyncDialog::SelectiveSyncDialog(AccountPtr account, Folder* folder, QWidget* parent, Qt::WindowFlags f)
: QDialog(parent, f), _folder(folder)
{
Expand Down Expand Up @@ -328,6 +361,12 @@ QStringList SelectiveSyncDialog::createBlackList() const
return _treeView->createBlackList();
}

quint64 SelectiveSyncDialog::estimatedSize()
{
return _treeView->estimatedSize();
}




}
Expand Down
6 changes: 6 additions & 0 deletions src/gui/selectivesyncdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ class SelectiveSyncTreeView : public QTreeWidget {

/// Returns a list of blacklisted paths, each including the trailing /
QStringList createBlackList(QTreeWidgetItem* root = 0) const;

//Estimate the total size of checked item (recursively)
qint64 estimatedSize(QTreeWidgetItem *root = 0);
void refreshFolders();

// oldBlackList is a list of excluded paths, each including a trailing /
Expand Down Expand Up @@ -68,6 +71,9 @@ class SelectiveSyncDialog : public QDialog {

QStringList createBlackList() const;

// Estimate the size of the total of sync'ed files from the server
quint64 estimatedSize();

private:

void init(AccountPtr account);
Expand Down
23 changes: 21 additions & 2 deletions src/gui/wizard/owncloudadvancedsetuppage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "configfile.h"
#include "selectivesyncdialog.h"
#include "creds/abstractcredentials.h"
#include "networkjobs.h"

namespace OCC
{
Expand Down Expand Up @@ -67,8 +68,6 @@ OwncloudAdvancedSetupPage::OwncloudAdvancedSetupPage()
_ui.lServerIcon->setPixmap(appIcon.pixmap(48));
_ui.lLocalIcon->setText(QString());
_ui.lLocalIcon->setPixmap(QPixmap(":/client/resources/folder-sync.png"));


}

void OwncloudAdvancedSetupPage::setupCustomization()
Expand Down Expand Up @@ -99,12 +98,19 @@ void OwncloudAdvancedSetupPage::initializePage()
_checking = false;
_multipleFoldersExist = false;
_oldLocalFolder = wizard()->property("oldLocalFolder").toString();
_ui.lSelectiveSyncSizeLabel->setText(QString());
_ui.lSyncEverythingSizeLabel->setText(QString());

// call to init label
updateStatus();

// ensure "next" gets the focus, not obSelectLocalFolder
QTimer::singleShot(0, wizard()->button(QWizard::NextButton), SLOT(setFocus()));

auto acc = static_cast<OwncloudWizard *>(wizard())->account();
auto quotaJob = new CheckQuotaJob(acc, "/", this);
connect(quotaJob, SIGNAL(quotaRetrieved(qint64,qint64)), SLOT(slotQuotaRetrieved(qint64,qint64)));
quotaJob->start();
}

// Called if the user changes the user- or url field. Adjust the texts and
Expand Down Expand Up @@ -280,18 +286,31 @@ void OwncloudAdvancedSetupPage::slotSelectiveSyncClicked()
_ui.rSelectiveSync->blockSignals(true);
_ui.rSelectiveSync->setChecked(true);
_ui.rSelectiveSync->blockSignals(false);
auto s = dlg->estimatedSize();
if (s > 0 ) {
_ui.lSelectiveSyncSizeLabel->setText(tr("(%1)").arg(Utility::octetsToString(s)));
} else {
_ui.lSelectiveSyncSizeLabel->setText(QString());
}
} else {
_ui.rSyncEverything->setChecked(true);
_ui.lSelectiveSyncSizeLabel->setText(QString());
}
wizard()->setProperty("blacklist", _blacklist);
}
}

void OwncloudAdvancedSetupPage::slotSyncEverythingClicked()
{
_ui.lSelectiveSyncSizeLabel->setText(QString());
_ui.rSyncEverything->setChecked(true);
_blacklist.clear();
}

void OwncloudAdvancedSetupPage::slotQuotaRetrieved(qint64, qint64 usedQuota)
{
_ui.lSyncEverythingSizeLabel->setText(tr("(%1)").arg(Utility::octetsToString(usedQuota)));

}

} // namespace OCC
1 change: 1 addition & 0 deletions src/gui/wizard/owncloudadvancedsetuppage.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ private slots:
void slotSelectFolder();
void slotSyncEverythingClicked();
void slotSelectiveSyncClicked();
void slotQuotaRetrieved(qint64,qint64);

private:
void setupCustomization();
Expand Down
125 changes: 78 additions & 47 deletions src/gui/wizard/owncloudadvancedsetuppage.ui
Original file line number Diff line number Diff line change
Expand Up @@ -94,53 +94,6 @@
</item>
</layout>
</item>
<item row="0" column="1" colspan="2">
<widget class="QWidget" name="widget" native="true">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QRadioButton" name="rSyncEverything">
<property name="text">
<string>Sync everything from server</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QRadioButton" name="rSelectiveSync">
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="bSelectiveSync">
<property name="text">
<string>Choose what to sync</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item row="1" column="1">
<spacer name="verticalSpacer">
<property name="orientation">
Expand Down Expand Up @@ -257,6 +210,84 @@
</property>
</widget>
</item>
<item row="0" column="1" colspan="2">
<widget class="QWidget" name="widget" native="true">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QRadioButton" name="rSyncEverything">
<property name="text">
<string>S&amp;ync everything from server</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="lSyncEverythingSizeLabel">
<property name="text">
<string>TextLabel</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QRadioButton" name="rSelectiveSync">
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="bSelectiveSync">
<property name="text">
<string>Choose what to sync</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="lSelectiveSyncSizeLabel">
<property name="text">
<string>TextLabel</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</widget>
</item>
</layout>
</item>
<item>
Expand Down

0 comments on commit da0f731

Please sign in to comment.