summaryrefslogtreecommitdiffstats
path: root/tderesources/scalix/scalixadmin/delegatedialog.cpp
blob: af8432854d444d2fd06a4a7578985d58e9bcd64e (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
/*
 *   This file is part of ScalixAdmin.
 *
 *   Copyright (C) 2007 Trolltech ASA. All rights reserved.
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation; either version 2 of the License, or
 *   (at your option) any later version.
 *
 *   This program 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 General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program; if not, write to the Free Software
 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */

#include <tqcheckbox.h>
#include <tqlabel.h>
#include <tqlayout.h>
#include <tqlineedit.h>
#include <tqtoolbutton.h>

#include <tdelocale.h>

#include "jobs.h"
#include "ldapdialog.h"

#include "delegatedialog.h"

DelegateDialog::DelegateDialog( TQWidget *parent )
  : KDialogBase( parent, "", true, "", Ok | Cancel, Ok, true )
{
  TQWidget *page = new TQWidget( this );
  TQGridLayout *layout = new TQGridLayout( page, 5, 3, 11, 6 );

  TQLabel *label = new TQLabel( i18n( "User:" ), page );
  layout->addWidget( label, 0, 0 );

  mEmail = new TQLineEdit( page );
  layout->addWidget( mEmail, 0, 1 );

  TQToolButton *emailSelector = new TQToolButton( page );
  emailSelector->setUsesTextLabel( true );
  emailSelector->setTextLabel( i18n( "..." ) );
  layout->addWidget( emailSelector, 0, 2 );

  TQValueList<Scalix::DelegateTypes> types;
  types << Scalix::SendOnBehalfOf;
  types << Scalix::SeePrivate;
  types << Scalix::GetMeetings;
  types << Scalix::InsteadOfMe;

  int row = 1;
  for ( uint i = 0; i < types.count(); ++i ) {
    TQCheckBox *box = new TQCheckBox( Scalix::Delegate::rightsAsString( types[ i ] ), page );
    layout->addMultiCellWidget( box, row, row, 1, 2 );

    mRights.insert( types[ i ], box );
    row++;
  }

  connect( emailSelector, TQ_SIGNAL( clicked() ), TQ_SLOT( selectEmail() ) );

  setMainWidget( page );
}

void DelegateDialog::setDelegate( const Scalix::Delegate &delegate )
{
  mEmail->setText( delegate.email() );

  TQMap<int, TQCheckBox*>::Iterator it;
  for ( it = mRights.begin(); it != mRights.end(); ++it )
    it.data()->setChecked( delegate.rights() & it.key() );
}

Scalix::Delegate DelegateDialog::delegate() const
{
  int rights = 0;

  TQMap<int, TQCheckBox*>::ConstIterator it;
  for ( it = mRights.begin(); it != mRights.end(); ++it )
    if ( it.data()->isChecked() )
      rights |= it.key();

  return Scalix::Delegate( mEmail->text(), rights );
}

void DelegateDialog::selectEmail()
{
  LdapDialog dlg( this );
  if ( !dlg.exec() )
    return;

  const TQString email = dlg.selectedUser();
  if ( email.isEmpty() )
    return;

  mEmail->setText( email );
}

#include "delegatedialog.moc"