[PC-BSD Commits] r21680 - pcbsd-projects/PCDM

svn at pcbsd.org svn at pcbsd.org
Fri Mar 1 09:32:19 PST 2013


Author: kenmoore
Date: 2013-03-01 17:32:18 +0000 (Fri, 01 Mar 2013)
New Revision: 21680

Modified:
   pcbsd-projects/PCDM/loginWidget.cpp
   pcbsd-projects/PCDM/loginWidget.h
   pcbsd-projects/PCDM/pcdm-gui.cpp
   pcbsd-projects/PCDM/pcdm-gui.h
Log:
Completely update the PCDM login widget interface, and save/load the last desktop and a custom icon for each user that is selected.



Modified: pcbsd-projects/PCDM/loginWidget.cpp
===================================================================
--- pcbsd-projects/PCDM/loginWidget.cpp	2013-03-01 13:00:03 UTC (rev 21679)
+++ pcbsd-projects/PCDM/loginWidget.cpp	2013-03-01 17:32:18 UTC (rev 21680)
@@ -18,11 +18,18 @@
   pwVisible = FALSE; //Have the password box hide the input behind dots
   
   //Create the Grid layout
-  QGridLayout* layout = new QGridLayout();
   QHBoxLayout* hlayout1 = new QHBoxLayout();
   QHBoxLayout* hlayout2 = new QHBoxLayout();
   QVBoxLayout* vlayout = new QVBoxLayout();
+  QFormLayout* flayout = new QFormLayout();
   //Create the items
+  userIcon = new QToolButton;
+  	QAction* tmp = new QAction(this);
+	pushUserIcon->setDefaultAction( tmp );
+	pushUserIcon->setFocusPolicy(Qt::NoFocus);
+  listUserBig = new QListWidget;
+  	listUserBig->setFocusPolicy(Qt::StrongFocus);
+  	listUserBig->setSelectionMode(QAbstractItemView::SingleSelection);
   listUsers = new QComboBox;
   	listUsers->setFocusPolicy(Qt::StrongFocus);
   linePassword = new QLineEdit;
@@ -40,23 +47,28 @@
 	pushUserIcon->setDefaultAction( tmp3 );
 	pushUserIcon->setFocusPolicy(Qt::NoFocus);
   //Add the items to the grid
-      hlayout1->addWidget(pushUserIcon);
-      hlayout1->addWidget(listUsers);
+    //user not yet selected widgets
+      hlayout1->addWidget(userIcon);
     vlayout->addLayout(hlayout1);
-      hlayout2->addWidget(pushViewPassword);   
-      hlayout2->addWidget(linePassword);
+    vlayout->addWidget(listUserBig);
+    //User selected widgets
+      flayout->addRow(pushUserIcon, listUsers);
+      flayout->addRow(pushViewPassword, linePassword);
+    vlayout->addLayout(flayout);
+      hlayout2->addWidget(pushLogin);
     vlayout->addLayout(hlayout2);
-  layout->addLayout(vlayout,0,0);
-  layout->addWidget(pushLogin,0,1);
+    
   //Setup the Signals/Slots
   connect(pushLogin,SIGNAL(clicked()),this,SLOT(slotTryLogin()));
   connect(pushUserIcon,SIGNAL(triggered(QAction*)), this, SLOT(slotUserActivated(QAction*)));
+  connect(userIcon,SIGNAL(triggered(QAction*)), this, SLOT(slotUserActivated(QAction*)));
   connect(pushViewPassword,SIGNAL(pressed()),this,SLOT(slotChangePWView()));
   connect(pushViewPassword,SIGNAL(released()),this,SLOT(slotChangePWView()));
   connect(listUsers,SIGNAL(activated(int)),this,SLOT(slotChooseUser(int)));
+  connect(listUserBig,SIGNAL(itemClicked(QListWidgetItem*)),this,SLOT(slotUserClicked(QListWidgetItem*)) );
   
   //Set this layout for the loginWidget
