diff --git a/EasyMiner.pro b/EasyMiner.pro index 3f1fccd..249afa5 100644 --- a/EasyMiner.pro +++ b/EasyMiner.pro @@ -12,11 +12,13 @@ TEMPLATE = app SOURCES += main.cpp\ mainwindow.cpp \ poolparse.cpp \ - json.cpp + json.cpp \ + qlogger.cpp HEADERS += mainwindow.h \ poolparse.h \ - json.h + json.h \ + qlogger.h FORMS += mainwindow.ui 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..5b6589c 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -2,6 +2,7 @@ #include "ui_mainwindow.h" #include "poolparse.h" +#include "qlogger.h" MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), @@ -23,7 +24,7 @@ MainWindow::MainWindow(QWidget *parent) : networkManager = new QNetworkAccessManager(this); - setFixedSize(400, 460); + setFixedSize(400, 500); checkSettings(); @@ -177,9 +178,6 @@ 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"; @@ -205,7 +203,7 @@ void MainWindow::startMining() ui->parametersLine->setDisabled(true); minerActive = true; ui->tabWidget->move(ui->tabWidget->x(), 52); - ui->tabWidget->setFixedHeight(380); + ui->tabWidget->setFixedHeight(400); ui->settingsFrame->setVisible(false); resizeElements(); @@ -247,8 +245,8 @@ void MainWindow::stopMining() ui->passwordLine->setDisabled(false); ui->portLine->setDisabled(false); ui->parametersLine->setDisabled(false); - ui->tabWidget->move(-1,260); - ui->tabWidget->setFixedHeight(170); + ui->tabWidget->move(8,263); + ui->tabWidget->setFixedHeight(201); ui->settingsFrame->setVisible(true); resizeElements(); @@ -532,8 +530,15 @@ void MainWindow::poolDataLoaded(QNetworkReply *data) 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); @@ -605,3 +610,8 @@ QString MainWindow::getTime(QString time) else return NULL; } + +void MainWindow::on_startButton_clicked() +{ + +} diff --git a/mainwindow.h b/mainwindow.h index deccdca..059c6a2 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -1,118 +1,121 @@ -#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 slots: + void on_startButton_clicked(); + +private: + Ui::MainWindow *ui; +}; + +#endif // MAINWINDOW_H diff --git a/mainwindow.ui b/mainwindow.ui index f964cbd..e071bac 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -6,8 +6,8 @@ 0 0 - 400 - 460 + 401 + 500 @@ -19,6 +19,13 @@ ScryptMiner GUI + + + :/icons/icon:/icons/icon + + + false + @@ -26,7 +33,7 @@ 10 0 131 - 31 + 21 @@ -39,7 +46,7 @@ 10 20 271 - 31 + 20 @@ -65,14 +72,18 @@ Start Mining + + + :/icons/activeIcon:/icons/activeIcon + 10 - 430 + 470 381 - 31 + 20 @@ -102,15 +113,33 @@ - -1 - 260 - 404 - 170 + 8 + 263 + 390 + 201 + + QTabWidget::North + + + QTabWidget::Triangular + 0 + + Qt::ElideNone + + + true + + + false + + + false + Log @@ -118,10 +147,10 @@ - 0 - 0 - 398 - 145 + 1 + 1 + 381 + 180 @@ -131,10 +160,10 @@ - QFrame::NoFrame + QFrame::WinPanel - QFrame::Plain + QFrame::Sunken 374 @@ -142,6 +171,9 @@ 100000 + + false + QAbstractItemView::SelectItems @@ -151,6 +183,9 @@ false + + QListView::Adjust + 10 @@ -165,7 +200,7 @@ 160 30 - 231 + 221 20 @@ -184,16 +219,6 @@ Litecoinpool.org - - - Pool-X - - - - - Elitist Jerks - - OzCoin LTC Pool @@ -218,7 +243,7 @@ 160 10 - 201 + 111 16 @@ -229,8 +254,8 @@ - 327 - 0 + 310 + 5 71 23 @@ -244,8 +269,8 @@ 10 60 - 381 - 80 + 371 + 111 @@ -291,6 +316,12 @@ QFrame::Plain + + 1 + + + 1 + <!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"> @@ -310,10 +341,10 @@ p, li { white-space: pre-wrap; } - 0 - 0 - 398 - 145 + 2 + 3 + 380 + 171 @@ -323,7 +354,7 @@ p, li { white-space: pre-wrap; } - QFrame::NoFrame + QFrame::WinPanel false @@ -598,6 +629,8 @@ p, li { white-space: pre-wrap; } - + + + diff --git a/poolparse.cpp b/poolparse.cpp index c7a7bd7..c61aee2 100644 --- a/poolparse.cpp +++ b/poolparse.cpp @@ -10,13 +10,7 @@ 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 = "https://www.litecoinpool.org/api?api_key="; url.append(apiKey); @@ -31,57 +25,59 @@ QString PoolParse::parseData(QString poolName, QVariantMap data) double paidRewards = -1; double unpaidRewards = -1; double past24hRewards = -1; + double hashrate=-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(); + 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").toDouble(); - } - else if (poolName == "Pool-X") - { - unpaidRewards = data.value("confirmed_rewards").toDouble(); - paidRewards = data.value("payout_history").toDouble(); - estimatedRewards = data.value("round_estimate").toDouble(); + unpaidRewards = data.value("current_balance").toReal(); } else if (poolName == "Elitist Jerks") { - unpaidRewards = data.value("confirmed_rewards").toDouble(); - paidRewards = data.value("payout_history").toDouble(); - estimatedRewards = data.value("round_estimate").toDouble(); + 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); + QString totalString = QString("Total rewards:
%1 LTC

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

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

").arg(estimatedRewards); + QString estString = QString("Estimated rewards:
%1 LTC

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

").arg(paidRewards); + QString paidString = QString("Paid rewards:
%1 LTC

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

").arg(unpaidRewards); + QString unpaidString = QString("Unpaid rewards:
%1 LTC

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

").arg(past24hRewards); + QString past24hString = QString("Rewards in past 24 hours:
%1 LTC

").arg(past24hRewards,0, 'f', 12); message.append(past24hString); } 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..bbd9a5e --- /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..d7e0202 --- /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