Browse Source

Merge pull request #1095 from Gelmir/separators

Use native separators where appropriate
adaptive-webui-19844
sledgehammer999 11 years ago
parent
commit
c167b47a2e
  1. 27
      src/addnewtorrentdialog.cpp
  2. 4
      src/filesystemwatcher.h
  3. 106
      src/fs_utils.cpp
  4. 54
      src/fs_utils.h
  5. 2
      src/geoip/geoipmanager.cpp
  6. 2
      src/headlessloader.h
  7. 2
      src/iconprovider.h
  8. 4
      src/mainwindow.cpp
  9. 107
      src/preferences/options_imp.cpp
  10. 78
      src/preferences/preferences.h
  11. 24
      src/properties/propertieswidget.cpp
  12. 2
      src/qinisettings.h
  13. 118
      src/qtlibtorrent/qbtsession.cpp
  14. 39
      src/qtlibtorrent/qtorrenthandle.cpp
  15. 3
      src/qtlibtorrent/torrentmodel.cpp
  16. 4
      src/rss/automatedrssdownloader.cpp
  17. 2
      src/rss/rssdownloadrule.cpp
  18. 1
      src/rss/rssmanager.cpp
  19. 2
      src/rss/rssparser.cpp
  20. 10
      src/scannedfoldersmodel.cpp
  21. 17
      src/searchengine/engineselectdlg.cpp
  22. 12
      src/searchengine/searchengine.cpp
  23. 2
      src/searchengine/supportedengines.h
  24. 5
      src/torrentcontentmodel.cpp
  25. 20
      src/torrentcreator/torrentcreatordlg.cpp
  26. 14
      src/torrentcreator/torrentcreatorthread.cpp
  27. 33
      src/torrentimportdlg.cpp
  28. 2
      src/torrentpersistentdata.h
  29. 17
      src/transferlistwidget.cpp
  30. 3
      src/transferlistwidget.h
  31. 7
      src/webui/btjson.cpp
  32. 18
      src/webui/prefjson.cpp

27
src/addnewtorrentdialog.cpp

