summaryrefslogtreecommitdiff
path: root/noncore/apps/odict/dingwidget.cpp
Unidiff
Diffstat (limited to 'noncore/apps/odict/dingwidget.cpp') (more/less context) (show whitespace changes)
-rw-r--r--noncore/apps/odict/dingwidget.cpp111
1 files changed, 92 insertions, 19 deletions
diff --git a/noncore/apps/odict/dingwidget.cpp b/noncore/apps/odict/dingwidget.cpp
index 2913836..7abad22 100644
--- a/noncore/apps/odict/dingwidget.cpp
+++ b/noncore/apps/odict/dingwidget.cpp
@@ -27,71 +27,117 @@
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
33DingWidget::DingWidget(QString word, QTextBrowser *browser_top, QTextBrowser *browser_bottom, QString activated_name) 33
34DingWidget::DingWidget( )
34{ 35{
35 methodname = activated_name; 36 methodname = QString::null;
36 queryword = word; 37 trenner = "::";//QString::null;
37 trenner = QString::null;
38 lines = 0L; 38 lines = 0L;
39 loadValues(); 39 loadValues();
40
41 //X qDebug( topbrowser );
42 //X qDebug( top );
43//X
44 //X topbrowser = "blahbalh";
45 //X
46 //X qDebug( topbrowser );
47 //X qDebug( top );
48}
49
50void DingWidget::loadDict( QString name )
51{
52 qDebug( "MUSS ich wirklich aufgerufen werder? schreit loadDict" );
53 qDebug( "Starte mit dem loadedDict(...)" );
54 dictName = name;
55 qDebug( "bin in loadedDict() und lade das Dict:" );
56 qDebug( dictName );
40 QString opie_dir = getenv("OPIEDIR"); 57 QString opie_dir = getenv("OPIEDIR");
41 QFile file( opie_dir+"/noncore/apps/odict/eng_ita.dic" ); 58 QFile file( opie_dir+"/noncore/apps/odict/eng_ita.dic" );
59 //FIXME:this should of course be not hardcoded ;)
42 60
43 if( file.open( IO_ReadOnly ) ) 61 if( file.open( IO_ReadOnly ) )
44 { 62 {
45 QTextStream stream( &file ); 63 QTextStream stream( &file );
46 while ( !stream.eof() ) 64 while ( !stream.eof() )
47 { 65 {
48 lines.append( stream.readLine() ); 66 lines.append( stream.readLine() );
49 } 67 }
50 file.close(); 68 file.close();
51 } 69 }
70 qDebug( "loadedDict(...) ist beended" );
71}
52 72
53 lines = lines.grep( queryword ); 73QString DingWidget::loadedDict()
74{
75 qDebug( dictName );
76 qDebug( "^ ^ ^ ^ ^ ^ ^ war der dictName" );
77 return dictName;
78}
54 79
55 topbrowser = browser_top; 80void DingWidget::setCaseSensitive( bool caseS )
56 bottombrowser = browser_bottom; 81{
82 isCaseSensitive = caseS;
57} 83}
58 84
59void DingWidget::setText() 85void DingWidget::setDict( QString dict )
60{ 86{
61 QString top, bottom; 87 methodname = dict;
62 QStringList test = lines; 88}
63 parseInfo( test, top , bottom );
64 89
65 topbrowser->setText( top ); 90void DingWidget::setCompleteWord( bool cword )
66 bottombrowser->setText( bottom ); 91{
92 isCompleteWord = cword;
93}
94
95void DingWidget::setQueryWord( QString qword )
96{
97 queryword = qword;
98}
99
100BroswerContent DingWidget::setText( QString word )
101{
102 queryword = word;
103 qDebug( queryword );
104 qDebug( "^ ^ ^ ^ ^ ^ ^ war das gesuchte Word");
105 return parseInfo();
67} 106}
68 107
69void DingWidget::loadValues() 108void DingWidget::loadValues()
70{ 109{
71 Config cfg( "odict" ); 110 Config cfg( "odict" );
72 cfg.setGroup( "Method_"+methodname ); 111 cfg.setGroup( "Method_"+methodname );
73 trenner = cfg.readEntry( "Seperator" ); 112 //trenner = cfg.readEntry( "Seperator" );
74} 113}
75 114
76void DingWidget::parseInfo( QStringList &lines, QString &top, QString &bottom ) 115BroswerContent DingWidget::parseInfo()
77{ 116{
117 QStringList search = lines.grep( queryword );
78 118
79 QString current; 119 QString current;
80 QString left; 120 QString left;
81 QString right; 121 QString right;
82 QString html_header = "<html><table>"; 122 QString html_header = "<html><table>";
83 QString html_footer = "</table></html>"; 123 QString html_footer = "</table></html>";
84 QString html_table_left = "<tr><td width='50'>"; 124 QString html_table_left = "<tr><td width='50'>";
85 QString html_table_sep = "</td><td>"; 125 QString html_table_sep = "</td><td>";
86 QString html_table_right = "</td></tr>"; 126 QString html_table_right = "</td></tr>";
87 QRegExp reg_div( trenner ); 127 QRegExp reg_div( trenner );
88 QRegExp reg_word( queryword ); 128 QRegExp reg_word( queryword );
89 QString substitute = "<a href=''>"+queryword+"</a>";
90 QStringList toplist, bottomlist; 129 QStringList toplist, bottomlist;
91 for( QStringList::Iterator it = lines.begin() ; it != lines.end() ; ++it ) 130 QString substitute = "<strong>"+queryword+"</strong>";
131
132 /* Dieser Block ist von Patrik. Ich versuche einen neuen
133 * Ansatz. Zum einen ist HTML scheiße an dieser Stelle und
134 * zum andern funktioniert der Code nicht so wie er sollte.
135 QString substitute = "<a href=''>"+queryword+"</a>";
136
137 for( QStringList::Iterator it = search.begin() ; it != search.end() ; ++it )
92 { 138 {
93 current = *it; 139 current = *it;
94 left = current.left( current.find(reg_div) ); 140 left = current.left( current.find(reg_div) );
95 right = current.right( current.length() - current.find(reg_div) - 1 ); 141 right = current.right( current.length() - current.find(reg_div) - 1 );
96 if ( left.contains( reg_word ) ) 142 if ( left.contains( reg_word ) )
97 { 143 {
@@ -103,9 +149,36 @@ void DingWidget::parseInfo( QStringList &lines, QString &top, QString &bottom )
103 right.replace( reg_word, substitute ); 149 right.replace( reg_word, substitute );
104 bottomlist.append( html_table_left + right + html_table_sep + left + html_table_right ); 150 bottomlist.append( html_table_left + right + html_table_sep + left + html_table_right );
105 } 151 }
106 } 152 }
107 153
108 //thats it, the lists are rendered. Lets put them in one string 154 //thats it, the lists are rendered. Lets put them in one string
109 bottom = html_header + bottomlist.join( "<br>" ) + html_footer; 155 s_strings.bottom = html_header + bottomlist.join( "<br>" ) + html_footer;
110 top = html_header + toplist.join( "<br>" ) + html_footer; 156 s_strings.top = html_header + toplist.join( "<br>" ) + html_footer;
157 */
158
159 for( QStringList::Iterator it = search.begin() ; it != search.end() ; ++it )
160 {
161 current = *it;
162 left = current.left( current.find( trenner ) );
163
164 right = current.right( current.length() - current.find(trenner) -2 );
165
166 if ( left.contains( queryword ) )
167 {
168 left.replace( queryword, substitute );
169 left = left + "-->" + right;
170 toplist.append( left );
171 }
172 else
173 {
174 right.replace( queryword, substitute );
175 left = right + "-->" + left;
176 bottomlist.append( right );
177 }
178 }
179
180 s_strings.bottom = bottomlist.join( "\n" );
181 s_strings.top = toplist.join( "\n" );
182
183 return s_strings;
111} 184}