Diffstat (limited to 'noncore/settings/usermanager/groupdialog.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/settings/usermanager/groupdialog.cpp | 106 |
1 files changed, 106 insertions, 0 deletions
diff --git a/noncore/settings/usermanager/groupdialog.cpp b/noncore/settings/usermanager/groupdialog.cpp new file mode 100644 index 0000000..b595d31 --- a/dev/null +++ b/noncore/settings/usermanager/groupdialog.cpp | |||
@@ -0,0 +1,106 @@ | |||
1 | /*************************************************************************** | ||
2 | * * | ||
3 | * This program is free software; you can redistribute it and/or modify * | ||
4 | * it under the terms of the GNU General Public License as published by * | ||
5 | * the Free Software Foundation; either version 2 of the License, or * | ||
6 | * (at your option) any later version. * | ||
7 | * * | ||
8 | ***************************************************************************/ | ||
9 | |||
10 | #include "groupdialog.h" | ||
11 | |||
12 | #include <qlabel.h> | ||
13 | #include <qlayout.h> | ||
14 | #include <qmessagebox.h> | ||
15 | |||
16 | #include <stdlib.h> | ||
17 | |||
18 | #include "passwd.h" | ||
19 | |||
20 | GroupDialog::GroupDialog(QWidget* parent, const char* name, bool modal, WFlags fl) : QDialog(parent, name, modal, fl) { | ||
21 | // GID | ||
22 | QLabel *gidLabel=new QLabel(this,"gid: "); | ||
23 | gidLabel->setText("GroupID: "); | ||
24 | gidLineEdit=new QLineEdit(this,"gid: "); | ||
25 | gidLineEdit->setEnabled(false); | ||
26 | |||
27 | // Groupname | ||
28 | QLabel *groupnameLabel=new QLabel(this,"groupname"); | ||
29 | groupnameLabel->setText("Groupname: "); | ||
30 | groupnameLineEdit=new QLineEdit(this,"groupname"); | ||
31 | |||
32 | // Widget layout | ||
33 | QVBoxLayout *layout=new QVBoxLayout(this); | ||
34 | layout->setMargin(5); | ||
35 | QHBoxLayout *hlayout=new QHBoxLayout(-1,"hlayout"); | ||
36 | layout->addLayout(hlayout); | ||
37 | QVBoxLayout *vlayout1=new QVBoxLayout(-1,"vlayout1"); | ||
38 | QVBoxLayout *vlayout2=new QVBoxLayout(-1,"vlayout2"); | ||
39 | // First column, labels | ||
40 | vlayout1->addWidget(gidLabel); | ||
41 | vlayout1->addWidget(groupnameLabel); | ||
42 | // Second column, data | ||
43 | vlayout2->addWidget(gidLineEdit); | ||
44 | vlayout2->addWidget(groupnameLineEdit); | ||
45 | hlayout->addLayout(vlayout1); | ||
46 | hlayout->addLayout(vlayout2); | ||
47 | layout->addSpacing(5); | ||
48 | |||
49 | //showMaximized(); | ||
50 | } | ||
51 | |||
52 | GroupDialog::~GroupDialog() { | ||
53 | } | ||
54 | |||
55 | bool GroupDialog::addGroup(int gid) { | ||
56 | GroupDialog *addgroupDialog=new GroupDialog();// Make a groupinfo dialog. | ||
57 | addgroupDialog->setCaption(tr("Add Group"));// Set the caption. | ||
58 | addgroupDialog->gidLineEdit->setText(QString::number(gid));// Set the next available gid. | ||
59 | if(!(addgroupDialog->exec())) return false;// View the dialog, and only continue if 'ok' was pressed. | ||
60 | if(!(accounts->addGroup(addgroupDialog->groupnameLineEdit->text(),addgroupDialog->gidLineEdit->text().toInt()))) {// Try to add the group. | ||
61 | QMessageBox::information(0,"Ooops!","Something went wrong.\nUnable to add group."); | ||
62 | return false; | ||
63 | } | ||
64 | return true; | ||
65 | } | ||
66 | |||
67 | bool GroupDialog::editGroup(int gid) { | ||
68 | GroupDialog *addgroupDialog=new GroupDialog();// Create the groupinfo dialog. | ||
69 | accounts->findGroup(gid);// Locate the group in the database, and fill out the variables in 'accounts'. | ||
70 | // Fill out the widgets with previous data for this group. | ||
71 | addgroupDialog->setCaption(tr("Edit Group")); | ||
72 | addgroupDialog->gidLineEdit->setText(QString::number(accounts->gr_gid)); | ||
73 | addgroupDialog->groupnameLineEdit->setText(accounts->gr_name); | ||
74 | if(!(addgroupDialog->exec())) return false;// View the dialog, and only continue if 'ok' was pressed. | ||
75 | accounts->findGroup(gid);// Locate the group, and fill out the variables in 'accounts' with all info about the group. | ||
76 | accounts->gr_name=addgroupDialog->groupnameLineEdit->text();// Change the name | ||
77 | accounts->gr_gid=addgroupDialog->gidLineEdit->text().toInt();// Change the GID. (Unneeded as its disabled right now.) | ||
78 | accounts->updateGroup(gid);// Update the database with the variables (gr_name,gr_gid,gr_mem) in 'accounts'. | ||
79 | return true; | ||
80 | } | ||
81 | |||
82 | bool GroupDialog::delGroup(const char *groupname) { | ||
83 | if((accounts->findGroup(groupname))) {// Does this group exist? | ||
84 | if(!(accounts->delGroup(groupname))) {// Try to delete it. | ||
85 | QMessageBox::information(0,"Ooops!","Something went wrong\nUnable to delete group: "+QString(groupname)+"."); | ||
86 | } | ||
87 | } else { | ||
88 | QMessageBox::information(0,"Invalid Groupname","That groupname ("+QString(groupname)+")does not exist."); | ||
89 | return false; | ||
90 | } | ||
91 | return true; | ||
92 | } | ||
93 | |||
94 | void GroupDialog::accept() { | ||
95 | // Check if gid is already taken. | ||
96 | //if((accounts->findGroup(gidLineEdit->text().toInt()))) { | ||
97 | // QMessageBox::information(this,"GroupID taken","That GroupID is already taken."); | ||
98 | // return; | ||
99 | //} | ||
100 | // Check if groupname is already taken. | ||
101 | if((accounts->findGroup(groupnameLineEdit->text()))) { | ||
102 | QMessageBox::information(0,"Groupname taken","That groupname is already taken."); | ||
103 | return;// Don't close the dialog. | ||
104 | } | ||
105 | QDialog::accept(); | ||
106 | } | ||