Skip to content
This repository has been archived by the owner on Sep 1, 2019. It is now read-only.

Commit

Permalink
allow to calculate size of folders
Browse files Browse the repository at this point in the history
closes #4
  • Loading branch information
mmozeiko committed Feb 27, 2017
1 parent 350f738 commit 1cef1fd
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 6 deletions.
17 changes: 15 additions & 2 deletions src/progress_dialog.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "progress_dialog.h"

ProgressDialog::ProgressDialog(const QString& title, const QString& operation, const QString& message, QProcess* process, QWidget* parent)
ProgressDialog::ProgressDialog(const QString& title, const QString& operation, const QString& message, QProcess* process, QWidget* parent, bool close)
: QDialog(parent)
{
ui.setupUi(this);
Expand Down Expand Up @@ -30,7 +30,10 @@ ProgressDialog::ProgressDialog(const QString& title, const QString& operation, c
{
if (status == QProcess::NormalExit && code == 0)
{
emit accept();
if (close)
{
emit accept();
}
}
else
{
Expand All @@ -51,3 +54,13 @@ ProgressDialog::ProgressDialog(const QString& title, const QString& operation, c
ProgressDialog::~ProgressDialog()
{
}

void ProgressDialog::expand()
{
ui.buttonShowOutput->setChecked(true);
}

void ProgressDialog::allowToClose()
{
ui.buttonBox->setEnabled(true);
}
5 changes: 4 additions & 1 deletion src/progress_dialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@ class ProgressDialog : public QDialog
Q_OBJECT

public:
ProgressDialog(const QString& title, const QString& operation, const QString& message, QProcess* process, QWidget* parent = nullptr);
ProgressDialog(const QString& title, const QString& operation, const QString& message, QProcess* process, QWidget* parent = nullptr, bool close = false);
~ProgressDialog();

void expand();
void allowToClose();

private:
Ui::ProgressDialog ui;
};
4 changes: 2 additions & 2 deletions src/progress_dialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>621</width>
<height>311</height>
<width>618</width>
<height>291</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout">
Expand Down
25 changes: 24 additions & 1 deletion src/remote_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ RemoteWidget::RemoteWidget(IconCache* iconCache, const QString& remote, bool isL
ui.stream->setIcon(style->standardIcon(QStyle::SP_MediaPlay));
ui.upload->setIcon(style->standardIcon(QStyle::SP_ArrowUp));
ui.download->setIcon(style->standardIcon(QStyle::SP_ArrowDown));
ui.download->setIcon(style->standardIcon(QStyle::SP_ArrowDown));
ui.getSize->setIcon(style->standardIcon(QStyle::SP_FileDialogInfoView));

ui.buttonRefresh->setDefaultAction(ui.refresh);
ui.buttonMkdir->setDefaultAction(ui.mkdir);
Expand All @@ -39,6 +41,7 @@ RemoteWidget::RemoteWidget(IconCache* iconCache, const QString& remote, bool isL
ui.buttonStream->setDefaultAction(ui.stream);
ui.buttonUpload->setDefaultAction(ui.upload);
ui.buttonDownload->setDefaultAction(ui.download);
ui.buttonSize->setDefaultAction(ui.getSize);

ui.tree->sortByColumn(0, Qt::AscendingOrder);
ui.tree->header()->setSectionsMovable(false);
Expand Down Expand Up @@ -92,6 +95,7 @@ RemoteWidget::RemoteWidget(IconCache* iconCache, const QString& remote, bool isL
path = model->path(index);
}

ui.getSize->setDisabled(!isFolder);
ui.path->setText(isLocal ? QDir::toNativeSeparators(path.path()) : path.path());
});

Expand Down Expand Up @@ -261,6 +265,25 @@ RemoteWidget::RemoteWidget(IconCache* iconCache, const QString& remote, bool isL
}
});

QObject::connect(ui.getSize, &QAction::triggered, this, [=]()
{
QModelIndex index = ui.tree->selectionModel()->selectedRows().front();

QString path = model->path(index).path();
QString pathMsg = isLocal ? QDir::toNativeSeparators(path) : path;

QProcess process;
UseRclonePassword(&process);
process.setProgram(GetRclone());
process.setArguments(QStringList() << "size" << remote + ":" + path);
process.setReadChannelMode(QProcess::MergedChannels);

ProgressDialog progress("Get Size", "Calculating...", pathMsg, &process, this, false);
progress.expand();
progress.allowToClose();
progress.exec();
});

QObject::connect(model, &ItemModel::drop, this, [=](const QDir& path, const QModelIndex& parent)
{
qApp->setActiveWindow(this);
Expand All @@ -276,13 +299,13 @@ RemoteWidget::RemoteWidget(IconCache* iconCache, const QString& remote, bool isL
QStringList args = t.getOptions();
emit addTransfer(QString("%1 from %2").arg(t.getMode()).arg(src), src, dst, args);
}

});

QObject::connect(ui.tree, &QWidget::customContextMenuRequested, this, [=](const QPoint& pos)
{
QMenu menu;
menu.addAction(ui.refresh);
menu.addAction(ui.getSize);
menu.addSeparator();
menu.addAction(ui.mkdir);
menu.addAction(ui.rename);
Expand Down
16 changes: 16 additions & 0 deletions src/remote_widget.ui
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,16 @@
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="buttonSize">
<property name="text">
<string>&amp;Get Size...</string>
</property>
<property name="toolButtonStyle">
<enum>Qt::ToolButtonTextBesideIcon</enum>
</property>
</widget>
</item>
<item>
<spacer name="spacer">
<property name="orientation">
Expand Down Expand Up @@ -245,6 +255,11 @@
<string>&amp;Download</string>
</property>
</action>
<action name="getSize">
<property name="text">
<string>&amp;Get Size</string>
</property>
</action>
</widget>
<tabstops>
<tabstop>buttonRefresh</tabstop>
Expand All @@ -255,6 +270,7 @@
<tabstop>buttonStream</tabstop>
<tabstop>buttonUpload</tabstop>
<tabstop>buttonDownload</tabstop>
<tabstop>buttonSize</tabstop>
<tabstop>path</tabstop>
<tabstop>tree</tabstop>
</tabstops>
Expand Down

0 comments on commit 1cef1fd

Please sign in to comment.