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

Commit

Permalink
support for encrypted configuration file
Browse files Browse the repository at this point in the history
fixes #2
  • Loading branch information
mmozeiko committed Jan 30, 2017
1 parent 31671e3 commit fa9380b
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 14 deletions.
2 changes: 2 additions & 0 deletions src/item_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,8 @@ void ItemModel::load(const QPersistentModelIndex& parentIndex, Item* parent)
emit endInsertRows();

timer->start(100);
UseRclonePassword(lsd);
UseRclonePassword(lsl);
lsd->start(GetRclone(), QStringList() << "lsd" << mRemote + ":" + parent->path.path(), QIODevice::ReadOnly);
lsl->start(GetRclone(), QStringList() << "lsl" << "--max-depth" << "1" << mRemote + ":" + parent->path.path(), QIODevice::ReadOnly);
}
Expand Down
1 change: 1 addition & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ int main(int argc, char* argv[])
{
QApplication app(argc, argv);

app.setApplicationDisplayName("Rclone Browser");
app.setApplicationName("rclone-browser");
app.setOrganizationName("rclone-browser");
app.setWindowIcon(QIcon(":/icons/icon.png"));
Expand Down
70 changes: 56 additions & 14 deletions src/main_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,6 @@ MainWindow::MainWindow()
{
restoreGeometry(settings.value("MainWindow/geometry").toByteArray());
}
if (settings.contains("Settings/style"))
{
QStyle* style = QStyleFactory::create(settings.value("Settings/style").toString());
if (style)
{
qApp->setStyle(style);
}
}
SetRclone(settings.value("Settings/rclone").toString());

mAlwaysShowInTray = settings.value("Settings/alwaysShowInTray", false).toBool();
Expand Down Expand Up @@ -204,13 +196,27 @@ void MainWindow::rcloneGetVersion()
QObject::connect(p, static_cast<void(QProcess::*)(int)>(&QProcess::finished), this, [=](int code)
{
if (code == 0)
{
{
QString version = p->readAllStandardOutput().trimmed();
mStatusMessage->setText(version + " in " + QDir::toNativeSeparators(GetRclone()));
QTimer::singleShot(0, this, &MainWindow::rcloneListRemotes);
}
else
{
if (p->error() != QProcess::FailedToStart)
{
if (getConfigPassword(p))
{
rcloneGetVersion();
}
else
{
close();
}
p->deleteLater();
return;
}

if (firstTime)
{
if (p->error() == QProcess::FailedToStart)
Expand All @@ -227,7 +233,8 @@ void MainWindow::rcloneGetVersion()
p->deleteLater();
});

p->start(GetRclone(), QStringList() << "version", QIODevice::ReadOnly);
UseRclonePassword(p);
p->start(GetRclone(), QStringList() << "version" << "--ask-password=false", QIODevice::ReadOnly);
}

void MainWindow::rcloneConfig()
Expand Down Expand Up @@ -280,19 +287,20 @@ void MainWindow::rcloneConfig()
p->setProgram(terminal);
p->setArguments(QStringList() << "-e" << (GetRclone() + " config"));
#endif
UseRclonePassword(p);
p->start(QIODevice::NotOpen);
}

void MainWindow::rcloneListRemotes()
{
ui.remotes->clear();

QProcess* p = new QProcess();

QObject::connect(p, static_cast<void(QProcess::*)(int)>(&QProcess::finished), this, [=](int code)
{
if (code == 0)
{
ui.remotes->clear();

QStyle* style = qApp->style();
int size = 2 * style->pixelMetric(QStyle::PM_ListViewIconSize);
ui.remotes->setIconSize(QSize(size, size));
Expand Down Expand Up @@ -325,10 +333,41 @@ void MainWindow::rcloneListRemotes()
ui.remotes->addItem(item);
}
}
else
{
if (p->error() != QProcess::FailedToStart)
{
if (getConfigPassword(p))
{
rcloneListRemotes();
}
}
}
p->deleteLater();
});

p->start(GetRclone(), QStringList() << "listremotes" << "-l", QIODevice::ReadOnly);
UseRclonePassword(p);
p->start(GetRclone(), QStringList() << "listremotes" << "-l" << "--ask-password=false", QIODevice::ReadOnly);
}

bool MainWindow::getConfigPassword(QProcess* p)
{
QString output = p->readAllStandardError().trimmed();
qDebug() << output;
if (output.indexOf("RCLONE_CONFIG_PASS") > 0)
{
bool ok;
QString password = QInputDialog::getText(
this, qApp->applicationDisplayName(),
"Enter password for .rclone.conf configuration file:",
QLineEdit::Password, QString(), &ok);
if (ok)
{
SetRclonePassword(password);
return true;
}
}
return false;
}

bool MainWindow::canClose()
Expand Down Expand Up @@ -457,7 +496,8 @@ void MainWindow::addTransfer(const QString& message, const QString& source, cons
ui.jobs->insertWidget(1, line);
ui.tabs->setTabText(1, QString("Jobs (%1)").arg(++mJobCount));

transfer->start(GetRclone(), args, QIODevice::ReadOnly);
UseRclonePassword(transfer);
transfer->start(GetRclone(), args, QIODevice::ReadOnly);
}

void MainWindow::addMount(const QString& remote, const QString& folder)
Expand Down Expand Up @@ -515,6 +555,7 @@ void MainWindow::addMount(const QString& remote, const QString& folder)
}
options << remote << folder;

