Skip to content

Commit

Permalink
Fix the initial setup workflow in the setup assistant.
Browse files Browse the repository at this point in the history
  • Loading branch information
dragotin committed Jan 1, 2018
1 parent 77309b9 commit fc6337d
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 31 deletions.
53 changes: 31 additions & 22 deletions src/setupassistant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@ QUrl SqLiteDetailsPage::url()
return QUrl::fromLocalFile(fileName);
}

bool SqLiteDetailsPage::validatePage()
{
return qobject_cast<SetupAssistant*>(wizard())->handleSqLiteDetails();
}

int SqLiteDetailsPage::nextId() const
{
if( KraftDB::self()->databaseExists() ) {
Expand Down Expand Up @@ -164,6 +169,12 @@ int MysqlDetailsPage::nextId() const
}
}

bool MysqlDetailsPage::validatePage()
{
bool re = qobject_cast<SetupAssistant*>(wizard())->handleMysqlDetails();
return re;
}

// ---------------------------------------------------------------------------

CreateDbPage::CreateDbPage(QWidget *parent)
Expand Down Expand Up @@ -248,8 +259,6 @@ UpgradeDbPage::UpgradeDbPage(QWidget *parent)
setTitle(i18n("Upgrade the Database"));
QVBoxLayout *vbox = new QVBoxLayout;
setLayout( vbox );
//TODO PORT QT5 vbox->setSpacing( QDialog::spacingHint() );
//TODO PORT QT5 vbox->setMargin( QDialog::marginHint() );

QWidget *w = new QWidget;
vbox->addWidget( w );
Expand Down Expand Up @@ -354,6 +363,11 @@ void FinalStatusPage::slotSetStatusText( const QString& txt )
ui.mStatusText->setText( txt );
}

int FinalStatusPage::nextId() const
{
return -1; // final page
}

// ---------------------------------------------------------------------------

SetupAssistant::SetupAssistant( QWidget *parent )
Expand Down Expand Up @@ -410,18 +424,18 @@ QString SetupAssistant::defaultSqliteFilename() const

void SetupAssistant::slotCurrentPageChanged( int currId )
{
qDebug() << "Page changed to " << currId;

if( currId == dbSelectPageNo ) {
handleDatabaseBackendSelect(); // does nothing currently
} else if( currId == mySqlPageNo ) {
// get the mysql datails
handleMysqlDetails();
} else if( currId == mySqlPageNo) {
// get the sqlite filename
handleSqLiteDetails();
// TODO: set the mysql datails
} else if( currId == sqlitePageNo) {
// TODO set the sqlite filename
} else if( currId == createDbPageNo ) {
if( mSqlBackendDriver == QLatin1String("QMYSQL") ) {
const QString dbName = field("MySqlDbName").toString();
if(!KraftDB::self()->dbConnect( QLatin1String("QMYSQL"),
field("MySqlDbName").toString(),
dbName,
field("MySqlUser").toString(),
field("MySqlHost").toString(),
field("MySqlPwd").toString() ) ) {
Expand Down Expand Up @@ -477,7 +491,8 @@ void SetupAssistant::done( int result )
if( selectedDriver == "QMYSQL" ) {
DatabaseSettings::self()->setDbDatabaseName( field("MySqlDbName").toString() );
DatabaseSettings::self()->setDbUser( field("MySqlUser").toString() );
DatabaseSettings::self()->setDbServerName( field("MySqlHost").toString() );
const QString host = field("MySqlHost").toString();
DatabaseSettings::self()->setDbServerName( host );
DatabaseSettings::self()->setDbPassword( field("MySqlPwd").toString() );
}
DatabaseSettings::self()->writeConfig();
Expand Down Expand Up @@ -649,11 +664,7 @@ void SetupAssistant::startDatabaseCreation()
disconnect( KraftDB::self(), SIGNAL(processedSqlCommand(bool)),0 ,0 );
}

void SetupAssistant::handleDatabaseBackendSelect() const
{
}

void SetupAssistant::handleSqLiteDetails()
bool SetupAssistant::handleSqLiteDetails()
{
DbSelectPage *mDbSelectPage = qobject_cast<DbSelectPage*>(page(dbSelectPageNo));

Expand All @@ -663,12 +674,12 @@ void SetupAssistant::handleSqLiteDetails()

mSqlBackendDriver = mDbSelectPage->selectedDriver();
// qDebug () << "The database driver is " << mSqlBackendDriver;
if( KraftDB::self()->dbConnect( mSqlBackendDriver, file ) ) {
// FIXME error handling
}
bool re = KraftDB::self()->dbConnect( mSqlBackendDriver, file );

return re;
}

void SetupAssistant::handleMysqlDetails()
bool SetupAssistant::handleMysqlDetails()
{
DbSelectPage *mDbSelectPage = qobject_cast<DbSelectPage*>(page(dbSelectPageNo));
mSqlBackendDriver = mDbSelectPage->selectedDriver();
Expand All @@ -678,9 +689,7 @@ void SetupAssistant::handleMysqlDetails()
QString userName = field("MySqlUser").toString();
QString password = field("MySqlPwd").toString();

if( KraftDB::self()->dbConnect( mSqlBackendDriver, databaseName, userName, hostName, password ) ) {
// FIXME error handling
}
return KraftDB::self()->dbConnect( mSqlBackendDriver, databaseName, userName, hostName, password );
}

bool SetupAssistant::init( Mode mode )
Expand Down
20 changes: 11 additions & 9 deletions src/setupassistant.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,17 @@ class DbSelectPage:public QWizardPage

class SqLiteDetailsPage:public QWizardPage
{
Q_OBJECT
Q_OBJECT

public:
SqLiteDetailsPage( QWidget *parent = 0 );
SqLiteDetailsPage( QWidget *parent = 0 );

QUrl url();
int nextId() const;
QUrl url();
int nextId() const;
bool validatePage();

protected slots:
private:
Ui::sqLiteDetailsForm ui;
Ui::sqLiteDetailsForm ui;
};

// ---------------------------------------------------------------------------
Expand All @@ -92,6 +92,7 @@ class MysqlDetailsPage:public QWizardPage

void reloadSettings();
int nextId() const;
bool validatePage();

private:
Ui::mySqlDetailsForm ui;
Expand Down Expand Up @@ -177,6 +178,7 @@ class FinalStatusPage:public QWizardPage

public:
FinalStatusPage( QWidget *parent = 0 );
int nextId() const;

public slots:
void slotSetStatusText( const QString& );
Expand Down Expand Up @@ -208,16 +210,16 @@ class SetupAssistant: public QWizard

~SetupAssistant();

bool handleSqLiteDetails();
bool handleMysqlDetails();

public slots:
void done( int );

private slots:
void slotCurrentPageChanged(int currId);

private:
void handleDatabaseBackendSelect() const;
void handleSqLiteDetails();
void handleMysqlDetails();
void startDatabaseCreation();
void startDatabaseUpdate();
void finalizePage();
Expand Down

0 comments on commit fc6337d

Please sign in to comment.