source: src-qt4/pc-sysmanager/pbsystemtab.cpp @ 1c0e4984

enter/10releng/10.0releng/10.0.1releng/10.0.2releng/10.0.3releng/10.1releng/10.1.1releng/10.1.2releng/10.2stable/10
Last change on this file since 1c0e4984 was 1c0e4984, checked in by Ken Moore <ken@…>, 20 months ago

Clean up a lot of the built-up kruft in the main system manager UI from the very old days.

  • Property mode set to 100644
File size: 7.7 KB
Line 
1/****************************************************************************
2** ui.h extension file, included from the uic-generated form implementation.
3**
4** If you want to add, delete, or rename functions or slots, use
5** Qt Designer to update this file, preserving your code.
6**
7** You should not define a constructor or destructor in this file.
8** Instead, write your code in functions called init() and destroy().
9** These will automatically be called by the form's constructor and
10** destructor.
11*****************************************************************************/
12#include <qstring.h>
13#include <pcbsd-utils.h>
14#include <qfiledialog.h>
15#include <QTextStream>
16#include <QNetworkAccessManager>
17#include <QNetworkReply>
18#include <QNetworkProxy>
19#include <QProgressDialog>
20#include <QDebug>
21#include "../config.h"
22
23#include "pbsystemtab.h"
24
25void PBSystemTab::ProgramInit()
26{
27    //Grab the username
28    username = QString::fromLocal8Bit(getenv("SUDO_USER")); //since the app is always run as root with sudo
29    if(username.isEmpty()){ username = QString::fromLocal8Bit(getenv("LOGNAME")); } //in case SUDO_USER is not set
30    //qDebug() << "Username:" << username;
31    // Set the Uname on the General Tab
32    CheckUname();
33    // Set the PC-BSD Version on the General Tab
34    CheckPBVer();
35
36    //Get & Set CPU Type
37    labelCPU->setText(pcbsd::Utils::sysctl("hw.model").simplified());
38   
39    //Get & Set RAM
40    labelMemory->setText(pcbsd::Utils::bytesToHumanReadable(pcbsd::Utils::sysctlAsInt("hw.physmem")));
41
42    //Load Misc tab data
43    loadMiscData();
44
45
46    // Connect our various buttons
47    connect(buttonGenerate, SIGNAL(clicked()), this, SLOT(startGenerateSheet()) );
48
49    connect(pushMiscSave, SIGNAL( clicked() ), this, SLOT( slotMiscSave() ) );
50
51    connect(fetchSourceBut, SIGNAL( clicked() ), this, SLOT( fetchSourcePressed() ) );
52    connect(fetchPortsBut, SIGNAL( clicked() ), this, SLOT( fetchPortsPressed() ) );
53   
54    cmdDlg = new CMDDialog(this);
55    cmdDlg->hide();
56}
57
58void PBSystemTab::CheckUname()
59{
60        QString line = Backend::shortCMD("","uname -rm").join("").simplified();
61        labelBASEVer->setText( line );
62        //Save the output version/architecture internally
63        Version= line.section(" ",0,0);
64        Arch = line.section(" ",1,1);
65}
66
67
68void PBSystemTab::CheckPBVer()
69{
70 
71  //Get pcbsd-base version
72  QString base = pcbsd::Utils::runShellCommand("pkg info -f pcbsd-base").filter("Version").join("").section(":",1,1).simplified();
73  if(base.isEmpty()){ base ="UNKNOWN"; }
74  label_pcbsdbase->setText(base);
75  //Get pcbsd-utils version
76  QString utils = pcbsd::Utils::runShellCommand("pkg info -f pcbsd-utils").filter("Version").join("").section(":",1,1).simplified();
77  if(utils.isEmpty()){ utils ="UNKNOWN"; }
78  label_pcbsdutils->setText(utils);
79  //Get pcbsd-utils-qt4 version
80  QString utilsqt4 = pcbsd::Utils::runShellCommand("pkg info -f pcbsd-utils-qt4").filter("Version").join("").section(":",1,1).simplified();
81  if(utilsqt4.isEmpty()){ utilsqt4 ="UNKNOWN"; }
82  label_pcbsdgutils->setText(utilsqt4);
83
84}
85
86// Ask user where to save text file, then start the generation
87void PBSystemTab::startGenerateSheet()
88{
89    SheetFileName="";
90        SheetFileName = QFileDialog::getSaveFileName(
91                    this,
92                    "save file dialog",
93                    "/home/" + username + "/Desktop/systemDiagnostic.txt",
94                    "Text File (*.txt)");
95       
96      if ( ! SheetFileName.isEmpty() ){
97        if ( !SheetFileName.endsWith(".txt") ){ SheetFileName.append(".txt");  }
98        if ( QFile::exists(SheetFileName ) ){
99            int answer = QMessageBox::warning( this, "Overwrite File", "Overwrite " + SheetFileName + "?", "&Yes", "&No", QString::null, 1, 1 );
100                   if ( answer == 0 ) {
101              CreateSheetFile();               
102            }
103        } else {
104            CreateSheetFile(); 
105        }
106     }
107       
108}
109
110void PBSystemTab::CreateSheetFile()
111{
112        qDebug() << "Generating System Diagnostic Sheet";
113        SheetGenScript = new QProcess( this );
114        QString prog = PREFIX + "/share/pcbsd/scripts/GenDiagSheet.sh";
115        QStringList args;
116        args << SheetFileName;
117        args << username;
118        //qDebug() << "CMD: " << prog+" "+args.join(" ");
119        connect( SheetGenScript, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(finishedSheet()) );
120               
121        SheetGenScript->start(prog, args);
122}
123
124void PBSystemTab::finishedSheet()
125{
126        int exitcode = SheetGenScript->exitCode();
127        qDebug() << "Diagnostic Sheet Return Code:" << QString::number(exitcode);
128        if(exitcode != 0 || !QFile::exists(SheetFileName) ){
129          QMessageBox::warning(this, tr("Error"), tr("Error Generating Diagnostic File"));
130        }else{
131          QMessageBox::information(this, tr("Success"), QString(tr("Diagnostic File Created: %1")).arg(SheetFileName));
132        }
133               
134}
135
136void PBSystemTab::showRebootRequired()
137{
138    QMessageBox::information( this, "PC-BSD Notification",
139    "Settings Updated!\n You must reboot for changes to take effect!" );
140}
141
142// Checks the file for a string KEY, and sees if its set to VALUE
143bool PBSystemTab::checkValue( QString File, QString Key, QString Value )
144{
145    QString theValue = pcbsd::Utils::getConfFileValue(File, Key);
146    if (theValue == Value) {
147        return TRUE;
148    }
149    return FALSE;
150   
151}
152
153void PBSystemTab::fetchSourcePressed()
154{
155    if(cmdDlg->isRunning() ){
156      QMessageBox::warning(this, tr("Process Already Running"), tr("You already have a process running. Please wait for that one to finish first.") );
157    }else{
158      //Get the current version branch of the source tree
159      QString version = pcbsd::Utils::runShellCommand("uname -r").join(" ");
160      QString branch;
161      if(version.contains("RELEASE")){ branch = "releng/"+version.section("-",0,0).simplified(); }
162      else if(version.contains("STABLE")){ branch = "stable/"+version.section("-",0,0).section(".",0,0).simplified(); }
163      else{ branch = "master"; } //CURRENT
164     
165      cmdDlg->start("source", branch); //Version not implemented yet
166      cmdDlg->show();
167    }
168}
169
170void PBSystemTab::fetchPortsPressed()
171{
172    if(cmdDlg->isRunning() ){
173      QMessageBox::warning(this, tr("Process Already Running"), tr("You already have a process running. Please wait for that one to finish first.") );
174    }else{
175      cmdDlg->start("ports"); //Version not implemented yet
176      cmdDlg->show();
177    }
178}
179
180
181void PBSystemTab::loadMiscData()
182{
183    // Load the default package set value
184    if ( pcbsd::Utils::getValFromPCBSDConf("PACKAGE_SET") == "EDGE" ) {
185       radioEdge->setChecked(true);
186       radioProduction->setChecked(false);
187    } else {
188       radioProduction->setChecked(true);
189       radioEdge->setChecked(false);
190    }
191    //Check if IBUS input is forced
192    if ( pcbsd::Utils::getConfFileValue(QString(PREFIX + "/share/pcbsd/xstartup/enable-ibus.sh"), QString("FORCEIBUS=") ) == QString("YES")){
193        checkForceIbus->setChecked(TRUE);
194    }else{
195        checkForceIbus->setChecked(FALSE);
196    }
197}
198
199void PBSystemTab::slotMiscSave() {
200     //Save IBUS setting
201     if ( checkForceIbus->isChecked() ){
202        pcbsd::Utils::setConfFileValue(PREFIX + "/share/pcbsd/xstartup/enable-ibus.sh", "FORCEIBUS", "FORCEIBUS=\"YES\"", 1);
203     }else{
204        pcbsd::Utils::setConfFileValue(PREFIX + "/share/pcbsd/xstartup/enable-ibus.sh", "FORCEIBUS", "FORCEIBUS=\"NO\"", 1);
205     }
206
207    // Save package set
208    if ( radioProduction->isChecked() )
209      pcbsd::Utils::setValPCBSDConf("PACKAGE_SET", "PRODUCTION");
210    else
211      pcbsd::Utils::setValPCBSDConf("PACKAGE_SET", "EDGE");
212
213    // Extract the ports overlay to grab a new package set repo config
214    QProcess::execute(QString("pc-extractoverlay"), QStringList() << "ports");
215}
216
217void PBSystemTab::slotClose() {
218    close();
219}
220
221void PBSystemTab::changeOpenTab(int tab)
222{
223   tabWidget->setCurrentIndex(tab);
224}
225
226void PBSystemTab::closeEvent(QCloseEvent *event){
227    if(cmdDlg->isRunning()){
228      //Process Running - minimize the main window instead
229      event->ignore();
230      this->showMinimized();
231    }
232}
Note: See TracBrowser for help on using the repository browser.