QTfrontend/ui/widget/feedbackdialog.cpp
changeset 8434 4821897a0f10
parent 8389 6d65ed1f832c
child 8595 d2940421d3d4
equal deleted inserted replaced
8432:f2d57e987ba9 8434:4821897a0f10
    51 #include "hwconsts.h"
    51 #include "hwconsts.h"
    52 #include "feedbackdialog.h"
    52 #include "feedbackdialog.h"
    53 
    53 
    54 FeedbackDialog::FeedbackDialog(QWidget * parent) : QDialog(parent)
    54 FeedbackDialog::FeedbackDialog(QWidget * parent) : QDialog(parent)
    55 {
    55 {
    56 	setModal(true);
    56     setModal(true);
    57 	setWindowFlags(Qt::Sheet);
    57     setWindowFlags(Qt::Sheet);
    58 	setWindowModality(Qt::WindowModal);
    58     setWindowModality(Qt::WindowModal);
    59 	setMinimumSize(700, 460);
    59     setMinimumSize(700, 460);
    60 	resize(700, 460);
    60     resize(700, 460);
    61 	setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
    61     setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
    62 
    62 
    63 	netManager = NULL;
    63     netManager = NULL;
    64 	GenerateSpecs();
    64     GenerateSpecs();
    65 
    65 
    66 	/* Top layout */
    66     /* Top layout */
    67 
    67 
    68 	QVBoxLayout * pageLayout = new QVBoxLayout();
    68     QVBoxLayout * pageLayout = new QVBoxLayout();
    69     QHBoxLayout * summaryLayout = new QHBoxLayout();
    69     QHBoxLayout * summaryLayout = new QHBoxLayout();
    70     QHBoxLayout * emailLayout = new QHBoxLayout();
    70     QHBoxLayout * emailLayout = new QHBoxLayout();
    71     QHBoxLayout * descriptionLayout = new QHBoxLayout();
    71     QHBoxLayout * descriptionLayout = new QHBoxLayout();
    72     QHBoxLayout * combinedTopLayout = new QHBoxLayout();
    72     QHBoxLayout * combinedTopLayout = new QHBoxLayout();
    73     QHBoxLayout * systemLayout = new QHBoxLayout();
    73     QHBoxLayout * systemLayout = new QHBoxLayout();
    94     label_email->setFixedWidth(labelWidth);
    94     label_email->setFixedWidth(labelWidth);
    95     emailLayout->addWidget(label_email);
    95     emailLayout->addWidget(label_email);
    96     email = new QLineEdit();
    96     email = new QLineEdit();
    97     emailLayout->addWidget(email);
    97     emailLayout->addWidget(email);
    98     summaryEmailLayout->addLayout(emailLayout);
    98     summaryEmailLayout->addLayout(emailLayout);
    99     
    99 
   100     label_summary = new QLabel();
   100     label_summary = new QLabel();
   101     label_summary->setText(QLabel::tr("Summary"));
   101     label_summary->setText(QLabel::tr("Summary"));
   102     label_summary->setFixedWidth(labelWidth);
   102     label_summary->setFixedWidth(labelWidth);
   103     summaryLayout->addWidget(label_summary);
   103     summaryLayout->addWidget(label_summary);
   104     summary = new QLineEdit();
   104     summary = new QLineEdit();
   105     summaryLayout->addWidget(summary);
   105     summaryLayout->addWidget(summary);
   106     summaryEmailLayout->addLayout(summaryLayout);
   106     summaryEmailLayout->addLayout(summaryLayout);
   107     
   107 
   108     combinedTopLayout->addLayout(summaryEmailLayout);
   108     combinedTopLayout->addLayout(summaryEmailLayout);
   109 
   109 
   110     CheckSendSpecs = new QCheckBox();
   110     CheckSendSpecs = new QCheckBox();
   111     CheckSendSpecs->setText(QLabel::tr("Send system information"));
   111     CheckSendSpecs->setText(QLabel::tr("Send system information"));
   112     CheckSendSpecs->setChecked(true);
   112     CheckSendSpecs->setChecked(true);
   161     captchaLayout->addLayout(captchaInputLayout);
   161     captchaLayout->addLayout(captchaInputLayout);
   162     captchaLayout->setAlignment(captchaInputLayout, Qt::AlignLeft);
   162     captchaLayout->setAlignment(captchaInputLayout, Qt::AlignLeft);
   163 
   163 
   164     bottomLayout->addLayout(captchaLayout);
   164     bottomLayout->addLayout(captchaLayout);
   165     bottomLayout->addSpacing(40);
   165     bottomLayout->addSpacing(40);
   166     
   166 
   167     // TODO: Set green arrow icon for send button (:/res/Start.png)
   167     // TODO: Set green arrow icon for send button (:/res/Start.png)
   168     BtnSend = new QPushButton(tr("Send Feedback"));
   168     BtnSend = new QPushButton(tr("Send Feedback"));
   169     bottomLayout->addWidget(BtnSend, 0);
   169     bottomLayout->addWidget(BtnSend, 0);
   170     BtnSend->setFixedSize(120, 40);
   170     BtnSend->setFixedSize(120, 40);
   171     connect(BtnSend, SIGNAL(clicked()), this, SLOT(SendFeedback()));
   171     connect(BtnSend, SIGNAL(clicked()), this, SLOT(SendFeedback()));
   371             return;
   371             return;
   372         }
   372         }
   373 
   373 
   374         QString url = "http://hedgewars.org/feedback/?captcha&id=";
   374         QString url = "http://hedgewars.org/feedback/?captcha&id=";
   375         url += QString::number(captchaID);
   375         url += QString::number(captchaID);
   376         
   376 
   377         QNetworkAccessManager *netManager = GetNetManager();
   377         QNetworkAccessManager *netManager = GetNetManager();
   378         QUrl captchaURL(url);
   378         QUrl captchaURL(url);
   379         QNetworkRequest req(captchaURL);
   379         QNetworkRequest req(captchaURL);
   380         captchaImageRequest = netManager->get(req);
   380         captchaImageRequest = netManager->get(req);
   381     }
   381     }
   422             infoMsg.setText(reply->readAll());
   422             infoMsg.setText(reply->readAll());
   423             infoMsg.setWindowModality(Qt::WindowModal);
   423             infoMsg.setWindowModality(Qt::WindowModal);
   424             infoMsg.exec();
   424             infoMsg.exec();
   425 
   425 
   426             accept();
   426             accept();
   427             
   427 
   428             return;
   428             return;
   429     }
   429     }
   430     else
   430     else
   431     {
   431     {
   432         ShowErrorMessage(QString("Error: ") + reply->readAll());
   432         ShowErrorMessage(QString("Error: ") + reply->readAll());
   435 }
   435 }
   436 
   436 
   437 void FeedbackDialog::SendFeedback()
   437 void FeedbackDialog::SendFeedback()
   438 {
   438 {
   439     // Get form data
   439     // Get form data
   440     
   440 
   441     QString summary = this->summary->text();
   441     QString summary = this->summary->text();
   442     QString description = this->description->toPlainText();
   442     QString description = this->description->toPlainText();
   443     QString email = this->email->text();
   443     QString email = this->email->text();
   444     QString captchaCode = this->captcha_code->text();
   444     QString captchaCode = this->captcha_code->text();
   445     QString captchaID = QString::number(this->captchaID);
   445     QString captchaID = QString::number(this->captchaID);
   450         ShowErrorMessage(QMessageBox::tr("Please fill out all fields. Email is optional."));
   450         ShowErrorMessage(QMessageBox::tr("Please fill out all fields. Email is optional."));
   451         return;
   451         return;
   452     }
   452     }
   453 
   453 
   454     // Submit issue to PHP script
   454     // Submit issue to PHP script
   455     
   455 
   456     QByteArray body;
   456     QByteArray body;
   457     body.append("captcha=");
   457     body.append("captcha=");
   458     body.append(captchaID);
   458     body.append(captchaID);
   459     body.append("&code=");
   459     body.append("&code=");
   460     body.append(captchaCode);
   460     body.append(captchaCode);
   469     if (CheckSendSpecs->isChecked())
   469     if (CheckSendSpecs->isChecked())
   470     {
   470     {
   471         body.append("&specs=");
   471         body.append("&specs=");
   472         body.append(QUrl::toPercentEncoding(specs));
   472         body.append(QUrl::toPercentEncoding(specs));
   473     }
   473     }
   474     
   474 
   475     nam = new QNetworkAccessManager(this);
   475     nam = new QNetworkAccessManager(this);
   476     connect(nam, SIGNAL(finished(QNetworkReply*)),
   476     connect(nam, SIGNAL(finished(QNetworkReply*)),
   477             this, SLOT(finishedSlot(QNetworkReply*)));
   477             this, SLOT(finishedSlot(QNetworkReply*)));
   478             
   478 
   479     QNetworkRequest header(QUrl("http://hedgewars.org/feedback/?submit"));
   479     QNetworkRequest header(QUrl("http://hedgewars.org/feedback/?submit"));
   480     header.setRawHeader("Content-Length", QString::number(body.size()).toAscii());
   480     header.setRawHeader("Content-Length", QString::number(body.size()).toAscii());
   481     header.setRawHeader("Content-Type", "application/x-www-form-urlencoded");
   481     header.setRawHeader("Content-Type", "application/x-www-form-urlencoded");
   482     
   482 
   483     nam->post(header, body);
   483     nam->post(header, body);
   484 }
   484 }