author | cniehaus <cniehaus> | 2003-04-30 19:28:50 (UTC) |
---|---|---|
committer | cniehaus <cniehaus> | 2003-04-30 19:28:50 (UTC) |
commit | b48845bf24f1361a349c86a48a7b54e49df94533 (patch) (unidiff) | |
tree | 38e6e2e027c6ed0c2d1bd94aa78e27b8434daea7 | |
parent | e6428d30a5dc90ed3ec6ca7e1cb3f92c81437cc0 (diff) | |
download | opie-b48845bf24f1361a349c86a48a7b54e49df94533.zip opie-b48845bf24f1361a349c86a48a7b54e49df94533.tar.gz opie-b48845bf24f1361a349c86a48a7b54e49df94533.tar.bz2 |
I hope I will code more in the next days
-rw-r--r-- | noncore/apps/odict/dingwidget.cpp | 59 | ||||
-rw-r--r-- | noncore/apps/odict/odict.cpp | 4 |
2 files changed, 14 insertions, 49 deletions
diff --git a/noncore/apps/odict/dingwidget.cpp b/noncore/apps/odict/dingwidget.cpp index cfef84d..16164ed 100644 --- a/noncore/apps/odict/dingwidget.cpp +++ b/noncore/apps/odict/dingwidget.cpp | |||
@@ -9,49 +9,48 @@ | |||
9 | /*************************************************************************** | 9 | /*************************************************************************** |
10 | * * | 10 | * * |
11 | * This program is free software; you can redistribute it and/or modify * | 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 * | 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 * | 13 | * the Free Software Foundation; either version 2 of the License, or * |
14 | * ( at your option ) any later version. * | 14 | * ( at your option ) any later version. * |
15 | * * | 15 | * * |
16 | **************************************************************************/ | 16 | **************************************************************************/ |
17 | #include "dingwidget.h" | 17 | #include "dingwidget.h" |
18 | 18 | ||
19 | #include <qfile.h> | 19 | #include <qfile.h> |
20 | #include <qpe/config.h> | 20 | #include <qpe/config.h> |
21 | #include <qhbox.h> | 21 | #include <qhbox.h> |
22 | #include <qlabel.h> | 22 | #include <qlabel.h> |
23 | #include <qpushbutton.h> | 23 | #include <qpushbutton.h> |
24 | #include <qlineedit.h> | 24 | #include <qlineedit.h> |
25 | #include <qmainwindow.h> | 25 | #include <qmainwindow.h> |
26 | #include <qstring.h> | 26 | #include <qstring.h> |
27 | #include <qtextstream.h> | 27 | #include <qtextstream.h> |
28 | #include <qstringlist.h> | 28 | #include <qstringlist.h> |
29 | #include <qregexp.h> | 29 | #include <qregexp.h> |
30 | #include <qtextbrowser.h> | 30 | #include <qtextbrowser.h> |
31 | #include <stdlib.h> // for getenv | 31 | #include <stdlib.h> // for getenv |
32 | 32 | ||
33 | |||
34 | DingWidget::DingWidget( ) | 33 | DingWidget::DingWidget( ) |
35 | { | 34 | { |
36 | methodname = QString::null; | 35 | methodname = QString::null; |
37 | trenner = QString::null; | 36 | trenner = QString::null; |
38 | lines = 0L; | 37 | lines = 0L; |
39 | } | 38 | } |
40 | 39 | ||
41 | void DingWidget::loadDict( QString name ) | 40 | void DingWidget::loadDict( QString name ) |
42 | { | 41 | { |
43 | qDebug( "MUSS ich wirklich aufgerufen werder? schreit loadDict" ); | 42 | qDebug( "MUSS ich wirklich aufgerufen werder? schreit loadDict" ); |
44 | qDebug( "Starte mit dem loadedDict(...)" ); | 43 | qDebug( "Starte mit dem loadedDict(...)" ); |
45 | dictName = name; | 44 | dictName = name; |
46 | qDebug( "bin in loadedDict() und lade das Dict:" ); | 45 | qDebug( "bin in loadedDict() und lade das Dict:" ); |
47 | qDebug( dictName ); | 46 | qDebug( dictName ); |
48 | QString opie_dir = getenv("OPIEDIR"); | 47 | QString opie_dir = getenv("OPIEDIR"); |
49 | QFile file( opie_dir+"/noncore/apps/odict/eng_ita.dic" ); | 48 | QFile file( opie_dir+"/noncore/apps/odict/eng_ita.dic" ); |
50 | //FIXME:this should of course be not hardcoded ;) | 49 | //FIXME:this should of course be not hardcoded ;) |
51 | 50 | ||
52 | if( file.open( IO_ReadOnly ) ) | 51 | if( file.open( IO_ReadOnly ) ) |
53 | { | 52 | { |
54 | QTextStream stream( &file ); | 53 | QTextStream stream( &file ); |
55 | while ( !stream.eof() ) | 54 | while ( !stream.eof() ) |
56 | { | 55 | { |
57 | lines.append( stream.readLine() ); | 56 | lines.append( stream.readLine() ); |
@@ -68,112 +67,82 @@ QString DingWidget::loadedDict() | |||
68 | qDebug( "^ ^ ^ ^ ^ ^ ^ war der dictName" ); | 67 | qDebug( "^ ^ ^ ^ ^ ^ ^ war der dictName" ); |
69 | return dictName; | 68 | return dictName; |
70 | } | 69 | } |
71 | 70 | ||
72 | void DingWidget::setCaseSensitive( bool caseS ) | 71 | void DingWidget::setCaseSensitive( bool caseS ) |
73 | { | 72 | { |
74 | isCaseSensitive = caseS; | 73 | isCaseSensitive = caseS; |
75 | } | 74 | } |
76 | 75 | ||
77 | void DingWidget::setDict( QString dict ) | 76 | void DingWidget::setDict( QString dict ) |
78 | { | 77 | { |
79 | methodname = dict; | 78 | methodname = dict; |
80 | } | 79 | } |
81 | 80 | ||
82 | void DingWidget::setCompleteWord( bool cword ) | 81 | void DingWidget::setCompleteWord( bool cword ) |
83 | { | 82 | { |
84 | isCompleteWord = cword; | 83 | isCompleteWord = cword; |
85 | } | 84 | } |
86 | 85 | ||
87 | void DingWidget::setQueryWord( QString qword ) | 86 | void DingWidget::setQueryWord( QString qword ) |
88 | { | 87 | { |
89 | queryword = qword; | 88 | queryword = qword; |
90 | } | 89 | } |
91 | 90 | ||
91 | |||
92 | void DingWidget::loadValues() | ||
93 | { | ||
94 | Config cfg( "odict" ); | ||
95 | cfg.setGroup( "Method_" + methodname ); | ||
96 | trenner = cfg.readEntry( "Seperator" ); | ||
97 | } | ||
98 | |||
92 | BroswerContent DingWidget::setText( QString word ) | 99 | BroswerContent DingWidget::setText( QString word ) |
93 | { | 100 | { |
94 | queryword = word; | 101 | queryword = word; |
95 | qDebug( queryword ); | 102 | qDebug( queryword ); |
96 | qDebug( "^ ^ ^ ^ ^ ^ ^ war das gesuchte Word"); | 103 | qDebug( "^ ^ ^ ^ ^ ^ ^ war das gesuchte Word"); |
97 | return parseInfo(); | 104 | return parseInfo(); |
98 | } | 105 | } |
99 | 106 | ||
100 | void DingWidget::loadValues() | ||
101 | { | ||
102 | Config cfg( "odict" ); | ||
103 | cfg.setGroup( "Method_" + methodname ); | ||
104 | trenner = cfg.readEntry( "Seperator" ); | ||
105 | } | ||
106 | 107 | ||
107 | BroswerContent DingWidget::parseInfo() | 108 | BroswerContent DingWidget::parseInfo() |
108 | { | 109 | { |
109 | if ( isCompleteWord ) queryword = " " + queryword + " "; | 110 | if ( isCompleteWord ) |
111 | queryword = " " + queryword + " "; | ||
110 | QStringList search = lines.grep( queryword , isCaseSensitive ); | 112 | QStringList search = lines.grep( queryword , isCaseSensitive ); |
111 | 113 | ||
112 | QString current; | 114 | QString current; |
113 | QString left; | 115 | QString left; |
114 | QString right; | 116 | QString right; |
115 | QRegExp reg_div( trenner ); | 117 | QRegExp reg_div( trenner ); |
116 | QRegExp reg_word( queryword ); | 118 | QRegExp reg_word( queryword ); |
117 | reg_word.setCaseSensitive( isCaseSensitive ); | 119 | reg_word.setCaseSensitive( isCaseSensitive ); |
118 | QStringList toplist, bottomlist; | 120 | QStringList toplist, bottomlist; |
119 | QString substitute = "<strong>"+queryword+"</strong>"; | 121 | QString substitute = "<strong>"+queryword+"</strong>"; |
120 | 122 | ||
121 | /* Dieser Block ist von Patrik. Ich versuche einen neuen | ||
122 | * Ansatz. Zum einen ist HTML scheiße an dieser Stelle und | ||
123 | * zum andern funktioniert der Code nicht so wie er sollte. | ||
124 | QString substitute = "<a href=''>"+queryword+"</a>"; | ||
125 | |||
126 | QString html_header = "<html><table>"; | ||
127 | QString html_footer = "</table></html>"; | ||
128 | QString html_table_left = "<tr><td width='50'>"; | ||
129 | QString html_table_sep = "</td><td>"; | ||
130 | QString html_table_right = "</td></tr>"; | ||
131 | |||
132 | for( QStringList::Iterator it = search.begin() ; it != search.end() ; ++it ) | ||
133 | { | ||
134 | current = *it; | ||
135 | left = current.left( current.find(reg_div) ); | ||
136 | right = current.right( current.length() - current.find(reg_div) - 1 ); | ||
137 | if ( left.contains( reg_word ) ) | ||
138 | { | ||
139 | left.replace( queryword, substitute ); | ||
140 | toplist.append( html_table_left + left + html_table_sep + right + html_table_right ); | ||
141 | } | ||
142 | else | ||
143 | { | ||
144 | right.replace( reg_word, substitute ); | ||
145 | bottomlist.append( html_table_left + right + html_table_sep + left + html_table_right ); | ||
146 | } | ||
147 | } | ||
148 | |||
149 | //thats it, the lists are rendered. Lets put them in one string | ||
150 | s_strings.bottom = html_header + bottomlist.join( "<br>" ) + html_footer; | ||
151 | s_strings.top = html_header + toplist.join( "<br>" ) + html_footer; | ||
152 | */ | ||
153 | |||
154 | for( QStringList::Iterator it = search.begin() ; it != search.end() ; ++it ) | 123 | for( QStringList::Iterator it = search.begin() ; it != search.end() ; ++it ) |
155 | { | 124 | { |
156 | current = *it; | 125 | current = *it; |
157 | left = current.left( current.find( trenner ) ); | 126 | left = current.left( current.find( trenner ) ); |
158 | 127 | ||
159 | right = current.right( current.length() - current.find(trenner) -2 ); | 128 | right = current.right( current.length() - current.find(trenner) - trenner.length() ); |
160 | 129 | ||
161 | if ( left.contains( queryword , isCaseSensitive ) ) | 130 | if ( left.contains( queryword , isCaseSensitive ) ) |
162 | { | 131 | { |
163 | left.replace( queryword, substitute ); | 132 | left.replace( queryword, substitute ); |
164 | left = left + "-->" + right; | 133 | left = left + " -- " + right; |
165 | toplist.append( left ); | 134 | toplist.append( left ); |
166 | } | 135 | } |
167 | else | 136 | else |
168 | { | 137 | { |
169 | right.replace( queryword, substitute ); | 138 | right.replace( queryword, substitute ); |
170 | left = right + "-->" + left; | 139 | left = right + " -- " + left; |
171 | bottomlist.append( right ); | 140 | bottomlist.append( right ); |
172 | } | 141 | } |
173 | } | 142 | } |
174 | 143 | ||
175 | s_strings.bottom = bottomlist.join( "\n" ); | ||
176 | s_strings.top = toplist.join( "\n" ); | 144 | s_strings.top = toplist.join( "\n" ); |
145 | s_strings.bottom = bottomlist.join( "\n" ); | ||
177 | 146 | ||
178 | return s_strings; | 147 | return s_strings; |
179 | } | 148 | } |
diff --git a/noncore/apps/odict/odict.cpp b/noncore/apps/odict/odict.cpp index c4114f7..58cff5f 100644 --- a/noncore/apps/odict/odict.cpp +++ b/noncore/apps/odict/odict.cpp | |||
@@ -180,31 +180,27 @@ void ODict::setupMenus() | |||
180 | settings = new QPopupMenu( menu ); | 180 | settings = new QPopupMenu( menu ); |
181 | setting_a = new QAction(tr( "Config" ), Resource::loadPixmap( "today/config" ), QString::null, 0, this, 0 ); | 181 | setting_a = new QAction(tr( "Config" ), Resource::loadPixmap( "today/config" ), QString::null, 0, this, 0 ); |
182 | connect( setting_a, SIGNAL( activated() ), this, SLOT( slotSettings() ) ); | 182 | connect( setting_a, SIGNAL( activated() ), this, SLOT( slotSettings() ) ); |
183 | setting_a->addTo( settings ); | 183 | setting_a->addTo( settings ); |
184 | setting_b = new QAction(tr( "Searchmethods" ), Resource::loadPixmap( "today/config" ), QString::null, 0, this, 0 ); | 184 | setting_b = new QAction(tr( "Searchmethods" ), Resource::loadPixmap( "today/config" ), QString::null, 0, this, 0 ); |
185 | 185 | ||
186 | parameter = new QPopupMenu( menu ); | 186 | parameter = new QPopupMenu( menu ); |
187 | connect( parameter, SIGNAL( activated( int ) ), this, SLOT( slotSetParameter( int ) ) ); | 187 | connect( parameter, SIGNAL( activated( int ) ), this, SLOT( slotSetParameter( int ) ) ); |
188 | parameter->insertItem( tr( "C&ase sensitive" ), 0 ,0 ); | 188 | parameter->insertItem( tr( "C&ase sensitive" ), 0 ,0 ); |
189 | parameter->insertItem( tr( "Only &complete Words" ), 1 , 1) ; | 189 | parameter->insertItem( tr( "Only &complete Words" ), 1 , 1) ; |
190 | parameter->insertItem( tr( "Allow ®. expressions" ), 2 ); | 190 | parameter->insertItem( tr( "Allow ®. expressions" ), 2 ); |
191 | parameter->insertSeparator(); | 191 | parameter->insertSeparator(); |
192 | error_tol_menu = new QPopupMenu( menu ); | 192 | error_tol_menu = new QPopupMenu( menu ); |
193 | error_tol_menu->setCheckable( TRUE ); | 193 | error_tol_menu->setCheckable( TRUE ); |
194 | connect( error_tol_menu, SIGNAL( activated( int ) ), this, SLOT( slotSetErrorcount( int ) ) ); | 194 | connect( error_tol_menu, SIGNAL( activated( int ) ), this, SLOT( slotSetErrorcount( int ) ) ); |
195 | 195 | ||
196 | error_tol_menu->insertItem( tr( "0 Errors" ), 0 ); | 196 | error_tol_menu->insertItem( tr( "0 Errors" ), 0 ); |
197 | error_tol_menu->insertItem( tr( "1 Errors" ), 1 ); | 197 | error_tol_menu->insertItem( tr( "1 Errors" ), 1 ); |
198 | error_tol_menu->insertItem( tr( "2 Errors" ), 2 ); | 198 | error_tol_menu->insertItem( tr( "2 Errors" ), 2 ); |
199 | error_tol_menu->insertItem( tr( "3 Errors" ), 3 ); | 199 | error_tol_menu->insertItem( tr( "3 Errors" ), 3 ); |
200 | error_tol_menu->insertItem( tr( "4 Errors" ), 4 ); | 200 | error_tol_menu->insertItem( tr( "4 Errors" ), 4 ); |
201 | error_tol_menu->insertItem( tr( "Until Hit" ), 5 ); | 201 | error_tol_menu->insertItem( tr( "Until Hit" ), 5 ); |
202 | parameter->insertItem( tr( "&Error tolerance" ), error_tol_menu ); | 202 | parameter->insertItem( tr( "&Error tolerance" ), error_tol_menu ); |
203 | 203 | ||
204 | help = new QPopupMenu( menu ); | ||
205 | help->insertItem("&About",this,SLOT( slotDisplayAbout() )); | ||
206 | |||
207 | menu->insertItem( tr( "Settings" ) , settings ); | 204 | menu->insertItem( tr( "Settings" ) , settings ); |
208 | menu->insertItem( tr( "Parameter" ) , parameter ); | 205 | menu->insertItem( tr( "Parameter" ) , parameter ); |
209 | menu->insertItem( tr( "Help" ) , help ); | ||
210 | } | 206 | } |