GCI task: feedback is important
authorvalnut
Sat, 14 Jan 2012 05:05:53 +0100
changeset 6561 b2165583cdf5
parent 6560 ca07e6be08d0
child 6562 e6b35a238d69
GCI task: feedback is important
QTfrontend/hwform.cpp
QTfrontend/hwform.h
QTfrontend/ui/page/pagefeedback.cpp
QTfrontend/ui/page/pagefeedback.h
QTfrontend/ui/page/pagemain.cpp
QTfrontend/ui/page/pagemain.h
QTfrontend/ui_hwform.cpp
QTfrontend/ui_hwform.h
--- a/QTfrontend/hwform.cpp	Sat Jan 14 05:03:21 2012 +0100
+++ b/QTfrontend/hwform.cpp	Sat Jan 14 05:05:53 2012 +0100
@@ -65,6 +65,7 @@
 #include "pagemultiplayer.h"
 #include "pagenet.h"
 #include "pagemain.h"
+#include "pagefeedback.h"
 #include "pagenetserver.h"
 #include "pagedrawmap.h"
 #include "pagenettype.h"
@@ -94,6 +95,7 @@
 #endif
 #endif
 
+
 // I started handing this down to each place it touches, but it was getting ridiculous
 // and this one flag does not warrant a static class
 bool frontendEffects = true;
@@ -170,6 +172,9 @@
 
     connect(ui.pageMain->BtnSetup, SIGNAL(clicked()), pageSwitchMapper, SLOT(map()));
     pageSwitchMapper->setMapping(ui.pageMain->BtnSetup, ID_PAGE_SETUP);
+
+    connect(ui.pageMain->BtnFeedback, SIGNAL(clicked()), pageSwitchMapper, SLOT(map()));
+    pageSwitchMapper->setMapping(ui.pageMain->BtnFeedback, ID_PAGE_FEEDBACK);
     
     connect(ui.pageMain->BtnNet, SIGNAL(clicked()), pageSwitchMapper, SLOT(map()));
     pageSwitchMapper->setMapping(ui.pageMain->BtnNet, ID_PAGE_NETTYPE);
@@ -183,6 +188,8 @@
     //connect(ui.pageMain->BtnExit, SIGNAL(pressed()), this, SLOT(btnExitPressed()));
     //connect(ui.pageMain->BtnExit, SIGNAL(clicked()), this, SLOT(btnExitClicked()));
 
+    connect(ui.pageFeedback->BtnSend, SIGNAL(clicked()), this, SLOT(SendFeedback()));
+
     connect(ui.pageEditTeam, SIGNAL(teamEdited()), this, SLOT(AfterTeamEdit()));
 
     connect(ui.pageMultiplayer->BtnStartMPGame, SIGNAL(clicked()), this, SLOT(StartMPGame()));
@@ -1554,3 +1561,106 @@
     }
 }
 
