source: src-qt4/pc-usermanager/pcbsdusermanager.cpp @ 1620346

9.1-release9.2-releasereleng/10.0releng/10.0.1releng/10.0.2releng/10.0.3releng/10.1
Last change on this file since 1620346 was 1620346, checked in by Kris Moore <kris@…>, 19 months ago

Initial import of PC-BSD /current/ SVN repo

  • Property mode set to 100644
File size: 4.3 KB
Line 
1/***************************************************************************
2 *   Copyright (C) 2007, 2012 by Tim McCormick   *
3 *   tim@pcbsd.org   *
4 *                                                                         *
5 *   Permission is hereby granted, free of charge, to any person obtaining *
6 *   a copy of this software and associated documentation files (the       *
7 *   "Software"), to deal in the Software without restriction, including   *
8 *   without limitation the rights to use, copy, modify, merge, publish,   *
9 *   distribute, sublicense, and/or sell copies of the Software, and to    *
10 *   permit persons to whom the Software is furnished to do so, subject to *
11 *   the following conditions:                                             *
12 *                                                                         *
13 *   The above copyright notice and this permission notice shall be        *
14 *   included in all copies or substantial portions of the Software.       *
15 *                                                                         *
16 *   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,       *
17 *   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF    *
18 *   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
19 *   IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR     *
20 *   OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, *
21 *   ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR *
22 *   OTHER DEALINGS IN THE SOFTWARE.                                       *
23 ***************************************************************************/
24
25#include <qlayout.h>
26#include <qtranslator.h>
27#include <qtextcodec.h>
28
29#include "pcbsdusermanager.h"
30
31void PCBSDUserManager::setupUMDialogs()
32{
33    layout = new QGridLayout(widgetUserContainer);
34    changesMade = false;
35
36    //Init GUI
37    if (getuid() == 0) //Check for root
38    {
39       // Setup our buttons
40       pushSave->setEnabled(false);
41       connect(pushClose, SIGNAL(clicked()), this, SLOT(slotClose()));
42       connect(pushSave, SIGNAL(clicked()), this, SLOT(slotSave()));
43
44       back = new UserManagerBackend(wDir);
45       advancedGui = new mainDlgCode();
46       advancedGui->programInit(back, wDir);
47       simpleGui = new SimpleDlgCode();
48       simpleGui->programInit(back, wDir);
49       layout->addWidget(simpleGui);
50 
51       connect(advancedGui, SIGNAL(changed( bool )), this, SLOT(configChanged()));
52       connect(simpleGui, SIGNAL(changed()), this, SLOT(configChanged()));
53       connect(simpleGui, SIGNAL(advancedView()), this, SLOT(switchToAdvanced()));
54       connect(advancedGui, SIGNAL(simpleView()), this, SLOT(switchToSimple()));
55    }
56    else
57    {
58       qDebug("Error, needs to be run as root");
59       exit(1);
60    }
61};
62
63
64PCBSDUserManager::~PCBSDUserManager()
65{
66}
67
68void PCBSDUserManager::switchToAdvanced()
69{
70    simpleGui->setParent(0);
71    layout->addWidget(advancedGui);
72    advancedGui->setParent(widgetUserContainer);
73    advancedGui->show();
74}
75
76void PCBSDUserManager::switchToSimple()
77{
78    advancedGui->setParent(0);
79    simpleGui->setParent(widgetUserContainer);
80    layout->addWidget(simpleGui);
81    simpleGui->show();
82}
83
84void PCBSDUserManager::configChanged()
85{
86  pushSave->setEnabled(true);
87  changesMade = true;
88}
89
90void PCBSDUserManager::slotSave()
91{
92  if (back->commit())
93  {
94    pushSave->setEnabled(false);
95    changesMade = false;
96  }
97}
98
99void PCBSDUserManager::slotClose()
100{
101  if(changesMade)
102  {
103      int answer = QMessageBox::question(this,
104                                         tr("Apply pending changes?"),
105                                         tr("There are pending changes which have not been applied. Would you like to apply them before quitting?") ,
106                                         QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel,
107                                         QMessageBox::Cancel);
108      if(answer == QMessageBox::Yes) back->commit();
109      else if(answer == QMessageBox::Cancel) return;
110  }
111  close();
112}
113
114/**
115  * Override QDialog's closeEvent() which is triggered when the window 'X' is hit and use our close slot
116  */
117void PCBSDUserManager::closeEvent(QCloseEvent*)
118{
119    slotClose();
120}
121
122void PCBSDUserManager::setWardenMode(QString d, QString ip)
123{
124  wDir = d;
125  wIP = ip;
126  setWindowTitle(tr("Editing Users for Jail:") + " " + wIP );
127}
Note: See TracBrowser for help on using the repository browser.