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

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

Set the default theme to use the "simple" desktop switcher, and disable the virtual keyboard button for now (need to figure out why it is not working right now)

  • Property mode set to 100644
File size: 5.1 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
121  }  // end of PCDM GUI running
122 
123  //Wait for the desktop session to finish before exiting
124  desktop.waitForSessionClosed();
125 
126  //Clean up Code
127  delete &desktop;
128  delete &a;
129  delete &splash;
130  //XSetCloseDownMode(QX11Info::display(), DestroyAll);
131  //XCLoseDisplay(QX11Info::display());
132 
133 
134  return 0;
135}
136
137int main(int argc, char *argv[])
138{
139 bool neverquit = TRUE;
140 bool runonce = FALSE;
141 if(argc==2){ if( QString(argv[1]) == "--once"){ runonce = TRUE; } }
142 
143 while(neverquit){
144  if(runonce){ neverquit = FALSE; }
145  qDebug() << " -- PCDM Session Starting...";
146  int retCode = runSingleSession(argc,argv);
147  if(retCode != 0){ neverquit=FALSE; }
148 }
149 return 0;
150}
Note: See TracBrowser for help on using the repository browser.