# HG changeset patch # User valnut # Date 1326513953 -3600 # Node ID b2165583cdf5490516f1a27222a663922871b070 # Parent ca07e6be08d038dcd393dc289b7e5edc9159e9ef GCI task: feedback is important diff -r ca07e6be08d0 -r b2165583cdf5 QTfrontend/hwform.cpp --- 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 = + "" + "" + ""; + issueXml.append(summary); + issueXml.append(""); + issueXml.append(description); + issueXml.append("feedback.hedgewars"); + + 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; +} + + + diff -r ca07e6be08d0 -r b2165583cdf5 QTfrontend/hwform.h --- 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 #include #include +#include +#include +#include +#include #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 game; QPointer pnetserver; @@ -172,6 +186,9 @@ BGWidget * wBackground; QSignalMapper * pageSwitchMapper; QByteArray m_lastDemo; + QNetworkAccessManager * nam; + QString issueXml; + QString authToken; QPropertyAnimation *animationNewSlide; QPropertyAnimation *animationOldSlide; diff -r ca07e6be08d0 -r b2165583cdf5 QTfrontend/ui/page/pagefeedback.cpp --- /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 + * + * 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 +#include +#include +#include + +#include "pagefeedback.h" +#include "hwconsts.h" + +QLayout * PageFeedback::bodyLayoutDefinition() +{ + QVBoxLayout * pageLayout = new QVBoxLayout(); + QHBoxLayout * summaryLayout = new QHBoxLayout(); + + info = new QLabel(); + info->setText( + "" + "

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.

" + "

" + ); + 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(); + +} diff -r ca07e6be08d0 -r b2165583cdf5 QTfrontend/ui/page/pagefeedback.h --- /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 + * + * 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 diff -r ca07e6be08d0 -r b2165583cdf5 QTfrontend/ui/page/pagemain.cpp --- 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; diff -r ca07e6be08d0 -r b2165583cdf5 QTfrontend/ui/page/pagemain.h --- 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; diff -r ca07e6be08d0 -r b2165583cdf5 QTfrontend/ui_hwform.cpp --- 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); } diff -r ca07e6be08d0 -r b2165583cdf5 QTfrontend/ui_hwform.h --- 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;