2 * Copyright (c) 2010 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com
3 * Copyright (c) 2010 Tobias Koenig <tokoe@kdab.com>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 #include "aclentrydialog_p.h"
22 #include "aclutils_p.h"
24 #include <akonadi/contact/emailaddressselectiondialog.h>
25 #include <klineedit.h>
28 #include <QtGui/QButtonGroup>
29 #include <QtGui/QGridLayout>
30 #include <QtGui/QGroupBox>
31 #include <QtGui/QLabel>
32 #include <QtGui/QPushButton>
33 #include <QtGui/QRadioButton>
34 #include <QtGui/QVBoxLayout>
36 using namespace MailCommon
;
38 class AclEntryDialog::Private
41 Private( AclEntryDialog
*qq
)
47 void slotSelectAddresses();
50 QButtonGroup
*mButtonGroup
;
51 KLineEdit
*mUserIdLineEdit
;
52 QVBoxLayout
*mButtonLayout
;
53 KIMAP::Acl::Rights mCustomPermissions
;
56 void AclEntryDialog::Private::slotChanged()
58 q
->enableButtonOk( !mUserIdLineEdit
->text().isEmpty() && mButtonGroup
->checkedButton() != 0 );
61 void AclEntryDialog::Private::slotSelectAddresses()
63 Akonadi::EmailAddressSelectionDialog dlg
;
68 const QString text
= (!dlg
.selectedAddresses().isEmpty() ? dlg
.selectedAddresses().first().quotedEmail()
71 mUserIdLineEdit
->setText( text
);
75 AclEntryDialog::AclEntryDialog( QWidget
*parent
)
76 : KDialog( parent
), d( new Private( this ) )
78 setButtons( Ok
| Cancel
);
80 QWidget
*page
= new QWidget( this );
81 setMainWidget( page
);
83 QGridLayout
*layout
= new QGridLayout( page
);
84 layout
->setSpacing( spacingHint() );
85 layout
->setMargin( 0 );
87 QLabel
*label
= new QLabel( i18n( "&User identifier:" ), page
);
88 layout
->addWidget( label
, 0, 0 );
90 d
->mUserIdLineEdit
= new KLineEdit( page
);
91 layout
->addWidget( d
->mUserIdLineEdit
, 0, 1 );
92 label
->setBuddy( d
->mUserIdLineEdit
);
93 d
->mUserIdLineEdit
->setWhatsThis( i18n( "The User Identifier is the login of the user on the IMAP server. This can be a simple user name or the full email address of the user; the login for your own account on the server will tell you which one it is." ) );
95 QPushButton
*button
= new QPushButton( i18n( "Se&lect..." ), page
);
96 layout
->addWidget( button
, 0, 2 );
98 QGroupBox
*groupBox
= new QGroupBox( i18n( "Permissions" ), page
);
99 QVBoxLayout
*vbox
= new QVBoxLayout( groupBox
);
101 d
->mButtonGroup
= new QButtonGroup( groupBox
);
103 for ( unsigned int i
= 0; i
< AclUtils::standardPermissionsCount(); ++i
) {
104 const KIMAP::Acl::Rights permissions
= AclUtils::permissionsForIndex( i
);
106 QRadioButton
*radioButton
= new QRadioButton( AclUtils::permissionsToUserString( permissions
), groupBox
);
107 vbox
->addWidget( radioButton
);
108 d
->mButtonGroup
->addButton( radioButton
, permissions
);
111 vbox
->addStretch( 1 );
112 layout
->addWidget( groupBox
, 1, 0, 1, 3 );
114 label
= new QLabel( i18n( "<b>Note: </b>Renaming requires write permissions on the parent folder." ), page
);
115 layout
->addWidget( label
, 2, 0, 1, 3 );
116 layout
->setRowStretch( 2, 10 );
118 connect( d
->mUserIdLineEdit
, SIGNAL(textChanged(QString
)), SLOT(slotChanged()) );
119 connect( button
, SIGNAL(clicked()), SLOT(slotSelectAddresses()) );
120 connect( d
->mButtonGroup
, SIGNAL(buttonClicked(int)), SLOT(slotChanged()) );
121 enableButtonOk( false );
123 d
->mUserIdLineEdit
->setFocus();
125 // Ensure the lineedit is rather wide so that email addresses can be read in it
126 incrementInitialSize( QSize( 200, 0 ) );
129 AclEntryDialog::~AclEntryDialog()
134 void AclEntryDialog::setUserId( const QString
& userId
)
136 d
->mUserIdLineEdit
->setText( userId
);
138 enableButtonOk( !userId
.isEmpty() );
141 QString
AclEntryDialog::userId() const
143 return d
->mUserIdLineEdit
->text();
146 void AclEntryDialog::setPermissions( KIMAP::Acl::Rights permissions
)
148 QAbstractButton
* button
= d
->mButtonGroup
->button( KIMAP::Acl::normalizedRights( permissions
) );
150 button
->setChecked( true );
152 QRadioButton
*radioButton
= new QRadioButton( AclUtils::permissionsToUserString( permissions
) );
153 d
->mButtonLayout
->addWidget( radioButton
);
154 d
->mButtonGroup
->addButton( radioButton
, permissions
);
157 d
->mCustomPermissions
= permissions
;
160 KIMAP::Acl::Rights
AclEntryDialog::permissions() const
162 QAbstractButton
* button
= d
->mButtonGroup
->checkedButton();
164 return d
->mCustomPermissions
;
166 return KIMAP::Acl::denormalizedRights( static_cast<KIMAP::Acl::Rights
>( d
->mButtonGroup
->id( button
) ) );
169 #include "aclentrydialog_p.moc"