QTfrontend/ui/page/pagefeedback.cpp
changeset 8328 03684c667664
parent 8289 302a2521fe7a
child 8330 aaefa587e277
child 8383 b557c73a7593
equal deleted inserted replaced
8327:a6f3452f5f94 8328:03684c667664
    27 #include <QApplication>
    27 #include <QApplication>
    28 #include <QDesktopWidget>
    28 #include <QDesktopWidget>
    29 #include <QNetworkReply>
    29 #include <QNetworkReply>
    30 #include <QProcess>
    30 #include <QProcess>
    31 #include <QMessageBox>
    31 #include <QMessageBox>
       
    32 #include <QCheckBox>
    32 
    33 
    33 #include <string>
    34 #include <string>
    34 
    35 
    35 #ifdef Q_WS_WIN
    36 #ifdef Q_WS_WIN
    36 #define WINVER 0x0500
    37 #define WINVER 0x0500
    52 QLayout * PageFeedback::bodyLayoutDefinition()
    53 QLayout * PageFeedback::bodyLayoutDefinition()
    53 {
    54 {
    54     QVBoxLayout * pageLayout = new QVBoxLayout();
    55     QVBoxLayout * pageLayout = new QVBoxLayout();
    55     QHBoxLayout * summaryLayout = new QHBoxLayout();
    56     QHBoxLayout * summaryLayout = new QHBoxLayout();
    56     QHBoxLayout * emailLayout = new QHBoxLayout();
    57     QHBoxLayout * emailLayout = new QHBoxLayout();
       
    58     QHBoxLayout * descriptionLayout = new QHBoxLayout();
    57     QHBoxLayout * combinedTopLayout = new QHBoxLayout();
    59     QHBoxLayout * combinedTopLayout = new QHBoxLayout();
       
    60     QHBoxLayout * systemLayout = new QHBoxLayout();
    58 
    61 
    59     info = new QLabel();
    62     info = new QLabel();
    60     info->setText(
    63     info->setText(
    61         "<style type=\"text/css\">"
    64         "<style type=\"text/css\">"
    62         "a { color: #fc0; }"
    65         "a { color: #fc0; }"
    63         "b { color: #0df; }"
    66         "b { color: #0df; }"
    64         "</style>"
    67         "</style>"
    65         "<div align=\"center\"><h1>Please give us a feedback!</h1>"
    68         "<div align=\"center\"><h1>Please give us feedback!</h1>"
    66         "<h3>We are always happy about suggestions, ideas or bug reports.<h3>"
    69         "<h3>We are always happy about suggestions, ideas, or bug reports.<h3>"
    67         "<h4>The feedback will be posted as a new issue on our Google Code page.<br />"
    70         "<h4>Your email address is optional, but we may want to contact you.<h4>"
    68         "<b>Don't forget to mention your email or you won't be able to receive updates on this topic!</b><br /></h4>"
       
    69         //"<h4>Your email is optional, but if given, you will be notified of responses.<h4>"
       
    70         "</div>"
    71         "</div>"
    71     );
    72     );
    72     pageLayout->addWidget(info);
    73     pageLayout->addWidget(info);
    73 
    74 
       
    75     QVBoxLayout * summaryEmailLayout = new QVBoxLayout();
       
    76 
       
    77     const int labelWidth = 90;
       
    78 
       
    79     label_email = new QLabel();
       
    80     label_email->setText(QLabel::tr("Your Email"));
       
    81     label_email->setFixedWidth(labelWidth);
       
    82     emailLayout->addWidget(label_email);
       
    83     email = new QLineEdit();
       
    84     emailLayout->addWidget(email);
       
    85     summaryEmailLayout->addLayout(emailLayout);
       
    86     
    74     label_summary = new QLabel();
    87     label_summary = new QLabel();
    75     label_summary->setText(QLabel::tr("Summary"));
    88     label_summary->setText(QLabel::tr("Summary"));
       
    89     label_summary->setFixedWidth(labelWidth);
    76     summaryLayout->addWidget(label_summary);
    90     summaryLayout->addWidget(label_summary);
    77     summary = new QLineEdit();
    91     summary = new QLineEdit();
    78     summaryLayout->addWidget(summary);
    92     summaryLayout->addWidget(summary);
    79     combinedTopLayout->addLayout(summaryLayout);
    93     summaryEmailLayout->addLayout(summaryLayout);
    80 
       
    81     label_email = new QLabel();
       
    82     label_email->setText(QLabel::tr("Your Email"));
       
    83     emailLayout->addWidget(label_email);
       
    84     email = new QLineEdit();
       
    85     emailLayout->addWidget(email);
       
    86     
    94     
    87     //  Email -- although implemented -- doesn't seem to work as intended.
    95     combinedTopLayout->addLayout(summaryEmailLayout);
    88     //  It's sent in the XML as a <issues:cc> , the <entry>, but it doesn't seem
    96 
    89     //  to actually do anything. If you figure out how to fix that, uncomment these lines
    97 
    90     //  and the line above in the 'info' QLabel to re-enable this feature.
    98     CheckSendSpecs = new QCheckBox();
    91     //  UPDATE: I found out that CC only works if that email is a member of the
    99     CheckSendSpecs->setText(QLabel::tr("Send system information"));
    92     //  Google Code project. So this feature is pretty much useless atm.
   100     CheckSendSpecs->setChecked(true);
    93     /*
   101     systemLayout->addWidget(CheckSendSpecs);
    94     combinedTopLayout->addLayout(emailLayout);
   102     BtnViewInfo = addButton("View", systemLayout, 1, false);
    95     combinedTopLayout->insertSpacing(1, 50);
   103     BtnViewInfo->setFixedSize(60, 30);
    96     */
   104     connect(BtnViewInfo, SIGNAL(clicked()), this, SLOT(ShowSpecs()));
       
   105     combinedTopLayout->addLayout(systemLayout);
       
   106 
       
   107     combinedTopLayout->setStretch(0, 1);
       
   108     combinedTopLayout->insertSpacing(1, 20);
    97 
   109 
    98     pageLayout->addLayout(combinedTopLayout);
   110     pageLayout->addLayout(combinedTopLayout);
    99 
   111 
   100     label_description = new QLabel();
   112     label_description = new QLabel();
   101     label_description->setText(QLabel::tr("Description"));
   113     label_description->setText(QLabel::tr("Description"));
   102     pageLayout->addWidget(label_description, 0, Qt::AlignHCenter);
   114     label_description->setFixedWidth(labelWidth);
       
   115     descriptionLayout->addWidget(label_description, 0, Qt::AlignTop);
   103     description = new QTextBrowser();
   116     description = new QTextBrowser();
   104 
   117     description->setReadOnly(false);
   105     EmbedSystemInfo();
   118     descriptionLayout->addWidget(description);
       
   119     pageLayout->addLayout(descriptionLayout);
       
   120 
       
   121     return pageLayout;
       
   122 }
       
   123 
       
   124 QNetworkAccessManager * PageFeedback::GetNetManager()
       
   125 {
       
   126     if (netManager) return netManager;
       
   127     netManager = new QNetworkAccessManager(this);
       
   128     connect(netManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(NetReply(QNetworkReply*)));
       
   129     return netManager;
       
   130 }
       
   131 
       
   132 void PageFeedback::LoadCaptchaImage()
       
   133 {
       
   134         QNetworkAccessManager *netManager = GetNetManager();
       
   135         QUrl captchaURL("http://hedgewars.org/feedback/?gencaptcha");
       
   136         QNetworkRequest req(captchaURL);
       
   137         genCaptchaRequest = netManager->get(req);
       
   138 }
       
   139 
       
   140 void PageFeedback::NetReply(QNetworkReply *reply)
       
   141 {
       
   142     if (reply == genCaptchaRequest)
       
   143     {
       
   144         if (reply->error() != QNetworkReply::NoError)
       
   145         {
       
   146             qDebug() << "Error generating captcha image: " << reply->errorString();
       
   147             ShowErrorMessage(QMessageBox::tr("Failed to generate captcha"));
       
   148             return;
       
   149         }
       
   150 
       
   151         bool okay;
       
   152         QByteArray body = reply->readAll();
       
   153         captchaID = QString(body).toInt(&okay);
       
   154 
       
   155         if (!okay)
       
   156         {
       
   157             qDebug() << "Failed to get captcha ID: " << body;
       
   158             ShowErrorMessage(QMessageBox::tr("Failed to generate captcha"));
       
   159             return;
       
   160         }
       
   161 
       
   162         QString url = "http://hedgewars.org/feedback/?captcha&id=";
       
   163         url += QString::number(captchaID);
       
   164         
       
   165         QNetworkAccessManager *netManager = GetNetManager();
       
   166         QUrl captchaURL(url);
       
   167         QNetworkRequest req(captchaURL);
       
   168         captchaImageRequest = netManager->get(req);
       
   169     }
       
   170     else if (reply == captchaImageRequest)
       
   171     {
       
   172         if (reply->error() != QNetworkReply::NoError)
       
   173         {
       
   174             qDebug() << "Error loading captcha image: " << reply->errorString();
       
   175             ShowErrorMessage(QMessageBox::tr("Failed to download captcha"));
       
   176             return;
       
   177         }
       
   178 
       
   179         QByteArray imageData = reply->readAll();
       
   180         QPixmap pixmap;
       
   181         pixmap.loadFromData(imageData);
       
   182         label_captcha->setPixmap(pixmap);
       
   183         captcha_code->setText("");
       
   184     }
       
   185 }
       
   186 
       
   187 QLayout * PageFeedback::footerLayoutDefinition()
       
   188 {
       
   189     QHBoxLayout * bottomLayout = new QHBoxLayout();
       
   190     QHBoxLayout * captchaLayout = new QHBoxLayout();
       
   191     QVBoxLayout * captchaInputLayout = new QVBoxLayout();
       
   192 
       
   193     label_captcha = new QLabel();
       
   194     label_captcha->setStyleSheet("border: 3px solid #ffcc00; border-radius: 4px");
       
   195     label_captcha->setText("<div style='width: 200px; height: 100px;'>loading<br>captcha</div>");
       
   196     captchaLayout->addWidget(label_captcha);
       
   197 
       
   198     label_captcha_input = new QLabel();
       
   199     label_captcha_input->setText(QLabel::tr("Type the security code:"));
       
   200     captchaInputLayout->addWidget(label_captcha_input);
       
   201     captchaInputLayout->setAlignment(label_captcha, Qt::AlignBottom);
       
   202     captcha_code = new QLineEdit();
       
   203     captcha_code->setFixedSize(165, 30);
       
   204     captchaInputLayout->addWidget(captcha_code);
       
   205     captchaInputLayout->setAlignment(captcha_code, Qt::AlignTop);
       
   206     captchaLayout->addLayout(captchaInputLayout);
       
   207     captchaLayout->setAlignment(captchaInputLayout, Qt::AlignLeft);
       
   208 
       
   209     captchaLayout->insertSpacing(-1, 40);
       
   210     bottomLayout->addLayout(captchaLayout);
   106     
   211     
   107     description->setReadOnly(false);
   212     //TODO: create logo for send button
   108     pageLayout->addWidget(description);
   213     BtnSend = addButton("Send Feedback", bottomLayout, 0, false);
   109 
   214     BtnSend->setFixedSize(120, 40);
   110     return pageLayout;
   215 
   111 }
   216     bottomLayout->setStretchFactor(captchaLayout, 0);
   112 
   217     bottomLayout->setStretchFactor(BtnSend, 1);
   113 void PageFeedback::EmbedSystemInfo()
   218 
       
   219     return bottomLayout;
       
   220 }
       
   221 
       
   222 void PageFeedback::GenerateSpecs()
   114 {
   223 {
   115     // Gather some information about the system and embed it into the report
   224     // Gather some information about the system and embed it into the report
   116     QDesktopWidget* screen = QApplication::desktop();
   225     QDesktopWidget* screen = QApplication::desktop();
   117     QString os_version = "Operating system: ";
   226     QString os_version = "Operating system: ";
   118     QString qt_version = QString("Qt version: ") + QT_VERSION_STR + QString("\n");
   227     QString qt_version = QString("Qt version: ") + QT_VERSION_STR + QString("\n");
   241     if(sizeof(void*) == 4)
   350     if(sizeof(void*) == 4)
   242         compiler_bits += "i386\n";
   351         compiler_bits += "i386\n";
   243     else if(sizeof(void*) == 8)
   352     else if(sizeof(void*) == 8)
   244         compiler_bits += "x86_64\n";
   353         compiler_bits += "x86_64\n";
   245 
   354 
   246     // add everything to the field of text
   355     // concat system info
   247     description->setText(
   356     specs = qt_version
   248         "\n\n\n\n\n"
       
   249         "System information:\n"
       
   250         + qt_version
       
   251         + os_version
   357         + os_version
   252         + total_ram
   358         + total_ram
   253         + screen_size
   359         + screen_size
   254         + number_of_screens
   360         + number_of_screens
   255         + QString::fromStdString(processor_name + "\n")
   361         + QString::fromStdString(processor_name + "\n")
   256         + number_of_cores
   362         + number_of_cores
   257         + compiler_version
   363         + compiler_version
   258         + compiler_bits
   364         + compiler_bits
   259         + kernel_line
   365         + kernel_line;
   260     );
       
   261 }
       
   262 
       
   263 QNetworkAccessManager * PageFeedback::GetNetManager()
       
   264 {
       
   265     if (netManager) return netManager;
       
   266     netManager = new QNetworkAccessManager(this);
       
   267     connect(netManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(NetReply(QNetworkReply*)));
       
   268     return netManager;
       
   269 }
       
   270 
       
   271 void PageFeedback::LoadCaptchaImage()
       
   272 {
       
   273         QNetworkAccessManager *netManager = GetNetManager();
       
   274         QUrl captchaURL("http://hedgewars.org/feedback/?gencaptcha");
       
   275         QNetworkRequest req(captchaURL);
       
   276         genCaptchaRequest = netManager->get(req);
       
   277 }
       
   278 
       
   279 void PageFeedback::NetReply(QNetworkReply *reply)
       
   280 {
       
   281     if (reply == genCaptchaRequest)
       
   282     {
       
   283         if (reply->error() != QNetworkReply::NoError)
       
   284         {
       
   285             qDebug() << "Error generating captcha image: " << reply->errorString();
       
   286             ShowErrorMessage(QMessageBox::tr("Failed to generate captcha"));
       
   287             return;
       
   288         }
       
   289 
       
   290         bool okay;
       
   291         QByteArray body = reply->readAll();
       
   292         captchaID = QString(body).toInt(&okay);
       
   293 
       
   294         if (!okay)
       
   295         {
       
   296             qDebug() << "Failed to get captcha ID: " << body;
       
   297             ShowErrorMessage(QMessageBox::tr("Failed to generate captcha"));
       
   298             return;
       
   299         }
       
   300 
       
   301         QString url = "http://hedgewars.org/feedback/?captcha&id=";
       
   302         url += QString::number(captchaID);
       
   303         
       
   304         QNetworkAccessManager *netManager = GetNetManager();
       
   305         QUrl captchaURL(url);
       
   306         QNetworkRequest req(captchaURL);
       
   307         captchaImageRequest = netManager->get(req);
       
   308     }
       
   309     else if (reply == captchaImageRequest)
       
   310     {
       
   311         if (reply->error() != QNetworkReply::NoError)
       
   312         {
       
   313             qDebug() << "Error loading captcha image: " << reply->errorString();
       
   314             ShowErrorMessage(QMessageBox::tr("Failed to download captcha"));
       
   315             return;
       
   316         }
       
   317 
       
   318         QByteArray imageData = reply->readAll();
       
   319         QPixmap pixmap;
       
   320         pixmap.loadFromData(imageData);
       
   321         label_captcha->setPixmap(pixmap);
       
   322         captcha_code->setText("");
       
   323     }
       
   324 }
       
   325 
       
   326 QLayout * PageFeedback::footerLayoutDefinition()
       
   327 {
       
   328     QHBoxLayout * bottomLayout = new QHBoxLayout();
       
   329     QHBoxLayout * captchaLayout = new QHBoxLayout();
       
   330     QVBoxLayout * captchaInputLayout = new QVBoxLayout();
       
   331 
       
   332     label_captcha = new QLabel();
       
   333     label_captcha->setStyleSheet("border: 3px solid #ffcc00; border-radius: 4px");
       
   334     label_captcha->setText("<div style='width: 200px; height: 100px;'>loading<br>captcha</div>");
       
   335     captchaLayout->addWidget(label_captcha);
       
   336 
       
   337     label_captcha_input = new QLabel();
       
   338     label_captcha_input->setText(QLabel::tr("Type the security code:"));
       
   339     captchaInputLayout->addWidget(label_captcha_input);
       
   340     captchaInputLayout->setAlignment(label_captcha, Qt::AlignBottom);
       
   341     captcha_code = new QLineEdit();
       
   342     captcha_code->setFixedSize(165, 30);
       
   343     captchaInputLayout->addWidget(captcha_code);
       
   344     captchaInputLayout->setAlignment(captcha_code, Qt::AlignTop);
       
   345     captchaLayout->addLayout(captchaInputLayout);
       
   346     captchaLayout->setAlignment(captchaInputLayout, Qt::AlignLeft);
       
   347 
       
   348     captchaLayout->insertSpacing(-1, 40);
       
   349     bottomLayout->addLayout(captchaLayout);
       
   350     
       
   351     //TODO: create logo for send button
       
   352     BtnSend = addButton("Send Feedback", bottomLayout, 0, false);
       
   353     BtnSend->setFixedSize(120, 40);
       
   354 
       
   355     bottomLayout->setStretchFactor(captchaLayout, 0);
       
   356     bottomLayout->setStretchFactor(BtnSend, 1);
       
   357 
       
   358     return bottomLayout;
       
   359 }
   366 }
   360 
   367 
   361 void PageFeedback::connectSignals()
   368 void PageFeedback::connectSignals()
   362 {
   369 {
   363     //TODO
   370     //TODO
   371     msgMsg.setText(msg);
   378     msgMsg.setText(msg);
   372     msgMsg.setWindowModality(Qt::WindowModal);
   379     msgMsg.setWindowModality(Qt::WindowModal);
   373     msgMsg.exec();
   380     msgMsg.exec();
   374 }
   381 }
   375 
   382 
       
   383 void PageFeedback::ShowSpecs()
       
   384 {
       
   385     QMessageBox msgMsg(this);
       
   386     msgMsg.setIcon(QMessageBox::Information);
       
   387     msgMsg.setWindowTitle(QMessageBox::tr("System Information Preview"));
       
   388     msgMsg.setText(specs);
       
   389     msgMsg.setTextFormat(Qt::PlainText);
       
   390     msgMsg.setWindowModality(Qt::WindowModal);
       
   391     msgMsg.setStyleSheet("background: #0A0533;");
       
   392     msgMsg.exec();
       
   393 }
       
   394 
   376 PageFeedback::PageFeedback(QWidget* parent) : AbstractPage(parent)
   395 PageFeedback::PageFeedback(QWidget* parent) : AbstractPage(parent)
   377 {
   396 {
   378     initPage();
   397     initPage();
   379     netManager = NULL;
   398     netManager = NULL;
   380 }
   399     GenerateSpecs();
       
   400 }