Changeset View
Changeset View
Standalone View
Standalone View
src/bugzillaintegration/reportassistantpages_bugzilla.cpp
Show All 25 Lines | |||||
26 | #include <QCheckBox> | 26 | #include <QCheckBox> | ||
27 | #include <QToolTip> | 27 | #include <QToolTip> | ||
28 | #include <QCursor> | 28 | #include <QCursor> | ||
29 | #include <QFileDialog> | 29 | #include <QFileDialog> | ||
30 | #include <QTemporaryFile> | 30 | #include <QTemporaryFile> | ||
31 | #include <QTextBrowser> | 31 | #include <QTextBrowser> | ||
32 | #include <QDesktopServices> | 32 | #include <QDesktopServices> | ||
33 | 33 | | |||
34 | | ||||
35 | #include "drkonqi_debug.h" | 34 | #include "drkonqi_debug.h" | ||
36 | #include <KMessageBox> | 35 | #include <KMessageBox> | ||
37 | #include <KLocalizedString> | 36 | #include <KLocalizedString> | ||
38 | #include <kwallet.h> | 37 | #include <kwallet.h> | ||
39 | #include <KCapacityBar> | 38 | #include <KCapacityBar> | ||
40 | 39 | | |||
41 | /* Unhandled error dialog includes */ | 40 | /* Unhandled error dialog includes */ | ||
42 | #include <KIO/Job> | 41 | #include <KIO/Job> | ||
▲ Show 20 Lines • Show All 285 Lines • ▼ Show 20 Line(s) | 320 | { | |||
328 | } | 327 | } | ||
329 | } | 328 | } | ||
330 | 329 | | |||
331 | //END BugzillaLoginPage | 330 | //END BugzillaLoginPage | ||
332 | 331 | | |||
333 | //BEGIN BugzillaInformationPage | 332 | //BEGIN BugzillaInformationPage | ||
334 | 333 | | |||
335 | BugzillaInformationPage::BugzillaInformationPage(ReportAssistantDialog * parent) | 334 | BugzillaInformationPage::BugzillaInformationPage(ReportAssistantDialog * parent) | ||
336 | : ReportAssistantPage(parent), | 335 | : ReportAssistantPage(parent) | ||
337 | m_textsOK(false), m_distributionComboSetup(false), m_distroComboVisible(false), | 336 | , m_textsOK(false) | ||
338 | m_requiredCharacters(1) | 337 | , m_requiredCharacters(1) | ||
339 | { | 338 | { | ||
340 | ui.setupUi(this); | 339 | ui.setupUi(this); | ||
340 | | ||||
341 | m_textCompleteBar = new KCapacityBar(KCapacityBar::DrawTextInline, this); | 341 | m_textCompleteBar = new KCapacityBar(KCapacityBar::DrawTextInline, this); | ||
342 | ui.horizontalLayout_2->addWidget(m_textCompleteBar); | 342 | ui.horizontalLayout_2->addWidget(m_textCompleteBar); | ||
343 | 343 | | |||
344 | connect(ui.m_titleEdit, &KLineEdit::textChanged, this, &BugzillaInformationPage::checkTexts); | 344 | connect(ui.m_titleEdit, &KLineEdit::textChanged, this, &BugzillaInformationPage::checkTexts); | ||
345 | connect(ui.m_detailsEdit, &QTextEdit::textChanged, this, &BugzillaInformationPage::checkTexts); | 345 | connect(ui.m_detailsEdit, &QTextEdit::textChanged, this, &BugzillaInformationPage::checkTexts); | ||
346 | 346 | | |||
347 | connect(ui.m_titleLabel, &QLabel::linkActivated, this, &BugzillaInformationPage::showTitleExamples); | 347 | connect(ui.m_titleLabel, &QLabel::linkActivated, this, &BugzillaInformationPage::showTitleExamples); | ||
348 | connect(ui.m_detailsLabel, &QLabel::linkActivated, this, &BugzillaInformationPage::showDescriptionHelpExamples); | 348 | connect(ui.m_detailsLabel, &QLabel::linkActivated, this, &BugzillaInformationPage::showDescriptionHelpExamples); | ||
349 | 349 | | |||
350 | ui.m_compiledSourcesCheckBox->setChecked( | 350 | ui.m_compiledSourcesCheckBox->setChecked(DrKonqi::systemInformation()->compiledSources()); | ||
351 | DrKonqi::systemInformation()->compiledSources()); | | |||
352 | 351 | | |||
352 | ui.m_messageWidget->setVisible(false); | ||||
353 | auto retryAction = new QAction(QIcon::fromTheme(QStringLiteral("view-refresh")), | ||||
354 | i18nc("@action/button retry button in error widget", | ||||
355 | "Retry"), | ||||
356 | ui.m_messageWidget); | ||||
357 | connect(retryAction, &QAction::triggered, | ||||
358 | this, [this, retryAction]{ | ||||
359 | ui.m_messageWidget->animatedHide(); | ||||
360 | loadDistroCombo(); | ||||
361 | }); | ||||
362 | ui.m_messageWidget->addAction(retryAction); | ||||
363 | | ||||
364 | loadDistroCombo(); | ||||
353 | } | 365 | } | ||
354 | 366 | | |||
355 | void BugzillaInformationPage::aboutToShow() | 367 | void BugzillaInformationPage::aboutToShow() | ||
356 | { | 368 | { | ||
357 | if (!m_distributionComboSetup) { | | |||
358 | //Autodetecting distro failed ? | | |||
359 | if (DrKonqi::systemInformation()->bugzillaPlatform() == QLatin1String("unspecified")) { | | |||
360 | m_distroComboVisible = true; | | |||
361 | ui.m_distroChooserCombo->addItem(i18nc("@label:listbox KDE distribution method", | | |||
362 | "Unspecified"),QStringLiteral("unspecified")); | | |||
363 | ui.m_distroChooserCombo->addItem(i18nc("@label:listbox KDE distribution method", | | |||
364 | "Archlinux"), QStringLiteral("Archlinux Packages")); | | |||
365 | ui.m_distroChooserCombo->addItem(i18nc("@label:listbox KDE distribution method", | | |||
366 | "Chakra"), QStringLiteral("Chakra")); | | |||
367 | ui.m_distroChooserCombo->addItem(i18nc("@label:listbox KDE distribution method", | | |||
368 | "Debian stable"), QStringLiteral("Debian stable")); | | |||
369 | ui.m_distroChooserCombo->addItem(i18nc("@label:listbox KDE distribution method", | | |||
370 | "Debian testing"), QStringLiteral("Debian testing")); | | |||
371 | ui.m_distroChooserCombo->addItem(i18nc("@label:listbox KDE distribution method", | | |||
372 | "Debian unstable"), QStringLiteral("Debian unstable")); | | |||
373 | ui.m_distroChooserCombo->addItem(i18nc("@label:listbox KDE distribution method", | | |||
374 | "Exherbo"), QStringLiteral("Exherbo Packages")); | | |||
375 | ui.m_distroChooserCombo->addItem(i18nc("@label:listbox KDE distribution method", | | |||
376 | "Fedora"), QStringLiteral("Fedora RPMs")); | | |||
377 | ui.m_distroChooserCombo->addItem(i18nc("@label:listbox KDE distribution method", | | |||
378 | "Gentoo"), QStringLiteral("Gentoo Packages")); | | |||
379 | ui.m_distroChooserCombo->addItem(i18nc("@label:listbox KDE distribution method", | | |||
380 | "Mageia"), QStringLiteral("Mageia RPMs")); | | |||
381 | ui.m_distroChooserCombo->addItem(i18nc("@label:listbox KDE distribution method", | | |||
382 | "Mandriva"), QStringLiteral("Mandriva RPMs")); | | |||
383 | ui.m_distroChooserCombo->addItem(i18nc("@label:listbox KDE distribution method", | | |||
384 | "Neon"), QStringLiteral("Neon Packages")); | | |||
385 | ui.m_distroChooserCombo->addItem(i18nc("@label:listbox KDE distribution method", | | |||
386 | "OpenSUSE"), QStringLiteral("openSUSE RPMs")); | | |||
387 | ui.m_distroChooserCombo->addItem(i18nc("@label:listbox KDE distribution method", | | |||
388 | "Pardus"), QStringLiteral("Pardus Packages")); | | |||
389 | ui.m_distroChooserCombo->addItem(i18nc("@label:listbox KDE distribution method", | | |||
390 | "RedHat"), QStringLiteral("RedHat RPMs")); | | |||
391 | ui.m_distroChooserCombo->addItem(i18nc("@label:listbox KDE distribution method", | | |||
392 | "Slackware"), QStringLiteral("Slackware Packages")); | | |||
393 | ui.m_distroChooserCombo->addItem(i18nc("@label:listbox KDE distribution method", | | |||
394 | "Ubuntu (and derivatives)"), | | |||
395 | QStringLiteral("Ubuntu Packages")); | | |||
396 | ui.m_distroChooserCombo->addItem(i18nc("@label:listbox KDE distribution method", | | |||
397 | "FreeBSD (Ports)"), QStringLiteral("FreeBSD Ports")); | | |||
398 | ui.m_distroChooserCombo->addItem(i18nc("@label:listbox KDE distribution method", | | |||
399 | "NetBSD (pkgsrc)"), QStringLiteral("NetBSD pkgsrc")); | | |||
400 | ui.m_distroChooserCombo->addItem(i18nc("@label:listbox KDE distribution method", | | |||
401 | "OpenBSD"), QStringLiteral("OpenBSD Packages")); | | |||
402 | ui.m_distroChooserCombo->addItem(i18nc("@label:listbox KDE distribution method", | | |||
403 | "Mac OS X"), QStringLiteral("MacPorts Packages")); | | |||
404 | ui.m_distroChooserCombo->addItem(i18nc("@label:listbox KDE distribution method", | | |||
405 | "Solaris"), QStringLiteral("Solaris Packages")); | | |||
406 | | ||||
407 | //Restore previously selected bugzilla platform (distribution) | | |||
408 | KConfigGroup config(KSharedConfig::openConfig(), "BugzillaInformationPage"); | | |||
409 | QString entry = config.readEntry("BugzillaPlatform","unspecified"); | | |||
410 | int index = ui.m_distroChooserCombo->findData(entry); | | |||
411 | if ( index == -1 ) index = 0; | | |||
412 | ui.m_distroChooserCombo->setCurrentIndex(index); | | |||
413 | } else { | | |||
414 | ui.m_distroChooserCombo->setVisible(false); | | |||
415 | } | | |||
416 | m_distributionComboSetup = true; | | |||
417 | } | | |||
418 | | ||||
419 | //Calculate the minimum number of characters required for a description | 369 | //Calculate the minimum number of characters required for a description | ||
420 | //If creating a new report: minimum 40, maximum 80 | 370 | //If creating a new report: minimum 40, maximum 80 | ||
421 | //If attaching to an existent report: minimum 30, maximum 50 | 371 | //If attaching to an existent report: minimum 30, maximum 50 | ||
422 | int multiplier = (reportInterface()->attachToBugNumber() == 0) ? 10 : 5; | 372 | int multiplier = (reportInterface()->attachToBugNumber() == 0) ? 10 : 5; | ||
423 | m_requiredCharacters = 20 + (reportInterface()->selectedOptionsRating() * multiplier); | 373 | m_requiredCharacters = 20 + (reportInterface()->selectedOptionsRating() * multiplier); | ||
424 | 374 | | |||
425 | //Fill the description textedit with some headings: | 375 | //Fill the description textedit with some headings: | ||
426 | QString descriptionTemplate; | 376 | QString descriptionTemplate; | ||
▲ Show 20 Lines • Show All 53 Lines • ▼ Show 20 Line(s) | 410 | { | |||
480 | m_textCompleteBar->setText(message); | 430 | m_textCompleteBar->setText(message); | ||
481 | 431 | | |||
482 | if (ok != m_textsOK) { | 432 | if (ok != m_textsOK) { | ||
483 | m_textsOK = ok; | 433 | m_textsOK = ok; | ||
484 | emitCompleteChanged(); | 434 | emitCompleteChanged(); | ||
485 | } | 435 | } | ||
486 | } | 436 | } | ||
487 | 437 | | |||
438 | void BugzillaInformationPage::loadDistroCombo() | ||||
439 | { | ||||
440 | // Alway have at least unspecified otherwise bugzilla would get to decide | ||||
441 | // the platform and that would likely be index=0 which is compiledfromsource | ||||
442 | ui.m_distroChooserCombo->addItem(QStringLiteral("unspecified")); | ||||
443 | | ||||
444 | Bugzilla::BugFieldClient client; | ||||
445 | auto job = client.getField(QStringLiteral("rep_platform")); | ||||
446 | connect(job, &KJob::finished, this, [this, &client](KJob *job) { | ||||
447 | try { | ||||
448 | Bugzilla::BugField::Ptr field = client.getField(job); | ||||
449 | if (!field) { | ||||
450 | // This is a bit flimsy but only acts as save guard. | ||||
451 | // Ideally this code path is never hit. | ||||
452 | throw Bugzilla::RuntimeException(i18nc("@info/status error", | ||||
453 | "Failed to get platform list")); | ||||
454 | } | ||||
455 | setDistros(field); | ||||
456 | } catch (Bugzilla::Exception &e) { | ||||
457 | qCWarning(DRKONQI_LOG) << e.whatString(); | ||||
458 | setDistroComboError(e.whatString()); | ||||
459 | } | ||||
460 | }); | ||||
461 | } | ||||
462 | | ||||
463 | void BugzillaInformationPage::setDistros(const Bugzilla::BugField::Ptr &field) | ||||
464 | { | ||||
465 | ui.m_distroChooserCombo->clear(); | ||||
466 | for (const auto &distro : field->values()) { | ||||
467 | ui.m_distroChooserCombo->addItem(distro->name()); | ||||
468 | } | ||||
469 | | ||||
470 | int index = 0; | ||||
471 | bool autoDetected = false; | ||||
472 | | ||||
473 | const QString detectedPlatform = DrKonqi::systemInformation()->bugzillaPlatform(); | ||||
474 | if (detectedPlatform != QLatin1String("unspecified")) { | ||||
475 | index = ui.m_distroChooserCombo->findText(detectedPlatform); | ||||
476 | if (index >= 0) { | ||||
477 | autoDetected = true; | ||||
478 | } | ||||
479 | } else { | ||||
480 | // Restore previously selected bugzilla platform (distribution) | ||||
481 | KConfigGroup config(KSharedConfig::openConfig(), "BugzillaInformationPage"); | ||||
482 | const QString entry = config.readEntry("BugzillaPlatform", "unspecified"); | ||||
483 | index = ui.m_distroChooserCombo->findText(entry); | ||||
484 | } | ||||
485 | | ||||
486 | if (index < 0) { // failed to restore value | ||||
487 | index = ui.m_distroChooserCombo->findText(QStringLiteral("unspecified")); | ||||
488 | } | ||||
489 | if (index < 0) { // also failed to find unspecified... shouldn't happen | ||||
490 | index = 0; | ||||
491 | } | ||||
492 | | ||||
493 | ui.m_distroChooserCombo->setCurrentIndex(index); | ||||
494 | ui.m_distroChooserCombo->setVisible(autoDetected); | ||||
495 | ui.m_distroChooserCombo->setDisabled(false); | ||||
496 | } | ||||
497 | | ||||
498 | void BugzillaInformationPage::setDistroComboError(const QString &error) | ||||
499 | { | ||||
500 | // NB: not being able to resolve the platform isn't a blocking issue. | ||||
501 | // You can still file a report, it'll simply default to unspecified. | ||||
502 | | ||||
503 | ui.m_messageWidget->setText(i18nc("@info error when talking to the bugzilla API", | ||||
504 | "An error occured when talking to bugs.kde.org: %1", | ||||
505 | error)); | ||||
506 | ui.m_messageWidget->animatedShow(); | ||||
507 | | ||||
508 | ui.m_distroChooserCombo->setVisible(true); | ||||
509 | ui.m_distroChooserCombo->setDisabled(true); | ||||
510 | } | ||||
511 | | ||||
488 | bool BugzillaInformationPage::showNextPage() | 512 | bool BugzillaInformationPage::showNextPage() | ||
489 | { | 513 | { | ||
490 | checkTexts(); | 514 | checkTexts(); | ||
491 | 515 | | |||
492 | if (m_textsOK) { | 516 | if (m_textsOK) { | ||
493 | bool detailsShort = currentDescriptionCharactersCount() < m_requiredCharacters; | 517 | bool detailsShort = currentDescriptionCharactersCount() < m_requiredCharacters; | ||
494 | 518 | | |||
495 | if (detailsShort) { | 519 | if (detailsShort) { | ||
▲ Show 20 Lines • Show All 45 Lines • ▼ Show 20 Line(s) | |||||
541 | } | 565 | } | ||
542 | 566 | | |||
543 | void BugzillaInformationPage::aboutToHide() | 567 | void BugzillaInformationPage::aboutToHide() | ||
544 | { | 568 | { | ||
545 | //Save fields data | 569 | //Save fields data | ||
546 | reportInterface()->setTitle(ui.m_titleEdit->text()); | 570 | reportInterface()->setTitle(ui.m_titleEdit->text()); | ||
547 | reportInterface()->setDetailText(ui.m_detailsEdit->toPlainText()); | 571 | reportInterface()->setDetailText(ui.m_detailsEdit->toPlainText()); | ||
548 | 572 | | |||
549 | if (m_distroComboVisible) { | 573 | if (ui.m_distroChooserCombo->isVisible()) { | ||
550 | //Save bugzilla platform (distribution) | 574 | //Save bugzilla platform (distribution) | ||
551 | QString bugzillaPlatform = ui.m_distroChooserCombo->itemData( | 575 | QString bugzillaPlatform = ui.m_distroChooserCombo->itemData( | ||
552 | ui.m_distroChooserCombo->currentIndex()).toString(); | 576 | ui.m_distroChooserCombo->currentIndex()).toString(); | ||
553 | KConfigGroup config(KSharedConfig::openConfig(), "BugzillaInformationPage"); | 577 | KConfigGroup config(KSharedConfig::openConfig(), "BugzillaInformationPage"); | ||
554 | config.writeEntry("BugzillaPlatform", bugzillaPlatform); | 578 | config.writeEntry("BugzillaPlatform", bugzillaPlatform); | ||
555 | DrKonqi::systemInformation()->setBugzillaPlatform(bugzillaPlatform); | 579 | DrKonqi::systemInformation()->setBugzillaPlatform(bugzillaPlatform); | ||
556 | } | 580 | } | ||
557 | bool compiledFromSources = ui.m_compiledSourcesCheckBox->checkState() == Qt::Checked; | 581 | bool compiledFromSources = ui.m_compiledSourcesCheckBox->checkState() == Qt::Checked; | ||
558 | DrKonqi::systemInformation()->setCompiledSources(compiledFromSources); | 582 | DrKonqi::systemInformation()->setCompiledSources(compiledFromSources); | ||
559 | | ||||
560 | } | 583 | } | ||
561 | 584 | | |||
562 | void BugzillaInformationPage::showTitleExamples() | 585 | void BugzillaInformationPage::showTitleExamples() | ||
563 | { | 586 | { | ||
564 | QString titleExamples = xi18nc("@info:tooltip examples of good bug report titles", | 587 | QString titleExamples = xi18nc("@info:tooltip examples of good bug report titles", | ||
565 | "<strong>Examples of good titles:</strong><nl />\"Plasma crashed after adding the Notes " | 588 | "<strong>Examples of good titles:</strong><nl />\"Plasma crashed after adding the Notes " | ||
566 | "widget and writing on it\"<nl />\"Konqueror crashed when accessing the Facebook " | 589 | "widget and writing on it\"<nl />\"Konqueror crashed when accessing the Facebook " | ||
567 | "application 'X'\"<nl />\"Kopete suddenly closed after resuming the computer and " | 590 | "application 'X'\"<nl />\"Kopete suddenly closed after resuming the computer and " | ||
▲ Show 20 Lines • Show All 181 Lines • Show Last 20 Lines |