summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--BeetPlayer.pro6
-rw-r--r--beetplayer.cpp20
-rw-r--r--beetplayer.h3
-rw-r--r--beetplayer.qrc1
-rw-r--r--indexerdialog.cpp31
-rw-r--r--indexerdialog.h17
-rw-r--r--indexerwidget.cpp86
-rw-r--r--indexerwidget.h29
-rw-r--r--main.cpp2
-rw-r--r--playerwidget.cpp10
-rw-r--r--playerwidget.h1
-rwxr-xr-xrefresh.pngbin0 -> 2182 bytes
12 files changed, 125 insertions, 81 deletions
diff --git a/BeetPlayer.pro b/BeetPlayer.pro
index 0873852..4a208a8 100644
--- a/BeetPlayer.pro
+++ b/BeetPlayer.pro
@@ -29,14 +29,16 @@ SOURCES += main.cpp\
indexerwidget.cpp \
globals.cpp \
playerwidget.cpp \
- beetview.cpp
+ beetview.cpp \
+ indexerdialog.cpp
HEADERS += beetplayer.h \
configurationdialog.h \
indexerwidget.h \
globals.h \
playerwidget.h \
- beetview.h
+ beetview.h \
+ indexerdialog.h
LIBS += -ltag
diff --git a/beetplayer.cpp b/beetplayer.cpp
index d2ed7d9..0a2c962 100644
--- a/beetplayer.cpp
+++ b/beetplayer.cpp
@@ -8,7 +8,6 @@
#include "beetplayer.h"
#include "configurationdialog.h"
-#include "indexerwidget.h"
#include "playerwidget.h"
#include "globals.h"
@@ -19,25 +18,8 @@ BeetPlayer::BeetPlayer(QWidget *parent, Qt::WindowFlags f) : QMainWindow(parent,
setMinimumHeight(768);
openDatabase();
createGlobalActions();
-
- //tabs
- mTab = new QTabWidget;
- IndexerWidget *indexer = new IndexerWidget;
PlayerWidget *player = new PlayerWidget;
- mTab->addTab(player, tr("Player"));
- mTab->addTab(indexer, tr("Indexer"));
- connect(mTab, SIGNAL(currentChanged(int)), this, SLOT(tabChanged(int)));
-
- //layout
- QHBoxLayout *mainLayout = new QHBoxLayout;
- mainLayout->addWidget(mTab);
- setCentralWidget(mTab);
-}
-
-void BeetPlayer::tabChanged(int tab){
- if(tab == 0){ //replace with indexer
- //do something;;
- }
+ setCentralWidget(player);
}
void BeetPlayer::openDatabase(){
diff --git a/beetplayer.h b/beetplayer.h
index f5169d9..857b46b 100644
--- a/beetplayer.h
+++ b/beetplayer.h
@@ -10,14 +10,11 @@ class BeetPlayer : public QMainWindow {
explicit BeetPlayer(QWidget *parent = 0, Qt::WindowFlags f = 0);
public slots:
- void tabChanged(int tab);
void configure();
private:
void openDatabase();
void createGlobalActions();
- QTabWidget *mTab;
- QHash<int, QVector<QMenu*>> mMenus;
};
#endif // BEETPLAYER_H
diff --git a/beetplayer.qrc b/beetplayer.qrc
index 690f619..b35e691 100644
--- a/beetplayer.qrc
+++ b/beetplayer.qrc
@@ -8,5 +8,6 @@
<file>stop.png</file>
<file>chastity_belt.png</file>
<file>delete.png</file>
+ <file>refresh.png</file>
</qresource>
</RCC>
diff --git a/indexerdialog.cpp b/indexerdialog.cpp
new file mode 100644
index 0000000..0722bad
--- /dev/null
+++ b/indexerdialog.cpp
@@ -0,0 +1,31 @@
+#include <QVBoxLayout>
+#include <QHBoxLayout>
+#include <QPushButton>
+#include <QApplication>
+
+#include "indexerdialog.h"
+#include "indexerwidget.h"
+
+IndexerDialog::IndexerDialog(QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f){
+ //indexer
+ mIndexer = new IndexerWidget;
+
+ //buttons
+ QPushButton *startB = new QPushButton(tr("Start"));
+ connect(startB, SIGNAL(clicked()), mIndexer, SLOT(startIndexing()));
+ QPushButton *stopB = new QPushButton(tr("Stop"));
+ connect(stopB, SIGNAL(clicked()), mIndexer, SLOT(stopIndexing()));
+ QHBoxLayout *buttonLayout = new QHBoxLayout;
+ buttonLayout->addStretch();
+ buttonLayout->addWidget(startB);
+ buttonLayout->addWidget(stopB);
+ buttonLayout->addStretch();
+
+ //mainlayout
+ QVBoxLayout *mainLayout = new QVBoxLayout;
+ mainLayout->addWidget(mIndexer);
+ mainLayout->addLayout(buttonLayout);
+ setLayout(mainLayout);
+ setWindowTitle(QString(tr("%1 - Indexer")).arg(qApp->applicationName()));
+ setMinimumWidth(768);
+}
diff --git a/indexerdialog.h b/indexerdialog.h
new file mode 100644
index 0000000..2928b08
--- /dev/null
+++ b/indexerdialog.h
@@ -0,0 +1,17 @@
+#ifndef INDEXERDIALOG_H
+#define INDEXERDIALOG_H
+
+#include <QDialog>
+
+class IndexerWidget;
+
+class IndexerDialog : public QDialog {
+ Q_OBJECT
+ public:
+ explicit IndexerDialog(QWidget *parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags());
+
+ private:
+ IndexerWidget *mIndexer;
+};
+
+#endif // INDEXERDIALOG_H
diff --git a/indexerwidget.cpp b/indexerwidget.cpp
index c5c8bda..f30de80 100644
--- a/indexerwidget.cpp
+++ b/indexerwidget.cpp
@@ -7,62 +7,75 @@
#include <QCursor>
#include <QSqlQuery>
#include <QFileInfo>
-#include <QAction>
-#include <QMenu>
+#include <QLabel>
+#include <QGroupBox>
+#include <QProgressBar>
#include "taglib/tag.h"
#include "indexerwidget.h"
#include "globals.h"
-IndexerWidget::IndexerWidget(QWidget *parent) : QWidget(parent) {
- //widgets
- mLog = new QTextEdit;
- mLog->setFont(QFont("courier new"));
- mLog->setTextColor(Qt::darkGreen);
+IndexerWidget::IndexerWidget(QWidget *parent) : QWidget(parent), mMax(0) {
+ //errors
+ QGroupBox *gb1 = new QGroupBox(tr("Errors"));
mError = new QTextEdit;
mError->setFont(QFont("courier new"));
mError->setTextColor(Qt::red);
- QPushButton *startB = new QPushButton(tr("Index"));
- connect(startB, SIGNAL(clicked()), this, SLOT(startIndexing()));
- QPushButton *cancelB = new QPushButton(tr("Cancel"));
- connect(cancelB, SIGNAL(clicked()), this, SLOT(stopIndexing()));
+ QVBoxLayout *gb1L = new QVBoxLayout;
+ gb1L->addWidget(mError);
+ gb1->setLayout(gb1L);
+
+ //progress
+ QLabel *l1 = new QLabel(tr("Indexing:"));
+ l1->setFont(QFont("courier"));
+ mProgress = new QProgressBar;
+ QHBoxLayout *progressL = new QHBoxLayout;
+ mProgressCount = new QLabel(tr("000000/00000"));
+ mProgressCount->setFont(QFont("courier"));
+ progressL->addWidget(l1);
+ progressL->addWidget(mProgress);
+ progressL->addWidget(mProgressCount);
//reader
mReader = new BeetReader;
- connect(mReader, SIGNAL(message(QString)), this, SLOT(addToLog(QString)));
connect(mReader, SIGNAL(errorMsg(QString)), this, SLOT(addToError(QString)));
+ connect(mReader, SIGNAL(totalCount(int)), this, SLOT(setupProgress(int)));
+ connect(mReader, SIGNAL(progress(int)), this, SLOT(progress(int)));
- //layout
+ //main layout
QVBoxLayout *mainLayout = new QVBoxLayout;
- QHBoxLayout *buttonLayout = new QHBoxLayout;
- buttonLayout->addStretch();
- buttonLayout->addWidget(startB);
- buttonLayout->addWidget(cancelB);
- buttonLayout->addStretch();
- mainLayout->addWidget(mLog);
- mainLayout->addWidget(mError);
- mainLayout->addLayout(buttonLayout);
+ mainLayout->addWidget(gb1);
+ mainLayout->addLayout(progressL);
setLayout(mainLayout);
}
void IndexerWidget::startIndexing(){
- mLog->clear();
mError->clear();
mReader->start();
}
void IndexerWidget::stopIndexing(){
mReader->cancel();
-}
-
-void IndexerWidget::addToLog(QString msg){
- mLog->append(msg);
+ addToError(tr("Canceled!"));
}
void IndexerWidget::addToError(QString msg){
mError->append(msg);
}
+void IndexerWidget::setupProgress(int max){
+ mProgress->reset();
+ mProgress->setMinimum(0);
+ mProgress->setMaximum(max);
+ mMax = max;
+}
+
+void IndexerWidget::progress(int cur){
+ mProgress->setValue(cur);
+ QString p = QString("%1/%2").arg(cur, 6, 10, QChar('0')).arg(mMax, 6, 10, QChar('0'));
+ mProgressCount->setText(p);
+}
+
BeetReader::BeetReader() : mCanceled(false){
mDb = QSqlDatabase::database("beetplayerdb");
mInsertArtistsQ = new QSqlQuery(mDb);
@@ -82,28 +95,29 @@ BeetReader::BeetReader() : mCanceled(false){
}
void BeetReader::run(){
- emit message(QString(tr("Clearing everything...")));
clearAll();
QProcess lister;
lister.start("beet", QStringList() << "ls" << "-p");
qApp->setOverrideCursor(QCursor(Qt::WaitCursor));
- emit message(QString(tr("Waiting for beet ls -p...")));
+ emit errorMsg(tr("Waiting for beet ls -p"));
lister.waitForStarted();
lister.waitForFinished();
qApp->restoreOverrideCursor();
+ emit errorMsg(tr("Done Waiting - Starting some serious work!"));
QByteArray lOut = lister.readAllStandardOutput();
QList<QByteArray> files = lOut.split('\n');
- int totalCount = files.size();
- QString foundMsg = QString(tr("Found %1 file(s)\n").arg(QString::number(totalCount)));
- emit message(foundMsg);
+ int total = files.size();
+ emit totalCount(total);
int ctr = 1;
foreach(QByteArray s, files){
//fetch data from file
TagLib::FileRef file(QString(s).toUtf8());
if(file.isNull()){
QString fn = QString(s).toUtf8();
- QString error = QString(tr("IsNull: %1")).arg(fn);
- emit errorMsg(error);
+ if(!fn.isEmpty()){
+ QString error = QString(tr("IsNull: %1")).arg(fn);
+ emit errorMsg(error);
+ }
continue;
}
QString artist = toQString(file.tag()->artist());
@@ -120,8 +134,7 @@ void BeetReader::run(){
doSong(title, track, albumId, genreId, artistId, s);
if(ctr % 100 == 0){
- QString msg = QString(tr("Processed %1 files of %2")).arg(QString::number(ctr)).arg(QString::number(totalCount));
- emit message(msg);
+ emit progress(ctr);
}
mCancelMx.lock();
@@ -133,7 +146,8 @@ void BeetReader::run(){
mCancelMx.unlock();
++ctr;
}
- emit message(QString(tr("Indexing DONE!")));
+ emit progress(total);
+ emit errorMsg(tr("Serious work done!"));
}
void BeetReader::cancel(){
diff --git a/indexerwidget.h b/indexerwidget.h
index 0f43266..d8e70bb 100644
--- a/indexerwidget.h
+++ b/indexerwidget.h
@@ -8,12 +8,10 @@
#include "taglib/fileref.h"
-class QMenu;
-class QAction;
-
class QTextEdit;
+class QProgressBar;
+class QLabel;
class BeetReader;
-struct BeetObject;
class IndexerWidget : public QWidget {
Q_OBJECT
@@ -23,15 +21,15 @@ class IndexerWidget : public QWidget {
public slots:
void startIndexing();
void stopIndexing();
- void addToLog(QString msg);
void addToError(QString msg);
+ void setupProgress(int max);
+ void progress(int cur);
private:
- QTextEdit *mLog;
QTextEdit *mError;
- QVector<QMenu*> mMenus;
- QAction *mStartIndexingA;
- QAction *mStopIndexingA;
+ QProgressBar *mProgress;
+ QLabel *mProgressCount;
+ int mMax;
BeetReader *mReader;
};
@@ -43,8 +41,9 @@ class BeetReader : public QThread {
void cancel();
signals:
- void message(const QString &msg);
void errorMsg(const QString &msg);
+ void totalCount(int count);
+ void progress(int cur);
void cleared();
private:
@@ -70,14 +69,4 @@ class BeetReader : public QThread {
QSqlQuery *mInsertSongQ;
};
-struct BeetObject {
- QString artist;
- QString album;
- quint16 year;
- QString genre;
- quint16 pos;
- QString title;
- QString fullpath;
-};
-
#endif // INDEXERWIDGET_H
diff --git a/main.cpp b/main.cpp
index 8014d8d..3a28ee2 100644
--- a/main.cpp
+++ b/main.cpp
@@ -9,7 +9,7 @@ int main(int argc, char *argv[]) {
QCoreApplication::setApplicationName("BeetPlayer");
QCoreApplication::setApplicationVersion("0.99 (__build_info__)");
BeetPlayer w;
- w.show();
+ w.showMaximized();
return a.exec();
}
diff --git a/playerwidget.cpp b/playerwidget.cpp
index 35f3c40..603334a 100644
--- a/playerwidget.cpp
+++ b/playerwidget.cpp
@@ -17,6 +17,7 @@
#include "playerwidget.h"
#include "beetview.h"
+#include "indexerdialog.h"
#include "globals.h"
PlayerWidget::PlayerWidget(QWidget *parent) : QWidget(parent){
@@ -114,6 +115,8 @@ void PlayerWidget::createActions(){
QAction *addToPlayListA = new QAction(QIcon(":/belly_right.png"), tr("Add to playlist"), this);
QAction *removeFromPlayListA = new QAction(QIcon(":/belly_left.png"), tr("Remove from playlist"), this);
QAction *clearPlayListA = new QAction(QIcon(":/delete.png"), tr("Clear Playlist"), this);
+ QAction *refreshA = new QAction(QIcon(":/refresh.png"), tr("Refresh..."), this);
+ connect(refreshA, SIGNAL(triggered()), this, SLOT(reindex()));
QAction *configA = Globals::instance()->action(Globals::ConfigAction);
mView->addAction(addToPlayListA);
mView->addAction(removeFromPlayListA);
@@ -130,6 +133,8 @@ void PlayerWidget::createActions(){
mToolBar->addAction(removeFromPlayListA);
mToolBar->addAction(clearPlayListA);
mToolBar->addSeparator();
+ mToolBar->addAction(refreshA);
+ mToolBar->addSeparator();
mToolBar->addAction(configA);
QWidget* spacer2 = new QWidget();
spacer2->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
@@ -273,3 +278,8 @@ void PlayerWidget::clearFilter(){
mFilter->clear();
mView->setModel(mViewModel);
}
+
+void PlayerWidget::reindex(){
+ IndexerDialog dlg(this);
+ dlg.exec();
+}
diff --git a/playerwidget.h b/playerwidget.h
index 22cd2c5..4de2e38 100644
--- a/playerwidget.h
+++ b/playerwidget.h
@@ -25,6 +25,7 @@ class PlayerWidget : public QWidget {
void populate();
void doFilter();
void clearFilter();
+ void reindex();
private:
void setupGui();
diff --git a/refresh.png b/refresh.png
new file mode 100755
index 0000000..afa2a9d
--- /dev/null
+++ b/refresh.png
Binary files differ