Browse Source

Update dialogs

adaptive-webui-19844
Nick Tiskov 11 years ago
parent
commit
6e77d12ac6
  1. 13
      src/addnewtorrentdialog.cpp
  2. 20
      src/torrentcreator/torrentcreatordlg.cpp
  3. 14
      src/torrentcreator/torrentcreatorthread.cpp
  4. 33
      src/torrentimportdlg.cpp

13
src/addnewtorrentdialog.cpp

@ -192,7 +192,7 @@ bool AddNewTorrentDialog::loadTorrent(const QString& torrent_path, const QString
m_hasMetadata = true; m_hasMetadata = true;
try { 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()); m_hash = misc::toQString(m_torrentInfo->info_hash());
} catch(const std::exception& e) { } catch(const std::exception& e) {
QMessageBox::critical(0, tr("Invalid torrent"), tr("Failed to load the torrent: %1").arg(e.what())); QMessageBox::critical(0, tr("Invalid torrent"), tr("Failed to load the torrent: %1").arg(e.what()));
@ -281,9 +281,8 @@ bool AddNewTorrentDialog::loadMagnet(const QString &magnet_uri)
// Set dialog position // Set dialog position
setdialogPosition(); setdialogPosition();
Preferences pref;
// Override save path // 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); HiddenData::addData(m_hash);
QBtSession::instance()->addMagnetUri(m_url, false); QBtSession::instance()->addMagnetUri(m_url, false);
setMetadataProgressIndicator(true, tr("Retrieving metadata...")); setMetadataProgressIndicator(true, tr("Retrieving metadata..."));
@ -440,8 +439,7 @@ void AddNewTorrentDialog::renameSelectedFile()
if (m_contentModel->itemType(index) == TorrentContentModelItem::FileType) { if (m_contentModel->itemType(index) == TorrentContentModelItem::FileType) {
// File renaming // File renaming
const int file_index = m_contentModel->getFileIndex(index); const int file_index = m_contentModel->getFileIndex(index);
QString old_name = m_filesPath.at(file_index); QString old_name = fsutils::fromNativePath(m_filesPath.at(file_index));
old_name.replace("\\", "/");
qDebug("Old name: %s", qPrintable(old_name)); qDebug("Old name: %s", qPrintable(old_name));
QStringList path_items = old_name.split("/"); QStringList path_items = old_name.split("/");
path_items.removeLast(); path_items.removeLast();
@ -451,7 +449,7 @@ void AddNewTorrentDialog::renameSelectedFile()
qDebug("Name did not change"); qDebug("Name did not change");
return; return;
} }
new_name = QDir::cleanPath(new_name); new_name = fsutils::expandPathAbs(new_name);
qDebug("New name: %s", qPrintable(new_name)); qDebug("New name: %s", qPrintable(new_name));
// Check if that name is already used // Check if that name is already used
for (int i=0; i<m_torrentInfo->num_files(); ++i) { for (int i=0; i<m_torrentInfo->num_files(); ++i) {
@ -464,7 +462,6 @@ void AddNewTorrentDialog::renameSelectedFile()
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
m_filesPath.replace(file_index, new_name); m_filesPath.replace(file_index, new_name);
@ -505,7 +502,7 @@ void AddNewTorrentDialog::renameSelectedFile()
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); new_name = fsutils::expandPathAbs(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
m_filesPath.replace(i, new_name); m_filesPath.replace(i, new_name);

20
src/torrentcreator/torrentcreatordlg.cpp

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

14
src/torrentcreator/torrentcreatorthread.cpp

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

33
src/torrentimportdlg.cpp

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

Loading…
Cancel
Save