1 /***************************************************************************
2 * Copyright (C) 2007 by Juan González Aguilera *
3 * (kde_devel@opsiland.info) *
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. *
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. *
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>
29 OptionsDialog::OptionsDialog ( QWidget
* parent
, Qt::WFlags fl
)
30 : QDialog ( parent
, fl
), Ui::OptionsDialog()
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());
39 QObject::connect(selectBasedirButton
,SIGNAL(clicked( bool )),this,SLOT(selectBasedirSlot()));
42 OptionsDialog::~OptionsDialog()
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
);
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
)
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");
72 QMessageBox::warning(this,"Failure","Imposible to add group:\n" + proc
.readAllStandardError());
76 QDir
dir(baseDirName
);
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
);
85 QMessageBox::warning(this,"Failure","Imposible to create directory");
88 } else if(groupStuffOk
) {
89 settings
.setValue("baseDir",baseDirName
);
92 if(groupStuffOk
&& baseDirOk
)
97 void OptionsDialog::selectBasedirSlot()
99 QString file
= QFileDialog::getExistingDirectory(this,"Select the base directory",baseDir
->text());
101 baseDir
->setText(file
);