UseRclonePassword(mount);
mount->start(GetRclone(), options, QIODevice::ReadOnly);
}

Expand Down Expand Up @@ -575,5 +616,6 @@ void MainWindow::addStream(const QString& remote, const QString& stream)
ui.tabs->setTabText(1, QString("Jobs (%1)").arg(++mJobCount));

player->start(stream, QProcess::ReadOnly);
UseRclonePassword(rclone);
rclone->start(GetRclone(), QStringList() << "cat" << remote, QProcess::WriteOnly);
}
1 change: 1 addition & 0 deletions src/main_window.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ private slots:

bool canClose();
void closeEvent(QCloseEvent* ev) override;
bool getConfigPassword(QProcess* p);

void addEmptyJobsMessage();
};
3 changes: 3 additions & 0 deletions src/remote_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ RemoteWidget::RemoteWidget(IconCache* iconCache, const QString& remote, bool isL
QString folderMsg = isLocal ? QDir::toNativeSeparators(folder) : folder;

QProcess process;
UseRclonePassword(&process);
process.setProgram(GetRclone());
process.setArguments(QStringList() << "mkdir" << remote + ":" + folder);
process.setReadChannelMode(QProcess::MergedChannels);
Expand All @@ -140,6 +141,7 @@ RemoteWidget::RemoteWidget(IconCache* iconCache, const QString& remote, bool isL
if (!name.isEmpty())
{
QProcess process;
UseRclonePassword(&process);
process.setProgram(GetRclone());
process.setArguments(QStringList()
<< "move"
Expand All @@ -166,6 +168,7 @@ RemoteWidget::RemoteWidget(IconCache* iconCache, const QString& remote, bool isL
if (button == QMessageBox::Yes)
{
QProcess process;
UseRclonePassword(&process);
process.setProgram(GetRclone());
process.setArguments(QStringList() << (model->isFolder(index) ? "purge" : "delete") << remote + ":" + path);
process.setReadChannelMode(QProcess::MergedChannels);
Expand Down
16 changes: 16 additions & 0 deletions src/utils.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "utils.h"

static QString gRclone;
static QString gRclonePassword;

void ReadSettings(QSettings* settings, QObject* widget)
{
Expand Down Expand Up @@ -108,3 +109,18 @@ void SetRclone(const QString& rclone)
{
gRclone = rclone;
}

void UseRclonePassword(QProcess* process)
{
if (!gRclonePassword.isEmpty())
{
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
env.insert("RCLONE_CONFIG_PASS", gRclonePassword);
process->setProcessEnvironment(env);
}
}

void SetRclonePassword(const QString& rclonePassword)
{
gRclonePassword = rclonePassword;
}
3 changes: 3 additions & 0 deletions src/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@ void WriteSettings(QSettings* settings, QObject* widget);

QString GetRclone();
void SetRclone(const QString& rclone);

void UseRclonePassword(QProcess* process);
void SetRclonePassword(const QString& rclonePassword);

0 comments on commit fa9380b

Please sign in to comment.