-  this->setLayout(layout);
+  this->setLayout(vlayout);
   
   //Run the display setup to ensure appropriate visiblility/usage
   updateWidget();
@@ -69,10 +81,18 @@
 void LoginWidget::updateWidget(){
   //Setup the visibility/sizes
   if(userSelected){
+    userIcon->setVisible(FALSE);
+    listUserBig->setVisible(FALSE);
+    pushUserIcon->setVisible(TRUE);
+    listUsers->setVisible(TRUE);
     linePassword->setVisible(TRUE);
     pushLogin->setVisible(TRUE);
     pushViewPassword->setVisible(TRUE);
   }else{
+    userIcon->setVisible(TRUE);
+    listUserBig->setVisible(TRUE);
+    pushUserIcon->setVisible(FALSE);
+    listUsers->setVisible(FALSE);
     linePassword->setVisible(FALSE);
     pushLogin->setVisible(FALSE);
     pushViewPassword->setVisible(FALSE);    
@@ -113,6 +133,10 @@
     }
 }
 
+void LoginWidget::slotUserClicked(QListWidgetItem* item){
+  slotUserSelected();	
+}
+
 void LoginWidget::slotTryLogin(){
   QString user = listUsers->currentText();
   QString pw = linePassword->text();
@@ -125,6 +149,11 @@
 }
 
 void LoginWidget::slotUserSelected(){
+  if(userSelected){ //make sure the big user widget is updated as well
+    listUserBig->setCurrentRow( listUsers->currentIndex() );
+  }else{ //make sure the small user widget is updated as well
+    listUsers->setCurrentIndex( listUserBig->currentRow() );
+  }
   userSelected = TRUE;
   pwVisible = FALSE;
   linePassword->clear(); //make sure the password is cleared if the user is changed
@@ -138,7 +167,7 @@
   pwVisible = FALSE;
   linePassword->clear(); //make sure the password is cleared if the user is changed
   updateWidget();
-  listUsers->setFocus();
+  listUserBig->setFocus();
   emit UserSelected("");
 }
 
