|
|
|
@ -51,15 +51,15 @@
@@ -51,15 +51,15 @@
|
|
|
|
|
|
|
|
|
|
using namespace libtorrent; |
|
|
|
|
|
|
|
|
|
AddNewTorrentDialog::AddNewTorrentDialog(QWidget *parent) : |
|
|
|
|
QDialog(parent), |
|
|
|
|
ui(new Ui::AddNewTorrentDialog), |
|
|
|
|
m_contentModel(0), |
|
|
|
|
m_contentDelegate(0), |
|
|
|
|
m_isMagnet(false), |
|
|
|
|
m_hasMetadata(false), |
|
|
|
|
m_hasRenamedFile(false), |
|
|
|
|
m_oldIndex(0) |
|
|
|
|
AddNewTorrentDialog::AddNewTorrentDialog(QWidget *parent) |
|
|
|
|
: QDialog(parent) |
|
|
|
|
, ui(new Ui::AddNewTorrentDialog) |
|
|
|
|
, m_contentModel(0) |
|
|
|
|
, m_contentDelegate(0) |
|
|
|
|
, m_isMagnet(false) |
|
|
|
|
, m_hasMetadata(false) |
|
|
|
|
, m_hasRenamedFile(false) |
|
|
|
|
, m_oldIndex(0) |
|
|
|
|
{ |
|
|
|
|
ui->setupUi(this); |
|
|
|
|
setAttribute(Qt::WA_DeleteOnClose); |
|
|
|
@ -77,9 +77,8 @@ AddNewTorrentDialog::AddNewTorrentDialog(QWidget *parent) :
@@ -77,9 +77,8 @@ AddNewTorrentDialog::AddNewTorrentDialog(QWidget *parent) :
|
|
|
|
|
// Load labels
|
|
|
|
|
const QStringList customLabels = pref->getTorrentLabels(); |
|
|
|
|
ui->label_combo->addItem(""); |
|
|
|
|
foreach (const QString& label, customLabels) { |
|
|
|
|
foreach (const QString& label, customLabels) |
|
|
|
|
ui->label_combo->addItem(label); |
|
|
|
|
} |
|
|
|
|
ui->label_combo->model()->sort(0); |
|
|
|
|
ui->content_tree->header()->setSortIndicator(0, Qt::AscendingOrder); |
|
|
|
|
loadState(); |
|
|
|
@ -140,7 +139,8 @@ void AddNewTorrentDialog::showMagnet(const QString& link, QWidget *parent)
@@ -140,7 +139,8 @@ void AddNewTorrentDialog::showMagnet(const QString& link, QWidget *parent)
|
|
|
|
|
delete dlg; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void AddNewTorrentDialog::showEvent(QShowEvent *event) { |
|
|
|
|
void AddNewTorrentDialog::showEvent(QShowEvent *event) |
|
|
|
|
{ |
|
|
|
|
QDialog::showEvent(event); |
|
|
|
|
Preferences* const pref = Preferences::instance(); |
|
|
|
|
if (!pref->additionDialogFront()) |
|
|
|
@ -159,12 +159,14 @@ void AddNewTorrentDialog::showAdvancedSettings(bool show)
@@ -159,12 +159,14 @@ void AddNewTorrentDialog::showAdvancedSettings(bool show)
|
|
|
|
|
if (m_hasMetadata && (m_torrentInfo->num_files() > 1)) { |
|
|
|
|
ui->content_tree->setVisible(true); |
|
|
|
|
setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); |
|
|
|
|
} else { |
|
|
|
|
} |
|
|
|
|
else { |
|
|
|
|
ui->content_tree->setVisible(false); |
|
|
|
|
setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); |
|
|
|
|
} |
|
|
|
|
static_cast<QVBoxLayout*>(layout())->insertWidget(layout()->indexOf(ui->never_show_cb) + 1, ui->adv_button); |
|
|
|
|
} else { |
|
|
|
|
} |
|
|
|
|
else { |
|
|
|
|
ui->adv_button->setText(QString::fromUtf8("▼")); |
|
|
|
|
ui->settings_group->setVisible(false); |
|
|
|
|
ui->info_group->setVisible(false); |
|
|
|
@ -273,10 +275,9 @@ void AddNewTorrentDialog::saveSavePathHistory() const
@@ -273,10 +275,9 @@ void AddNewTorrentDialog::saveSavePathHistory() const
|
|
|
|
|
int AddNewTorrentDialog::indexOfSavePath(const QString &save_path) |
|
|
|
|
{ |
|
|
|
|
QDir saveDir(save_path); |
|
|
|
|
for(int i=0; i<ui->save_path_combo->count()-1; ++i) { |
|
|
|
|
for(int i = 0; i<ui->save_path_combo->count() - 1; ++i) |
|
|
|
|
if (QDir(ui->save_path_combo->itemData(i).toString()) == saveDir) |
|
|
|
|
return i; |
|
|
|
|
} |
|
|
|
|
return -1; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -288,7 +289,8 @@ void AddNewTorrentDialog::updateFileNameInSavePaths(const QString &new_filename)
@@ -288,7 +289,8 @@ void AddNewTorrentDialog::updateFileNameInSavePaths(const QString &new_filename)
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void AddNewTorrentDialog::updateDiskSpaceLabel() { |
|
|
|
|
void AddNewTorrentDialog::updateDiskSpaceLabel() |
|
|
|
|
{ |
|
|
|
|
// Determine torrent size
|
|
|
|
|
qulonglong torrent_size = 0; |
|
|
|
|
|
|
|
|
@ -296,11 +298,11 @@ void AddNewTorrentDialog::updateDiskSpaceLabel() {
@@ -296,11 +298,11 @@ void AddNewTorrentDialog::updateDiskSpaceLabel() {
|
|
|
|
|
if (m_contentModel) { |
|
|
|
|
const std::vector<int> priorities = m_contentModel->model()->getFilesPriorities(); |
|
|
|
|
Q_ASSERT(priorities.size() == (uint) m_torrentInfo->num_files()); |
|
|
|
|
for (uint i=0; i<priorities.size(); ++i) { |
|
|
|
|
for (uint i = 0; i<priorities.size(); ++i) |
|
|
|
|
if (priorities[i] > 0) |
|
|
|
|
torrent_size += m_torrentInfo->files().file_size(i); |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
else { |
|
|
|
|
torrent_size = m_torrentInfo->total_size(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -339,7 +341,8 @@ void AddNewTorrentDialog::browseButton_clicked()
@@ -339,7 +341,8 @@ void AddNewTorrentDialog::browseButton_clicked()
|
|
|
|
|
new_path = fsutils::branchPath(new_path, &new_filename); |
|
|
|
|
qDebug() << "new_path: " << new_path; |
|
|
|
|
qDebug() << "new_filename: " << new_filename; |
|
|
|
|
} else { |
|
|
|
|
} |
|
|
|
|
else { |
|
|
|
|
if (!cur_save_path.isEmpty() && QDir(cur_save_path).exists()) |
|
|
|
|
new_path = QFileDialog::getExistingDirectory(this, tr("Choose save path"), cur_save_path); |
|
|
|
|
else |
|
|
|
@ -347,8 +350,9 @@ void AddNewTorrentDialog::browseButton_clicked()
@@ -347,8 +350,9 @@ void AddNewTorrentDialog::browseButton_clicked()
|
|
|
|
|
} |
|
|
|
|
if (!new_path.isEmpty()) { |
|
|
|
|
const int existing_index = indexOfSavePath(new_path); |
|
|
|
|
if (existing_index >= 0) |
|
|
|
|
if (existing_index >= 0) { |
|
|
|
|
ui->save_path_combo->setCurrentIndex(existing_index); |
|
|
|
|
} |
|
|
|
|
else { |
|
|
|
|
// New path, prepend to combo box
|
|
|
|
|
if (!new_filename.isEmpty()) |
|
|
|
@ -365,7 +369,8 @@ void AddNewTorrentDialog::browseButton_clicked()
@@ -365,7 +369,8 @@ void AddNewTorrentDialog::browseButton_clicked()
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
onSavePathChanged(0); |
|
|
|
|
} else { |
|
|
|
|
} |
|
|
|
|
else { |
|
|
|
|
// Restore index
|
|
|
|
|
ui->save_path_combo->setCurrentIndex(m_oldIndex); |
|
|
|
|
} |
|
|
|
@ -435,7 +440,8 @@ void AddNewTorrentDialog::renameSelectedFile()
@@ -435,7 +440,8 @@ void AddNewTorrentDialog::renameSelectedFile()
|
|
|
|
|
m_hasRenamedFile = true; |
|
|
|
|
// Rename in torrent files model too
|
|
|
|
|
m_contentModel->setData(index, new_name_last); |
|
|
|
|
} else { |
|
|
|
|
} |
|
|
|
|
else { |
|
|
|
|
// Folder renaming
|
|
|
|
|
QStringList path_items; |
|
|
|
|
path_items << index.data().toString(); |
|
|
|
@ -490,7 +496,8 @@ void AddNewTorrentDialog::setdialogPosition()
@@ -490,7 +496,8 @@ void AddNewTorrentDialog::setdialogPosition()
|
|
|
|
|
int y = Preferences::instance()->getAddNewTorrentDialogPos(); |
|
|
|
|
if (y >= 0) { |
|
|
|
|
center.setY(y); |
|
|
|
|
} else { |
|
|
|
|
} |
|
|
|
|
else { |
|
|
|
|
center.ry() -= 120; |
|
|
|
|
if (center.y() < 0) |
|
|
|
|
center.setY(0); |
|
|
|
@ -503,13 +510,13 @@ void AddNewTorrentDialog::loadSavePathHistory()
@@ -503,13 +510,13 @@ void AddNewTorrentDialog::loadSavePathHistory()
|
|
|
|
|
QDir default_save_path(Preferences::instance()->getSavePath()); |
|
|
|
|
// Load save path history
|
|
|
|
|
QStringList raw_path_history = Preferences::instance()->getAddNewTorrentDialogPathHistory(); |
|
|
|
|
foreach (const QString &sp, raw_path_history) { |
|
|
|
|
foreach (const QString &sp, raw_path_history) |
|
|
|
|
if (QDir(sp) != default_save_path) |
|
|
|
|
ui->save_path_combo->addItem(fsutils::toNativePath(sp), sp); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void AddNewTorrentDialog::displayContentTreeMenu(const QPoint&) { |
|
|
|
|
void AddNewTorrentDialog::displayContentTreeMenu(const QPoint&) |
|
|
|
|
{ |
|
|
|
|
QMenu myFilesLlistMenu; |
|
|
|
|
const QModelIndexList selectedRows = ui->content_tree->selectionModel()->selectedRows(0); |
|
|
|
|
QAction *actRename = 0; |
|
|
|
@ -529,18 +536,19 @@ void AddNewTorrentDialog::displayContentTreeMenu(const QPoint&) {
@@ -529,18 +536,19 @@ void AddNewTorrentDialog::displayContentTreeMenu(const QPoint&) {
|
|
|
|
|
if (act) { |
|
|
|
|
if (act == actRename) { |
|
|
|
|
renameSelectedFile(); |
|
|
|
|
} else { |
|
|
|
|
} |
|
|
|
|
else { |
|
|
|
|
int prio = prio::NORMAL; |
|
|
|
|
if (act == ui->actionHigh) |
|
|
|
|
if (act == ui->actionHigh) { |
|
|
|
|
prio = prio::HIGH; |
|
|
|
|
} |
|
|
|
|
else { |
|
|
|
|
if (act == ui->actionMaximum) { |
|
|
|
|
if (act == ui->actionMaximum) |
|
|
|
|
prio = prio::MAXIMUM; |
|
|
|
|
} else { |
|
|
|
|
else |
|
|
|
|
if (act == ui->actionNot_downloaded) |
|
|
|
|
prio = prio::IGNORED; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
qDebug("Setting files priority"); |
|
|
|
|
foreach (const QModelIndex &index, selectedRows) { |
|
|
|
|
qDebug("Setting priority(%d) for file at row %d", prio, index.row()); |
|
|
|
@ -559,10 +567,9 @@ void AddNewTorrentDialog::accept()
@@ -559,10 +567,9 @@ void AddNewTorrentDialog::accept()
|
|
|
|
|
// Save Temporary data about torrent
|
|
|
|
|
QString save_path = ui->save_path_combo->itemData(ui->save_path_combo->currentIndex()).toString(); |
|
|
|
|
TorrentTempData::setSavePath(m_hash, save_path); |
|
|
|
|
if (ui->skip_check_cb->isChecked()) { |
|
|
|
|
if (ui->skip_check_cb->isChecked()) |
|
|
|
|
// TODO: Check if destination actually exists
|
|
|
|
|
TorrentTempData::setSeedingMode(m_hash, true); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Label
|
|
|
|
|
const QString label = ui->label_combo->currentText(); |
|
|
|
@ -595,7 +602,8 @@ void AddNewTorrentDialog::accept()
@@ -595,7 +602,8 @@ void AddNewTorrentDialog::accept()
|
|
|
|
|
QDialog::accept(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void AddNewTorrentDialog::reject() { |
|
|
|
|
void AddNewTorrentDialog::reject() |
|
|
|
|
{ |
|
|
|
|
if (m_isMagnet) { |
|
|
|
|
disconnect(this, SLOT(updateMetadata(const QTorrentHandle &))); |
|
|
|
|
setMetadataProgressIndicator(false); |
|
|
|
@ -604,7 +612,8 @@ void AddNewTorrentDialog::reject() {
@@ -604,7 +612,8 @@ void AddNewTorrentDialog::reject() {
|
|
|
|
|
QDialog::reject(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void AddNewTorrentDialog::updateMetadata(const QTorrentHandle &h) { |
|
|
|
|
void AddNewTorrentDialog::updateMetadata(const QTorrentHandle &h) |
|
|
|
|
{ |
|
|
|
|
try { |
|
|
|
|
if (h.hash() != m_hash) |
|
|
|
|
return; |
|
|
|
@ -632,14 +641,16 @@ void AddNewTorrentDialog::updateMetadata(const QTorrentHandle &h) {
@@ -632,14 +641,16 @@ void AddNewTorrentDialog::updateMetadata(const QTorrentHandle &h) {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void AddNewTorrentDialog::setMetadataProgressIndicator(bool visibleIndicator, const QString &labelText) { |
|
|
|
|
void AddNewTorrentDialog::setMetadataProgressIndicator(bool visibleIndicator, const QString &labelText) |
|
|
|
|
{ |
|
|
|
|
// Always show info label when waiting for metadata
|
|
|
|
|
ui->lblMetaLoading->setVisible(true); |
|
|
|
|
ui->lblMetaLoading->setText(labelText); |
|
|
|
|
ui->progMetaLoading->setVisible(visibleIndicator); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void AddNewTorrentDialog::setupTreeview() { |
|
|
|
|
void AddNewTorrentDialog::setupTreeview() |
|
|
|
|
{ |
|
|
|
|
if (!m_hasMetadata) { |
|
|
|
|
ui->comment_lbl->setText(tr("Not Available", "This comment is unavailable")); |
|
|
|
|
ui->date_lbl->setText(tr("Not Available", "This date is unavailable")); |
|
|
|
@ -656,9 +667,8 @@ void AddNewTorrentDialog::setupTreeview() {
@@ -656,9 +667,8 @@ void AddNewTorrentDialog::setupTreeview() {
|
|
|
|
|
file_storage const& fs = m_torrentInfo->files(); |
|
|
|
|
|
|
|
|
|
// Populate m_filesList
|
|
|
|
|
for (int i = 0; i < fs.num_files(); ++i) { |
|
|
|
|
for (int i = 0; i < fs.num_files(); ++i) |
|
|
|
|
m_filesPath << misc::toQStringU(fs.file_path(i)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Prepare content tree
|
|
|
|
|
if (fs.num_files() > 1) { |
|
|
|
@ -678,14 +688,14 @@ void AddNewTorrentDialog::setupTreeview() {
@@ -678,14 +688,14 @@ void AddNewTorrentDialog::setupTreeview() {
|
|
|
|
|
|
|
|
|
|
// Expand root folder
|
|
|
|
|
ui->content_tree->setExpanded(m_contentModel->index(0, 0), true); |
|
|
|
|
} else { |
|
|
|
|
} |
|
|
|
|
else { |
|
|
|
|
// Update save paths (append file name to them)
|
|
|
|
|
QString single_file_relpath = misc::toQStringU(fs.file_path(0)); |
|
|
|
|
for (int i=0; i<ui->save_path_combo->count()-1; ++i) { |
|
|
|
|
for (int i = 0; i<ui->save_path_combo->count() - 1; ++i) |
|
|
|
|
ui->save_path_combo->setItemText(i, fsutils::toNativePath(QDir(ui->save_path_combo->itemText(i)).absoluteFilePath(single_file_relpath))); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
updateDiskSpaceLabel(); |
|
|
|
|
showAdvancedSettings(Preferences::instance()->getAddNewTorrentDialogExpanded()); |
|
|
|
|