diff --git a/src/bittorrent.cpp b/src/bittorrent.cpp index 66eb86dc1..b84ca9099 100644 --- a/src/bittorrent.cpp +++ b/src/bittorrent.cpp @@ -1133,6 +1133,7 @@ QTorrentHandle Bittorrent::addTorrent(QString path, bool fromScanDir, QString fr const QStringList &files_path = TorrentTempData::getFilesPath(hash); bool force_recheck = false; if(files_path.size() == h.num_files()) { + qDebug("Renaming a file"); for(int i=0; i 0 && (fp[i]/(double)file_size) < 1.) { - const QString &name = misc::toQString(h.get_torrent_info().file_at(i).path.string()); + const QString &name = misc::toQStringU(h.get_torrent_info().file_at(i).path.string()); if(!name.endsWith(".!qB")) { const QString new_name = name+".!qB"; qDebug("Renaming %s to %s", qPrintable(name), qPrintable(new_name)); @@ -1627,7 +1628,7 @@ void Bittorrent::addConsoleMessage(QString msg, QString) { } } } else { - QString name = misc::toQString(h.get_torrent_info().file_at(i).path.string()); + QString name = misc::toQStringU(h.get_torrent_info().file_at(i).path.string()); if(name.endsWith(".!qB")) { const QString old_name = name; name.chop(4); @@ -1924,7 +1925,7 @@ void Bittorrent::addConsoleMessage(QString msg, QString) { qDebug("Checking if the torrent contains torrent files to download"); // Check if there are torrent files inside for(int i=0; i(a.get())) { + QTorrentHandle h(p->handle); + if(h.is_valid() && h.num_files() > 1) { + // Check if folders were renamed + QStringList old_path_parts = misc::toQStringU(h.get_torrent_info().orig_files().at(p->index).path.string()).split("/"); + old_path_parts.removeLast(); + QString old_path = old_path_parts.join("/"); + QStringList new_path_parts = misc::toQStringU(p->name).split("/"); + new_path_parts.removeLast(); + if(old_path != new_path_parts.join("/")) { + old_path = h.save_path()+"/"+old_path; + qDebug("Detected folder renaming, attempt to delete old folder: %s", qPrintable(old_path)); + QDir().rmpath(old_path); + } + } + } else if (storage_moved_alert* p = dynamic_cast(a.get())) { QTorrentHandle h(p->handle); if(h.is_valid()) { @@ -2046,7 +2063,7 @@ void Bittorrent::addConsoleMessage(QString msg, QString) { else if (file_completed_alert* p = dynamic_cast(a.get())) { QTorrentHandle h(p->handle); if(appendqBExtension) { - QString name = misc::toQString(h.get_torrent_info().file_at(p->index).path.string()); + QString name = misc::toQStringU(h.get_torrent_info().file_at(p->index).path.string()); if(name.endsWith(".!qB")) { const QString old_name = name; name.chop(4); diff --git a/src/createtorrent_imp.cpp b/src/createtorrent_imp.cpp index 4dbd38b59..5a11b7831 100644 --- a/src/createtorrent_imp.cpp +++ b/src/createtorrent_imp.cpp @@ -264,7 +264,7 @@ void torrentCreatorThread::run() { // Set qBittorrent as creator and add user comment to // torrent_info structure t.set_creator(creator_str); - t.set_comment((const char*)comment.toLocal8Bit()); + t.set_comment((const char*)comment.toUtf8()); // Is private ? t.set_priv(is_private); if(abort) return; diff --git a/src/misc.h b/src/misc.h index d81d8b80f..9126910a3 100644 --- a/src/misc.h +++ b/src/misc.h @@ -57,6 +57,14 @@ public: return QString::fromLocal8Bit(str); } + static inline QString toQStringU(std::string str) { + return QString::fromUtf8(str.c_str()); + } + + static inline QString toQStringU(char* str) { + return QString::fromUtf8(str); + } + static inline QString toQString(sha1_hash hash) { std::ostringstream o; o << hash; diff --git a/src/propertieswidget.cpp b/src/propertieswidget.cpp index 778ae8aeb..1612358f1 100644 --- a/src/propertieswidget.cpp +++ b/src/propertieswidget.cpp @@ -474,17 +474,22 @@ void PropertiesWidget::openDoubleClickedFile(QModelIndex index) { if(PropListModel->getType(index) == TFILE) { int i = PropListModel->getFileIndex(index); const QDir &saveDir(h.save_path()); - const QString &filename = misc::toQString(h.get_torrent_info().file_at(i).path.string()); + const QString &filename = misc::toQStringU(h.get_torrent_info().file_at(i).path.string()); const QString &file_path = QDir::cleanPath(saveDir.absoluteFilePath(filename)); qDebug("Trying to open file at %s", qPrintable(file_path)); #ifdef LIBTORRENT_0_15 // Flush data h.flush_cache(); #endif - if(QFile::exists(file_path)) + if(QFile::exists(file_path)) { +#ifdef Q_WS_WIN + QDesktopServices::openUrl(QUrl("file:///"+file_path)); +#else QDesktopServices::openUrl(QUrl("file://"+file_path)); - else +#endif + } else { QMessageBox::warning(this, tr("I/O Error"), tr("This file does not exist yet.")); + } } else { // FOLDER QStringList path_items; @@ -502,10 +507,15 @@ void PropertiesWidget::openDoubleClickedFile(QModelIndex index) { // Flush data h.flush_cache(); #endif - if(QFile::exists(file_path)) + if(QFile::exists(file_path)) { +#ifdef Q_WS_WIN + QDesktopServices::openUrl(QUrl("file:///"+file_path)); +#else QDesktopServices::openUrl(QUrl("file://"+file_path)); - else +#endif + } else { QMessageBox::warning(this, tr("I/O Error"), tr("This folder does not exist yet.")); + } } } diff --git a/src/qtorrenthandle.cpp b/src/qtorrenthandle.cpp index 4b13806ee..9c18f14df 100644 --- a/src/qtorrenthandle.cpp +++ b/src/qtorrenthandle.cpp @@ -68,7 +68,7 @@ QString QTorrentHandle::name() const { Q_ASSERT(h.is_valid()); QString name = TorrentPersistentData::getName(hash()); if(name.isEmpty()) { - name = misc::toQString(h.name()); + name = misc::toQStringU(h.name()); } return name; } @@ -282,7 +282,7 @@ void QTorrentHandle::save_resume_data() const { QString QTorrentHandle::file_at(unsigned int index) const { Q_ASSERT(h.is_valid()); Q_ASSERT(index < (unsigned int)h.get_torrent_info().num_files()); - return misc::toQString(h.get_torrent_info().file_at(index).path.leaf()); + return misc::toQStringU(h.get_torrent_info().file_at(index).path.leaf()); } size_type QTorrentHandle::filesize_at(unsigned int index) const { @@ -313,7 +313,7 @@ QString QTorrentHandle::creator() const { QString QTorrentHandle::comment() const { Q_ASSERT(h.is_valid()); - return misc::toQString(h.get_torrent_info().comment()); + return misc::toQStringU(h.get_torrent_info().comment()); } size_type QTorrentHandle::total_failed_bytes() const { @@ -442,9 +442,9 @@ bool QTorrentHandle::priv() const { QString QTorrentHandle::root_path() const { Q_ASSERT(h.is_valid()); if(num_files() == 0) return ""; - QStringList path_list = misc::toQString(h.get_torrent_info().file_at(0).path.string()).split(QDir::separator()); + QStringList path_list = misc::toQString(h.get_torrent_info().file_at(0).path.string()).split("/"); if(path_list.size() > 1) - return save_path()+QDir::separator()+path_list.first(); + return save_path()+"/"+path_list.first(); return save_path(); } diff --git a/src/torrentadditiondlg.h b/src/torrentadditiondlg.h index c3b84b05f..bac1f5169 100644 --- a/src/torrentadditiondlg.h +++ b/src/torrentadditiondlg.h @@ -201,7 +201,7 @@ public: } nbFiles = t->num_files(); // Setting file name - fileName = misc::toQString(t->name()); + fileName = misc::toQStringU(t->name()); hash = misc::toQString(t->info_hash()); // Use left() to remove .old extension QString newFileName; @@ -229,7 +229,7 @@ public: } // Loads files path in the torrent for(uint i=0; ifile_at(i).path.string()); + files_path << misc::toQStringU(t->file_at(i).path.string()); } // Show the dialog show(); @@ -457,15 +457,16 @@ public slots: bool path_changed = false; for(uint i=0; ifile_at(i).path.string()), Qt::CaseSensitive) != 0) { + if(files_path.at(i).compare(misc::toQStringU(t->file_at(i).path.string()), Qt::CaseSensitive) != 0) { #else - if(files_path.at(i).compare(misc::toQString(t->file_at(i).path.string()), Qt::CaseInsensitive) != 0) { + if(files_path.at(i).compare(misc::toQStringU(t->file_at(i).path.string()), Qt::CaseInsensitive) != 0) { #endif path_changed = true; break; } } if(path_changed) { + qDebug("Changing files paths"); TorrentTempData::setFilesPath(hash, files_path); } } @@ -473,7 +474,7 @@ public slots: // Skip file checking and directly start seeding if(addInSeed->isChecked()) { // Check if local file(s) actually exist - if(is_magnet || savePath.exists(misc::toQString(t->name()))) { + if(is_magnet || savePath.exists(misc::toQStringU(t->name()))) { TorrentTempData::setSeedingMode(hash, true); } else { QMessageBox::warning(0, tr("Seeding mode error"), tr("You chose to skip file checking. However, local files do not seem to exist in the current destionation folder. Please disable this feature or update the save path.")); diff --git a/src/torrentfilesmodel.h b/src/torrentfilesmodel.h index 1e798dacb..2e9ed8871 100644 --- a/src/torrentfilesmodel.h +++ b/src/torrentfilesmodel.h @@ -61,7 +61,7 @@ public: parentItem = parent; type = TFILE; file_index = _file_index; - QString name = misc::toQString(f.path.string()).split("/").last(); + QString name = misc::toQStringU(f.path.string()).split("/").last(); // Do not display incomplete extensions if(name.endsWith(".!qB")) name.chop(4); @@ -507,7 +507,7 @@ public: TreeItem *parent = this->rootItem; if(t.num_files() == 1) { // Create possible parent folder - QStringList path_parts = misc::toQString(t.file_at(0).path.string()).split("/"); + QStringList path_parts = misc::toQStringU(t.file_at(0).path.string()).split("/"); path_parts.removeLast(); foreach(const QString &part, path_parts) { TreeItem *folder = new TreeItem(part, parent); @@ -520,7 +520,7 @@ public: return; } // Create parent folder - QString root_name = misc::toQString(t.file_at(0).path.string()).split("/").first(); + QString root_name = misc::toQStringU(t.file_at(0).path.string()).split("/").first(); TreeItem *current_parent = new TreeItem(root_name, parent); //parent->appendChild(current_parent); TreeItem *root_folder = current_parent; @@ -530,7 +530,7 @@ public: torrent_info::file_iterator fi = t.begin_files(); while(fi != t.end_files()) { current_parent = root_folder; - QString path = QDir::cleanPath(misc::toQString(fi->path.string())); + QString path = QDir::cleanPath(misc::toQStringU(fi->path.string())); // Iterate of parts of the path to create necessary folders QStringList pathFolders = path.split("/"); Q_ASSERT(pathFolders.size() >= 2); diff --git a/src/transferlistwidget.cpp b/src/transferlistwidget.cpp index 932bbf27f..97d2ad7ae 100644 --- a/src/transferlistwidget.cpp +++ b/src/transferlistwidget.cpp @@ -722,9 +722,14 @@ void TransferListWidget::openSelectedTorrentsFolder() const { const QTorrentHandle &h = BTSession->getTorrentHandle(hash); if(h.is_valid()) { const QString &savePath = h.root_path(); + qDebug("Opening path at %s", qPrintable(savePath)); if(!pathsList.contains(savePath)) { pathsList.append(savePath); +#ifdef Q_WS_WIN + QDesktopServices::openUrl(QUrl(QString("file:///")+savePath)); +#else QDesktopServices::openUrl(QUrl(QString("file://")+savePath)); +#endif } } }