source: src-qt4/PCDM/src/pcdm-gui.cpp @ 1d2d46a

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

Completely redo the simple desktop switcher option. It now puts it in the login widget underneath the password prompt. Also clean up the default theme a bit to accomodate these changes.

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