1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
|
/*
autoreplaceconfig.cpp
Copyright (c) 2003 by Roberto Pariset <[email protected]>
Copyright (c) 2003 by Martijn Klingens <[email protected]>
Kopete (c) 2002-2003 by the Kopete developers <[email protected]>
*************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
*************************************************************************
*/
#include "autoreplaceconfig.h"
#include <tdeconfig.h>
#include <tdeglobal.h>
#include <tdelocale.h>
AutoReplaceConfig::AutoReplaceConfig()
{
load();
}
// reload configuration reading it from kopeterc
void AutoReplaceConfig::load()
{
TDEConfig *config = TDEGlobal::config();
config->setGroup( "AutoReplace Plugin" );
TQStringList wordsList = config->readListEntry( "WordsToReplace" );
if( wordsList.isEmpty() )
{
// basic list, key/value
// a list based on i18n should be provided, i.e. for italian
// "qsa,qualcosa,qno,qualcuno" remember UTF-8 accents
wordsList = defaultAutoReplaceList();
}
// we may be reloading after removing an entry from the list
m_map.clear();
TQString k, v;
for ( TQStringList::Iterator it = wordsList.begin(); it != wordsList.end(); ++it )
{
k = *it;
++it;
if( it == wordsList.end() )
break;
v = *it;
m_map.insert( k, v );
}
m_autoreplaceIncoming = config->readBoolEntry( "AutoReplaceIncoming" , false );
m_autoreplaceOutgoing = config->readBoolEntry( "AutoReplaceOutgoing" , true );
m_addDot = config->readBoolEntry( "DotEndSentence" , false );
m_upper = config->readBoolEntry( "CapitalizeBeginningSentence" , false );
}
TQStringList AutoReplaceConfig::defaultAutoReplaceList()
{
return TQStringList::split( ",", i18n( "list_of_words_to_replace",
"ur,your,r,are,u,you,theres,there is,arent,are not,dont,do not" ) );
}
void AutoReplaceConfig::loadDefaultAutoReplaceList()
{
TQStringList wordsList = defaultAutoReplaceList();
m_map.clear();
TQString k, v;
for ( TQStringList::Iterator it = wordsList.begin(); it != wordsList.end(); ++it )
{
k = *it;
v = *( ++it );
m_map.insert( k, v );
}
}
bool AutoReplaceConfig::autoReplaceIncoming() const
{
return m_autoreplaceIncoming;
}
bool AutoReplaceConfig::autoReplaceOutgoing() const
{
return m_autoreplaceOutgoing;
}
bool AutoReplaceConfig::dotEndSentence() const
{
return m_addDot;
}
bool AutoReplaceConfig::capitalizeBeginningSentence() const
{
return m_upper;
}
void AutoReplaceConfig::setMap( const WordsToReplace &w )
{
m_map = w;
}
AutoReplaceConfig::WordsToReplace AutoReplaceConfig::map() const
{
return m_map;
}
void AutoReplaceConfig::save()
{
TDEConfig * config = TDEGlobal::config();
config->setGroup( "AutoReplace Plugin" );
TQStringList newWords;
WordsToReplace::Iterator it;
for ( it = m_map.begin(); it != m_map.end(); ++it )
{
newWords.append( it.key() );
newWords.append( it.data() );
}
config->writeEntry( "WordsToReplace", newWords );
config->sync();
}
// vim: set noet ts=4 sts=4 sw=4:
|