summaryrefslogtreecommitdiffstats
path: root/kuser/mainWidget.cpp
blob: 046ed76f1326c6d38af2916010f1a9cdc538c5f7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
/*
 *  Copyright (c) 1998 Denis Perchine <[email protected]>
 *  Copyright (c) 2004 Szombathelyi György <[email protected]>
 *  Former maintainer: Adriaan de Groot <[email protected]>
 *
 *  This program is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU General Public
 *  License version 2 as published by the Free Software Foundation.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Library General Public License for more details.
 *
 *  You should have received a copy of the GNU Library General Public License
 *  along with this library; see the file COPYING.LIB.  If not, write to
 *  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 *  Boston, MA 02110-1301, USA.
 **/

#include <tqtooltip.h>
#include <tqtimer.h>

#include <ktoolbar.h>
#include <kiconloader.h>
#include <kaction.h>
#include <klocale.h>
#include <kstdaction.h>

#include <kdebug.h>
#include <kaction.h>
#include <kstatusbar.h>
#include <kedittoolbar.h>

#include "kglobal_.h"
#include "editDefaults.h"
#include "mainWidget.h"
#include "selectconn.h"
#include "mainView.h"

mainWidget::mainWidget(const char *name) : TDEMainWindow(0,name)
{
  md = new mainView(this);

  setupActions();
  md->setShowSys( mShowSys->isChecked() );
  init();
  md->slotTabChanged();

  statusBar()->insertItem(i18n("Reading configuration"), 0);

  setCentralWidget(md);

  setupGUI();
	
  statusBar()->changeItem(i18n("Ready"), 0);
}

mainWidget::~mainWidget()
{
  delete md;
}

bool mainWidget::queryClose()
{
  return md->queryClose();
}

void mainWidget::setupActions()
{
  KStdAction::quit(TQT_TQOBJECT(this), TQT_SLOT(close()), actionCollection());
  KStdAction::keyBindings(guiFactory(), TQT_SLOT(configureShortcuts()), actionCollection());

  KStdAction::preferences(TQT_TQOBJECT(this), TQT_SLOT(properties()), actionCollection());

#define BarIconC(x)	BarIcon(TQString::fromLatin1(x))

  (void) new TDEAction(i18n("&Add..."), TQIconSet(BarIconC("add_user")), 0, TQT_TQOBJECT(md),
    TQT_SLOT(useradd()), actionCollection(), "add_user");

  (void) new TDEAction(i18n("&Edit..."), TQIconSet(BarIconC("edit_user")), 0, TQT_TQOBJECT(md),
    TQT_SLOT(useredit()), actionCollection(), "edit_user");

  (void) new TDEAction(i18n("&Delete..."), TQIconSet(BarIconC("delete_user")), 0, TQT_TQOBJECT(md),
    TQT_SLOT(userdel()), actionCollection(), "delete_user");

  (void) new TDEAction(i18n("&Set Password..."),
    0, TQT_TQOBJECT(md), TQT_SLOT(setpwd()), actionCollection(), "set_password_user");

  (void) new TDEAction(i18n("&Add..."), TQIconSet(BarIconC("add_group")), 0, TQT_TQOBJECT(md),
    TQT_SLOT(grpadd()), actionCollection(), "add_group");

  (void) new TDEAction(i18n("&Edit..."), TQIconSet(BarIconC("edit_group")), 0, TQT_TQOBJECT(md),
    TQT_SLOT(grpedit()), actionCollection(), "edit_group");

  (void) new TDEAction(i18n("&Delete"), TQIconSet(BarIconC("delete_group")), 0, TQT_TQOBJECT(md),
    TQT_SLOT(grpdel()), actionCollection(), "delete_group");

  (void) new TDEAction(i18n("&Reload"), TQIconSet(BarIconC("reload")), 0, TQT_TQOBJECT(this),
    TQT_SLOT(reload()), actionCollection(), "reload");

#undef BarIconC
	
  (void) new TDEAction(i18n("&Select Connection..."),
    0, TQT_TQOBJECT(this),
    TQT_SLOT(selectconn()), actionCollection(), "select_conn");

  mShowSys = new TDEToggleAction(i18n("Show System Users/Groups"),
    0, 0, TQT_TQOBJECT(this),
    TQT_SLOT(showSys()), actionCollection(), "show_sys");
  mShowSys->setCheckedState(i18n("Hide System Users/Groups"));
  mShowSys->setChecked( kug->kcfg()->showsys() );
}

