QTfrontend/ui/page/pagefeedback.cpp
changeset 8268 fe4e94311585
parent 8258 c14b27abe452
child 8270 16a52ad5a362
equal deleted inserted replaced
8266:927da572bcdc 8268:fe4e94311585
    18 
    18 
    19 #include <QHBoxLayout>
    19 #include <QHBoxLayout>
    20 #include <QLineEdit>
    20 #include <QLineEdit>
    21 #include <QTextBrowser>
    21 #include <QTextBrowser>
    22 #include <QLabel>
    22 #include <QLabel>
       
    23 #include <QHttp>
    23 #include <QSysInfo>
    24 #include <QSysInfo>
       
    25 #include <QDebug>
       
    26 #include <QBuffer>
    24 #include <QApplication>
    27 #include <QApplication>
    25 #include <QDesktopWidget>
    28 #include <QDesktopWidget>
       
    29 #include <QNetworkReply>
    26 #include <QProcess>
    30 #include <QProcess>
       
    31 #include <QMessageBox>
    27 
    32 
    28 #include <string>
    33 #include <string>
    29 
    34 
    30 #ifdef Q_WS_WIN
    35 #ifdef Q_WS_WIN
    31 #define WINVER 0x0500
    36 #define WINVER 0x0500
    46 
    51 
    47 QLayout * PageFeedback::bodyLayoutDefinition()
    52 QLayout * PageFeedback::bodyLayoutDefinition()
    48 {
    53 {
    49     QVBoxLayout * pageLayout = new QVBoxLayout();
    54     QVBoxLayout * pageLayout = new QVBoxLayout();
    50     QHBoxLayout * summaryLayout = new QHBoxLayout();
    55     QHBoxLayout * summaryLayout = new QHBoxLayout();
       
    56     QHBoxLayout * emailLayout = new QHBoxLayout();
       
    57     QHBoxLayout * combinedTopLayout = new QHBoxLayout();
    51 
    58 
    52     info = new QLabel();
    59     info = new QLabel();
    53     info->setText(
    60     info->setText(
    54         "<style type=\"text/css\">"
    61         "<style type=\"text/css\">"
    55         "a { color: #ffcc00; }"
    62         "a { color: #ffcc00; }"
    56         "</style>"
    63         "</style>"
    57         "<div align=\"center\"><h1>Please give us a feedback!</h1>"
    64         "<div align=\"center\"><h1>Please give us a feedback!</h1>"
    58         "<h3>We are always happy about suggestions, ideas or bug reports.<h3>"
    65         "<h3>We are always happy about suggestions, ideas or bug reports.<h3>"
    59         "<h4>The feedback will be posted as a new issue on our Google Code page.<h4>"
    66         "<h4>The feedback will be posted as a new issue on our Google Code page.<h4>"
       
    67         //"<h4>Your email is optional, but if given, you will be notified of responses.<h4>"
    60         "</div>"
    68         "</div>"
    61     );
    69     );
    62     pageLayout->addWidget(info);
    70     pageLayout->addWidget(info);
    63 
    71 
    64     label_summary = new QLabel();
    72     label_summary = new QLabel();
    65     label_summary->setText(QLabel::tr("Summary   "));
    73     label_summary->setText(QLabel::tr("Summary"));
    66     summaryLayout->addWidget(label_summary);
    74     summaryLayout->addWidget(label_summary);
    67     summary = new QLineEdit();
    75     summary = new QLineEdit();
    68     summaryLayout->addWidget(summary);
    76     summaryLayout->addWidget(summary);
    69     pageLayout->addLayout(summaryLayout);
    77     combinedTopLayout->addLayout(summaryLayout);
       
    78 
       
    79     label_email = new QLabel();
       
    80     label_email->setText(QLabel::tr("Your Email"));
       
    81     emailLayout->addWidget(label_email);
       
    82     email = new QLineEdit();
       
    83     emailLayout->addWidget(email);
       
    84     
       
    85     //  Email -- although implemented -- doesn't seem to work as intended.
       
    86     //  It's sent in the XML as a <issues:cc> , the <entry>, but it doesn't seem
       
    87     //  to actually do anything. If you figure out how to fix that, uncomment these lines
       
    88     //  and the line above in the 'info' QLabel to re-enable this feature.
       
    89     //combinedTopLayout->addLayout(emailLayout);
       
    90     //combinedTopLayout->insertSpacing(1, 50);
       
    91 
       
    92     pageLayout->addLayout(combinedTopLayout);
    70 
    93 
    71     label_description = new QLabel();
    94     label_description = new QLabel();
    72     label_description->setText(QLabel::tr("Description"));
    95     label_description->setText(QLabel::tr("Description"));
    73     pageLayout->addWidget(label_description, 0, Qt::AlignHCenter);
    96     pageLayout->addWidget(label_description, 0, Qt::AlignHCenter);
    74     description = new QTextBrowser();
    97     description = new QTextBrowser();
    75 
    98 
       
    99     EmbedSystemInfo();
       
   100     
       
   101     description->setReadOnly(false);
       
   102     pageLayout->addWidget(description);
       
   103 
       
   104     return pageLayout;
       
   105 }
       
   106 
       
   107 void PageFeedback::EmbedSystemInfo()
       
   108 {
    76     // Gather some information about the system and embed it into the report
   109     // Gather some information about the system and embed it into the report
    77     QDesktopWidget* screen = QApplication::desktop();
   110     QDesktopWidget* screen = QApplication::desktop();
    78     QString os_version = "Operating system: ";
   111     QString os_version = "Operating system: ";
    79     QString qt_version = QString("Qt version: ") + QT_VERSION_STR + QString("\n");
   112     QString qt_version = QString("Qt version: ") + QT_VERSION_STR + QString("\n");
    80     QString total_ram = "Total RAM: ";
   113     QString total_ram = "Total RAM: ";
   221         + number_of_cores
   254         + number_of_cores
   222         + compiler_version
   255         + compiler_version
   223         + compiler_bits
   256         + compiler_bits
   224         + kernel_line
   257         + kernel_line
   225     );
   258     );
   226     description->setReadOnly(false);
   259 }
   227     pageLayout->addWidget(description);
   260 
   228 
   261 QNetworkAccessManager * PageFeedback::GetNetManager()
   229     return pageLayout;
   262 {
       
   263     if (netManager) return netManager;
       
   264     netManager = new QNetworkAccessManager(this);
       
   265     connect(netManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(NetReply(QNetworkReply*)));
       
   266     return netManager;
       
   267 }
       
   268 
       
   269 void PageFeedback::LoadCaptchaImage()
       
   270 {
       
   271         QNetworkAccessManager *netManager = GetNetManager();
       
   272         QUrl captchaURL("http://hedgewars.org/feedback/?gencaptcha");
       
   273         QNetworkRequest req(captchaURL);
       
   274         genCaptchaRequest = netManager->get(req);
       
   275 }
       
   276 
       
   277 void PageFeedback::NetReply(QNetworkReply *reply)
       
   278 {
       
   279     if (reply == genCaptchaRequest)
       
   280     {
       
   281         if (reply->error() != QNetworkReply::NoError)
       
   282         {
       
   283             qDebug() << "Error generating captcha image: " << reply->errorString();
       
   284             ShowErrorMessage(QMessageBox::tr("Failed to generate captcha"));
       
   285             return;
       
   286         }
       
   287 
       
   288         bool okay;
       
   289         QByteArray body = reply->readAll();
       
   290         captchaID = QString(body).toInt(&okay);
       
   291 
       
   292         if (!okay)
       
   293         {
       
   294             qDebug() << "Failed to get captcha ID: " << body;
       
   295             ShowErrorMessage(QMessageBox::tr("Failed to generate captcha"));
       
   296             return;
       
   297         }
       
   298 
       
   299         QString url = "http://hedgewars.org/feedback/?captcha&id=";
       
   300         url += QString::number(captchaID);
       
   301         
       
   302         QNetworkAccessManager *netManager = GetNetManager();
       
   303         QUrl captchaURL(url);
       
   304         QNetworkRequest req(captchaURL);
       
   305         captchaImageRequest = netManager->get(req);
       
   306     }
       
   307     else if (reply == captchaImageRequest)
       
   308     {
       
   309         if (reply->error() != QNetworkReply::NoError)
       
   310         {
       
   311             qDebug() << "Error loading captcha image: " << reply->errorString();
       
   312             ShowErrorMessage(QMessageBox::tr("Failed to download captcha"));
       
   313             return;
       
   314         }
       
   315 
       
   316         QByteArray imageData = reply->readAll();
       
   317         QPixmap pixmap;
       
   318         pixmap.loadFromData(imageData);
       
   319         label_captcha->setPixmap(pixmap);
       
   320         captcha_code->setText("");
       
   321     }
   230 }
   322 }
   231 
   323 
   232 QLayout * PageFeedback::footerLayoutDefinition()
   324 QLayout * PageFeedback::footerLayoutDefinition()
   233 {
   325 {
   234     QHBoxLayout * bottomLayout = new QHBoxLayout();
   326     QHBoxLayout * bottomLayout = new QHBoxLayout();
   235 
   327     QHBoxLayout * captchaLayout = new QHBoxLayout();
   236     bottomLayout->setStretch(0,1);
   328     QVBoxLayout * captchaInputLayout = new QVBoxLayout();
       
   329 
       
   330     label_captcha = new QLabel();
       
   331     label_captcha->setStyleSheet("border: 3px solid #ffcc00; border-radius: 4px");
       
   332     label_captcha->setText("<div style='width: 200px; height: 100px;'>loading<br>captcha</div>");
       
   333     captchaLayout->addWidget(label_captcha);
       
   334 
       
   335     label_captcha_input = new QLabel();
       
   336     label_captcha_input->setText(QLabel::tr("Type the security code:"));
       
   337     captchaInputLayout->addWidget(label_captcha_input);
       
   338     captchaInputLayout->setAlignment(label_captcha, Qt::AlignBottom);
       
   339     captcha_code = new QLineEdit();
       
   340     captcha_code->setFixedSize(165, 30);
       
   341     captchaInputLayout->addWidget(captcha_code);
       
   342     captchaInputLayout->setAlignment(captcha_code, Qt::AlignTop);
       
   343     captchaLayout->addLayout(captchaInputLayout);
       
   344     captchaLayout->setAlignment(captchaInputLayout, Qt::AlignLeft);
       
   345 
       
   346     captchaLayout->insertSpacing(-1, 40);
       
   347     bottomLayout->addLayout(captchaLayout);
       
   348     
   237     //TODO: create logo for send button
   349     //TODO: create logo for send button
   238     BtnSend = addButton("Send", bottomLayout, 0, false);
   350     BtnSend = addButton("Send Feedback", bottomLayout, 0, false);
   239     bottomLayout->insertStretch(0);
   351     BtnSend->setFixedSize(120, 40);
       
   352 
       
   353     bottomLayout->setStretchFactor(captchaLayout, 0);
       
   354     bottomLayout->setStretchFactor(BtnSend, 1);
   240 
   355 
   241     return bottomLayout;
   356     return bottomLayout;
   242 }
   357 }
   243 
   358 
   244 void PageFeedback::connectSignals()
   359 void PageFeedback::connectSignals()
   245 {
   360 {
   246     //TODO
   361     //TODO
   247 }
   362 }
   248 
   363 
       
   364 void PageFeedback::ShowErrorMessage(const QString & msg)
       
   365 {
       
   366     QMessageBox msgMsg(this);
       
   367     msgMsg.setIcon(QMessageBox::Warning);
       
   368     msgMsg.setWindowTitle(QMessageBox::tr("Hedgewars - Error"));
       
   369     msgMsg.setText(msg);
       
   370     msgMsg.setWindowModality(Qt::WindowModal);
       
   371     msgMsg.exec();
       
   372 }
       
   373 
   249 PageFeedback::PageFeedback(QWidget* parent) : AbstractPage(parent)
   374 PageFeedback::PageFeedback(QWidget* parent) : AbstractPage(parent)
   250 {
   375 {
   251     initPage();
   376     initPage();
   252 
   377     netManager = NULL;
   253 }
   378 }