Possibility pass bdd file to load at startup

This commit is contained in:
Grégory Soutadé 2010-08-22 16:35:12 +02:00
parent 9f7d858bc3
commit fb1007bfcb
10 changed files with 80 additions and 51 deletions

1
TODO
View File

@ -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

Binary file not shown.

View File

@ -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é <soutade@gmail.com>\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"

View File

@ -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 <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\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 ""

View File

@ -19,7 +19,7 @@ along with KissCount. If not, see <http://www.gnu.org/licenses/>.
#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)
{

View File

@ -33,7 +33,7 @@ class wxUI;
class KissCount
{
public:
KissCount();
KissCount(const char* bdd_filename);
~KissCount();
std::list<wxString> GetUsers();

View File

@ -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;
// }

View File

@ -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);

View File

@ -35,7 +35,7 @@ along with KissCount. If not, see <http://www.gnu.org/licenses/>.
class Database
{
public:
Database();
Database(const char* filename);
std::list<wxString> GetUsers();
bool IsValidUser(const wxString& user, const wxString& password);

View File

@ -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 !"