From fb1007bfcb3190849ea73188ec722ab27aa3bd09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9gory=20Soutad=C3=A9?= Date: Sun, 22 Aug 2010 16:35:12 +0200 Subject: [PATCH] Possibility pass bdd file to load at startup --- TODO | 1 - ressources/po/french.mo | Bin 6084 -> 6164 bytes ressources/po/french.po | 25 +++++++++++++------ ressources/po/kisscount.pot | 19 ++++++++++----- src/controller/KissCount.cpp | 4 +-- src/controller/KissCount.h | 2 +- src/main.cpp | 30 +++-------------------- src/model/Database.cpp | 46 ++++++++++++++++++++++++++++++----- src/model/Database.h | 2 +- tools/package.sh | 2 +- 10 files changed, 80 insertions(+), 51 deletions(-) diff --git a/TODO b/TODO index b9c404f..7256327 100644 --- a/TODO +++ b/TODO @@ -14,7 +14,6 @@ Others translation Handle bad SQL return Category color/font Button tooltip not translated -Do not consider account transferts into statistics =============================================================== Next version diff --git a/ressources/po/french.mo b/ressources/po/french.mo index 85718faf6fab3e471c9d4700abcca667d15825bd..cf05a6786783adbf0dc85e75e921af1227dc76db 100644 GIT binary patch delta 2181 zcmXZce`wTo9LMp`t!;Pbwb`7zn>O=?o=2AZ;c}3=A}3Rem1YHt3EkQ)*S5R0yJ--0 zxCoa0A@wyBZDp8YB+1af#57cNh>#1UOejnILx!!K7BeEBukC$&Ki|jq`}uyp@6Y@5 z{@mS}>YX*YUuNZh?D%A96}02`IX8r@eolNY2A!kJjp9tagvEFrXX9-w!r%-VMo{;a zSb){2P|GlY4R}8`A#rkUqdjQD5D&UgfwrO&+J^J-Q|mv0h1`!Ihx?wB0{@J9?;0x3 zO;o~@W{^(x&*4Oui(vutyBaP^=%~jBa4l+r7SzC3P=UKpE9=L6eAoI1Q7iliwcBaXAIC;i!fzw5 zxB=9-9mwH!bBf`Ys0Ca=Rpv?&_0QwtcRD!Sbxz830=0LAj8^Hws0vh~5{aV{ufVPj&*AH_IcMor)&y2gi4<4aL-=bMX>gmP{f7b@v$vlYv@&mxE0&PjoWa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2YBY-<4;g z&!Rhf0i9rLbQij?-RO}Vz#M+-v%mjyRQ#tar`Lt#(B}ncMsAPKYtWPrV-voMPEgDi}ZyxRNUzhHsZ&~afMNIhbPd0C($D~k6ar(|;bwFJBWQq^q6vET+oQYCl)i_K--C|d zhsHUWO?pzZu6&4UD}~n3PMJq}l(L+%F?ltWUAmr{A72`rs7>Ckf=YnIO$9;EL)chr?Zt0+Lmlfx0LlJrS$epUmVkgE_op7 puU?YrkF9etPkChj-s<}*lYHIbR3TR=w6(VGKU=pkm5gLx`yVQex8?u< diff --git a/ressources/po/french.po b/ressources/po/french.po index e042ef6..a9ec922 100644 --- a/ressources/po/french.po +++ b/ressources/po/french.po @@ -2,7 +2,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2010-08-21 11:44+0200\n" +"POT-Creation-Date: 2010-08-22 16:33+0200\n" "PO-Revision-Date: \n" "Last-Translator: Soutadé \n" "Language-Team: \n" @@ -36,7 +36,7 @@ msgstr " existe déjà " msgid " entries found" msgstr " entrées trouvées" -#: src/model/Database.cpp:102 +#: src/model/Database.cpp:130 msgid " not found, aborting" msgstr " non trouvé, arrêt" @@ -207,8 +207,12 @@ msgstr "Décroissant" msgid "Description" msgstr "Description" -#: src/model/Database.cpp:102 -#: src/model/Database.cpp:125 +#: src/model/Database.cpp:84 +#: src/model/Database.cpp:91 +#: src/model/Database.cpp:109 +#: src/model/Database.cpp:130 +#: src/model/Database.cpp:138 +#: src/model/Database.cpp:159 #: src/view/PasswordDialog.cpp:72 #: src/view/PasswordDialog.cpp:78 #: src/view/PreferencesPanel.cpp:336 @@ -228,7 +232,7 @@ msgstr "Description" msgid "Error" msgstr "Erreur" -#: src/model/Database.cpp:125 +#: src/model/Database.cpp:159 msgid "Error creating original database" msgstr "Erreur durant la création de la base de données initiale" @@ -236,7 +240,7 @@ msgstr "Erreur durant la création de la base de données initiale" msgid "Final value" msgstr "Valeur finale" -#: src/model/Database.cpp:260 +#: src/model/Database.cpp:294 #: src/controller/KissCount.cpp:276 #: src/view/GridAccount.cpp:126 msgid "Fix" @@ -352,7 +356,7 @@ msgstr "Nouvel utilisateur" msgid "New password " msgstr "Nouveau mot de passe" -#: src/model/Database.cpp:96 +#: src/model/Database.cpp:124 msgid "No database found, creating a new one" msgstr "Aucune base de données trouvée, création d'une nouvelle" @@ -466,6 +470,13 @@ msgstr "Total Crédit" msgid "Total Debit" msgstr "Total Débit" +#: src/model/Database.cpp:84 +#: src/model/Database.cpp:91 +#: src/model/Database.cpp:109 +#: src/model/Database.cpp:138 +msgid "Unable to open Database" +msgstr "Impossible d'ouvrir la base de données" + #: src/controller/KissCount.cpp:284 msgid "Unexpected" msgstr "Exceptionnel" diff --git a/ressources/po/kisscount.pot b/ressources/po/kisscount.pot index 3fd6a00..106d59b 100644 --- a/ressources/po/kisscount.pot +++ b/ressources/po/kisscount.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2010-08-21 11:44+0200\n" +"POT-Creation-Date: 2010-08-22 16:33+0200\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -30,7 +30,7 @@ msgstr "" msgid " entries found" msgstr "" -#: src/model/Database.cpp:102 +#: src/model/Database.cpp:130 msgid " not found, aborting" msgstr "" @@ -190,7 +190,9 @@ msgstr "" msgid "Description" msgstr "" -#: src/model/Database.cpp:102 src/model/Database.cpp:125 +#: src/model/Database.cpp:84 src/model/Database.cpp:91 +#: src/model/Database.cpp:109 src/model/Database.cpp:130 +#: src/model/Database.cpp:138 src/model/Database.cpp:159 #: src/view/PasswordDialog.cpp:72 src/view/PasswordDialog.cpp:78 #: src/view/PreferencesPanel.cpp:336 src/view/PreferencesPanel.cpp:359 #: src/view/PreferencesPanel.cpp:378 src/view/PreferencesPanel.cpp:468 @@ -202,7 +204,7 @@ msgstr "" msgid "Error" msgstr "" -#: src/model/Database.cpp:125 +#: src/model/Database.cpp:159 msgid "Error creating original database" msgstr "" @@ -210,7 +212,7 @@ msgstr "" msgid "Final value" msgstr "" -#: src/model/Database.cpp:260 src/controller/KissCount.cpp:276 +#: src/model/Database.cpp:294 src/controller/KissCount.cpp:276 #: src/view/GridAccount.cpp:126 msgid "Fix" msgstr "" @@ -321,7 +323,7 @@ msgstr "" msgid "New password " msgstr "" -#: src/model/Database.cpp:96 +#: src/model/Database.cpp:124 msgid "No database found, creating a new one" msgstr "" @@ -427,6 +429,11 @@ msgstr "" msgid "Total Debit" msgstr "" +#: src/model/Database.cpp:84 src/model/Database.cpp:91 +#: src/model/Database.cpp:109 src/model/Database.cpp:138 +msgid "Unable to open Database" +msgstr "" + #: src/controller/KissCount.cpp:284 msgid "Unexpected" msgstr "" diff --git a/src/controller/KissCount.cpp b/src/controller/KissCount.cpp index 08ad27d..1238033 100644 --- a/src/controller/KissCount.cpp +++ b/src/controller/KissCount.cpp @@ -19,7 +19,7 @@ along with KissCount. If not, see . #include "KissCount.h" -KissCount::KissCount() : _user(NULL) +KissCount::KissCount(const char* bdd_filename) : _user(NULL) { _wxUI = new wxUI(this, wxT("KissCount"), wxPoint(50, 50), wxSize(1024, 768)); @@ -31,7 +31,7 @@ KissCount::KissCount() : _user(NULL) try { - _db = new Database(); + _db = new Database(bdd_filename); } catch (std::string s) { diff --git a/src/controller/KissCount.h b/src/controller/KissCount.h index a5be452..b8063cc 100644 --- a/src/controller/KissCount.h +++ b/src/controller/KissCount.h @@ -33,7 +33,7 @@ class wxUI; class KissCount { public: - KissCount(); + KissCount(const char* bdd_filename); ~KissCount(); std::list GetUsers(); diff --git a/src/main.cpp b/src/main.cpp index 7a4d950..70cb491 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -25,7 +25,10 @@ class MyApp: public wxApp { try { - new KissCount(); + if (argc == 2) + new KissCount(wxString(argv[1]).mb_str()); + else + new KissCount(NULL); } catch (std::string s) { @@ -38,28 +41,3 @@ class MyApp: public wxApp }; IMPLEMENT_APP(MyApp); - -// bool MyApp::OnInit() -// { -// Main app; - -// MyFrame *frame = new MyFrame( _("Hello World"), wxPoint(50, 50), wxSize(1024, 768) ); -// AccountPanel* f = new AccountPanel(frame); -// frame->Show(true); -// SetTopWindow(frame); - -// frame->Centre(); -// frame->Disable(); - -// try -// { -// app.Init(); -// } -// catch (std::string s) -// { -// std::cout << "Error " << s << "\n"; -// frame->Close(true); -// } -// frame->Enable(); -// return true; -// } diff --git a/src/model/Database.cpp b/src/model/Database.cpp index dd48480..3e9497b 100644 --- a/src/model/Database.cpp +++ b/src/model/Database.cpp @@ -71,19 +71,47 @@ static inline wxString DoubleToString(double d) return res; } -Database::Database() +Database::Database(const char* filename) { std::ifstream bdd_file; - bdd_file.open(BDD_FILE); - - if (!bdd_file) + if (filename) { - CreateDatabase(); + bdd_file.open(filename, std::ifstream::in); + + if (!bdd_file.good()) + { + wxMessageBox(_("Unable to open Database"), _("Error"), wxICON_ERROR | wxOK ); + throw std::string("Unable to open ") + filename; + } + + _db.Open(wxString(filename, wxConvUTF8)); + if (!_db.IsOpen()) + { + wxMessageBox(_("Unable to open Database"), _("Error"), wxICON_ERROR | wxOK ); + throw std::string("Unable to open ") + filename; + } } else - _db.Open(wxT(BDD_FILE)); + { + // If default BDD file, assume this can be the first load + bdd_file.open(BDD_FILE, std::ifstream::in); + if (!bdd_file.good()) + { + CreateDatabase(); + } + else + { + _db.Open(wxT(BDD_FILE)); + if (!_db.IsOpen()) + { + wxMessageBox(_("Unable to open Database"), _("Error"), wxICON_ERROR | wxOK ); + throw std::string("Unable to open ") + BDD_FILE; + } + } + } + bdd_file.close(); } @@ -105,6 +133,12 @@ void Database::CreateDatabase() _db.Open(wxT(BDD_FILE)); + if (!_db.IsOpen()) + { + wxMessageBox(_("Unable to open Database"), _("Error"), wxICON_ERROR | wxOK ); + throw std::string("Unable to open ") + BDD_FILE; + } + do { getline(init_script, line); diff --git a/src/model/Database.h b/src/model/Database.h index 05311d5..7d211fc 100644 --- a/src/model/Database.h +++ b/src/model/Database.h @@ -35,7 +35,7 @@ along with KissCount. If not, see . class Database { public: - Database(); + Database(const char* filename); std::list GetUsers(); bool IsValidUser(const wxString& user, const wxString& password); diff --git a/tools/package.sh b/tools/package.sh index 1368036..1be18af 100755 --- a/tools/package.sh +++ b/tools/package.sh @@ -11,9 +11,9 @@ make clean fi make || (echo "Compilation failed" ; exit 1) mkdir -p $DIR/lib -find $DIR -type f -exec strip \{\} \; cp -r lib/freechart/lib/* lib/wxsqlite3-1.9.9/lib/* $DIR/lib cp -r kc init.sql ressources tools/launch_kc.sh TODO CONTRIBUTORS COPYING README README.fr $DIR +find $DIR -type f -executable -exec strip \{\} \; tar -jcf $FILE $DIR rm -rf $DIR echo "Packaged !" \ No newline at end of file