mirror of
https://github.com/QuasarApp/CopyrightFixer.git
synced 2025-04-26 17:54:42 +00:00
ref #46 "Correction of types fields and name into Owner."
This commit is contained in:
parent
f7530c9ed3
commit
c0e4477605
@ -20,12 +20,12 @@ const QString &Owner::getOwnerName() const {
|
||||
return _name;
|
||||
}
|
||||
|
||||
void Owner::setTimeRange(const QString &interval) {
|
||||
_timeRange = interval;
|
||||
void Owner::setTimePoint(const int &interval) {
|
||||
_timePoint = interval;
|
||||
}
|
||||
|
||||
const QString &Owner::getTimeRange() const {
|
||||
return _timeRange;
|
||||
const int &Owner::getTimePoint() const {
|
||||
return _timePoint;
|
||||
}
|
||||
|
||||
};
|
||||
|
@ -36,16 +36,17 @@ public:
|
||||
* @brief setTimeRange A method that allows you to set the time interval for using a file.
|
||||
* @param interval This is a string value indicating the date of ownership of the file.
|
||||
*/
|
||||
void setTimeRange(const QString &interval);
|
||||
void setTimePoint(const QString &interval);
|
||||
|
||||
/**
|
||||
* @brief getTimeRange The method changes the timestamp of the usage.
|
||||
* @return the time interval when the file was modified
|
||||
*/
|
||||
const QString& getTimeRange() const;
|
||||
const QString& getTimePoint() const;
|
||||
|
||||
private:
|
||||
QString _name;
|
||||
QString _timeRange;
|
||||
int _timePoint;
|
||||
|
||||
};
|
||||
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include "owner.h"
|
||||
#include <quasarapp.h>
|
||||
#include <QFile>
|
||||
#include <QFileInfo>
|
||||
#include <QJsonArray>
|
||||
#include <QJsonValue>
|
||||
#include <QJsonObject>
|
||||
@ -21,8 +22,8 @@ Signature::Signature() {
|
||||
|
||||
}
|
||||
|
||||
void Signature::setlistOwners(const QList<Owner> &objOwner) {
|
||||
_ownersList = objOwner;
|
||||
void Signature::setMapOwners(const QMap<int, Owner> &objOwner) {
|
||||
_ownersMap = objOwner;
|
||||
}
|
||||
|
||||
void Signature::setLicenseTitle(const QString &strTitle) {
|
||||
@ -33,8 +34,8 @@ void Signature::setMessage(const QString &strMsg) {
|
||||
_customMessage = strMsg;
|
||||
}
|
||||
|
||||
const QList<Owner> &Signature::getLstOwn() const {
|
||||
return _ownersList;
|
||||
const QMap<int, Owner> &Signature::getMapOwn() const {
|
||||
return _ownersMap;
|
||||
}
|
||||
|
||||
const QString &Signature::getLicenseTitle() const {
|
||||
@ -45,17 +46,64 @@ const QString &Signature::getMessage() const {
|
||||
return _customMessage;
|
||||
}
|
||||
|
||||
bool Signature::fromJson() {
|
||||
bool Signature::fromJson(const QString &pathToFile) {
|
||||
|
||||
QFileInfo signFile(pathToFile);
|
||||
if (signFile.exists() && signFile.isFile()) {
|
||||
|
||||
QFile file(pathToFile);
|
||||
if (!file.open(QIODevice::ReadOnly)) {
|
||||
QuasarAppUtils::Params::log("Json file couldn't be opened/found");
|
||||
return false;
|
||||
}
|
||||
|
||||
QByteArray byteSignFile;
|
||||
byteSignFile = file.readAll();
|
||||
file.close();
|
||||
|
||||
QJsonDocument jsDoc(QJsonDocument::fromJson(byteSignFile));
|
||||
if (jsDoc.isNull()) {
|
||||
QuasarAppUtils::Params::log("Failed to create JSON doc.");
|
||||
return false;
|
||||
}
|
||||
if (!jsDoc.isObject()) {
|
||||
QuasarAppUtils::Params::log("JSON is not an object.");
|
||||
return false;
|
||||
}
|
||||
|
||||
QJsonObject jsObj = jsDoc.object();
|
||||
if (jsObj.isEmpty()) {
|
||||
QuasarAppUtils::Params::log("JSON object is empty.");
|
||||
return false;
|
||||
}
|
||||
|
||||
_licenseTitle = jsObj["license"].toString();
|
||||
_customMessage = jsObj["licenseText"].toString();
|
||||
|
||||
Owner OwnObj;
|
||||
QMap<int, Owner> ownMap;
|
||||
|
||||
// _ownersMap = jsObj["ownersList"]
|
||||
|
||||
|
||||
|
||||
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
bool Signature::toJson() const {
|
||||
bool Signature::toJson(QString &pathToFile) const {
|
||||
|
||||
QJsonArray lstObjown;
|
||||
QJsonObject objOwner;
|
||||
for (const Owner &obj: qAsConst(_ownersList)) {
|
||||
objOwner["timePoint"] = obj.getTimeRange();
|
||||
objOwner["name"] = obj.getOwnerName();
|
||||
|
||||
for (auto obj = _ownersMap.cbegin(); obj != _ownersMap.end(); ++obj) {
|
||||
objOwner["timePoint"] = obj.value().getTimePoint();
|
||||
objOwner["name"] = obj.value().getOwnerName();
|
||||
|
||||
lstObjown.append(objOwner);
|
||||
}
|
||||
|
||||
@ -67,15 +115,14 @@ bool Signature::toJson() const {
|
||||
QByteArray jsonDoc;
|
||||
jsonDoc = QJsonDocument(signJson).toJson();
|
||||
|
||||
QFile file;
|
||||
file.setFileName(filenameJson);
|
||||
if (!file.open(QIODevice::WriteOnly)) {
|
||||
QFile saveFile(pathToFile);
|
||||
if (!saveFile.open(QIODevice::WriteOnly)) {
|
||||
QuasarAppUtils::Params::log("NO write access for json file.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
file.write(jsonDoc);
|
||||
file.close();
|
||||
saveFile.write(jsonDoc);
|
||||
saveFile.close();
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
@ -10,7 +10,7 @@
|
||||
|
||||
#include "CopyrighFixer_global.h"
|
||||
#include "CopyrighFixer/owner.h"
|
||||
#include <QList>
|
||||
#include <QMap>
|
||||
|
||||
|
||||
namespace CopyrighFixer {
|
||||
@ -26,7 +26,7 @@ public:
|
||||
* @brief setlistOwners The method generates a list of owners.
|
||||
* @param objOwner This is a structure with information about the owner.
|
||||
*/
|
||||
void setlistOwners(const QList<Owner> &objOwner);
|
||||
void setMapOwners(const QMap<int, Owner> &objOwner);
|
||||
|
||||
/**
|
||||
* @brief setLicenseTitle The method sets the copyright message.
|
||||
@ -44,7 +44,7 @@ public:
|
||||
* @brief getLstOwn The method allows you to get the current list of owners.
|
||||
* @return List of owners with full information.
|
||||
*/
|
||||
const QList<Owner>& getLstOwn() const;
|
||||
const QMap<int, Owner>& getMapOwn() const;
|
||||
|
||||
/**
|
||||
* @brief getLicenseTitle Allows you to get a license description.
|
||||
@ -62,17 +62,16 @@ public:
|
||||
* @brief fromJson Reads data from json file.
|
||||
* @return True if everything is correct, otherwise false.
|
||||
*/
|
||||
bool fromJson();
|
||||
bool fromJson(const QString &pathToFile);
|
||||
|
||||
/**
|
||||
* @brief toJson Converts the QJsonDocument to an file JSON.
|
||||
* @return Returns true if the object exists and is filled correctly, otherwise false.
|
||||
*/
|
||||
bool toJson() const;
|
||||
bool toJson(QString &pathToFile) const;
|
||||
|
||||
private:
|
||||
QString filenameJson = "Signature.json";
|
||||
QList<Owner> _ownersList;
|
||||
QMap<int, Owner> _ownersMap;
|
||||
QString _licenseTitle;
|
||||
QString _customMessage;
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user