summaryrefslogtreecommitdiff
authorumopapisdn <umopapisdn>2002-10-14 20:42:04 (UTC)
committer umopapisdn <umopapisdn>2002-10-14 20:42:04 (UTC)
commit14f450ead20011e5697bb36a4ad087cc648b439d (patch) (unidiff)
tree7b474bbeeba4ceebb50c2da0bf26d80002062970
parent8140420efa133ea59310d3f8de721950fd1d13af (diff)
downloadopie-14f450ead20011e5697bb36a4ad087cc648b439d.zip
opie-14f450ead20011e5697bb36a4ad087cc648b439d.tar.gz
opie-14f450ead20011e5697bb36a4ad087cc648b439d.tar.bz2
New users added in OpenZaurus now by default belong to some groups. (video, audio, time, power, input, sharp, tty)
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/usermanager/userdialog.cpp23
1 files changed, 20 insertions, 3 deletions
diff --git a/noncore/settings/usermanager/userdialog.cpp b/noncore/settings/usermanager/userdialog.cpp
index 90e27d5..c43b391 100644
--- a/noncore/settings/usermanager/userdialog.cpp
+++ b/noncore/settings/usermanager/userdialog.cpp
@@ -1,46 +1,47 @@
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#include <qfile.h>
15 16
16#include <stdlib.h> 17#include <stdlib.h>
17 18
18#include <stdio.h> 19#include <stdio.h>
19#include <sys/types.h> 20#include <sys/types.h>
20#include <sys/wait.h> 21#include <sys/wait.h>
21#include <unistd.h> 22#include <unistd.h>
22#include <signal.h> 23#include <signal.h>
23 24
24#include "passwd.h" 25#include "passwd.h"
25 26
26/** 27/**
27 * UserDialog constructor. Setup the dialog, fill the groupComboBox & groupsListView with all groups. 28 * UserDialog constructor. Setup the dialog, fill the groupComboBox & groupsListView with all groups.
28 * 29 *
29 */ 30 */
30UserDialog::UserDialog(QWidget* parent, const char* name, bool modal, WFlags fl) : QDialog(parent, name, modal, fl) { 31UserDialog::UserDialog(QWidget* parent, const char* name, bool modal, WFlags fl) : QDialog(parent, name, modal, fl) {
31 QVBoxLayout *layout = new QVBoxLayout(this); 32 QVBoxLayout *layout = new QVBoxLayout(this);
32 myTabWidget=new QTabWidget(this,"User Tab Widget"); 33 myTabWidget=new QTabWidget(this,"User Tab Widget");
33 layout->addWidget(myTabWidget); 34 layout->addWidget(myTabWidget);
34 setupTab1(); 35 setupTab1();
35 setupTab2(); 36 setupTab2();
36 37
37 accounts->groupStringList.sort(); 38 accounts->groupStringList.sort();
38 // And also fill the listview & the combobox with all available groups. 39 // And also fill the listview & the combobox with all available groups.
39 for( QStringList::Iterator it = accounts->groupStringList.begin(); it!=accounts->groupStringList.end(); ++it) { 40 for( QStringList::Iterator it = accounts->groupStringList.begin(); it!=accounts->groupStringList.end(); ++it) {
40 accounts->splitGroupEntry(*it); 41 accounts->splitGroupEntry(*it);
41 new QCheckListItem(groupsListView,accounts->gr_name,QCheckListItem::CheckBox); 42 new QCheckListItem(groupsListView,accounts->gr_name,QCheckListItem::CheckBox);
42 groupComboBox->insertItem(accounts->gr_name); 43 groupComboBox->insertItem(accounts->gr_name);
43 } 44 }
44 showMaximized(); 45 showMaximized();
45} 46}
46 47
@@ -158,91 +159,107 @@ void UserDialog::setupTab1() {
158 * 159 *
159 */ 160 */
160void UserDialog::setupTab2() { 161void UserDialog::setupTab2() {
161 QWidget *tabpage = new QWidget(myTabWidget,"page2"); 162 QWidget *tabpage = new QWidget(myTabWidget,"page2");
162 QVBoxLayout *layout = new QVBoxLayout(tabpage); 163 QVBoxLayout *layout = new QVBoxLayout(tabpage);
163 layout->setMargin(5); 164 layout->setMargin(5);
164 165
165 // Additional groups 166 // Additional groups
166 groupsListView=new QListView(tabpage,"groups"); 167 groupsListView=new QListView(tabpage,"groups");
167 groupsListView->addColumn("Additional groups"); 168 groupsListView->addColumn("Additional groups");
168 groupsListView->setColumnWidthMode(0,QListView::Maximum); 169 groupsListView->setColumnWidthMode(0,QListView::Maximum);
169 groupsListView->setMultiSelection(false); 170 groupsListView->setMultiSelection(false);
170 groupsListView->setAllColumnsShowFocus(false); 171 groupsListView->setAllColumnsShowFocus(false);
171 172
172 layout->addSpacing(5); 173 layout->addSpacing(5);
173 // Grouplist 174 // Grouplist
174 layout->addWidget(groupsListView); 175 layout->addWidget(groupsListView);
175 176
176 myTabWidget->addTab(tabpage,"User Groups"); 177 myTabWidget->addTab(tabpage,"User Groups");
177} 178}
178 179
179/** 180/**
180 * Static function that creates the userinfo dialog. 181 * Static function that creates the userinfo dialog.
181 * The user will be prompted to add a user. 182 * The user will be prompted to add a user.
182 * 183 *
183 * @param uid This is a suggested available UID. 184 * @param uid This is a suggested available UID.
184 * @param gid This is a suggested available GID. 185 * @param gid This is a suggested available GID.
185 * 186 *
186 * @return <code>true</code> if the user was successfully added, otherwise <code>false</code>. 187 * @return <code>true</code> if the user was successfully added, otherwise <code>false</code>.
187 * 188 *
188 */ 189 */
189bool UserDialog::addUser(int uid, int gid) { 190bool UserDialog::addUser(int uid, int gid) {
191 QCheckListItem *temp;
192 QFile ozTest;
193 int oz=ozTest.exists("/etc/oz_version");
190 UserDialog *adduserDialog=new UserDialog(); 194 UserDialog *adduserDialog=new UserDialog();
191 adduserDialog->setCaption(tr("Add User")); 195 adduserDialog->setCaption(tr("Add User"));
192 adduserDialog->userID=uid;// Set next available UID as default uid. 196 adduserDialog->userID=uid;// Set next available UID as default uid.
193 adduserDialog->groupID=gid;// Set next available GID as default gid. 197 adduserDialog->groupID=gid;// Set next available GID as default gid.
194 // Insert default group into groupComboBox 198 // Insert default group into groupComboBox
195 adduserDialog->groupComboBox->insertItem("<create new group>",0); 199 adduserDialog->groupComboBox->insertItem("<create new group>",0);
196 adduserDialog->uidLineEdit->setText(QString::number(uid)); 200 adduserDialog->uidLineEdit->setText(QString::number(uid));
201 // If we're running on OZ, add new users to some default groups.
202 if(oz) {
203 QListViewItemIterator iter( adduserDialog->groupsListView );
204 for ( ; iter.current(); ++iter ) {
205 temp=(QCheckListItem*)iter.current();
206 if (temp->text()=="video") temp->setOn(true);
207 if (temp->text()=="audio") temp->setOn(true);
208 if (temp->text()=="time") temp->setOn(true);
209 if (temp->text()=="power") temp->setOn(true);
210 if (temp->text()=="input") temp->setOn(true);
211 if (temp->text()=="sharp") temp->setOn(true);
212 if (temp->text()=="tty") temp->setOn(true);
213 }
214 }
197 // Show the dialog! 215 // Show the dialog!
198 if(!(adduserDialog->exec())) return false; 216 if(!(adduserDialog->exec())) return false;
199 if((adduserDialog->groupComboBox->currentItem()!=0)) { 217 if((adduserDialog->groupComboBox->currentItem()!=0)) {
200 accounts->findGroup(adduserDialog->groupComboBox->currentText()); 218 accounts->findGroup(adduserDialog->groupComboBox->currentText());
201 adduserDialog->groupID=accounts->gr_gid; 219 adduserDialog->groupID=accounts->gr_gid;
202 qWarning(QString::number(accounts->gr_gid)); 220 qWarning(QString::number(accounts->gr_gid));
203 } 221 }
204 if(!(accounts->addUser(adduserDialog->loginLineEdit->text(), adduserDialog->passwordLineEdit->text(), 222 if(!(accounts->addUser(adduserDialog->loginLineEdit->text(), adduserDialog->passwordLineEdit->text(),
205 adduserDialog->uidLineEdit->text().toInt(), adduserDialog->groupID, adduserDialog->gecosLineEdit->text(), 223 adduserDialog->uidLineEdit->text().toInt(), adduserDialog->groupID, adduserDialog->gecosLineEdit->text(),
206 QString("/home/")+adduserDialog->loginLineEdit->text() , adduserDialog->shellComboBox->currentText()))) { 224 QString("/home/")+adduserDialog->loginLineEdit->text() , adduserDialog->shellComboBox->currentText()))) {
207 QMessageBox::information(0,"Ooops!","Something went wrong!\nUnable to add user."); 225 QMessageBox::information(0,"Ooops!","Something went wrong!\nUnable to add user.");
208 return false; 226 return false;
209 } 227 }
210 228
211 // Add User to additional groups. 229 // Add User to additional groups.
212 QCheckListItem *temp;
213 QListViewItemIterator it( adduserDialog->groupsListView ); 230 QListViewItemIterator it( adduserDialog->groupsListView );
214 for ( ; it.current(); ++it ) { 231 for ( ; it.current(); ++it ) {
215 temp=(QCheckListItem*)it.current(); 232 temp=(QCheckListItem*)it.current();
216 if (temp->isOn() ) 233 if (temp->isOn() )
217 accounts->addGroupMember(it.current()->text(0),adduserDialog->loginLineEdit->text()); 234 accounts->addGroupMember(it.current()->text(0),adduserDialog->loginLineEdit->text());
218 } 235 }
219 // Copy image to pics/users/ 236 // Copy image to pics/users/
220 if(!(adduserDialog->userImage.isNull())) { 237 if(!(adduserDialog->userImage.isNull())) {
221 QDir d; 238 QDir d;
222 if(!(d.exists("/opt/QtPalmtop/pics/users"))) { 239 if(!(d.exists("/opt/QtPalmtop/pics/users"))) {
223 d.mkdir("/opt/QtPalmtop/pics/users"); 240 d.mkdir("/opt/QtPalmtop/pics/users");
224 } 241 }
225 QString filename="/opt/QtPalmtop/pics/users/"+accounts->pw_name+".png"; 242 QString filename="/opt/QtPalmtop/pics/users/"+accounts->pw_name+".png";
226 // adduserDialog->userImage=adduserDialog->userImage.smoothScale(48,48); 243 // adduserDialog->userImage=adduserDialog->userImage.smoothScale(48,48);
227 adduserDialog->userImage.save(filename,"PNG"); 244 adduserDialog->userImage.save(filename,"PNG");
228 } 245 }
229 return true; 246 return true;
230} 247}
231 248
232/** 249/**
233 * Deletes the user account. 250 * Deletes the user account.
234 * 251 *
235 * @param username User to be deleted. 252 * @param username User to be deleted.
236 * 253 *
237 * @return <code>true</code> if the user was successfully deleted, otherwise <code>false</code>. 254 * @return <code>true</code> if the user was successfully deleted, otherwise <code>false</code>.
238 * 255 *
239 */ 256 */
240bool UserDialog::delUser(const char *username) { 257bool UserDialog::delUser(const char *username) {
241 if((accounts->findUser(username))) {// Does that user exist? 258 if((accounts->findUser(username))) {// Does that user exist?
242 if(!(accounts->delUser(username))) {// Delete the user. 259 if(!(accounts->delUser(username))) {// Delete the user.
243 QMessageBox::information(0,"Ooops!","Something went wrong\nUnable to delete user: "+QString(username)+"."); 260 QMessageBox::information(0,"Ooops!","Something went wrong\nUnable to delete user: "+QString(username)+".");
244 } 261 }
245 } else { 262 } else {
246 QMessageBox::information(0,"Invalid Username","That username ("+QString(username)+")does not exist."); 263 QMessageBox::information(0,"Invalid Username","That username ("+QString(username)+")does not exist.");
247 return false; 264 return false;
248 } 265 }