Diffstat (limited to 'noncore/apps/odict/dingwidget.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/apps/odict/dingwidget.cpp | 30 |
1 files changed, 9 insertions, 21 deletions
diff --git a/noncore/apps/odict/dingwidget.cpp b/noncore/apps/odict/dingwidget.cpp index ed67abf..55a716d 100644 --- a/noncore/apps/odict/dingwidget.cpp +++ b/noncore/apps/odict/dingwidget.cpp | |||
@@ -27,38 +27,34 @@ DingWidget::DingWidget( ) | |||
27 | { | 27 | { |
28 | methodname = QString::null; | 28 | methodname = QString::null; |
29 | trenner = QString::null; | 29 | trenner = QString::null; |
30 | lines = 0L; | 30 | lines = 0L; |
31 | } | 31 | } |
32 | 32 | ||
33 | void DingWidget::loadDict( QString name ) | 33 | void DingWidget::loadDict( QString name ) |
34 | { | 34 | { |
35 | qDebug( "bin in DingWidget::loadDict(). name ist:" ); | 35 | lines.clear(); //as we will load a new list we have to |
36 | qDebug( name ); | 36 | //remove the old one |
37 | qDebug( "DingWidget::loadDict( ... )" ); | ||
37 | 38 | ||
38 | dictName = name; | ||
39 | Config cfg( "odict" ); | 39 | Config cfg( "odict" ); |
40 | if ( !methodname ) { return; } | 40 | cfg.setGroup( "Method_" + name ); |
41 | cfg.setGroup( "Method_" + methodname ); | ||
42 | QFile file( cfg.readEntry( "file" ) ); | 41 | QFile file( cfg.readEntry( "file" ) ); |
43 | 42 | ||
44 | qDebug( cfg.readEntry( "file" ) ); | ||
45 | |||
46 | if( file.open( IO_ReadOnly ) ) | 43 | if( file.open( IO_ReadOnly ) ) |
47 | { | 44 | { |
48 | QTextStream stream( &file ); | 45 | QTextStream stream( &file ); |
49 | while ( !stream.eof() ) | 46 | while ( !stream.eof() ) |
50 | { | 47 | { |
51 | lines.append( stream.readLine() ); | 48 | lines.append( stream.readLine() ); |
52 | } | 49 | } |
53 | file.close(); | 50 | file.close(); |
54 | } | 51 | } |
55 | loadValues(); | 52 | loadValues(); |
56 | |||
57 | } | 53 | } |
58 | 54 | ||
59 | QString DingWidget::loadedDict() const | 55 | QString DingWidget::loadedDict() const |
60 | { | 56 | { |
61 | return dictName; | 57 | return dictName; |
62 | } | 58 | } |
63 | 59 | ||
64 | void DingWidget::setCaseSensitive( bool caseS ) | 60 | void DingWidget::setCaseSensitive( bool caseS ) |
@@ -66,21 +62,16 @@ void DingWidget::setCaseSensitive( bool caseS ) | |||
66 | isCaseSensitive = caseS; | 62 | isCaseSensitive = caseS; |
67 | } | 63 | } |
68 | 64 | ||
69 | void DingWidget::setDict( QString dict ) | 65 | void DingWidget::setDict( QString dict ) |
70 | { | 66 | { |
71 | methodname = dict; | 67 | methodname = dict; |
72 | } | 68 | } |
73 | 69 | ||
74 | void DingWidget::setCompleteWord( bool cword ) | ||
75 | { | ||
76 | isCompleteWord = cword; | ||
77 | } | ||
78 | |||
79 | void DingWidget::setQueryWord( QString qword ) | 70 | void DingWidget::setQueryWord( QString qword ) |
80 | { | 71 | { |
81 | queryword = qword; | 72 | queryword = qword; |
82 | } | 73 | } |
83 | 74 | ||
84 | 75 | ||
85 | void DingWidget::loadValues() | 76 | void DingWidget::loadValues() |
86 | { | 77 | { |
@@ -96,25 +87,21 @@ BroswerContent DingWidget::setText( QString word ) | |||
96 | { | 87 | { |
97 | queryword = word; | 88 | queryword = word; |
98 | return parseInfo(); | 89 | return parseInfo(); |
99 | } | 90 | } |
100 | 91 | ||
101 | 92 | ||
102 | BroswerContent DingWidget::parseInfo() | 93 | BroswerContent DingWidget::parseInfo() |
103 | { | 94 | { |
104 | qDebug( "bin in DingWidget::parseInfo()" ); | ||
105 | |||
106 | if ( isCompleteWord ) | ||
107 | queryword = " " + queryword + " "; | ||
108 | QStringList search = lines.grep( queryword , isCaseSensitive ); | 95 | QStringList search = lines.grep( queryword , isCaseSensitive ); |
109 | 96 | ||
110 | QString current; | 97 | QString current; |
111 | QString left; | 98 | QString left; |
112 | QString right; | 99 | QString right; |
113 | QRegExp reg_div( trenner ); | 100 | QRegExp reg_div( trenner ); |
114 | QRegExp reg_word( queryword ); | 101 | QRegExp reg_word( queryword ); |
115 | reg_word.setCaseSensitive( isCaseSensitive ); | 102 | reg_word.setCaseSensitive( isCaseSensitive ); |
116 | QStringList toplist, bottomlist; | 103 | QStringList toplist, bottomlist; |
117 | QString substitute = "<strong>"+queryword+"</strong>"; | 104 | QString substitute = "<strong>"+queryword+"</strong>"; |
118 | 105 | ||
119 | for( QStringList::Iterator it = search.begin() ; it != search.end() ; ++it ) | 106 | for( QStringList::Iterator it = search.begin() ; it != search.end() ; ++it ) |
120 | { | 107 | { |
@@ -134,11 +121,12 @@ BroswerContent DingWidget::parseInfo() | |||
134 | right.replace( queryword, substitute ); | 121 | right.replace( queryword, substitute ); |
135 | right = right + " --> " + left; | 122 | right = right + " --> " + left; |
136 | bottomlist.append( right ); | 123 | bottomlist.append( right ); |
137 | } | 124 | } |
138 | } | 125 | } |
139 | 126 | ||
140 | s_strings.top = toplist.join( "<br>" ); | 127 | s_strings.top = toplist.join( "<br>" ); |
141 | s_strings.bottom = bottomlist.join( "<br>" ); | 128 | s_strings.bottom = bottomlist.join( "<br>" ); |
142 | 129 | ||
143 | return s_strings; | 130 | return s_strings; |
144 | } | 131 | } |
132 | |||