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 ***************************************************************************/
21 #include "optionsdialog.h"
22 #include "usermanager.h"
23 #include "userpreferences.h"
25 #include <QMessageBox>
31 UserManager::UserManager ( QWidget
* parent
, Qt::WFlags fl
)
32 : QMainWindow ( parent
, fl
), Ui::MainWindow(),settings(new QSettings("opsiland","RFIDUserManager",this))
36 QMessageBox::warning(this,"Not the superuser","Sorry, you must be the superuser to run this program");
40 QObject::connect(addUser
,SIGNAL(clicked( bool )),this,SLOT(addUserSlot()));
41 QObject::connect(editUser
,SIGNAL(clicked( bool )),this,SLOT(editUserSlot()));
42 QObject::connect(rmUser
,SIGNAL(clicked( bool )),this,SLOT(rmUserSlot()));
43 QObject::connect(prefs
,SIGNAL(clicked( bool )),this,SLOT(preferencesSlot()));
44 QObject::connect(userListWidget
,SIGNAL(itemSelectionChanged()),this,SLOT(activarBotonesSlot()));
46 //Check if the app has been already configured
47 settings
->beginGroup("RFID");
48 bool configured
= settings
->value("configured",false).toBool();
53 ops
.setWindowTitle("First run setup!");
54 if(ops
.exec() == QDialog::Accepted
)
56 settings
->beginGroup("RFID");
57 settings
->setValue("configured",true);
64 UserManager::~UserManager()
70 void UserManager::addUserSlot()
72 UserPreferences prefs
;
77 void UserManager::editUserSlot()
79 QList
<QListWidgetItem
*> items
= userListWidget
->selectedItems();
80 UserPreferences
prefs(items
[0]->text());
85 void UserManager::rmUserSlot()
87 QString userName
= userListWidget
->selectedItems()[0]->text();
88 int res
= QMessageBox::question(this,QString("Deleting user %1").arg(userName
),QString("Are you sure you want to remove the %1 user?\n\nTHIS CAN NOT BE UNDONE!!").arg(userName
),QMessageBox::Ok
|QMessageBox::Cancel
);
89 if (res
== QMessageBox::Ok
) {
92 int res
= QMessageBox::question(this,"Remove home directory?","Do you want to remove the user's home directory too?",QMessageBox::Yes
|QMessageBox::No
);
93 if (res
== QMessageBox::Yes
) {
97 proc
.start("userdel",args
);
98 proc
.waitForFinished();
99 if (proc
.exitCode()!=0) {
100 QMessageBox::warning(this,"Failure",QString("Impossible to delete the user:\n%1").arg(QString(proc
.readAllStandardError())));
106 void UserManager::preferencesSlot()
113 void UserManager::activateButtonsSlot()
115 bool enable
= !userListWidget
->selectedItems().isEmpty();
116 rmUser
->setEnabled(enable
);
117 editUser
->setEnabled(enable
);
120 void UserManager::updateUserList()
122 QStringList usersList
;
125 settings
->beginGroup("RFID");
126 QString
rfidGroupName(settings
->value("defaultGroup","rfid").toString());
127 settings
->endGroup();
130 while((p
=getpwent())!=NULL
)
132 QString
userName(p
->pw_name
);
133 g
= getgrgid(p
->pw_gid
);
134 QString
groupName(g
->gr_name
);
135 if(groupName
== rfidGroupName
) {
136 usersList
<< userName
;
140 userListWidget
->clear();
141 userListWidget
->addItems(usersList
);