--- a/QTfrontend/ui/page/pagefeedback.cpp Fri Dec 07 16:03:53 2012 -0500
+++ b/QTfrontend/ui/page/pagefeedback.cpp Sat Dec 08 15:06:30 2012 +0100
@@ -20,10 +20,15 @@
#include <QLineEdit>
#include <QTextBrowser>
#include <QLabel>
+#include <QHttp>
#include <QSysInfo>
+#include <QDebug>
+#include <QBuffer>
#include <QApplication>
#include <QDesktopWidget>
+#include <QNetworkReply>
#include <QProcess>
+#include <QMessageBox>
#include <string>
@@ -48,6 +53,8 @@
{
QVBoxLayout * pageLayout = new QVBoxLayout();
QHBoxLayout * summaryLayout = new QHBoxLayout();
+ QHBoxLayout * emailLayout = new QHBoxLayout();
+ QHBoxLayout * combinedTopLayout = new QHBoxLayout();
info = new QLabel();
info->setText(
@@ -57,22 +64,48 @@
"<div align=\"center\"><h1>Please give us a feedback!</h1>"
"<h3>We are always happy about suggestions, ideas or bug reports.<h3>"
"<h4>The feedback will be posted as a new issue on our Google Code page.<h4>"
+ //"<h4>Your email is optional, but if given, you will be notified of responses.<h4>"
"</div>"
);
pageLayout->addWidget(info);
label_summary = new QLabel();
- label_summary->setText(QLabel::tr("Summary "));
+ label_summary->setText(QLabel::tr("Summary"));
summaryLayout->addWidget(label_summary);
summary = new QLineEdit();
summaryLayout->addWidget(summary);
- pageLayout->addLayout(summaryLayout);
+ combinedTopLayout->addLayout(summaryLayout);
+
+ label_email = new QLabel();
+ label_email->setText(QLabel::tr("Your Email"));
+ emailLayout->addWidget(label_email);
+ email = new QLineEdit();
+ emailLayout->addWidget(email);
+
+ // Email -- although implemented -- doesn't seem to work as intended.
+ // It's sent in the XML as a <issues:cc> , the <entry>, but it doesn't seem
+ // to actually do anything. If you figure out how to fix that, uncomment these lines
+ // and the line above in the 'info' QLabel to re-enable this feature.
+ //combinedTopLayout->addLayout(emailLayout);
+ //combinedTopLayout->insertSpacing(1, 50);
+
+ pageLayout->addLayout(combinedTopLayout);
label_description = new QLabel();
label_description->setText(QLabel::tr("Description"));
pageLayout->addWidget(label_description, 0, Qt::AlignHCenter);
description = new QTextBrowser();
+ EmbedSystemInfo();
+
+ description->setReadOnly(false);
+ pageLayout->addWidget(description);
+
+ return pageLayout;
+}
+
+void PageFeedback::EmbedSystemInfo()
+{
// Gather some information about the system and embed it into the report
QDesktopWidget* screen = QApplication::desktop();
QString os_version = "Operating system: ";
@@ -223,20 +256,102 @@
+ compiler_bits
+ kernel_line
);
- description->setReadOnly(false);
- pageLayout->addWidget(description);
+}
+
+QNetworkAccessManager * PageFeedback::GetNetManager()
+{
+ if (netManager) return netManager;
+ netManager = new QNetworkAccessManager(this);
+ connect(netManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(NetReply(QNetworkReply*)));
+ return netManager;
+}
+
+void PageFeedback::LoadCaptchaImage()
+{
+ QNetworkAccessManager *netManager = GetNetManager();
+ QUrl captchaURL("http://hedgewars.org/feedback/?gencaptcha");
+ QNetworkRequest req(captchaURL);
+ genCaptchaRequest = netManager->get(req);
+}
+
+void PageFeedback::NetReply(QNetworkReply *reply)
+{
+ if (reply == genCaptchaRequest)
+ {
+ if (reply->error() != QNetworkReply::NoError)
+ {
+ qDebug() << "Error generating captcha image: " << reply->errorString();
+ ShowErrorMessage(QMessageBox::tr("Failed to generate captcha"));
+ return;
+ }
- return pageLayout;
+ bool okay;
+ QByteArray body = reply->readAll();
+ captchaID = QString(body).toInt(&okay);
+
+ if (!okay)
+ {
+ qDebug() << "Failed to get captcha ID: " << body;
+ ShowErrorMessage(QMessageBox::tr("Failed to generate captcha"));
+ return;
+ }
+
+ QString url = "http://hedgewars.org/feedback/?captcha&id=";
+ url += QString::number(captchaID);
+
+ QNetworkAccessManager *netManager = GetNetManager();
+ QUrl captchaURL(url);
+ QNetworkRequest req(captchaURL);
+ captchaImageRequest = netManager->get(req);
+ }
+ else if (reply == captchaImageRequest)
+ {
+ if (reply->error() != QNetworkReply::NoError)
+ {
+ qDebug() << "Error loading captcha image: " << reply->errorString();
+ ShowErrorMessage(QMessageBox::tr("Failed to download captcha"));
+ return;
+ }
+
+ QByteArray imageData = reply->readAll();
+ QPixmap pixmap;
+ pixmap.loadFromData(imageData);
+ label_captcha->setPixmap(pixmap);
+ captcha_code->setText("");
+ }
}
QLayout * PageFeedback::footerLayoutDefinition()
{
QHBoxLayout * bottomLayout = new QHBoxLayout();
+ QHBoxLayout * captchaLayout = new QHBoxLayout();
+ QVBoxLayout * captchaInputLayout = new QVBoxLayout();
- bottomLayout->setStretch(0,1);
+ label_captcha = new QLabel();
+ label_captcha->setStyleSheet("border: 3px solid #ffcc00; border-radius: 4px");
+ label_captcha->setText("<div style='width: 200px; height: 100px;'>loading<br>captcha</div>");
+ captchaLayout->addWidget(label_captcha);
+
+ label_captcha_input = new QLabel();
+ label_captcha_input->setText(QLabel::tr("Type the security code:"));
+ captchaInputLayout->addWidget(label_captcha_input);
+ captchaInputLayout->setAlignment(label_captcha, Qt::AlignBottom);
+ captcha_code = new QLineEdit();
+ captcha_code->setFixedSize(165, 30);
+ captchaInputLayout->addWidget(captcha_code);
+ captchaInputLayout->setAlignment(captcha_code, Qt::AlignTop);
+ captchaLayout->addLayout(captchaInputLayout);
+ captchaLayout->setAlignment(captchaInputLayout, Qt::AlignLeft);
+
+ captchaLayout->insertSpacing(-1, 40);
+ bottomLayout->addLayout(captchaLayout);
+
//TODO: create logo for send button
- BtnSend = addButton("Send", bottomLayout, 0, false);
- bottomLayout->insertStretch(0);
+ BtnSend = addButton("Send Feedback", bottomLayout, 0, false);
+ BtnSend->setFixedSize(120, 40);
+
+ bottomLayout->setStretchFactor(captchaLayout, 0);
+ bottomLayout->setStretchFactor(BtnSend, 1);
return bottomLayout;
}
@@ -246,8 +361,18 @@
//TODO
}
+void PageFeedback::ShowErrorMessage(const QString & msg)
+{
+ QMessageBox msgMsg(this);
+ msgMsg.setIcon(QMessageBox::Warning);
+ msgMsg.setWindowTitle(QMessageBox::tr("Hedgewars - Error"));
+ msgMsg.setText(msg);
+ msgMsg.setWindowModality(Qt::WindowModal);
+ msgMsg.exec();
+}
+
PageFeedback::PageFeedback(QWidget* parent) : AbstractPage(parent)
{
initPage();
-
+ netManager = NULL;
}