mysettings.cpp 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603
  1. #include "mysettings.h"
  2. #include <QDir>
  3. QString MySettings::appName = "meegim";
  4. QString MySettings::pathMeegIMHome = QDir::homePath() + QDir::separator() + ".config" + QDir::separator() + appName;
  5. QString MySettings::pathMeegIMCache = pathMeegIMHome + QDir::separator() + QString("cache");
  6. QString MySettings::fileConfig = pathMeegIMHome + QDir::separator() + MySettings::appName + ".conf";
  7. MySettings::MySettings(QObject *parent) : QSettings(MySettings::fileConfig, QSettings::NativeFormat , parent)
  8. {
  9. group_main = "main";
  10. group_gui = "gui";
  11. group_xmpp = "xmpp";
  12. group_accounts = "accounts";
  13. key_jid = "jid";
  14. key_passwd = "passwd";
  15. key_showGroup = "show_groups";
  16. key_lastPresence = "show_last_presence";
  17. key_accounts = "accounts";
  18. key_resource = "resource";
  19. key_status_text = "status_text";
  20. key_status = "status";
  21. key_default = "is_default";
  22. key_useHostPort = "use_host_port";
  23. key_host = "host";
  24. key_port = "port";
  25. key_sndIncomingMsg = "snd_incoming_message";
  26. key_sndOutcomingMsg = "snd_outcoming_message";
  27. key_notifyConnection = "notify_connection";
  28. key_notifyOnline = "notify_online";
  29. key_notifyOffline = "notify_offline";
  30. key_notifyMessage = "notify_message";
  31. key_notifyTyping = "notify_typing";
  32. key_sndBuddyLogsIn = "snd_buddy_logs_in";
  33. key_sndBuddyLogsOut = "snd_buddy_logs_out";
  34. key_reconnectOnError = "reconnect_when_error";
  35. key_keepAliveInterval = "keep_alive_interval";
  36. key_sndChatSome1SaysMyName = "sndchat_someone_says_my_name";
  37. key_sndChatPersonEnters = "sndchat_person_enters";
  38. key_sndChatPersonLeaves = "sndchat_person_leaves";
  39. key_sndChatOthersTalk = "sndchat_others_talk";
  40. key_sndChatITalk = "sndchat_I_talk";
  41. key_vibrMessageRecv = "vibration_msg_recv";
  42. key_vibrMessageSent = "vibration_msg_sent";
  43. key_vibrChatSaysMyName = "vibration_chat_says_my_name";
  44. key_vibrChatOthersTalk = "vibration_chat_others_talk";
  45. key_smilesTheme = "smiles_theme";
  46. }
  47. QStringList MySettings::getListAccounts()
  48. {
  49. beginGroup( group_accounts );
  50. QVariant ret = value( key_accounts, QStringList() );
  51. endGroup();
  52. return ret.toStringList();
  53. }
  54. void MySettings::addAccount( const QString &acc )
  55. {
  56. beginGroup( group_accounts );
  57. QVariant retList = value( key_accounts, QStringList() );
  58. QStringList sl = retList.toStringList();
  59. if( sl.indexOf(acc) < 0 ) {
  60. sl.append(acc);
  61. setValue( key_accounts, QVariant(sl) );
  62. }
  63. endGroup();
  64. }
  65. void MySettings::remAccount( const QString &acc )
  66. {
  67. beginGroup( group_accounts );
  68. QVariant retList = value( key_accounts, QStringList() );
  69. QStringList sl = retList.toStringList();
  70. if( sl.indexOf(acc) >= 0 ) {
  71. sl.removeOne(acc);
  72. setValue( key_accounts, QVariant(sl) );
  73. }
  74. endGroup();
  75. }
  76. /*-------------------*/
  77. QString MySettings::getPasswd(const QString &jid)
  78. {
  79. beginGroup( jid );
  80. QVariant ret = value( key_passwd, QString("") );
  81. endGroup();
  82. return ret.toString();
  83. }
  84. void MySettings::setPasswd(const QString &jid, const QString &passwd)
  85. {
  86. beginGroup( jid );
  87. setValue( key_passwd, QVariant(passwd) );
  88. endGroup();
  89. }
  90. /*-----------*/
  91. QString MySettings::getResource(const QString &jid)
  92. {
  93. beginGroup( jid );
  94. QVariant ret = value( key_resource, QString("") );
  95. endGroup();
  96. return ret.toString();
  97. }
  98. void MySettings::setResource(const QString &jid, const QString &resource)
  99. {
  100. beginGroup( jid );
  101. setValue( key_resource, QVariant(resource) );
  102. endGroup();
  103. }
  104. /*-----------*/
  105. bool MySettings::isAccDefault(const QString &jid)
  106. {
  107. beginGroup( jid );
  108. QVariant ret = value( key_default, false );
  109. endGroup();
  110. return ret.toBool();
  111. }
  112. void MySettings::setAccDefault(const QString &jid, const bool &def)
  113. {
  114. beginGroup( jid );
  115. setValue( key_default, QVariant(def) );
  116. endGroup();
  117. }
  118. /*-----------*/
  119. bool MySettings::isHostPortManually(const QString &jid)
  120. {
  121. beginGroup( jid );
  122. QVariant ret = value( key_useHostPort, false );
  123. endGroup();
  124. return ret.toBool();
  125. }
  126. void MySettings::setHostPortManually(const QString &jid, const bool &def)
  127. {
  128. beginGroup( jid );
  129. setValue( key_useHostPort, QVariant(def) );
  130. endGroup();
  131. }
  132. /*-----------*/
  133. QString MySettings::getHost(const QString &jid)
  134. {
  135. beginGroup( jid );
  136. QVariant ret = value( key_host, QString("") );
  137. endGroup();
  138. return ret.toString();
  139. }
  140. void MySettings::setHost(const QString &jid, const QString &host)
  141. {
  142. beginGroup( jid );
  143. setValue( key_host, QVariant(host) );
  144. endGroup();
  145. }
  146. /*-----------*/
  147. int MySettings::getPort(const QString &jid)
  148. {
  149. beginGroup( jid );
  150. QVariant ret = value( key_port, 0 );
  151. endGroup();
  152. return ret.toInt();
  153. }
  154. void MySettings::setPort(const QString &jid, const int port)
  155. {
  156. beginGroup( jid );
  157. setValue( key_port, QVariant(port) );
  158. endGroup();
  159. }
  160. /*-----------*/
  161. QString MySettings::getStatus()
  162. {
  163. beginGroup( group_main );
  164. QVariant ret = value( key_status, QString("") );
  165. endGroup();
  166. return ret.toString();
  167. }
  168. void MySettings::setStatus( const QString &status)
  169. {
  170. beginGroup( group_main );
  171. setValue( key_status, QVariant(status) );
  172. endGroup();
  173. }
  174. /*-----------*/
  175. QString MySettings::getStatusText()
  176. {
  177. beginGroup( group_main );
  178. QVariant ret = value( key_status_text, QString("") );
  179. endGroup();
  180. return ret.toString();
  181. }
  182. void MySettings::setStatusText( const QString &status_text)
  183. {
  184. beginGroup( group_main );
  185. setValue( key_status_text, QVariant(status_text) );
  186. endGroup();
  187. }
  188. /*-----------*/
  189. QString MySettings::getSndIncomingMsg()
  190. {
  191. beginGroup( group_main );
  192. QVariant ret = value( key_sndIncomingMsg, QString("") );
  193. endGroup();
  194. return ret.toString();
  195. }
  196. void MySettings::setSndIncomingMsg( const QString &f )
  197. {
  198. beginGroup( group_main );
  199. setValue( key_sndIncomingMsg, QVariant(f) );
  200. endGroup();
  201. }
  202. /*-----------*/
  203. QString MySettings::getSndOutcomingMsg()
  204. {
  205. beginGroup( group_main );
  206. QVariant ret = value( key_sndOutcomingMsg, QString("") );
  207. endGroup();
  208. return ret.toString();
  209. }
  210. void MySettings::setSndOutcomingMsg( const QString &f )
  211. {
  212. beginGroup( group_main );
  213. setValue( key_sndOutcomingMsg, QVariant(f) );
  214. endGroup();
  215. }
  216. /*------------------------*/
  217. bool MySettings::notifyConnection()
  218. {
  219. beginGroup( group_main );
  220. QVariant ret = value( key_notifyConnection, true );
  221. endGroup();
  222. return ret.toBool();
  223. }
  224. void MySettings::setNotifyConnection( const bool def )
  225. {
  226. beginGroup( group_main );
  227. setValue( key_notifyConnection, QVariant(def) );
  228. endGroup();
  229. }
  230. /*------------------------*/
  231. bool MySettings::notifyOnline()
  232. {
  233. beginGroup( group_main );
  234. QVariant ret = value( key_notifyOnline, true );
  235. endGroup();
  236. return ret.toBool();
  237. }
  238. void MySettings::setNotifyOnline( const bool def )
  239. {
  240. beginGroup( group_main );
  241. setValue( key_notifyOnline, QVariant(def) );
  242. endGroup();
  243. }
  244. /*------------------------*/
  245. bool MySettings::notifyOffline()
  246. {
  247. beginGroup( group_main );
  248. QVariant ret = value( key_notifyOffline, true );
  249. endGroup();
  250. return ret.toBool();
  251. }
  252. void MySettings::setNotifyOffline( const bool def )
  253. {
  254. beginGroup( group_main );
  255. setValue( key_notifyOffline, QVariant(def) );
  256. endGroup();
  257. }
  258. /*------------------------*/
  259. bool MySettings::notifyMessage()
  260. {
  261. beginGroup( group_main );
  262. QVariant ret = value( key_notifyMessage, true );
  263. endGroup();
  264. return ret.toBool();
  265. }
  266. void MySettings::setNotifyMessage( const bool def )
  267. {
  268. beginGroup( group_main );
  269. setValue( key_notifyMessage, QVariant(def) );
  270. endGroup();
  271. }
  272. /*------------------------*/
  273. bool MySettings::notifyTyping()
  274. {
  275. beginGroup( group_main );
  276. QVariant ret = value( key_notifyTyping, true );
  277. endGroup();
  278. return ret.toBool();
  279. }
  280. void MySettings::setNotifyTyping( const bool def )
  281. {
  282. beginGroup( group_main );
  283. setValue( key_notifyTyping, QVariant(def) );
  284. endGroup();
  285. }
  286. /*-----------*/
  287. QString MySettings::getSndBuddyLogsIn()
  288. {
  289. beginGroup( group_main );
  290. QVariant ret = value( key_sndBuddyLogsIn, QString("") );
  291. endGroup();
  292. return ret.toString();
  293. }
  294. void MySettings::setSndBuddyLogsIn( const QString &f )
  295. {
  296. beginGroup( group_main );
  297. setValue( key_sndBuddyLogsIn, QVariant(f) );
  298. endGroup();
  299. }
  300. /*-----------*/
  301. QString MySettings::getSndBuddyLogsOut()
  302. {
  303. beginGroup( group_main );
  304. QVariant ret = value( key_sndBuddyLogsOut, QString("") );
  305. endGroup();
  306. return ret.toString();
  307. }
  308. void MySettings::setSndBuddyLogsOut( const QString &f )
  309. {
  310. beginGroup( group_main );
  311. setValue( key_sndBuddyLogsOut, QVariant(f) );
  312. endGroup();
  313. }
  314. /*-----------*/
  315. bool MySettings::reconnectWhenError()
  316. {
  317. beginGroup( group_main );
  318. QVariant ret = value( key_reconnectOnError, false );
  319. endGroup();
  320. return ret.toBool();
  321. }
  322. void MySettings::setReconnectWhenError(const bool isSet)
  323. {
  324. beginGroup( group_main );
  325. setValue( key_reconnectOnError, QVariant(isSet) );
  326. endGroup();
  327. }
  328. /*-----------*/
  329. int MySettings::keepAliveInterval()
  330. {
  331. beginGroup( group_main );
  332. QVariant ret = value( key_keepAliveInterval, 60 );
  333. endGroup();
  334. bool ok = false;
  335. int retValue = ret.toInt( &ok );
  336. if( ok )
  337. return retValue;
  338. else
  339. return 60;
  340. }
  341. void MySettings::setKeepAliveInterval(const int isSet)
  342. {
  343. beginGroup( group_main );
  344. setValue( key_keepAliveInterval, QVariant(isSet) );
  345. endGroup();
  346. }
  347. /*-----------*/
  348. QString MySettings::getSndChatSaysMyName()
  349. {
  350. beginGroup( group_main );
  351. QVariant ret = value( key_sndChatSome1SaysMyName, QString("") );
  352. endGroup();
  353. return ret.toString();
  354. }
  355. void MySettings::setSndChatSaysMyName( const QString &f )
  356. {
  357. beginGroup( group_main );
  358. setValue( key_sndChatSome1SaysMyName, QVariant(f) );
  359. endGroup();
  360. }
  361. /*-----------*/
  362. QString MySettings::getSndChatPersonEnters()
  363. {
  364. beginGroup( group_main );
  365. QVariant ret = value( key_sndChatPersonEnters, QString("") );
  366. endGroup();
  367. return ret.toString();
  368. }
  369. void MySettings::setSndChatPersonEnters( const QString &f )
  370. {
  371. beginGroup( group_main );
  372. setValue( key_sndChatPersonEnters, QVariant(f) );
  373. endGroup();
  374. }
  375. /*-----------*/
  376. QString MySettings::getSndChatPersonLeaves()
  377. {
  378. beginGroup( group_main );
  379. QVariant ret = value( key_sndChatPersonLeaves, QString("") );
  380. endGroup();
  381. return ret.toString();
  382. }
  383. void MySettings::setSndChatPersonLeaves( const QString &f )
  384. {
  385. beginGroup( group_main );
  386. setValue( key_sndChatPersonLeaves, QVariant(f) );
  387. endGroup();
  388. }
  389. /*-----------*/
  390. QString MySettings::getSndChatITalk()
  391. {
  392. beginGroup( group_main );
  393. QVariant ret = value( key_sndChatITalk, QString("") );
  394. endGroup();
  395. return ret.toString();
  396. }
  397. void MySettings::setSndChatITalk( const QString &f )
  398. {
  399. beginGroup( group_main );
  400. setValue( key_sndChatITalk, QVariant(f) );
  401. endGroup();
  402. }
  403. /*-----------*/
  404. QString MySettings::getSndChatOthersTalk()
  405. {
  406. beginGroup( group_main );
  407. QVariant ret = value( key_sndChatOthersTalk, QString("") );
  408. endGroup();
  409. return ret.toString();
  410. }
  411. void MySettings::setSndChatOthersTalk( const QString &f )
  412. {
  413. beginGroup( group_main );
  414. setValue( key_sndChatOthersTalk, QVariant(f) );
  415. endGroup();
  416. }
  417. /*------------------------*/
  418. bool MySettings::vibrationMessageRecv()
  419. {
  420. beginGroup( group_main );
  421. QVariant ret = value( key_vibrMessageRecv, false );
  422. endGroup();
  423. return ret.toBool();
  424. }
  425. void MySettings::setVibrationMessageRecv(const bool isSet)
  426. {
  427. beginGroup( group_main );
  428. setValue( key_vibrMessageRecv, QVariant(isSet) );
  429. endGroup();
  430. }
  431. /*------------------------*/
  432. bool MySettings::vibrationMessageSent()
  433. {
  434. beginGroup( group_main );
  435. QVariant ret = value( key_vibrMessageSent, false );
  436. endGroup();
  437. return ret.toBool();
  438. }
  439. void MySettings::setVibrationMessageSent(const bool isSet)
  440. {
  441. beginGroup( group_main );
  442. setValue( key_vibrMessageSent, QVariant(isSet) );
  443. endGroup();
  444. }
  445. /*------------------------*/
  446. bool MySettings::vibrationChatSaysMyName()
  447. {
  448. beginGroup( group_main );
  449. QVariant ret = value( key_vibrChatSaysMyName, false );
  450. endGroup();
  451. return ret.toBool();
  452. }
  453. void MySettings::setVibrationChatSaysMyName(const bool isSet)
  454. {
  455. beginGroup( group_main );
  456. setValue( key_vibrChatSaysMyName, QVariant(isSet) );
  457. endGroup();
  458. }
  459. /*------------------------*/
  460. bool MySettings::vibrationChatOthersTalk()
  461. {
  462. beginGroup( group_main );
  463. QVariant ret = value( key_vibrChatOthersTalk, false );
  464. endGroup();
  465. return ret.toBool();
  466. }
  467. void MySettings::setVibrationChatOthersTalk(const bool isSet)
  468. {
  469. beginGroup( group_main );
  470. setValue( key_vibrChatOthersTalk, QVariant(isSet) );
  471. endGroup();
  472. }
  473. /*-----------*/
  474. QString MySettings::getSmilesTheme()
  475. {
  476. beginGroup( group_main );
  477. QVariant ret = value( key_smilesTheme, QString("/opt/meegim/smiles/theme.xml") );
  478. endGroup();
  479. return ret.toString();
  480. }
  481. void MySettings::setSmilesTheme( const QString &f )
  482. {
  483. beginGroup( group_main );
  484. setValue( key_smilesTheme, QVariant(f) );
  485. endGroup();
  486. }