summaryrefslogtreecommitdiff
path: root/noncore/apps/odict/dingwidget.cpp
Unidiff
Diffstat (limited to 'noncore/apps/odict/dingwidget.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/odict/dingwidget.cpp19
1 files changed, 10 insertions, 9 deletions
diff --git a/noncore/apps/odict/dingwidget.cpp b/noncore/apps/odict/dingwidget.cpp
index 0707bfb..ed67abf 100644
--- a/noncore/apps/odict/dingwidget.cpp
+++ b/noncore/apps/odict/dingwidget.cpp
@@ -1,128 +1,129 @@
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 <qhbox.h>
22#include <qlabel.h>
23#include <qpushbutton.h>
24#include <qlineedit.h>
25#include <qmainwindow.h>
26#include <qstring.h> 21#include <qstring.h>
27#include <qtextstream.h> 22#include <qtextstream.h>
28#include <qstringlist.h> 23#include <qstringlist.h>
29#include <qregexp.h> 24#include <qregexp.h>
30#include <qtextbrowser.h>
31//#include <stdlib.h> // for getenv
32 25
33DingWidget::DingWidget( ) 26DingWidget::DingWidget( )
34{ 27{
35 methodname = QString::null; 28 methodname = QString::null;
36 trenner = QString::null; 29 trenner = QString::null;
37 lines = 0L; 30 lines = 0L;
38} 31}
39 32
40void DingWidget::loadDict( QString name ) 33void DingWidget::loadDict( QString name )
41{ 34{
35 qDebug( "bin in DingWidget::loadDict(). name ist:" );
36 qDebug( name );
37
42 dictName = name; 38 dictName = name;
43 Config cfg( "odict" ); 39 Config cfg( "odict" );
44 if ( !methodname ) return; 40 if ( !methodname ) { return; }
45 cfg.setGroup( "Method_" + methodname ); 41 cfg.setGroup( "Method_" + methodname );
46 QFile file( cfg.readEntry( "file" ) ); 42 QFile file( cfg.readEntry( "file" ) );
43
44 qDebug( cfg.readEntry( "file" ) );
47 45
48 if( file.open( IO_ReadOnly ) ) 46 if( file.open( IO_ReadOnly ) )
49 { 47 {
50 QTextStream stream( &file ); 48 QTextStream stream( &file );
51 while ( !stream.eof() ) 49 while ( !stream.eof() )
52 { 50 {
53 lines.append( stream.readLine() ); 51 lines.append( stream.readLine() );
54 } 52 }
55 file.close(); 53 file.close();
56 } 54 }
57 loadValues(); 55 loadValues();
56
58} 57}
59 58
60QString DingWidget::loadedDict() 59QString DingWidget::loadedDict() const
61{ 60{
62 return dictName; 61 return dictName;
63} 62}
64 63
65void DingWidget::setCaseSensitive( bool caseS ) 64void DingWidget::setCaseSensitive( bool caseS )
66{ 65{
67 isCaseSensitive = caseS; 66 isCaseSensitive = caseS;
68} 67}
69 68
70void DingWidget::setDict( QString dict ) 69void DingWidget::setDict( QString dict )
71{ 70{
72 methodname = dict; 71 methodname = dict;
73} 72}
74 73
75void DingWidget::setCompleteWord( bool cword ) 74void DingWidget::setCompleteWord( bool cword )
76{ 75{
77 isCompleteWord = cword; 76 isCompleteWord = cword;
78} 77}
79 78
80void DingWidget::setQueryWord( QString qword ) 79void DingWidget::setQueryWord( QString qword )
81{ 80{
82 queryword = qword; 81 queryword = qword;
83} 82}
84 83
85 84
86void DingWidget::loadValues() 85void DingWidget::loadValues()
87{ 86{
88 if ( !methodname ) return; 87 if ( !methodname ) return;
89 Config cfg( "odict" ); 88 Config cfg( "odict" );
90 cfg.setGroup( "Method_" + methodname ); 89 cfg.setGroup( "Method_" + methodname );
91 trenner = cfg.readEntry( "Seperator" ); 90 trenner = cfg.readEntry( "Seperator" );
92 lang1_name = cfg.readEntry( "Lang1" ); 91 lang1_name = cfg.readEntry( "Lang1" );
93 lang2_name = cfg.readEntry( "Lang2" ); 92 lang2_name = cfg.readEntry( "Lang2" );
94} 93}
95 94
96BroswerContent DingWidget::setText( QString word ) 95BroswerContent DingWidget::setText( QString word )
97{ 96{
98 queryword = word; 97 queryword = word;
99 return parseInfo(); 98 return parseInfo();
100} 99}
101 100
102 101
103BroswerContent DingWidget::parseInfo() 102BroswerContent DingWidget::parseInfo()
104{ 103{
104 qDebug( "bin in DingWidget::parseInfo()" );
105
105 if ( isCompleteWord ) 106 if ( isCompleteWord )
106 queryword = " " + queryword + " "; 107 queryword = " " + queryword + " ";
107 QStringList search = lines.grep( queryword , isCaseSensitive ); 108 QStringList search = lines.grep( queryword , isCaseSensitive );
108 109
109 QString current; 110 QString current;
110 QString left; 111 QString left;
111 QString right; 112 QString right;
112 QRegExp reg_div( trenner ); 113 QRegExp reg_div( trenner );
113 QRegExp reg_word( queryword ); 114 QRegExp reg_word( queryword );
114 reg_word.setCaseSensitive( isCaseSensitive ); 115 reg_word.setCaseSensitive( isCaseSensitive );
115 QStringList toplist, bottomlist; 116 QStringList toplist, bottomlist;
116 QString substitute = "<strong>"+queryword+"</strong>"; 117 QString substitute = "<strong>"+queryword+"</strong>";
117 118
118 for( QStringList::Iterator it = search.begin() ; it != search.end() ; ++it ) 119 for( QStringList::Iterator it = search.begin() ; it != search.end() ; ++it )
119 { 120 {
120 current = *it; 121 current = *it;
121 left = current.left( current.find( trenner ) ); 122 left = current.left( current.find( trenner ) );
122 123
123 right = current.right( current.length() - current.find(trenner) - trenner.length() ); 124 right = current.right( current.length() - current.find(trenner) - trenner.length() );
124 125
125 if ( left.contains( queryword , isCaseSensitive ) ) 126 if ( left.contains( queryword , isCaseSensitive ) )
126 { 127 {
127 left.replace( queryword, substitute ); 128 left.replace( queryword, substitute );
128 left = left + " --> " + right; 129 left = left + " --> " + right;