Parcourir la source

Renamed some classes

Renamed some classes
Felix Turo il y a 2 ans
Parent
commit
aceafb7fd8

+ 8 - 8
CMakeLists.txt

@@ -81,18 +81,18 @@ set(PROJECT_SOURCES
     src/classes/astyle.cpp
     src/classes/paths.h
     src/classes/paths.cpp
-    src/classes/adownload.h
-    src/classes/adownload.cpp
+    src/classes/downloadhelper.h
+    src/classes/downloadhelper.cpp
     src/classes/arunguard.h
     src/classes/arunguard.cpp
     src/classes/asettings.h
     src/classes/asettings.cpp
-    src/classes/atranslator.h
-    src/classes/atranslator.cpp
-    src/classes/ajson.h
-    src/classes/ajson.cpp
-    src/classes/ahash.h
-    src/classes/ahash.cpp
+    src/classes/translator.h
+    src/classes/translator.cpp
+    src/classes/jsonhelper.h
+    src/classes/jsonhelper.cpp
+    src/classes/md5sum.h
+    src/classes/md5sum.cpp
 
     # Namespaces
     src/functions/calc.h

+ 8 - 12
src/classes/adownload.cpp → src/classes/downloadhelper.cpp

@@ -15,34 +15,30 @@
  *You should have received a copy of the GNU General Public License
  *along with this program.  If not, see <https://www.gnu.org/licenses/>.
  */
-#include "adownload.h"
+#include "downloadhelper.h"
 #include "src/opl.h"
-#include "src/functions/log.h"
 
-
-
-
-ADownload::ADownload() : QObject(nullptr)
+DownloadHelper::DownloadHelper() : QObject(nullptr)
 {
     QObject::connect(&manager, SIGNAL(finished(QNetworkReply*)),this, SLOT(downloadFinished(QNetworkReply*)));
 }
 
-ADownload::~ADownload()
+DownloadHelper::~DownloadHelper()
 {
 
 }
 
-void ADownload::setTarget(const QUrl &value)
+void DownloadHelper::setTarget(const QUrl &value)
 {
     this->target = value;
 }
 
-void ADownload::setFileName(const QString &value)
+void DownloadHelper::setFileName(const QString &value)
 {
     this->fileName = value;
 }
 
-void ADownload::download()
+void DownloadHelper::download()
 {
     QNetworkRequest request(target);
     DEB << "Downloading from: " << target.toString();
@@ -51,14 +47,14 @@ void ADownload::download()
 }
 
 
-void ADownload::downloadProgress(qint64 received, qint64 total)
+void DownloadHelper::downloadProgress(qint64 received, qint64 total)
 {
     //DEB << "Received " << received << " bytes of " << total;
 }
 
 
 
-void ADownload::downloadFinished(QNetworkReply *data)
+void DownloadHelper::downloadFinished(QNetworkReply *data)
 {
     QFile localFile(fileName);
     if (!localFile.open(QIODevice::WriteOnly))

+ 6 - 6
src/classes/adownload.h → src/classes/downloadhelper.h

@@ -15,8 +15,8 @@
  *You should have received a copy of the GNU General Public License
  *along with this program.  If not, see <https://www.gnu.org/licenses/>.
  */
-#ifndef ADOWNLOAD_H
-#define ADOWNLOAD_H
+#ifndef DOWNLOADHELPER_H
+#define DOWNLOADHELPER_H
 
 #include <QObject>
 #include <QNetworkAccessManager>
@@ -27,12 +27,12 @@
 #include <QDebug>
 
 
-class ADownload : public QObject {
+class DownloadHelper : public QObject {
     Q_OBJECT
 public:
-    explicit ADownload();
+    explicit DownloadHelper();
 
-    ~ADownload();
+    ~DownloadHelper();
 
     void setTarget(const QUrl &value);
 
@@ -54,4 +54,4 @@ public slots:
     void downloadProgress(qint64 received, qint64 total);
 };
 
-#endif // ADOWNLOAD_H
+#endif // DOWNLOADHELPER_H

+ 6 - 7
src/classes/ajson.cpp → src/classes/jsonhelper.cpp

@@ -15,12 +15,11 @@
  *You should have received a copy of the GNU General Public License
  *along with this program.  If not, see <https://www.gnu.org/licenses/>.
  */
-#include "ajson.h"
+#include "jsonhelper.h"
 #include "src/database/database.h"
+#include "src/classes/paths.h"
 
-
-
-void AJson::exportDatabase()
+void JsonHelper::exportDatabase()
 {
     for (const auto &table : TABLES){
         QJsonArray array;
@@ -34,7 +33,7 @@ void AJson::exportDatabase()
     }
 }
 
-void AJson::importDatabase()
+void JsonHelper::importDatabase()
 {
     TODO << "Another function should do some checking here if data exists etc...";
     TODO << "Make the function take a list of files/fileinfo as arguments";
@@ -53,7 +52,7 @@ void AJson::importDatabase()
     }
 }
 
-QJsonDocument AJson::readFileToDoc(const QString &file_path)
+QJsonDocument JsonHelper::readFileToDoc(const QString &file_path)
 {
     QFile file(file_path);
     file.open(QIODevice::ReadOnly | QIODevice::Text);
@@ -64,7 +63,7 @@ QJsonDocument AJson::readFileToDoc(const QString &file_path)
     return doc;
 }
 
-void AJson::writeDocToFile(const QJsonDocument &doc, const QString &file_name)
+void JsonHelper::writeDocToFile(const QJsonDocument &doc, const QString &file_name)
 {
     QFile out(OPL::Paths::filePath(OPL::Paths::Export,file_name));
     out.open(QFile::WriteOnly);

+ 7 - 8
src/classes/ajson.h → src/classes/jsonhelper.h

@@ -15,22 +15,21 @@
  *You should have received a copy of the GNU General Public License
  *along with this program.  If not, see <https://www.gnu.org/licenses/>.
  */
-#ifndef AJSON_H
-#define AJSON_H
+#ifndef JSONHELPER_H
+#define JSONHELPER_H
 #include "src/opl.h"
-#include "src/classes/paths.h"
 #include <QJsonDocument>
 #include <QJsonValue>
 #include <QJsonObject>
 
 /*!
- * \brief The AJSON class is responsible for parsing the database (sqlite) to and from JSON.
+ * \brief The JsonHelper class is responsible for parsing the database (sqlite) to and from JSON.
  */
-class AJson
+class JsonHelper
 {
 public:
-    AJson();
-    AJson(QFileInfo database_file);
+    JsonHelper();
+    JsonHelper(QFileInfo database_file);
 
     /*!
      * \brief exportDatabase exports the currently active database to JSON.
@@ -71,4 +70,4 @@ private:
 
 };
 
-#endif // AJSON_H
+#endif // JSONHELPER_H

+ 6 - 5
src/classes/ahash.cpp → src/classes/md5sum.cpp

@@ -15,10 +15,10 @@
  *You should have received a copy of the GNU General Public License
  *along with this program.  If not, see <https://www.gnu.org/licenses/>.
  */
-#include "ahash.h"
+#include "md5sum.h"
 #include "src/opl.h"
 
-AHash::AHash(QFileInfo &file_info)
+Md5Sum::Md5Sum(QFileInfo &file_info)
 {
     QFile f(file_info.absoluteFilePath());
     if (f.open(QFile::ReadOnly)) {
@@ -36,7 +36,7 @@ AHash::AHash(QFileInfo &file_info)
     f.close();
 }
 
-bool AHash::compare(QFileInfo &md5_file)
+bool Md5Sum::compare(QFileInfo &md5_file) const
 {
     // Open the file and read the first 32 characters
     QFile f(md5_file.absoluteFilePath());
@@ -45,9 +45,10 @@ bool AHash::compare(QFileInfo &md5_file)
         const QString hash_string = in.read(32);
 
         // Verify checksum is not empty and compare to md5 read from file
-        if (checksum == QByteArray())
+        if (checksum == QByteArray()) {
+            LOG << QString("Unable to read checksum from file: %1").arg(md5_file.absoluteFilePath());
             return false;
-        else
+        } else
             if (checksum.toHex() == hash_string)
                 return true;
             else {

+ 10 - 9
src/classes/ahash.h → src/classes/md5sum.h

@@ -15,30 +15,31 @@
  *You should have received a copy of the GNU General Public License
  *along with this program.  If not, see <https://www.gnu.org/licenses/>.
  */
-#ifndef AHASH_H
-#define AHASH_H
+#ifndef MD5SUM_H
+#define MD5SUM_H
 #include <QtCore>
 #include <QByteArray>
 #include <QCryptographicHash>
 
 /*!
- * \brief The AHash class is responsible for calculating cryptographic hashes of files (used to verify downloads)
+ * \brief The Md5Sum class is responsible for calculating cryptographic hashes of files (used to verify downloads)
  */
-class AHash
+class Md5Sum
 {
 public:
     /*!
-     * \brief AHash - calculates the MD5-checksum for the parameter given in the constructor and
+     * \brief AHash - calculates the MD5-checksum for the input file specified in the constructor and
      * saves the result in the checksum member variable
      */
-    AHash(QFileInfo &file_info);
+    Md5Sum(QFileInfo &file_info);
+    Md5Sum() = delete;
 
     QByteArray checksum;
 
     /*!
      * \brief hashString returns a hex representation of the hash
      */
-    inline const QString hashToHex()
+    inline const QString hashToHex() const
     {
             return QString(checksum.toHex());
     };
@@ -48,7 +49,7 @@ public:
      * \param md5_file - the checkfile containing the md5 checksum in hex format
      * \return true if hashes match
      */
-    bool compare(QFileInfo &md5_file);
+    bool compare(QFileInfo &md5_file) const;
 };
 
-#endif // AHASH_H
+#endif // MD5SUM_H

+ 3 - 3
src/classes/atranslator.cpp → src/classes/translator.cpp

@@ -1,8 +1,8 @@
-#include "atranslator.h"
+#include "translator.h"
 
-QTranslator* ATranslator::translator;
+QTranslator* Translator::translator;
 
-void ATranslator::installTranslator(OPL::Translation language)
+void Translator::installTranslator(OPL::Translation language)
 {
     translator = new QTranslator();
     if (translator->load(OPL::GLOBALS->getLanguageFilePath(language)))

+ 4 - 4
src/classes/atranslator.h → src/classes/translator.h

@@ -1,5 +1,5 @@
-#ifndef ATRANSLATOR_H
-#define ATRANSLATOR_H
+#ifndef TRANSLATOR_H
+#define TRANSLATOR_H
 #include "src/opl.h"
 
 /*!
@@ -15,7 +15,7 @@
  * When a QTranslator is installed, the UI is updated through [QWidget::changeEvent()](https://doc.qt.io/qt-5/qwidget.html#changeEvent).
  *
  */
-class ATranslator  : public QObject {
+class Translator  : public QObject {
     Q_OBJECT
 public:
     /*!
@@ -27,4 +27,4 @@ private:
     static QTranslator *translator;
 };
 
-#endif // ATRANSLATOR_H
+#endif // TRANSLATOR_H

+ 3 - 3
src/database/database.cpp

@@ -17,7 +17,7 @@
  */
 #include "database.h"
 #include "src/opl.h"
-#include "src/classes/ajson.h"
+#include "src/classes/jsonhelper.h"
 
 namespace OPL {
 
@@ -681,13 +681,13 @@ bool Database::importTemplateData(bool use_local_ressources)
         QString error_message("Error importing data ");
 
         if (use_local_ressources) {
-            data_to_commit = AJson::readFileToDoc(QLatin1String(":database/templates/")
+            data_to_commit = JsonHelper::readFileToDoc(QLatin1String(":database/templates/")
                                       + table_name + QLatin1String(".json")).array();
             error_message.append(QLatin1String(" (ressource) "));
         } else {
             const QString file_path = OPL::Paths::filePath(OPL::Paths::Templates,
                                                            table_name + QLatin1String(".json"));
-            data_to_commit = AJson::readFileToDoc(file_path).array();
+            data_to_commit = JsonHelper::readFileToDoc(file_path).array();
             //data_to_commit = AJson::readFileToDoc(AStandardPaths::directory(
             //                              AStandardPaths::Templates).absoluteFilePath(
             //                              table_name + QLatin1String(".json"))).array();

+ 7 - 7
src/gui/dialogues/firstrundialog.cpp

@@ -22,11 +22,11 @@
 #include "src/database/dbsummary.h"
 #include "src/gui/widgets/backupwidget.h"
 #include "src/database/row.h"
-#include "src/classes/adownload.h"
+#include "src/classes/downloadhelper.h"
 #include "src/classes/asettings.h"
 #include "src/functions/adate.h"
 #include "src/classes/astyle.h"
-#include "src/classes/ahash.h"
+#include "src/classes/md5sum.h"
 #include <QErrorMessage>
 #include <QFileDialog>
 #include <QKeyEvent>
@@ -205,8 +205,8 @@ bool FirstRunDialog::downloadTemplates(QString branch_name)
     // Download json files
     for (const auto& table_name : template_table_names) {
         QEventLoop loop;
-        ADownload* dl = new ADownload;
-        QObject::connect(dl, &ADownload::done, &loop, &QEventLoop::quit );
+        DownloadHelper* dl = new DownloadHelper;
+        QObject::connect(dl, &DownloadHelper::done, &loop, &QEventLoop::quit );
         dl->setTarget(QUrl(template_url_string + table_name + QLatin1String(".json")));
         dl->setFileName(template_dir.absoluteFilePath(table_name + QLatin1String(".json")));
         DEB << "Downloading: " << template_url_string + table_name + QLatin1String(".json");
@@ -223,8 +223,8 @@ bool FirstRunDialog::downloadTemplates(QString branch_name)
     // Download checksum files
     for (const auto& table_name : template_table_names) {
         QEventLoop loop;
-        ADownload* dl = new ADownload;
-        QObject::connect(dl, &ADownload::done, &loop, &QEventLoop::quit );
+        DownloadHelper* dl = new DownloadHelper;
+        QObject::connect(dl, &DownloadHelper::done, &loop, &QEventLoop::quit );
         dl->setTarget(QUrl(template_url_string + table_name + QLatin1String(".md5")));
         dl->setFileName(template_dir.absoluteFilePath(table_name + QLatin1String(".md5")));
 
@@ -252,7 +252,7 @@ bool FirstRunDialog::verifyTemplates()
         const QString path = OPL::Paths::filePath(OPL::Paths::Templates, table_name);
 
         QFileInfo check_file(path + QLatin1String(".json"));
-        AHash hash(check_file);
+        Md5Sum hash(check_file);
 
         QFileInfo md5_file(path + QLatin1String(".md5"));
         if (!hash.compare(md5_file))

+ 4 - 4
src/gui/widgets/debugwidget.cpp

@@ -93,8 +93,8 @@ void DebugWidget::on_resetDatabasePushButton_clicked()
     // Download json files
     for (const auto& table_name : template_table_names) {
         QEventLoop loop;
-        ADownload* dl = new ADownload;
-        QObject::connect(dl, &ADownload::done, &loop, &QEventLoop::quit );
+        DownloadHelper* dl = new DownloadHelper;
+        QObject::connect(dl, &DownloadHelper::done, &loop, &QEventLoop::quit );
         dl->setTarget(QUrl(template_url_string + table_name + QLatin1String(".json")));
         dl->setFileName(template_dir.absoluteFilePath(table_name + QLatin1String(".json")));
         DEB << "Downloading: " << template_url_string + table_name + QLatin1String(".json");
@@ -109,8 +109,8 @@ void DebugWidget::on_resetDatabasePushButton_clicked()
     // Download checksum files
     for (const auto& table : template_table_names) {
         QEventLoop loop;
-        ADownload* dl = new ADownload;
-        QObject::connect(dl, &ADownload::done, &loop, &QEventLoop::quit );
+        DownloadHelper* dl = new DownloadHelper;
+        QObject::connect(dl, &DownloadHelper::done, &loop, &QEventLoop::quit );
         dl->setTarget(QUrl(template_url_string + table + QLatin1String(".md5")));
         dl->setFileName(template_dir.absoluteFilePath(table + QLatin1String(".md5")));
 

+ 1 - 1
src/gui/widgets/debugwidget.h

@@ -25,7 +25,7 @@
 #include <QFileDialog>
 #include <QMessageBox>
 #include <QProcess>
-#include "src/classes/adownload.h"
+#include "src/classes/downloadhelper.h"
 #include "src/functions/areadcsv.h"
 
 #include "src/database/database.h"