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 m_prjtype_sel->lv_types->setSelected(d->lvi_file, true);
00207 }
00208
00209 KexiNewProjectWizard::~KexiNewProjectWizard()
00210 {
00211 delete d;
00212 }
00213
00214 void KexiNewProjectWizard::show()
00215 {
00216 KDialog::centerOnScreen(this);
00217 KWizard::show();
00218 }
00219
00220 void KexiNewProjectWizard::slotLvTypesExecuted(QListViewItem *)
00221 {
00222 next();
00223 }
00224
00225 void KexiNewProjectWizard::slotLvTypesSelected(QListViewItem *item)
00226 {
00227
00228
00229
00230
00231
00232
00233 setAppropriate( m_db_title, item==d->lvi_file );
00234 setAppropriate( m_server_db_name, item==d->lvi_server );
00235 }
00236
00237 void KexiNewProjectWizard::showPage(QWidget *page)
00238 {
00239 if (page==m_prjtype_sel) {
00240 m_prjtype_sel->lv_types->setFocus();
00241 m_prjtype_sel->lv_types->setCurrentItem(m_prjtype_sel->lv_types->currentItem());
00242 } else if (page==m_db_title) {
00243 if (m_db_title->le_caption->text().stripWhiteSpace().isEmpty())
00244 m_db_title->le_caption->setText(i18n("New database"));
00245 m_db_title->le_caption->selectAll();
00246 m_db_title->le_caption->setFocus();
00247 } else if (page==m_conn_sel_widget) {
00248 if (m_prjtype_sel->lv_types->currentItem()==d->lvi_file) {
00249 m_conn_sel->showSimpleConn();
00250 QString fn = KexiUtils::string2FileName( m_db_title->le_caption->text() );
00251 if (!fn.endsWith(".kexi"))
00252 fn += ".kexi";
00253 m_conn_sel->m_fileDlg->setLocationText(fn);
00254 setFinishEnabled(m_conn_sel_widget,true);
00255 m_conn_sel->setFocus();
00256 }
00257 else {
00258 m_conn_sel->showAdvancedConn();
00259 setFinishEnabled(m_conn_sel_widget,false);
00260 m_conn_sel->setFocus();
00261 m_server_db_name->le_caption->selectAll();
00262 }
00263 } else if (page==m_server_db_name) {
00264 if (m_conn_sel->selectedConnectionData()
00265 && (static_cast<KexiDB::ConnectionData*>(d->conndata_to_show) != m_conn_sel->selectedConnectionData())) {
00266 m_project_selector->setProjectSet(0);
00267
00268 d->conndata_to_show = 0;
00269 d->project_set_to_show = new KexiProjectSet(*m_conn_sel->selectedConnectionData(), d->msgHandler);
00270 if (d->project_set_to_show->error()) {
00271 delete d->project_set_to_show;
00272 d->project_set_to_show = 0;
00273 return;
00274 }
00275 d->conndata_to_show = m_conn_sel->selectedConnectionData();
00276
00277 m_project_selector->setProjectSet( d->project_set_to_show );
00278 }
00279 }
00280 KWizard::showPage(page);
00281 }
00282
00283 void KexiNewProjectWizard::next()
00284 {
00285
00286 if (currentPage()==m_db_title) {
00287 if (m_db_title->le_caption->text().stripWhiteSpace().isEmpty()) {
00288 KMessageBox::information(this, i18n("Enter project caption."));
00289 m_db_title->le_caption->setText("");
00290 m_db_title->le_caption->setFocus();
00291 return;
00292 }
00293 } else if (currentPage()==m_conn_sel_widget) {
00294 if (m_prjtype_sel->lv_types->currentItem()==d->lvi_file) {
00295
00296 }
00297 else {
00298
00299 if (!m_conn_sel->selectedConnectionData()) {
00300 KMessageBox::information(this, i18n("Select server connection for a new project."));
00301 return;
00302 }
00303 m_project_selector->label->setText(
00304 d->server_db_name_dblist_lbl_txt.arg(m_conn_sel->selectedConnectionData()->serverInfoString(false)) );
00305 m_server_db_name->le_caption->setFocus();
00306
00307 }
00308 }
00309 KWizard::next();
00310 }
00311
00312 void KexiNewProjectWizard::accept()
00313 {
00314 if (m_prjtype_sel->lv_types->currentItem()==d->lvi_file) {
00315
00316 kdDebug() << "********** sender() " << sender()->className() << endl;
00317 if (sender()==finishButton()) {
00318 kdDebug() << "********** sender()==finishButton() ********" << endl;
00319
00320 if (!m_conn_sel->m_fileDlg->checkFileName()) {
00321 return;
00322 }
00323 }
00324 } else {
00325
00326 if (m_server_db_name->le_caption->text().stripWhiteSpace().isEmpty()) {
00327 KMessageBox::information(this, i18n("Enter project caption."));
00328 m_server_db_name->le_caption->setText("");
00329 m_server_db_name->le_caption->setFocus();
00330 return;
00331 }
00332 QString dbname = m_server_db_name->le_dbname->text().stripWhiteSpace();
00333 if (dbname.isEmpty()) {
00334 KMessageBox::information(this, i18n("Enter project's database name."));
00335 m_server_db_name->le_dbname->setText("");
00336 m_server_db_name->le_dbname->setFocus();
00337 return;
00338 }
00339
00340 if (m_conn_sel->confirmOverwrites() && m_project_selector->projectSet() && m_project_selector->projectSet()
00341 ->findProject( m_server_db_name->le_dbname->text() )) {
00342 if (KMessageBox::Continue!=KMessageBox::warningContinueCancel( this, "<qt>"
00343 +i18n("<b>A project with database name \"%1\" already exists</b>"
00344 "<p>Do you want to delete it and create a new one?")
00345 .arg( m_server_db_name->le_dbname->text() ), QString::null, KStdGuiItem::del(),
00346 QString::null, KMessageBox::Notify|KMessageBox::Dangerous ))
00347 {
00348 m_server_db_name->le_dbname->setFocus();
00349 return;
00350 }
00351 }
00352 }
00353
00354 KWizard::accept();
00355 }
00356
00357 void KexiNewProjectWizard::done(int r)
00358 {
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368 KGlobal::config()->sync();
00369 KWizard::done(r);
00370 }
00371
00372 QString KexiNewProjectWizard::projectDBName() const
00373 {
00374 if (m_prjtype_sel->lv_types->currentItem()==d->lvi_server)
00375 return m_server_db_name->le_dbname->text();
00376 return m_conn_sel->selectedFileName();
00377 }
00378
00379 QString KexiNewProjectWizard::projectCaption() const
00380 {
00381 if (m_prjtype_sel->lv_types->currentItem()==d->lvi_server) {
00382 return m_server_db_name->le_caption->text();
00383 }
00384 return m_db_title->le_caption->text();
00385 }
00386
00387 KexiDB::ConnectionData* KexiNewProjectWizard::projectConnectionData() const
00388 {
00389 if (m_prjtype_sel->lv_types->currentItem()==d->lvi_file)
00390 return 0;
00391 return m_conn_sel->selectedConnectionData();
00392 }
00393
00394 void KexiNewProjectWizard::slotServerDBCaptionTxtChanged(const QString &capt)
00395 {
00396 if (m_server_db_name->le_dbname->text().isEmpty())
00397 d->le_dbname_autofill=true;
00398 if (d->le_dbname_autofill) {
00399 d->le_dbname_txtchanged_disable = true;
00400 QString captionAsId = KexiUtils::string2Identifier(capt);
00401 m_server_db_name->le_dbname->setText(captionAsId);
00402 d->le_dbname_txtchanged_disable = false;
00403 }
00404 }
00405
00406 void KexiNewProjectWizard::slotServerDBNameTxtChanged(const QString &)
00407 {
00408 if (d->le_dbname_txtchanged_disable)
00409 return;
00410 d->le_dbname_autofill = false;
00411 }
00412
00415 void KexiNewProjectWizard::setConfirmOverwrites(bool set)
00416 {
00417 m_conn_sel->setConfirmOverwrites(set);
00418 }
00419
00420
00421 #include "KexiNewProjectWizard.moc"
00422