You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
171 lines
5.1 KiB
171 lines
5.1 KiB
15 years ago
|
/*
|
||
|
* 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.
|
||
|
*/
|
||
|
|
||
13 years ago
|
#include <tqlayout.h>
|
||
15 years ago
|
#include <tqpushbutton.h>
|
||
15 years ago
|
|
||
|
#include <kinputdialog.h>
|
||
|
#include <klocale.h>
|
||
|
#include <kmessagebox.h>
|
||
|
|
||
|
#include <unistd.h>
|
||
|
|
||
|
#include "delegatedialog.h"
|
||
|
#include "delegateview.h"
|
||
|
#include "jobs.h"
|
||
|
#include "settings.h"
|
||
|
|
||
|
#include "delegatepage.h"
|
||
|
|
||
14 years ago
|
DelegatePage::DelegatePage( TQWidget *parent )
|
||
|
: TQWidget( parent )
|
||
15 years ago
|
{
|
||
13 years ago
|
TQGridLayout *layout = new TQGridLayout( this, 2, 3, 11, 6 );
|
||
15 years ago
|
|
||
|
mView = new DelegateView( &mManager, this );
|
||
13 years ago
|
layout->addMultiCellWidget( mView, 0, 0, 0, 2 );
|
||
15 years ago
|
|
||
15 years ago
|
mAddButton = new TQPushButton( i18n( "Add Delegate..." ), this );
|
||
13 years ago
|
layout->addWidget( mAddButton, 1, 0 );
|
||
15 years ago
|
|
||
15 years ago
|
mEditButton = new TQPushButton( i18n( "Edit Delegate..." ), this );
|
||
15 years ago
|
mEditButton->setEnabled( false );
|
||
13 years ago
|
layout->addWidget( mEditButton, 1, 1 );
|
||
15 years ago
|
|
||
15 years ago
|
mRemoveButton = new TQPushButton( i18n( "Remove Delegate" ), this );
|
||
15 years ago
|
mRemoveButton->setEnabled( false );
|
||
13 years ago
|
layout->addWidget( mRemoveButton, 1, 2 );
|
||
15 years ago
|
|
||
15 years ago
|
connect( mView, TQT_SIGNAL( selectionChanged() ), TQT_SLOT( selectionChanged() ) );
|
||
|
connect( mAddButton, TQT_SIGNAL( clicked() ), TQT_SLOT( addDelegate() ) );
|
||
|
connect( mEditButton, TQT_SIGNAL( clicked() ), TQT_SLOT( editDelegate() ) );
|
||
|
connect( mRemoveButton, TQT_SIGNAL( clicked() ), TQT_SLOT( removeDelegate() ) );
|
||
15 years ago
|
|
||
|
loadAllDelegates();
|
||
|
}
|
||
|
|
||
|
DelegatePage::~DelegatePage()
|
||
|
{
|
||
|
}
|
||
|
|
||
|
void DelegatePage::loadAllDelegates()
|
||
|
{
|
||
|
Scalix::GetDelegatesJob *job = Scalix::getDelegates( Settings::self()->globalSlave(),
|
||
|
Settings::self()->accountUrl() );
|
||
12 years ago
|
connect( job, TQT_SIGNAL( result( TDEIO::Job* ) ), TQT_SLOT( allDelegates( TDEIO::Job* ) ) );
|
||
15 years ago
|
}
|
||
|
|
||
|
void DelegatePage::addDelegate()
|
||
|
{
|
||
|
DelegateDialog dlg( this );
|
||
|
dlg.setCaption( i18n( "Add Delegate" ) );
|
||
|
|
||
|
if ( !dlg.exec() )
|
||
|
return;
|
||
|
|
||
|
const Scalix::Delegate delegate = dlg.delegate();
|
||
|
|
||
|
if ( !delegate.isValid() )
|
||
|
return;
|
||
|
|
||
|
Scalix::SetDelegateJob *job = Scalix::setDelegate( Settings::self()->globalSlave(),
|
||
|
Settings::self()->accountUrl(),
|
||
|
delegate.email(), delegate.rights() );
|
||
12 years ago
|
connect( job, TQT_SIGNAL( result( TDEIO::Job* ) ), TQT_SLOT( delegateAdded( TDEIO::Job* ) ) );
|
||
15 years ago
|
}
|
||
|
|
||
|
void DelegatePage::editDelegate()
|
||
|
{
|
||
|
const Scalix::Delegate oldDelegate = mView->selectedDelegate();
|
||
|
if ( !oldDelegate.isValid() )
|
||
|
return;
|
||
|
|
||
|
DelegateDialog dlg( this );
|
||
|
dlg.setCaption( i18n( "Edit Delegate" ) );
|
||
|
|
||
|
dlg.setDelegate( oldDelegate );
|
||
|
|
||
|
if ( !dlg.exec() )
|
||
|
return;
|
||
|
|
||
|
const Scalix::Delegate delegate = dlg.delegate();
|
||
|
|
||
|
if ( !delegate.isValid() )
|
||
|
return;
|
||
|
|
||
|
Scalix::SetDelegateJob *job = Scalix::setDelegate( Settings::self()->globalSlave(),
|
||
|
Settings::self()->accountUrl(),
|
||
|
delegate.email(), delegate.rights() );
|
||
12 years ago
|
connect( job, TQT_SIGNAL( result( TDEIO::Job* ) ), TQT_SLOT( delegateAdded( TDEIO::Job* ) ) );
|
||
15 years ago
|
}
|
||
|
|
||
|
void DelegatePage::removeDelegate()
|
||
|
{
|
||
|
const Scalix::Delegate delegate = mView->selectedDelegate();
|
||
|
if ( !delegate.isValid() )
|
||
|
return;
|
||
|
|
||
|
Scalix::DeleteDelegateJob *job = Scalix::deleteDelegate( Settings::self()->globalSlave(),
|
||
|
Settings::self()->accountUrl(), delegate.email() );
|
||
12 years ago
|
connect( job, TQT_SIGNAL( result( TDEIO::Job* ) ), TQT_SLOT( delegateRemoved( TDEIO::Job* ) ) );
|
||
15 years ago
|
}
|
||
|
|
||
12 years ago
|
void DelegatePage::allDelegates( TDEIO::Job *job )
|
||
15 years ago
|
{
|
||
|
if ( job->error() )
|
||
|
KMessageBox::error( this, job->errorString() );
|
||
|
|
||
|
Scalix::GetDelegatesJob *delegateJob = static_cast<Scalix::GetDelegatesJob*>( job );
|
||
|
|
||
|
mManager.clear();
|
||
|
|
||
|
const Scalix::Delegate::List delegates = delegateJob->delegates();
|
||
|
for ( uint i = 0; i < delegates.count(); ++i )
|
||
|
mManager.addDelegate( delegates[ i ] );
|
||
|
|
||
|
selectionChanged();
|
||
|
}
|
||
|
|
||
12 years ago
|
void DelegatePage::delegateAdded( TDEIO::Job *job )
|
||
15 years ago
|
{
|
||
|
if ( job->error() )
|
||
|
KMessageBox::error( this, job->errorString() );
|
||
|
else
|
||
|
loadAllDelegates(); // update the GUI
|
||
|
}
|
||
|
|
||
12 years ago
|
void DelegatePage::delegateRemoved( TDEIO::Job *job )
|
||
15 years ago
|
{
|
||
|
if ( job->error() )
|
||
|
KMessageBox::error( this, job->errorString() );
|
||
|
else
|
||
|
loadAllDelegates(); // update the GUI
|
||
|
}
|
||
|
|
||
|
void DelegatePage::selectionChanged()
|
||
|
{
|
||
|
bool state = ( mView->selectedItem() != 0 );
|
||
|
|
||
|
mEditButton->setEnabled( state );
|
||
|
mRemoveButton->setEnabled( state );
|
||
|
}
|
||
|
|
||
|
#include "delegatepage.moc"
|