void mainWidget::showSys()
{
  kug->kcfg()->setShowsys( mShowSys->isChecked() );
  md->setShowSys( mShowSys->isChecked() );
  md->reloadUsers();
  md->reloadGroups();
}

void mainWidget::properties()
{
  editDefaults *eddlg = new editDefaults( kug->kcfg(), this );
  connect(eddlg, TQT_SIGNAL(settingsChanged()), this, TQT_SLOT(slotApplySettings()));

  eddlg->show();
}

void mainWidget::reload()
{
  init();
}

void mainWidget::init()
{
  bool rw;

  md->clearUsers();
  md->clearGroups();
  kug->init();
  rw = ! ( kug->getUsers().getCaps() & KU::KUsers::Cap_ReadOnly );
  kdDebug() << "Users rw()" << rw << endl;
  actionCollection()->action("add_user")->setEnabled( rw );
  actionCollection()->action("edit_user")->setEnabled( rw );
  actionCollection()->action("delete_user")->setEnabled( rw );
  actionCollection()->action("set_password_user")->setEnabled( rw );
  if ( rw ) {
    connect( md, TQT_SIGNAL(userSelected(bool)),
      actionCollection()->action("edit_user"), TQT_SLOT(setEnabled(bool)) );
    connect( md, TQT_SIGNAL(userSelected(bool)),
      actionCollection()->action("delete_user"), TQT_SLOT(setEnabled(bool)) );
    connect( md, TQT_SIGNAL(userSelected(bool)),
      actionCollection()->action("set_password_user"), TQT_SLOT(setEnabled(bool)) );
  } else {
    disconnect( md, TQT_SIGNAL(userSelected(bool)), 0, 0 );
  }

  rw = ! ( kug->getGroups().getCaps() & KU::KGroups::Cap_ReadOnly );
  kdDebug() << "Groups rw()" << rw << endl;
  actionCollection()->action("add_group")->setEnabled( rw );
  actionCollection()->action("edit_group")->setEnabled( rw );
  actionCollection()->action("delete_group")->setEnabled( rw );
  if ( rw ) {
    connect( md, TQT_SIGNAL(groupSelected(bool)),
      actionCollection()->action("edit_group"), TQT_SLOT(setEnabled(bool)) );
    connect( md, TQT_SIGNAL(groupSelected(bool)),
      actionCollection()->action("delete_group"), TQT_SLOT(setEnabled(bool)) );
  } else {
    disconnect( md, TQT_SIGNAL(groupSelected(bool)), 0, 0 );
  }
  md->reloadUsers();
  md->reloadGroups();
  TQTimer::singleShot( 0, TQT_TQOBJECT(md), TQT_SLOT(slotTabChanged()) );
}

void mainWidget::slotApplySettings()
{
  kdDebug() << "settings changed!" << endl;
  init();
}

void mainWidget::slotApplyConnection()
{
  kdDebug() << "slotApplyConnection()" << endl;
  TQString conn = sc->connSelected();
  kug->kcfg()->setConnection( conn );
  kug->initCfg( conn );
  slotApplySettings();
}

void mainWidget::selectconn()
{
  sc = new SelectConn( kug->kcfg()->connection(), this, "selectconn" );
  connect( sc, TQT_SIGNAL(applyClicked()), TQT_SLOT(slotApplyConnection()) );
  connect( sc, TQT_SIGNAL(okClicked()), TQT_SLOT(slotApplyConnection()) );
  sc->show();
}

#include "mainWidget.moc"