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
+62 -1
View File
@@ -22,18 +22,21 @@
#include "guilog.h"
#include "configfile.h"
#include "mymessagebox.h"
#include "callback.h"
#include "curl/curl.h"
LogFileDialog::LogFileDialog(QWidget *parent, ConfigFile *c) :
QDialog(parent), myConfig(c),
ui(new Ui::LogFileDialog)
{
ui->setupUi(this);
ui->setupUi(this);
connect( ui->pushButton_deleteLog, SIGNAL(clicked()), this, SLOT (deleteLogFile()));
connect( ui->pushButton_exportLogHtml, SIGNAL(clicked()), this, SLOT (exportLogToHtml()));
connect( ui->pushButton_exportLogTxt, SIGNAL(clicked()), this, SLOT (exportLogToTxt()));
connect( ui->pushButton_saveLogAs, SIGNAL(clicked()), this, SLOT (saveLogFileAs()));
connect( ui->treeWidget_logFiles, SIGNAL(currentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*)), this, SLOT(showLogFilePreview()));
connect( ui->pushButton_analyseLogfile, SIGNAL(clicked()), this, SLOT (uploadFile()));
}
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;
}
}
}