From 138a55cae9aa68c751730e8b23190ec2e1edd25f Mon Sep 17 00:00:00 2001 From: mrpostiga Date: Thu, 20 Oct 2016 02:12:06 +0100 Subject: [PATCH 1/2] Add files via upload * Corrected work with cpuminer 2.4.5 built on Jun 10 2016 Fix handling of additional parameters Fix url links for litecoinpool.org --- EasyMiner.pro | 54 +-- README.txt | 64 +-- icon.qrc | 14 +- json.cpp | 856 +++++++++++++++++----------------- json.h | 314 ++++++------- main.cpp | 22 +- mainwindow.cpp | 1219 ++++++++++++++++++++++++------------------------ mainwindow.h | 236 +++++----- mainwindow.ui | 1196 +++++++++++++++++++++++------------------------ poolparse.cpp | 178 +++---- poolparse.h | 44 +- qlogger.cpp | 35 ++ qlogger.h | 30 ++ 13 files changed, 2162 insertions(+), 2100 deletions(-) create mode 100644 qlogger.cpp create mode 100644 qlogger.h diff --git a/EasyMiner.pro b/EasyMiner.pro index 3f1fccd..494f379 100644 --- a/EasyMiner.pro +++ b/EasyMiner.pro @@ -1,26 +1,28 @@ -#------------------------------------------------- -# -# Project created by QtCreator 2011-10-14T18:13:25 -# -#------------------------------------------------- - -QT += core gui network - -TARGET = ScryptMiner GUI -TEMPLATE = app - -SOURCES += main.cpp\ - mainwindow.cpp \ - poolparse.cpp \ - json.cpp - -HEADERS += mainwindow.h \ - poolparse.h \ - json.h - -FORMS += mainwindow.ui - -RESOURCES += \ - icon.qrc - - +#------------------------------------------------- +# +# Project created by QtCreator 2011-10-14T18:13:25 +# +#------------------------------------------------- + +QT += core gui network + +TARGET = ScryptMiner GUI +TEMPLATE = app + +SOURCES += main.cpp\ + mainwindow.cpp \ + poolparse.cpp \ + json.cpp \ + qlogger.cpp + +HEADERS += mainwindow.h \ + poolparse.h \ + json.h \ + qlogger.h + +FORMS += mainwindow.ui + +RESOURCES += \ + icon.qrc + + diff --git a/README.txt b/README.txt index dde1799..67ba862 100644 --- a/README.txt +++ b/README.txt @@ -1,33 +1,33 @@ -ScryptMiner-GUI -=== - -A simple GUI for the scrypt-based cpuminer written in C++ using Qt. - -To use, copy the minerd executable to the same directory as the GUI itself, alongside with any needed libraries. -After that, just run the GUI executable. - -=== - -LICENSING INFORMATION - -=== - -Copyright (C) 2011 by Matoking - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +ScryptMiner-GUI +=== + +A simple GUI for the scrypt-based cpuminer written in C++ using Qt. + +To use, copy the minerd executable to the same directory as the GUI itself, alongside with any needed libraries. +After that, just run the GUI executable. + +=== + +LICENSING INFORMATION + +=== + +Copyright (C) 2011 by Matoking + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/icon.qrc b/icon.qrc index 0b9d3be..473a92b 100644 --- a/icon.qrc +++ b/icon.qrc @@ -1,7 +1,7 @@ - - - icon_active.png - icon_inactive.png - icon.png - - + + + icon_active.png + icon_inactive.png + icon.png + + diff --git a/json.cpp b/json.cpp index 22bf02e..7cc6fa0 100644 --- a/json.cpp +++ b/json.cpp @@ -1,428 +1,428 @@ -/** - * \file json.h - * - * \author Eeli Reilin , - * Mikko Ahonen - * \version 0.1 - * \date 8/25/2010 - */ - -#include - -#include "json.h" - -/** - * parse - */ -QVariant Json::parse(const QString &json) -{ - bool success = true; - return Json::parse(json, success); -} - -/** - * parse - */ -QVariant Json::parse(const QString &json, bool &success) -{ - success = true; - - //Return an empty QVariant if the JSON data is either null or empty - if(!json.isNull() || !json.isEmpty()) - { - QString data = json; - //We'll start from index 0 - int index = 0; - - //Parse the first value - QVariant value = Json::parseValue(data, index, success); - - //Return the parsed value - return value; - } - else - { - //Return the empty QVariant - return QVariant(); - } -} - -/** - * parseValue - */ -QVariant Json::parseValue(const QString &json, int &index, bool &success) -{ - //Determine what kind of data we should parse by - //checking out the upcoming token - switch(Json::lookAhead(json, index)) - { - case JsonTokenString: - return Json::parseString(json, index, success); - case JsonTokenNumber: - return Json::parseNumber(json, index); - case JsonTokenCurlyOpen: - return Json::parseObject(json, index, success); - case JsonTokenSquaredOpen: - return Json::parseArray(json, index, success); - case JsonTokenTrue: - Json::nextToken(json, index); - return QVariant(true); - case JsonTokenFalse: - Json::nextToken(json, index); - return QVariant(false); - case JsonTokenNull: - Json::nextToken(json, index); - return QVariant(); - case JsonTokenNone: - break; - } - - //If there were no tokens, flag the failure and return an empty QVariant - success = false; - return QVariant(); -} - -/** - * parseObject - */ -QVariant Json::parseObject(const QString &json, int &index, bool &success) -{ - QVariantMap map; - int token; - - //Get rid of the whitespace and increment index - Json::nextToken(json, index); - - //Loop through all of the key/value pairs of the object - bool done = false; - while(!done) - { - //Get the upcoming token - token = Json::lookAhead(json, index); - - if(token == JsonTokenNone) - { - success = false; - return QVariantMap(); - } - else if(token == JsonTokenComma) - { - Json::nextToken(json, index); - } - else if(token == JsonTokenCurlyClose) - { - Json::nextToken(json, index); - return map; - } - else - { - //Parse the key/value pair's name - QString name = Json::parseString(json, index, success).toString(); - - if(!success) - { - return QVariantMap(); - } - - //Get the next token - token = Json::nextToken(json, index); - - //If the next token is not a colon, flag the failure - //return an empty QVariant - if(token != JsonTokenColon) - { - success = false; - return QVariant(QVariantMap()); - } - - //Parse the key/value pair's value - QVariant value = Json::parseValue(json, index, success); - - if(!success) - { - return QVariantMap(); - } - - //Assign the value to the key in the map - map[name] = value; - } - } - - //Return the map successfully - return QVariant(map); -} - -/** - * parseArray - */ -QVariant Json::parseArray(const QString &json, int &index, bool &success) -{ - QVariantList list; - - Json::nextToken(json, index); - - bool done = false; - while(!done) - { - int token = Json::lookAhead(json, index); - - if(token == JsonTokenNone) - { - success = false; - return QVariantList(); - } - else if(token == JsonTokenComma) - { - Json::nextToken(json, index); - } - else if(token == JsonTokenSquaredClose) - { - Json::nextToken(json, index); - break; - } - else - { - QVariant value = Json::parseValue(json, index, success); - - if(!success) - { - return QVariantList(); - } - - list.push_back(value); - } - } - - return QVariant(list); -} - -/** - * parseString - */ -QVariant Json::parseString(const QString &json, int &index, bool &success) -{ - QString s; - QChar c; - - Json::eatWhitespace(json, index); - - c = json[index++]; - - bool complete = false; - while(!complete) - { - if(index == json.size()) - { - break; - } - - c = json[index++]; - - if(c == '\"') - { - complete = true; - break; - } - else if(c == '\\') - { - if(index == json.size()) - { - break; - } - - c = json[index++]; - - if(c == '\"') - { - s.append('\"'); - } - else if(c == '\\') - { - s.append('\\'); - } - else if(c == '/') - { - s.append('/'); - } - else if(c == 'b') - { - s.append('\b'); - } - else if(c == 'f') - { - s.append('\f'); - } - else if(c == 'n') - { - s.append('\n'); - } - else if(c == 'r') - { - s.append('\r'); - } - else if(c == 't') - { - s.append('\t'); - } - else if(c == 'u') - { - int remainingLength = json.size() - index; - - if(remainingLength >= 4) - { - QString unicodeStr = json.mid(index, 4); - - int symbol = unicodeStr.toInt(0, 16); - - s.append(QChar(symbol)); - - index += 4; - } - else - { - break; - } - } - } - else - { - s.append(c); - } - } - - if(!complete) - { - success = false; - return QVariant(); - } - - return QVariant(s); -} - -/** - * parseNumber - */ -QVariant Json::parseNumber(const QString &json, int &index) -{ - Json::eatWhitespace(json, index); - - int lastIndex = Json::lastIndexOfNumber(json, index); - int charLength = (lastIndex - index) + 1; - QString numberStr; - - numberStr = json.mid(index, charLength); - - index = lastIndex + 1; - - return QVariant(numberStr); -} - -/** - * lastIndexOfNumber - */ -int Json::lastIndexOfNumber(const QString &json, int index) -{ - int lastIndex; - - for(lastIndex = index; lastIndex < json.size(); lastIndex++) - { - if(QString("0123456789+-.eE").indexOf(json[lastIndex]) == -1) - { - break; - } - } - - return lastIndex -1; -} - -/** - * eatWhitespace - */ -void Json::eatWhitespace(const QString &json, int &index) -{ - for(; index < json.size(); index++) - { - if(QString(" \t\n\r").indexOf(json[index]) == -1) - { - break; - } - } -} - -/** - * lookAhead - */ -int Json::lookAhead(const QString &json, int index) -{ - int saveIndex = index; - return Json::nextToken(json, saveIndex); -} - -/** - * nextToken - */ -int Json::nextToken(const QString &json, int &index) -{ - Json::eatWhitespace(json, index); - - if(index == json.size()) - { - return JsonTokenNone; - } - - QChar c = json[index]; - index++; - switch(c.toAscii()) - { - case '{': return JsonTokenCurlyOpen; - case '}': return JsonTokenCurlyClose; - case '[': return JsonTokenSquaredOpen; - case ']': return JsonTokenSquaredClose; - case ',': return JsonTokenComma; - case '"': return JsonTokenString; - case '0': case '1': case '2': case '3': case '4': - case '5': case '6': case '7': case '8': case '9': - case '-': return JsonTokenNumber; - case ':': return JsonTokenColon; - } - - index--; - - int remainingLength = json.size() - index; - - //True - if(remainingLength >= 4) - { - if (json[index] == 't' && json[index + 1] == 'r' && - json[index + 2] == 'u' && json[index + 3] == 'e') - { - index += 4; - return JsonTokenTrue; - } - } - - //False - if (remainingLength >= 5) - { - if (json[index] == 'f' && json[index + 1] == 'a' && - json[index + 2] == 'l' && json[index + 3] == 's' && - json[index + 4] == 'e') - { - index += 5; - return JsonTokenFalse; - } - } - - //Null - if (remainingLength >= 4) - { - if (json[index] == 'n' && json[index + 1] == 'u' && - json[index + 2] == 'l' && json[index + 3] == 'l') - { - index += 4; - return JsonTokenNull; - } - } - - return JsonTokenNone; -} +/** + * \file json.h + * + * \author Eeli Reilin , + * Mikko Ahonen + * \version 0.1 + * \date 8/25/2010 + */ + +#include + +#include "json.h" + +/** + * parse + */ +QVariant Json::parse(const QString &json) +{ + bool success = true; + return Json::parse(json, success); +} + +/** + * parse + */ +QVariant Json::parse(const QString &json, bool &success) +{ + success = true; + + //Return an empty QVariant if the JSON data is either null or empty + if(!json.isNull() || !json.isEmpty()) + { + QString data = json; + //We'll start from index 0 + int index = 0; + + //Parse the first value + QVariant value = Json::parseValue(data, index, success); + + //Return the parsed value + return value; + } + else + { + //Return the empty QVariant + return QVariant(); + } +} + +/** + * parseValue + */ +QVariant Json::parseValue(const QString &json, int &index, bool &success) +{ + //Determine what kind of data we should parse by + //checking out the upcoming token + switch(Json::lookAhead(json, index)) + { + case JsonTokenString: + return Json::parseString(json, index, success); + case JsonTokenNumber: + return Json::parseNumber(json, index); + case JsonTokenCurlyOpen: + return Json::parseObject(json, index, success); + case JsonTokenSquaredOpen: + return Json::parseArray(json, index, success); + case JsonTokenTrue: + Json::nextToken(json, index); + return QVariant(true); + case JsonTokenFalse: + Json::nextToken(json, index); + return QVariant(false); + case JsonTokenNull: + Json::nextToken(json, index); + return QVariant(); + case JsonTokenNone: + break; + } + + //If there were no tokens, flag the failure and return an empty QVariant + success = false; + return QVariant(); +} + +/** + * parseObject + */ +QVariant Json::parseObject(const QString &json, int &index, bool &success) +{ + QVariantMap map; + int token; + + //Get rid of the whitespace and increment index + Json::nextToken(json, index); + + //Loop through all of the key/value pairs of the object + bool done = false; + while(!done) + { + //Get the upcoming token + token = Json::lookAhead(json, index); + + if(token == JsonTokenNone) + { + success = false; + return QVariantMap(); + } + else if(token == JsonTokenComma) + { + Json::nextToken(json, index); + } + else if(token == JsonTokenCurlyClose) + { + Json::nextToken(json, index); + return map; + } + else + { + //Parse the key/value pair's name + QString name = Json::parseString(json, index, success).toString(); + + if(!success) + { + return QVariantMap(); + } + + //Get the next token + token = Json::nextToken(json, index); + + //If the next token is not a colon, flag the failure + //return an empty QVariant + if(token != JsonTokenColon) + { + success = false; + return QVariant(QVariantMap()); + } + + //Parse the key/value pair's value + QVariant value = Json::parseValue(json, index, success); + + if(!success) + { + return QVariantMap(); + } + + //Assign the value to the key in the map + map[name] = value; + } + } + + //Return the map successfully + return QVariant(map); +} + +/** + * parseArray + */ +QVariant Json::parseArray(const QString &json, int &index, bool &success) +{ + QVariantList list; + + Json::nextToken(json, index); + + bool done = false; + while(!done) + { + int token = Json::lookAhead(json, index); + + if(token == JsonTokenNone) + { + success = false; + return QVariantList(); + } + else if(token == JsonTokenComma) + { + Json::nextToken(json, index); + } + else if(token == JsonTokenSquaredClose) + { + Json::nextToken(json, index); + break; + } + else + { + QVariant value = Json::parseValue(json, index, success); + + if(!success) + { + return QVariantList(); + } + + list.push_back(value); + } + } + + return QVariant(list); +} + +/** + * parseString + */ +QVariant Json::parseString(const QString &json, int &index, bool &success) +{ + QString s; + QChar c; + + Json::eatWhitespace(json, index); + + c = json[index++]; + + bool complete = false; + while(!complete) + { + if(index == json.size()) + { + break; + } + + c = json[index++]; + + if(c == '\"') + { + complete = true; + break; + } + else if(c == '\\') + { + if(index == json.size()) + { + break; + } + + c = json[index++]; + + if(c == '\"') + { + s.append('\"'); + } + else if(c == '\\') + { + s.append('\\'); + } + else if(c == '/') + { + s.append('/'); + } + else if(c == 'b') + { + s.append('\b'); + } + else if(c == 'f') + { + s.append('\f'); + } + else if(c == 'n') + { + s.append('\n'); + } + else if(c == 'r') + { + s.append('\r'); + } + else if(c == 't') + { + s.append('\t'); + } + else if(c == 'u') + { + int remainingLength = json.size() - index; + + if(remainingLength >= 4) + { + QString unicodeStr = json.mid(index, 4); + + int symbol = unicodeStr.toInt(0, 16); + + s.append(QChar(symbol)); + + index += 4; + } + else + { + break; + } + } + } + else + { + s.append(c); + } + } + + if(!complete) + { + success = false; + return QVariant(); + } + + return QVariant(s); +} + +/** + * parseNumber + */ +QVariant Json::parseNumber(const QString &json, int &index) +{ + Json::eatWhitespace(json, index); + + int lastIndex = Json::lastIndexOfNumber(json, index); + int charLength = (lastIndex - index) + 1; + QString numberStr; + + numberStr = json.mid(index, charLength); + + index = lastIndex + 1; + + return QVariant(numberStr); +} + +/** + * lastIndexOfNumber + */ +int Json::lastIndexOfNumber(const QString &json, int index) +{ + int lastIndex; + + for(lastIndex = index; lastIndex < json.size(); lastIndex++) + { + if(QString("0123456789+-.eE").indexOf(json[lastIndex]) == -1) + { + break; + } + } + + return lastIndex -1; +} + +/** + * eatWhitespace + */ +void Json::eatWhitespace(const QString &json, int &index) +{ + for(; index < json.size(); index++) + { + if(QString(" \t\n\r").indexOf(json[index]) == -1) + { + break; + } + } +} + +/** + * lookAhead + */ +int Json::lookAhead(const QString &json, int index) +{ + int saveIndex = index; + return Json::nextToken(json, saveIndex); +} + +/** + * nextToken + */ +int Json::nextToken(const QString &json, int &index) +{ + Json::eatWhitespace(json, index); + + if(index == json.size()) + { + return JsonTokenNone; + } + + QChar c = json[index]; + index++; + switch(c.toAscii()) + { + case '{': return JsonTokenCurlyOpen; + case '}': return JsonTokenCurlyClose; + case '[': return JsonTokenSquaredOpen; + case ']': return JsonTokenSquaredClose; + case ',': return JsonTokenComma; + case '"': return JsonTokenString; + case '0': case '1': case '2': case '3': case '4': + case '5': case '6': case '7': case '8': case '9': + case '-': return JsonTokenNumber; + case ':': return JsonTokenColon; + } + + index--; + + int remainingLength = json.size() - index; + + //True + if(remainingLength >= 4) + { + if (json[index] == 't' && json[index + 1] == 'r' && + json[index + 2] == 'u' && json[index + 3] == 'e') + { + index += 4; + return JsonTokenTrue; + } + } + + //False + if (remainingLength >= 5) + { + if (json[index] == 'f' && json[index + 1] == 'a' && + json[index + 2] == 'l' && json[index + 3] == 's' && + json[index + 4] == 'e') + { + index += 5; + return JsonTokenFalse; + } + } + + //Null + if (remainingLength >= 4) + { + if (json[index] == 'n' && json[index + 1] == 'u' && + json[index + 2] == 'l' && json[index + 3] == 'l') + { + index += 4; + return JsonTokenNull; + } + } + + return JsonTokenNone; +} diff --git a/json.h b/json.h index 4b24731..88eced0 100644 --- a/json.h +++ b/json.h @@ -1,157 +1,157 @@ -/** - * \file json.h - * - * \author Eeli Reilin , - * Mikko Ahonen - * \version 0.1 - * \date 8/25/2010 - */ - -#ifndef JSON_H -#define JSON_H - -#include -#include - -/** - * \enum JsonToken - */ -enum JsonToken -{ - JsonTokenNone = 0, - JsonTokenCurlyOpen = 1, - JsonTokenCurlyClose = 2, - JsonTokenSquaredOpen = 3, - JsonTokenSquaredClose = 4, - JsonTokenColon = 5, - JsonTokenComma = 6, - JsonTokenString = 7, - JsonTokenNumber = 8, - JsonTokenTrue = 9, - JsonTokenFalse = 10, - JsonTokenNull = 11 -}; - -/** - * \class Json - * \brief A JSON data parser - * - * Json parses a JSON data into a QVariant hierarchy. - */ -class Json -{ - public: - /** - * Parse a JSON string - * - * \param json The JSON data - */ - static QVariant parse(const QString &json); - - /** - * Parse a JSON string - * - * \param json The JSON data - * \param success The success of the parsing - */ - static QVariant parse(const QString &json, bool &success); - - private: - /** - * Parses a value starting from index - * - * \param json The JSON data - * \param index The start index - * \param success The success of the parse process - * - * \return QVariant The parsed value - */ - static QVariant parseValue(const QString &json, int &index, - bool &success); - - /** - * Parses an object starting from index - * - * \param json The JSON data - * \param index The start index - * \param success The success of the object parse - * - * \return QVariant The parsed object map - */ - static QVariant parseObject(const QString &json, int &index, - bool &success); - - /** - * Parses an array starting from index - * - * \param json The JSON data - * \param index The starting index - * \param success The success of the array parse - * - * \return QVariant The parsed variant array - */ - static QVariant parseArray(const QString &json, int &index, - bool &success); - - /** - * Parses a string starting from index - * - * \param json The JSON data - * \param index The starting index - * \param success The success of the string parse - * - * \return QVariant The parsed string - */ - static QVariant parseString(const QString &json, int &index, - bool &success); - - /** - * Parses a number starting from index - * - * \param json The JSON data - * \param index The starting index - * - * \return QVariant The parsed number - */ - static QVariant parseNumber(const QString &json, int &index); - - /** - * Get the last index of a number starting from index - * - * \param json The JSON data - * \param index The starting index - * - * \return The last index of the number - */ - static int lastIndexOfNumber(const QString &json, int index); - - /** - * Skip unwanted whitespace symbols starting from index - * - * \param json The JSON data - * \param index The start index - */ - static void eatWhitespace(const QString &json, int &index); - - /** - * Check what token lies ahead - * - * \param json The JSON data - * \param index The starting index - * - * \return int The upcoming token - */ - static int lookAhead(const QString &json, int index); - - /** - * Get the next JSON token - * - * \param json The JSON data - * \param index The starting index - * - * \return int The next JSON token - */ - static int nextToken(const QString &json, int &index); -}; - -#endif //JSON_H +/** + * \file json.h + * + * \author Eeli Reilin , + * Mikko Ahonen + * \version 0.1 + * \date 8/25/2010 + */ + +#ifndef JSON_H +#define JSON_H + +#include +#include + +/** + * \enum JsonToken + */ +enum JsonToken +{ + JsonTokenNone = 0, + JsonTokenCurlyOpen = 1, + JsonTokenCurlyClose = 2, + JsonTokenSquaredOpen = 3, + JsonTokenSquaredClose = 4, + JsonTokenColon = 5, + JsonTokenComma = 6, + JsonTokenString = 7, + JsonTokenNumber = 8, + JsonTokenTrue = 9, + JsonTokenFalse = 10, + JsonTokenNull = 11 +}; + +/** + * \class Json + * \brief A JSON data parser + * + * Json parses a JSON data into a QVariant hierarchy. + */ +class Json +{ + public: + /** + * Parse a JSON string + * + * \param json The JSON data + */ + static QVariant parse(const QString &json); + + /** + * Parse a JSON string + * + * \param json The JSON data + * \param success The success of the parsing + */ + static QVariant parse(const QString &json, bool &success); + + private: + /** + * Parses a value starting from index + * + * \param json The JSON data + * \param index The start index + * \param success The success of the parse process + * + * \return QVariant The parsed value + */ + static QVariant parseValue(const QString &json, int &index, + bool &success); + + /** + * Parses an object starting from index + * + * \param json The JSON data + * \param index The start index + * \param success The success of the object parse + * + * \return QVariant The parsed object map + */ + static QVariant parseObject(const QString &json, int &index, + bool &success); + + /** + * Parses an array starting from index + * + * \param json The JSON data + * \param index The starting index + * \param success The success of the array parse + * + * \return QVariant The parsed variant array + */ + static QVariant parseArray(const QString &json, int &index, + bool &success); + + /** + * Parses a string starting from index + * + * \param json The JSON data + * \param index The starting index + * \param success The success of the string parse + * + * \return QVariant The parsed string + */ + static QVariant parseString(const QString &json, int &index, + bool &success); + + /** + * Parses a number starting from index + * + * \param json The JSON data + * \param index The starting index + * + * \return QVariant The parsed number + */ + static QVariant parseNumber(const QString &json, int &index); + + /** + * Get the last index of a number starting from index + * + * \param json The JSON data + * \param index The starting index + * + * \return The last index of the number + */ + static int lastIndexOfNumber(const QString &json, int index); + + /** + * Skip unwanted whitespace symbols starting from index + * + * \param json The JSON data + * \param index The start index + */ + static void eatWhitespace(const QString &json, int &index); + + /** + * Check what token lies ahead + * + * \param json The JSON data + * \param index The starting index + * + * \return int The upcoming token + */ + static int lookAhead(const QString &json, int index); + + /** + * Get the next JSON token + * + * \param json The JSON data + * \param index The starting index + * + * \return int The next JSON token + */ + static int nextToken(const QString &json, int &index); +}; + +#endif //JSON_H diff --git a/main.cpp b/main.cpp index 9ae175b..a001eb2 100644 --- a/main.cpp +++ b/main.cpp @@ -1,11 +1,11 @@ -#include -#include "mainwindow.h" - -int main(int argc, char *argv[]) -{ - QApplication a(argc, argv); - MainWindow w; - w.show(); - - return a.exec(); -} +#include +#include "mainwindow.h" + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + MainWindow w; + w.show(); + + return a.exec(); +} diff --git a/mainwindow.cpp b/mainwindow.cpp index 75e7d8e..3d4808f 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -1,607 +1,612 @@ -#include "mainwindow.h" -#include "ui_mainwindow.h" - -#include "poolparse.h" - -MainWindow::MainWindow(QWidget *parent) : - QMainWindow(parent), - ui(new Ui::MainWindow) -{ - ui->setupUi(this); - - // Create system tray icon - trayIcon = new QSystemTrayIcon(this); - - inactiveIcon.addFile(":/icons/inactiveIcon"); - activeIcon.addFile(":/icons/activeIcon"); - - trayIcon->setIcon(inactiveIcon); - - this->setWindowIcon(QIcon(":/icons/icon")); - - createTrayActions(); - - networkManager = new QNetworkAccessManager(this); - - setFixedSize(400, 460); - - checkSettings(); - - minerActive = false; - - minerProcess = new QProcess(this); - minerProcess->setProcessChannelMode(QProcess::MergedChannels); - - readTimer = new QTimer(this); - poolTimer = new QTimer(this); - - poolTimer->setInterval(60000); - poolTimer->setSingleShot(false); - poolTimer->start(); - - acceptedShares = 0; - rejectedShares = 0; - - roundAcceptedShares = 0; - roundRejectedShares = 0; - - initThreads = 0; - - outputFile = new QFile("output.txt"); - - connect(readTimer, SIGNAL(timeout()), this, SLOT(readProcessOutput())); - connect(poolTimer, SIGNAL(timeout()), this, SLOT(updatePoolData())); - - connect(trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(trayIconActivated(QSystemTrayIcon::ActivationReason))); - - connect(ui->startButton, SIGNAL(pressed()), this, SLOT(startPressed())); - connect(ui->updateButton, SIGNAL(pressed()), this, SLOT(updatePoolData())); - - connect(minerProcess, SIGNAL(started()), this, SLOT(minerStarted())); - connect(minerProcess, SIGNAL(error(QProcess::ProcessError)), this, SLOT(minerError(QProcess::ProcessError))); - connect(minerProcess, SIGNAL(finished(int,QProcess::ExitStatus)), this, SLOT(minerFinished(int, QProcess::ExitStatus))); - connect(minerProcess, SIGNAL(readyReadStandardOutput()), this, SLOT(readProcessOutput())); - - // Check if we got a --automine argument - if (qApp->arguments().contains("--automine") || qApp->arguments().contains("-m")) - { - hideMainWindow(); - startMining(); - } -} - -MainWindow::~MainWindow() -{ - if (outputFile->isOpen()) - { - outputFile->flush(); - outputFile->close(); - } - - minerProcess->kill(); - - saveSettings(); - - delete ui; -} - -void MainWindow::trayIconActivated(QSystemTrayIcon::ActivationReason reason) -{ - if (reason == QSystemTrayIcon::DoubleClick) - showMainWindow(); - else - return; -} - -void MainWindow::changeEvent(QEvent *e) -{ - if (e->type() == QEvent::WindowStateChange) - { - if (isMinimized()) - hideMainWindow(); - else - showMainWindow(); - } - QMainWindow::changeEvent(e); -} - -void MainWindow::createTrayActions() -{ - QMenu *trayMenu = new QMenu(); - - QAction *openAction = new QAction("Open", trayMenu); - QAction *exitAction = new QAction("Exit", trayMenu); - - trayMenu->addAction(openAction); - trayMenu->addAction(exitAction); - - connect(openAction, SIGNAL(triggered()), this, SLOT(showMainWindow())); - connect(exitAction, SIGNAL(triggered()), this, SLOT(close())); - - trayIcon->setContextMenu(trayMenu); -} - -void MainWindow::resizeElements() -{ - if (minerActive == true) - { - ui->output->setFixedHeight(355); - ui->list->setFixedHeight(355); - ui->poolData->setFixedHeight(250); - } - else if (minerActive == false) - { - ui->output->setFixedHeight(145); - ui->list->setFixedHeight(145); - ui->poolData->setFixedHeight(80); - } -} - -void MainWindow::showMainWindow() -{ - setParent(NULL, Qt::Window); - showNormal(); - trayIcon->hide(); -} - -void MainWindow::hideMainWindow() -{ - hide(); - trayIcon->show(); - - // Hiding the window from the taskbar - QWidget *tmp = new QWidget(); - setParent(tmp, Qt::SubWindow); -} - -void MainWindow::startPressed() -{ - if (minerActive == false) - startMining(); - else - stopMining(); - -} - -void MainWindow::recordOutput(QString text) -{ - if (!outputFile->isOpen()) - { - outputFile->open(QIODevice::ReadWrite); - } - - outputFile->write(text.toAscii()); -} - -QStringList MainWindow::getArgs() -{ - QStringList args; - QString url = ui->rpcServerLine->text(); - if (!url.contains("http://")) - url.prepend("http://"); - qDebug(url.toAscii()); - QString urlLine = QString("%1:%2").arg(url, ui->portLine->text()); - QString userpassLine = QString("%1:%2").arg(ui->usernameLine->text(), ui->passwordLine->text()); - args << "--algo" << "scrypt"; - args << "-s" << ui->scantimeLine->text().toAscii(); - args << "--url" << urlLine.toAscii(); - args << "--userpass" << userpassLine.toAscii(); - args << "--threads" << ui->threadsBox->currentText().toAscii(); - args << "-P"; - args << ui->parametersLine->text().split(" ", QString::SkipEmptyParts); - - return args; -} - -void MainWindow::startMining() -{ - ui->startButton->setText("Stop Mining"); - ui->threadsBox->setDisabled(true); - ui->scantimeLine->setDisabled(true); - ui->rpcServerLine->setDisabled(true); - ui->usernameLine->setDisabled(true); - ui->passwordLine->setDisabled(true); - ui->portLine->setDisabled(true); - ui->parametersLine->setDisabled(true); - minerActive = true; - ui->tabWidget->move(ui->tabWidget->x(), 52); - ui->tabWidget->setFixedHeight(380); - ui->settingsFrame->setVisible(false); - resizeElements(); - - trayIcon->setIcon(activeIcon); - QStringList args = getArgs(); - - threadSpeed.clear(); - - acceptedShares = 0; - rejectedShares = 0; - - roundAcceptedShares = 0; - roundRejectedShares = 0; - - initThreads = ui->threadsBox->currentText().toInt(); - -#ifdef WIN32 - QString program = "minerd"; -#else - QString program = "./minerd"; -#endif - - minerProcess->start(program,args); - minerProcess->waitForStarted(-1); - - readTimer->start(500); - - trayIcon->setToolTip("Mining"); -} - -void MainWindow::stopMining() -{ - ui->startButton->setText("Start Mining"); - minerActive = false; - ui->threadsBox->setDisabled(false); - ui->scantimeLine->setDisabled(false); - ui->rpcServerLine->setDisabled(false); - ui->usernameLine->setDisabled(false); - ui->passwordLine->setDisabled(false); - ui->portLine->setDisabled(false); - ui->parametersLine->setDisabled(false); - ui->tabWidget->move(-1,260); - ui->tabWidget->setFixedHeight(170); - ui->settingsFrame->setVisible(true); - resizeElements(); - - trayIcon->setIcon(inactiveIcon); - reportToList("Miner stopped", 0, NULL); - ui->mineSpeedLabel->setText("N/A"); - ui->shareCount->setText("Accepted: 0 - Rejected: 0"); - minerProcess->kill(); - readTimer->stop(); - trayIcon->setToolTip("Not mining"); -} - -void MainWindow::saveSettings() -{ - QSettings settings("easyminer.conf", QSettings::IniFormat); - - settings.setValue("threads", ui->threadsBox->currentText()); - settings.setValue("scantime", ui->scantimeLine->text()); - settings.setValue("url", ui->rpcServerLine->text()); - settings.setValue("username", ui->usernameLine->text()); - settings.setValue("password", ui->passwordLine->text()); - settings.setValue("port", ui->portLine->text()); - settings.setValue("miningPoolIndex", ui->poolBox->currentIndex()); - settings.setValue("poolApiKey", ui->apiKeyLine->text()); - settings.setValue("sharePopup", ui->shareBox->isChecked()); - settings.setValue("minerRestart", ui->restartBox->isChecked()); - settings.setValue("saveOutput", ui->saveOutputBox->isChecked()); - - settings.sync(); -} - -void MainWindow::checkSettings() -{ - QSettings settings("easyminer.conf", QSettings::IniFormat); - if (settings.value("threads").isValid()) - { - int threads = settings.value("threads").toInt(); - threads--; - ui->threadsBox->setCurrentIndex(threads); - } - - if (settings.value("scantime").isValid()) - ui->scantimeLine->setText(settings.value("scantime").toString()); - else - ui->scantimeLine->setText("15"); - - if (settings.value("url").isValid()) - ui->rpcServerLine->setText(settings.value("url").toString()); - if (settings.value("username").isValid()) - ui->usernameLine->setText(settings.value("username").toString()); - if (settings.value("password").isValid()) - ui->passwordLine->setText(settings.value("password").toString()); - - if (settings.value("port").isValid()) - ui->portLine->setText(settings.value("port").toString()); - else - ui->portLine->setText("9332"); - - if (settings.value("miningPoolIndex").isValid()) - ui->poolBox->setCurrentIndex(settings.value("miningPoolIndex").toInt()); - if (settings.value("poolApiKey").isValid()) - ui->apiKeyLine->setText(settings.value("poolApiKey").toString()); - - if (settings.value("sharePopup").isValid()) - ui->shareBox->setChecked(settings.value("sharePopup").toBool()); - if (settings.value("minerRestart").isValid()) - ui->restartBox->setChecked(settings.value("minerRestart").toBool()); - if (settings.value("saveOutput").isValid()) - ui->saveOutputBox->setChecked(settings.value("saveOutput").toBool()); -} - -void MainWindow::readProcessOutput() -{ - QByteArray output; - - minerProcess->reset(); - - output = minerProcess->readAll(); - - QString outputString(output); - - if (!outputString.isEmpty()) - { - QStringList list = outputString.split("\n"); - int i; - for (i=0; ioutput->append(QString("%1").arg(line)); - if (ui->saveOutputBox->isChecked()) - recordOutput(line); - } - } - - if (ui->output->toPlainText().length() > 4000) - { - QString text = ui->output->toPlainText(); - text.remove(0, text.length() - 4000); - ui->output->setText(text); - } - } -} - - -void MainWindow::minerError(QProcess::ProcessError error) -{ - QString errorMessage; - switch(error) - { - case QProcess::Crashed: - errorMessage = "Miner killed"; - break; - - case QProcess::FailedToStart: - errorMessage = "Miner failed to start"; - break; - - default: - errorMessage = "Unknown error"; - break; - } - - reportToList(errorMessage, ERROR, NULL); - - trayIcon->showMessage("Miner encountered an error", errorMessage); - -} - -void MainWindow::minerFinished(int exitCode, QProcess::ExitStatus exitStatus) -{ - QString exitMessage; - switch(exitStatus) - { - case QProcess::NormalExit: - exitMessage = "Miner exited normally"; - break; - - case QProcess::CrashExit: - exitMessage = "Miner exited."; - if (ui->restartBox->isChecked()) - startMining(); - break; - - default: - exitMessage = "Miner exited abnormally."; - if (ui->restartBox->isChecked()) - startMining(); - break; - } - - if (exitStatus == QProcess::NormalExit) - stopMining(); - trayIcon->showMessage("Miner stopped", exitMessage); -} - -void MainWindow::minerStarted() -{ - QString argString = ""; - QStringList args = getArgs(); - - int i; - for (i=0; i<=args.length()-1; i++) - { - argString.append(args[i]); - argString.append(" "); - } - reportToList(QString("Miner started. It usually takes a minute until the program starts reporting information. Parameters: %1").arg(argString), STARTED, NULL); -} - -void MainWindow::updateSpeed() -{ - double totalSpeed=0; - int totalThreads=0; - - QMapIterator iter(threadSpeed); - while(iter.hasNext()) - { - iter.next(); - totalSpeed += iter.value(); - totalThreads++; - } - - // If all threads haven't reported the hash speed yet, make an assumption - if (totalThreads != initThreads) - { - totalSpeed = (totalSpeed/totalThreads)*initThreads; - } - - QString speedString = QString("%1").arg(totalSpeed); - QString threadsString = QString("%1").arg(initThreads); - - QString acceptedString = QString("%1").arg(acceptedShares); - QString rejectedString = QString("%1").arg(rejectedShares); - - QString roundAcceptedString = QString("%1").arg(roundAcceptedShares); - QString roundRejectedString = QString("%1").arg(roundRejectedShares); - - if (totalThreads == initThreads) - ui->mineSpeedLabel->setText(QString("%1 khash/sec - %2 thread(s)").arg(speedString, threadsString)); - else - ui->mineSpeedLabel->setText(QString("~%1 khash/sec - %2 thread(s)").arg(speedString, threadsString)); - - ui->shareCount->setText(QString("Accepted: %1 (%3) - Rejected: %2 (%4)").arg(acceptedString, rejectedString, roundAcceptedString, roundRejectedString)); - - QString tooltipString = QString("%1 kh/sec -").arg(totalSpeed); - tooltipString.append(QString("A:%1 - R:%2").arg(acceptedString,rejectedString)); - - trayIcon->setToolTip(tooltipString); -} - -void MainWindow::updatePoolData() -{ - QString url = PoolParse::getURL(ui->poolBox->currentText(), ui->apiKeyLine->text()); - - if (ui->apiKeyLine->text().isEmpty() == false) - { - networkManager->get(QNetworkRequest(QUrl(url))); - - connect(networkManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(poolDataLoaded(QNetworkReply*))); - } -} - -void MainWindow::poolDataLoaded(QNetworkReply *data) -{ - QString poolDataString; - - QByteArray replyBytes = data->readAll(); - QString replyString = QString::fromUtf8(replyBytes); - - QVariantMap replyMap; - bool parseSuccess; - - replyMap = Json::parse(replyString, parseSuccess).toMap(); - - if (parseSuccess == true) - { - poolDataString = PoolParse::parseData(ui->poolBox->currentText(), replyMap); - } - else - { - poolDataString = "Couldn't update mining pool data."; - } - - ui->poolData->setText(poolDataString); - - disconnect(networkManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(poolDataLoaded(QNetworkReply*))); - -} - -void MainWindow::reportToList(QString msg, int type, QString time) -{ - QString message; - if (time == NULL) - message = QString("[%1] - %2").arg(QTime::currentTime().toString(), msg); - else - message = QString("[%1] - %2").arg(time, msg); - - switch(type) - { - case SHARE_SUCCESS: - acceptedShares++; - if (ui->shareBox->isChecked()) - trayIcon->showMessage("Share found", QString("[%1] Accepted share").arg(QTime::currentTime().toString()), QSystemTrayIcon::Information, 5000); - roundAcceptedShares++; - updateSpeed(); - break; - - case SHARE_FAIL: - rejectedShares++; - roundRejectedShares++; - updateSpeed(); - break; - - case FATAL_ERROR: - startPressed(); - break; - - case LONGPOLL: - roundAcceptedShares = 0; - roundRejectedShares = 0; - break; - - default: - break; - } - - ui->list->addItem(message); - ui->list->scrollToBottom(); -} - -// Function for fetching the time -QString MainWindow::getTime(QString time) -{ - if (time.contains("[")) - { - time.resize(21); - time.remove("["); - time.remove("]"); - time.remove(0,11); - - return time; - } - else - return NULL; -} +#include "mainwindow.h" +#include "ui_mainwindow.h" + +#include "poolparse.h" +#include "qlogger.h" + +MainWindow::MainWindow(QWidget *parent) : + QMainWindow(parent), + ui(new Ui::MainWindow) +{ + ui->setupUi(this); + + // Create system tray icon + trayIcon = new QSystemTrayIcon(this); + + inactiveIcon.addFile(":/icons/inactiveIcon"); + activeIcon.addFile(":/icons/activeIcon"); + + trayIcon->setIcon(inactiveIcon); + + this->setWindowIcon(QIcon(":/icons/icon")); + + createTrayActions(); + + networkManager = new QNetworkAccessManager(this); + + setFixedSize(400, 460); + + checkSettings(); + + minerActive = false; + + minerProcess = new QProcess(this); + minerProcess->setProcessChannelMode(QProcess::MergedChannels); + + readTimer = new QTimer(this); + poolTimer = new QTimer(this); + + poolTimer->setInterval(60000); + poolTimer->setSingleShot(false); + poolTimer->start(); + + acceptedShares = 0; + rejectedShares = 0; + + roundAcceptedShares = 0; + roundRejectedShares = 0; + + initThreads = 0; + + outputFile = new QFile("output.txt"); + + connect(readTimer, SIGNAL(timeout()), this, SLOT(readProcessOutput())); + connect(poolTimer, SIGNAL(timeout()), this, SLOT(updatePoolData())); + + connect(trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(trayIconActivated(QSystemTrayIcon::ActivationReason))); + + connect(ui->startButton, SIGNAL(pressed()), this, SLOT(startPressed())); + connect(ui->updateButton, SIGNAL(pressed()), this, SLOT(updatePoolData())); + + connect(minerProcess, SIGNAL(started()), this, SLOT(minerStarted())); + connect(minerProcess, SIGNAL(error(QProcess::ProcessError)), this, SLOT(minerError(QProcess::ProcessError))); + connect(minerProcess, SIGNAL(finished(int,QProcess::ExitStatus)), this, SLOT(minerFinished(int, QProcess::ExitStatus))); + connect(minerProcess, SIGNAL(readyReadStandardOutput()), this, SLOT(readProcessOutput())); + + // Check if we got a --automine argument + if (qApp->arguments().contains("--automine") || qApp->arguments().contains("-m")) + { + hideMainWindow(); + startMining(); + } +} + +MainWindow::~MainWindow() +{ + if (outputFile->isOpen()) + { + outputFile->flush(); + outputFile->close(); + } + + minerProcess->kill(); + + saveSettings(); + + delete ui; +} + +void MainWindow::trayIconActivated(QSystemTrayIcon::ActivationReason reason) +{ + if (reason == QSystemTrayIcon::DoubleClick) + showMainWindow(); + else + return; +} + +void MainWindow::changeEvent(QEvent *e) +{ + if (e->type() == QEvent::WindowStateChange) + { + if (isMinimized()) + hideMainWindow(); + else + showMainWindow(); + } + QMainWindow::changeEvent(e); +} + +void MainWindow::createTrayActions() +{ + QMenu *trayMenu = new QMenu(); + + QAction *openAction = new QAction("Open", trayMenu); + QAction *exitAction = new QAction("Exit", trayMenu); + + trayMenu->addAction(openAction); + trayMenu->addAction(exitAction); + + connect(openAction, SIGNAL(triggered()), this, SLOT(showMainWindow())); + connect(exitAction, SIGNAL(triggered()), this, SLOT(close())); + + trayIcon->setContextMenu(trayMenu); +} + +void MainWindow::resizeElements() +{ + if (minerActive == true) + { + ui->output->setFixedHeight(355); + ui->list->setFixedHeight(355); + ui->poolData->setFixedHeight(250); + } + else if (minerActive == false) + { + ui->output->setFixedHeight(145); + ui->list->setFixedHeight(145); + ui->poolData->setFixedHeight(80); + } +} + +void MainWindow::showMainWindow() +{ + setParent(NULL, Qt::Window); + showNormal(); + trayIcon->hide(); +} + +void MainWindow::hideMainWindow() +{ + hide(); + trayIcon->show(); + + // Hiding the window from the taskbar + QWidget *tmp = new QWidget(); + setParent(tmp, Qt::SubWindow); +} + +void MainWindow::startPressed() +{ + if (minerActive == false) + startMining(); + else + stopMining(); + +} + +void MainWindow::recordOutput(QString text) +{ + if (!outputFile->isOpen()) + { + outputFile->open(QIODevice::ReadWrite); + } + + outputFile->write(text.toAscii()); +} + +QStringList MainWindow::getArgs() +{ + QStringList args; + QString url = ui->rpcServerLine->text(); + QString urlLine = QString("%1:%2").arg(url, ui->portLine->text()); + QString userpassLine = QString("%1:%2").arg(ui->usernameLine->text(), ui->passwordLine->text()); + args << "--algo" << "scrypt"; + args << "-s" << ui->scantimeLine->text().toAscii(); + args << "--url" << urlLine.toAscii(); + args << "--userpass" << userpassLine.toAscii(); + args << "--threads" << ui->threadsBox->currentText().toAscii(); + args << "-P"; + args << ui->parametersLine->text().split(" ", QString::SkipEmptyParts); + + return args; +} + +void MainWindow::startMining() +{ + ui->startButton->setText("Stop Mining"); + ui->threadsBox->setDisabled(true); + ui->scantimeLine->setDisabled(true); + ui->rpcServerLine->setDisabled(true); + ui->usernameLine->setDisabled(true); + ui->passwordLine->setDisabled(true); + ui->portLine->setDisabled(true); + ui->parametersLine->setDisabled(true); + minerActive = true; + ui->tabWidget->move(ui->tabWidget->x(), 52); + ui->tabWidget->setFixedHeight(380); + ui->settingsFrame->setVisible(false); + resizeElements(); + + trayIcon->setIcon(activeIcon); + QStringList args = getArgs(); + + threadSpeed.clear(); + + acceptedShares = 0; + rejectedShares = 0; + + roundAcceptedShares = 0; + roundRejectedShares = 0; + + initThreads = ui->threadsBox->currentText().toInt(); + +#ifdef WIN32 + QString program = "minerd"; +#else + QString program = "./minerd"; +#endif + + minerProcess->start(program,args); + minerProcess->waitForStarted(-1); + + readTimer->start(500); + + trayIcon->setToolTip("Mining"); +} + +void MainWindow::stopMining() +{ + ui->startButton->setText("Start Mining"); + minerActive = false; + ui->threadsBox->setDisabled(false); + ui->scantimeLine->setDisabled(false); + ui->rpcServerLine->setDisabled(false); + ui->usernameLine->setDisabled(false); + ui->passwordLine->setDisabled(false); + ui->portLine->setDisabled(false); + ui->parametersLine->setDisabled(false); + ui->tabWidget->move(-1,260); + ui->tabWidget->setFixedHeight(170); + ui->settingsFrame->setVisible(true); + resizeElements(); + + trayIcon->setIcon(inactiveIcon); + reportToList("Miner stopped", 0, NULL); + ui->mineSpeedLabel->setText("N/A"); + ui->shareCount->setText("Accepted: 0 - Rejected: 0"); + minerProcess->kill(); + readTimer->stop(); + trayIcon->setToolTip("Not mining"); +} + +void MainWindow::saveSettings() +{ + QSettings settings("easyminer.conf", QSettings::IniFormat); + + settings.setValue("threads", ui->threadsBox->currentText()); + settings.setValue("scantime", ui->scantimeLine->text()); + settings.setValue("url", ui->rpcServerLine->text()); + settings.setValue("username", ui->usernameLine->text()); + settings.setValue("password", ui->passwordLine->text()); + settings.setValue("port", ui->portLine->text()); + settings.setValue("miningPoolIndex", ui->poolBox->currentIndex()); + settings.setValue("poolApiKey", ui->apiKeyLine->text()); + settings.setValue("sharePopup", ui->shareBox->isChecked()); + settings.setValue("minerRestart", ui->restartBox->isChecked()); + settings.setValue("saveOutput", ui->saveOutputBox->isChecked()); + + settings.sync(); +} + +void MainWindow::checkSettings() +{ + QSettings settings("easyminer.conf", QSettings::IniFormat); + if (settings.value("threads").isValid()) + { + int threads = settings.value("threads").toInt(); + threads--; + ui->threadsBox->setCurrentIndex(threads); + } + + if (settings.value("scantime").isValid()) + ui->scantimeLine->setText(settings.value("scantime").toString()); + else + ui->scantimeLine->setText("15"); + + if (settings.value("url").isValid()) + ui->rpcServerLine->setText(settings.value("url").toString()); + if (settings.value("username").isValid()) + ui->usernameLine->setText(settings.value("username").toString()); + if (settings.value("password").isValid()) + ui->passwordLine->setText(settings.value("password").toString()); + + if (settings.value("port").isValid()) + ui->portLine->setText(settings.value("port").toString()); + else + ui->portLine->setText("9332"); + + if (settings.value("miningPoolIndex").isValid()) + ui->poolBox->setCurrentIndex(settings.value("miningPoolIndex").toInt()); + if (settings.value("poolApiKey").isValid()) + ui->apiKeyLine->setText(settings.value("poolApiKey").toString()); + + if (settings.value("sharePopup").isValid()) + ui->shareBox->setChecked(settings.value("sharePopup").toBool()); + if (settings.value("minerRestart").isValid()) + ui->restartBox->setChecked(settings.value("minerRestart").toBool()); + if (settings.value("saveOutput").isValid()) + ui->saveOutputBox->setChecked(settings.value("saveOutput").toBool()); +} + +void MainWindow::readProcessOutput() +{ + QByteArray output; + + minerProcess->reset(); + + output = minerProcess->readAll(); + + QString outputString(output); + + if (!outputString.isEmpty()) + { + QStringList list = outputString.split("\n"); + int i; + for (i=0; ioutput->append(QString("%1").arg(line)); + if (ui->saveOutputBox->isChecked()) + recordOutput(line); + } + } + + if (ui->output->toPlainText().length() > 4000) + { + QString text = ui->output->toPlainText(); + text.remove(0, text.length() - 4000); + ui->output->setText(text); + } + } +} + + +void MainWindow::minerError(QProcess::ProcessError error) +{ + QString errorMessage; + switch(error) + { + case QProcess::Crashed: + errorMessage = "Miner killed"; + break; + + case QProcess::FailedToStart: + errorMessage = "Miner failed to start"; + break; + + default: + errorMessage = "Unknown error"; + break; + } + + reportToList(errorMessage, ERROR, NULL); + + trayIcon->showMessage("Miner encountered an error", errorMessage); + +} + +void MainWindow::minerFinished(int exitCode, QProcess::ExitStatus exitStatus) +{ + QString exitMessage; + switch(exitStatus) + { + case QProcess::NormalExit: + exitMessage = "Miner exited normally"; + break; + + case QProcess::CrashExit: + exitMessage = "Miner exited."; + if (ui->restartBox->isChecked()) + startMining(); + break; + + default: + exitMessage = "Miner exited abnormally."; + if (ui->restartBox->isChecked()) + startMining(); + break; + } + + if (exitStatus == QProcess::NormalExit) + stopMining(); + trayIcon->showMessage("Miner stopped", exitMessage); +} + +void MainWindow::minerStarted() +{ + QString argString = ""; + QStringList args = getArgs(); + + int i; + for (i=0; i<=args.length()-1; i++) + { + argString.append(args[i]); + argString.append(" "); + } + reportToList(QString("Miner started. It usually takes a minute until the program starts reporting information. Parameters: %1").arg(argString), STARTED, NULL); +} + +void MainWindow::updateSpeed() +{ + double totalSpeed=0; + int totalThreads=0; + + QMapIterator iter(threadSpeed); + while(iter.hasNext()) + { + iter.next(); + totalSpeed += iter.value(); + totalThreads++; + } + + // If all threads haven't reported the hash speed yet, make an assumption + if (totalThreads != initThreads) + { + totalSpeed = (totalSpeed/totalThreads)*initThreads; + } + + QString speedString = QString("%1").arg(totalSpeed); + QString threadsString = QString("%1").arg(initThreads); + + QString acceptedString = QString("%1").arg(acceptedShares); + QString rejectedString = QString("%1").arg(rejectedShares); + + QString roundAcceptedString = QString("%1").arg(roundAcceptedShares); + QString roundRejectedString = QString("%1").arg(roundRejectedShares); + + if (totalThreads == initThreads) + ui->mineSpeedLabel->setText(QString("%1 khash/sec - %2 thread(s)").arg(speedString, threadsString)); + else + ui->mineSpeedLabel->setText(QString("~%1 khash/sec - %2 thread(s)").arg(speedString, threadsString)); + + ui->shareCount->setText(QString("Accepted: %1 (%3) - Rejected: %2 (%4)").arg(acceptedString, rejectedString, roundAcceptedString, roundRejectedString)); + + QString tooltipString = QString("%1 kh/sec -").arg(totalSpeed); + tooltipString.append(QString("A:%1 - R:%2").arg(acceptedString,rejectedString)); + + trayIcon->setToolTip(tooltipString); +} + +void MainWindow::updatePoolData() +{ + QString url = PoolParse::getURL(ui->poolBox->currentText(), ui->apiKeyLine->text()); + + if (ui->apiKeyLine->text().isEmpty() == false) + { + networkManager->get(QNetworkRequest(QUrl(url))); + + connect(networkManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(poolDataLoaded(QNetworkReply*))); + } +} + +void MainWindow::poolDataLoaded(QNetworkReply *data) +{ + QString poolDataString; + + QByteArray replyBytes = data->readAll(); + QString replyString = QString::fromUtf8(replyBytes); + + QVariantMap replyMap; + bool parseSuccess; + + + QPlainTextEdit *editor = new QPlainTextEdit(this); + QString fileName = "logger.txt"; + QLogger *logger = new QLogger(this, fileName, editor); + logger->write(replyString); + + replyMap = Json::parse(replyString, parseSuccess).toMap(); + + + if (parseSuccess == true) + { + poolDataString = PoolParse::parseData(ui->poolBox->currentText(), replyMap); + } + else + { + poolDataString = "Couldn't update mining pool data."; + } + + ui->poolData->setText(poolDataString); + + disconnect(networkManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(poolDataLoaded(QNetworkReply*))); + +} + +void MainWindow::reportToList(QString msg, int type, QString time) +{ + QString message; + if (time == NULL) + message = QString("[%1] - %2").arg(QTime::currentTime().toString(), msg); + else + message = QString("[%1] - %2").arg(time, msg); + + switch(type) + { + case SHARE_SUCCESS: + acceptedShares++; + if (ui->shareBox->isChecked()) + trayIcon->showMessage("Share found", QString("[%1] Accepted share").arg(QTime::currentTime().toString()), QSystemTrayIcon::Information, 5000); + roundAcceptedShares++; + updateSpeed(); + break; + + case SHARE_FAIL: + rejectedShares++; + roundRejectedShares++; + updateSpeed(); + break; + + case FATAL_ERROR: + startPressed(); + break; + + case LONGPOLL: + roundAcceptedShares = 0; + roundRejectedShares = 0; + break; + + default: + break; + } + + ui->list->addItem(message); + ui->list->scrollToBottom(); +} + +// Function for fetching the time +QString MainWindow::getTime(QString time) +{ + if (time.contains("[")) + { + time.resize(21); + time.remove("["); + time.remove("]"); + time.remove(0,11); + + return time; + } + else + return NULL; +} diff --git a/mainwindow.h b/mainwindow.h index deccdca..fc867ce 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -1,118 +1,118 @@ -#ifndef MAINWINDOW_H -#define MAINWINDOW_H - -#include - -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#include - -#include "json.h" - -// Log types -#define STARTED 0 -#define SHARE_SUCCESS 1 -#define SHARE_FAIL 2 -#define ERROR 3 -#define LONGPOLL 4 -#define FATAL_ERROR 5 - -namespace Ui { - class MainWindow; -} - -class MainWindow : public QMainWindow -{ - Q_OBJECT - -public: - explicit MainWindow(QWidget *parent = 0); - ~MainWindow(); - - QIcon inactiveIcon; - QIcon activeIcon; - - QSystemTrayIcon *trayIcon; - - bool minerActive; - - QNetworkAccessManager *networkManager; - - QProcess *minerProcess; - - QMap threadSpeed; - - QTimer *readTimer; - QTimer *poolTimer; - - QFile *outputFile; - - int acceptedShares; - int rejectedShares; - - int roundAcceptedShares; - int roundRejectedShares; - - int initThreads; - -public slots: - // - void changeEvent(QEvent *); - - void startPressed(); - void createTrayActions(); - - QStringList getArgs(); - - void startMining(); - void stopMining(); - - // Window manipulation stuff - void resizeElements(); - void showMainWindow(); - void hideMainWindow(); - - void trayIconActivated(QSystemTrayIcon::ActivationReason reason); - - void updateSpeed(); - - void updatePoolData(); - - void checkSettings(); - void saveSettings(); - - void recordOutput(QString text); - - void reportToList(QString, int, QString); - - void minerStarted(); - - void minerError(QProcess::ProcessError); - void minerFinished(int, QProcess::ExitStatus); - - void poolDataLoaded(QNetworkReply*); - - void readProcessOutput(); - - QString getTime(QString); - -private: - Ui::MainWindow *ui; -}; - -#endif // MAINWINDOW_H +#ifndef MAINWINDOW_H +#define MAINWINDOW_H + +#include + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include + +#include "json.h" + +// Log types +#define STARTED 0 +#define SHARE_SUCCESS 1 +#define SHARE_FAIL 2 +#define ERROR 3 +#define LONGPOLL 4 +#define FATAL_ERROR 5 + +namespace Ui { + class MainWindow; +} + +class MainWindow : public QMainWindow +{ + Q_OBJECT + +public: + explicit MainWindow(QWidget *parent = 0); + ~MainWindow(); + + QIcon inactiveIcon; + QIcon activeIcon; + + QSystemTrayIcon *trayIcon; + + bool minerActive; + + QNetworkAccessManager *networkManager; + + QProcess *minerProcess; + + QMap threadSpeed; + + QTimer *readTimer; + QTimer *poolTimer; + + QFile *outputFile; + + int acceptedShares; + int rejectedShares; + + int roundAcceptedShares; + int roundRejectedShares; + + int initThreads; + +public slots: + // + void changeEvent(QEvent *); + + void startPressed(); + void createTrayActions(); + + QStringList getArgs(); + + void startMining(); + void stopMining(); + + // Window manipulation stuff + void resizeElements(); + void showMainWindow(); + void hideMainWindow(); + + void trayIconActivated(QSystemTrayIcon::ActivationReason reason); + + void updateSpeed(); + + void updatePoolData(); + + void checkSettings(); + void saveSettings(); + + void recordOutput(QString text); + + void reportToList(QString, int, QString); + + void minerStarted(); + + void minerError(QProcess::ProcessError); + void minerFinished(int, QProcess::ExitStatus); + + void poolDataLoaded(QNetworkReply*); + + void readProcessOutput(); + + QString getTime(QString); + +private: + Ui::MainWindow *ui; +}; + +#endif // MAINWINDOW_H diff --git a/mainwindow.ui b/mainwindow.ui index f964cbd..58c77ff 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -1,603 +1,593 @@ - - - MainWindow - - - - 0 - 0 - 400 - 460 - - - - - 0 - 0 - - - - ScryptMiner GUI - - - - - - 10 - 0 - 131 - 31 - - - - Speed - - - - - - 10 - 20 - 271 - 31 - - - - - 10 - 75 - true - - - - N/A - - - - - - 290 - 10 - 101 - 31 - - - - Start Mining - - - - - - 10 - 430 - 381 - 31 - - - - - 10 - 75 - true - - - - Accepted: 0 - Rejected: 0 - - - - - - 0 - 40 - 411 - 16 - - - - Qt::Horizontal - - - - - - -1 - 260 - 404 - 170 - - - - 0 - - - - Log - - - - - 0 - 0 - 398 - 145 - - - - - 0 - 0 - - - - QFrame::NoFrame - - - QFrame::Plain - - - 374 - - - 100000 - - - QAbstractItemView::SelectItems - - - QListView::Snap - - - false - - - 10 - - - - - - Mining Pool Status - - - - - 160 - 30 - 231 - 20 - - - - - - - 10 - 30 - 141 - 22 - - - - - Litecoinpool.org - - - - - Pool-X - - - - - Elitist Jerks - - - - - OzCoin LTC Pool - - - - - - - 10 - 10 - 141 - 16 - - - - Mining pool - - - - - - 160 - 10 - 201 - 16 - - - - Mining pool API key - - - - - - 327 - 0 - 71 - 23 - - - - Update - - - - - - 10 - 60 - 381 - 80 - - - - - - - - - 255 - 255 - 255 - - - - - - - - - 255 - 255 - 255 - - - - - - - - - 240 - 240 - 240 - - - - - - - - QFrame::NoFrame - - - QFrame::Plain - - - <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> -<html><head><meta name="qrichtext" content="1" /><style type="text/css"> -p, li { white-space: pre-wrap; } -</style></head><body style=" font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;"> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:8pt;">Mining pool status hasn't been updated yet.</span></p></body></html> - - - false - - - - - - Output - - - - - 0 - 0 - 398 - 145 - - - - - 0 - 0 - - - - QFrame::NoFrame - - - false - - - - - - Options - - - - - 10 - 10 - 381 - 17 - - - - Show system tray message on found share - - - - - - 10 - 30 - 381 - 17 - - - - Restart miner automatically after crashing - - - - - - 10 - 50 - 381 - 17 - - - - Save output to a text file - - - - - - - - 0 - 50 - 401 - 211 - - - - QFrame::StyledPanel - - - QFrame::Raised - - - - - 10 - 180 - 381 - 20 - - - - - - - 10 - 150 - 131 - 31 - - - - Additional parameters - - - - - - 10 - 130 - 141 - 20 - - - - - - - 160 - 130 - 141 - 20 - - - - - - - 310 - 130 - 81 - 20 - - - - 5 - - - - - - 10 - 100 - 131 - 31 - - - - Username - - - - - - 160 - 100 - 131 - 31 - - - - Password - - - - - - 310 - 100 - 131 - 31 - - - - Port - - - - - - 10 - 80 - 381 - 20 - - - - - - - 10 - 50 - 381 - 31 - - - - RPC Server - - - - - - 10 - 30 - 191 - 22 - - - - - 1 - - - - - 2 - - - - - 3 - - - - - 4 - - - - - 5 - - - - - 6 - - - - - 7 - - - - - 8 - - - - - - - 10 - 0 - 191 - 31 - - - - Threads - - - - - - 210 - 0 - 181 - 31 - - - - Scantime - - - - - - 210 - 30 - 181 - 20 - - - - - - - - - - + + + MainWindow + + + + 0 + 0 + 400 + 460 + + + + + 0 + 0 + + + + ScryptMiner GUI + + + + + + 10 + 0 + 131 + 31 + + + + Speed + + + + + + 10 + 20 + 271 + 31 + + + + + 10 + 75 + true + + + + N/A + + + + + + 290 + 10 + 101 + 31 + + + + Start Mining + + + + + + 10 + 430 + 381 + 31 + + + + + 10 + 75 + true + + + + Accepted: 0 - Rejected: 0 + + + + + + 0 + 40 + 411 + 16 + + + + Qt::Horizontal + + + + + + -1 + 260 + 404 + 170 + + + + 1 + + + + Log + + + + + 0 + 0 + 398 + 145 + + + + + 0 + 0 + + + + QFrame::NoFrame + + + QFrame::Plain + + + 374 + + + 100000 + + + QAbstractItemView::SelectItems + + + QListView::Snap + + + false + + + 10 + + + + + + Mining Pool Status + + + + + 160 + 30 + 231 + 20 + + + + + + + 10 + 30 + 141 + 22 + + + + + Litecoinpool.org + + + + + OzCoin LTC Pool + + + + + + + 10 + 10 + 141 + 16 + + + + Mining pool + + + + + + 160 + 10 + 201 + 16 + + + + Mining pool API key + + + + + + 327 + 0 + 71 + 23 + + + + Update + + + + + + 10 + 60 + 381 + 80 + + + + + + + + + 255 + 255 + 255 + + + + + + + + + 255 + 255 + 255 + + + + + + + + + 240 + 240 + 240 + + + + + + + + QFrame::NoFrame + + + QFrame::Plain + + + <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> +<html><head><meta name="qrichtext" content="1" /><style type="text/css"> +p, li { white-space: pre-wrap; } +</style></head><body style=" font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;"> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:8pt;">Mining pool status hasn't been updated yet.</span></p></body></html> + + + false + + + + + + Output + + + + + 0 + 0 + 398 + 145 + + + + + 0 + 0 + + + + QFrame::NoFrame + + + false + + + + + + Options + + + + + 10 + 10 + 381 + 17 + + + + Show system tray message on found share + + + + + + 10 + 30 + 381 + 17 + + + + Restart miner automatically after crashing + + + + + + 10 + 50 + 381 + 17 + + + + Save output to a text file + + + + + + + + 0 + 50 + 401 + 211 + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + 10 + 180 + 381 + 20 + + + + + + + 10 + 150 + 131 + 31 + + + + Additional parameters + + + + + + 10 + 130 + 141 + 20 + + + + + + + 160 + 130 + 141 + 20 + + + + + + + 310 + 130 + 81 + 20 + + + + 5 + + + + + + 10 + 100 + 131 + 31 + + + + Username + + + + + + 160 + 100 + 131 + 31 + + + + Password + + + + + + 310 + 100 + 131 + 31 + + + + Port + + + + + + 10 + 80 + 381 + 20 + + + + + + + 10 + 50 + 381 + 31 + + + + RPC Server + + + + + + 10 + 30 + 191 + 22 + + + + + 1 + + + + + 2 + + + + + 3 + + + + + 4 + + + + + 5 + + + + + 6 + + + + + 7 + + + + + 8 + + + + + + + 10 + 0 + 191 + 31 + + + + Threads + + + + + + 210 + 0 + 181 + 31 + + + + Scantime + + + + + + 210 + 30 + 181 + 20 + + + + + + + + + + diff --git a/poolparse.cpp b/poolparse.cpp index c7a7bd7..010783c 100644 --- a/poolparse.cpp +++ b/poolparse.cpp @@ -1,89 +1,89 @@ -#include "poolparse.h" - -PoolParse::PoolParse(QObject *parent) : - QObject(parent) -{ -} - -QString PoolParse::getURL(QString poolName, QString apiKey) -{ - QString url; - - if (poolName == "Litecoinpool.org") - url = "http://www.litecoinpool.org/api?api_key="; - else if (poolName == "OzCoin LTC Pool") - url = "https://lc.ozco.in/api.php?api_key="; - else if (poolName == "Pool-X") - url = "http://pool-x.eu/api?api_key="; - else if (poolName == "Elitist Jerks") - url = "http://www.ejpool.info:8080/api?api_key="; - - url.append(apiKey); - - return url; -} - -QString PoolParse::parseData(QString poolName, QVariantMap data) -{ - QString message; - double totalRewards = -1; - double estimatedRewards = -1; - double paidRewards = -1; - double unpaidRewards = -1; - double past24hRewards = -1; - - QVariantMap userMap; - - if (poolName == "Litecoinpool.org") - { - userMap = data.value("user").toMap(); - totalRewards = userMap.value("total_rewards").toDouble(); - paidRewards = userMap.value("paid_rewards").toDouble(); - unpaidRewards = userMap.value("unpaid_rewards").toDouble(); - past24hRewards = userMap.value("past_24h_rewards").toDouble(); - } - else if (poolName == "OzCoin LTC Pool") - { - unpaidRewards = data.value("current_balance").toDouble(); - } - else if (poolName == "Pool-X") - { - unpaidRewards = data.value("confirmed_rewards").toDouble(); - paidRewards = data.value("payout_history").toDouble(); - estimatedRewards = data.value("round_estimate").toDouble(); - } - else if (poolName == "Elitist Jerks") - { - unpaidRewards = data.value("confirmed_rewards").toDouble(); - paidRewards = data.value("payout_history").toDouble(); - estimatedRewards = data.value("round_estimate").toDouble(); - } - - if (totalRewards != -1) - { - QString totalString = QString("Total rewards:
%1 LTC

