123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603 |
- #include "mysettings.h"
- #include <QDir>
- QString MySettings::appName = "meegim";
- QString MySettings::pathMeegIMHome = QDir::homePath() + QDir::separator() + ".config" + QDir::separator() + appName;
- QString MySettings::pathMeegIMCache = pathMeegIMHome + QDir::separator() + QString("cache");
- QString MySettings::fileConfig = pathMeegIMHome + QDir::separator() + MySettings::appName + ".conf";
- MySettings::MySettings(QObject *parent) : QSettings(MySettings::fileConfig, QSettings::NativeFormat , parent)
- {
- group_main = "main";
- group_gui = "gui";
- group_xmpp = "xmpp";
- group_accounts = "accounts";
- key_jid = "jid";
- key_passwd = "passwd";
- key_showGroup = "show_groups";
- key_lastPresence = "show_last_presence";
- key_accounts = "accounts";
- key_resource = "resource";
- key_status_text = "status_text";
- key_status = "status";
- key_default = "is_default";
- key_useHostPort = "use_host_port";
- key_host = "host";
- key_port = "port";
- key_sndIncomingMsg = "snd_incoming_message";
- key_sndOutcomingMsg = "snd_outcoming_message";
- key_notifyConnection = "notify_connection";
- key_notifyOnline = "notify_online";
- key_notifyOffline = "notify_offline";
- key_notifyMessage = "notify_message";
- key_notifyTyping = "notify_typing";
- key_sndBuddyLogsIn = "snd_buddy_logs_in";
- key_sndBuddyLogsOut = "snd_buddy_logs_out";
- key_reconnectOnError = "reconnect_when_error";
- key_keepAliveInterval = "keep_alive_interval";
- key_sndChatSome1SaysMyName = "sndchat_someone_says_my_name";
- key_sndChatPersonEnters = "sndchat_person_enters";
- key_sndChatPersonLeaves = "sndchat_person_leaves";
- key_sndChatOthersTalk = "sndchat_others_talk";
- key_sndChatITalk = "sndchat_I_talk";
- key_vibrMessageRecv = "vibration_msg_recv";
- key_vibrMessageSent = "vibration_msg_sent";
- key_vibrChatSaysMyName = "vibration_chat_says_my_name";
- key_vibrChatOthersTalk = "vibration_chat_others_talk";
- key_smilesTheme = "smiles_theme";
- }
- QStringList MySettings::getListAccounts()
- {
- beginGroup( group_accounts );
- QVariant ret = value( key_accounts, QStringList() );
- endGroup();
- return ret.toStringList();
- }
- void MySettings::addAccount( const QString &acc )
- {
- beginGroup( group_accounts );
- QVariant retList = value( key_accounts, QStringList() );
- QStringList sl = retList.toStringList();
- if( sl.indexOf(acc) < 0 ) {
- sl.append(acc);
- setValue( key_accounts, QVariant(sl) );
- }
- endGroup();
- }
- void MySettings::remAccount( const QString &acc )
- {
- beginGroup( group_accounts );
- QVariant retList = value( key_accounts, QStringList() );
- QStringList sl = retList.toStringList();
- if( sl.indexOf(acc) >= 0 ) {
- sl.removeOne(acc);
- setValue( key_accounts, QVariant(sl) );
- }
- endGroup();
- }
- /*-------------------*/
- QString MySettings::getPasswd(const QString &jid)
- {
- beginGroup( jid );
- QVariant ret = value( key_passwd, QString("") );
- endGroup();
- return ret.toString();
- }
- void MySettings::setPasswd(const QString &jid, const QString &passwd)
- {
- beginGroup( jid );
- setValue( key_passwd, QVariant(passwd) );
- endGroup();
- }
- /*-----------*/
- QString MySettings::getResource(const QString &jid)
- {
- beginGroup( jid );
- QVariant ret = value( key_resource, QString("") );
- endGroup();
- return ret.toString();
- }
- void MySettings::setResource(const QString &jid, const QString &resource)
- {
- beginGroup( jid );
- setValue( key_resource, QVariant(resource) );
- endGroup();
- }
- /*-----------*/
- bool MySettings::isAccDefault(const QString &jid)
- {
- beginGroup( jid );
- QVariant ret = value( key_default, false );
- endGroup();
- return ret.toBool();
- }
- void MySettings::setAccDefault(const QString &jid, const bool &def)
- {
- beginGroup( jid );
- setValue( key_default, QVariant(def) );
- endGroup();
- }
- /*-----------*/
- bool MySettings::isHostPortManually(const QString &jid)
- {
- beginGroup( jid );
- QVariant ret = value( key_useHostPort, false );
- endGroup();
- return ret.toBool();
- }
- void MySettings::setHostPortManually(const QString &jid, const bool &def)
- {
- beginGroup( jid );
- setValue( key_useHostPort, QVariant(def) );
- endGroup();
- }
- /*-----------*/
- QString MySettings::getHost(const QString &jid)
- {
- beginGroup( jid );
- QVariant ret = value( key_host, QString("") );
- endGroup();
- return ret.toString();
- }
- void MySettings::setHost(const QString &jid, const QString &host)
- {
- beginGroup( jid );
- setValue( key_host, QVariant(host) );
- endGroup();
- }
- /*-----------*/
- int MySettings::getPort(const QString &jid)
- {
- beginGroup( jid );
- QVariant ret = value( key_port, 0 );
- endGroup();
- return ret.toInt();
- }
- void MySettings::setPort(const QString &jid, const int port)
- {
- beginGroup( jid );
- setValue( key_port, QVariant(port) );
- endGroup();
- }
- /*-----------*/
- QString MySettings::getStatus()
- {
- beginGroup( group_main );
- QVariant ret = value( key_status, QString("") );
- endGroup();
- return ret.toString();
- }
- void MySettings::setStatus( const QString &status)
- {
- beginGroup( group_main );
- setValue( key_status, QVariant(status) );
- endGroup();
- }
- /*-----------*/
- QString MySettings::getStatusText()
- {
- beginGroup( group_main );
- QVariant ret = value( key_status_text, QString("") );
- endGroup();
- return ret.toString();
- }
- void MySettings::setStatusText( const QString &status_text)
- {
- beginGroup( group_main );
- setValue( key_status_text, QVariant(status_text) );
- endGroup();
- }
- /*-----------*/
- QString MySettings::getSndIncomingMsg()
- {
- beginGroup( group_main );
- QVariant ret = value( key_sndIncomingMsg, QString("") );
- endGroup();
- return ret.toString();
- }
- void MySettings::setSndIncomingMsg( const QString &f )
- {
- beginGroup( group_main );
- setValue( key_sndIncomingMsg, QVariant(f) );
- endGroup();
- }
- /*-----------*/
- QString MySettings::getSndOutcomingMsg()
- {
- beginGroup( group_main );
- QVariant ret = value( key_sndOutcomingMsg, QString("") );
- endGroup();
- return ret.toString();
- }
- void MySettings::setSndOutcomingMsg( const QString &f )
- {
- beginGroup( group_main );
- setValue( key_sndOutcomingMsg, QVariant(f) );
- endGroup();
- }
- /*------------------------*/
- bool MySettings::notifyConnection()
- {
- beginGroup( group_main );
- QVariant ret = value( key_notifyConnection, true );
- endGroup();
- return ret.toBool();
- }
- void MySettings::setNotifyConnection( const bool def )
- {
- beginGroup( group_main );
- setValue( key_notifyConnection, QVariant(def) );
- endGroup();
- }
- /*------------------------*/
- bool MySettings::notifyOnline()
- {
- beginGroup( group_main );
- QVariant ret = value( key_notifyOnline, true );
- endGroup();
- return ret.toBool();
- }
- void MySettings::setNotifyOnline( const bool def )
- {
- beginGroup( group_main );
- setValue( key_notifyOnline, QVariant(def) );
- endGroup();
- }
- /*------------------------*/
- bool MySettings::notifyOffline()
- {
- beginGroup( group_main );
- QVariant ret = value( key_notifyOffline, true );
- endGroup();
- return ret.toBool();
- }
- void MySettings::setNotifyOffline( const bool def )
- {
- beginGroup( group_main );
- setValue( key_notifyOffline, QVariant(def) );
- endGroup();
- }
- /*------------------------*/
- bool MySettings::notifyMessage()
- {
- beginGroup( group_main );
- QVariant ret = value( key_notifyMessage, true );
- endGroup();
- return ret.toBool();
- }
- void MySettings::setNotifyMessage( const bool def )
- {
- beginGroup( group_main );
- setValue( key_notifyMessage, QVariant(def) );
- endGroup();
- }
- /*------------------------*/
- bool MySettings::notifyTyping()
- {
- beginGroup( group_main );
- QVariant ret = value( key_notifyTyping, true );
- endGroup();
- return ret.toBool();
- }
- void MySettings::setNotifyTyping( const bool def )
- {
- beginGroup( group_main );
- setValue( key_notifyTyping, QVariant(def) );
- endGroup();
- }
- /*-----------*/
- QString MySettings::getSndBuddyLogsIn()
- {
- beginGroup( group_main );
- QVariant ret = value( key_sndBuddyLogsIn, QString("") );
- endGroup();
- return ret.toString();
- }
- void MySettings::setSndBuddyLogsIn( const QString &f )
- {
- beginGroup( group_main );
- setValue( key_sndBuddyLogsIn, QVariant(f) );
- endGroup();
- }
- /*-----------*/
- QString MySettings::getSndBuddyLogsOut()
- {
- beginGroup( group_main );
- QVariant ret = value( key_sndBuddyLogsOut, QString("") );
- endGroup();
- return ret.toString();
- }
- void MySettings::setSndBuddyLogsOut( const QString &f )
- {
- beginGroup( group_main );
- setValue( key_sndBuddyLogsOut, QVariant(f) );
- endGroup();
- }
- /*-----------*/
- bool MySettings::reconnectWhenError()
- {
- beginGroup( group_main );
- QVariant ret = value( key_reconnectOnError, false );
- endGroup();
- return ret.toBool();
- }
- void MySettings::setReconnectWhenError(const bool isSet)
- {
- beginGroup( group_main );
- setValue( key_reconnectOnError, QVariant(isSet) );
- endGroup();
- }
- /*-----------*/
- int MySettings::keepAliveInterval()
- {
- beginGroup( group_main );
- QVariant ret = value( key_keepAliveInterval, 60 );
- endGroup();
- bool ok = false;
- int retValue = ret.toInt( &ok );
- if( ok )
- return retValue;
- else
- return 60;
- }
- void MySettings::setKeepAliveInterval(const int isSet)
- {
- beginGroup( group_main );
- setValue( key_keepAliveInterval, QVariant(isSet) );
- endGroup();
- }
- /*-----------*/
- QString MySettings::getSndChatSaysMyName()
- {
- beginGroup( group_main );
- QVariant ret = value( key_sndChatSome1SaysMyName, QString("") );
- endGroup();
- return ret.toString();
- }
- void MySettings::setSndChatSaysMyName( const QString &f )
- {
- beginGroup( group_main );
- setValue( key_sndChatSome1SaysMyName, QVariant(f) );
- endGroup();
- }
- /*-----------*/
- QString MySettings::getSndChatPersonEnters()
- {
- beginGroup( group_main );
- QVariant ret = value( key_sndChatPersonEnters, QString("") );
- endGroup();
- return ret.toString();
- }
- void MySettings::setSndChatPersonEnters( const QString &f )
- {
- beginGroup( group_main );
- setValue( key_sndChatPersonEnters, QVariant(f) );
- endGroup();
- }
- /*-----------*/
- QString MySettings::getSndChatPersonLeaves()
- {
- beginGroup( group_main );
- QVariant ret = value( key_sndChatPersonLeaves, QString("") );
- endGroup();
- return ret.toString();
- }
- void MySettings::setSndChatPersonLeaves( const QString &f )
- {
- beginGroup( group_main );
- setValue( key_sndChatPersonLeaves, QVariant(f) );
- endGroup();
- }
- /*-----------*/
- QString MySettings::getSndChatITalk()
- {
- beginGroup( group_main );
- QVariant ret = value( key_sndChatITalk, QString("") );
- endGroup();
- return ret.toString();
- }
- void MySettings::setSndChatITalk( const QString &f )
- {
- beginGroup( group_main );
- setValue( key_sndChatITalk, QVariant(f) );
- endGroup();
- }
- /*-----------*/
- QString MySettings::getSndChatOthersTalk()
- {
- beginGroup( group_main );
- QVariant ret = value( key_sndChatOthersTalk, QString("") );
- endGroup();
- return ret.toString();
- }
- void MySettings::setSndChatOthersTalk( const QString &f )
- {
- beginGroup( group_main );
- setValue( key_sndChatOthersTalk, QVariant(f) );
- endGroup();
- }
- /*------------------------*/
- bool MySettings::vibrationMessageRecv()
- {
- beginGroup( group_main );
- QVariant ret = value( key_vibrMessageRecv, false );
- endGroup();
- return ret.toBool();
- }
- void MySettings::setVibrationMessageRecv(const bool isSet)
- {
- beginGroup( group_main );
- setValue( key_vibrMessageRecv, QVariant(isSet) );
- endGroup();
- }
- /*------------------------*/
- bool MySettings::vibrationMessageSent()
- {
- beginGroup( group_main );
- QVariant ret = value( key_vibrMessageSent, false );
- endGroup();
- return ret.toBool();
- }
- void MySettings::setVibrationMessageSent(const bool isSet)
- {
- beginGroup( group_main );
- setValue( key_vibrMessageSent, QVariant(isSet) );
- endGroup();
- }
- /*------------------------*/
- bool MySettings::vibrationChatSaysMyName()
- {
- beginGroup( group_main );
- QVariant ret = value( key_vibrChatSaysMyName, false );
- endGroup();
- return ret.toBool();
- }
- void MySettings::setVibrationChatSaysMyName(const bool isSet)
- {
- beginGroup( group_main );
- setValue( key_vibrChatSaysMyName, QVariant(isSet) );
- endGroup();
- }
- /*------------------------*/
- bool MySettings::vibrationChatOthersTalk()
- {
- beginGroup( group_main );
- QVariant ret = value( key_vibrChatOthersTalk, false );
- endGroup();
- return ret.toBool();
- }
- void MySettings::setVibrationChatOthersTalk(const bool isSet)
- {
- beginGroup( group_main );
- setValue( key_vibrChatOthersTalk, QVariant(isSet) );
- endGroup();
- }
- /*-----------*/
- QString MySettings::getSmilesTheme()
- {
- beginGroup( group_main );
- QVariant ret = value( key_smilesTheme, QString("/opt/meegim/smiles/theme.xml") );
- endGroup();
- return ret.toString();
- }
- void MySettings::setSmilesTheme( const QString &f )
- {
- beginGroup( group_main );
- setValue( key_smilesTheme, QVariant(f) );
- endGroup();
- }
|