Skip to content

Commit

Permalink
Update options UI
Browse files Browse the repository at this point in the history
  Guaranteed to work with strings with qt-style separators internally, shows string with native separators to the user
  • Loading branch information
Gelmir committed Jan 22, 2014
1 parent 48250c7 commit b706210
Showing 1 changed file with 27 additions and 76 deletions.
103 changes: 27 additions & 76 deletions src/preferences/options_imp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -376,17 +376,9 @@ void options_imp::saveOptions() {
// End General preferences

// Downloads preferences
QString save_path = getSavePath();
#if defined(Q_WS_WIN) || defined(Q_OS_OS2)
save_path.replace("\\", "/");
#endif
pref.setSavePath(save_path);
pref.setSavePath(getSavePath());
pref.setTempPathEnabled(isTempPathEnabled());
QString temp_path = getTempPath();
#if defined(Q_WS_WIN) || defined(Q_OS_OS2)
temp_path.replace("\\", "/");
#endif
pref.setTempPath(temp_path);
pref.setTempPath(getTempPath());
pref.setAppendTorrentLabel(checkAppendLabel->isChecked());
pref.useIncompleteFilesExtension(checkAppendqB->isChecked());
pref.preAllocateAllFiles(preAllocateAllFiles());
Expand All @@ -395,14 +387,8 @@ void options_imp::saveOptions() {
pref.addTorrentsInPause(addTorrentsInPause());
ScanFoldersModel::instance()->makePersistent();
addedScanDirs.clear();
QString export_dir = getTorrentExportDir();
QString export_dir_fin = getFinishedTorrentExportDir();
#if defined(Q_WS_WIN) || defined(Q_OS_OS2)
export_dir_fin.replace("\\", "/");
export_dir.replace("\\", "/");
#endif
pref.setTorrentExportDir(export_dir);
pref.setFinishedTorrentExportDir(export_dir_fin);
pref.setTorrentExportDir(getTorrentExportDir());
pref.setFinishedTorrentExportDir(getFinishedTorrentExportDir());
pref.setMailNotificationEnabled(groupMailNotification->isChecked());
pref.setMailNotificationEmail(dest_email_txt->text());
pref.setMailNotificationSMTP(smtp_server_txt->text());
Expand Down Expand Up @@ -457,13 +443,8 @@ void options_imp::saveOptions() {
// Misc preferences
// * IPFilter
pref.setFilteringEnabled(isFilteringEnabled());
if (isFilteringEnabled()) {
QString filter_path = textFilterPath->text();
#if defined(Q_WS_WIN) || defined(Q_OS_OS2)
filter_path.replace("\\", "/");
#endif
pref.setFilter(filter_path);
}
if (isFilteringEnabled())
pref.setFilter(textFilterPath->text());
// End IPFilter preferences
// Queueing system
pref.setQueueingSystemEnabled(isQueueingSystemEnabled());
Expand Down Expand Up @@ -551,52 +532,37 @@ void options_imp::loadOptions() {
#endif
// End General preferences
// Downloads preferences
QString save_path = pref.getSavePath();
#if defined(Q_WS_WIN) || defined(Q_OS_OS2)
save_path.replace("/", "\\");
#endif
textSavePath->setText(save_path);
textSavePath->setText(fsutils::toNativePath(pref.getSavePath()));
if (pref.isTempPathEnabled()) {
// enable
checkTempFolder->setChecked(true);
} else {
checkTempFolder->setChecked(false);
}
QString temp_path = pref.getTempPath();
#if defined(Q_WS_WIN) || defined(Q_OS_OS2)
temp_path.replace("/", "\\");
#endif
textTempPath->setText(temp_path);
textTempPath->setText(fsutils::toNativePath(pref.getTempPath()));
checkAppendLabel->setChecked(pref.appendTorrentLabel());
checkAppendqB->setChecked(pref.useIncompleteFilesExtension());
checkPreallocateAll->setChecked(pref.preAllocateAllFiles());
checkAdditionDialog->setChecked(pref.useAdditionDialog());
checkAdditionDialogFront->setChecked(pref.AdditionDialogFront());
checkStartPaused->setChecked(pref.addTorrentsInPause());

strValue = pref.getTorrentExportDir();
strValue = fsutils::toNativePath(pref.getTorrentExportDir());
if (strValue.isEmpty()) {
// Disable
checkExportDir->setChecked(false);
} else {
// enable
checkExportDir->setChecked(true);
#if defined(Q_WS_WIN) || defined(Q_OS_OS2)
strValue.replace("/", "\\");
#endif
textExportDir->setText(strValue);
}

strValue = pref.getFinishedTorrentExportDir();
strValue = fsutils::toNativePath(pref.getFinishedTorrentExportDir());
if (strValue.isEmpty()) {
// Disable
checkExportDirFin->setChecked(false);
} else {
// enable
checkExportDirFin->setChecked(true);
#if defined(Q_WS_WIN) || defined(Q_OS_OS2)
strValue.replace("/", "\\");
#endif
textExportDirFin->setText(strValue);
}
groupMailNotification->setChecked(pref.isMailNotificationEnabled());
Expand Down Expand Up @@ -756,7 +722,7 @@ void options_imp::loadOptions() {
// Misc preferences
// * IP Filter
checkIPFilter->setChecked(pref.isFilteringEnabled());
textFilterPath->setText(pref.getFilter());
textFilterPath->setText(fsutils::toNativePath(pref.getFilter()));
// End IP Filter
// Queueing system preferences
checkEnableQueueing->setChecked(pref.isQueueingSystemEnabled());
Expand Down Expand Up @@ -875,16 +841,13 @@ qreal options_imp::getMaxRatio() const {
QString options_imp::getSavePath() const {
if (textSavePath->text().trimmed().isEmpty()) {
QString save_path = Preferences().getSavePath();
#if defined(Q_WS_WIN) || defined(Q_OS_OS2)
save_path.replace("/", "\\");
#endif
textSavePath->setText(save_path);
textSavePath->setText(fsutils::toNativePath(save_path));
}
return fsutils::expandPath(textSavePath->text());
return fsutils::expandPathAbs(textSavePath->text());
}

QString options_imp::getTempPath() const {
return fsutils::expandPath(textTempPath->text());
return fsutils::expandPathAbs(textTempPath->text());
}

bool options_imp::isTempPathEnabled() const {
Expand Down Expand Up @@ -1068,13 +1031,13 @@ void options_imp::setLocale(const QString &localeStr) {

QString options_imp::getTorrentExportDir() const {
if (checkExportDir->isChecked())
return fsutils::expandPath(textExportDir->text());
return fsutils::expandPathAbs(textExportDir->text());
return QString();
}

QString options_imp::getFinishedTorrentExportDir() const {
if (checkExportDirFin->isChecked())
return fsutils::expandPath(textExportDirFin->text());
return fsutils::expandPathAbs(textExportDirFin->text());
return QString();
}

Expand Down Expand Up @@ -1133,7 +1096,7 @@ void options_imp::handleScanFolderViewSelectionChanged() {

QString options_imp::askForExportDir(const QString& currentExportPath)
{
QDir currentExportDir(fsutils::expandPath(currentExportPath));
QDir currentExportDir(fsutils::expandPathAbs(currentExportPath));
QString dir;
if (!currentExportPath.isEmpty() && currentExportDir.exists()) {
dir = QFileDialog::getExistingDirectory(this, tr("Choose export directory"), currentExportDir.absolutePath());
Expand All @@ -1156,60 +1119,48 @@ void options_imp::on_browseExportDirFinButton_clicked() {
}

void options_imp::on_browseFilterButton_clicked() {
const QString filter_path = fsutils::expandPath(textFilterPath->text());
const QString filter_path = fsutils::expandPathAbs(textFilterPath->text());
QDir filterDir(filter_path);
QString ipfilter;
if (!filter_path.isEmpty() && filterDir.exists()) {
ipfilter = QFileDialog::getOpenFileName(this, tr("Choose an ip filter file"), filterDir.absolutePath(), tr("Filters")+QString(" (*.dat *.p2p *.p2b)"));
} else {
ipfilter = QFileDialog::getOpenFileName(this, tr("Choose an ip filter file"), QDir::homePath(), tr("Filters")+QString(" (*.dat *.p2p *.p2b)"));
}
if (!ipfilter.isNull()) {
#if defined(Q_WS_WIN) || defined(Q_OS_OS2)
ipfilter.replace("/", "\\");
#endif
textFilterPath->setText(ipfilter);
}
if (!ipfilter.isNull())
textFilterPath->setText(fsutils::toNativePath(ipfilter));
}

// Display dialog to choose save dir
void options_imp::on_browseSaveDirButton_clicked() {
const QString save_path = fsutils::expandPath(textSavePath->text());
const QString save_path = fsutils::expandPathAbs(textSavePath->text());
QDir saveDir(save_path);
QString dir;
if (!save_path.isEmpty() && saveDir.exists()) {
dir = QFileDialog::getExistingDirectory(this, tr("Choose a save directory"), saveDir.absolutePath());
} else {
dir = QFileDialog::getExistingDirectory(this, tr("Choose a save directory"), QDir::homePath());
}
if (!dir.isNull()) {
#if defined(Q_WS_WIN) || defined(Q_OS_OS2)
dir.replace("/", "\\");
#endif
textSavePath->setText(dir);
}
if (!dir.isNull())
textSavePath->setText(fsutils::toNativePath(dir));
}

void options_imp::on_browseTempDirButton_clicked() {
const QString temp_path = fsutils::expandPath(textTempPath->text());
const QString temp_path = fsutils::expandPathAbs(textTempPath->text());
QDir tempDir(temp_path);
QString dir;
if (!temp_path.isEmpty() && tempDir.exists()) {
dir = QFileDialog::getExistingDirectory(this, tr("Choose a save directory"), tempDir.absolutePath());
} else {
dir = QFileDialog::getExistingDirectory(this, tr("Choose a save directory"), QDir::homePath());
}
if (!dir.isNull()) {
#if defined(Q_WS_WIN) || defined(Q_OS_OS2)
dir.replace("/", "\\");
#endif
textTempPath->setText(dir);
}
if (!dir.isNull())
textTempPath->setText(fsutils::toNativePath(dir));
}

// Return Filter object to apply to BT session
QString options_imp::getFilter() const {
return textFilterPath->text();
return fsutils::fromNativePath(textFilterPath->text());
}

// Web UI
Expand Down

0 comments on commit b706210

Please sign in to comment.