Browse Source

Switch to modeless dialog

Don't close dialog after creating torrent
Show progress bar all the time
adaptive-webui-19844
Chocobo1 9 years ago
parent
commit
7de1aba092
  1. 4
      src/gui/mainwindow.cpp
  2. 36
      src/gui/torrentcreatordlg.cpp
  3. 3
      src/gui/torrentcreatordlg.h
  4. 6
      src/gui/torrentcreatordlg.ui

4
src/gui/mainwindow.cpp

@ -1075,8 +1075,10 @@ void MainWindow::on_actionCreateTorrent_triggered()
void MainWindow::createTorrentTriggered(const QString &path) void MainWindow::createTorrentTriggered(const QString &path)
{ {
if (m_createTorrentDlg) if (m_createTorrentDlg) {
m_createTorrentDlg->updateInputPath(path);
m_createTorrentDlg->setFocus(); m_createTorrentDlg->setFocus();
}
else else
m_createTorrentDlg = new TorrentCreatorDlg(this, path); m_createTorrentDlg = new TorrentCreatorDlg(this, path);
} }

36
src/gui/torrentcreatordlg.cpp

@ -67,13 +67,11 @@ TorrentCreatorDlg::TorrentCreatorDlg(QWidget *parent, const QString &defaultPath
: QDialog(parent) : QDialog(parent)
, m_ui(new Ui::TorrentCreatorDlg) , m_ui(new Ui::TorrentCreatorDlg)
, m_creatorThread(nullptr) , m_creatorThread(nullptr)
, m_defaultPath(Utils::Fs::toNativePath(defaultPath))
{ {
m_ui->setupUi(this); m_ui->setupUi(this);
setAttribute(Qt::WA_DeleteOnClose); setAttribute(Qt::WA_DeleteOnClose);
setModal(true); setModal(false);
showProgressBar(false);
m_ui->buttonBox->button(QDialogButtonBox::Ok)->setText(tr("Create Torrent")); m_ui->buttonBox->button(QDialogButtonBox::Ok)->setText(tr("Create Torrent"));
connect(m_ui->addFile_button, SIGNAL(clicked(bool)), SLOT(onAddFileButtonClicked())); connect(m_ui->addFile_button, SIGNAL(clicked(bool)), SLOT(onAddFileButtonClicked()));
@ -81,6 +79,8 @@ TorrentCreatorDlg::TorrentCreatorDlg(QWidget *parent, const QString &defaultPath
connect(m_ui->buttonBox, SIGNAL(accepted()), SLOT(onCreateButtonClicked())); connect(m_ui->buttonBox, SIGNAL(accepted()), SLOT(onCreateButtonClicked()));
loadSettings(); loadSettings();
updateInputPath(defaultPath);
show(); show();
} }
@ -102,20 +102,25 @@ TorrentCreatorDlg::~TorrentCreatorDlg()
delete m_ui; delete m_ui;
} }
void TorrentCreatorDlg::updateInputPath(const QString &path)
{
if (path.isEmpty()) return;
m_ui->textInputPath->setText(Utils::Fs::toNativePath(path));
updateProgressBar(0);
}
void TorrentCreatorDlg::onAddFolderButtonClicked() void TorrentCreatorDlg::onAddFolderButtonClicked()
{ {
QString oldPath = m_ui->textInputPath->text(); QString oldPath = m_ui->textInputPath->text();
QString path = QFileDialog::getExistingDirectory(this, tr("Select folder"), oldPath); QString path = QFileDialog::getExistingDirectory(this, tr("Select folder"), oldPath);
if (!path.isEmpty()) updateInputPath(path);
m_ui->textInputPath->setText(Utils::Fs::toNativePath(path));
} }
void TorrentCreatorDlg::onAddFileButtonClicked() void TorrentCreatorDlg::onAddFileButtonClicked()
{ {
QString oldPath = m_ui->textInputPath->text(); QString oldPath = m_ui->textInputPath->text();
QString path = QFileDialog::getOpenFileName(this, tr("Select file"), oldPath); QString path = QFileDialog::getOpenFileName(this, tr("Select file"), oldPath);
if (!path.isEmpty()) updateInputPath(path);
m_ui->textInputPath->setText(Utils::Fs::toNativePath(path));
} }
int TorrentCreatorDlg::getPieceSize() const int TorrentCreatorDlg::getPieceSize() const
@ -133,7 +138,7 @@ void TorrentCreatorDlg::dropEvent(QDropEvent *event)
QUrl firstItem = event->mimeData()->urls().first(); QUrl firstItem = event->mimeData()->urls().first();
QString path = (firstItem.scheme().compare("file", Qt::CaseInsensitive) == 0) QString path = (firstItem.scheme().compare("file", Qt::CaseInsensitive) == 0)
? firstItem.toLocalFile() : firstItem.toString(); ? firstItem.toLocalFile() : firstItem.toString();
m_ui->textInputPath->setText(Utils::Fs::toNativePath(path)); updateInputPath(path);
} }
} }
@ -167,7 +172,6 @@ void TorrentCreatorDlg::onCreateButtonClicked()
// Disable dialog & set busy cursor // Disable dialog & set busy cursor
setInteractionEnabled(false); setInteractionEnabled(false);
showProgressBar(true);
setCursor(QCursor(Qt::WaitCursor)); setCursor(QCursor(Qt::WaitCursor));
QStringList trackers = m_ui->trackers_list->toPlainText().split("\n"); QStringList trackers = m_ui->trackers_list->toPlainText().split("\n");
@ -175,10 +179,12 @@ void TorrentCreatorDlg::onCreateButtonClicked()
QString comment = m_ui->txt_comment->toPlainText(); QString comment = m_ui->txt_comment->toPlainText();
// Create the creator thread // Create the creator thread
if (!m_creatorThread) {
m_creatorThread = new BitTorrent::TorrentCreatorThread(this); m_creatorThread = new BitTorrent::TorrentCreatorThread(this);
connect(m_creatorThread, SIGNAL(creationSuccess(QString, QString)), this, SLOT(handleCreationSuccess(QString, QString))); connect(m_creatorThread, SIGNAL(creationSuccess(QString, QString)), this, SLOT(handleCreationSuccess(QString, QString)));
connect(m_creatorThread, SIGNAL(creationFailure(QString)), this, SLOT(handleCreationFailure(QString))); connect(m_creatorThread, SIGNAL(creationFailure(QString)), this, SLOT(handleCreationFailure(QString)));
connect(m_creatorThread, SIGNAL(updateProgress(int)), this, SLOT(updateProgressBar(int))); connect(m_creatorThread, SIGNAL(updateProgress(int)), this, SLOT(updateProgressBar(int)));
}
m_creatorThread->create(input, destination, trackers, urlSeeds, comment, m_ui->check_private->isChecked(), getPieceSize()); m_creatorThread->create(input, destination, trackers, urlSeeds, comment, m_ui->check_private->isChecked(), getPieceSize());
} }
@ -188,7 +194,6 @@ void TorrentCreatorDlg::handleCreationFailure(const QString &msg)
setCursor(QCursor(Qt::ArrowCursor)); setCursor(QCursor(Qt::ArrowCursor));
QMessageBox::information(this, tr("Torrent creator failed"), tr("Reason: %1").arg(msg)); QMessageBox::information(this, tr("Torrent creator failed"), tr("Reason: %1").arg(msg));
setInteractionEnabled(true); setInteractionEnabled(true);
showProgressBar(false);
} }
void TorrentCreatorDlg::handleCreationSuccess(const QString &path, const QString &branchPath) void TorrentCreatorDlg::handleCreationSuccess(const QString &path, const QString &branchPath)
@ -211,8 +216,7 @@ void TorrentCreatorDlg::handleCreationSuccess(const QString &path, const QString
BitTorrent::Session::instance()->addTorrent(t, params); BitTorrent::Session::instance()->addTorrent(t, params);
} }
QMessageBox::information(this, tr("Torrent creator"), QString("%1\n%2").arg(tr("Create torrent success:")).arg(Utils::Fs::toNativePath(path))); QMessageBox::information(this, tr("Torrent creator"), QString("%1\n%2").arg(tr("Create torrent success:")).arg(Utils::Fs::toNativePath(path)));
setInteractionEnabled(true);
close();
} }
void TorrentCreatorDlg::updateProgressBar(int progress) void TorrentCreatorDlg::updateProgressBar(int progress)
@ -235,12 +239,6 @@ void TorrentCreatorDlg::setInteractionEnabled(bool enabled)
m_ui->checkIgnoreShareLimits->setEnabled(enabled && m_ui->checkStartSeeding->isChecked()); m_ui->checkIgnoreShareLimits->setEnabled(enabled && m_ui->checkStartSeeding->isChecked());
} }
void TorrentCreatorDlg::showProgressBar(bool show)
{
m_ui->progressLbl->setVisible(show);
m_ui->progressBar->setVisible(show);
}
void TorrentCreatorDlg::saveSettings() void TorrentCreatorDlg::saveSettings()
{ {
storeLastAddPath = m_ui->textInputPath->text().trimmed(); storeLastAddPath = m_ui->textInputPath->text().trimmed();
@ -259,7 +257,7 @@ void TorrentCreatorDlg::saveSettings()
void TorrentCreatorDlg::loadSettings() void TorrentCreatorDlg::loadSettings()
{ {
m_ui->textInputPath->setText(!m_defaultPath.isEmpty() ? m_defaultPath : storeLastAddPath); m_ui->textInputPath->setText(storeLastAddPath);
m_ui->comboPieceSize->setCurrentIndex(storePieceSize); m_ui->comboPieceSize->setCurrentIndex(storePieceSize);
m_ui->check_private->setChecked(storePrivateTorrent); m_ui->check_private->setChecked(storePrivateTorrent);

3
src/gui/torrentcreatordlg.h

@ -50,6 +50,7 @@ class TorrentCreatorDlg: public QDialog
public: public:
TorrentCreatorDlg(QWidget *parent = 0, const QString &defaultPath = QString()); TorrentCreatorDlg(QWidget *parent = 0, const QString &defaultPath = QString());
~TorrentCreatorDlg(); ~TorrentCreatorDlg();
void updateInputPath(const QString &path);
private slots: private slots:
void updateProgressBar(int progress); void updateProgressBar(int progress);
@ -66,12 +67,10 @@ private:
void saveSettings(); void saveSettings();
void loadSettings(); void loadSettings();
int getPieceSize() const; int getPieceSize() const;
void showProgressBar(bool show);
void setInteractionEnabled(bool enabled); void setInteractionEnabled(bool enabled);
Ui::TorrentCreatorDlg *m_ui; Ui::TorrentCreatorDlg *m_ui;
BitTorrent::TorrentCreatorThread *m_creatorThread; BitTorrent::TorrentCreatorThread *m_creatorThread;
QString m_defaultPath;
}; };
#endif #endif

6
src/gui/torrentcreatordlg.ui

@ -269,7 +269,11 @@
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QProgressBar" name="progressBar"/> <widget class="QProgressBar" name="progressBar">
<property name="value">
<number>0</number>
</property>
</widget>
</item> </item>
</layout> </layout>
</item> </item>

Loading…
Cancel
Save