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

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

Update PCDMd, add option to enable TCP listen, off by default

Also fix up main.cpp, make sure we set the screen resolution correctly, that
way we always come back to a full-screen widget

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