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 @@ -971,7 +971,7 @@ QTorrentHandle Bittorrent::addTorrent(QString path, bool fromScanDir, QString fr
qDebug("Adding %s to download list", qPrintable(file));
try {
// Getting torrent file informations
t = new torrent_info(file.toLocal8Bit().constData());
t = new torrent_info(file.toUtf8().constData());
if(!t->is_valid())
throw std::exception();
} catch(std::exception&) {
@ -1141,9 +1141,20 @@ QTorrentHandle Bittorrent::addTorrent(QString path, bool fromScanDir, QString fr @@ -1141,9 +1141,20 @@ QTorrentHandle Bittorrent::addTorrent(QString path, bool fromScanDir, QString fr
bool force_recheck = false;
if(files_path.size() == h.num_files()) {
for(int i=0; i<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);
if(!force_recheck && QFile::exists(h.save_path()+QDir::separator()+path))
if(!force_recheck && QDir(h.save_path()).exists(path))
force_recheck = true;
qDebug("Renaming file to %s", qPrintable(path));
h.rename_file(i, path);
}
// Force recheck
@ -1577,7 +1588,7 @@ void Bittorrent::addConsoleMessage(QString msg, QString) { @@ -1577,7 +1588,7 @@ void Bittorrent::addConsoleMessage(QString msg, QString) {
foreach(const QString &file, pathList) {
qDebug("File %s added", qPrintable(file));
try {
torrent_info t(file.toLocal8Bit().constData());
torrent_info t(file.toUtf8().constData());
if(t.is_valid())
addTorrent(file, true);
} catch(std::exception&) {
@ -1893,12 +1904,12 @@ void Bittorrent::addConsoleMessage(QString msg, QString) { @@ -1893,12 +1904,12 @@ void Bittorrent::addConsoleMessage(QString msg, QString) {
void Bittorrent::recursiveTorrentDownload(const QTorrentHandle &h) {
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")) {
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;
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());
// Passing the save path along to the sub torrent file
TorrentTempData::setSavePath(sub_hash, h.save_path());
@ -1947,7 +1958,7 @@ void Bittorrent::addConsoleMessage(QString msg, QString) { @@ -1947,7 +1958,7 @@ void Bittorrent::addConsoleMessage(QString msg, QString) {
const QString torrent_fullpath = h.save_path()+QDir::separator()+torrent_relpath;
qDebug("Full subtorrent path is %s", qPrintable(torrent_fullpath));
try {
boost::intrusive_ptr<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()) {
qDebug("emitting recursiveTorrentDownloadPossible()");
emit recursiveTorrentDownloadPossible(h);

2
src/createtorrent_imp.cpp

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

1
src/misc.h

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

27
src/propertieswidget.cpp

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

20
src/torrentadditiondlg.h

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

2
src/torrentfilesmodel.h

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

Loading…
Cancel
Save