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.
174 lines
4.8 KiB
174 lines
4.8 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.
|
||
|
*/
|
||
|
|
||
15 years ago
|
#include <tqapplication.h>
|
||
13 years ago
|
#include <tqlayout.h>
|
||
15 years ago
|
#include <tqpushbutton.h>
|
||
15 years ago
|
|
||
|
#include <dcopref.h>
|
||
|
#include <kdcopservicestarter.h>
|
||
|
#include <kinputdialog.h>
|
||
|
#include <klocale.h>
|
||
|
#include <kmessagebox.h>
|
||
|
|
||
|
#include <unistd.h>
|
||
|
|
||
|
#include "jobs.h"
|
||
|
#include "ldapdialog.h"
|
||
|
#include "otheruserview.h"
|
||
|
#include "settings.h"
|
||
|
|
||
|
#include "otheruserpage.h"
|
||
|
|
||
13 years ago
|
OtherUserPage::OtherUserPage( TQWidget *parent )
|
||
|
: TQWidget( parent )
|
||
15 years ago
|
{
|
||
13 years ago
|
TQGridLayout *layout = new TQGridLayout( this, 2, 2, 11, 6 );
|
||
15 years ago
|
|
||
|
mView = new OtherUserView( &mManager, this );
|
||
13 years ago
|
layout->addMultiCellWidget( mView, 0, 0, 0, 1 );
|
||
15 years ago
|
|
||
15 years ago
|
mAddButton = new TQPushButton( i18n( "Add Account..." ), this );
|
||
13 years ago
|
layout->addWidget( mAddButton, 1, 0 );
|
||
15 years ago
|
|
||
15 years ago
|
mDeleteButton = new TQPushButton( i18n( "Remove Account" ), this );
|
||
15 years ago
|
mDeleteButton->setEnabled( false );
|
||
13 years ago
|
layout->addWidget( mDeleteButton, 1, 1 );
|
||
15 years ago
|
|
||
15 years ago
|
connect( mView, TQT_SIGNAL( selectionChanged() ), TQT_SLOT( selectionChanged() ) );
|
||
|
connect( mAddButton, TQT_SIGNAL( clicked() ), TQT_SLOT( addUser() ) );
|
||
|
connect( mDeleteButton, TQT_SIGNAL( clicked() ), TQT_SLOT( removeUser() ) );
|
||
15 years ago
|
|
||
|
loadAllUsers();
|
||
|
}
|
||
|
|
||
|
OtherUserPage::~OtherUserPage()
|
||
|
{
|
||
|
}
|
||
|
|
||
|
void OtherUserPage::loadAllUsers()
|
||
|
{
|
||
|
Scalix::GetOtherUsersJob *job = Scalix::getOtherUsers( Settings::self()->globalSlave(),
|
||
|
Settings::self()->accountUrl() );
|
||
12 years ago
|
connect( job, TQT_SIGNAL( result( TDEIO::Job* ) ), TQT_SLOT( allUsers( TDEIO::Job* ) ) );
|
||
15 years ago
|
}
|
||
|
|
||
|
void OtherUserPage::addUser()
|
||
|
{
|
||
|
LdapDialog dlg( this );
|
||
|
if ( !dlg.exec() )
|
||
|
return;
|
||
|
|
||
15 years ago
|
const TQString email = dlg.selectedUser();
|
||
15 years ago
|
if ( email.isEmpty() )
|
||
|
return;
|
||
|
|
||
|
Scalix::AddOtherUserJob *job = Scalix::addOtherUser( Settings::self()->globalSlave(),
|
||
|
Settings::self()->accountUrl(), email );
|
||
12 years ago
|
connect( job, TQT_SIGNAL( result( TDEIO::Job* ) ), TQT_SLOT( userAdded( TDEIO::Job* ) ) );
|
||
15 years ago
|
}
|
||
|
|
||
|
void OtherUserPage::removeUser()
|
||
|
{
|
||
15 years ago
|
const TQString email = mView->selectedUser();
|
||
15 years ago
|
if ( email.isEmpty() )
|
||
|
return;
|
||
|
|
||
|
Scalix::DeleteOtherUserJob *job = Scalix::deleteOtherUser( Settings::self()->globalSlave(),
|
||
|
Settings::self()->accountUrl(), email );
|
||
12 years ago
|
connect( job, TQT_SIGNAL( result( TDEIO::Job* ) ), TQT_SLOT( userRemoved( TDEIO::Job* ) ) );
|
||
15 years ago
|
}
|
||
|
|
||
12 years ago
|
void OtherUserPage::allUsers( TDEIO::Job *job )
|
||
15 years ago
|
{
|
||
|
if ( job->error() )
|
||
|
KMessageBox::error( this, job->errorString() );
|
||
|
|
||
|
Scalix::GetOtherUsersJob *userJob = static_cast<Scalix::GetOtherUsersJob*>( job );
|
||
|
|
||
|
mManager.clear();
|
||
|
|
||
15 years ago
|
const TQStringList users = userJob->otherUsers();
|
||
15 years ago
|
for ( uint i = 0; i < users.count(); ++i )
|
||
|
mManager.addOtherUser( users[ i ] );
|
||
|
|
||
|
selectionChanged();
|
||
|
}
|
||
|
|
||
12 years ago
|
void OtherUserPage::userAdded( TDEIO::Job *job )
|
||
15 years ago
|
{
|
||
|
if ( job->error() )
|
||
|
KMessageBox::error( this, job->errorString() );
|
||
|
else
|
||
|
loadAllUsers(); // update the GUI
|
||
|
|
||
|
updateKmail();
|
||
|
}
|
||
|
|
||
12 years ago
|
void OtherUserPage::userRemoved( TDEIO::Job *job )
|
||
15 years ago
|
{
|
||
|
if ( job->error() )
|
||
|
KMessageBox::error( this, job->errorString() );
|
||
|
else
|
||
|
loadAllUsers(); // update the GUI
|
||
|
|
||
|
updateKmail();
|
||
|
}
|
||
|
|
||
|
void OtherUserPage::selectionChanged()
|
||
|
{
|
||
|
mDeleteButton->setEnabled( mView->selectedItem() != 0 );
|
||
|
}
|
||
|
|
||
|
void OtherUserPage::updateKmail()
|
||
|
{
|
||
14 years ago
|
TQMessageBox *msg = new TQMessageBox( tqApp->mainWidget() );
|
||
15 years ago
|
msg->setText( i18n( "Updating account..." ) );
|
||
|
msg->show();
|
||
14 years ago
|
tqApp->processEvents();
|
||
15 years ago
|
sleep( 1 );
|
||
14 years ago
|
tqApp->processEvents();
|
||
15 years ago
|
|
||
15 years ago
|
TQString error;
|
||
|
TQCString dcopService;
|
||
15 years ago
|
int result = KDCOPServiceStarter::self()->
|
||
14 years ago
|
findServiceFor( "DCOP/ResourceBackend/IMAP", TQString(),
|
||
|
TQString(), &error, &dcopService );
|
||
15 years ago
|
if ( result != 0 ) {
|
||
|
KMessageBox::error( 0, i18n( "Unable to start KMail to trigger account update with Scalix server" ) );
|
||
|
delete msg;
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
DCOPRef ref( dcopService, "KMailIface" );
|
||
|
|
||
|
// loop until dcop iface is set up correctly
|
||
15 years ago
|
TQStringList list;
|
||
15 years ago
|
while ( list.isEmpty() ) {
|
||
|
ref.call( "accounts()" ).get( list );
|
||
|
}
|
||
|
|
||
15 years ago
|
ref.call( "checkAccount(TQString)", i18n( "Scalix Server" ) );
|
||
15 years ago
|
|
||
|
delete msg;
|
||
|
}
|
||
|
|
||
|
#include "otheruserpage.moc"
|