| 1 |
#include "main_window.h" |
| 2 |
#include "job_options.h" |
| 3 |
#include "job_widget.h" |
| 4 |
#include "list_of_job_options.h" |
| 5 |
#include "mount_widget.h" |
| 6 |
#include "preferences_dialog.h" |
| 7 |
#include "remote_widget.h" |
| 8 |
#include "stream_widget.h" |
| 9 |
#include "transfer_dialog.h" |
| 10 |
#include "utils.h" |
| 11 |
#ifdef Q_OS_MACOS |
| 12 |
#include "osx_helper.h" |
| 13 |
#endif |
| 14 |
|
| 15 |
MainWindow::MainWindow() { |
| 16 |
ui.setupUi(this); |
| 17 |
|
| 18 |
if (IsPortableMode()) { |
| 19 |
this->setWindowTitle("Rclone Browser - portable mode"); |
| 20 |
} else { |
| 21 |
this->setWindowTitle("Rclone Browser"); |
| 22 |
} |
| 23 |
|
| 24 |
#if defined(Q_OS_WIN) |
| 25 |
// disable "?" WindowContextHelpButton |
| 26 |
QApplication::setAttribute(Qt::AA_DisableWindowContextHelpButton); |
| 27 |
#endif |
| 28 |
|
| 29 |
#if !defined(Q_OS_MACOS) |
| 30 |
auto settings = GetSettings(); |
| 31 |
bool darkMode = settings->value("Settings/darkMode").toBool(); |
| 32 |
|
| 33 |
// enable dark mode for Windows and Linux |
| 34 |
if (darkMode) { |
| 35 |
qApp->setStyle(QStyleFactory::create("Fusion")); |
| 36 |
|
| 37 |
QPalette darkPalette; |
| 38 |
darkPalette.setColor(QPalette::Window, QColor(53, 53, 53)); |
| 39 |
darkPalette.setColor(QPalette::WindowText, Qt::white); |
| 40 |
darkPalette.setColor(QPalette::Base, QColor(25, 25, 25)); |
| 41 |
darkPalette.setColor(QPalette::AlternateBase, QColor(53, 53, 53)); |
| 42 |
darkPalette.setColor(QPalette::ToolTipBase, Qt::white); |
| 43 |
darkPalette.setColor(QPalette::ToolTipText, Qt::white); |
| 44 |
darkPalette.setColor(QPalette::Text, Qt::white); |
| 45 |
darkPalette.setColor(QPalette::Button, QColor(53, 53, 53)); |
| 46 |
darkPalette.setColor(QPalette::ButtonText, Qt::white); |
| 47 |
darkPalette.setColor(QPalette::BrightText, Qt::red); |
| 48 |
darkPalette.setColor(QPalette::Link, QColor(42, 130, 218)); |
| 49 |
|
| 50 |
darkPalette.setColor(QPalette::Highlight, QColor(42, 130, 218)); |
| 51 |
darkPalette.setColor(QPalette::HighlightedText, Qt::black); |
| 52 |
|
| 53 |
qApp->setPalette(darkPalette); |
| 54 |
|
| 55 |
qApp->setStyleSheet("QToolTip { color: #ffffff; background-color: #2a82da; " |
| 56 |
"border: 1px solid white; }"); |
| 57 |
} |
| 58 |
|
| 59 |
#else |
| 60 |
|
| 61 |
// enable dark mode for older macOS |
| 62 |
QString sysInfo = QSysInfo::productVersion(); |
| 63 |
|
| 64 |
if (sysInfo == "10.9" || sysInfo == "10.10" || sysInfo == "10.11" || |
| 65 |
sysInfo == "10.12" || sysInfo == "10.13") { |
| 66 |
auto settings = GetSettings(); |
| 67 |
bool darkMode = settings->value("Settings/darkMode").toBool(); |
| 68 |
if (darkMode) { |
| 69 |
qApp->setStyle(QStyleFactory::create("Fusion")); |
| 70 |
|
| 71 |
QPalette darkPalette; |
| 72 |
darkPalette.setColor(QPalette::Window, QColor(53, 53, 53)); |
| 73 |
darkPalette.setColor(QPalette::WindowText, Qt::white); |
| 74 |
darkPalette.setColor(QPalette::Base, QColor(25, 25, 25)); |
| 75 |
darkPalette.setColor(QPalette::AlternateBase, QColor(53, 53, 53)); |
| 76 |
darkPalette.setColor(QPalette::ToolTipBase, Qt::white); |
| 77 |
darkPalette.setColor(QPalette::ToolTipText, Qt::white); |
| 78 |
darkPalette.setColor(QPalette::Text, Qt::white); |
| 79 |
darkPalette.setColor(QPalette::Button, QColor(53, 53, 53)); |
| 80 |
darkPalette.setColor(QPalette::ButtonText, Qt::white); |
| 81 |
darkPalette.setColor(QPalette::BrightText, Qt::red); |
| 82 |
darkPalette.setColor(QPalette::Link, QColor(42, 130, 218)); |
| 83 |
|
| 84 |
darkPalette.setColor(QPalette::Highlight, QColor(42, 130, 218)); |
| 85 |
darkPalette.setColor(QPalette::HighlightedText, Qt::black); |
| 86 |
|
| 87 |
qApp->setPalette(darkPalette); |
| 88 |
|
| 89 |
qApp->setStyleSheet("QToolTip { color: #ffffff; background-color: " |
| 90 |
"#2a82da; border: 1px solid white; }"); |
| 91 |
} |
| 92 |
} |
| 93 |
#endif |
| 94 |
|
| 95 |
mSystemTray.setIcon(qApp->windowIcon()); |
| 96 |
{ |
| 97 |
auto settings = GetSettings(); |
| 98 |
if (settings->contains("MainWindow/geometry")) { |
| 99 |
restoreGeometry(settings->value("MainWindow/geometry").toByteArray()); |
| 100 |
} |
| 101 |
SetRclone(settings->value("Settings/rclone").toString()); |
| 102 |
SetRcloneConf(settings->value("Settings/rcloneConf").toString()); |
| 103 |
|
| 104 |
mAlwaysShowInTray = |
| 105 |
settings->value("Settings/alwaysShowInTray", false).toBool(); |
| 106 |
mCloseToTray = settings->value("Settings/closeToTray", false).toBool(); |
| 107 |
mNotifyFinishedTransfers = |
| 108 |
settings->value("Settings/notifyFinishedTransfers", true).toBool(); |
| 109 |
|
| 110 |
mSystemTray.setVisible(mAlwaysShowInTray); |
| 111 |
|
| 112 |
// during first run the lastUsed keys might not exist |
| 113 |
if (!(settings->contains("Settings/lastUsedSourceFolder"))) { |
| 114 |
// if lastUsedSourceFolder does not exist create new empty key |
| 115 |
settings->setValue("Settings/lastUsedSourceFolder", ""); |
| 116 |
}; |
| 117 |
if (!(settings->contains("Settings/lastUsedDestFolder"))) { |
| 118 |
// if lastUsedDestFolder does not exist create new empty key |
| 119 |
settings->setValue("Settings/lastUsedDestFolder", ""); |
| 120 |
}; |
| 121 |
if (!(settings->contains("Settings/defaultDownloadOptions"))) { |
| 122 |
// if defaultDownloadOptions does not exist create new empty key |
| 123 |
settings->setValue("Settings/defaultDownloadOptions", ""); |
| 124 |
}; |
| 125 |
#ifdef Q_OS_MACOS |
| 126 |
// for macOS by default exclude .DS_Store files from uploads |
| 127 |
if (!(settings->contains("Settings/defaultUploadOptions"))) { |
| 128 |
// if defaultDownloadOptions does not exist create new empty key |
| 129 |
settings->setValue("Settings/defaultUploadOptions", |
| 130 |
"--exclude .DS_Store"); |
| 131 |
}; |
| 132 |
#else |
| 133 |
if (!(settings->contains("Settings/defaultUploadOptions"))) { |
| 134 |
// if defaultDownloadOptions does not exist create new empty key |
| 135 |
settings->setValue("Settings/defaultUploadOptions", ""); |
| 136 |
}; |
| 137 |
#endif |
| 138 |
if (!(settings->contains("Settings/defaultRcloneOptions"))) { |
| 139 |
// if defaultRcloneOptions does not exist create new empty key |
| 140 |
settings->setValue("Settings/defaultRcloneOptions", "--fast-list"); |
| 141 |
}; |
| 142 |
} |
| 143 |
|
| 144 |
QObject::connect(ui.preferences, &QAction::triggered, this, [=]() { |
| 145 |
PreferencesDialog dialog(this); |
| 146 |
if (dialog.exec() == QDialog::Accepted) { |
| 147 |
auto settings = GetSettings(); |
| 148 |
settings->setValue("Settings/rclone", dialog.getRclone().trimmed()); |
| 149 |
settings->setValue("Settings/rcloneConf", |
| 150 |
dialog.getRcloneConf().trimmed()); |
| 151 |
settings->setValue("Settings/stream", dialog.getStream()); |
| 152 |
settings->setValue("Settings/mount", dialog.getMount()); |
| 153 |
settings->setValue("Settings/defaultDownloadDir", |
| 154 |
dialog.getDefaultDownloadDir().trimmed()); |
| 155 |
settings->setValue("Settings/defaultUploadDir", |
| 156 |
dialog.getDefaultUploadDir().trimmed()); |
| 157 |
settings->setValue("Settings/defaultDownloadOptions", |
| 158 |
dialog.getDefaultDownloadOptions().trimmed()); |
| 159 |
settings->setValue("Settings/defaultUploadOptions", |
| 160 |
dialog.getDefaultUploadOptions().trimmed()); |
| 161 |
settings->setValue("Settings/defaultRcloneOptions", |
| 162 |
dialog.getDefaultRcloneOptions().trimmed()); |
| 163 |
|
| 164 |
settings->setValue("Settings/checkRcloneBrowserUpdates", |
| 165 |
dialog.getCheckRcloneBrowserUpdates()); |
| 166 |
settings->setValue("Settings/checkRcloneUpdates", |
| 167 |
dialog.getCheckRcloneUpdates()); |
| 168 |
|
| 169 |
settings->setValue("Settings/alwaysShowInTray", |
| 170 |
dialog.getAlwaysShowInTray()); |
| 171 |
settings->setValue("Settings/closeToTray", dialog.getCloseToTray()); |
| 172 |
settings->setValue("Settings/notifyFinishedTransfers", |
| 173 |
dialog.getNotifyFinishedTransfers()); |
| 174 |
|
| 175 |
settings->setValue("Settings/showFolderIcons", |
| 176 |
dialog.getShowFolderIcons()); |
| 177 |
settings->setValue("Settings/showFileIcons", dialog.getShowFileIcons()); |
| 178 |
settings->setValue("Settings/rowColors", dialog.getRowColors()); |
| 179 |
settings->setValue("Settings/showHidden", dialog.getShowHidden()); |
| 180 |
settings->setValue("Settings/darkMode", dialog.getDarkMode()); |
| 181 |
settings->setValue("Settings/iconSize", dialog.getIconSize().trimmed()); |
| 182 |
|
| 183 |
settings->setValue("Settings/useProxy", dialog.getUseProxy()); |
| 184 |
settings->setValue("Settings/http_proxy", |
| 185 |
dialog.getHttpProxy().trimmed()); |
| 186 |
settings->setValue("Settings/https_proxy", |
| 187 |
dialog.getHttpsProxy().trimmed()); |
| 188 |
settings->setValue("Settings/no_proxy", dialog.getNoProxy().trimmed()); |
| 189 |
|
| 190 |
SetRclone(dialog.getRclone()); |
| 191 |
SetRcloneConf(dialog.getRcloneConf()); |
| 192 |
mFirstTime = true; |
| 193 |
rcloneGetVersion(); |
| 194 |
|
| 195 |
mAlwaysShowInTray = dialog.getAlwaysShowInTray(); |
| 196 |
mCloseToTray = dialog.getCloseToTray(); |
| 197 |
mNotifyFinishedTransfers = dialog.getNotifyFinishedTransfers(); |
| 198 |
|
| 199 |
mSystemTray.setVisible(mAlwaysShowInTray); |
| 200 |
} |
| 201 |
}); |
| 202 |
|
| 203 |
QObject::connect(ui.quit, &QAction::triggered, this, [=]() { |
| 204 |
mCloseToTray = false; |
| 205 |
close(); |
| 206 |
}); |
| 207 |
|
| 208 |
QObject::connect(ui.about, &QAction::triggered, this, [=]() { |
| 209 |
QMessageBox::about( |
| 210 |
this, "Rclone Browser", |
| 211 |
QString( |
| 212 |
R"(<h3>GUI for rclone, v)" RCLONE_BROWSER_VERSION "</h3>" |
| 213 |
R"(<p>Copyright © 2019</p>)" |
| 214 |
|
| 215 |
R"(<p>Current development and maintenance<br /><a href="https://github.com/kapitainsky/RcloneBrowser">kapitainsky</a></p>)" |
| 216 |
|
| 217 |
R"(<p>New features and fixes<br /><a href="https://github.com/kapitainsky/RcloneBrowser/graphs/contributors">contributors</a></p>)" |
| 218 |
|
| 219 |
R"(<p>Original version<br /><a href="https://mmozeiko.github.io/RcloneBrowser">Martins Mozeiko</a></p>)")); |
| 220 |
}); |
| 221 |
QObject::connect(ui.aboutQt, &QAction::triggered, qApp, |
| 222 |
&QApplication::aboutQt); |
| 223 |
|
| 224 |
QObject::connect( |
| 225 |
ui.remotes, &QListWidget::currentItemChanged, this, |
| 226 |
[=](QListWidgetItem *current) { ui.open->setEnabled(current != NULL); }); |
| 227 |
QObject::connect(ui.remotes, &QListWidget::itemActivated, ui.open, |
| 228 |
&QPushButton::clicked); |
| 229 |
|
| 230 |
QObject::connect(ui.config, &QPushButton::clicked, this, |
| 231 |
&MainWindow::rcloneConfig); |
| 232 |
QObject::connect(ui.refresh, &QPushButton::clicked, this, |
| 233 |
&MainWindow::rcloneListRemotes); |
| 234 |
|
| 235 |
QObject::connect(ui.open, &QPushButton::clicked, this, [=]() { |
| 236 |
auto item = ui.remotes->selectedItems().front(); |
| 237 |
QString type = item->data(Qt::UserRole).toString(); |
| 238 |
QString name = item->text(); |
| 239 |
bool isLocal = type == "local"; |
| 240 |
bool isGoogle = type == "drive"; |
| 241 |
|
| 242 |
auto remote = new RemoteWidget(&mIcons, name, isLocal, isGoogle, ui.tabs); |
| 243 |
QObject::connect(remote, &RemoteWidget::addMount, this, |
| 244 |
&MainWindow::addMount); |
| 245 |
QObject::connect(remote, &RemoteWidget::addStream, this, |
| 246 |
&MainWindow::addStream); |
| 247 |
QObject::connect(remote, &RemoteWidget::addTransfer, this, |
| 248 |
&MainWindow::addTransfer); |
| 249 |
|
| 250 |
int index = ui.tabs->addTab(remote, name); |
| 251 |
ui.tabs->setCurrentIndex(index); |
| 252 |
}); |
| 253 |
|
| 254 |
QObject::connect(ui.tabs, &QTabWidget::tabCloseRequested, ui.tabs, |
| 255 |
&QTabWidget::removeTab); |
| 256 |
|
| 257 |
QObject::connect(ui.tasksListWidget, &QListWidget::currentItemChanged, this, |
| 258 |
[=](QListWidgetItem *current) { |
| 259 |
ui.buttonDeleteTask->setEnabled(current != nullptr); |
| 260 |
ui.buttonEditTask->setEnabled(current != nullptr); |
| 261 |
ui.buttonRunTask->setEnabled(current != nullptr); |
| 262 |
ui.buttonDryrunTask->setEnabled(current != nullptr); |
| 263 |
}); |
| 264 |
|
| 265 |
QObject::connect(ui.buttonRunTask, &QPushButton::clicked, this, [=]() { |
| 266 |
JobOptionsListWidgetItem *item = static_cast<JobOptionsListWidgetItem *>( |
| 267 |
ui.tasksListWidget->currentItem()); |
| 268 |
runItem(item); |
| 269 |
}); |
| 270 |
QObject::connect(ui.buttonDryrunTask, &QPushButton::clicked, this, [=]() { |
| 271 |
JobOptionsListWidgetItem *item = static_cast<JobOptionsListWidgetItem *>( |
| 272 |
ui.tasksListWidget->currentItem()); |
| 273 |
runItem(item, true); |
| 274 |
}); |
| 275 |
|
| 276 |
// QObject::connect(ui.tasksListWidget, &QListWidget::itemDoubleClicked, |
| 277 |
// this, [=]() |
| 278 |
// { |
| 279 |
// editSelectedTask(); |
| 280 |
// }); |
| 281 |
|
| 282 |
QObject::connect(ui.buttonEditTask, &QPushButton::clicked, this, |
| 283 |
[=]() { editSelectedTask(); }); |
| 284 |
|
| 285 |
QObject::connect(ui.buttonDeleteTask, &QPushButton::clicked, this, [=]() { |
| 286 |
JobOptionsListWidgetItem *item = static_cast<JobOptionsListWidgetItem *>( |
| 287 |
ui.tasksListWidget->currentItem()); |
| 288 |
JobOptions *jo = item->GetData(); |
| 289 |
ListOfJobOptions::getInstance()->Forget(jo); |
| 290 |
}); |
| 291 |
|
| 292 |
QObject::connect(ListOfJobOptions::getInstance(), |
| 293 |
&ListOfJobOptions::tasksListUpdated, this, |
| 294 |
&MainWindow::listTasks); |
| 295 |
|
| 296 |
QStyle *style = QApplication::style(); |
| 297 |
ui.buttonDeleteTask->setIcon(style->standardIcon(QStyle::SP_TrashIcon)); |
| 298 |
ui.buttonEditTask->setIcon(style->standardIcon(QStyle::SP_FileIcon)); |
| 299 |
ui.buttonRunTask->setIcon(style->standardIcon(QStyle::SP_CommandLink)); |
| 300 |
mUploadIcon = style->standardIcon(QStyle::SP_ArrowUp); |
| 301 |
mDownloadIcon = style->standardIcon(QStyle::SP_ArrowDown); |
| 302 |
|
| 303 |
ui.tabs->tabBar()->setTabButton(0, QTabBar::RightSide, nullptr); |
| 304 |
ui.tabs->tabBar()->setTabButton(0, QTabBar::LeftSide, nullptr); |
| 305 |
ui.tabs->tabBar()->setTabButton(1, QTabBar::RightSide, nullptr); |
| 306 |
ui.tabs->tabBar()->setTabButton(1, QTabBar::LeftSide, nullptr); |
| 307 |
ui.tabs->tabBar()->setTabButton(2, QTabBar::RightSide, nullptr); |
| 308 |
ui.tabs->tabBar()->setTabButton(2, QTabBar::LeftSide, nullptr); |
| 309 |
ui.tabs->setCurrentIndex(0); |
| 310 |
|
| 311 |
listTasks(); |
| 312 |
|
| 313 |
QObject::connect(&mSystemTray, &QSystemTrayIcon::activated, this, |
| 314 |
[=](QSystemTrayIcon::ActivationReason reason) { |
| 315 |
if (reason == QSystemTrayIcon::DoubleClick || |
| 316 |
reason == QSystemTrayIcon::Trigger) { |
| 317 |
showNormal(); |
| 318 |
mSystemTray.setVisible(mAlwaysShowInTray); |
| 319 |
#ifdef Q_OS_MACOS |
| 320 |
osxShowDockIcon(); |
| 321 |
#endif |
| 322 |
} |
| 323 |
}); |
| 324 |
|
| 325 |
QObject::connect(&mSystemTray, &QSystemTrayIcon::messageClicked, this, [=]() { |
| 326 |
showNormal(); |
| 327 |
mSystemTray.setVisible(mAlwaysShowInTray); |
| 328 |
#ifdef Q_OS_MACOS |
| 329 |
osxShowDockIcon(); |
| 330 |
#endif |
| 331 |
|
| 332 |
ui.tabs->setCurrentIndex(1); |
| 333 |
if (mLastFinished) { |
| 334 |
mLastFinished->showDetails(); |
| 335 |
ui.jobsArea->ensureWidgetVisible(mLastFinished); |
| 336 |
} |
| 337 |
}); |
| 338 |
|
| 339 |
QMenu *trayMenu = new QMenu(this); |
| 340 |
QObject::connect( |
| 341 |
trayMenu->addAction("&Show"), &QAction::triggered, this, [=]() { |
| 342 |
MainWindow::setWindowState((windowState() & ~Qt::WindowMinimized) | |
| 343 |
Qt::WindowActive); |
| 344 |
MainWindow::show(); // bring window to top on macOS |
| 345 |
MainWindow::raise(); // bring window from minimized state on macOS |
| 346 |
MainWindow::activateWindow(); // bring window to front/unminimize on |
| 347 |
// windows |
| 348 |
mSystemTray.setVisible(mAlwaysShowInTray); |
| 349 |
#ifdef Q_OS_MACOS |
| 350 |
osxShowDockIcon(); |
| 351 |
#endif |
| 352 |
}); |
| 353 |
QObject::connect(trayMenu->addAction("&Quit"), &QAction::triggered, this, |
| 354 |
&QWidget::close); |
| 355 |
mSystemTray.setContextMenu(trayMenu); |
| 356 |
|
| 357 |
mStatusMessage = new QLabel(); |
| 358 |
ui.statusBar->addWidget(mStatusMessage); |
| 359 |
ui.statusBar->setStyleSheet("QStatusBar::item { border: 0; }"); |
| 360 |
|
| 361 |
QTimer::singleShot(0, ui.remotes, SLOT(setFocus())); |
| 362 |
|
| 363 |
QString rclone = GetRclone(); |
| 364 |
if (rclone.isEmpty()) { |
| 365 |
rclone = QStandardPaths::findExecutable("rclone"); |
| 366 |
if (rclone.isEmpty()) { |
| 367 |
QMessageBox::information( |
| 368 |
this, "Error", |
| 369 |
"Cannot check rclone version!\nPlease verify rclone location."); |
| 370 |
emit ui.preferences->trigger(); |
| 371 |
} else { |
| 372 |
auto settings = GetSettings(); |
| 373 |
settings->setValue("Settings/rclone", rclone); |
| 374 |
SetRclone(rclone); |
| 375 |
} |
| 376 |
} else { |
| 377 |
rcloneGetVersion(); |
| 378 |
} |
| 379 |
} |
| 380 |
|
| 381 |
MainWindow::~MainWindow() { |
| 382 |
auto settings = GetSettings(); |
| 383 |
settings->setValue("MainWindow/geometry", saveGeometry()); |
| 384 |
} |
| 385 |
|
| 386 |
void MainWindow::rcloneGetVersion() { |
| 387 |
bool firstTime = mFirstTime; |
| 388 |
mFirstTime = false; |
| 389 |
|
| 390 |
QProcess *p = new QProcess(); |
| 391 |
|
| 392 |
QObject::connect( |
| 393 |
p, |
| 394 |
static_cast<void (QProcess::*)(int, QProcess::ExitStatus)>( |
| 395 |
&QProcess::finished), |
| 396 |
this, [=](int code, QProcess::ExitStatus) { |
| 397 |
if (code == 0) { |
| 398 |
QString version = p->readAllStandardOutput().trimmed(); |
| 399 |
|
| 400 |
// extract rclone version - numbers only |
| 401 |
QString rclone_info1 = version; |
| 402 |
QString rclone_version_no; |
| 403 |
int lineBreak = rclone_info1.indexOf('\n'); |
| 404 |
if (lineBreak != -1) { |
| 405 |
rclone_info1.remove(lineBreak, rclone_info1.length() - lineBreak); |
| 406 |
rclone_version_no = rclone_info1; |
| 407 |
rclone_version_no.replace("rclone v", ""); |
| 408 |
rclone_version_no.replace("-DEV", ""); |
| 409 |
} else { |
| 410 |
// for very old rclone versions format was one line only |
| 411 |
rclone_version_no = rclone_info1.trimmed(); |
| 412 |
rclone_version_no.replace("rclone v", ""); |
| 413 |
rclone_version_no.replace("-DEV", ""); |
| 414 |
} |
| 415 |
// save current version no in settings |
| 416 |
auto settings = GetSettings(); |
| 417 |
settings->setValue("Settings/rcloneVersion", rclone_version_no); |
| 418 |
|
| 419 |
#if defined(Q_OS_WIN32) |
| 420 |
// check if required version |
| 421 |
unsigned int result = |
| 422 |
compareVersion(rclone_version_no.toStdString(), "1.50"); |
| 423 |
|
| 424 |
if (result == 2) { |
| 425 |
QMessageBox::warning( |
| 426 |
this, "", |
| 427 |
"For mount functionality to work you need " |
| 428 |
"rclone version at least v1.50 " |
| 429 |
"and your current version is v" + |
| 430 |
rclone_version_no + |
| 431 |
". Mount will be disabled. \n\nPlease consider upgrading."); |
| 432 |
}; |
| 433 |
#endif |
| 434 |
|
| 435 |
QStringList lines = version.split("\n", QString::SkipEmptyParts); |
| 436 |
QString rclone_info2; |
| 437 |
QString rclone_info3; |
| 438 |
|
| 439 |
int counter = 0; |
| 440 |
foreach (QString line, lines) { |
| 441 |
line = line.trimmed(); |
| 442 |
if (counter == 1) |
| 443 |
rclone_info2 = line.replace("- ", ""); |
| 444 |
if (counter == 2) |
| 445 |
rclone_info3 = line.replace("- ", ""); |
| 446 |
counter++; |
| 447 |
}; |
| 448 |
|
| 449 |
QFileInfo appBundlePath; |
| 450 |
#ifdef Q_OS_MACOS |
| 451 |
if (IsPortableMode()) { |
| 452 |
|
| 453 |
QFileInfo applicationPath = qApp->applicationFilePath(); |
| 454 |
QFileInfo MacOSPath = applicationPath.dir().path(); |
| 455 |
QFileInfo ContentsPath = MacOSPath.dir().path(); |
| 456 |
appBundlePath = ContentsPath.dir().path(); |
| 457 |
|
| 458 |
mStatusMessage->setText( |
| 459 |
rclone_info1 + " in " + |
| 460 |
QDir::toNativeSeparators(GetRclone().replace( |
| 461 |
appBundlePath.fileName() + "/Contents/MacOS/../../../", |
| 462 |
"")) + |
| 463 |
", " + rclone_info2 + ", " + rclone_info3); |
| 464 |
|
| 465 |
} else { |
| 466 |
|
| 467 |
mStatusMessage->setText(rclone_info1 + " in " + |
| 468 |
QDir::toNativeSeparators(GetRclone()) + |
| 469 |
", " + rclone_info2 + ", " + rclone_info3); |
| 470 |
} |
| 471 |
#else |
| 472 |
#ifdef Q_OS_WIN |
| 473 |
mStatusMessage->setText(rclone_info1 + " in " + |
| 474 |
QDir::toNativeSeparators(GetRclone()) + ", " + |
| 475 |
rclone_info2 + ", " + rclone_info3); |
| 476 |
#else |
| 477 |
if (IsPortableMode()) { |
| 478 |
QString xdg_config_home = qgetenv("XDG_CONFIG_HOME"); |
| 479 |
QString appImageConfigFolder = xdg_config_home.right(xdg_config_home.length()-xdg_config_home.lastIndexOf("/")); |
| 480 |
|
| 481 |
mStatusMessage->setText(rclone_info1 + " in " + |
| 482 |
QDir::toNativeSeparators(GetRclone().replace(appImageConfigFolder + "/..", "")) + ", " + |
| 483 |
rclone_info2 + ", " + rclone_info3); |
| 484 |
} else { |
| 485 |
mStatusMessage->setText(rclone_info1 + " in " + |
| 486 |
QDir::toNativeSeparators(GetRclone()) + ", " + |
| 487 |
rclone_info2 + ", " + rclone_info3); |
| 488 |
} |
| 489 |
#endif |
| 490 |
#endif |
| 491 |
|
| 492 |
rcloneListRemotes(); |
| 493 |
} else { |
| 494 |
if (p->error() != QProcess::FailedToStart) { |
| 495 |
if (getConfigPassword(p)) { |
| 496 |
rcloneGetVersion(); |
| 497 |
} else { |
| 498 |
close(); |
| 499 |
} |
| 500 |
p->deleteLater(); |
| 501 |
return; |
| 502 |
} |
| 503 |
|
| 504 |
if (firstTime) { |
| 505 |
if (p->error() == QProcess::FailedToStart) { |
| 506 |
QMessageBox::information( |
| 507 |
this, "Error", |
| 508 |
"Wrong rclone executable or rclone not found!\nPlease select " |
| 509 |
"its location in next dialog."); |
| 510 |
} else { |
| 511 |
QMessageBox::information(this, "Error", |
| 512 |
"Cannot check rclone version!\nPlease " |
| 513 |
"verify rclone location."); |
| 514 |
} |
| 515 |
emit ui.preferences->trigger(); |
| 516 |
} |
| 517 |
} |
| 518 |
|
| 519 |
auto settings = GetSettings(); |
| 520 |
|
| 521 |
/// check rclone version |
| 522 |
|
| 523 |
// get already stored rclone version no |
| 524 |
QString rclone_version_no = |
| 525 |
settings->value("Settings/rcloneVersion").toString(); |
| 526 |
|
| 527 |
// during first run the key might not exist yet |
| 528 |
if (!(settings->contains("Settings/checkRcloneUpdates"))) { |
| 529 |
// if checkRcloneUpdates does not exist create new key |
| 530 |
settings->setValue("Settings/checkRcloneUpdates", true); |
| 531 |
}; |
| 532 |
|
| 533 |
bool checkRcloneUpdates = |
| 534 |
settings->value("Settings/checkRcloneUpdates").toBool(); |
| 535 |
|
| 536 |
// if check updates enabled in settings |
| 537 |
if (checkRcloneUpdates) { |
| 538 |
QString last_check; |
| 539 |
QString current_date = QDate::currentDate().toString(); |
| 540 |
|
| 541 |
if (!(settings->contains("Settings/lastRcloneUpdateCheck"))) { |
| 542 |
// if lastRcloneUpdateCheck does not exist create new key |
| 543 |
settings->setValue("Settings/lastRcloneUpdateCheck", current_date); |
| 544 |
} else { // read last check date |
| 545 |
last_check = |
| 546 |
settings->value("Settings/lastRcloneUpdateCheck").toString(); |
| 547 |
}; |
| 548 |
|
| 549 |
// dont check if already checked today (once per day only) |
| 550 |
if (!(last_check == current_date)) { |
| 551 |
// remmber when last checked |
| 552 |
settings->setValue("Settings/lastRcloneUpdateCheck", current_date); |
| 553 |
|
| 554 |
QString url = |
| 555 |
"https://api.github.com/repos/rclone/rclone/releases/latest"; |
| 556 |
QNetworkAccessManager manager; |
| 557 |
QNetworkReply *response = manager.get(QNetworkRequest(QUrl(url))); |
| 558 |
QEventLoop event; |
| 559 |
connect(response, SIGNAL(finished()), &event, SLOT(quit())); |
| 560 |
event.exec(); |
| 561 |
QByteArray content = response->readAll(); |
| 562 |
QJsonParseError jsonError; |
| 563 |
|
| 564 |
QJsonDocument document = QJsonDocument::fromJson( |
| 565 |
content, &jsonError); // parse and capture the error flag |
| 566 |
|
| 567 |
if (jsonError.error == QJsonParseError::NoError) { |
| 568 |
|
| 569 |
if (document.object().contains("tag_name")) { |
| 570 |
|
| 571 |
QJsonValue tag_name = document.object().value("tag_name"); |
| 572 |
|
| 573 |
QString rclone_latest_version_no = tag_name.toString(QString()); |
| 574 |
|
| 575 |
rclone_latest_version_no.replace("v", ""); |
| 576 |
rclone_latest_version_no.replace("-DEV", ""); |
| 577 |
rclone_latest_version_no = rclone_latest_version_no.trimmed(); |
| 578 |
|
| 579 |
// check if new version available and if yes display information |
| 580 |
unsigned int result = |
| 581 |
compareVersion(rclone_latest_version_no.toStdString(), |
| 582 |
rclone_version_no.toStdString()); |
| 583 |
// latest version is greater than current |
| 584 |
if (result == 1) { |
| 585 |
|
| 586 |
QMessageBox::information( |
| 587 |
this, "", |
| 588 |
QString( |
| 589 |
R"(<p>New rclone version is available</p>)" |
| 590 |
R"(<p>You have: v)" + |
| 591 |
rclone_version_no + |
| 592 |
"<br />" |
| 593 |
R"(New version: v)" + |
| 594 |
rclone_latest_version_no + |
| 595 |
"</p>" |
| 596 |
R"(<p>Visit rclone <a href="https://rclone.org/downloads/">downloads</a> page to upgrade</p>)")); |
| 597 |
}; |
| 598 |
}; |
| 599 |
}; |
| 600 |
}; |
| 601 |
}; |
| 602 |
|
| 603 |
/// check rclone browser version |
| 604 |
|
| 605 |
// during first run the key might not exist yet |
| 606 |
if (!(settings->contains("Settings/checkRcloneBrowserUpdates"))) { |
| 607 |
// if checkRcloneBrowserUpdates does not exist create new key |
| 608 |
settings->setValue("Settings/checkRcloneBrowserUpdates", true); |
| 609 |
}; |
| 610 |
|
| 611 |
bool checkRcloneBrowserUpdates = |
| 612 |
settings->value("Settings/checkRcloneBrowserUpdates").toBool(); |
| 613 |
|
| 614 |
// if check updates enabled in settings |
| 615 |
if (checkRcloneBrowserUpdates) { |
| 616 |
QString last_check; |
| 617 |
QString current_date = QDate::currentDate().toString(); |
| 618 |
|
| 619 |
if (!(settings->contains("Settings/lastRcloneBrowserUpdateCheck"))) { |
| 620 |
// if lastRcloneBrowserUpdateCheck does not exist create new key |
| 621 |
settings->setValue("Settings/lastRcloneBrowserUpdateCheck", |
| 622 |
current_date); |
| 623 |
} else { // read last check date |
| 624 |
last_check = |
| 625 |
settings->value("Settings/lastRcloneBrowserUpdateCheck") |
| 626 |
.toString(); |
| 627 |
}; |
| 628 |
|
| 629 |
// dont check if already checked today (once per day only) |
| 630 |
if (!(last_check == current_date)) { |
| 631 |
// remmber when last checked |
| 632 |
settings->setValue("Settings/lastRcloneBrowserUpdateCheck", |
| 633 |
current_date); |
| 634 |
|
| 635 |
// get latest version available |
| 636 |
QString url = "https://api.github.com/repos/kapitainsky/" |
| 637 |
"rclonebrowser/releases/latest"; |
| 638 |
QNetworkAccessManager manager; |
| 639 |
QNetworkReply *response = manager.get(QNetworkRequest(QUrl(url))); |
| 640 |
QEventLoop event; |
| 641 |
connect(response, SIGNAL(finished()), &event, SLOT(quit())); |
| 642 |
event.exec(); |
| 643 |
QByteArray content = response->readAll(); |
| 644 |
|
| 645 |
QJsonParseError jsonError; |
| 646 |
QJsonDocument document = QJsonDocument::fromJson( |
| 647 |
content, &jsonError); // parse and capture the error flag |
| 648 |
|
| 649 |
if (jsonError.error == QJsonParseError::NoError) { |
| 650 |
if (document.object().contains("tag_name")) { |
| 651 |
QJsonValue tag_name = document.object().value("tag_name"); |
| 652 |
QString rclone_browser_latest_version_no = |
| 653 |
tag_name.toString(QString()); |
| 654 |
rclone_browser_latest_version_no = |
| 655 |
rclone_browser_latest_version_no.trimmed(); |
| 656 |
|
| 657 |
// check if new version available and if yes display information |
| 658 |
unsigned int result = compareVersion( |
| 659 |
rclone_browser_latest_version_no.toStdString(), |
| 660 |
RCLONE_BROWSER_VERSION); |
| 661 |
// latest version is greater than current |
| 662 |
if (result == 1) { |
| 663 |
QMessageBox::information( |
| 664 |
this, "", |
| 665 |
QString( |
| 666 |
R"(<p>New Rclone Browser version is available</p>)" |
| 667 |
R"(<p>You have: v)" RCLONE_BROWSER_VERSION "<br />" |
| 668 |
R"(New version: v)" + |
| 669 |
rclone_browser_latest_version_no + |
| 670 |
"</p>" |
| 671 |
R"(<p>Visit <a href="https://github.com/kapitainsky/RcloneBrowser/releases/latest">releases</a> page to download</p>)")); |
| 672 |
}; |
| 673 |
}; |
| 674 |
}; |
| 675 |
}; |
| 676 |
}; |
| 677 |
|
| 678 |
p->deleteLater(); |
| 679 |
}); |
| 680 |
|
| 681 |
UseRclonePassword(p); |
| 682 |
p->start(GetRclone(), |
| 683 |
QStringList() << "version" |
| 684 |
<< "--ask-password=false", |
| 685 |
QIODevice::ReadOnly); |
| 686 |
} |
| 687 |
|
| 688 |
void MainWindow::rcloneConfig() { |
| 689 |
|
| 690 |
// for macOS and Linux we have to take care of possible spaces in rclone and |
| 691 |
// rclone.conf paths by using "" around them |
| 692 |
QString terminalRcloneCmd; |
| 693 |
if (!GetRcloneConf().isEmpty()) { |
| 694 |
terminalRcloneCmd = "\"" + GetRclone() + "\"" + " config" + " --config " + |
| 695 |
"\"" + GetRcloneConf().at(1) + "\""; |
| 696 |
} else { |
| 697 |
terminalRcloneCmd = "\"" + GetRclone() + "\"" + " config"; |
| 698 |
} |
| 699 |
|
| 700 |
#if defined(Q_OS_WIN32) && (QT_VERSION < QT_VERSION_CHECK(5, 7, 0)) |
| 701 |
QProcess::startDetached(GetRclone(), QStringList() |
| 702 |
<< "config" << GetRcloneConf()); |
| 703 |
return; |
| 704 |
#else |
| 705 |
|
| 706 |
QProcess *p = new QProcess(this); |
| 707 |
|
| 708 |
QObject::connect(p, |
| 709 |
static_cast<void (QProcess::*)(int, QProcess::ExitStatus)>( |
| 710 |
&QProcess::finished), |
| 711 |
this, [=](int code, QProcess::ExitStatus) { |
| 712 |
if (code == 0) { |
| 713 |
emit rcloneListRemotes(); |
| 714 |
} |
| 715 |
p->deleteLater(); |
| 716 |
}); |
| 717 |
#endif |
| 718 |
|
| 719 |
#if defined(Q_OS_WIN32) |
| 720 |
#if QT_VERSION >= QT_VERSION_CHECK(5, 7, 0) |
| 721 |
p->setCreateProcessArgumentsModifier( |
| 722 |
[](QProcess::CreateProcessArguments *args) { |
| 723 |
args->flags |= CREATE_NEW_CONSOLE; |
| 724 |
args->startupInfo->dwFlags &= ~STARTF_USESTDHANDLES; |
| 725 |
}); |
| 726 |
p->setProgram(GetRclone()); |
| 727 |
p->setArguments(QStringList() << "config" << GetRcloneConf()); |
| 728 |
#endif |
| 729 |
|
| 730 |
#elif defined(Q_OS_MACOS) |
| 731 |
auto tmp = new QFile("/tmp/rclone_config.command"); |
| 732 |
tmp->open(QIODevice::WriteOnly); |
| 733 |
QTextStream(tmp) << "#!/bin/sh\n" << terminalRcloneCmd << "\n"; |
| 734 |
tmp->close(); |
| 735 |
tmp->setPermissions(QFileDevice::ReadUser | QFileDevice::WriteUser | |
| 736 |
QFileDevice::ExeUser | QFileDevice::ReadGroup | |
| 737 |
QFileDevice::ExeGroup | QFileDevice::ReadOther | |
| 738 |
QFileDevice::ExeOther); |
| 739 |
p->setProgram("open"); |
| 740 |
p->setArguments(QStringList() << tmp->fileName()); |
| 741 |
#else |
| 742 |
QProcessEnvironment env = QProcessEnvironment::systemEnvironment(); |
| 743 |
QString terminal = env.value("TERMINAL"); |
| 744 |
if (terminal.isEmpty()) { |
| 745 |
terminal = QStandardPaths::findExecutable("gnome-terminal"); |
| 746 |
if (terminal.isEmpty()) { |
| 747 |
terminal = QStandardPaths::findExecutable("xfce4-terminal"); |
| 748 |
if (terminal.isEmpty()) { |
| 749 |
terminal = QStandardPaths::findExecutable("xterm"); |
| 750 |
if (terminal.isEmpty()) { |
| 751 |
terminal = QStandardPaths::findExecutable("x-terminal-emulator"); |
| 752 |
if (terminal.isEmpty()) { |
| 753 |
terminal = QStandardPaths::findExecutable("konsole"); |
| 754 |
if (terminal.isEmpty()) { |
| 755 |
QMessageBox::critical(this, "Error", |
| 756 |
"Not sure how to launch terminal!\n" |
| 757 |
"Please set path to terminal executable in " |
| 758 |
"$TERMINAL environment variable.", |
| 759 |
QMessageBox::Ok); |
| 760 |
return; |
| 761 |
} |
| 762 |
} |
| 763 |
} |
| 764 |
} |
| 765 |
} |
| 766 |
} |
| 767 |
|
| 768 |
p->setArguments(QStringList() << "-e" << terminalRcloneCmd); |
| 769 |
p->setProgram(terminal); |
| 770 |
#endif |
| 771 |
|
| 772 |
#if !defined(Q_OS_WIN32) || (QT_VERSION >= QT_VERSION_CHECK(5, 7, 0)) |
| 773 |
UseRclonePassword(p); |
| 774 |
p->start(QIODevice::NotOpen); |
| 775 |
#endif |
| 776 |
} |
| 777 |
|
| 778 |
void MainWindow::rcloneListRemotes() { |
| 779 |
ui.remotes->clear(); |
| 780 |
|
| 781 |
QProcess *p = new QProcess(); |
| 782 |
|
| 783 |
QObject::connect( |
| 784 |
p, |
| 785 |
static_cast<void (QProcess::*)(int, QProcess::ExitStatus)>( |
| 786 |
&QProcess::finished), |
| 787 |
this, [=](int code, QProcess::ExitStatus) { |
| 788 |
if (code == 0) { |
| 789 |
QStyle *style = qApp->style(); |
| 790 |
|
| 791 |
QString bytes = p->readAllStandardOutput().trimmed(); |
| 792 |
QStringList items = bytes.split('\n'); |
| 793 |
|
| 794 |
auto settings = GetSettings(); |
| 795 |
bool darkModeIni = settings->value("Settings/darkModeIni").toBool(); |
| 796 |
QString iconSize = settings->value("Settings/iconSize").toString(); |
| 797 |
|
| 798 |
for (const QString &line : items) { |
| 799 |
if (line.isEmpty()) { |
| 800 |
continue; |
| 801 |
} |
| 802 |
|
| 803 |
QStringList parts = line.split(':'); |
| 804 |
if (parts.count() != 2) { |
| 805 |
continue; |
| 806 |
} |
| 807 |
|
| 808 |
QString name = parts[0].trimmed(); |
| 809 |
QString type = parts[1].trimmed(); |
| 810 |
QString tooltip = type; |
| 811 |
|
| 812 |
QString img_add = ""; |
| 813 |
int size; |
| 814 |
|
| 815 |
// medium scale by default |
| 816 |
double darkModeIconScale = 1.333; |
| 817 |
double lightModeiconScale = 2; |
| 818 |
// to avoid "variable not used" compiler error |
| 819 |
if (darkModeIconScale == lightModeiconScale) { |
| 820 |
}; |
| 821 |
|
| 822 |
// set icons scale based on iconSize value |
| 823 |
if (iconSize == "small") { |
| 824 |
lightModeiconScale = 1.5; |
| 825 |
darkModeIconScale = 1; |
| 826 |
} |
| 827 |
|
| 828 |
if (iconSize == "medium") { |
| 829 |
lightModeiconScale = 2; |
| 830 |
darkModeIconScale = 1.333; |
| 831 |
} |
| 832 |
|
| 833 |
if (iconSize == "large") { |
| 834 |
lightModeiconScale = 3; |
| 835 |
darkModeIconScale = 2; |
| 836 |
} |
| 837 |
|
| 838 |
#if !defined(Q_OS_MACOS) |
| 839 |
// _inv only for dark mode |
| 840 |
// we use darkModeIni to apply mode active at startup |
| 841 |
if (darkModeIni) { |
| 842 |
img_add = "_inv"; |
| 843 |
|
| 844 |
} else { |
| 845 |
img_add = ""; |
| 846 |
} |
| 847 |
#if defined(Q_OS_WIN) |
| 848 |
// on Windows dark theme changes PM_ListViewIconSize size |
| 849 |
// so we have to adjust |
| 850 |
if (darkModeIni) { |
| 851 |
size = darkModeIconScale * |
| 852 |
style->pixelMetric(QStyle::PM_ListViewIconSize); |
| 853 |
} else { |
| 854 |
size = lightModeiconScale * |
| 855 |
style->pixelMetric(QStyle::PM_ListViewIconSize); |
| 856 |
} |
| 857 |
#else |
| 858 |
// for Linux/BSD PM_ListViewIconSize stays the same |
| 859 |
size = lightModeiconScale * style->pixelMetric(QStyle::PM_ListViewIconSize); |
| 860 |
#endif |
| 861 |
#else |
| 862 |
QString sysInfo = QSysInfo::productVersion(); |
| 863 |
// dark mode on older macOS |
| 864 |
if (sysInfo == "10.9" || |
| 865 |
sysInfo == "10.10" || |
| 866 |
sysInfo == "10.11" || |
| 867 |
sysInfo == "10.12" || |
| 868 |
sysInfo == "10.13") { |
| 869 |
|
| 870 |
// on older macOS we also have to adjust icon size per mode |
| 871 |
if (darkModeIni) { |
| 872 |
size = darkModeIconScale * style->pixelMetric(QStyle::PM_ListViewIconSize); |
| 873 |
img_add = "_inv"; |
| 874 |
} else { |
| 875 |
size = lightModeiconScale * style->pixelMetric(QStyle::PM_ListViewIconSize); |
| 876 |
img_add = ""; |
| 877 |
} |
| 878 |
|
| 879 |
} else { |
| 880 |
// for macOS > 10.13 native dark mode does not change IconSize base |
| 881 |
size = 1.5 * lightModeiconScale * style->pixelMetric(QStyle::PM_ListViewIconSize); |
| 882 |
} |
| 883 |
#endif |
| 884 |
ui.remotes->setIconSize(QSize(size, size)); |
| 885 |
|
| 886 |
QString path = |
| 887 |
":/remotes/images/" + type.replace(' ', '_') + img_add + ".png"; |
| 888 |
QIcon icon(QFile(path).exists() |
| 889 |
? path |
| 890 |
: ":/remotes/images/unknown" + img_add + ".png"); |
| 891 |
|
| 892 |
QListWidgetItem *item = new QListWidgetItem(icon, name); |
| 893 |
item->setData(Qt::UserRole, type); |
| 894 |
item->setToolTip(tooltip); |
| 895 |
ui.remotes->addItem(item); |
| 896 |
} |
| 897 |
} else { |
| 898 |
if (p->error() != QProcess::FailedToStart) { |
| 899 |
if (getConfigPassword(p)) { |
| 900 |
rcloneListRemotes(); |
| 901 |
} |
| 902 |
} |
| 903 |
} |
| 904 |
p->deleteLater(); |
| 905 |
}); |
| 906 |
|
| 907 |
UseRclonePassword(p); |
| 908 |
p->start(GetRclone(), |
| 909 |
QStringList() << "listremotes" << GetRcloneConf() << "--long" |
| 910 |
<< "--ask-password=false", |
| 911 |
QIODevice::ReadOnly); |
| 912 |
} |
| 913 |
|
| 914 |
bool MainWindow::getConfigPassword(QProcess *p) { |
| 915 |
QString output = p->readAllStandardError().trimmed(); |
| 916 |
if (output.indexOf("RCLONE_CONFIG_PASS") > 0) { |
| 917 |
bool ok; |
| 918 |
QString password = QInputDialog::getText( |
| 919 |
this, qApp->applicationDisplayName(), |
| 920 |
"Enter password for .rclone.conf configuration file:", |
| 921 |
QLineEdit::Password, QString(), &ok); |
| 922 |
if (ok) { |
| 923 |
SetRclonePassword(password); |
| 924 |
return true; |
| 925 |
} |
| 926 |
} else if (output.indexOf("unknown command \"listremotes\"") > 0) { |
| 927 |
QMessageBox::critical(this, qApp->applicationDisplayName(), |
| 928 |
"It seems rclone version you are using is too " |
| 929 |
"old.\nPlease upgrade to the latest version"); |
| 930 |
return false; |
| 931 |
} |
| 932 |
return false; |
| 933 |
} |
| 934 |
|
| 935 |
bool MainWindow::canClose() { |
| 936 |
if (mJobCount == 0) { |
| 937 |
return true; |
| 938 |
} |
| 939 |
|
| 940 |
bool wasVisible = isVisible(); |
| 941 |
|
| 942 |
ui.tabs->setCurrentIndex(1); |
| 943 |
showNormal(); |
| 944 |
|
| 945 |
int button = |
| 946 |
QMessageBox::question(this, "Rclone Browser", |
| 947 |
QString("There are %1 job(s) running.\n" |
| 948 |
"Do you want to stop them and quit?") |
| 949 |
.arg(mJobCount), |
| 950 |
QMessageBox::Yes | QMessageBox::No); |
| 951 |
|
| 952 |
if (!wasVisible) { |
| 953 |
hide(); |
| 954 |
} |
| 955 |
|
| 956 |
if (button == QMessageBox::Yes) { |
| 957 |
for (int i = 0; i < ui.jobs->count(); i++) { |
| 958 |
QWidget *widget = ui.jobs->itemAt(i)->widget(); |
| 959 |
if (auto mount = qobject_cast<MountWidget *>(widget)) { |
| 960 |
mount->cancel(); |
| 961 |
} else if (auto transfer = qobject_cast<JobWidget *>(widget)) { |
| 962 |
transfer->cancel(); |
| 963 |
} else if (auto stream = qobject_cast<StreamWidget *>(widget)) { |
| 964 |
stream->cancel(); |
| 965 |
} |
| 966 |
} |
| 967 |
return true; |
| 968 |
} |
| 969 |
|
| 970 |
return false; |
| 971 |
} |
| 972 |
|
| 973 |
void MainWindow::closeEvent(QCloseEvent *ev) { |
| 974 |
if (mCloseToTray && isVisible()) { |
| 975 |
#ifdef Q_OS_MACOS |
| 976 |
osxHideDockIcon(); |
| 977 |
#endif |
| 978 |
mSystemTray.show(); |
| 979 |
hide(); |
| 980 |
ev->ignore(); |
| 981 |
return; |
| 982 |
} |
| 983 |
|
| 984 |
if (canClose()) { |
| 985 |
QApplication::quit(); |
| 986 |
} else { |
| 987 |
ev->ignore(); |
| 988 |
} |
| 989 |
} |
| 990 |
|
| 991 |
void MainWindow::listTasks() { |
| 992 |
ui.tasksListWidget->clear(); |
| 993 |
|
| 994 |
ListOfJobOptions *ljo = ListOfJobOptions::getInstance(); |
| 995 |
|
| 996 |
for (JobOptions *jo : ljo->getTasks()) { |
| 997 |
JobOptionsListWidgetItem *item = new JobOptionsListWidgetItem( |
| 998 |
jo, |
| 999 |
jo->jobType == JobOptions::JobType::Download ? mDownloadIcon |
| 1000 |
: mUploadIcon, |
| 1001 |
jo->description); |
| 1002 |
ui.tasksListWidget->addItem(item); |
| 1003 |
} |
| 1004 |
} |
| 1005 |
|
| 1006 |
void MainWindow::runItem(JobOptionsListWidgetItem *item, bool dryrun) { |
| 1007 |
if (item == nullptr) |
| 1008 |
return; |
| 1009 |
JobOptions *jo = item->GetData(); |
| 1010 |
jo->dryRun = dryrun; |
| 1011 |
QStringList args = jo->getOptions(); |
| 1012 |
addTransfer(QString("%1 %2").arg(jo->operation).arg(jo->source), jo->source, |
| 1013 |
jo->dest, args); |
| 1014 |
} |
| 1015 |
|
| 1016 |
void MainWindow::editSelectedTask() { |
| 1017 |
auto selection = ui.tasksListWidget->selectionModel()->currentIndex(); |
| 1018 |
JobOptionsListWidgetItem *item = static_cast<JobOptionsListWidgetItem *>( |
| 1019 |
ui.tasksListWidget->currentItem()); |
| 1020 |
JobOptions *jo = item->GetData(); |
| 1021 |
bool isDownload = (jo->jobType == JobOptions::Download); |
| 1022 |
QString remote = isDownload ? jo->source : jo->dest; |
| 1023 |
QString path = isDownload ? jo->dest : jo->source; |
| 1024 |
// qDebug() << "remote:" + remote; |
| 1025 |
// qDebug() << "path:" + path; |
| 1026 |
TransferDialog td(isDownload, false, remote, path, jo->isFolder, this, jo, |
| 1027 |
true); |
| 1028 |
td.exec(); |
| 1029 |
// restore the selection to help user keep track of what s/he was doing |
| 1030 |
ui.tasksListWidget->selectionModel()->select(selection, |
| 1031 |
QItemSelectionModel::Select); |
| 1032 |
// edit mode on the TransferDialog suppresses the usual Accept buttons |
| 1033 |
// and the Save Task button closes it... so there is nothing more to do here |
| 1034 |
} |
| 1035 |
|
| 1036 |
void MainWindow::addTransfer(const QString &message, const QString &source, |
| 1037 |
const QString &dest, const QStringList &args) { |
| 1038 |
QProcess *transfer = new QProcess(this); |
| 1039 |
transfer->setProcessChannelMode(QProcess::MergedChannels); |
| 1040 |
|
| 1041 |
auto widget = new JobWidget(transfer, message, args, source, dest); |
| 1042 |
|
| 1043 |
auto line = new QFrame(); |
| 1044 |
line->setFrameShape(QFrame::HLine); |
| 1045 |
line->setFrameShadow(QFrame::Sunken); |
| 1046 |
|
| 1047 |
QObject::connect( |
| 1048 |
widget, &JobWidget::finished, this, [=](const QString &info) { |
| 1049 |
if (mNotifyFinishedTransfers) { |
| 1050 |
qApp->alert(this); |
| 1051 |
mLastFinished = widget; |
| 1052 |
mSystemTray.showMessage("Transfer finished", info); |
| 1053 |
} |
| 1054 |
|
| 1055 |
if (--mJobCount == 0) { |
| 1056 |
ui.tabs->setTabText(1, "Jobs"); |
| 1057 |
} else { |
| 1058 |
ui.tabs->setTabText(1, QString("Jobs (%1)").arg(mJobCount)); |
| 1059 |
} |
| 1060 |
}); |
| 1061 |
|
| 1062 |
QObject::connect(widget, &JobWidget::closed, this, [=]() { |
| 1063 |
if (widget == mLastFinished) { |
| 1064 |
mLastFinished = nullptr; |
| 1065 |
} |
| 1066 |
ui.jobs->removeWidget(widget); |
| 1067 |
ui.jobs->removeWidget(line); |
| 1068 |
widget->deleteLater(); |
| 1069 |
delete line; |
| 1070 |
if (ui.jobs->count() == 2) { |
| 1071 |
ui.noJobsAvailable->show(); |
| 1072 |
} |
| 1073 |
}); |
| 1074 |
|
| 1075 |
if (ui.jobs->count() == 2) { |
| 1076 |
ui.noJobsAvailable->hide(); |
| 1077 |
} |
| 1078 |
|
| 1079 |
ui.jobs->insertWidget(0, widget); |
| 1080 |
ui.jobs->insertWidget(1, line); |
| 1081 |
ui.tabs->setTabText(1, QString("Jobs (%1)").arg(++mJobCount)); |
| 1082 |
|
| 1083 |
UseRclonePassword(transfer); |
| 1084 |
transfer->start(GetRclone(), GetRcloneConf() + args, QIODevice::ReadOnly); |
| 1085 |
} |
| 1086 |
|
| 1087 |
void MainWindow::addMount(const QString &remote, const QString &folder) { |
| 1088 |
QProcess *mount = new QProcess(this); |
| 1089 |
mount->setProcessChannelMode(QProcess::MergedChannels); |
| 1090 |
|
| 1091 |
auto widget = new MountWidget(mount, remote, folder); |
| 1092 |
|
| 1093 |
auto line = new QFrame(); |
| 1094 |
line->setFrameShape(QFrame::HLine); |
| 1095 |
line->setFrameShadow(QFrame::Sunken); |
| 1096 |
|
| 1097 |
QObject::connect(widget, &MountWidget::finished, this, [=]() { |
| 1098 |
if (--mJobCount == 0) { |
| 1099 |
ui.tabs->setTabText(1, "Jobs"); |
| 1100 |
} else { |
| 1101 |
ui.tabs->setTabText(1, QString("Jobs (%1)").arg(mJobCount)); |
| 1102 |
} |
| 1103 |
}); |
| 1104 |
|
| 1105 |
QObject::connect(widget, &MountWidget::closed, this, [=]() { |
| 1106 |
ui.jobs->removeWidget(widget); |
| 1107 |
ui.jobs->removeWidget(line); |
| 1108 |
widget->deleteLater(); |
| 1109 |
delete line; |
| 1110 |
if (ui.jobs->count() == 2) { |
| 1111 |
ui.noJobsAvailable->show(); |
| 1112 |
} |
| 1113 |
}); |
| 1114 |
|
| 1115 |
if (ui.jobs->count() == 2) { |
| 1116 |
ui.noJobsAvailable->hide(); |
| 1117 |
} |
| 1118 |
|
| 1119 |
ui.jobs->insertWidget(0, widget); |
| 1120 |
ui.jobs->insertWidget(1, line); |
| 1121 |
ui.tabs->setTabText(1, QString("Jobs (%1)").arg(++mJobCount)); |
| 1122 |
|
| 1123 |
auto settings = GetSettings(); |
| 1124 |
QString opt = settings->value("Settings/mount").toString(); |
| 1125 |
bool driveShared = settings->value("Settings/driveShared").toBool(); |
| 1126 |
|
| 1127 |
QStringList args; |
| 1128 |
args << "mount"; |
| 1129 |
|
| 1130 |
#if defined(Q_OS_WIN32) |
| 1131 |
args << "--rc"; |
| 1132 |
args << "--rc-addr"; |
| 1133 |
|
| 1134 |
// calculate remote control interface port based on mount drive letter |
| 1135 |
// this way every mount will have unique port assigned |
| 1136 |
int port_offset = folder[0].toLatin1(); |
| 1137 |
unsigned short int rclone_rc_port_base = 19000; |
| 1138 |
unsigned short int rclone_rc_port = rclone_rc_port_base + port_offset; |
| 1139 |
args << "localhost:" + QVariant(rclone_rc_port).toString(); |
| 1140 |
#endif |
| 1141 |
|
| 1142 |
// for google drive "shared with me" without --read-only writes go created in |
| 1143 |
// main google drive it is more logical to mount it as read only so there is |
| 1144 |
// no confusion |
| 1145 |
if (driveShared) { |
| 1146 |
args << "--drive-shared-with-me"; |
| 1147 |
args << "--read-only"; |
| 1148 |
}; |
| 1149 |
|
| 1150 |
// default mount is now more generic. all options can be passed via |
| 1151 |
// preferences mount field |
| 1152 |
// args << "--vfs-cache-mode"; |
| 1153 |
// args << "writes"; |
| 1154 |
|
| 1155 |
args.append(GetRcloneConf()); |
| 1156 |
if (!opt.isEmpty()) { |
| 1157 |
args.append(opt.split(' ')); |
| 1158 |
} |
| 1159 |
args << remote << folder; |
| 1160 |
|
| 1161 |
UseRclonePassword(mount); |
| 1162 |
mount->start(GetRclone(), args, QIODevice::ReadOnly); |
| 1163 |
} |
| 1164 |
|
| 1165 |
void MainWindow::addStream(const QString &remote, const QString &stream) { |
| 1166 |
auto player = new QProcess(); |
| 1167 |
auto rclone = new QProcess(); |
| 1168 |
rclone->setStandardOutputProcess(player); |
| 1169 |
|
| 1170 |
QObject::connect( |
| 1171 |
player, |
| 1172 |
static_cast<void (QProcess::*)(int, QProcess::ExitStatus)>( |
| 1173 |
&QProcess::finished), |
| 1174 |
this, [=](int status, QProcess::ExitStatus) { |
| 1175 |
player->deleteLater(); |
| 1176 |
if (status != 0 && player->error() == QProcess::FailedToStart) { |
| 1177 |
QMessageBox::critical( |
| 1178 |
this, "Error", |
| 1179 |
QString("Failed to start '%1' player process").arg(stream)); |
| 1180 |
auto settings = GetSettings(); |
| 1181 |
settings->remove("Settings/streamConfirmed"); |
| 1182 |
} |
| 1183 |
}); |
| 1184 |
|
| 1185 |
auto widget = new StreamWidget(rclone, player, remote, stream); |
| 1186 |
|
| 1187 |
auto line = new QFrame(); |
| 1188 |
line->setFrameShape(QFrame::HLine); |
| 1189 |
line->setFrameShadow(QFrame::Sunken); |
| 1190 |
|
| 1191 |
QObject::connect(widget, &StreamWidget::finished, this, [=]() { |
| 1192 |
if (--mJobCount == 0) { |
| 1193 |
ui.tabs->setTabText(1, "Jobs"); |
| 1194 |
} else { |
| 1195 |
ui.tabs->setTabText(1, QString("Jobs (%1)").arg(mJobCount)); |
| 1196 |
} |
| 1197 |
}); |
| 1198 |
|
| 1199 |
QObject::connect(widget, &StreamWidget::closed, this, [=]() { |
| 1200 |
ui.jobs->removeWidget(widget); |
| 1201 |
ui.jobs->removeWidget(line); |
| 1202 |
widget->deleteLater(); |
| 1203 |
delete line; |
| 1204 |
if (ui.jobs->count() == 2) { |
| 1205 |
ui.noJobsAvailable->show(); |
| 1206 |
} |
| 1207 |
}); |
| 1208 |
|
| 1209 |
if (ui.jobs->count() == 2) { |
| 1210 |
ui.noJobsAvailable->hide(); |
| 1211 |
} |
| 1212 |
|
| 1213 |
ui.jobs->insertWidget(0, widget); |
| 1214 |
ui.jobs->insertWidget(1, line); |
| 1215 |
ui.tabs->setTabText(1, QString("Jobs (%1)").arg(++mJobCount)); |
| 1216 |
|
| 1217 |
player->start(stream, QProcess::ReadOnly); |
| 1218 |
UseRclonePassword(rclone); |
| 1219 |
rclone->start(GetRclone(), |
| 1220 |
QStringList() << "cat" << GetRcloneConf() << remote, |
| 1221 |
QProcess::WriteOnly); |
| 1222 |
} |