source: src-qt4/PCDM/src/pcdm-gui.cpp @ 4018e43

9.2-releasereleng/10.0releng/10.0.1
Last change on this file since 4018e43 was 4018e43, checked in by Ken Moore <ken@…>, 9 months ago

Update the PCDM splash screen, and finish adjusting the toolbar size.
Allow PCDM to detect when the system is shutting down, and show the splash screen until the shutdown procedure closes the program (30 sec max wait).

  • Property mode set to 100644
File size: 21.3 KB
Line 
1/* PCDM Login Manager:
2*  Written by Ken Moore (ken@pcbsd.org) 2012/2013
3*  Copyright(c) 2013 by the PC-BSD Project
4*  Available under the 3-clause BSD license
5*/
6
7#include <QProcess>
8#include <QTimer>
9#include <QGraphicsPixmapItem>
10#include <QStyle>
11#include <pcbsd-utils.h>
12
13#include "pcdm-gui.h"
14#include "pcdm-backend.h"
15#include "fancySwitcher.h"
16
17bool DEBUG_MODE=FALSE;
18QString VIRTUALKBDBIN="/usr/local/bin/xvkbd -compact";
19
20PCDMgui::PCDMgui() : QMainWindow()
21{
22    lastUser.clear();
23    lastDE.clear();
24    //Load the Theme
25    loadTheme();
26    //Create the GUI based upon the current Theme
27    createGUIfromTheme();
28    //Now make sure that the login widget has keyboard focus
29    loginW->resetFocus();
30    this->setObjectName("PCDM-background");
31}
32
33PCDMgui::~PCDMgui()
34{
35    //delete ui;
36}
37
38void PCDMgui::loadTheme(){
39  currentTheme = new ThemeStruct();
40  QString themeFile = Config::themeFile();
41  if(!QFile::exists(themeFile)){ themeFile = ":samples/themes/default/default.theme"; }
42  currentTheme->loadThemeFile( themeFile );
43  //Check the Theme, using default values as necessary
44  QStringList invalid = currentTheme->invalidItems();
45  if( !invalid.isEmpty() ){
46    ThemeStruct* defaultTheme = new ThemeStruct();
47    defaultTheme->loadThemeFile( ":samples/themes/default/default.theme" );
48    for( int i=0; i<invalid.length(); i++){
49      //Replace the invalid items with the defaults
50      qDebug() << "Invalid Theme Item, Using defaults:" << invalid[i];
51      currentTheme->importItem( invalid[i] , defaultTheme->exportItem(invalid[i]) );
52    }
53  }
54  //Load the data from the last successful login
55  loadLastUser();
56 
57}
58
59void PCDMgui::createGUIfromTheme(){
60  QString style;
61  QString tmpIcon; //used for checking image files before loading them
62  //Set the background image
63  if(DEBUG_MODE){ qDebug() << "Setting Background Image"; }
64  if( currentTheme->itemIsEnabled("background") ){
65    tmpIcon = currentTheme->itemIcon("background");
66    if( tmpIcon.isEmpty() || !QFile::exists(tmpIcon) ){ tmpIcon = ":/images/backgroundimage.jpg"; }
67    //use "border-image" instead of "background-image" to stretch rather than tile the image
68    QString bgstyle = "QMainWindow#PCDM-background {border-image: url(BGIMAGE) stretch;}"; 
69    bgstyle.replace("BGIMAGE", tmpIcon);
70    style.append(bgstyle);
71  }
72  //Set the application style sheet
73  style.append(" "+ currentTheme->styleSheet() );
74  this->setStyleSheet( style.simplified() );
75
76  //Check for whether the desktop switcher is on the toolbar or not
77  simpleDESwitcher = (currentTheme->itemValue("desktop") == "simple");
78 
79  //get the default translation directory
80  if(DEBUG_MODE){ qDebug() << "Load Translations"; }
81  translationDir = "/usr/local/share/PCDM/i18n/";
82  //Fill the translator
83  m_translator = new QTranslator();
84  //Create the Toolbar
85  toolbar = new QToolBar();
86  //Add the Toolbar to the window
87  if(DEBUG_MODE){ qDebug() << "Create Toolbar"; }
88    //use the theme location   
89    QString tarea = currentTheme->itemValue("toolbar");
90    if(tarea == "left"){
91      this->addToolBar( Qt::LeftToolBarArea, toolbar );             
92    }else if( tarea=="top"){
93      this->addToolBar( Qt::TopToolBarArea, toolbar );             
94    }else if(tarea=="right"){
95      this->addToolBar( Qt::RightToolBarArea, toolbar );           
96    }else{ //bottom is default
97      this->addToolBar( Qt::BottomToolBarArea, toolbar );       
98    }
99    //Set toolbar flags
100    toolbar->setVisible(TRUE);
101    toolbar->setMovable(FALSE);
102    toolbar->setFloatable(FALSE);
103    //Set the default style and icon sizes
104    QString tstyle = currentTheme->itemIcon("toolbar").toLower(); //use the theme style
105    if(tstyle=="textonly"){ toolbar->setToolButtonStyle(Qt::ToolButtonTextOnly); }
106    else if(tstyle=="textbesideicon"){ toolbar->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); }
107    else if(tstyle=="textundericon"){ toolbar->setToolButtonStyle(Qt::ToolButtonTextUnderIcon); }
108    else{ toolbar->setToolButtonStyle(Qt::ToolButtonIconOnly); } //default to icon only
109   
110    toolbar->setIconSize( currentTheme->itemIconSize("toolbar") ); //use theme size
111    toolbar->setFocusPolicy( Qt::NoFocus );
112  //Populate the Toolbar with items (starts at leftmost/topmost)
113    //----Virtual Keyboard
114    if(currentTheme->itemIsEnabled("vkeyboard") ){
115      if(DEBUG_MODE){ qDebug() << " - Create Virtual Keyboard Button"; }
116      tmpIcon = currentTheme->itemIcon("vkeyboard");
117      if(!QFile::exists(tmpIcon) || tmpIcon.isEmpty() ){ tmpIcon=":/images/input-keyboard.png"; }
118      virtkeyboardButton = new QAction( QIcon(tmpIcon),tr("Virtual Keyboard"),this );
119      toolbar->addAction(virtkeyboardButton);
120      connect( virtkeyboardButton, SIGNAL(triggered()), this, SLOT(slotPushVirtKeyboard()) );
121    }else{
122      virtkeyboardButton = new QAction(this);
123    }
124
125    //----Locale Switcher
126    if(DEBUG_MODE){ qDebug() << " - Create Locale Button"; }
127    tmpIcon = currentTheme->itemIcon("locale");
128    if(!QFile::exists(tmpIcon) || tmpIcon.isEmpty() ){ tmpIcon=":/images/language.png"; }
129    localeButton = new QAction( QIcon(tmpIcon),tr("Locale"),this );
130    toolbar->addAction(localeButton);
131    connect( localeButton, SIGNAL(triggered()), this, SLOT(slotChangeLocale()) );
132   
133    //----Keyboard Layout Switcher
134    if(DEBUG_MODE){ qDebug() << " - Create Keyboard Layout Button"; }
135    tmpIcon = currentTheme->itemIcon("keyboard");
136    if(!QFile::exists(tmpIcon) || tmpIcon.isEmpty() ){ tmpIcon=":/images/keyboard.png"; }
137    keyboardButton = new QAction( QIcon(tmpIcon),tr("Keyboard Layout"),this );
138    toolbar->addAction(keyboardButton);
139    connect( keyboardButton, SIGNAL(triggered()), this, SLOT(slotChangeKeyboardLayout()) );
140   
141    //----Add a spacer
142    QWidget* spacer = new QWidget();
143    spacer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
144    toolbar->addWidget(spacer);
145   
146    if(simpleDESwitcher){
147      if(DEBUG_MODE){ qDebug() << " - Create Simple DE Switcher"; }
148      //Create the simple DE Switcher
149      sdeSwitcher = new QComboBox(this); 
150      sdeSwitcher->setFocusPolicy( Qt::NoFocus );
151      sdeSwitcher->setIconSize(currentTheme->itemIconSize("toolbar"));
152      toolbar->addWidget(sdeSwitcher);
153      //Add an additional spacer
154      QWidget* spacer2 = new QWidget();
155      spacer2->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
156      toolbar->addWidget(spacer2);
157     
158    }
159   
160    //----System Shutdown/Restart
161    if(DEBUG_MODE){ qDebug() << " - Create System Button"; }
162    tmpIcon = currentTheme->itemIcon("system");
163    if(!QFile::exists(tmpIcon) || tmpIcon.isEmpty() ){ tmpIcon=":/images/system.png"; }
164    QAction* act = new QAction( QIcon(tmpIcon),tr("System"),this );
165    systemButton = new QToolButton();
166    systemButton->setDefaultAction(act);
167    systemMenu = new QMenu();
168    toolbar->addWidget(systemButton);
169    systemButton->setPopupMode( QToolButton::InstantPopup );
170    systemButton->setFocusPolicy( Qt::NoFocus );
171   
172  //Create the grid layout
173  QGridLayout* grid = new QGridLayout;
174  if(DEBUG_MODE){ qDebug() << "Fill Desktop Area"; }
175  //Populate the grid with items
176    //----Header Image
177    QLabel* header = new QLabel; 
178    if( currentTheme->itemIsEnabled("header") ){
179      if(DEBUG_MODE){ qDebug() << " - Create Header"; }
180      tmpIcon = currentTheme->itemIcon("header");
181      if(!QFile::exists(tmpIcon) || tmpIcon.isEmpty() ){ tmpIcon=":/images/banner.png"; }
182      QPixmap tmp( tmpIcon );
183      header->setPixmap( tmp.scaled( currentTheme->itemIconSize("header") ) );
184      grid->addWidget( header, currentTheme->itemLocation("header","row"), \
185                      currentTheme->itemLocation("header","col"), \
186                      currentTheme->itemLocation("header","rowspan"), \
187                      currentTheme->itemLocation("header","colspan"), Qt::AlignCenter);
188    }
189   
190    //Username/Password/Login widget
191    if(DEBUG_MODE){ qDebug() << " - Create Login Widget"; }
192    loginW = new LoginWidget;
193    loginW->setUsernames(Backend::getSystemUsers()); //add in the detected users
194    if(!lastUser.isEmpty()){ //set the previously used user
195        loginW->setCurrentUser(lastUser); 
196        loadLastDE(lastUser); //make sure the DE switcher reflects the last user choice
197    } 
198    //Set Icons from theme
199    tmpIcon = currentTheme->itemIcon("login");
200    if(!QFile::exists(tmpIcon) || tmpIcon.isEmpty() ){ tmpIcon=":/images/next.png"; }
201    loginW->changeButtonIcon("login",tmpIcon, currentTheme->itemIconSize("login"));
202    tmpIcon = currentTheme->itemIcon("user");
203    slotUserChanged(loginW->currentUsername()); //Make sure that we have the correct user icon
204    tmpIcon = currentTheme->itemIcon("password");
205    if(!QFile::exists(tmpIcon) || tmpIcon.isEmpty() ){ tmpIcon=":/images/password.png"; }
206    loginW->changeButtonIcon("pwview",tmpIcon, currentTheme->itemIconSize("password"));
207    //Enable/disable the password view functionality
208    loginW->allowPasswordView( Config::allowPasswordView() );
209    //Add item to the grid
210    grid->addWidget( loginW, currentTheme->itemLocation("login","row"), \
211                      currentTheme->itemLocation("login","col"), \
212                      currentTheme->itemLocation("login","rowspan"), \
213                      currentTheme->itemLocation("login","colspan"), Qt::AlignCenter);
214    //Connect the signals/slots
215    connect(loginW,SIGNAL(loginRequested(QString,QString)),this,SLOT(slotStartLogin(QString,QString)));
216    connect(loginW,SIGNAL(escapePressed()),this,SLOT(slotShutdownComputer()));
217    connect(loginW,SIGNAL(UserSelected(QString)), this, SLOT(slotUserSelected(QString)) );
218    connect(loginW,SIGNAL(UserChanged(QString)), this, SLOT(slotUserChanged(QString)) );
219   
220    //----Desktop Environment Switcher
221    if(!simpleDESwitcher){
222      if(DEBUG_MODE){ qDebug() << " - Create DE Switcher"; }
223      //Create the switcher
224      deSwitcher = new FancySwitcher(this, !currentTheme->itemIsVertical("desktop") );
225      QSize deSize = currentTheme->itemIconSize("desktop");
226      deSwitcher->setIconSize(deSize.height());
227      tmpIcon = currentTheme->itemIcon("nextde");
228      if( !tmpIcon.isEmpty() && QFile::exists(tmpIcon) ){ deSwitcher->changeButtonIcon("forward", tmpIcon); }
229      tmpIcon = currentTheme->itemIcon("previousde");
230      if( !tmpIcon.isEmpty() && QFile::exists(tmpIcon) ){ deSwitcher->changeButtonIcon("back", tmpIcon); }
231      //Figure out if we need to smooth out the animation
232      deSwitcher->setNumberAnimationFrames("4"); 
233      //NOTE: A transparent widget background slows the full animation to a crawl with a stretched background image
234
235      grid->addWidget( deSwitcher, currentTheme->itemLocation("desktop","row"), \
236                      currentTheme->itemLocation("desktop","col"), \
237                      currentTheme->itemLocation("desktop","rowspan"), \
238                      currentTheme->itemLocation("desktop","colspan"), Qt::AlignCenter);
239    }
240    //----WINDOW SPACERS
241    QStringList spacers = currentTheme->getSpacers();
242    for(int i=0; i<spacers.length(); i++){
243      bool isVertical = (spacers[i].section("::",0,0) == "true");
244      int row = spacers[i].section("::",1,1).toInt();
245      int col = spacers[i].section("::",2,2).toInt();
246      //qDebug() << "Add Spacer:" << isVertical << row << col;
247      if(isVertical){
248        grid->setRowStretch(row,1);
249      }else{ //horizontal
250        grid->setColumnStretch(col,1);
251      }
252    }
253
254  //Connect the grid to the Window
255    QWidget* widget = new QWidget;
256    widget->setLayout(grid);
257    this->setCentralWidget(widget);
258   
259  //Now translate the UI and set all the text
260  if(DEBUG_MODE){ qDebug() << " - Fill GUI with data"; }
261  retranslateUi();
262  if(DEBUG_MODE){ qDebug() << "Done with initialization"; }
263
264}
265
266void PCDMgui::slotStartLogin(QString displayname, QString password){
267  //Get user inputs
268  QString username = Backend::getUsernameFromDisplayname(displayname);
269  QString binary;
270  if(simpleDESwitcher){
271    binary = Backend::getDesktopBinary(sdeSwitcher->currentText());
272  }else{
273    binary = Backend::getDesktopBinary(deSwitcher->currentItem());
274  }
275  QString homedir = Backend::getUserHomeDir(username);
276  //Disable user input while confirming login
277  loginW->setEnabled(FALSE);
278  if(!simpleDESwitcher){ deSwitcher->setEnabled(FALSE); }
279  toolbar->setEnabled(FALSE);
280  //Try to login
281  emit xLoginAttempt(username, password, homedir, binary);
282  //Return signals are connected to the slotLogin[Success/Failure] functions
283 
284}
285
286void PCDMgui::slotLoginSuccess(){
287  QString de;
288  if(simpleDESwitcher){ de = sdeSwitcher->currentText(); }
289  else{ de = deSwitcher->currentItem(); }
290  saveLastLogin( loginW->currentUsername(), de );
291  slotClosePCDM(); //now start to close down the PCDM GUI
292}
293
294void PCDMgui::slotLoginFailure(){
295  //Display an info box that the login failed
296  QMessageBox notice(this);
297    notice.setWindowTitle(tr("Invalid Username/Password"));
298    notice.setIcon(QMessageBox::Warning);
299    notice.setText(tr("Username/Password combination is invalid, please try again."));
300    notice.setInformativeText("("+tr("Tip: Make sure that caps-lock is turned off.")+")");
301    notice.setStandardButtons(QMessageBox::Ok);
302    notice.setDefaultButton(QMessageBox::Ok);
303    notice.exec();
304       
305  //Re-Enable user input
306  loginW->setEnabled(TRUE);
307  if(!simpleDESwitcher){ deSwitcher->setEnabled(TRUE); }
308  toolbar->setEnabled(TRUE);
309}
310
311void PCDMgui::slotUserChanged(QString newuser){
312  if( !newuser.isEmpty() ){
313    //Try to load the custom user icon
314    QString tmpIcon = Backend::getUserHomeDir(newuser) + "/.loginIcon.png";
315    if(!QFile::exists(tmpIcon) ){ tmpIcon= currentTheme->itemIcon("user"); }
316    if(!QFile::exists(tmpIcon) || tmpIcon.isEmpty() ){ tmpIcon=":/images/user.png"; }
317    loginW->changeButtonIcon("display",tmpIcon, currentTheme->itemIconSize("user"));
318  }
319}
320
321void PCDMgui::slotUserSelected(QString newuser){
322  if(newuser.isEmpty()){
323    if(simpleDESwitcher){ sdeSwitcher->setVisible(FALSE); }
324    else{ deSwitcher->setVisible(FALSE); }
325  }else{
326    if(simpleDESwitcher){ sdeSwitcher->setVisible(TRUE); }
327    else{ deSwitcher->setVisible(TRUE); }
328    //Try to load the user's last DE
329    loadLastDE(newuser);
330    //Try to load the custom user icon
331    slotUserChanged(newuser);
332  }
333  retranslateUi();
334}
335
336void PCDMgui::slotShutdownComputer(){
337  QMessageBox verify;
338  verify.setWindowTitle(tr("System Shutdown"));
339  verify.setText(tr("You are about to shut down the system."));
340  verify.setInformativeText(tr("Are you sure?"));
341  verify.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
342  verify.setDefaultButton(QMessageBox::No);
343  int ret = verify.exec();
344
345  if(ret == QMessageBox::Yes){
346    Backend::log("PCDM: Shutting down computer");
347    system("shutdown -p now");
348    close();
349  }
350}
351
352void PCDMgui::slotRestartComputer(){
353  QMessageBox verify;
354  verify.setWindowTitle(tr("System Restart"));
355  verify.setText(tr("You are about to restart the system."));
356  verify.setInformativeText(tr("Are you sure?"));
357  verify.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
358  verify.setDefaultButton(QMessageBox::No);
359  int ret = verify.exec();
360
361  if(ret == QMessageBox::Yes){
362    Backend::log("PCDM: Restarting computer");
363    system("shutdown -r now");
364    close();
365  }
366}
367
368void PCDMgui::slotClosePCDM(){
369  system("killall -9 xvkbd"); //be sure to close the virtual keyboard
370  QCoreApplication::exit(0);
371  close();
372}
373
374void PCDMgui::slotChangeLocale(){
375  //Open the selector
376  wLoc = new widgetLocale();
377  QLocale currLocale = this->locale();
378  Backend::log("Current PCDM Locale: " + currLocale.name() );
379  wLoc->setCurrentLocale(currLocale.name());
380  wLoc->setWindowModality(Qt::ApplicationModal);
381  wLoc->show();
382  wLoc->raise();
383
384  //Connect the language changed signal
385  connect(wLoc,SIGNAL(languageChanged(QString)),this,SLOT(slotLocaleChanged(QString)) );
386}
387
388void PCDMgui::slotLocaleChanged(QString langCode){
389  //Get the valid Locale code
390  QString translationFile;
391  if(!QFile::exists(translationDir+"PCDM_"+langCode+".qm")){
392    langCode = langCode.section("_",0,0);
393    if(!QFile::exists(translationDir+"PCDM_"+langCode+".qm")){
394      if(!QFile::exists(translationDir+"qt_"+langCode+".qm")){
395        Backend::log("Desired locale is not a valid translation: " + langCode);
396        return;
397      }else{
398        translationFile = translationDir+"qt_"+langCode+".qm";     
399      }
400    }else{
401      translationFile = translationDir+"PCDM_"+langCode+".qm";     
402    }
403  }else{
404    translationFile = translationDir+"PCDM_"+langCode+".qm";
405  }     
406       
407  Backend::log("Changing localization to " + langCode);
408
409  //Alternate method for changing Locale
410  QLocale locale(langCode);
411  this->setLocale(locale);
412  //this->setDefaultLocale(locale);
413  //Change the translator
414  if( !m_translator->isEmpty() ){
415    Backend::log("Remove the translator");
416    QCoreApplication::removeTranslator(m_translator);
417  }
418
419  if(m_translator->load(translationFile)){
420    Backend::log("Install the new translator: "+translationFile);
421    QCoreApplication::installTranslator(m_translator);   
422  }
423  //Re-draw the interface
424  retranslateUi();
425 
426  Backend::log("Current Locale after change: " + this->locale().name() );
427}
428
429void PCDMgui::slotChangeKeyboardLayout(){
430  //Fill a couple global variables
431  QStringList kModels = Backend::keyModels();
432  QStringList kLayouts = Backend::keyLayouts();
433  //Startup the GUI
434  wKey = new widgetKeyboard();
435  wKey->programInit(kModels, kLayouts);
436  wKey->setWindowModality(Qt::ApplicationModal);
437  wKey->show();
438  wKey->raise();
439}
440
441// Start xvkbd
442void PCDMgui::slotPushVirtKeyboard(){
443   QString cmd = "killall -9 "+VIRTUALKBDBIN.section(" ",0,0).section("/",-1)+"; "+VIRTUALKBDBIN+" &";
444   qDebug() << "Starting Virtual Keyboard:";
445   qDebug() << " - CMD: "+cmd;
446   system( cmd.toUtf8() );
447   loginW->resetFocus("password");
448}
449
450void PCDMgui::retranslateUi(){
451  //All the text-setting for the main interface needs to be done here
452  //virtual keyboard button
453  //if(currentTheme->itemIsEnabled("vkeyboard")){
454    virtkeyboardButton->setToolTip(tr("Virtual Keyboard"));
455    virtkeyboardButton->setText(tr("Virtual Keyboard"));
456  //}
457  //locale switcher button
458  localeButton->setToolTip(tr("Change locale"));
459  localeButton->setText(tr("Locale"));
460  //keyboard layout button
461  keyboardButton->setToolTip(tr("Change Keyboard Layout"));
462  keyboardButton->setText(tr("Keyboard Layout"));
463  //system button
464  systemButton->defaultAction()->setToolTip(tr("Shutdown the computer"));
465  systemButton->defaultAction()->setText(tr("System"));
466  //Menu entries for system button
467    systemMenu->clear();       
468    systemMenu->addAction( tr("Restart"),this, SLOT(slotRestartComputer()) );
469    systemMenu->addAction( tr("Shut Down"), this, SLOT(slotShutdownComputer()) );
470    if(DEBUG_MODE){systemMenu->addAction( tr("Close PCDM"), this, SLOT(slotClosePCDM()) ); }
471    systemButton->setMenu(systemMenu);
472  //The main login widget
473  if(hostname.isEmpty()){
474    //Find the system hostname
475    hostname = pcbsd::Utils::runShellCommand("hostname").join(" ").simplified();
476    loginW->displayHostName(hostname);   
477  }
478  loginW->retranslateUi();
479  //The desktop switcher
480  if(simpleDESwitcher){ sdeSwitcher->clear(); }
481  else{ deSwitcher->removeAllItems(); }
482 
483    //Get the new desktop list (translated)
484    QStringList deList = Backend::getAvailableDesktops();
485    for(int i=0; i<deList.length(); i++){
486      QString deIcon = Backend::getDesktopIcon(deList[i]);
487      if( deIcon.isEmpty() ){ deIcon = currentTheme->itemIcon("desktop"); } //set the default icon if none given
488      if( !QFile::exists(deIcon) ){ deIcon = ":/images/desktop.png"; }
489      //Now add the item back to the widget
490      if(simpleDESwitcher){ sdeSwitcher->addItem(QIcon(deIcon), deList[i]); }
491      else{ deSwitcher->addItem( deList[i], deIcon, Backend::getDesktopComment(deList[i]) ); }
492    }
493    //Set the switcher to the last used desktop environment
494    if( !lastDE.isEmpty() ){ 
495      if(simpleDESwitcher){ 
496        int index = deList.indexOf(lastDE);
497        if(index != -1){ sdeSwitcher->setCurrentIndex(index); }
498        else{ sdeSwitcher->setCurrentIndex(0); }
499      }else{ 
500        deSwitcher->setCurrentItem(lastDE); 
501      }
502    }
503
504}
505
506void PCDMgui::loadLastUser(){
507  lastUser.clear();
508  if(!QFile::exists("/usr/local/share/PCDM/.lastlogin")){
509    Backend::log("PCDM: No previous login data found");
510  }else{
511    //Load the previous login data
512    QFile file("/usr/local/share/PCDM/.lastlogin");
513    if(!file.open(QIODevice::ReadOnly | QIODevice::Text)){
514      Backend::log("PCDM: Unable to open previous login data file");   
515    }else{
516      QTextStream in(&file);
517      lastUser= in.readLine();
518      file.close();
519    }
520  }
521}
522
523void PCDMgui::loadLastDE(QString user){
524  lastDE.clear();
525  QString LLpath = Backend::getUserHomeDir(user) + "/.lastlogin";
526  if(!QFile::exists(LLpath)){
527    Backend::log("PCDM: No previous user login data found for user: "+user);
528  }else{
529    //Load the previous login data
530    QFile file(LLpath);
531    if(!file.open(QIODevice::ReadOnly | QIODevice::Text)){
532      Backend::log("PCDM: Unable to open previous user login file: "+user);   
533    }else{
534      QTextStream in(&file);
535      lastDE= in.readLine();
536      file.close();
537    }
538  }
539
540}
541
542void PCDMgui::saveLastLogin(QString USER, QString DE){
543  QFile file1("/usr/local/share/PCDM/.lastlogin");
544  if(!file1.open(QIODevice::Truncate | QIODevice::WriteOnly | QIODevice::Text)){
545    Backend::log("PCDM: Unable to save last login data");         
546  }else{
547    QTextStream out(&file1);
548    out << USER;
549    file1.close();
550  }
551  QFile file2( Backend::getUserHomeDir(USER) + "/.lastlogin" );
552  if(!file2.open(QIODevice::Truncate | QIODevice::WriteOnly | QIODevice::Text)){
553    Backend::log("PCDM: Unable to save last login data for user:"+USER);         
554  }else{
555    QTextStream out(&file2);
556    out << DE;
557    file2.close();
558  }
559}
560
Note: See TracBrowser for help on using the repository browser.