-rw-r--r-- | noncore/apps/odict/dingwidget.cpp | 111 | ||||
-rw-r--r-- | noncore/apps/odict/dingwidget.h | 35 | ||||
-rw-r--r-- | noncore/apps/odict/odict.cpp | 53 | ||||
-rw-r--r-- | noncore/apps/odict/odict.h | 4 |
4 files changed, 159 insertions, 44 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 | |||
@@ -30,15 +30,33 @@ | |||
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 | |
34 | DingWidget::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 | |||
50 | void 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 | { |
@@ -49,32 +67,54 @@ DingWidget::DingWidget(QString word, QTextBrowser *browser_top, QTextBrowser *br | |||
49 | } | 67 | } |
50 | file.close(); | 68 | file.close(); |
51 | } | 69 | } |
70 | qDebug( "loadedDict(...) ist beended" ); | ||
71 | } | ||
52 | 72 | ||
53 | lines = lines.grep( queryword ); | 73 | QString DingWidget::loadedDict() |
74 | { | ||
75 | qDebug( dictName ); | ||
76 | qDebug( "^ ^ ^ ^ ^ ^ ^ war der dictName" ); | ||
77 | return dictName; | ||
78 | } | ||
54 | 79 | ||
55 | topbrowser = browser_top; | 80 | void DingWidget::setCaseSensitive( bool caseS ) |
56 | bottombrowser = browser_bottom; | 81 | { |
82 | isCaseSensitive = caseS; | ||
57 | } | 83 | } |
58 | 84 | ||
59 | void DingWidget::setText() | 85 | void 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 ); | 90 | void DingWidget::setCompleteWord( bool cword ) |
66 | bottombrowser->setText( bottom ); | 91 | { |
92 | isCompleteWord = cword; | ||
93 | } | ||
94 | |||
95 | void DingWidget::setQueryWord( QString qword ) | ||
96 | { | ||
97 | queryword = qword; | ||
98 | } | ||
99 | |||
100 | BroswerContent DingWidget::setText( QString word ) | ||
101 | { | ||
102 | queryword = word; | ||
103 | qDebug( queryword ); | ||
104 | qDebug( "^ ^ ^ ^ ^ ^ ^ war das gesuchte Word"); | ||
105 | return parseInfo(); | ||
67 | } | 106 | } |
68 | 107 | ||
69 | void DingWidget::loadValues() | 108 | void 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 | ||
76 | void DingWidget::parseInfo( QStringList &lines, QString &top, QString &bottom ) | 115 | BroswerContent DingWidget::parseInfo() |
77 | { | 116 | { |
117 | QStringList search = lines.grep( queryword ); | ||
78 | 118 | ||
79 | QString current; | 119 | QString current; |
80 | QString left; | 120 | QString left; |
@@ -86,9 +126,15 @@ void DingWidget::parseInfo( QStringList &lines, QString &top, QString &bottom ) | |||
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) ); |
@@ -106,6 +152,33 @@ void DingWidget::parseInfo( QStringList &lines, QString &top, QString &bottom ) | |||
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 | } |
diff --git a/noncore/apps/odict/dingwidget.h b/noncore/apps/odict/dingwidget.h index c96039f..ba37009 100644 --- a/noncore/apps/odict/dingwidget.h +++ b/noncore/apps/odict/dingwidget.h | |||
@@ -7,28 +7,41 @@ | |||
7 | * * | 7 | * * |
8 | **************************************************************************/ | 8 | **************************************************************************/ |
9 | 9 | ||
10 | class QString; | ||
11 | class QTextBrowser; | ||
12 | class QStringList; | ||
13 | |||
14 | #include <qstringlist.h> | 10 | #include <qstringlist.h> |
15 | |||
16 | #include <qstring.h> | 11 | #include <qstring.h> |
17 | 12 | ||
13 | struct BroswerContent | ||
14 | { | ||
15 | QString top; | ||
16 | QString bottom; | ||
17 | }; | ||
18 | |||
18 | class DingWidget | 19 | class DingWidget |
19 | { | 20 | { |
20 | public: | 21 | public: |
21 | DingWidget(QString word = 0, QTextBrowser* = 0, QTextBrowser* =0, QString activated_name=0); | 22 | DingWidget(); |
22 | 23 | ||
23 | void setText(); | 24 | BroswerContent setText( QString ); |
24 | QStringList lines; | 25 | QStringList lines; |
26 | void setCaseSensitive( bool ); | ||
27 | void setCompleteWord( bool ); | ||
28 | void loadDict( QString ); | ||
29 | QString loadedDict(); | ||
30 | void setQueryWord( QString ); | ||
31 | void setDict( QString ); | ||
32 | |||
25 | private: | 33 | private: |
34 | BroswerContent parseInfo(); | ||
35 | |||
36 | BroswerContent s_strings; | ||
37 | bool isCompleteWord; | ||
38 | bool isCaseSensitive; | ||
39 | |||
40 | QString dictName; | ||
41 | |||
26 | QString search_word; | 42 | QString search_word; |
27 | void parseInfo( QStringList& , QString&, QString& ); | ||
28 | QString queryword; | ||
29 | void loadValues(); | 43 | void loadValues(); |
44 | QString queryword; | ||
30 | QString methodname; | 45 | QString methodname; |
31 | QString trenner; | 46 | QString trenner; |
32 | |||
33 | QTextBrowser *topbrowser, *bottombrowser; | ||
34 | }; | 47 | }; |
diff --git a/noncore/apps/odict/odict.cpp b/noncore/apps/odict/odict.cpp index 6f176f9..549c40a 100644 --- a/noncore/apps/odict/odict.cpp +++ b/noncore/apps/odict/odict.cpp | |||
@@ -39,12 +39,13 @@ | |||
39 | 39 | ||
40 | ODict::ODict() : QMainWindow() | 40 | ODict::ODict() : QMainWindow() |
41 | { | 41 | { |
42 | |||
43 | activated_name = QString::null; | 42 | activated_name = QString::null; |
43 | |||
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 | QHBox *hbox = new QHBox( vbox ); | 49 | QHBox *hbox = new QHBox( vbox ); |
49 | QLabel* query_label = new QLabel( tr( "Query:" ) , hbox ); query_label->show(); | 50 | QLabel* query_label = new QLabel( tr( "Query:" ) , hbox ); query_label->show(); |
50 | query_le = new QLineEdit( hbox ); | 51 | query_le = new QLineEdit( hbox ); |
@@ -55,6 +56,8 @@ ODict::ODict() : QMainWindow() | |||
55 | browser_top = new QTextBrowser( vbox ); | 56 | browser_top = new QTextBrowser( vbox ); |
56 | browser_bottom = new QTextBrowser( vbox ); | 57 | browser_bottom = new QTextBrowser( vbox ); |
57 | 58 | ||
59 | ding = new DingWidget(); | ||
60 | |||
58 | loadConfig(); | 61 | loadConfig(); |
59 | setCentralWidget( vbox ); | 62 | setCentralWidget( vbox ); |
60 | } | 63 | } |
@@ -75,6 +78,7 @@ void ODict::loadConfig() | |||
75 | cfg.setGroup( *it ); | 78 | cfg.setGroup( *it ); |
76 | query_co->insertItem( cfg.readEntry( "Name" ) ); | 79 | query_co->insertItem( cfg.readEntry( "Name" ) ); |
77 | } | 80 | } |
81 | slotMethodChanged(1 ); //FIXME: this line should not contain a integer | ||
78 | } | 82 | } |
79 | 83 | ||
80 | 84 | ||
@@ -90,22 +94,47 @@ void ODict::saveConfig() | |||
90 | 94 | ||
91 | void ODict::slotDisplayAbout() | 95 | void ODict::slotDisplayAbout() |
92 | { | 96 | { |
93 | QMessageBox::about( this, tr( "About ODict" ), tr( "OPIE-Dictionary ODict \n (c) 2002, 2003 Carsten Niehaus \n cniehaus@handhelds.org \n Version 20030104" ) ); | 97 | QMessageBox::about( this, tr( "About ODict" ), tr( "OPIE-Dictionary ODict \n (c) 2002, 2003 Carsten Niehaus \n cniehaus@handhelds.org \n Version 20030108" ) ); |
94 | } | 98 | } |
95 | 99 | ||
96 | void ODict::slotStartQuery() | 100 | void ODict::slotStartQuery() |
97 | { | 101 | { |
98 | QString querystring = query_le->text(); | 102 | QString querystring = query_le->text(); |
99 | qDebug("opening dict >%s< for >%s<", activated_name.latin1(),querystring.latin1()); | 103 | //X qDebug("opening dict >%s< for >%s<", activated_name.latin1(),querystring.latin1()); |
100 | if (querystring.isEmpty()){ | 104 | //X if (querystring.isEmpty()){ |
101 | qWarning("empty querystring"); | 105 | //X qWarning("empty querystring"); |
102 | return; | 106 | //X return; |
107 | //X } | ||
108 | //X if (!activated_name || activated_name.isEmpty()) | ||
109 | //X QMessageBox::warning(this,tr("No Dictionary"),tr("Please choose a dictonary") ); | ||
110 | //X else | ||
111 | //X { | ||
112 | |||
113 | ding->setCaseSensitive( casesens ); | ||
114 | ding->setCompleteWord( completewords ); | ||
115 | ding->setDict( activated_name ); | ||
116 | |||
117 | qDebug( " activated_name ist :" ); | ||
118 | qDebug( activated_name ); | ||
119 | |||
120 | qDebug( " loadedDict() ist :" ); | ||
121 | qDebug( ding->loadedDict() ); | ||
122 | if ( activated_name != ding->loadedDict() ) | ||
123 | { | ||
124 | qDebug( "ComboBox geändert" ); | ||
125 | ding->loadDict(activated_name); | ||
103 | } | 126 | } |
104 | if (!activated_name || activated_name.isEmpty()) | 127 | else qDebug( "ComboBox war GLEICH" ); |
105 | QMessageBox::warning(this,tr("No Dictionary"),tr("Please choose a dictonary") ); | 128 | |
106 | else | 129 | BroswerContent test = ding->setText( querystring ); |
107 | DingWidget *ding = new DingWidget( querystring , browser_top, browser_bottom, activated_name ); | 130 | |
108 | ding->setText(); | 131 | browser_top->setText( test.top ); |
132 | browser_bottom->setText( test.bottom ); | ||
133 | |||
134 | qDebug( "Text sollte gesetzt sein..." ); | ||
135 | |||
136 | //X } | ||
137 | |||
109 | } | 138 | } |
110 | 139 | ||
111 | 140 | ||
@@ -152,7 +181,7 @@ void ODict::slotSetParameter( int count ) | |||
152 | else qWarning( "ERROR" ); | 181 | else qWarning( "ERROR" ); |
153 | } | 182 | } |
154 | 183 | ||
155 | void ODict::slotMethodChanged( int methodnumber ) | 184 | void ODict::slotMethodChanged( int /*methodnumber*/ ) |
156 | { | 185 | { |
157 | activated_name = query_co->currentText(); | 186 | activated_name = query_co->currentText(); |
158 | } | 187 | } |
diff --git a/noncore/apps/odict/odict.h b/noncore/apps/odict/odict.h index 5096c5e..b20c165 100644 --- a/noncore/apps/odict/odict.h +++ b/noncore/apps/odict/odict.h | |||
@@ -21,6 +21,7 @@ class QActionGroup; | |||
21 | class DingWidget; | 21 | class DingWidget; |
22 | class QTextBrowser; | 22 | class QTextBrowser; |
23 | class QComboBox; | 23 | class QComboBox; |
24 | class DingWidget; | ||
24 | 25 | ||
25 | class ODict : public QMainWindow | 26 | class ODict : public QMainWindow |
26 | { | 27 | { |
@@ -31,6 +32,7 @@ class ODict : public QMainWindow | |||
31 | QVBox *vbox; | 32 | QVBox *vbox; |
32 | QTextBrowser *browser_top, | 33 | QTextBrowser *browser_top, |
33 | *browser_bottom; | 34 | *browser_bottom; |
35 | DingWidget *ding; | ||
34 | 36 | ||
35 | private: | 37 | private: |
36 | QPopupMenu *help, *settings, *parameter, *error_tol_menu; | 38 | QPopupMenu *help, *settings, *parameter, *error_tol_menu; |
@@ -44,8 +46,6 @@ class ODict : public QMainWindow | |||
44 | 46 | ||
45 | QAction *setting_a, *setting_b; | 47 | QAction *setting_a, *setting_b; |
46 | 48 | ||
47 | DingWidget *ding; | ||
48 | |||
49 | void setupMenus(); | 49 | void setupMenus(); |
50 | 50 | ||
51 | int errorTol; | 51 | int errorTol; |