").arg(totalRewards); - message.append(totalString); - } - if (estimatedRewards != -1) - { - QString estString = QString("Estimated rewards:
%1 LTC

").arg(estimatedRewards); - message.append(estString); - } - if (paidRewards != -1) - { - QString paidString = QString("Paid rewards:
%1 LTC

").arg(paidRewards); - message.append(paidString); - } - if (unpaidRewards != -1) - { - QString unpaidString = QString("Unpaid rewards:
%1 LTC

").arg(unpaidRewards); - message.append(unpaidString); - } - if (past24hRewards != -1) - { - QString past24hString = QString("Rewards in past 24 hours:
%1 LTC

").arg(past24hRewards); - message.append(past24hString); - } - - return message; -} +#include "poolparse.h" + +PoolParse::PoolParse(QObject *parent) : + QObject(parent) +{ +} + +QString PoolParse::getURL(QString poolName, QString apiKey) +{ + QString url; + + if (poolName == "Litecoinpool.org") + url = "https://www.litecoinpool.org/api?api_key="; + else if (poolName == "OzCoin LTC Pool") + url = "https://lc.ozcoin.net/api.php?api_key="; + else if (poolName == "Elitist Jerks") + url = "http://www.ejpool.info:8080/api?api_key="; + + url.append(apiKey); + + return url; +} + +QString PoolParse::parseData(QString poolName, QVariantMap data) +{ + QString message; + double totalRewards = -1; + double estimatedRewards = -1; + double paidRewards = -1; + double unpaidRewards = -1; + double past24hRewards = -1; + double hashrate=-1; + + QVariantMap userMap; + + if (poolName == "Litecoinpool.org") + { + userMap = data.value("user").toMap(); + hashrate = userMap.value("hashrate").toReal(); + totalRewards = userMap.value("total_rewards").toReal(); + paidRewards = userMap.value("paid_rewards").toReal(); + unpaidRewards = userMap.value("unpaid_rewards").toReal(); + past24hRewards = userMap.value("past_24h_rewards").toReal(); + + } + else if (poolName == "OzCoin LTC Pool") + { + unpaidRewards = data.value("current_balance").toReal(); + } + else if (poolName == "Elitist Jerks") + { + unpaidRewards = data.value("confirmed_rewards").toReal(); + paidRewards = data.value("payout_history").toReal(); + estimatedRewards = data.value("round_estimate").toReal(); + } + + if (totalRewards != -1) + { + QString totalString = QString("Total rewards:
%1 LTC

