summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/odict/dingwidget.cpp1
1 files changed, 1 insertions, 0 deletions
diff --git a/noncore/apps/odict/dingwidget.cpp b/noncore/apps/odict/dingwidget.cpp
index ef36ee5..3eb1e45 100644
--- a/noncore/apps/odict/dingwidget.cpp
+++ b/noncore/apps/odict/dingwidget.cpp
@@ -1,132 +1,133 @@
1/*************************************************************************** 1/***************************************************************************
2 application: : ODict 2 application: : ODict
3 3
4 begin : December 2002 4 begin : December 2002
5 copyright : ( C ) 2002, 2003 by Carsten Niehaus 5 copyright : ( C ) 2002, 2003 by Carsten Niehaus
6 email : cniehaus@handhelds.org 6 email : cniehaus@handhelds.org
7 **************************************************************************/ 7 **************************************************************************/
8 8
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 <qtextstream.h> 21#include <qtextstream.h>
22 22
23DingWidget::DingWidget( ) 23DingWidget::DingWidget( )
24{ 24{
25 methodname = QString::null; 25 methodname = QString::null;
26 trenner = QString::null; 26 trenner = QString::null;
27 lines = 0L; 27 lines = 0L;
28} 28}
29 29
30void DingWidget::loadDict( QString name ) 30void DingWidget::loadDict( QString name )
31{ 31{
32 lines.clear(); //as we will load a new list we have to 32 lines.clear(); //as we will load a new list we have to
33 //remove the old one 33 //remove the old one
34 34
35 Config cfg( "odict" ); 35 Config cfg( "odict" );
36 cfg.setGroup( "Method_" + name ); 36 cfg.setGroup( "Method_" + name );
37 QFile file( cfg.readEntry( "file" ) ); 37 QFile file( cfg.readEntry( "file" ) );
38 38
39 if( file.open( IO_ReadOnly ) ) 39 if( file.open( IO_ReadOnly ) )
40 { 40 {
41 QTextStream stream( &file ); 41 QTextStream stream( &file );
42 stream.setEncoding(QTextStream::UnicodeUTF8);
42 while ( !stream.eof() ) 43 while ( !stream.eof() )
43 { 44 {
44 lines.append( stream.readLine() ); 45 lines.append( stream.readLine() );
45 } 46 }
46 file.close(); 47 file.close();
47 } 48 }
48 49
49 setDict( name ); 50 setDict( name );
50 51
51 loadValues(); 52 loadValues();
52} 53}
53 54
54QString DingWidget::loadedDict() const 55QString DingWidget::loadedDict() const
55{ 56{
56 return dictName; 57 return dictName;
57} 58}
58 59
59void DingWidget::setCaseSensitive( bool caseS ) 60void DingWidget::setCaseSensitive( bool caseS )
60{ 61{
61 isCaseSensitive = caseS; 62 isCaseSensitive = caseS;
62} 63}
63 64
64void DingWidget::setDict( QString dict ) 65void DingWidget::setDict( QString dict )
65{ 66{
66 methodname = dict; 67 methodname = dict;
67} 68}
68 69
69void DingWidget::setQueryWord( QString qword ) 70void DingWidget::setQueryWord( QString qword )
70{ 71{
71 queryword = qword; 72 queryword = qword;
72} 73}
73 74
74 75
75void DingWidget::loadValues() 76void DingWidget::loadValues()
76{ 77{
77 if ( !methodname ) return; 78 if ( !methodname ) return;
78 Config cfg( "odict" ); 79 Config cfg( "odict" );
79 cfg.setGroup( "Method_" + methodname ); 80 cfg.setGroup( "Method_" + methodname );
80 trenner = cfg.readEntry( "Seperator" ); 81 trenner = cfg.readEntry( "Seperator" );
81 82
82 lang1_name = cfg.readEntry( "Lang1" ); 83 lang1_name = cfg.readEntry( "Lang1" );
83 lang2_name = cfg.readEntry( "Lang2" ); 84 lang2_name = cfg.readEntry( "Lang2" );
84} 85}
85 86
86BroswerContent DingWidget::setText( QString word ) 87BroswerContent DingWidget::setText( QString word )
87{ 88{
88 queryword = word; 89 queryword = word;
89 return parseInfo(); 90 return parseInfo();
90} 91}
91 92
92 93
93BroswerContent DingWidget::parseInfo() 94BroswerContent DingWidget::parseInfo()
94{ 95{
95 QStringList search = lines.grep( queryword , isCaseSensitive ); 96 QStringList search = lines.grep( queryword , isCaseSensitive );
96 97
97 QString current; 98 QString current;
98 QString left; 99 QString left;
99 QString right; 100 QString right;
100 QRegExp reg_div( trenner ); 101 QRegExp reg_div( trenner );
101 QRegExp reg_word( queryword ); 102 QRegExp reg_word( queryword );
102 reg_word.setCaseSensitive( isCaseSensitive ); 103 reg_word.setCaseSensitive( isCaseSensitive );
103 QStringList toplist, bottomlist; 104 QStringList toplist, bottomlist;
104 QString substitute = "<strong>"+queryword+"</strong>"; 105 QString substitute = "<strong>"+queryword+"</strong>";
105 106
106 for( QStringList::Iterator it = search.begin() ; it != search.end() ; ++it ) 107 for( QStringList::Iterator it = search.begin() ; it != search.end() ; ++it )
107 { 108 {
108 current = *it; 109 current = *it;
109 left = current.left( current.find( trenner ) ); 110 left = current.left( current.find( trenner ) );
110 111
111 right = current.right( current.length() - current.find(trenner) - trenner.length() ); 112 right = current.right( current.length() - current.find(trenner) - trenner.length() );
112 113
113 if ( left.contains( queryword , isCaseSensitive ) ) 114 if ( left.contains( queryword , isCaseSensitive ) )
114 { 115 {
115 left.replace( queryword, substitute ); 116 left.replace( queryword, substitute );
116 left = left + " --> " + right; 117 left = left + " --> " + right;
117 toplist.append( left ); 118 toplist.append( left );
118 } 119 }
119 else if( right.contains( queryword , isCaseSensitive ) ) 120 else if( right.contains( queryword , isCaseSensitive ) )
120 { 121 {
121 right.replace( queryword, substitute ); 122 right.replace( queryword, substitute );
122 right = right + " --> " + left; 123 right = right + " --> " + left;
123 bottomlist.append( right ); 124 bottomlist.append( right );
124 } 125 }
125 } 126 }
126 127
127 s_strings.top = toplist.join( "<br>" ); 128 s_strings.top = toplist.join( "<br>" );
128 s_strings.bottom = bottomlist.join( "<br>" ); 129 s_strings.bottom = bottomlist.join( "<br>" );
129 130
130 return s_strings; 131 return s_strings;
131} 132}
132 133