|
|
@ -58,7 +58,7 @@ |
|
|
|
using namespace libtorrent; |
|
|
|
using namespace libtorrent; |
|
|
|
|
|
|
|
|
|
|
|
PropertiesWidget::PropertiesWidget(QWidget *parent, MainWindow* main_window, TransferListWidget *transferList): |
|
|
|
PropertiesWidget::PropertiesWidget(QWidget *parent, MainWindow* main_window, TransferListWidget *transferList): |
|
|
|
QWidget(parent), transferList(transferList), main_window(main_window) { |
|
|
|
QWidget(parent), transferList(transferList), main_window(main_window) { |
|
|
|
|
|
|
|
|
|
|
|
setupUi(this); |
|
|
|
setupUi(this); |
|
|
|
state = VISIBLE; |
|
|
|
state = VISIBLE; |
|
|
@ -565,192 +565,190 @@ void PropertiesWidget::renameSelectedFile() { |
|
|
|
#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(h.filepath_at(i).compare(new_name, Qt::CaseSensitive) == 0) { |
|
|
|
if(h.filepath_at(i).compare(new_name, Qt::CaseSensitive) == 0) { |
|
|
|
#else |
|
|
|
#else |
|
|
|
if(h.filepath_at(i).compare(new_name, Qt::CaseInsensitive) == 0) { |
|
|
|
if(h.filepath_at(i).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"), |
|
|
|
tr("This name is already in use in this folder. Please use a different name."), |
|
|
|
tr("This name is already in use in this folder. Please use a different name."), |
|
|
|
QMessageBox::Ok); |
|
|
|
QMessageBox::Ok); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
const bool force_recheck = QFile::exists(h.save_path()+QDir::separator()+new_name); |
|
|
|
|
|
|
|
qDebug("Renaming %s to %s", qPrintable(old_name), qPrintable(new_name)); |
|
|
|
|
|
|
|
h.rename_file(file_index, new_name); |
|
|
|
|
|
|
|
// Force recheck
|
|
|
|
|
|
|
|
if(force_recheck) h.force_recheck(); |
|
|
|
|
|
|
|
// Rename if torrent files model too
|
|
|
|
|
|
|
|
if(new_name_last.endsWith(".!qB")) |
|
|
|
|
|
|
|
new_name_last.chop(4); |
|
|
|
|
|
|
|
PropListModel->setData(index, new_name_last); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
// Folder renaming
|
|
|
|
|
|
|
|
QStringList path_items; |
|
|
|
|
|
|
|
path_items << index.data().toString(); |
|
|
|
|
|
|
|
QModelIndex parent = PropListModel->parent(index); |
|
|
|
|
|
|
|
while(parent.isValid()) { |
|
|
|
|
|
|
|
path_items.prepend(parent.data().toString()); |
|
|
|
|
|
|
|
parent = PropListModel->parent(parent); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
const QString old_path = path_items.join("/"); |
|
|
|
} |
|
|
|
path_items.removeLast(); |
|
|
|
const bool force_recheck = QFile::exists(h.save_path()+QDir::separator()+new_name); |
|
|
|
path_items << new_name_last; |
|
|
|
qDebug("Renaming %s to %s", qPrintable(old_name), qPrintable(new_name)); |
|
|
|
QString new_path = path_items.join("/"); |
|
|
|
h.rename_file(file_index, new_name); |
|
|
|
if(!new_path.endsWith("/")) new_path += "/"; |
|
|
|
// Force recheck
|
|
|
|
// Check for overwriting
|
|
|
|
if(force_recheck) h.force_recheck(); |
|
|
|
const int num_files = h.num_files(); |
|
|
|
// Rename if torrent files model too
|
|
|
|
for(int i=0; i<num_files; ++i) { |
|
|
|
if(new_name_last.endsWith(".!qB")) |
|
|
|
const QString current_name = h.filepath_at(i); |
|
|
|
new_name_last.chop(4); |
|
|
|
|
|
|
|
PropListModel->setData(index, new_name_last); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
// Folder renaming
|
|
|
|
|
|
|
|
QStringList path_items; |
|
|
|
|
|
|
|
path_items << index.data().toString(); |
|
|
|
|
|
|
|
QModelIndex parent = PropListModel->parent(index); |
|
|
|
|
|
|
|
while(parent.isValid()) { |
|
|
|
|
|
|
|
path_items.prepend(parent.data().toString()); |
|
|
|
|
|
|
|
parent = PropListModel->parent(parent); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
const QString old_path = path_items.join("/"); |
|
|
|
|
|
|
|
path_items.removeLast(); |
|
|
|
|
|
|
|
path_items << new_name_last; |
|
|
|
|
|
|
|
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 = h.filepath_at(i); |
|
|
|
#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 |
|
|
|
if(current_name.startsWith(new_path, Qt::CaseInsensitive)) { |
|
|
|
if(current_name.startsWith(new_path, Qt::CaseInsensitive)) { |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
QMessageBox::warning(this, tr("The folder could not be renamed"), |
|
|
|
QMessageBox::warning(this, tr("The folder could not be renamed"), |
|
|
|
tr("This name is already in use in this folder. Please use a different name."), |
|
|
|
tr("This name is already in use in this folder. Please use a different name."), |
|
|
|
QMessageBox::Ok); |
|
|
|
QMessageBox::Ok); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
bool force_recheck = false; |
|
|
|
|
|
|
|
// Replace path in all files
|
|
|
|
|
|
|
|
for(int i=0; i<num_files; ++i) { |
|
|
|
|
|
|
|
const QString current_name = h.filepath_at(i); |
|
|
|
|
|
|
|
if(current_name.startsWith(old_path)) { |
|
|
|
|
|
|
|
QString new_name = current_name; |
|
|
|
|
|
|
|
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); |
|
|
|
|
|
|
|
qDebug("Rename %s to %s", qPrintable(current_name), qPrintable(new_name)); |
|
|
|
|
|
|
|
h.rename_file(i, new_name); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// Force recheck
|
|
|
|
|
|
|
|
if(force_recheck) h.force_recheck(); |
|
|
|
|
|
|
|
// Rename folder in torrent files model too
|
|
|
|
|
|
|
|
PropListModel->setData(index, new_name_last); |
|
|
|
|
|
|
|
// Remove old folder
|
|
|
|
|
|
|
|
const QDir old_folder(h.save_path()+"/"+old_path); |
|
|
|
|
|
|
|
int timeout = 10; |
|
|
|
|
|
|
|
while(!misc::removeEmptyTree(old_folder.absolutePath()) && timeout > 0) { |
|
|
|
|
|
|
|
SleeperThread::msleep(100); |
|
|
|
|
|
|
|
--timeout; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
bool force_recheck = false; |
|
|
|
|
|
|
|
// Replace path in all files
|
|
|
|
void PropertiesWidget::askWebSeed(){ |
|
|
|
for(int i=0; i<num_files; ++i) { |
|
|
|
bool ok; |
|
|
|
const QString current_name = h.filepath_at(i); |
|
|
|
// Ask user for a new url seed
|
|
|
|
if(current_name.startsWith(old_path)) { |
|
|
|
const QString url_seed = QInputDialog::getText(this, tr("New url seed", "New HTTP source"), |
|
|
|
QString new_name = current_name; |
|
|
|
tr("New url seed:"), QLineEdit::Normal, |
|
|
|
new_name.replace(0, old_path.length(), new_path); |
|
|
|
QString::fromUtf8("http://www."), &ok); |
|
|
|
if(!force_recheck && QDir(h.save_path()).exists(new_name)) |
|
|
|
if(!ok) return; |
|
|
|
force_recheck = true; |
|
|
|
qDebug("Adding %s web seed", qPrintable(url_seed)); |
|
|
|
new_name = QDir::cleanPath(new_name); |
|
|
|
if(!listWebSeeds->findItems(url_seed, Qt::MatchFixedString).empty()) { |
|
|
|
qDebug("Rename %s to %s", qPrintable(current_name), qPrintable(new_name)); |
|
|
|
QMessageBox::warning(this, tr("qBittorrent"), |
|
|
|
h.rename_file(i, new_name); |
|
|
|
tr("This url seed is already in the list."), |
|
|
|
} |
|
|
|
QMessageBox::Ok); |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
h.add_url_seed(url_seed); |
|
|
|
|
|
|
|
// Refresh the seeds list
|
|
|
|
|
|
|
|
loadUrlSeeds(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void PropertiesWidget::deleteSelectedUrlSeeds(){ |
|
|
|
|
|
|
|
const QList<QListWidgetItem *> selectedItems = listWebSeeds->selectedItems(); |
|
|
|
|
|
|
|
bool change = false; |
|
|
|
|
|
|
|
foreach(const QListWidgetItem *item, selectedItems){ |
|
|
|
|
|
|
|
QString url_seed = item->text(); |
|
|
|
|
|
|
|
h.remove_url_seed(url_seed); |
|
|
|
|
|
|
|
change = true; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
if(change){ |
|
|
|
// Force recheck
|
|
|
|
// Refresh list
|
|
|
|
if(force_recheck) h.force_recheck(); |
|
|
|
loadUrlSeeds(); |
|
|
|
// Rename folder in torrent files model too
|
|
|
|
|
|
|
|
PropListModel->setData(index, new_name_last); |
|
|
|
|
|
|
|
// Remove old folder
|
|
|
|
|
|
|
|
const QDir old_folder(h.save_path()+"/"+old_path); |
|
|
|
|
|
|
|
int timeout = 10; |
|
|
|
|
|
|
|
while(!misc::removeEmptyTree(old_folder.absolutePath()) && timeout > 0) { |
|
|
|
|
|
|
|
SleeperThread::msleep(100); |
|
|
|
|
|
|
|
--timeout; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool PropertiesWidget::applyPriorities() { |
|
|
|
void PropertiesWidget::askWebSeed(){ |
|
|
|
qDebug("Saving files priorities"); |
|
|
|
bool ok; |
|
|
|
const std::vector<int> priorities = PropListModel->getFilesPriorities(h.get_torrent_info().num_files()); |
|
|
|
// Ask user for a new url seed
|
|
|
|
bool first_last_piece_first = false; |
|
|
|
const QString url_seed = QInputDialog::getText(this, tr("New url seed", "New HTTP source"), |
|
|
|
// Save first/last piece first option state
|
|
|
|
tr("New url seed:"), QLineEdit::Normal, |
|
|
|
if(h.first_last_piece_first()) |
|
|
|
QString::fromUtf8("http://www."), &ok); |
|
|
|
first_last_piece_first = true; |
|
|
|
if(!ok) return; |
|
|
|
// Prioritize the files
|
|
|
|
qDebug("Adding %s web seed", qPrintable(url_seed)); |
|
|
|
qDebug("prioritize files: %d", priorities[0]); |
|
|
|
if(!listWebSeeds->findItems(url_seed, Qt::MatchFixedString).empty()) { |
|
|
|
h.prioritize_files(priorities); |
|
|
|
QMessageBox::warning(this, tr("qBittorrent"), |
|
|
|
// Restore first/last piece first option if necessary
|
|
|
|
tr("This url seed is already in the list."), |
|
|
|
if(first_last_piece_first) |
|
|
|
QMessageBox::Ok); |
|
|
|
h.prioritize_first_last_piece(true); |
|
|
|
return; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
h.add_url_seed(url_seed); |
|
|
|
|
|
|
|
// Refresh the seeds list
|
|
|
|
|
|
|
|
loadUrlSeeds(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void PropertiesWidget::deleteSelectedUrlSeeds(){ |
|
|
|
|
|
|
|
const QList<QListWidgetItem *> selectedItems = listWebSeeds->selectedItems(); |
|
|
|
|
|
|
|
bool change = false; |
|
|
|
|
|
|
|
foreach(const QListWidgetItem *item, selectedItems){ |
|
|
|
|
|
|
|
QString url_seed = item->text(); |
|
|
|
|
|
|
|
h.remove_url_seed(url_seed); |
|
|
|
|
|
|
|
change = true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if(change){ |
|
|
|
|
|
|
|
// Refresh list
|
|
|
|
|
|
|
|
loadUrlSeeds(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool PropertiesWidget::applyPriorities() { |
|
|
|
|
|
|
|
qDebug("Saving files priorities"); |
|
|
|
|
|
|
|
const std::vector<int> priorities = PropListModel->getFilesPriorities(h.get_torrent_info().num_files()); |
|
|
|
|
|
|
|
// Save first/last piece first option state
|
|
|
|
|
|
|
|
bool first_last_piece_first = h.first_last_piece_first(); |
|
|
|
|
|
|
|
// Prioritize the files
|
|
|
|
|
|
|
|
qDebug("prioritize files: %d", priorities[0]); |
|
|
|
|
|
|
|
h.prioritize_files(priorities); |
|
|
|
|
|
|
|
// Restore first/last piece first option if necessary
|
|
|
|
|
|
|
|
if(first_last_piece_first) |
|
|
|
|
|
|
|
h.prioritize_first_last_piece(true); |
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void PropertiesWidget::on_changeSavePathButton_clicked() { |
|
|
|
|
|
|
|
if(!h.is_valid()) return; |
|
|
|
void PropertiesWidget::on_changeSavePathButton_clicked() { |
|
|
|
QString new_path; |
|
|
|
if(!h.is_valid()) return; |
|
|
|
if(h.has_metadata() && h.num_files() == 1) { |
|
|
|
QString new_path; |
|
|
|
new_path = QFileDialog::getSaveFileName(this, tr("Choose save path"), h.firstFileSavePath()); |
|
|
|
if(h.has_metadata() && h.num_files() == 1) { |
|
|
|
} else { |
|
|
|
new_path = QFileDialog::getSaveFileName(this, tr("Choose save path"), h.firstFileSavePath()); |
|
|
|
const QDir saveDir(TorrentPersistentData::getSavePath(h.hash())); |
|
|
|
} else { |
|
|
|
QFileDialog dlg(this, tr("Choose save path"), saveDir.absolutePath()); |
|
|
|
const QDir saveDir(TorrentPersistentData::getSavePath(h.hash())); |
|
|
|
dlg.setConfirmOverwrite(false); |
|
|
|
QFileDialog dlg(this, tr("Choose save path"), saveDir.absolutePath()); |
|
|
|
dlg.setFileMode(QFileDialog::Directory); |
|
|
|
dlg.setConfirmOverwrite(false); |
|
|
|
dlg.setOption(QFileDialog::ShowDirsOnly, true); |
|
|
|
dlg.setFileMode(QFileDialog::Directory); |
|
|
|
dlg.setFilter(QDir::AllDirs); |
|
|
|
dlg.setOption(QFileDialog::ShowDirsOnly, true); |
|
|
|
dlg.setAcceptMode(QFileDialog::AcceptSave); |
|
|
|
dlg.setFilter(QDir::AllDirs); |
|
|
|
dlg.setNameFilterDetailsVisible(false); |
|
|
|
dlg.setAcceptMode(QFileDialog::AcceptSave); |
|
|
|
if(dlg.exec()) |
|
|
|
dlg.setNameFilterDetailsVisible(false); |
|
|
|
new_path = dlg.selectedFiles().first(); |
|
|
|
if(dlg.exec()) |
|
|
|
} |
|
|
|
new_path = dlg.selectedFiles().first(); |
|
|
|
if(!new_path.isEmpty()){ |
|
|
|
} |
|
|
|
// Check if savePath exists
|
|
|
|
if(!new_path.isEmpty()){ |
|
|
|
QString save_path_dir = new_path.replace("\\", "/"); |
|
|
|
// Check if savePath exists
|
|
|
|
QString new_file_name; |
|
|
|
QString save_path_dir = new_path.replace("\\", "/"); |
|
|
|
if(h.has_metadata() && h.num_files() == 1) { |
|
|
|
QString new_file_name; |
|
|
|
QStringList parts = save_path_dir.split("/"); |
|
|
|
if(h.has_metadata() && h.num_files() == 1) { |
|
|
|
new_file_name = parts.takeLast(); // Skip file name
|
|
|
|
QStringList parts = save_path_dir.split("/"); |
|
|
|
save_path_dir = parts.join("/"); |
|
|
|
new_file_name = parts.takeLast(); // Skip file name
|
|
|
|
} |
|
|
|
save_path_dir = parts.join("/"); |
|
|
|
QDir savePath(misc::expandPath(save_path_dir)); |
|
|
|
} |
|
|
|
// Actually move storage
|
|
|
|
QDir savePath(misc::expandPath(save_path_dir)); |
|
|
|
if(!QBtSession::instance()->useTemporaryFolder() || h.is_seed()) { |
|
|
|
// Actually move storage
|
|
|
|
if(!savePath.exists()) savePath.mkpath(savePath.absolutePath()); |
|
|
|
if(!QBtSession::instance()->useTemporaryFolder() || h.is_seed()) { |
|
|
|
h.move_storage(savePath.absolutePath()); |
|
|
|
if(!savePath.exists()) savePath.mkpath(savePath.absolutePath()); |
|
|
|
} |
|
|
|
h.move_storage(savePath.absolutePath()); |
|
|
|
// Update save_path in dialog
|
|
|
|
} |
|
|
|
QString display_path; |
|
|
|
// Update save_path in dialog
|
|
|
|
if(h.has_metadata() && h.num_files() == 1) { |
|
|
|
QString display_path; |
|
|
|
// Rename the file
|
|
|
|
if(h.has_metadata() && h.num_files() == 1) { |
|
|
|
Q_ASSERT(!new_file_name.isEmpty()); |
|
|
|
// Rename the file
|
|
|
|
|
|
|
|
Q_ASSERT(!new_file_name.isEmpty()); |
|
|
|
#if defined(Q_WS_WIN) || defined(Q_OS_OS2) |
|
|
|
#if defined(Q_WS_WIN) || defined(Q_OS_OS2) |
|
|
|
if(h.filename_at(0).compare(new_file_name, Qt::CaseInsensitive) != 0) { |
|
|
|
if(h.filename_at(0).compare(new_file_name, Qt::CaseInsensitive) != 0) { |
|
|
|
#else |
|
|
|
#else |
|
|
|
if(h.filename_at(0).compare(new_file_name, Qt::CaseSensitive) != 0) { |
|
|
|
if(h.filename_at(0).compare(new_file_name, Qt::CaseSensitive) != 0) { |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
qDebug("Renaming single file to %s", qPrintable(new_file_name)); |
|
|
|
qDebug("Renaming single file to %s", qPrintable(new_file_name)); |
|
|
|
h.rename_file(0, new_file_name); |
|
|
|
h.rename_file(0, new_file_name); |
|
|
|
// Also rename it in the files list model
|
|
|
|
// Also rename it in the files list model
|
|
|
|
PropListModel->setData(PropListModel->index(0, 0), new_file_name); |
|
|
|
PropListModel->setData(PropListModel->index(0, 0), new_file_name); |
|
|
|
} |
|
|
|
|
|
|
|
display_path = h.firstFileSavePath(); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
display_path = savePath.absolutePath(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
#if defined(Q_WS_WIN) || defined(Q_OS_OS2) |
|
|
|
|
|
|
|
display_path = display_path.replace("/", "\\"); |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
save_path->setText(display_path); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
display_path = h.firstFileSavePath(); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
display_path = savePath.absolutePath(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
#if defined(Q_WS_WIN) || defined(Q_OS_OS2) |
|
|
|
|
|
|
|
display_path = display_path.replace("/", "\\"); |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
save_path->setText(display_path); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void PropertiesWidget::filteredFilesChanged() { |
|
|
|
void PropertiesWidget::filteredFilesChanged() { |
|
|
|
if(h.is_valid()) { |
|
|
|
if(h.is_valid()) { |
|
|
|
applyPriorities(); |
|
|
|
applyPriorities(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|