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