summaryrefslogtreecommitdiff
authorcniehaus <cniehaus>2003-01-12 16:16:13 (UTC)
committer cniehaus <cniehaus>2003-01-12 16:16:13 (UTC)
commitaa4f80fdc2d78bfe1c1d4cb8ec1d852115d00fc7 (patch) (unidiff)
treed102e440196aea471b3ed8d0357934a1a9f2e385
parent6e7d82135cdab0190739d2ddf84cd2211d18d00b (diff)
downloadopie-aa4f80fdc2d78bfe1c1d4cb8ec1d852115d00fc7.zip
opie-aa4f80fdc2d78bfe1c1d4cb8ec1d852115d00fc7.tar.gz
opie-aa4f80fdc2d78bfe1c1d4cb8ec1d852115d00fc7.tar.bz2
Make search for only complete words working. Removing qDebug-lines. Fix a
bug (the seperator has not been loaded).
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/odict/dingwidget.cpp28
-rw-r--r--noncore/apps/odict/dingwidget.h2
-rw-r--r--noncore/apps/odict/odict.cpp6
3 files changed, 13 insertions, 23 deletions
diff --git a/noncore/apps/odict/dingwidget.cpp b/noncore/apps/odict/dingwidget.cpp
index 5b5d731..cfef84d 100644
--- a/noncore/apps/odict/dingwidget.cpp
+++ b/noncore/apps/odict/dingwidget.cpp
@@ -21,66 +21,58 @@
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 33
34DingWidget::DingWidget( ) 34DingWidget::DingWidget( )
35{ 35{
36 methodname = QString::null; 36 methodname = QString::null;
37 trenner = "::";//QString::null; 37 trenner = QString::null;
38 lines = 0L; 38 lines = 0L;
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} 39}
49 40
50void DingWidget::loadDict( QString name ) 41void DingWidget::loadDict( QString name )
51{ 42{
52 qDebug( "MUSS ich wirklich aufgerufen werder? schreit loadDict" ); 43 qDebug( "MUSS ich wirklich aufgerufen werder? schreit loadDict" );
53 qDebug( "Starte mit dem loadedDict(...)" ); 44 qDebug( "Starte mit dem loadedDict(...)" );
54 dictName = name; 45 dictName = name;
55 qDebug( "bin in loadedDict() und lade das Dict:" ); 46 qDebug( "bin in loadedDict() und lade das Dict:" );
56 qDebug( dictName ); 47 qDebug( dictName );
57 QString opie_dir = getenv("OPIEDIR"); 48 QString opie_dir = getenv("OPIEDIR");
58 QFile file( opie_dir+"/noncore/apps/odict/eng_ita.dic" ); 49 QFile file( opie_dir+"/noncore/apps/odict/eng_ita.dic" );
59 //FIXME:this should of course be not hardcoded ;) 50 //FIXME:this should of course be not hardcoded ;)
60 51
61 if( file.open( IO_ReadOnly ) ) 52 if( file.open( IO_ReadOnly ) )
62 { 53 {
63 QTextStream stream( &file ); 54 QTextStream stream( &file );
64 while ( !stream.eof() ) 55 while ( !stream.eof() )
65 { 56 {
66 lines.append( stream.readLine() ); 57 lines.append( stream.readLine() );
67 } 58 }
68 file.close(); 59 file.close();
69 } 60 }
70 qDebug( "loadedDict(...) ist beended" ); 61 qDebug( "loadedDict(...) ist beended" );
62 loadValues();
71} 63}
72 64
73QString DingWidget::loadedDict() 65QString DingWidget::loadedDict()
74{ 66{
75 qDebug( dictName ); 67 qDebug( dictName );
76 qDebug( "^ ^ ^ ^ ^ ^ ^ war der dictName" ); 68 qDebug( "^ ^ ^ ^ ^ ^ ^ war der dictName" );
77 return dictName; 69 return dictName;
78} 70}
79 71
80void DingWidget::setCaseSensitive( bool caseS ) 72void DingWidget::setCaseSensitive( bool caseS )
81{ 73{
82 isCaseSensitive = caseS; 74 isCaseSensitive = caseS;
83} 75}
84 76
85void DingWidget::setDict( QString dict ) 77void DingWidget::setDict( QString dict )
86{ 78{
@@ -95,58 +87,60 @@ void DingWidget::setCompleteWord( bool cword )
95void DingWidget::setQueryWord( QString qword ) 87void DingWidget::setQueryWord( QString qword )
96{ 88{
97 queryword = qword; 89 queryword = qword;
98} 90}
99 91
100BroswerContent DingWidget::setText( QString word ) 92BroswerContent DingWidget::setText( QString word )
101{ 93{
102 queryword = word; 94 queryword = word;
103 qDebug( queryword ); 95 qDebug( queryword );
104 qDebug( "^ ^ ^ ^ ^ ^ ^ war das gesuchte Word"); 96 qDebug( "^ ^ ^ ^ ^ ^ ^ war das gesuchte Word");
105 return parseInfo(); 97 return parseInfo();
106} 98}
107 99
108void DingWidget::loadValues() 100void DingWidget::loadValues()
109{ 101{
110 Config cfg( "odict" ); 102 Config cfg( "odict" );
111 cfg.setGroup( "Method_"+methodname ); 103 cfg.setGroup( "Method_" + methodname );
112 //trenner = cfg.readEntry( "Seperator" ); 104 trenner = cfg.readEntry( "Seperator" );
113} 105}
114 106
115BroswerContent DingWidget::parseInfo() 107BroswerContent DingWidget::parseInfo()
116{ 108{
109 if ( isCompleteWord ) queryword = " " + queryword + " ";
117 QStringList search = lines.grep( queryword , isCaseSensitive ); 110 QStringList search = lines.grep( queryword , isCaseSensitive );
118 111
119 QString current; 112 QString current;
120 QString left; 113 QString left;
121 QString right; 114 QString right;
122 QString html_header = "<html><table>";
123 QString html_footer = "</table></html>";
124 QString html_table_left = "<tr><td width='50'>";
125 QString html_table_sep = "</td><td>";
126 QString html_table_right = "</td></tr>";
127 QRegExp reg_div( trenner ); 115 QRegExp reg_div( trenner );
128 QRegExp reg_word( queryword ); 116 QRegExp reg_word( queryword );
129 reg_word.setCaseSensitive( isCaseSensitive ); 117 reg_word.setCaseSensitive( isCaseSensitive );
130 QStringList toplist, bottomlist; 118 QStringList toplist, bottomlist;
131 QString substitute = "<strong>"+queryword+"</strong>"; 119 QString substitute = "<strong>"+queryword+"</strong>";
132 120
133 /* Dieser Block ist von Patrik. Ich versuche einen neuen 121 /* Dieser Block ist von Patrik. Ich versuche einen neuen
134 * Ansatz. Zum einen ist HTML scheiße an dieser Stelle und 122 * Ansatz. Zum einen ist HTML scheiße an dieser Stelle und
135 * zum andern funktioniert der Code nicht so wie er sollte. 123 * zum andern funktioniert der Code nicht so wie er sollte.
136 QString substitute = "<a href=''>"+queryword+"</a>"; 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>";
137 131
138 for( QStringList::Iterator it = search.begin() ; it != search.end() ; ++it ) 132 for( QStringList::Iterator it = search.begin() ; it != search.end() ; ++it )
139 { 133 {
140 current = *it; 134 current = *it;
141 left = current.left( current.find(reg_div) ); 135 left = current.left( current.find(reg_div) );
142 right = current.right( current.length() - current.find(reg_div) - 1 ); 136 right = current.right( current.length() - current.find(reg_div) - 1 );
143 if ( left.contains( reg_word ) ) 137 if ( left.contains( reg_word ) )
144 { 138 {
145 left.replace( queryword, substitute ); 139 left.replace( queryword, substitute );
146 toplist.append( html_table_left + left + html_table_sep + right + html_table_right ); 140 toplist.append( html_table_left + left + html_table_sep + right + html_table_right );
147 } 141 }
148 else 142 else
149 { 143 {
150 right.replace( reg_word, substitute ); 144 right.replace( reg_word, substitute );
151 bottomlist.append( html_table_left + right + html_table_sep + left + html_table_right ); 145 bottomlist.append( html_table_left + right + html_table_sep + left + html_table_right );
152 } 146 }
diff --git a/noncore/apps/odict/dingwidget.h b/noncore/apps/odict/dingwidget.h
index ba37009..74f40c9 100644
--- a/noncore/apps/odict/dingwidget.h
+++ b/noncore/apps/odict/dingwidget.h
@@ -16,32 +16,32 @@ struct BroswerContent
16 QString bottom; 16 QString bottom;
17}; 17};
18 18
19class DingWidget 19class DingWidget
20{ 20{
21 public: 21 public:
22 DingWidget(); 22 DingWidget();
23 23
24 BroswerContent setText( QString ); 24 BroswerContent setText( QString );
25 QStringList lines; 25 QStringList lines;
26 void setCaseSensitive( bool ); 26 void setCaseSensitive( bool );
27 void setCompleteWord( bool ); 27 void setCompleteWord( bool );
28 void loadDict( QString ); 28 void loadDict( QString );
29 QString loadedDict(); 29 QString loadedDict();
30 void setQueryWord( QString ); 30 void setQueryWord( QString );
31 void setDict( QString ); 31 void setDict( QString );
32 void loadValues();
32 33
33 private: 34 private:
34 BroswerContent parseInfo(); 35 BroswerContent parseInfo();
35 36
36 BroswerContent s_strings; 37 BroswerContent s_strings;
37 bool isCompleteWord; 38 bool isCompleteWord;
38 bool isCaseSensitive; 39 bool isCaseSensitive;
39 40
40 QString dictName; 41 QString dictName;
41 42
42 QString search_word; 43 QString search_word;
43 void loadValues();
44 QString queryword; 44 QString queryword;
45 QString methodname; 45 QString methodname;
46 QString trenner; 46 QString trenner;
47}; 47};
diff --git a/noncore/apps/odict/odict.cpp b/noncore/apps/odict/odict.cpp
index 42604ee..78c3f90 100644
--- a/noncore/apps/odict/odict.cpp
+++ b/noncore/apps/odict/odict.cpp
@@ -44,32 +44,33 @@ ODict::ODict() : QMainWindow()
44 vbox = new QVBox( this ); 44 vbox = new QVBox( this );
45 setCaption( tr( "OPIE-Dictionary" ) ); 45 setCaption( tr( "OPIE-Dictionary" ) );
46 setupMenus(); 46 setupMenus();
47 47
48 48
49 QHBox *hbox = new QHBox( vbox ); 49 QHBox *hbox = new QHBox( vbox );
50 QLabel* query_label = new QLabel( tr( "Query:" ) , hbox ); query_label->show(); 50 QLabel* query_label = new QLabel( tr( "Query:" ) , hbox ); query_label->show();
51 query_le = new QLineEdit( hbox ); 51 query_le = new QLineEdit( hbox );
52 query_co = new QComboBox( hbox ); 52 query_co = new QComboBox( hbox );
53 connect( query_co , SIGNAL( activated(int) ), this, SLOT( slotMethodChanged(int) ) ); 53 connect( query_co , SIGNAL( activated(int) ), this, SLOT( slotMethodChanged(int) ) );
54 ok_button = new QPushButton( tr( "&Ok" ), hbox ); 54 ok_button = new QPushButton( tr( "&Ok" ), hbox );
55 connect( ok_button, SIGNAL( released() ), this, SLOT( slotStartQuery() ) ); 55 connect( ok_button, SIGNAL( released() ), this, SLOT( slotStartQuery() ) );
56 browser_top = new QTextBrowser( vbox ); 56 browser_top = new QTextBrowser( vbox );
57 browser_bottom = new QTextBrowser( vbox ); 57 browser_bottom = new QTextBrowser( vbox );
58 58
59 ding = new DingWidget(); 59 ding = new DingWidget();
60 ding->loadValues();
60 61
61 loadConfig(); 62 loadConfig();
62 setCentralWidget( vbox ); 63 setCentralWidget( vbox );
63} 64}
64 65
65void ODict::loadConfig() 66void ODict::loadConfig()
66{ 67{
67 Config cfg ( "odict" ); 68 Config cfg ( "odict" );
68 cfg.setGroup( "generalsettings" ); 69 cfg.setGroup( "generalsettings" );
69 errorTol = cfg.readEntry( "errtol" ).toInt(); 70 errorTol = cfg.readEntry( "errtol" ).toInt();
70 casesens = cfg.readEntry( "casesens" ).toInt(); 71 casesens = cfg.readEntry( "casesens" ).toInt();
71 regexp = cfg.readEntry( "regexp" ).toInt(); 72 regexp = cfg.readEntry( "regexp" ).toInt();
72 completewords = cfg.readEntry( "completewords" ).toInt(); 73 completewords = cfg.readEntry( "completewords" ).toInt();
73 74
74 QStringList groupListCfg = cfg.groupList().grep( "Method_" ); 75 QStringList groupListCfg = cfg.groupList().grep( "Method_" );
75 query_co->clear(); 76 query_co->clear();
@@ -97,45 +98,40 @@ void ODict::slotDisplayAbout()
97 QMessageBox::about( this, tr( "About ODict" ), tr( "OPIE-Dictionary ODict \n (c) 2002, 2003 Carsten Niehaus \n cniehaus@handhelds.org \n Version 20030111" ) ); 98 QMessageBox::about( this, tr( "About ODict" ), tr( "OPIE-Dictionary ODict \n (c) 2002, 2003 Carsten Niehaus \n cniehaus@handhelds.org \n Version 20030111" ) );
98} 99}
99 100
100void ODict::slotStartQuery() 101void ODict::slotStartQuery()
101{ 102{
102 QString querystring = query_le->text(); 103 QString querystring = query_le->text();
103 //X qDebug("opening dict >%s< for >%s<", activated_name.latin1(),querystring.latin1()); 104 //X qDebug("opening dict >%s< for >%s<", activated_name.latin1(),querystring.latin1());
104 //X if (querystring.isEmpty()){ 105 //X if (querystring.isEmpty()){
105 //X qWarning("empty querystring"); 106 //X qWarning("empty querystring");
106 //X return; 107 //X return;
107 //X } 108 //X }
108 //X if (!activated_name || activated_name.isEmpty()) 109 //X if (!activated_name || activated_name.isEmpty())
109 //X QMessageBox::warning(this,tr("No Dictionary"),tr("Please choose a dictonary") ); 110 //X QMessageBox::warning(this,tr("No Dictionary"),tr("Please choose a dictonary") );
110 //X else 111 //X else
111 //X { 112 //X {
112 113
113 if ( casesens ) qDebug( "casesens = TRUE" );
114 else qDebug( "casesens = FALSE" );
115
116 ding->setCaseSensitive( casesens ); 114 ding->setCaseSensitive( casesens );
117 ding->setCompleteWord( completewords ); 115 ding->setCompleteWord( completewords );
118 ding->setDict( activated_name ); 116 ding->setDict( activated_name );
119 117
120 if ( activated_name != ding->loadedDict() ) 118 if ( activated_name != ding->loadedDict() )
121 { 119 {
122 qDebug( "ComboBox geändert" );
123 ding->loadDict(activated_name); 120 ding->loadDict(activated_name);
124 } 121 }
125 else qDebug( "ComboBox war GLEICH" );
126 122
127 BroswerContent test = ding->setText( querystring ); 123 BroswerContent test = ding->setText( querystring );
128 124
129 browser_top->setText( test.top ); 125 browser_top->setText( test.top );
130 browser_bottom->setText( test.bottom ); 126 browser_bottom->setText( test.bottom );
131 127
132 qDebug( "Text sollte gesetzt sein..." ); 128 qDebug( "Text sollte gesetzt sein..." );
133 //X } 129 //X }
134} 130}
135 131
136 132
137void ODict::slotSetErrorcount( int count ) 133void ODict::slotSetErrorcount( int count )
138{ 134{
139 errorTol = count; 135 errorTol = count;
140} 136}
141 137