source: src-qt4/PCDM/src/pcdm-config.cpp @ 28c79ad

releng/10.0.1releng/10.0.2releng/10.0.3
Last change on this file since 28c79ad was 28c79ad, checked in by Ken Moore <ken@…>, 7 months ago

Add an auto-login delay function for PCDM that defaults to 10 seconds. This will pop-up a window giving the user the specified amount of time to either cancel the auto-login or immediately continue on.

  • Property mode set to 100644
File size: 3.8 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 "pcdm-config.h"
8#include "pcdm-backend.h"
9
10//Setup variables that save the current configuration data
11QStringList confStruct;
12
13
14//******** PRIVATE FUNCTIONS *************
15void Config::loadDefaults(){
16  confStruct.clear();
17  confStruct << "/usr/local/share/PCDM/pcdm.theme";     // [0] Theme File Path
18  confStruct << "/usr/local/share/xsessions";           // [1] *.desktop files directory
19  confStruct << "/usr/local/share/pixmaps";             // [2] Images directory for *.desktop icons
20  confStruct << "FALSE";                                // [3] Auto-login enabled
21  confStruct << "no-username";                          // [4] Auto-login username
22  confStruct << "no-desktop";                           // [5] Auto-login desktop environment (legacy)
23  confStruct << "no-password";                          // [6] Auto-login password
24  confStruct << "/usr/local/share/PCDM/images/default-splash.png"; // [7] Splash Screen File
25  confStruct << "TRUE";                                 // [8] Password view button enabled
26  confStruct << "10";                                           // [9] Auto-login delay (seconds)
27  return;
28}
29
30void Config::readConfigFile(QString filePath){
31  QFile conf(filePath);
32  bool ok = conf.open(QIODevice::ReadOnly | QIODevice::Text);
33  if(!ok){ 
34    Backend::log("Could not open configuration file: "+filePath+"\nLoading default configuration");
35    if(filePath!=":samples/pcdm.conf"){ readConfigFile(":samples/pcdm.conf"); }
36    return;
37  }
38  QTextStream in(&conf);
39  while( !in.atEnd() ){
40    QString line = in.readLine().simplified();
41    //Skip comment lines
42    if(!line.startsWith("#")){
43      line = line.section("#",0,0).simplified(); //cut any comments off the end of the line
44      QString var = line.section("=",0,0).simplified(); // get the variable
45      QString val = line.section("=",1,1).simplified(); // get the value
46     
47      //Parse the Configuration File
48      if(var=="THEME_FILE"){ confStruct[0] = val; }
49      else if(var=="DE_STARTUP_DIR"){ confStruct[1] = val; }
50      else if(var=="DE_STARTUP_IMAGE_DIR"){ confStruct[2] = val; }
51      else if(var=="ENABLE_AUTO_LOGIN"){ confStruct[3] = val; }
52      else if(var=="AUTO_LOGIN_USER"){ confStruct[4] = val; }
53      //else if(var=="AUTO_LOGIN_DESKTOP"){ confStruct[5] = val; } //legacy option
54      else if(var=="AUTO_LOGIN_PASSWORD"){ confStruct[6] = val; }
55      else if(var=="SPLASHSCREEN_FILE"){ confStruct[7] = val; }
56      else if(var=="ENABLE_VIEW_PASSWORD_BUTTON"){ confStruct[8] = val; }
57      else if(var=="AUTO_LOGIN_DELAY"){ confStruct[9] = val; }
58      else{}
59     
60    }
61  }
62  conf.close();
63}
64
65//******** PUBLIC FUNCTIONS **************
66void Config::loadConfigFile(QString filePath){
67  loadDefaults();
68  if(!QFile::exists(filePath)){
69    Backend::log("Configuration file does not exist: "+filePath+"\nLoading default configuration");
70    filePath=":samples/pcdm.conf";
71  }
72  readConfigFile(filePath);
73}
74
75QString Config::themeFile(){
76  return confStruct[0];
77}
78
79QString Config::xSessionsDir(){
80  return confStruct[1];
81}
82
83QString Config::xSessionsImageDir(){
84  return confStruct[2];
85}
86
87bool Config::useAutoLogin(){
88  //qDebug() << "confStruct[3]:" << confStruct[3];
89  if(confStruct[3].toLower()=="true"){ return TRUE; }
90  else{ return FALSE; } 
91}
92
93QString Config::autoLoginUsername(){
94  return confStruct[4]; 
95}
96
97QString Config::autoLoginDesktop(){
98  if(confStruct.startsWith("/")){  return confStruct[5]; } //already an absolute path
99  else{ return (confStruct[1]+"/"+confStruct[5]); } //prepend the xsessions directory path
100}
101
102QString Config::autoLoginPassword(){
103  return confStruct[6]; 
104}
105
106int Config::autoLoginDelay(){
107  return confStruct[9].toInt(); 
108}
109
110QString Config::splashscreen(){
111  return confStruct[7]; 
112}
113
114bool Config::allowPasswordView(){
115  if(confStruct[8].toLower()=="true"){ return TRUE; }
116  else{ return FALSE; } 
117}
118
Note: See TracBrowser for help on using the repository browser.