@@ -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 @@
"Please give us a feedback!
"
"We are always happy about suggestions, ideas or bug reports."
"The feedback will be posted as a new issue on our Google Code page."
+ //"Your email is optional, but if given, you will be notified of responses."
"
"
);
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 , the , 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("loading
captcha
");
+ 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;
}
diff -r 927da572bcdc -r fe4e94311585 QTfrontend/ui/page/pagefeedback.h
--- a/QTfrontend/ui/page/pagefeedback.h Fri Dec 07 16:03:53 2012 -0500
+++ b/QTfrontend/ui/page/pagefeedback.h Sat Dec 08 15:06:30 2012 +0100
@@ -21,12 +21,17 @@
#include "AbstractPage.h"
+class QNetworkReply;
+class QNetworkAccessManager;
+
class PageFeedback : public AbstractPage
{
Q_OBJECT
public:
PageFeedback(QWidget * parent = 0);
+ void EmbedSystemInfo();
+ void LoadCaptchaImage();
QPushButton * BtnSend;
QLineEdit * summary;
@@ -34,11 +39,27 @@
QLabel * info;
QLabel * label_summary;
QLabel * label_description;
+ QLabel * label_captcha;
+ QLabel * label_email;
+ QLabel * label_captcha_input;
+ QLineEdit * captcha_code;
+ QLineEdit * email;
+ int captchaID;
+
+ private slots:
+
+ virtual void NetReply(QNetworkReply*);
private:
QLayout * bodyLayoutDefinition();
QLayout * footerLayoutDefinition();
+ QNetworkAccessManager * GetNetManager();
+ void ShowErrorMessage(const QString & msg);
void connectSignals();
+
+ QNetworkAccessManager * netManager;
+ QNetworkReply * captchaImageRequest;
+ QNetworkReply * genCaptchaRequest;
};
#endif