diff options
| author | Arno <arno@disconnect.de> | 2017-11-30 15:36:35 +0100 | 
|---|---|---|
| committer | Arno <arno@disconnect.de> | 2017-11-30 15:36:35 +0100 | 
| commit | 8b611b7c69b50bf2f252903a849dd41ed685fece (patch) | |
| tree | c8b88ceaacdc572f6cdd8a549520910204f07afa | |
| parent | 16fc23f00d5bd8536acef56e21d01057bcf88709 (diff) | |
| download | BeetPlayer-8b611b7c69b50bf2f252903a849dd41ed685fece.tar.gz BeetPlayer-8b611b7c69b50bf2f252903a849dd41ed685fece.tar.bz2 BeetPlayer-8b611b7c69b50bf2f252903a849dd41ed685fece.zip  | |
Improve indexing dialog
Show close button and disable/enable approriate buttons while reading
data.
| -rw-r--r-- | indexerdialog.cpp | 31 | ||||
| -rw-r--r-- | indexerdialog.h | 8 | ||||
| -rw-r--r-- | indexerwidget.cpp | 4 | ||||
| -rw-r--r-- | indexerwidget.h | 4 | 
4 files changed, 40 insertions, 7 deletions
diff --git a/indexerdialog.cpp b/indexerdialog.cpp index c9e6ca3..1909c9e 100644 --- a/indexerdialog.cpp +++ b/indexerdialog.cpp @@ -9,16 +9,23 @@  IndexerDialog::IndexerDialog(QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f){      //indexer      mIndexer = new IndexerWidget; +    connect(mIndexer, &IndexerWidget::indexingDone, this, &IndexerDialog::indexingCanceled);      //buttons -    QPushButton *startB = new QPushButton(tr("Start")); -    connect(startB, &QPushButton::clicked, mIndexer, &IndexerWidget::startIndexing); -    QPushButton *stopB = new QPushButton(tr("Stop")); -    connect(stopB, &QPushButton::clicked, mIndexer, &IndexerWidget::stopIndexing); +    mStartBtn = new QPushButton(tr("Start")); +    connect(mStartBtn, &QPushButton::clicked, mIndexer, &IndexerWidget::startIndexing); +    connect(mStartBtn, &QPushButton::clicked, this, &IndexerDialog::indexingStarted); +    mCancelBtn = new QPushButton(tr("Cancel")); +    mCancelBtn->setEnabled(false); +    connect(mCancelBtn, &QPushButton::clicked, mIndexer, &IndexerWidget::stopIndexing); +    connect(mCancelBtn, &QPushButton::clicked, this, &IndexerDialog::indexingCanceled); +    mCloseBtn = new QPushButton(tr("Close")); +    connect(mCloseBtn, &QPushButton::clicked, this, &IndexerDialog::close);      QHBoxLayout *buttonLayout = new QHBoxLayout;      buttonLayout->addStretch(); -    buttonLayout->addWidget(startB); -    buttonLayout->addWidget(stopB); +    buttonLayout->addWidget(mStartBtn); +    buttonLayout->addWidget(mCancelBtn); +    buttonLayout->addWidget(mCloseBtn);      buttonLayout->addStretch();      //mainlayout @@ -29,3 +36,15 @@ IndexerDialog::IndexerDialog(QWidget *parent, Qt::WindowFlags f) : QDialog(paren      setWindowTitle(QString(tr("%1 - Indexer")).arg(qApp->applicationName()));      setMinimumWidth(768);  } + +void IndexerDialog::indexingStarted(){ +    mStartBtn->setEnabled(false); +    mCancelBtn->setEnabled(true); +    mCloseBtn->setEnabled(false); +} + +void IndexerDialog::indexingCanceled(){ +    mStartBtn->setEnabled(true); +    mCancelBtn->setEnabled(false); +    mCloseBtn->setEnabled(true); +} diff --git a/indexerdialog.h b/indexerdialog.h index 2928b08..95201e4 100644 --- a/indexerdialog.h +++ b/indexerdialog.h @@ -4,14 +4,22 @@  #include <QDialog>  class IndexerWidget; +class QPushButton;  class IndexerDialog : public QDialog {      Q_OBJECT      public:          explicit IndexerDialog(QWidget *parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags()); +    private slots: +        void indexingStarted(); +        void indexingCanceled(); +      private:          IndexerWidget *mIndexer; +        QPushButton *mStartBtn; +        QPushButton *mCancelBtn; +        QPushButton *mCloseBtn;  };  #endif // INDEXERDIALOG_H diff --git a/indexerwidget.cpp b/indexerwidget.cpp index ae1bd68..db1818c 100644 --- a/indexerwidget.cpp +++ b/indexerwidget.cpp @@ -46,6 +46,7 @@ IndexerWidget::IndexerWidget(QWidget *parent) : QWidget(parent), mMax(0) {      connect(mReader, &BeetReader::errorMsg, this, &IndexerWidget::addToError);      connect(mReader, &BeetReader::totalCount, this, &IndexerWidget::setupProgress);      connect(mReader, &BeetReader::progress, this, &IndexerWidget::progress); +    connect(mReader, &BeetReader::indexingDone, this, &IndexerWidget::indexingDone);      //main layout      QVBoxLayout *mainLayout = new QVBoxLayout; @@ -137,7 +138,7 @@ void BeetReader::run(){          //fetch data from file          TagLib::FileRef file(QString(s).toUtf8());          if(file.isNull()){ -            QString fn = QString(s).toUtf8(); +            QString fn(s);              if(!fn.isEmpty()){                  QString error = QString(tr("IsNull: %1")).arg(fn);                  emit errorMsg(error); @@ -176,6 +177,7 @@ void BeetReader::run(){      }      emit progress(total);      emit errorMsg(tr("Indexing done!")); +    emit indexingDone();  }  void BeetReader::cancel(){ diff --git a/indexerwidget.h b/indexerwidget.h index cd3621c..c11eaf5 100644 --- a/indexerwidget.h +++ b/indexerwidget.h @@ -18,6 +18,9 @@ class IndexerWidget : public QWidget {      public:          explicit IndexerWidget(QWidget *parent = 0); +    signals: +        void indexingDone(); +      public slots:          void startIndexing();          void stopIndexing(); @@ -45,6 +48,7 @@ class BeetReader : public QThread {          void totalCount(int count);          void progress(int cur);          void cleared(); +        void indexingDone();      private:          QString toQString(TagLib::String string);  | 
