| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367 |
- #include "MultimediaPersistent.h"
- #include <QDebug>
- #include <QFile>
- #include <QSettings>
- #include <QCoreApplication>
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <fcntl.h>
- #include <unistd.h>
- #include <stdio.h>
- static const QString persistentPath("/data/Multimedia.ini");
- static const QString persistentPathBackup("/data/MultimediaBackup.ini");
- static const QString Exists("Exists");
- static const QString SDMultimedia("SDMultimedia");
- static const QString USBMultimedia("USBMultimedia");
- static const QString SDMusicMillesmial("SDMusicMillesmial");
- static const QString SDMusicPathInfo("SDMusicPathInfo");
- static const QString USBMusicMillesmial("USBMusicMillesmial");
- static const QString USBMusicPathInfo("USBMusicPathInfo");
- static const QString SDImagePathInfo("SDImagePathInfo");
- static const QString USBImagePathInfo("USBImagePathInfo");
- static const QString SDVideoMillesmial("SDVideoMillesmial");
- static const QString SDVideoPathInfo("SDVideoPathInfo");
- static const QString USBVideoMillesmial("USBVideoMillesmial");
- static const QString USBVideoPathInfo("USBVideoPathInfo");
- class MultimediaSettings : public QSettings
- {
- Q_DISABLE_COPY(MultimediaSettings)
- #ifdef g_Settings
- #undef g_Settings
- #endif
- #define g_Settings (MultimediaSettings::instance())
- public:
- inline static MultimediaSettings* instance() {
- static MultimediaSettings* settings(new MultimediaSettings(qApp));
- return settings;
- }
- void clear();
- void sync();
- void setValue(const QString &key, const QVariant &value);
- private:
- explicit MultimediaSettings(QObject* parent = NULL);
- ~MultimediaSettings();
- QSettings m_SettingsBackup;
- };
- void MultimediaSettings::clear()
- {
- QSettings::clear();
- m_SettingsBackup.clear();
- }
- void MultimediaSettings::sync()
- {
- // QSettings::sync();
- // m_SettingsBackup.sync();
- system("sync");
- }
- void MultimediaSettings::setValue(const QString &key, const QVariant &value)
- {
- if (!contains(Exists)) {
- QSettings::setValue(Exists, QVariant(bool(true)));
- }
- QSettings::setValue(key, value);
- if (!m_SettingsBackup.contains(Exists)) {
- m_SettingsBackup.setValue(Exists, QVariant(bool(true)));
- }
- m_SettingsBackup.setValue(key, value);
- }
- MultimediaSettings::MultimediaSettings(QObject *parent)
- : QSettings(persistentPath, QSettings::IniFormat, parent)
- , m_SettingsBackup(persistentPathBackup, QSettings::IniFormat, parent)
- {
- bool ret(true);
- if (contains(Exists) && (!m_SettingsBackup.contains(Exists))) {
- QFile::remove(persistentPathBackup);
- ret = QFile::copy(persistentPath, persistentPathBackup);
- } else if ((!contains(Exists)) && m_SettingsBackup.contains(Exists)) {
- QFile::remove(persistentPath);
- ret = QFile::copy(persistentPathBackup, persistentPath);
- }
- if (!ret) {
- qWarning() << __FUNCTION__ << "copy failed!";
- }
- }
- MultimediaSettings::~MultimediaSettings()
- {
- qDebug();
- }
- int MultimediaPersistent::getMusicMillesmial(const DeviceWatcherType type, const bool reload)
- {
- QString pathInfo("");
- switch (type) {
- case DWT_SDDisk: {
- pathInfo = SDMusicMillesmial;
- break;
- }
- case DWT_USBDisk: {
- pathInfo = USBMusicMillesmial;
- break;
- }
- default: {
- return 0;
- break;
- }
- }
- if (reload) {
- g_Settings->sync();
- }
- bool flag(false);
- int ret = g_Settings->value(pathInfo, QVariant(0)).toInt(&flag);
- if (!flag) {
- ret = 0;
- }
- return ret;
- }
- QString MultimediaPersistent::getMusicPathInfo(const DeviceWatcherType type, const bool reload)
- {
- QString pathInfo("");
- switch (type) {
- case DWT_SDDisk: {
- pathInfo = SDMusicPathInfo;
- break;
- }
- case DWT_USBDisk: {
- pathInfo = USBMusicPathInfo;
- break;
- }
- default: {
- return pathInfo;
- break;
- }
- }
- if (reload) {
- g_Settings->sync();
- }
- return g_Settings->value(pathInfo, QVariant(QString(""))).toString();
- }
- QString MultimediaPersistent::getImagePathInfo(const DeviceWatcherType type, const bool reload)
- {
- QString pathInfo("");
- QString imagePathInfo("");
- switch (type) {
- case DWT_SDDisk: {
- pathInfo = SDImagePathInfo;
- break;
- }
- case DWT_USBDisk: {
- pathInfo = USBImagePathInfo;
- break;
- }
- default: {
- return pathInfo;
- break;
- }
- }
- if (reload) {
- g_Settings->sync();
- }
- imagePathInfo = g_Settings->value(pathInfo, QVariant(QString(""))).toString();
- return imagePathInfo;
- }
- int MultimediaPersistent::getVideoMillesmial(const DeviceWatcherType type, const bool reload)
- {
- QString pathInfo("");
- switch (type) {
- case DWT_SDDisk: {
- pathInfo = SDVideoMillesmial;
- break;
- }
- case DWT_USBDisk: {
- pathInfo = USBVideoMillesmial;
- break;
- }
- default: {
- return 0;
- break;
- }
- }
- if (reload) {
- g_Settings->sync();
- }
- bool flag(false);
- int ret = g_Settings->value(pathInfo, QVariant(0)).toInt(&flag);
- if (!flag) {
- ret = 0;
- }
- return ret;
- }
- QString MultimediaPersistent::getVideoPathInfo(const DeviceWatcherType type, const bool reload)
- {
- QString pathInfo("");
- switch (type) {
- case DWT_SDDisk: {
- pathInfo = SDVideoPathInfo;
- break;
- }
- case DWT_USBDisk: {
- pathInfo = USBVideoPathInfo;
- break;
- }
- default: {
- return pathInfo;
- break;
- }
- }
- if (reload) {
- g_Settings->sync();
- }
- return g_Settings->value(pathInfo, QVariant(QString(""))).toString();
- }
- void MultimediaPersistent::setMultimediaType(const DeviceWatcherType deviceWatcherType, const MultimediaType multimediaType)
- {
- QString path("");
- switch (deviceWatcherType) {
- case DWT_SDDisk: {
- path = SDMultimedia;
- break;
- }
- case DWT_USBDisk: {
- path = USBMultimedia;
- break;
- }
- default: {
- return;
- break;
- }
- }
- g_Settings->setValue(path, multimediaType);
- g_Settings->sync();
- }
- void MultimediaPersistent::setMusicMillesmial(const DeviceWatcherType type, const int elapsed)
- {
- switch (type) {
- case DWT_SDDisk: {
- g_Settings->setValue(SDMusicMillesmial, elapsed);
- break;
- }
- case DWT_USBDisk: {
- g_Settings->setValue(USBMusicMillesmial, elapsed);
- break;
- }
- default: {
- break;
- }
- }
- g_Settings->sync();
- }
- void MultimediaPersistent::setMusicPathInfo(const DeviceWatcherType type, const QString &pathInfo)
- {
- switch (type) {
- case DWT_SDDisk: {
- g_Settings->setValue(SDMusicPathInfo, pathInfo);
- break;
- }
- case DWT_USBDisk: {
- g_Settings->setValue(USBMusicPathInfo, pathInfo);
- break;
- }
- default: {
- break;
- }
- }
- qDebug()<<"++++++++setMusicPathInfo2222++++++++++";
- g_Settings->sync();
- qDebug()<<"++++++++setMusicPathInfo3333++++++++++";
- }
- void MultimediaPersistent::setImagePathInfo(const DeviceWatcherType type, const QString &pathInfo)
- {
- switch (type) {
- case DWT_SDDisk: {
- g_Settings->setValue(SDImagePathInfo, pathInfo);
- break;
- }
- case DWT_USBDisk: {
- g_Settings->setValue(USBImagePathInfo, pathInfo);
- break;
- }
- default: {
- break;
- }
- }
- g_Settings->sync();
- }
- /*设置视频断点记忆*///modify by wandz 20190418不再视频记忆,解码错误
- void MultimediaPersistent::setVideoMillesmial(const DeviceWatcherType type, const int elapsed)
- {
- switch (type) {
- case DWT_SDDisk: {
- g_Settings->setValue(SDVideoMillesmial, elapsed);
- break;
- }
- case DWT_USBDisk: {
- g_Settings->setValue(USBVideoMillesmial, elapsed);
- break;
- }
- default: {
- break;
- }
- }
- g_Settings->sync();
- }
- void MultimediaPersistent::setVideoPathInfo(const DeviceWatcherType type, const QString &pathInfo)
- {
- switch (type) {
- case DWT_SDDisk: {
- g_Settings->setValue(SDVideoPathInfo, pathInfo);
- break;
- }
- case DWT_USBDisk: {
- g_Settings->setValue(USBVideoPathInfo, pathInfo);
- break;
- }
- default: {
- break;
- }
- }
- g_Settings->sync();
- }
- int MultimediaPersistent::getMultimediaType(const DeviceWatcherType deviceWatcherType, const bool reload)
- {
- QString pathInfo("");
- switch (deviceWatcherType) {
- case DWT_SDDisk: {
- pathInfo = SDMultimedia;
- break;
- }
- case DWT_USBDisk: {
- pathInfo = USBMultimedia;
- break;
- }
- default: {
- return 0;
- break;
- }
- }
- if (reload) {
- g_Settings->sync();
- }
- bool flag(false);
- int ret = g_Settings->value(pathInfo, QVariant(0)).toInt(&flag);
- if (!flag) {
- ret = 0;
- }
- return ret;
- }
- void MultimediaPersistent::reset()
- {
- g_Settings->clear();
- g_Settings->sync();
- }
|