mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2024-11-29 13:58:51 +03:00
Code clean up
This commit is contained in:
parent
4c5dd66b0f
commit
ce6348bc32
10 changed files with 36 additions and 39 deletions
10
src/misc.cpp
10
src/misc.cpp
|
@ -151,7 +151,7 @@ QString misc::QDesktopServicesCacheLocation() {
|
|||
|
||||
long long misc::freeDiskSpaceOnPath(QString path) {
|
||||
if(path.isEmpty()) return -1;
|
||||
path = path.replace("\\", "/");
|
||||
path.replace("\\", "/");
|
||||
QDir dir_path(path);
|
||||
if(!dir_path.exists()) {
|
||||
QStringList parts = path.split("/");
|
||||
|
@ -475,15 +475,15 @@ QString misc::updateLabelInSavePath(QString defaultSavePath, QString save_path,
|
|||
|
||||
QString misc::toValidFileSystemName(QString filename) {
|
||||
qDebug("toValidFSName: %s", qPrintable(filename));
|
||||
filename = filename.replace("\\", "/").trimmed();
|
||||
filename.replace("\\", "/").trimmed();
|
||||
const QRegExp regex("[/:?\"*<>|]");
|
||||
filename = filename.replace(regex, " ").trimmed();
|
||||
filename.replace(regex, " ").trimmed();
|
||||
qDebug("toValidFSName, result: %s", qPrintable(filename));
|
||||
return filename;
|
||||
}
|
||||
|
||||
bool misc::isValidFileSystemName(QString filename) {
|
||||
filename = filename.replace("\\", "/").trimmed();
|
||||
filename.replace("\\", "/").trimmed();
|
||||
if(filename.isEmpty()) return false;
|
||||
const QRegExp regex("[/:?\"*<>|]");
|
||||
if(filename.contains(regex))
|
||||
|
@ -712,7 +712,7 @@ QString misc::expandPath(QString path) {
|
|||
if(path[0] == '~' ) return QDir::homePath();
|
||||
}
|
||||
if(path[0] == '~' && path[1] == QDir::separator()) {
|
||||
path = path.replace(0, 1, QDir::homePath());
|
||||
path.replace(0, 1, QDir::homePath());
|
||||
} else {
|
||||
if(QDir::isAbsolutePath(path)) {
|
||||
path = QDir(path).absolutePath();
|
||||
|
|
|
@ -88,7 +88,7 @@ public:
|
|||
|
||||
static inline QString removeLastPathPart(QString path) {
|
||||
if(path.isEmpty()) return path;
|
||||
path = path.replace("\\", "/");
|
||||
path.replace("\\", "/");
|
||||
QStringList tmp = path.split("/");
|
||||
tmp.removeLast();
|
||||
return tmp.join("/");
|
||||
|
|
|
@ -382,13 +382,13 @@ void options_imp::saveOptions(){
|
|||
// Downloads preferences
|
||||
QString save_path = getSavePath();
|
||||
#if defined(Q_WS_WIN) || defined(Q_OS_OS2)
|
||||
save_path = save_path.replace("\\", "/");
|
||||
save_path.replace("\\", "/");
|
||||
#endif
|
||||
pref.setSavePath(save_path);
|
||||
pref.setTempPathEnabled(isTempPathEnabled());
|
||||
QString temp_path = getTempPath();
|
||||
#if defined(Q_WS_WIN) || defined(Q_OS_OS2)
|
||||
temp_path = temp_path.replace("\\", "/");
|
||||
temp_path.replace("\\", "/");
|
||||
#endif
|
||||
pref.setTempPath(temp_path);
|
||||
pref.setAppendTorrentLabel(checkAppendLabel->isChecked());
|
||||
|
@ -402,7 +402,7 @@ void options_imp::saveOptions(){
|
|||
addedScanDirs.clear();
|
||||
QString export_dir = getExportDir();
|
||||
#if defined(Q_WS_WIN) || defined(Q_OS_OS2)
|
||||
export_dir = export_dir.replace("\\", "/");
|
||||
export_dir.replace("\\", "/");
|
||||
#endif
|
||||
pref.setExportDir(export_dir);
|
||||
pref.setMailNotificationEnabled(groupMailNotification->isChecked());
|
||||
|
@ -462,7 +462,7 @@ void options_imp::saveOptions(){
|
|||
if(isFilteringEnabled()){
|
||||
QString filter_path = textFilterPath->text();
|
||||
#if defined(Q_WS_WIN) || defined(Q_OS_OS2)
|
||||
filter_path = filter_path.replace("\\", "/");
|
||||
filter_path.replace("\\", "/");
|
||||
#endif
|
||||
pref.setFilter(filter_path);
|
||||
}
|
||||
|
@ -554,7 +554,7 @@ void options_imp::loadOptions(){
|
|||
// Downloads preferences
|
||||
QString save_path = pref.getSavePath();
|
||||
#if defined(Q_WS_WIN) || defined(Q_OS_OS2)
|
||||
save_path = save_path.replace("/", "\\");
|
||||
save_path.replace("/", "\\");
|
||||
#endif
|
||||
textSavePath->setText(save_path);
|
||||
if(pref.isTempPathEnabled()) {
|
||||
|
@ -565,7 +565,7 @@ void options_imp::loadOptions(){
|
|||
}
|
||||
QString temp_path = pref.getTempPath();
|
||||
#if defined(Q_WS_WIN) || defined(Q_OS_OS2)
|
||||
temp_path = temp_path.replace("/", "\\");
|
||||
temp_path.replace("/", "\\");
|
||||
#endif
|
||||
textTempPath->setText(temp_path);
|
||||
checkAppendLabel->setChecked(pref.appendTorrentLabel());
|
||||
|
@ -584,7 +584,7 @@ void options_imp::loadOptions(){
|
|||
// enable
|
||||
checkExportDir->setChecked(true);
|
||||
#if defined(Q_WS_WIN) || defined(Q_OS_OS2)
|
||||
strValue = strValue.replace("/", "\\");
|
||||
strValue.replace("/", "\\");
|
||||
#endif
|
||||
textExportDir->setText(strValue);
|
||||
}
|
||||
|
@ -855,7 +855,7 @@ 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 = save_path.replace("/", "\\");
|
||||
save_path.replace("/", "\\");
|
||||
#endif
|
||||
textSavePath->setText(save_path);
|
||||
}
|
||||
|
@ -1093,7 +1093,7 @@ void options_imp::on_browseExportDirButton_clicked() {
|
|||
}
|
||||
if(!dir.isNull()){
|
||||
#if defined(Q_WS_WIN) || defined(Q_OS_OS2)
|
||||
dir = dir.replace("/", "\\");
|
||||
dir.replace("/", "\\");
|
||||
#endif
|
||||
textExportDir->setText(dir);
|
||||
}
|
||||
|
@ -1110,7 +1110,7 @@ void options_imp::on_browseFilterButton_clicked() {
|
|||
}
|
||||
if(!ipfilter.isNull()){
|
||||
#if defined(Q_WS_WIN) || defined(Q_OS_OS2)
|
||||
ipfilter = ipfilter.replace("/", "\\");
|
||||
ipfilter.replace("/", "\\");
|
||||
#endif
|
||||
textFilterPath->setText(ipfilter);
|
||||
}
|
||||
|
@ -1128,7 +1128,7 @@ void options_imp::on_browseSaveDirButton_clicked(){
|
|||
}
|
||||
if(!dir.isNull()){
|
||||
#if defined(Q_WS_WIN) || defined(Q_OS_OS2)
|
||||
dir = dir.replace("/", "\\");
|
||||
dir.replace("/", "\\");
|
||||
#endif
|
||||
textSavePath->setText(dir);
|
||||
}
|
||||
|
@ -1145,7 +1145,7 @@ void options_imp::on_browseTempDirButton_clicked(){
|
|||
}
|
||||
if(!dir.isNull()){
|
||||
#if defined(Q_WS_WIN) || defined(Q_OS_OS2)
|
||||
dir = dir.replace("/", "\\");
|
||||
dir.replace("/", "\\");
|
||||
#endif
|
||||
textTempPath->setText(dir);
|
||||
}
|
||||
|
|
|
@ -222,7 +222,7 @@ void PropertiesWidget::updateSavePath(const QTorrentHandle& _h) {
|
|||
p = h.save_path();
|
||||
}
|
||||
#if defined(Q_WS_WIN) || defined(Q_OS_OS2)
|
||||
p = p.replace("/", "\\");
|
||||
p.replace("/", "\\");
|
||||
#endif
|
||||
save_path->setText(p);
|
||||
}
|
||||
|
@ -524,8 +524,7 @@ void PropertiesWidget::renameSelectedFile() {
|
|||
// File renaming
|
||||
const int file_index = PropListModel->getFileIndex(index);
|
||||
if(!h.is_valid() || !h.has_metadata()) return;
|
||||
QString old_name = h.filepath_at(file_index);
|
||||
old_name = old_name.replace("\\", "/");
|
||||
QString old_name = h.filepath_at(file_index).replace("\\", "/");
|
||||
if(old_name.endsWith(".!qB") && !new_name_last.endsWith(".!qB")) {
|
||||
new_name_last += ".!qB";
|
||||
}
|
||||
|
@ -713,7 +712,7 @@ void PropertiesWidget::on_changeSavePathButton_clicked() {
|
|||
display_path = savePath.absolutePath();
|
||||
}
|
||||
#if defined(Q_WS_WIN) || defined(Q_OS_OS2)
|
||||
display_path = display_path.replace("/", "\\");
|
||||
display_path.replace("/", "\\");
|
||||
#endif
|
||||
save_path->setText(display_path);
|
||||
}
|
||||
|
|
|
@ -69,7 +69,7 @@ public:
|
|||
void setValue(const QString &key, const QVariant &val) {
|
||||
QString key_tmp(key);
|
||||
if(format() == QSettings::NativeFormat)
|
||||
key_tmp = key_tmp.replace("\\", "/");
|
||||
key_tmp.replace("\\", "/");
|
||||
QSettings::setValue(key_tmp, val);
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -1281,7 +1281,7 @@ void QBtSession::loadTorrentTempData(QTorrentHandle &h, QString savePath, bool m
|
|||
if(files_path.size() == h.num_files()) {
|
||||
for(int i=0; i<h.num_files(); ++i) {
|
||||
QString old_path = h.absolute_files_path().at(i);
|
||||
old_path = old_path.replace("\\", "/");
|
||||
old_path.replace("\\", "/");
|
||||
if(!QFile::exists(old_path)) {
|
||||
// Remove old parent folder manually since we will
|
||||
// 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));
|
||||
}
|
||||
// Clean path
|
||||
savePath = savePath.replace("\\", "/");
|
||||
savePath.replace("\\", "/");
|
||||
savePath = misc::expandPath(savePath);
|
||||
if(!savePath.endsWith("/"))
|
||||
savePath += "/";
|
||||
|
|
|
@ -520,7 +520,7 @@ QString QTorrentHandle::firstFileSavePath() const {
|
|||
QString fsave_path = TorrentPersistentData::getSavePath(hash());
|
||||
if(fsave_path.isEmpty())
|
||||
fsave_path = save_path();
|
||||
fsave_path = fsave_path.replace("\\", "/");
|
||||
fsave_path.replace("\\", "/");
|
||||
if(!fsave_path.endsWith("/"))
|
||||
fsave_path += "/";
|
||||
fsave_path += filepath_at(0);
|
||||
|
|
|
@ -83,9 +83,7 @@ QVariant ScanFoldersModel::data(const QModelIndex &index, int role) const {
|
|||
const PathData* pathData = m_pathList.at(index.row());
|
||||
if (index.column() == PathColumn && role == Qt::DisplayRole) {
|
||||
#if defined(Q_WS_WIN) || defined(Q_OS_OS2)
|
||||
QString ret = pathData->path;
|
||||
ret = ret.replace("/", "\\");
|
||||
return ret;
|
||||
return pathData->path.replace("/", "\\");
|
||||
#else
|
||||
return pathData->path;
|
||||
#endif
|
||||
|
|
|
@ -96,7 +96,7 @@ torrentAdditionDialog::torrentAdditionDialog(QWidget *parent) :
|
|||
display_path += "/";
|
||||
path_history << display_path;
|
||||
#if defined(Q_WS_WIN) || defined(Q_OS_OS2)
|
||||
display_path = display_path.replace("/", "\\");
|
||||
display_path.replace("/", "\\");
|
||||
#endif
|
||||
savePathTxt->addItem(display_path);
|
||||
|
||||
|
@ -311,7 +311,7 @@ void torrentAdditionDialog::showLoad(QString filePath, QString from_url) {
|
|||
|
||||
QString save_path = savePathTxt->currentText();
|
||||
#if defined(Q_WS_WIN) || defined(Q_OS_OS2)
|
||||
save_path = save_path.replace("/", "\\");
|
||||
save_path.replace("/", "\\");
|
||||
#endif
|
||||
if(!save_path.endsWith(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());
|
||||
#endif
|
||||
#if defined(Q_WS_WIN) || defined(Q_OS_OS2)
|
||||
single_file_relpath = single_file_relpath.replace("/", "\\");
|
||||
single_file_relpath.replace("/", "\\");
|
||||
#endif
|
||||
save_path += single_file_relpath;
|
||||
}
|
||||
|
@ -414,7 +414,7 @@ void torrentAdditionDialog::renameSelectedFile() {
|
|||
// File renaming
|
||||
const uint file_index = PropListModel->getFileIndex(index);
|
||||
QString old_name = files_path.at(file_index);
|
||||
old_name = old_name.replace("\\", "/");
|
||||
old_name.replace("\\", "/");
|
||||
qDebug("Old name: %s", qPrintable(old_name));
|
||||
QStringList path_items = old_name.split("/");
|
||||
path_items.removeLast();
|
||||
|
@ -580,7 +580,7 @@ void torrentAdditionDialog::on_browseButton_clicked(){
|
|||
savePathTxt->setCurrentIndex(cur_index);
|
||||
}
|
||||
#if defined(Q_WS_WIN) || defined(Q_OS_OS2)
|
||||
new_path = new_path.replace("/", "\\");
|
||||
new_path.replace("/", "\\");
|
||||
#endif
|
||||
savePathTxt->setEditText(new_path);
|
||||
}
|
||||
|
@ -611,7 +611,7 @@ void torrentAdditionDialog::on_OkButton_clicked(){
|
|||
}
|
||||
QString save_path = savePathTxt->currentText();
|
||||
#if defined(Q_WS_WIN) || defined(Q_OS_OS2)
|
||||
save_path = save_path.replace("\\", "/");
|
||||
save_path.replace("\\", "/");
|
||||
#endif
|
||||
save_path = misc::expandPath(save_path);
|
||||
qDebug("Save path is %s", qPrintable(save_path));
|
||||
|
@ -751,7 +751,7 @@ void torrentAdditionDialog::updateSavePathCurrentText() {
|
|||
if(!root_folder_or_file_name.isEmpty())
|
||||
item_path += root_folder_or_file_name;
|
||||
#if defined(Q_WS_WIN) || defined(Q_OS_OS2)
|
||||
item_path = item_path.replace("/", "\\");
|
||||
item_path.replace("/", "\\");
|
||||
#endif
|
||||
savePathTxt->setItemText(i, item_path);
|
||||
}
|
||||
|
@ -812,7 +812,7 @@ void torrentAdditionDialog::loadSavePathHistory() {
|
|||
if(QDir(sp) != QDir(defaultSavePath)) {
|
||||
QString dsp = sp;
|
||||
#if defined(Q_WS_WIN) || defined(Q_OS_OS2)
|
||||
dsp = dsp.replace("/", "\\");
|
||||
dsp.replace("/", "\\");
|
||||
#endif
|
||||
path_history << sp;
|
||||
savePathTxt->addItem(dsp);
|
||||
|
|
|
@ -74,7 +74,7 @@ void TorrentCreatorDlg::on_addFolder_button_clicked(){
|
|||
if(!dir.isEmpty()) {
|
||||
settings.setValue("CreateTorrent/last_add_path", dir);
|
||||
#if defined(Q_WS_WIN) || defined(Q_OS_OS2)
|
||||
dir = dir.replace("/", "\\");
|
||||
dir.replace("/", "\\");
|
||||
#endif
|
||||
textInputPath->setText(dir);
|
||||
// Update piece size
|
||||
|
@ -90,7 +90,7 @@ void TorrentCreatorDlg::on_addFile_button_clicked(){
|
|||
if(!file.isEmpty()) {
|
||||
settings.setValue("CreateTorrent/last_add_path", misc::removeLastPathPart(file));
|
||||
#if defined(Q_WS_WIN) || defined(Q_OS_OS2)
|
||||
file = file.replace("/", "\\");
|
||||
file.replace("/", "\\");
|
||||
#endif
|
||||
textInputPath->setText(file);
|
||||
// Update piece size
|
||||
|
|
Loading…
Reference in a new issue