gui implementation of log analysis scripts for #146

This commit is contained in:
doitux
2012-11-01 20:33:04 +01:00
parent c01dc0d821
commit aa2491c2de
8 changed files with 189 additions and 125 deletions
+4 -2
View File
@@ -210,7 +210,8 @@ HEADERS += src/engine/game.h \
src/gui/qt/gametable/mycashlabel.h \ src/gui/qt/gametable/mycashlabel.h \
src/gui/qt/sound/soundevents.h \ src/gui/qt/sound/soundevents.h \
src/gui/qt/mymessagebox/mymessagebox.h \ src/gui/qt/mymessagebox/mymessagebox.h \
src/gui/qt/logfiledialog/logfiledialog.h src/gui/qt/logfiledialog/logfiledialog.h \
src/gui/qt/logfiledialog/callback.h
!gui_800x480 { !gui_800x480 {
FORMS += src/gui/qt/gametable.ui \ FORMS += src/gui/qt/gametable.ui \
@@ -287,7 +288,8 @@ SOURCES += src/pokerth.cpp \
src/gui/qt/gametable/mycashlabel.cpp \ src/gui/qt/gametable/mycashlabel.cpp \
src/gui/qt/sound/soundevents.cpp \ src/gui/qt/sound/soundevents.cpp \
src/gui/qt/mymessagebox/mymessagebox.cpp \ src/gui/qt/mymessagebox/mymessagebox.cpp \
src/gui/qt/logfiledialog/logfiledialog.cpp src/gui/qt/logfiledialog/logfiledialog.cpp \
src/gui/qt/logfiledialog/callback.cpp
TRANSLATIONS = ts/pokerth_af.ts \ TRANSLATIONS = ts/pokerth_af.ts \
ts/pokerth_bg.ts \ ts/pokerth_bg.ts \
ts/pokerth_zhcn.ts \ ts/pokerth_zhcn.ts \
+87 -76
View File
@@ -14,6 +14,85 @@
<string>Dialog</string> <string>Dialog</string>
</property> </property>
<layout class="QGridLayout" name="gridLayout"> <layout class="QGridLayout" name="gridLayout">
<item row="1" column="0" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout_9">
<item>
<widget class="QPushButton" name="pushButton_exportLogHtml">
<property name="text">
<string>Export as HTML</string>
</property>
<property name="icon">
<iconset resource="resources/pokerth.qrc">
<normaloff>:/gfx/text-html.png</normaloff>:/gfx/text-html.png</iconset>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_exportLogTxt">
<property name="text">
<string>Export as txt</string>
</property>
<property name="icon">
<iconset resource="resources/pokerth.qrc">
<normaloff>:/gfx/text-plain.png</normaloff>:/gfx/text-plain.png</iconset>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_saveLogAs">
<property name="text">
<string>Save as ...</string>
</property>
<property name="icon">
<iconset resource="resources/pokerth.qrc">
<normaloff>:/gfx/filesave.png</normaloff>:/gfx/filesave.png</iconset>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_deleteLog">
<property name="text">
<string>Delete</string>
</property>
<property name="icon">
<iconset resource="resources/pokerth.qrc">
<normaloff>:/gfx/editdelete.png</normaloff>:/gfx/editdelete.png</iconset>
</property>
</widget>
</item>
</layout>
</item>
<item row="0" column="1">
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<widget class="QLabel" name="label_37">
<property name="text">
<string>Preview:</string>
</property>
</widget>
</item>
<item>
<widget class="QTextBrowser" name="textBrowser_logPreview">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
</layout>
</item>
<item row="4" column="0" colspan="2">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
<item row="0" column="0"> <item row="0" column="0">
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QVBoxLayout" name="verticalLayout">
<item> <item>
@@ -81,89 +160,21 @@
</item> </item>
</layout> </layout>
</item> </item>
<item row="0" column="1"> <item row="3" column="0" colspan="2">
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<widget class="QLabel" name="label_37">
<property name="text">
<string>Preview:</string>
</property>
</widget>
</item>
<item>
<widget class="QTextBrowser" name="textBrowser_logPreview">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
</layout>
</item>
<item row="1" column="0" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout_9">
<item>
<widget class="QPushButton" name="pushButton_exportLogHtml">
<property name="text">
<string>Export as HTML</string>
</property>
<property name="icon">
<iconset resource="resources/pokerth.qrc">
<normaloff>:/gfx/text-html.png</normaloff>:/gfx/text-html.png</iconset>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_exportLogTxt">
<property name="text">
<string>Export as txt</string>
</property>
<property name="icon">
<iconset resource="resources/pokerth.qrc">
<normaloff>:/gfx/text-plain.png</normaloff>:/gfx/text-plain.png</iconset>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_saveLogAs">
<property name="text">
<string>Save as ...</string>
</property>
<property name="icon">
<iconset resource="resources/pokerth.qrc">
<normaloff>:/gfx/filesave.png</normaloff>:/gfx/filesave.png</iconset>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_deleteLog">
<property name="text">
<string>Delete</string>
</property>
<property name="icon">
<iconset resource="resources/pokerth.qrc">
<normaloff>:/gfx/editdelete.png</normaloff>:/gfx/editdelete.png</iconset>
</property>
</widget>
</item>
</layout>
</item>
<item row="2" column="0" colspan="2">
<widget class="Line" name="line"> <widget class="Line" name="line">
<property name="orientation"> <property name="orientation">
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
</property> </property>
</widget> </widget>
</item> </item>
<item row="3" column="0" colspan="2"> <item row="2" column="0" colspan="2">
<widget class="QDialogButtonBox" name="buttonBox"> <widget class="QPushButton" name="pushButton_analyseLogfile">
<property name="orientation"> <property name="text">
<enum>Qt::Horizontal</enum> <string>Analyse Logfile ...</string>
</property> </property>
<property name="standardButtons"> <property name="icon">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set> <iconset resource="resources/pokerth.qrc">
<normaloff>:/gfx/view-statistics.png</normaloff>:/gfx/view-statistics.png</iconset>
</property> </property>
</widget> </widget>
</item> </item>
+19
View File
@@ -0,0 +1,19 @@
#include "callback.h"
Callback::Callback()
{
}
size_t
Callback::writeCallback(char* buf, size_t size, size_t nmemb, void* up)
{
data = "";
for (int c = 0; c<size*nmemb; c++)
{
data.push_back(buf[c]);
}
return size*nmemb;
}
@@ -1,14 +1,15 @@
#ifndef LOGUPLOADCALLBACK_H #ifndef CALLBACK_H
#define LOGUPLOADCALLBACK_H #define CALLBACK_H
#include <iostream> #include <iostream>
class LogUploadCallback class Callback
{ {
public: public:
LogUploadCallback(); Callback();
size_t writeCallback(char* buf, size_t size, size_t nmemb, void* up); size_t writeCallback(char* buf, size_t size, size_t nmemb, void* up);
std::string getData() { return data; } std::string getData() { return data; }
private: private:
@@ -17,4 +18,4 @@ private:
}; };
#endif // LOGUPLOADCALLBACK_H #endif // CALLBACK_H
+62 -1
View File
@@ -22,18 +22,21 @@
#include "guilog.h" #include "guilog.h"
#include "configfile.h" #include "configfile.h"
#include "mymessagebox.h" #include "mymessagebox.h"
#include "callback.h"
#include "curl/curl.h"
LogFileDialog::LogFileDialog(QWidget *parent, ConfigFile *c) : LogFileDialog::LogFileDialog(QWidget *parent, ConfigFile *c) :
QDialog(parent), myConfig(c), QDialog(parent), myConfig(c),
ui(new Ui::LogFileDialog) ui(new Ui::LogFileDialog)
{ {
ui->setupUi(this); ui->setupUi(this);
connect( ui->pushButton_deleteLog, SIGNAL(clicked()), this, SLOT (deleteLogFile())); connect( ui->pushButton_deleteLog, SIGNAL(clicked()), this, SLOT (deleteLogFile()));
connect( ui->pushButton_exportLogHtml, SIGNAL(clicked()), this, SLOT (exportLogToHtml())); connect( ui->pushButton_exportLogHtml, SIGNAL(clicked()), this, SLOT (exportLogToHtml()));
connect( ui->pushButton_exportLogTxt, SIGNAL(clicked()), this, SLOT (exportLogToTxt())); connect( ui->pushButton_exportLogTxt, SIGNAL(clicked()), this, SLOT (exportLogToTxt()));
connect( ui->pushButton_saveLogAs, SIGNAL(clicked()), this, SLOT (saveLogFileAs())); connect( ui->pushButton_saveLogAs, SIGNAL(clicked()), this, SLOT (saveLogFileAs()));
connect( ui->treeWidget_logFiles, SIGNAL(currentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*)), this, SLOT(showLogFilePreview())); connect( ui->treeWidget_logFiles, SIGNAL(currentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*)), this, SLOT(showLogFilePreview()));
connect( ui->pushButton_analyseLogfile, SIGNAL(clicked()), this, SLOT (uploadFile()));
} }
LogFileDialog::~LogFileDialog() LogFileDialog::~LogFileDialog()
@@ -167,3 +170,61 @@ void LogFileDialog::keyPressEvent ( QKeyEvent * event )
} }
} }
} }
Callback* curl_writedata = new Callback();
void writeCallback(char* buf, size_t size, size_t nmemb, void* up)
{
curl_writedata->writeCallback(buf, size, nmemb, up);
}
void LogFileDialog::uploadFile()
{
QTreeWidgetItem* selectedItem = ui->treeWidget_logFiles->currentItem();
if(selectedItem) {
file.setFileName(selectedItem->data(0, Qt::UserRole).toString());
CURL *curl;
CURLcode res;
struct curl_httppost* post = NULL;
struct curl_httppost* last = NULL;
curl = curl_easy_init();
if(curl) {
curl_formadd(&post, &last,
CURLFORM_COPYNAME, "pdb_file",
CURLFORM_FILE, file.fileName().toStdString().c_str(),
CURLFORM_END);
curl_easy_setopt(curl, CURLOPT_URL, "http://pokerth.net/floty_upload/upload.php");
curl_easy_setopt(curl, CURLOPT_HTTPPOST, post);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writeCallback);
res = curl_easy_perform(curl);
if(res) {
qDebug() << "curl_easy_perform failed: " << res << endl;
}
id = QString(curl_writedata->getData().data()).trimmed();
curl_formfree(post);
if(id.length() == 40 && !id.contains("ERROR")) {
qDebug() << id << endl;
QDesktopServices::openUrl(QUrl("http://logfile-analysis.pokerth.net/?ID="+id));
} else {
qDebug() << QString::fromStdString(curl_writedata->getData()) << endl;
}
} else {
qDebug() << "curl_easy_init failed\n" << endl;
}
}
}
+9 -3
View File
@@ -20,7 +20,7 @@
#define LOGFILEDIALOG_H #define LOGFILEDIALOG_H
#include <QDialog> #include <QDialog>
#include <QFile>
namespace Ui { namespace Ui {
class LogFileDialog; class LogFileDialog;
@@ -29,6 +29,7 @@ namespace Ui {
class guiLog; class guiLog;
class ConfigFile; class ConfigFile;
class Callback;
class LogFileDialog : public QDialog class LogFileDialog : public QDialog
{ {
@@ -48,12 +49,17 @@ public slots:
void exportLogToTxt(); void exportLogToTxt();
void saveLogFileAs(); void saveLogFileAs();
void showLogFilePreview(); void showLogFilePreview();
void keyPressEvent ( QKeyEvent * event ); void keyPressEvent ( QKeyEvent * event );
void uploadFile();
private: private:
ConfigFile *myConfig; ConfigFile *myConfig;
guiLog *myGuiLog; guiLog *myGuiLog;
Ui::LogFileDialog *ui; Ui::LogFileDialog *ui;
int writer(char *data, size_t size, size_t nmemb,std::string *buffer);
QFile file;
QString id;
}; };
#endif // LOGFILEDIALOG_H #endif // LOGFILEDIALOG_H
@@ -1,36 +0,0 @@
/*****************************************************************************
* PokerTH - The open source texas holdem engine *
* Copyright (C) 2006-2012 Felix Hammer, Florian Thauer, Lothar May *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Affero General Public License as *
* published by the Free Software Foundation, either version 3 of the *
* License, or (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Affero General Public License for more details. *
* *
* You should have received a copy of the GNU Affero General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
*****************************************************************************/
#include "loguploadcallback.h"
LogUploadCallback::LogUploadCallback()
{
}
size_t
LogUploadCallback::writeCallback(char* buf, size_t size, size_t nmemb, void* up)
{
data = "";
for (int c = 0; c<size*nmemb; c++)
{
data.push_back(buf[c]);
}
return size*nmemb;
}
@@ -1,6 +1,6 @@
/***************************************************************************** /*****************************************************************************
* PokerTH - The open source texas holdem engine * * PokerTH - The open source texas holdem engine *
* Copyright (C) 2006-2011 Felix Hammer, Florian Thauer, Lothar May * * Copyright (C) 2006-2012 Felix Hammer, Florian Thauer, Lothar May *
* * * *
* This program is free software: you can redistribute it and/or modify * * This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Affero General Public License as * * it under the terms of the GNU Affero General Public License as *