QTfrontend/hwform.cpp
branchflibqtfrontend
changeset 8269 c71721d371dc
parent 8267 9cf64a5c3445
child 8280 734b069a418e
child 8284 a874d00df4a4
equal deleted inserted replaced
8267:9cf64a5c3445 8269:c71721d371dc
   679 
   679 
   680     if (id == ID_PAGE_MAIN)
   680     if (id == ID_PAGE_MAIN)
   681     {
   681     {
   682         ui.pageOptions->setTeamOptionsEnabled(true);
   682         ui.pageOptions->setTeamOptionsEnabled(true);
   683     }
   683     }
       
   684 
       
   685     if (id == ID_PAGE_FEEDBACK)
       
   686     {
       
   687         ui.pageFeedback->LoadCaptchaImage();
       
   688     }
   684 }
   689 }
   685 
   690 
   686 void HWForm::GoToPage(int id)
   691 void HWForm::GoToPage(int id)
   687 {
   692 {
   688     bool stopAnim = false;
   693     bool stopAnim = false;
  1851     {
  1856     {
  1852         ShowErrorMessage(QMessageBox::tr("Please fill out all fields"));
  1857         ShowErrorMessage(QMessageBox::tr("Please fill out all fields"));
  1853         return;
  1858         return;
  1854     }
  1859     }
  1855 
  1860 
  1856     //Google login using fake account (feedback.hedgewars@gmail.com)
  1861     //Submit issue to PHP script
       
  1862     QString source = "HedgewarsFoundation-Hedgewars-";
       
  1863     source += (cVersionString?(*cVersionString):QString(""));
       
  1864     QString captchaCode = ui.pageFeedback->captcha_code->text();
       
  1865     QString captchaID = QString::number(ui.pageFeedback->captchaID);
       
  1866     
       
  1867     QByteArray body;
       
  1868     body.append("captcha=");
       
  1869     body.append(captchaID);
       
  1870     body.append("&code=");
       
  1871     body.append(captchaCode);
       
  1872     body.append("&source=");
       
  1873     body.append(source);
       
  1874     body.append("&issue=");
       
  1875     body.append(QUrl::toPercentEncoding(issueXml));
       
  1876     
  1857     nam = new QNetworkAccessManager(this);
  1877     nam = new QNetworkAccessManager(this);
  1858     connect(nam, SIGNAL(finished(QNetworkReply*)),
  1878     connect(nam, SIGNAL(finished(QNetworkReply*)),
  1859             this, SLOT(finishedSlot(QNetworkReply*)));
  1879             this, SLOT(finishedSlot(QNetworkReply*)));
  1860 
  1880             
  1861     QUrl url(QString("https://www.google.com/accounts/ClientLogin?"
  1881     QNetworkRequest header(QUrl("http://hedgewars.org/feedback/?submit"));
  1862                      "accountType=GOOGLE&Email=feedback.hedgewars@gmail.com&Passwd=hwfeedback&service=code&source=HedgewarsFoundation-Hedgewars-")
  1882     header.setRawHeader("Content-Length", QString::number(body.size()).toAscii());
  1863                     + (cVersionString?(*cVersionString):QString("")));
  1883     
  1864     nam->get(QNetworkRequest(url));
  1884     nam->post(header, body);
  1865 
       
  1866 }
  1885 }
  1867 
  1886 
  1868 bool HWForm::CreateIssueXml()
  1887 bool HWForm::CreateIssueXml()
  1869 {
  1888 {
  1870     QString summary = ui.pageFeedback->summary->text();
  1889     QString summary = ui.pageFeedback->summary->text();
  1871     QString description = ui.pageFeedback->description->toPlainText();
  1890     QString description = ui.pageFeedback->description->toPlainText();
       
  1891     QString email = ui.pageFeedback->email->text();
  1872 
  1892 
  1873     //Check if all necessary information is entered
  1893     //Check if all necessary information is entered
  1874     if (summary.isEmpty() || description.isEmpty())
  1894     if (summary.isEmpty() || description.isEmpty())
  1875         return false;
  1895         return false;
  1876 
  1896 
  1879         "<entry xmlns='http://www.w3.org/2005/Atom' xmlns:issues='http://code.google.com/p/hedgewars/issues/list'>"
  1899         "<entry xmlns='http://www.w3.org/2005/Atom' xmlns:issues='http://code.google.com/p/hedgewars/issues/list'>"
  1880         "<title>";
  1900         "<title>";
  1881     issueXml.append(summary);
  1901     issueXml.append(summary);
  1882     issueXml.append("</title><content type='html'>");
  1902     issueXml.append("</title><content type='html'>");
  1883     issueXml.append(description);
  1903     issueXml.append(description);
  1884     issueXml.append("</content><author><name>feedback.hedgewars</name></author></entry>");
  1904     issueXml.append("</content><author><name>feedback.hedgewars</name></author>");
       
  1905 
       
  1906     if (!email.isEmpty())
       
  1907     {
       
  1908         issueXml.append("<issues:owner><issues:username>");
       
  1909         issueXml.append(email);
       
  1910         issueXml.append("</issues:username></issues:owner>");
       
  1911         issueXml.append("<issues:cc><issues:username>");
       
  1912         issueXml.append(email);
       
  1913         issueXml.append("</issues:username></issues:cc>");
       
  1914     }
       
  1915 
       
  1916     issueXml.append("</entry>");
  1885 
  1917 
  1886     return true;
  1918     return true;
  1887 }
  1919 }
  1888 
  1920 
  1889 void HWForm::finishedSlot(QNetworkReply* reply)
  1921 void HWForm::finishedSlot(QNetworkReply* reply)
  1890 {
  1922 {
  1891     if (reply && reply->error() == QNetworkReply::NoError)
  1923     if (reply && reply->error() == QNetworkReply::NoError)
  1892     {
  1924     {
  1893         QByteArray array = reply->readAll();
       
  1894         QString str(array);
       
  1895 
       
  1896         if (authToken.length() != 0)
       
  1897         {
       
  1898 
       
  1899             QMessageBox infoMsg(this);
  1925             QMessageBox infoMsg(this);
  1900             infoMsg.setIcon(QMessageBox::Information);
  1926             infoMsg.setIcon(QMessageBox::Information);
  1901             infoMsg.setWindowTitle(QMessageBox::tr("Hedgewars - Success"));
  1927             infoMsg.setWindowTitle(QMessageBox::tr("Hedgewars - Success"));
  1902             infoMsg.setText(QMessageBox::tr("Successfully posted the issue on hedgewars.googlecode.com"));
  1928             infoMsg.setText(QMessageBox::tr("Successfully posted the issue on hedgewars.googlecode.com"));
  1903             infoMsg.setWindowModality(Qt::WindowModal);
  1929             infoMsg.setWindowModality(Qt::WindowModal);
  1904             infoMsg.exec();
  1930             infoMsg.exec();
  1905 
  1931 
  1906             ui.pageFeedback->summary->clear();
  1932             ui.pageFeedback->summary->clear();
  1907             ui.pageFeedback->description->clear();
  1933             ui.pageFeedback->description->clear();
  1908             authToken = "";
  1934             ui.pageFeedback->EmbedSystemInfo();
       
  1935             ui.pageFeedback->LoadCaptchaImage();
       
  1936             
  1909             return;
  1937             return;
  1910         }
  1938     }
  1911 
       
  1912         if (!getAuthToken(str))
       
  1913         {
       
  1914             ShowErrorMessage(QMessageBox::tr("Error during authentication at google.com"));
       
  1915             return;
       
  1916         }
       
  1917 
       
  1918         QByteArray body(issueXml.toUtf8());
       
  1919         QNetworkRequest header(QUrl("https://code.google.com/feeds/issues/p/hedgewars/issues/full"));
       
  1920         header.setRawHeader("Content-Length", QString::number(issueXml.length()).toAscii());
       
  1921         header.setRawHeader("Content-Type", "application/atom+xml");
       
  1922         header.setRawHeader("Authorization", QString("GoogleLogin auth=%1").arg(authToken).toUtf8());
       
  1923         nam->post(header, body);
       
  1924 
       
  1925     }
       
  1926     else if (authToken.length() == 0)
       
  1927         ShowErrorMessage(QMessageBox::tr("Error during authentication at google.com"));
       
  1928     else
  1939     else
  1929     {
  1940     {
  1930         ShowErrorMessage(QMessageBox::tr("Error reporting the issue, please try again later (or visit hedgewars.googlecode.com directly)"));
  1941         ShowErrorMessage(QString("Error: ") + reply->readAll());
  1931         authToken = "";
  1942         ui.pageFeedback->LoadCaptchaImage();
  1932     }
  1943     }
  1933 
  1944 }
  1934 }
  1945 
  1935 
       
  1936 bool HWForm::getAuthToken(QString str)
       
  1937 {
       
  1938     QRegExp ex("Auth=(.+)");
       
  1939 
       
  1940     if (-1 == ex.indexIn(str))
       
  1941         return false;
       
  1942 
       
  1943     authToken = ex.cap(1);
       
  1944     authToken.remove(QChar('\n'));
       
  1945 
       
  1946     return true;
       
  1947 }
       
  1948 
       
  1949 
       
  1950