-rw-r--r-- | noncore/settings/usermanager/userdialog.cpp | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/noncore/settings/usermanager/userdialog.cpp b/noncore/settings/usermanager/userdialog.cpp index 892fc8a..f31775d 100644 --- a/noncore/settings/usermanager/userdialog.cpp +++ b/noncore/settings/usermanager/userdialog.cpp | |||
@@ -1,196 +1,196 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | * * | 2 | * * |
3 | * This program is free software; you can redistribute it and/or modify * | 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 * | 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 * | 5 | * the Free Software Foundation; either version 2 of the License, or * |
6 | * (at your option) any later version. * | 6 | * (at your option) any later version. * |
7 | * * | 7 | * * |
8 | ***************************************************************************/ | 8 | ***************************************************************************/ |
9 | 9 | ||
10 | #include "userdialog.h" | 10 | #include "userdialog.h" |
11 | 11 | ||
12 | #include <qlayout.h> | 12 | #include <qlayout.h> |
13 | #include <qlabel.h> | 13 | #include <qlabel.h> |
14 | #include <qmessagebox.h> | 14 | #include <qmessagebox.h> |
15 | 15 | ||
16 | #include <stdlib.h> | 16 | #include <stdlib.h> |
17 | 17 | ||
18 | #include <stdio.h> | 18 | #include <stdio.h> |
19 | #include <sys/types.h> | 19 | #include <sys/types.h> |
20 | #include <sys/wait.h> | 20 | #include <sys/wait.h> |
21 | #include <unistd.h> | 21 | #include <unistd.h> |
22 | #include <signal.h> | 22 | #include <signal.h> |
23 | 23 | ||
24 | #include "passwd.h" | 24 | #include "passwd.h" |
25 | 25 | ||
26 | /** | 26 | /** |
27 | * UserDialog constructor. Setup the dialog, fill the groupComboBox & groupsListView with all groups. | 27 | * UserDialog constructor. Setup the dialog, fill the groupComboBox & groupsListView with all groups. |
28 | * | 28 | * |
29 | */ | 29 | */ |
30 | UserDialog::UserDialog(QWidget* parent, const char* name, bool modal, WFlags fl) : QDialog(parent, name, modal, fl) { | 30 | UserDialog::UserDialog(QWidget* parent, const char* name, bool modal, WFlags fl) : QDialog(parent, name, modal, fl) { |
31 | QVBoxLayout *layout = new QVBoxLayout(this); | 31 | QVBoxLayout *layout = new QVBoxLayout(this); |
32 | myTabWidget=new QTabWidget(this,"User Tab Widget"); | 32 | myTabWidget=new QTabWidget(this,"User Tab Widget"); |
33 | layout->addWidget(myTabWidget); | 33 | layout->addWidget(myTabWidget); |
34 | setupTab1(); | 34 | setupTab1(); |
35 | setupTab2(); | 35 | setupTab2(); |
36 | 36 | ||
37 | // And also fill the listview & the combobox with all available groups. | 37 | // And also fill the listview & the combobox with all available groups. |
38 | for( QStringList::Iterator it = accounts->groupStringList.begin(); it!=accounts->groupStringList.end(); ++it) { | 38 | for( QStringList::Iterator it = accounts->groupStringList.begin(); it!=accounts->groupStringList.end(); ++it) { |
39 | accounts->splitGroupEntry(*it); | 39 | accounts->splitGroupEntry(*it); |
40 | new QListViewItem(groupsListView,accounts->gr_name); | 40 | new QListViewItem(groupsListView,accounts->gr_name); |
41 | groupComboBox->insertItem(accounts->gr_name); | 41 | groupComboBox->insertItem(accounts->gr_name); |
42 | } | 42 | } |
43 | 43 | ||
44 | showMaximized(); | 44 | showMaximized(); |
45 | } | 45 | } |
46 | 46 | ||
47 | /** | 47 | /** |
48 | * Empty destructor. | 48 | * Empty destructor. |
49 | * | 49 | * |
50 | */ | 50 | */ |
51 | UserDialog::~UserDialog() { | 51 | UserDialog::~UserDialog() { |
52 | } | 52 | } |
53 | 53 | ||
54 | /** | 54 | /** |
55 | * Creates the first tab, all userinfo is here. | 55 | * Creates the first tab, all userinfo is here. |
56 | * | 56 | * |
57 | */ | 57 | */ |
58 | void UserDialog::setupTab1() { | 58 | void UserDialog::setupTab1() { |
59 | QPixmap mypixmap; | 59 | QPixmap mypixmap; |
60 | QWidget *tabpage = new QWidget(myTabWidget,"page1"); | 60 | QWidget *tabpage = new QWidget(myTabWidget,"page1"); |
61 | QVBoxLayout *layout = new QVBoxLayout(tabpage); | 61 | QVBoxLayout *layout = new QVBoxLayout(tabpage); |
62 | layout->setMargin(5); | 62 | layout->setMargin(5); |
63 | 63 | ||
64 | // Picture | 64 | // Picture |
65 | picturePushButton = new QPushButton(tabpage,"Label"); | 65 | picturePushButton = new QPushButton(tabpage,"Label"); |
66 | picturePushButton->setMinimumSize(48,48); | 66 | picturePushButton->setMinimumSize(48,48); |
67 | picturePushButton->setMaximumSize(48,48); | 67 | picturePushButton->setMaximumSize(48,48); |
68 | picturePushButton->setPixmap(Resource::loadPixmap("userconfig/usericon"));// Load default usericon. | 68 | picturePushButton->setPixmap(Resource::loadPixmap("usermanager/usericon"));// Load default usericon. |
69 | connect(picturePushButton,SIGNAL(clicked()),this,SLOT(clickedPicture()));// Clicking the picture should invoke pictureselector. | 69 | connect(picturePushButton,SIGNAL(clicked()),this,SLOT(clickedPicture()));// Clicking the picture should invoke pictureselector. |
70 | 70 | ||
71 | // Login | 71 | // Login |
72 | QLabel *loginLabel=new QLabel(tabpage,"Login: "); | 72 | QLabel *loginLabel=new QLabel(tabpage,"Login: "); |
73 | loginLabel->setText("Login: "); | 73 | loginLabel->setText("Login: "); |
74 | loginLineEdit=new QLineEdit(tabpage,"Login: "); | 74 | loginLineEdit=new QLineEdit(tabpage,"Login: "); |
75 | 75 | ||
76 | // UID | 76 | // UID |
77 | QLabel *uidLabel=new QLabel(tabpage,"uid: "); | 77 | QLabel *uidLabel=new QLabel(tabpage,"uid: "); |
78 | uidLabel->setText("UserID: "); | 78 | uidLabel->setText("UserID: "); |
79 | uidLineEdit=new QLineEdit(tabpage,"uid: "); | 79 | uidLineEdit=new QLineEdit(tabpage,"uid: "); |
80 | uidLineEdit->setEnabled(false); | 80 | uidLineEdit->setEnabled(false); |
81 | 81 | ||
82 | // Username (gecos) | 82 | // Username (gecos) |
83 | QLabel *gecosLabel=new QLabel(tabpage,"gecos"); | 83 | QLabel *gecosLabel=new QLabel(tabpage,"gecos"); |
84 | gecosLabel->setText("Username: "); | 84 | gecosLabel->setText("Username: "); |
85 | gecosLineEdit=new QLineEdit(tabpage,"gecos"); | 85 | gecosLineEdit=new QLineEdit(tabpage,"gecos"); |
86 | 86 | ||
87 | // Password | 87 | // Password |
88 | QLabel *passwordLabel=new QLabel(tabpage,"password"); | 88 | QLabel *passwordLabel=new QLabel(tabpage,"password"); |
89 | passwordLabel->setText("Password: "); | 89 | passwordLabel->setText("Password: "); |
90 | passwordLineEdit=new QLineEdit(tabpage,"password"); | 90 | passwordLineEdit=new QLineEdit(tabpage,"password"); |
91 | passwordLineEdit->setEchoMode(QLineEdit::Password); | 91 | passwordLineEdit->setEchoMode(QLineEdit::Password); |
92 | 92 | ||
93 | // Shell | 93 | // Shell |
94 | QLabel *shellLabel=new QLabel(tabpage,"shell"); | 94 | QLabel *shellLabel=new QLabel(tabpage,"shell"); |
95 | shellLabel->setText("Shell: "); | 95 | shellLabel->setText("Shell: "); |
96 | shellComboBox=new QComboBox(tabpage,"shell"); | 96 | shellComboBox=new QComboBox(tabpage,"shell"); |
97 | shellComboBox->setEditable(true); | 97 | shellComboBox->setEditable(true); |
98 | shellComboBox->insertItem("/bin/sh"); | 98 | shellComboBox->insertItem("/bin/sh"); |
99 | shellComboBox->insertItem("/bin/ash"); | 99 | shellComboBox->insertItem("/bin/ash"); |
100 | shellComboBox->insertItem("/bin/false"); | 100 | shellComboBox->insertItem("/bin/false"); |
101 | 101 | ||
102 | // Primary Group | 102 | // Primary Group |
103 | QLabel *groupLabel=new QLabel(tabpage,"group"); | 103 | QLabel *groupLabel=new QLabel(tabpage,"group"); |
104 | groupLabel->setText("Primary group: "); | 104 | groupLabel->setText("Primary group: "); |
105 | groupComboBox=new QComboBox(tabpage,"PrimaryGroup"); | 105 | groupComboBox=new QComboBox(tabpage,"PrimaryGroup"); |
106 | 106 | ||
107 | // Widget layout | 107 | // Widget layout |
108 | QHBoxLayout *hlayout=new QHBoxLayout(-1,"hlayout"); | 108 | QHBoxLayout *hlayout=new QHBoxLayout(-1,"hlayout"); |
109 | layout->addWidget(picturePushButton); | 109 | layout->addWidget(picturePushButton); |
110 | layout->addSpacing(5); | 110 | layout->addSpacing(5); |
111 | layout->addLayout(hlayout); | 111 | layout->addLayout(hlayout); |
112 | QVBoxLayout *vlayout1=new QVBoxLayout(-1,"vlayout1"); | 112 | QVBoxLayout *vlayout1=new QVBoxLayout(-1,"vlayout1"); |
113 | QVBoxLayout *vlayout2=new QVBoxLayout(-1,"vlayout2"); | 113 | QVBoxLayout *vlayout2=new QVBoxLayout(-1,"vlayout2"); |
114 | // First column, labels | 114 | // First column, labels |
115 | vlayout1->addWidget(loginLabel); | 115 | vlayout1->addWidget(loginLabel); |
116 | vlayout1->addSpacing(5); | 116 | vlayout1->addSpacing(5); |
117 | vlayout1->addWidget(uidLabel); | 117 | vlayout1->addWidget(uidLabel); |
118 | vlayout1->addSpacing(5); | 118 | vlayout1->addSpacing(5); |
119 | vlayout1->addWidget(gecosLabel); | 119 | vlayout1->addWidget(gecosLabel); |
120 | vlayout1->addSpacing(5); | 120 | vlayout1->addSpacing(5); |
121 | vlayout1->addWidget(passwordLabel); | 121 | vlayout1->addWidget(passwordLabel); |
122 | vlayout1->addSpacing(5); | 122 | vlayout1->addSpacing(5); |
123 | vlayout1->addWidget(shellLabel); | 123 | vlayout1->addWidget(shellLabel); |
124 | vlayout1->addSpacing(5); | 124 | vlayout1->addSpacing(5); |
125 | vlayout1->addWidget(groupLabel); | 125 | vlayout1->addWidget(groupLabel); |
126 | // Second column, data | 126 | // Second column, data |
127 | vlayout2->addWidget(loginLineEdit); | 127 | vlayout2->addWidget(loginLineEdit); |
128 | vlayout2->addSpacing(5); | 128 | vlayout2->addSpacing(5); |
129 | vlayout2->addWidget(uidLineEdit); | 129 | vlayout2->addWidget(uidLineEdit); |
130 | vlayout2->addSpacing(5); | 130 | vlayout2->addSpacing(5); |
131 | vlayout2->addWidget(gecosLineEdit); | 131 | vlayout2->addWidget(gecosLineEdit); |
132 | vlayout2->addSpacing(5); | 132 | vlayout2->addSpacing(5); |
133 | vlayout2->addWidget(passwordLineEdit); | 133 | vlayout2->addWidget(passwordLineEdit); |
134 | vlayout2->addSpacing(5); | 134 | vlayout2->addSpacing(5); |
135 | vlayout2->addWidget(shellComboBox); | 135 | vlayout2->addWidget(shellComboBox); |
136 | vlayout2->addSpacing(5); | 136 | vlayout2->addSpacing(5); |
137 | vlayout2->addWidget(groupComboBox); | 137 | vlayout2->addWidget(groupComboBox); |
138 | hlayout->addLayout(vlayout1); | 138 | hlayout->addLayout(vlayout1); |
139 | hlayout->addLayout(vlayout2); | 139 | hlayout->addLayout(vlayout2); |
140 | 140 | ||
141 | myTabWidget->addTab(tabpage,"User Info"); | 141 | myTabWidget->addTab(tabpage,"User Info"); |
142 | } | 142 | } |
143 | 143 | ||
144 | /** | 144 | /** |
145 | * Creates the second tab containing additional groups for the user. | 145 | * Creates the second tab containing additional groups for the user. |
146 | * | 146 | * |
147 | */ | 147 | */ |
148 | void UserDialog::setupTab2() { | 148 | void UserDialog::setupTab2() { |
149 | QWidget *tabpage = new QWidget(myTabWidget,"page2"); | 149 | QWidget *tabpage = new QWidget(myTabWidget,"page2"); |
150 | QVBoxLayout *layout = new QVBoxLayout(tabpage); | 150 | QVBoxLayout *layout = new QVBoxLayout(tabpage); |
151 | layout->setMargin(5); | 151 | layout->setMargin(5); |
152 | 152 | ||
153 | // Additional groups | 153 | // Additional groups |
154 | groupsListView=new QListView(tabpage,"groups"); | 154 | groupsListView=new QListView(tabpage,"groups"); |
155 | groupsListView->addColumn("Additional groups"); | 155 | groupsListView->addColumn("Additional groups"); |
156 | groupsListView->setColumnWidthMode(0,QListView::Maximum); | 156 | groupsListView->setColumnWidthMode(0,QListView::Maximum); |
157 | groupsListView->setMultiSelection(true); | 157 | groupsListView->setMultiSelection(true); |
158 | 158 | ||
159 | layout->addSpacing(5); | 159 | layout->addSpacing(5); |
160 | // Grouplist | 160 | // Grouplist |
161 | layout->addWidget(groupsListView); | 161 | layout->addWidget(groupsListView); |
162 | 162 | ||
163 | myTabWidget->addTab(tabpage,"User Groups"); | 163 | myTabWidget->addTab(tabpage,"User Groups"); |
164 | } | 164 | } |
165 | 165 | ||
166 | /** | 166 | /** |
167 | * Static function that creates the userinfo dialog. | 167 | * Static function that creates the userinfo dialog. |
168 | * The user will be prompted to add a user. | 168 | * The user will be prompted to add a user. |
169 | * | 169 | * |
170 | * @param uid This is a suggested available UID. | 170 | * @param uid This is a suggested available UID. |
171 | * @param gid This is a suggested available GID. | 171 | * @param gid This is a suggested available GID. |
172 | * | 172 | * |
173 | * @return <code>true</code> if the user was successfully added, otherwise <code>false</code>. | 173 | * @return <code>true</code> if the user was successfully added, otherwise <code>false</code>. |
174 | * | 174 | * |
175 | */ | 175 | */ |
176 | bool UserDialog::addUser(int uid, int gid) { | 176 | bool UserDialog::addUser(int uid, int gid) { |
177 | UserDialog *adduserDialog=new UserDialog(); | 177 | UserDialog *adduserDialog=new UserDialog(); |
178 | adduserDialog->setCaption(tr("Add User")); | 178 | adduserDialog->setCaption(tr("Add User")); |
179 | adduserDialog->userID=uid;// Set next available UID as default uid. | 179 | adduserDialog->userID=uid;// Set next available UID as default uid. |
180 | adduserDialog->groupID=gid;// Set next available GID as default gid. | 180 | adduserDialog->groupID=gid;// Set next available GID as default gid. |
181 | // Insert default group into groupComboBox | 181 | // Insert default group into groupComboBox |
182 | adduserDialog->groupComboBox->insertItem("<create new group>",0); | 182 | adduserDialog->groupComboBox->insertItem("<create new group>",0); |
183 | adduserDialog->uidLineEdit->setText(QString::number(uid)); | 183 | adduserDialog->uidLineEdit->setText(QString::number(uid)); |
184 | // Show the dialog! | 184 | // Show the dialog! |
185 | if(!(adduserDialog->exec())) return false; | 185 | if(!(adduserDialog->exec())) return false; |
186 | if((adduserDialog->groupComboBox->currentItem()!=0)) { | 186 | if((adduserDialog->groupComboBox->currentItem()!=0)) { |
187 | accounts->findGroup(adduserDialog->groupComboBox->currentText()); | 187 | accounts->findGroup(adduserDialog->groupComboBox->currentText()); |
188 | adduserDialog->groupID=accounts->gr_gid; | 188 | adduserDialog->groupID=accounts->gr_gid; |
189 | qWarning(QString::number(accounts->gr_gid)); | 189 | qWarning(QString::number(accounts->gr_gid)); |
190 | } | 190 | } |
191 | if(!(accounts->addUser(adduserDialog->loginLineEdit->text(), adduserDialog->passwordLineEdit->text(), | 191 | if(!(accounts->addUser(adduserDialog->loginLineEdit->text(), adduserDialog->passwordLineEdit->text(), |
192 | adduserDialog->uidLineEdit->text().toInt(), adduserDialog->groupID, adduserDialog->gecosLineEdit->text(), | 192 | adduserDialog->uidLineEdit->text().toInt(), adduserDialog->groupID, adduserDialog->gecosLineEdit->text(), |
193 | QString("/home/")+adduserDialog->loginLineEdit->text() , adduserDialog->shellComboBox->currentText()))) { | 193 | QString("/home/")+adduserDialog->loginLineEdit->text() , adduserDialog->shellComboBox->currentText()))) { |
194 | QMessageBox::information(0,"Ooops!","Something went wrong!\nUnable to add user."); | 194 | QMessageBox::information(0,"Ooops!","Something went wrong!\nUnable to add user."); |
195 | return false; | 195 | return false; |
196 | } | 196 | } |