-rw-r--r-- | noncore/apps/odict/odict.cpp | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/noncore/apps/odict/odict.cpp b/noncore/apps/odict/odict.cpp index 497de36..96ba3ae 100644 --- a/noncore/apps/odict/odict.cpp +++ b/noncore/apps/odict/odict.cpp | |||
@@ -1,217 +1,221 @@ | |||
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 "odict.h" | 17 | #include "odict.h" |
18 | #include "configdlg.h" | 18 | #include "configdlg.h" |
19 | #include "dingwidget.h" | 19 | #include "dingwidget.h" |
20 | 20 | ||
21 | #include <opie2/oresource.h> | ||
22 | |||
23 | #include <qpe/config.h> | ||
24 | |||
21 | #include <qmenubar.h> | 25 | #include <qmenubar.h> |
22 | #include <qmessagebox.h> | 26 | #include <qmessagebox.h> |
23 | #include <qvbox.h> | 27 | #include <qvbox.h> |
24 | #include <qlabel.h> | 28 | #include <qlabel.h> |
25 | #include <qpushbutton.h> | 29 | #include <qpushbutton.h> |
26 | #include <qlineedit.h> | 30 | #include <qlineedit.h> |
27 | #include <qaction.h> | 31 | #include <qaction.h> |
28 | #include <qtextbrowser.h> | 32 | #include <qtextbrowser.h> |
29 | #include <qcombobox.h> | 33 | #include <qcombobox.h> |
30 | 34 | ||
31 | #include <qpe/resource.h> | ||
32 | #include <qpe/config.h> | ||
33 | |||
34 | ODict::ODict(QWidget* parent, const char* name, WFlags fl ) : QMainWindow(parent, name, fl ) | 35 | ODict::ODict(QWidget* parent, const char* name, WFlags fl ) : QMainWindow(parent, name, fl ) |
35 | { | 36 | { |
36 | activated_name = QString::null; | 37 | activated_name = QString::null; |
37 | 38 | ||
38 | vbox = new QVBox( this ); | 39 | vbox = new QVBox( this ); |
39 | setCaption( tr( "Opie-Dictionary" ) ); | 40 | setCaption( tr( "Opie-Dictionary" ) ); |
40 | setupMenus(); | 41 | setupMenus(); |
41 | 42 | ||
42 | QHBox *hbox = new QHBox( vbox ); | 43 | QHBox *hbox = new QHBox( vbox ); |
43 | QLabel* query_label = new QLabel( tr( "Query:" ) , hbox ); | 44 | QLabel* query_label = new QLabel( tr( "Query:" ) , hbox ); |
44 | query_label->show(); | 45 | query_label->show(); |
45 | query_le = new QLineEdit( hbox ); | 46 | query_le = new QLineEdit( hbox ); |
46 | query_co = new QComboBox( hbox ); | 47 | query_co = new QComboBox( hbox ); |
47 | connect( query_co , SIGNAL( activated(const QString&) ), this, SLOT( slotMethodChanged(const QString&) ) ); | 48 | connect( query_co , SIGNAL( activated(const QString&) ), this, SLOT( slotMethodChanged(const QString&) ) ); |
48 | ok_button = new QPushButton( tr( "&Ok" ), hbox ); | 49 | ok_button = new QPushButton( tr( "&Ok" ), hbox ); |
49 | connect( ok_button, SIGNAL( released() ), this, SLOT( slotStartQuery() ) ); | 50 | connect( ok_button, SIGNAL( released() ), this, SLOT( slotStartQuery() ) ); |
50 | 51 | ||
51 | top_name = new QLabel( vbox ); | 52 | top_name = new QLabel( vbox ); |
52 | top_name->setAlignment( AlignHCenter ); | 53 | top_name->setAlignment( AlignHCenter ); |
53 | browser_top = new QTextBrowser( vbox ); | 54 | browser_top = new QTextBrowser( vbox ); |
54 | bottom_name = new QLabel( vbox ); | 55 | bottom_name = new QLabel( vbox ); |
55 | bottom_name->setAlignment( AlignHCenter ); | 56 | bottom_name->setAlignment( AlignHCenter ); |
56 | browser_bottom = new QTextBrowser( vbox ); | 57 | browser_bottom = new QTextBrowser( vbox ); |
57 | 58 | ||
58 | ding = new DingWidget(); | 59 | ding = new DingWidget(); |
59 | 60 | ||
60 | loadConfig(); | 61 | loadConfig(); |
61 | setCentralWidget( vbox ); | 62 | setCentralWidget( vbox ); |
62 | } | 63 | } |
63 | 64 | ||
64 | void ODict::loadConfig() | 65 | void ODict::loadConfig() |
65 | { | 66 | { |
66 | /* | 67 | /* |
67 | * the name of the last used dictionary | 68 | * the name of the last used dictionary |
68 | */ | 69 | */ |
69 | QString lastname; | 70 | QString lastname; |
70 | 71 | ||
71 | Config cfg ( "odict" ); | 72 | Config cfg ( "odict" ); |
72 | cfg.setGroup( "generalsettings" ); | 73 | cfg.setGroup( "generalsettings" ); |
73 | casesens = cfg.readEntry( "casesens" ).toInt(); | 74 | casesens = cfg.readEntry( "casesens" ).toInt(); |
74 | 75 | ||
75 | QString lastDict = cfg.readEntry( "lastdict" ); | 76 | QString lastDict = cfg.readEntry( "lastdict" ); |
76 | int i = 0, e = 0; | 77 | int i = 0, e = 0; |
77 | 78 | ||
78 | QStringList groupListCfg = cfg.groupList().grep( "Method_" ); | 79 | QStringList groupListCfg = cfg.groupList().grep( "Method_" ); |
79 | query_co->clear(); | 80 | query_co->clear(); |
80 | for ( QStringList::Iterator it = groupListCfg.begin() ; it != groupListCfg.end() ; ++it ) | 81 | for ( QStringList::Iterator it = groupListCfg.begin() ; it != groupListCfg.end() ; ++it ) |
81 | { | 82 | { |
82 | QString name; | 83 | QString name; |
83 | cfg.setGroup( *it ); | 84 | cfg.setGroup( *it ); |
84 | name = cfg.readEntry( "Name" ); | 85 | name = cfg.readEntry( "Name" ); |
85 | if ( name != QString::null ) { | 86 | if ( name != QString::null ) { |
86 | query_co->insertItem( name ); | 87 | query_co->insertItem( name ); |
87 | } | 88 | } |
88 | 89 | ||
89 | /* | 90 | /* |
90 | * this check is to look up what dictionary has been used the | 91 | * this check is to look up what dictionary has been used the |
91 | * last time | 92 | * last time |
92 | */ | 93 | */ |
93 | if ( lastDict == name ) | 94 | if ( lastDict == name ) |
94 | { | 95 | { |
95 | e = i; | 96 | e = i; |
96 | lastname = name; | 97 | lastname = name; |
97 | } | 98 | } |
98 | i++; | 99 | i++; |
99 | } | 100 | } |
100 | /* | 101 | /* |
101 | * now set the two names of the dictionary and the correct QComboBox-Entry | 102 | * now set the two names of the dictionary and the correct QComboBox-Entry |
102 | */ | 103 | */ |
103 | 104 | ||
104 | lookupLanguageNames( lastname ); | 105 | lookupLanguageNames( lastname ); |
105 | ding->loadDict( lastname ); | 106 | ding->loadDict( lastname ); |
106 | ding->loadValues(); | 107 | ding->loadValues(); |
107 | 108 | ||
108 | query_co->setCurrentItem( e ); | 109 | query_co->setCurrentItem( e ); |
109 | top_name->setText( top_name_content ); | 110 | top_name->setText( top_name_content ); |
110 | bottom_name->setText( bottom_name_content ); | 111 | bottom_name->setText( bottom_name_content ); |
111 | } | 112 | } |
112 | 113 | ||
113 | void ODict::lookupLanguageNames( QString dictname ) | 114 | void ODict::lookupLanguageNames( QString dictname ) |
114 | { | 115 | { |
115 | Config cfg ( "odict" ); | 116 | Config cfg ( "odict" ); |
116 | cfg.setGroup( "Method_"+dictname ); | 117 | cfg.setGroup( "Method_"+dictname ); |
117 | top_name_content = cfg.readEntry( "Lang1" ); | 118 | top_name_content = cfg.readEntry( "Lang1" ); |
118 | bottom_name_content = cfg.readEntry( "Lang2" ); | 119 | bottom_name_content = cfg.readEntry( "Lang2" ); |
119 | } | 120 | } |
120 | 121 | ||
121 | void ODict::saveConfig() | 122 | void ODict::saveConfig() |
122 | { | 123 | { |
123 | Config cfg ( "odict" ); | 124 | Config cfg ( "odict" ); |
124 | cfg.setGroup( "generalsettings" ); | 125 | cfg.setGroup( "generalsettings" ); |
125 | cfg.writeEntry( "casesens" , casesens ); | 126 | cfg.writeEntry( "casesens" , casesens ); |
126 | cfg.writeEntry( "lastdict" , query_co->currentText() ); | 127 | cfg.writeEntry( "lastdict" , query_co->currentText() ); |
127 | } | 128 | } |
128 | 129 | ||
129 | void ODict::slotStartQuery() | 130 | void ODict::slotStartQuery() |
130 | { | 131 | { |
131 | QString querystring = query_le->text(); | 132 | QString querystring = query_le->text(); |
132 | if ( !querystring.isEmpty() ) | 133 | if ( !querystring.isEmpty() ) |
133 | { | 134 | { |
134 | /* | 135 | /* |
135 | * if the user has not yet defined a dictionary | 136 | * if the user has not yet defined a dictionary |
136 | */ | 137 | */ |
137 | if ( !query_co->currentText() ) | 138 | if ( !query_co->currentText() ) |
138 | { | 139 | { |
139 | switch ( QMessageBox::information( this, tr( "OPIE-Dictionary" ), | 140 | switch ( QMessageBox::information( this, tr( "OPIE-Dictionary" ), |
140 | tr( "No dictionary defined" ), | 141 | tr( "No dictionary defined" ), |
141 | tr( "&Define one" ), | 142 | tr( "&Define one" ), |
142 | tr( "&Cancel" ), | 143 | tr( "&Cancel" ), |
143 | 0, // Define a dict | 144 | 0, // Define a dict |
144 | 1 ) ) // Cancel choosen | 145 | 1 ) ) // Cancel choosen |
145 | { | 146 | { |
146 | case 0: | 147 | case 0: |
147 | slotSettings(); | 148 | slotSettings(); |
148 | break; | 149 | break; |
149 | case 1: // stop here | 150 | case 1: // stop here |
150 | return; | 151 | return; |
151 | } | 152 | } |
152 | } | 153 | } |
153 | 154 | ||
154 | /* | 155 | /* |
155 | * ok, the user has defined a dict | 156 | * ok, the user has defined a dict |
156 | */ | 157 | */ |
157 | ding->setCaseSensitive( casesens ); | 158 | ding->setCaseSensitive( casesens ); |
158 | 159 | ||
159 | BroswerContent test = ding->setText( querystring ); | 160 | BroswerContent test = ding->setText( querystring ); |
160 | 161 | ||
161 | browser_top->setText( test.top ); | 162 | browser_top->setText( test.top ); |
162 | browser_bottom->setText( test.bottom ); | 163 | browser_bottom->setText( test.bottom ); |
163 | } | 164 | } |
164 | } | 165 | } |
165 | 166 | ||
166 | void ODict::slotSettings() | 167 | void ODict::slotSettings() |
167 | { | 168 | { |
168 | ConfigDlg dlg( this, "Config" , true); | 169 | ConfigDlg dlg( this, "Config" , true); |
169 | if ( dlg.exec() == QDialog::Accepted ) | 170 | if ( dlg.exec() == QDialog::Accepted ) |
170 | saveConfig(); | 171 | saveConfig(); |
171 | } | 172 | } |
172 | 173 | ||
173 | void ODict::slotSetParameter( int count ) | 174 | void ODict::slotSetParameter( int count ) |
174 | { | 175 | { |
175 | if ( count == 0 ) | 176 | if ( count == 0 ) |
176 | { | 177 | { |
177 | if ( casesens ) | 178 | if ( casesens ) |
178 | casesens = false; | 179 | casesens = false; |
179 | else | 180 | else |
180 | casesens = true; | 181 | casesens = true; |
181 | } | 182 | } |
182 | 183 | ||
183 | saveConfig(); | 184 | saveConfig(); |
184 | } | 185 | } |
185 | 186 | ||
186 | void ODict::slotMethodChanged( const QString& methodnumber ) | 187 | void ODict::slotMethodChanged( const QString& methodnumber ) |
187 | { | 188 | { |
188 | activated_name = methodnumber; | 189 | activated_name = methodnumber; |
189 | 190 | ||
190 | if ( activated_name != ding->loadedDict() ) | 191 | if ( activated_name != ding->loadedDict() ) |
191 | { | 192 | { |
192 | ding->loadDict(activated_name); | 193 | ding->loadDict(activated_name); |
193 | 194 | ||
194 | lookupLanguageNames( activated_name ); | 195 | lookupLanguageNames( activated_name ); |
195 | top_name->setText( top_name_content ); | 196 | top_name->setText( top_name_content ); |
196 | bottom_name->setText( bottom_name_content ); | 197 | bottom_name->setText( bottom_name_content ); |
197 | } | 198 | } |
198 | } | 199 | } |
199 | 200 | ||
200 | void ODict::setupMenus() | 201 | void ODict::setupMenus() |
201 | { | 202 | { |
202 | menu = new QMenuBar( this ); | 203 | menu = new QMenuBar( this ); |
203 | 204 | ||
204 | settings = new QPopupMenu( menu ); | 205 | settings = new QPopupMenu( menu ); |
205 | setting_a = new QAction(tr( "Configuration" ), Resource::loadPixmap( "new" ), QString::null, 0, this, 0 ); | 206 | setting_a = new QAction( tr( "Configuration" ), |
207 | Opie::Core::OResource::loadPixmap( "SettingsIcon", Opie::Core::OResource::SmallIcon ), | ||
208 | QString::null, 0, this, 0 ); | ||
206 | connect( setting_a, SIGNAL( activated() ), this, SLOT( slotSettings() ) ); | 209 | connect( setting_a, SIGNAL( activated() ), this, SLOT( slotSettings() ) ); |
207 | setting_a->addTo( settings ); | 210 | setting_a->addTo( settings ); |
208 | setting_b = new QAction(tr( "Searchmethods" ), Resource::loadPixmap( "edit" ), QString::null, 0, this, 0 ); | 211 | setting_b = new QAction( tr( "Search methods" ), |
212 | Opie::Core::OResource::loadPixmap( "edit", Opie::Core::OResource::SmallIcon ), | ||
213 | QString::null, 0, this, 0 ); | ||
209 | 214 | ||
210 | parameter = new QPopupMenu( menu ); | 215 | parameter = new QPopupMenu( menu ); |
211 | connect( parameter, SIGNAL( activated(int) ), this, SLOT( slotSetParameter(int) ) ); | 216 | connect( parameter, SIGNAL( activated(int) ), this, SLOT( slotSetParameter(int) ) ); |
212 | parameter->insertItem( tr( "C&ase sensitive" ), 0 ,0 ); | 217 | parameter->insertItem( tr( "Case sensitive" ), 0 ,0 ); |
213 | parameter->insertSeparator(); | ||
214 | 218 | ||
215 | menu->insertItem( tr( "Settings" ) , settings ); | 219 | menu->insertItem( tr( "Settings" ) , settings ); |
216 | menu->insertItem( tr( "Parameter" ) , parameter ); | 220 | menu->insertItem( tr( "Parameter" ) , parameter ); |
217 | } | 221 | } |