From c9ece4695e4f82eedf87b8b12fd14f7d3eab41f6 Mon Sep 17 00:00:00 2001 From: Christophe Dumez Date: Sun, 6 Jun 2010 13:58:43 +0000 Subject: [PATCH] Merge latest changes for stable branch (mostly unicode fixes) --- src/bittorrent.cpp | 23 +++++++++++++++++------ src/createtorrent_imp.cpp | 2 +- src/misc.h | 1 - src/propertieswidget.cpp | 27 +++++++++++++++------------ src/torrentadditiondlg.h | 20 +++++++++++++------- src/torrentfilesmodel.h | 2 +- 6 files changed, 47 insertions(+), 28 deletions(-) diff --git a/src/bittorrent.cpp b/src/bittorrent.cpp index 6df4ea1bd..1ac5e2810 100644 --- a/src/bittorrent.cpp +++ b/src/bittorrent.cpp @@ -971,7 +971,7 @@ QTorrentHandle Bittorrent::addTorrent(QString path, bool fromScanDir, QString fr qDebug("Adding %s to download list", qPrintable(file)); try { // Getting torrent file informations - t = new torrent_info(file.toLocal8Bit().constData()); + t = new torrent_info(file.toUtf8().constData()); if(!t->is_valid()) throw std::exception(); } catch(std::exception&) { @@ -1141,9 +1141,20 @@ QTorrentHandle Bittorrent::addTorrent(QString path, bool fromScanDir, QString fr bool force_recheck = false; if(files_path.size() == h.num_files()) { for(int i=0; i t = new torrent_info(torrent_fullpath.toLocal8Bit().constData()); + boost::intrusive_ptr t = new torrent_info(torrent_fullpath.toUtf8().constData()); const QString &sub_hash = misc::toQString(t->info_hash()); // Passing the save path along to the sub torrent file TorrentTempData::setSavePath(sub_hash, h.save_path()); @@ -1947,7 +1958,7 @@ void Bittorrent::addConsoleMessage(QString msg, QString) { const QString torrent_fullpath = h.save_path()+QDir::separator()+torrent_relpath; qDebug("Full subtorrent path is %s", qPrintable(torrent_fullpath)); try { - boost::intrusive_ptr t = new torrent_info(torrent_fullpath.toLocal8Bit().constData()); + boost::intrusive_ptr t = new torrent_info(torrent_fullpath.toUtf8().constData()); if(t->is_valid()) { qDebug("emitting recursiveTorrentDownloadPossible()"); emit recursiveTorrentDownloadPossible(h); diff --git a/src/createtorrent_imp.cpp b/src/createtorrent_imp.cpp index e8cc5a5a8..641f57ef4 100644 --- a/src/createtorrent_imp.cpp +++ b/src/createtorrent_imp.cpp @@ -201,7 +201,7 @@ void createtorrent::handleCreationSuccess(QString path, const char* branch_path) // Create save path temp data boost::intrusive_ptr t; try { - t = new torrent_info(path.toLocal8Bit().data()); + t = new torrent_info(path.toUtf8().data()); } catch(std::exception&) { QMessageBox::critical(0, tr("Torrent creation"), tr("Created torrent file is invalid. It won't be added to download list.")); return; diff --git a/src/misc.h b/src/misc.h index 05059595e..04936ad92 100644 --- a/src/misc.h +++ b/src/misc.h @@ -76,7 +76,6 @@ public: static inline sha1_hash QStringToSha1(const QString& s) { std::string str(s.toLocal8Bit().data()); std::istringstream i(str); - std::cout << "lol" << std::endl; sha1_hash x; i>>x; return x; diff --git a/src/propertieswidget.cpp b/src/propertieswidget.cpp index b3489e3d0..9ebb6c04b 100644 --- a/src/propertieswidget.cpp +++ b/src/propertieswidget.cpp @@ -593,25 +593,27 @@ void PropertiesWidget::renameSelectedFile() { // File renaming const int file_index = PropListModel->getFileIndex(index); if(!h.is_valid() || !h.has_metadata()) return; - const QString &old_name = misc::toQString(h.get_torrent_info().file_at(file_index).path.string()); + QString old_name = misc::toQStringU(h.get_torrent_info().file_at(file_index).path.string()); + old_name = old_name.replace("\\", "/"); if(old_name.endsWith(".!qB") && !new_name_last.endsWith(".!qB")) { new_name_last += ".!qB"; } - QStringList path_items = old_name.split(QDir::separator()); + QStringList path_items = old_name.split("/"); path_items.removeLast(); path_items << new_name_last; - const QString &new_name = path_items.join(QDir::separator()); + QString new_name = path_items.join("/"); if(old_name == new_name) { qDebug("Name did not change"); return; } + new_name = QDir::cleanPath(new_name); // Check if that name is already used for(int i=0; iparent(parent); } - const QString &old_path = path_items.join(QDir::separator()); + const QString &old_path = path_items.join("/"); path_items.removeLast(); path_items << new_name_last; - QString new_path = path_items.join(QDir::separator()); - if(!new_path.endsWith(QDir::separator())) new_path += QDir::separator(); + QString new_path = path_items.join("/"); + if(!new_path.endsWith("/")) new_path += "/"; // Check for overwriting const int num_files = h.num_files(); for(int i=0; isetData(index, new_name_last); // Remove old folder - const QDir old_folder(h.save_path()+QDir::separator()+old_path); + const QDir old_folder(h.save_path()+"/"+old_path); int timeout = 10; while(!misc::removeEmptyTree(old_folder.absolutePath()) && timeout > 0) { SleeperThread::msleep(100); diff --git a/src/torrentadditiondlg.h b/src/torrentadditiondlg.h index 5e8e168b3..9a80ac341 100644 --- a/src/torrentadditiondlg.h +++ b/src/torrentadditiondlg.h @@ -203,7 +203,7 @@ public: this->from_url = from_url; // Getting torrent file informations try { - t = new torrent_info(filePath.toLocal8Bit().data()); + t = new torrent_info(filePath.toUtf8().data()); if(!t->is_valid()) throw std::exception(); } catch(std::exception&) { @@ -318,15 +318,19 @@ public slots: if(PropListModel->getType(index)==TFILE) { // File renaming const uint file_index = PropListModel->getFileIndex(index); - const QString &old_name = files_path.at(file_index); - QStringList path_items = old_name.split(QDir::separator()); + QString old_name = files_path.at(file_index); + old_name = old_name.replace("\\", "/"); + qDebug("Old name: %s", qPrintable(old_name)); + QStringList path_items = old_name.split("/"); path_items.removeLast(); path_items << new_name_last; - const QString &new_name = path_items.join(QDir::separator()); + QString new_name = path_items.join("/"); if(old_name == new_name) { qDebug("Name did not change"); return; } + new_name = QDir::cleanPath(new_name); + qDebug("New name: %s", qPrintable(new_name)); // Check if that name is already used for(uint i=0; iparent(parent); } - const QString &old_path = path_items.join(QDir::separator()); + const QString &old_path = path_items.join("/"); path_items.removeLast(); path_items << new_name_last; - QString new_path = path_items.join(QDir::separator()); - if(!new_path.endsWith(QDir::separator())) new_path += QDir::separator(); + QString new_path = path_items.join("/"); + if(!new_path.endsWith("/")) new_path += "/"; // Check for overwriting for(uint i=0; irootItem; /*if(t.num_files() == 1) { // Create possible parent folder - QStringList path_parts = misc::toQStringU(t.file_at(0).path.string()).split("/"); + QStringList path_parts = misc::toQStringU(t.file_at(0).path.string()).split("/", QString::SkipEmptyParts); path_parts.removeLast(); foreach(const QString &part, path_parts) { TreeItem *folder = new TreeItem(part, parent);