source: src-qt4/PCDM/src/main.cpp @ 90dc161

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

Completely revamp how PCDM uses the previous login information. Now you no longer need to specify which desktop to auto-login to if you have auto-login selected. It will first try to check for previous login information for that user, then fall back on the last login for the system in order to try and auto login. Also fix the PCDMd script a bit so that autologins work properly when triggered.

  • Property mode set to 100644
File size: 6.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 <QtGui/QApplication>
8#include <QTranslator>
9#include <QLocale>
10#include <QDesktopWidget>
11#include <QFile>
12#include <QSplashScreen>
13#include <QTime>
14#include <QDebug>
15#include <QX11Info>
16//#include <X11/Xlib.h>
17
18#include "pcdm-gui.h"
19#include "pcdm-backend.h"
20#include "pcdm-config.h"
21#include "pcdm-xprocess.h"
22
23#define TMPLANGFILE QString("/tmp/.PCDMLang")
24#define TMPAUTOLOGINFILE QString("/tmp/.PCDMAutoLogin")
25
26//Make sure that prefix is set
27//#ifndef prefix
28//#define prefix "/usr/local/"
29//#endif
30
31int runSingleSession(int argc, char *argv[]){
32  //QTime clock;
33  //clock.start();
34  Backend::checkLocalDirs();  // Create and fill "/usr/local/share/PCDM" if needed
35  Backend::openLogFile("/usr/local/share/PCDM/PCDM.log"); 
36  //qDebug() << "Backend Checks Finished:" << QString::number(clock.elapsed())+" ms";
37  //Check for the flag to try and auto-login
38  bool ALtriggered = FALSE;
39  if(QFile::exists(TMPAUTOLOGINFILE)){ ALtriggered=TRUE; QFile::remove(TMPAUTOLOGINFILE); }
40 
41  QString changeLang; 
42  // Load the configuration file
43  QString confFile = "/usr/local/etc/pcdm.conf";
44  if(!QFile::exists(confFile)){ 
45    qDebug() << "PCDM: Configuration file missing:"<<confFile<<"\n  - Using default configuration";
46    confFile = ":samples/pcdm.conf"; 
47  }
48 
49  Config::loadConfigFile(confFile);
50  //qDebug() << "Config File Loaded:" << QString::number(clock.elapsed())+" ms";
51  // Startup the main application
52  QApplication a(argc,argv); 
53 
54  // Show our splash screen, so the user doesn't freak that that it takes a few seconds to show up
55  QSplashScreen splash;
56  if(!Config::splashscreen().isEmpty()){
57    splash.setPixmap( QPixmap(Config::splashscreen()) ); //load the splashscreen file
58  }
59  splash.show();
60  QCoreApplication::processEvents(); //Process the splash screen event immediately
61  //qDebug() << "SplashScreen Started:" << QString::number(clock.elapsed())+" ms";
62  //Initialize the xprocess
63  XProcess desktop;
64 
65  //*** STARTUP THE PROGRAM ***
66  bool goodAL = FALSE; //Flag for whether the autologin was successful
67  // Start the autologin procedure if applicable
68  if( ALtriggered && Config::useAutoLogin() ){
69    //Setup the Auto Login
70    QString user = Backend::getALUsername();
71    QString pwd = Backend::getALPassword();
72    QString dsk = Backend::getLastDE(user);
73    if( user.isEmpty() || dsk.isEmpty() ){
74         goodAL=FALSE;   
75    }else{
76        desktop.loginToXSession(user,pwd, Backend::getUserHomeDir(user), dsk);
77        splash.close();
78        if(desktop.isRunning()){
79          goodAL=TRUE; //flag this as a good login to skip the GUI
80        }
81    }
82  }
83  //qDebug() << "AutoLogin Finished:" << QString::number(clock.elapsed())+" ms";
84  if(!goodAL){
85    // ------START THE PCDM GUI-------
86   
87    // Check what directory our app is in
88    QString appDir = "/usr/local/share/PCDM";
89    // Load the translator
90    QTranslator translator;
91    QLocale mylocale;
92    QString langCode = mylocale.name();
93    //Check for a language change detected
94    if ( ! changeLang.isEmpty() )       
95       langCode = changeLang;
96    //Load the proper locale for the translator
97    if ( QFile::exists(appDir + "/i18n/PCDM_" + langCode + ".qm" ) ) {
98      translator.load( QString("PCDM_") + langCode, appDir + "/i18n/" );
99      a.installTranslator(&translator);
100      Backend::log("Loaded Translation:" + appDir + "/i18n/PCDM_" + langCode + ".qm");
101    } else {
102      Backend::log("Could not find: " + appDir + "/i18n/PCDM_" + langCode + ".qm");
103      langCode = "";
104    }
105    //qDebug() << "Translation Finished:" << QString::number(clock.elapsed())+" ms";
106
107    Backend::log("Starting up PCDM interface");
108    PCDMgui w;
109    //qDebug() << "Main GUI Created:" << QString::number(clock.elapsed())+" ms";
110    splash.finish(&w); //close the splash when the GUI starts up
111    //Set the proper size on the Application
112      w.setWindowFlags(Qt::Window | Qt::FramelessWindowHint | Qt::WindowStaysOnBottomHint);
113      w.setWindowState(Qt::WindowMaximized); //Qt::WindowFullScreen);
114
115    //Setup the signals/slots to startup the desktop session
116    QObject::connect( &w,SIGNAL(xLoginAttempt(QString,QString,QString,QString)), &desktop,SLOT(loginToXSession(QString,QString,QString,QString)) );
117    //Setup the signals/slots for return information for the GUI
118    QObject::connect( &desktop, SIGNAL(InvalidLogin()), &w, SLOT(slotLoginFailure()) );
119    QObject::connect( &desktop, SIGNAL(started()), &w, SLOT(slotLoginSuccess()) );
120   
121    //qDebug() << "Showing GUI:" << QString::number(clock.elapsed())+" ms";
122    w.show();
123    a.exec();
124  }  // end of PCDM GUI running
125  int retcode = 0;
126  //Wait for the desktop session to finish before exiting
127  desktop.waitForSessionClosed();
128  splash.show(); //show the splash screen again
129  splash.showMessage(QObject::tr("System Shutting Down"), Qt::AlignHCenter | Qt::AlignBottom, Qt::white);
130  //check for shutdown process
131  if(QFile::exists("/var/run/nologin")){
132    //Pause for a few seconds to prevent starting a new session during a shutdown
133    QTime wTime = QTime::currentTime().addSecs(30);
134    while( QTime::currentTime() < wTime ){ 
135      //Keep processing events during the wait (for splashscreen)
136      QCoreApplication::processEvents(QEventLoop::AllEvents, 100); 
137    }
138    //set the return code for a shutdown
139    retcode = -1; //make sure it does not start a new session
140  }
141 
142  //Clean up Code
143  delete &desktop;
144  delete &a;
145  delete &splash;
146  //XSetCloseDownMode(QX11Info::display(), DestroyAll);
147  //XCLoseDisplay(QX11Info::display());
148 
149 
150  return retcode;
151}
152
153int main(int argc, char *argv[])
154{
155 bool neverquit = TRUE;
156 bool runonce = TRUE; //looping is currently not working yet - needs to restart X each time?
157 if(argc==2){ if( QString(argv[1]) == "--once"){ runonce = TRUE; } }
158 
159 while(neverquit){
160  if(runonce){ neverquit = FALSE; }
161  qDebug() << " -- PCDM Session Starting...";
162  int retCode = runSingleSession(argc,argv);
163  if(retCode != 0){ neverquit=FALSE; }
164 }
165 return 0;
166}
Note: See TracBrowser for help on using the repository browser.