Show invite menu in wlm chat window immediately
[kdenetwork.git] / kopete / plugins / autoreplace / autoreplaceconfig.cpp
blobaadf60ab314abf33da6b81190a1c0174534e7441
1 /*
2 autoreplaceconfig.cpp
4 Copyright (c) 2003 by Roberto Pariset <victorheremita@fastwebnet.it>
5 Copyright (c) 2003 by Martijn Klingens <klingens@kde.org>
7 Kopete (c) 2002-2003 by the Kopete developers <kopete-devel@kde.org>
9 *************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 *************************************************************************
19 #include "autoreplaceconfig.h"
21 #include <kconfig.h>
22 #include <kglobal.h>
23 #include <klocale.h>
24 #include <kconfiggroup.h>
26 //TODO: Use KConfigXT
27 AutoReplaceConfig::AutoReplaceConfig()
29 load();
32 // reload configuration reading it from kopeterc
33 void AutoReplaceConfig::load()
35 KConfigGroup config(KGlobal::config(), "AutoReplace Plugin");
37 QStringList wordsList = config.readEntry( "WordsToReplace", QStringList() );
38 if( wordsList.isEmpty() )
40 // basic list, key/value
41 // a list based on i18n should be provided, i.e. for italian
42 // "qsa,qualcosa,qno,qualcuno" remember UTF-8 accents
43 wordsList = defaultAutoReplaceList();
46 // we may be reloading after removing an entry from the list
47 m_map.clear();
48 QString k, v;
49 for ( QStringList::ConstIterator it = wordsList.constBegin(); it != wordsList.constEnd(); ++it )
51 k = *it;
52 ++it;
53 if( it == wordsList.constEnd() )
54 break;
55 v = *it;
56 m_map.insert( k, v );
59 m_autoreplaceIncoming = config.readEntry( "AutoReplaceIncoming" , false );
60 m_autoreplaceOutgoing = config.readEntry( "AutoReplaceOutgoing" , true );
61 m_addDot = config.readEntry( "DotEndSentence" , false );
62 m_upper = config.readEntry( "CapitalizeBeginningSentence" , false );
65 QStringList AutoReplaceConfig::defaultAutoReplaceList()
67 return i18nc( "list_of_words_to_replace",
68 "ur,your,r,are,u,you,theres,there is,arent,are not,dont,do not" ).split( ',', QString::SkipEmptyParts );
71 void AutoReplaceConfig::loadDefaultAutoReplaceList()
73 const QStringList wordsList = defaultAutoReplaceList();
74 m_map.clear();
75 QString k, v;
76 for ( QStringList::ConstIterator it = wordsList.begin(); it != wordsList.end(); ++it )
78 k = *it;
79 v = *( ++it );
80 m_map.insert( k, v );
85 bool AutoReplaceConfig::autoReplaceIncoming() const
87 return m_autoreplaceIncoming;
90 bool AutoReplaceConfig::autoReplaceOutgoing() const
92 return m_autoreplaceOutgoing;
95 bool AutoReplaceConfig::dotEndSentence() const
97 return m_addDot;
100 bool AutoReplaceConfig::capitalizeBeginningSentence() const
102 return m_upper;
105 void AutoReplaceConfig::setAutoReplaceIncoming(bool enabled)
107 m_autoreplaceIncoming = enabled;
110 void AutoReplaceConfig::setAutoReplaceOutgoing(bool enabled)
112 m_autoreplaceOutgoing = enabled;
115 void AutoReplaceConfig::setDotEndSentence(bool enabled)
117 m_addDot = enabled;
120 void AutoReplaceConfig::setCapitalizeBeginningSentence(bool enabled)
122 m_upper = enabled;
126 void AutoReplaceConfig::setMap( const WordsToReplace &w )
128 m_map = w;
131 AutoReplaceConfig::WordsToReplace AutoReplaceConfig::map() const
133 return m_map;
136 void AutoReplaceConfig::save()
138 KConfigGroup config(KGlobal::config(), "AutoReplace Plugin" );
140 QStringList newWords;
141 WordsToReplace::ConstIterator it;
142 for ( it = m_map.constBegin(); it != m_map.constEnd(); ++it )
144 newWords.append( it.key() );
145 newWords.append( it.value() );
148 config.writeEntry( "WordsToReplace", newWords );
150 config.writeEntry( "AutoReplaceIncoming" , m_autoreplaceIncoming );
151 config.writeEntry( "AutoReplaceOutgoing" , m_autoreplaceOutgoing );
152 config.writeEntry( "DotEndSentence" , m_addDot );
153 config.writeEntry( "CapitalizeBeginningSentence" , m_upper );
155 config.sync();
158 // vim: set noet ts=4 sts=4 sw=4: