From 104002c3014b14778515b50266a7de4a76ba0123 Mon Sep 17 00:00:00 2001 From: Sagi Dayan Date: Sun, 31 Aug 2014 20:51:27 +0300 Subject: [PATCH 1/3] merge conflict on my master - fix --- src/data/savedata.cpp | 58 +++++++++++++++++++++++++++++++++++++++++++ src/data/savedata.h | 5 ++++ 2 files changed, 63 insertions(+) diff --git a/src/data/savedata.cpp b/src/data/savedata.cpp index 4cab10a..f8f8960 100644 --- a/src/data/savedata.cpp +++ b/src/data/savedata.cpp @@ -48,6 +48,18 @@ bool SaveData::save(QString username, QString password) return true; } +bool SaveData::saveCal(QString cal) +{ + std::cout << "Trying to save data..." << std::endl; + QFile file(FILE_NAME); + if(!file.open(QIODevice::WriteOnly|QIODevice::Text)) + return false; /* IO Error! */ + QTextStream output(&file); + QString text = output.readAll(); + QString line = text. + +} + /** * @brief Deletes the data from file, and sets status tag to false. * @return true if success @@ -97,6 +109,36 @@ QString SaveData::getPassword() } +/** + * @brief Getiing the last calendar user hase been viewing. + * @return QString - cal - in format [year]-[semester] + */ +QString SaveData::gatCal() +{ + QString cal = ""; + QFile* file = new QFile(FILE_NAME); + /* Opening file for read */ + if(file->open(QIODevice::ReadOnly|QIODevice::Text)) + cal = getValViaTag("cal", file); + file->close(); + return cal; +} + +/** + * @brief Getiing the users local - default is the OS local + * @return QString - local (heb/en/default) + */ +QString SaveData::getLocal() +{ + QString local = ""; + QFile* file = new QFile(FILE_NAME); + /* Opening file for read */ + if(file->open(QIODevice::ReadOnly|QIODevice::Text)) + local = getValViaTag("local", file); + file->close(); + return local; +} + /** * @brief This is A functions that will init the tags file. * if it exist - do nothing @@ -198,3 +240,19 @@ QString SaveData::deHashPasword(QString pass) } return password; } + +bool SaveData::isTagLine(QString line, QString tag) +{ + for(int i = 0 ; i< line.length() ;++i) + { + if(line[i] == '[' && line[i+1] != '/') //get open tag at begining of line and not end of tag ("[/") + { + i++; + tmpTag = line.mid(i, tag.length()); + if(tmpTag == tag) + return true; + } + return false; + } + return false; +} diff --git a/src/data/savedata.h b/src/data/savedata.h index e348aa6..cb8b52b 100644 --- a/src/data/savedata.h +++ b/src/data/savedata.h @@ -41,14 +41,19 @@ class SaveData public: bool static isSaved(); bool static save(QString username, QString password); + bool static saveCal(QString cal); + bool static saveLocal(QString local); bool static deleteData(); QString static getUsername(); QString static getPassword(); + QString static gatCal(); + QString static getLocal(); void static init(); private: QString static getValViaTag(QString tag, QFile *file); QString static hashPassword(QString pass); QString static deHashPasword(QString pass); + bool static isTagLine(QString line, QString tag); }; #endif // SAVEDATA_H From 1a3747956a85c29ada1996531f481dff178824f3 Mon Sep 17 00:00:00 2001 From: Sagi Dayan Date: Sun, 31 Aug 2014 21:39:43 +0300 Subject: [PATCH 2/3] New way of saving data not yet checked due to compiling errors coming from Liran's changes in Page.h pls, let me know if you fixed it. so i can run some tests! --- src/appDatabase/savedata.cpp | 324 ++++++++++------------------------- src/appDatabase/savedata.h | 30 ++-- 2 files changed, 101 insertions(+), 253 deletions(-) diff --git a/src/appDatabase/savedata.cpp b/src/appDatabase/savedata.cpp index f8f8960..0f1dbfd 100644 --- a/src/appDatabase/savedata.cpp +++ b/src/appDatabase/savedata.cpp @@ -1,144 +1,5 @@ #include "savedata.h" - - -/** - * @brief Checks the status tag in the file - * @return boolean the status - */ -bool SaveData::isSaved() -{ - QString status; - QFile* file = new QFile(FILE_NAME); - /* Opening file for read */ - if(file->open(QIODevice::ReadOnly|QIODevice::Text)) - { - status = getValViaTag("status", file); - if(status == "true") - { - file->close(); //close & return - return true; - } - return false; //close & return - file->close(); - } - /* If Faild to open */ - std::cout << "Faild To Accsess file: " << FILE_NAME << std::endl; - return false; -} - - -/** - * @brief This Function will modify the file, and save the data. - * @param username - QString - * @param password - QString - * @return true if saved - false if error - */ -bool SaveData::save(QString username, QString password) -{ - std::cout << "Trying to save data..." << std::endl; - QFile file(FILE_NAME); - if(!file.open(QIODevice::WriteOnly|QIODevice::Text)) - return false; /* IO Error! */ - QTextStream output(&file); - QString hash_pass = hashPassword(password); - output << "[status]true[/]\n[username]"<open(QIODevice::ReadOnly|QIODevice::Text)) - username = getValViaTag("username", file); - file->close(); - return username; - -} - -/** - * @brief getter for password - * @return QString - password - */ -QString SaveData::getPassword() -{ - QString pass = ""; - QFile* file = new QFile(FILE_NAME); - /* Opening file for read */ - if(file->open(QIODevice::ReadOnly|QIODevice::Text)) - pass = getValViaTag("password", file); - file->close(); - pass = deHashPasword(pass); - return pass; - -} - -/** - * @brief Getiing the last calendar user hase been viewing. - * @return QString - cal - in format [year]-[semester] - */ -QString SaveData::gatCal() -{ - QString cal = ""; - QFile* file = new QFile(FILE_NAME); - /* Opening file for read */ - if(file->open(QIODevice::ReadOnly|QIODevice::Text)) - cal = getValViaTag("cal", file); - file->close(); - return cal; -} - -/** - * @brief Getiing the users local - default is the OS local - * @return QString - local (heb/en/default) - */ -QString SaveData::getLocal() -{ - QString local = ""; - QFile* file = new QFile(FILE_NAME); - /* Opening file for read */ - if(file->open(QIODevice::ReadOnly|QIODevice::Text)) - local = getValViaTag("local", file); - file->close(); - return local; -} - /** * @brief This is A functions that will init the tags file. * if it exist - do nothing @@ -152,107 +13,96 @@ void SaveData::init() { file.open(QIODevice::ReadWrite | QIODevice::Text); file.close(); - deleteData(); + createDB(); + save(); } + else + load(); } -/** - * @brief This function will return the vale of a given tag name. - * NOTE: valid tag names are : "status", "username", "password" - * if tag is invalid - will return "" - an empty QString! - * @param tag - QString, the tag name - * @param file - a QFile pointer - * @return QString - the value in tag - * NOTE: if NULL value, or an invalid tag name -> return "" (empty QString!) - */ -QString SaveData::getValViaTag(QString tag, QFile* file) +bool SaveData::isSaved() { - QString val, line , tmpTag; - QTextStream textStream( file); - while((line = textStream.readLine()) != NULL) - { - std::cout << "DEBUG: line => " << line.toStdString() << std::endl; - for(int i = 0 ; i< line.length() ;++i) - { - if(line[i] == '[' && line[i+1] != '/') //get open tag at begining of line and not end of tag ("[/") - { - i++; - tmpTag = line.mid(i, tag.length()); - if(tmpTag == tag) - { - i+= tag.length()+1; // i is now right after '[' - int j = i; - while(line[j] != '[')// put j at the end of the value - j++; - /* Then... the value is :*/ - val = line.mid(i, j-i); - std::cout << "DEBUG: ["<> DB; + file.close(); +} + +void SaveData::save() +{ + QFile file(FILE_NAME); + file.open(QIODevice::WriteOnly); + QDataStream out(&file); + out << DB; + file.flush(); + file.close(); +} + +void SaveData::createDB() +{ + DB.insert("username", ""); + DB.insert("password", ""); + DB.insert("local", "default"); + DB.insert("calendar", ""); } diff --git a/src/appDatabase/savedata.h b/src/appDatabase/savedata.h index 98235c2..df1d7c4 100644 --- a/src/appDatabase/savedata.h +++ b/src/appDatabase/savedata.h @@ -27,33 +27,31 @@ #include #include #include - -/* C/C++ libs */ -#include -#include -#include +#include +#include #define FILE_NAME "JAC_DB.dat" -#define DEFAULT_DATA_EMPTY "[status]false[/]\n[username][/]\n[password][/]" class SaveData { public: + void static init(); bool static isSaved(); - bool static save(QString username, QString password); - bool static saveCal(QString cal); - bool static saveLocal(QString local); - bool static deleteData(); + bool static reset(); + QString static setUsername(QString username); + QString static setPassword(QString password); + QString static setCal(QString cal); + QString static setLocal(QString local); QString static getUsername(); QString static getPassword(); - QString static gatCal(); + QString static getCal(); QString static getLocal(); - void static init(); + private: - QString static getValViaTag(QString tag, QFile *file); - QString static hashPassword(QString pass); - QString static deHashPasword(QString pass); - bool static isTagLine(QString line, QString tag); + QMap DB; + void static load(); + void static save(); + void static createDB(); }; #endif // SAVEDATA_H From cf49325e3b6c335ff01aab49bf97bccecc75f8df Mon Sep 17 00:00:00 2001 From: Sagi Dayan Date: Mon, 1 Sep 2014 00:27:15 +0300 Subject: [PATCH 3/3] Tested and works! (SaveData) Now all the data is saved as a binary file. Note: the SaveData class is now an object! works as it should! --- jceGrade.pro.user | 46 ++++-- jceGrade.pro.user.3.2-pre1 | 251 +++++++++++++++++++++++++++++++++ main/mainscreen.cpp | 20 ++- main/mainscreen.h | 2 +- src/appDatabase/savedata.cpp | 20 +-- src/appDatabase/savedata.h | 28 ++-- src/jceData/{Page.h => page.h} | 0 7 files changed, 320 insertions(+), 47 deletions(-) create mode 100644 jceGrade.pro.user.3.2-pre1 rename src/jceData/{Page.h => page.h} (100%) diff --git a/jceGrade.pro.user b/jceGrade.pro.user index c29c631..f606ccd 100644 --- a/jceGrade.pro.user +++ b/jceGrade.pro.user @@ -1,7 +1,11 @@ - + + + EnvironmentId + {27d037c7-80c2-4adc-9ebd-7fcaa787aa69} + ProjectExplorer.Project.ActiveTarget 0 @@ -54,14 +58,14 @@ ProjectExplorer.Project.Target.0 - Desktop Qt 5.3.0 MinGW 32bit - Desktop Qt 5.3.0 MinGW 32bit - qt.53.win32_mingw482_kit + Desktop + Desktop + {5099a051-769d-496c-9c12-be2a0d9569cf} 0 0 0 - D:/Dropbox/cpp/jceConQT/build-jceGrade-Desktop_Qt_5_3_0_MinGW_32bit-Debug + /home/sagi/Development/SocialDev/build-jceGrade-Desktop-Debug true @@ -78,7 +82,10 @@ Make Qt4ProjectManager.MakeStep - + + -w + -r + false @@ -94,7 +101,10 @@ Make Qt4ProjectManager.MakeStep - + + -w + -r + true clean @@ -114,7 +124,7 @@ true - D:/Dropbox/cpp/jceConQT/build-jceGrade-Desktop_Qt_5_3_0_MinGW_32bit-Release + /home/sagi/Development/SocialDev/build-jceGrade-Desktop-Release true @@ -131,7 +141,10 @@ Make Qt4ProjectManager.MakeStep - + + -w + -r + false @@ -147,7 +160,10 @@ Make Qt4ProjectManager.MakeStep - + + -w + -r + true clean @@ -220,7 +236,7 @@ jceGrade - Qt4ProjectManager.Qt4RunConfiguration:D:/Dropbox/cpp/jceConQT/jceAverageCalculator/jceGrade.pro + Qt4ProjectManager.Qt4RunConfiguration:/home/sagi/Development/SocialDev/jceAverageCalculator/jceGrade.pro jceGrade.pro false @@ -241,11 +257,11 @@ 1 - ProjectExplorer.Project.Updater.EnvironmentId - {f3f3b933-8225-47b3-aa78-fc5de0bd714b} + ProjectExplorer.Project.Updater.FileVersion + 16 - ProjectExplorer.Project.Updater.FileVersion - 15 + Version + 16 diff --git a/jceGrade.pro.user.3.2-pre1 b/jceGrade.pro.user.3.2-pre1 new file mode 100644 index 0000000..c29c631 --- /dev/null +++ b/jceGrade.pro.user.3.2-pre1 @@ -0,0 +1,251 @@ + + + + + + ProjectExplorer.Project.ActiveTarget + 0 + + + ProjectExplorer.Project.EditorSettings + + true + false + true + + Cpp + + CppGlobal + + + + QmlJS + + QmlJSGlobal + + + 2 + UTF-8 + false + 4 + false + 80 + true + true + 1 + true + false + 0 + true + 0 + 8 + true + 1 + true + true + true + false + + + + ProjectExplorer.Project.PluginSettings + + + + ProjectExplorer.Project.Target.0 + + Desktop Qt 5.3.0 MinGW 32bit + Desktop Qt 5.3.0 MinGW 32bit + qt.53.win32_mingw482_kit + 0 + 0 + 0 + + D:/Dropbox/cpp/jceConQT/build-jceGrade-Desktop_Qt_5_3_0_MinGW_32bit-Debug + + + true + qmake + + QtProjectManager.QMakeBuildStep + false + true + + false + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Debug + + Qt4ProjectManager.Qt4BuildConfiguration + 2 + true + + + D:/Dropbox/cpp/jceConQT/build-jceGrade-Desktop_Qt_5_3_0_MinGW_32bit-Release + + + true + qmake + + QtProjectManager.QMakeBuildStep + false + true + + false + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Release + + Qt4ProjectManager.Qt4BuildConfiguration + 0 + true + + 2 + + + 0 + Deploy + + ProjectExplorer.BuildSteps.Deploy + + 1 + Deploy locally + + ProjectExplorer.DefaultDeployConfiguration + + 1 + + + + false + false + false + false + true + 0.01 + 10 + true + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + jceGrade + + Qt4ProjectManager.Qt4RunConfiguration:D:/Dropbox/cpp/jceConQT/jceAverageCalculator/jceGrade.pro + + jceGrade.pro + false + false + + 3768 + false + true + false + false + true + + 1 + + + + ProjectExplorer.Project.TargetCount + 1 + + + ProjectExplorer.Project.Updater.EnvironmentId + {f3f3b933-8225-47b3-aa78-fc5de0bd714b} + + + ProjectExplorer.Project.Updater.FileVersion + 15 + + diff --git a/main/mainscreen.cpp b/main/mainscreen.cpp index 39a3925..3d29cf1 100644 --- a/main/mainscreen.cpp +++ b/main/mainscreen.cpp @@ -32,13 +32,14 @@ MainScreen::MainScreen(QWidget *parent) :QMainWindow(parent), ui(new Ui::MainScr this->courseTableMgr = new coursesTableManager(ui->coursesTable,userLoginSetting); this->loginHandel = new loginHandler(userLoginSetting); this->calendar = new CalendarManager(ui->calendartext); + this->data = new SaveData(); //check login File - SaveData::init(); - if (SaveData::isSaved()) + //SaveData::init(); --> No need. constructor dose everything. + if (data->isSaved()) { - ui->usrnmLineEdit->setText(SaveData::getUsername()); - ui->pswdLineEdit->setText(SaveData::getPassword()); + ui->usrnmLineEdit->setText(data->getUsername()); + ui->pswdLineEdit->setText(data->getPassword()); ui->keepLogin->setChecked(true); } } @@ -48,6 +49,9 @@ MainScreen::~MainScreen() delete userLoginSetting; delete loginHandel; delete ui; + + //Delete save data + delete data; } void MainScreen::on_loginButton_clicked() { @@ -261,10 +265,12 @@ void MainScreen::on_actionExit_triggered() void MainScreen::on_keepLogin_clicked() { if (ui->keepLogin->isChecked()) - SaveData::save(ui->usrnmLineEdit->text(),ui->pswdLineEdit->text()); - + { + data->setUsername(ui->usrnmLineEdit->text()); + data->setPassword(ui->pswdLineEdit->text()); + } else - SaveData::deleteData(); + data->reset(); } void MainScreen::on_actionHow_To_triggered() diff --git a/main/mainscreen.h b/main/mainscreen.h index ddf79c3..2ea31d2 100644 --- a/main/mainscreen.h +++ b/main/mainscreen.h @@ -68,7 +68,7 @@ private: Ui::MainScreen *ui; user *userLoginSetting; - + SaveData *data; CalendarManager * calendar; coursesTableManager *courseTableMgr; loginHandler *loginHandel; diff --git a/src/appDatabase/savedata.cpp b/src/appDatabase/savedata.cpp index 0f1dbfd..edb1815 100644 --- a/src/appDatabase/savedata.cpp +++ b/src/appDatabase/savedata.cpp @@ -6,7 +6,7 @@ * if there is no file, it will create it and run the deleteData function * so tags will be set. */ -void SaveData::init() +SaveData::SaveData() { QFile file(FILE_NAME); if(!file.exists()) @@ -27,34 +27,34 @@ bool SaveData::isSaved() return true; } -bool SaveData::reset() +void SaveData::reset() { DB.clear(); createDB(); save(); } -QString SaveData::setUsername(QString username) +void SaveData::setUsername(QString username) { - DB.value("username") = username; + DB.insert("username", username); save(); } -QString SaveData::setPassword(QString password) +void SaveData::setPassword(QString password) { - DB.value("password") = password; + DB.insert("password", password); save(); } -QString SaveData::setCal(QString cal) +void SaveData::setCal(QString cal) { - DB.value("calendar") = cal; + DB.insert("calendar", cal); save(); } -QString SaveData::setLocal(QString local) +void SaveData::setLocal(QString local) { - DB.value("local") = local; + DB.insert("local", local); save(); } diff --git a/src/appDatabase/savedata.h b/src/appDatabase/savedata.h index df1d7c4..3952e22 100644 --- a/src/appDatabase/savedata.h +++ b/src/appDatabase/savedata.h @@ -35,23 +35,23 @@ class SaveData { public: - void static init(); - bool static isSaved(); - bool static reset(); - QString static setUsername(QString username); - QString static setPassword(QString password); - QString static setCal(QString cal); - QString static setLocal(QString local); - QString static getUsername(); - QString static getPassword(); - QString static getCal(); - QString static getLocal(); + SaveData(); + bool isSaved(); + void reset(); + void setUsername(QString username); + void setPassword(QString password); + void setCal(QString cal); + void setLocal(QString local); + QString getUsername(); + QString getPassword(); + QString getCal(); + QString getLocal(); private: QMap DB; - void static load(); - void static save(); - void static createDB(); + void load(); + void save(); + void createDB(); }; #endif // SAVEDATA_H diff --git a/src/jceData/Page.h b/src/jceData/page.h similarity index 100% rename from src/jceData/Page.h rename to src/jceData/page.h