mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-01-10 23:07:59 +00:00
Code clean up
This commit is contained in:
parent
5696944c6f
commit
64f4775a81
@ -281,8 +281,7 @@ QString misc::truncateRootFolder(boost::intrusive_ptr<torrent_info> t) {
|
||||
#else
|
||||
QString path = QString::fromUtf8(t->file_at(0).path.string().c_str());
|
||||
#endif
|
||||
QStringList path_parts = path.split("/", QString::SkipEmptyParts);
|
||||
t->rename_file(0, path_parts.last().toUtf8().data());
|
||||
t->rename_file(0, fileName(path).toUtf8().data());
|
||||
return QString::null;
|
||||
}
|
||||
QString root_folder;
|
||||
@ -316,8 +315,7 @@ QString misc::truncateRootFolder(libtorrent::torrent_handle h) {
|
||||
#else
|
||||
QString path = QString::fromUtf8(t.file_at(0).path.string().c_str());
|
||||
#endif
|
||||
QStringList path_parts = path.split("/", QString::SkipEmptyParts);
|
||||
t.rename_file(0, path_parts.last().toUtf8().data());
|
||||
t.rename_file(0, fileName(path).toUtf8().data());
|
||||
return QString::null;
|
||||
}
|
||||
QString root_folder;
|
||||
@ -747,8 +745,9 @@ bool misc::isValidTorrentFile(const QString &torrent_path) {
|
||||
return true;
|
||||
}
|
||||
|
||||
QString misc::branchPath(QString file_path)
|
||||
QString misc::branchPath(QString file_path, bool uses_slashes)
|
||||
{
|
||||
if(!uses_slashes)
|
||||
file_path.replace("\\", "/");
|
||||
return file_path.left(file_path.lastIndexOf('/'));
|
||||
}
|
||||
|
@ -180,7 +180,7 @@ public:
|
||||
// value must be given in bytes
|
||||
static QString friendlyUnit(double val);
|
||||
static bool isPreviewable(QString extension);
|
||||
static QString branchPath(QString file_path);
|
||||
static QString branchPath(QString file_path, bool uses_slashes=false);
|
||||
static QString fileName(QString file_path);
|
||||
static QString magnetUriToName(QString magnet_uri);
|
||||
static QString magnetUriToHash(QString magnet_uri);
|
||||
|
@ -711,9 +711,7 @@ void PropertiesWidget::on_changeSavePathButton_clicked() {
|
||||
QString save_path_dir = new_path.replace("\\", "/");
|
||||
QString new_file_name;
|
||||
if(h.has_metadata() && h.num_files() == 1) {
|
||||
QStringList parts = save_path_dir.split("/");
|
||||
new_file_name = parts.takeLast(); // Skip file name
|
||||
save_path_dir = parts.join("/");
|
||||
save_path_dir = misc::branchPath(save_path_dir, true); // Skip file name
|
||||
}
|
||||
QDir savePath(misc::expandPath(save_path_dir));
|
||||
// Actually move storage
|
||||
|
@ -221,7 +221,7 @@ int QTorrentHandle::num_files() const {
|
||||
QString QTorrentHandle::filename_at(unsigned int index) const {
|
||||
Q_ASSERT(index < (unsigned int)torrent_handle::get_torrent_info().num_files());
|
||||
#if LIBTORRENT_VERSION_MINOR > 15
|
||||
return filepath_at(index).replace("\\", "/").split("/").last();
|
||||
return misc::fileName(filepath_at(index));
|
||||
#else
|
||||
return misc::toQStringU(torrent_handle::get_torrent_info().file_at(index).path.leaf());
|
||||
#endif
|
||||
|
@ -430,8 +430,8 @@ void engineSelectDlg::processDownloadedFile(QString url, QString filePath) {
|
||||
return;
|
||||
}
|
||||
if(url.endsWith(".py", Qt::CaseInsensitive)) {
|
||||
QString plugin_name = url.split('/').last();
|
||||
plugin_name.replace(".py", "");
|
||||
QString plugin_name = misc::fileName(url);
|
||||
plugin_name.chop(3); // Remove extension
|
||||
installPlugin(filePath, plugin_name);
|
||||
misc::safeRemove(filePath);
|
||||
return;
|
||||
|
@ -141,13 +141,9 @@ void torrentAdditionDialog::saveSettings() {
|
||||
}
|
||||
|
||||
void torrentAdditionDialog::renameTorrentNameInModel(QString file_path) {
|
||||
file_path = file_path.trimmed();
|
||||
if(file_path.isEmpty()) return;
|
||||
file_path = file_path.replace("\\", "/");
|
||||
// Rename in torrent files model too
|
||||
QStringList parts = file_path.split("/", QString::SkipEmptyParts);
|
||||
if(!parts.empty())
|
||||
PropListModel->setData(PropListModel->index(0, 0), parts.last());
|
||||
const QString new_name = misc::fileName(file_path);
|
||||
if(!new_name.isEmpty())
|
||||
PropListModel->setData(PropListModel->index(0, 0), new_name);
|
||||
}
|
||||
|
||||
void torrentAdditionDialog::limitDialogWidth() {
|
||||
|
@ -109,7 +109,7 @@ void TorrentCreatorThread::run() {
|
||||
// calculate the hash for all pieces
|
||||
#if LIBTORRENT_VERSION_MINOR >= 16
|
||||
QString parent_path = input_path.replace("\\", "/");
|
||||
QStringList parts = parent_path.split("/");
|
||||
QStringList parts = parent_path.split("/"/*, QString::SkipEmptyParts*/);
|
||||
parts.removeLast();
|
||||
parent_path = parts.join("/");
|
||||
set_piece_hashes(t, parent_path.toUtf8().constData(), boost::bind<void>(&sendProgressUpdateSignal, _1, t.num_pieces(), this));
|
||||
|
@ -65,10 +65,10 @@ public:
|
||||
type = TFILE;
|
||||
file_index = _file_index;
|
||||
#if LIBTORRENT_VERSION_MINOR >= 16
|
||||
QString name = misc::toQStringU(t.files().file_path(f)).replace("\\", "/").split("/").last();
|
||||
QString name = misc::fileName(misc::toQStringU(t.files().file_path(f)));
|
||||
#else
|
||||
Q_UNUSED(t);
|
||||
QString name = misc::toQStringU(f.path.string()).split("/").last();
|
||||
QString name = misc::toQStringU(f.path.filename());
|
||||
#endif
|
||||
// Do not display incomplete extensions
|
||||
if(name.endsWith(".!qB"))
|
||||
|
@ -85,9 +85,9 @@ void TorrentImportDlg::on_browseContentBtn_clicked()
|
||||
if(t->num_files() == 1) {
|
||||
// Single file torrent
|
||||
#if LIBTORRENT_VERSION_MINOR >= 16
|
||||
const QString file_name = misc::toQStringU(fs.file_path(t->file_at(0))).replace("\\", "/").split("/").last();
|
||||
const QString file_name = misc::fileName(misc::toQStringU(fs.file_path(t->file_at(0)));
|
||||
#else
|
||||
const QString file_name = misc::toQStringU(t->file_at(0).path.leaf());
|
||||
const QString file_name = misc::toQStringU(t->file_at(0).path.filename());
|
||||
#endif
|
||||
qDebug("Torrent has only one file: %s", qPrintable(file_name));
|
||||
QString extension = misc::file_extension(file_name);
|
||||
|
@ -109,7 +109,7 @@ QList<QVariantMap> EventManager::getPropFilesInfo(QString hash) const {
|
||||
for(fi=t.begin_files(); fi != t.end_files(); fi++) {
|
||||
QVariantMap file;
|
||||
QString path = h.filepath(*fi);
|
||||
QString name = path.split('/').last();
|
||||
QString name = misc::fileName(path);
|
||||
file["name"] = name;
|
||||
file["size"] = misc::friendlyUnit((double)fi->size);
|
||||
if(fi->size > 0)
|
||||
|
Loading…
Reference in New Issue
Block a user