@ -68,7 +68,7 @@ AddNewTorrentDialog::AddNewTorrentDialog(QWidget *parent) : @@ -68,7 +68,7 @@ AddNewTorrentDialog::AddNewTorrentDialog(QWidget *parent) :
QIniSettings settings;
Preferences pref;
ui->start_torrent_cb->setChecked(!pref.addTorrentsInPause());
ui->save_path_combo->addItem(fsutils::toDisplayPath(pref.getSavePath()), pref.getSavePath());
ui->save_path_combo->addItem(fsutils::toNativePath(pref.getSavePath()), pref.getSavePath());
loadSavePathHistory();
ui->save_path_combo->insertSeparator(ui->save_path_combo->count());
ui->save_path_combo->addItem(tr("Other...", "Other save path..."));
@ -192,7 +192,7 @@ bool AddNewTorrentDialog::loadTorrent(const QString& torrent_path, const QString @@ -192,7 +192,7 @@ bool AddNewTorrentDialog::loadTorrent(const QString& torrent_path, const QString
m_hasMetadata = true;
try {
m_torrentInfo = new torrent_info(m_filePath.toUtf8().data());
m_torrentInfo = new torrent_info(fsutils::toNativePath(m_filePath).toUtf8().data());
m_hash = misc::toQString(m_torrentInfo->info_hash());
} catch(const std::exception& e) {
QMessageBox::critical(0, tr("Invalid torrent"), tr("Failed to load the torrent: %1").arg(e.what()));
@ -242,7 +242,7 @@ bool AddNewTorrentDialog::loadTorrent(const QString& torrent_path, const QString @@ -242,7 +242,7 @@ bool AddNewTorrentDialog::loadTorrent(const QString& torrent_path, const QString
// Update save paths (append file name to them)
QString single_file_relpath = misc::toQStringU(fs.file_path(0));
for (int i=0; i<ui->save_path_combo->count()-1; ++i) {
ui->save_path_combo->setItemText(i, fsutils::toDisplayPath(QDir(ui->save_path_combo->itemText(i)).absoluteFilePath(single_file_relpath)));
ui->save_path_combo->setItemText(i, fsutils::toNativePath(QDir(ui->save_path_combo->itemText(i)).absoluteFilePath(single_file_relpath)));
}
}
@ -281,9 +281,8 @@ bool AddNewTorrentDialog::loadMagnet(const QString &magnet_uri) @@ -281,9 +281,8 @@ bool AddNewTorrentDialog::loadMagnet(const QString &magnet_uri)
// Set dialog position
setdialogPosition();
Preferences pref;
// Override save path
TorrentTempData::setSavePath(m_hash, QString(QDir::tempPath() + QDir::separator() + m_hash).replace("\\", "/"));
TorrentTempData::setSavePath(m_hash, QString(QDir::tempPath() + "/" + m_hash));
HiddenData::addData(m_hash);
QBtSession::instance()->addMagnetUri(m_url, false);
setMetadataProgressIndicator(true, tr("Retrieving metadata..."));
@ -326,7 +325,7 @@ void AddNewTorrentDialog::updateFileNameInSavePaths(const QString &new_filename) @@ -326,7 +325,7 @@ void AddNewTorrentDialog::updateFileNameInSavePaths(const QString &new_filename)
{
for(int i=0; i<ui->save_path_combo->count()-1; ++i) {
const QDir folder(ui->save_path_combo->itemData(i).toString());
ui->save_path_combo->setItemText(i, fsutils::toDisplayPath(folder.absoluteFilePath(new_filename)));
ui->save_path_combo->setItemText(i, fsutils::toNativePath(folder.absoluteFilePath(new_filename)));
}
}
@ -383,9 +382,9 @@ void AddNewTorrentDialog::onSavePathChanged(int index) @@ -383,9 +382,9 @@ void AddNewTorrentDialog::onSavePathChanged(int index)
else {
// New path, prepend to combo box
if (!new_filename.isEmpty())
ui->save_path_combo->insertItem(0, fsutils::toDisplayPath(QDir(new_path).absoluteFilePath(new_filename)), new_path);
ui->save_path_combo->insertItem(0, fsutils::toNativePath(QDir(new_path).absoluteFilePath(new_filename)), new_path);
else
ui->save_path_combo->insertItem(0, fsutils::toDisplayPath(new_path), new_path);
ui->save_path_combo->insertItem(0, fsutils::toNativePath(new_path), new_path);
ui->save_path_combo->setCurrentIndex(0);
}
// Update file name in all save_paths
@ -440,8 +439,7 @@ void AddNewTorrentDialog::renameSelectedFile() @@ -440,8 +439,7 @@ void AddNewTorrentDialog::renameSelectedFile()
if (m_contentModel->itemType(index) == TorrentContentModelItem::FileType) {
// File renaming
const int file_index = m_contentModel->getFileIndex(index);
QString old_name = m_filesPath.at(file_index);
old_name.replace("\\", "/");
QString old_name = fsutils::fromNativePath(m_filesPath.at(file_index));
qDebug("Old name: %s", qPrintable(old_name));
QStringList path_items = old_name.split("/");
path_items.removeLast();
@ -451,7 +449,7 @@ void AddNewTorrentDialog::renameSelectedFile() @@ -451,7 +449,7 @@ void AddNewTorrentDialog::renameSelectedFile()
qDebug("Name did not change");
return;
}
new_name = QDir::cleanPath(new_name);
new_name = fsutils::expandPathAbs(new_name);
qDebug("New name: %s", qPrintable(new_name));
// Check if that name is already used
for (int i=0; i<m_torrentInfo->num_files(); ++i) {
@ -464,7 +462,6 @@ void AddNewTorrentDialog::renameSelectedFile() @@ -464,7 +462,6 @@ void AddNewTorrentDialog::renameSelectedFile()
return;
}
}
new_name = QDir::cleanPath(new_name);
qDebug("Renaming %s to %s", qPrintable(old_name), qPrintable(new_name));
// Rename file in files_path
m_filesPath.replace(file_index, new_name);
@ -505,7 +502,7 @@ void AddNewTorrentDialog::renameSelectedFile() @@ -505,7 +502,7 @@ void AddNewTorrentDialog::renameSelectedFile()
if (current_name.startsWith(old_path)) {
QString new_name = current_name;
new_name.replace(0, old_path.length(), new_path);
new_name = QDir::cleanPath(new_name);
new_name = fsutils::expandPathAbs(new_name);
qDebug("Rename %s to %s", qPrintable(current_name), qPrintable(new_name));
// Rename in files_path
m_filesPath.replace(i, new_name);
@ -543,7 +540,7 @@ void AddNewTorrentDialog::loadSavePathHistory() @@ -543,7 +540,7 @@ void AddNewTorrentDialog::loadSavePathHistory()
QStringList raw_path_history = settings.value("TorrentAdditionDlg/save_path_history").toStringList();
foreach (const QString &sp, raw_path_history) {
if (QDir(sp) != default_save_path)
ui->save_path_combo->addItem(fsutils::toDisplayPath(sp), sp);
ui->save_path_combo->addItem(fsutils::toNativePath(sp), sp);
}
}
@ -696,7 +693,7 @@ void AddNewTorrentDialog::updateMetadata(const QTorrentHandle &h) { @@ -696,7 +693,7 @@ void AddNewTorrentDialog::updateMetadata(const QTorrentHandle &h) {
// Update save paths (append file name to them)
QString single_file_relpath = misc::toQStringU(fs.file_path(0));
for (int i=0; i<ui->save_path_combo->count()-1; ++i) {
ui->save_path_combo->setItemText(i, fsutils::toDisplayPath(QDir(ui->save_path_combo->itemText(i)).absoluteFilePath(single_file_relpath)));
ui->save_path_combo->setItemText(i, fsutils::toNativePath(QDir(ui->save_path_combo->itemText(i)).absoluteFilePath(single_file_relpath)));
}
}

4
src/filesystemwatcher.h

@ -60,8 +60,8 @@ private: @@ -60,8 +60,8 @@ private:
private:
static bool isNetworkFileSystem(QString path) {
QString file = path;
if (!file.endsWith(QDir::separator()))
file += QDir::separator();
if (!file.endsWith("/"))
file += "/";
file += ".";
struct statfs buf;
if (!statfs(file.toLocal8Bit().constData(), &buf)) {

106
src/fs_utils.cpp

@ -71,11 +71,14 @@ using namespace libtorrent; @@ -71,11 +71,14 @@ using namespace libtorrent;
* This function makes sure the directory separator used is consistent
* with the OS being run.
*/
QString fsutils::toDisplayPath(const QString& path)
{
QString fsutils::toNativePath(const QString& path) {
return QDir::toNativeSeparators(path);
}
QString fsutils::fromNativePath(const QString &path) {
return QDir::fromNativeSeparators(path);
}
/**
* Returns the file extension part of a file name.
*/
@ -87,15 +90,16 @@ QString fsutils::fileExtension(const QString &filename) @@ -87,15 +90,16 @@ QString fsutils::fileExtension(const QString &filename)
QString fsutils::fileName(const QString& file_path)
{
const int slash_index = file_path.lastIndexOf(QRegExp("[/\\\\]"));
QString path = fsutils::fromNativePath(file_path);
const int slash_index = path.lastIndexOf("/");
if (slash_index == -1)
return file_path;
return file_path.mid(slash_index + 1);
return path;
return path.mid(slash_index + 1);
}
bool fsutils::isValidTorrentFile(const QString& torrent_path) {
try {
boost::intrusive_ptr<libtorrent::torrent_info> t = new torrent_info(torrent_path.toUtf8().constData());
boost::intrusive_ptr<libtorrent::torrent_info> t = new torrent_info(fsutils::toNativePath(torrent_path).toUtf8().constData());
if (!t->is_valid() || t->num_files() == 0)
return false;
} catch(std::exception&) {
@ -220,14 +224,14 @@ bool fsutils::sameFiles(const QString& path1, const QString& path2) @@ -220,14 +224,14 @@ bool fsutils::sameFiles(const QString& path1, const QString& path2)
return same;
}
QString fsutils::updateLabelInSavePath(QString defaultSavePath,QString save_path, const QString& old_label, const QString& new_label) {
if (old_label == new_label) return save_path;
defaultSavePath.replace("\\", "/");
save_path.replace("\\", "/");
qDebug("UpdateLabelInSavePath(%s, %s, %s)", qPrintable(save_path), qPrintable(old_label), qPrintable(new_label));
if (!save_path.startsWith(defaultSavePath)) return save_path;
QString new_save_path = save_path;
new_save_path.replace(defaultSavePath, "");
QString fsutils::updateLabelInSavePath(const QString& defaultSavePath, const QString& save_path, const QString& old_label, const QString& new_label) {
if (old_label == new_label) return fsutils::fromNativePath(save_path);
QString defaultPath = fsutils::fromNativePath(defaultSavePath);
QString path = fsutils::fromNativePath(save_path);
qDebug("UpdateLabelInSavePath(%s, %s, %s)", qPrintable(path), qPrintable(old_label), qPrintable(new_label));
if (!path.startsWith(defaultPath)) return path;
QString new_save_path = path;
new_save_path.remove(defaultPath);
QStringList path_parts = new_save_path.split("/", QString::SkipEmptyParts);
if (path_parts.empty()) {
if (!new_label.isEmpty())
@ -245,9 +249,9 @@ QString fsutils::updateLabelInSavePath(QString defaultSavePath,QString save_path @@ -245,9 +249,9 @@ QString fsutils::updateLabelInSavePath(QString defaultSavePath,QString save_path
}
}
}
new_save_path = defaultSavePath;
if (!new_save_path.endsWith(QDir::separator())) new_save_path += QDir::separator();
new_save_path += path_parts.join(QDir::separator());
new_save_path = defaultPath;
if (!new_save_path.endsWith("/")) new_save_path += "/";
new_save_path += path_parts.join("/");
qDebug("New save path is %s", qPrintable(new_save_path));
return new_save_path;
}
@ -268,7 +272,6 @@ bool fsutils::isValidFileSystemName(const QString& filename) { @@ -268,7 +272,6 @@ bool fsutils::isValidFileSystemName(const QString& filename) {
long long fsutils::freeDiskSpaceOnPath(QString path) {
if (path.isEmpty()) return -1;
path.replace("\\", "/");
QDir dir_path(path);
if (!dir_path.exists()) {
QStringList parts = path.split("/");
@ -307,7 +310,7 @@ long long fsutils::freeDiskSpaceOnPath(QString path) { @@ -307,7 +310,7 @@ long long fsutils::freeDiskSpaceOnPath(QString path) {
{
ULARGE_INTEGER bytesFree, bytesTotal;
unsigned long long *ret;
if (pGetDiskFreeSpaceEx((LPCTSTR)(QDir::toNativeSeparators(dir_path.path())).utf16(), &bytesFree, &bytesTotal, NULL)) {
if (pGetDiskFreeSpaceEx((LPCTSTR)(fsutils::toNativePath(dir_path.path())).utf16(), &bytesFree, &bytesTotal, NULL)) {
ret = (unsigned long long*)&bytesFree;
return *ret;
} else {
@ -321,10 +324,10 @@ long long fsutils::freeDiskSpaceOnPath(QString path) { @@ -321,10 +324,10 @@ long long fsutils::freeDiskSpaceOnPath(QString path) {
QString fsutils::branchPath(const QString& file_path, QString* removed)
{
QString ret = file_path;
if (ret.endsWith("/") || ret.endsWith("\\"))
QString ret = fsutils::fromNativePath(file_path);
if (ret.endsWith("/"))
ret.chop(1);
const int slashIndex = ret.lastIndexOf(QRegExp("[/\\\\]"));
const int slashIndex = ret.lastIndexOf("/");
if (slashIndex >= 0) {
if (removed)
*removed = ret.mid(slashIndex + 1);
@ -342,35 +345,33 @@ bool fsutils::sameFileNames(const QString &first, const QString &second) @@ -342,35 +345,33 @@ bool fsutils::sameFileNames(const QString &first, const QString &second)
#endif
}
// Replace ~ in path
QString fsutils::expandPath(const QString& path) {
QString ret = path.trimmed();
if (ret.isEmpty()) return ret;
if (ret == "~")
return QDir::homePath();
if (ret[0] == '~' && (ret[1] == '/' || ret[1] == '\\')) {
ret.replace(0, 1, QDir::homePath());
} else {
if (!QDir::isAbsolutePath(ret))
ret = QDir(ret).absolutePath();
}
return QDir::cleanPath(path);
QString fsutils::expandPath(const QString &path) {
QString ret = fsutils::fromNativePath(path.trimmed());
if (ret.isEmpty())
return ret;
return QDir::cleanPath(ret);
}
QString fsutils::expandPathAbs(const QString& path) {
QString ret = fsutils::expandPath(path);
if (!QDir::isAbsolutePath(ret))
ret = QDir(ret).absolutePath();
return ret;
}
QString fsutils::QDesktopServicesDataLocation() {
#ifdef Q_WS_WIN
LPWSTR path=new WCHAR[256];
QString result;
#if defined Q_WS_WINCE
if (SHGetSpecialFolderPath(0, path, CSIDL_APPDATA, FALSE))
#else
if (SHGetSpecialFolderPath(0, path, CSIDL_LOCAL_APPDATA, FALSE))
#endif
result = QString::fromWCharArray(path);
result = fsutils::fromNativePath(QString::fromWCharArray(path));
if (!QCoreApplication::applicationName().isEmpty())
result = result + QLatin1String("\\") + qApp->applicationName();
if (!result.endsWith("\\"))
result += "\\";
result += QLatin1String("/") + qApp->applicationName();
if (!result.endsWith("/"))
result += "/";
return result;
#else
#ifdef Q_WS_MAC
@ -397,7 +398,7 @@ QString fsutils::QDesktopServicesDataLocation() { @@ -397,7 +398,7 @@ QString fsutils::QDesktopServicesDataLocation() {
QString fsutils::QDesktopServicesCacheLocation() {
#if defined(Q_WS_WIN) || defined(Q_OS_OS2)
return QDesktopServicesDataLocation() + QLatin1String("\\cache");
return QDesktopServicesDataLocation() + QLatin1String("cache");
#else
#ifdef Q_WS_MAC
// http://developer.apple.com/documentation/Carbon/Reference/Folder_Manager/Reference/reference.html
@ -427,7 +428,8 @@ QString fsutils::QDesktopServicesDownloadLocation() { @@ -427,7 +428,8 @@ QString fsutils::QDesktopServicesDownloadLocation() {
// TODO: Use IKnownFolderManager to get path of FOLDERID_Downloads
// instead of hardcoding "Downloads"
// Unfortunately, this would break compatibility with WinXP
return QDir(QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation)).absoluteFilePath(tr("Downloads"));
return QDir(QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation)).absoluteFilePath(
QCoreApplication::translate("fsutils", "Downloads"));
#endif
#ifdef Q_WS_X11
@ -458,7 +460,7 @@ QString fsutils::QDesktopServicesDownloadLocation() { @@ -458,7 +460,7 @@ QString fsutils::QDesktopServicesDownloadLocation() {
}
if (save_path.isEmpty() || !QFile::exists(save_path)) {
save_path = QDir::home().absoluteFilePath(tr("Downloads"));
save_path = QDir::home().absoluteFilePath(QCoreApplication::translate("fsutils", "Downloads"));
qDebug() << Q_FUNC_INFO << "using" << save_path << "as fallback since the XDG detection did not work";
}
@ -470,15 +472,15 @@ QString fsutils::QDesktopServicesDownloadLocation() { @@ -470,15 +472,15 @@ QString fsutils::QDesktopServicesDownloadLocation() {
#endif
// Fallback
return QDir::home().absoluteFilePath(tr("Downloads"));
return QDir::home().absoluteFilePath(QCoreApplication::translate("fsutils", "Downloads"));
}
QString fsutils::searchEngineLocation() {
QString folder = "nova";
if (misc::pythonVersion() >= 3)
folder = "nova3";
const QString location = QDir::cleanPath(QDesktopServicesDataLocation()
+ QDir::separator() + folder);
const QString location = fsutils::expandPathAbs(QDesktopServicesDataLocation()
+ folder);
QDir locationDir(location);
if (!locationDir.exists())
locationDir.mkpath(locationDir.absolutePath());
@ -486,8 +488,8 @@ QString fsutils::searchEngineLocation() { @@ -486,8 +488,8 @@ QString fsutils::searchEngineLocation() {
}
QString fsutils::BTBackupLocation() {
const QString location = QDir::cleanPath(QDesktopServicesDataLocation()
+ QDir::separator() + "BT_backup");
const QString location = fsutils::expandPathAbs(QDesktopServicesDataLocation()
+ "BT_backup");
QDir locationDir(location);
if (!locationDir.exists())
locationDir.mkpath(locationDir.absolutePath());
@ -495,7 +497,7 @@ QString fsutils::BTBackupLocation() { @@ -495,7 +497,7 @@ QString fsutils::BTBackupLocation() {
}
QString fsutils::cacheLocation() {
QString location = QDir::cleanPath(QDesktopServicesCacheLocation());
QString location = fsutils::expandPathAbs(QDesktopServicesCacheLocation());
QDir locationDir(location);
if (!locationDir.exists())
locationDir.mkpath(locationDir.absolutePath());

54
src/fs_utils.h

@ -37,37 +37,37 @@ @@ -37,37 +37,37 @@
/**
* Utility functions related to file system.
*/
class fsutils
namespace fsutils
{
Q_DECLARE_TR_FUNCTIONS(fsutils)
public:
static QString toDisplayPath(const QString& path);
static QString fileExtension(const QString& filename);
static QString fileName(const QString& file_path);
static qint64 computePathSize(const QString& path);
static bool sameFiles(const QString& path1, const QString& path2);
static QString updateLabelInSavePath(QString defaultSavePath, QString save_path, const QString& old_label, const QString& new_label);
static QString toValidFileSystemName(QString filename);
static bool isValidFileSystemName(const QString& filename);
static long long freeDiskSpaceOnPath(QString path);
static QString branchPath(const QString& file_path, QString* removed = 0);
static bool sameFileNames(const QString& first, const QString& second);
static QString expandPath(const QString& path);
static bool isValidTorrentFile(const QString& path);
static bool smartRemoveEmptyFolderTree(const QString& dir_path);
static bool forceRemove(const QString& file_path);
QString toNativePath(const QString& path);
QString fromNativePath(const QString& path);
QString fileExtension(const QString& filename);
QString fileName(const QString& file_path);
qint64 computePathSize(const QString& path);
bool sameFiles(const QString& path1, const QString& path2);
QString updateLabelInSavePath(const QString &defaultSavePath, const QString &save_path, const QString& old_label, const QString& new_label);
QString toValidFileSystemName(QString filename);
bool isValidFileSystemName(const QString& filename);
long long freeDiskSpaceOnPath(QString path);
QString branchPath(const QString& file_path, QString* removed = 0);
bool sameFileNames(const QString& first, const QString& second);
QString expandPath(const QString& path);
QString expandPathAbs(const QString& path);
bool isValidTorrentFile(const QString& path);
bool smartRemoveEmptyFolderTree(const QString& dir_path);
bool forceRemove(const QString& file_path);
/* Ported from Qt4 to drop dependency on QtGui */
static QString QDesktopServicesDataLocation();
static QString QDesktopServicesCacheLocation();
static QString QDesktopServicesDownloadLocation();
/* End of Qt4 code */
static QString searchEngineLocation();
static QString BTBackupLocation();
static QString cacheLocation();
/* Ported from Qt4 to drop dependency on QtGui */
QString QDesktopServicesDataLocation();
QString QDesktopServicesCacheLocation();
QString QDesktopServicesDownloadLocation();
/* End of Qt4 code */
QString searchEngineLocation();
QString BTBackupLocation();
QString cacheLocation();
};
}
#endif // FS_UTILS_H

2
src/geoip/geoipmanager.cpp

@ -72,7 +72,7 @@ QString GeoIPManager::geoipFolder(bool embedded) { @@ -72,7 +72,7 @@ QString GeoIPManager::geoipFolder(bool embedded) {
#ifdef WITH_GEOIP_EMBEDDED
if (embedded)
return ":/geoip/";
return fsutils::QDesktopServicesDataLocation()+"geoip"+QDir::separator();
return fsutils::QDesktopServicesDataLocation()+"geoip"+"/";
#else
Q_UNUSED(embedded);
if (QFile::exists("/usr/local/share/GeoIP/GeoIP.dat"))

2
src/headlessloader.h

@ -88,7 +88,7 @@ public slots: @@ -88,7 +88,7 @@ public slots:
// the parameter type.
void processParams(const QStringList& params) {
foreach (QString param, params) {
param = param.trimmed();
param = fsutils::fromNativePath(param).trimmed();
if (param.startsWith(QString::fromUtf8("http://"), Qt::CaseInsensitive) || param.startsWith(QString::fromUtf8("ftp://"), Qt::CaseInsensitive) || param.startsWith(QString::fromUtf8("https://"), Qt::CaseInsensitive)) {
QBtSession::instance()->downloadFromUrl(param);
}else{

2
src/iconprovider.h

@ -36,7 +36,7 @@ @@ -36,7 +36,7 @@
class IconProvider
{
Q_DISABLE_COPY(IconProvider);
Q_DISABLE_COPY(IconProvider)
private:
explicit IconProvider();

4
src/mainwindow.cpp

@ -943,9 +943,9 @@ void MainWindow::on_actionOpen_triggered() { @@ -943,9 +943,9 @@ void MainWindow::on_actionOpen_triggered() {
QBtSession::instance()->addTorrent(pathsList.at(i));
}
// Save last dir to remember it
QStringList top_dir = pathsList.at(0).split(QDir::separator());
QStringList top_dir = fsutils::fromNativePath(pathsList.at(0)).split("/");
top_dir.removeLast();
settings.setValue(QString::fromUtf8("MainWindowLastDir"), top_dir.join(QDir::separator()));
settings.setValue(QString::fromUtf8("MainWindowLastDir"), fsutils::fromNativePath(top_dir.join("/")));
}
}

107
src/preferences/options_imp.cpp

@ -376,17 +376,9 @@ void options_imp::saveOptions() { @@ -376,17 +376,9 @@ void options_imp::saveOptions() {
// End General preferences
// Downloads preferences
QString save_path = getSavePath();
#if defined(Q_WS_WIN) || defined(Q_OS_OS2)
save_path.replace("\\", "/");
#endif
pref.setSavePath(save_path);
pref.setSavePath(getSavePath());
pref.setTempPathEnabled(isTempPathEnabled());
QString temp_path = getTempPath();
#if defined(Q_WS_WIN) || defined(Q_OS_OS2)
temp_path.replace("\\", "/");
#endif
pref.setTempPath(temp_path);
pref.setTempPath(getTempPath());
pref.setAppendTorrentLabel(checkAppendLabel->isChecked());
pref.useIncompleteFilesExtension(checkAppendqB->isChecked());
pref.preAllocateAllFiles(preAllocateAllFiles());
@ -395,14 +387,8 @@ void options_imp::saveOptions() { @@ -395,14 +387,8 @@ void options_imp::saveOptions() {
pref.addTorrentsInPause(addTorrentsInPause());
ScanFoldersModel::instance()->makePersistent();
addedScanDirs.clear();
QString export_dir = getTorrentExportDir();
QString export_dir_fin = getFinishedTorrentExportDir();
#if defined(Q_WS_WIN) || defined(Q_OS_OS2)
export_dir_fin.replace("\\", "/");
export_dir.replace("\\", "/");
#endif
pref.setTorrentExportDir(export_dir);
pref.setFinishedTorrentExportDir(export_dir_fin);
pref.setTorrentExportDir(getTorrentExportDir());
pref.setFinishedTorrentExportDir(getFinishedTorrentExportDir());
pref.setMailNotificationEnabled(groupMailNotification->isChecked());
pref.setMailNotificationEmail(dest_email_txt->text());
pref.setMailNotificationSMTP(smtp_server_txt->text());
@ -457,13 +443,8 @@ void options_imp::saveOptions() { @@ -457,13 +443,8 @@ void options_imp::saveOptions() {
// Misc preferences
// * IPFilter
pref.setFilteringEnabled(isFilteringEnabled());
if (isFilteringEnabled()) {
QString filter_path = textFilterPath->text();
#if defined(Q_WS_WIN) || defined(Q_OS_OS2)
filter_path.replace("\\", "/");
#endif
pref.setFilter(filter_path);
}
if (isFilteringEnabled())
pref.setFilter(textFilterPath->text());
// End IPFilter preferences
// Queueing system
pref.setQueueingSystemEnabled(isQueueingSystemEnabled());
@ -551,22 +532,14 @@ void options_imp::loadOptions() { @@ -551,22 +532,14 @@ void options_imp::loadOptions() {
#endif
// End General preferences
// Downloads preferences
QString save_path = pref.getSavePath();
#if defined(Q_WS_WIN) || defined(Q_OS_OS2)
save_path.replace("/", "\\");
#endif
textSavePath->setText(save_path);
textSavePath->setText(fsutils::toNativePath(pref.getSavePath()));
if (pref.isTempPathEnabled()) {
// enable
checkTempFolder->setChecked(true);
} else {
checkTempFolder->setChecked(false);
}
QString temp_path = pref.getTempPath();
#if defined(Q_WS_WIN) || defined(Q_OS_OS2)
temp_path.replace("/", "\\");
#endif
textTempPath->setText(temp_path);
textTempPath->setText(fsutils::toNativePath(pref.getTempPath()));
checkAppendLabel->setChecked(pref.appendTorrentLabel());
checkAppendqB->setChecked(pref.useIncompleteFilesExtension());
checkPreallocateAll->setChecked(pref.preAllocateAllFiles());
@ -574,29 +547,22 @@ void options_imp::loadOptions() { @@ -574,29 +547,22 @@ void options_imp::loadOptions() {
checkAdditionDialogFront->setChecked(pref.AdditionDialogFront());
checkStartPaused->setChecked(pref.addTorrentsInPause());
strValue = pref.getTorrentExportDir();
strValue = fsutils::toNativePath(pref.getTorrentExportDir());
if (strValue.isEmpty()) {
// Disable
checkExportDir->setChecked(false);
} else {
// enable
checkExportDir->setChecked(true);
#if defined(Q_WS_WIN) || defined(Q_OS_OS2)
strValue.replace("/", "\\");
#endif
textExportDir->setText(strValue);
}
strValue = pref.getFinishedTorrentExportDir();
strValue = fsutils::toNativePath(pref.getFinishedTorrentExportDir());
if (strValue.isEmpty()) {
// Disable
checkExportDirFin->setChecked(false);
} else {
// enable
checkExportDirFin->setChecked(true);
#if defined(Q_WS_WIN) || defined(Q_OS_OS2)
strValue.replace("/", "\\");
#endif
textExportDirFin->setText(strValue);
}
groupMailNotification->setChecked(pref.isMailNotificationEnabled());
@ -756,7 +722,7 @@ void options_imp::loadOptions() { @@ -756,7 +722,7 @@ void options_imp::loadOptions() {
// Misc preferences
// * IP Filter
checkIPFilter->setChecked(pref.isFilteringEnabled());
textFilterPath->setText(pref.getFilter());
textFilterPath->setText(fsutils::toNativePath(pref.getFilter()));
// End IP Filter
// Queueing system preferences
checkEnableQueueing->setChecked(pref.isQueueingSystemEnabled());
@ -875,16 +841,13 @@ qreal options_imp::getMaxRatio() const { @@ -875,16 +841,13 @@ qreal options_imp::getMaxRatio() const {
QString options_imp::getSavePath() const {
if (textSavePath->text().trimmed().isEmpty()) {
QString save_path = Preferences().getSavePath();
#if defined(Q_WS_WIN) || defined(Q_OS_OS2)
save_path.replace("/", "\\");
#endif
textSavePath->setText(save_path);
textSavePath->setText(fsutils::toNativePath(save_path));
}
return fsutils::expandPath(textSavePath->text());
return fsutils::expandPathAbs(textSavePath->text());
}
QString options_imp::getTempPath() const {
return fsutils::expandPath(textTempPath->text());
return fsutils::expandPathAbs(textTempPath->text());
}
bool options_imp::isTempPathEnabled() const {
@ -1068,13 +1031,13 @@ void options_imp::setLocale(const QString &localeStr) { @@ -1068,13 +1031,13 @@ void options_imp::setLocale(const QString &localeStr) {
QString options_imp::getTorrentExportDir() const {
if (checkExportDir->isChecked())
return fsutils::expandPath(textExportDir->text());
return fsutils::expandPathAbs(textExportDir->text());
return QString();
}
QString options_imp::getFinishedTorrentExportDir() const {
if (checkExportDirFin->isChecked())
return fsutils::expandPath(textExportDirFin->text());
return fsutils::expandPathAbs(textExportDirFin->text());
return QString();
}
@ -1133,7 +1096,7 @@ void options_imp::handleScanFolderViewSelectionChanged() { @@ -1133,7 +1096,7 @@ void options_imp::handleScanFolderViewSelectionChanged() {
QString options_imp::askForExportDir(const QString& currentExportPath)
{
QDir currentExportDir(fsutils::expandPath(currentExportPath));
QDir currentExportDir(fsutils::expandPathAbs(currentExportPath));
QString dir;
if (!currentExportPath.isEmpty() && currentExportDir.exists()) {
dir = QFileDialog::getExistingDirectory(this, tr("Choose export directory"), currentExportDir.absolutePath());
@ -1146,17 +1109,17 @@ QString options_imp::askForExportDir(const QString& currentExportPath) @@ -1146,17 +1109,17 @@ QString options_imp::askForExportDir(const QString& currentExportPath)
void options_imp::on_browseExportDirButton_clicked() {
const QString newExportDir = askForExportDir(textExportDir->text());
if (!newExportDir.isNull())
textExportDir->setText(fsutils::toDisplayPath(newExportDir));
textExportDir->setText(fsutils::toNativePath(newExportDir));
}
void options_imp::on_browseExportDirFinButton_clicked() {
const QString newExportDir = askForExportDir(textExportDirFin->text());
if (!newExportDir.isNull())
textExportDirFin->setText(fsutils::toDisplayPath(newExportDir));
textExportDirFin->setText(fsutils::toNativePath(newExportDir));
}
void options_imp::on_browseFilterButton_clicked() {
const QString filter_path = fsutils::expandPath(textFilterPath->text());
const QString filter_path = fsutils::expandPathAbs(textFilterPath->text());
QDir filterDir(filter_path);
QString ipfilter;
if (!filter_path.isEmpty() && filterDir.exists()) {
@ -1164,17 +1127,13 @@ void options_imp::on_browseFilterButton_clicked() { @@ -1164,17 +1127,13 @@ void options_imp::on_browseFilterButton_clicked() {
} else {
ipfilter = QFileDialog::getOpenFileName(this, tr("Choose an ip filter file"), QDir::homePath(), tr("Filters")+QString(" (*.dat *.p2p *.p2b)"));
}
if (!ipfilter.isNull()) {
#if defined(Q_WS_WIN) || defined(Q_OS_OS2)
ipfilter.replace("/", "\\");
#endif
textFilterPath->setText(ipfilter);
}
if (!ipfilter.isNull())
textFilterPath->setText(fsutils::toNativePath(ipfilter));
}
// Display dialog to choose save dir
void options_imp::on_browseSaveDirButton_clicked() {
const QString save_path = fsutils::expandPath(textSavePath->text());
const QString save_path = fsutils::expandPathAbs(textSavePath->text());
QDir saveDir(save_path);
QString dir;
if (!save_path.isEmpty() && saveDir.exists()) {
@ -1182,16 +1141,12 @@ void options_imp::on_browseSaveDirButton_clicked() { @@ -1182,16 +1141,12 @@ void options_imp::on_browseSaveDirButton_clicked() {
} else {
dir = QFileDialog::getExistingDirectory(this, tr("Choose a save directory"), QDir::homePath());
}
if (!dir.isNull()) {
#if defined(Q_WS_WIN) || defined(Q_OS_OS2)
dir.replace("/", "\\");
#endif
textSavePath->setText(dir);
}
if (!dir.isNull())
textSavePath->setText(fsutils::toNativePath(dir));
}
void options_imp::on_browseTempDirButton_clicked() {
const QString temp_path = fsutils::expandPath(textTempPath->text());
const QString temp_path = fsutils::expandPathAbs(textTempPath->text());
QDir tempDir(temp_path);
QString dir;
if (!temp_path.isEmpty() && tempDir.exists()) {
@ -1199,17 +1154,13 @@ void options_imp::on_browseTempDirButton_clicked() { @@ -1199,17 +1154,13 @@ void options_imp::on_browseTempDirButton_clicked() {
} else {
dir = QFileDialog::getExistingDirectory(this, tr("Choose a save directory"), QDir::homePath());
}
if (!dir.isNull()) {
#if defined(Q_WS_WIN) || defined(Q_OS_OS2)
dir.replace("/", "\\");
#endif
textTempPath->setText(dir);
}
if (!dir.isNull())
textTempPath->setText(fsutils::toNativePath(dir));
}
// Return Filter object to apply to BT session
QString options_imp::getFilter() const {
return textFilterPath->text();
return fsutils::fromNativePath(textFilterPath->text());
}
// Web UI

78
src/preferences/preferences.h

@ -204,7 +204,7 @@ public: @@ -204,7 +204,7 @@ public:
void setStartup(bool b) {
QSettings settings("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Run", QSettings::NativeFormat);
if (b) {
const QString bin_path = "\""+qApp->applicationFilePath().replace("/", "\\")+"\"";
const QString bin_path = "\""+qApp->applicationFilePath()+"\"";
settings.setValue("qBittorrent", bin_path);
}
else {
@ -217,12 +217,12 @@ public: @@ -217,12 +217,12 @@ public:
QString getSavePath() const {
QString save_path = value(QString::fromUtf8("Preferences/Downloads/SavePath")).toString();
if (!save_path.isEmpty())
return save_path;
return fsutils::fromNativePath(save_path);
return fsutils::QDesktopServicesDownloadLocation();
}
void setSavePath(const QString &save_path) {
setValue(QString::fromUtf8("Preferences/Downloads/SavePath"), save_path);
setValue(QString::fromUtf8("Preferences/Downloads/SavePath"), fsutils::fromNativePath(save_path));
}
bool isTempPathEnabled() const {
@ -235,11 +235,11 @@ public: @@ -235,11 +235,11 @@ public:
QString getTempPath() const {
const QString temp = QDir(getSavePath()).absoluteFilePath("temp");
return value(QString::fromUtf8("Preferences/Downloads/TempPath"), temp).toString();
return fsutils::fromNativePath(value(QString::fromUtf8("Preferences/Downloads/TempPath"), temp).toString());
}
void setTempPath(const QString &path) {
setValue(QString::fromUtf8("Preferences/Downloads/TempPath"), path);
setValue(QString::fromUtf8("Preferences/Downloads/TempPath"), fsutils::fromNativePath(path));
}
bool useIncompleteFilesExtension() const {
@ -259,11 +259,11 @@ public: @@ -259,11 +259,11 @@ public:
}
QString lastLocationPath() const {
return value(QString::fromUtf8("Preferences/Downloads/LastLocationPath"), QString()).toString();
return fsutils::fromNativePath(value(QString::fromUtf8("Preferences/Downloads/LastLocationPath"), QString()).toString());
}
void setLastLocationPath(const QString &path) {
setValue(QString::fromUtf8("Preferences/Downloads/LastLocationPath"), path);
setValue(QString::fromUtf8("Preferences/Downloads/LastLocationPath"), fsutils::fromNativePath(path));
}
bool preAllocateAllFiles() const {
@ -299,12 +299,26 @@ public: @@ -299,12 +299,26 @@ public:
}
QStringList getScanDirs() const {
return value(QString::fromUtf8("Preferences/Downloads/ScanDirs"), QStringList()).toStringList();
QStringList originalList = value(QString::fromUtf8("Preferences/Downloads/ScanDirs"), QStringList()).toStringList();
if (originalList.isEmpty())
return originalList;
QStringList newList;
foreach (const QString& s, originalList) {
newList << fsutils::fromNativePath(s);
}
return newList;
}
// This must be called somewhere with data from the model
void setScanDirs(const QStringList &dirs) {
setValue(QString::fromUtf8("Preferences/Downloads/ScanDirs"), dirs);
QStringList newList;
if (!dirs.isEmpty()) {
foreach (const QString& s, dirs) {
newList << fsutils::fromNativePath(s);
}
}
setValue(QString::fromUtf8("Preferences/Downloads/ScanDirs"), newList);
}
QList<bool> getDownloadInScanDirs() const {
@ -320,14 +334,11 @@ public: @@ -320,14 +334,11 @@ public:
}
QString getTorrentExportDir() const {
return value(QString::fromUtf8("Preferences/Downloads/TorrentExportDir"), QString()).toString();
return fsutils::fromNativePath(value(QString::fromUtf8("Preferences/Downloads/TorrentExportDir"), QString()).toString());
}
void setTorrentExportDir(QString path) {
path = path.trimmed();
if (path.isEmpty())
path = QString();
setValue(QString::fromUtf8("Preferences/Downloads/TorrentExportDir"), path);
setValue(QString::fromUtf8("Preferences/Downloads/TorrentExportDir"), fsutils::fromNativePath(path.trimmed()));
}
bool isFinishedTorrentExportEnabled() const {
@ -335,14 +346,11 @@ public: @@ -335,14 +346,11 @@ public:
}
QString getFinishedTorrentExportDir() const {
return value(QString::fromUtf8("Preferences/Downloads/FinishedTorrentExportDir"), QString()).toString();
return fsutils::fromNativePath(value(QString::fromUtf8("Preferences/Downloads/FinishedTorrentExportDir"), QString()).toString());
}
void setFinishedTorrentExportDir(QString path) {
path = path.trimmed();
if (path.isEmpty())
path = QString();
setValue(QString::fromUtf8("Preferences/Downloads/FinishedTorrentExportDir"), path);
setValue(QString::fromUtf8("Preferences/Downloads/FinishedTorrentExportDir"), fsutils::fromNativePath(path.trimmed()));
}
bool isMailNotificationEnabled() const {
@ -704,11 +712,11 @@ public: @@ -704,11 +712,11 @@ public:
}
QString getFilter() const {
return value(QString::fromUtf8("Preferences/IPFilter/File"), QString()).toString();
return fsutils::fromNativePath(value(QString::fromUtf8("Preferences/IPFilter/File"), QString()).toString());
}
void setFilter(const QString &path) {
setValue(QString::fromUtf8("Preferences/IPFilter/File"), path);
setValue(QString::fromUtf8("Preferences/IPFilter/File"), fsutils::fromNativePath(path));
}
void banIP(const QString &ip) {
@ -948,11 +956,11 @@ public: @@ -948,11 +956,11 @@ public:
}
void setAutoRunProgram(const QString &program) {
setValue("AutoRun/program", program);
setValue("AutoRun/program", fsutils::fromNativePath(program));
}
QString getAutoRunProgram() const {
return value("AutoRun/program", QString()).toString();
return fsutils::fromNativePath(value("AutoRun/program", QString()).toString());
}
bool shutdownWhenDownloadsComplete() const {
@ -1173,7 +1181,7 @@ public: @@ -1173,7 +1181,7 @@ public:
while(!versions.empty()) {
const QString version = versions.takeLast();
qDebug("Detected possible Python v%s location", qPrintable(version));
QString path = reg_python.value(version+"/InstallPath/Default", "").toString().replace("/", "\\");
QString path = reg_python.value(version+"/InstallPath/Default", "").toString();
if (!path.isEmpty() && QDir(path).exists("python.exe")) {
qDebug("Found python.exe at %s", qPrintable(path));
return path;
@ -1184,8 +1192,8 @@ public: @@ -1184,8 +1192,8 @@ public:
supported_versions << "32" << "31" << "30" << "27" << "26" << "25";
foreach (const QString &v, supported_versions) {
if (QFile::exists("C:/Python"+v+"/python.exe")) {
reg_python.setValue(v[0]+"."+v[1]+"/InstallPath/Default", QString("C:\\Python"+v));
return "C:\\Python"+v;
reg_python.setValue(v[0]+"."+v[1]+"/InstallPath/Default", QString("C:/Python"+v));
return "C:/Python"+v;
}
}
return QString::null;
@ -1206,17 +1214,17 @@ public: @@ -1206,17 +1214,17 @@ public:
return false;
}
qDebug("Checking shell command");
QString shell_command = settings.value("qBittorrent/shell/open/command/Default", "").toString();
QString shell_command = fsutils::toNativePath(settings.value("qBittorrent/shell/open/command/Default", "").toString());
qDebug("Shell command is: %s", qPrintable(shell_command));
QRegExp exe_reg("\"([^\"]+)\".*");
if (exe_reg.indexIn(shell_command) < 0)
return false;
QString assoc_exe = exe_reg.cap(1);
qDebug("exe: %s", qPrintable(assoc_exe));
if (assoc_exe.compare(qApp->applicationFilePath().replace("/", "\\"), Qt::CaseInsensitive) != 0)
if (assoc_exe.compare(fsutils::toNativePath(qApp->applicationFilePath()), Qt::CaseInsensitive) != 0)
return false;
// Icon
const QString icon_str = "\""+qApp->applicationFilePath().replace("/", "\\")+"\",1";
const QString icon_str = "\""+fsutils::toNativePath(qApp->applicationFilePath())+"\",1";
if (settings.value("qBittorrent/DefaultIcon/Default", icon_str).toString().compare(icon_str, Qt::CaseInsensitive) != 0)
return false;
@ -1228,12 +1236,12 @@ public: @@ -1228,12 +1236,12 @@ public:
// Check magnet link assoc
QRegExp exe_reg("\"([^\"]+)\".*");
QString shell_command = settings.value("Magnet/shell/open/command/Default", "").toString();
QString shell_command = fsutils::toNativePath(settings.value("Magnet/shell/open/command/Default", "").toString());
if (exe_reg.indexIn(shell_command) < 0)
return false;
QString assoc_exe = exe_reg.cap(1);
qDebug("exe: %s", qPrintable(assoc_exe));
if (assoc_exe.compare(qApp->applicationFilePath().replace("/", "\\"), Qt::CaseInsensitive) != 0)
if (assoc_exe.compare(fsutils::toNativePath(qApp->applicationFilePath()), Qt::CaseInsensitive) != 0)
return false;
return true;
}
@ -1243,8 +1251,8 @@ public: @@ -1243,8 +1251,8 @@ public:
// .Torrent association
if (set) {
const QString command_str = "\""+qApp->applicationFilePath().replace("/", "\\")+"\" \"%1\"";
const QString icon_str = "\""+qApp->applicationFilePath().replace("/", "\\")+"\",1";
const QString command_str = "\""+qApp->applicationFilePath()+"\" \"%1\"";
const QString icon_str = "\""+qApp->applicationFilePath()+"\",1";
settings.setValue(".torrent/Default", "qBittorrent");
settings.setValue(".torrent/Content Type", "application/x-bittorrent");
@ -1267,8 +1275,8 @@ public: @@ -1267,8 +1275,8 @@ public:
// Magnet association
if (set) {
const QString command_str = "\""+qApp->applicationFilePath().replace("/", "\\")+"\" \"%1\"";
const QString icon_str = "\""+qApp->applicationFilePath().replace("/", "\\")+"\",1";
const QString command_str = "\""+qApp->applicationFilePath()+"\" \"%1\"";
const QString icon_str = "\""+qApp->applicationFilePath()+"\",1";
settings.setValue("Magnet/Default", "Magnet URI");
settings.setValue("Magnet/Content Type", "application/x-magnet");

24
src/properties/propertieswidget.cpp

@ -220,7 +220,7 @@ QTorrentHandle PropertiesWidget::getCurrentTorrent() const { @@ -220,7 +220,7 @@ QTorrentHandle PropertiesWidget::getCurrentTorrent() const {
void PropertiesWidget::updateSavePath(const QTorrentHandle& _h) {
if (h.is_valid() && h == _h) {
save_path->setText(h.save_path_parsed());
save_path->setText(fsutils::toNativePath(h.save_path_parsed()));
}
}
@ -414,12 +414,14 @@ void PropertiesWidget::openDoubleClickedFile(QModelIndex index) { @@ -414,12 +414,14 @@ void PropertiesWidget::openDoubleClickedFile(QModelIndex index) {
int i = PropListModel->getFileIndex(index);
const QDir saveDir(h.save_path());
const QString filename = h.filepath_at(i);
const QString file_path = QDir::cleanPath(saveDir.absoluteFilePath(filename));
const QString file_path = fsutils::expandPath(saveDir.absoluteFilePath(filename));
qDebug("Trying to open file at %s", qPrintable(file_path));
// Flush data
h.flush_cache();
if (QFile::exists(file_path)) {
QDesktopServices::openUrl(QUrl::fromLocalFile(file_path));
// Hack to access samba shares with QDesktopServices::openUrl
const QString p = file_path.startsWith("//") ? QString("file:") + file_path : file_path;
QDesktopServices::openUrl(QUrl::fromLocalFile(p));
} else {
QMessageBox::warning(this, tr("I/O Error"), tr("This file does not exist yet."));
}
@ -433,13 +435,15 @@ void PropertiesWidget::openDoubleClickedFile(QModelIndex index) { @@ -433,13 +435,15 @@ void PropertiesWidget::openDoubleClickedFile(QModelIndex index) {
parent = PropListModel->parent(parent);
}
const QDir saveDir(h.save_path());
const QString filename = path_items.join(QDir::separator());
const QString file_path = QDir::cleanPath(saveDir.absoluteFilePath(filename));
const QString filename = path_items.join("/");
const QString file_path = fsutils::expandPath(saveDir.absoluteFilePath(filename));
qDebug("Trying to open folder at %s", qPrintable(file_path));
// Flush data
h.flush_cache();
if (QFile::exists(file_path)) {
QDesktopServices::openUrl(QUrl::fromLocalFile(file_path));
// Hack to access samba shares with QDesktopServices::openUrl
const QString p = file_path.startsWith("//") ? QString("file:") + file_path : file_path;
QDesktopServices::openUrl(QUrl::fromLocalFile(p));
} else {
QMessageBox::warning(this, tr("I/O Error"), tr("This folder does not exist yet."));
}
@ -541,7 +545,7 @@ void PropertiesWidget::renameSelectedFile() { @@ -541,7 +545,7 @@ void PropertiesWidget::renameSelectedFile() {
// File renaming
const int file_index = PropListModel->getFileIndex(index);
if (!h.is_valid() || !h.has_metadata()) return;
QString old_name = h.filepath_at(file_index).replace("\\", "/");
QString old_name = h.filepath_at(file_index);
if (old_name.endsWith(".!qB") && !new_name_last.endsWith(".!qB")) {
new_name_last += ".!qB";
}
@ -553,7 +557,7 @@ void PropertiesWidget::renameSelectedFile() { @@ -553,7 +557,7 @@ void PropertiesWidget::renameSelectedFile() {
qDebug("Name did not change");
return;
}
new_name = QDir::cleanPath(new_name);
new_name = fsutils::expandPathAbs(new_name);
// Check if that name is already used
for (int i=0; i<h.num_files(); ++i) {
if (i == file_index) continue;
@ -569,7 +573,7 @@ void PropertiesWidget::renameSelectedFile() { @@ -569,7 +573,7 @@ void PropertiesWidget::renameSelectedFile() {
return;
}
}
const bool force_recheck = QFile::exists(h.save_path()+QDir::separator()+new_name);
const bool force_recheck = QFile::exists(h.save_path()+"/"+new_name);
qDebug("Renaming %s to %s", qPrintable(old_name), qPrintable(new_name));
h.rename_file(file_index, new_name);
// Force recheck
@ -616,7 +620,7 @@ void PropertiesWidget::renameSelectedFile() { @@ -616,7 +620,7 @@ void PropertiesWidget::renameSelectedFile() {
new_name.replace(0, old_path.length(), new_path);
if (!force_recheck && QDir(h.save_path()).exists(new_name))
force_recheck = true;
new_name = QDir::cleanPath(new_name);
new_name = fsutils::expandPathAbs(new_name);
qDebug("Rename %s to %s", qPrintable(current_name), qPrintable(new_name));
h.rename_file(i, new_name);
}

2
src/qinisettings.h

@ -63,7 +63,7 @@ public: @@ -63,7 +63,7 @@ public:
void setValue(const QString &key, const QVariant &val) {
QString key_tmp(key);
if (format() == QSettings::NativeFormat)
if (format() == QSettings::NativeFormat) // Using registry, don't touch replace here
key_tmp.replace("\\", "/");
QSettings::setValue(key_tmp, val);
}

118
src/qtlibtorrent/qbtsession.cpp

@ -947,14 +947,14 @@ QTorrentHandle QBtSession::addMagnetUri(QString magnet_uri, bool resumed, bool f @@ -947,14 +947,14 @@ QTorrentHandle QBtSession::addMagnetUri(QString magnet_uri, bool resumed, bool f
savePath = getSavePath(hash, false);
if (!defaultTempPath.isEmpty() && !TorrentPersistentData::isSeed(hash)) {
qDebug("addMagnetURI: Temp folder is enabled.");
QString torrent_tmp_path = defaultTempPath.replace("\\", "/");
p.save_path = torrent_tmp_path.toUtf8().constData();
QString torrent_tmp_path = defaultTempPath;
p.save_path = fsutils::toNativePath(torrent_tmp_path).toUtf8().constData();
// Check if save path exists, creating it otherwise
if (!QDir(torrent_tmp_path).exists())
QDir().mkpath(torrent_tmp_path);
qDebug("addTorrent: using save_path: %s", qPrintable(torrent_tmp_path));
} else {
p.save_path = savePath.toUtf8().constData();
p.save_path = fsutils::toNativePath(savePath).toUtf8().constData();
// Check if save path exists, creating it otherwise
if (!QDir(savePath).exists()) QDir().mkpath(savePath);
qDebug("addTorrent: using save_path: %s", qPrintable(savePath));
@ -1020,6 +1020,7 @@ QTorrentHandle QBtSession::addTorrent(QString path, bool fromScanDir, QString fr @@ -1020,6 +1020,7 @@ QTorrentHandle QBtSession::addTorrent(QString path, bool fromScanDir, QString fr
if (!torrentBackup.exists()) return h;
// Fix the input path if necessary
path = fsutils::fromNativePath(path);
#ifdef Q_WS_WIN
// Windows hack
if (!path.endsWith(".torrent"))
@ -1036,7 +1037,7 @@ QTorrentHandle QBtSession::addTorrent(QString path, bool fromScanDir, QString fr @@ -1036,7 +1037,7 @@ QTorrentHandle QBtSession::addTorrent(QString path, bool fromScanDir, QString fr
try {
qDebug() << "Loading torrent at" << path;
// Getting torrent file informations
t = new torrent_info(path.toUtf8().constData());
t = new torrent_info(fsutils::toNativePath(path).toUtf8().constData());
if (!t->is_valid())
throw std::exception();
} catch(std::exception& e) {
@ -1046,13 +1047,7 @@ QTorrentHandle QBtSession::addTorrent(QString path, bool fromScanDir, QString fr @@ -1046,13 +1047,7 @@ QTorrentHandle QBtSession::addTorrent(QString path, bool fromScanDir, QString fr
//emit invalidTorrent(from_url);
fsutils::forceRemove(path);
}else{
#if defined(Q_WS_WIN) || defined(Q_OS_OS2)
QString displayed_path = path;
displayed_path.replace("/", "\\");
addConsoleMessage(tr("Unable to decode torrent file: '%1'", "e.g: Unable to decode torrent file: '/home/y/xxx.torrent'").arg(displayed_path), QString::fromUtf8("red"));
#else
addConsoleMessage(tr("Unable to decode torrent file: '%1'", "e.g: Unable to decode torrent file: '/home/y/xxx.torrent'").arg(path), QString::fromUtf8("red"));
#endif
addConsoleMessage(tr("Unable to decode torrent file: '%1'", "e.g: Unable to decode torrent file: '/home/y/xxx.torrent'").arg(fsutils::toNativePath(path)), QString::fromUtf8("red"));
//emit invalidTorrent(path);
}
addConsoleMessage(tr("This file is either corrupted or this isn't a torrent."),QString::fromUtf8("red"));
@ -1075,13 +1070,7 @@ QTorrentHandle QBtSession::addTorrent(QString path, bool fromScanDir, QString fr @@ -1075,13 +1070,7 @@ QTorrentHandle QBtSession::addTorrent(QString path, bool fromScanDir, QString fr
if (!from_url.isNull()) {
addConsoleMessage(tr("'%1' is already in download list.", "e.g: 'xxx.avi' is already in download list.").arg(from_url));
}else{
#if defined(Q_WS_WIN) || defined(Q_OS_OS2)
QString displayed_path = path;
displayed_path.replace("/", "\\");
addConsoleMessage(tr("'%1' is already in download list.", "e.g: 'xxx.avi' is already in download list.").arg(displayed_path));
#else
addConsoleMessage(tr("'%1' is already in download list.", "e.g: 'xxx.avi' is already in download list.").arg(path));
#endif
addConsoleMessage(tr("'%1' is already in download list.", "e.g: 'xxx.avi' is already in download list.").arg(fsutils::toNativePath(path)));
}
// Check if the torrent contains trackers or url seeds we don't know about
// and add them
@ -1139,13 +1128,13 @@ QTorrentHandle QBtSession::addTorrent(QString path, bool fromScanDir, QString fr @@ -1139,13 +1128,13 @@ QTorrentHandle QBtSession::addTorrent(QString path, bool fromScanDir, QString fr
}
if (!defaultTempPath.isEmpty() && !TorrentPersistentData::isSeed(hash)) {
qDebug("addTorrent::Temp folder is enabled.");
QString torrent_tmp_path = defaultTempPath.replace("\\", "/");
p.save_path = torrent_tmp_path.toUtf8().constData();
QString torrent_tmp_path = defaultTempPath;
p.save_path = fsutils::toNativePath(torrent_tmp_path).toUtf8().constData();
// Check if save path exists, creating it otherwise
if (!QDir(torrent_tmp_path).exists()) QDir().mkpath(torrent_tmp_path);
qDebug("addTorrent: using save_path: %s", qPrintable(torrent_tmp_path));
} else {
p.save_path = savePath.toUtf8().constData();
p.save_path = fsutils::toNativePath(savePath).toUtf8().constData();
// Check if save path exists, creating it otherwise
if (!QDir(savePath).exists()) QDir().mkpath(savePath);
qDebug("addTorrent: using save_path: %s", qPrintable(savePath));
@ -1201,9 +1190,9 @@ QTorrentHandle QBtSession::addTorrent(QString path, bool fromScanDir, QString fr @@ -1201,9 +1190,9 @@ QTorrentHandle QBtSession::addTorrent(QString path, bool fromScanDir, QString fr
addConsoleMessage(tr("'%1' added to download list.", "'/home/y/xxx.torrent' was added to download list.").arg(from_url));
}else{
if (fastResume)
addConsoleMessage(tr("'%1' resumed. (fast resume)", "'/home/y/xxx.torrent' was resumed. (fast resume)").arg(fsutils::toDisplayPath(path)));
addConsoleMessage(tr("'%1' resumed. (fast resume)", "'/home/y/xxx.torrent' was resumed. (fast resume)").arg(fsutils::toNativePath(path)));
else
addConsoleMessage(tr("'%1' added to download list.", "'/home/y/xxx.torrent' was added to download list.").arg(fsutils::toDisplayPath(path)));
addConsoleMessage(tr("'%1' added to download list.", "'/home/y/xxx.torrent' was added to download list.").arg(fsutils::toNativePath(path)));
}
// Send torrent addition signal
@ -1299,7 +1288,7 @@ void QBtSession::loadTorrentTempData(QTorrentHandle &h, QString savePath, bool m @@ -1299,7 +1288,7 @@ void QBtSession::loadTorrentTempData(QTorrentHandle &h, QString savePath, bool m
if (defaultTempPath.isEmpty())
TorrentPersistentData::saveTorrentPersistentData(h, QString::null, magnet);
else
TorrentPersistentData::saveTorrentPersistentData(h, savePath, magnet);
TorrentPersistentData::saveTorrentPersistentData(h, fsutils::fromNativePath(savePath), magnet);
}
void QBtSession::mergeTorrents(QTorrentHandle& h_ex, const QString& magnet_uri)
@ -1490,7 +1479,7 @@ void QBtSession::enableLSD(bool b) { @@ -1490,7 +1479,7 @@ void QBtSession::enableLSD(bool b) {
}
void QBtSession::loadSessionState() {
const QString state_path = fsutils::cacheLocation()+QDir::separator()+QString::fromUtf8("ses_state");
const QString state_path = fsutils::cacheLocation()+"/"+QString::fromUtf8("ses_state");
if (!QFile::exists(state_path)) return;
if (QFile(state_path).size() == 0) {
// Remove empty invalid state file
@ -1514,7 +1503,7 @@ void QBtSession::loadSessionState() { @@ -1514,7 +1503,7 @@ void QBtSession::loadSessionState() {
void QBtSession::saveSessionState() {
qDebug("Saving session state to disk...");
const QString state_path = fsutils::cacheLocation()+QDir::separator()+QString::fromUtf8("ses_state");
const QString state_path = fsutils::cacheLocation()+"/"+QString::fromUtf8("ses_state");
entry session_state;
s->save_state(session_state);
vector<char> out;
@ -1739,7 +1728,7 @@ void QBtSession::addTorrentsFromScanFolder(QStringList &pathList) { @@ -1739,7 +1728,7 @@ void QBtSession::addTorrentsFromScanFolder(QStringList &pathList) {
continue;
}
try {
torrent_info t(file.toUtf8().constData());
torrent_info t(fsutils::toNativePath(file).toUtf8().constData());
if (t.is_valid())
addTorrent(file, true);
} catch(std::exception&) {
@ -1752,7 +1741,7 @@ void QBtSession::setDefaultSavePath(const QString &savepath) { @@ -1752,7 +1741,7 @@ void QBtSession::setDefaultSavePath(const QString &savepath) {
if (savepath.isEmpty())
return;
defaultSavePath = QDir::fromNativeSeparators(savepath);
defaultSavePath = fsutils::fromNativePath(savepath);
}
void QBtSession::setDefaultTempPath(const QString &temppath) {
@ -1782,13 +1771,12 @@ void QBtSession::setDefaultTempPath(const QString &temppath) { @@ -1782,13 +1771,12 @@ void QBtSession::setDefaultTempPath(const QString &temppath) {
QTorrentHandle h = QTorrentHandle(*torrentIT);
if (!h.is_valid()) continue;
if (!h.is_seed()) {
QString torrent_tmp_path = QDir::fromNativeSeparators(temppath);
qDebug("Moving torrent to its temp save path: %s", qPrintable(fsutils::toDisplayPath(torrent_tmp_path)));
h.move_storage(torrent_tmp_path);
qDebug("Moving torrent to its temp save path: %s", qPrintable(temppath));
h.move_storage(temppath);
}
}
}
defaultTempPath = QDir::fromNativeSeparators(temppath);
defaultTempPath = fsutils::fromNativePath(temppath);
}
void QBtSession::appendqBextensionToTorrent(const QTorrentHandle &h, bool append) {
@ -1821,7 +1809,7 @@ void QBtSession::appendqBextensionToTorrent(const QTorrentHandle &h, bool append @@ -1821,7 +1809,7 @@ void QBtSession::appendqBextensionToTorrent(const QTorrentHandle &h, bool append
void QBtSession::changeLabelInTorrentSavePath(const QTorrentHandle &h, QString old_label, QString new_label) {
if (!h.is_valid()) return;
if (!appendLabelToSavePath) return;
QString old_save_path = TorrentPersistentData::getSavePath(h.hash());
QString old_save_path = fsutils::fromNativePath(TorrentPersistentData::getSavePath(h.hash()));
if (!old_save_path.startsWith(defaultSavePath)) return;
QString new_save_path = fsutils::updateLabelInSavePath(defaultSavePath, old_save_path, old_label, new_label);
if (new_save_path != old_save_path) {
@ -1837,7 +1825,7 @@ void QBtSession::appendLabelToTorrentSavePath(const QTorrentHandle& h) { @@ -1837,7 +1825,7 @@ void QBtSession::appendLabelToTorrentSavePath(const QTorrentHandle& h) {
const QString label = TorrentPersistentData::getLabel(h.hash());
if (label.isEmpty()) return;
// Current save path
QString old_save_path = TorrentPersistentData::getSavePath(h.hash());
QString old_save_path = fsutils::fromNativePath(TorrentPersistentData::getSavePath(h.hash()));
QString new_save_path = fsutils::updateLabelInSavePath(defaultSavePath, old_save_path, "", label);
if (old_save_path != new_save_path) {
// Move storage
@ -2005,9 +1993,9 @@ void QBtSession::enableIPFilter(const QString &filter_path, bool force) { @@ -2005,9 +1993,9 @@ void QBtSession::enableIPFilter(const QString &filter_path, bool force) {
connect(filterParser.data(), SIGNAL(IPFilterParsed(int)), SLOT(handleIPFilterParsed(int)));
connect(filterParser.data(), SIGNAL(IPFilterError()), SLOT(handleIPFilterError()));
}
if (filterPath.isEmpty() || filterPath != filter_path || force) {
filterPath = filter_path;
filterParser->processFilterFile(filter_path);
if (filterPath.isEmpty() || filterPath != fsutils::fromNativePath(filter_path) || force) {
filterPath = fsutils::fromNativePath(filter_path);
filterParser->processFilterFile(fsutils::fromNativePath(filter_path));
}
}
@ -2069,16 +2057,10 @@ void QBtSession::recursiveTorrentDownload(const QTorrentHandle &h) { @@ -2069,16 +2057,10 @@ void QBtSession::recursiveTorrentDownload(const QTorrentHandle &h) {
for (int i=0; i<h.num_files(); ++i) {
const QString torrent_relpath = h.filepath_at(i);
if (torrent_relpath.endsWith(".torrent")) {
#if defined(Q_WS_WIN) || defined(Q_OS_OS2)
QString displayed_relpath = torrent_relpath;
displayed_relpath.replace("/", "\\");
addConsoleMessage(tr("Recursive download of file %1 embedded in torrent %2", "Recursive download of test.torrent embedded in torrent test2").arg(displayed_relpath).arg(h.name()));
#else
addConsoleMessage(tr("Recursive download of file %1 embedded in torrent %2", "Recursive download of test.torrent embedded in torrent test2").arg(torrent_relpath).arg(h.name()));
#endif
const QString torrent_fullpath = h.save_path()+QDir::separator()+torrent_relpath;
addConsoleMessage(tr("Recursive download of file %1 embedded in torrent %2", "Recursive download of test.torrent embedded in torrent test2").arg(fsutils::toNativePath(torrent_relpath)).arg(h.name()));
const QString torrent_fullpath = h.save_path()+"/"+torrent_relpath;
boost::intrusive_ptr<torrent_info> t = new torrent_info(torrent_fullpath.toUtf8().constData());
boost::intrusive_ptr<torrent_info> t = new torrent_info(fsutils::toNativePath(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());
@ -2151,14 +2133,14 @@ void QBtSession::readAlerts() { @@ -2151,14 +2133,14 @@ void QBtSession::readAlerts() {
qDebug("Checking if the torrent contains torrent files to download");
// Check if there are torrent files inside
for (int i=0; i<h.num_files(); ++i) {
const QString torrent_relpath = h.filepath_at(i).replace("\\", "/");
const QString torrent_relpath = h.filepath_at(i);
qDebug() << "File path:" << torrent_relpath;
if (torrent_relpath.endsWith(".torrent", Qt::CaseInsensitive)) {
qDebug("Found possible recursive torrent download.");
const QString torrent_fullpath = h.save_path()+"/"+torrent_relpath;
qDebug("Full subtorrent path is %s", qPrintable(torrent_fullpath));
try {
boost::intrusive_ptr<torrent_info> t = new torrent_info(torrent_fullpath.toUtf8().constData());
boost::intrusive_ptr<torrent_info> t = new torrent_info(fsutils::toNativePath(torrent_fullpath).toUtf8().constData());
if (t->is_valid()) {
qDebug("emitting recursiveTorrentDownloadPossible()");
emit recursiveTorrentDownloadPossible(h);
@ -2166,13 +2148,7 @@ void QBtSession::readAlerts() { @@ -2166,13 +2148,7 @@ void QBtSession::readAlerts() {
}
} catch(std::exception&) {
qDebug("Caught error loading torrent");
#if defined(Q_WS_WIN) || defined(Q_OS_OS2)
QString displayed_path = torrent_fullpath;
displayed_path.replace("/", "\\");
addConsoleMessage(tr("Unable to decode %1 torrent file.").arg(displayed_path), QString::fromUtf8("red"));
#else
addConsoleMessage(tr("Unable to decode %1 torrent file.").arg(torrent_fullpath), QString::fromUtf8("red"));
#endif
addConsoleMessage(tr("Unable to decode %1 torrent file.").arg(fsutils::toNativePath(torrent_fullpath)), QString::fromUtf8("red"));
}
}
}
@ -2276,7 +2252,7 @@ void QBtSession::readAlerts() { @@ -2276,7 +2252,7 @@ void QBtSession::readAlerts() {
QStringList old_path_parts = h.orig_filepath_at(p->index).split("/");
old_path_parts.removeLast();
QString old_path = old_path_parts.join("/");
QStringList new_path_parts = misc::toQStringU(p->name).split("/");
QStringList new_path_parts = fsutils::fromNativePath(misc::toQStringU(p->name)).split("/");
new_path_parts.removeLast();
if (!new_path_parts.isEmpty() && old_path != new_path_parts.join("/")) {
qDebug("Old_path(%s) != new_path(%s)", qPrintable(old_path), qPrintable(new_path_parts.join("/")));
@ -2317,8 +2293,8 @@ void QBtSession::readAlerts() { @@ -2317,8 +2293,8 @@ void QBtSession::readAlerts() {
QTorrentHandle h(p->handle);
if (h.is_valid()) {
// Attempt to remove old folder if empty
const QString old_save_path = TorrentPersistentData::getPreviousPath(h.hash());
const QString new_save_path = misc::toQStringU(p->path.c_str());
const QString old_save_path = fsutils::fromNativePath(TorrentPersistentData::getPreviousPath(h.hash()));
const QString new_save_path = fsutils::fromNativePath(misc::toQStringU(p->path.c_str()));
qDebug("Torrent moved from %s to %s", qPrintable(old_save_path), qPrintable(new_save_path));
QDir old_save_dir(old_save_path);
if (old_save_dir != QDir(defaultSavePath) && old_save_dir != QDir(defaultTempPath)) {
@ -2564,7 +2540,7 @@ void QBtSession::readAlerts() { @@ -2564,7 +2540,7 @@ void QBtSession::readAlerts() {
const QDir save_dir(getSavePath(h.hash()));
if (current_dir == save_dir) {
qDebug("Moving the torrent to the temp directory...");
QString torrent_tmp_path = defaultTempPath.replace("\\", "/");
QString torrent_tmp_path = defaultTempPath;
h.move_storage(torrent_tmp_path);
}
}
@ -2617,7 +2593,7 @@ session_status QBtSession::getSessionStatus() const { @@ -2617,7 +2593,7 @@ session_status QBtSession::getSessionStatus() const {
QString QBtSession::getSavePath(const QString &hash, bool fromScanDir, QString filePath) {
QString savePath;
if (TorrentTempData::hasTempData(hash)) {
savePath = TorrentTempData::getSavePath(hash);
savePath = fsutils::fromNativePath(TorrentTempData::getSavePath(hash));
if (savePath.isEmpty()) {
savePath = defaultSavePath;
}
@ -2630,7 +2606,7 @@ QString QBtSession::getSavePath(const QString &hash, bool fromScanDir, QString f @@ -2630,7 +2606,7 @@ QString QBtSession::getSavePath(const QString &hash, bool fromScanDir, QString f
}
qDebug("getSavePath, got save_path from temp data: %s", qPrintable(savePath));
} else {
savePath = TorrentPersistentData::getSavePath(hash);
savePath = fsutils::fromNativePath(TorrentPersistentData::getSavePath(hash));
qDebug("SavePath got from persistant data is %s", qPrintable(savePath));
if (savePath.isEmpty()) {
if (fromScanDir && m_scanFolders->downloadInTorrentFolder(filePath)) {
@ -2649,8 +2625,7 @@ QString QBtSession::getSavePath(const QString &hash, bool fromScanDir, QString f @@ -2649,8 +2625,7 @@ QString QBtSession::getSavePath(const QString &hash, bool fromScanDir, QString f
qDebug("getSavePath, got save_path from persistent data: %s", qPrintable(savePath));
}
// Clean path
savePath.replace("\\", "/");
savePath = fsutils::expandPath(savePath);
savePath = fsutils::expandPathAbs(savePath);
if (!savePath.endsWith("/"))
savePath += "/";
return savePath;
@ -2684,7 +2659,7 @@ void QBtSession::addMagnetInteractive(const QString& uri) @@ -2684,7 +2659,7 @@ void QBtSession::addMagnetInteractive(const QString& uri)
void QBtSession::addMagnetSkipAddDlg(const QString& uri, const QString& save_path, const QString& label) {
if (!save_path.isEmpty() || !label.isEmpty())
savepathLabel_fromurl[uri] = qMakePair(save_path, label);
savepathLabel_fromurl[uri] = qMakePair(fsutils::fromNativePath(save_path), label);
addMagnetUri(uri, false);
emit newDownloadedTorrentFromRss(uri);
}
@ -2693,7 +2668,7 @@ void QBtSession::downloadUrlAndSkipDialog(QString url, QString save_path, QStrin @@ -2693,7 +2668,7 @@ void QBtSession::downloadUrlAndSkipDialog(QString url, QString save_path, QStrin
//emit aboutToDownloadFromUrl(url);
const QUrl qurl = QUrl::fromEncoded(url.toUtf8());
if (!save_path.isEmpty() || !label.isEmpty())
savepathLabel_fromurl[qurl] = qMakePair(save_path, label);
savepathLabel_fromurl[qurl] = qMakePair(fsutils::fromNativePath(save_path), label);
url_skippingDlg << qurl;
// Launch downloader thread
downloader->downloadTorrentUrl(url, cookies);
@ -2705,6 +2680,7 @@ void QBtSession::processDownloadedFile(QString url, QString file_path) { @@ -2705,6 +2680,7 @@ void QBtSession::processDownloadedFile(QString url, QString file_path) {
const int index = url_skippingDlg.indexOf(QUrl::fromEncoded(url.toUtf8()));
if (index < 0) {
// Add file to torrent download list
file_path = fsutils::fromNativePath(file_path);
#ifdef Q_WS_WIN
// Windows hack
if (!file_path.endsWith(".torrent", Qt::CaseInsensitive)) {
@ -2766,7 +2742,7 @@ void QBtSession::startUpTorrents() { @@ -2766,7 +2742,7 @@ void QBtSession::startUpTorrents() {
if (!known_torrents.contains(hash)) {
qDebug("found torrent with hash: %s on hard disk", qPrintable(hash));
std::cerr << "ERROR Detected!!! Adding back torrent " << qPrintable(hash) << " which got lost for some reason." << std::endl;
addTorrent(torrentBackup.path()+QDir::separator()+hash+".torrent", false, QString(), true);
addTorrent(torrentBackup.path()+"/"+hash+".torrent", false, QString(), true);
}
}
// End of safety measure
@ -2787,7 +2763,7 @@ void QBtSession::startUpTorrents() { @@ -2787,7 +2763,7 @@ void QBtSession::startUpTorrents() {
if (TorrentPersistentData::isMagnet(hash)) {
addMagnetUri(TorrentPersistentData::getMagnetUri(hash), true);
} else {
addTorrent(torrentBackup.path()+QDir::separator()+hash+".torrent", false, QString(), true);
addTorrent(torrentBackup.path()+"/"+hash+".torrent", false, QString(), true);
}
}
} else {
@ -2797,7 +2773,7 @@ void QBtSession::startUpTorrents() { @@ -2797,7 +2773,7 @@ void QBtSession::startUpTorrents() {
if (TorrentPersistentData::isMagnet(hash))
addMagnetUri(TorrentPersistentData::getMagnetUri(hash), true);
else
addTorrent(torrentBackup.path()+QDir::separator()+hash+".torrent", false, QString(), true);
addTorrent(torrentBackup.path()+"/"+hash+".torrent", false, QString(), true);
}
}
QIniSettings settings;
@ -2857,7 +2833,7 @@ void QBtSession::recoverPersistentData(const QString &hash, const std::vector<ch @@ -2857,7 +2833,7 @@ void QBtSession::recoverPersistentData(const QString &hash, const std::vector<ch
if (fast.type() != libtorrent::lazy_entry::dict_t && !ec)
return;
QString savePath = QString::fromUtf8(fast.dict_find_string_value("qBt-savePath").c_str());
QString savePath = fsutils::fromNativePath(QString::fromUtf8(fast.dict_find_string_value("qBt-savePath").c_str()));
qreal ratioLimit = QString::fromUtf8(fast.dict_find_string_value("qBt-ratioLimit").c_str()).toDouble();
QDateTime addedDate = QDateTime::fromTime_t(fast.dict_find_int_value("added_time"));
QString previousSavePath = QString::fromUtf8(fast.dict_find_string_value("qBt-previousSavePath").c_str());
@ -2877,9 +2853,9 @@ void QBtSession::recoverPersistentData(const QString &hash, const std::vector<ch @@ -2877,9 +2853,9 @@ void QBtSession::recoverPersistentData(const QString &hash, const std::vector<ch
}
void QBtSession::backupPersistentData(const QString &hash, boost::shared_ptr<libtorrent::entry> data) {
(*data)["qBt-savePath"] = TorrentPersistentData::getSavePath(hash).toUtf8().constData();
(*data)["qBt-savePath"] = fsutils::fromNativePath(TorrentPersistentData::getSavePath(hash)).toUtf8().constData();
(*data)["qBt-ratioLimit"] = QString::number(TorrentPersistentData::getRatioLimit(hash)).toUtf8().constData();
(*data)["qBt-previousSavePath"] = TorrentPersistentData::getPreviousPath(hash).toUtf8().constData();
(*data)["qBt-previousSavePath"] = fsutils::fromNativePath(TorrentPersistentData::getPreviousPath(hash)).toUtf8().constData();
(*data)["qBt-seedDate"] = TorrentPersistentData::getSeedDate(hash).toTime_t();
(*data)["qBt-label"] = TorrentPersistentData::getLabel(hash).toUtf8().constData();
(*data)["qBt-queuePosition"] = TorrentPersistentData::getPriority(hash);

39
src/qtlibtorrent/qtorrenthandle.cpp

@ -223,11 +223,9 @@ int QTorrentHandle::num_incomplete() const { @@ -223,11 +223,9 @@ int QTorrentHandle::num_incomplete() const {
QString QTorrentHandle::save_path() const {
#if LIBTORRENT_VERSION_NUM < 10000
return misc::toQStringU(torrent_handle::save_path())
.replace("\\", "/");
return fsutils::fromNativePath(misc::toQStringU(torrent_handle::save_path()));
#else
return misc::toQStringU(status(torrent_handle::query_save_path).save_path)
.replace("\\", "/");
return fsutils::fromNativePath(misc::toQStringU(status(torrent_handle::query_save_path).save_path));
#endif
}
@ -236,13 +234,10 @@ QString QTorrentHandle::save_path_parsed() const { @@ -236,13 +234,10 @@ QString QTorrentHandle::save_path_parsed() const {
if (has_metadata() && num_files() == 1) {
p = firstFileSavePath();
} else {
p = TorrentPersistentData::getSavePath(hash());
p = fsutils::fromNativePath(TorrentPersistentData::getSavePath(hash()));
if (p.isEmpty())
p = save_path();
}
#if defined(Q_WS_WIN) || defined(Q_OS_OS2)
p.replace("/", "\\");
#endif
return p;
}
@ -306,18 +301,19 @@ size_type QTorrentHandle::filesize_at(unsigned int index) const { @@ -306,18 +301,19 @@ size_type QTorrentHandle::filesize_at(unsigned int index) const {
QString QTorrentHandle::filepath_at(unsigned int index) const {
#if LIBTORRENT_VERSION_NUM < 10000
return misc::toQStringU(torrent_handle::get_torrent_info().files().file_path(index));
return fsutils::fromNativePath(misc::toQStringU(torrent_handle::get_torrent_info().files().file_path(index)));
#else
return misc::toQStringU(torrent_handle::torrent_file()->files().file_path(index));
return fsutils::fromNativePath(misc::toQStringU(torrent_handle::torrent_file()->files().file_path(index)));
#endif
}
QString QTorrentHandle::orig_filepath_at(unsigned int index) const {
#if LIBTORRENT_VERSION_NUM < 10000
return misc::toQStringU(torrent_handle::get_torrent_info().orig_files().file_path(index));
return fsutils::fromNativePath(misc::toQStringU(torrent_handle::get_torrent_info().orig_files().file_path(index)));
#else
return misc::toQStringU(torrent_handle::torrent_file()->orig_files().file_path(index));
return fsutils::fromNativePath(misc::toQStringU(torrent_handle::torrent_file()->orig_files().file_path(index)));
#endif
}
torrent_status::state_t QTorrentHandle::state() const {
@ -379,7 +375,7 @@ QStringList QTorrentHandle::absolute_files_path() const { @@ -379,7 +375,7 @@ QStringList QTorrentHandle::absolute_files_path() const {
QDir saveDir(save_path());
QStringList res;
for (int i = 0; i<num_files(); ++i) {
res << QDir::cleanPath(saveDir.absoluteFilePath(filepath_at(i)));
res << fsutils::expandPathAbs(saveDir.absoluteFilePath(filepath_at(i)));
}
return res;
}
@ -390,7 +386,7 @@ QStringList QTorrentHandle::absolute_files_path_uneeded() const { @@ -390,7 +386,7 @@ QStringList QTorrentHandle::absolute_files_path_uneeded() const {
std::vector<int> fp = torrent_handle::file_priorities();
for (uint i = 0; i < fp.size(); ++i) {
if (fp[i] == 0) {
const QString file_path = QDir::cleanPath(saveDir.absoluteFilePath(filepath_at(i)));
const QString file_path = fsutils::expandPathAbs(saveDir.absoluteFilePath(filepath_at(i)));
if (file_path.contains(".unwanted"))
res << file_path;
}
@ -462,10 +458,9 @@ bool QTorrentHandle::priv() const { @@ -462,10 +458,9 @@ bool QTorrentHandle::priv() const {
QString QTorrentHandle::firstFileSavePath() const {
Q_ASSERT(has_metadata());
QString fsave_path = TorrentPersistentData::getSavePath(hash());
QString fsave_path = fsutils::fromNativePath(TorrentPersistentData::getSavePath(hash()));
if (fsave_path.isEmpty())
fsave_path = save_path();
fsave_path.replace("\\", "/");
if (!fsave_path.endsWith("/"))
fsave_path += "/";
fsave_path += filepath_at(0);
@ -480,7 +475,7 @@ QString QTorrentHandle::root_path() const @@ -480,7 +475,7 @@ QString QTorrentHandle::root_path() const
if (num_files() < 2)
return save_path();
QString first_filepath = filepath_at(0);
const int slashIndex = first_filepath.indexOf(QRegExp("[/\\\\]"));
const int slashIndex = first_filepath.indexOf("/");
if (slashIndex >= 0)
return QDir(save_path()).absoluteFilePath(first_filepath.left(slashIndex));
return save_path();
@ -576,7 +571,7 @@ void QTorrentHandle::move_storage(const QString& new_path) const { @@ -576,7 +571,7 @@ void QTorrentHandle::move_storage(const QString& new_path) const {
// or move_storage() will fail...
QDir().mkpath(new_path);
// Actually move the storage
torrent_handle::move_storage(new_path.toUtf8().constData());
torrent_handle::move_storage(fsutils::toNativePath(new_path).toUtf8().constData());
}
bool QTorrentHandle::save_torrent_file(const QString& path) const {
@ -651,7 +646,7 @@ void QTorrentHandle::prioritize_files(const vector<int> &files) const { @@ -651,7 +646,7 @@ void QTorrentHandle::prioritize_files(const vector<int> &files) const {
if (created) {
// Hide the folder on Windows
qDebug() << "Hiding folder (Windows)";
wstring win_path = unwanted_abspath.replace("/","\\").toStdWString();
wstring win_path = fsutils::toNativePath(unwanted_abspath).toStdWString();
DWORD dwAttrs = GetFileAttributesW(win_path.c_str());
bool ret = SetFileAttributesW(win_path.c_str(), dwAttrs|FILE_ATTRIBUTE_HIDDEN);
Q_ASSERT(ret != 0); Q_UNUSED(ret);
@ -676,8 +671,8 @@ void QTorrentHandle::prioritize_files(const vector<int> &files) const { @@ -676,8 +671,8 @@ void QTorrentHandle::prioritize_files(const vector<int> &files) const {
else
rename_file(i, QDir(new_relpath).filePath(old_name));
// Remove .unwanted directory if empty
qDebug() << "Attempting to remove .unwanted folder at " << QDir(spath + QDir::separator() + new_relpath).absoluteFilePath(".unwanted");
QDir(spath + QDir::separator() + new_relpath).rmdir(".unwanted");
qDebug() << "Attempting to remove .unwanted folder at " << QDir(spath + "/" + new_relpath).absoluteFilePath(".unwanted");
QDir(spath + "/" + new_relpath).rmdir(".unwanted");
}
}
}
@ -727,7 +722,7 @@ void QTorrentHandle::prioritize_first_last_piece(bool b) const { @@ -727,7 +722,7 @@ void QTorrentHandle::prioritize_first_last_piece(bool b) const {
void QTorrentHandle::rename_file(int index, const QString& name) const {
qDebug() << Q_FUNC_INFO << index << name;
torrent_handle::rename_file(index, std::string(name.toUtf8().constData()));
torrent_handle::rename_file(index, std::string(fsutils::toNativePath(name).toUtf8().constData()));
}
//

3
src/qtlibtorrent/torrentmodel.cpp

@ -33,6 +33,7 @@ @@ -33,6 +33,7 @@
#include "torrentmodel.h"
#include "torrentpersistentdata.h"
#include "qbtsession.h"
#include "fs_utils.h"
using namespace libtorrent;
@ -215,7 +216,7 @@ QVariant TorrentModelItem::data(int column, int role) const @@ -215,7 +216,7 @@ QVariant TorrentModelItem::data(int column, int role) const
case TR_TIME_ELAPSED:
return (role == Qt::DisplayRole) ? m_torrent.active_time() : m_torrent.seeding_time();
case TR_SAVE_PATH:
return m_torrent.save_path_parsed();
return fsutils::toNativePath(m_torrent.save_path_parsed());
default:
return QVariant();
}

4
src/rss/automatedrssdownloader.cpp

@ -225,7 +225,7 @@ void AutomatedRssDownloader::updateRuleDefinitionBox() @@ -225,7 +225,7 @@ void AutomatedRssDownloader::updateRuleDefinitionBox()
ui->lineContains->setText(rule->mustContain());
ui->lineNotContains->setText(rule->mustNotContain());
ui->saveDiffDir_check->setChecked(!rule->savePath().isEmpty());
ui->lineSavePath->setText(rule->savePath());
ui->lineSavePath->setText(fsutils::toNativePath(rule->savePath()));
ui->checkRegex->setChecked(rule->useRegex());
if (rule->label().isEmpty()) {
ui->comboLabel->setCurrentIndex(-1);
@ -362,7 +362,7 @@ void AutomatedRssDownloader::on_browseSP_clicked() @@ -362,7 +362,7 @@ void AutomatedRssDownloader::on_browseSP_clicked()
{
QString save_path = QFileDialog::getExistingDirectory(this, tr("Destination directory"), QDir::homePath());
if (!save_path.isEmpty())
ui->lineSavePath->setText(save_path);
ui->lineSavePath->setText(fsutils::toNativePath(save_path));
}
void AutomatedRssDownloader::on_exportBtn_clicked()

2
src/rss/rssdownloadrule.cpp

@ -113,7 +113,7 @@ bool RssDownloadRule::operator==(const RssDownloadRule &other) const { @@ -113,7 +113,7 @@ bool RssDownloadRule::operator==(const RssDownloadRule &other) const {
void RssDownloadRule::setSavePath(const QString &save_path)
{
if (!save_path.isEmpty() && QDir(save_path) != QDir(Preferences().getSavePath()))
m_savePath = save_path;
m_savePath = fsutils::fromNativePath(save_path);
else
m_savePath = QString();
}

1
src/rss/rssmanager.cpp

@ -147,6 +147,7 @@ void RssManager::saveStreamList() const @@ -147,6 +147,7 @@ void RssManager::saveStreamList() const
QStringList aliases;
RssFeedList streams = getAllFeeds();
foreach (const RssFeedPtr& stream, streams) {
// This backslash has nothing to do with path handling
QString stream_path = stream->pathHierarchy().join("\\");
if (stream_path.isNull())
stream_path = "";

2
src/rss/rssparser.cpp

@ -214,7 +214,7 @@ void RssParser::parseRssFile(const QString& feedUrl, const QString& filePath) @@ -214,7 +214,7 @@ void RssParser::parseRssFile(const QString& feedUrl, const QString& filePath)
{
qDebug() << Q_FUNC_INFO << feedUrl << filePath;
m_mutex.lock();
ParsingJob job = {feedUrl, filePath};
ParsingJob job = { feedUrl, fsutils::fromNativePath(filePath) };
m_queue.enqueue(job);
// Wake up thread.
if (m_queue.count() == 1) {

10
src/scannedfoldersmodel.cpp

@ -82,12 +82,8 @@ QVariant ScanFoldersModel::data(const QModelIndex &index, int role) const { @@ -82,12 +82,8 @@ QVariant ScanFoldersModel::data(const QModelIndex &index, int role) const {
const PathData* pathData = m_pathList.at(index.row());
if (index.column() == PathColumn && role == Qt::DisplayRole) {
#if defined(Q_WS_WIN) || defined(Q_OS_OS2)
QString ret = pathData->path;
return ret.replace("/", "\\");
#else
return pathData->path;
#endif
return fsutils::toNativePath(pathData->path);
}
if (index.column() == DownloadAtTorrentColumn && role == Qt::CheckStateRole)
return pathData->downloadAtPath ? Qt::Checked : Qt::Unchecked;
@ -181,7 +177,7 @@ bool ScanFoldersModel::downloadInTorrentFolder(const QString &filePath) const { @@ -181,7 +177,7 @@ bool ScanFoldersModel::downloadInTorrentFolder(const QString &filePath) const {
int ScanFoldersModel::findPathData(const QString &path) const {
for (int i = 0; i < m_pathList.count(); ++i) {
const PathData* pathData = m_pathList.at(i);
if (pathData->path == path)
if (pathData->path == fsutils::fromNativePath(path))
return i;
}

17
src/searchengine/engineselectdlg.cpp

@ -158,7 +158,7 @@ void engineSelectDlg::on_actionUninstall_triggered() { @@ -158,7 +158,7 @@ void engineSelectDlg::on_actionUninstall_triggered() {
}else {
// Proceed with uninstall
// remove it from hard drive
QDir enginesFolder(fsutils::searchEngineLocation()+QDir::separator()+"engines");
QDir enginesFolder(fsutils::searchEngineLocation() + "/engines");
QStringList filters;
filters << id+".*";
QStringList files = enginesFolder.entryList(filters, QDir::Files, QDir::Unsorted);
@ -224,7 +224,7 @@ QTreeWidgetItem* engineSelectDlg::findItemWithID(QString id) { @@ -224,7 +224,7 @@ QTreeWidgetItem* engineSelectDlg::findItemWithID(QString id) {
}
bool engineSelectDlg::isUpdateNeeded(QString plugin_name, qreal new_version) const {
qreal old_version = SearchEngine::getPluginVersion(fsutils::searchEngineLocation()+QDir::separator()+"engines"+QDir::separator()+plugin_name+".py");
qreal old_version = SearchEngine::getPluginVersion(fsutils::searchEngineLocation() + "/engines/" + plugin_name + ".py");
qDebug("IsUpdate needed? tobeinstalled: %.2f, alreadyinstalled: %.2f", new_version, old_version);
return (new_version > old_version);
}
@ -239,7 +239,7 @@ void engineSelectDlg::installPlugin(QString path, QString plugin_name) { @@ -239,7 +239,7 @@ void engineSelectDlg::installPlugin(QString path, QString plugin_name) {
return;
}
// Process with install
QString dest_path = fsutils::searchEngineLocation()+QDir::separator()+"engines"+QDir::separator()+plugin_name+".py";
QString dest_path = fsutils::searchEngineLocation() + "/engines/" + plugin_name + ".py";
bool update = false;
if (QFile::exists(dest_path)) {
// Backup in case install fails
@ -304,12 +304,12 @@ void engineSelectDlg::addNewEngine(QString engine_name) { @@ -304,12 +304,12 @@ void engineSelectDlg::addNewEngine(QString engine_name) {
setRowColor(pluginsTree->indexOfTopLevelItem(item), "red");
}
// Handle icon
QString iconPath = fsutils::searchEngineLocation()+QDir::separator()+"engines"+QDir::separator()+engine->getName()+".png";
QString iconPath = fsutils::searchEngineLocation() + "/engines/" + engine->getName() + ".png";
if (QFile::exists(iconPath)) {
// Good, we already have the icon
item->setData(ENGINE_NAME, Qt::DecorationRole, QVariant(QIcon(iconPath)));
} else {
iconPath = fsutils::searchEngineLocation()+QDir::separator()+"engines"+QDir::separator()+engine->getName()+".ico";
iconPath = fsutils::searchEngineLocation() + "/engines/" + engine->getName() + ".ico";
if (QFile::exists(iconPath)) { // ICO support
item->setData(ENGINE_NAME, Qt::DecorationRole, QVariant(QIcon(iconPath)));
} else {
@ -355,7 +355,7 @@ void engineSelectDlg::askForLocalPlugin() { @@ -355,7 +355,7 @@ void engineSelectDlg::askForLocalPlugin() {
QString path;
foreach (path, pathsList) {
if (path.endsWith(".py", Qt::CaseInsensitive)) {
QString plugin_name = path.split(QDir::separator()).last();
QString plugin_name = path.split("/").last();
plugin_name.replace(".py", "", Qt::CaseInsensitive);
installPlugin(path, plugin_name);
}
@ -409,6 +409,7 @@ bool engineSelectDlg::parseVersionsFile(QString versions_file) { @@ -409,6 +409,7 @@ bool engineSelectDlg::parseVersionsFile(QString versions_file) {
}
void engineSelectDlg::processDownloadedFile(QString url, QString filePath) {
filePath = fsutils::fromNativePath(filePath);
setCursor(QCursor(Qt::ArrowCursor));
qDebug("engineSelectDlg received %s", qPrintable(url));
if (url.endsWith("favicon.ico", Qt::CaseInsensitive)) {
@ -423,9 +424,9 @@ void engineSelectDlg::processDownloadedFile(QString url, QString filePath) { @@ -423,9 +424,9 @@ void engineSelectDlg::processDownloadedFile(QString url, QString filePath) {
QFile icon(filePath);
icon.open(QIODevice::ReadOnly);
if (ICOHandler::canRead(&icon))
iconPath = fsutils::searchEngineLocation()+QDir::separator()+"engines"+QDir::separator()+id+".ico";
iconPath = fsutils::searchEngineLocation() + "/engines/" + id + ".ico";
else
iconPath = fsutils::searchEngineLocation()+QDir::separator()+"engines"+QDir::separator()+id+".png";
iconPath = fsutils::searchEngineLocation() + "/engines/" + id + ".png";
QFile::copy(filePath, iconPath);
item->setData(ENGINE_NAME, Qt::DecorationRole, QVariant(QIcon(iconPath)));
}

12
src/searchengine/searchengine.cpp

@ -126,7 +126,7 @@ bool SearchEngine::addPythonPathToEnv() { @@ -126,7 +126,7 @@ bool SearchEngine::addPythonPathToEnv() {
}
path_envar = python_path+";"+path_envar;
qDebug("New PATH envvar is: %s", qPrintable(path_envar));
qputenv("PATH", path_envar.toLocal8Bit());
qputenv("PATH", fsutils::toNativePath(path_envar).toLocal8Bit());
return true;
}
return false;
@ -148,7 +148,7 @@ void SearchEngine::pythonDownloadSuccess(QString url, QString file_path) { @@ -148,7 +148,7 @@ void SearchEngine::pythonDownloadSuccess(QString url, QString file_path) {
QProcess installer;
qDebug("Launching Python installer in passive mode...");
installer.start("msiexec.exe /passive /i "+file_path.replace("/", "\\")+".msi");
installer.start("msiexec.exe /passive /i " + fsutils::toNativePath(file_path) + ".msi");
// Wait for setup to complete
installer.waitForFinished();
@ -275,7 +275,7 @@ void SearchEngine::on_search_button_clicked() { @@ -275,7 +275,7 @@ void SearchEngine::on_search_button_clicked() {
// Getting checked search engines
QStringList params;
search_stopped = false;
params << fsutils::searchEngineLocation()+QDir::separator()+"nova2.py";
params << fsutils::toNativePath(fsutils::searchEngineLocation() + "/nova2.py");
params << supported_engines->enginesEnabled().join(",");
qDebug("Search with category: %s", qPrintable(selectedCategory()));
params << selectedCategory();
@ -343,7 +343,7 @@ void SearchEngine::downloadTorrent(QString engine_url, QString torrent_url) { @@ -343,7 +343,7 @@ void SearchEngine::downloadTorrent(QString engine_url, QString torrent_url) {
connect(downloadProcess, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(downloadFinished(int,QProcess::ExitStatus)));
downloaders << downloadProcess;
QStringList params;
params << fsutils::searchEngineLocation()+QDir::separator()+"nova2dl.py";
params << fsutils::toNativePath(fsutils::searchEngineLocation() + "/nova2dl.py");
params << engine_url;
params << torrent_url;
// Launch search
@ -396,7 +396,7 @@ void SearchEngine::downloadFinished(int exitcode, QProcess::ExitStatus) { @@ -396,7 +396,7 @@ void SearchEngine::downloadFinished(int exitcode, QProcess::ExitStatus) {
static void removePythonScriptIfExists(const QString& script_path)
{
fsutils::forceRemove(script_path);
fsutils::forceRemove(script_path+"c");
fsutils::forceRemove(script_path + "c");
}
// Update nova.py search plugin if necessary
@ -411,7 +411,7 @@ void SearchEngine::updateNova() { @@ -411,7 +411,7 @@ void SearchEngine::updateNova() {
if (!search_dir.exists("engines")) {
search_dir.mkdir("engines");
}
QFile package_file2(search_dir.absolutePath().replace("\\", "/")+"/engines/__init__.py");
QFile package_file2(search_dir.absolutePath() + "/engines/__init__.py");
package_file2.open(QIODevice::WriteOnly | QIODevice::Text);
package_file2.close();
// Copy search plugin files (if necessary)

2
src/searchengine/supportedengines.h

@ -144,7 +144,7 @@ public slots: @@ -144,7 +144,7 @@ public slots:
QProcess nova;
nova.setEnvironment(QProcess::systemEnvironment());
QStringList params;
params << fsutils::searchEngineLocation()+QDir::separator()+"nova2.py";
params << fsutils::toNativePath(fsutils::searchEngineLocation()+"/nova2.py");
params << "--capabilities";
nova.start("python", params, QIODevice::ReadOnly);
nova.waitForStarted();

5
src/torrentcontentmodel.cpp

@ -30,6 +30,7 @@ @@ -30,6 +30,7 @@
#include "iconprovider.h"
#include "misc.h"
#include "fs_utils.h"
#include "torrentcontentmodel.h"
#include "torrentcontentmodelitem.h"
#include "torrentcontentmodelfolder.h"
@ -283,9 +284,9 @@ void TorrentContentModel::setupModelData(const libtorrent::torrent_info& t) @@ -283,9 +284,9 @@ void TorrentContentModel::setupModelData(const libtorrent::torrent_info& t)
for (int i = 0; i < t.num_files(); ++i) {
const libtorrent::file_entry& fentry = t.file_at(i);
current_parent = m_rootItem;
QString path = misc::toQStringU(fentry.path);
QString path = fsutils::fromNativePath(misc::toQStringU(fentry.path));
// Iterate of parts of the path to create necessary folders
QStringList pathFolders = path.split(QRegExp("[/\\\\]"), QString::SkipEmptyParts);
QStringList pathFolders = path.split("/", QString::SkipEmptyParts);
pathFolders.removeLast();
foreach (const QString& pathPart, pathFolders) {
if (pathPart == ".unwanted")

20
src/torrentcreator/torrentcreatordlg.cpp

@ -74,10 +74,7 @@ void TorrentCreatorDlg::on_addFolder_button_clicked() { @@ -74,10 +74,7 @@ void TorrentCreatorDlg::on_addFolder_button_clicked() {
QString dir = QFileDialog::getExistingDirectory(this, tr("Select a folder to add to the torrent"), last_path, QFileDialog::ShowDirsOnly);
if (!dir.isEmpty()) {
settings.setValue("CreateTorrent/last_add_path", dir);
#if defined(Q_WS_WIN) || defined(Q_OS_OS2)
dir.replace("/", "\\");
#endif
textInputPath->setText(dir);
textInputPath->setText(fsutils::toNativePath(dir));
// Update piece size
if (checkAutoPieceSize->isChecked())
updateOptimalPieceSize();
@ -90,10 +87,7 @@ void TorrentCreatorDlg::on_addFile_button_clicked() { @@ -90,10 +87,7 @@ void TorrentCreatorDlg::on_addFile_button_clicked() {
QString file = QFileDialog::getOpenFileName(this, tr("Select a file to add to the torrent"), last_path);
if (!file.isEmpty()) {
settings.setValue("CreateTorrent/last_add_path", fsutils::branchPath(file));
#if defined(Q_WS_WIN) || defined(Q_OS_OS2)
file.replace("/", "\\");
#endif
textInputPath->setText(file);
textInputPath->setText(fsutils::toNativePath(file));
// Update piece size
if (checkAutoPieceSize->isChecked())
updateOptimalPieceSize();
@ -106,8 +100,8 @@ int TorrentCreatorDlg::getPieceSize() const { @@ -106,8 +100,8 @@ int TorrentCreatorDlg::getPieceSize() const {
// Main function that create a .torrent file
void TorrentCreatorDlg::on_createButton_clicked() {
QString input = textInputPath->text().trimmed();
if (input.endsWith(QDir::separator()))
QString input = fsutils::fromNativePath(textInputPath->text()).trimmed();
if (input.endsWith("/"))
input.chop(1);
if (input.isEmpty()) {
QMessageBox::critical(0, tr("No input path set"), tr("Please type an input path first"));
@ -141,7 +135,7 @@ void TorrentCreatorDlg::on_createButton_clicked() { @@ -141,7 +135,7 @@ void TorrentCreatorDlg::on_createButton_clicked() {
connect(creatorThread, SIGNAL(creationSuccess(QString, QString)), this, SLOT(handleCreationSuccess(QString, QString)));
connect(creatorThread, SIGNAL(creationFailure(QString)), this, SLOT(handleCreationFailure(QString)));
connect(creatorThread, SIGNAL(updateProgress(int)), this, SLOT(updateProgressBar(int)));
creatorThread->create(input, QDir::toNativeSeparators(destination), trackers, url_seeds, comment, check_private->isChecked(), getPieceSize());
creatorThread->create(input, destination, trackers, url_seeds, comment, check_private->isChecked(), getPieceSize());
}
void TorrentCreatorDlg::handleCreationFailure(QString msg) {
@ -159,7 +153,7 @@ void TorrentCreatorDlg::handleCreationSuccess(QString path, QString branch_path) @@ -159,7 +153,7 @@ void TorrentCreatorDlg::handleCreationSuccess(QString path, QString branch_path)
// Create save path temp data
boost::intrusive_ptr<torrent_info> t;
try {
t = new torrent_info(path.toUtf8().data());
t = new torrent_info(fsutils::toNativePath(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;
@ -173,7 +167,7 @@ void TorrentCreatorDlg::handleCreationSuccess(QString path, QString branch_path) @@ -173,7 +167,7 @@ void TorrentCreatorDlg::handleCreationSuccess(QString path, QString branch_path)
if (checkIgnoreShareLimits->isChecked())
QBtSession::instance()->setMaxRatioPerTorrent(hash, -1);
}
QMessageBox::information(0, tr("Torrent creation"), tr("Torrent was created successfully:")+" "+path);
QMessageBox::information(0, tr("Torrent creation"), tr("Torrent was created successfully:")+" "+fsutils::toNativePath(path));
close();
}

14
src/torrentcreator/torrentcreatorthread.cpp

@ -59,8 +59,8 @@ bool file_filter(std::string const& f) @@ -59,8 +59,8 @@ bool file_filter(std::string const& f)
void TorrentCreatorThread::create(QString _input_path, QString _save_path, QStringList _trackers, QStringList _url_seeds, QString _comment, bool _is_private, int _piece_size)
{
input_path = _input_path;
save_path = _save_path;
input_path = fsutils::fromNativePath(_input_path);
save_path = fsutils::fromNativePath(_save_path);
if (QFile(save_path).exists())
fsutils::forceRemove(save_path);
trackers = _trackers;
@ -86,7 +86,7 @@ void TorrentCreatorThread::run() { @@ -86,7 +86,7 @@ void TorrentCreatorThread::run() {
try {
file_storage fs;
// Adding files to the torrent
libtorrent::add_files(fs, input_path.toUtf8().constData(), file_filter);
libtorrent::add_files(fs, fsutils::toNativePath(input_path).toUtf8().constData(), file_filter);
if (abort) return;
create_torrent t(fs, piece_size);
@ -109,8 +109,8 @@ void TorrentCreatorThread::run() { @@ -109,8 +109,8 @@ void TorrentCreatorThread::run() {
}
if (abort) return;
// calculate the hash for all pieces
const QString parent_path = fsutils::branchPath(input_path) + QDir::separator();
set_piece_hashes(t, parent_path.toUtf8().constData(), boost::bind<void>(&sendProgressUpdateSignal, _1, t.num_pieces(), this));
const QString parent_path = fsutils::branchPath(input_path) + "/";
set_piece_hashes(t, fsutils::toNativePath(parent_path).toUtf8().constData(), boost::bind<void>(&sendProgressUpdateSignal, _1, t.num_pieces(), this));
// Set qBittorrent as creator and add user comment to
// torrent_info structure
t.set_creator(creator_str.toUtf8().constData());
@ -122,12 +122,12 @@ void TorrentCreatorThread::run() { @@ -122,12 +122,12 @@ void TorrentCreatorThread::run() {
qDebug("Saving to %s", qPrintable(save_path));
#ifdef _MSC_VER
wchar_t *wsave_path = new wchar_t[save_path.length()+1];
int len = save_path.toWCharArray(wsave_path);
int len = fsutils::toNativePath(save_path).toWCharArray(wsave_path);
wsave_path[len] = '\0';
std::ofstream outfile(wsave_path, std::ios_base::out|std::ios_base::binary);
delete[] wsave_path;
#else
std::ofstream outfile(save_path.toLocal8Bit().constData(), std::ios_base::out|std::ios_base::binary);
std::ofstream outfile(fsutils::toNativePath(save_path).toLocal8Bit().constData(), std::ios_base::out|std::ios_base::binary);
#endif
if (outfile.fail())
throw std::exception();

33
src/torrentimportdlg.cpp

@ -96,11 +96,7 @@ void TorrentImportDlg::on_browseContentBtn_clicked() @@ -96,11 +96,7 @@ void TorrentImportDlg::on_browseContentBtn_clicked()
return;
}
// Update display
#if defined(Q_WS_WIN) || defined(Q_OS_OS2)
ui->lineContent->setText(m_contentPath.replace("/", "\\"));
#else
ui->lineContent->setText(m_contentPath);
#endif
ui->lineContent->setText(fsutils::toNativePath(m_contentPath));
// Check file size
const qint64 file_size = QFile(m_contentPath).size();
if (t->file_at(0).size == file_size) {
@ -112,7 +108,7 @@ void TorrentImportDlg::on_browseContentBtn_clicked() @@ -112,7 +108,7 @@ void TorrentImportDlg::on_browseContentBtn_clicked()
ui->checkSkipCheck->setEnabled(false);
}
// Handle file renaming
QStringList parts = m_contentPath.replace("\\", "/").split("/");
QStringList parts = m_contentPath.split("/");
QString new_file_name = parts.takeLast();
if (new_file_name != file_name) {
qDebug("The file has been renamed");
@ -132,20 +128,16 @@ void TorrentImportDlg::on_browseContentBtn_clicked() @@ -132,20 +128,16 @@ void TorrentImportDlg::on_browseContentBtn_clicked()
return;
}
// Update the display
#if defined(Q_WS_WIN) || defined(Q_OS_OS2)
ui->lineContent->setText(m_contentPath.replace("/", "\\"));
#else
ui->lineContent->setText(m_contentPath);
#endif
ui->lineContent->setText(fsutils::toNativePath(m_contentPath));
bool size_mismatch = false;
QDir content_dir(m_contentPath);
content_dir.cdUp();
// Check file sizes
for (int i=0; i<t->num_files(); ++i) {
const QString rel_path = misc::toQStringU(t->file_at(i).path);
if (QFile(QDir::cleanPath(content_dir.absoluteFilePath(rel_path))).size() != t->file_at(i).size) {
if (QFile(fsutils::expandPath(content_dir.absoluteFilePath(rel_path))).size() != t->file_at(i).size) {
qDebug("%s is %lld",
qPrintable(QDir::cleanPath(content_dir.absoluteFilePath(rel_path))), (long long int) QFile(QDir::cleanPath(content_dir.absoluteFilePath(rel_path))).size());
qPrintable(fsutils::expandPath(content_dir.absoluteFilePath(rel_path))), (long long int) QFile(fsutils::expandPath(content_dir.absoluteFilePath(rel_path))).size());
qDebug("%s is %lld",
qPrintable(rel_path), (long long int)t->file_at(i).size);
size_mismatch = true;
@ -206,8 +198,8 @@ void TorrentImportDlg::importTorrent() @@ -206,8 +198,8 @@ void TorrentImportDlg::importTorrent()
QBtSession::instance()->addTorrent(torrent_path);
// Remember the last opened folder
QIniSettings settings;
settings.setValue(QString::fromUtf8("MainWindowLastDir"), torrent_path);
settings.setValue("TorrentImport/LastContentDir", content_path);
settings.setValue(QString::fromUtf8("MainWindowLastDir"), fsutils::fromNativePath(torrent_path));
settings.setValue("TorrentImport/LastContentDir", fsutils::fromNativePath(content_path));
return;
}
qDebug() << Q_FUNC_INFO << "EXIT";
@ -218,7 +210,7 @@ void TorrentImportDlg::loadTorrent(const QString &torrent_path) @@ -218,7 +210,7 @@ void TorrentImportDlg::loadTorrent(const QString &torrent_path)
{
// Load the torrent file
try {
t = new torrent_info(torrent_path.toUtf8().constData());
t = new torrent_info(fsutils::toNativePath(torrent_path).toUtf8().constData());
if (!t->is_valid() || t->num_files() == 0)
throw std::exception();
} catch(std::exception&) {
@ -228,12 +220,7 @@ void TorrentImportDlg::loadTorrent(const QString &torrent_path) @@ -228,12 +220,7 @@ void TorrentImportDlg::loadTorrent(const QString &torrent_path)
return;
}
// Update display
#if defined(Q_WS_WIN) || defined(Q_OS_OS2)
QString tmp = torrent_path;
ui->lineTorrent->setText(tmp.replace("/", "\\"));
#else
ui->lineTorrent->setText(torrent_path);
#endif
ui->lineTorrent->setText(fsutils::toNativePath(torrent_path));
ui->browseContentBtn->setEnabled(true);
// Load the file names
initializeFilesPath();
@ -244,7 +231,7 @@ void TorrentImportDlg::initializeFilesPath() @@ -244,7 +231,7 @@ void TorrentImportDlg::initializeFilesPath()
m_filesPath.clear();
// Loads files path in the torrent
for (int i=0; i<t->num_files(); ++i) {
m_filesPath << misc::toQStringU(t->file_at(i).path).replace("\\", "/");
m_filesPath << fsutils::fromNativePath(misc::toQStringU(t->file_at(i).path));
}
}

2
src/torrentpersistentdata.h

@ -43,6 +43,7 @@ @@ -43,6 +43,7 @@
#include <QHash>
class TorrentTempData {
// This class stores strings w/o modifying separators
public:
static bool hasTempData(const QString &hash) {
return data.contains(hash);
@ -151,6 +152,7 @@ private: @@ -151,6 +152,7 @@ private:
};
class TorrentPersistentData {
// This class stores strings w/o modifying separators
public:
enum RatioLimit {
USE_GLOBAL_RATIO = -2,

17
src/transferlistwidget.cpp

@ -177,7 +177,7 @@ TorrentModel* TransferListWidget::getSourceModel() const { @@ -177,7 +177,7 @@ TorrentModel* TransferListWidget::getSourceModel() const {
}
void TransferListWidget::previewFile(QString filePath) {
QDesktopServices::openUrl(QUrl::fromLocalFile(filePath));
openUrl(filePath);
}
void TransferListWidget::setRefreshInterval(int t) {
@ -235,8 +235,8 @@ void TransferListWidget::torrentDoubleClicked(const QModelIndex& index) { @@ -235,8 +235,8 @@ void TransferListWidget::torrentDoubleClicked(const QModelIndex& index) {
}
break;
case OPEN_DEST:
QDesktopServices::openUrl(QUrl::fromLocalFile(h.root_path()));
break;
const QString path = h.root_path();
openUrl(path);
}
}
@ -260,7 +260,7 @@ void TransferListWidget::setSelectedTorrentsLocation() { @@ -260,7 +260,7 @@ void TransferListWidget::setSelectedTorrentsLocation() {
if (!dir.isNull()) {
qDebug("New path is %s", qPrintable(dir));
// Check if savePath exists
QDir savePath(fsutils::expandPath(dir));
QDir savePath(fsutils::expandPathAbs(dir));
qDebug("New path after clean up is %s", qPrintable(savePath.absolutePath()));
foreach (const QString & hash, hashes) {
// Actually move storage
@ -439,7 +439,7 @@ void TransferListWidget::openSelectedTorrentsFolder() const { @@ -439,7 +439,7 @@ void TransferListWidget::openSelectedTorrentsFolder() const {
qDebug("Opening path at %s", qPrintable(rootFolder));
if (!pathsList.contains(rootFolder)) {
pathsList.insert(rootFolder);
QDesktopServices::openUrl(QUrl::fromLocalFile(rootFolder));
openUrl(rootFolder);
}
}
}
@ -644,6 +644,13 @@ void TransferListWidget::askNewLabelForSelection() { @@ -644,6 +644,13 @@ void TransferListWidget::askNewLabelForSelection() {
}while(invalid);
}
bool TransferListWidget::openUrl(const QString &_path) const {
const QString path = fsutils::fromNativePath(_path);
// Hack to access samba shares with QDesktopServices::openUrl
const QString p = path.startsWith("//") ? QString("file:") + path : path;
return QDesktopServices::openUrl(QUrl::fromLocalFile(p));
}
void TransferListWidget::renameSelectedTorrent() {
const QModelIndexList selectedIndexes = selectionModel()->selectedRows();
if (selectedIndexes.size() != 1) return;

3
src/transferlistwidget.h

@ -106,6 +106,9 @@ protected slots: @@ -106,6 +106,9 @@ protected slots:
void toggleSelectedFirstLastPiecePrio() const;
void askNewLabelForSelection();
private:
bool openUrl(const QString& _path) const;
signals:
void currentTorrentChanged(const QTorrentHandle &h);

7
src/webui/btjson.cpp

@ -32,6 +32,7 @@ @@ -32,6 +32,7 @@
#include "jsondict.h"
#include "jsonlist.h"
#include "misc.h"
#include "fs_utils.h"
#include "qbtsession.h"
#include "torrentpersistentdata.h"
@ -287,9 +288,9 @@ QString btjson::getPropertiesForTorrent(const QString& hash) @@ -287,9 +288,9 @@ QString btjson::getPropertiesForTorrent(const QString& hash)
return QString();
// Save path
QString save_path = TorrentPersistentData::getSavePath(hash);
QString save_path = fsutils::toNativePath(TorrentPersistentData::getSavePath(hash));
if (save_path.isEmpty())
save_path = h.save_path();
save_path = fsutils::toNativePath(h.save_path());
data.add(KEY_PROP_SAVE_PATH, save_path);
data.add(KEY_PROP_CREATION_DATE, h.creation_date());
data.add(KEY_PROP_PIECE_SIZE, misc::friendlyUnit(h.piece_length()));
@ -341,7 +342,7 @@ QString btjson::getFilesForTorrent(const QString& hash) @@ -341,7 +342,7 @@ QString btjson::getFilesForTorrent(const QString& hash)
QString fileName = h.filename_at(i);
if (fileName.endsWith(".!qB", Qt::CaseInsensitive))
fileName.chop(4);
file_dict.add(KEY_FILE_NAME, fileName);
file_dict.add(KEY_FILE_NAME, fsutils::toNativePath(fileName));
const size_type size = h.filesize_at(i);
file_dict.add(KEY_FILE_SIZE, misc::friendlyUnit(size));
file_dict.add(KEY_FILE_PROGRESS, (size > 0) ? (fp[i] / (double) size) : 1.);

18
src/webui/prefjson.cpp

@ -53,17 +53,21 @@ QString prefjson::getPreferences() @@ -53,17 +53,21 @@ QString prefjson::getPreferences()
// UI
data.add("locale", pref.getLocale());
// Downloads
data.add("save_path", pref.getSavePath());
data.add("save_path", fsutils::toNativePath(pref.getSavePath()));
data.add("temp_path_enabled", pref.isTempPathEnabled());
data.add("temp_path", pref.getTempPath());
data.add("scan_dirs", pref.getScanDirs());
data.add("temp_path", fsutils::toNativePath(pref.getTempPath()));
QStringList l;
foreach (const QString& s, pref.getScanDirs()) {
l << fsutils::toNativePath(s);
}
data.add("scan_dirs", l);
QVariantList var_list;
foreach (bool b, pref.getDownloadInScanDirs()) {
var_list << b;
}
data.add("download_in_scan_dirs", var_list);
data.add("export_dir_enabled", pref.isTorrentExportEnabled());
data.add("export_dir", pref.getTorrentExportDir());
data.add("export_dir", fsutils::toNativePath(pref.getTorrentExportDir()));
data.add("mail_notification_enabled", pref.isMailNotificationEnabled());
data.add("mail_notification_email", pref.getMailNotificationEmail());
data.add("mail_notification_smtp", pref.getMailNotificationSMTP());
@ -72,7 +76,7 @@ QString prefjson::getPreferences() @@ -72,7 +76,7 @@ QString prefjson::getPreferences()
data.add("mail_notification_username", pref.getMailNotificationSMTPUsername());
data.add("mail_notification_password", pref.getMailNotificationSMTPPassword());
data.add("autorun_enabled", pref.isAutoRunEnabled());
data.add("autorun_program", pref.getAutoRunProgram());
data.add("autorun_program", fsutils::toNativePath(pref.getAutoRunProgram()));
data.add("preallocate_all", pref.preAllocateAllFiles());
data.add("queueing_enabled", pref.isQueueingSystemEnabled());
data.add("max_active_downloads", pref.getMaxActiveDownloads());
@ -119,7 +123,7 @@ QString prefjson::getPreferences() @@ -119,7 +123,7 @@ QString prefjson::getPreferences()
data.add("proxy_password", pref.getProxyPassword());
// IP Filter
data.add("ip_filter_enabled", pref.isFilteringEnabled());
data.add("ip_filter_path", pref.getFilter());
data.add("ip_filter_path", fsutils::toNativePath(pref.getFilter()));
// Web UI
data.add("web_ui_port", pref.getWebUiPort());
data.add("web_ui_username", pref.getWebUiUsername());
@ -186,7 +190,7 @@ void prefjson::setPreferences(const QString& json) @@ -186,7 +190,7 @@ void prefjson::setPreferences(const QString& json)
foreach (const QString &new_folder, new_folders) {
qDebug("New watched folder: %s", qPrintable(new_folder));
// Update new folders
if (!old_folders.contains(new_folder)) {
if (!old_folders.contains(fsutils::fromNativePath(new_folder))) {
QBtSession::instance()->getScanFoldersModel()->addPath(new_folder, download_at_path.at(i));
}
++i;

Loading…
Cancel
Save