+void HWForm::SendFeedback()
+{
+    //Create Xml representation of google code issue first
+    if (!CreateIssueXml())
+    {
+        QMessageBox::warning(this, QMessageBox::tr("Fields required"),
+              QMessageBox::tr("Please fill out all fields"));
+        return;
+    }
+    
+    //Google login using fake account (feedback.hedgewars@gmail.com)
+    nam = new QNetworkAccessManager(this);
+    connect(nam, SIGNAL(finished(QNetworkReply*)),
+	this, SLOT(finishedSlot(QNetworkReply*)));
+
+    QUrl url(string(string("https://www.google.com/accounts/ClientLogin?"
+             "accountType=GOOGLE&Email=feedback.hedgewars@gmail.com&Passwd=hwfeedback&service=code&source=HedgewarsFoundation-Hedgewars-")
+	     + (cVersionString?(*cVersionString):QString("")).toStdString()).c_str());
+    nam->get(QNetworkRequest(url));
+
+}
+
+bool HWForm::CreateIssueXml()
+{
+    QString summary = ui.pageFeedback->summary->text();
+    QString description = ui.pageFeedback->description->toPlainText();
+
+    //Check if all necessary information is entered
+    if (summary.isEmpty() || description.isEmpty())
+	return false;
+
+    issueXml =
+	"<?xml version='1.0' encoding='UTF-8'?>"
+	"<entry xmlns='http://www.w3.org/2005/Atom' xmlns:issues='http://code.google.com/p/hedgewars/issues/list'>"
+        "<title>";
+    issueXml.append(summary);
+    issueXml.append("</title><content type='html'>");
+    issueXml.append(description);
+    issueXml.append("</content><author><name>feedback.hedgewars</name></author></entry>");
+
+    return true;
+}
+
+void HWForm::finishedSlot(QNetworkReply* reply)
+{
+    if (reply && reply->error() == QNetworkReply::NoError)
+    {
+	QByteArray array = reply->readAll();
+        QString str(array);
+
+        if (authToken.length() != 0)
+	{
+	   QMessageBox::information(this, QMessageBox::tr("Success"),
+              QMessageBox::tr("Successfully posted the issue on code.google.com!"));
+	   ui.pageFeedback->summary->clear();
+	   ui.pageFeedback->description->clear();
+	   authToken = "";
+	   return;
+	}
+
+	if(!getAuthToken(str))
+	{
+	   QMessageBox::warning(this, QMessageBox::tr("Network"),
+              QMessageBox::tr("Error during authentication with www.google.com"));
+	   return;
+	}
+
+	QByteArray body(issueXml.toStdString().c_str());
+	QNetworkRequest header(QUrl("https://code.google.com/feeds/issues/p/hedgewars/issues/full"));
+	header.setRawHeader("Content-Length", QString::number(issueXml.length()).toAscii());
+	header.setRawHeader("Content-Type", "application/atom+xml");
+	header.setRawHeader("Authorization", string(
+	   string("GoogleLogin auth=") + authToken.toStdString()).c_str());
+	nam->post(header, body);
+
+    }
+    else if (authToken.length() == 0)
+	QMessageBox::warning(this, QMessageBox::tr("Network"),
+              QMessageBox::tr("Error during authentication with www.google.com"));
+    else
+    {
+	QMessageBox::warning(this, QMessageBox::tr("Network"),
+              QMessageBox::tr("Error creating the issue"));
+	authToken = "";
+    }
+	
+}
+
+bool HWForm::getAuthToken(QString str)
+{
+   QRegExp ex("Auth=(.+)");
+
+   if (-1 == ex.indexIn(str))
+	return false;
+   
+   authToken = ex.cap(1);
+   authToken.remove(QChar('\n'));
+
+   return true;
+}
+
+
+
--- a/QTfrontend/hwform.h	Sat Jan 14 05:03:21 2012 +0100
+++ b/QTfrontend/hwform.h	Sat Jan 14 05:05:53 2012 +0100
@@ -24,6 +24,10 @@
 #include <QTime>
 #include <QPointer>
 #include <QPropertyAnimation>
+#include <QUrl>
+#include <QNetworkReply>
+#include <QNetworkRequest>
+#include <QNetworkAccessManager>
 
 #include "netserver.h"
 #include "game.h"
@@ -116,6 +120,15 @@
     void onFrontendFullscreen(bool value);
     void Music(bool checked);
     void UpdateCampaignPage(int index);
+    //Starts the transmission process for the feedback
+    void SendFeedback();
+    //Make a xml representation of the issue to be created
+    bool CreateIssueXml();
+    //Called the first time when receiving authorization token from google,
+    //second time when receiving the response after posting the issue
+    void finishedSlot(QNetworkReply* reply);
+    //Filter the auth token from the reply from google
+    bool getAuthToken(QString str);
 
     void NetGameChangeStatus(bool isMaster);
     void NetGameMaster();
@@ -158,7 +171,8 @@
         ID_PAGE_NETTYPE         = 18,
         ID_PAGE_CAMPAIGN        = 19,
         ID_PAGE_DRAWMAP         = 20,
-        ID_PAGE_DATADOWNLOAD    = 21
+        ID_PAGE_DATADOWNLOAD    = 21,
+        ID_PAGE_FEEDBACK        = 22
         };
     QPointer<HWGame> game;
     QPointer<HWNetServer> pnetserver;
@@ -172,6 +186,9 @@
     BGWidget * wBackground;
     QSignalMapper * pageSwitchMapper;
     QByteArray m_lastDemo;
+    QNetworkAccessManager * nam;
+    QString issueXml;
+    QString authToken;
 
     QPropertyAnimation *animationNewSlide;
     QPropertyAnimation *animationOldSlide;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/QTfrontend/ui/page/pagefeedback.cpp	Sat Jan 14 05:05:53 2012 +0100
