Browse Source

Code clean up

adaptive-webui-19844
Christophe Dumez 13 years ago
parent
commit
ce6348bc32
  1. 10
      src/misc.cpp
  2. 2
      src/misc.h
  3. 24
      src/preferences/options_imp.cpp
  4. 7
      src/properties/propertieswidget.cpp
  5. 2
      src/qinisettings.h
  6. 4
      src/qtlibtorrent/qbtsession.cpp
  7. 2
      src/qtlibtorrent/qtorrenthandle.cpp
  8. 4
      src/scannedfoldersmodel.cpp
  9. 16
      src/torrentadditiondlg.cpp
  10. 4
      src/torrentcreator/torrentcreatordlg.cpp

10
src/misc.cpp

@ -151,7 +151,7 @@ QString misc::QDesktopServicesCacheLocation() {
long long misc::freeDiskSpaceOnPath(QString path) { long long misc::freeDiskSpaceOnPath(QString path) {
if(path.isEmpty()) return -1; if(path.isEmpty()) return -1;
path = path.replace("\\", "/"); path.replace("\\", "/");
QDir dir_path(path); QDir dir_path(path);
if(!dir_path.exists()) { if(!dir_path.exists()) {
QStringList parts = path.split("/"); QStringList parts = path.split("/");
@ -475,15 +475,15 @@ QString misc::updateLabelInSavePath(QString defaultSavePath, QString save_path,
QString misc::toValidFileSystemName(QString filename) { QString misc::toValidFileSystemName(QString filename) {
qDebug("toValidFSName: %s", qPrintable(filename)); qDebug("toValidFSName: %s", qPrintable(filename));
filename = filename.replace("\\", "/").trimmed(); filename.replace("\\", "/").trimmed();
const QRegExp regex("[/:?\"*<>|]"); const QRegExp regex("[/:?\"*<>|]");
filename = filename.replace(regex, " ").trimmed(); filename.replace(regex, " ").trimmed();
qDebug("toValidFSName, result: %s", qPrintable(filename)); qDebug("toValidFSName, result: %s", qPrintable(filename));
return filename; return filename;
} }
bool misc::isValidFileSystemName(QString filename) { bool misc::isValidFileSystemName(QString filename) {
filename = filename.replace("\\", "/").trimmed(); filename.replace("\\", "/").trimmed();
if(filename.isEmpty()) return false; if(filename.isEmpty()) return false;
const QRegExp regex("[/:?\"*<>|]"); const QRegExp regex("[/:?\"*<>|]");
if(filename.contains(regex)) if(filename.contains(regex))
@ -712,7 +712,7 @@ QString misc::expandPath(QString path) {
if(path[0] == '~' ) return QDir::homePath(); if(path[0] == '~' ) return QDir::homePath();
} }
if(path[0] == '~' && path[1] == QDir::separator()) { if(path[0] == '~' && path[1] == QDir::separator()) {
path = path.replace(0, 1, QDir::homePath()); path.replace(0, 1, QDir::homePath());
} else { } else {
if(QDir::isAbsolutePath(path)) { if(QDir::isAbsolutePath(path)) {
path = QDir(path).absolutePath(); path = QDir(path).absolutePath();

2
src/misc.h

@ -88,7 +88,7 @@ public:
static inline QString removeLastPathPart(QString path) { static inline QString removeLastPathPart(QString path) {
if(path.isEmpty()) return path; if(path.isEmpty()) return path;
path = path.replace("\\", "/"); path.replace("\\", "/");
QStringList tmp = path.split("/"); QStringList tmp = path.split("/");
tmp.removeLast(); tmp.removeLast();
return tmp.join("/"); return tmp.join("/");

24
src/preferences/options_imp.cpp

@ -382,13 +382,13 @@ void options_imp::saveOptions(){
// Downloads preferences // Downloads preferences
QString save_path = getSavePath(); QString save_path = getSavePath();
#if defined(Q_WS_WIN) || defined(Q_OS_OS2) #if defined(Q_WS_WIN) || defined(Q_OS_OS2)
save_path = save_path.replace("\\", "/"); save_path.replace("\\", "/");
#endif #endif
pref.setSavePath(save_path); pref.setSavePath(save_path);
pref.setTempPathEnabled(isTempPathEnabled()); pref.setTempPathEnabled(isTempPathEnabled());
QString temp_path = getTempPath(); QString temp_path = getTempPath();
#if defined(Q_WS_WIN) || defined(Q_OS_OS2) #if defined(Q_WS_WIN) || defined(Q_OS_OS2)
temp_path = temp_path.replace("\\", "/"); temp_path.replace("\\", "/");
#endif #endif
pref.setTempPath(temp_path); pref.setTempPath(temp_path);
pref.setAppendTorrentLabel(checkAppendLabel->isChecked()); pref.setAppendTorrentLabel(checkAppendLabel->isChecked());
@ -402,7 +402,7 @@ void options_imp::saveOptions(){
addedScanDirs.clear(); addedScanDirs.clear();
QString export_dir = getExportDir(); QString export_dir = getExportDir();
#if defined(Q_WS_WIN) || defined(Q_OS_OS2) #if defined(Q_WS_WIN) || defined(Q_OS_OS2)
export_dir = export_dir.replace("\\", "/"); export_dir.replace("\\", "/");
#endif #endif
pref.setExportDir(export_dir); pref.setExportDir(export_dir);
pref.setMailNotificationEnabled(groupMailNotification->isChecked()); pref.setMailNotificationEnabled(groupMailNotification->isChecked());
@ -462,7 +462,7 @@ void options_imp::saveOptions(){
if(isFilteringEnabled()){ if(isFilteringEnabled()){
QString filter_path = textFilterPath->text(); QString filter_path = textFilterPath->text();
#if defined(Q_WS_WIN) || defined(Q_OS_OS2) #if defined(Q_WS_WIN) || defined(Q_OS_OS2)
filter_path = filter_path.replace("\\", "/"); filter_path.replace("\\", "/");
#endif #endif
pref.setFilter(filter_path); pref.setFilter(filter_path);
} }
@ -554,7 +554,7 @@ void options_imp::loadOptions(){
// Downloads preferences // Downloads preferences
QString save_path = pref.getSavePath(); QString save_path = pref.getSavePath();
#if defined(Q_WS_WIN) || defined(Q_OS_OS2) #if defined(Q_WS_WIN) || defined(Q_OS_OS2)
save_path = save_path.replace("/", "\\"); save_path.replace("/", "\\");
#endif #endif
textSavePath->setText(save_path); textSavePath->setText(save_path);
if(pref.isTempPathEnabled()) { if(pref.isTempPathEnabled()) {
@ -565,7 +565,7 @@ void options_imp::loadOptions(){
} }
QString temp_path = pref.getTempPath(); QString temp_path = pref.getTempPath();
#if defined(Q_WS_WIN) || defined(Q_OS_OS2) #if defined(Q_WS_WIN) || defined(Q_OS_OS2)
temp_path = temp_path.replace("/", "\\"); temp_path.replace("/", "\\");
#endif #endif
textTempPath->setText(temp_path); textTempPath->setText(temp_path);
checkAppendLabel->setChecked(pref.appendTorrentLabel()); checkAppendLabel->setChecked(pref.appendTorrentLabel());
@ -584,7 +584,7 @@ void options_imp::loadOptions(){
// enable // enable
checkExportDir->setChecked(true); checkExportDir->setChecked(true);
#if defined(Q_WS_WIN) || defined(Q_OS_OS2) #if defined(Q_WS_WIN) || defined(Q_OS_OS2)
strValue = strValue.replace("/", "\\"); strValue.replace("/", "\\");
#endif #endif
textExportDir->setText(strValue); textExportDir->setText(strValue);
} }
@ -855,7 +855,7 @@ QString options_imp::getSavePath() const{
if(textSavePath->text().trimmed().isEmpty()){ if(textSavePath->text().trimmed().isEmpty()){
QString save_path = Preferences().getSavePath(); QString save_path = Preferences().getSavePath();
#if defined(Q_WS_WIN) || defined(Q_OS_OS2) #if defined(Q_WS_WIN) || defined(Q_OS_OS2)
save_path = save_path.replace("/", "\\"); save_path.replace("/", "\\");
#endif #endif
textSavePath->setText(save_path); textSavePath->setText(save_path);
} }
@ -1093,7 +1093,7 @@ void options_imp::on_browseExportDirButton_clicked() {
} }
if(!dir.isNull()){ if(!dir.isNull()){
#if defined(Q_WS_WIN) || defined(Q_OS_OS2) #if defined(Q_WS_WIN) || defined(Q_OS_OS2)
dir = dir.replace("/", "\\"); dir.replace("/", "\\");
#endif #endif
textExportDir->setText(dir); textExportDir->setText(dir);
} }
@ -1110,7 +1110,7 @@ void options_imp::on_browseFilterButton_clicked() {
} }
if(!ipfilter.isNull()){ if(!ipfilter.isNull()){
#if defined(Q_WS_WIN) || defined(Q_OS_OS2) #if defined(Q_WS_WIN) || defined(Q_OS_OS2)
ipfilter = ipfilter.replace("/", "\\"); ipfilter.replace("/", "\\");
#endif #endif
textFilterPath->setText(ipfilter); textFilterPath->setText(ipfilter);
} }
@ -1128,7 +1128,7 @@ void options_imp::on_browseSaveDirButton_clicked(){
} }
if(!dir.isNull()){ if(!dir.isNull()){
#if defined(Q_WS_WIN) || defined(Q_OS_OS2) #if defined(Q_WS_WIN) || defined(Q_OS_OS2)
dir = dir.replace("/", "\\"); dir.replace("/", "\\");
#endif #endif
textSavePath->setText(dir); textSavePath->setText(dir);
} }
@ -1145,7 +1145,7 @@ void options_imp::on_browseTempDirButton_clicked(){
} }
if(!dir.isNull()){ if(!dir.isNull()){
#if defined(Q_WS_WIN) || defined(Q_OS_OS2) #if defined(Q_WS_WIN) || defined(Q_OS_OS2)
dir = dir.replace("/", "\\"); dir.replace("/", "\\");
#endif #endif
textTempPath->setText(dir); textTempPath->setText(dir);
} }

7
src/properties/propertieswidget.cpp

@ -222,7 +222,7 @@ void PropertiesWidget::updateSavePath(const QTorrentHandle& _h) {
p = h.save_path(); p = h.save_path();
} }
#if defined(Q_WS_WIN) || defined(Q_OS_OS2) #if defined(Q_WS_WIN) || defined(Q_OS_OS2)
p = p.replace("/", "\\"); p.replace("/", "\\");
#endif #endif
save_path->setText(p); save_path->setText(p);
} }
@ -524,8 +524,7 @@ void PropertiesWidget::renameSelectedFile() {
// File renaming // File renaming
const int file_index = PropListModel->getFileIndex(index); const int file_index = PropListModel->getFileIndex(index);
if(!h.is_valid() || !h.has_metadata()) return; if(!h.is_valid() || !h.has_metadata()) return;
QString old_name = h.filepath_at(file_index); QString old_name = h.filepath_at(file_index).replace("\\", "/");
old_name = old_name.replace("\\", "/");
if(old_name.endsWith(".!qB") && !new_name_last.endsWith(".!qB")) { if(old_name.endsWith(".!qB") && !new_name_last.endsWith(".!qB")) {
new_name_last += ".!qB"; new_name_last += ".!qB";
} }
@ -713,7 +712,7 @@ void PropertiesWidget::on_changeSavePathButton_clicked() {
display_path = savePath.absolutePath(); display_path = savePath.absolutePath();
} }
#if defined(Q_WS_WIN) || defined(Q_OS_OS2) #if defined(Q_WS_WIN) || defined(Q_OS_OS2)
display_path = display_path.replace("/", "\\"); display_path.replace("/", "\\");
#endif #endif
save_path->setText(display_path); save_path->setText(display_path);
} }

2
src/qinisettings.h

@ -69,7 +69,7 @@ public:
void setValue(const QString &key, const QVariant &val) { void setValue(const QString &key, const QVariant &val) {
QString key_tmp(key); QString key_tmp(key);
if(format() == QSettings::NativeFormat) if(format() == QSettings::NativeFormat)
key_tmp = key_tmp.replace("\\", "/"); key_tmp.replace("\\", "/");
QSettings::setValue(key_tmp, val); QSettings::setValue(key_tmp, val);
} }
#endif #endif

4
src/qtlibtorrent/qbtsession.cpp

@ -1281,7 +1281,7 @@ void QBtSession::loadTorrentTempData(QTorrentHandle &h, QString savePath, bool m
if(files_path.size() == h.num_files()) { if(files_path.size() == h.num_files()) {
for(int i=0; i<h.num_files(); ++i) { for(int i=0; i<h.num_files(); ++i) {
QString old_path = h.absolute_files_path().at(i); QString old_path = h.absolute_files_path().at(i);
old_path = old_path.replace("\\", "/"); old_path.replace("\\", "/");
if(!QFile::exists(old_path)) { if(!QFile::exists(old_path)) {
// Remove old parent folder manually since we will // Remove old parent folder manually since we will
// not get a file_renamed alert // not get a file_renamed alert
@ -2685,7 +2685,7 @@ QString QBtSession::getSavePath(const QString &hash, bool fromScanDir, QString f
qDebug("getSavePath, got save_path from persistent data: %s", qPrintable(savePath)); qDebug("getSavePath, got save_path from persistent data: %s", qPrintable(savePath));
} }
// Clean path // Clean path
savePath = savePath.replace("\\", "/"); savePath.replace("\\", "/");
savePath = misc::expandPath(savePath); savePath = misc::expandPath(savePath);
if(!savePath.endsWith("/")) if(!savePath.endsWith("/"))
savePath += "/"; savePath += "/";

2
src/qtlibtorrent/qtorrenthandle.cpp

@ -520,7 +520,7 @@ QString QTorrentHandle::firstFileSavePath() const {
QString fsave_path = TorrentPersistentData::getSavePath(hash()); QString fsave_path = TorrentPersistentData::getSavePath(hash());
if(fsave_path.isEmpty()) if(fsave_path.isEmpty())
fsave_path = save_path(); fsave_path = save_path();
fsave_path = fsave_path.replace("\\", "/"); fsave_path.replace("\\", "/");
if(!fsave_path.endsWith("/")) if(!fsave_path.endsWith("/"))
fsave_path += "/"; fsave_path += "/";
fsave_path += filepath_at(0); fsave_path += filepath_at(0);

4
src/scannedfoldersmodel.cpp

@ -83,9 +83,7 @@ QVariant ScanFoldersModel::data(const QModelIndex &index, int role) const {
const PathData* pathData = m_pathList.at(index.row()); const PathData* pathData = m_pathList.at(index.row());
if (index.column() == PathColumn && role == Qt::DisplayRole) { if (index.column() == PathColumn && role == Qt::DisplayRole) {
#if defined(Q_WS_WIN) || defined(Q_OS_OS2) #if defined(Q_WS_WIN) || defined(Q_OS_OS2)
QString ret = pathData->path; return pathData->path.replace("/", "\\");
ret = ret.replace("/", "\\");
return ret;
#else #else
return pathData->path; return pathData->path;
#endif #endif

16
src/torrentadditiondlg.cpp

@ -96,7 +96,7 @@ torrentAdditionDialog::torrentAdditionDialog(QWidget *parent) :
display_path += "/"; display_path += "/";
path_history << display_path; path_history << display_path;
#if defined(Q_WS_WIN) || defined(Q_OS_OS2) #if defined(Q_WS_WIN) || defined(Q_OS_OS2)
display_path = display_path.replace("/", "\\"); display_path.replace("/", "\\");
#endif #endif
savePathTxt->addItem(display_path); savePathTxt->addItem(display_path);
@ -311,7 +311,7 @@ void torrentAdditionDialog::showLoad(QString filePath, QString from_url) {
QString save_path = savePathTxt->currentText(); QString save_path = savePathTxt->currentText();
#if defined(Q_WS_WIN) || defined(Q_OS_OS2) #if defined(Q_WS_WIN) || defined(Q_OS_OS2)
save_path = save_path.replace("/", "\\"); save_path.replace("/", "\\");
#endif #endif
if(!save_path.endsWith(QDir::separator())) if(!save_path.endsWith(QDir::separator()))
save_path += QDir::separator(); save_path += QDir::separator();
@ -327,7 +327,7 @@ void torrentAdditionDialog::showLoad(QString filePath, QString from_url) {
QString single_file_relpath = misc::toQStringU(t->file_at(0).path.string()); QString single_file_relpath = misc::toQStringU(t->file_at(0).path.string());
#endif #endif
#if defined(Q_WS_WIN) || defined(Q_OS_OS2) #if defined(Q_WS_WIN) || defined(Q_OS_OS2)
single_file_relpath = single_file_relpath.replace("/", "\\"); single_file_relpath.replace("/", "\\");
#endif #endif
save_path += single_file_relpath; save_path += single_file_relpath;
} }
@ -414,7 +414,7 @@ void torrentAdditionDialog::renameSelectedFile() {
// File renaming // File renaming
const uint file_index = PropListModel->getFileIndex(index); const uint file_index = PropListModel->getFileIndex(index);
QString old_name = files_path.at(file_index); QString old_name = files_path.at(file_index);
old_name = old_name.replace("\\", "/"); old_name.replace("\\", "/");
qDebug("Old name: %s", qPrintable(old_name)); qDebug("Old name: %s", qPrintable(old_name));
QStringList path_items = old_name.split("/"); QStringList path_items = old_name.split("/");
path_items.removeLast(); path_items.removeLast();
@ -580,7 +580,7 @@ void torrentAdditionDialog::on_browseButton_clicked(){
savePathTxt->setCurrentIndex(cur_index); savePathTxt->setCurrentIndex(cur_index);
} }
#if defined(Q_WS_WIN) || defined(Q_OS_OS2) #if defined(Q_WS_WIN) || defined(Q_OS_OS2)
new_path = new_path.replace("/", "\\"); new_path.replace("/", "\\");
#endif #endif
savePathTxt->setEditText(new_path); savePathTxt->setEditText(new_path);
} }
@ -611,7 +611,7 @@ void torrentAdditionDialog::on_OkButton_clicked(){
} }
QString save_path = savePathTxt->currentText(); QString save_path = savePathTxt->currentText();
#if defined(Q_WS_WIN) || defined(Q_OS_OS2) #if defined(Q_WS_WIN) || defined(Q_OS_OS2)
save_path = save_path.replace("\\", "/"); save_path.replace("\\", "/");
#endif #endif
save_path = misc::expandPath(save_path); save_path = misc::expandPath(save_path);
qDebug("Save path is %s", qPrintable(save_path)); qDebug("Save path is %s", qPrintable(save_path));
@ -751,7 +751,7 @@ void torrentAdditionDialog::updateSavePathCurrentText() {
if(!root_folder_or_file_name.isEmpty()) if(!root_folder_or_file_name.isEmpty())
item_path += root_folder_or_file_name; item_path += root_folder_or_file_name;
#if defined(Q_WS_WIN) || defined(Q_OS_OS2) #if defined(Q_WS_WIN) || defined(Q_OS_OS2)
item_path = item_path.replace("/", "\\"); item_path.replace("/", "\\");
#endif #endif
savePathTxt->setItemText(i, item_path); savePathTxt->setItemText(i, item_path);
} }
@ -812,7 +812,7 @@ void torrentAdditionDialog::loadSavePathHistory() {
if(QDir(sp) != QDir(defaultSavePath)) { if(QDir(sp) != QDir(defaultSavePath)) {
QString dsp = sp; QString dsp = sp;
#if defined(Q_WS_WIN) || defined(Q_OS_OS2) #if defined(Q_WS_WIN) || defined(Q_OS_OS2)
dsp = dsp.replace("/", "\\"); dsp.replace("/", "\\");
#endif #endif
path_history << sp; path_history << sp;
savePathTxt->addItem(dsp); savePathTxt->addItem(dsp);

4
src/torrentcreator/torrentcreatordlg.cpp

@ -74,7 +74,7 @@ void TorrentCreatorDlg::on_addFolder_button_clicked(){
if(!dir.isEmpty()) { if(!dir.isEmpty()) {
settings.setValue("CreateTorrent/last_add_path", dir); settings.setValue("CreateTorrent/last_add_path", dir);
#if defined(Q_WS_WIN) || defined(Q_OS_OS2) #if defined(Q_WS_WIN) || defined(Q_OS_OS2)
dir = dir.replace("/", "\\"); dir.replace("/", "\\");
#endif #endif
textInputPath->setText(dir); textInputPath->setText(dir);
// Update piece size // Update piece size
@ -90,7 +90,7 @@ void TorrentCreatorDlg::on_addFile_button_clicked(){
if(!file.isEmpty()) { if(!file.isEmpty()) {
settings.setValue("CreateTorrent/last_add_path", misc::removeLastPathPart(file)); settings.setValue("CreateTorrent/last_add_path", misc::removeLastPathPart(file));
#if defined(Q_WS_WIN) || defined(Q_OS_OS2) #if defined(Q_WS_WIN) || defined(Q_OS_OS2)
file = file.replace("/", "\\"); file.replace("/", "\\");
#endif #endif
textInputPath->setText(file); textInputPath->setText(file);
// Update piece size // Update piece size

Loading…
Cancel
Save