679fc61feb
stop, next file, previous file buttons along with the added feasures the buttons represent. i've also added png versions of all of the icons just in case the svg versions are not practical to use. i also fully built out a tray icon functionality so the application can now minimize to system tray. also updated the app logo to a new flat icon type sinewave look. then finally, i've added the restore button to the tray icon so it will restore the window back in front from the tray.
164 lines
3.5 KiB
C++
164 lines
3.5 KiB
C++
#include "io/conf.h"
|
|
|
|
MenuItem::MenuItem(const QString &label, QWidget *widget, QObject *parent) : QWidgetAction(parent)
|
|
{
|
|
str = label;
|
|
wid = widget;
|
|
}
|
|
|
|
QWidget *MenuItem::createWidget(QWidget *parent)
|
|
{
|
|
if (str.isEmpty())
|
|
{
|
|
wid->setParent(parent);
|
|
|
|
return wid;
|
|
}
|
|
else
|
|
{
|
|
QWidget *widget = new QWidget(parent);
|
|
QHBoxLayout *layout = new QHBoxLayout(widget);
|
|
|
|
layout->addWidget(wid);
|
|
layout->addWidget(new QLabel(str, parent));
|
|
|
|
return widget;
|
|
|
|
}
|
|
}
|
|
|
|
Conf::Conf(QObject *parent) : QObject(parent)
|
|
{
|
|
QFile file(confPath(), this);
|
|
|
|
QByteArray data;
|
|
|
|
if (file.open(QFile::ReadOnly))
|
|
{
|
|
data = file.readAll();
|
|
}
|
|
|
|
file.close();
|
|
|
|
Idm idm(data, this);
|
|
|
|
idm.rdHeader();
|
|
|
|
QByteArray pathBa = idm.value(LAST_PATH);
|
|
QByteArray nextBa = idm.value(NEXT_FILE);
|
|
QByteArray volBa = idm.value(VOLUME);
|
|
|
|
if (!pathBa.isEmpty()) lastPath = pathBa;
|
|
else lastPath = QDir::homePath();
|
|
if (!nextBa.isEmpty()) nextFileState = (nextBa == "Y");
|
|
else nextFileState = true;
|
|
if (!volBa.isEmpty()) volumeValue = rdInt(volBa);
|
|
else volumeValue = 50;
|
|
}
|
|
|
|
void Conf::sync()
|
|
{
|
|
Idm idm(this);
|
|
|
|
idm.wrHeader();
|
|
idm.insert(LAST_PATH, lastPath.toUtf8());
|
|
idm.insert(VOLUME, wrInt(volumeValue));
|
|
|
|
if (nextFileState) idm.insert(NEXT_FILE, "Y");
|
|
else idm.insert(NEXT_FILE, "N");
|
|
|
|
QFile file(confPath(), this);
|
|
|
|
file.open(QFile::WriteOnly | QFile::Truncate);
|
|
file.write(idm.getBuff());
|
|
}
|
|
|
|
void Conf::populateOptionsMenu(QMenu *menu, QWidget *parent)
|
|
{
|
|
QWidget *volWidget = new QWidget(parent);
|
|
QHBoxLayout *volLayout = new QHBoxLayout(volWidget);
|
|
QSlider *volSlider = new QSlider(parent);
|
|
QCheckBox *nextBox = new QCheckBox(parent);
|
|
Icon *volUp = new Icon(Icon::VOL_UP, parent);
|
|
Icon *volDown = new Icon(Icon::VOL_DOWN, parent);
|
|
|
|
volUp->setSlider(volSlider);
|
|
volDown->setSlider(volSlider);
|
|
volSlider->setMinimum(0);
|
|
volSlider->setMaximum(100);
|
|
volSlider->setValue(getVolume());
|
|
volSlider->setOrientation(Qt::Horizontal);
|
|
volLayout->addWidget(volDown);
|
|
volLayout->addWidget(volSlider);
|
|
volLayout->addWidget(volUp);
|
|
nextBox->setText(tr("Auto play next file in directory"));
|
|
nextBox->setChecked(nextFile());
|
|
|
|
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)));
|
|
|
|
menu->addAction(new MenuItem("", volWidget, this));
|
|
menu->addAction(new MenuItem("", nextBox, this));
|
|
}
|
|
|
|
void Conf::setLastPath(const QString &path)
|
|
{
|
|
lastPath = path; sync();
|
|
}
|
|
|
|
void Conf::setNextFile(bool state)
|
|
{
|
|
nextFileState = state; sync();
|
|
}
|
|
|
|
void Conf::setVolume(int value)
|
|
{
|
|
emit volume(value);
|
|
|
|
volumeValue = value; sync();
|
|
}
|
|
|
|
QString Conf::getLastPath()
|
|
{
|
|
if (!QDir(lastPath).exists())
|
|
{
|
|
lastPath = QDir::homePath();
|
|
}
|
|
|
|
return lastPath;
|
|
}
|
|
|
|
bool Conf::nextFile()
|
|
{
|
|
return nextFileState;
|
|
}
|
|
|
|
int Conf::getVolume()
|
|
{
|
|
return volumeValue;
|
|
}
|
|
|
|
QString Conf::confPath()
|
|
{
|
|
QString path = QDir::homePath() + '/';
|
|
|
|
#ifndef Q_OS_WIN32
|
|
|
|
path.append("/.config/");
|
|
|
|
#else
|
|
|
|
path.append("AppData/Local/");
|
|
|
|
#endif
|
|
|
|
QDir dir;
|
|
|
|
path.append(QApplication::applicationName() + '/');
|
|
|
|
dir.mkpath(path);
|
|
|
|
return path + "conf.idm";
|
|
}
|