source: src-qt4/PCDM/src/main.cpp @ 4018e43

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

Update the PCDM splash screen, and finish adjusting the toolbar size.
Allow PCDM to detect when the system is shutting down, and show the splash screen until the shutdown procedure closes the program (30 sec max wait).

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