source: src-qt4/pc-sysmanager/pbsystemtab.cpp @ 8a4c7a0

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 8a4c7a0 was 8a4c7a0, checked in by Ken Moore <ken@…>, 19 months ago

Add system source branch detection to the system manager.

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