summaryrefslogtreecommitdiffstats
path: root/krecipes/src/pref.cpp
blob: 9776fd9d85948be8e4163724b65ad7c46ff178ad (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
/***************************************************************************
*   Copyright (C) 2003 by                                                 *
*   Unai Garro (ugarro@users.sourceforge.net)                             *
*   Cyril Bosselut (bosselut@b1project.com)                               *
*   Jason Kivlighn (jkivlighn@gmail.com)                                  *
*                                                                         *
*   Copyright (C) 2004-2006 Jason Kivlighn (jkivlighn@gmail.com)          *
*                                                                         *
*   This program is free software; you can redistribute it and/or modify  *
*   it under the terms of the GNU General Public License as published by  *
*   the Free Software Foundation; either version 2 of the License, or     *
*   (at your option) any later version.                                   *
***************************************************************************/

#include "pref.h"

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include <ntqlayout.h>
#include <ntqlabel.h>
#include <ntqhbox.h>
#include <ntqbuttongroup.h>
#include <ntqcheckbox.h>
#include <ntqradiobutton.h>
#include <ntqpushbutton.h>
#include <ntqtooltip.h>
#include <ntqwhatsthis.h>
#include <ntqframe.h>
#include <ntqcombobox.h>

#include <tdeapplication.h>
#include <tdeconfig.h>
#include <kiconloader.h>
#include <tdelocale.h>
#include <kstandarddirs.h>
#include <tdefiledialog.h>
#include <knuminput.h>
#include <klineedit.h>
#include <kurlrequester.h>
#include <kdebug.h>

KrecipesPreferences::KrecipesPreferences( TQWidget *parent )
		: KDialogBase( IconList, i18n( "Krecipes Preferences" ),
		               Help | Ok | Cancel, Ok, parent )
{
	// this is the base class for your preferences dialog.  it is now
	// a TreeList dialog.. but there are a number of other
	// possibilities (including Tab, Swallow, and just Plain)
	TQFrame * frame;

	TDEConfig *config = TDEGlobal::config();
	config->setGroup( "DBType" );

	TDEIconLoader il;
	frame = addPage( i18n( "Server Settings" ),
	                 TQString( i18n( "Database Server Options (%1)" ) ).arg( config->readEntry( "Type" ) ),
	                 il.loadIcon( "network_local", TDEIcon::NoGroup, 32 ) );
	TQHBoxLayout* layout = new TQHBoxLayout( frame );
	m_pageServer = new ServerPrefs( frame );
	layout->addWidget( m_pageServer );
	m_helpMap.insert(0,"configure-server-settings");

	frame = addPage( i18n( "Formatting" ), i18n( "Customize Formatting" ), il.loadIcon( "math_frac", TDEIcon::NoGroup, 32 ) );
	TQHBoxLayout* formatting_layout = new TQHBoxLayout( frame );
	m_pageNumbers = new NumbersPrefs( frame );
	formatting_layout->addWidget( m_pageNumbers );
	m_helpMap.insert(1,"custom-formatting");

	frame = addPage( i18n( "Import/Export" ), i18n( "Recipe Import and Export Options" ), il.loadIcon( "go-down", TDEIcon::NoGroup, 32 ) );
	TQHBoxLayout* import_layout = new TQHBoxLayout( frame );
	m_pageImport = new ImportPrefs( frame );
	import_layout->addWidget( m_pageImport );
	m_helpMap.insert(2,"import-export-preference");

	frame = addPage( i18n( "Performance" ), i18n( "Performance Options" ), il.loadIcon( "launch", TDEIcon::NoGroup, 32 ) );
	TQHBoxLayout* performance_layout = new TQHBoxLayout( frame );
	m_pagePerformance = new PerformancePrefs( frame );
	performance_layout->addWidget( m_pagePerformance );
	m_helpMap.insert(3,"configure-performance");

	// Signals & Slots
	connect ( this, TQ_SIGNAL( okClicked() ), this, TQ_SLOT( saveSettings() ) );

}

void KrecipesPreferences::slotHelp()
{
	kapp->invokeHelp( m_helpMap[activePageIndex()] );
}


MySQLServerPrefs::MySQLServerPrefs( TQWidget *parent ) : TQWidget( parent )
{
	TQGridLayout * layout = new TQGridLayout( this, 1, 1, 0, 0 );
	layout->setSpacing( KDialog::spacingHint() );
	layout->setMargin( 0 );

	TQSpacerItem* spacerTop = new TQSpacerItem( 10, 10, TQSizePolicy::Minimum, TQSizePolicy::Fixed );
	layout->addItem( spacerTop, 0, 1 );
	TQSpacerItem* spacerLeft = new TQSpacerItem( 10, 10, TQSizePolicy::Fixed, TQSizePolicy::Minimum );
	layout->addItem( spacerLeft, 1, 0 );

	TQLabel* serverText = new TQLabel( i18n( "Server:" ), this );
	serverText->setFixedSize( TQSize( 100, 20 ) );
	serverText->setSizePolicy( TQSizePolicy::Fixed, TQSizePolicy::Fixed );
	layout->addWidget( serverText, 1, 1 );

	serverEdit = new KLineEdit( this );
	serverEdit->setFixedSize( TQSize( 120, 20 ) );
	serverEdit->setSizePolicy( TQSizePolicy::Fixed, TQSizePolicy::Fixed );
	layout->addWidget( serverEdit, 1, 2 );

	TQSpacerItem* spacerRow1 = new TQSpacerItem( 10, 10, TQSizePolicy::Minimum, TQSizePolicy::Fixed );
	layout->addItem( spacerRow1, 2, 1 );

	TQLabel* usernameText = new TQLabel( i18n( "Username:" ), this );
	usernameText->setFixedSize( TQSize( 100, 20 ) );
	usernameText->setSizePolicy( TQSizePolicy::Fixed, TQSizePolicy::Fixed );
	layout->addWidget( usernameText, 3, 1 );

	usernameEdit = new KLineEdit( this );
	usernameEdit->setFixedSize( TQSize( 120, 20 ) );
	usernameEdit->setSizePolicy( TQSizePolicy::Fixed, TQSizePolicy::Fixed );
	layout->addWidget( usernameEdit, 3, 2 );

	TQSpacerItem* spacerRow2 = new TQSpacerItem( 10, 10, TQSizePolicy::Minimum, TQSizePolicy::Fixed );
	layout->addItem( spacerRow2, 4, 1 );

	TQLabel* passwordText = new TQLabel( i18n( "Password:" ), this );
	passwordText->setFixedSize( TQSize( 100, 20 ) );
	passwordText->setSizePolicy( TQSizePolicy::Fixed, TQSizePolicy::Fixed );
	layout->addWidget( passwordText, 5, 1 );

	passwordEdit = new KLineEdit( this );
	passwordEdit->setFixedSize( TQSize( 120, 20 ) );
	passwordEdit->setEchoMode( TQLineEdit::Password );
	passwordEdit->setSizePolicy( TQSizePolicy::Fixed, TQSizePolicy::Fixed );
	layout->addWidget( passwordEdit, 5, 2 );

	TQSpacerItem* spacerRow3 = new TQSpacerItem( 10, 10, TQSizePolicy::Minimum, TQSizePolicy::Fixed );
	layout->addItem( spacerRow3, 6, 1 );

	TQLabel* portText = new TQLabel( i18n( "Port:" ), this );
	portText->setFixedSize( TQSize( 100, 20 ) );
	portText->setSizePolicy( TQSizePolicy::Fixed, TQSizePolicy::Fixed );
	layout->addWidget( portText, 7, 1 );

	portEdit = new KIntNumInput( this );
	portEdit->setMinValue(0);
	portEdit->setSpecialValueText( i18n("Default") );
	portEdit->setFixedSize( TQSize( 120, 20 ) );
	portEdit->setSizePolicy( TQSizePolicy::Fixed, TQSizePolicy::Fixed );
	layout->addWidget( portEdit, 7, 2 );

	TQSpacerItem* spacerRow4 = new TQSpacerItem( 10, 10, TQSizePolicy::Minimum, TQSizePolicy::Fixed );
	layout->addItem( spacerRow4, 8, 1 );

	TQLabel* dbNameText = new TQLabel( i18n( "Database name:" ), this );
	dbNameText->setFixedSize( TQSize( 100, 20 ) );
	dbNameText->setSizePolicy( TQSizePolicy::Fixed, TQSizePolicy::Fixed );
	layout->addWidget( dbNameText, 9, 1 );

	dbNameEdit = new KLineEdit( this );
	dbNameEdit->setFixedSize( TQSize( 120, 20 ) );
	dbNameEdit->setSizePolicy( TQSizePolicy::Fixed, TQSizePolicy::Fixed );
	layout->addWidget( dbNameEdit, 9, 2 );

	TQSpacerItem* spacerRow5 = new TQSpacerItem( 10, 10, TQSizePolicy::Minimum, TQSizePolicy::MinimumExpanding );
	layout->addItem( spacerRow5, 10, 1 );

	// Backup options
	TQGroupBox *backupGBox = new TQGroupBox( this, "backupGBox" );
	backupGBox->setTitle( i18n( "Backup" ) );
	backupGBox->setColumns( 2 );
	layout->addMultiCellWidget( backupGBox, 10, 10, 1, 4 );

	TQLabel *dumpPathLabel = new TQLabel( backupGBox );
	dumpPathLabel->setText( TQString(i18n( "Path to '%1':" )).arg("mysqldump") );
	dumpPathRequester = new KURLRequester( backupGBox );
	dumpPathRequester->setFilter( "mysqldump" );

	TQLabel *mysqlPathLabel = new TQLabel( backupGBox );
	mysqlPathLabel->setText( TQString(i18n( "Path to '%1':" )).arg("mysql") );
	mysqlPathRequester = new KURLRequester( backupGBox );
	mysqlPathRequester->setFilter( "mysql" );


	TQSpacerItem* spacerRow6 = new TQSpacerItem( 10, 10, TQSizePolicy::Minimum, TQSizePolicy::MinimumExpanding );
	layout->addItem( spacerRow6, 11, 1 );
	TQSpacerItem* spacerRight = new TQSpacerItem( 10, 10, TQSizePolicy::MinimumExpanding, TQSizePolicy::Fixed );
	layout->addItem( spacerRight, 1, 4 );

	// Load & Save Current Settings
	TDEConfig *config = kapp->config();
	config->setGroup( "Server" );
	serverEdit->setText( config->readEntry( "Host", "localhost" ) );
	usernameEdit->setText( config->readEntry( "Username", "" ) );
	passwordEdit->setText( config->readEntry( "Password", "" ) );
	portEdit->setValue( config->readNumEntry( "Port", 0 ) );
	dbNameEdit->setText( config->readEntry( "DBName", "Krecipes" ) );
	dumpPathRequester->setURL( config->readEntry( "MySQLDumpPath", "mysqldump" ) );
	mysqlPathRequester->setURL( config->readEntry( "MySQLPath", "mysql" ) );
}

void MySQLServerPrefs::saveOptions( void )
{
	TDEConfig * config = kapp->config();
	config->setGroup( "Server" );
	config->writeEntry( "Host", serverEdit->text() );
	config->writeEntry( "Username", usernameEdit->text() );
	config->writeEntry( "Password", passwordEdit->text() );
	config->writeEntry( "Port", portEdit->value() );
	config->writeEntry( "DBName", dbNameEdit->text() );
	config->writeEntry( "MySQLDumpPath", dumpPathRequester->url() );
	config->writeEntry( "MySQLPath", mysqlPathRequester->url() );
}


PostgreSQLServerPrefs::PostgreSQLServerPrefs( TQWidget *parent ) : TQWidget( parent )
{
	TQGridLayout * layout = new TQGridLayout( this, 1, 1, 0, 0 );
	layout->setSpacing( KDialog::spacingHint() );
	layout->setMargin( 0 );

	TQSpacerItem* spacerTop = new TQSpacerItem( 10, 10, TQSizePolicy::Minimum, TQSizePolicy::Fixed );
	layout->addItem( spacerTop, 0, 1 );
	TQSpacerItem* spacerLeft = new TQSpacerItem( 10, 10, TQSizePolicy::Fixed, TQSizePolicy::Minimum );
	layout->addItem( spacerLeft, 1, 0 );

	TQLabel* serverText = new TQLabel( i18n( "Server:" ), this );
	serverText->setFixedSize( TQSize( 100, 20 ) );
	serverText->setSizePolicy( TQSizePolicy::Fixed, TQSizePolicy::Fixed );
	layout->addWidget( serverText, 1, 1 );

	serverEdit = new KLineEdit( this );
	serverEdit->setFixedSize( TQSize( 120, 20 ) );
	serverEdit->setSizePolicy( TQSizePolicy::Fixed, TQSizePolicy::Fixed );
	layout->addWidget( serverEdit, 1, 2 );

	TQSpacerItem* spacerRow1 = new TQSpacerItem( 10, 10, TQSizePolicy::Minimum, TQSizePolicy::Fixed );
	layout->addItem( spacerRow1, 2, 1 );

	TQLabel* usernameText = new TQLabel( i18n( "Username:" ), this );
	usernameText->setFixedSize( TQSize( 100, 20 ) );
	usernameText->setSizePolicy( TQSizePolicy::Fixed, TQSizePolicy::Fixed );
	layout->addWidget( usernameText, 3, 1 );

	usernameEdit = new KLineEdit( this );
	usernameEdit->setFixedSize( TQSize( 120, 20 ) );
	usernameEdit->setSizePolicy( TQSizePolicy::Fixed, TQSizePolicy::Fixed );
	layout->addWidget( usernameEdit, 3, 2 );

	TQSpacerItem* spacerRow2 = new TQSpacerItem( 10, 10, TQSizePolicy::Minimum, TQSizePolicy::Fixed );
	layout->addItem( spacerRow2, 4, 1 );

	TQLabel* passwordText = new TQLabel( i18n( "Password:" ), this );
	passwordText->setFixedSize( TQSize( 100, 20 ) );
	passwordText->setSizePolicy( TQSizePolicy::Fixed, TQSizePolicy::Fixed );
	layout->addWidget( passwordText, 5, 1 );

	passwordEdit = new KLineEdit( this );
	passwordEdit->setFixedSize( TQSize( 120, 20 ) );
	passwordEdit->setEchoMode( TQLineEdit::Password );
	passwordEdit->setSizePolicy( TQSizePolicy::Fixed, TQSizePolicy::Fixed );
	layout->addWidget( passwordEdit, 5, 2 );

	TQSpacerItem* spacerRow3 = new TQSpacerItem( 10, 10, TQSizePolicy::Minimum, TQSizePolicy::Fixed );
	layout->addItem( spacerRow3, 6, 1 );

	TQLabel* portText = new TQLabel( i18n( "Port:" ), this );
	portText->setFixedSize( TQSize( 100, 20 ) );
	portText->setSizePolicy( TQSizePolicy::Fixed, TQSizePolicy::Fixed );
	layout->addWidget( portText, 7, 1 );

	portEdit = new KIntNumInput( this );
	portEdit->setMinValue(0);
	portEdit->setSpecialValueText( i18n("Default") );
	portEdit->setFixedSize( TQSize( 120, 20 ) );
	portEdit->setSizePolicy( TQSizePolicy::Fixed, TQSizePolicy::Fixed );
	layout->addWidget( portEdit, 7, 2 );

	TQSpacerItem* spacerRow4 = new TQSpacerItem( 10, 10, TQSizePolicy::Minimum, TQSizePolicy::Fixed );
	layout->addItem( spacerRow4, 8, 1 );

	TQLabel* dbNameText = new TQLabel( i18n( "Database name:" ), this );
	dbNameText->setFixedSize( TQSize( 100, 20 ) );
	dbNameText->setSizePolicy( TQSizePolicy::Fixed, TQSizePolicy::Fixed );
	layout->addWidget( dbNameText, 9, 1 );

	dbNameEdit = new KLineEdit( this );
	dbNameEdit->setFixedSize( TQSize( 120, 20 ) );
	dbNameEdit->setSizePolicy( TQSizePolicy::Fixed, TQSizePolicy::Fixed );
	layout->addWidget( dbNameEdit, 9, 2 );

	TQSpacerItem* spacerRow5 = new TQSpacerItem( 10, 10, TQSizePolicy::Minimum, TQSizePolicy::MinimumExpanding );
	layout->addItem( spacerRow5, 10, 1 );

	// Backup options
	TQGroupBox *backupGBox = new TQGroupBox( this, "backupGBox" );
	backupGBox->setTitle( i18n( "Backup" ) );
	backupGBox->setColumns( 2 );
	layout->addMultiCellWidget( backupGBox, 10, 10, 1, 4 );

	TQLabel *dumpPathLabel = new TQLabel( backupGBox );
	dumpPathLabel->setText( TQString(i18n( "Path to '%1':" )).arg("pg_dump") );
	dumpPathRequester = new KURLRequester( backupGBox );
	dumpPathRequester->setFilter( "pg_dump" );

	TQLabel *psqlPathLabel = new TQLabel( backupGBox );
	psqlPathLabel->setText( TQString(i18n( "Path to '%1':" )).arg("psql") );
	psqlPathRequester = new KURLRequester( backupGBox );
	psqlPathRequester->setFilter( "psql" );


	TQSpacerItem* spacerRow6 = new TQSpacerItem( 10, 10, TQSizePolicy::Minimum, TQSizePolicy::MinimumExpanding );
	layout->addItem( spacerRow6, 11, 1 );
	TQSpacerItem* spacerRight = new TQSpacerItem( 10, 10, TQSizePolicy::MinimumExpanding, TQSizePolicy::Fixed );
	layout->addItem( spacerRight, 1, 4 );

	// Load & Save Current Settings
	TDEConfig *config = kapp->config();
	config->setGroup( "Server" );
	serverEdit->setText( config->readEntry( "Host", "localhost" ) );
	usernameEdit->setText( config->readEntry( "Username", "" ) );
	passwordEdit->setText( config->readEntry( "Password", "" ) );
	portEdit->setValue( config->readNumEntry( "Port", 0 ) );
	dbNameEdit->setText( config->readEntry( "DBName", "Krecipes" ) );
	dumpPathRequester->setURL( config->readEntry( "PgDumpPath", "pg_dump" ) );
	psqlPathRequester->setURL( config->readEntry( "PsqlPath", "psql" ) );
}

void PostgreSQLServerPrefs::saveOptions( void )
{
	TDEConfig * config = kapp->config();
	config->setGroup( "Server" );
	config->writeEntry( "Host", serverEdit->text() );
	config->writeEntry( "Username", usernameEdit->text() );
	config->writeEntry( "Password", passwordEdit->text() );
	config->writeEntry( "Port", portEdit->value() );
	config->writeEntry( "DBName", dbNameEdit->text() );
	config->writeEntry( "PgDumpPath", dumpPathRequester->url() );
	config->writeEntry( "PsqlPath", psqlPathRequester->url() );
}



SQLiteServerPrefs::SQLiteServerPrefs( TQWidget *parent ) : TQWidget( parent )
{
	TQVBoxLayout * Form1Layout = new TQVBoxLayout( this );

	TQHBox *hbox = new TQHBox( this );
	( void ) new TQLabel( i18n( "Database file:" ), hbox );

	fileRequester = new KURLRequester( hbox );
	hbox->setStretchFactor( fileRequester, 2 );

	Form1Layout->addWidget( hbox );

	TQSpacerItem* spacerRow5 = new TQSpacerItem( 10, 10, TQSizePolicy::Minimum, TQSizePolicy::MinimumExpanding );
	Form1Layout->addItem( spacerRow5 );

	TQString sqliteBinary;
	#if HAVE_SQLITE3
	sqliteBinary = "sqlite3";
 	#elif HAVE_SQLITE
	sqliteBinary = "sqlite";
	#endif

	// Backup options
	TQGroupBox *backupGBox = new TQGroupBox( this, "backupGBox" );
	backupGBox->setTitle( i18n( "Backup" ) );
	backupGBox->setColumns( 2 );
	Form1Layout->addWidget( backupGBox );

	TQLabel *dumpPathLabel = new TQLabel( backupGBox );
	dumpPathLabel->setText( TQString(i18n( "Path to '%1':" )).arg(sqliteBinary) );
	dumpPathRequester = new KURLRequester( backupGBox );
	dumpPathRequester->setFilter( sqliteBinary );

	// Load & Save Current Settings
	TDEConfig *config = kapp->config();
	config->setGroup( "Server" );
	fileRequester->setURL( config->readEntry( "DBFile", locateLocal( "appdata", "krecipes.krecdb" ) ) );
	dumpPathRequester->setURL( config->readEntry( "SQLitePath", sqliteBinary ) );
}

void SQLiteServerPrefs::saveOptions( void )
{
	TDEConfig * config = kapp->config();
	config->setGroup( "Server" );
	config->writeEntry( "DBFile", fileRequester->url() );
	config->writeEntry( "SQLitePath", dumpPathRequester->url() );
}


// Server Setttings Dialog
ServerPrefs::ServerPrefs( TQWidget *parent )
		: TQWidget( parent )
{
	TQVBoxLayout * Form1Layout = new TQVBoxLayout( this, 11, 6 );

	TDEConfig *config = kapp->config();
	config->setGroup( "DBType" );
	TQString DBtype = config->readEntry( "Type" );
	if ( DBtype == "MySQL" )
		serverWidget = new MySQLServerPrefs( this );
	else if ( DBtype == "PostgreSQL" )
		serverWidget = new PostgreSQLServerPrefs( this );
	else
		serverWidget = new SQLiteServerPrefs( this );

	serverWidget->setSizePolicy( TQSizePolicy::MinimumExpanding, TQSizePolicy::Minimum );
	Form1Layout->addWidget( serverWidget );

	Form1Layout->addItem( new TQSpacerItem( 20, 40, TQSizePolicy::Minimum, TQSizePolicy::Expanding ) );

	wizard_button = new TQCheckBox( i18n( "Re-run wizard on next startup" ), this );
	wizard_button->setSizePolicy( TQSizePolicy::MinimumExpanding, TQSizePolicy::Minimum );
	Form1Layout->addWidget( wizard_button );

	TQLabel *note = new TQLabel( i18n( "Note: Krecipes must be restarted for most server preferences to take effect." ), this );
	Form1Layout->addWidget( note );

	adjustSize();
}


void KrecipesPreferences::saveSettings( void )
{
	m_pageServer->saveOptions();
	m_pageNumbers->saveOptions();
	m_pageImport->saveOptions();
	m_pagePerformance->saveOptions();
}

// Save Server settings
void ServerPrefs::saveOptions( void )
{
	TDEConfig * config = kapp->config();
	config->setGroup( "DBType" );
	TQString DBtype = config->readEntry( "Type" );
	if ( DBtype == "MySQL" )
		( ( MySQLServerPrefs* ) serverWidget ) ->saveOptions();
	else if ( DBtype == "PostgreSQL" )
		( ( PostgreSQLServerPrefs* ) serverWidget ) ->saveOptions();
	else
		( ( SQLiteServerPrefs* ) serverWidget ) ->saveOptions();

	if ( wizard_button->isChecked() ) {
		config->setGroup( "Wizard" );
		config->writeEntry( "SystemSetup", false );
	}
}

//=============Numbers Preferences Dialog================//
NumbersPrefs::NumbersPrefs( TQWidget *parent )
		: TQWidget( parent )
{
	Form1Layout = new TQVBoxLayout( this, 11, 6 );

	numberButtonGroup = new TQButtonGroup( this );
	numberButtonGroup->setColumnLayout( 0, TQt::Vertical );
	numberButtonGroup->layout() ->setSpacing( 6 );
	numberButtonGroup->layout() ->setMargin( 11 );
	numberButtonGroup->resize( TQSize() );
	numberButtonGroupLayout = new TQVBoxLayout( numberButtonGroup->layout() );
	numberButtonGroupLayout->setAlignment( TQt::AlignTop );

	fractionRadioButton = new TQRadioButton( numberButtonGroup );
	numberButtonGroupLayout->addWidget( fractionRadioButton );

	decimalRadioButton = new TQRadioButton( numberButtonGroup );
	numberButtonGroupLayout->addWidget( decimalRadioButton );
	Form1Layout->addWidget( numberButtonGroup );

	numberButtonGroup->insert( decimalRadioButton, 0 );
	numberButtonGroup->insert( fractionRadioButton, 1 );

	//ingredient display format
	TQGroupBox *ingredientGrpBox = new TQGroupBox( 2, TQt::Vertical, i18n( "Ingredients" ), this );

	TQHBox *ingredientBox = new TQHBox( ingredientGrpBox );
	( void ) new TQLabel( i18n( "Ingredient Format:" ), ingredientBox );
	ingredientEdit = new KLineEdit( ingredientBox );
	( void ) new TQLabel( i18n( "%n: Name<br>"
	                           "%p: Preparation method<br>"
	                           "%a: Amount<br>"
	                           "%u: Unit"
	                         ), ingredientGrpBox );

	Form1Layout->addWidget( ingredientGrpBox );

	//unit display format
	TQGroupBox *abbrevGrpBox = new TQGroupBox( 1, TQt::Vertical, i18n( "Units" ), this );
	TQHBox *abbrevBox = new TQHBox( abbrevGrpBox );
	abbrevButton = new TQCheckBox( i18n( "Use abbreviations" ), abbrevBox );
	Form1Layout->addWidget( abbrevGrpBox );


	Form1Layout->addItem( new TQSpacerItem( 20, 40, TQSizePolicy::Minimum, TQSizePolicy::Expanding ) );

	adjustSize();

	languageChange();

	// Load Current Settings
	TDEConfig *config = kapp->config();
	config->setGroup( "Formatting" );

	int button = ( config->readBoolEntry( "Fraction", false ) ) ? 1 : 0;
	numberButtonGroup->setButton( button );

	ingredientEdit->setText( config->readEntry( "Ingredient", "%n%p: %a %u" ) );

	abbrevButton->setChecked( config->readBoolEntry( "AbbreviateUnits", false ) );
}

void NumbersPrefs::saveOptions()
{
	TDEConfig * config = kapp->config();
	config->setGroup( "Formatting" );

	bool fraction = !numberButtonGroup->find( 0 ) ->isOn();
	config->writeEntry( "Fraction", fraction );

	config->writeEntry( "Ingredient", ingredientEdit->text() );

	config->writeEntry( "AbbreviateUnits", abbrevButton->isChecked() );
}

void NumbersPrefs::languageChange()
{
	numberButtonGroup->setTitle( i18n( "Number Format" ) );
	fractionRadioButton->setText( i18n( "Fraction" ) );
	decimalRadioButton->setText( i18n( "Decimal" ) );
}

//=============Import/Export Preferences Dialog================//
ImportPrefs::ImportPrefs( TQWidget *parent )
		: TQWidget( parent )
{
	// Load Current Settings
	TDEConfig * config = kapp->config();
	config->setGroup( "Import" );

	bool overwrite = config->readBoolEntry( "OverwriteExisting", false );
	bool direct = config->readBoolEntry( "DirectImport", false );

	Form1Layout = new TQVBoxLayout( this, 11, 6 );

	TQGroupBox *importGroup = new TQGroupBox(2,TQt::Vertical,i18n("Import"), this);

	overwriteCheckbox = new TQCheckBox( i18n( "Overwrite recipes with same title" ), importGroup );
	overwriteCheckbox->setChecked( overwrite );
	overwriteCheckbox->setSizePolicy( TQSizePolicy::MinimumExpanding, TQSizePolicy::Minimum );

	directImportCheckbox = new TQCheckBox( i18n( "Ask which recipes to import" ), importGroup );
	directImportCheckbox->setChecked( !direct );
	directImportCheckbox->setSizePolicy( TQSizePolicy::MinimumExpanding, TQSizePolicy::Minimum );

	Form1Layout->addWidget(importGroup);

	TQGroupBox *exportGroup = new TQGroupBox(1,TQt::Vertical,i18n("Export"), this);

	TQHBox *clipboardHBox = new TQHBox(exportGroup);
	clipboardHBox->setSpacing(6);
	TQLabel *clipboardLabel = new TQLabel(i18n("'Copy to Clipboard' format:"),clipboardHBox);
	clipBoardFormatComboBox = new TQComboBox( clipboardHBox );
	clipBoardFormatComboBox->insertItem(TQString("%3 (*.txt)").arg(i18n("Plain Text")));
	clipBoardFormatComboBox->insertItem("Krecipes (*.kreml)");
	clipBoardFormatComboBox->insertItem("Meal-Master (*.mmf)");
	clipBoardFormatComboBox->insertItem("Rezkonv (*.rk)");
	clipBoardFormatComboBox->insertItem("RecipeML (*.xml)");
	//clipBoardFormatComboBox->insertItem("CookML (*.cml)");
	clipboardHBox->setStretchFactor(clipBoardFormatComboBox,1);

	config->setGroup( "Export" );
	TQString clipboardFormat = config->readEntry("ClipboardFormat");
	if ( clipboardFormat == "*.kreml" )
		clipBoardFormatComboBox->setCurrentItem(1);
	else if ( clipboardFormat == "*.mmf" )
		clipBoardFormatComboBox->setCurrentItem(2);
	else if ( clipboardFormat == "*.xml" )
		clipBoardFormatComboBox->setCurrentItem(3);
	else
		clipBoardFormatComboBox->setCurrentItem(0);

	Form1Layout->addWidget(exportGroup);

	Form1Layout->addItem( new TQSpacerItem( 20, 40, TQSizePolicy::Minimum, TQSizePolicy::Expanding ) );

	TQWhatsThis::add( directImportCheckbox, 
		i18n("When this is enabled, the importer will show every recipe in the file(s) and allow you to select which recipes you want imported.\n \
							\
		Disable this to always import every recipe, which allows for faster and less memory-intensive imports.")
	);

	adjustSize();
}

void ImportPrefs::saveOptions()
{
	TDEConfig * config = kapp->config();
	config->setGroup( "Import" );

	config->writeEntry( "OverwriteExisting", overwriteCheckbox->isChecked() );
	config->writeEntry( "DirectImport", !directImportCheckbox->isChecked() );

	config->setGroup( "Export" );
	TQString ext = clipBoardFormatComboBox->currentText().mid(clipBoardFormatComboBox->currentText().find("(")+1,clipBoardFormatComboBox->currentText().length()-clipBoardFormatComboBox->currentText().find("(")-2);
	config->writeEntry( "ClipboardFormat", ext );
}


//=============Performance Options Dialog================//
PerformancePrefs::PerformancePrefs( TQWidget *parent )
		: TQWidget( parent )
{
	// Load Current Settings
	TDEConfig * config = kapp->config();
	config->setGroup( "Performance" );

	int cat_limit = config->readNumEntry( "CategoryLimit", -1 );
	int limit = config->readNumEntry( "Limit", -1 );

	Form1Layout = new TQVBoxLayout( this, 11, 6 );

	searchAsYouTypeBox = new TQCheckBox( i18n( "Search as you type" ), this );
	searchAsYouTypeBox->setChecked( config->readBoolEntry( "SearchAsYouType", true ) );

	TQLabel *explainationLabel = new TQLabel( i18n("In most instances these options do not need to be changed.  However, limiting the amount of items displayed at once will <b>allow Krecipes to better perform when the database is loaded with many thousands of recipes</b>."), this );
	explainationLabel->setTextFormat( TQt::RichText );

	TQHBox *catLimitHBox = new TQHBox( this );
	catLimitInput = new KIntNumInput(catLimitHBox);
	catLimitInput->setLabel( i18n( "Number of categories to display at once:" ) );
	catLimitInput->setRange(0,5000,20,true);
	catLimitInput->setSpecialValueText( i18n("Unlimited") );

	if ( cat_limit > 0 )
		catLimitInput->setValue( cat_limit );

	TQHBox *limitHBox = new TQHBox( this );
	limitInput = new KIntNumInput(limitHBox);
	limitInput->setLabel( i18n( "Number of elements to display at once:" ) );
	limitInput->setRange(0,100000,1000,true);
	limitInput->setSpecialValueText( i18n("Unlimited") );

	if ( limit > 0 )
		limitInput->setValue( limit );

	Form1Layout->addWidget( searchAsYouTypeBox );
	Form1Layout->addWidget( explainationLabel );
	Form1Layout->addWidget( catLimitHBox );
	Form1Layout->addWidget( limitHBox );

	Form1Layout->addItem( new TQSpacerItem( 20, 40, TQSizePolicy::Minimum, TQSizePolicy::Expanding ) );

	adjustSize();
}

void PerformancePrefs::saveOptions()
{
	TDEConfig * config = kapp->config();
	config->setGroup( "Performance" );

	int catLimit = ( catLimitInput->value() == 0 ) ? -1 : catLimitInput->value();
	config->writeEntry( "CategoryLimit", catLimit );

	int limit = ( limitInput->value() == 0 ) ? -1 : limitInput->value();
	config->writeEntry( "Limit", limit );

	config->writeEntry( "SearchAsYouType", searchAsYouTypeBox->isChecked() );
}

#include "pref.moc"