summaryrefslogtreecommitdiff
authorcniehaus <cniehaus>2003-05-02 15:36:57 (UTC)
committer cniehaus <cniehaus>2003-05-02 15:36:57 (UTC)
commitf0b3896983e1f2c10d3fb3dde3fa08997221cdce (patch) (unidiff)
tree81191da4f86b0d28727432b9fe621b98f689ed19
parentb40991b25dd22c55cc80a9a9c4ae0adec103d575 (diff)
downloadopie-f0b3896983e1f2c10d3fb3dde3fa08997221cdce.zip
opie-f0b3896983e1f2c10d3fb3dde3fa08997221cdce.tar.gz
opie-f0b3896983e1f2c10d3fb3dde3fa08997221cdce.tar.bz2
warn the user if there is no dict defines
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/odict/odict.cpp26
1 files changed, 25 insertions, 1 deletions
diff --git a/noncore/apps/odict/odict.cpp b/noncore/apps/odict/odict.cpp
index cc3148a..9f9a8d9 100644
--- a/noncore/apps/odict/odict.cpp
+++ b/noncore/apps/odict/odict.cpp
@@ -1,190 +1,214 @@
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 <qlayout.h> 21#include <qlayout.h>
22#include <qpopupmenu.h> 22#include <qpopupmenu.h>
23#include <qmenubar.h> 23#include <qmenubar.h>
24#include <qmessagebox.h> 24#include <qmessagebox.h>
25#include <qpe/config.h> 25#include <qpe/config.h>
26#include <qhbox.h> 26#include <qhbox.h>
27#include <qvbox.h> 27#include <qvbox.h>
28#include <qlabel.h> 28#include <qlabel.h>
29#include <qpushbutton.h> 29#include <qpushbutton.h>
30#include <qlineedit.h> 30#include <qlineedit.h>
31#include <qmainwindow.h> 31#include <qmainwindow.h>
32#include <qstring.h> 32#include <qstring.h>
33#include <qaction.h> 33#include <qaction.h>
34#include <qtextbrowser.h> 34#include <qtextbrowser.h>
35#include <qcombobox.h> 35#include <qcombobox.h>
36 36
37#include <qpe/resource.h> 37#include <qpe/resource.h>
38 38
39 39
40ODict::ODict() : QMainWindow() 40ODict::ODict() : QMainWindow()
41{ 41{
42 activated_name = QString::null; 42 activated_name = QString::null;
43 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 QHBox *hbox = new QHBox( vbox ); 48 QHBox *hbox = new QHBox( vbox );
49 QLabel* query_label = new QLabel( tr( "Query:" ) , hbox ); query_label->show(); 49 QLabel* query_label = new QLabel( tr( "Query:" ) , hbox ); query_label->show();
50 query_le = new QLineEdit( hbox ); 50 query_le = new QLineEdit( hbox );
51 query_co = new QComboBox( hbox ); 51 query_co = new QComboBox( hbox );
52 connect( query_co , SIGNAL( activated(int) ), this, SLOT( slotMethodChanged(int) ) ); 52 connect( query_co , SIGNAL( activated(int) ), this, SLOT( slotMethodChanged(int) ) );
53 ok_button = new QPushButton( tr( "&Ok" ), hbox ); 53 ok_button = new QPushButton( tr( "&Ok" ), hbox );
54 connect( ok_button, SIGNAL( released() ), this, SLOT( slotStartQuery() ) ); 54 connect( ok_button, SIGNAL( released() ), this, SLOT( slotStartQuery() ) );
55 browser_top = new QTextBrowser( vbox ); 55 browser_top = new QTextBrowser( vbox );
56 browser_bottom = new QTextBrowser( vbox ); 56 browser_bottom = new QTextBrowser( vbox );
57 57
58 ding = new DingWidget(); 58 ding = new DingWidget();
59 ding->loadValues(); 59 ding->loadValues();
60 60
61 loadConfig(); 61 loadConfig();
62 setCentralWidget( vbox ); 62 setCentralWidget( vbox );
63} 63}
64 64
65void ODict::loadConfig() 65void ODict::loadConfig()
66{ 66{
67 Config cfg ( "odict" ); 67 Config cfg ( "odict" );
68 cfg.setGroup( "generalsettings" ); 68 cfg.setGroup( "generalsettings" );
69 errorTol = cfg.readEntry( "errtol" ).toInt(); 69 errorTol = cfg.readEntry( "errtol" ).toInt();
70 casesens = cfg.readEntry( "casesens" ).toInt(); 70 casesens = cfg.readEntry( "casesens" ).toInt();
71 regexp = cfg.readEntry( "regexp" ).toInt(); 71 regexp = cfg.readEntry( "regexp" ).toInt();
72 completewords = cfg.readEntry( "completewords" ).toInt(); 72 completewords = cfg.readEntry( "completewords" ).toInt();
73 73
74 QStringList groupListCfg = cfg.groupList().grep( "Method_" ); 74 QStringList groupListCfg = cfg.groupList().grep( "Method_" );
75 query_co->clear(); 75 query_co->clear();
76 for ( QStringList::Iterator it = groupListCfg.begin() ; it != groupListCfg.end() ; ++it ) 76 for ( QStringList::Iterator it = groupListCfg.begin() ; it != groupListCfg.end() ; ++it )
77 { 77 {
78 cfg.setGroup( *it ); 78 cfg.setGroup( *it );
79 query_co->insertItem( cfg.readEntry( "Name" ) ); 79 query_co->insertItem( cfg.readEntry( "Name" ) );
80 } 80 }
81 slotMethodChanged(1 ); //FIXME: this line should not contain a integer 81 slotMethodChanged( 1 ); //FIXME: this line should not contain a integer
82} 82}
83 83
84 84
85void ODict::saveConfig() 85void ODict::saveConfig()
86{ 86{
87 Config cfg ( "odict" ); 87 Config cfg ( "odict" );
88 cfg.setGroup( "generalsettings" ); 88 cfg.setGroup( "generalsettings" );
89 cfg.writeEntry( "errtol" , errorTol ); 89 cfg.writeEntry( "errtol" , errorTol );
90 cfg.writeEntry( "casesens" , casesens ); 90 cfg.writeEntry( "casesens" , casesens );
91 cfg.writeEntry( "regexp" , regexp ); 91 cfg.writeEntry( "regexp" , regexp );
92 cfg.writeEntry( "completewords" , completewords ); 92 cfg.writeEntry( "completewords" , completewords );
93} 93}
94 94
95void ODict::slotStartQuery() 95void ODict::slotStartQuery()
96{ 96{
97 /*
98 * if the user has not yet defined a dictionary
99 */
100 if ( !query_co->currentText() )
101 {
102 switch ( QMessageBox::information( this, tr( "OPIE-Dictionary" ),
103 tr( "No dictionary defined" ),
104 tr( "&Define one" ),
105 tr( "&Cancel" ),
106 0, // Define a dict choosen
107 1 ) ) // Cancel choosen
108 {
109
110 case 0:
111 slotSettings();
112 break;
113 case 1: // stop here
114 return;
115 }
116 }
117
118 /*
119 * ok, the user has defined a dict
120 */
97 QString querystring = query_le->text(); 121 QString querystring = query_le->text();
98 ding->setCaseSensitive( casesens ); 122 ding->setCaseSensitive( casesens );
99 ding->setCompleteWord( completewords ); 123 ding->setCompleteWord( completewords );
100 ding->setDict( activated_name ); 124 ding->setDict( activated_name );
101 125
102 if ( activated_name != ding->loadedDict() ) 126 if ( activated_name != ding->loadedDict() )
103 ding->loadDict(activated_name); 127 ding->loadDict(activated_name);
104 128
105 BroswerContent test = ding->setText( querystring ); 129 BroswerContent test = ding->setText( querystring );
106 130
107 browser_top->setText( test.top ); 131 browser_top->setText( test.top );
108 browser_bottom->setText( test.bottom ); 132 browser_bottom->setText( test.bottom );
109} 133}
110 134
111 135
112void ODict::slotSetErrorcount( int count ) 136void ODict::slotSetErrorcount( int count )
113{ 137{
114 errorTol = count; 138 errorTol = count;
115} 139}
116 140
117void ODict::slotSettings() 141void ODict::slotSettings()
118{ 142{
119 ConfigDlg dlg( this, "Config" , true); 143 ConfigDlg dlg( this, "Config" , true);
120 if ( dlg.exec() == QDialog::Accepted ) 144 if ( dlg.exec() == QDialog::Accepted )
121 { 145 {
122 dlg.writeEntries(); 146 dlg.writeEntries();
123 loadConfig(); 147 loadConfig();
124 } 148 }
125 else qDebug( "abgebrochen" ); 149 else qDebug( "abgebrochen" );
126} 150}
127 151
128void ODict::slotSetParameter( int count ) 152void ODict::slotSetParameter( int count )
129{ 153{
130 if ( count == 0 ) 154 if ( count == 0 )
131 { 155 {
132 if ( casesens ) 156 if ( casesens )
133 casesens = false; 157 casesens = false;
134 else 158 else
135 casesens = true; 159 casesens = true;
136 } 160 }
137 161
138 if ( count == 1 ) 162 if ( count == 1 )
139 { 163 {
140 if ( completewords ) 164 if ( completewords )
141 completewords = false; 165 completewords = false;
142 else 166 else
143 completewords = true; 167 completewords = true;
144 } 168 }
145 if ( count == 2 ) 169 if ( count == 2 )
146 { 170 {
147 if ( regexp ) 171 if ( regexp )
148 regexp = false; 172 regexp = false;
149 else 173 else
150 regexp = true; 174 regexp = true;
151 } 175 }
152 else qWarning( "ERROR" ); 176 else qWarning( "ERROR" );
153} 177}
154 178
155void ODict::slotMethodChanged( int /*methodnumber*/ ) 179void ODict::slotMethodChanged( int /*methodnumber*/ )
156{ 180{
157 activated_name = query_co->currentText(); 181 activated_name = query_co->currentText();
158} 182}
159 183
160void ODict::setupMenus() 184void ODict::setupMenus()
161{ 185{
162 menu = new QMenuBar( this ); 186 menu = new QMenuBar( this );
163 187
164 settings = new QPopupMenu( menu ); 188 settings = new QPopupMenu( menu );
165 setting_a = new QAction(tr( "Configuration" ), Resource::loadPixmap( "new" ), QString::null, 0, this, 0 ); 189 setting_a = new QAction(tr( "Configuration" ), Resource::loadPixmap( "new" ), QString::null, 0, this, 0 );
166 connect( setting_a, SIGNAL( activated() ), this, SLOT( slotSettings() ) ); 190 connect( setting_a, SIGNAL( activated() ), this, SLOT( slotSettings() ) );
167 setting_a->addTo( settings ); 191 setting_a->addTo( settings );
168 setting_b = new QAction(tr( "Searchmethods" ), Resource::loadPixmap( "edit" ), QString::null, 0, this, 0 ); 192 setting_b = new QAction(tr( "Searchmethods" ), Resource::loadPixmap( "edit" ), QString::null, 0, this, 0 );
169 193
170 parameter = new QPopupMenu( menu ); 194 parameter = new QPopupMenu( menu );
171 connect( parameter, SIGNAL( activated( int ) ), this, SLOT( slotSetParameter( int ) ) ); 195 connect( parameter, SIGNAL( activated( int ) ), this, SLOT( slotSetParameter( int ) ) );
172 parameter->insertItem( tr( "C&ase sensitive" ), 0 ,0 ); 196 parameter->insertItem( tr( "C&ase sensitive" ), 0 ,0 );
173 parameter->insertItem( tr( "Only &complete Words" ), 1 , 1) ; 197 parameter->insertItem( tr( "Only &complete Words" ), 1 , 1) ;
174 parameter->insertItem( tr( "Allow &reg. expressions" ), 2 ); 198 parameter->insertItem( tr( "Allow &reg. expressions" ), 2 );
175 parameter->insertSeparator(); 199 parameter->insertSeparator();
176 error_tol_menu = new QPopupMenu( menu ); 200 error_tol_menu = new QPopupMenu( menu );
177 error_tol_menu->setCheckable( TRUE ); 201 error_tol_menu->setCheckable( TRUE );
178 connect( error_tol_menu, SIGNAL( activated( int ) ), this, SLOT( slotSetErrorcount( int ) ) ); 202 connect( error_tol_menu, SIGNAL( activated( int ) ), this, SLOT( slotSetErrorcount( int ) ) );
179 203
180 error_tol_menu->insertItem( tr( "0 Errors" ), 0 ); 204 error_tol_menu->insertItem( tr( "0 Errors" ), 0 );
181 error_tol_menu->insertItem( tr( "1 Errors" ), 1 ); 205 error_tol_menu->insertItem( tr( "1 Errors" ), 1 );
182 error_tol_menu->insertItem( tr( "2 Errors" ), 2 ); 206 error_tol_menu->insertItem( tr( "2 Errors" ), 2 );
183 error_tol_menu->insertItem( tr( "3 Errors" ), 3 ); 207 error_tol_menu->insertItem( tr( "3 Errors" ), 3 );
184 error_tol_menu->insertItem( tr( "4 Errors" ), 4 ); 208 error_tol_menu->insertItem( tr( "4 Errors" ), 4 );
185 error_tol_menu->insertItem( tr( "Until Hit" ), 5 ); 209 error_tol_menu->insertItem( tr( "Until Hit" ), 5 );
186 parameter->insertItem( tr( "&Error tolerance" ), error_tol_menu ); 210 parameter->insertItem( tr( "&Error tolerance" ), error_tol_menu );
187 211
188 menu->insertItem( tr( "Settings" ) , settings ); 212 menu->insertItem( tr( "Settings" ) , settings );
189 menu->insertItem( tr( "Parameter" ) , parameter ); 213 menu->insertItem( tr( "Parameter" ) , parameter );
190} 214}