20#include "KexiNewProjectWizard.h"
22#include "KexiConnSelector.h"
23#include "KexiConnSelectorBase.h"
24#include "KexiNewPrjTypeSelector.h"
25#include "KexiOpenExistingFile.h"
26#include "KexiDBTitlePage.h"
27#include "KexiServerDBNamePage.h"
28#include "KexiProjectSelector.h"
31#include <kexiutils/identifier.h>
32#include <kexiutils/utils.h>
33#include <kexiguimsghandler.h>
35#include <tdeapplication.h>
36#include <kiconloader.h>
41#include <tdelistview.h>
42#include <kurlcombobox.h>
43#include <tdemessagebox.h>
46#include <tqobjectlist.h>
48#include <tqpushbutton.h>
50#include <tqcheckbox.h>
54class KexiNewProjectWizardPrivate
57 KexiNewProjectWizardPrivate()
59 le_dbname_txtchanged_disable =
false;
60 le_dbname_autofill =
true;
64 ~KexiNewProjectWizardPrivate()
71 TDEListViewItem *lvi_file, *lvi_server;
72 TQString chk_file_txt, chk_server_txt;
74 TQString server_db_name_dblist_lbl_txt;
77 TQGuardedPtr<KexiDB::ConnectionData> conndata_to_show;
78 KexiProjectSet *project_set_to_show;
80 KexiGUIMessageHandler* msgHandler;
82 bool le_dbname_txtchanged_disable : 1;
83 bool le_dbname_autofill : 1;
87 TQWidget *parent,
const char *name,
bool modal, WFlags f)
88: KWizard(parent, name, modal, f)
89, d(new KexiNewProjectWizardPrivate() )
91 d->msgHandler =
new KexiGUIMessageHandler(
this);
92 setIcon( DesktopIcon(
"document-new") );
93 setCaption( i18n(
"Creating New Project") );
94 finishButton()->setText(i18n(
"Create"));
97 m_prjtype_sel =
new KexiNewPrjTypeSelector(
this,
"KexiNewPrjTypeSelector");
100 m_prjtype_sel->lv_types->setShadeSortColumn(
false);
101 m_prjtype_sel->lv_types->header()->hide();
102 m_prjtype_sel->lv_types->setSorting(-1);
103 m_prjtype_sel->lv_types->setAlternateBackground(TQColor());
104 m_prjtype_sel->lv_types->setItemMargin( KDialogBase::marginHint() );
106 d->lvi_file =
new TDEListViewItem( m_prjtype_sel->lv_types, i18n(
"New Project Stored in File") );
107 d->lvi_file->setPixmap(0,
108 TDEGlobal::iconLoader()->loadIcon( KMimeType::mimeType(
112 d->lvi_file->setMultiLinesEnabled(
true );
113 d->lvi_server =
new TDEListViewItem( m_prjtype_sel->lv_types, d->lvi_file,
114 i18n(
"New Project Stored on Database Server") );
115 d->lvi_server->setPixmap(0, DesktopIcon(
"network") );
116 d->lvi_server->setMultiLinesEnabled(
true );
118 m_prjtype_sel->lv_types->setFocus();
124 connect(m_prjtype_sel->lv_types,TQ_SIGNAL(executed(TQListViewItem*)),
this,TQ_SLOT(slotLvTypesExecuted(TQListViewItem*)));
125 connect(m_prjtype_sel->lv_types,TQ_SIGNAL(returnPressed(TQListViewItem*)),
this,TQ_SLOT(slotLvTypesExecuted(TQListViewItem*)));
126 connect(m_prjtype_sel->lv_types,TQ_SIGNAL(selectionChanged( TQListViewItem*)),
this,TQ_SLOT(slotLvTypesSelected(TQListViewItem*)));
132 addPage(m_prjtype_sel, i18n(
"Select Storage Method"));
137 addPage(m_db_title, i18n(
"Select Project's Caption"));
140 m_conn_sel_widget =
new TQWidget(
this);
141 TQVBoxLayout* conn_sel_lyr =
new TQVBoxLayout(m_conn_sel_widget);
142 TQLabel *conn_sel_label =
new TQLabel(i18n(
"Enter a new Kexi project's file name:"), m_conn_sel_widget);
143 conn_sel_label->setAlignment(TQt::AlignAuto|TQt::AlignTop|TQt::WordBreak);
144 conn_sel_lyr->addWidget( conn_sel_label );
145 conn_sel_lyr->addSpacing(KDialogBase::spacingHint());
148 m_conn_sel_widget,
"KexiConnSelectorWidget");
149 conn_sel_lyr->addWidget( m_conn_sel );
155 m_conn_sel->hideHelpers();
157 m_conn_sel->m_remote->label->setText(
158 i18n(
"Select database server's connection you wish to use to create a new Kexi project. "
159 "<p>Here you may also add, edit or remove connections from the list."));
163 m_conn_sel->showSimpleConn();
165 m_conn_sel->m_fileDlg->setMode( KexiStartupFileDialog::SavingFileBasedDB );
170 connect(m_conn_sel->m_fileDlg,TQ_SIGNAL(accepted()),
this,TQ_SLOT(accept()));
171 m_conn_sel->showAdvancedConn();
173 this,TQ_SLOT(next()));
175 addPage(m_conn_sel_widget, i18n(
"Select Project's Location"));
178 m_server_db_name =
new KexiServerDBNamePage(
this,
"KexiServerDBNamePage");
179 d->server_db_name_dblist_lbl_txt = i18n(
"Existing project databases on <b>%1</b> database server:");
180 connect(m_server_db_name->le_caption, TQ_SIGNAL(textChanged(
const TQString&)),
181 this,TQ_SLOT(slotServerDBCaptionTxtChanged(
const TQString&)));
182 connect(m_server_db_name->le_dbname, TQ_SIGNAL(textChanged(
const TQString&)),
183 this,TQ_SLOT(slotServerDBNameTxtChanged(
const TQString&)));
184 connect(m_server_db_name->le_caption, TQ_SIGNAL(returnPressed()),
185 this,TQ_SLOT(accept()));
186 connect(m_server_db_name->le_dbname, TQ_SIGNAL(returnPressed()),
187 this,TQ_SLOT(accept()));
188 m_server_db_name->le_caption->setText(i18n(
"New database"));
191 m_server_db_name->frm_dblist,
"KexiProjectSelectorWidget", 0,
false,
false );
192 GLUE_WIDGET(m_project_selector, m_server_db_name->frm_dblist);
193 m_project_selector->setFocusPolicy(TQWidget::NoFocus);
194 m_project_selector->setSelectable(
false);
196 addPage(m_server_db_name, i18n(
"Select Project's Caption & Database Name"));
198 setFinishEnabled(m_prjtype_sel,
false);
199 setFinishEnabled(m_db_title,
false);
200 setFinishEnabled(m_server_db_name,
true);
204 m_prjtype_sel->lv_types->setSelected(d->lvi_file,
true);
207KexiNewProjectWizard::~KexiNewProjectWizard()
212void KexiNewProjectWizard::show()
214 KDialog::centerOnScreen(
this);
218void KexiNewProjectWizard::slotLvTypesExecuted(TQListViewItem *)
223void KexiNewProjectWizard::slotLvTypesSelected(TQListViewItem *item)
231 setAppropriate( m_db_title, item==d->lvi_file );
232 setAppropriate( m_server_db_name, item==d->lvi_server );
235void KexiNewProjectWizard::showPage(TQWidget *page)
237 if (page==m_prjtype_sel) {
238 m_prjtype_sel->lv_types->setFocus();
239 m_prjtype_sel->lv_types->setCurrentItem(m_prjtype_sel->lv_types->currentItem());
240 }
else if (page==m_db_title) {
241 if (m_db_title->le_caption->text().stripWhiteSpace().isEmpty())
242 m_db_title->le_caption->setText(i18n(
"New database"));
243 m_db_title->le_caption->selectAll();
244 m_db_title->le_caption->setFocus();
245 }
else if (page==m_conn_sel_widget) {
246 if (m_prjtype_sel->lv_types->currentItem()==d->lvi_file) {
247 m_conn_sel->showSimpleConn();
249 if (!fn.endsWith(
".kexi"))
251 m_conn_sel->m_fileDlg->setLocationText(fn);
252 setFinishEnabled(m_conn_sel_widget,
true);
253 m_conn_sel->setFocus();
256 m_conn_sel->showAdvancedConn();
257 setFinishEnabled(m_conn_sel_widget,
false);
258 m_conn_sel->setFocus();
259 m_server_db_name->le_caption->selectAll();
261 }
else if (page==m_server_db_name) {
262 if (m_conn_sel->selectedConnectionData()
263 && (
static_cast<KexiDB::ConnectionData*
>(d->conndata_to_show) != m_conn_sel->selectedConnectionData())) {
264 m_project_selector->setProjectSet(0);
266 d->conndata_to_show = 0;
267 d->project_set_to_show =
new KexiProjectSet(*m_conn_sel->selectedConnectionData(), d->msgHandler);
268 if (d->project_set_to_show->error()) {
269 delete d->project_set_to_show;
270 d->project_set_to_show = 0;
273 d->conndata_to_show = m_conn_sel->selectedConnectionData();
275 m_project_selector->setProjectSet( d->project_set_to_show );
278 KWizard::showPage(page);
281void KexiNewProjectWizard::next()
284 if (currentPage()==m_db_title) {
285 if (m_db_title->le_caption->text().stripWhiteSpace().isEmpty()) {
286 KMessageBox::information(
this, i18n(
"Enter project caption."));
287 m_db_title->le_caption->setText(
"");
288 m_db_title->le_caption->setFocus();
291 }
else if (currentPage()==m_conn_sel_widget) {
292 if (m_prjtype_sel->lv_types->currentItem()==d->lvi_file) {
297 if (!m_conn_sel->selectedConnectionData()) {
298 KMessageBox::information(
this, i18n(
"Select server connection for a new project."));
301 m_project_selector->label->setText(
302 d->server_db_name_dblist_lbl_txt.arg(m_conn_sel->selectedConnectionData()->serverInfoString(
false)) );
303 m_server_db_name->le_caption->setFocus();
310void KexiNewProjectWizard::accept()
312 if (m_prjtype_sel->lv_types->currentItem()==d->lvi_file) {
314 kdDebug() <<
"********** sender() " << sender()->className() << endl;
315 if (sender()==finishButton()) {
316 kdDebug() <<
"********** sender()==finishButton() ********" << endl;
318 if (!m_conn_sel->m_fileDlg->checkFileName()) {
324 if (m_server_db_name->le_caption->text().stripWhiteSpace().isEmpty()) {
325 KMessageBox::information(
this, i18n(
"Enter project caption."));
326 m_server_db_name->le_caption->setText(
"");
327 m_server_db_name->le_caption->setFocus();
330 TQString dbname = m_server_db_name->le_dbname->text().stripWhiteSpace();
331 if (dbname.isEmpty()) {
332 KMessageBox::information(
this, i18n(
"Enter project's database name."));
333 m_server_db_name->le_dbname->setText(
"");
334 m_server_db_name->le_dbname->setFocus();
338 if (m_conn_sel->confirmOverwrites() && m_project_selector->projectSet() && m_project_selector->projectSet()
339 ->findProject( m_server_db_name->le_dbname->text() )) {
340 if (KMessageBox::Continue!=KMessageBox::warningContinueCancel(
this,
"<qt>"
341 +i18n(
"<b>A project with database name \"%1\" already exists</b>"
342 "<p>Do you want to delete it and create a new one?")
343 .arg( m_server_db_name->le_dbname->text() ), TQString(), KStdGuiItem::del(),
344 TQString(), KMessageBox::Notify|KMessageBox::Dangerous ))
346 m_server_db_name->le_dbname->setFocus();
355void KexiNewProjectWizard::done(
int r)
366 TDEGlobal::config()->sync();
370TQString KexiNewProjectWizard::projectDBName()
const
372 if (m_prjtype_sel->lv_types->currentItem()==d->lvi_server)
373 return m_server_db_name->le_dbname->text();
374 return m_conn_sel->selectedFileName();
377TQString KexiNewProjectWizard::projectCaption()
const
379 if (m_prjtype_sel->lv_types->currentItem()==d->lvi_server) {
380 return m_server_db_name->le_caption->text();
382 return m_db_title->le_caption->text();
387 if (m_prjtype_sel->lv_types->currentItem()==d->lvi_file)
389 return m_conn_sel->selectedConnectionData();
392void KexiNewProjectWizard::slotServerDBCaptionTxtChanged(
const TQString &capt)
394 if (m_server_db_name->le_dbname->text().isEmpty())
395 d->le_dbname_autofill=
true;
396 if (d->le_dbname_autofill) {
397 d->le_dbname_txtchanged_disable =
true;
399 m_server_db_name->le_dbname->setText(captionAsId);
400 d->le_dbname_txtchanged_disable =
false;
404void KexiNewProjectWizard::slotServerDBNameTxtChanged(
const TQString &)
406 if (d->le_dbname_txtchanged_disable)
408 d->le_dbname_autofill =
false;
413void KexiNewProjectWizard::setConfirmOverwrites(
bool set)
415 m_conn_sel->setConfirmOverwrites(set);
419#include "KexiNewProjectWizard.moc"
A helper widget used to displaying a line edit with a label and layout.
Database specific connection data, e.g. host, port.
static TQString defaultFileBasedDriverMimeType()
Validates input for identifier name.
KEXIUTILS_EXPORT TQString string2FileName(const TQString &s)
KEXIUTILS_EXPORT TQString string2Identifier(const TQString &s)