Commit 028c3e79 authored by Ingemar Ceicer's avatar Ingemar Ceicer

Clang-Tidy and Clazy

parent 0760e0a3
......@@ -23,7 +23,7 @@
void CheckForUpdates::check(std::string sprak)
void CheckForUpdates::check(const std::string &sprak)
{
if(sprak == "sv_SE")
applicationHomepage = APPLICATION_HOMEPAGE;
......@@ -31,7 +31,7 @@ void CheckForUpdates::check(std::string sprak)
applicationHomepage = APPLICATION_HOMEPAGE_ENG;
QUrl url(VERSION_PATH);
QNetworkAccessManager *nam = new QNetworkAccessManager(this);
auto *nam = new QNetworkAccessManager(this);
reply = nam->get(QNetworkRequest(url));
QObject::connect(nam, SIGNAL(finished(QNetworkReply*)), this, SLOT(checkForUpdates(QNetworkReply*)));
}
......@@ -68,7 +68,7 @@ void CheckForUpdates::checkForUpdates(QNetworkReply *reply)
}
void CheckForUpdates::checkOnStart(std::string sprak)
void CheckForUpdates::checkOnStart(const std::string &sprak)
{
if(sprak == "sv_SE")
applicationHomepage = APPLICATION_HOMEPAGE;
......@@ -76,7 +76,7 @@ void CheckForUpdates::checkOnStart(std::string sprak)
applicationHomepage = APPLICATION_HOMEPAGE_ENG;
QUrl url(VERSION_PATH);
QNetworkAccessManager *nam = new QNetworkAccessManager(this);
auto *nam = new QNetworkAccessManager(this);
reply = nam->get(QNetworkRequest(url));
QObject::connect(nam, SIGNAL(finished(QNetworkReply*)), this, SLOT(checkForUpdatesOnStart(QNetworkReply*)));
}
......@@ -94,7 +94,7 @@ void CheckForUpdates::checkForUpdatesOnStart(QNetworkReply *reply)
// private:
int CheckForUpdates::jfrVersion(QString version)
int CheckForUpdates::jfrVersion(const QString &version)
{
int v, tv;
bool ok;
......
......@@ -33,15 +33,16 @@
using namespace std;
class CheckForUpdates : public QWidget {
class CheckForUpdates : public QWidget
{
Q_OBJECT
private:
QString applicationHomepage;
QNetworkReply *reply;
int jfrVersion(QString);
QNetworkReply const *reply;
int jfrVersion(const QString &);
private slots:
......@@ -52,8 +53,8 @@ private slots:
public:
void check(std::string);
void checkOnStart(std::string);
void check(const string &);
void checkOnStart(const string &);
~CheckForUpdates();
......
......@@ -25,7 +25,7 @@
QString configure_path = QDir::toNativeSeparators(QDir::homePath()+"/."+ APPLICATION_NAME);
QString configure_path = QDir::toNativeSeparators(QDir::homePath() + "/." + APPLICATION_NAME);
string my_configure_path = configure_path.toStdString();
......@@ -40,7 +40,7 @@ Config::Config(QString namn)
{
//Lser in configurationsfilen i minnet
//vid skapandet
namn=namn.trimmed();
namn = namn.trimmed();
//Hela skvgen
QString configure = configure_path + QDir::toNativeSeparators(namn);
string configure_s = configure.toStdString();
......@@ -61,142 +61,148 @@ Config::~Config()
}
// Lmnar ut "values" grundade p "name"
string Config::getConf(string name)
string Config::getConf(const string &name)
{
vector<string>::iterator it;
string s;
for (it=name_values->begin(); it<name_values->end(); it++)
{
if (it->substr(0,1) != "#") // hoppa ver kommaterade rader direkt
{
// Sker efter samma delstrng som skickas hit med samma lngd
// som hitskickade strngen. Samt att nsta tecken r "="
// Fr att undvika fel typ: gustav gustavson
if ((it->substr(0,name.size()) == name) && (it->substr(name.size(),1) == "="))
{
// Returnerar frn tecknet efter "=" tecknet och til radens slut
s = it->substr(name.size()+1,it->size());
return s;
}
}
for(it = name_values->begin(); it < name_values->end(); it++) {
if(it->substr(0, 1) != "#") { // hoppa ver kommaterade rader direkt
// Sker efter samma delstrng som skickas hit med samma lngd
// som hitskickade strngen. Samt att nsta tecken r "="
// Fr att undvika fel typ: gustav gustavson
if((it->substr(0, name.size()) == name) && (it->substr(name.size(), 1) == "=")) {
// Returnerar frn tecknet efter "=" tecknet och til radens slut
s = it->substr(name.size() + 1, it->size());
return s;
}
}
s="nothing";
}
s = "nothing";
return s;
}
string Config::getConf(string name, string default_value)
string Config::getConf(const string &name, const string &default_value)
{
vector<string>::iterator it;
string s;
for (it=name_values->begin(); it<name_values->end(); it++)
{
if (it->substr(0,1) != "#") // hoppa ver kommaterade rader direkt
{
// Sker efter samma delstrng som skickas hit med samma lngd
// som hitskickade strngen. Samt att nsta tecken r "="
// Fr att undvika fel typ: gustav gustavson
if ((it->substr(0,name.size()) == name) && (it->substr(name.size(),1) == "="))
{
// Returnerar frn tecknet efter "=" tecknet och til radens slut
s = it->substr(name.size()+1,it->size());
return s;
}
}
for(it = name_values->begin(); it < name_values->end(); it++) {
if(it->substr(0, 1) != "#") { // hoppa ver kommaterade rader direkt
// Sker efter samma delstrng som skickas hit med samma lngd
// som hitskickade strngen. Samt att nsta tecken r "="
// Fr att undvika fel typ: gustav gustavson
if((it->substr(0, name.size()) == name) && (it->substr(name.size(), 1) == "=")) {
// Returnerar frn tecknet efter "=" tecknet och til radens slut
s = it->substr(name.size() + 1, it->size());
return s;
}
}
s=default_value;
newConf(name,default_value);
}
s = default_value;
newConf(name, default_value);
return s;
}
bool Config::setConf(string name,string value)
bool Config::setConf(string name, string value)
{
vector<string>::iterator it;
for (it=name_values->begin(); it<name_values->end(); it++)
{
if (it->substr(0,1) != "#") // hoppa ver kommaterade rader direkt
{
// Sker efter strngen "name" som skickas hit med samma lngd
// som hitskickade strngen. Samt att nsta tecken r "="
// Fr att undvika fel typ: gustav gustavson
if ((it->substr(0,name.size()) == name) && (it->substr(name.size(),1) == "="))
{
// Returnerar frn tecknet efter "=" tecknet och til radens slut
// "name" har hittats, nu skall nya vrdet lggaas in
name.append("=");
name.append(value);
*it = name;
return true;
}
}
for(it = name_values->begin(); it < name_values->end(); it++) {
if(it->substr(0, 1) != "#") { // hoppa ver kommaterade rader direkt
// Sker efter strngen "name" som skickas hit med samma lngd
// som hitskickade strngen. Samt att nsta tecken r "="
// Fr att undvika fel typ: gustav gustavson
if((it->substr(0, name.size()) == name) && (it->substr(name.size(), 1) == "=")) {
// Returnerar frn tecknet efter "=" tecknet och til radens slut
// "name" har hittats, nu skall nya vrdet lggaas in
name.append("=");
name.append(value);
*it = name;
return true;
}
}
}
newConf(name, value);
return true;
}
void Config::newConf(string name,string value)
void Config::newConf(const string &name, string value)
{
string pair = name+"="+value;
string pair = name + "=" + value;
name_values->push_back(pair);
}
// Lser configurationsvektorn
bool Config::readConf(string conf)
bool Config::readConf(const string &conf)
{
name_values = new vector<string>;
string conf_values;
ifstream infil;
infil.open(conf.c_str());
if (!(infil.good()))
if(!(infil.good()))
return false;
while (getline(infil,conf_values))
while(getline(infil, conf_values))
name_values->push_back(conf_values);
infil.close();
return true;
}
// skriver configurationsvektorn till fil
bool Config::writeConf()
{
ofstream utfil;
utfil.open (conf_file->c_str(),ios::out);
if (!(utfil.is_open()))
utfil.open(conf_file->c_str(), ios::out);
if(!(utfil.is_open()))
return false;
vector<string>::iterator it;
for (it=name_values->begin(); it<name_values->end(); it++)
{
utfil << *it;
utfil << "\n";
}
for(it = name_values->begin(); it < name_values->end(); it++) {
utfil << *it;
utfil << "\n";
}
delete conf_file;
return true;
}
// kollar om konfigurationsfilen finns
void Config::checkConf(string conf)
void Config::checkConf(const string &conf)
{
ifstream infil2;
infil2.open(conf.c_str());
infil2.seekg(0,ios::end);
if (infil2.tellg() < 1)
{
infil2.close();
createConffile(conf);
}
infil2.seekg(0, ios::end);
if(infil2.tellg() < 1) {
infil2.close();
createConffile(conf);
}
}
// skapar en default konfigurationsfil
bool Config::createConffile(string conf)
bool Config::createConffile(const string &conf)
{
cr->mkDir();
ofstream utfil2;
utfil2.open (conf.c_str(),ios::out);
if (utfil2.good())
{
utfil2.close();
return true;
}
utfil2.open(conf.c_str(), ios::out);
if(utfil2.good()) {
utfil2.close();
return true;
}
return false;
}
......
......@@ -28,18 +28,20 @@
using namespace std;
class Config {
class Config
{
private:
vector<string> *name_values;
bool createConffile(string conf);
void checkConf(string conf);
bool readConf(string conf);
vector<string> *name_values{};
bool createConffile(const string &conf);
void checkConf(const string &conf);
bool readConf(const string &conf);
bool writeConf();
void newConf(string name,string value);
void newConf(const string &name, string value);
string *conf_file;
Createuser *cr;
......@@ -52,9 +54,9 @@ public:
string getConf(string name);
string getConf(string name, string default_value);
bool setConf(string name,string value);
string getConf(const string &name);
string getConf(const string &name, const string &default_value);
bool setConf(string name, string value);
};
......
......@@ -18,7 +18,7 @@
#include "createuser.h"
#include "hash.h"
const QString CONF_DIR = QDir::toNativeSeparators(QDir::homePath()+"/." APPLICATION_NAME);
const QString CONF_DIR = QDir::toNativeSeparators(QDir::homePath() + "/." APPLICATION_NAME);
const QString CONF_FILE = CONF_DIR + QDir::toNativeSeparators("/" APPLICATION_NAME ".conf");
......@@ -26,9 +26,7 @@ const QString CONF_FILE = CONF_DIR + QDir::toNativeSeparators("/" APPLICATION_NA
bool Createuser::mkDir()
{
QDir dir;
if ( dir.mkdir(CONF_DIR) )
return true;
return false;
return dir.mkdir(CONF_DIR);
}
......@@ -37,19 +35,16 @@ bool Createuser::mkDir()
bool Createuser::removeDir()
{
QDir dir;
if ( dir.remove(CONF_FILE) && dir.remove(CONF_FILE) )
{
if (dir.rmdir(CONF_DIR))
return true;
}
if ( dir.remove(CONF_FILE) )
{
if (dir.rmdir(CONF_DIR))
return true;
}
if (dir.rmdir(CONF_DIR))
return true;
return false;
}
if(dir.remove(CONF_FILE) && dir.remove(CONF_FILE)) {
if(dir.rmdir(CONF_DIR))
return true;
}
if(dir.remove(CONF_FILE)) {
if(dir.rmdir(CONF_DIR))
return true;
}
return dir.rmdir(CONF_DIR);
}
......@@ -59,7 +59,7 @@ void Hash::findDuplicates()
if(dialog->exec()) {
ui->progressLabel->clear();
ui->progressLabel->toolTip().clear();
// ui->progressLabel->toolTip().clear();
ui->lineEdit->clear();
QDir dir = dialog->directory();
directoryName = dir.path();
......@@ -69,7 +69,6 @@ void Hash::findDuplicates()
return;
}
QString tmp = "";
QVector<Hash::PathHash> v_ph;
std::string algoritm = k->getConf("algorithm");
QString alg = QString::fromStdString(algoritm);
......@@ -79,15 +78,15 @@ void Hash::findDuplicates()
/* */
bool lyckats = rekursivt2(directoryName, v_ph, alg, qopen_path);
if(lyckats == false)
if(!lyckats)
QMessageBox::critical(this, APPLICATION_NAME " " VERSION, tr("Could not check the hash sum. Check your file permissions."));
collectDuplicates(v_ph, directoryName);
}
bool Hash::rekursivt2(QDir path, QVector<Hash::PathHash> &v_ph, QString alg, QString qopen_path)
bool Hash::rekursivt2(const QDir &path, QVector<PathHash> &v_ph, const QString &alg, const QString &qopen_path)
{
QString conf_file_name = QDir::toNativeSeparators("/" APPLICATION_NAME ".conf");
// const QString &conf_file_name = QDir::toNativeSeparators("/" APPLICATION_NAME ".conf");
QFileInfoList list = path.entryInfoList(QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot);
PathHash ph;
......@@ -131,7 +130,7 @@ bool Hash::rekursivt2(QDir path, QVector<Hash::PathHash> &v_ph, QString alg, QSt
QString Hash::checksum2(QString in, QString s)
QString Hash::checksum2(const QString &in, const QString &s)
{
QByteArray ba;
QFile f(in);
......@@ -180,7 +179,7 @@ QString Hash::checksum2(QString in, QString s)
ut = (QString) sum;
return ut;
}
void Hash::collectDuplicates(QVector<PathHash> &v_ph, QString directoryNamne)
void Hash::collectDuplicates(QVector<PathHash> &v_ph, const QString &directoryNamne)
{
QStringList path;
QStringList hash;
......@@ -212,7 +211,7 @@ void Hash::collectDuplicates(QVector<PathHash> &v_ph, QString directoryNamne)
}
}
auto sortFunc = [](PathHash a, PathHash b) -> bool {
auto sortFunc = [](const PathHash & a, const PathHash & b) -> bool {
return a.hash < b.hash;
};
std::sort(ny.begin(), ny.end(), sortFunc);
......
......@@ -22,9 +22,8 @@ ExtQLineEdit::ExtQLineEdit(QWidget *parent) : QLineEdit(parent)
{
}
ExtQLineEdit::~ExtQLineEdit()
{
}
ExtQLineEdit::~ExtQLineEdit() = default;
......
This diff is collapsed.
......@@ -81,50 +81,50 @@ protected:
private:
Ui::Hash *ui;
Ui::Lic *ui2;
Config *k;
QDialog *d;
Ui::Hash *ui{};
Ui::Lic *ui2{};
Config *k{};
QDialog *d{};
void setStartConfig();
void setEndConfig();
bool doChecksum(QString);
bool doChecksum(QString, QStringList *lista);
bool doChecksumText(const QString);
bool doChecksumList(QString, QString &, std::string);
bool doCompare(QString, QString);
bool askForFileName(QString, std::string, QStringList);
bool askForFileNameCheck(QString, std::string, QStringList);
bool dontAskForFileName(std::string, QStringList);
bool doChecksum(const QString &);
bool doChecksum(const QString &, QStringList *lista);
bool doChecksumText(const QString &);
bool doChecksumList(const QString &, QString &, const string &);
bool doCompare(const QString &, const QString &);
bool askForFileName(const QString &, const string &, QStringList);
bool askForFileNameCheck(const QString &, const string &, QStringList);
bool dontAskForFileName(const string &, QStringList);
QString datumtid();
bool rekursivt(QDir, QString);
bool rekursivt(const QDir &, QString);
bool rekursivtPrint(QString, QString, QDir, std::string);
int hurmangaFoldrar;
bool rekursivtPrint(const QString &, const QString &, QDir, std::string);
int hurmangaFoldrar{};
void checkSumList(int);
int hurmangaFiler;
bool createDeb(QString sokvag2, QStringList fileNames);
int hurmangaFiler{};
bool createDeb(const QString &sokvag2, QStringList fileNames);
QString getSystem();
bool rekursivtDeb(QDir path, QString &indent, QStringList &allt);
bool rekursivtDeb(const QDir &path, QString &indent, QStringList &allt);
bool rekursivtPrintDeb(QDir path, QStringList &allt);
bool recentFileList(QString);
QStringList recentFiles;
int MAX_RECENT_FILES;
int MAX_RECENT_FILES{};
QStringList algoritmer;
QStringList *lista;
QStringList *lista{};
/* DUPLICATES */
void findDuplicates();
QString checksum2(const QString in, QString s);
QString checksum2(const QString &in, const QString &s);
struct PathHash {
QString path;
QString hash;
};
void collectDuplicates(QVector<PathHash> &v_ph, QString directoryNamne);
bool rekursivt2(QDir, QVector<Hash::PathHash> &v_ph, QString alg, QString qopen_path);
void collectDuplicates(QVector<PathHash> &v_ph, const QString &directoryNamne);
bool rekursivt2(const QDir &, QVector<PathHash> &v_ph, const QString &alg, const QString &qopen_path);
static bool compareAlphabet(const Hash::PathHash & a, const Hash::PathHash & b);
......@@ -179,7 +179,7 @@ private slots:
void showFullPathInHashSumFile();
void slotRecentFiles();
void recentFileRequested(const QString path);
void recentFileRequested(const QString &path);
void setRecentFiles();
void clearRecentFiles();
void stang();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment