Commit b64fa557 authored by Ingemar Ceicer's avatar Ingemar Ceicer Committed by GitHub

Add files via upload

parent 2f889c2d
/*
hashSum
Copyright (C) 2011-2016 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.
*/
#include "checkforupdates.h"
#include "hash.h"
void CheckForUpdates::check(std::string sprak)
{
if (sprak == "sv_SE")
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)
{
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;
};
}
}
void CheckForUpdates::checkOnStart(std::string sprak)
{
if (sprak == "sv_SE")
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)
{
QByteArray bytes = reply->readAll(); // bytes
QString version = (QString) bytes; // string
version = version.trimmed();
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;
}
CheckForUpdates::~CheckForUpdates()
{
delete this;
}
/*
hashSum
Copyright (C) 2011-2016 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.
*/
/*
Skall vara definierade:
VERSION_PATH
APPLICATION_NAME
VERSION
APPLICATION_HOMEPAGE
APPLICATION_HOMEPAGE _ENG
*/
#ifndef CHECKFORUPDATESH
#define CHECKFORUPDATESH
#include <QtWidgets>
#include <QNetworkReply>
#include <string>
using namespace std;
class CheckForUpdates : public QWidget
{
Q_OBJECT
private:
QString applicationHomepage;
QNetworkReply *reply;
int jfrVersion(QString);
private slots:
void checkForUpdates(QNetworkReply*);
void checkForUpdatesOnStart(QNetworkReply*);
public:
void check(std::string);
void checkOnStart(std::string);
~CheckForUpdates();
};
#endif // CHECKFORUPDATESH
/*
hashSum
Copyright (C) 2011-2016 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.
*/
#include "config.h"
#include "hash.h"
#include<fstream>
#include<string>
#include<vector>
#include<iostream>
QString configure_path = QDir::toNativeSeparators(QDir::homePath()+"/."+ APPLICATION_NAME);
string my_configure_path = configure_path.toStdString();
using namespace std;
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;
}
Config::~Config()
{
//Skriver configurationsfilen innan dden
writeConf();
}
// 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++)
{
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";
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++)
{
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);
return s;
}
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;
}
}
}
newConf(name, value);
return true;
}
void Config::newConf(string name,string value)
{
string pair = name+"="+value;
name_values->push_back(pair);
}
// 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;
}
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()))
{
return false;
}
vector<string>::iterator it;
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)
{
ifstream infil2;
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())
{
utfil2.close();
return true;
}
return false;
}
/*
Hash
Copyright (C) 2011-2013 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
/*
hashSum
Copyright (C) 2011-2016 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.
*/
#include "createuser.h"
#include "hash.h"
const QString CONF_DIR = QDir::toNativeSeparators(QDir::homePath()+"/." APPLICATION_NAME);
const QString CONF_FILE = CONF_DIR + QDir::toNativeSeparators("/" APPLICATION_NAME ".conf");
bool Createuser::mkDir()
{
QDir dir;
if ( dir.mkdir(CONF_DIR) )
return true;
return false;
}
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;
}
/*
hashSum
Copyright (C) 2011-2016 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 CREATEUSERH
#define CREATEUSERH
#include <QtWidgets>
class Createuser : public QObject
{
Q_OBJECT