Commit a1dbac9b authored by Ingemar Ceicer's avatar Ingemar Ceicer

Source files formatted with astyle


Former-commit-id: f0707923
parent 37567d04
......@@ -29,15 +29,10 @@ void CheckForUpdates::check(std::string sprak)
applicationHomepage = APPLICATION_HOMEPAGE;
else
applicationHomepage = APPLICATION_HOMEPAGE_ENG;
QUrl url(VERSION_PATH);
QNetworkAccessManager *nam = new QNetworkAccessManager(this);
reply = nam->get(QNetworkRequest(url));
QObject::connect(nam, SIGNAL(finished(QNetworkReply*)),this, SLOT(checkForUpdates(QNetworkReply*)));
}
void CheckForUpdates::checkForUpdates(QNetworkReply *reply)
......@@ -45,33 +40,27 @@ void CheckForUpdates::checkForUpdates(QNetworkReply *reply)
QByteArray bytes = reply->readAll(); // bytes
QString version = (QString) bytes; // string
version = version.trimmed();
if (version == "")
QMessageBox::critical(this,APPLICATION_NAME " " VERSION, tr("No Internet connection was found.\nPlease check your Internet settings and firewall."));
else
{
int ver = jfrVersion(version);
switch (ver)
{
case 0:
QMessageBox::information(this,APPLICATION_NAME " " VERSION, tr("\nThere is a later version of ")+ APPLICATION_NAME + "<br>"+tr("Please download from")+"<p><a href=\"" + applicationHomepage + "\">" + applicationHomepage + "</a></p><p>"+tr("Latest version: ")+version+"</p>");
break;
case 1:
QMessageBox::information(this,APPLICATION_NAME " " VERSION, tr("\nYour version of ")+ APPLICATION_NAME+tr(" is later than the latest official version ")+"("+version+").");
break;
case 2:
QMessageBox::information(this,APPLICATION_NAME " " VERSION, tr("\nYou have the latest version of ")+ APPLICATION_NAME +".");
break;
default:
QMessageBox::information(this,APPLICATION_NAME " " VERSION, tr("\nThere was an error when the version was checked."));
break;
};
}
{
int ver = jfrVersion(version);
switch (ver)
{
case 0:
QMessageBox::information(this,APPLICATION_NAME " " VERSION, tr("\nThere is a later version of ")+ APPLICATION_NAME + "<br>"+tr("Please download from")+"<p><a href=\"" + applicationHomepage + "\">" + applicationHomepage + "</a></p><p>"+tr("Latest version: ")+version+"</p>");
break;
case 1:
QMessageBox::information(this,APPLICATION_NAME " " VERSION, tr("\nYour version of ")+ APPLICATION_NAME+tr(" is later than the latest official version ")+"("+version+").");
break;
case 2:
QMessageBox::information(this,APPLICATION_NAME " " VERSION, tr("\nYou have the latest version of ")+ APPLICATION_NAME +".");
break;
default:
QMessageBox::information(this,APPLICATION_NAME " " VERSION, tr("\nThere was an error when the version was checked."));
break;
};
}
}
......@@ -81,16 +70,10 @@ void CheckForUpdates::checkOnStart(std::string sprak)
applicationHomepage = APPLICATION_HOMEPAGE;
else
applicationHomepage = APPLICATION_HOMEPAGE_ENG;
QUrl url(VERSION_PATH);
QNetworkAccessManager *nam = new QNetworkAccessManager(this);
reply = nam->get(QNetworkRequest(url));
QObject::connect(nam, SIGNAL(finished(QNetworkReply*)),this, SLOT(checkForUpdatesOnStart(QNetworkReply*)));
}
void CheckForUpdates::checkForUpdatesOnStart(QNetworkReply *reply)
......@@ -98,40 +81,32 @@ void CheckForUpdates::checkForUpdatesOnStart(QNetworkReply *reply)
QByteArray bytes = reply->readAll(); // bytes
QString version = (QString) bytes; // string
version = version.trimmed();
int ver = jfrVersion(version);
int ver = jfrVersion(version);
if (ver == 0)
QMessageBox::information(this,APPLICATION_NAME " " VERSION, tr("\nThere is a later version of ")+ APPLICATION_NAME +"<br>"+tr("Please download from")+"<p><a href=&quot;"+ applicationHomepage + "&quot;>" + applicationHomepage + "</a></p><p>"+tr("Latest version: ")+version+"</p>");
}
// private:
int CheckForUpdates::jfrVersion(QString version)
{
int v, tv;
bool ok;
QString this_version(VERSION);
QStringList l_this_version = this_version.split(".");
QStringList l_version = version.split(".");
for (int i=0;i<=2;i++)
{
v = l_version[i].toInt(&ok, 10);
tv = l_this_version[i].toInt(&ok, 10);
if (!ok)
return 3;
if (v>tv)
return 0;
if (v<tv)
return 1;
}
return 2;
int v, tv;
bool ok;
QString this_version(VERSION);
QStringList l_this_version = this_version.split(".");
QStringList l_version = version.split(".");
for (int i=0; i<=2; i++)
{
v = l_version[i].toInt(&ok, 10);
tv = l_this_version[i].toInt(&ok, 10);
if (!ok)
return 3;
if (v>tv)
return 0;
if (v<tv)
return 1;
}
return 2;
}
CheckForUpdates::~CheckForUpdates()
......
......@@ -33,10 +33,9 @@
using namespace std;
class CheckForUpdates : public QWidget
{
class CheckForUpdates : public QWidget {
Q_OBJECT
Q_OBJECT
private:
......@@ -53,9 +52,9 @@ private slots:
public:
void check(std::string);
void checkOnStart(std::string);
~CheckForUpdates();
void check(std::string);
void checkOnStart(std::string);
~CheckForUpdates();
......
......@@ -40,20 +40,15 @@ Config::Config(QString namn)
{
//Lser in configurationsfilen i minnet
//vid skapandet
namn=namn.trimmed();
//Hela skvgen
QString configure = configure_path + QDir::toNativeSeparators(namn);
string configure_s = configure.toStdString();
conf_file = new string;
*conf_file = configure_s;
cr = new Createuser;
checkConf(configure_s);
readConf(configure_s);
delete cr;
}
......@@ -68,56 +63,46 @@ Config::~Config()
// Lmnar ut "values" grundade p "name"
string Config::getConf(string name)
{
vector<string>::iterator it;
string s;
for (it=name_values->begin();it<name_values->end();it++)
{
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;
// 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";
return s;
}
string Config::getConf(string name, string default_value)
{
vector<string>::iterator it;
string s;
for (it=name_values->begin();it<name_values->end();it++)
{
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;
// 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);
return s;
......@@ -125,30 +110,27 @@ for (it=name_values->begin();it<name_values->end();it++)
bool Config::setConf(string name,string value)
{
vector<string>::iterator it;
for (it=name_values->begin();it<name_values->end();it++)
{
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;
// 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;
}
newConf(name, value);
return true;
}
......@@ -164,26 +146,16 @@ void Config::newConf(string name,string value)
// Lser configurationsvektorn
bool Config::readConf(string conf)
{
name_values = new vector<string>;
string conf_values;
ifstream infil;
infil.open(conf.c_str());
if (!(infil.good()))
{
return false;
}
return false;
while (getline(infil,conf_values))
{
name_values->push_back(conf_values);
}
infil.close();
return true;
}
// skriver configurationsvektorn till fil
......@@ -192,18 +164,15 @@ bool Config::writeConf()
ofstream utfil;
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)
......@@ -212,38 +181,23 @@ void Config::checkConf(string conf)
infil2.open(conf.c_str());
infil2.seekg(0,ios::end);
if (infil2.tellg() < 1)
{
{
infil2.close();
createConffile(conf);
}
}
}
// skapar en default konfigurationsfil
bool Config::createConffile(string conf)
{
cr->mkDir();
ofstream utfil2;
utfil2.open (conf.c_str(),ios::out);
if (utfil2.good())
ofstream utfil2;
utfil2.open (conf.c_str(),ios::out);
if (utfil2.good())
{
utfil2.close();
return true;
utfil2.close();
return true;
}
return false;
return false;
}
/*
Hash
Copyright (C) 2011-2017 Ingemar Ceicer
http://ceicer.org/
programmering1 (at) ceicer (dot) org
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
*/
#ifndef CONFIGH
#define CONFIGH
#include<string>
#include<vector>
#include "createuser.h"
using namespace std;
class Config
{
private:
vector<string> *name_values;
bool createConffile(string conf);
void checkConf(string conf);
bool readConf(string conf);
bool writeConf();
void newConf(string name,string value);
string *conf_file;
Createuser *cr;
public:
Config(QString namn);
~Config();
string getConf(string name);
string getConf(string name, string default_value);
bool setConf(string name,string value);
};
#endif // CONFIGH
......@@ -26,15 +26,9 @@ 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 false;
}
......@@ -44,22 +38,18 @@ bool Createuser::removeDir()
{
QDir dir;
if ( dir.remove(CONF_FILE) && dir.remove(CONF_FILE) )
{
if (dir.rmdir(CONF_DIR))
return true;
}
{
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;
}
if (dir.rmdir(CONF_DIR))
return true;
return false;
return true;
return false;
}
......@@ -22,11 +22,10 @@
class Createuser : public QObject
{
class Createuser : public QObject {
Q_OBJECT
public:
bool mkDir();
......@@ -34,9 +33,9 @@ public:
std::string readDir();
};
#endif // CREATEUSERH
......@@ -20,7 +20,6 @@
ExtQLineEdit::ExtQLineEdit(QWidget *parent) : QLineEdit(parent)
{
}
ExtQLineEdit::~ExtQLineEdit()
......@@ -32,41 +31,26 @@ ExtQLineEdit::~ExtQLineEdit()
void ExtQLineEdit::mouseDoubleClickEvent ( QMouseEvent * event )
{
this->setToolTip(tr(""));
this->setToolTip(tr(""));
if (event->button() == Qt::LeftButton)
{
if (this->text() != "" && this->text().mid(0,7) != tr("Mission"))
{
QClipboard *clipboard = QApplication::clipboard();
clipboard->setText(this->text());
this->setToolTip(tr("Hash sum has been copied to the clipboard"));
if (this->text() != "" && this->text().mid(0,7) != tr("Mission"))
{
QClipboard *clipboard = QApplication::clipboard();
clipboard->setText(this->text());
this->setToolTip(tr("Hash sum has been copied to the clipboard"));
}
}
}
}
void ExtQLineEdit::mouseMoveEvent(QMouseEvent * event)
{
event->accept();
if (this->text() != "" && this->text().mid(0,7) != tr("Mission"))
{
event->accept();
if (this->text() != "" && this->text().mid(0,7) != tr("Mission"))
{
if (this->toolTip() != tr("Hash sum has been copied to the clipboard"))
this->setToolTip(tr("Double-click to copy to clipboard"));
}
else
this->setToolTip(tr(""));