diff --git a/gui/ui.cpp b/gui/ui.cpp index 4a3df29..d2c022f 100644 --- a/gui/ui.cpp +++ b/gui/ui.cpp @@ -5,6 +5,7 @@ Ui::Ui(const QStringList &args, QWidget *parent) : QWidget(parent) QWidget *btnWid = new QWidget(this); QHBoxLayout *btnLayout = new QHBoxLayout(btnWid); QVBoxLayout *mainLayout = new QVBoxLayout(this); + QLabel *timeDisp = new QLabel("00:00:00", this); Icon *trayPausePlay = new Icon(Icon::PAUSE_PLAY, this); Icon *trayOpen = new Icon(Icon::OPEN, this); Icon *trayStop = new Icon(Icon::STOP, this); @@ -38,7 +39,7 @@ Ui::Ui(const QStringList &args, QWidget *parent) : QWidget(parent) fileName->setText(tr("Ready")); fileName->setFont(fnt); slider->setOrientation(Qt::Horizontal); - trayIcon->show(); + trayIcon->setVisible(conf->trayIcon()); trayIcon->setContextMenu(trayMenu); conf->populateOptionsMenu(menu, this); player->setVolume(conf->getVolume()); @@ -56,6 +57,7 @@ Ui::Ui(const QStringList &args, QWidget *parent) : QWidget(parent) btnLayout->addWidget(settings); mainLayout->addWidget(fileName); mainLayout->addWidget(slider); + mainLayout->addWidget(timeDisp, 0, Qt::AlignCenter); mainLayout->addWidget(btnWid, 0, Qt::AlignCenter); connect(trayRestore, SIGNAL(restore()), this, SLOT(showNormal())); @@ -75,11 +77,13 @@ Ui::Ui(const QStringList &args, QWidget *parent) : QWidget(parent) connect(player, SIGNAL(error(QMediaPlayer::Error)), this, SLOT(error(QMediaPlayer::Error))); connect(player, SIGNAL(stateChanged(QMediaPlayer::State)), pausePlay, SLOT(stateChanged(QMediaPlayer::State))); connect(player, SIGNAL(stateChanged(QMediaPlayer::State)), trayPausePlay, SLOT(stateChanged(QMediaPlayer::State))); + connect(ioDev, SIGNAL(duration(QString)), timeDisp, SLOT(setText(QString))); connect(ioDev, SIGNAL(posChanged(qint64)), this, SLOT(posChanged(qint64))); connect(ioDev, SIGNAL(endOfPlayback()), this, SLOT(nextFile())); connect(slider, SIGNAL(sliderPressed()), this, SLOT(sliderPressed())); connect(slider, SIGNAL(sliderReleased()), this, SLOT(sliderReleased())); connect(conf, SIGNAL(volume(int)), player, SLOT(setVolume(int))); + connect(conf, SIGNAL(enableTrayIcon(bool)), trayIcon, SLOT(setVisible(bool))); if (args.size() > 1) { @@ -224,14 +228,21 @@ void Ui::fileDir(char direction) void Ui::trayActivated(QSystemTrayIcon::ActivationReason reason) { - Q_UNUSED(reason); - - trayMenu->popup(trayIcon->geometry().center()); + if (reason == QSystemTrayIcon::DoubleClick) + { + showNormal(); + raise(); + activateWindow(); + } + else if (reason == QSystemTrayIcon::Trigger) + { + trayMenu->popup(trayIcon->geometry().center()); + } } void Ui::changeEvent(QEvent *event) { - if (event->type() == QEvent::WindowStateChange) + if ((event->type() == QEvent::WindowStateChange) && conf->trayIcon()) { if (windowState() & Qt::WindowMinimized) { diff --git a/io/aud_file.cpp b/io/aud_file.cpp index 3d335fd..70007a8 100644 --- a/io/aud_file.cpp +++ b/io/aud_file.cpp @@ -96,9 +96,13 @@ qint64 AudFile::getOffset() return offset; } -qint64 AudFile::getDuration() +QString AudFile::getDuration() { - return ((size() - offset) / buffRate) * 1000; + QTime time(0, 0, 0, 0); + + time = time.addMSecs((size() / buffRate) * 1000); + + return time.toString("hh:mm:ss"); } void AudFile::delayFinished() diff --git a/io/aud_file.h b/io/aud_file.h index 75e18dd..179fd13 100644 --- a/io/aud_file.h +++ b/io/aud_file.h @@ -6,7 +6,9 @@ #include #include #include +#include #include +#include class AudFile : public QFile { @@ -26,10 +28,10 @@ public: AudFile(QObject *parent = 0); - bool openFile(const QString &path); - bool seek(qint64 off); - qint64 getOffset(); - qint64 getDuration(); + bool openFile(const QString &path); + bool seek(qint64 off); + qint64 getOffset(); + QString getDuration(); ~AudFile(); @@ -37,7 +39,7 @@ signals: void posChanged(qint64 off); void endOfPlayback(); - void duration(qint64 msec); + void duration(QString timeStr); }; #endif // AUD_FILE_H diff --git a/io/conf.cpp b/io/conf.cpp index 4b588fa..3a27ba8 100644 --- a/io/conf.cpp +++ b/io/conf.cpp @@ -23,7 +23,6 @@ QWidget *MenuItem::createWidget(QWidget *parent) layout->addWidget(new QLabel(str, parent)); return widget; - } } @@ -46,12 +45,15 @@ Conf::Conf(QObject *parent) : QObject(parent) QByteArray pathBa = idm.value(LAST_PATH); QByteArray nextBa = idm.value(NEXT_FILE); + QByteArray trayBa = idm.value(TRAY_ICON); QByteArray volBa = idm.value(VOLUME); if (!pathBa.isEmpty()) lastPath = pathBa; else lastPath = QDir::homePath(); if (!nextBa.isEmpty()) nextFileState = (nextBa == "Y"); else nextFileState = true; + if (!trayBa.isEmpty()) showTrayIcon = (trayBa == "Y"); + else showTrayIcon = false; if (!volBa.isEmpty()) volumeValue = rdInt(volBa); else volumeValue = 50; } @@ -67,6 +69,9 @@ void Conf::sync() if (nextFileState) idm.insert(NEXT_FILE, "Y"); else idm.insert(NEXT_FILE, "N"); + if (showTrayIcon) idm.insert(TRAY_ICON, "Y"); + else idm.insert(TRAY_ICON, "N"); + QFile file(confPath(), this); file.open(QFile::WriteOnly | QFile::Truncate); @@ -79,6 +84,7 @@ void Conf::populateOptionsMenu(QMenu *menu, QWidget *parent) QHBoxLayout *volLayout = new QHBoxLayout(volWidget); QSlider *volSlider = new QSlider(parent); QCheckBox *nextBox = new QCheckBox(parent); + QCheckBox *trayBox = new QCheckBox(parent); Icon *volUp = new Icon(Icon::VOL_UP, parent); Icon *volDown = new Icon(Icon::VOL_DOWN, parent); @@ -93,13 +99,17 @@ void Conf::populateOptionsMenu(QMenu *menu, QWidget *parent) volLayout->addWidget(volUp); nextBox->setText(tr("Auto play next file in directory")); nextBox->setChecked(nextFile()); + trayBox->setText(tr("Enable tray icon")); + trayBox->setChecked(trayIcon()); connect(volSlider, SIGNAL(valueChanged(int)), this, SLOT(setVolume(int))); connect(volSlider, SIGNAL(valueChanged(int)), this, SIGNAL(volume(int))); connect(nextBox, SIGNAL(clicked(bool)), this, SLOT(setNextFile(bool))); + connect(trayBox, SIGNAL(clicked(bool)), this, SLOT(setTrayIcon(bool))); menu->addAction(new MenuItem("", volWidget, this)); menu->addAction(new MenuItem("", nextBox, this)); + menu->addAction(new MenuItem("", trayBox, this)); } void Conf::setLastPath(const QString &path) @@ -112,6 +122,13 @@ void Conf::setNextFile(bool state) nextFileState = state; sync(); } +void Conf::setTrayIcon(bool state) +{ + emit enableTrayIcon(state); + + showTrayIcon = state; sync(); +} + void Conf::setVolume(int value) { emit volume(value); @@ -134,6 +151,11 @@ bool Conf::nextFile() return nextFileState; } +bool Conf::trayIcon() +{ + return showTrayIcon; +} + int Conf::getVolume() { return volumeValue; diff --git a/io/conf.h b/io/conf.h index 1d57833..e5c7ac6 100644 --- a/io/conf.h +++ b/io/conf.h @@ -42,10 +42,12 @@ private: { LAST_PATH = 1, NEXT_FILE, - VOLUME + VOLUME, + TRAY_ICON }; QString lastPath; + bool showTrayIcon; bool nextFileState; int volumeValue; @@ -57,11 +59,13 @@ public slots: void setLastPath(const QString &path); void setNextFile(bool state); void setVolume(int value); + void setTrayIcon(bool state); public: QString getLastPath(); bool nextFile(); + bool trayIcon(); void populateOptionsMenu(QMenu *menu, QWidget *parent); int getVolume(); @@ -69,7 +73,8 @@ public: signals: - void volume(int); + void volume(int value); + void enableTrayIcon(bool state); }; #endif // CONF_H