diff --git a/src/controller/KissCount.cpp b/src/controller/KissCount.cpp index eddd5a6..45866d9 100644 --- a/src/controller/KissCount.cpp +++ b/src/controller/KissCount.cpp @@ -386,7 +386,12 @@ void KissCount::NewUser(const QString& name) /*.shared = */false, /*.blocked = */false, /*._default = */true, - /*.is_owner = */true}; + /*.is_owner = */true, + /* ._virtual = */false, + /* .hidden = */false, + /* .start_date = */QDate::currentDate(), + /* .end_date = */QDate::currentDate().addYears(50), + }; Category cat ; _db->NewUser(name); @@ -717,12 +722,12 @@ QLocale* KissCount::GetLocale() return _wxUI->GetLocale(); } -QString KissCount::GetDateFormat() +QString KissCount::GetDateLocalFormat() { - return _wxUI->GetDateFormat(); + return _wxUI->GetDateLocalFormat(); } QString KissCount::FormatDate(int day, int month, int year) { - return QDate(year, month, day).toString(_wxUI->GetDateFormat()); + return QDate(year, month, day).toString(_wxUI->GetDateLocalFormat()); } diff --git a/src/controller/KissCount.hpp b/src/controller/KissCount.hpp index d30f92a..7a3c4fe 100644 --- a/src/controller/KissCount.hpp +++ b/src/controller/KissCount.hpp @@ -152,7 +152,7 @@ public: bool ChangeDatabase(QString filename); QLocale* GetLocale(); - QString GetDateFormat(); + QString GetDateLocalFormat(); QString FormatDate(int day, int month, int year); private: diff --git a/src/model/Database.cpp b/src/model/Database.cpp index 4d80c3b..bff8c0e 100644 --- a/src/model/Database.cpp +++ b/src/model/Database.cpp @@ -90,16 +90,15 @@ void Database::CreateDatabase() QFile file(sPath); QString message; - message = _("A new database will be created, continue ?"); + message = _("A new database will be created, continue ?"); if (QMessageBox::question(0, "KissCount", message, QMessageBox::Yes|QMessageBox::No) == QMessageBox::No) throw std::string("Abort") ; if (!init_script.exists() || !init_script.open(QIODevice::ReadOnly | QIODevice::Text)) { - QMessageBox::critical(0, _("Error"), _(INIT_SCRIPT " not found, aborting")); + QMessageBox::critical(0, _("Error"), INIT_SCRIPT + _(" not found, aborting")); throw "init.sql not found, aborting"; } - if (!dirname.exists() && !dirname.mkdir(dirname.absolutePath())) { QMessageBox::critical(0, _("Error"), _("Unable to Create ") + dirname.absolutePath() ); @@ -784,8 +783,9 @@ int Database::AddAccount(User* user, Account& ac) { QString req; QSqlQuery query(_db); + int id; - req = "INSERT INTO account ('user', 'name', 'number', 'shared', 'blocked', 'default_account', 'virtual', 'hidden') VALUES " ; + req = "INSERT INTO account ('user', 'name', 'number', 'shared', 'blocked', 'default_account', 'virtual', 'hidden') VALUES " ; req += "('%1', '%2', '%3', '%4', '%5', '%6', '%7', '%8')"; req = req.arg(QString::number(user->_id), ac.name, ac.number, QString::number(ac.shared), QString::number(ac.blocked), QString::number(ac._default), QString::number(ac._virtual), QString::number(ac.hidden)); @@ -799,7 +799,13 @@ int Database::AddAccount(User* user, Account& ac) return 0; } - return query.lastInsertId().toInt(); + id = query.lastInsertId().toInt(); + req = "UPDATE account SET start='%1', end='%2' WHERE id='%3'"; + req = req.arg(ac.start_date.toString("yyyy-MM-dd"), ac.end_date.toString("yyyy-MM-dd"), QString::number(id)); + + EXECUTE_SQL_UPDATE(req, 0); + + return id; } void Database::UpdateAccount(Account& ac) diff --git a/src/view/PreferencesPanel.cpp b/src/view/PreferencesPanel.cpp index bdc74c9..233df83 100644 --- a/src/view/PreferencesPanel.cpp +++ b/src/view/PreferencesPanel.cpp @@ -104,10 +104,10 @@ PreferencesPanel::PreferencesPanel(KissCount* kiss, wxUI *parent, bool lowResolu _accountsGrid = new QTableWidget(); - CalendarDelegate* calendarDelegate = new CalendarDelegate(this, &user->_accounts, true, _kiss->GetDateFormat()); + CalendarDelegate* calendarDelegate = new CalendarDelegate(this, &user->_accounts, true, _kiss->GetDateLocalFormat()); _accountsGrid->setItemDelegateForColumn(ACCOUNT_START, calendarDelegate); - calendarDelegate = new CalendarDelegate(this, &user->_accounts, false, _kiss->GetDateFormat()); + calendarDelegate = new CalendarDelegate(this, &user->_accounts, false, _kiss->GetDateLocalFormat()); _accountsGrid->setItemDelegateForColumn(ACCOUNT_END, calendarDelegate); InitAccounts(user); @@ -370,8 +370,8 @@ void PreferencesPanel::AddAccount(int line, Account ac) _hiddenAccountSignalMapper.setMapping(checkBox, ac.id); connect(checkBox, SIGNAL(stateChanged(int)), &_hiddenAccountSignalMapper, SLOT(map())); - _accountsGrid->setItem(line, ACCOUNT_START, new QTableWidgetItem(ac.start_date.toString(_kiss->GetDateFormat()))); - _accountsGrid->setItem(line, ACCOUNT_END, new QTableWidgetItem(ac.end_date.toString(_kiss->GetDateFormat()))); + _accountsGrid->setItem(line, ACCOUNT_START, new QTableWidgetItem(ac.start_date.toString(_kiss->GetDateLocalFormat()))); + _accountsGrid->setItem(line, ACCOUNT_END, new QTableWidgetItem(ac.end_date.toString(_kiss->GetDateLocalFormat()))); for(int i=0; iitem(line, i)) @@ -403,9 +403,9 @@ void PreferencesPanel::AddAccount(int line, Account ac) else { QDate date = QDate::currentDate(); - _accountsGrid->setItem(line, ACCOUNT_START, new QTableWidgetItem(date.toString(_kiss->GetDateFormat()))); + _accountsGrid->setItem(line, ACCOUNT_START, new QTableWidgetItem(date.toString(_kiss->GetDateLocalFormat()))); date = date.addYears(30); - _accountsGrid->setItem(line, ACCOUNT_END, new QTableWidgetItem(date.toString(_kiss->GetDateFormat()))); + _accountsGrid->setItem(line, ACCOUNT_END, new QTableWidgetItem(date.toString(_kiss->GetDateLocalFormat()))); for(int i=0; iitem(line, i)) diff --git a/src/view/grid/GridAccount.cpp b/src/view/grid/GridAccount.cpp index 1a49631..edfab9c 100644 --- a/src/view/grid/GridAccount.cpp +++ b/src/view/grid/GridAccount.cpp @@ -261,7 +261,7 @@ void GridAccount::LoadOperations(std::vector* operations, int month, ChoiceDelegate* accountEditor = new ChoiceDelegate(this, _accounts, _nbAccounts); setItemDelegateForColumn(ACCOUNT, accountEditor); - DateDelegate* dateEditor = new DateDelegate(this, month+1, year, _kiss->GetDateFormat()); + DateDelegate* dateEditor = new DateDelegate(this, month+1, year, _kiss->GetDateLocalFormat()); setItemDelegateForColumn(OP_DATE, dateEditor); FormulaDelegate* formulaEditor = new FormulaDelegate(this, &_displayedOperations); @@ -1011,7 +1011,7 @@ void GridAccount::OnOperationModified(int row, int col) value = item(row, OP_DATE)->text(); if (value.length()) { - date = QDate::fromString(value, _kiss->GetDateFormat()); + date = QDate::fromString(value, _kiss->GetDateLocalFormat()); new_op.day = date.day()-1; new_op.month = date.month()-1; new_op.year = date.year(); diff --git a/src/view/wxUI.cpp b/src/view/wxUI.cpp index cc02b9c..1f681a5 100644 --- a/src/view/wxUI.cpp +++ b/src/view/wxUI.cpp @@ -378,7 +378,7 @@ void wxUI::NeedReload(KissPanel* panel) } } -QString wxUI::GetDateFormat() +QString wxUI::GetDateLocalFormat() { return _curLanguage.dateFormat; } diff --git a/src/view/wxUI.hpp b/src/view/wxUI.hpp index c43ebb4..5bb71f4 100644 --- a/src/view/wxUI.hpp +++ b/src/view/wxUI.hpp @@ -75,7 +75,7 @@ public: void NeedReload(KissPanel* panel); QLocale* GetLocale() {return _locale;} - QString GetDateFormat(); + QString GetDateLocalFormat(); QString _language; SupportedLanguages::language _curLanguage;