#include #include #include #include #include #include #include #include #include #include #include #include "beetplayer.h" #include "configurationdialog.h" #include "playerwidget.h" #include "globals.h" BeetPlayer::BeetPlayer(QWidget *parent, Qt::WindowFlags f) : QMainWindow(parent, f) { //general setup qApp->setWindowIcon(QIcon(":/beetplayer32.png")); QSplashScreen splash(QPixmap(":/splash.png")); splash.show(); setMinimumWidth(1024); setMinimumHeight(768); splash.showMessage(tr("Opening database..."), Qt::AlignHCenter, Qt::yellow); qApp->processEvents(); openDatabase(); splash.showMessage(tr("Creating global actions..."), Qt::AlignHCenter, Qt::yellow); qApp->processEvents(); createGlobalActions(); splash.showMessage(tr("Reading BeetPlayer settings..."), Qt::AlignHCenter, Qt::yellow); qApp->processEvents(); readSettings(); splash.showMessage(tr("Constructing Player..."), Qt::AlignHCenter, Qt::yellow); qApp->processEvents(); mPlayerWidget = new PlayerWidget; connect(mPlayerWidget, SIGNAL(viewModeChanged(QString)), this, SLOT(setViewMode(QString))); connect(mPlayerWidget, SIGNAL(playModeChanged(QString)), this, SLOT(setPlayMode(QString))); connect(mPlayerWidget, SIGNAL(numFilesChanged(int)), this, SLOT(setNumFiles(int))); connect(mPlayerWidget, SIGNAL(playListLengthChanged(quint64)), this, SLOT(setPlayListLength(quint64))); connect(mPlayerWidget, SIGNAL(message(QString)), this, SLOT(setMessage(QString))); connect(mPlayerWidget, SIGNAL(setWinTitle(QString)), this, SLOT(setWindowTitle(QString))); createStatusbar(); setCentralWidget(mPlayerWidget); splash.showMessage(tr("Populating..."), Qt::AlignHCenter, Qt::yellow); qApp->processEvents(); mPlayerWidget->doStop(); mPlayerWidget->doPopulateByArtist(); splash.showMessage(tr("Reading settings..."), Qt::AlignHCenter, Qt::yellow); qApp->processEvents(); mPlayerWidget->readSettings(); } void BeetPlayer::openDatabase(){ QSettings s; QString dbhost = s.value("dbhost").toString(); QString dbuser = s.value("dbuser").toString(); QString dbpass = s.value("dbpass").toString(); QString dbname = s.value("dbname").toString(); if(!QSqlDatabase::contains("beetplayerdb")){ QSqlDatabase db = QSqlDatabase::addDatabase("QPSQL", "beetplayerdb"); db.setHostName(dbhost); db.setUserName(dbuser); db.setPassword(dbpass); db.setDatabaseName(dbname); if(!db.open()){ int res = ConfigurationDialog(this).exec(); if(res == QDialog::Accepted){ openDatabase(); }else{ QMessageBox::critical(this, tr("Error"), tr("Could not open database. Giving up!")); qApp->closeAllWindows(); } } } } void BeetPlayer::readSettings(){ QSettings s; bool useAltColors = s.value("usealtcolors", false).toBool(); if(useAltColors){ QPalette curPal = qApp->palette(); QVariant baseColorV = s.value("basecolor", palette().base().color()); QColor baseColor = baseColorV.value(); curPal.setColor(QPalette::Base, baseColor); QVariant altColorV = s.value("altcolor", palette().alternateBase().color()); QColor altColor = altColorV.value(); curPal.setColor(QPalette::AlternateBase, altColor); qApp->setPalette(curPal); } } void BeetPlayer::createGlobalActions(){ QAction *quitA = new QAction(tr("Quit"), this); quitA->setShortcut(tr("CTRL+Q")); connect(quitA, SIGNAL(triggered()), qApp, SLOT(closeAllWindows())); quitA->setData(Globals::QuitAction); Globals::instance()->addAction(quitA); QAction *configA = new QAction(QIcon(":/chastity_belt.png"), tr("Configure..."), this); connect(configA, SIGNAL(triggered()), this, SLOT(configure())); configA->setData(Globals::ConfigAction); Globals::instance()->addAction(configA); } void BeetPlayer::configure(){ ConfigurationDialog w(this); int res = w.exec(); if(res == QDialog::Accepted){ openDatabase(); } } void BeetPlayer::setViewMode(const QString &viewMode){ mModeL->setText(viewMode); } void BeetPlayer::setPlayMode(const QString &playMode){ mActionL->setText(playMode); } void BeetPlayer::setNumFiles(int numFiles){ QString n = QString("%1").arg(numFiles, 4, 10, QChar('0')); mFilesL->setText(n); } void BeetPlayer::setPlayListLength(quint64 seconds){ int h = (seconds / 60 / 60); int min = (seconds / 60) % 60; int secs = seconds % 60; QString r = QString("%1:%2:%3").arg(h, 3, 10, QChar('0')).arg(min, 2, 10, QChar('0')).arg(secs, 2, 10, QChar('0')); mPlaylistDurL->setText(r); } void BeetPlayer::setMessage(const QString &msg){ mGeneralL->setText(msg); } void BeetPlayer::createStatusbar(){ QLabel *l1 = new QLabel(tr("View:")); mModeL = new QLabel; mModeL->setFrameStyle(QFrame::Panel | QFrame::Sunken); mModeL->setFont(QFont("courier")); mModeL->setText(tr("Album")); statusBar()->addPermanentWidget(l1); statusBar()->addPermanentWidget(mModeL); mGeneralL = new QLabel; mGeneralL->setFrameStyle(QFrame::Panel | QFrame::Sunken); mGeneralL->setFont(QFont("courier")); statusBar()->addPermanentWidget(mGeneralL, 20); //20 is an arbitray value, stretch to max QLabel *l2 = new QLabel(tr("Status:")); mActionL = new QLabel; mActionL->setFrameStyle(QFrame::Panel | QFrame::Sunken); mActionL->setFont(QFont("courier")); mActionL->setText(tr("Stopped")); statusBar()->addPermanentWidget(l2); statusBar()->addPermanentWidget(mActionL); QLabel *l3 = new QLabel(tr("NumFiles:")); mFilesL = new QLabel; mFilesL->setFrameStyle(QFrame::Panel | QFrame::Sunken); mFilesL->setFont(QFont("courier")); mFilesL->setText(tr("0000")); statusBar()->addPermanentWidget(l3); statusBar()->addPermanentWidget(mFilesL); QLabel *l4 = new QLabel(tr("Dur:")); mPlaylistDurL = new QLabel; mPlaylistDurL->setFrameStyle(QFrame::Panel | QFrame::Sunken); mPlaylistDurL->setFont(QFont("courier")); mPlaylistDurL->setText("000:00:00"); statusBar()->addPermanentWidget(l4); statusBar()->addPermanentWidget(mPlaylistDurL); } void BeetPlayer::closeEvent(QCloseEvent *event){ Q_UNUSED(event); qApp->quit(); }