@@ -0,0 +1,82 @@
+/*
+ * Hedgewars, a free turn based strategy game
+ * Copyright (c) 2006-2011 Andrey Korotaev <unC0Rr@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License
+ *
+ * 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ */
+ 
+#include <QHBoxLayout>
+#include <QLineEdit>
+#include <QTextBrowser>
+#include <QLabel>
+
+#include "pagefeedback.h"
+#include "hwconsts.h"
+
+QLayout * PageFeedback::bodyLayoutDefinition()
+{
+    QVBoxLayout * pageLayout = new QVBoxLayout();
+    QHBoxLayout * summaryLayout = new QHBoxLayout();
+    
+    info = new QLabel();
+    info->setText(
+            "<style type=\"text/css\">"
+            "a { color: #ffcc00; }"
+            "</style>"
+            "<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>"
+            "</div>"
+            );
+    pageLayout->addWidget(info);
+
+    label_summary = new QLabel();
+    label_summary->setText(QLabel::tr("Summary   "));
+    summaryLayout->addWidget(label_summary);
+    summary = new QLineEdit();
+    summaryLayout->addWidget(summary);
+    pageLayout->addLayout(summaryLayout);
+
+    label_description = new QLabel();
+    label_description->setText(QLabel::tr("Description"));
+    pageLayout->addWidget(label_description, 0, Qt::AlignHCenter);
+    description = new QTextBrowser();
+    description->setReadOnly(false);
+    pageLayout->addWidget(description);
+
+    return pageLayout;
+}
+
+QLayout * PageFeedback::footerLayoutDefinition()
+{
+    QHBoxLayout * bottomLayout = new QHBoxLayout();
+    
+    bottomLayout->setStretch(0,1);
+    //TODO: create logo for send button
+    BtnSend = addButton("Send", bottomLayout, 0, false);
+    bottomLayout->insertStretch(0);
+
+    return bottomLayout;
+}
+
+void PageFeedback::connectSignals()
+{
+    //TODO
+}
+
+PageFeedback::PageFeedback(QWidget* parent) : AbstractPage(parent)
+{
+    initPage();
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/QTfrontend/ui/page/pagefeedback.h	Sat Jan 14 05:05:53 2012 +0100
@@ -0,0 +1,44 @@
+/*
+ * Hedgewars, a free turn based strategy game
+ * Copyright (c) 2006-2011 Andrey Korotaev <unC0Rr@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License
+ *
+ * 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ */
+
+#ifndef PAGE_FEEDBACK_H
+#define PAGE_FEEDBACK_H
+
+#include "AbstractPage.h"
+
+class PageFeedback : public AbstractPage
+{
+    Q_OBJECT
+
+public:
+    PageFeedback(QWidget * parent = 0);
+    
+    QPushButton * BtnSend;
+    QLineEdit * summary;
+    QTextBrowser * description;
+    QLabel * info;
+    QLabel * label_summary;
+    QLabel * label_description;
+
+private:
+    QLayout * bodyLayoutDefinition();
+    QLayout * footerLayoutDefinition();
+    void connectSignals();
+};
+
+#endif
--- a/QTfrontend/ui/page/pagemain.cpp	Sat Jan 14 05:03:21 2012 +0100
+++ b/QTfrontend/ui/page/pagemain.cpp	Sat Jan 14 05:05:53 2012 +0100
@@ -78,6 +78,7 @@
     bottomLayout->setStretch(0,1);
 
     BtnSetup = addButton(":/res/Settings.png", bottomLayout, 1, true);
+    BtnFeedback = addButton("Feedback", bottomLayout, 0);
     bottomLayout->setStretch(1,0);
 
     return bottomLayout;
--- a/QTfrontend/ui/page/pagemain.h	Sat Jan 14 05:03:21 2012 +0100
+++ b/QTfrontend/ui/page/pagemain.h	Sat Jan 14 05:05:53 2012 +0100
@@ -31,6 +31,7 @@
     QPushButton * BtnSinglePlayer;
     QPushButton * BtnNet;
     QPushButton * BtnSetup;
+    QPushButton * BtnFeedback;
     QPushButton * BtnInfo;
     QPushButton * BtnDataDownload;
     QLabel * mainNote;
--- a/QTfrontend/ui_hwform.cpp	Sat Jan 14 05:03:21 2012 +0100
+++ b/QTfrontend/ui_hwform.cpp	Sat Jan 14 05:05:53 2012 +0100
@@ -27,6 +27,7 @@
 #include "pagetraining.h"
 #include "pagenetserver.h"
 #include "pageoptions.h"
+#include "pagefeedback.h"
 #include "pageingame.h"
 #include "pagescheme.h"
 #include "pagenettype.h"
@@ -141,4 +142,7 @@
 
     pageDataDownload = new PageDataDownload();
     Pages->addWidget(pageDataDownload);
+
+    pageFeedback = new PageFeedback();
+    Pages->addWidget(pageFeedback);
 }
--- a/QTfrontend/ui_hwform.h	Sat Jan 14 05:03:21 2012 +0100
+++ b/QTfrontend/ui_hwform.h	Sat Jan 14 05:05:53 2012 +0100
@@ -24,6 +24,7 @@
 class PageMultiplayer;
 class PagePlayDemo;
 class PageOptions;
+class PageFeedback;
 class PageNet;
 class PageNetServer;
 class PageNetChat;
@@ -58,6 +59,7 @@
     PageMultiplayer *pageMultiplayer;
     PagePlayDemo *pagePlayDemo;
     PageOptions *pageOptions;
+    PageFeedback *pageFeedback;
     PageNet *pageNet;
     PageNetServer * pageNetServer;
     PageNetChat *pageNetChat;