- Documentation
[qt_rdw125klib.git] / RFIDUserManager / optionsdialog.cpp
blobb4400ec4c511e15f103ae6365bbce6b3407b1433
1 /***************************************************************************
2 * Copyright (C) 2007 by Juan González Aguilera *
3 * (kde_devel@opsiland.info) *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU Library General Public License as *
7 * published by the Free Software Foundation; either version 2 of the *
8 * License, or (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU Library General Public *
16 * License along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
22 #include "optionsdialog.h"
23 #include <QFileDialog>
24 #include <QMessageBox>
25 #include <QSettings>
26 #include <QProcess>
27 #include <grp.h>
29 OptionsDialog::OptionsDialog ( QWidget* parent, Qt::WFlags fl )
30 : QDialog ( parent, fl ), Ui::OptionsDialog()
32 setupUi ( this );
33 QSettings settings("/etc/rfid.conf",QSettings::NativeFormat);
34 settings.beginGroup("RFID");
35 defaultGroupName->setText(settings.value("defaultGroup","rfid").toString());
36 baseDir->setText(settings.value("baseDir","/home/").toString());
37 settings.endGroup();
39 QObject::connect(selectBasedirButton,SIGNAL(clicked( bool )),this,SLOT(selectBasedirSlot()));
42 OptionsDialog::~OptionsDialog()
46 /*$SPECIALIZATION$*/
48 void OptionsDialog::accept()
50 bool groupStuffOk = false, baseDirOk = false;;
51 QString groupName = defaultGroupName->text();
52 QString baseDirName = baseDir->text();
54 QSettings settings("/etc/rfid.conf",QSettings::NativeFormat);
55 settings.beginGroup("RFID");
56 if (getgrnam(groupName.toStdString().c_str())) {
57 settings.setValue("defaultGroup",groupName);
58 groupStuffOk = true;
59 } else {
60 int res = QMessageBox::question(this,"No such group",QString("Given group (%1) doesn't exist, Do I create it?").arg(groupName),QMessageBox::Ok|QMessageBox::Cancel);
61 if(res == QMessageBox::Ok)
63 QProcess proc;
64 proc.start("groupadd",QStringList(groupName));
65 proc.waitForFinished();
66 if(proc.exitCode() == 0)
68 settings.setValue("defaultGroup",groupName);
69 QMessageBox::information(this,"Success","Group added");
70 groupStuffOk = true;
71 } else {
72 QMessageBox::warning(this,"Failure","Imposible to add group:\n" + proc.readAllStandardError());
76 QDir dir(baseDirName);
77 if (!dir.exists()) {
78 int res = QMessageBox::question(this,"No such base directory",QString("Given direcory (%1) doesn't exist, Do I create it?\n (Note you won't be able to add users until this directory exists and is writable)").arg(baseDirName),QMessageBox::Ok|QMessageBox::Cancel);
79 if (res == QMessageBox::Ok) {
80 if (dir.mkpath(baseDirName)) {
81 QMessageBox::information(this,"Succes","Directory created");
82 settings.setValue("baseDir",baseDirName);
83 baseDirOk = true;
84 } else {
85 QMessageBox::warning(this,"Failure","Imposible to create directory");
88 } else if(groupStuffOk) {
89 settings.setValue("baseDir",baseDirName);
90 baseDirOk = true;
92 if(groupStuffOk && baseDirOk)
93 QDialog::accept();
94 settings.endGroup();
97 void OptionsDialog::selectBasedirSlot()
99 QString file = QFileDialog::getExistingDirectory(this,"Select the base directory",baseDir->text());
100 if(!file.isEmpty())
101 baseDir->setText(file);