source: src-qt4/PCDM/src/pcdm-gui.cpp @ 6bd7798

9.2-releasereleng/10.0releng/10.0.1releng/10.0.2releng/10.0.3
Last change on this file since 6bd7798 was 6bd7798, checked in by Ken Moore <ken@…>, 15 months ago

Make sure that the simple desktop switcher does not take keyboard focus away from the password line, and disable debug mode

  • Property mode set to 100644
File size: 21.2 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 = QApplication::applicationDirPath() + "/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      toolbar->addWidget(sdeSwitcher);
152      //Add an additional spacer
153      QWidget* spacer2 = new QWidget();
154      spacer2->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
155      toolbar->addWidget(spacer2);
156     
157    }
158   
159    //----System Shutdown/Restart
160    if(DEBUG_MODE){ qDebug() << " - Create System Button"; }
161    tmpIcon = currentTheme->itemIcon("system");
162    if(!QFile::exists(tmpIcon) || tmpIcon.isEmpty() ){ tmpIcon=":/images/system.png"; }
163    QAction* act = new QAction( QIcon(tmpIcon),tr("System"),this );
164    systemButton = new QToolButton();
165    systemButton->setDefaultAction(act);
166    systemMenu = new QMenu();
167    toolbar->addWidget(systemButton);
168    systemButton->setPopupMode( QToolButton::InstantPopup );
169    systemButton->setFocusPolicy( Qt::NoFocus );
170   
171  //Create the grid layout
172  QGridLayout* grid = new QGridLayout;
173  if(DEBUG_MODE){ qDebug() << "Fill Desktop Area"; }
174  //Populate the grid with items
175    //----Header Image
176    QLabel* header = new QLabel; 
177    if( currentTheme->itemIsEnabled("header") ){
178      if(DEBUG_MODE){ qDebug() << " - Create Header"; }
179      tmpIcon = currentTheme->itemIcon("header");
180      if(!QFile::exists(tmpIcon) || tmpIcon.isEmpty() ){ tmpIcon=":/images/banner.png"; }
181      QPixmap tmp( tmpIcon );
182      header->setPixmap( tmp.scaled( currentTheme->itemIconSize("header") ) );
183      grid->addWidget( header, currentTheme->itemLocation("header","row"), \
184                      currentTheme->itemLocation("header","col"), \
185                      currentTheme->itemLocation("header","rowspan"), \
186                      currentTheme->itemLocation("header","colspan"), Qt::AlignCenter);
187    }
188   
189    //Username/Password/Login widget
190    if(DEBUG_MODE){ qDebug() << " - Create Login Widget"; }
191    loginW = new LoginWidget;
192    loginW->setUsernames(Backend::getSystemUsers()); //add in the detected users
193    if(!lastUser.isEmpty()){ //set the previously used user
194        loginW->setCurrentUser(lastUser); 
195        loadLastDE(lastUser); //make sure the DE switcher reflects the last user choice
196    } 
197    //Set Icons from theme
198    tmpIcon = currentTheme->itemIcon("login");
199    if(!QFile::exists(tmpIcon) || tmpIcon.isEmpty() ){ tmpIcon=":/images/next.png"; }
200    loginW->changeButtonIcon("login",tmpIcon, currentTheme->itemIconSize("login"));
201    tmpIcon = currentTheme->itemIcon("user");
202    slotUserChanged(loginW->currentUsername()); //Make sure that we have the correct user icon
203    tmpIcon = currentTheme->itemIcon("password");
204    if(!QFile::exists(tmpIcon) || tmpIcon.isEmpty() ){ tmpIcon=":/images/password.png"; }
205    loginW->changeButtonIcon("pwview",tmpIcon, currentTheme->itemIconSize("password"));
206    //Enable/disable the password view functionality
207    loginW->allowPasswordView( Config::allowPasswordView() );
208    //Add item to the grid
209    grid->addWidget( loginW, currentTheme->itemLocation("login","row"), \
210                      currentTheme->itemLocation("login","col"), \
211                      currentTheme->itemLocation("login","rowspan"), \
212                      currentTheme->itemLocation("login","colspan"), Qt::AlignCenter);
213    //Connect the signals/slots
214    connect(loginW,SIGNAL(loginRequested(QString,QString)),this,SLOT(slotStartLogin(QString,QString)));
215    connect(loginW,SIGNAL(escapePressed()),this,SLOT(slotShutdownComputer()));
216    connect(loginW,SIGNAL(UserSelected(QString)), this, SLOT(slotUserSelected(QString)) );
217    connect(loginW,SIGNAL(UserChanged(QString)), this, SLOT(slotUserChanged(QString)) );
218   
219    //----Desktop Environment Switcher
220    if(!simpleDESwitcher){
221      if(DEBUG_MODE){ qDebug() << " - Create DE Switcher"; }
222      //Create the switcher
223      deSwitcher = new FancySwitcher(this, !currentTheme->itemIsVertical("desktop") );
224      QSize deSize = currentTheme->itemIconSize("desktop");
225      deSwitcher->setIconSize(deSize.height());
226      tmpIcon = currentTheme->itemIcon("nextde");
227      if( !tmpIcon.isEmpty() && QFile::exists(tmpIcon) ){ deSwitcher->changeButtonIcon("forward", tmpIcon); }
228      tmpIcon = currentTheme->itemIcon("previousde");
229      if( !tmpIcon.isEmpty() && QFile::exists(tmpIcon) ){ deSwitcher->changeButtonIcon("back", tmpIcon); }
230      //Figure out if we need to smooth out the animation
231      deSwitcher->setNumberAnimationFrames("4"); 
232      //NOTE: A transparent widget background slows the full animation to a crawl with a stretched background image
233
234      grid->addWidget( deSwitcher, currentTheme->itemLocation("desktop","row"), \
235                      currentTheme->itemLocation("desktop","col"), \
236                      currentTheme->itemLocation("desktop","rowspan"), \
237                      currentTheme->itemLocation("desktop","colspan"), Qt::AlignCenter);
238    }
239    //----WINDOW SPACERS
240    QStringList spacers = currentTheme->getSpacers();
241    for(int i=0; i<spacers.length(); i++){
242      bool isVertical = (spacers[i].section("::",0,0) == "true");
243      int row = spacers[i].section("::",1,1).toInt();
244      int col = spacers[i].section("::",2,2).toInt();
245      //qDebug() << "Add Spacer:" << isVertical << row << col;
246      if(isVertical){
247        grid->setRowStretch(row,1);
248      }else{ //horizontal
249        grid->setColumnStretch(col,1);
250      }
251    }
252
253  //Connect the grid to the Window
254    QWidget* widget = new QWidget;
255    widget->setLayout(grid);
256    this->setCentralWidget(widget);
257   
258  //Now translate the UI and set all the text
259  if(DEBUG_MODE){ qDebug() << " - Fill GUI with data"; }
260  retranslateUi();
261  if(DEBUG_MODE){ qDebug() << "Done with initialization"; }
262
263}
264
265void PCDMgui::slotStartLogin(QString displayname, QString password){
266  //Get user inputs
267  QString username = Backend::getUsernameFromDisplayname(displayname);
268  QString binary;
269  if(simpleDESwitcher){
270    binary = Backend::getDesktopBinary(sdeSwitcher->currentText());
271  }else{
272    binary = Backend::getDesktopBinary(deSwitcher->currentItem());
273  }
274  QString homedir = Backend::getUserHomeDir(username);
275  //Disable user input while confirming login
276  loginW->setEnabled(FALSE);
277  if(!simpleDESwitcher){ deSwitcher->setEnabled(FALSE); }
278  toolbar->setEnabled(FALSE);
279  //Try to login
280  emit xLoginAttempt(username, password, homedir, binary);
281  //Return signals are connected to the slotLogin[Success/Failure] functions
282 
283}
284
285void PCDMgui::slotLoginSuccess(){
286  QString de;
287  if(simpleDESwitcher){ de = sdeSwitcher->currentText(); }
288  else{ de = deSwitcher->currentItem(); }
289  saveLastLogin( loginW->currentUsername(), de );
290  slotClosePCDM(); //now start to close down the PCDM GUI
291}
292
293void PCDMgui::slotLoginFailure(){
294  //Display an info box that the login failed
295  QMessageBox notice(this);
296    notice.setWindowTitle(tr("Invalid Username/Password"));
297    notice.setIcon(QMessageBox::Warning);
298    notice.setText(tr("Username/Password combination is invalid, please try again."));
299    notice.setInformativeText("("+tr("Tip: Make sure that caps-lock is turned off.")+")");
300    notice.setStandardButtons(QMessageBox::Ok);
301    notice.setDefaultButton(QMessageBox::Ok);
302    notice.exec();
303       
304  //Re-Enable user input
305  loginW->setEnabled(TRUE);
306  if(!simpleDESwitcher){ deSwitcher->setEnabled(TRUE); }
307  toolbar->setEnabled(TRUE);
308}
309
310void PCDMgui::slotUserChanged(QString newuser){
311  if( !newuser.isEmpty() ){
312    //Try to load the custom user icon
313    QString tmpIcon = Backend::getUserHomeDir(newuser) + "/.loginIcon.png";
314    if(!QFile::exists(tmpIcon) ){ tmpIcon= currentTheme->itemIcon("user"); }
315    if(!QFile::exists(tmpIcon) || tmpIcon.isEmpty() ){ tmpIcon=":/images/user.png"; }
316    loginW->changeButtonIcon("display",tmpIcon, currentTheme->itemIconSize("user"));
317  }
318}
319
320void PCDMgui::slotUserSelected(QString newuser){
321  if(newuser.isEmpty()){
322    if(simpleDESwitcher){ sdeSwitcher->setVisible(FALSE); }
323    else{ deSwitcher->setVisible(FALSE); }
324  }else{
325    if(simpleDESwitcher){ sdeSwitcher->setVisible(TRUE); }
326    else{ deSwitcher->setVisible(TRUE); }
327    //Try to load the user's last DE
328    loadLastDE(newuser);
329    //Try to load the custom user icon
330    slotUserChanged(newuser);
331  }
332  retranslateUi();
333}
334
335void PCDMgui::slotShutdownComputer(){
336  QMessageBox verify;
337  verify.setWindowTitle(tr("System Shutdown"));
338  verify.setText(tr("You are about to shut down the system."));
339  verify.setInformativeText(tr("Are you sure?"));
340  verify.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
341  verify.setDefaultButton(QMessageBox::No);
342  int ret = verify.exec();
343
344  if(ret == QMessageBox::Yes){
345    Backend::log("PCDM: Shutting down computer");
346    system("shutdown -p now");
347  }
348}
349
350void PCDMgui::slotRestartComputer(){
351  QMessageBox verify;
352  verify.setWindowTitle(tr("System Restart"));
353  verify.setText(tr("You are about to restart the system."));
354  verify.setInformativeText(tr("Are you sure?"));
355  verify.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
356  verify.setDefaultButton(QMessageBox::No);
357  int ret = verify.exec();
358
359  if(ret == QMessageBox::Yes){
360    Backend::log("PCDM: Restarting computer");
361    system("shutdown -r now");
362  }
363}
364
365void PCDMgui::slotClosePCDM(){
366  system("killall -9 xvkbd"); //be sure to close the virtual keyboard
367  QCoreApplication::exit(0);
368  close();
369}
370
371void PCDMgui::slotChangeLocale(){
372  //Open the selector
373  wLoc = new widgetLocale();
374  QLocale currLocale = this->locale();
375  Backend::log("Current PCDM Locale: " + currLocale.name() );
376  wLoc->setCurrentLocale(currLocale.name());
377  wLoc->setWindowModality(Qt::ApplicationModal);
378  wLoc->show();
379  wLoc->raise();
380
381  //Connect the language changed signal
382  connect(wLoc,SIGNAL(languageChanged(QString)),this,SLOT(slotLocaleChanged(QString)) );
383}
384
385void PCDMgui::slotLocaleChanged(QString langCode){
386  //Get the valid Locale code
387  QString translationFile;
388  if(!QFile::exists(translationDir+"PCDM_"+langCode+".qm")){
389    langCode = langCode.section("_",0,0);
390    if(!QFile::exists(translationDir+"PCDM_"+langCode+".qm")){
391      if(!QFile::exists(translationDir+"qt_"+langCode+".qm")){
392        Backend::log("Desired locale is not a valid translation: " + langCode);
393        return;
394      }else{
395        translationFile = translationDir+"qt_"+langCode+".qm";     
396      }
397    }else{
398      translationFile = translationDir+"PCDM_"+langCode+".qm";     
399    }
400  }else{
401    translationFile = translationDir+"PCDM_"+langCode+".qm";
402  }     
403       
404  Backend::log("Changing localization to " + langCode);
405
406  //Alternate method for changing Locale
407  QLocale locale(langCode);
408  this->setLocale(locale);
409  //this->setDefaultLocale(locale);
410  //Change the translator
411  if( !m_translator->isEmpty() ){
412    Backend::log("Remove the translator");
413    QCoreApplication::removeTranslator(m_translator);
414  }
415
416  if(m_translator->load(translationFile)){
417    Backend::log("Install the new translator");
418    QCoreApplication::installTranslator(m_translator);   
419  }
420  //Re-draw the interface
421  retranslateUi();
422 
423  Backend::log("Current Locale after change: " + this->locale().name() );
424}
425
426void PCDMgui::slotChangeKeyboardLayout(){
427  //Fill a couple global variables
428  QStringList kModels = Backend::keyModels();
429  QStringList kLayouts = Backend::keyLayouts();
430  //Startup the GUI
431  wKey = new widgetKeyboard();
432  wKey->programInit(kModels, kLayouts);
433  wKey->setWindowModality(Qt::ApplicationModal);
434  wKey->show();
435  wKey->raise();
436}
437
438// Start xvkbd
439void PCDMgui::slotPushVirtKeyboard(){
440   QString cmd = "killall -9 "+VIRTUALKBDBIN.section(" ",0,0).section("/",-1)+"; "+VIRTUALKBDBIN+" &";
441   qDebug() << "Starting Virtual Keyboard:";
442   qDebug() << " - CMD: "+cmd;
443   system( cmd.toUtf8() );
444   loginW->resetFocus("password");
445}
446
447void PCDMgui::retranslateUi(){
448  //All the text-setting for the main interface needs to be done here
449  //virtual keyboard button
450  //if(currentTheme->itemIsEnabled("vkeyboard")){
451    virtkeyboardButton->setToolTip(tr("Virtual Keyboard"));
452    virtkeyboardButton->setText(tr("Virtual Keyboard"));
453  //}
454  //locale switcher button
455  localeButton->setToolTip(tr("Change locale"));
456  localeButton->setText(tr("Locale"));
457  //keyboard layout button
458  keyboardButton->setToolTip(tr("Change Keyboard Layout"));
459  keyboardButton->setText(tr("Keyboard Layout"));
460  //system button
461  systemButton->defaultAction()->setToolTip(tr("Shutdown the computer"));
462  systemButton->defaultAction()->setText(tr("System"));
463  //Menu entries for system button
464    systemMenu->clear();       
465    systemMenu->addAction( tr("Restart"),this, SLOT(slotRestartComputer()) );
466    systemMenu->addAction( tr("Shut Down"), this, SLOT(slotShutdownComputer()) );
467    if(DEBUG_MODE){systemMenu->addAction( tr("Close PCDM"), this, SLOT(slotClosePCDM()) ); }
468    systemButton->setMenu(systemMenu);
469  //The main login widget
470  if(hostname.isEmpty()){
471    //Find the system hostname
472    hostname = pcbsd::Utils::runShellCommand("hostname").join(" ").simplified();
473    loginW->displayHostName(hostname);   
474  }
475  loginW->retranslateUi();
476  //The desktop switcher
477  if(simpleDESwitcher){ sdeSwitcher->clear(); }
478  else{ deSwitcher->removeAllItems(); }
479 
480    //Get the new desktop list (translated)
481    QStringList deList = Backend::getAvailableDesktops();
482    for(int i=0; i<deList.length(); i++){
483      QString deIcon = Backend::getDesktopIcon(deList[i]);
484      if( deIcon.isEmpty() ){ deIcon = currentTheme->itemIcon("desktop"); } //set the default icon if none given
485      if( !QFile::exists(deIcon) ){ deIcon = ":/images/desktop.png"; }
486      //Now add the item back to the widget
487      if(simpleDESwitcher){ sdeSwitcher->addItem(QIcon(deIcon), deList[i]); }
488      else{ deSwitcher->addItem( deList[i], deIcon, Backend::getDesktopComment(deList[i]) ); }
489    }
490    //Set the switcher to the last used desktop environment
491    if( !lastDE.isEmpty() ){ 
492      if(simpleDESwitcher){ 
493        int index = deList.indexOf(lastDE);
494        if(index != -1){ sdeSwitcher->setCurrentIndex(index); }
495        else{ sdeSwitcher->setCurrentIndex(0); }
496      }else{ 
497        deSwitcher->setCurrentItem(lastDE); 
498      }
499    }
500
501}
502
503void PCDMgui::loadLastUser(){
504  lastUser.clear();
505  if(!QFile::exists("/usr/local/share/PCDM/.lastlogin")){
506    Backend::log("PCDM: No previous login data found");
507  }else{
508    //Load the previous login data
509    QFile file("/usr/local/share/PCDM/.lastlogin");
510    if(!file.open(QIODevice::ReadOnly | QIODevice::Text)){
511      Backend::log("PCDM: Unable to open previous login data file");   
512    }else{
513      QTextStream in(&file);
514      lastUser= in.readLine();
515      file.close();
516    }
517  }
518}
519
520void PCDMgui::loadLastDE(QString user){
521  lastDE.clear();
522  QString LLpath = Backend::getUserHomeDir(user) + "/.lastlogin";
523  if(!QFile::exists(LLpath)){
524    Backend::log("PCDM: No previous user login data found for user: "+user);
525  }else{
526    //Load the previous login data
527    QFile file(LLpath);
528    if(!file.open(QIODevice::ReadOnly | QIODevice::Text)){
529      Backend::log("PCDM: Unable to open previous user login file: "+user);   
530    }else{
531      QTextStream in(&file);
532      lastDE= in.readLine();
533      file.close();
534    }
535  }
536
537}
538
539void PCDMgui::saveLastLogin(QString USER, QString DE){
540  QFile file1("/usr/local/share/PCDM/.lastlogin");
541  if(!file1.open(QIODevice::Truncate | QIODevice::WriteOnly | QIODevice::Text)){
542    Backend::log("PCDM: Unable to save last login data");         
543  }else{
544    QTextStream out(&file1);
545    out << USER;
546    file1.close();
547  }
548  QFile file2( Backend::getUserHomeDir(USER) + "/.lastlogin" );
549  if(!file2.open(QIODevice::Truncate | QIODevice::WriteOnly | QIODevice::Text)){
550    Backend::log("PCDM: Unable to save last login data for user:"+USER);         
551  }else{
552    QTextStream out(&file2);
553    out << DE;
554    file2.close();
555  }
556}
557
Note: See TracBrowser for help on using the repository browser.