Diffstat (limited to 'noncore/settings/usermanager') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/settings/usermanager/userdialog.cpp | 14 | ||||
-rw-r--r-- | noncore/settings/usermanager/usermanager.cpp | 11 | ||||
-rw-r--r-- | noncore/settings/usermanager/usermanager.pro | 9 |
3 files changed, 17 insertions, 17 deletions
diff --git a/noncore/settings/usermanager/userdialog.cpp b/noncore/settings/usermanager/userdialog.cpp index 5854fe0..3616507 100644 --- a/noncore/settings/usermanager/userdialog.cpp +++ b/noncore/settings/usermanager/userdialog.cpp | |||
@@ -1,133 +1,131 @@ | |||
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 | #include "passwd.h" | 11 | #include "passwd.h" |
12 | 12 | ||
13 | /* OPIE */ | 13 | /* OPIE */ |
14 | #include <opie2/odebug.h> | ||
14 | #include <opie2/odevice.h> | 15 | #include <opie2/odevice.h> |
15 | #include <qpe/qpeapplication.h> | 16 | #include <qpe/qpeapplication.h> |
17 | using namespace Opie::Core; | ||
18 | using namespace Opie::Ui; | ||
16 | 19 | ||
17 | /* QT */ | 20 | /* QT */ |
18 | #include <qlayout.h> | 21 | #include <qlayout.h> |
19 | #include <qlabel.h> | 22 | #include <qlabel.h> |
20 | #include <qmessagebox.h> | 23 | #include <qmessagebox.h> |
21 | #include <qfile.h> | 24 | #include <qfile.h> |
22 | 25 | ||
23 | /* STD */ | 26 | /* STD */ |
24 | #include <sys/types.h> | 27 | #include <sys/types.h> |
25 | #include <sys/wait.h> | 28 | #include <sys/wait.h> |
26 | #include <unistd.h> | 29 | #include <unistd.h> |
27 | #include <signal.h> | 30 | #include <signal.h> |
28 | 31 | ||
29 | |||
30 | using namespace Opie::Core; | ||
31 | |||
32 | |||
33 | /** | 32 | /** |
34 | * UserDialog constructor. Setup the dialog, fill the groupComboBox & groupsListView with all groups. | 33 | * UserDialog constructor. Setup the dialog, fill the groupComboBox & groupsListView with all groups. |
35 | * | 34 | * |
36 | */ | 35 | */ |
37 | using namespace Opie::Ui; | ||
38 | UserDialog::UserDialog(int viewmode, QWidget* parent, const char* name, bool modal, WFlags fl) : QDialog(parent, name, modal, fl) | 36 | UserDialog::UserDialog(int viewmode, QWidget* parent, const char* name, bool modal, WFlags fl) : QDialog(parent, name, modal, fl) |
39 | { | 37 | { |
40 | vm=viewmode; | 38 | vm=viewmode; |
41 | QVBoxLayout *layout = new QVBoxLayout(this); | 39 | QVBoxLayout *layout = new QVBoxLayout(this); |
42 | myTabWidget=new QTabWidget(this,"User Tab Widget"); | 40 | myTabWidget=new QTabWidget(this,"User Tab Widget"); |
43 | layout->addWidget(myTabWidget); | 41 | layout->addWidget(myTabWidget); |
44 | setupTab1(); | 42 | setupTab1(); |
45 | setupTab2(); | 43 | setupTab2(); |
46 | 44 | ||
47 | accounts->groupStringList.sort(); | 45 | accounts->groupStringList.sort(); |
48 | // And also fill the listview & the combobox with all available groups. | 46 | // And also fill the listview & the combobox with all available groups. |
49 | for( QStringList::Iterator it = accounts->groupStringList.begin(); it!=accounts->groupStringList.end(); ++it) | 47 | for( QStringList::Iterator it = accounts->groupStringList.begin(); it!=accounts->groupStringList.end(); ++it) |
50 | { | 48 | { |
51 | accounts->splitGroupEntry(*it); | 49 | accounts->splitGroupEntry(*it); |
52 | if(accounts->gr_name.find(QRegExp("^#"),0)) | 50 | if(accounts->gr_name.find(QRegExp("^#"),0)) |
53 | { // Skip commented lines. | 51 | { // Skip commented lines. |
54 | new QCheckListItem(groupsListView,accounts->gr_name,QCheckListItem::CheckBox); | 52 | new QCheckListItem(groupsListView,accounts->gr_name,QCheckListItem::CheckBox); |
55 | groupComboBox->insertItem(accounts->gr_name); | 53 | groupComboBox->insertItem(accounts->gr_name); |
56 | } | 54 | } |
57 | } | 55 | } |
58 | QPEApplication::showDialog( this ); | 56 | QPEApplication::showDialog( this ); |
59 | } | 57 | } |
60 | 58 | ||
61 | /** | 59 | /** |
62 | * Empty destructor. | 60 | * Empty destructor. |
63 | * | 61 | * |
64 | */ | 62 | */ |
65 | UserDialog::~UserDialog() | 63 | UserDialog::~UserDialog() |
66 | {} | 64 | {} |
67 | 65 | ||
68 | /** | 66 | /** |
69 | * Creates the first tab, all userinfo is here. | 67 | * Creates the first tab, all userinfo is here. |
70 | * | 68 | * |
71 | */ | 69 | */ |
72 | void UserDialog::setupTab1() | 70 | void UserDialog::setupTab1() |
73 | { | 71 | { |
74 | QPixmap mypixmap; | 72 | QPixmap mypixmap; |
75 | QWidget *tabpage = new QWidget(myTabWidget,"page1"); | 73 | QWidget *tabpage = new QWidget(myTabWidget,"page1"); |
76 | QVBoxLayout *layout = new QVBoxLayout(tabpage); | 74 | QVBoxLayout *layout = new QVBoxLayout(tabpage); |
77 | layout->setMargin(5); | 75 | layout->setMargin(5); |
78 | 76 | ||
79 | // Picture | 77 | // Picture |
80 | picturePushButton = new QPushButton(tabpage,"Label"); | 78 | picturePushButton = new QPushButton(tabpage,"Label"); |
81 | picturePushButton->setMinimumSize(48,48); | 79 | picturePushButton->setMinimumSize(48,48); |
82 | picturePushButton->setMaximumSize(48,48); | 80 | picturePushButton->setMaximumSize(48,48); |
83 | picturePushButton->setPixmap(Resource::loadPixmap("usermanager/usericon")); // Load default usericon. | 81 | picturePushButton->setPixmap(Resource::loadPixmap("usermanager/usericon")); // Load default usericon. |
84 | connect(picturePushButton,SIGNAL(clicked()),this,SLOT(clickedPicture())); // Clicking the picture should invoke pictureselector. | 82 | connect(picturePushButton,SIGNAL(clicked()),this,SLOT(clickedPicture())); // Clicking the picture should invoke pictureselector. |
85 | 83 | ||
86 | // Login | 84 | // Login |
87 | QLabel *loginLabel=new QLabel(tabpage,"Login: "); | 85 | QLabel *loginLabel=new QLabel(tabpage,"Login: "); |
88 | loginLabel->setText("Login: "); | 86 | loginLabel->setText("Login: "); |
89 | loginLineEdit=new QLineEdit(tabpage,"Login: "); | 87 | loginLineEdit=new QLineEdit(tabpage,"Login: "); |
90 | 88 | ||
91 | // UID | 89 | // UID |
92 | QLabel *uidLabel=new QLabel(tabpage,"uid: "); | 90 | QLabel *uidLabel=new QLabel(tabpage,"uid: "); |
93 | uidLabel->setText("UserID: "); | 91 | uidLabel->setText("UserID: "); |
94 | uidLineEdit=new QLineEdit(tabpage,"uid: "); | 92 | uidLineEdit=new QLineEdit(tabpage,"uid: "); |
95 | uidLineEdit->setEnabled(false); | 93 | uidLineEdit->setEnabled(false); |
96 | 94 | ||
97 | // Username (gecos) | 95 | // Username (gecos) |
98 | QLabel *gecosLabel=new QLabel(tabpage,"gecos"); | 96 | QLabel *gecosLabel=new QLabel(tabpage,"gecos"); |
99 | gecosLabel->setText("Username: "); | 97 | gecosLabel->setText("Username: "); |
100 | gecosLineEdit=new QLineEdit(tabpage,"gecos"); | 98 | gecosLineEdit=new QLineEdit(tabpage,"gecos"); |
101 | 99 | ||
102 | // Password | 100 | // Password |
103 | QLabel *passwordLabel=new QLabel(tabpage,"password"); | 101 | QLabel *passwordLabel=new QLabel(tabpage,"password"); |
104 | passwordLabel->setText("Password: "); | 102 | passwordLabel->setText("Password: "); |
105 | passwordLineEdit=new QLineEdit(tabpage,"password"); | 103 | passwordLineEdit=new QLineEdit(tabpage,"password"); |
106 | passwordLineEdit->setEchoMode(QLineEdit::Password); | 104 | passwordLineEdit->setEchoMode(QLineEdit::Password); |
107 | 105 | ||
108 | // Shell | 106 | // Shell |
109 | QLabel *shellLabel=new QLabel(tabpage,"shell"); | 107 | QLabel *shellLabel=new QLabel(tabpage,"shell"); |
110 | shellLabel->setText("Shell: "); | 108 | shellLabel->setText("Shell: "); |
111 | shellComboBox=new QComboBox(tabpage,"shell"); | 109 | shellComboBox=new QComboBox(tabpage,"shell"); |
112 | shellComboBox->setEditable(true); | 110 | shellComboBox->setEditable(true); |
113 | shellComboBox->insertItem("/bin/sh"); | 111 | shellComboBox->insertItem("/bin/sh"); |
114 | shellComboBox->insertItem("/bin/ash"); | 112 | shellComboBox->insertItem("/bin/ash"); |
115 | shellComboBox->insertItem("/bin/false"); | 113 | shellComboBox->insertItem("/bin/false"); |
116 | 114 | ||
117 | // Primary Group | 115 | // Primary Group |
118 | QLabel *groupLabel=new QLabel(tabpage,"group"); | 116 | QLabel *groupLabel=new QLabel(tabpage,"group"); |
119 | groupLabel->setText("Primary group: "); | 117 | groupLabel->setText("Primary group: "); |
120 | groupComboBox=new QComboBox(tabpage,"PrimaryGroup"); | 118 | groupComboBox=new QComboBox(tabpage,"PrimaryGroup"); |
121 | 119 | ||
122 | if(vm==VIEWMODE_NEW) | 120 | if(vm==VIEWMODE_NEW) |
123 | { | 121 | { |
124 | // Copy /etc/skel | 122 | // Copy /etc/skel |
125 | skelLabel=new QLabel(tabpage,"skel"); | 123 | skelLabel=new QLabel(tabpage,"skel"); |
126 | skelLabel->setText("Copy /etc/skel: "); | 124 | skelLabel->setText("Copy /etc/skel: "); |
127 | skelCheckBox=new QCheckBox(tabpage); | 125 | skelCheckBox=new QCheckBox(tabpage); |
128 | skelCheckBox->setChecked(true); | 126 | skelCheckBox->setChecked(true); |
129 | } | 127 | } |
130 | 128 | ||
131 | // Widget layout | 129 | // Widget layout |
132 | QHBoxLayout *hlayout=new QHBoxLayout(-1,"hlayout"); | 130 | QHBoxLayout *hlayout=new QHBoxLayout(-1,"hlayout"); |
133 | layout->addWidget(picturePushButton); | 131 | layout->addWidget(picturePushButton); |
@@ -152,337 +150,337 @@ void UserDialog::setupTab1() | |||
152 | vlayout1->addSpacing(5); | 150 | vlayout1->addSpacing(5); |
153 | vlayout1->addWidget(skelLabel); | 151 | vlayout1->addWidget(skelLabel); |
154 | } | 152 | } |
155 | // Second column, data | 153 | // Second column, data |
156 | vlayout2->addWidget(loginLineEdit); | 154 | vlayout2->addWidget(loginLineEdit); |
157 | vlayout2->addSpacing(5); | 155 | vlayout2->addSpacing(5); |
158 | vlayout2->addWidget(uidLineEdit); | 156 | vlayout2->addWidget(uidLineEdit); |
159 | vlayout2->addSpacing(5); | 157 | vlayout2->addSpacing(5); |
160 | vlayout2->addWidget(gecosLineEdit); | 158 | vlayout2->addWidget(gecosLineEdit); |
161 | vlayout2->addSpacing(5); | 159 | vlayout2->addSpacing(5); |
162 | vlayout2->addWidget(passwordLineEdit); | 160 | vlayout2->addWidget(passwordLineEdit); |
163 | vlayout2->addSpacing(5); | 161 | vlayout2->addSpacing(5); |
164 | vlayout2->addWidget(shellComboBox); | 162 | vlayout2->addWidget(shellComboBox); |
165 | vlayout2->addSpacing(5); | 163 | vlayout2->addSpacing(5); |
166 | vlayout2->addWidget(groupComboBox); | 164 | vlayout2->addWidget(groupComboBox); |
167 | if(vm==VIEWMODE_NEW) | 165 | if(vm==VIEWMODE_NEW) |
168 | { | 166 | { |
169 | vlayout2->addSpacing(5); | 167 | vlayout2->addSpacing(5); |
170 | vlayout2->addWidget(skelCheckBox); | 168 | vlayout2->addWidget(skelCheckBox); |
171 | } | 169 | } |
172 | hlayout->addLayout(vlayout1); | 170 | hlayout->addLayout(vlayout1); |
173 | hlayout->addLayout(vlayout2); | 171 | hlayout->addLayout(vlayout2); |
174 | 172 | ||
175 | myTabWidget->addTab(tabpage,"User Info"); | 173 | myTabWidget->addTab(tabpage,"User Info"); |
176 | } | 174 | } |
177 | 175 | ||
178 | /** | 176 | /** |
179 | * Creates the second tab containing additional groups for the user. | 177 | * Creates the second tab containing additional groups for the user. |
180 | * | 178 | * |
181 | */ | 179 | */ |
182 | void UserDialog::setupTab2() | 180 | void UserDialog::setupTab2() |
183 | { | 181 | { |
184 | QWidget *tabpage = new QWidget(myTabWidget,"page2"); | 182 | QWidget *tabpage = new QWidget(myTabWidget,"page2"); |
185 | QVBoxLayout *layout = new QVBoxLayout(tabpage); | 183 | QVBoxLayout *layout = new QVBoxLayout(tabpage); |
186 | layout->setMargin(5); | 184 | layout->setMargin(5); |
187 | 185 | ||
188 | // Additional groups | 186 | // Additional groups |
189 | groupsListView=new QListView(tabpage,"groups"); | 187 | groupsListView=new QListView(tabpage,"groups"); |
190 | groupsListView->addColumn("Additional groups"); | 188 | groupsListView->addColumn("Additional groups"); |
191 | groupsListView->setColumnWidthMode(0,QListView::Maximum); | 189 | groupsListView->setColumnWidthMode(0,QListView::Maximum); |
192 | groupsListView->setMultiSelection(false); | 190 | groupsListView->setMultiSelection(false); |
193 | groupsListView->setAllColumnsShowFocus(false); | 191 | groupsListView->setAllColumnsShowFocus(false); |
194 | 192 | ||
195 | layout->addSpacing(5); | 193 | layout->addSpacing(5); |
196 | // Grouplist | 194 | // Grouplist |
197 | layout->addWidget(groupsListView); | 195 | layout->addWidget(groupsListView); |
198 | 196 | ||
199 | myTabWidget->addTab(tabpage,"User Groups"); | 197 | myTabWidget->addTab(tabpage,"User Groups"); |
200 | } | 198 | } |
201 | 199 | ||
202 | /** | 200 | /** |
203 | * Static function that creates the userinfo dialog. | 201 | * Static function that creates the userinfo dialog. |
204 | * The user will be prompted to add a user. | 202 | * The user will be prompted to add a user. |
205 | * | 203 | * |
206 | * @param uid This is a suggested available UID. | 204 | * @param uid This is a suggested available UID. |
207 | * @param gid This is a suggested available GID. | 205 | * @param gid This is a suggested available GID. |
208 | * | 206 | * |
209 | * @return <code>true</code> if the user was successfully added, otherwise <code>false</code>. | 207 | * @return <code>true</code> if the user was successfully added, otherwise <code>false</code>. |
210 | * | 208 | * |
211 | */ | 209 | */ |
212 | bool UserDialog::addUser(int uid, int gid) | 210 | bool UserDialog::addUser(int uid, int gid) |
213 | { | 211 | { |
214 | QCheckListItem *temp; | 212 | QCheckListItem *temp; |
215 | QFile ozTest; | 213 | QFile ozTest; |
216 | int oz=false; | 214 | int oz=false; |
217 | if(ODevice::inst()->system()==System_OpenZaurus) oz=true; | 215 | if(ODevice::inst()->system()==System_OpenZaurus) oz=true; |
218 | // viewmode is a workaround for a bug in qte-2.3.4 that gives bus error on manipulating adduserDialog's widgets here. | 216 | // viewmode is a workaround for a bug in qte-2.3.4 that gives bus error on manipulating adduserDialog's widgets here. |
219 | UserDialog *adduserDialog=new UserDialog(VIEWMODE_NEW); | 217 | UserDialog *adduserDialog=new UserDialog(VIEWMODE_NEW); |
220 | adduserDialog->setCaption(tr("Add User")); | 218 | adduserDialog->setCaption(tr("Add User")); |
221 | adduserDialog->userID=uid; // Set next available UID as default uid. | 219 | adduserDialog->userID=uid; // Set next available UID as default uid. |
222 | adduserDialog->groupID=gid; // Set next available GID as default gid. | 220 | adduserDialog->groupID=gid; // Set next available GID as default gid. |
223 | // Insert default group into groupComboBox | 221 | // Insert default group into groupComboBox |
224 | adduserDialog->groupComboBox->insertItem("<create new group>",0); | 222 | adduserDialog->groupComboBox->insertItem("<create new group>",0); |
225 | adduserDialog->uidLineEdit->setText(QString::number(uid)); | 223 | adduserDialog->uidLineEdit->setText(QString::number(uid)); |
226 | // If we're running on OZ, add new users to some default groups. | 224 | // If we're running on OZ, add new users to some default groups. |
227 | if(oz) | 225 | if(oz) |
228 | { | 226 | { |
229 | QListViewItemIterator iter( adduserDialog->groupsListView ); | 227 | QListViewItemIterator iter( adduserDialog->groupsListView ); |
230 | for ( ; iter.current(); ++iter ) | 228 | for ( ; iter.current(); ++iter ) |
231 | { | 229 | { |
232 | temp=(QCheckListItem*)iter.current(); | 230 | temp=(QCheckListItem*)iter.current(); |
233 | if (temp->text()=="video") temp->setOn(true); | 231 | if (temp->text()=="video") temp->setOn(true); |
234 | if (temp->text()=="audio") temp->setOn(true); | 232 | if (temp->text()=="audio") temp->setOn(true); |
235 | if (temp->text()=="time") temp->setOn(true); | 233 | if (temp->text()=="time") temp->setOn(true); |
236 | if (temp->text()=="power") temp->setOn(true); | 234 | if (temp->text()=="power") temp->setOn(true); |
237 | if (temp->text()=="input") temp->setOn(true); | 235 | if (temp->text()=="input") temp->setOn(true); |
238 | if (temp->text()=="sharp") temp->setOn(true); | 236 | if (temp->text()=="sharp") temp->setOn(true); |
239 | if (temp->text()=="tty") temp->setOn(true); | 237 | if (temp->text()=="tty") temp->setOn(true); |
240 | } | 238 | } |
241 | } | 239 | } |
242 | // Show the dialog! | 240 | // Show the dialog! |
243 | if(!(adduserDialog->exec())) return false; | 241 | if(!(adduserDialog->exec())) return false; |
244 | if((adduserDialog->groupComboBox->currentItem()!=0)) | 242 | if((adduserDialog->groupComboBox->currentItem()!=0)) |
245 | { | 243 | { |
246 | accounts->findGroup(adduserDialog->groupComboBox->currentText()); | 244 | accounts->findGroup(adduserDialog->groupComboBox->currentText()); |
247 | adduserDialog->groupID=accounts->gr_gid; | 245 | adduserDialog->groupID=accounts->gr_gid; |
248 | qWarning(QString::number(accounts->gr_gid)); | 246 | owarn << QString::number(accounts->gr_gid) << oendl; |
249 | } | 247 | } |
250 | if(!(accounts->addUser(adduserDialog->loginLineEdit->text(), adduserDialog->passwordLineEdit->text(), | 248 | if(!(accounts->addUser(adduserDialog->loginLineEdit->text(), adduserDialog->passwordLineEdit->text(), |
251 | adduserDialog->uidLineEdit->text().toInt(), adduserDialog->groupID, adduserDialog->gecosLineEdit->text(), | 249 | adduserDialog->uidLineEdit->text().toInt(), adduserDialog->groupID, adduserDialog->gecosLineEdit->text(), |
252 | QString("/home/")+adduserDialog->loginLineEdit->text() , adduserDialog->shellComboBox->currentText()))) | 250 | QString("/home/")+adduserDialog->loginLineEdit->text() , adduserDialog->shellComboBox->currentText()))) |
253 | { | 251 | { |
254 | QMessageBox::information(0,"Ooops!","Something went wrong!\nUnable to add user."); | 252 | QMessageBox::information(0,"Ooops!","Something went wrong!\nUnable to add user."); |
255 | return false; | 253 | return false; |
256 | } | 254 | } |
257 | 255 | ||
258 | // Add User to additional groups. | 256 | // Add User to additional groups. |
259 | QListViewItemIterator it( adduserDialog->groupsListView ); | 257 | QListViewItemIterator it( adduserDialog->groupsListView ); |
260 | for ( ; it.current(); ++it ) | 258 | for ( ; it.current(); ++it ) |
261 | { | 259 | { |
262 | temp=(QCheckListItem*)it.current(); | 260 | temp=(QCheckListItem*)it.current(); |
263 | if (temp->isOn() ) | 261 | if (temp->isOn() ) |
264 | accounts->addGroupMember(it.current()->text(0),adduserDialog->loginLineEdit->text()); | 262 | accounts->addGroupMember(it.current()->text(0),adduserDialog->loginLineEdit->text()); |
265 | } | 263 | } |
266 | // Copy image to pics/users/ | 264 | // Copy image to pics/users/ |
267 | if(!(adduserDialog->userImage.isNull())) | 265 | if(!(adduserDialog->userImage.isNull())) |
268 | { | 266 | { |
269 | QDir d; | 267 | QDir d; |
270 | if(!(d.exists("/opt/QtPalmtop/pics/users"))) | 268 | if(!(d.exists("/opt/QtPalmtop/pics/users"))) |
271 | { | 269 | { |
272 | d.mkdir("/opt/QtPalmtop/pics/users"); | 270 | d.mkdir("/opt/QtPalmtop/pics/users"); |
273 | } | 271 | } |
274 | QString filename="/opt/QtPalmtop/pics/users/"+accounts->pw_name+".png"; | 272 | QString filename="/opt/QtPalmtop/pics/users/"+accounts->pw_name+".png"; |
275 | // adduserDialog->userImage=adduserDialog->userImage.smoothScale(48,48); | 273 | // adduserDialog->userImage=adduserDialog->userImage.smoothScale(48,48); |
276 | adduserDialog->userImage.save(filename,"PNG"); | 274 | adduserDialog->userImage.save(filename,"PNG"); |
277 | } | 275 | } |
278 | 276 | ||
279 | // Should we copy the skeleton homedirectory /etc/skel to the user's homedirectory? | 277 | // Should we copy the skeleton homedirectory /etc/skel to the user's homedirectory? |
280 | accounts->findUser(adduserDialog->loginLineEdit->text()); | 278 | accounts->findUser(adduserDialog->loginLineEdit->text()); |
281 | if(adduserDialog->skelCheckBox->isChecked()) | 279 | if(adduserDialog->skelCheckBox->isChecked()) |
282 | { | 280 | { |
283 | QString command_cp; | 281 | QString command_cp; |
284 | QString command_chown; | 282 | QString command_chown; |
285 | command_cp.sprintf("cp -a /etc/skel/* %s/",accounts->pw_dir.latin1()); | 283 | command_cp.sprintf("cp -a /etc/skel/* %s/",accounts->pw_dir.latin1()); |
286 | system(command_cp); | 284 | system(command_cp); |
287 | 285 | ||
288 | command_cp.sprintf("cp -a /etc/skel/.[!.]* %s/",accounts->pw_dir.latin1()); // Bug in busybox, ".*" includes parent directory, does this work as a workaround? | 286 | command_cp.sprintf("cp -a /etc/skel/.[!.]* %s/",accounts->pw_dir.latin1()); // Bug in busybox, ".*" includes parent directory, does this work as a workaround? |
289 | system(command_cp); | 287 | system(command_cp); |
290 | 288 | ||
291 | command_chown.sprintf("chown -R %d:%d %s",accounts->pw_uid,accounts->pw_gid,accounts->pw_dir.latin1()); | 289 | command_chown.sprintf("chown -R %d:%d %s",accounts->pw_uid,accounts->pw_gid,accounts->pw_dir.latin1()); |
292 | system(command_chown); | 290 | system(command_chown); |
293 | } | 291 | } |
294 | 292 | ||
295 | return true; | 293 | return true; |
296 | } | 294 | } |
297 | 295 | ||
298 | /** | 296 | /** |
299 | * Deletes the user account. | 297 | * Deletes the user account. |
300 | * | 298 | * |
301 | * @param username User to be deleted. | 299 | * @param username User to be deleted. |
302 | * | 300 | * |
303 | * @return <code>true</code> if the user was successfully deleted, otherwise <code>false</code>. | 301 | * @return <code>true</code> if the user was successfully deleted, otherwise <code>false</code>. |
304 | * | 302 | * |
305 | */ | 303 | */ |
306 | bool UserDialog::delUser(const char *username) | 304 | bool UserDialog::delUser(const char *username) |
307 | { | 305 | { |
308 | if((accounts->findUser(username))) | 306 | if((accounts->findUser(username))) |
309 | { // Does that user exist? | 307 | { // Does that user exist? |
310 | if(!(accounts->delUser(username))) | 308 | if(!(accounts->delUser(username))) |
311 | { // Delete the user. | 309 | { // Delete the user. |
312 | QMessageBox::information(0,"Ooops!","Something went wrong\nUnable to delete user: "+QString(username)+"."); | 310 | QMessageBox::information(0,"Ooops!","Something went wrong\nUnable to delete user: "+QString(username)+"."); |
313 | } | 311 | } |
314 | } | 312 | } |
315 | else | 313 | else |
316 | { | 314 | { |
317 | QMessageBox::information(0,"Invalid Username","That username ("+QString(username)+")does not exist."); | 315 | QMessageBox::information(0,"Invalid Username","That username ("+QString(username)+")does not exist."); |
318 | return false; | 316 | return false; |
319 | } | 317 | } |
320 | return true; | 318 | return true; |
321 | } | 319 | } |
322 | 320 | ||
323 | /** | 321 | /** |
324 | * This displays a confirmation dialog wether a user should be deleted or not. | 322 | * This displays a confirmation dialog wether a user should be deleted or not. |
325 | * (And also deletes the account) | 323 | * (And also deletes the account) |
326 | * | 324 | * |
327 | * @param username User to be deleted. | 325 | * @param username User to be deleted. |
328 | * | 326 | * |
329 | * @return <code>true</code> if the user was successfully deleted, otherwise <code>false</code>. | 327 | * @return <code>true</code> if the user was successfully deleted, otherwise <code>false</code>. |
330 | * | 328 | * |
331 | */ | 329 | */ |
332 | bool UserDialog::editUser(const char *username) | 330 | bool UserDialog::editUser(const char *username) |
333 | { | 331 | { |
334 | int invalid_group=0; | 332 | int invalid_group=0; |
335 | // viewmode is a workaround for a bug in qte-2.3.4 that gives bus error on manipulating edituserDialog's widgets here. | 333 | // viewmode is a workaround for a bug in qte-2.3.4 that gives bus error on manipulating edituserDialog's widgets here. |
336 | UserDialog *edituserDialog=new UserDialog(VIEWMODE_EDIT); // Create Dialog | 334 | UserDialog *edituserDialog=new UserDialog(VIEWMODE_EDIT); // Create Dialog |
337 | edituserDialog->setCaption(tr("Edit User")); | 335 | edituserDialog->setCaption(tr("Edit User")); |
338 | accounts->findUser(username); // Locate user in database and fill variables in 'accounts' object. | 336 | accounts->findUser(username); // Locate user in database and fill variables in 'accounts' object. |
339 | if(!(accounts->findGroup(accounts->pw_gid))) | 337 | if(!(accounts->findGroup(accounts->pw_gid))) |
340 | { // Locate the user's primary group, and fill group variables in 'accounts' object. | 338 | { // Locate the user's primary group, and fill group variables in 'accounts' object. |
341 | invalid_group=1; | 339 | invalid_group=1; |
342 | } | 340 | } |
343 | // Fill widgets with userinfo. | 341 | // Fill widgets with userinfo. |
344 | edituserDialog->loginLineEdit->setText(accounts->pw_name); | 342 | edituserDialog->loginLineEdit->setText(accounts->pw_name); |
345 | edituserDialog->uidLineEdit->setText(QString::number(accounts->pw_uid)); | 343 | edituserDialog->uidLineEdit->setText(QString::number(accounts->pw_uid)); |
346 | edituserDialog->gecosLineEdit->setText(accounts->pw_gecos); | 344 | edituserDialog->gecosLineEdit->setText(accounts->pw_gecos); |
347 | // Set password to '........', we will later check if this still is the contents, if not, the password has been changed. | 345 | // Set password to '........', we will later check if this still is the contents, if not, the password has been changed. |
348 | edituserDialog->passwordLineEdit->setText("........"); | 346 | edituserDialog->passwordLineEdit->setText("........"); |
349 | // If this user is not using /bin/sh,/bin/ash or /bin/false as shell, add that entry to the shell-combobox. | 347 | // If this user is not using /bin/sh,/bin/ash or /bin/false as shell, add that entry to the shell-combobox. |
350 | if(accounts->pw_shell!="/bin/sh" && accounts->pw_shell!="/bin/ash" && accounts->pw_shell!="/bin/false") | 348 | if(accounts->pw_shell!="/bin/sh" && accounts->pw_shell!="/bin/ash" && accounts->pw_shell!="/bin/false") |
351 | { | 349 | { |
352 | edituserDialog->shellComboBox->insertItem(accounts->pw_shell,0); | 350 | edituserDialog->shellComboBox->insertItem(accounts->pw_shell,0); |
353 | edituserDialog->shellComboBox->setCurrentItem(0); | 351 | edituserDialog->shellComboBox->setCurrentItem(0); |
354 | } | 352 | } |
355 | // Select the primary group for this user. | 353 | // Select the primary group for this user. |
356 | for(int i=0;i<edituserDialog->groupComboBox->count();++i) | 354 | for(int i=0;i<edituserDialog->groupComboBox->count();++i) |
357 | { | 355 | { |
358 | if(accounts->gr_name==edituserDialog->groupComboBox->text(i)) | 356 | if(accounts->gr_name==edituserDialog->groupComboBox->text(i)) |
359 | { | 357 | { |
360 | edituserDialog->groupComboBox->setCurrentItem(i); | 358 | edituserDialog->groupComboBox->setCurrentItem(i); |
361 | break; | 359 | break; |
362 | } | 360 | } |
363 | } | 361 | } |
364 | if(invalid_group) | 362 | if(invalid_group) |
365 | { | 363 | { |
366 | edituserDialog->groupComboBox->insertItem("<Undefined group>",0); | 364 | edituserDialog->groupComboBox->insertItem("<Undefined group>",0); |
367 | edituserDialog->groupComboBox->setCurrentItem(0); | 365 | edituserDialog->groupComboBox->setCurrentItem(0); |
368 | } | 366 | } |
369 | 367 | ||
370 | // Select the groups in the listview, to which the user belongs. | 368 | // Select the groups in the listview, to which the user belongs. |
371 | QCheckListItem *temp; | 369 | QCheckListItem *temp; |
372 | // BAH!!! QRegExp in qt2 sucks... or maybe I do... can't figure out how to check for EITHER end of input ($) OR a comma, so here we do two different QRegExps instead. | 370 | // BAH!!! QRegExp in qt2 sucks... or maybe I do... can't figure out how to check for EITHER end of input ($) OR a comma, so here we do two different QRegExps instead. |
373 | QRegExp userRegExp(QString("[:,]%1$").arg(username)); // The end of line variant. | 371 | QRegExp userRegExp(QString("[:,]%1$").arg(username)); // The end of line variant. |
374 | QStringList tempList=accounts->groupStringList.grep(userRegExp); // Find all entries in the group database, that the user is a member of. | 372 | QStringList tempList=accounts->groupStringList.grep(userRegExp); // Find all entries in the group database, that the user is a member of. |
375 | for(QStringList::Iterator it=tempList.begin(); it!=tempList.end(); ++it) | 373 | for(QStringList::Iterator it=tempList.begin(); it!=tempList.end(); ++it) |
376 | { // Iterate over all of them. | 374 | { // Iterate over all of them. |
377 | qWarning(*it); | 375 | owarn << *it << oendl; |
378 | QListViewItemIterator lvit( edituserDialog->groupsListView ); // Compare to all groups. | 376 | QListViewItemIterator lvit( edituserDialog->groupsListView ); // Compare to all groups. |
379 | for ( ; lvit.current(); ++lvit ) | 377 | for ( ; lvit.current(); ++lvit ) |
380 | { | 378 | { |
381 | if(lvit.current()->text(0)==(*it).left((*it).find(":"))) | 379 | if(lvit.current()->text(0)==(*it).left((*it).find(":"))) |
382 | { | 380 | { |
383 | temp=(QCheckListItem*)lvit.current(); | 381 | temp=(QCheckListItem*)lvit.current(); |
384 | temp->setOn(true); // If we find a line with that groupname, select it.; | 382 | temp->setOn(true); // If we find a line with that groupname, select it.; |
385 | } | 383 | } |
386 | } | 384 | } |
387 | } | 385 | } |
388 | userRegExp=QRegExp(QString("[:,]%1,").arg(username)); // And the other one. (not end of line.) | 386 | userRegExp=QRegExp(QString("[:,]%1,").arg(username)); // And the other one. (not end of line.) |
389 | tempList=accounts->groupStringList.grep(userRegExp); // Find all entries in the group database, that the user is a member of. | 387 | tempList=accounts->groupStringList.grep(userRegExp); // Find all entries in the group database, that the user is a member of. |
390 | for(QStringList::Iterator it=tempList.begin(); it!=tempList.end(); ++it) | 388 | for(QStringList::Iterator it=tempList.begin(); it!=tempList.end(); ++it) |
391 | { // Iterate over all of them. | 389 | { // Iterate over all of them. |
392 | qWarning(*it); | 390 | owarn << *it << oendl; |
393 | QListViewItemIterator lvit( edituserDialog->groupsListView ); // Compare to all groups. | 391 | QListViewItemIterator lvit( edituserDialog->groupsListView ); // Compare to all groups. |
394 | for ( ; lvit.current(); ++lvit ) | 392 | for ( ; lvit.current(); ++lvit ) |
395 | { | 393 | { |
396 | if(lvit.current()->text(0)==(*it).left((*it).find(":"))) | 394 | if(lvit.current()->text(0)==(*it).left((*it).find(":"))) |
397 | { | 395 | { |
398 | temp=(QCheckListItem*)lvit.current(); | 396 | temp=(QCheckListItem*)lvit.current(); |
399 | temp->setOn(true); // If we find a line with that groupname, select it.; | 397 | temp->setOn(true); // If we find a line with that groupname, select it.; |
400 | } | 398 | } |
401 | } | 399 | } |
402 | } | 400 | } |
403 | 401 | ||
404 | if(!(edituserDialog->exec())) return false; // SHOW THE DIALOG! | 402 | if(!(edituserDialog->exec())) return false; // SHOW THE DIALOG! |
405 | 403 | ||
406 | accounts->findUser(username); // Fill user variables in 'acccounts' object. | 404 | accounts->findUser(username); // Fill user variables in 'acccounts' object. |
407 | accounts->pw_name=edituserDialog->loginLineEdit->text(); | 405 | accounts->pw_name=edituserDialog->loginLineEdit->text(); |
408 | // Has the password been changed ? Make a new "crypt":ed password. | 406 | // Has the password been changed ? Make a new "crypt":ed password. |
409 | if(edituserDialog->passwordLineEdit->text()!="........") accounts->pw_passwd=crypt(edituserDialog->passwordLineEdit->text(), accounts->crypt_make_salt()); | 407 | if(edituserDialog->passwordLineEdit->text()!="........") accounts->pw_passwd=crypt(edituserDialog->passwordLineEdit->text(), accounts->crypt_make_salt()); |
410 | 408 | ||
411 | // Set all variables in accounts object, that will be used when calling 'updateUser()' | 409 | // Set all variables in accounts object, that will be used when calling 'updateUser()' |
412 | accounts->pw_uid=edituserDialog->uidLineEdit->text().toInt(); | 410 | accounts->pw_uid=edituserDialog->uidLineEdit->text().toInt(); |
413 | if(accounts->findGroup(edituserDialog->groupComboBox->currentText())) | 411 | if(accounts->findGroup(edituserDialog->groupComboBox->currentText())) |
414 | { // Fill all group variables in 'accounts' object. | 412 | { // Fill all group variables in 'accounts' object. |
415 | accounts->pw_gid=accounts->gr_gid; // Only do this if the group is a valid group (ie. "<Undefined group>"), otherwise keep the old group. | 413 | accounts->pw_gid=accounts->gr_gid; // Only do this if the group is a valid group (ie. "<Undefined group>"), otherwise keep the old group. |
416 | } | 414 | } |
417 | accounts->pw_gecos=edituserDialog->gecosLineEdit->text(); | 415 | accounts->pw_gecos=edituserDialog->gecosLineEdit->text(); |
418 | accounts->pw_shell=edituserDialog->shellComboBox->currentText(); | 416 | accounts->pw_shell=edituserDialog->shellComboBox->currentText(); |
419 | // Update userinfo, using the information stored in the user variables stored in the accounts object. | 417 | // Update userinfo, using the information stored in the user variables stored in the accounts object. |
420 | accounts->updateUser(username); | 418 | accounts->updateUser(username); |
421 | 419 | ||
422 | // Remove user from all groups he/she is a member of. (could be done in a better way I guess, this was simple though.) | 420 | // Remove user from all groups he/she is a member of. (could be done in a better way I guess, this was simple though.) |
423 | for(QStringList::Iterator it=tempList.begin(); it!=tempList.end(); ++it) | 421 | for(QStringList::Iterator it=tempList.begin(); it!=tempList.end(); ++it) |
424 | { | 422 | { |
425 | accounts->delGroupMember((*it).left((*it).find(":")),username); | 423 | accounts->delGroupMember((*it).left((*it).find(":")),username); |
426 | } | 424 | } |
427 | 425 | ||
428 | // Add User to additional groups that he/she is a member of. | 426 | // Add User to additional groups that he/she is a member of. |
429 | QListViewItemIterator it( edituserDialog->groupsListView ); | 427 | QListViewItemIterator it( edituserDialog->groupsListView ); |
430 | for ( ; it.current(); ++it ) | 428 | for ( ; it.current(); ++it ) |
431 | { | 429 | { |
432 | temp=(QCheckListItem*)it.current(); | 430 | temp=(QCheckListItem*)it.current(); |
433 | if ( temp->isOn() ) | 431 | if ( temp->isOn() ) |
434 | accounts->addGroupMember(it.current()->text(0),edituserDialog->loginLineEdit->text()); | 432 | accounts->addGroupMember(it.current()->text(0),edituserDialog->loginLineEdit->text()); |
435 | } | 433 | } |
436 | 434 | ||
437 | // Copy image to pics/users/ | 435 | // Copy image to pics/users/ |
438 | if(!(edituserDialog->userImage.isNull())) | 436 | if(!(edituserDialog->userImage.isNull())) |
439 | { | 437 | { |
440 | QDir d; | 438 | QDir d; |
441 | if(!(d.exists("/opt/QtPalmtop/pics/users"))) | 439 | if(!(d.exists("/opt/QtPalmtop/pics/users"))) |
442 | { | 440 | { |
443 | d.mkdir("/opt/QtPalmtop/pics/users"); | 441 | d.mkdir("/opt/QtPalmtop/pics/users"); |
444 | } | 442 | } |
445 | QString filename="/opt/QtPalmtop/pics/users/"+accounts->pw_name+".png"; | 443 | QString filename="/opt/QtPalmtop/pics/users/"+accounts->pw_name+".png"; |
446 | // edituserDialog->userImage=edituserDialog->userImage.smoothScale(48,48); | 444 | // edituserDialog->userImage=edituserDialog->userImage.smoothScale(48,48); |
447 | edituserDialog->userImage.save(filename,"PNG"); | 445 | edituserDialog->userImage.save(filename,"PNG"); |
448 | } | 446 | } |
449 | return true; | 447 | return true; |
450 | } | 448 | } |
451 | 449 | ||
452 | /** | 450 | /** |
453 | * "OK" has been clicked. Verify some information before closing the dialog. | 451 | * "OK" has been clicked. Verify some information before closing the dialog. |
454 | * | 452 | * |
455 | */ | 453 | */ |
456 | void UserDialog::accept() | 454 | void UserDialog::accept() |
457 | { | 455 | { |
458 | // Add checking... valid username? username taken? | 456 | // Add checking... valid username? username taken? |
459 | if(loginLineEdit->text().isEmpty()) | 457 | if(loginLineEdit->text().isEmpty()) |
460 | { | 458 | { |
461 | QMessageBox::information(0,"Empty Login","Please enter a login."); | 459 | QMessageBox::information(0,"Empty Login","Please enter a login."); |
462 | return; | 460 | return; |
463 | } | 461 | } |
464 | QDialog::accept(); | 462 | QDialog::accept(); |
465 | } | 463 | } |
466 | 464 | ||
467 | /** | 465 | /** |
468 | * This slot is called when the usericon is clicked, this loads (should) the iconselector. | 466 | * This slot is called when the usericon is clicked, this loads (should) the iconselector. |
469 | * | 467 | * |
470 | */ | 468 | */ |
471 | void UserDialog::clickedPicture() | 469 | void UserDialog::clickedPicture() |
472 | { | 470 | { |
473 | QString filename=OFileDialog::getOpenFileName(OFileSelector::EXTENDED, QString::null); | 471 | QString filename=OFileDialog::getOpenFileName(OFileSelector::EXTENDED, QString::null); |
474 | if(!(filename.isEmpty())) | 472 | if(!(filename.isEmpty())) |
475 | { | 473 | { |
476 | userImage.reset(); | 474 | userImage.reset(); |
477 | if(!(userImage.load(filename))) | 475 | if(!(userImage.load(filename))) |
478 | { | 476 | { |
479 | QMessageBox::information(0,"Sorry!","That icon could not be loaded.\nLoading failed on: "+filename); | 477 | QMessageBox::information(0,"Sorry!","That icon could not be loaded.\nLoading failed on: "+filename); |
480 | } | 478 | } |
481 | else | 479 | else |
482 | { | 480 | { |
483 | // userImage=userImage.smoothScale(48,48); | 481 | // userImage=userImage.smoothScale(48,48); |
484 | QPixmap *picture; | 482 | QPixmap *picture; |
485 | picture=(QPixmap *)picturePushButton->pixmap(); | 483 | picture=(QPixmap *)picturePushButton->pixmap(); |
486 | picture->convertFromImage(userImage,0); | 484 | picture->convertFromImage(userImage,0); |
487 | picturePushButton->update(); | 485 | picturePushButton->update(); |
488 | } | 486 | } |
diff --git a/noncore/settings/usermanager/usermanager.cpp b/noncore/settings/usermanager/usermanager.cpp index a1130d4..1d345ee 100644 --- a/noncore/settings/usermanager/usermanager.cpp +++ b/noncore/settings/usermanager/usermanager.cpp | |||
@@ -1,113 +1,116 @@ | |||
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 "usermanager.h" | 10 | #include "usermanager.h" |
11 | 11 | ||
12 | #include <qlayout.h> | 12 | /* OPIE */ |
13 | #include <opie2/odebug.h> | ||
14 | #include <qpe/resource.h> | ||
15 | using namespace Opie::Core; | ||
13 | 16 | ||
17 | /* QT */ | ||
18 | #include <qlayout.h> | ||
14 | #include <qmessagebox.h> | 19 | #include <qmessagebox.h> |
15 | #include <qfile.h> | 20 | #include <qfile.h> |
16 | #include <qpe/resource.h> | ||
17 | |||
18 | #include <qregexp.h> | 21 | #include <qregexp.h> |
19 | 22 | ||
20 | /** | 23 | /** |
21 | * The mainwindow constructor. | 24 | * The mainwindow constructor. |
22 | * | 25 | * |
23 | * @param QWidget *parent | 26 | * @param QWidget *parent |
24 | * @param const char *name | 27 | * @param const char *name |
25 | * @ param WFlags fl | 28 | * @ param WFlags fl |
26 | * | 29 | * |
27 | */ | 30 | */ |
28 | UserConfig::UserConfig(QWidget* parent, const char* name, WFlags fl) : QMainWindow(parent, name, fl) { | 31 | UserConfig::UserConfig(QWidget* parent, const char* name, WFlags fl) : QMainWindow(parent, name, fl) { |
29 | setCaption(tr("Opie User Manager")); | 32 | setCaption(tr("Opie User Manager")); |
30 | 33 | ||
31 | // Create an instance of the global object 'accounts'. This holds all user/group info, and functions to modify them. | 34 | // Create an instance of the global object 'accounts'. This holds all user/group info, and functions to modify them. |
32 | accounts=new Passwd(); | 35 | accounts=new Passwd(); |
33 | accounts->open();// This actually loads the files /etc/passwd & /etc/group into memory. | 36 | accounts->open();// This actually loads the files /etc/passwd & /etc/group into memory. |
34 | 37 | ||
35 | // Create the toolbar. | 38 | // Create the toolbar. |
36 | QToolBar *toolbar = new QToolBar(this,"Toolbar"); | 39 | QToolBar *toolbar = new QToolBar(this,"Toolbar"); |
37 | toolbar->setHorizontalStretchable(1); // Is there any other way to get the toolbar to stretch of the full screen!? | 40 | toolbar->setHorizontalStretchable(1); // Is there any other way to get the toolbar to stretch of the full screen!? |
38 | adduserToolButton = new QToolButton(Resource::loadPixmap("usermanager/adduser"),"Add User",0,this,SLOT(addUser()),toolbar,"Add User"); | 41 | adduserToolButton = new QToolButton(Resource::loadPixmap("usermanager/adduser"),"Add User",0,this,SLOT(addUser()),toolbar,"Add User"); |
39 | edituserToolButton = new QToolButton(Resource::loadPixmap("usermanager/edituser"),"Edit User",0,this,SLOT(editUser()),toolbar,"Edit User"); | 42 | edituserToolButton = new QToolButton(Resource::loadPixmap("usermanager/edituser"),"Edit User",0,this,SLOT(editUser()),toolbar,"Edit User"); |
40 | deleteuserToolButton = new QToolButton(Resource::loadPixmap("usermanager/deleteuser"),"Delete User",0,this,SLOT(delUser()),toolbar,"Delete User"); | 43 | deleteuserToolButton = new QToolButton(Resource::loadPixmap("usermanager/deleteuser"),"Delete User",0,this,SLOT(delUser()),toolbar,"Delete User"); |
41 | QToolButton *userstext = new QToolButton(0,"User",0,0,0,toolbar,"User"); | 44 | QToolButton *userstext = new QToolButton(0,"User",0,0,0,toolbar,"User"); |
42 | userstext->setUsesTextLabel(true); | 45 | userstext->setUsesTextLabel(true); |
43 | toolbar->addSeparator(); | 46 | toolbar->addSeparator(); |
44 | addgroupToolButton = new QToolButton(Resource::loadPixmap("usermanager/addgroup"),"Add Group",0,this,SLOT(addGroup()),toolbar,"Add Group"); | 47 | addgroupToolButton = new QToolButton(Resource::loadPixmap("usermanager/addgroup"),"Add Group",0,this,SLOT(addGroup()),toolbar,"Add Group"); |
45 | editgroupToolButton = new QToolButton(Resource::loadPixmap("usermanager/editgroup"),"Edit Group",0,this,SLOT(editGroup()),toolbar,"Edit Group"); | 48 | editgroupToolButton = new QToolButton(Resource::loadPixmap("usermanager/editgroup"),"Edit Group",0,this,SLOT(editGroup()),toolbar,"Edit Group"); |
46 | deletegroupToolButton = new QToolButton(Resource::loadPixmap("usermanager/deletegroup"),"Delete Group",0,this,SLOT(delGroup()),toolbar,"Delete Group"); | 49 | deletegroupToolButton = new QToolButton(Resource::loadPixmap("usermanager/deletegroup"),"Delete Group",0,this,SLOT(delGroup()),toolbar,"Delete Group"); |
47 | QToolButton *groupstext = new QToolButton(0,"Group",0,0,0,toolbar,"Group"); | 50 | QToolButton *groupstext = new QToolButton(0,"Group",0,0,0,toolbar,"Group"); |
48 | groupstext->setUsesTextLabel(true); | 51 | groupstext->setUsesTextLabel(true); |
49 | addToolBar(toolbar,"myToolBar"); | 52 | addToolBar(toolbar,"myToolBar"); |
50 | 53 | ||
51 | // Add a tabwidget and all the tabs. | 54 | // Add a tabwidget and all the tabs. |
52 | myTabWidget = new QTabWidget(this,"My Tab Widget"); | 55 | myTabWidget = new QTabWidget(this,"My Tab Widget"); |
53 | setupTabAccounts(); | 56 | setupTabAccounts(); |
54 | setupTabAllUsers(); | 57 | setupTabAllUsers(); |
55 | setupTabAllGroups(); | 58 | setupTabAllGroups(); |
56 | userPopupMenu.insertItem("Copy",0); | 59 | userPopupMenu.insertItem("Copy",0); |
57 | 60 | ||
58 | getUsers(); // Fill out the iconview & listview with all users. | 61 | getUsers(); // Fill out the iconview & listview with all users. |
59 | getGroups(); // Fill out the group listview with all groups. | 62 | getGroups(); // Fill out the group listview with all groups. |
60 | 63 | ||
61 | setCentralWidget(myTabWidget); | 64 | setCentralWidget(myTabWidget); |
62 | } | 65 | } |
63 | 66 | ||
64 | UserConfig::~UserConfig() { | 67 | UserConfig::~UserConfig() { |
65 | accounts->close(); | 68 | accounts->close(); |
66 | delete accounts; | 69 | delete accounts; |
67 | } | 70 | } |
68 | 71 | ||
69 | void UserConfig::setupTabAccounts() { | 72 | void UserConfig::setupTabAccounts() { |
70 | QWidget *tabpage = new QWidget(this); | 73 | QWidget *tabpage = new QWidget(this); |
71 | QVBoxLayout *layout = new QVBoxLayout(tabpage); | 74 | QVBoxLayout *layout = new QVBoxLayout(tabpage); |
72 | layout->setMargin(5); | 75 | layout->setMargin(5); |
73 | 76 | ||
74 | usersIconView=new QListView(tabpage,"users"); | 77 | usersIconView=new QListView(tabpage,"users"); |
75 | usersIconView->addColumn("Icon"); | 78 | usersIconView->addColumn("Icon"); |
76 | usersIconView->addColumn("Username"); | 79 | usersIconView->addColumn("Username"); |
77 | usersIconView->setAllColumnsShowFocus(true); | 80 | usersIconView->setAllColumnsShowFocus(true); |
78 | layout->addWidget(usersIconView); | 81 | layout->addWidget(usersIconView); |
79 | 82 | ||
80 | connect(usersIconView,SIGNAL(returnPressed(QListViewItem*)),this,SLOT(showUserMenu(QListViewItem*))); | 83 | connect(usersIconView,SIGNAL(returnPressed(QListViewItem*)),this,SLOT(showUserMenu(QListViewItem*))); |
81 | 84 | ||
82 | myTabWidget->addTab(tabpage,"Users"); | 85 | myTabWidget->addTab(tabpage,"Users"); |
83 | } | 86 | } |
84 | 87 | ||
85 | void UserConfig::setupTabAllUsers() { | 88 | void UserConfig::setupTabAllUsers() { |
86 | QWidget *tabpage = new QWidget(this); | 89 | QWidget *tabpage = new QWidget(this); |
87 | QVBoxLayout *layout = new QVBoxLayout(tabpage); | 90 | QVBoxLayout *layout = new QVBoxLayout(tabpage); |
88 | layout->setMargin(5); | 91 | layout->setMargin(5); |
89 | 92 | ||
90 | usersListView=new QListView(tabpage,"allusers"); | 93 | usersListView=new QListView(tabpage,"allusers"); |
91 | usersListView->addColumn("UID"); | 94 | usersListView->addColumn("UID"); |
92 | usersListView->addColumn("Login"); | 95 | usersListView->addColumn("Login"); |
93 | usersListView->addColumn("Username"); | 96 | usersListView->addColumn("Username"); |
94 | layout->addWidget(usersListView); | 97 | layout->addWidget(usersListView); |
95 | usersListView->setSorting(1,1); | 98 | usersListView->setSorting(1,1); |
96 | usersListView->setAllColumnsShowFocus(true); | 99 | usersListView->setAllColumnsShowFocus(true); |
97 | 100 | ||
98 | myTabWidget->addTab(tabpage,"All Users"); | 101 | myTabWidget->addTab(tabpage,"All Users"); |
99 | } | 102 | } |
100 | 103 | ||
101 | void UserConfig::setupTabAllGroups() { | 104 | void UserConfig::setupTabAllGroups() { |
102 | QWidget *tabpage = new QWidget(this); | 105 | QWidget *tabpage = new QWidget(this); |
103 | QVBoxLayout *layout = new QVBoxLayout(tabpage); | 106 | QVBoxLayout *layout = new QVBoxLayout(tabpage); |
104 | layout->setMargin(5); | 107 | layout->setMargin(5); |
105 | 108 | ||
106 | groupsListView=new QListView(tabpage,"groups"); | 109 | groupsListView=new QListView(tabpage,"groups"); |
107 | groupsListView->addColumn("GID"); | 110 | groupsListView->addColumn("GID"); |
108 | groupsListView->addColumn("Groupname"); | 111 | groupsListView->addColumn("Groupname"); |
109 | layout->addWidget(groupsListView); | 112 | layout->addWidget(groupsListView); |
110 | groupsListView->setSorting(1,1); | 113 | groupsListView->setSorting(1,1); |
111 | groupsListView->setAllColumnsShowFocus(true); | 114 | groupsListView->setAllColumnsShowFocus(true); |
112 | 115 | ||
113 | myTabWidget->addTab(tabpage,"All Groups"); | 116 | myTabWidget->addTab(tabpage,"All Groups"); |
@@ -160,98 +163,98 @@ void UserConfig::editUser() { | |||
160 | getGroups(); | 163 | getGroups(); |
161 | } | 164 | } |
162 | } else { | 165 | } else { |
163 | QMessageBox::information(this,"No selection.","No user has been selected."); | 166 | QMessageBox::information(this,"No selection.","No user has been selected."); |
164 | } | 167 | } |
165 | } | 168 | } |
166 | if(myTabWidget->currentPageIndex()==1) {// All users | 169 | if(myTabWidget->currentPageIndex()==1) {// All users |
167 | if(usersListView->currentItem()) {// Anything changed!? | 170 | if(usersListView->currentItem()) {// Anything changed!? |
168 | username=usersListView->currentItem()->text(1);// Get the username. | 171 | username=usersListView->currentItem()->text(1);// Get the username. |
169 | if(UserDialog::editUser(username)) {// Bring up the userinfo dialog. | 172 | if(UserDialog::editUser(username)) {// Bring up the userinfo dialog. |
170 | // And again update the views if there were any changes. | 173 | // And again update the views if there were any changes. |
171 | getUsers(); | 174 | getUsers(); |
172 | getGroups(); | 175 | getGroups(); |
173 | } | 176 | } |
174 | } else { | 177 | } else { |
175 | QMessageBox::information(this,"No selection.","No user has been selected."); | 178 | QMessageBox::information(this,"No selection.","No user has been selected."); |
176 | } | 179 | } |
177 | } | 180 | } |
178 | } | 181 | } |
179 | 182 | ||
180 | void UserConfig::delUser() { | 183 | void UserConfig::delUser() { |
181 | QString username; | 184 | QString username; |
182 | 185 | ||
183 | if(myTabWidget->currentPageIndex()==0) {// Users, Iconview. | 186 | if(myTabWidget->currentPageIndex()==0) {// Users, Iconview. |
184 | if(usersIconView->currentItem()) {// Anything selected? | 187 | if(usersIconView->currentItem()) {// Anything selected? |
185 | username=usersIconView->currentItem()->text(1);// Get string associated with icon. | 188 | username=usersIconView->currentItem()->text(1);// Get string associated with icon. |
186 | username=username.left(username.find(" - (",0,true));// Strip out the username. | 189 | username=username.left(username.find(" - (",0,true));// Strip out the username. |
187 | if(QMessageBox::warning(this,"Delete user","Are you sure you want to\ndelete this user? \""+QString(username)+"\" ?","&No","&Yes",0,0,1)) { | 190 | if(QMessageBox::warning(this,"Delete user","Are you sure you want to\ndelete this user? \""+QString(username)+"\" ?","&No","&Yes",0,0,1)) { |
188 | if(UserDialog::delUser(username)) {// Delete the user if possible. | 191 | if(UserDialog::delUser(username)) {// Delete the user if possible. |
189 | // Update views. | 192 | // Update views. |
190 | getUsers(); | 193 | getUsers(); |
191 | getGroups(); | 194 | getGroups(); |
192 | } | 195 | } |
193 | } | 196 | } |
194 | } else { | 197 | } else { |
195 | QMessageBox::information(this,"No selection","No user has been selected."); | 198 | QMessageBox::information(this,"No selection","No user has been selected."); |
196 | } | 199 | } |
197 | } | 200 | } |
198 | if(myTabWidget->currentPageIndex()==1) {// All users | 201 | if(myTabWidget->currentPageIndex()==1) {// All users |
199 | if(usersListView->currentItem()) {// Anything changed!? | 202 | if(usersListView->currentItem()) {// Anything changed!? |
200 | username=usersListView->currentItem()->text(1);// Get the username. | 203 | username=usersListView->currentItem()->text(1);// Get the username. |
201 | if(QMessageBox::warning(this,"Delete user","Are you sure you want to\ndelete this user? \""+QString(username)+"\" ?","&No","&Yes",0,0,1)) { | 204 | if(QMessageBox::warning(this,"Delete user","Are you sure you want to\ndelete this user? \""+QString(username)+"\" ?","&No","&Yes",0,0,1)) { |
202 | if(UserDialog::delUser(username)) {// Try to delete the user. | 205 | if(UserDialog::delUser(username)) {// Try to delete the user. |
203 | // Update views. | 206 | // Update views. |
204 | getUsers(); | 207 | getUsers(); |
205 | getGroups(); | 208 | getGroups(); |
206 | } | 209 | } |
207 | } | 210 | } |
208 | } else { | 211 | } else { |
209 | QMessageBox::information(this,"No selection","No user has been selected."); | 212 | QMessageBox::information(this,"No selection","No user has been selected."); |
210 | } | 213 | } |
211 | } | 214 | } |
212 | 215 | ||
213 | } | 216 | } |
214 | 217 | ||
215 | void UserConfig::getGroups() { | 218 | void UserConfig::getGroups() { |
216 | groupsListView->clear();// Empty the listview. | 219 | groupsListView->clear();// Empty the listview. |
217 | availableGID=500;// We need to find the next free GID, and are only interested in values between 500 & 65000. | 220 | availableGID=500;// We need to find the next free GID, and are only interested in values between 500 & 65000. |
218 | for(QStringList::Iterator it=accounts->groupStringList.begin(); it!=accounts->groupStringList.end(); ++it) {// Split the list into lines. | 221 | for(QStringList::Iterator it=accounts->groupStringList.begin(); it!=accounts->groupStringList.end(); ++it) {// Split the list into lines. |
219 | accounts->splitGroupEntry(*it);// Split the line into its components and fill the variables of 'accounts'. (gr_name, gr_uid & gr_mem). | 222 | accounts->splitGroupEntry(*it);// Split the line into its components and fill the variables of 'accounts'. (gr_name, gr_uid & gr_mem). |
220 | if(accounts->gr_name.find(QRegExp("^#"),0)) {// Skip commented lines. | 223 | if(accounts->gr_name.find(QRegExp("^#"),0)) {// Skip commented lines. |
221 | new QListViewItem(groupsListView,QString::number(accounts->gr_gid),accounts->gr_name); | 224 | new QListViewItem(groupsListView,QString::number(accounts->gr_gid),accounts->gr_name); |
222 | if((accounts->gr_gid>=availableGID) && (accounts->gr_gid<65000)) availableGID=accounts->gr_gid+1;// Maybe a new free GID. | 225 | if((accounts->gr_gid>=availableGID) && (accounts->gr_gid<65000)) availableGID=accounts->gr_gid+1;// Maybe a new free GID. |
223 | } | 226 | } |
224 | } | 227 | } |
225 | } | 228 | } |
226 | 229 | ||
227 | void UserConfig::addGroup() { | 230 | void UserConfig::addGroup() { |
228 | if(GroupDialog::addGroup(availableGID)) getGroups();// Bring up the add group dialog. | 231 | if(GroupDialog::addGroup(availableGID)) getGroups();// Bring up the add group dialog. |
229 | } | 232 | } |
230 | 233 | ||
231 | void UserConfig::editGroup() { | 234 | void UserConfig::editGroup() { |
232 | int gid; | 235 | int gid; |
233 | if(groupsListView->currentItem()) {// Any group selected? | 236 | if(groupsListView->currentItem()) {// Any group selected? |
234 | gid=groupsListView->currentItem()->text(0).toInt();// Get the GID from the listview. | 237 | gid=groupsListView->currentItem()->text(0).toInt();// Get the GID from the listview. |
235 | if(GroupDialog::editGroup(gid)) getGroups();// Bring up the edit group dialog. | 238 | if(GroupDialog::editGroup(gid)) getGroups();// Bring up the edit group dialog. |
236 | } else { | 239 | } else { |
237 | QMessageBox::information(this,"No selection","No group has been selected."); | 240 | QMessageBox::information(this,"No selection","No group has been selected."); |
238 | } | 241 | } |
239 | } | 242 | } |
240 | 243 | ||
241 | void UserConfig::delGroup() { | 244 | void UserConfig::delGroup() { |
242 | const char *groupname; | 245 | const char *groupname; |
243 | if(groupsListView->currentItem()) {// Any group selected? | 246 | if(groupsListView->currentItem()) {// Any group selected? |
244 | groupname=groupsListView->currentItem()->text(1);// Get the groupname from the listview. | 247 | groupname=groupsListView->currentItem()->text(1);// Get the groupname from the listview. |
245 | if(QMessageBox::warning(this,"Delete group","Are you sure you want to\ndelete the group \""+QString(groupname)+"\" ?","&No","&Yes",0,0,1)) { | 248 | if(QMessageBox::warning(this,"Delete group","Are you sure you want to\ndelete the group \""+QString(groupname)+"\" ?","&No","&Yes",0,0,1)) { |
246 | // If confirmed, try to delete the group. | 249 | // If confirmed, try to delete the group. |
247 | if(GroupDialog::delGroup(groupname)) getGroups(); // And also update the view afterwards if the user was deleted. | 250 | if(GroupDialog::delGroup(groupname)) getGroups(); // And also update the view afterwards if the user was deleted. |
248 | } | 251 | } |
249 | } else { | 252 | } else { |
250 | QMessageBox::information(this,"No selection","No group has been selected."); | 253 | QMessageBox::information(this,"No selection","No group has been selected."); |
251 | } | 254 | } |
252 | } | 255 | } |
253 | 256 | ||
254 | void UserConfig::showUserMenu(QListViewItem *item) { | 257 | void UserConfig::showUserMenu(QListViewItem *item) { |
255 | //userPopupMenu.exec(item->mapToGlobal(QPoint(0,0))); | 258 | //userPopupMenu.exec(item->mapToGlobal(QPoint(0,0))); |
256 | qWarning("Pressed!"); | 259 | owarn << "Pressed!" << oendl; |
257 | } | 260 | } |
diff --git a/noncore/settings/usermanager/usermanager.pro b/noncore/settings/usermanager/usermanager.pro index d0647dd..31f52a6 100644 --- a/noncore/settings/usermanager/usermanager.pro +++ b/noncore/settings/usermanager/usermanager.pro | |||
@@ -1,10 +1,9 @@ | |||
1 | #CONFIG = qt warn_on | 1 | CONFIG = qt warn_on quick-app |
2 | CONFIG = qt warn_on quick-app | ||
3 | HEADERS = usermanager.h userdialog.h groupdialog.h passwd.h | 2 | HEADERS = usermanager.h userdialog.h groupdialog.h passwd.h |
4 | SOURCES = usermanager.cpp userdialog.cpp groupdialog.cpp passwd.cpp main.cpp | 3 | SOURCES = usermanager.cpp userdialog.cpp groupdialog.cpp passwd.cpp main.cpp |
5 | INCLUDEPATH += $(OPIEDIR)/include | 4 | INCLUDEPATH += $(OPIEDIR)/include |
6 | DEPENDPATH += $(OPIEDIR)/include | 5 | DEPENDPATH += $(OPIEDIR)/include |
7 | LIBS += -lqpe -lopiecore2 -lopieui2 -lcrypt | 6 | LIBS += -lqpe -lopiecore2 -lopieui2 -lcrypt |
8 | TARGET = usermanager | 7 | TARGET = usermanager |
9 | 8 | ||
10 | include ( $(OPIEDIR)/include.pro ) | 9 | include ( $(OPIEDIR)/include.pro ) |