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

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

Set the default theme to use the "simple" desktop switcher, and disable the virtual keyboard button for now (need to figure out why it is not working right now)

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