MultimediaPersistent.cpp 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  1. #include "MultimediaPersistent.h"
  2. #include "configUtils.h"
  3. #include <QDebug>
  4. #include <QFile>
  5. #include <QSettings>
  6. #include <QCoreApplication>
  7. #include <sys/types.h>
  8. #include <sys/stat.h>
  9. #include <fcntl.h>
  10. #include <unistd.h>
  11. #include <stdio.h>
  12. static const QString persistentPath("/data/Multimedia.ini");
  13. static const QString persistentPathBackup("/data/MultimediaBackup.ini");
  14. static const QString Exists("Exists");
  15. static const QString SDMultimedia("SDMultimedia");
  16. static const QString USBMultimedia("USBMultimedia");
  17. static const QString SDMusicMillesmial("SDMusicMillesmial");
  18. static const QString SDMusicPathInfo("SDMusicPathInfo");
  19. static const QString USBMusicMillesmial("USBMusicMillesmial");
  20. static const QString USBMusicPathInfo("USBMusicPathInfo");
  21. static const QString SDImagePathInfo("SDImagePathInfo");
  22. static const QString USBImagePathInfo("USBImagePathInfo");
  23. static const QString SDVideoMillesmial("SDVideoMillesmial");
  24. static const QString SDVideoPathInfo("SDVideoPathInfo");
  25. static const QString USBVideoMillesmial("USBVideoMillesmial");
  26. static const QString USBVideoPathInfo("USBVideoPathInfo");
  27. class MultimediaSettings : public QSettings
  28. {
  29. Q_DISABLE_COPY(MultimediaSettings)
  30. #ifdef g_Settings
  31. #undef g_Settings
  32. #endif
  33. #define g_Settings (MultimediaSettings::instance())
  34. public:
  35. inline static MultimediaSettings* instance() {
  36. static MultimediaSettings* settings(new MultimediaSettings(qApp));
  37. return settings;
  38. }
  39. void clear();
  40. void sync();
  41. void setValue(const QString &key, const QVariant &value);
  42. private:
  43. explicit MultimediaSettings(QObject* parent = NULL);
  44. ~MultimediaSettings();
  45. QSettings m_SettingsBackup;
  46. };
  47. void MultimediaSettings::clear()
  48. {
  49. QSettings::clear();
  50. m_SettingsBackup.clear();
  51. }
  52. void MultimediaSettings::sync()
  53. {
  54. // QSettings::sync();
  55. // m_SettingsBackup.sync();
  56. CHECK_SYSTEM("sync");
  57. }
  58. void MultimediaSettings::setValue(const QString &key, const QVariant &value)
  59. {
  60. if (!contains(Exists)) {
  61. QSettings::setValue(Exists, QVariant(bool(true)));
  62. }
  63. QSettings::setValue(key, value);
  64. if (!m_SettingsBackup.contains(Exists)) {
  65. m_SettingsBackup.setValue(Exists, QVariant(bool(true)));
  66. }
  67. m_SettingsBackup.setValue(key, value);
  68. }
  69. MultimediaSettings::MultimediaSettings(QObject *parent)
  70. : QSettings(persistentPath, QSettings::IniFormat, parent)
  71. , m_SettingsBackup(persistentPathBackup, QSettings::IniFormat, parent)
  72. {
  73. bool ret(true);
  74. if (contains(Exists) && (!m_SettingsBackup.contains(Exists))) {
  75. QFile::remove(persistentPathBackup);
  76. ret = QFile::copy(persistentPath, persistentPathBackup);
  77. } else if ((!contains(Exists)) && m_SettingsBackup.contains(Exists)) {
  78. QFile::remove(persistentPath);
  79. ret = QFile::copy(persistentPathBackup, persistentPath);
  80. }
  81. if (!ret) {
  82. qWarning() << __FUNCTION__ << "copy failed!";
  83. }
  84. }
  85. MultimediaSettings::~MultimediaSettings()
  86. {
  87. qDebug();
  88. }
  89. int MultimediaPersistent::getMusicMillesmial(const DeviceWatcherType type, const bool reload)
  90. {
  91. QString pathInfo("");
  92. switch (type) {
  93. case DWT_SDDisk: {
  94. pathInfo = SDMusicMillesmial;
  95. break;
  96. }
  97. case DWT_USBDisk: {
  98. pathInfo = USBMusicMillesmial;
  99. break;
  100. }
  101. default: {
  102. return 0;
  103. break;
  104. }
  105. }
  106. if (reload) {
  107. g_Settings->sync();
  108. }
  109. bool flag(false);
  110. int ret = g_Settings->value(pathInfo, QVariant(0)).toInt(&flag);
  111. if (!flag) {
  112. ret = 0;
  113. }
  114. return ret;
  115. }
  116. QString MultimediaPersistent::getMusicPathInfo(const DeviceWatcherType type, const bool reload)
  117. {
  118. QString pathInfo("");
  119. switch (type) {
  120. case DWT_SDDisk: {
  121. pathInfo = SDMusicPathInfo;
  122. break;
  123. }
  124. case DWT_USBDisk: {
  125. pathInfo = USBMusicPathInfo;
  126. break;
  127. }
  128. default: {
  129. return pathInfo;
  130. break;
  131. }
  132. }
  133. if (reload) {
  134. g_Settings->sync();
  135. }
  136. return g_Settings->value(pathInfo, QVariant(QString(""))).toString();
  137. }
  138. QString MultimediaPersistent::getImagePathInfo(const DeviceWatcherType type, const bool reload)
  139. {
  140. QString pathInfo("");
  141. QString imagePathInfo("");
  142. switch (type) {
  143. case DWT_SDDisk: {
  144. pathInfo = SDImagePathInfo;
  145. break;
  146. }
  147. case DWT_USBDisk: {
  148. pathInfo = USBImagePathInfo;
  149. break;
  150. }
  151. default: {
  152. return pathInfo;
  153. break;
  154. }
  155. }
  156. if (reload) {
  157. g_Settings->sync();
  158. }
  159. imagePathInfo = g_Settings->value(pathInfo, QVariant(QString(""))).toString();
  160. return imagePathInfo;
  161. }
  162. int MultimediaPersistent::getVideoMillesmial(const DeviceWatcherType type, const bool reload)
  163. {
  164. QString pathInfo("");
  165. switch (type) {
  166. case DWT_SDDisk: {
  167. pathInfo = SDVideoMillesmial;
  168. break;
  169. }
  170. case DWT_USBDisk: {
  171. pathInfo = USBVideoMillesmial;
  172. break;
  173. }
  174. default: {
  175. return 0;
  176. break;
  177. }
  178. }
  179. if (reload) {
  180. g_Settings->sync();
  181. }
  182. bool flag(false);
  183. int ret = g_Settings->value(pathInfo, QVariant(0)).toInt(&flag);
  184. if (!flag) {
  185. ret = 0;
  186. }
  187. return ret;
  188. }
  189. QString MultimediaPersistent::getVideoPathInfo(const DeviceWatcherType type, const bool reload)
  190. {
  191. QString pathInfo("");
  192. switch (type) {
  193. case DWT_SDDisk: {
  194. pathInfo = SDVideoPathInfo;
  195. break;
  196. }
  197. case DWT_USBDisk: {
  198. pathInfo = USBVideoPathInfo;
  199. break;
  200. }
  201. default: {
  202. return pathInfo;
  203. break;
  204. }
  205. }
  206. if (reload) {
  207. g_Settings->sync();
  208. }
  209. return g_Settings->value(pathInfo, QVariant(QString(""))).toString();
  210. }
  211. void MultimediaPersistent::setMultimediaType(const DeviceWatcherType deviceWatcherType, const MultimediaType multimediaType)
  212. {
  213. QString path("");
  214. switch (deviceWatcherType) {
  215. case DWT_SDDisk: {
  216. path = SDMultimedia;
  217. break;
  218. }
  219. case DWT_USBDisk: {
  220. path = USBMultimedia;
  221. break;
  222. }
  223. default: {
  224. return;
  225. break;
  226. }
  227. }
  228. g_Settings->setValue(path, multimediaType);
  229. g_Settings->sync();
  230. }
  231. void MultimediaPersistent::setMusicMillesmial(const DeviceWatcherType type, const int elapsed)
  232. {
  233. switch (type) {
  234. case DWT_SDDisk: {
  235. g_Settings->setValue(SDMusicMillesmial, elapsed);
  236. break;
  237. }
  238. case DWT_USBDisk: {
  239. g_Settings->setValue(USBMusicMillesmial, elapsed);
  240. break;
  241. }
  242. default: {
  243. break;
  244. }
  245. }
  246. g_Settings->sync();
  247. }
  248. void MultimediaPersistent::setMusicPathInfo(const DeviceWatcherType type, const QString &pathInfo)
  249. {
  250. switch (type) {
  251. case DWT_SDDisk: {
  252. g_Settings->setValue(SDMusicPathInfo, pathInfo);
  253. break;
  254. }
  255. case DWT_USBDisk: {
  256. g_Settings->setValue(USBMusicPathInfo, pathInfo);
  257. break;
  258. }
  259. default: {
  260. break;
  261. }
  262. }
  263. qDebug()<<"++++++++setMusicPathInfo2222++++++++++";
  264. g_Settings->sync();
  265. qDebug()<<"++++++++setMusicPathInfo3333++++++++++";
  266. }
  267. void MultimediaPersistent::setImagePathInfo(const DeviceWatcherType type, const QString &pathInfo)
  268. {
  269. switch (type) {
  270. case DWT_SDDisk: {
  271. g_Settings->setValue(SDImagePathInfo, pathInfo);
  272. break;
  273. }
  274. case DWT_USBDisk: {
  275. g_Settings->setValue(USBImagePathInfo, pathInfo);
  276. break;
  277. }
  278. default: {
  279. break;
  280. }
  281. }
  282. g_Settings->sync();
  283. }
  284. /*设置视频断点记忆*///modify by wandz 20190418不再视频记忆,解码错误
  285. void MultimediaPersistent::setVideoMillesmial(const DeviceWatcherType type, const int elapsed)
  286. {
  287. switch (type) {
  288. case DWT_SDDisk: {
  289. g_Settings->setValue(SDVideoMillesmial, elapsed);
  290. break;
  291. }
  292. case DWT_USBDisk: {
  293. g_Settings->setValue(USBVideoMillesmial, elapsed);
  294. break;
  295. }
  296. default: {
  297. break;
  298. }
  299. }
  300. g_Settings->sync();
  301. }
  302. void MultimediaPersistent::setVideoPathInfo(const DeviceWatcherType type, const QString &pathInfo)
  303. {
  304. switch (type) {
  305. case DWT_SDDisk: {
  306. g_Settings->setValue(SDVideoPathInfo, pathInfo);
  307. break;
  308. }
  309. case DWT_USBDisk: {
  310. g_Settings->setValue(USBVideoPathInfo, pathInfo);
  311. break;
  312. }
  313. default: {
  314. break;
  315. }
  316. }
  317. g_Settings->sync();
  318. }
  319. int MultimediaPersistent::getMultimediaType(const DeviceWatcherType deviceWatcherType, const bool reload)
  320. {
  321. QString pathInfo("");
  322. switch (deviceWatcherType) {
  323. case DWT_SDDisk: {
  324. pathInfo = SDMultimedia;
  325. break;
  326. }
  327. case DWT_USBDisk: {
  328. pathInfo = USBMultimedia;
  329. break;
  330. }
  331. default: {
  332. return 0;
  333. break;
  334. }
  335. }
  336. if (reload) {
  337. g_Settings->sync();
  338. }
  339. bool flag(false);
  340. int ret = g_Settings->value(pathInfo, QVariant(0)).toInt(&flag);
  341. if (!flag) {
  342. ret = 0;
  343. }
  344. return ret;
  345. }
  346. void MultimediaPersistent::reset()
  347. {
  348. g_Settings->clear();
  349. g_Settings->sync();
  350. }