source: src-qt4/pc-bugreport/toolbox.cpp @ e9e7e28

releng/10.0.1releng/10.0.2
Last change on this file since e9e7e28 was e9e7e28, checked in by Ken Moore <ken@…>, 6 months ago

Finish cleaning up the diagnostic sheet generation for pc-bugreport: completely works now.

  • Property mode set to 100644
File size: 3.2 KB
Line 
1#include "toolbox.h"
2#include "ui_toolbox.h"
3#include "showinfodialog.h"
4
5#include <QFile>
6#include <QDir>
7#include <QProcess>
8#include <QDate>
9#include <QDebug>
10#include <QMessageBox>
11
12#define PREFIX "/usr/local/"
13static const QString KSANPSHOT_FILE(PREFIX"bin/ksnapshot");
14static const QString GNOME_PANEL_SCREENSHOT_FILE(PREFIX"bin/gnome-panel-screenshot");
15
16Toolbox::Toolbox(QWidget *parent) :
17    QWidget(parent),
18    ui(new Ui::Toolbox)
19{
20    ui->setupUi(this);
21
22        ui->LogsButton->addAction(ui->actionDiagnostic_report);
23        ui->LogsButton->addAction(ui->actionUname);
24        ui->LogsButton->addAction(ui->actionDmesg);
25        ui->LogsButton->addAction(ui->actionXorg_version);
26        ui->LogsButton->addAction(ui->actionXorg_log_file);
27
28        ui->HardwareButton->addAction(ui->actionPCIConf);
29
30        // Setup screenshot button. Check for present screenshot tools
31        ui->ScreenshotButton->setVisible(false);
32        if (QFile::exists(KSANPSHOT_FILE))
33        {
34                mScreenshotCommand= KSANPSHOT_FILE;
35                ui->ScreenshotButton->setVisible(true);
36        }
37        else if (QFile::exists(GNOME_PANEL_SCREENSHOT_FILE))
38        {
39                mScreenshotCommand= GNOME_PANEL_SCREENSHOT_FILE;
40                ui->ScreenshotButton->setVisible(true);
41        }
42}
43
44Toolbox::~Toolbox()
45{
46    delete ui;
47}
48
49void Toolbox::changeEvent(QEvent *e)
50{
51    QWidget::changeEvent(e);
52    switch (e->type()) {
53    case QEvent::LanguageChange:
54        ui->retranslateUi(this);
55        break;
56    default:
57        break;
58    }
59}
60
61void Toolbox::on_actionXorg_log_file_triggered()
62{
63        ShowInfoDialog* dlg = new ShowInfoDialog(this);
64        dlg->show(QString("/var/log/Xorg.0.log"));
65}
66
67void Toolbox::on_actionDmesg_triggered()
68{
69        ShowInfoDialog* dlg = new ShowInfoDialog(this);
70        dlg->show("dmesg", QStringList());
71}
72
73void Toolbox::on_actionDiagnostic_report_triggered()
74{
75        qDebug() << "Generate Diagnostic Sheet";
76        //Generate the diagnostic file on the user desktop
77        QString filename = QDir::homePath()+"/Desktop/diagnostic-"+QDate::currentDate().toString("yyyyMMdd")+".txt";
78        QString username = getenv("LOGNAME");
79        QString cmd = "/usr/local/share/pcbsd/scripts/GenDiagSheet.sh "+filename+" "+username;
80        QProcess p;
81        p.setProcessEnvironment(QProcessEnvironment::systemEnvironment());
82        //qDebug() << " - cmd:" << cmd;
83        if(QFile::exists(filename)){ QFile::remove(filename); } //remove any old file first
84        p.start(cmd);
85        while(p.waitForFinished(200)){
86          QApplication::processEvents();
87        }
88        if(QFile::exists(filename)){
89          qDebug() << " - success";
90          //Now show the info dialog for the newly generated diagnostic file
91          ShowInfoDialog *dlg = new ShowInfoDialog(this);
92          dlg->show(filename);
93        }else{
94          qDebug() << " - failure";
95          QMessageBox::warning(this, tr("Failure"), tr("Failed to create diagnostic sheet"));
96        }
97}
98
99void Toolbox::on_actionPCIConf_triggered()
100{
101        ShowInfoDialog* dlg = new ShowInfoDialog(this);
102        dlg->show("pciconf", QStringList()<<"-l"<<"-v");
103}
104
105void Toolbox::on_ScreenshotButton_clicked()
106{
107        if (mScreenshotCommand.length())
108        {
109                QProcess proc;
110                proc.startDetached(mScreenshotCommand);
111        }
112}
113
114void Toolbox::on_actionXorg_version_triggered()
115{
116        ShowInfoDialog* dlg = new ShowInfoDialog(this);
117        dlg->show("Xorg", QStringList()<<"-version");
118}
119
120void Toolbox::on_actionUname_triggered()
121{
122        ShowInfoDialog* dlg = new ShowInfoDialog(this);
123        dlg->show("uname", QStringList()<<"-a");
124}
Note: See TracBrowser for help on using the repository browser.