Browse Source

Code clean up

adaptive-webui-19844
Christophe Dumez 14 years ago
parent
commit
64f4775a81
  1. 9
      src/misc.cpp
  2. 2
      src/misc.h
  3. 4
      src/properties/propertieswidget.cpp
  4. 2
      src/qtlibtorrent/qtorrenthandle.cpp
  5. 4
      src/searchengine/engineselectdlg.cpp
  6. 10
      src/torrentadditiondlg.cpp
  7. 2
      src/torrentcreator/torrentcreatorthread.cpp
  8. 4
      src/torrentfilesmodel.h
  9. 4
      src/torrentimportdlg.cpp
  10. 2
      src/webui/eventmanager.cpp

9
src/misc.cpp

@ -281,8 +281,7 @@ QString misc::truncateRootFolder(boost::intrusive_ptr<torrent_info> t) { @@ -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) { @@ -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) { @@ -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('/'));
}

2
src/misc.h

@ -180,7 +180,7 @@ public: @@ -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);

4
src/properties/propertieswidget.cpp

@ -711,9 +711,7 @@ void PropertiesWidget::on_changeSavePathButton_clicked() { @@ -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

2
src/qtlibtorrent/qtorrenthandle.cpp

@ -221,7 +221,7 @@ int QTorrentHandle::num_files() const { @@ -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

4
src/searchengine/engineselectdlg.cpp

@ -430,8 +430,8 @@ void engineSelectDlg::processDownloadedFile(QString url, QString filePath) { @@ -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;

10
src/torrentadditiondlg.cpp

@ -141,13 +141,9 @@ void torrentAdditionDialog::saveSettings() { @@ -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() {

2
src/torrentcreator/torrentcreatorthread.cpp

@ -109,7 +109,7 @@ void TorrentCreatorThread::run() { @@ -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));

4
src/torrentfilesmodel.h

@ -65,10 +65,10 @@ public: @@ -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"))

4
src/torrentimportdlg.cpp

@ -85,9 +85,9 @@ void TorrentImportDlg::on_browseContentBtn_clicked() @@ -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);

2
src/webui/eventmanager.cpp

@ -109,7 +109,7 @@ QList<QVariantMap> EventManager::getPropFilesInfo(QString hash) const { @@ -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…
Cancel
Save