Browse Source

Hide torrent content in torrent addition dialog when there is only one file in it

adaptive-webui-19844
Christophe Dumez 15 years ago
parent
commit
0da83694e0
  1. 62
      src/torrentadditiondlg.cpp
  2. 1
      src/torrentadditiondlg.h

62
src/torrentadditiondlg.cpp

@ -107,10 +107,7 @@ void torrentAdditionDialog::renameTorrentNameInModel(QString file_path) {
PropListModel->setData(PropListModel->index(0, 0), file_path.split("/", QString::SkipEmptyParts).last()); PropListModel->setData(PropListModel->index(0, 0), file_path.split("/", QString::SkipEmptyParts).last());
} }
void torrentAdditionDialog::showLoadMagnetURI(QString magnet_uri) { void torrentAdditionDialog::hideTorrentContent() {
show();
is_magnet = true;
this->from_url = magnet_uri;
int hidden_height = 0; int hidden_height = 0;
// Disable useless widgets // Disable useless widgets
hidden_height += torrentContentList->height(); hidden_height += torrentContentList->height();
@ -120,6 +117,17 @@ void torrentAdditionDialog::showLoadMagnetURI(QString magnet_uri) {
hidden_height += collapseAllButton->height(); hidden_height += collapseAllButton->height();
collapseAllButton->setVisible(false); collapseAllButton->setVisible(false);
expandAllButton->setVisible(false); expandAllButton->setVisible(false);
// Resize main window
setMinimumSize(0, 0);
resize(width(), height()-hidden_height);
}
void torrentAdditionDialog::showLoadMagnetURI(QString magnet_uri) {
show();
is_magnet = true;
this->from_url = magnet_uri;
// Get torrent hash // Get torrent hash
hash = misc::magnetUriToHash(magnet_uri); hash = misc::magnetUriToHash(magnet_uri);
if(hash.isEmpty()) { if(hash.isEmpty()) {
@ -146,10 +154,8 @@ void torrentAdditionDialog::showLoadMagnetURI(QString magnet_uri) {
foreach(const QString& label, customLabels) { foreach(const QString& label, customLabels) {
comboLabel->addItem(label); comboLabel->addItem(label);
} }
// Show dialog // No need to display torrent content
//show(); hideTorrentContent();
setMinimumSize(0, 0);
resize(width(), height()-hidden_height);
} }
void torrentAdditionDialog::showLoad(QString filePath, QString from_url) { void torrentAdditionDialog::showLoad(QString filePath, QString from_url) {
@ -216,12 +222,17 @@ void torrentAdditionDialog::showLoad(QString filePath, QString from_url) {
newFileName = fileName; newFileName = fileName;
} }
fileNameLbl->setText(QString::fromUtf8("<center><b>")+newFileName+QString::fromUtf8("</b></center>")); fileNameLbl->setText(QString::fromUtf8("<center><b>")+newFileName+QString::fromUtf8("</b></center>"));
// List files in torrent if(t->num_files() > 1) {
PropListModel->setupModelData(*t); // List files in torrent
// Expand first item if possible PropListModel->setupModelData(*t);
torrentContentList->expand(PropListModel->index(0, 0)); // Expand first item if possible
connect(PropDelegate, SIGNAL(filteredFilesChanged()), this, SLOT(updateDiskSpaceLabels())); torrentContentList->expand(PropListModel->index(0, 0));
//torrentContentList->expandAll(); connect(PropDelegate, SIGNAL(filteredFilesChanged()), this, SLOT(updateDiskSpaceLabels()));
// Loads files path in the torrent
for(uint i=0; i<nbFiles; ++i) {
files_path << misc::toQStringU(t->file_at(i).path.string());
}
}
connect(savePathTxt, SIGNAL(textChanged(QString)), this, SLOT(updateDiskSpaceLabels())); connect(savePathTxt, SIGNAL(textChanged(QString)), this, SLOT(updateDiskSpaceLabels()));
updateDiskSpaceLabels(); updateDiskSpaceLabels();
// Load custom labels // Load custom labels
@ -232,12 +243,10 @@ void torrentAdditionDialog::showLoad(QString filePath, QString from_url) {
foreach(const QString& label, customLabels) { foreach(const QString& label, customLabels) {
comboLabel->addItem(label); comboLabel->addItem(label);
} }
// Loads files path in the torrent
for(uint i=0; i<nbFiles; ++i) {
files_path << misc::toQStringU(t->file_at(i).path.string());
}
// Show the dialog // Show the dialog
show(); show();
if(t->num_files() <= 1)
hideTorrentContent();
} }
void torrentAdditionDialog::displayContentListMenu(const QPoint&) { void torrentAdditionDialog::displayContentListMenu(const QPoint&) {
@ -382,12 +391,16 @@ void torrentAdditionDialog::renameSelectedFile() {
if(!is_magnet) { if(!is_magnet) {
// Determine torrent size // Determine torrent size
qulonglong torrent_size = 0; qulonglong torrent_size = 0;
const unsigned int nbFiles = t->num_files(); if(t->num_files() > 1) {
const std::vector<int> &priorities = PropListModel->getFilesPriorities(nbFiles); const unsigned int nbFiles = t->num_files();
const std::vector<int> &priorities = PropListModel->getFilesPriorities(nbFiles);
for(unsigned int i=0; i<nbFiles; ++i) { for(unsigned int i=0; i<nbFiles; ++i) {
if(priorities[i] > 0) if(priorities[i] > 0)
torrent_size += t->file_at(i).size; torrent_size += t->file_at(i).size;
}
} else {
torrent_size = t->total_size();
} }
lbl_torrent_size->setText(misc::friendlyUnit(torrent_size)); lbl_torrent_size->setText(misc::friendlyUnit(torrent_size));
@ -460,7 +473,8 @@ void torrentAdditionDialog::renameSelectedFile() {
// Remove file name // Remove file name
QStringList parts = save_path.split("/", QString::SkipEmptyParts); QStringList parts = save_path.split("/", QString::SkipEmptyParts);
const QString single_file_name = parts.takeLast(); const QString single_file_name = parts.takeLast();
files_path.replace(0, single_file_name); Q_ASSERT(files_path.isEmpty());
files_path << single_file_name;
save_path = "/"+parts.join("/"); save_path = "/"+parts.join("/");
} }
QDir savePath(save_path); QDir savePath(save_path);

1
src/torrentadditiondlg.h

@ -79,6 +79,7 @@ public slots:
void savePiecesPriorities(); void savePiecesPriorities();
void on_OkButton_clicked(); void on_OkButton_clicked();
void renameTorrentNameInModel(QString file_path); void renameTorrentNameInModel(QString file_path);
void hideTorrentContent();
public slots: public slots:
void updateLabelInSavePath(QString label); void updateLabelInSavePath(QString label);

Loading…
Cancel
Save