-rw-r--r-- | noncore/apps/odict/dingwidget.cpp | 20 | ||||
-rw-r--r-- | noncore/apps/odict/dingwidget.h | 6 | ||||
-rw-r--r-- | noncore/apps/odict/odict.cpp | 9 |
3 files changed, 24 insertions, 11 deletions
diff --git a/noncore/apps/odict/dingwidget.cpp b/noncore/apps/odict/dingwidget.cpp index 6154d68..2913836 100644 --- a/noncore/apps/odict/dingwidget.cpp +++ b/noncore/apps/odict/dingwidget.cpp | |||
@@ -30,37 +30,45 @@ | |||
30 | #include <qtextbrowser.h> | 30 | #include <qtextbrowser.h> |
31 | #include <stdlib.h> // for getenv | 31 | #include <stdlib.h> // for getenv |
32 | 32 | ||
33 | DingWidget::DingWidget(QString word, QTextBrowser *browser_top, QTextBrowser *browser_bottom, QString activated_name) | 33 | DingWidget::DingWidget(QString word, QTextBrowser *browser_top, QTextBrowser *browser_bottom, QString activated_name) |
34 | { | 34 | { |
35 | methodname = activated_name; | 35 | methodname = activated_name; |
36 | queryword = word; | 36 | queryword = word; |
37 | trenner = QString::null; | 37 | trenner = QString::null; |
38 | lines = 0L; | ||
38 | loadValues(); | 39 | loadValues(); |
39 | QString opie_dir = getenv("OPIEDIR"); | 40 | QString opie_dir = getenv("OPIEDIR"); |
40 | QFile file( opie_dir+"/noncore/apps/odict/eng_ita.dic" ); | 41 | QFile file( opie_dir+"/noncore/apps/odict/eng_ita.dic" ); |
41 | QStringList lines; | ||
42 | 42 | ||
43 | if( file.open( IO_ReadOnly ) ) | 43 | if( file.open( IO_ReadOnly ) ) |
44 | { | 44 | { |
45 | QTextStream stream( &file ); | 45 | QTextStream stream( &file ); |
46 | while ( !stream.eof() ) | 46 | while ( !stream.eof() ) |
47 | { | 47 | { |
48 | lines.append( stream.readLine() ); | 48 | lines.append( stream.readLine() ); |
49 | } | 49 | } |
50 | file.close(); | 50 | file.close(); |
51 | } | 51 | } |
52 | 52 | ||
53 | lines = lines.grep( queryword ); | 53 | lines = lines.grep( queryword ); |
54 | 54 | ||
55 | topbrowser = browser_top; | ||
56 | bottombrowser = browser_bottom; | ||
57 | } | ||
58 | |||
59 | void DingWidget::setText() | ||
60 | { | ||
55 | QString top, bottom; | 61 | QString top, bottom; |
56 | parseInfo( lines, top , bottom ); | 62 | QStringList test = lines; |
57 | browser_top->setText( top ); | 63 | parseInfo( test, top , bottom ); |
58 | browser_bottom->setText( bottom ); | 64 | |
65 | topbrowser->setText( top ); | ||
66 | bottombrowser->setText( bottom ); | ||
59 | } | 67 | } |
60 | 68 | ||
61 | void DingWidget::loadValues() | 69 | void DingWidget::loadValues() |
62 | { | 70 | { |
63 | Config cfg( "odict" ); | 71 | Config cfg( "odict" ); |
64 | cfg.setGroup( "Method_"+methodname ); | 72 | cfg.setGroup( "Method_"+methodname ); |
65 | trenner = cfg.readEntry( "Seperator" ); | 73 | trenner = cfg.readEntry( "Seperator" ); |
66 | } | 74 | } |
@@ -71,20 +79,18 @@ void DingWidget::parseInfo( QStringList &lines, QString &top, QString &bottom ) | |||
71 | QString current; | 79 | QString current; |
72 | QString left; | 80 | QString left; |
73 | QString right; | 81 | QString right; |
74 | QString html_header = "<html><table>"; | 82 | QString html_header = "<html><table>"; |
75 | QString html_footer = "</table></html>"; | 83 | QString html_footer = "</table></html>"; |
76 | QString html_table_left = "<tr><td width='50'>"; | 84 | QString html_table_left = "<tr><td width='50'>"; |
77 | QString html_table_sep = "</td><td>"; | 85 | QString html_table_sep = "</td><td>"; |
78 | QString html_table_right = "</td></tr>"; | 86 | QString html_table_right = "</td></tr>"; |
79 | QRegExp reg_div( "\\" ); | 87 | QRegExp reg_div( trenner ); |
80 | //QRegExp reg_div( trenner ); | ||
81 | QRegExp reg_word( queryword ); | 88 | QRegExp reg_word( queryword ); |
82 | //QString substitute = "<font color=red>"+queryword+"</font>"; | ||
83 | QString substitute = "<a href=''>"+queryword+"</a>"; | 89 | QString substitute = "<a href=''>"+queryword+"</a>"; |
84 | QStringList toplist, bottomlist; | 90 | QStringList toplist, bottomlist; |
85 | for( QStringList::Iterator it = lines.begin() ; it != lines.end() ; ++it ) | 91 | for( QStringList::Iterator it = lines.begin() ; it != lines.end() ; ++it ) |
86 | { | 92 | { |
87 | current = *it; | 93 | current = *it; |
88 | left = current.left( current.find(reg_div) ); | 94 | left = current.left( current.find(reg_div) ); |
89 | right = current.right( current.length() - current.find(reg_div) - 1 ); | 95 | right = current.right( current.length() - current.find(reg_div) - 1 ); |
90 | if ( left.contains( reg_word ) ) | 96 | if ( left.contains( reg_word ) ) |
diff --git a/noncore/apps/odict/dingwidget.h b/noncore/apps/odict/dingwidget.h index 1cedb4e..c96039f 100644 --- a/noncore/apps/odict/dingwidget.h +++ b/noncore/apps/odict/dingwidget.h | |||
@@ -6,23 +6,29 @@ | |||
6 | * ( at your option ) any later version. * | 6 | * ( at your option ) any later version. * |
7 | * * | 7 | * * |
8 | **************************************************************************/ | 8 | **************************************************************************/ |
9 | 9 | ||
10 | class QString; | 10 | class QString; |
11 | class QTextBrowser; | 11 | class QTextBrowser; |
12 | class QStringList; | 12 | class QStringList; |
13 | 13 | ||
14 | #include <qstringlist.h> | ||
15 | |||
14 | #include <qstring.h> | 16 | #include <qstring.h> |
15 | 17 | ||
16 | class DingWidget | 18 | class DingWidget |
17 | { | 19 | { |
18 | public: | 20 | public: |
19 | DingWidget(QString word = 0, QTextBrowser* = 0, QTextBrowser* =0, QString activated_name=0); | 21 | DingWidget(QString word = 0, QTextBrowser* = 0, QTextBrowser* =0, QString activated_name=0); |
20 | 22 | ||
23 | void setText(); | ||
24 | QStringList lines; | ||
21 | private: | 25 | private: |
22 | QString search_word; | 26 | QString search_word; |
23 | void parseInfo( QStringList& , QString&, QString& ); | 27 | void parseInfo( QStringList& , QString&, QString& ); |
24 | QString queryword; | 28 | QString queryword; |
25 | void loadValues(); | 29 | void loadValues(); |
26 | QString methodname; | 30 | QString methodname; |
27 | QString trenner; | 31 | QString trenner; |
32 | |||
33 | QTextBrowser *topbrowser, *bottombrowser; | ||
28 | }; | 34 | }; |
diff --git a/noncore/apps/odict/odict.cpp b/noncore/apps/odict/odict.cpp index e0104eb..6f176f9 100644 --- a/noncore/apps/odict/odict.cpp +++ b/noncore/apps/odict/odict.cpp | |||
@@ -93,23 +93,24 @@ void ODict::slotDisplayAbout() | |||
93 | QMessageBox::about( this, tr( "About ODict" ), tr( "OPIE-Dictionary ODict \n (c) 2002, 2003 Carsten Niehaus \n cniehaus@handhelds.org \n Version 20030104" ) ); | 93 | QMessageBox::about( this, tr( "About ODict" ), tr( "OPIE-Dictionary ODict \n (c) 2002, 2003 Carsten Niehaus \n cniehaus@handhelds.org \n Version 20030104" ) ); |
94 | } | 94 | } |
95 | 95 | ||
96 | void ODict::slotStartQuery() | 96 | void ODict::slotStartQuery() |
97 | { | 97 | { |
98 | QString querystring = query_le->text(); | 98 | QString querystring = query_le->text(); |
99 | qDebug("opening dict >%s< for >%s<", activated_name.latin1(),querystring.latin1()); | 99 | qDebug("opening dict >%s< for >%s<", activated_name.latin1(),querystring.latin1()); |
100 | if (querystring.isEmpty()){ | 100 | if (querystring.isEmpty()){ |
101 | qWarning("empty querystring"); | 101 | qWarning("empty querystring"); |
102 | return; | 102 | return; |
103 | } | 103 | } |
104 | if (!activated_name || activated_name.isEmpty()) | 104 | if (!activated_name || activated_name.isEmpty()) |
105 | QMessageBox::warning(this,tr("No Dictionary"),tr("Please choose a dictonary") ); | 105 | QMessageBox::warning(this,tr("No Dictionary"),tr("Please choose a dictonary") ); |
106 | else | 106 | else |
107 | DingWidget *ding = new DingWidget( querystring , browser_top, browser_bottom, activated_name ); | 107 | DingWidget *ding = new DingWidget( querystring , browser_top, browser_bottom, activated_name ); |
108 | ding->setText(); | ||
108 | } | 109 | } |
109 | 110 | ||
110 | 111 | ||
111 | void ODict::slotSetErrorcount( int count ) | 112 | void ODict::slotSetErrorcount( int count ) |
112 | { | 113 | { |
113 | errorTol = count; | 114 | errorTol = count; |
114 | } | 115 | } |
115 | 116 | ||