From 60d9bfe077d6d6f526004eee8f8ce4241a639ff1 Mon Sep 17 00:00:00 2001 From: Christophe Dumez Date: Thu, 16 Feb 2012 21:32:18 +0200 Subject: [PATCH] misc: Remove duplicate function to branch a path --- src/misc.cpp | 4 ++++ src/misc.h | 8 -------- src/torrentcreator/torrentcreatordlg.cpp | 4 ++-- 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/src/misc.cpp b/src/misc.cpp index a4849c4be..d2c67bfb1 100644 --- a/src/misc.cpp +++ b/src/misc.cpp @@ -888,6 +888,10 @@ bool misc::isValidTorrentFile(const QString &torrent_path) { return true; } +/** + * Returns a path constructed from all the elements of file_path except the last. + * A typical use is to obtain the parent path for a path supplied by the user. + */ QString misc::branchPath(QString file_path, bool uses_slashes) { if(!uses_slashes) diff --git a/src/misc.h b/src/misc.h index d837bc9e5..3ee337d18 100644 --- a/src/misc.h +++ b/src/misc.h @@ -80,14 +80,6 @@ public: static void chmod644(const QDir& folder); - static inline QString removeLastPathPart(QString path) { - if(path.isEmpty()) return path; - path.replace("\\", "/"); - QStringList tmp = path.split("/"); - tmp.removeLast(); - return tmp.join("/"); - } - static inline QString file_extension(const QString &filename) { QString extension; int point_index = filename.lastIndexOf("."); diff --git a/src/torrentcreator/torrentcreatordlg.cpp b/src/torrentcreator/torrentcreatordlg.cpp index d68118798..f789b246d 100644 --- a/src/torrentcreator/torrentcreatordlg.cpp +++ b/src/torrentcreator/torrentcreatordlg.cpp @@ -88,7 +88,7 @@ void TorrentCreatorDlg::on_addFile_button_clicked(){ QString last_path = settings.value("CreateTorrent/last_add_path", QDir::homePath()).toString(); QString file = QFileDialog::getOpenFileName(this, tr("Select a file to add to the torrent"), last_path); if(!file.isEmpty()) { - settings.setValue("CreateTorrent/last_add_path", misc::removeLastPathPart(file)); + settings.setValue("CreateTorrent/last_add_path", misc::branchPath(file)); #if defined(Q_WS_WIN) || defined(Q_OS_OS2) file.replace("/", "\\"); #endif @@ -121,7 +121,7 @@ void TorrentCreatorDlg::on_createButton_clicked(){ QString destination = QFileDialog::getSaveFileName(this, tr("Select destination torrent file"), last_path, tr("Torrent Files")+QString::fromUtf8(" (*.torrent)")); if(!destination.isEmpty()) { - settings.setValue("CreateTorrent/last_save_path", misc::removeLastPathPart(destination)); + settings.setValue("CreateTorrent/last_save_path", misc::branchPath(destination)); if(!destination.toUpper().endsWith(".TORRENT")) destination += QString::fromUtf8(".torrent"); } else {