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 @@ -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()));
@ -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..."));
@ -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);

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));
}
}

Loading…
Cancel
Save