1
0

MultimediaPersistent.cpp 8.8 KB

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