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

9.1-release9.2-releasereleng/10.0releng/10.0.1releng/10.0.2releng/10.0.3
Last change on this file since 1620346 was 1620346, checked in by Kris Moore <kris@…>, 17 months ago

Initial import of PC-BSD /current/ SVN repo

  • Property mode set to 100644
File size: 3.5 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
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  return;
27}
28
29void Config::readConfigFile(QString filePath){
30  QFile conf(filePath);
31  bool ok = conf.open(QIODevice::ReadOnly | QIODevice::Text);
32  if(!ok){ 
33    Backend::log("Could not open configuration file: "+filePath+"\nLoading default configuration");
34    if(filePath!=":samples/pcdm.conf"){ readConfigFile(":samples/pcdm.conf"); }
35    return;
36  }
37  QTextStream in(&conf);
38  while( !in.atEnd() ){
39    QString line = in.readLine().simplified();
40    //Skip comment lines
41    if(!line.startsWith("#")){
42      line = line.section("#",0,0).simplified(); //cut any comments off the end of the line
43      QString var = line.section("=",0,0).simplified(); // get the variable
44      QString val = line.section("=",1,1).simplified(); // get the value
45     
46      //Parse the Configuration File
47      if(var=="THEME_FILE"){ confStruct[0] = val; }
48      else if(var=="DE_STARTUP_DIR"){ confStruct[1] = val; }
49      else if(var=="DE_STARTUP_IMAGE_DIR"){ confStruct[2] = val; }
50      else if(var=="ENABLE_AUTO_LOGIN"){ confStruct[3] = val; }
51      else if(var=="AUTO_LOGIN_USER"){ confStruct[4] = val; }
52      else if(var=="AUTO_LOGIN_DESKTOP"){ confStruct[5] = val; }
53      else if(var=="AUTO_LOGIN_PASSWORD"){ confStruct[6] = val; }
54      else if(var=="SPLASHSCREEN_FILE"){ confStruct[7] = val; }
55      else if(var=="ENABLE_VIEW_PASSWORD_BUTTON"){ confStruct[8] = val; }
56      else{}
57     
58    }
59  }
60  conf.close();
61}
62
63//******** PUBLIC FUNCTIONS **************
64void Config::loadConfigFile(QString filePath){
65  loadDefaults();
66  if(!QFile::exists(filePath)){
67    Backend::log("Configuration file does not exist: "+filePath+"\nLoading default configuration");
68    filePath=":samples/pcdm.conf";
69  }
70  readConfigFile(filePath);
71}
72
73QString Config::themeFile(){
74  return confStruct[0];
75}
76
77QString Config::xSessionsDir(){
78  return confStruct[1];
79}
80
81QString Config::xSessionsImageDir(){
82  return confStruct[2];
83}
84
85bool Config::useAutoLogin(){
86  //qDebug() << "confStruct[3]:" << confStruct[3];
87  if(confStruct[3].toLower()=="true"){ return TRUE; }
88  else{ return FALSE; } 
89}
90
91QString Config::autoLoginUsername(){
92  return confStruct[4]; 
93}
94
95QString Config::autoLoginDesktop(){
96  if(confStruct.startsWith("/")){  return confStruct[5]; } //already an absolute path
97  else{ return (confStruct[1]+"/"+confStruct[5]); } //prepend the xsessions directory path
98}
99
100QString Config::autoLoginPassword(){
101  return confStruct[6]; 
102}
103
104QString Config::splashscreen(){
105  return confStruct[7]; 
106}
107
108bool Config::allowPasswordView(){
109  if(confStruct[8].toLower()=="true"){ return TRUE; }
110  else{ return FALSE; } 
111}
112
Note: See TracBrowser for help on using the repository browser.