File indexing completed on 2024-05-12 16:40:00

0001 /* This file is part of the KDE project
0002    Copyright (C) 2014 Jarosław Staniek <staniek@kde.org>
0003 
0004    This library is free software; you can redistribute it and/or
0005    modify it under the terms of the GNU Library General Public
0006    License as published by the Free Software Foundation; either
0007    version 2 of the License, or (at your option) any later version.
0008 
0009    This library is distributed in the hope that it will be useful,
0010    but WITHOUT ANY WARRANTY; without even the implied warranty of
0011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0012    Library General Public License for more details.
0013 
0014    You should have received a copy of the GNU Library General Public License
0015    along with this library; see the file COPYING.LIB.  If not, write to
0016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0017  * Boston, MA 02110-1301, USA.
0018 */
0019 
0020 #include "KexiBugReportDialog.h"
0021 #include "KexiUserFeedbackAgent.h"
0022 #include <core/KexiMainWindowIface.h>
0023 #include <kexiutils/utils.h>
0024 #include <KexiVersion.h>
0025 
0026 #include <KAboutData>
0027 #include <KTitleWidget>
0028 #include <KLocalizedString>
0029 
0030 #include <QGridLayout>
0031 #include <QLabel>
0032 #include <QDesktopServices>
0033 #include <QUrlQuery>
0034 
0035 /*! Make a deep copy so we can modify the version.
0036  We need to override the version since it sometimes can look like
0037  "2.9 Alpha (git 4e06281 master)" what confuses the bugs.kde.org service.
0038  KEXI_VERSION_STRING returns just 2.9 Alpha */
0039 static KAboutData copyAboutDataWithFixedVersion()
0040 {
0041     KAboutData data = KAboutData::applicationData();
0042     data.setVersion(KEXI_VERSION_STRING);
0043     return data;
0044 }
0045 
0046 KexiBugReportDialog::KexiBugReportDialog(QWidget *parent)
0047  : KBugReport(copyAboutDataWithFixedVersion(), parent)
0048 {
0049     setModal(true);
0050     setWindowTitle(xi18nc("@title:window", "Report a Bug or Wish"));
0051     collectData();
0052     QWidget *title = KexiUtils::findFirstChild<QWidget*>(this, "KTitleWidget");
0053     if (title) {
0054         title->hide();
0055         QVBoxLayout* lay = qobject_cast<QVBoxLayout*>(title->layout());
0056         lay->insertSpacing(0, 6);
0057         lay->addStretch(1);
0058     }
0059     QGridLayout *glay = KexiUtils::findFirstChild<QGridLayout*>(this, "QGridLayout");
0060     if (glay) {
0061         if (glay->itemAtPosition(0, 0) && glay->itemAtPosition(0, 0)->widget()) {
0062             glay->itemAtPosition(0, 0)->widget()->hide(); // app name label
0063         }
0064         if (glay->itemAtPosition(0, 1) && glay->itemAtPosition(0, 1)->widget()) {
0065             glay->itemAtPosition(0, 1)->widget()->hide(); // app name
0066         }
0067         QLabel *lbl;
0068         if (glay->itemAtPosition(1, 0) && ((lbl = qobject_cast<QLabel*>(glay->itemAtPosition(1, 0)->widget())))) {
0069             lbl->setAlignment(Qt::AlignRight);
0070         }
0071         if (glay->itemAtPosition(2, 0) && ((lbl = qobject_cast<QLabel*>(glay->itemAtPosition(2, 0)->widget())))) {
0072             lbl->setText(xi18n("Operating system & platform:"));
0073             lbl->setAlignment(Qt::AlignRight);
0074         }
0075         if (glay->itemAtPosition(2, 1) && ((lbl = qobject_cast<QLabel*>(glay->itemAtPosition(2, 1)->widget())))) {
0076             QString op_sys = m_op_sys;
0077             QString rep_platform = m_rep_platform;
0078             if (op_sys == "other") {
0079                 op_sys = xi18nc("Other operating system", "Other");
0080             }
0081             if (rep_platform == "Other") {
0082                 rep_platform = xi18nc("Other platform", "Other");
0083             }
0084             lbl->setText(xi18nc("<operating system>, <platform>", "%1, %2", op_sys, rep_platform));
0085         }
0086         if (glay->itemAtPosition(3, 0) && glay->itemAtPosition(3, 0)->widget()) {
0087             glay->itemAtPosition(3, 0)->widget()->hide(); // compiler label
0088         }
0089         if (glay->itemAtPosition(3, 1) && glay->itemAtPosition(3, 1)->widget()) {
0090             glay->itemAtPosition(3, 1)->widget()->hide(); // compiler
0091         }
0092         glay->addItem(new QSpacerItem(1, 10), glay->count(), 0);
0093     }
0094     //! @todo KEXI3 test it
0095     setMinimumHeight(sizeHint().height()); // WORKAROUND: prevent "cropped" kcombobox
0096     adjustSize();
0097 }
0098 
0099 void KexiBugReportDialog::accept()
0100 {
0101     // override, based on KBugReport::accept()
0102     QUrl url("https://bugs.kde.org/enter_bug.cgi");
0103     QUrlQuery query;
0104     query.addQueryItem("format", "guided"); // use the guided form
0105     // the string format is product/component, where component is optional
0106     query.addQueryItem("product", "kexi");
0107     query.addQueryItem("version", KEXI_VERSION_STRING);
0108 #if 0   //! @todo add when enter_bug.cgi supports adding comments or when Kexi gets
0109     //! own Bug Report GUI and communicates using RPC.
0110     QString desc;
0111     if (0 != qstrcmp(Kexi::fullVersionString(), Kexi::versionString())) {
0112         desc += futureI18nc("Full version of Kexi app", "Full version: %1", Kexi::fullVersionString());
0113     }
0114     body += futureI18n("(filed directly from Kexi app)");
0115     query.addQueryItem("comment", m_aboutData->version());
0116 #endif
0117     query.addQueryItem("op_sys", m_op_sys);
0118     query.addQueryItem("rep_platform", m_rep_platform);
0119     url.setQuery(query);
0120     QDesktopServices::openUrl(url);
0121     QDialog::accept();
0122 }
0123 
0124 void KexiBugReportDialog::collectData()
0125 {
0126 #ifdef Q_OS_LINUX
0127     m_op_sys = "Linux";
0128     const QString linux_id = KexiMainWindowIface::global()->userFeedbackAgent()->value("linux_id").toString().toLower();
0129     const QString linux_desc = KexiMainWindowIface::global()->userFeedbackAgent()->value("linux_desc").toString().toLower();
0130     if (linux_id.contains("arch")) {
0131         m_rep_platform = "Archlinux Packages";
0132     }
0133     else if (linux_id.contains("balsam")) {
0134         m_rep_platform = "Balsam Professional";
0135     }
0136     else if (linux_id.contains("chakra")) {
0137         m_rep_platform = "Chakra";
0138     }
0139     else if (linux_id.contains("debian")) {
0140         if (linux_id.contains("unstable")) {
0141             m_rep_platform = "Debian unstable";
0142         }
0143         else if (linux_id.contains("testing")) {
0144             m_rep_platform = "Debian testing";
0145         }
0146         else {
0147             m_rep_platform = "Debian stable";
0148         }
0149     }
0150     else if (linux_id.contains("exherbo")) {
0151         m_rep_platform = "Exherbo Packages";
0152     }
0153     else if (linux_id.contains("fedora")) {
0154         m_rep_platform = "Fedora RPMs";
0155     }
0156     else if (linux_id.contains("gentoo")) {
0157         m_rep_platform = "Gentoo Packages";
0158     }
0159     else if (linux_id.contains("ubuntu")) {
0160         m_rep_platform = "Ubuntu Packages";
0161     }
0162     else if (linux_id.contains("kubuntu")) {
0163         m_rep_platform = "Kubuntu Packages";
0164     }
0165     else if (linux_id.contains("mageia")) {
0166         m_rep_platform = "Mageia RPMs";
0167     }
0168     else if (linux_id.contains("mint")) {
0169         if (linux_desc.contains("debian")) {
0170             m_rep_platform = "Mint (Debian based)";
0171         }
0172         else {
0173             m_rep_platform = "Mint (Ubuntu based)";
0174         }
0175     }
0176     else if (linux_id.contains("opensuse")) {
0177         m_rep_platform = "openSUSE RPMs";
0178     }
0179     else if (linux_id.contains("pclinuxos")) {
0180         m_rep_platform = "PCLinuxOS";
0181     }
0182     else if (linux_id.contains("redhat")) {
0183         m_rep_platform = "RedHat RPMs";
0184     }
0185     else if (linux_id.contains("slackware")) {
0186         m_rep_platform = "Slackware Packages";
0187     }
0188     else {
0189         m_rep_platform = "Other";
0190     }
0191 #elif defined(Q_OS_FREEBSD)
0192     m_op_sys = "FreeBSD";
0193     m_rep_platform = "FreeBSD Ports";
0194 #elif defined(Q_OS_NETBSD)
0195     m_op_sys = "NetBSD";
0196     m_rep_platform = "NetBSD pkgsrc";
0197 #elif defined(Q_OS_OPENBSD)
0198     m_op_sys = "OpenBSD";
0199     m_rep_platform = "OpenBSD Packages";
0200 #elif defined(Q_OS_AIX)
0201     m_op_sys = "AIX";
0202     m_rep_platform = "AIX Packages";
0203 #elif defined(Q_OS_HPUX)
0204     m_op_sys = "HP-UX";
0205     m_rep_platform = "Other";
0206 #elif defined(Q_OS_IRIX)
0207     m_op_sys = "IRIX";
0208     m_rep_platform = "Other";
0209 #elif defined(Q_OS_OSF)
0210     m_op_sys = "Tru64";
0211     m_rep_platform = "Tru64 Unix Packages";
0212 #elif defined(Q_OS_SOLARIS)
0213     m_op_sys = "Solaris";
0214     m_rep_platform = "Solaris Packages";
0215 #elif defined(Q_OS_MACOS)
0216     m_op_sys = "OS X";
0217     m_rep_platform = "Mac OS X Disk Images";
0218 #elif defined(Q_OS_WIN)
0219     m_op_sys = "MS Windows";
0220     m_rep_platform = "MS Windows";
0221 #elif defined(Q_OS_WINCE)
0222     m_op_sys = "Windows CE";
0223     m_rep_platform = "Windows CE";
0224 #elif defined(Q_OS_ANDROID)
0225     m_op_sys = "Android 4.x";
0226     m_rep_platform = "Android";
0227 #else
0228     m_op_sys = "other";
0229     m_rep_platform = "Other";
0230 #endif
0231 }