| 1 |
#include "preferences_dialog.h" |
| 2 |
#include "utils.h" |
| 3 |
|
| 4 |
PreferencesDialog::PreferencesDialog(QWidget *parent) : QDialog(parent) { |
| 5 |
ui.setupUi(this); |
| 6 |
|
| 7 |
QObject::connect(ui.rcloneBrowse, &QPushButton::clicked, this, [=]() { |
| 8 |
QString rclone = QFileDialog::getOpenFileName( |
| 9 |
this, "Select rclone executable", ui.rclone->text()); |
| 10 |
if (rclone.isEmpty()) { |
| 11 |
return; |
| 12 |
} |
| 13 |
|
| 14 |
if (!QFileInfo(rclone).isExecutable()) { |
| 15 |
QMessageBox::critical(this, "Error", |
| 16 |
QString("File %1 is not executable").arg(rclone)); |
| 17 |
return; |
| 18 |
} |
| 19 |
|
| 20 |
if (QFileInfo(rclone) == QFileInfo(qApp->applicationFilePath())) { |
| 21 |
QMessageBox::critical(this, "Error", |
| 22 |
"You selected RcloneBrowser executable!\nPlease " |
| 23 |
"select rclone executable instead."); |
| 24 |
return; |
| 25 |
} |
| 26 |
|
| 27 |
ui.rclone->setText(rclone); |
| 28 |
}); |
| 29 |
|
| 30 |
QObject::connect(ui.rcloneConfBrowse, &QPushButton::clicked, this, [=]() { |
| 31 |
QString rcloneConf = QFileDialog::getOpenFileName( |
| 32 |
this, "Select .rclone.conf location", ui.rcloneConf->text()); |
| 33 |
if (rcloneConf.isEmpty()) { |
| 34 |
return; |
| 35 |
} |
| 36 |
|
| 37 |
ui.rcloneConf->setText(rcloneConf); |
| 38 |
}); |
| 39 |
|
| 40 |
QObject::connect( |
| 41 |
ui.defaultDownloadDirBrowse, &QPushButton::clicked, this, [=]() { |
| 42 |
QString defaultDownloadDir = QFileDialog::getExistingDirectory( |
| 43 |
this, "Select default download directory", |
| 44 |
ui.defaultDownloadDir->text()); |
| 45 |
|
| 46 |
if (defaultDownloadDir.isEmpty()) { |
| 47 |
return; |
| 48 |
} |
| 49 |
|
| 50 |
ui.defaultDownloadDir->setText(defaultDownloadDir); |
| 51 |
}); |
| 52 |
|
| 53 |
QObject::connect( |
| 54 |
ui.defaultUploadDirBrowse, &QPushButton::clicked, this, [=]() { |
| 55 |
QString defaultUploadDir = QFileDialog::getExistingDirectory( |
| 56 |
this, "Select default upload directory", |
| 57 |
ui.defaultUploadDir->text()); |
| 58 |
|
| 59 |
if (defaultUploadDir.isEmpty()) { |
| 60 |
return; |
| 61 |
} |
| 62 |
|
| 63 |
ui.defaultUploadDir->setText(defaultUploadDir); |
| 64 |
}); |
| 65 |
|
| 66 |
auto settings = GetSettings(); |
| 67 |
ui.rclone->setText( |
| 68 |
QDir::toNativeSeparators(settings->value("Settings/rclone").toString())); |
| 69 |
ui.rcloneConf->setText(QDir::toNativeSeparators( |
| 70 |
settings->value("Settings/rcloneConf").toString())); |
| 71 |
ui.stream->setText(settings->value("Settings/stream").toString()); |
| 72 |
|
| 73 |
#if defined(Q_OS_OPENBSD) || defined(Q_OS_NETBSD) |
| 74 |
ui.mount->setText( |
| 75 |
settings |
| 76 |
->value("Settings/mount", |
| 77 |
"* mount is not supported by rclone on this system *") |
| 78 |
.toString()); |
| 79 |
ui.mount->setDisabled(true); |
| 80 |
#else |
| 81 |
ui.mount->setText( |
| 82 |
settings->value("Settings/mount", "--vfs-cache-mode writes").toString()); |
| 83 |
#endif |
| 84 |
|
| 85 |
ui.defaultDownloadDir->setText(QDir::toNativeSeparators( |
| 86 |
settings->value("Settings/defaultDownloadDir").toString())); |
| 87 |
ui.defaultUploadDir->setText(QDir::toNativeSeparators( |
| 88 |
settings->value("Settings/defaultUploadDir").toString())); |
| 89 |
ui.defaultDownloadOptions->setText( |
| 90 |
settings->value("Settings/defaultDownloadOptions").toString()); |
| 91 |
ui.defaultUploadOptions->setText( |
| 92 |
settings->value("Settings/defaultUploadOptions").toString()); |
| 93 |
ui.defaultRcloneOptions->setText( |
| 94 |
settings->value("Settings/defaultRcloneOptions").toString()); |
| 95 |
|
| •96 |
ui.checkRcloneBrowserUpdates->setChecked(false); |
| 97 |
ui.checkRcloneUpdates->setChecked(false); |
| 98 |
|
| 99 |
if (QSystemTrayIcon::isSystemTrayAvailable()) { |
| 100 |
ui.alwaysShowInTray->setChecked( |
| 101 |
settings->value("Settings/alwaysShowInTray", false).toBool()); |
| 102 |
ui.closeToTray->setChecked( |
| 103 |
settings->value("Settings/closeToTray", false).toBool()); |
| 104 |
ui.notifyFinishedTransfers->setChecked( |
| 105 |
settings->value("Settings/notifyFinishedTransfers", true).toBool()); |
| 106 |
} else { |
| 107 |
ui.alwaysShowInTray->setChecked(false); |
| 108 |
ui.alwaysShowInTray->setDisabled(true); |
| 109 |
ui.closeToTray->setChecked(false); |
| 110 |
ui.closeToTray->setDisabled(true); |
| 111 |
ui.notifyFinishedTransfers->setChecked(false); |
| 112 |
ui.notifyFinishedTransfers->setDisabled(true); |
| 113 |
} |
| 114 |
|
| 115 |
ui.showFolderIcons->setChecked( |
| 116 |
settings->value("Settings/showFolderIcons", true).toBool()); |
| 117 |
ui.showFileIcons->setChecked( |
| 118 |
settings->value("Settings/showFileIcons", true).toBool()); |
| 119 |
ui.rowColors->setChecked( |
| 120 |
settings->value("Settings/rowColors", true).toBool()); |
| 121 |
ui.showHidden->setChecked( |
| 122 |
settings->value("Settings/showHidden", true).toBool()); |
| 123 |
ui.darkMode->setChecked(settings->value("Settings/darkMode", true).toBool()); |
| 124 |
|
| 125 |
// dark mode option for all systems but latest macOS |
| 126 |
// on macOS Mojave or newer dark mode is managed by OS |
| 127 |
#if defined(Q_OS_MACOS) |
| 128 |
QString sysInfo = QSysInfo::productVersion(); |
| 129 |
if (sysInfo == "10.9" || sysInfo == "10.10" || sysInfo == "10.11" || |
| 130 |
sysInfo == "10.12" || sysInfo == "10.13") { |
| 131 |
} else { |
| 132 |
ui.darkMode->hide(); |
| 133 |
ui.darkMode_info->hide(); |
| 134 |
} |
| 135 |
#endif |
| 136 |
|
| 137 |
if ((settings->value("Settings/iconSize").toString()) == "small") { |
| 138 |
ui.cb_small->setChecked(true); |
| 139 |
} else { |
| 140 |
if (settings->value("Settings/iconSize").toString() == "large") { |
| 141 |
ui.cb_large->setChecked(true); |
| 142 |
} else { |
| 143 |
ui.cb_medium->setChecked(true); |
| 144 |
} |
| 145 |
} |
| 146 |
|
| 147 |
ui.info_2->setText( |
| 148 |
"See rclone <a " |
| 149 |
"href=\"https://github.com/rclone/rclone/blob/master/docs/content/" |
| 150 |
"faq.md#can-i-use-rclone-with-an-http-proxy\">FAQ</a> for details."); |
| 151 |
ui.info_2->setTextFormat(Qt::RichText); |
| 152 |
ui.info_2->setTextInteractionFlags(Qt::TextBrowserInteraction); |
| 153 |
ui.info_2->setOpenExternalLinks(true); |
| 154 |
|
| 155 |
if (settings->value("Settings/useProxy").toBool()) { |
| 156 |
ui.useProxy->setChecked(true); |
| 157 |
} else { |
| 158 |
ui.useSystemSettings->setChecked(true); |
| 159 |
} |
| 160 |
ui.http_proxy->setText(settings->value("Settings/http_proxy").toString()); |
| 161 |
ui.https_proxy->setText(settings->value("Settings/https_proxy").toString()); |
| 162 |
ui.no_proxy->setText(settings->value("Settings/no_proxy").toString()); |
| 163 |
} |
| 164 |
|
| 165 |
PreferencesDialog::~PreferencesDialog() {} |
| 166 |
|
| 167 |
QString PreferencesDialog::getRclone() const { |
| 168 |
return QDir::fromNativeSeparators(ui.rclone->text()); |
| 169 |
} |
| 170 |
|
| 171 |
QString PreferencesDialog::getRcloneConf() const { |
| 172 |
return QDir::fromNativeSeparators(ui.rcloneConf->text()); |
| 173 |
} |
| 174 |
|
| 175 |
QString PreferencesDialog::getStream() const { return ui.stream->text(); } |
| 176 |
|
| 177 |
QString PreferencesDialog::getMount() const { return ui.mount->text(); } |
| 178 |
|
| 179 |
QString PreferencesDialog::getDefaultDownloadDir() const { |
| 180 |
return QDir::fromNativeSeparators(ui.defaultDownloadDir->text()); |
| 181 |
} |
| 182 |
|
| 183 |
QString PreferencesDialog::getDefaultUploadDir() const { |
| 184 |
return QDir::fromNativeSeparators(ui.defaultUploadDir->text()); |
| 185 |
} |
| 186 |
|
| 187 |
QString PreferencesDialog::getDefaultDownloadOptions() const { |
| 188 |
return ui.defaultDownloadOptions->text(); |
| 189 |
} |
| 190 |
|
| 191 |
QString PreferencesDialog::getDefaultUploadOptions() const { |
| 192 |
return ui.defaultUploadOptions->text(); |
| 193 |
} |
| 194 |
|
| 195 |
QString PreferencesDialog::getDefaultRcloneOptions() const { |
| 196 |
return ui.defaultRcloneOptions->text(); |
| 197 |
} |
| 198 |
|
| 199 |
bool PreferencesDialog::getCheckRcloneBrowserUpdates() const { |
| 200 |
return ui.checkRcloneBrowserUpdates->isChecked(); |
| 201 |
} |
| 202 |
|
| 203 |
bool PreferencesDialog::getCheckRcloneUpdates() const { |
| 204 |
return ui.checkRcloneUpdates->isChecked(); |
| 205 |
} |
| 206 |
|
| 207 |
bool PreferencesDialog::getAlwaysShowInTray() const { |
| 208 |
return ui.alwaysShowInTray->isChecked(); |
| 209 |
} |
| 210 |
|
| 211 |
bool PreferencesDialog::getCloseToTray() const { |
| 212 |
return ui.closeToTray->isChecked(); |
| 213 |
} |
| 214 |
|
| 215 |
bool PreferencesDialog::getNotifyFinishedTransfers() const { |
| 216 |
return ui.notifyFinishedTransfers->isChecked(); |
| 217 |
} |
| 218 |
|
| 219 |
bool PreferencesDialog::getShowFolderIcons() const { |
| 220 |
return ui.showFolderIcons->isChecked(); |
| 221 |
} |
| 222 |
|
| 223 |
bool PreferencesDialog::getShowFileIcons() const { |
| 224 |
return ui.showFileIcons->isChecked(); |
| 225 |
} |
| 226 |
|
| 227 |
bool PreferencesDialog::getRowColors() const { |
| 228 |
return ui.rowColors->isChecked(); |
| 229 |
} |
| 230 |
|
| 231 |
bool PreferencesDialog::getShowHidden() const { |
| 232 |
return ui.showHidden->isChecked(); |
| 233 |
} |
| 234 |
|
| 235 |
bool PreferencesDialog::getDarkMode() const { return ui.darkMode->isChecked(); } |
| 236 |
|
| 237 |
QString PreferencesDialog::getIconSize() const { |
| 238 |
if (ui.cb_small->isChecked()) { |
| 239 |
return "small"; |
| 240 |
} else { |
| 241 |
if (ui.cb_large->isChecked()) { |
| 242 |
return "large"; |
| 243 |
} else { |
| 244 |
return "medium"; |
| 245 |
} |
| 246 |
} |
| 247 |
} |
| 248 |
|
| 249 |
QString PreferencesDialog::getHttpProxy() const { |
| 250 |
return ui.http_proxy->text(); |
| 251 |
} |
| 252 |
|
| 253 |
QString PreferencesDialog::getHttpsProxy() const { |
| 254 |
return ui.https_proxy->text(); |
| 255 |
} |
| 256 |
|
| 257 |
QString PreferencesDialog::getNoProxy() const { return ui.no_proxy->text(); } |
| 258 |
|
| 259 |
bool PreferencesDialog::getUseProxy() const { |
| 260 |
if (ui.useSystemSettings->isChecked()) { |
| 261 |
return false; |
| 262 |
} else { |
| 263 |
return true; |
| 264 |
} |
| 265 |
} |