summaryrefslogtreecommitdiffstats
path: root/krecipes/src/setupwizard.cpp
blob: ec179d58ec13adcc1627013d35b1b630143f46b0 (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
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
/***************************************************************************
*   Copyright (C) 2003-2004 by                                            *
*   Unai Garro (ugarro@users.sourceforge.net)                             *
*   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.                                   *
***************************************************************************/

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

#include <unistd.h>
#include <pwd.h>

#include <ntqhbox.h>
#include <ntqvgroupbox.h>
#include <ntqlayout.h>
#include <ntqpixmap.h>
#include <ntqpushbutton.h>
#include <ntqtooltip.h>

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

#include "setupwizard.h"

SetupWizard::SetupWizard( TQWidget *parent, const char *name, bool modal, WFlags f ) : KWizard( parent, name, modal, f )
{
	welcomePage = new WelcomePage( this );
	addPage( welcomePage, i18n( "Welcome to Krecipes" ) );

	dbTypeSetupPage = new DBTypeSetupPage( this );
	addPage( dbTypeSetupPage, i18n( "Database Type" ) );

	sqliteSetupPage = new SQLiteSetupPage( this );
	addPage( sqliteSetupPage, i18n( "Server Settings" ) );

	permissionsSetupPage = new PermissionsSetupPage( this );
	addPage( permissionsSetupPage, i18n( "Database Permissions" ) );

	pSqlPermissionsSetupPage = new PSqlPermissionsSetupPage( this );
	addPage( pSqlPermissionsSetupPage, i18n( "Database Permissions" ) );

	serverSetupPage = new ServerSetupPage( this );
	addPage( serverSetupPage, i18n( "Server Settings" ) );

	dataInitializePage = new DataInitializePage( this );
	addPage( dataInitializePage, i18n( "Initialize Database" ) );

	savePage = new SavePage( this );
	addPage( savePage, i18n( "Finish & Save Settings" ) );

	setFinishEnabled( savePage, true ); // Enable finish button
	setSizePolicy( TQSizePolicy::MinimumExpanding, TQSizePolicy::MinimumExpanding );

	#if (!(HAVE_SQLITE || HAVE_SQLITE3))
		#if (HAVE_MYSQL)
			showPages( MySQL );
		#else
		#if (HAVE_POSTGRESQL)
			showPages( PostgreSQL );
		#endif
		#endif
	#else
		showPages( SQLite );
	#endif

	connect( finishButton(), SIGNAL( clicked() ), this, SLOT( save() ) );
	connect( dbTypeSetupPage, SIGNAL( showPages( DBType ) ), this, SLOT( showPages( DBType ) ) );

}


SetupWizard::~SetupWizard()
{
}


void SetupWizard::showPages( DBType type )
{
	switch ( type ) {
	case MySQL:
		setAppropriate( serverSetupPage, true );
		setAppropriate( permissionsSetupPage, true );
		setAppropriate( pSqlPermissionsSetupPage, false );
		setAppropriate( sqliteSetupPage, false );
		break;
	case PostgreSQL:
		setAppropriate( serverSetupPage, true );
		setAppropriate( pSqlPermissionsSetupPage, true );
		setAppropriate( permissionsSetupPage, false );
		setAppropriate( sqliteSetupPage, false );
		break;
	case SQLite:
		setAppropriate( serverSetupPage, false );
		setAppropriate( permissionsSetupPage, false );
		setAppropriate( pSqlPermissionsSetupPage, false );
		setAppropriate( sqliteSetupPage, true );
		break;
	}
}


WelcomePage::WelcomePage( TQWidget *parent ) : TQWidget( parent )
{
	TQGridLayout * layout = new TQGridLayout( this, 1, 1, 0, 0 );
	TQSpacerItem *spacer_top = new TQSpacerItem( 10, 10, TQSizePolicy::Minimum, TQSizePolicy::Fixed );
	layout->addItem( spacer_top, 0, 1 );
	TQSpacerItem *spacer_left = new TQSpacerItem( 10, 10, TQSizePolicy::Fixed, TQSizePolicy::Minimum );
	layout->addItem( spacer_left, 1, 0 );
	TQPixmap logoPixmap ( locate( "data", "krecipes/pics/wizard.png" ) );
	logo = new TQLabel( this );
	logo->setPixmap( logoPixmap );
	logo->setSizePolicy( TQSizePolicy::Fixed, TQSizePolicy::Fixed );
	layout->addWidget( logo, 1, 1, TQt::AlignTop );

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

	welcomeText = new TQLabel( this );
	welcomeText->setText( i18n( "<b><font size=\"+1\">Thank you very much for choosing Krecipes.</font></b><br>It looks like this is the first time you are using it. This wizard will help you with the initial setup so that you can start using it quickly.<br><br>Welcome, and enjoy cooking!" ) );
	welcomeText->setMinimumWidth( 200 );
	welcomeText->setMaximumWidth( 10000 );
	welcomeText->setSizePolicy( TQSizePolicy::MinimumExpanding, TQSizePolicy::Minimum );
	welcomeText->setAlignment( int( TQLabel::WordBreak | TQLabel::AlignTop ) );
	layout->addWidget( welcomeText, 1, 3 );

}

PermissionsSetupPage::PermissionsSetupPage( TQWidget *parent ) : TQWidget( parent )
{
	TQGridLayout * layout = new TQGridLayout( this, 1, 1, 0, 0 );
	TQSpacerItem *spacer_top = new TQSpacerItem( 10, 10, TQSizePolicy::Minimum, TQSizePolicy::Fixed );
	layout->addItem( spacer_top, 0, 1 );
	TQSpacerItem *spacer_left = new TQSpacerItem( 10, 10, TQSizePolicy::Fixed, TQSizePolicy::Minimum );
	layout->addItem( spacer_left, 1, 0 );


	// Logo
	TQPixmap permissionsSetupPixmap ( locate( "data", "krecipes/pics/dbpermissions.png" ) );
	logo = new TQLabel( this );
	logo->setPixmap( permissionsSetupPixmap );
	logo->setSizePolicy( TQSizePolicy::Fixed, TQSizePolicy::Fixed );
	layout->addMultiCellWidget( logo, 1, 8, 1, 1, TQt::AlignTop );

	// Spacer to separate the logo
	TQSpacerItem *logoSpacer = new TQSpacerItem( 10, 10, TQSizePolicy::Fixed, TQSizePolicy::Minimum );
	layout->addItem( logoSpacer, 1, 2 );


	// Explanation Text
	permissionsText = new TQLabel( this );
	permissionsText->setText( i18n( "This dialog will allow you to specify a MySQL account that has the necessary permissions to access the Krecipes MySQL database.<br><br><b><font size=\"+1\">Most users that use Krecipes and MySQL for the first time can just leave the default parameters and press \'Next\'.</font></b> <br><br>If you set a MySQL root password before, or you have already permissions as normal user, click on the appropriate option. Otherwise the account 'root' will be used, with no password.<br><br>[For security reasons, we strongly encourage you to setup a MySQL root password if you have not done so yet. Just type as root: mysqladmin password <i>your_password</i>]" ) );

	permissionsText->setSizePolicy( TQSizePolicy::MinimumExpanding, TQSizePolicy::Minimum );
	permissionsText->setAlignment( int( TQLabel::WordBreak | TQLabel::AlignTop ) );
	layout->addWidget( permissionsText, 1, 3 );

	// Text spacer
	TQSpacerItem *textSpacer = new TQSpacerItem( 10, 30, TQSizePolicy::Minimum, TQSizePolicy::Fixed );
	layout->addItem( textSpacer, 2, 3 );


	// "The user already has permissions" checkbox
	noSetupCheckBox = new TQCheckBox( i18n( "I have already set the necessary permissions" ), this, "noSetupCheckBox" );
	layout->addWidget( noSetupCheckBox, 3, 3 );

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

	// root checkbox
	rootCheckBox = new TQCheckBox( i18n( "I have already set a MySQL root/admin account" ), this, "rootCheckBox" );
	layout->addWidget( rootCheckBox, 5, 3 );

	TQSpacerItem *rootInfoSpacer = new TQSpacerItem( 10, 20, TQSizePolicy::Minimum, TQSizePolicy::Fixed );
	layout->addItem( rootInfoSpacer, 6, 3 );

	// MySQL root/admin info
	TQGroupBox *rootInfoGBox = new TQGroupBox( this, "rootInfoGBox" );
	rootInfoGBox->setTitle( i18n( "MySQL Administrator Account" ) );
	rootInfoGBox->setEnabled( false ); // Disable by default
	rootInfoGBox->setColumns( 2 );
	rootInfoGBox->setInsideSpacing( 10 );
	layout->addWidget( rootInfoGBox, 7, 3 );

	// User Entry
	TQLabel *userLabel = new TQLabel( rootInfoGBox );
	userLabel->setText( i18n( "Username:" ) );
	userEdit = new KLineEdit( rootInfoGBox );
	userEdit->setText( "root" );

	// Password Entry
	TQLabel *passLabel = new TQLabel( rootInfoGBox );
	passLabel->setText( i18n( "Password:" ) );
	passEdit = new KLineEdit( rootInfoGBox );
	passEdit->setEchoMode( TQLineEdit::Password );

	// Bottom spacer
	TQSpacerItem *bottomSpacer = new TQSpacerItem( 10, 20, TQSizePolicy::Minimum, TQSizePolicy::MinimumExpanding );
	layout->addItem( bottomSpacer, 8, 1 );

	// Connect Signals & slots

	connect( rootCheckBox, SIGNAL( toggled( bool ) ), rootInfoGBox, SLOT( setEnabled( bool ) ) );
	connect( rootCheckBox, SIGNAL( toggled( bool ) ), this, SLOT( rootCheckBoxChanged( bool ) ) );
	connect( noSetupCheckBox, SIGNAL( toggled( bool ) ), this, SLOT( noSetupCheckBoxChanged( bool ) ) );
}

void PermissionsSetupPage::rootCheckBoxChanged( bool on )
{
	if ( on )
		noSetupCheckBox->setChecked( false ); // exclude mutually the options (both can be unset)
}

bool PermissionsSetupPage::doUserSetup()
{
	return ( !noSetupCheckBox->isChecked() );
}

bool PermissionsSetupPage::useAdmin()
{
	return ( rootCheckBox->isChecked() );
}

void PermissionsSetupPage::getAdmin( TQString &adminName, TQString &adminPass )
{
	adminName = userEdit->text();
	adminPass = passEdit->text();
}

void PermissionsSetupPage::noSetupCheckBoxChanged( bool on )
{
	if ( on )
		rootCheckBox->setChecked( false ); // exclude mutually the options (both can be unset)
}


PSqlPermissionsSetupPage::PSqlPermissionsSetupPage( TQWidget *parent ) : TQWidget( parent )
{
	TQGridLayout * layout = new TQGridLayout( this, 1, 1, 0, 0 );
	TQSpacerItem *spacer_top = new TQSpacerItem( 10, 10, TQSizePolicy::Minimum, TQSizePolicy::Fixed );
	layout->addItem( spacer_top, 0, 1 );
	TQSpacerItem *spacer_left = new TQSpacerItem( 10, 10, TQSizePolicy::Fixed, TQSizePolicy::Minimum );
	layout->addItem( spacer_left, 1, 0 );


	// Logo
	TQPixmap permissionsSetupPixmap ( locate( "data", "krecipes/pics/dbpermissions.png" ) );
	logo = new TQLabel( this );
	logo->setPixmap( permissionsSetupPixmap );
	logo->setSizePolicy( TQSizePolicy::Fixed, TQSizePolicy::Fixed );
	layout->addMultiCellWidget( logo, 1, 8, 1, 1, TQt::AlignTop );

	// Spacer to separate the logo
	TQSpacerItem *logoSpacer = new TQSpacerItem( 10, 10, TQSizePolicy::Fixed, TQSizePolicy::Minimum );
	layout->addItem( logoSpacer, 1, 2 );


	// Explanation Text
	permissionsText = new TQLabel( this );
	permissionsText->setText( i18n( "This dialog will allow you to specify a PostgreSQL account that has the necessary permissions to access the Krecipes PostgreSQL database.  This account may either be a <b>PostgreSQL superuser</b> or have the ability to both <b>create new PostgreSQL users and databases</b>.<br><br>If no superuser or privileged account is given, the account 'postgres' will be attempted, with no password.  If this is insufficient for your PostgreSQL setup, you <b>must</b> select the appropriate option below to enter the information of a privileged PostgreSQL account." ) );

	permissionsText->setSizePolicy( TQSizePolicy::MinimumExpanding, TQSizePolicy::Minimum );
	permissionsText->setAlignment( int( TQLabel::WordBreak | TQLabel::AlignTop ) );
	layout->addWidget( permissionsText, 1, 3 );

	// Text spacer
	TQSpacerItem *textSpacer = new TQSpacerItem( 10, 30, TQSizePolicy::Minimum, TQSizePolicy::Fixed );
	layout->addItem( textSpacer, 2, 3 );


	// "The user already has permissions" checkbox
	noSetupCheckBox = new TQCheckBox( i18n( "I have already set the necessary permissions" ), this, "noSetupCheckBox" );
	layout->addWidget( noSetupCheckBox, 3, 3 );

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

	// root checkbox
	rootCheckBox = new TQCheckBox( i18n( "I have already set a superuser or privileged account" ), this, "rootCheckBox" );
	layout->addWidget( rootCheckBox, 5, 3 );

	TQSpacerItem *rootInfoSpacer = new TQSpacerItem( 10, 20, TQSizePolicy::Minimum, TQSizePolicy::Fixed );
	layout->addItem( rootInfoSpacer, 6, 3 );

	// MySQL root/admin info
	TQGroupBox *rootInfoGBox = new TQGroupBox( this, "rootInfoGBox" );
	rootInfoGBox->setTitle( i18n( "PostgreSQL Superuser or Privileged Account" ) );
	rootInfoGBox->setEnabled( false ); // Disable by default
	rootInfoGBox->setColumns( 2 );
	rootInfoGBox->setInsideSpacing( 10 );
	layout->addWidget( rootInfoGBox, 7, 3 );

	// User Entry
	TQLabel *userLabel = new TQLabel( rootInfoGBox );
	userLabel->setText( i18n( "Username:" ) );
	userEdit = new KLineEdit( rootInfoGBox );
	userEdit->setText( "postgres" );

	// Password Entry
	TQLabel *passLabel = new TQLabel( rootInfoGBox );
	passLabel->setText( i18n( "Password:" ) );
	passEdit = new KLineEdit( rootInfoGBox );
	passEdit->setEchoMode( TQLineEdit::Password );

	// Bottom spacer
	TQSpacerItem *bottomSpacer = new TQSpacerItem( 10, 20, TQSizePolicy::Minimum, TQSizePolicy::MinimumExpanding );
	layout->addItem( bottomSpacer, 8, 1 );

	// Connect Signals & slots

	connect( rootCheckBox, SIGNAL( toggled( bool ) ), rootInfoGBox, SLOT( setEnabled( bool ) ) );
	connect( rootCheckBox, SIGNAL( toggled( bool ) ), this, SLOT( rootCheckBoxChanged( bool ) ) );
	connect( noSetupCheckBox, SIGNAL( toggled( bool ) ), this, SLOT( noSetupCheckBoxChanged( bool ) ) );
}

void PSqlPermissionsSetupPage::rootCheckBoxChanged( bool on )
{
	if ( on )
		noSetupCheckBox->setChecked( false ); // exclude mutually the options (both can be unset)
}

bool PSqlPermissionsSetupPage::doUserSetup()
{
	return ( !noSetupCheckBox->isChecked() );
}

bool PSqlPermissionsSetupPage::useAdmin()
{
	return ( rootCheckBox->isChecked() );
}

void PSqlPermissionsSetupPage::getAdmin( TQString &adminName, TQString &adminPass )
{
	adminName = userEdit->text();
	adminPass = passEdit->text();
}

void PSqlPermissionsSetupPage::noSetupCheckBoxChanged( bool on )
{
	if ( on )
		rootCheckBox->setChecked( false ); // exclude mutually the options (both can be unset)
}


ServerSetupPage::ServerSetupPage( TQWidget *parent ) : TQWidget( parent )
{
	TQGridLayout * layout = new TQGridLayout( this, 1, 1, 0, 0 );
	TQSpacerItem *spacer_top = new TQSpacerItem( 10, 10, TQSizePolicy::Minimum, TQSizePolicy::Fixed );
	layout->addItem( spacer_top, 0, 1 );
	TQSpacerItem *spacer_left = new TQSpacerItem( 10, 10, TQSizePolicy::Fixed, TQSizePolicy::Minimum );
	layout->addItem( spacer_left, 1, 0 );


	// Image

	TQPixmap serverSetupPixmap ( locate( "data", "krecipes/pics/network.png" ) );
	logo = new TQLabel( this );
	logo->setPixmap( serverSetupPixmap );
	logo->setSizePolicy( TQSizePolicy::Fixed, TQSizePolicy::Fixed );
	layout->addMultiCellWidget( logo, 1, 8, 1, 1, TQt::AlignTop );

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


	// Explanation text
	serverSetupText = new TQLabel( this );
	serverSetupText->setText( i18n( "In this dialog you can adjust the database server settings.<br><br><b>Warning: Passwords are stored in plain text and could potentially be compromised.  We recommend that you create a username and password combination solely for use by Krecipes.</b>" ) );
	serverSetupText->setSizePolicy( TQSizePolicy::MinimumExpanding, TQSizePolicy::Minimum );
	serverSetupText->setAlignment( int( TQLabel::AlignTop | TQLabel::WordBreak ) );
	layout->addWidget( serverSetupText, 1, 3 );

	// Text spacer

	TQSpacerItem* textSpacer = new TQSpacerItem( 10, 30, TQSizePolicy::Minimum, TQSizePolicy::Fixed );
	layout->addItem( textSpacer, 2, 3 );

	// Input Boxes

	TQGroupBox *inputGBox = new TQGroupBox( this, "inputGBox" );
	inputGBox->setFrameStyle( TQFrame::NoFrame );
	inputGBox->setInsideSpacing( 10 );
	inputGBox->setColumns( 2 );
	layout->addWidget( inputGBox, 3, 3 );

	// Username Input

	TQLabel* usernameText = new TQLabel( i18n( "Username:" ), inputGBox );
	usernameText->setFixedSize( TQSize( 100, 20 ) );
	usernameText->setSizePolicy( TQSizePolicy::Fixed, TQSizePolicy::Fixed );

	usernameEdit = new KLineEdit( inputGBox );
	usernameEdit->setFixedSize( TQSize( 120, 20 ) );
	usernameEdit->setSizePolicy( TQSizePolicy::Fixed, TQSizePolicy::Fixed );
	// get username
	uid_t userID;
	TQString username;
	struct passwd *user;
	userID = getuid();
	user = getpwuid ( userID );
	username = user->pw_name;

	usernameEdit->setText( username );


	// Password

	TQLabel* passwordText = new TQLabel( i18n( "Password:" ), inputGBox );
	passwordText->setFixedSize( TQSize( 100, 20 ) );
	passwordText->setSizePolicy( TQSizePolicy::Fixed, TQSizePolicy::Fixed );

	passwordEdit = new KLineEdit( inputGBox );
	passwordEdit->setEchoMode( TQLineEdit::Password );
	passwordEdit->setFixedSize( TQSize( 120, 20 ) );
	passwordEdit->setSizePolicy( TQSizePolicy::Fixed, TQSizePolicy::Fixed );

	// DB Name

	TQLabel* dbNameText = new TQLabel( i18n( "Database name:" ), inputGBox );
	dbNameText->setFixedSize( TQSize( 100, 20 ) );
	dbNameText->setSizePolicy( TQSizePolicy::Fixed, TQSizePolicy::Fixed );

	dbNameEdit = new KLineEdit( inputGBox );
	dbNameEdit->setFixedSize( TQSize( 120, 20 ) );
	dbNameEdit->setSizePolicy( TQSizePolicy::Fixed, TQSizePolicy::Fixed );
	dbNameEdit->setText( "Krecipes" );


	// Spacer from box
	TQSpacerItem* spacerFromBox = new TQSpacerItem( 10, 20, TQSizePolicy::Minimum, TQSizePolicy::Fixed );
	layout->addItem( spacerFromBox, 4, 3 );


	// Remote server checkbox

	remoteServerCheckBox = new TQCheckBox( i18n( "The server is remote" ), this, "remoteServerCheckBox" );
	layout->addWidget( remoteServerCheckBox, 5, 3 );

	// Spacer from CheckBox
	TQSpacerItem* spacerFromCheckBox = new TQSpacerItem( 10, 10, TQSizePolicy::Minimum, TQSizePolicy::Fixed );
	layout->addItem( spacerFromCheckBox, 6, 3 );

	// Server & Client Box
	TQGroupBox *serverSettingsGBox = new TQGroupBox( this, "serverSettingsGBox" );
	serverSettingsGBox->setTitle( i18n( "Server / Client Settings" ) );
	serverSettingsGBox->setEnabled( false ); // Disable by default
	serverSettingsGBox->setInsideSpacing( 10 );
	serverSettingsGBox->setColumns( 2 );
	layout->addWidget( serverSettingsGBox, 7, 3 );


	// Server
	( void ) new TQLabel( i18n( "Server:" ), serverSettingsGBox );
	serverEdit = new KLineEdit( serverSettingsGBox );
	serverEdit->setText( "localhost" );

	// Client
	( void ) new TQLabel( i18n( "Client:" ), serverSettingsGBox );
	clientEdit = new KLineEdit( serverSettingsGBox );
	clientEdit->setText( "localhost" );

	// Bottom Spacers

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

	//TQSpacerItem* spacerRight = new TQSpacerItem( 10, 10, TQSizePolicy::MinimumExpanding, TQSizePolicy::Fixed );
	//layout->addItem( spacerRight, 7, 4 );

	// Signals & Slots
	connect( remoteServerCheckBox, SIGNAL( toggled( bool ) ), serverSettingsGBox, SLOT( setEnabled( bool ) ) );

}

TQString ServerSetupPage::server( void )
{
	return ( serverEdit->text() );
}

TQString ServerSetupPage::user( void )
{
	return ( usernameEdit->text() );
}

TQString ServerSetupPage::password( void )
{
	return ( passwordEdit->text() );
}

TQString ServerSetupPage::dbName( void )
{
	return ( dbNameEdit->text() );
}

void ServerSetupPage::getServerInfo( bool &isRemote, TQString &host, TQString &client, TQString &dbName, TQString &user, TQString &pass, int &port )
{
	isRemote = remoteServerCheckBox->isChecked();
	host = serverEdit->text();
	client = clientEdit->text();
	user = usernameEdit->text();
	pass = passwordEdit->text();
	dbName = dbNameEdit->text();
	port = 0;
}

SQLiteSetupPage::SQLiteSetupPage( TQWidget *parent ) : TQWidget( parent )
{
	TQGridLayout * layout = new TQGridLayout( this, 1, 1, 0, 0 );
	TQSpacerItem *spacer_top = new TQSpacerItem( 10, 10, TQSizePolicy::Minimum, TQSizePolicy::Fixed );
	layout->addItem( spacer_top, 0, 1 );
	TQSpacerItem *spacer_left = new TQSpacerItem( 10, 10, TQSizePolicy::Fixed, TQSizePolicy::Minimum );
	layout->addItem( spacer_left, 1, 0 );


	// Image

	TQPixmap serverSetupPixmap ( locate( "data", "krecipes/pics/network.png" ) );
	logo = new TQLabel( this );
	logo->setPixmap( serverSetupPixmap );
	logo->setSizePolicy( TQSizePolicy::Fixed, TQSizePolicy::Fixed );
	layout->addMultiCellWidget( logo, 1, 4, 1, 1, TQt::AlignTop );

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


	// Explanation text
	serverSetupText = new TQLabel( this );
	serverSetupText->setText( i18n( "In this dialog you can adjust SQLite settings." ) );
	serverSetupText->setSizePolicy( TQSizePolicy::MinimumExpanding, TQSizePolicy::Minimum );
	serverSetupText->setAlignment( int( TQLabel::AlignTop | TQLabel::AlignJustify ) );
	layout->addWidget( serverSetupText, 1, 3 );

	// Text spacer

	TQSpacerItem* textSpacer = new TQSpacerItem( 10, 30, TQSizePolicy::Minimum, TQSizePolicy::Fixed );
	layout->addItem( textSpacer, 2, 3 );

	// Input Boxes

	TQHBox *hbox = new TQHBox( this );

	( void ) new TQLabel( i18n( "Database file:" ), hbox );

	fileEdit = new KLineEdit( hbox );
	fileEdit->setText( locateLocal ( "appdata", "krecipes.krecdb" ) );
	hbox->setStretchFactor( fileEdit, 2 );

	TDEIconLoader il;
	TQPushButton *file_select = new TQPushButton( il.loadIcon( "document-open", TDEIcon::NoGroup, 16 ), TQString::null, hbox );
	TQToolTip::add
		( file_select, i18n( "Open file dialog" ) );
	file_select->setFixedWidth( 25 );

	layout->addWidget( hbox, 3, 3 );

	// Bottom Spacers

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

	connect( file_select, SIGNAL( clicked() ), SLOT( selectFile() ) );
}

TQString SQLiteSetupPage::dbFile( void ) const
{
	return ( fileEdit->text() );
}

void SQLiteSetupPage::selectFile()
{
	KFileDialog dialog( TQString::null, "*.*|All Files", this, "dialog", true );
	if ( dialog.exec() == TQDialog::Accepted ) {
		fileEdit->setText( dialog.selectedFile() );
	}
}


SavePage::SavePage( TQWidget *parent ) : TQWidget( parent )
{
	TQGridLayout * layout = new TQGridLayout( this, 1, 1, 0, 0 );
	TQSpacerItem *spacer_top = new TQSpacerItem( 10, 10, TQSizePolicy::Minimum, TQSizePolicy::Fixed );
	layout->addItem( spacer_top, 0, 1 );
	TQSpacerItem *spacer_left = new TQSpacerItem( 10, 10, TQSizePolicy::Fixed, TQSizePolicy::Minimum );
	layout->addItem( spacer_left, 1, 0 );

	TQPixmap logoPixmap ( locate( "data", "krecipes/pics/save.png" ) );
	logo = new TQLabel( this );
	logo->setPixmap( logoPixmap );
	logo->setSizePolicy( TQSizePolicy::Fixed, TQSizePolicy::Fixed );
	layout->addWidget( logo, 1, 1, TQt::AlignTop );

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

	saveText = new TQLabel( this );
	saveText->setText( i18n( "Congratulations; all the necessary configuration setup is done. Press 'Finish' to continue, and enjoy cooking!" ) );
	saveText->setSizePolicy( TQSizePolicy::Minimum, TQSizePolicy::Minimum );

	saveText->setAlignment( int( TQLabel::WordBreak | TQLabel::AlignVCenter ) );
	layout->addWidget( saveText, 1, 3 );


}

void SetupWizard::save( void )
{
	kdDebug() << "Setting parameters in tdeconfig..." << endl;
	TDEConfig *config = kapp->config();

	// Save the database type
	TQString sDBType;

	switch ( dbTypeSetupPage->dbType() ) {
	case MySQL:
		sDBType = "MySQL";
		break;
	case PostgreSQL:
		sDBType = "PostgreSQL";
		break;
	default:
		sDBType = "SQLite";
		break;
	}

	config->setGroup( "DBType" );
	config->writeEntry( "Type", sDBType );
	kdDebug() << "DB type set in tdeconfig was... " << sDBType << endl;
	// Save the server data if needed
	if ( !( dbTypeSetupPage->dbType() == SQLite ) ) {
		config->setGroup( "Server" );
		config->writeEntry( "Host", serverSetupPage->server() );
		config->writeEntry( "Username", serverSetupPage->user() );
		config->writeEntry( "Password", serverSetupPage->password() );
		config->writeEntry( "DBName", serverSetupPage->dbName() );
		kdDebug() << "Finished setting the database parameters for MySQL or PostgreSQL (non SQLite)..." << endl;
	}
	else {
		config->setGroup( "Server" );
		config->writeEntry( "DBFile", sqliteSetupPage->dbFile() );
	}

	// Indicate that settings were already made

	config->setGroup( "Wizard" );
	config->writeEntry( "SystemSetup", true );
	config->writeEntry( "Version", "0.9" );
	kdDebug() << "Setting in tdeconfig the lines to disable wizard startup..." << sDBType << endl;
}

void SetupWizard::getOptions( bool &setupUser, bool &initializeData, bool &doUSDAImport )
{
	setupUser = permissionsSetupPage->doUserSetup() && pSqlPermissionsSetupPage->doUserSetup();
	initializeData = dataInitializePage->doInitialization();
	doUSDAImport = dataInitializePage->doUSDAImport();
}

void SetupWizard::getAdminInfo( bool &enabled, TQString &adminUser, TQString &adminPass, const TQString &dbType )
{
	enabled = permissionsSetupPage->useAdmin() || pSqlPermissionsSetupPage->useAdmin();
	if ( dbType == "MySQL" )
		permissionsSetupPage->getAdmin( adminUser, adminPass );
	else
		pSqlPermissionsSetupPage->getAdmin( adminUser, adminPass );
}

void SetupWizard::getServerInfo( bool &isRemote, TQString &host, TQString &client, TQString &dbName, TQString &user, TQString &pass, int &port )
{
	serverSetupPage->getServerInfo( isRemote, host, client, dbName, user, pass, port );
	if ( dbTypeSetupPage->dbType() == SQLite )
		dbName = sqliteSetupPage->dbFile();
}

DataInitializePage::DataInitializePage( TQWidget *parent ) : TQWidget( parent )
{
	TQGridLayout * layout = new TQGridLayout( this, 1, 1, 0, 0 );
	TQSpacerItem *spacer_top = new TQSpacerItem( 10, 10, TQSizePolicy::Minimum, TQSizePolicy::Fixed );
	layout->addItem( spacer_top, 0, 1 );
	TQSpacerItem *spacer_left = new TQSpacerItem( 10, 10, TQSizePolicy::Fixed, TQSizePolicy::Minimum );
	layout->addItem( spacer_left, 1, 0 );

	// Explanation Text// Widgets
	TQLabel *logo;
	//TQLabel *serverSetupText;
	//KLineEdit *usernameEdit;
	//KLineEdit *passwordEdit;
	//KLineEdit *dbNameEdit;
	initializeText = new TQLabel( this );
	initializeText->setText( i18n( "Krecipes comes with some delicious default recipes and useful data. <br><br>Would you like to initialize your database with those? Note that this will erase all your previous recipes if you have any. " ) );

	initializeText->setSizePolicy( TQSizePolicy::MinimumExpanding, TQSizePolicy::Minimum );
	initializeText->setAlignment( int( TQLabel::WordBreak | TQLabel::AlignTop ) );
	layout->addWidget( initializeText, 1, 3 );

	// Logo
	TQPixmap dataInitializePixmap ( locate( "data", "krecipes/pics/recipes.png" ) );
	logo = new TQLabel( this );
	logo->setPixmap( dataInitializePixmap );
	logo->setSizePolicy( TQSizePolicy::Fixed, TQSizePolicy::Fixed );
	layout->addMultiCellWidget( logo, 1, 8, 1, 1, TQt::AlignTop );

	// Spacer to separate the logo
	TQSpacerItem *logoSpacer = new TQSpacerItem( 10, 10, TQSizePolicy::Fixed, TQSizePolicy::Minimum );
	layout->addItem( logoSpacer, 1, 2 );

	// Initialize data checkbox

	initializeCheckBox = new TQCheckBox( i18n( "Yes please, initialize the database with the examples" ), this, "initializeCheckBox" );
	layout->addWidget( initializeCheckBox, 3, 3 );

	TQSpacerItem *textInfoSpacer = new TQSpacerItem( 0, 50, TQSizePolicy::Minimum, TQSizePolicy::Fixed );
	layout->addItem( textInfoSpacer, 4, 3 );

	USDAImportText = new TQLabel( i18n( "Krecipes can import nutrient data from the USDA's nutrient database for over 400 foods.  A total of 43 food properties are included for each food, such as energy, fat, vitamin C, etc.<br><br>Would you like to import this data now?  Note that this operation is safe to use on an existing database, and no data loss will occur.  This operation may take several minutes." ), this );
	layout->addWidget( USDAImportText, 5, 3 );

	TQSpacerItem *importInfoSpacer = new TQSpacerItem( 0, 50, TQSizePolicy::Minimum, TQSizePolicy::Fixed );
	layout->addItem( importInfoSpacer, 6, 3 );

	USDAImportCheckBox = new TQCheckBox( i18n( "Yes please, load the database with nutrient data for 400+ foods. (Note: English only.)" ), this, "USDAImportCheckBox" );
	layout->addWidget( USDAImportCheckBox, 7, 3 );
}

bool DataInitializePage::doInitialization( void )
{
	return ( initializeCheckBox->isChecked() );
}

bool DataInitializePage::doUSDAImport( void )
{
	return ( USDAImportCheckBox->isChecked() );
}

DBTypeSetupPage::DBTypeSetupPage( TQWidget *parent ) : TQWidget( parent )
{
	TQGridLayout * layout = new TQGridLayout( this, 1, 1, 0, 0 );
	TQSpacerItem *spacer_top = new TQSpacerItem( 10, 10, TQSizePolicy::Minimum, TQSizePolicy::Fixed );
	layout->addItem( spacer_top, 0, 1 );
	TQSpacerItem *spacer_left = new TQSpacerItem( 10, 10, TQSizePolicy::Fixed, TQSizePolicy::Minimum );
	layout->addItem( spacer_left, 1, 0 );


	// Image

	TQPixmap serverSetupPixmap ( locate( "data", "krecipes/pics/network.png" ) );
	logo = new TQLabel( this );
	logo->setPixmap( serverSetupPixmap );
	logo->setSizePolicy( TQSizePolicy::Fixed, TQSizePolicy::Fixed );
	layout->addMultiCellWidget( logo, 1, 4, 1, 1, TQt::AlignTop );

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


	// Explanation text
	dbTypeSetupText = new TQLabel( this );
	dbTypeSetupText->setText( i18n( "Choose the type of database that you want to use. Most users will want to choose a simple local database here. However, you can also use remote servers by means of a MySQL or PostgreSQL database." ) );
	dbTypeSetupText->setSizePolicy( TQSizePolicy::MinimumExpanding, TQSizePolicy::Minimum );
	dbTypeSetupText->setAlignment( int( TQLabel::AlignTop | TQLabel::WordBreak ) );
	layout->addWidget( dbTypeSetupText, 1, 3 );

	// Text spacer

	TQSpacerItem* textSpacer = new TQSpacerItem( 10, 30, TQSizePolicy::Minimum, TQSizePolicy::Fixed );
	layout->addItem( textSpacer, 2, 3 );



	// Database type choice
	bg = new TQVButtonGroup( this );
	layout->addWidget( bg, 3, 3 );

	liteCheckBox = new TQRadioButton( i18n( "Simple Local File (SQLite)" ), bg, "liteCheckBox" );
	mysqlCheckBox = new TQRadioButton( i18n( "Local or Remote MySQL Database" ), bg, "liteCheckBox" );
	psqlCheckBox = new TQRadioButton( i18n( "Local or Remote PostgreSQL Database" ), bg, "psqlCheckBox" );
	bg->setButton( 0 ); // By default, SQLite

#if (!HAVE_MYSQL)
	mysqlCheckBox->setEnabled( false );
#endif

#if (!HAVE_POSTGRESQL)
	psqlCheckBox->setEnabled( false );
#endif

#if (!(HAVE_SQLITE || HAVE_SQLITE3))
	liteCheckBox->setEnabled( false );
#if (HAVE_MYSQL)

	bg->setButton( 1 ); // Otherwise by default liteCheckBox is checked even if it's disabled
#else
	#if (HAVE_POSTGRESQL)

	bg->setButton( 2 );
#endif
	#endif
#endif


	TQSpacerItem *spacer_bottom = new TQSpacerItem( 10, 10, TQSizePolicy::Fixed, TQSizePolicy::MinimumExpanding );
	layout->addItem( spacer_bottom, 4, 3 );

	connect( bg, SIGNAL( clicked( int ) ), this, SLOT( setPages( int ) ) );

}

int DBTypeSetupPage::dbType( void )
{
	//int id=bg->selectedId(); //QT 3.2
	int id = bg->id( bg->selected() ); //QT 3.1

	switch ( id ) {
	case 1:
		return ( MySQL ); // MySQL (note index=0,1....)
	case 2:
		return ( PostgreSQL );
	default:
		return ( SQLite );
	}
}

/*
** hides/shows pages given the radio button state
*/

void DBTypeSetupPage::setPages( int rb )
{
	switch ( rb ) {
	case 1:
		emit showPages( MySQL );
		break;
	case 2:
		emit showPages( PostgreSQL );
		break;
	default:
		emit showPages( SQLite );
		break;
	}
}

#include "setupwizard.moc"