00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "KexiNewProjectWizard.h"
00021
00022 #include "KexiConnSelector.h"
00023 #include "KexiConnSelectorBase.h"
00024 #include "KexiNewPrjTypeSelector.h"
00025 #include "KexiOpenExistingFile.h"
00026 #include "KexiDBTitlePage.h"
00027 #include "KexiServerDBNamePage.h"
00028 #include "KexiProjectSelector.h"
00029 #include "kexi.h"
00030
00031 #include <kexiutils/identifier.h>
00032 #include <kexiutils/utils.h>
00033 #include <kexiguimsghandler.h>
00034
00035 #include <kapplication.h>
00036 #include <kiconloader.h>
00037 #include <kmimetype.h>
00038 #include <klocale.h>
00039 #include <kdebug.h>
00040 #include <kconfig.h>
00041 #include <klistview.h>
00042 #include <kurlcombobox.h>
00043 #include <kmessagebox.h>
00044 #include <klineedit.h>
00045
00046 #include <qobjectlist.h>
00047 #include <qlabel.h>
00048 #include <qpushbutton.h>
00049 #include <qlayout.h>
00050 #include <qcheckbox.h>
00051 #include <qheader.h>
00052
00054 class KexiNewProjectWizardPrivate
00055 {
00056 public:
00057 KexiNewProjectWizardPrivate()
00058 {
00059 le_dbname_txtchanged_disable = false;
00060 le_dbname_autofill = true;
00061
00062
00063 }
00064 ~KexiNewProjectWizardPrivate()
00065 {
00066
00067
00068 delete msgHandler;
00069 }
00070
00071 KListViewItem *lvi_file, *lvi_server;
00072 QString chk_file_txt, chk_server_txt;
00073
00074 QString server_db_name_dblist_lbl_txt;
00075
00076
00077 QGuardedPtr<KexiDB::ConnectionData> conndata_to_show;
00078 KexiProjectSet *project_set_to_show;
00079
00080 KexiGUIMessageHandler* msgHandler;
00081
00082 bool le_dbname_txtchanged_disable : 1;
00083 bool le_dbname_autofill : 1;
00084 };
00085
00086 KexiNewProjectWizard::KexiNewProjectWizard(KexiDBConnectionSet& conn_set,
00087 QWidget *parent, const char *name, bool modal, WFlags f)
00088 : KWizard(parent, name, modal, f)
00089 , d(new KexiNewProjectWizardPrivate() )
00090 {
00091 d->msgHandler = new KexiGUIMessageHandler(this);
00092 setIcon( DesktopIcon("filenew") );
00093 setCaption( i18n("Creating New Project") );
00094 finishButton()->setText(i18n("Create"));
00095
00096
00097 m_prjtype_sel = new KexiNewPrjTypeSelector(this, "KexiNewPrjTypeSelector");
00098
00099
00100 #if KDE_IS_VERSION(3,3,9)
00101 m_prjtype_sel->lv_types->setShadeSortColumn(false);
00102 #endif
00103 m_prjtype_sel->lv_types->header()->hide();
00104 m_prjtype_sel->lv_types->setSorting(-1);
00105 m_prjtype_sel->lv_types->setAlternateBackground(QColor());
00106 m_prjtype_sel->lv_types->setItemMargin( KDialogBase::marginHint() );
00107 QString none;
00108 d->lvi_file = new KListViewItem( m_prjtype_sel->lv_types, i18n("New Project Stored in File") );
00109 d->lvi_file->setPixmap(0,
00110 KGlobal::iconLoader()->loadIcon( KMimeType::mimeType(
00111 KexiDB::Driver::defaultFileBasedDriverMimeType() )->icon(none,0), KIcon::Desktop
00112 )
00113 );
00114 d->lvi_file->setMultiLinesEnabled( true );
00115 d->lvi_server = new KListViewItem( m_prjtype_sel->lv_types, d->lvi_file,
00116 i18n("New Project Stored on Database Server") );
00117 d->lvi_server->setPixmap(0, DesktopIcon("network") );
00118 d->lvi_server->setMultiLinesEnabled( true );
00119
00120 m_prjtype_sel->lv_types->setFocus();
00121
00122
00123
00124
00125
00126 connect(m_prjtype_sel->lv_types,SIGNAL(executed(QListViewItem*)),this,SLOT(slotLvTypesExecuted(QListViewItem*)));
00127 connect(m_prjtype_sel->lv_types,SIGNAL(returnPressed(QListViewItem*)),this,SLOT(slotLvTypesExecuted(QListViewItem*)));
00128 connect(m_prjtype_sel->lv_types,SIGNAL(selectionChanged( QListViewItem*)),this,SLOT(slotLvTypesSelected(QListViewItem*)));
00129
00130
00131
00132
00133
00134 addPage(m_prjtype_sel, i18n("Select Storage Method"));
00135
00136
00137
00138 m_db_title = new KexiDBTitlePage(QString::null, this, "KexiDBTitlePage");
00139 addPage(m_db_title, i18n("Select Project's Caption"));
00140
00141
00142 m_conn_sel_widget = new QWidget(this);
00143 QVBoxLayout* conn_sel_lyr = new QVBoxLayout(m_conn_sel_widget);
00144 QLabel *conn_sel_label = new QLabel(i18n("Enter a new Kexi project's file name:"), m_conn_sel_widget);
00145 conn_sel_label->setAlignment(Qt::AlignAuto|Qt::AlignTop|Qt::WordBreak);
00146 conn_sel_lyr->addWidget( conn_sel_label );
00147 conn_sel_lyr->addSpacing(KDialogBase::spacingHint());
00148
00149 m_conn_sel = new KexiConnSelectorWidget(conn_set, ":OpenExistingOrCreateNewProject",
00150 m_conn_sel_widget, "KexiConnSelectorWidget");
00151 conn_sel_lyr->addWidget( m_conn_sel );
00152
00153
00154
00155
00156
00157 m_conn_sel->hideHelpers();
00158
00159 m_conn_sel->m_remote->label->setText(
00160 i18n("Select database server's connection you wish to use to create a new Kexi project. "
00161 "<p>Here you may also add, edit or remove connections from the list."));
00162
00163
00164
00165 m_conn_sel->showSimpleConn();
00166
00167 m_conn_sel->m_fileDlg->setMode( KexiStartupFileDialog::SavingFileBasedDB );
00168
00169
00171
00172 connect(m_conn_sel->m_fileDlg,SIGNAL(accepted()),this,SLOT(accept()));
00173 m_conn_sel->showAdvancedConn();
00174 connect(m_conn_sel,SIGNAL(connectionItemExecuted(ConnectionDataLVItem*)),
00175 this,SLOT(next()));
00176
00177 addPage(m_conn_sel_widget, i18n("Select Project's Location"));
00178
00179
00180 m_server_db_name = new KexiServerDBNamePage(this, "KexiServerDBNamePage");
00181 d->server_db_name_dblist_lbl_txt = i18n("Existing project databases on <b>%1</b> database server:");
00182 connect(m_server_db_name->le_caption, SIGNAL(textChanged(const QString&)),
00183 this,SLOT(slotServerDBCaptionTxtChanged(const QString&)));
00184 connect(m_server_db_name->le_dbname, SIGNAL(textChanged(const QString&)),
00185 this,SLOT(slotServerDBNameTxtChanged(const QString&)));
00186 connect(m_server_db_name->le_caption, SIGNAL(returnPressed()),
00187 this,SLOT(accept()));
00188 connect(m_server_db_name->le_dbname, SIGNAL(returnPressed()),
00189 this,SLOT(accept()));
00190 m_server_db_name->le_caption->setText(i18n("New database"));
00191 m_server_db_name->le_dbname->setValidator(new KexiUtils::IdentifierValidator(this, "id_val"));
00192 m_project_selector = new KexiProjectSelectorWidget(
00193 m_server_db_name->frm_dblist, "KexiProjectSelectorWidget", 0, false, false );
00194 GLUE_WIDGET(m_project_selector, m_server_db_name->frm_dblist);
00195 m_project_selector->setFocusPolicy(NoFocus);
00196 m_project_selector->setSelectable(false);
00197
00198 addPage(m_server_db_name, i18n("Select Project's Caption & Database Name"));
00199
00200 setFinishEnabled(m_prjtype_sel,false);
00201 setFinishEnabled(m_db_title,false);
00202 setFinishEnabled(m_server_db_name,true);
00203
00204
00205 updateGeometry();
00206
00207 m_prjtype_sel->lv_types->setSelected(d->lvi_file, true);
00208
00209 #ifdef KEXI_SERVER_SUPPORT
00210
00211
00212
00213
00214 #else
00215
00216 setBackEnabled(m_db_title, false);
00217 showPage(m_db_title);
00218 #endif
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229 }
00230
00231 KexiNewProjectWizard::~KexiNewProjectWizard()
00232 {
00233 delete d;
00234 }
00235
00236 void KexiNewProjectWizard::show()
00237 {
00238 KDialog::centerOnScreen(this);
00239 KWizard::show();
00240 }
00241
00242 void KexiNewProjectWizard::slotLvTypesExecuted(QListViewItem *)
00243 {
00244 next();
00245 }
00246
00247 void KexiNewProjectWizard::slotLvTypesSelected(QListViewItem *item)
00248 {
00249
00250
00251
00252
00253
00254
00255 setAppropriate( m_db_title, item==d->lvi_file );
00256 setAppropriate( m_server_db_name, item==d->lvi_server );
00257 }
00258
00259 void KexiNewProjectWizard::showPage(QWidget *page)
00260 {
00261 if (page==m_prjtype_sel) {
00262 m_prjtype_sel->lv_types->setFocus();
00263 m_prjtype_sel->lv_types->setCurrentItem(m_prjtype_sel->lv_types->currentItem());
00264 } else if (page==m_db_title) {
00265 if (m_db_title->le_caption->text().stripWhiteSpace().isEmpty())
00266 m_db_title->le_caption->setText(i18n("New database"));
00267 m_db_title->le_caption->selectAll();
00268 m_db_title->le_caption->setFocus();
00269 } else if (page==m_conn_sel_widget) {
00270 if (m_prjtype_sel->lv_types->currentItem()==d->lvi_file) {
00271 m_conn_sel->showSimpleConn();
00272 QString fn = KexiUtils::string2FileName( m_db_title->le_caption->text() );
00273 if (!fn.endsWith(".kexi"))
00274 fn += ".kexi";
00275 m_conn_sel->m_fileDlg->setLocationText(fn);
00276 setFinishEnabled(m_conn_sel_widget,true);
00277 m_conn_sel->setFocus();
00278 }
00279 else {
00280 m_conn_sel->showAdvancedConn();
00281 setFinishEnabled(m_conn_sel_widget,false);
00282 m_conn_sel->setFocus();
00283 m_server_db_name->le_caption->selectAll();
00284 }
00285 } else if (page==m_server_db_name) {
00286 if (m_conn_sel->selectedConnectionData()
00287 && (static_cast<KexiDB::ConnectionData*>(d->conndata_to_show) != m_conn_sel->selectedConnectionData())) {
00288 m_project_selector->setProjectSet(0);
00289
00290 d->conndata_to_show = 0;
00291 d->project_set_to_show = new KexiProjectSet(*m_conn_sel->selectedConnectionData(), d->msgHandler);
00292 if (d->project_set_to_show->error()) {
00293 delete d->project_set_to_show;
00294 d->project_set_to_show = 0;
00295 return;
00296 }
00297 d->conndata_to_show = m_conn_sel->selectedConnectionData();
00298
00299 m_project_selector->setProjectSet( d->project_set_to_show );
00300 }
00301 }
00302 KWizard::showPage(page);
00303 }
00304
00305 void KexiNewProjectWizard::next()
00306 {
00307
00308 if (currentPage()==m_db_title) {
00309 if (m_db_title->le_caption->text().stripWhiteSpace().isEmpty()) {
00310 KMessageBox::information(this, i18n("Enter project caption."));
00311 m_db_title->le_caption->setText("");
00312 m_db_title->le_caption->setFocus();
00313 return;
00314 }
00315 } else if (currentPage()==m_conn_sel_widget) {
00316 if (m_prjtype_sel->lv_types->currentItem()==d->lvi_file) {
00317
00318 }
00319 else {
00320
00321 if (!m_conn_sel->selectedConnectionData()) {
00322 KMessageBox::information(this, i18n("Select server connection for a new project."));
00323 return;
00324 }
00325 m_project_selector->label->setText(
00326 d->server_db_name_dblist_lbl_txt.arg(m_conn_sel->selectedConnectionData()->serverInfoString(false)) );
00327 m_server_db_name->le_caption->setFocus();
00328
00329 }
00330 }
00331 KWizard::next();
00332 }
00333
00334 void KexiNewProjectWizard::accept()
00335 {
00336 if (m_prjtype_sel->lv_types->currentItem()==d->lvi_file) {
00337
00338 kdDebug() << "********** sender() " << sender()->className() << endl;
00339 if (sender()==finishButton()) {
00340 kdDebug() << "********** sender()==finishButton() ********" << endl;
00341
00342 if (!m_conn_sel->m_fileDlg->checkFileName()) {
00343 return;
00344 }
00345 }
00346 } else {
00347
00348 if (m_server_db_name->le_caption->text().stripWhiteSpace().isEmpty()) {
00349 KMessageBox::information(this, i18n("Enter project caption."));
00350 m_server_db_name->le_caption->setText("");
00351 m_server_db_name->le_caption->setFocus();
00352 return;
00353 }
00354 QString dbname = m_server_db_name->le_dbname->text().stripWhiteSpace();
00355 if (dbname.isEmpty()) {
00356 KMessageBox::information(this, i18n("Enter project's database name."));
00357 m_server_db_name->le_dbname->setText("");
00358 m_server_db_name->le_dbname->setFocus();
00359 return;
00360 }
00361
00362 if (m_conn_sel->confirmOverwrites() && m_project_selector->projectSet() && m_project_selector->projectSet()
00363 ->findProject( m_server_db_name->le_dbname->text() )) {
00364 if (KMessageBox::Continue!=KMessageBox::warningContinueCancel( this, "<qt>"
00365 +i18n("<b>A project with database name \"%1\" already exists</b>"
00366 "<p>Do you want to delete it and create a new one?")
00367 .arg( m_server_db_name->le_dbname->text() ), QString::null, KStdGuiItem::del(),
00368 QString::null, KMessageBox::Notify|KMessageBox::Dangerous ))
00369 {
00370 m_server_db_name->le_dbname->setFocus();
00371 return;
00372 }
00373 }
00374 }
00375
00376 KWizard::accept();
00377 }
00378
00379 void KexiNewProjectWizard::done(int r)
00380 {
00381
00382
00383
00384
00385
00386
00387
00388
00389
00390 KGlobal::config()->sync();
00391 KWizard::done(r);
00392 }
00393
00394 QString KexiNewProjectWizard::projectDBName() const
00395 {
00396 if (m_prjtype_sel->lv_types->currentItem()==d->lvi_server)
00397 return m_server_db_name->le_dbname->text();
00398 return m_conn_sel->selectedFileName();
00399 }
00400
00401 QString KexiNewProjectWizard::projectCaption() const
00402 {
00403 if (m_prjtype_sel->lv_types->currentItem()==d->lvi_server) {
00404 return m_server_db_name->le_caption->text();
00405 }
00406 return m_db_title->le_caption->text();
00407 }
00408
00409 KexiDB::ConnectionData* KexiNewProjectWizard::projectConnectionData() const
00410 {
00411 if (m_prjtype_sel->lv_types->currentItem()==d->lvi_file)
00412 return 0;
00413 return m_conn_sel->selectedConnectionData();
00414 }
00415
00416 void KexiNewProjectWizard::slotServerDBCaptionTxtChanged(const QString &capt)
00417 {
00418 if (m_server_db_name->le_dbname->text().isEmpty())
00419 d->le_dbname_autofill=true;
00420 if (d->le_dbname_autofill) {
00421 d->le_dbname_txtchanged_disable = true;
00422 QString captionAsId = KexiUtils::string2Identifier(capt);
00423 m_server_db_name->le_dbname->setText(captionAsId);
00424 d->le_dbname_txtchanged_disable = false;
00425 }
00426 }
00427
00428 void KexiNewProjectWizard::slotServerDBNameTxtChanged(const QString &)
00429 {
00430 if (d->le_dbname_txtchanged_disable)
00431 return;
00432 d->le_dbname_autofill = false;
00433 }
00434
00437 void KexiNewProjectWizard::setConfirmOverwrites(bool set)
00438 {
00439 m_conn_sel->setConfirmOverwrites(set);
00440 }
00441
00442
00443 #include "KexiNewProjectWizard.moc"
00444