diff --git a/src/bittorrent.cpp b/src/bittorrent.cpp index 641110788..f5087e00a 100644 --- a/src/bittorrent.cpp +++ b/src/bittorrent.cpp @@ -945,12 +945,12 @@ QTorrentHandle Bittorrent::addTorrent(QString path, bool fromScanDir, QString fr boost::intrusive_ptr t; #ifdef Q_WS_WIN - // Windows hack - if(!path.endsWith(".torrent")) { - if(QFile::rename(path, path+".torrent")) - path += ".torrent"; - } - qDebug("Downloading torrent at path: %s", qPrintable(path)); + // Windows hack + if(!path.endsWith(".torrent")) { + if(QFile::rename(path, path+".torrent")) + path += ".torrent"; + } + qDebug("Downloading torrent at path: %s", qPrintable(path)); #endif // Checking if BT_backup Dir exists @@ -1626,7 +1626,7 @@ void Bittorrent::addConsoleMessage(QString msg, QString) { if(append) { const qulonglong file_size = h.filesize_at(i); if(file_size > 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)); @@ -1634,7 +1634,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); @@ -1927,7 +1927,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()) { @@ -2052,7 +2068,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 96c52be71..8e5ed7f5b 100644 --- a/src/misc.h +++ b/src/misc.h @@ -59,6 +59,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 09ae3cbb0..ea16980c0 100644 --- a/src/propertieswidget.cpp +++ b/src/propertieswidget.cpp @@ -483,17 +483,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; @@ -511,10 +516,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 c7e6ed4a6..fe07f3768 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; } @@ -292,7 +292,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 { @@ -323,7 +323,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 { @@ -452,9 +452,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 907d78e4c..d6006b94d 100644 --- a/src/torrentadditiondlg.h +++ b/src/torrentadditiondlg.h @@ -222,7 +222,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; @@ -250,7 +250,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(); @@ -478,15 +478,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); } } @@ -494,7 +495,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 47fb88b50..fcd69e03b 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); @@ -510,7 +510,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); @@ -535,7 +535,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 1c751fdad..953c47608 100644 --- a/src/transferlistwidget.cpp +++ b/src/transferlistwidget.cpp @@ -763,9 +763,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 } } }