Fix bugs:

* Database creation failed
	* UsersDialog shown on new user
This commit is contained in:
Grégory Soutadé 2012-04-26 20:45:01 +02:00
parent bfd16a6540
commit 28bb4c49f0
6 changed files with 26 additions and 14 deletions

View File

@ -45,7 +45,7 @@ KissCount::KissCount(int argc, char** argv) : QApplication(argc, argv), _user(0)
catch (std::string s) catch (std::string s)
{ {
_wxUI->close(); _wxUI->close();
throw ; throw s;
} }
_wxUI->ChangeUser(); _wxUI->ChangeUser();

View File

@ -136,24 +136,24 @@ void Database::CreateDatabase()
while (!init_script.atEnd()) while (!init_script.atEnd())
{ {
QByteArray line = file.readLine().trimmed(); QByteArray line = init_script.readLine().trimmed();
QSqlQuery query;
if (line.isEmpty() || line.startsWith("--")) continue; if (line.isEmpty() || line.startsWith("--")) continue;
QSqlQuery query (QString(line), _db); // if (!query.isValid())
// {
// std::cout << QString(line).toStdString() << " is invalid !\n" ;
// continue;
// }
if (!query.isValid()) if (!query.exec(QString(line)))
{
std::cout << QString(line).toStdString() << " is invalid !\n" ;
continue;
}
if (!query.exec())
{ {
QMessageBox::critical(0, _("Error"), _("Error creating original database")); QMessageBox::critical(0, _("Error"), _("Error creating original database"));
init_script.close(); init_script.close();
file.remove(); file.remove();
throw line; std::cout << QString(line).toStdString() << " is invalid !\n" ;
throw QString(line);
} }
} }

View File

@ -67,7 +67,10 @@ UsersDialog::UsersDialog(KissCount* kiss, wxUI *parent) : QDialog(0, Qt::Dialog)
_users->setFocus(); _users->setFocus();
if (users_list.size() == 0) if (users_list.size() == 0)
{
OnNewUser(); OnNewUser();
throw ExceptionNewUser();
}
else else
show(); show();
} }

View File

@ -33,6 +33,8 @@ class UsersDialog : public QDialog
public: public:
UsersDialog(KissCount* kiss, wxUI *parent); UsersDialog(KissCount* kiss, wxUI *parent);
class ExceptionNewUser {};
private slots: private slots:
void OnEnter(); void OnEnter();
void OnOK(); void OnOK();

View File

@ -278,10 +278,17 @@ void wxUI::OnButtonChangeUser()
} }
void wxUI::ChangeUser() void wxUI::ChangeUser()
{
try
{ {
UsersDialog u(_kiss, this); UsersDialog u(_kiss, this);
u.exec(); u.exec();
} }
catch (UsersDialog::ExceptionNewUser e)
{
}
}
void wxUI::OnButtonAbout() void wxUI::OnButtonAbout()
{ {