source: src-qt4/PCDM/src/main.cpp @ ab9281c

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

Initial import of PC-BSD /current/ SVN repo

  • Property mode set to 100644
File size: 4.4 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
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")
22
23//Make sure that prefix is set
24//#ifndef prefix
25//#define prefix "/usr/local/"
26//#endif
27
28int main(int argc, char *argv[])
29{
30  int returnCode = 0;
31  //QTime clock;
32  //clock.start();
33  Backend::checkLocalDirs();  // Create and fill "/usr/local/share/PCDM" if needed
34  Backend::openLogFile("/usr/local/share/PCDM/PCDM.log"); 
35  //qDebug() << "Backend Checks Finished:" << QString::number(clock.elapsed())+" ms";
36  //Check for the flag to try and auto-login
37  bool ALtriggered = FALSE;
38  if(QString(argv[1]) == "-AutoLogin"){ ALtriggered=TRUE; }
39 
40  QString changeLang; 
41  // Load the configuration file
42  QString confFile = "/usr/local/share/PCDM/pcdm.conf";
43  if(!QFile::exists(confFile)){ confFile = ":samples/pcdm.conf"; }
44  Config::loadConfigFile(confFile);
45  //qDebug() << "Config File Loaded:" << QString::number(clock.elapsed())+" ms";
46  // Startup the main application
47  QApplication a(argc,argv); 
48 
49  // Show our splash screen, so the user doesn't freak that that it takes a few seconds to show up
50  QSplashScreen splash;
51  if(!Config::splashscreen().isEmpty()){
52    splash.setPixmap( QPixmap(Config::splashscreen()) ); //load the splashscreen file
53  }
54  splash.show();
55  //qDebug() << "SplashScreen Started:" << QString::number(clock.elapsed())+" ms";
56  //Initialize the xprocess
57  XProcess desktop;
58 
59  //*** STARTUP THE PROGRAM ***
60  bool goodAL = FALSE; //Flag for whether the autologin was successful
61 
62  // Start the autologin procedure if applicable
63  if( ALtriggered && Config::useAutoLogin() ){
64    //Setup the Auto Login
65    QString user = Backend::getALUsername();
66    QString dcmd = Backend::getALDesktopCmd();
67    QString pwd = Backend::getALPassword();
68    if( user.isEmpty() || dcmd.isEmpty() ){
69         goodAL=FALSE;   
70    }else{
71        desktop.loginToXSession(user,pwd, Backend::getUserHomeDir(user), dcmd);
72        splash.close();
73        if(desktop.isRunning()){
74          goodAL=TRUE; //flag this as a good login to skip the GUI
75        }
76    }
77  }
78  //qDebug() << "AutoLogin Finished:" << QString::number(clock.elapsed())+" ms";
79  if(!goodAL){
80    // ------START THE PCDM GUI-------
81   
82    // Check what directory our app is in
83    QString appDir = "/usr/local/share/PCDM";
84    // Load the translator
85    QTranslator translator;
86    QLocale mylocale;
87    QString langCode = mylocale.name();
88    //Check for a language change detected
89    if ( ! changeLang.isEmpty() )       
90       langCode = changeLang;
91    //Load the proper locale for the translator
92    if ( QFile::exists(appDir + "/i18n/PCDM_" + langCode + ".qm" ) ) {
93      translator.load( QString("PCDM_") + langCode, appDir + "/i18n/" );
94      a.installTranslator(&translator);
95      Backend::log("Loaded Translation:" + appDir + "/i18n/PCDM_" + langCode + ".qm");
96    } else {
97      Backend::log("Could not find: " + appDir + "/i18n/PCDM_" + langCode + ".qm");
98      langCode = "";
99    }
100    //qDebug() << "Translation Finished:" << QString::number(clock.elapsed())+" ms";
101
102    Backend::log("Starting up PCDM interface");
103    PCDMgui w;
104    //qDebug() << "Main GUI Created:" << QString::number(clock.elapsed())+" ms";
105    splash.finish(&w); //close the splash when the GUI starts up
106    //Set the proper size on the Application
107      w.setWindowFlags(w.windowFlags() ^Qt::WindowSoftkeysVisibleHint);
108      w.setWindowState(Qt::WindowFullScreen);
109
110    //Setup the signals/slots to startup the desktop session
111    QObject::connect( &w,SIGNAL(xLoginAttempt(QString,QString,QString,QString)), &desktop,SLOT(loginToXSession(QString,QString,QString,QString)) );
112    //Setup the signals/slots for return information for the GUI
113    QObject::connect( &desktop, SIGNAL(InvalidLogin()), &w, SLOT(slotLoginFailure()) );
114    QObject::connect( &desktop, SIGNAL(started()), &w, SLOT(slotLoginSuccess()) );
115   
116    //qDebug() << "Showing GUI:" << QString::number(clock.elapsed())+" ms";
117    w.show();
118    returnCode = a.exec();
119
120  }  // end of PCDM GUI running
121 
122  //Wait for the desktop session to finish before exiting
123  desktop.waitForSessionClosed();
124 
125  return returnCode;
126}
Note: See TracBrowser for help on using the repository browser.