Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

groupdialog.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *                                                                         *
00003  *   This program is free software; you can redistribute it and/or modify  *
00004  *   it under the terms of the GNU General Public License as published by  *
00005  *   the Free Software Foundation; either version 2 of the License, or     *
00006  *   (at your option) any later version.                                   *
00007  *                                                                         *
00008  ***************************************************************************/
00009 
00010 #include "groupdialog.h"
00011 
00012 #include <qlabel.h>
00013 #include <qlayout.h>
00014 #include <qmessagebox.h>
00015 
00016 #include "passwd.h"
00017 
00018 GroupDialog::GroupDialog(QWidget* parent, const char* name, bool modal, WFlags fl) : QDialog(parent, name, modal, fl) {
00019         // GID
00020         QLabel *gidLabel=new QLabel(this,"gid: ");
00021         gidLabel->setText("GroupID: ");
00022         gidLineEdit=new QLineEdit(this,"gid: ");
00023         gidLineEdit->setEnabled(false);
00024 
00025         // Groupname
00026         QLabel *groupnameLabel=new QLabel(this,"groupname");
00027         groupnameLabel->setText("Groupname: ");
00028         groupnameLineEdit=new QLineEdit(this,"groupname");
00029 
00030                 // Widget layout
00031         QVBoxLayout *layout=new QVBoxLayout(this);
00032         layout->setMargin(5);
00033         QHBoxLayout *hlayout=new QHBoxLayout(-1,"hlayout");
00034         layout->addLayout(hlayout);
00035         QVBoxLayout *vlayout1=new QVBoxLayout(-1,"vlayout1");
00036         QVBoxLayout *vlayout2=new QVBoxLayout(-1,"vlayout2");
00037                 // First column, labels
00038                 vlayout1->addWidget(gidLabel);
00039                 vlayout1->addWidget(groupnameLabel);
00040                 // Second column, data
00041                 vlayout2->addWidget(gidLineEdit);
00042                 vlayout2->addWidget(groupnameLineEdit);
00043         hlayout->addLayout(vlayout1);
00044         hlayout->addLayout(vlayout2);
00045         layout->addSpacing(5);
00046         
00047 //      showMaximized();
00048 }
00049 
00050 GroupDialog::~GroupDialog() {
00051 }
00052 
00053 bool GroupDialog::addGroup(int gid) {
00054         GroupDialog *addgroupDialog=new GroupDialog();  // Make a groupinfo dialog.
00055         addgroupDialog->setCaption(tr("Add Group"));    // Set the caption.
00056         addgroupDialog->gidLineEdit->setText(QString::number(gid));     // Set the next available gid.
00057         if(!(addgroupDialog->exec())) return false;     // View the dialog, and only continue if 'ok' was pressed.
00058         if(!(accounts->addGroup(addgroupDialog->groupnameLineEdit->text(),addgroupDialog->gidLineEdit->text().toInt()))) {      // Try to add the group.
00059                 QMessageBox::information(0,"Ooops!","Something went wrong.\nUnable to add group.");
00060                 return false;
00061         }
00062         return true;
00063 }
00064 
00065 bool GroupDialog::editGroup(int gid) {
00066         GroupDialog *addgroupDialog=new GroupDialog();  // Create the groupinfo dialog.
00067         accounts->findGroup(gid);       // Locate the group in the database, and fill out the variables in 'accounts'.
00068         // Fill out the widgets with previous data for this group.
00069         addgroupDialog->setCaption(tr("Edit Group"));
00070         addgroupDialog->gidLineEdit->setText(QString::number(accounts->gr_gid));
00071         addgroupDialog->groupnameLineEdit->setText(accounts->gr_name);
00072         if(!(addgroupDialog->exec())) return false;     // View the dialog, and only continue if 'ok' was pressed.
00073         accounts->findGroup(gid);       // Locate the group, and fill out the variables in 'accounts' with all info about the group.
00074         accounts->gr_name=addgroupDialog->groupnameLineEdit->text();    // Change the name
00075         accounts->gr_gid=addgroupDialog->gidLineEdit->text().toInt();   // Change the GID. (Unneeded as its disabled right now.)
00076         accounts->updateGroup(gid);     // Update the database with the variables (gr_name,gr_gid,gr_mem) in 'accounts'.
00077         return true;
00078 }
00079 
00080 bool GroupDialog::delGroup(const char *groupname) {
00081         if((accounts->findGroup(groupname))) {  // Does this group exist?
00082                 if(!(accounts->delGroup(groupname))) {  // Try to delete it.
00083                         QMessageBox::information(0,"Ooops!","Something went wrong\nUnable to delete group: "+QString(groupname)+".");
00084                 }
00085         } else {
00086                 QMessageBox::information(0,"Invalid Groupname","That groupname ("+QString(groupname)+")does not exist.");
00087                 return false;
00088         }
00089         return true;
00090 }
00091 
00092 void GroupDialog::accept() {
00093         // Check if gid is already taken.
00094 //      if((accounts->findGroup(gidLineEdit->text().toInt()))) {
00095 //              QMessageBox::information(this,"GroupID taken","That GroupID is already taken.");
00096 //              return;
00097 //      }
00098         // Check if groupname is already taken.
00099         if((accounts->findGroup(groupnameLineEdit->text()))) {
00100                 QMessageBox::information(0,"Groupname taken","That groupname is already taken.");
00101                 return; // Don't close the dialog.
00102         }
00103         QDialog::accept();
00104 }

Generated on Sat Nov 5 16:17:58 2005 for OPIE by  doxygen 1.4.2