~ubuntu-branches/ubuntu/saucy/kopete/saucy-proposed

« back to all changes in this revision

Viewing changes to plugins/autoreplace/autoreplaceconfig.cpp

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2013-06-21 02:22:39 UTC
  • Revision ID: package-import@ubuntu.com-20130621022239-63l3zc8p0nf26pt6
Tags: upstream-4.10.80
ImportĀ upstreamĀ versionĀ 4.10.80

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
    autoreplaceconfig.cpp
 
3
 
 
4
    Copyright (c) 2003      by Roberto Pariset       <victorheremita@fastwebnet.it>
 
5
    Copyright (c) 2003      by Martijn Klingens      <klingens@kde.org>
 
6
 
 
7
    Kopete    (c) 2002-2003 by the Kopete developers <kopete-devel@kde.org>
 
8
 
 
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
    *************************************************************************
 
17
*/
 
18
 
 
19
#include "autoreplaceconfig.h"
 
20
 
 
21
#include <kconfig.h>
 
22
#include <kglobal.h>
 
23
#include <klocale.h>
 
24
#include <kconfiggroup.h>
 
25
 
 
26
//TODO: Use KConfigXT
 
27
AutoReplaceConfig::AutoReplaceConfig()
 
28
{
 
29
        load();
 
30
}
 
31
 
 
32
// reload configuration reading it from kopeterc
 
33
void AutoReplaceConfig::load()
 
34
{
 
35
        KConfigGroup config(KGlobal::config(), "AutoReplace Plugin");
 
36
 
 
37
        QStringList wordsList = config.readEntry( "WordsToReplace", QStringList() );
 
38
        if( wordsList.isEmpty() )
 
39
        {
 
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();
 
44
        }
 
45
        
 
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 )
 
50
        {
 
51
                k = *it;
 
52
                ++it;
 
53
                if( it == wordsList.constEnd() )
 
54
                        break;
 
55
                v = *it;
 
56
                m_map.insert( k, v );
 
57
        }
 
58
 
 
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 );
 
63
}
 
64
 
 
65
QStringList AutoReplaceConfig::defaultAutoReplaceList()
 
66
{
 
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 );
 
69
}
 
70
 
 
71
void AutoReplaceConfig::loadDefaultAutoReplaceList()
 
72
{
 
73
    const QStringList wordsList = defaultAutoReplaceList();
 
74
    m_map.clear();
 
75
    QString k, v;
 
76
    for ( QStringList::ConstIterator it = wordsList.constBegin(); it != wordsList.constEnd(); ++it )
 
77
    {
 
78
        k = *it;
 
79
        v = *( ++it );
 
80
        m_map.insert( k, v );
 
81
    }
 
82
}
 
83
 
 
84
 
 
85
bool AutoReplaceConfig::autoReplaceIncoming() const
 
86
{
 
87
        return m_autoreplaceIncoming;
 
88
}
 
89
 
 
90
bool AutoReplaceConfig::autoReplaceOutgoing() const
 
91
{
 
92
        return m_autoreplaceOutgoing;
 
93
}
 
94
 
 
95
bool AutoReplaceConfig::dotEndSentence() const
 
96
{
 
97
        return m_addDot;
 
98
}
 
99
 
 
100
bool AutoReplaceConfig::capitalizeBeginningSentence() const
 
101
{
 
102
        return m_upper;
 
103
}
 
104
 
 
105
void AutoReplaceConfig::setAutoReplaceIncoming(bool enabled)
 
106
{
 
107
        m_autoreplaceIncoming = enabled;
 
108
}
 
109
 
 
110
void AutoReplaceConfig::setAutoReplaceOutgoing(bool enabled)
 
111
{
 
112
        m_autoreplaceOutgoing = enabled;
 
113
}
 
114
 
 
115
void AutoReplaceConfig::setDotEndSentence(bool enabled)
 
116
{
 
117
        m_addDot = enabled;
 
118
}
 
119
 
 
120
void AutoReplaceConfig::setCapitalizeBeginningSentence(bool enabled)
 
121
{
 
122
        m_upper = enabled;
 
123
}
 
124
 
 
125
 
 
126
void AutoReplaceConfig::setMap( const WordsToReplace &w )
 
127
{
 
128
        m_map = w;
 
129
}
 
130
 
 
131
AutoReplaceConfig::WordsToReplace AutoReplaceConfig::map() const
 
132
{
 
133
        return m_map;
 
134
}
 
135
 
 
136
void AutoReplaceConfig::save()
 
137
{
 
138
        KConfigGroup config(KGlobal::config(), "AutoReplace Plugin" );
 
139
 
 
140
        QStringList newWords;
 
141
        WordsToReplace::ConstIterator it;
 
142
        for ( it = m_map.constBegin(); it != m_map.constEnd(); ++it )
 
143
        {
 
144
                newWords.append( it.key() );
 
145
                newWords.append( it.value() );
 
146
        }
 
147
 
 
148
        config.writeEntry( "WordsToReplace", newWords );
 
149
 
 
150
        config.writeEntry( "AutoReplaceIncoming" , m_autoreplaceIncoming );
 
151
        config.writeEntry( "AutoReplaceOutgoing" , m_autoreplaceOutgoing );
 
152
        config.writeEntry( "DotEndSentence" , m_addDot );
 
153
        config.writeEntry( "CapitalizeBeginningSentence" , m_upper );
 
154
 
 
155
        config.sync();
 
156
}
 
157
 
 
158
// vim: set noet ts=4 sts=4 sw=4:
 
159