").arg(totalRewards); + message.append(totalString); + } + if (hashrate != -1) + { + QString totalString = QString("Hash Rate:
%1 LTC

").arg(hashrate); + message.append(totalString); + } + if (estimatedRewards != -1) + { + QString estString = QString("Estimated rewards:
%1 LTC

").arg(estimatedRewards); + message.append(estString); + } + if (paidRewards != -1) + { + QString paidString = QString("Paid rewards:
%1 LTC

").arg(paidRewards); + message.append(paidString); + } + if (unpaidRewards != -1) + { + QString unpaidString = QString("Unpaid rewards:
%1 LTC

").arg(unpaidRewards); + message.append(unpaidString); + } + if (past24hRewards != -1) + { + QString past24hString = QString("Rewards in past 24 hours:
%1 LTC

").arg(past24hRewards); + message.append(past24hString); + } + + return message; +} diff --git a/poolparse.h b/poolparse.h index 678a5c5..dccbd82 100644 --- a/poolparse.h +++ b/poolparse.h @@ -1,22 +1,22 @@ -#ifndef POOLPARSE_H -#define POOLPARSE_H - -#include -#include -#include - -class PoolParse : public QObject -{ - Q_OBJECT -public: - explicit PoolParse(QObject *parent = 0); - -signals: - -public slots: - static QString getURL(QString poolName, QString apiKey); - static QString parseData(QString poolName, QVariantMap data); - -}; - -#endif // POOLPARSE_H +#ifndef POOLPARSE_H +#define POOLPARSE_H + +#include +#include +#include + +class PoolParse : public QObject +{ + Q_OBJECT +public: + explicit PoolParse(QObject *parent = 0); + +signals: + +public slots: + static QString getURL(QString poolName, QString apiKey); + static QString parseData(QString poolName, QVariantMap data); + +}; + +#endif // POOLPARSE_H diff --git a/qlogger.cpp b/qlogger.cpp new file mode 100644 index 0000000..0293104 --- /dev/null +++ b/qlogger.cpp @@ -0,0 +1,35 @@ +#include "qlogger.h" + +#include "qlogger.h" + +QLogger::QLogger(QObject *parent, QString fileName, QPlainTextEdit *editor) : QObject(parent) { + m_editor = editor; + m_showDate = true; + if (!fileName.isEmpty()) { + file = new QFile; + file->setFileName(fileName); + file->open(QIODevice::Append | QIODevice::Text); + } +} + +void QLogger::write(const QString &value) { + QString text = value;// + ""; + if (m_showDate) + text = QDateTime::currentDateTime().toString("dd.MM.yyyy hh:mm:ss ") + text; + QTextStream out(file); + out.setCodec("UTF-8"); + if (file != 0) { + out << text; + } + if (m_editor != 0) + m_editor->appendPlainText(text); +} + +void QLogger::setShowDateTime(bool value) { + m_showDate = value; +} + +QLogger::~QLogger() { + if (file != 0) + file->close(); +} diff --git a/qlogger.h b/qlogger.h new file mode 100644 index 0000000..428284f --- /dev/null +++ b/qlogger.h @@ -0,0 +1,30 @@ +#ifndef QLOGGER_H +#define QLOGGER_H + +#include +#include +#include +#include +#include + +class QLogger : public QObject +{ + Q_OBJECT +public: + explicit QLogger(QObject *parent, QString fileName, QPlainTextEdit *editor = 0); + ~QLogger(); + void setShowDateTime(bool value); + +private: + QFile *file; + QPlainTextEdit *m_editor; + bool m_showDate; + +signals: + +public slots: + void write(const QString &value); + +}; + +#endif // LOGGER_H From 5c7e5a2bd993f9143f2d8bbf892728d0fd910f65 Mon Sep 17 00:00:00 2001 From: mrpostiga Date: Fri, 28 Jun 2019 15:05:29 +0100 Subject: [PATCH 2/2] Update PoolParse.cpp Removed old pools --- poolparse.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/poolparse.cpp b/poolparse.cpp index cf68756..c61aee2 100644 --- a/poolparse.cpp +++ b/poolparse.cpp @@ -11,10 +11,6 @@ QString PoolParse::getURL(QString poolName, QString apiKey) if (poolName == "Litecoinpool.org") url = "https://www.litecoinpool.org/api?api_key="; - else if (poolName == "OzCoin LTC Pool") - url = "https://lc.ozcoin.net/api.php?api_key="; - else if (poolName == "Elitist Jerks") - url = "http://www.ejpool.info:8080/api?api_key="; url.append(apiKey);