summaryrefslogtreecommitdiffstats
path: root/kbarcode/confwizard.cpp
blob: 2d7631c5214d5998269e1ab02b9363aa5e79ef2b (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
/***************************************************************************
                          confwizard.cpp  -  description
                             -------------------
    begin                : Son Jun 16 2002
    copyright            : (C) 2002 by Dominik Seichter
    email                : domseichter@web.de
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   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 "confwizard.h"
#include "sqltables.h"
#include "printersettings.h"
#include "dsmainwindow.h"

// TQt includes
#include <tqbuttongroup.h>
#include <tqcheckbox.h>
#include <tqcursor.h>
#include <tqlayout.h>
#include <tqsqldatabase.h>
#include <tqradiobutton.h>
#include <tqprinter.h>
#include <tqtextbrowser.h>

// KDE includes
#include <tdeapplication.h>
#include <kcombobox.h>
#include <klineedit.h>
#include <tdelocale.h>
#include <tdemessagebox.h>
#include <kpushbutton.h>
#include <kurllabel.h>
#include <kstandarddirs.h>


const char* description = I18N_NOOP(
        "KBarcode is a barcode and label printing application for TDE. It can "
        "be used to print every thing from simple business cards up to complex "
        "labels with several barcodes (e.g. article descriptions). KBarcode "
        "comes with an easy to use WYSIWYG label designer, a setup wizard, "
        "batch import of labels (directly from the delivery note), thousands "
        "of predefined labels, database management tools and translations "
        "in many languages. Even printing more than 10.000 labels in one go is "
        "no problem for KBarcode. Additionally it is a simply xbarcode "
        "replacement for the creation of barcodes. All major types of barcodes "
        "like EAN, UPC, CODE39 and ISBN are supported." );

ConfWizard::ConfWizard( TQWidget* parent,  const char* name, bool modal )
    : KWizard( parent, name, modal )
{
    setCaption( i18n( "Configure KBarcode" ) );

    setupPage1();
    setupPage0();
    setupPage2();
    setupPage3();

    setNextEnabled( page_2, false );
    helpButton()->hide();
    
    connect( buttonCreate, TQ_SIGNAL( clicked() ), this, TQ_SLOT( create() ) );
    connect( buttonExample, TQ_SIGNAL( clicked() ), this, TQ_SLOT( example() ) );
    connect( checkDatabase, TQ_SIGNAL( clicked() ), this, TQ_SLOT( useDatabase() ) );
}

ConfWizard::~ConfWizard()
{ }

void ConfWizard::accept()
{
    sqlwidget->save( checkDatabase->isChecked() );

    KWizard::accept();
}

void ConfWizard::setupPage1()
{
    page = new TQWidget( this, "page" );
    pageLayout = new TQVBoxLayout( page, 11, 6, "pageLayout");

    Layout8 = new TQHBoxLayout( 0, 0, 6, "Layout8");

    Layout7 = new TQVBoxLayout( 0, 0, 6, "Layout7");

    logo = new TQLabel( page, "logo" );
    logo->setPixmap( locate("data", "kbarcode/logo.png") );
    TQSpacerItem* spacer = new TQSpacerItem( 0, 0, TQSizePolicy::Minimum, TQSizePolicy::Expanding );
    pageLayout->addWidget( logo );
    Layout7->addItem( spacer );
    Layout8->addLayout( Layout7 );

    TextLabel2_2 = new TQLabel( page, "TextLabel2_2" );
    TextLabel2_2->setText( i18n( "<qt><h1>Welcome to KBarcode</h1><br><br>") +
        i18n( description ) + "</qt>" );
    Layout8->addWidget( TextLabel2_2 );

    pageLayout->addLayout( Layout8 );

    KURLLabel1 = new KURLLabel( page, "KURLLabel1" );
    KURLLabel1->setText( "http://www.trinitydesktop.org" );
    KURLLabel1->setURL("http://www.trinitydesktop.org");
    pageLayout->addWidget( KURLLabel1 );
    addPage( page, i18n( "Welcome" ) );
}

void ConfWizard::setupPage0()
{
    TQWidget* page_0 = new TQWidget( this, "page_0" );
    TQVBoxLayout* pageLayout = new TQVBoxLayout( page_0, 11, 6, "pageLayout");

    TQTextBrowser* b = new TQTextBrowser( page_0, "b" );
    b->setText( DSMainWindow::systemCheck() );

    pageLayout->addWidget( b );
    
    addPage( page_0, i18n("System Check") );
}

void ConfWizard::setupPage2()
{
    page_2 = new TQWidget( this, "page_2" );
    pageLayout_2 = new TQVBoxLayout( page_2, 11, 6, "pageLayout_2");

    checkDatabase = new TQCheckBox( page_2 );
    checkDatabase->setText( i18n("&Use database with KBarcode") );
    checkDatabase->setChecked( true );

    sqlwidget = new SqlWidget( true, page_2, "sqlwidget" );
    connect( sqlwidget, TQ_SIGNAL( databaseWorking( bool ) ), this, TQ_SLOT( testSettings( bool ) ) );
        
    TQSpacerItem* spacer_5 = new TQSpacerItem( 0, 0, TQSizePolicy::Minimum, TQSizePolicy::Expanding );
    pageLayout_2->addWidget( checkDatabase );
    pageLayout_2->addWidget( sqlwidget );
    pageLayout_2->addItem( spacer_5 );

    addPage( page_2, i18n( "Database" ) );
}

void ConfWizard::setupPage3()
{
    page_3 = new TQWidget( this, "page_3" );
    pageLayout_3 = new TQVBoxLayout( page_3, 11, 6, "pageLayout_3");

    TextLabel1_2 = new TQLabel( page_3, "TextLabel1_2" );
    TextLabel1_2->setText( i18n( "KBarcode can create the required SQL tables for you.<br>KBarcode will add also some Label Definitions to the tables.<br>After that you can fill the tables with some example data." ) );
    TextLabel1_2->setAlignment( int( TQLabel::WordBreak | TQLabel::AlignVCenter ) );
    pageLayout_3->addWidget( TextLabel1_2 );

    Layout5_2 = new TQVBoxLayout( 0, 0, 6, "Layout5_2");

    buttonCreate = new KPushButton( page_3, "buttonCreate" );
    buttonCreate->setText( i18n( "&Create Tables" ) );
    Layout5_2->addWidget( buttonCreate );

    buttonExample = new KPushButton( page_3, "buttonExample" );
    buttonExample->setEnabled( FALSE );
    buttonExample->setText( i18n( "&Add Example Data" ) );
    Layout5_2->addWidget( buttonExample );
    TQSpacerItem* spacer_6 = new TQSpacerItem( 0, 0, TQSizePolicy::Minimum, TQSizePolicy::Expanding );
    Layout5_2->addItem( spacer_6 );
    pageLayout_3->addLayout( Layout5_2 );
    addPage( page_3, i18n( "Create Tables" ) );
}

void ConfWizard::testSettings( bool b )
{
    setNextEnabled( page_2, b );
}

void ConfWizard::create()
{
    TDEApplication::setOverrideCursor( TQt::WaitCursor );
    if(!SqlTables::getInstance()->newTables( sqlwidget->username(), sqlwidget->password(), sqlwidget->hostname(), sqlwidget->database(), sqlwidget->driver() ) )
    {
        TDEApplication::restoreOverrideCursor();
        return;
    }
    else
        TDEApplication::restoreOverrideCursor();

    TQSqlDatabase* db = TQSqlDatabase::addDatabase( sqlwidget->driver() );
    db->setDatabaseName( sqlwidget->database() );
    db->setUserName( sqlwidget->username() );
    db->setPassword( sqlwidget->password() );
    db->setHostName( sqlwidget->hostname() );

    if( !db->open() )
        KMessageBox::error( this, i18n("<qt>Connection failed:<br>") + sqlwidget->database(),
              db->lastError().databaseText() + "</qt>" );

    if( db->open() ) {
        TDEApplication::setOverrideCursor( TQt::WaitCursor );
        SqlTables::getInstance()->importData(
            locate("appdata", "labeldefinitions.sql"), db );
        buttonExample->setEnabled( true );
        TDEApplication::restoreOverrideCursor();
    }

    db->close();
}

void ConfWizard::example()
{
    TQSqlDatabase* db = TQSqlDatabase::addDatabase( sqlwidget->driver() );
    db->setDatabaseName( sqlwidget->database() );
    db->setUserName( sqlwidget->username() );
    db->setPassword( sqlwidget->password() );
    db->setHostName( sqlwidget->hostname() );

    if( !db->open() )
        KMessageBox::error( this, i18n("<qt>Connection failed:<br>") + sqlwidget->database(),
              db->lastError().databaseText() + "</qt>" );


    SqlTables::getInstance()->importData(
        locate("appdata", "exampledata.sql"), db );
    KMessageBox::information( this, i18n("Example data has been imported.") );

    db->close();
}

void ConfWizard::showPage( TQWidget* page )
{
    TQWizard::showPage(page);

    if( page == page_2 && !sqlwidget->driverCount() ) {
        KMessageBox::information( this, i18n(
            "There are no TQt SQL drivers installed. "
            "KBarcode needs those drivers to access the different SQL databases. "
            "This drivers are part of the TQt Source distribution and should also be part of "
            "your distribution. Please install them first.") );
    }
    
    if ( page == page_3 )
        finishButton()->setEnabled( true );
}

void ConfWizard::useDatabase()
{
    setFinishEnabled( page_2, !checkDatabase->isChecked() );
    setNextEnabled( page_2, false );
    setFinishEnabled( page_3, checkDatabase->isChecked() );
    sqlwidget->setEnabled( checkDatabase->isChecked() );
}


#include "confwizard.moc"