summaryrefslogtreecommitdiffstats
path: root/tdeprint/management/kmwizard.cpp
blob: 5bb86967ae26cf3d6b4ff1ca5ad3f9b5d0f231b3 (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
/*
 *  This file is part of the KDE libraries
 *  Copyright (c) 2001 Michael Goffioul <[email protected]>
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Library General Public
 *  License version 2 as published by the Free Software Foundation.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Library General Public License for more details.
 *
 *  You should have received a copy of the GNU Library General Public License
 *  along with this library; see the file COPYING.LIB.  If not, write to
 *  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 *  Boston, MA 02110-1301, USA.
 **/

#include "kmwizard.h"
#include "kmwizardpage.h"
#include "kmprinter.h"
#include "kmfactory.h"
#include "kmuimanager.h"

#include <kpushbutton.h>
#include <tqlabel.h>
#include <tqwidgetstack.h>
#include <kmessagebox.h>
#include <tqlayout.h>
#include <klocale.h>
#include <kdebug.h>
#include <kseparator.h>
#include <tdeapplication.h>
#include <kstdguiitem.h>

#include "kmwinfopage.h"
#include "kmwpassword.h"
#include "kmwbackend.h"
#include "kmwsocket.h"
#include "kmwdriver.h"
#include "kmwdriverselect.h"
#include "kmwdrivertest.h"
#include "kmwname.h"
#include "kmwend.h"
#include "kmwclass.h"
#include "kmwlpd.h"
#include "kmwfile.h"
#include "kmwsmb.h"
#include "kmwlocal.h"
#include "sidepixmap.h"

KMWizard::KMWizard(TQWidget *parent, const char *name)
: TQDialog(parent,name,true)
{
	m_start = KMWizard::Start;
	m_end = KMWizard::End;
	m_inclusive = true;
	m_printer = new KMPrinter();

	m_pagepool.setAutoDelete(false);

	m_stack = new TQWidgetStack(this);
	m_next = new KPushButton(i18n("&Next >"), this);
	m_next->setDefault(true);
	m_prev = new KPushButton(i18n("< &Back"), this);
	TQPushButton	*m_cancel = new KPushButton(KStdGuiItem::cancel(), this);
	m_title = new TQLabel(this);
	TQFont	f(m_title->font());
	f.setBold(true);
	m_title->setFont(f);
	KSeparator* sep = new KSeparator( KSeparator::HLine, this);
	sep->setFixedHeight(5);
	KSeparator* sep2 = new KSeparator( KSeparator::HLine, this);
	TQPushButton	*m_help = new KPushButton(KStdGuiItem::help(), this);

	connect(m_cancel,TQT_SIGNAL(clicked()),TQT_SLOT(reject()));
	connect(m_next,TQT_SIGNAL(clicked()),TQT_SLOT(slotNext()));
	connect(m_prev,TQT_SIGNAL(clicked()),TQT_SLOT(slotPrev()));
	connect(m_help, TQT_SIGNAL(clicked()), TQT_SLOT(slotHelp()));

	m_side = new SidePixmap(this);
	if (!m_side->isValid())
	{
		delete m_side;
		m_side = 0;
	}

	// layout
	TQVBoxLayout *main0_ = new TQVBoxLayout(this, 10, 10);
	TQVBoxLayout	*main_ = new TQVBoxLayout(0, 0, 0);
	TQHBoxLayout *main1_ = new TQHBoxLayout(0, 0, 10);
	TQHBoxLayout	*btn_ = new TQHBoxLayout(0, 0, 10);
	main0_->addLayout(main1_);
	if (m_side)
		main1_->addWidget(m_side);
	main1_->addLayout(main_);
	main_->addWidget(m_title);
	main_->addWidget(sep);
	main_->addSpacing(10);
	main_->addWidget(m_stack,1);
	main0_->addWidget(sep2);
	main0_->addLayout(btn_);
	btn_->addWidget(m_help);
	btn_->addStretch(1);
	btn_->addWidget(m_prev);
	btn_->addWidget(m_next);
	btn_->addWidget(m_cancel);

	// create standard pages
	addPage(new KMWInfoPage(this));
	m_backend = new KMWBackend(this);
	addPage(m_backend);
	addPage(new KMWPassword(this));
	addPage(new KMWSocket(this));
	addPage(new KMWDriver(this));
	addPage(new KMWDriverSelect(this));
	addPage(new KMWDriverTest(this));
	addPage(new KMWName(this));
	addPage(new KMWEnd(this));
	addPage(new KMWClass(this));
	addPage(new KMWLpd(this));
	addPage(new KMWFile(this));
	addPage(new KMWSmb(this));
	addPage(new KMWLocal(this));

	// add other pages
	KMFactory::self()->uiManager()->setupWizard(this);

	setCurrentPage(m_start,false);
	setCaption(i18n("Add Printer Wizard"));
	resize(400,350);
}

KMWizard::~KMWizard()
{
	delete m_printer;
}

void KMWizard::addPage(KMWizardPage *page)
{
	m_stack->addWidget(page,page->id());
	m_pagepool.insert(page->id(),page);
}

void KMWizard::setPrinter(KMPrinter *p)
{
	if (p)
	{
		m_printer->copy(*p);
		KMWizardPage	*page = (KMWizardPage*)m_stack->visibleWidget();
		if (page)
			page->initPrinter(m_printer);
	}
}

void KMWizard::configure(int start, int end, bool inclusive)
{
	m_start = start;
	m_end = end;
	m_inclusive = inclusive;
	m_pagestack.clear();

	// disable class if not starting from beginning
	m_backend->enableBackend(KMWizard::Class,(m_start == KMWizard::Start));
	setCaption((m_start == KMWizard::Start ? i18n("Add Printer Wizard") : i18n("Modify Printer")));

	if (m_side)
	{
		if (start == KMWizard::Start && end == KMWizard::End)
			m_side->show();
		else
			m_side->hide();
	}

	setCurrentPage(m_start,false);
}

void KMWizard::setNextPage(int page, int next)
{
	KMWizardPage	*p = m_pagepool.find(page);
	if (p)
		p->setNextPage(next);
}

void KMWizard::setCurrentPage(int ID, bool back)
{
	KMWizardPage	*page = m_pagepool.find(ID);
	if (!page)
	{
		KMessageBox::error(this,i18n("Unable to find the requested page."),i18n("Add Printer Wizard"));
		return;
	}

	// add current page to stack (only if going backward)
	if (!back) m_pagestack.push(ID);

	// raise page + initialize
	m_stack->raiseWidget(page);
	m_title->setText(page->title());
	if (!back || page->needsInitOnBack()) page->initPrinter(m_printer);

	// update buttons
	if (ID == m_start) m_prev->setEnabled(false);
	else m_prev->setEnabled(true);
	if ((m_inclusive && ID == m_end) || (!m_inclusive && page->nextPage() == m_end))
		m_next->setText(i18n("&Finish"));
	else
		m_next->setText(i18n("&Next >"));
}

void KMWizard::slotPrev()
{
	// current page is on top of stack -> pop it and retrieve new top of stack
	m_pagestack.pop();
	int	ID = m_pagestack.top();
	setCurrentPage(ID,true);
}

void KMWizard::slotNext()
{
	KMWizardPage	*page = (KMWizardPage*)m_stack->visibleWidget();
	if (page)
	{
		TQString	msg;
		if (!page->isValid(msg))
		{
			if (!msg.isEmpty())
				KMessageBox::error(this,msg.prepend("<qt>").append("</qt>"),page->title());
		}
		else
		{
			page->updatePrinter(m_printer);
			if (m_next->text() == i18n("&Finish"))
				accept();
			else
			{
				int	ID = page->nextPage();
				setCurrentPage(ID,false);
			}
		}
	}
}

void KMWizard::slotHelp()
{
	kapp->invokeHelp(TQString::null, "tdeprint");
}

void KMWizard::enableWizard()
{
	m_next->setEnabled( true );
	m_prev->setEnabled( m_pagestack.top() != m_start );
}

void KMWizard::disableWizard()
{
	m_next->setEnabled( false );
	m_prev->setEnabled( false );
}

#include "kmwizard.moc"