source: src-qt4/pc-sysmanager/pbsystemtab.cpp @ 7cd7e8f

enter/10releng/10.0releng/10.0.1releng/10.0.2releng/10.0.3releng/10.1releng/10.1.1releng/10.1.2
Last change on this file since 7cd7e8f was 7cd7e8f, checked in by Ken Moore <ken@…>, 17 months ago

Fix up the system diagnostic output and make sure that it lists any pcbsd-* packages that are installed on the system (with version numbers).

  • Property mode set to 100644
File size: 10.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"));
29    qDebug() << "Username:" << username;
30    // Set the Uname on the General Tab
31    CheckUname();
32    // Set the PC-BSD Version on the General Tab
33    CheckPBVer();
34
35    // See if we need to setup a proxy
36    checkProxy();
37   
38    //Get & Set CPU Type
39    labelCPU->setText(pcbsd::Utils::sysctl("hw.model").simplified());
40   
41    //Get & Set RAM
42    labelMemory->setText(pcbsd::Utils::bytesToHumanReadable(pcbsd::Utils::sysctlAsInt("hw.physmem")));
43   
44    // Read any kernel settings
45    //LoadKernSettings();
46
47    // Read any rc.conf settings
48    //loadServSettings();
49
50    //Load boot screen data
51    loadBootData();
52
53    // Load the default package set value
54    if ( pcbsd::Utils::getValFromPCBSDConf("PACKAGE_SET") == "EDGE" ) {
55       radioEdge->setChecked(true);
56       radioProduction->setChecked(false);
57    } else {
58       radioProduction->setChecked(true);
59       radioEdge->setChecked(false);
60    }
61
62    // Connect our various buttons
63    connect(buttonGenerate, SIGNAL(clicked()), this, SLOT(startGenerateSheet()) );
64    //connect(showBootCheck, SIGNAL(clicked()), this, SIGNAL(changed()));
65
66    connect(pushMiscSave, SIGNAL( clicked() ), this, SLOT( slotMiscSave() ) );
67
68    connect(fetchSourceBut, SIGNAL( clicked() ), this, SLOT( fetchSourcePressed() ) );
69    connect(fetchPortsBut, SIGNAL( clicked() ), this, SLOT( fetchPortsPressed() ) );
70}
71
72void PBSystemTab::CheckUname()
73{
74        QString prog = "uname";
75        QStringList args; 
76        args << "-rm"; 
77               
78        GetUname = new QProcess( this );
79        connect( GetUname, SIGNAL(readyReadStandardOutput()), this, SLOT(ReadUname()) );
80        GetUname->start(prog, args);
81}
82
83
84void PBSystemTab::CheckPBVer()
85{
86 
87  //Get pcbsd-base version
88  QString base = pcbsd::Utils::runShellCommand("pkg info -f pcbsd-base").filter("Version").join("").section(":",1,1).simplified();
89  if(base.isEmpty()){ base ="UNKNOWN"; }
90  label_pcbsdbase->setText(base);
91  //Get pcbsd-utils version
92  QString utils = pcbsd::Utils::runShellCommand("pkg info -f pcbsd-utils").filter("Version").join("").section(":",1,1).simplified();
93  if(utils.isEmpty()){ utils ="UNKNOWN"; }
94  label_pcbsdutils->setText(utils);
95  //Get pcbsd-utils-qt4 version
96  QString utilsqt4 = pcbsd::Utils::runShellCommand("pkg info -f pcbsd-utils-qt4").filter("Version").join("").section(":",1,1).simplified();
97  if(utilsqt4.isEmpty()){ utilsqt4 ="UNKNOWN"; }
98  label_pcbsdgutils->setText(utilsqt4);
99
100  //Save the system architecture internally
101 Arch = getLineFromCommandOutput("uname -m");
102 
103}
104
105
106void PBSystemTab::ReadUname()
107{   
108    if (GetUname->canReadLine() )
109    {
110        QString uname = GetUname->readLine().simplified();
111        labelBASEVer->setText( uname );
112        Version= uname.section(" ",0,0);
113    }
114}
115
116
117// Ask user where to save text file, then start the generation
118void PBSystemTab::startGenerateSheet()
119{
120    SheetFileName="";
121        SheetFileName = QFileDialog::getSaveFileName(
122                    this,
123                    "save file dialog",
124                    "/home/" + username + "/Desktop/systemDiagnostic.txt",
125                    "Text File (*.txt)");
126       
127      if ( ! SheetFileName.isEmpty() ){
128        if ( !SheetFileName.endsWith(".txt") ){ SheetFileName.append(".txt");  }
129        if ( QFile::exists(SheetFileName ) ){
130            int answer = QMessageBox::warning( this, "Overwrite File", "Overwrite " + SheetFileName + "?", "&Yes", "&No", QString::null, 1, 1 );
131                   if ( answer == 0 ) {
132              CreateSheetFile();               
133            }
134        } else {
135            CreateSheetFile(); 
136        }
137     }
138       
139}
140
141
142void PBSystemTab::CreateSheetFile()
143{
144        qDebug() << "Generating System Diagnostic Sheet";
145        SheetGenScript = new QProcess( this );
146        QString prog = PREFIX + "/share/pcbsd/scripts/GenDiagSheet.sh";
147        QStringList args;
148        args << SheetFileName;
149        args << username;
150        qDebug() << "CMD: " << prog+" "+args.join(" ");
151        connect( SheetGenScript, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(finishedSheet()) );
152               
153        SheetGenScript->start(prog, args);
154}
155
156
157void PBSystemTab::finishedSheet()
158{
159        int exitcode = SheetGenScript->exitCode();
160        qDebug() << "Diagnostic Sheet Return Code:" << QString::number(exitcode);
161        if(exitcode != 0 || !QFile::exists(SheetFileName) ){
162          QMessageBox::warning(this, tr("Error"), tr("Error Generating Diagnostic File"));
163        }else{
164          QMessageBox::information(this, tr("Success"), QString(tr("Diagnostic File Created: %1")).arg(SheetFileName));
165        }
166               
167}
168
169
170void PBSystemTab::saveKernScreen()
171{
172     if ( checkForceIbus->isChecked() )
173                pcbsd::Utils::setConfFileValue(PREFIX + "/share/pcbsd/xstartup/enable-ibus.sh", "FORCEIBUS", "FORCEIBUS=\"YES\"", 1);
174     else
175                pcbsd::Utils::setConfFileValue(PREFIX + "/share/pcbsd/xstartup/enable-ibus.sh", "FORCEIBUS", "FORCEIBUS=\"NO\"", 1);
176
177}
178
179
180
181void PBSystemTab::showRebootRequired()
182{
183    QMessageBox::information( this, "PC-BSD Notification",
184    "Settings Updated!\n You must reboot for changes to take effect!" );
185}
186
187
188// Read the loader.conf, and load any settings we need
189/*void PBSystemTab::LoadKernSettings()
190{
191    if ( checkValue("/boot/loader.conf", "splash_pcx_load=", "YES" ) ) { showBootCheck->setChecked(true); }
192    else { showBootCheck->setChecked(false); }
193}
194*/
195// Checks the file for a string KEY, and sees if its set to VALUE
196bool PBSystemTab::checkValue( QString File, QString Key, QString Value )
197{
198    QString theValue = pcbsd::Utils::getConfFileValue(File, Key);
199    if (theValue == Value) {
200        return TRUE;
201    }
202    return FALSE;
203   
204}
205
206void PBSystemTab::fetchSourcePressed()
207{
208    portsnapUI = new CMDDialog(this);
209    portsnapUI->start("source"); //Version not implemented yet
210    portsnapUI->show();
211}
212
213void PBSystemTab::fetchPortsPressed()
214{
215    portsnapUI = new CMDDialog(this);
216    portsnapUI->start("ports"); //Version not implemented yet
217    portsnapUI->show();
218}
219
220
221void PBSystemTab::loadBootData()
222{
223    /*//Trawl screens directory
224    QDir screens = QDir(PREFIX + "/share/pcbsd/splash-screens/");
225    if (! screens.exists())
226    {
227        QMessageBox::critical( 0, tr("File not found!"), PREFIX + "/share/pcbsd/splash-screens/ " + tr("doesn't exist!"), QMessageBox::Ok );
228        return;
229    }
230    screens.setFilter(QDir::Files);
231    QStringList screensList = screens.entryList();
232   
233    QRegExp screenMatcher = QRegExp("^loading-screen-(([a-z]|[A-Z]|_)+)\\.pcx$");
234    QStringList langList = QStringList();
235    QLocale langResolver;
236    codeMap = QMap<QString, QString>();
237    bool customPresent = false;
238    for (QStringList::Iterator it = screensList.begin(); it != screensList.end(); it++)
239    {
240        int pos  = screenMatcher.indexIn(*it);
241        if (pos > -1)
242        {
243            QString code = screenMatcher.cap(1);
244            if (code == "custom") { customPresent = true; }
245            else
246            {
247                QLocale lang(code);
248                QString langName = langResolver.languageToString(lang.language());
249                if ( langName.isEmpty() )
250                {
251                    langName = "Splash Screen: " + code;
252                }
253                langList += langName;
254                codeMap[langName] = code;
255            }
256        }
257    }
258   
259   
260    //Populate select box
261    langList.sort();
262    splashSelect->addItems(langList);
263
264    int indexMod = 0;
265   
266    if (customPresent)
267    {
268        codeMap[tr("Custom")] = "custom";
269        splashSelect->addItem(tr("Custom"), 0);
270        indexMod = 1;
271    }
272   
273    //Load current, get info from registry - /PCBSD/splash-screen
274    QSettings settings;
275    QString selectedLang = settings.value("/PCBSD/splash-screen", langResolver.language()).toString();
276   
277    if (selectedLang == "custom") { splashSelect->setCurrentIndex(0); }
278    else
279    {
280        //If we don't have a splash for the user's language, default to english
281        QLocale tlocale(selectedLang);
282        QString testLangName = langResolver.languageToString(tlocale.language());
283        if (codeMap[testLangName] == "") selectedLang = "en";
284
285        QLocale tlocale2(selectedLang);
286        selectedLang = langResolver.languageToString(tlocale2.language());
287        if ( selectedLang.isEmpty() )
288        {
289             selectedLang = "Splash Screen: " + selectedLang;
290        }
291
292        splashSelect->setCurrentIndex(langList.indexOf(selectedLang) + indexMod);
293    }
294*/
295    if ( pcbsd::Utils::getConfFileValue(QString(PREFIX + "/share/pcbsd/xstartup/enable-ibus.sh"), QString("FORCEIBUS=") ) == QString("YES"))
296                checkForceIbus->setChecked(TRUE);
297    else
298                checkForceIbus->setChecked(FALSE);
299}
300
301void PBSystemTab::slotMiscSave() {
302    saveKernScreen();
303
304    // Save package set
305    if ( radioProduction->isChecked() )
306      pcbsd::Utils::setValPCBSDConf("PACKAGE_SET", "PRODUCTION");
307    else
308      pcbsd::Utils::setValPCBSDConf("PACKAGE_SET", "EDGE");
309
310    // Extract the ports overlay to grab a new package set repo config
311    QProcess::execute(QString("pc-extractoverlay"), QStringList() << "ports");
312}
313
314void PBSystemTab::slotClose() {
315    close();
316}
317
318bool PBSystemTab::sanityCheckSettings()
319{
320  return true;
321}
322
323
324QString PBSystemTab::getLineFromCommandOutput( QString cmd )
325{
326        FILE *file = popen(cmd.toLatin1(),"r");
327   
328        char buffer[100];
329 
330        QString line = "";
331        char firstChar;
332
333        if ((firstChar = fgetc(file)) != -1){
334                line += firstChar;
335                line += fgets(buffer,100,file);
336        }
337        pclose(file);
338        return line.simplified();
339}
340
341void PBSystemTab::changeOpenTab(int tab)
342{
343   tabWidget->setCurrentIndex(tab);
344}
345
346void PBSystemTab::checkProxy()
347{
348  bool ok;
349  int port;
350
351  // If no proxy set
352  if ( pcbsd::Utils::getProxyURL().isEmpty() )
353    return;
354
355  QNetworkProxy proxy;
356  if ( pcbsd::Utils::getProxyType() == "SOCKS5" )
357    proxy.setType(QNetworkProxy::Socks5Proxy);
358  else
359    proxy.setType(QNetworkProxy::HttpProxy);
360
361  proxy.setHostName(pcbsd::Utils::getProxyURL());
362
363  port = pcbsd::Utils::getProxyPort().toInt(&ok);
364  if ( ! pcbsd::Utils::getProxyPort().isEmpty() && ok )
365    proxy.setPort(port);
366  if ( ! pcbsd::Utils::getProxyUser().isEmpty() )
367    proxy.setUser(pcbsd::Utils::getProxyUser());
368  if ( ! pcbsd::Utils::getProxyPass().isEmpty() )
369    proxy.setPassword(pcbsd::Utils::getProxyPass());
370
371  QNetworkProxy::setApplicationProxy(proxy);
372}
Note: See TracBrowser for help on using the repository browser.