@@ -171,15 +200,24 @@
     return;
   }else{
     listUsers->setCurrentIndex(index);
+    listUserBig->setCurrentRow(index);
   }
 }
 
 void LoginWidget::setUsernames(QStringList uList){
+  //Make sure that the two user widgets are identical
   listUsers->clear();
   listUsers->addItems(uList);
+  listUserBig->clear();
+  listUserBig->addItems(uList);
   idL.clear();
   idL = uList; //save for later
   listUsers->setCurrentIndex(0);
+  listUserBig->setCurrentRow(0);
+  //Automatically select the user if there is only one
+  if(idL.length() == 1){
+    slotUserSelected();	  
+  }
 }
 
 void LoginWidget::displayHostName(QString name){
@@ -190,7 +228,9 @@
   if(!QFile::exists(iconFile)){ qDebug() << "LoginWidget: invalid image file"<<iconFile; return; }
   if(button.toLower() == "display"){ 
     pushUserIcon->setIcon(QIcon(iconFile));
-    pushUserIcon->setIconSize(iconSize);  	  
+    pushUserIcon->setIconSize(iconSize);
+    userIcon->setIcon(QIcon(iconFile));
+    userIcon->setIconSize(iconSize);
   }else if(button.toLower() == "login"){ 
     pushLogin->setIcon(QIcon(iconFile));
     pushLogin->setIconSize(iconSize);
@@ -216,16 +256,16 @@
 void LoginWidget::retranslateUi(){
   //Set all the text for the widget (to easily allow changing the locale)
   pushUserIcon->setText(tr("Select"));	
-  if(userSelected){
-    pushUserIcon->setToolTip(tr("Select an alternate user and clear the password field"));
-  }else{
-    pushUserIcon->setToolTip(tr("Select this user"));
-  }
+  pushUserIcon->setToolTip(tr("Select an alternate user and clear the password field"));
+  userIcon->setText(tr("Select"));
+  userIcon->setToolTip(tr("Select this user"));
+ 
   pushLogin->setText(tr("Login"));
   pushLogin->setToolTip(tr("Login to the system with the current user and password"));
   pushViewPassword->setText(tr("Password"));
   pushViewPassword->setToolTip(tr("Hold to view the currently entered password"));
   listUsers->setToolTip(tr("Available users"));
+  listUserBig->setToolTip(tr("Available users"));
   linePassword->setToolTip(tr("Login password for the selected user"));
   //Setup the computer/host name display
   if( hostName.isEmpty() ){
@@ -237,12 +277,13 @@
 
 void LoginWidget::resetFocus(QString item){
   if(item == "userlist"){
-    listUsers->setFocus();
+    if(userSelected){ listUsers->setFocus(); }
+    else{ listUserBig->setFocus(); }
   }else if(item == "password"){
     linePassword->setFocus();
   }else{
     //By default, de-select the user and set focus on the user selection
-    listUsers->setFocus();
-    slotUserUnselected();
+    slotUserUnselected();    
+    listUserBig->setFocus();
   }
 }

Modified: pcbsd-projects/PCDM/loginWidget.h
===================================================================
--- pcbsd-projects/PCDM/loginWidget.h	2013-03-01 13:00:03 UTC (rev 21679)
+++ pcbsd-projects/PCDM/loginWidget.h	2013-03-01 17:32:18 UTC (rev 21680)
@@ -15,7 +15,7 @@
 #include <QFile>
 #include <QPushButton>
 #include <QToolButton>
-#include <QGridLayout>
+#include <QFormLayout>
 #include <QPixmap>
 #include <QDebug>
 #include <QLabel>
@@ -24,6 +24,8 @@
 #include <QKeyEvent>
 #include <QAction>
 #include <QGroupBox>
+#include <QListWidget>
+#include <QAbstractItemView>
 
 class LoginWidget : public QGroupBox
 {
@@ -50,10 +52,12 @@
   
   private:
   	QComboBox* listUsers;
+  	QListWidget* listUserBig;
   	QLineEdit* linePassword;
 	QToolButton* pushLogin;
 	QToolButton* pushViewPassword;
-	QToolButton* pushUserIcon;
+	QToolButton *pushUserIcon, *userIcon;
+	
 
 	QStringList idL;
         QString hostName;
@@ -63,6 +67,7 @@
 
   private slots:
 	void slotUserActivated(QAction*);
+	void slotUserClicked(QListWidgetItem*);
 	void slotUserSelected();
 	void slotUserUnselected();
   	void slotTryLogin();

Modified: pcbsd-projects/PCDM/pcdm-gui.cpp
===================================================================
--- pcbsd-projects/PCDM/pcdm-gui.cpp	2013-03-01 13:00:03 UTC (rev 21679)
+++ pcbsd-projects/PCDM/pcdm-gui.cpp	2013-03-01 17:32:18 UTC (rev 21680)
@@ -47,7 +47,7 @@
     }
   }
   //Load the data from the last successful login
-  loadLastLogin();
+  loadLastUser();
   
 }
 
@@ -177,7 +177,8 @@
     //Connect the signals/slots
     connect(loginW,SIGNAL(loginRequested(QString,QString)),this,SLOT(slotStartLogin(QString,QString)));
     connect(loginW,SIGNAL(escapePressed()),this,SLOT(slotShutdownComputer()));
-    
+    connect(loginW,SIGNAL(UserSelected(QString)), this, SLOT(slotUserChanged(QString)) );
+    	    
     //----Desktop Environment Switcher
     //Create the switcher
     deSwitcher = new FancySwitcher(this, !currentTheme->itemIsVertical("desktop") );
@@ -250,6 +251,22 @@
   toolbar->setEnabled(TRUE);
 }
 
+void PCDMgui::slotUserChanged(QString newuser){
+  if(newuser.isEmpty()){
+    deSwitcher->setVisible(FALSE);
+  }else{
+    deSwitcher->setVisible(TRUE);
+    //Try to load the user's last DE
+    loadLastDE(newuser);
+    //Try to load the custom user icon
+    QString tmpIcon = Backend::getUserHomeDir(newuser) + "/.loginImage.png";
+    if(!QFile::exists(tmpIcon) ){ tmpIcon= currentTheme->itemIcon("user"); }
+    if(!QFile::exists(tmpIcon) || tmpIcon.isEmpty() ){ tmpIcon=":/images/user.png"; }
+    loginW->changeButtonIcon("display",tmpIcon, currentTheme->itemIconSize("user"));
+  }
+  retranslateUi();
+}
+
 void PCDMgui::slotShutdownComputer(){
   QMessageBox verify;
   verify.setWindowTitle(tr("System Shutdown"));
@@ -399,9 +416,8 @@
 
 }
 
-void PCDMgui::loadLastLogin(){
+void PCDMgui::loadLastUser(){
   lastUser.clear();
-  lastDE.clear();
   if(!QFile::exists("/usr/local/share/PCDM/.lastlogin")){
     Backend::log("PCDM: No previous login data found");
   }else{
@@ -412,20 +428,46 @@
     }else{
       QTextStream in(&file);
       lastUser= in.readLine();
+      file.close();
+    }
+  }
+}
+
+void PCDMgui::loadLastDE(QString user){
+  lastDE.clear();
+  QString LLpath = Backend::getUserHomeDir(user) + "/.lastlogin";
+  if(!QFile::exists(LLpath)){
+    Backend::log("PCDM: No previous user login data found for user: "+user);
+  }else{
+    //Load the previous login data
+    QFile file(LLpath);
+    if(!file.open(QIODevice::ReadOnly | QIODevice::Text)){
+      Backend::log("PCDM: Unable to open previous user login file: "+user);    
+    }else{
+      QTextStream in(&file);
       lastDE= in.readLine();
       file.close();
     }
   }
+
 }
 
 void PCDMgui::saveLastLogin(QString USER, QString DE){
-  QFile file("/usr/local/share/PCDM/.lastlogin");
-  if(!file.open(QIODevice::Truncate | QIODevice::WriteOnly | QIODevice::Text)){
+  QFile file1("/usr/local/share/PCDM/.lastlogin");
+  if(!file1.open(QIODevice::Truncate | QIODevice::WriteOnly | QIODevice::Text)){
     Backend::log("PCDM: Unable to save last login data");	  
   }else{
-    QTextStream out(&file);
-    out << USER << "\n" << DE;
-    file.close();
+    QTextStream out(&file1);
+    out << USER;
+    file1.close();
   }
+  QFile file2( Backend::getUserHomeDir(USER) + "/.lastlogin" );
+  if(!file2.open(QIODevice::Truncate | QIODevice::WriteOnly | QIODevice::Text)){
+    Backend::log("PCDM: Unable to save last login data for user:"+USER);	  
+  }else{
+    QTextStream out(&file2);
+    out << DE;
+    file2.close();
+  }
 }
 

Modified: pcbsd-projects/PCDM/pcdm-gui.h
===================================================================
--- pcbsd-projects/PCDM/pcdm-gui.h	2013-03-01 13:00:03 UTC (rev 21679)
+++ pcbsd-projects/PCDM/pcdm-gui.h	2013-03-01 17:32:18 UTC (rev 21680)
@@ -45,6 +45,7 @@
 
 private slots:
     void slotStartLogin(QString,QString);
+    void slotUserChanged(QString);
     void slotRestartComputer();
     void slotShutdownComputer();
     void slotClosePCDM();
@@ -74,7 +75,8 @@
     void createGUIfromTheme();
     void retranslateUi();
     void loadTheme();
-    void loadLastLogin();
+    void loadLastUser();
+    void loadLastDE(QString);
     void saveLastLogin(QString, QString);
 
 signals:



More information about the Commits mailing list