source: src-qt4/PCDM/src/main.cpp @ 6e8238f

9.2-releasereleng/10.0releng/10.0.1releng/10.0.2releng/10.0.3releng/10.1
Last change on this file since 6e8238f was 6e8238f, checked in by Ken Moore <ken@…>, 18 months ago

Clean up the PCDM autostart functionality a bit, as well as the restart daemon

  • Property mode set to 100644
File size: 4.5 KB
RevLine 
[1620346]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
16#include "pcdm-gui.h"
17#include "pcdm-backend.h"
18#include "pcdm-config.h"
19#include "pcdm-xprocess.h"
20
21#define TMPLANGFILE QString("/tmp/.PCDMLang")
[6e8238f]22#define TMPAUTOLOGINFILE QString("/tmp/.PCDMAutoLogin")
[1620346]23
24//Make sure that prefix is set
25//#ifndef prefix
26//#define prefix "/usr/local/"
27//#endif
28
29int main(int argc, char *argv[])
30{
31  int returnCode = 0;
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;
[6e8238f]39  if(QFile::exists(TMPAUTOLOGINFILE)){ ALtriggered=TRUE; QFile::remove(TMPAUTOLOGINFILE); }
[1620346]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(w.windowFlags() ^Qt::WindowSoftkeysVisibleHint);
109      w.setWindowState(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    returnCode = a.exec();
120
121  }  // end of PCDM GUI running
122 
123  //Wait for the desktop session to finish before exiting
124  desktop.waitForSessionClosed();
125 
126  return returnCode;
127}
Note: See TracBrowser for help on using the repository browser.