Merge pull request #21 from liranbg/sagi_dev

Added some more documentation
This commit is contained in:
Liran BG 2014-09-27 00:16:30 +03:00
commit 972e44a895
7 changed files with 119 additions and 11 deletions

View file

@ -20,6 +20,12 @@ SaveData::SaveData()
load(); load();
} }
/**
* @brief This will check if the is data saved ie. username and password.
* the only way in JCE manager is to store a username and password together. therefore if there is
* a user name in the file, so there is a password ass well.
* @return true if the is a username in the file. (if not the username will be "")
*/
bool SaveData::isSaved() bool SaveData::isSaved()
{ {
if(DB.value("username") == "") if(DB.value("username") == "")
@ -27,6 +33,14 @@ bool SaveData::isSaved()
return true; return true;
} }
/**
* @brief This void function will erase all data. QMap will be cleard and saved to the file.
* data thet will be deleted:
* # username
* # password
* # calendar
* # local
*/
void SaveData::reset() void SaveData::reset()
{ {
DB.clear(); DB.clear();
@ -34,52 +48,89 @@ void SaveData::reset()
save(); save();
} }
/**
* @brief gest a username and saves it into the QMap.
* QMap then is saved to the file.
* @param username - users username from the mainwindow ui pointer.
*/
void SaveData::setUsername(QString username) void SaveData::setUsername(QString username)
{ {
DB.insert("username", username); DB.insert("username", username);
save(); save();
} }
/**
* @brief gets a password, sends it to encyption, and saves the encrypter password to QMap.
* saves the QMap into the file.
* @param password - raw password (not encrypted)
*/
void SaveData::setPassword(QString password) void SaveData::setPassword(QString password)
{ {
DB.insert("password", encrypt(password)); DB.insert("password", encrypt(password));
save(); save();
} }
/**
* @brief gest a calendar and saves it into the QMap.
* QMap then is saved to the file.
* @param cal - last calendar that user seen
*/
void SaveData::setCal(QString cal) void SaveData::setCal(QString cal)
{ {
DB.insert("calendar", cal); DB.insert("calendar", cal);
save(); save();
} }
/**
* @brief gest a local and saves it into the QMap.
* QMap then is saved to the file.
* @param local - QString (he, en, default)
*/
void SaveData::setLocal(QString local) void SaveData::setLocal(QString local)
{ {
DB.insert("local", local); DB.insert("local", local);
save(); save();
} }
/**
* @brief read from file
* @return - username
*/
QString SaveData::getUsername() QString SaveData::getUsername()
{ {
return DB.value("username"); return DB.value("username");
} }
/**
* @brief read from file
* @return - unencrypted password
*/
QString SaveData::getPassword() QString SaveData::getPassword()
{ {
return decrypte(DB.value("password")); return decrypte(DB.value("password"));
} }
/**
* @brief read from file
* @return local
*/
QString SaveData::getLocal() QString SaveData::getLocal()
{ {
return DB.value("local"); return DB.value("local");
} }
/**
* @brief read from file
* @return calendar
*/
QString SaveData::getCal() QString SaveData::getCal()
{ {
return DB.value("calendar"); return DB.value("calendar");
} }
/**
* @brief read from file the QMap object into the DB inside "this" object.
*/
void SaveData::load() void SaveData::load()
{ {
QFile file(FILE_NAME); QFile file(FILE_NAME);
@ -89,6 +140,9 @@ void SaveData::load()
file.close(); file.close();
} }
/**
* @brief Saves the QMap to the file. overriding the content of the file.
*/
void SaveData::save() void SaveData::save()
{ {
QFile file(FILE_NAME); QFile file(FILE_NAME);
@ -99,6 +153,9 @@ void SaveData::save()
file.close(); file.close();
} }
/**
* @brief Creates en empty tamplate for QMap (use only on init! if there is no file.)
*/
void SaveData::createDB() void SaveData::createDB()
{ {
DB.insert("username", ""); DB.insert("username", "");
@ -107,12 +164,24 @@ void SaveData::createDB()
DB.insert("calendar", ""); DB.insert("calendar", "");
} }
/**
* @brief this function will connect this class to the simplecrypt class.
* sends the raw password to encryption and returns the encrypted one.
* @param pass - raw password.
* @return encrypted password.
*/
QString SaveData::encrypt(QString pass) QString SaveData::encrypt(QString pass)
{ {
SimpleCrypt crypto(Q_UINT64_C(0x0c2ad4a4acb9f027)); SimpleCrypt crypto(Q_UINT64_C(0x0c2ad4a4acb9f027));
return crypto.encryptToString(pass); return crypto.encryptToString(pass);
} }
/**
* @brief this function will connect this class to the simplecrypt class.
* sends the encrypted password to decryption and returns the raw one.
* @param pass - encrypted password.
* @return raw password.
*/
QString SaveData::decrypte(QString pass) QString SaveData::decrypte(QString pass)
{ {
SimpleCrypt crypto(Q_UINT64_C(0x0c2ad4a4acb9f027)); SimpleCrypt crypto(Q_UINT64_C(0x0c2ad4a4acb9f027));

View file

@ -124,7 +124,7 @@ QString CSV_Exporter::getFileFath()
* @param name * @param name
* @param date * @param date
* @param startH * @param startH
* @param startM * @param startM - Not used at the moment.
* @param endH * @param endH
* @param endM * @param endM
* @param lecturer * @param lecturer
@ -203,6 +203,13 @@ QString CSV_Exporter::makeLine(QString name, QDate *date, int startH, int startM
return CSV_line; return CSV_line;
} }
/**
* @brief The QDate.dayOfWeek() returns an integer as follows (Sunday = 7, monday = 1... Friday = 5)
* This method will make that return integer more uderstandble and easy to use with the Calander classes of
* JCE Manager. so Sunday = 1, Monday = 2 and so on...
*
* @param QtDay - A Qt dayOfWeek integer pointer. it will cange his value.
*/
void CSV_Exporter::changeDayNumberFromQtToNormal(int *QtDay) void CSV_Exporter::changeDayNumberFromQtToNormal(int *QtDay)
{ {
switch(*QtDay){ switch(*QtDay){

View file

@ -1,3 +1,11 @@
/**
* This simple static class will generate a csv file of a given semester.
*
* the class wat written for the JCE Manager and exporting a calendar to Goolgle Calendar.
*
* this CSV file should also work for iCal and Outlook. but have not been tested.
*
*/
#ifndef CSV_EXPORTER_H #ifndef CSV_EXPORTER_H
#define CSV_EXPORTER_H #define CSV_EXPORTER_H

View file

@ -26,30 +26,42 @@ QDate CalendarDialog::getEndDate()
return ui->calEnd->selectedDate(); return ui->calEnd->selectedDate();
} }
/**
* @breif This method will return the state of the dates aka User input.
* @return true - if dates are valid, invalid false.
*/
bool CalendarDialog::ok() bool CalendarDialog::ok()
{ {
return this->isOK; return this->isOK;
} }
/**
* @breif A Slot - triggers when the start calendar widget is selected (Date changed by user)
* it will change the status label (ui->lbl_status) according to the users input.
*/
void CalendarDialog::on_calStart_selectionChanged() void CalendarDialog::on_calStart_selectionChanged()
{ {
if(ui->calStart->selectedDate() >= ui->calEnd->selectedDate()) if(ui->calStart->selectedDate() >= ui->calEnd->selectedDate()) //User input is invalid
{ {
changeLabeStatusIcon(false); changeLabeStatusIcon(false);
ui->lbl_status->setText(tr("The end of the semester can NOT be equal or before the semester begin.")); ui->lbl_status->setText(tr("The end of the semester can NOT be equal or before the semester begin."));
this->isOK = false; this->isOK = false;
} }
else else // input is valid
{ {
changeLabeStatusIcon(true); changeLabeStatusIcon(true);
ui->lbl_status->setText(tr("Looks ok, Press OK")); ui->lbl_status->setText(tr("Looks fine, Click \"OK\""));
this->isOK = true; this->isOK = true;
} }
} }
/**
* @breif A Slot triggerd when OK clicked
*/
void CalendarDialog::on_buttonBox_accepted() void CalendarDialog::on_buttonBox_accepted()
{ {
if(ui->calStart->selectedDate() > ui->calEnd->selectedDate()) if(this->isOK)
qDebug() << "start is bigger than end!"; qDebug() << "CalendarDialog: Valid input";
} }
void CalendarDialog::on_calEnd_selectionChanged() void CalendarDialog::on_calEnd_selectionChanged()
@ -69,6 +81,10 @@ void CalendarDialog::on_calEnd_selectionChanged()
} }
/**
* @breif changes the status icon according to the... status... smart huh?
* @param goodOrBad - self explained
*/
void CalendarDialog::changeLabeStatusIcon(bool goodOrBad) void CalendarDialog::changeLabeStatusIcon(bool goodOrBad)
{ {
if (goodOrBad == true) //good date! if (goodOrBad == true) //good date!

View file

@ -1,3 +1,12 @@
/**
* JCE Manager (C)
*
* This QDialog widget will hold the dates of a Semester, Start and End.
*
* this dialog will help the csv_exporter class to export a CSV file that will contain
* all the courses within that period of time.
*/
#ifndef CALENDARDIALOG_H #ifndef CALENDARDIALOG_H
#define CALENDARDIALOG_H #define CALENDARDIALOG_H

View file

@ -3,8 +3,7 @@
/* This Code Made By Sagi Dayan /* This Code Made By Sagi Dayan
* SagiDayan@gmail.com * SagiDayan@gmail.com
* * & Liran Ben Gida
* minor changes by Liran Ben Gida
* LiranBG@gmail.com * LiranBG@gmail.com
*/ */

View file

@ -4,7 +4,7 @@
/* This Code Made By Sagi Dayan /* This Code Made By Sagi Dayan
* SagiDayan@gmail.com * SagiDayan@gmail.com
* *
* Changes has been made by Liran Ben Gida * Changes have been made by Liran Ben Gida
* LiranBG@gmail.com * LiranBG@gmail.com
*/ */
#include <QDebug> #include <QDebug>