summaryrefslogtreecommitdiff
path: root/noncore/apps/odict/odict.cpp
Unidiff
Diffstat (limited to 'noncore/apps/odict/odict.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/odict/odict.cpp106
1 files changed, 68 insertions, 38 deletions
diff --git a/noncore/apps/odict/odict.cpp b/noncore/apps/odict/odict.cpp
index cb9c4e0..0745f53 100644
--- a/noncore/apps/odict/odict.cpp
+++ b/noncore/apps/odict/odict.cpp
@@ -50,57 +50,98 @@ ODict::ODict() : QMainWindow()
50 query_label->show(); 50 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(const QString&) ), this, SLOT( slotMethodChanged(const QString&) ) ); 53 connect( query_co , SIGNAL( activated(const QString&) ), this, SLOT( slotMethodChanged(const QString&) ) );
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
56 top_name = new QLabel( vbox ); 57 top_name = new QLabel( vbox );
58 top_name->setAlignment( AlignHCenter );
57 browser_top = new QTextBrowser( vbox ); 59 browser_top = new QTextBrowser( vbox );
58 bottom_name = new QLabel( vbox ); 60 bottom_name = new QLabel( vbox );
61 bottom_name->setAlignment( AlignHCenter );
59 browser_bottom = new QTextBrowser( vbox ); 62 browser_bottom = new QTextBrowser( vbox );
60 63
61 ding = new DingWidget(); 64 ding = new DingWidget();
62 ding->loadValues(); 65 ding->loadValues();
63 66
64 loadConfig(); 67 loadConfig();
65 setCentralWidget( vbox ); 68 setCentralWidget( vbox );
66} 69}
67 70
68void ODict::loadConfig() 71void ODict::loadConfig()
69{ 72{
73 /*
74 * the name of the last used dictionary
75 */
76 QString lastname;
77
70 Config cfg ( "odict" ); 78 Config cfg ( "odict" );
71 cfg.setGroup( "generalsettings" ); 79 cfg.setGroup( "generalsettings" );
72 errorTol = cfg.readEntry( "errtol" ).toInt();
73 casesens = cfg.readEntry( "casesens" ).toInt(); 80 casesens = cfg.readEntry( "casesens" ).toInt();
74 regexp = cfg.readEntry( "regexp" ).toInt(); 81 regexp = cfg.readEntry( "regexp" ).toInt();
75 completewords = cfg.readEntry( "completewords" ).toInt(); 82 completewords = cfg.readEntry( "completewords" ).toInt();
76 83
84 QString lastDict = cfg.readEntry( "lastdict" );
85 int i = 0, e = 0;
86
77 QStringList groupListCfg = cfg.groupList().grep( "Method_" ); 87 QStringList groupListCfg = cfg.groupList().grep( "Method_" );
78 query_co->clear(); 88 query_co->clear();
79 for ( QStringList::Iterator it = groupListCfg.begin() ; it != groupListCfg.end() ; ++it ) 89 for ( QStringList::Iterator it = groupListCfg.begin() ; it != groupListCfg.end() ; ++it )
80 { 90 {
91 QString name;
81 cfg.setGroup( *it ); 92 cfg.setGroup( *it );
82 query_co->insertItem( cfg.readEntry( "Name" ) ); 93 name = cfg.readEntry( "Name" );
94 query_co->insertItem( name );
95
96 /*
97 * this check is to look up what dictionary has been used the
98 * last time
99 */
100 if ( lastDict == name )
101 {
102 e = i;
103 lastname = name;
104 }
105 i++;
83 } 106 }
84 //XXXslotMethodChanged( "1" ); //FIXME: this line should not contain a integer 107 /*
108 * now set the two names of the dictionary and the correct QComboBox-Entry
109 */
110
111 lookupLanguageNames( lastname );
112
113 query_co->setCurrentItem( e );
114 top_name->setText( top_name_content );
115 bottom_name->setText( bottom_name_content );
85} 116}
86 117
118void ODict::lookupLanguageNames( QString dictname )
119{
120 Config cfg ( "odict" );
121 cfg.setGroup( "Method_"+dictname );
122 top_name_content = cfg.readEntry( "Lang1" );
123 bottom_name_content = cfg.readEntry( "Lang2" );
124}
87 125
88void ODict::saveConfig() 126void ODict::saveConfig()
89{ 127{
90 Config cfg ( "odict" ); 128 Config cfg ( "odict" );
91 cfg.setGroup( "generalsettings" ); 129 cfg.setGroup( "generalsettings" );
92 cfg.writeEntry( "errtol" , errorTol );
93 cfg.writeEntry( "casesens" , casesens ); 130 cfg.writeEntry( "casesens" , casesens );
94 cfg.writeEntry( "regexp" , regexp ); 131 cfg.writeEntry( "regexp" , regexp );
95 cfg.writeEntry( "completewords" , completewords ); 132 cfg.writeEntry( "completewords" , completewords );
133 cfg.writeEntry( "lastdict" , query_co->currentText() );
96} 134}
97 135
98void ODict::slotStartQuery() 136void ODict::slotStartQuery()
99{ 137{
100 if ( !query_le->text( ).isEmpty() ) 138 qDebug( "bin in slotStartQuery()" );
139
140 QString querystring = query_le->text();
141 if ( !querystring.isEmpty() )
101 { 142 {
102 /* 143 /*
103 * if the user has not yet defined a dictionary 144 * if the user has not yet defined a dictionary
104 */ 145 */
105 if ( !query_co->currentText() ) 146 if ( !query_co->currentText() )
106 { 147 {
@@ -108,55 +149,51 @@ void ODict::slotStartQuery()
108 tr( "No dictionary defined" ), 149 tr( "No dictionary defined" ),
109 tr( "&Define one" ), 150 tr( "&Define one" ),
110 tr( "&Cancel" ), 151 tr( "&Cancel" ),
111 0, // Define a dict choosen 152 0, // Define a dict choosen
112 1 ) ) // Cancel choosen 153 1 ) ) // Cancel choosen
113 { 154 {
114
115 case 0: 155 case 0:
116 slotSettings(); 156 slotSettings();
117 break; 157 break;
118 case 1: // stop here 158 case 1: // stop here
119 return; 159 return;
120 } 160 }
121 } 161 }
122 162
123 /* 163 /*
124 * ok, the user has defined a dict 164 * ok, the user has defined a dict
125 */ 165 */
126 QString querystring = query_le->text();
127 ding->setCaseSensitive( casesens ); 166 ding->setCaseSensitive( casesens );
128 ding->setCompleteWord( completewords ); 167 ding->setCompleteWord( completewords );
168
169 qDebug( "activated_name ist:" );
170 qDebug( activated_name );
171
129 ding->setDict( activated_name ); 172 ding->setDict( activated_name );
130 top_name->setText( ding->lang1_name );
131 bottom_name->setText( ding->lang2_name );
132 173
133 if ( activated_name != ding->loadedDict() ) 174 //X if ( activated_name != ding->loadedDict() )
134 ding->loadDict(activated_name); 175 ding->loadDict(activated_name);
135 176
136 BroswerContent test = ding->setText( querystring ); 177 BroswerContent test = ding->setText( querystring );
137 178
179 qDebug( querystring );
180 if ( ding->isCaseSensitive )
181 qDebug( "ist CS");
182 else qDebug( "kein CS" );
183
138 browser_top->setText( test.top ); 184 browser_top->setText( test.top );
139 browser_bottom->setText( test.bottom ); 185 browser_bottom->setText( test.bottom );
140 } 186 }
141} 187}
142 188
143
144void ODict::slotSetErrorcount( int count )
145{
146 errorTol = count;
147}
148
149void ODict::slotSettings() 189void ODict::slotSettings()
150{ 190{
151 ConfigDlg dlg( this, "Config" , true); 191 ConfigDlg dlg( this, "Config" , true);
152 if ( dlg.exec() == QDialog::Accepted ) 192 if ( dlg.exec() == QDialog::Accepted )
153 { 193 saveConfig();
154 dlg.writeEntries();
155 loadConfig();
156 }
157} 194}
158 195
159void ODict::slotSetParameter( int count ) 196void ODict::slotSetParameter( int count )
160{ 197{
161 if ( count == 0 ) 198 if ( count == 0 )
162 { 199 {
@@ -177,26 +214,30 @@ void ODict::slotSetParameter( int count )
177 { 214 {
178 if ( regexp ) 215 if ( regexp )
179 regexp = false; 216 regexp = false;
180 else 217 else
181 regexp = true; 218 regexp = true;
182 } 219 }
183 else qWarning( "ERROR" ); 220 saveConfig();
184} 221}
185 222
186void ODict::slotMethodChanged( const QString& methodnumber ) 223void ODict::slotMethodChanged( const QString& methodnumber )
187{ 224{
188 activated_name = methodnumber; 225 activated_name = methodnumber;
189 226
190 if ( activated_name != ding->loadedDict() ) 227 qDebug( "activated_name in slotMethodChanged() ist:" );
191 ding->loadDict(activated_name); 228 qDebug( activated_name );
192 229
193 top_name->setText( ding->lang1_name ); 230 //X if ( activated_name != ding->loadedDict() )
194 top_name->setAlignment( AlignHCenter ); 231 {
195 bottom_name->setText( ding->lang2_name ); 232 ding->loadDict(activated_name);
196 bottom_name->setAlignment( AlignHCenter ); 233
234 lookupLanguageNames( activated_name );
235 top_name->setText( top_name_content );
236 bottom_name->setText( bottom_name_content );
237 }
197} 238}
198 239
199void ODict::setupMenus() 240void ODict::setupMenus()
200{ 241{
201 menu = new QMenuBar( this ); 242 menu = new QMenuBar( this );
202 243
@@ -209,21 +250,10 @@ void ODict::setupMenus()
209 parameter = new QPopupMenu( menu ); 250 parameter = new QPopupMenu( menu );
210 connect( parameter, SIGNAL( activated( int ) ), this, SLOT( slotSetParameter( int ) ) ); 251 connect( parameter, SIGNAL( activated( int ) ), this, SLOT( slotSetParameter( int ) ) );
211 parameter->insertItem( tr( "C&ase sensitive" ), 0 ,0 ); 252 parameter->insertItem( tr( "C&ase sensitive" ), 0 ,0 );
212 parameter->insertItem( tr( "Only &complete Words" ), 1 , 1) ; 253 parameter->insertItem( tr( "Only &complete Words" ), 1 , 1) ;
213 parameter->insertItem( tr( "Allow &reg. expressions" ), 2 ); 254 parameter->insertItem( tr( "Allow &reg. expressions" ), 2 );
214 parameter->insertSeparator(); 255 parameter->insertSeparator();
215 error_tol_menu = new QPopupMenu( menu );
216 error_tol_menu->setCheckable( TRUE );
217 connect( error_tol_menu, SIGNAL( activated( int ) ), this, SLOT( slotSetErrorcount( int ) ) );
218
219 error_tol_menu->insertItem( tr( "0 Errors" ), 0 );
220 error_tol_menu->insertItem( tr( "1 Errors" ), 1 );
221 error_tol_menu->insertItem( tr( "2 Errors" ), 2 );
222 error_tol_menu->insertItem( tr( "3 Errors" ), 3 );
223 error_tol_menu->insertItem( tr( "4 Errors" ), 4 );
224 error_tol_menu->insertItem( tr( "Until Hit" ), 5 );
225 parameter->insertItem( tr( "&Error tolerance" ), error_tol_menu );
226 256
227 menu->insertItem( tr( "Settings" ) , settings ); 257 menu->insertItem( tr( "Settings" ) , settings );
228 menu->insertItem( tr( "Parameter" ) , parameter ); 258 menu->insertItem( tr( "Parameter" ) , parameter );
229} 259}