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

releng/10.0releng/10.0.1releng/10.0.2releng/10.0.3releng/10.1
Last change on this file since 656891d was 656891d, checked in by Ken Moore <ken@…>, 12 months ago

Make sure that the PCDM toolbar has teh context menu disabled (so the user cannot hide it and not be able to get it back).
Trac Bug# 883

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