From f6e0f92ad7086cb2fd39a3f4b74c205e05d55dfd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9gory=20Soutad=C3=A9?= Date: Sun, 4 Sep 2011 11:21:30 +0200 Subject: [PATCH] Work on wxUI and UsersDialog --- src/controller/KissCount.cpp | 13 ++-- src/controller/KissCount.hpp | 2 +- src/main.cpp | 7 +- src/view/UsersDialog.cpp | 128 +++++++++++++++++++++++++++++++++++ src/view/UsersDialog.hpp | 48 +++++++++++++ src/view/wxUI.cpp | 69 ++++++++++--------- src/view/wxUI.hpp | 6 +- 7 files changed, 224 insertions(+), 49 deletions(-) create mode 100644 src/view/UsersDialog.cpp create mode 100644 src/view/UsersDialog.hpp diff --git a/src/controller/KissCount.cpp b/src/controller/KissCount.cpp index 2aea1fd..14c6da5 100644 --- a/src/controller/KissCount.cpp +++ b/src/controller/KissCount.cpp @@ -28,21 +28,18 @@ std::vector * KissCount::_importEngines; std::vector * KissCount::_exportEngines; -KissCount::KissCount(const char* bdd_filename) : QApplication(0, 0), _user(0) +KissCount::KissCount(int argc, char** argv) : QApplication(argc, argv), _user(0) { - //wxRect rect = wxDisplay().GetGeometry(); - _wxUI = new wxUI(this, "KissCount"); //_wxUI->SetLanguage(wxLocale::GetSystemLanguage()); - _wxUI->show(); - // _wxUI->Centre(); - // _wxUI->Disable(); + _wxUI->showMaximized(); + _wxUI->setDisabled(true); try { - _db = new Database(bdd_filename, this); + _db = new Database((argc == 2) ? argv[1] : 0, this); } catch (std::string s) { @@ -51,7 +48,7 @@ KissCount::KissCount(const char* bdd_filename) : QApplication(0, 0), _user(0) } _wxUI->ChangeUser(); - //_wxUI->enable(); + _wxUI->setDisabled(false); } KissCount::~KissCount() diff --git a/src/controller/KissCount.hpp b/src/controller/KissCount.hpp index 018ac22..c5c0fbf 100644 --- a/src/controller/KissCount.hpp +++ b/src/controller/KissCount.hpp @@ -54,7 +54,7 @@ class ExportEngine; class KissCount : public QApplication { public: - KissCount(const char* bdd_filename); + KissCount(int argc, char** argv); ~KissCount(); std::list GetUsers(); diff --git a/src/main.cpp b/src/main.cpp index 5479728..d01cc14 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -21,14 +21,11 @@ #include -int main(int argc, const char *argv[]) +int main(int argc, char *argv[]) { try { - if (argc == 2) - return KissCount(argv[1]).exec(); - else - return KissCount(0).exec(); + return KissCount(argc, argv).exec(); } catch (std::string s) { diff --git a/src/view/UsersDialog.cpp b/src/view/UsersDialog.cpp new file mode 100644 index 0000000..6cb27c1 --- /dev/null +++ b/src/view/UsersDialog.cpp @@ -0,0 +1,128 @@ +/* + Copyright 2010-2011 Grégory Soutadé + + This file is part of KissCount. + + KissCount is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + KissCount is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with KissCount. If not, see . +*/ +#include +#include +#include + +#include +#include +#include +#include +#include + +#include "UsersDialog.hpp" + +UsersDialog::UsersDialog(KissCount* kiss, wxUI *parent) : QDialog(0, Qt::Dialog), _kiss(kiss), _wxUI(parent) +{ + QGridLayout* gridLayout; + + setWindowTitle(_("Users")); + setModal(true); + + gridLayout = new QGridLayout(this); + + gridLayout->addWidget(new QLabel(_("User "), this), 0, 0); + _users = new QComboBox(this); + gridLayout->addWidget(_users, 0, 1); + + gridLayout->addWidget(new QLabel(_("Password "), this), 1, 0); + _password = new QLineEdit(this); + _password->setEchoMode(QLineEdit::Password); + gridLayout->addWidget(_password, 1, 1); + + QPushButton* ok = new QPushButton(_("OK"), this); + QPushButton* cancel = new QPushButton(_("Cancel"), this); + QPushButton* newUser = new QPushButton(_("New User"), this); + gridLayout->addWidget(ok, 3, 1); + gridLayout->addWidget(cancel, 3, 2); + gridLayout->addWidget(newUser, 3, 3); + + connect(ok, SIGNAL(clicked()), this, SLOT(OnOK())); + connect(cancel, SIGNAL(clicked()), this, SLOT(OnCancel())); + connect(newUser, SIGNAL(clicked()), this, SLOT(OnNewUser())); + + std::list users_list = _kiss->GetUsers(); + + for(std::list::iterator i = users_list.begin(); i != users_list.end(); i++) + { + _users->addItem(*i); + } + + _users->setFocus(); + + if (users_list.size() == 0) + OnNewUser(); + else + show(); +} + +void UsersDialog::OnEnter() +{ + OnOK(); +} + +void UsersDialog::OnOK() +{ + QString curUser = _users->currentText(); + + // No users in database + if (!curUser.size()) + return; + + if (!_kiss->IsValidUser(curUser, _password->text())) + { + QMessageBox::critical(0, _("Error"), _("Invalid password")); + _password->clear(); + _password->setFocus(); + } + else + { + _kiss->LoadUser(curUser); + close(); + } +} + +void UsersDialog::OnCancel() +{ + close(); +} + +void UsersDialog::OnNewUser() +{ + QString name; + bool ok; + + name = QInputDialog::getText (0, _("New User"), "", QLineEdit::Normal, "", &ok); + + if (!ok) + return; + + if (!name.size()) return; + + if (_kiss->UserExists(name)) + { + QMessageBox::critical(0, _("Error"), _("User ") + name + _(" already exists")); + return; + } + + _kiss->NewUser(name); + _kiss->LoadUser(name); + + close(); +} diff --git a/src/view/UsersDialog.hpp b/src/view/UsersDialog.hpp new file mode 100644 index 0000000..5b37a4f --- /dev/null +++ b/src/view/UsersDialog.hpp @@ -0,0 +1,48 @@ +/* + Copyright 2010-2011 Grégory Soutadé + + This file is part of KissCount. + + KissCount is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + KissCount is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with KissCount. If not, see . +*/ + +#ifndef USERSDIALOG_H +#define USERSDIALOG_H + +#include +#include +#include + +#include "wxUI.hpp" + +class UsersDialog : public QDialog +{ + Q_OBJECT; + +public: + UsersDialog(KissCount* kiss, wxUI *parent); + +private slots: + void OnEnter(); + void OnOK(); + void OnCancel(); + void OnNewUser(); + +private: + KissCount* _kiss; + wxUI* _wxUI; + QComboBox* _users; + QLineEdit* _password; +}; +#endif diff --git a/src/view/wxUI.cpp b/src/view/wxUI.cpp index 41c4ae9..c6f7409 100644 --- a/src/view/wxUI.cpp +++ b/src/view/wxUI.cpp @@ -34,6 +34,7 @@ #include "grid/wxGridCellButtonEditor.hpp" */ #include "wxUI.hpp" +#include "view.hpp" #include "UsersDialog.hpp" @@ -55,31 +56,33 @@ wxUI::wxUI(KissCount* kiss, const QString& title) : QFrame(0), _kiss(kiss), _curPanel(0), _locale(0), _needReload(false) { + QPushButton* button; + setWindowTitle(title); - // _vbox = new wxBoxSizer(wxVERTICAL); - // _buttonsBox = new wxBoxSizer(wxHORIZONTAL); - // // ButtonPanel* buttons = new ButtonPanel(_kiss, this); - // // wxMenu *menuFile = new wxMenu; + _vbox = new QVBoxLayout; + _buttonsBox = new QHBoxLayout; - // // menuFile->Append( ID_About, wxT("&About...") ); - // // menuFile->AppendSeparator(); - // // menuFile->Append( ID_Quit, wxT("E&xit") ); + button = new QPushButton(QIcon(CHANGE_USER_ICON), "", this); + button->setFixedSize(128, 128); + button->setIconSize(QSize(128, 128)); + connect(button, SIGNAL(clicked()), this, SLOT(OnButtonChangeUser())); + _buttonsBox->addWidget(button); - // // wxMenuBar *menuBar = new wxMenuBar; - // // menuBar->Append( menuFile, wxT("&File") ); + button = new QPushButton(QIcon(ABOUT_ICON), "", this); + button->setFixedSize(128, 128); + button->setIconSize(QSize(128, 128)); + connect(button, SIGNAL(clicked()), this, SLOT(OnButtonAbout())); + _buttonsBox->addWidget(button); - // // SetMenuBar( menuBar ); + button = new QPushButton(QIcon(QUIT_ICON), "", this); + button->setFixedSize(128, 128); + button->setIconSize(QSize(128, 128)); + connect(button, SIGNAL(clicked()), this, SLOT(OnButtonQuit())); + _buttonsBox->addWidget(button); - // // CreateStatusBar(); - // // SetStatusText( wxT("Welcome to wxWidgets!") ); - // _buttonsBox->Add(new wxBitmapButton(this, BUTTON_CHANGE_USER_ID, wxBitmap(wxT(CHANGE_USER_ICON), wxBITMAP_TYPE_PNG), wxDefaultPosition, wxSize(128, 128))); - // _buttonsBox->Add(new wxBitmapButton(this, BUTTON_ABOUT_ID, wxBitmap(wxT(ABOUT_ICON), wxBITMAP_TYPE_PNG), wxDefaultPosition, wxSize(128, 128))); - // _buttonsBox->Add(new wxBitmapButton(this, BUTTON_QUIT_ID, wxBitmap(wxT(QUIT_ICON), wxBITMAP_TYPE_PNG), wxDefaultPosition, wxSize(128, 128))); - - // SetSizer(_vbox); - - // _vbox->Add(_buttonsBox, 0, wxGROW); + _vbox->addLayout(_buttonsBox); + setLayout(_vbox); } wxUI::~wxUI() @@ -129,18 +132,18 @@ bool wxUI::SetLanguage(QString language) // res = false; // } -// months[0] = _("january"); -// months[1] = _("february"); -// months[2] = _("marchpp"); -// months[3] = _("april"); -// months[4] = _("may"); -// months[5] = _("june"); -// months[6] = _("july"); -// months[7] = _("august"); -// months[8] = _("september"); -// months[9] = _("october"); -// months[10] = _("november"); -// months[11] = _("december") ; + months[0] = _("january"); + months[1] = _("february"); + months[2] = _("marchpp"); + months[3] = _("april"); + months[4] = _("may"); + months[5] = _("june"); + months[6] = _("july"); + months[7] = _("august"); + months[8] = _("september"); + months[9] = _("october"); + months[10] = _("november"); + months[11] = _("december") ; return res; } @@ -258,12 +261,12 @@ void wxUI::ChangeUser() void wxUI::OnButtonAbout() { - QMessageBox::information(this, "KissCount " APP_VERSION, _("Personal accounting software\n\nhttp://indefero.soutade.fr/p/kisscount/\n\nLicenced under GNU GPL v3\n\nCopyright (C) 2010-2011 Grégory Soutadé")); + QMessageBox::information(0, "KissCount " APP_VERSION, _("Personal accounting software\n\nhttp://indefero.soutade.fr/p/kisscount/\n\nLicenced under GNU GPL v3\n\nCopyright (C) 2010-2011 Grégory Soutadé")); } void wxUI::OnButtonQuit() { - if (QMessageBox::question(this, "KissCount", _("Quit KissCount ?"), QMessageBox::Yes|QMessageBox::No, QMessageBox::No) == QMessageBox::Yes) + if (QMessageBox::question(0, "KissCount", _("Quit KissCount ?"), QMessageBox::Yes|QMessageBox::No, QMessageBox::No) == QMessageBox::Yes) close(); } diff --git a/src/view/wxUI.hpp b/src/view/wxUI.hpp index 5dadfe6..318b5a0 100644 --- a/src/view/wxUI.hpp +++ b/src/view/wxUI.hpp @@ -24,6 +24,7 @@ class ImportEngine; #include #include +#include #include #include #include @@ -33,7 +34,7 @@ class ImportEngine; #include #include -#define _(s) QObject::tr(s) +#define _(s) QObject::trUtf8(s) class KissCount; class KissPanel; @@ -77,7 +78,8 @@ private slots: private: KissCount *_kiss; - QVBoxLayout *_vbox, *_buttonsBox; + QVBoxLayout *_vbox; + QHBoxLayout *_buttonsBox; KissPanel *_curPanel; std::vector _panels; std::vector _buttons;