Browse Source

Merge latest changes for stable branch (mostly unicode fixes)

adaptive-webui-19844
Christophe Dumez 15 years ago
parent
commit
c9ece4695e
  1. 23
      src/bittorrent.cpp
  2. 2
      src/createtorrent_imp.cpp
  3. 1
      src/misc.h
  4. 27
      src/propertieswidget.cpp
  5. 20
      src/torrentadditiondlg.h
  6. 2
      src/torrentfilesmodel.h

23
src/bittorrent.cpp

@ -971,7 +971,7 @@ QTorrentHandle Bittorrent::addTorrent(QString path, bool fromScanDir, QString fr
qDebug("Adding %s to download list", qPrintable(file)); qDebug("Adding %s to download list", qPrintable(file));
try { try {
// Getting torrent file informations // Getting torrent file informations
t = new torrent_info(file.toLocal8Bit().constData()); t = new torrent_info(file.toUtf8().constData());
if(!t->is_valid()) if(!t->is_valid())
throw std::exception(); throw std::exception();
} catch(std::exception&) { } catch(std::exception&) {
@ -1141,9 +1141,20 @@ QTorrentHandle Bittorrent::addTorrent(QString path, bool fromScanDir, QString fr
bool force_recheck = false; bool force_recheck = false;
if(files_path.size() == h.num_files()) { if(files_path.size() == h.num_files()) {
for(int i=0; i<h.num_files(); ++i) { for(int i=0; i<h.num_files(); ++i) {
QString old_path = h.files_path().at(i);
old_path = old_path.replace("\\", "/");
if(!QFile::exists(old_path)) {
// Remove old parent folder manually since we will
// not get a file_renamed alert
QStringList parts = old_path.split("/", QString::SkipEmptyParts);
parts.removeLast();
if(!parts.empty())
QDir().rmpath(parts.join("/"));
}
const QString &path = files_path.at(i); const QString &path = files_path.at(i);
if(!force_recheck && QFile::exists(h.save_path()+QDir::separator()+path)) if(!force_recheck && QDir(h.save_path()).exists(path))
force_recheck = true; force_recheck = true;
qDebug("Renaming file to %s", qPrintable(path));
h.rename_file(i, path); h.rename_file(i, path);
} }
// Force recheck // Force recheck
@ -1577,7 +1588,7 @@ void Bittorrent::addConsoleMessage(QString msg, QString) {
foreach(const QString &file, pathList) { foreach(const QString &file, pathList) {
qDebug("File %s added", qPrintable(file)); qDebug("File %s added", qPrintable(file));
try { try {
torrent_info t(file.toLocal8Bit().constData()); torrent_info t(file.toUtf8().constData());
if(t.is_valid()) if(t.is_valid())
addTorrent(file, true); addTorrent(file, true);
} catch(std::exception&) { } catch(std::exception&) {
@ -1893,12 +1904,12 @@ void Bittorrent::addConsoleMessage(QString msg, QString) {
void Bittorrent::recursiveTorrentDownload(const QTorrentHandle &h) { void Bittorrent::recursiveTorrentDownload(const QTorrentHandle &h) {
for(int i=0; i<h.get_torrent_info().num_files(); ++i) { for(int i=0; i<h.get_torrent_info().num_files(); ++i) {
const QString &torrent_relpath = misc::toQString(h.get_torrent_info().file_at(i).path.string()); const QString &torrent_relpath = misc::toQStringU(h.get_torrent_info().file_at(i).path.string());
if(torrent_relpath.endsWith(".torrent")) { if(torrent_relpath.endsWith(".torrent")) {
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())); 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()));
const QString torrent_fullpath = h.save_path()+QDir::separator()+torrent_relpath; const QString torrent_fullpath = h.save_path()+QDir::separator()+torrent_relpath;
try { try {
boost::intrusive_ptr<torrent_info> t = new torrent_info(torrent_fullpath.toLocal8Bit().constData()); boost::intrusive_ptr<torrent_info> t = new torrent_info(torrent_fullpath.toUtf8().constData());
const QString &sub_hash = misc::toQString(t->info_hash()); const QString &sub_hash = misc::toQString(t->info_hash());
// Passing the save path along to the sub torrent file // Passing the save path along to the sub torrent file
TorrentTempData::setSavePath(sub_hash, h.save_path()); TorrentTempData::setSavePath(sub_hash, h.save_path());
@ -1947,7 +1958,7 @@ void Bittorrent::addConsoleMessage(QString msg, QString) {
const QString torrent_fullpath = h.save_path()+QDir::separator()+torrent_relpath; const QString torrent_fullpath = h.save_path()+QDir::separator()+torrent_relpath;
qDebug("Full subtorrent path is %s", qPrintable(torrent_fullpath)); qDebug("Full subtorrent path is %s", qPrintable(torrent_fullpath));
try { try {
boost::intrusive_ptr<torrent_info> t = new torrent_info(torrent_fullpath.toLocal8Bit().constData()); boost::intrusive_ptr<torrent_info> t = new torrent_info(torrent_fullpath.toUtf8().constData());
if(t->is_valid()) { if(t->is_valid()) {
qDebug("emitting recursiveTorrentDownloadPossible()"); qDebug("emitting recursiveTorrentDownloadPossible()");
emit recursiveTorrentDownloadPossible(h); emit recursiveTorrentDownloadPossible(h);

2
src/createtorrent_imp.cpp

@ -201,7 +201,7 @@ void createtorrent::handleCreationSuccess(QString path, const char* branch_path)
// Create save path temp data // Create save path temp data
boost::intrusive_ptr<torrent_info> t; boost::intrusive_ptr<torrent_info> t;
try { try {
t = new torrent_info(path.toLocal8Bit().data()); t = new torrent_info(path.toUtf8().data());
} catch(std::exception&) { } catch(std::exception&) {
QMessageBox::critical(0, tr("Torrent creation"), tr("Created torrent file is invalid. It won't be added to download list.")); QMessageBox::critical(0, tr("Torrent creation"), tr("Created torrent file is invalid. It won't be added to download list."));
return; return;

1
src/misc.h

@ -76,7 +76,6 @@ public:
static inline sha1_hash QStringToSha1(const QString& s) { static inline sha1_hash QStringToSha1(const QString& s) {
std::string str(s.toLocal8Bit().data()); std::string str(s.toLocal8Bit().data());
std::istringstream i(str); std::istringstream i(str);
std::cout << "lol" << std::endl;
sha1_hash x; sha1_hash x;
i>>x; i>>x;
return x; return x;

27
src/propertieswidget.cpp

@ -593,25 +593,27 @@ void PropertiesWidget::renameSelectedFile() {
// File renaming // File renaming
const int file_index = PropListModel->getFileIndex(index); const int file_index = PropListModel->getFileIndex(index);
if(!h.is_valid() || !h.has_metadata()) return; if(!h.is_valid() || !h.has_metadata()) return;
const QString &old_name = misc::toQString(h.get_torrent_info().file_at(file_index).path.string()); QString old_name = misc::toQStringU(h.get_torrent_info().file_at(file_index).path.string());
old_name = old_name.replace("\\", "/");
if(old_name.endsWith(".!qB") && !new_name_last.endsWith(".!qB")) { if(old_name.endsWith(".!qB") && !new_name_last.endsWith(".!qB")) {
new_name_last += ".!qB"; new_name_last += ".!qB";
} }
QStringList path_items = old_name.split(QDir::separator()); QStringList path_items = old_name.split("/");
path_items.removeLast(); path_items.removeLast();
path_items << new_name_last; path_items << new_name_last;
const QString &new_name = path_items.join(QDir::separator()); QString new_name = path_items.join("/");
if(old_name == new_name) { if(old_name == new_name) {
qDebug("Name did not change"); qDebug("Name did not change");
return; return;
} }
new_name = QDir::cleanPath(new_name);
// Check if that name is already used // Check if that name is already used
for(int i=0; i<h.num_files(); ++i) { for(int i=0; i<h.num_files(); ++i) {
if(i == file_index) continue; if(i == file_index) continue;
#if defined(Q_WS_X11) || defined(Q_WS_MAC) || defined(Q_WS_QWS) #if defined(Q_WS_X11) || defined(Q_WS_MAC) || defined(Q_WS_QWS)
if(misc::toQString(h.get_torrent_info().file_at(i).path.string()).compare(new_name, Qt::CaseSensitive) == 0) { if(misc::toQStringU(h.get_torrent_info().file_at(i).path.string()).compare(new_name, Qt::CaseSensitive) == 0) {
#else #else
if(misc::toQString(h.get_torrent_info().file_at(i).path.string()).compare(new_name, Qt::CaseInsensitive) == 0) { if(misc::toQStringU(h.get_torrent_info().file_at(i).path.string()).compare(new_name, Qt::CaseInsensitive) == 0) {
#endif #endif
// Display error message // Display error message
QMessageBox::warning(this, tr("The file could not be renamed"), QMessageBox::warning(this, tr("The file could not be renamed"),
@ -638,15 +640,15 @@ void PropertiesWidget::renameSelectedFile() {
path_items.prepend(parent.data().toString()); path_items.prepend(parent.data().toString());
parent = PropListModel->parent(parent); parent = PropListModel->parent(parent);
} }
const QString &old_path = path_items.join(QDir::separator()); const QString &old_path = path_items.join("/");
path_items.removeLast(); path_items.removeLast();
path_items << new_name_last; path_items << new_name_last;
QString new_path = path_items.join(QDir::separator()); QString new_path = path_items.join("/");
if(!new_path.endsWith(QDir::separator())) new_path += QDir::separator(); if(!new_path.endsWith("/")) new_path += "/";
// Check for overwriting // Check for overwriting
const int num_files = h.num_files(); const int num_files = h.num_files();
for(int i=0; i<num_files; ++i) { for(int i=0; i<num_files; ++i) {
const QString current_name = misc::toQString(h.get_torrent_info().file_at(i).path.string()); const QString current_name = misc::toQStringU(h.get_torrent_info().file_at(i).path.string());
#if defined(Q_WS_X11) || defined(Q_WS_MAC) || defined(Q_WS_QWS) #if defined(Q_WS_X11) || defined(Q_WS_MAC) || defined(Q_WS_QWS)
if(current_name.startsWith(new_path, Qt::CaseSensitive)) { if(current_name.startsWith(new_path, Qt::CaseSensitive)) {
#else #else
@ -661,12 +663,13 @@ void PropertiesWidget::renameSelectedFile() {
bool force_recheck = false; bool force_recheck = false;
// Replace path in all files // Replace path in all files
for(int i=0; i<num_files; ++i) { for(int i=0; i<num_files; ++i) {
const QString &current_name = misc::toQString(h.get_torrent_info().file_at(i).path.string()); const QString &current_name = misc::toQStringU(h.get_torrent_info().file_at(i).path.string());
if(current_name.startsWith(old_path)) { if(current_name.startsWith(old_path)) {
QString new_name = current_name; QString new_name = current_name;
new_name.replace(0, old_path.length(), new_path); new_name.replace(0, old_path.length(), new_path);
if(!force_recheck && QFile::exists(h.save_path()+QDir::separator()+new_name)) if(!force_recheck && QDir(h.save_path()).exists(new_name))
force_recheck = true; force_recheck = true;
new_name = QDir::cleanPath(new_name);
qDebug("Rename %s to %s", qPrintable(current_name), qPrintable(new_name)); qDebug("Rename %s to %s", qPrintable(current_name), qPrintable(new_name));
h.rename_file(i, new_name); h.rename_file(i, new_name);
} }
@ -676,7 +679,7 @@ void PropertiesWidget::renameSelectedFile() {
// Rename folder in torrent files model too // Rename folder in torrent files model too
PropListModel->setData(index, new_name_last); PropListModel->setData(index, new_name_last);
// Remove old folder // Remove old folder
const QDir old_folder(h.save_path()+QDir::separator()+old_path); const QDir old_folder(h.save_path()+"/"+old_path);
int timeout = 10; int timeout = 10;
while(!misc::removeEmptyTree(old_folder.absolutePath()) && timeout > 0) { while(!misc::removeEmptyTree(old_folder.absolutePath()) && timeout > 0) {
SleeperThread::msleep(100); SleeperThread::msleep(100);

20
src/torrentadditiondlg.h

@ -203,7 +203,7 @@ public:
this->from_url = from_url; this->from_url = from_url;
// Getting torrent file informations // Getting torrent file informations
try { try {
t = new torrent_info(filePath.toLocal8Bit().data()); t = new torrent_info(filePath.toUtf8().data());
if(!t->is_valid()) if(!t->is_valid())
throw std::exception(); throw std::exception();
} catch(std::exception&) { } catch(std::exception&) {
@ -318,15 +318,19 @@ public slots:
if(PropListModel->getType(index)==TFILE) { if(PropListModel->getType(index)==TFILE) {
// File renaming // File renaming
const uint file_index = PropListModel->getFileIndex(index); const uint file_index = PropListModel->getFileIndex(index);
const QString &old_name = files_path.at(file_index); QString old_name = files_path.at(file_index);
QStringList path_items = old_name.split(QDir::separator()); old_name = old_name.replace("\\", "/");
qDebug("Old name: %s", qPrintable(old_name));
QStringList path_items = old_name.split("/");
path_items.removeLast(); path_items.removeLast();
path_items << new_name_last; path_items << new_name_last;
const QString &new_name = path_items.join(QDir::separator()); QString new_name = path_items.join("/");
if(old_name == new_name) { if(old_name == new_name) {
qDebug("Name did not change"); qDebug("Name did not change");
return; return;
} }
new_name = QDir::cleanPath(new_name);
qDebug("New name: %s", qPrintable(new_name));
// Check if that name is already used // Check if that name is already used
for(uint i=0; i<nbFiles; ++i) { for(uint i=0; i<nbFiles; ++i) {
if(i == file_index) continue; if(i == file_index) continue;
@ -342,6 +346,7 @@ public slots:
return; return;
} }
} }
new_name = QDir::cleanPath(new_name);
qDebug("Renaming %s to %s", qPrintable(old_name), qPrintable(new_name)); qDebug("Renaming %s to %s", qPrintable(old_name), qPrintable(new_name));
// Rename file in files_path // Rename file in files_path
files_path.replace(file_index, new_name); files_path.replace(file_index, new_name);
@ -356,11 +361,11 @@ public slots:
path_items.prepend(parent.data().toString()); path_items.prepend(parent.data().toString());
parent = PropListModel->parent(parent); parent = PropListModel->parent(parent);
} }
const QString &old_path = path_items.join(QDir::separator()); const QString &old_path = path_items.join("/");
path_items.removeLast(); path_items.removeLast();
path_items << new_name_last; path_items << new_name_last;
QString new_path = path_items.join(QDir::separator()); QString new_path = path_items.join("/");
if(!new_path.endsWith(QDir::separator())) new_path += QDir::separator(); if(!new_path.endsWith("/")) new_path += "/";
// Check for overwriting // Check for overwriting
for(uint i=0; i<nbFiles; ++i) { for(uint i=0; i<nbFiles; ++i) {
const QString &current_name = files_path.at(i); const QString &current_name = files_path.at(i);
@ -381,6 +386,7 @@ public slots:
if(current_name.startsWith(old_path)) { if(current_name.startsWith(old_path)) {
QString new_name = current_name; QString new_name = current_name;
new_name.replace(0, old_path.length(), new_path); new_name.replace(0, old_path.length(), new_path);
new_name = QDir::cleanPath(new_name);
qDebug("Rename %s to %s", qPrintable(current_name), qPrintable(new_name)); qDebug("Rename %s to %s", qPrintable(current_name), qPrintable(new_name));
// Rename in files_path // Rename in files_path
files_path.replace(i, new_name); files_path.replace(i, new_name);

2
src/torrentfilesmodel.h

@ -510,7 +510,7 @@ public:
TreeItem *parent = this->rootItem; TreeItem *parent = this->rootItem;
/*if(t.num_files() == 1) { /*if(t.num_files() == 1) {
// Create possible parent folder // Create possible parent folder
QStringList path_parts = misc::toQStringU(t.file_at(0).path.string()).split("/"); QStringList path_parts = misc::toQStringU(t.file_at(0).path.string()).split("/", QString::SkipEmptyParts);
path_parts.removeLast(); path_parts.removeLast();
foreach(const QString &part, path_parts) { foreach(const QString &part, path_parts) {
TreeItem *folder = new TreeItem(part, parent); TreeItem *folder = new TreeItem(part, parent);

Loading…
Cancel
Save