source: src-qt4/PCDM/src/main.cpp @ 39fe8b0

9.2-releasereleng/10.0releng/10.0.1releng/10.0.2releng/10.0.3releng/10.1
Last change on this file since 39fe8b0 was 39fe8b0, checked in by Kris Moore <kris@…>, 18 months ago

Update PCDM to use pcdm.conf out of /usr/local/etc/

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