diff options
Diffstat (limited to 'kresources/scalix/scalixadmin')
30 files changed, 2572 insertions, 0 deletions
diff --git a/kresources/scalix/scalixadmin/Makefile.am b/kresources/scalix/scalixadmin/Makefile.am new file mode 100644 index 000000000..7402ef281 --- /dev/null +++ b/kresources/scalix/scalixadmin/Makefile.am @@ -0,0 +1,15 @@ +bin_PROGRAMS = scalixadmin + +INCLUDES = $(all_includes) + +scalixadmin_LDFLAGS = $(KDE_RPATH) $(all_libraries) +scalixadmin_LDADD = $(LIB_KABC) +scalixadmin_SOURCES = main.cpp mainwindow.cpp passwordpage.cpp settings.cpp jobs.cpp \ + otherusermanager.cpp otheruserview.cpp otheruserpage.cpp ldapview.cpp ldapdialog.cpp \ + delegatemanager.cpp delegateview.cpp delegatepage.cpp delegatedialog.cpp \ + outofofficepage.cpp + +METASOURCES = AUTO + +messages: rc.cpp + $(XGETTEXT) *.cpp -o $(podir)/scalixadmin.pot diff --git a/kresources/scalix/scalixadmin/delegatedialog.cpp b/kresources/scalix/scalixadmin/delegatedialog.cpp new file mode 100644 index 000000000..3dc0412a4 --- /dev/null +++ b/kresources/scalix/scalixadmin/delegatedialog.cpp @@ -0,0 +1,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 <qcheckbox.h> +#include <qlabel.h> +#include <qlayout.h> +#include <qlineedit.h> +#include <qtoolbutton.h> + +#include <klocale.h> + +#include "jobs.h" +#include "ldapdialog.h" + +#include "delegatedialog.h" + +DelegateDialog::DelegateDialog( QWidget *parent ) + : KDialogBase( parent, "", true, "", Ok | Cancel, Ok, true ) +{ + QWidget *page = new QWidget( this ); + QGridLayout *layout = new QGridLayout( page, 5, 3, 11, 6 ); + + QLabel *label = new QLabel( i18n( "User:" ), page ); + layout->addWidget( label, 0, 0 ); + + mEmail = new QLineEdit( page ); + layout->addWidget( mEmail, 0, 1 ); + + QToolButton *emailSelector = new QToolButton( page ); + emailSelector->setUsesTextLabel( true ); + emailSelector->setTextLabel( i18n( "..." ) ); + layout->addWidget( emailSelector, 0, 2 ); + + QValueList<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 ) { + QCheckBox *box = new QCheckBox( Scalix::Delegate::rightsAsString( types[ i ] ), page ); + layout->addMultiCellWidget( box, row, row, 1, 2 ); + + mRights.insert( types[ i ], box ); + row++; + } + + connect( emailSelector, SIGNAL( clicked() ), SLOT( selectEmail() ) ); + + setMainWidget( page ); +} + +void DelegateDialog::setDelegate( const Scalix::Delegate &delegate ) +{ + mEmail->setText( delegate.email() ); + + QMap<int, QCheckBox*>::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; + + QMap<int, QCheckBox*>::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 QString email = dlg.selectedUser(); + if ( email.isEmpty() ) + return; + + mEmail->setText( email ); +} + +#include "delegatedialog.moc" diff --git a/kresources/scalix/scalixadmin/delegatedialog.h b/kresources/scalix/scalixadmin/delegatedialog.h new file mode 100644 index 000000000..b5503a4f3 --- /dev/null +++ b/kresources/scalix/scalixadmin/delegatedialog.h @@ -0,0 +1,53 @@ +/* + * 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. + */ + +#ifndef DELEGATEDIALOG_H +#define DELEGATEDIALOG_H + +#include <qmap.h> + +#include <kdialogbase.h> + +class QCheckBox; +class QLineEdit; + +namespace Scalix { +class Delegate; +} + +class DelegateDialog : public KDialogBase +{ + Q_OBJECT + + public: + DelegateDialog( QWidget *parent = 0 ); + + void setDelegate( const Scalix::Delegate &delegate ); + Scalix::Delegate delegate() const; + + private slots: + void selectEmail(); + + private: + QLineEdit *mEmail; + QMap<int, QCheckBox*> mRights; +}; + +#endif diff --git a/kresources/scalix/scalixadmin/delegatemanager.cpp b/kresources/scalix/scalixadmin/delegatemanager.cpp new file mode 100644 index 000000000..686370d77 --- /dev/null +++ b/kresources/scalix/scalixadmin/delegatemanager.cpp @@ -0,0 +1,49 @@ +/* + * 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 "delegatemanager.h" + +DelegateManager::DelegateManager() +{ +} + +DelegateManager::~DelegateManager() +{ +} + +void DelegateManager::addDelegate( const Scalix::Delegate &delegate ) +{ + mDelegates.append( delegate ); + emit changed(); +} + +void DelegateManager::clear() +{ + mDelegates.clear(); + + emit changed(); +} + +Scalix::Delegate::List DelegateManager::delegates() const +{ + return mDelegates; +} + +#include "delegatemanager.moc" diff --git a/kresources/scalix/scalixadmin/delegatemanager.h b/kresources/scalix/scalixadmin/delegatemanager.h new file mode 100644 index 000000000..f27b79a1b --- /dev/null +++ b/kresources/scalix/scalixadmin/delegatemanager.h @@ -0,0 +1,49 @@ +/* + * 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. + */ + +#ifndef DELEGATEMANAGER_H +#define DELEGATEMANAGER_H + +#include <qobject.h> +#include <qstringlist.h> + +#include "jobs.h" + +class DelegateManager : public QObject +{ + Q_OBJECT + + public: + DelegateManager(); + ~DelegateManager(); + + void addDelegate( const Scalix::Delegate &delegate ); + void clear(); + + Scalix::Delegate::List delegates() const; + + signals: + void changed(); + + private: + Scalix::Delegate::List mDelegates; +}; + +#endif diff --git a/kresources/scalix/scalixadmin/delegatepage.cpp b/kresources/scalix/scalixadmin/delegatepage.cpp new file mode 100644 index 000000000..f9a9b8e7a --- /dev/null +++ b/kresources/scalix/scalixadmin/delegatepage.cpp @@ -0,0 +1,170 @@ +/* + * 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 <qlayout.h> +#include <qpushbutton.h> + +#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" + +DelegatePage::DelegatePage( QWidget *parent ) + : QWidget( parent ) +{ + QGridLayout *layout = new QGridLayout( this, 2, 3, 11, 6 ); + + mView = new DelegateView( &mManager, this ); + layout->addMultiCellWidget( mView, 0, 0, 0, 2 ); + + mAddButton = new QPushButton( i18n( "Add Delegate..." ), this ); + layout->addWidget( mAddButton, 1, 0 ); + + mEditButton = new QPushButton( i18n( "Edit Delegate..." ), this ); + mEditButton->setEnabled( false ); + layout->addWidget( mEditButton, 1, 1 ); + + mRemoveButton = new QPushButton( i18n( "Remove Delegate" ), this ); + mRemoveButton->setEnabled( false ); + layout->addWidget( mRemoveButton, 1, 2 ); + + connect( mView, SIGNAL( selectionChanged() ), SLOT( selectionChanged() ) ); + connect( mAddButton, SIGNAL( clicked() ), SLOT( addDelegate() ) ); + connect( mEditButton, SIGNAL( clicked() ), SLOT( editDelegate() ) ); + connect( mRemoveButton, SIGNAL( clicked() ), SLOT( removeDelegate() ) ); + + loadAllDelegates(); +} + +DelegatePage::~DelegatePage() +{ +} + +void DelegatePage::loadAllDelegates() +{ + Scalix::GetDelegatesJob *job = Scalix::getDelegates( Settings::self()->globalSlave(), + Settings::self()->accountUrl() ); + connect( job, SIGNAL( result( KIO::Job* ) ), SLOT( allDelegates( KIO::Job* ) ) ); +} + +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() ); + connect( job, SIGNAL( result( KIO::Job* ) ), SLOT( delegateAdded( KIO::Job* ) ) ); +} + +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() ); + connect( job, SIGNAL( result( KIO::Job* ) ), SLOT( delegateAdded( KIO::Job* ) ) ); +} + +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() ); + connect( job, SIGNAL( result( KIO::Job* ) ), SLOT( delegateRemoved( KIO::Job* ) ) ); +} + +void DelegatePage::allDelegates( KIO::Job *job ) +{ + 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(); +} + +void DelegatePage::delegateAdded( KIO::Job *job ) +{ + if ( job->error() ) + KMessageBox::error( this, job->errorString() ); + else + loadAllDelegates(); // update the GUI +} + +void DelegatePage::delegateRemoved( KIO::Job *job ) +{ + 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" diff --git a/kresources/scalix/scalixadmin/delegatepage.h b/kresources/scalix/scalixadmin/delegatepage.h new file mode 100644 index 000000000..243c0f0d3 --- /dev/null +++ b/kresources/scalix/scalixadmin/delegatepage.h @@ -0,0 +1,60 @@ +/* + * 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. + */ + +#ifndef DELEGATEPAGE_H +#define DELEGATEPAGE_H + +#include <qwidget.h> + +#include "delegatemanager.h" + +class QPushButton; +class DelegateView; + +class DelegatePage : public QWidget +{ + Q_OBJECT + + public: + DelegatePage( QWidget *parent = 0 ); + ~DelegatePage(); + + private slots: + void loadAllDelegates(); + void addDelegate(); + void editDelegate(); + void removeDelegate(); + + void delegateAdded( KIO::Job* ); + void delegateRemoved( KIO::Job* ); + void allDelegates( KIO::Job* ); + + void selectionChanged(); + + private: + QPushButton *mAddButton; + QPushButton *mEditButton; + QPushButton *mRemoveButton; + + DelegateManager mManager; + DelegateView *mView; +}; + +#endif diff --git a/kresources/scalix/scalixadmin/delegateview.cpp b/kresources/scalix/scalixadmin/delegateview.cpp new file mode 100644 index 000000000..9ea16cf1a --- /dev/null +++ b/kresources/scalix/scalixadmin/delegateview.cpp @@ -0,0 +1,74 @@ +/* + * 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 <klocale.h> + +#include "delegatemanager.h" + +#include "delegateview.h" + +class DelegateItem : public QListViewItem +{ + public: + DelegateItem( QListView *parent, const Scalix::Delegate &delegate ) + : QListViewItem( parent ), mDelegate( delegate ) + { + setText( 0, mDelegate.email() ); + setText( 1, Scalix::Delegate::rightsAsString( mDelegate.rights() ) ); + } + + Scalix::Delegate delegate() const { return mDelegate; } + + private: + Scalix::Delegate mDelegate; +}; + +DelegateView::DelegateView( DelegateManager *manager, QWidget *parent ) + : KListView( parent ), mManager( manager ) +{ + addColumn( i18n( "Delegate" ) ); + addColumn( i18n( "Rights" ) ); + setFullWidth( true ); + setAllColumnsShowFocus( true ); + + connect( mManager, SIGNAL( changed() ), SLOT( delegateChanged() ) ); + + delegateChanged(); +} + +Scalix::Delegate DelegateView::selectedDelegate() const +{ + DelegateItem *item = dynamic_cast<DelegateItem*>( selectedItem() ); + if ( item ) + return item->delegate(); + + return Scalix::Delegate(); +} + +void DelegateView::delegateChanged() +{ + clear(); + + const Scalix::Delegate::List delegates = mManager->delegates(); + for ( uint i = 0; i < delegates.count(); ++i ) + new DelegateItem( this, delegates[ i ] ); +} + +#include "delegateview.moc" diff --git a/kresources/scalix/scalixadmin/delegateview.h b/kresources/scalix/scalixadmin/delegateview.h new file mode 100644 index 000000000..61725be29 --- /dev/null +++ b/kresources/scalix/scalixadmin/delegateview.h @@ -0,0 +1,48 @@ +/* + * 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. + */ + +#ifndef DELEGATEVIEW_H +#define DELEGATEVIEW_H + +#include <klistview.h> + +namespace Scalix { +class Delegate; +} + +class DelegateManager; + +class DelegateView : public KListView +{ + Q_OBJECT + + public: + DelegateView( DelegateManager *manager, QWidget *parent = 0 ); + + Scalix::Delegate selectedDelegate() const; + + private slots: + void delegateChanged(); + + private: + DelegateManager *mManager; +}; + +#endif diff --git a/kresources/scalix/scalixadmin/jobs.cpp b/kresources/scalix/scalixadmin/jobs.cpp new file mode 100644 index 000000000..c463463d2 --- /dev/null +++ b/kresources/scalix/scalixadmin/jobs.cpp @@ -0,0 +1,306 @@ +/* + * 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 <kio/scheduler.h> +#include <klocale.h> + +#include "jobs.h" + +using namespace Scalix; + +Delegate::Delegate() + : mRights( -1 ) +{ +} + +Delegate::Delegate( const QString &email, int rights ) + : mEmail( email ), mRights( rights ) +{ +} + +bool Delegate::isValid() const +{ + return ( !mEmail.isEmpty() && mRights != -1 ); +} + +QString Delegate::email() const +{ + return mEmail; +} + +int Delegate::rights() const +{ + return mRights; +} + +QString Delegate::rightsAsString( int rights ) +{ + QStringList rightNames; + + if ( rights & SendOnBehalfOf ) + rightNames.append( i18n( "Send on behalf of" ) ); + if ( rights & SeePrivate ) + rightNames.append( i18n( "See private" ) ); + if ( rights & GetMeetings ) + rightNames.append( i18n( "Get meetings" ) ); + if ( rights & InsteadOfMe ) + rightNames.append( i18n( "Instead of me" ) ); + + return rightNames.join( ", " ); +} + + +SetPasswordJob* Scalix::setPassword( KIO::Slave* slave, const KURL& url, + const QString &oldPassword, const QString& newPassword ) +{ + QByteArray packedArgs; + QDataStream stream( packedArgs, IO_WriteOnly ); + stream << (int)'X' << (int)'N' + << QString( "X-SCALIX-PASSWORD" ) << QString( "%1 %2" ).arg( oldPassword ).arg( newPassword ); + + SetPasswordJob* job = new SetPasswordJob( url, packedArgs, false ); + KIO::Scheduler::assignJobToSlave( slave, job ); + return job; +} + +SetDelegateJob* Scalix::setDelegate( KIO::Slave* slave, const KURL& url, const QString& email, int params ) +{ + QStringList types; + if ( params & SendOnBehalfOf ) + types.append( "SOBO" ); + if ( params & SeePrivate ) + types.append( "SEEPRIVATE" ); + if ( params & GetMeetings ) + types.append( "GETMEETINGS" ); + if ( params & InsteadOfMe ) + types.append( "INSTEADOFME" ); + + QByteArray packedArgs; + QDataStream stream( packedArgs, IO_WriteOnly ); + stream << (int)'X' << (int)'N' + << QString( "X-SET-DELEGATE" ) << QString( "%1 %2" ).arg( email ).arg( types.join( " " ) ); + + SetDelegateJob* job = new SetDelegateJob( url, packedArgs, false ); + KIO::Scheduler::assignJobToSlave( slave, job ); + return job; +} + +DeleteDelegateJob* Scalix::deleteDelegate( KIO::Slave* slave, const KURL& url, const QString& email ) +{ + QByteArray packedArgs; + QDataStream stream( packedArgs, IO_WriteOnly ); + stream << (int)'X' << (int)'N' + << QString( "X-DELETE-DELEGATE" ) << email; + + DeleteDelegateJob* job = new DeleteDelegateJob( url, packedArgs, false ); + KIO::Scheduler::assignJobToSlave( slave, job ); + return job; +} + +GetDelegatesJob* Scalix::getDelegates( KIO::Slave* slave, const KURL& url ) +{ + QByteArray packedArgs; + QDataStream stream( packedArgs, IO_WriteOnly ); + stream << (int)'X' << (int)'N' << QString( "X-GET-DELEGATES" ) << QString(); + + GetDelegatesJob* job = new GetDelegatesJob( url, packedArgs, false ); + KIO::Scheduler::assignJobToSlave( slave, job ); + return job; +} + +AddOtherUserJob* Scalix::addOtherUser( KIO::Slave* slave, const KURL& url, const QString& email ) +{ + QByteArray packedArgs; + QDataStream stream( packedArgs, IO_WriteOnly ); + stream << (int)'X' << (int)'N' + << QString( "X-ADD-OTHER-USER" ) << email; + + AddOtherUserJob* job = new AddOtherUserJob( url, packedArgs, false ); + KIO::Scheduler::assignJobToSlave( slave, job ); + return job; +} + +DeleteOtherUserJob* Scalix::deleteOtherUser( KIO::Slave* slave, const KURL& url, const QString& email ) +{ + QByteArray packedArgs; + QDataStream stream( packedArgs, IO_WriteOnly ); + stream << (int)'X' << (int)'N' + << QString( "X-DELETE-OTHER-USER" ) << email; + + DeleteOtherUserJob* job = new DeleteOtherUserJob( url, packedArgs, false ); + KIO::Scheduler::assignJobToSlave( slave, job ); + return job; +} + +GetOtherUsersJob* Scalix::getOtherUsers( KIO::Slave* slave, const KURL& url ) +{ + QByteArray packedArgs; + QDataStream stream( packedArgs, IO_WriteOnly ); + stream << (int)'X' << (int)'N' + << QString( "X-GET-OTHER-USERS" ) << QString(); + + GetOtherUsersJob* job = new GetOtherUsersJob( url, packedArgs, false ); + KIO::Scheduler::assignJobToSlave( slave, job ); + return job; +} + +SetOutOfOfficeJob* Scalix::setOutOfOffice( KIO::Slave* slave, const KURL& url, bool enabled, const QString& msg ) +{ + const QString argument = msg; + const QString command = QString( "X-SET-OUT-OF-OFFICE %1 %2 {%3}" ).arg( enabled ? "ENABLED" : "DISABLED" ) + .arg( "UTF-8" ) + .arg( msg.utf8().length() ); + + QByteArray packedArgs; + QDataStream stream( packedArgs, IO_WriteOnly ); + stream << (int) 'X' << (int)'E' << command << argument; + + SetOutOfOfficeJob* job = new SetOutOfOfficeJob( url, packedArgs, false ); + KIO::Scheduler::assignJobToSlave( slave, job ); + return job; +} + +GetOutOfOfficeJob* Scalix::getOutOfOffice( KIO::Slave* slave, const KURL& url ) +{ + QByteArray packedArgs; + QDataStream stream( packedArgs, IO_WriteOnly ); + stream << (int)'X' << (int)'N' + << QString( "X-GET-OUT-OF-OFFICE" ) << QString(); + + GetOutOfOfficeJob* job = new GetOutOfOfficeJob( url, packedArgs, false ); + KIO::Scheduler::assignJobToSlave( slave, job ); + return job; +} + +SetPasswordJob::SetPasswordJob( const KURL& url, const QByteArray &packedArgs, bool showProgressInfo ) + : KIO::SimpleJob( url, KIO::CMD_SPECIAL, packedArgs, showProgressInfo ) +{ +} + +SetDelegateJob::SetDelegateJob( const KURL& url, const QByteArray &packedArgs, bool showProgressInfo ) + : KIO::SimpleJob( url, KIO::CMD_SPECIAL, packedArgs, showProgressInfo ) +{ +} + +DeleteDelegateJob::DeleteDelegateJob( const KURL& url, const QByteArray &packedArgs, bool showProgressInfo ) + : KIO::SimpleJob( url, KIO::CMD_SPECIAL, packedArgs, showProgressInfo ) +{ +} + +GetDelegatesJob::GetDelegatesJob( const KURL& url, const QByteArray &packedArgs, bool showProgressInfo ) + : KIO::SimpleJob( url, KIO::CMD_SPECIAL, packedArgs, showProgressInfo ) +{ + connect( this, SIGNAL( infoMessage( KIO::Job*, const QString& ) ), + this, SLOT( slotInfoMessage( KIO::Job*, const QString& ) ) ); +} + +Delegate::List GetDelegatesJob::delegates() const +{ + return mDelegates; +} + +void GetDelegatesJob::slotInfoMessage( KIO::Job*, const QString &data ) +{ + /** + * The passed data have the following form: + * + * "user1@host.com:right1,right2,right4 user2@host.com:right3,right5" + */ + QStringList delegates = QStringList::split( ' ', data ); + for ( uint i = 0; i < delegates.count(); ++i ) { + QStringList delegate = QStringList::split( ':', delegates[ i ] ); + + const QString email = delegate[ 0 ]; + int rights = 0; + + QStringList rightsList = QStringList::split( ',', delegate[ 1 ] ); + for ( uint j = 0; j < rightsList.count(); ++j ) { + if ( rightsList[ j ] == "SOBO" ) + rights |= SendOnBehalfOf; + else if ( rightsList[ j ] == "SEEPRIVATE" ) + rights |= SeePrivate; + else if ( rightsList[ j ] == "GETMEETINGS" ) + rights |= GetMeetings; + else if ( rightsList[ j ] == "INSTEADOFME" ) + rights |= InsteadOfMe; + } + + mDelegates.append( Delegate( email, rights ) ); + } +} + +AddOtherUserJob::AddOtherUserJob( const KURL& url, const QByteArray &packedArgs, bool showProgressInfo ) + : KIO::SimpleJob( url, KIO::CMD_SPECIAL, packedArgs, showProgressInfo ) +{ +} + +DeleteOtherUserJob::DeleteOtherUserJob( const KURL& url, const QByteArray &packedArgs, bool showProgressInfo ) + : KIO::SimpleJob( url, KIO::CMD_SPECIAL, packedArgs, showProgressInfo ) +{ +} + +GetOtherUsersJob::GetOtherUsersJob( const KURL& url, const QByteArray &packedArgs, bool showProgressInfo ) + : KIO::SimpleJob( url, KIO::CMD_SPECIAL, packedArgs, showProgressInfo ) +{ + connect( this, SIGNAL( infoMessage( KIO::Job*, const QString& ) ), + this, SLOT( slotInfoMessage( KIO::Job*, const QString& ) ) ); +} + +QStringList GetOtherUsersJob::otherUsers() const +{ + return mOtherUsers; +} + +void GetOtherUsersJob::slotInfoMessage( KIO::Job*, const QString &data ) +{ + mOtherUsers = QStringList::split( ' ', data ); +} + +SetOutOfOfficeJob::SetOutOfOfficeJob( const KURL& url, const QByteArray &packedArgs, bool showProgressInfo ) + : KIO::SimpleJob( url, KIO::CMD_SPECIAL, packedArgs, showProgressInfo ) +{ +} + +GetOutOfOfficeJob::GetOutOfOfficeJob( const KURL& url, const QByteArray &packedArgs, bool showProgressInfo ) + : KIO::SimpleJob( url, KIO::CMD_SPECIAL, packedArgs, showProgressInfo ) +{ + connect( this, SIGNAL( infoMessage( KIO::Job*, const QString& ) ), + this, SLOT( slotInfoMessage( KIO::Job*, const QString& ) ) ); +} + +bool GetOutOfOfficeJob::enabled() const +{ + return mEnabled; +} + +QString GetOutOfOfficeJob::message() const +{ + return mMessage; +} + +void GetOutOfOfficeJob::slotInfoMessage( KIO::Job*, const QString &data ) +{ + const QStringList fields = QStringList::split( '^', data ); + + mEnabled = ( fields[ 0 ] == "ENABLED" ); + mMessage = fields[ 1 ]; +} + +#include "jobs.moc" diff --git a/kresources/scalix/scalixadmin/jobs.h b/kresources/scalix/scalixadmin/jobs.h new file mode 100644 index 000000000..3b5a1b81f --- /dev/null +++ b/kresources/scalix/scalixadmin/jobs.h @@ -0,0 +1,202 @@ +/* + * 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 <kio/job.h> + +#ifndef JOBS_H +#define JOBS_H + +namespace Scalix { + + enum DelegateTypes + { + SendOnBehalfOf = 1, + SeePrivate = 2, + GetMeetings = 4, + InsteadOfMe = 8 + }; + + class SetPasswordJob; + class SetDelegateJob; + class DeleteDelegateJob; + class GetDelegatesJob; + class AddOtherUserJob; + class DeleteOtherUserJob; + class GetOtherUsersJob; + class SetOutOfOfficeJob; + class GetOutOfOfficeJob; + + class Delegate + { + public: + typedef QValueList<Delegate> List; + + Delegate(); + Delegate( const QString &email, int rights ); + + bool isValid() const; + + QString email() const; + int rights() const; + + static QString rightsAsString( int rights ); + + private: + QString mEmail; + int mRights; + }; + + /** + * Sets/Changes the password of the user encoded in @p url. + */ + SetPasswordJob* setPassword( KIO::Slave* slave, const KURL& url, const QString& oldPassword, const QString& newPassword ); + + /** + * Adds a delegate represented by @p email with the given @p params for the user encoded in @p url. + */ + SetDelegateJob* setDelegate( KIO::Slave* slave, const KURL& url, const QString& email, int params ); + + /** + * Deletes the delegate represented by @p email for the user encoded in @p url. + */ + DeleteDelegateJob* deleteDelegate( KIO::Slave* slave, const KURL& url, const QString& email ); + + /** + * Retrieves the delegates for the user encoded in @p url. + */ + GetDelegatesJob* getDelegates( KIO::Slave* slave, const KURL& url ); + + /** + * Adds the mailbox of another user represented by @p email to the users 'Other Users' namespace. + */ + AddOtherUserJob* addOtherUser( KIO::Slave* slave, const KURL& url, const QString& email ); + + /** + * Deletes the mailbox of another user represented by @p email from the users 'Other Users' namespace. + */ + DeleteOtherUserJob* deleteOtherUser( KIO::Slave* slave, const KURL& url, const QString& email ); + + /** + * Retrieves the list of all other users. + */ + GetOtherUsersJob* getOtherUsers( KIO::Slave* slave, const KURL& url ); + + /** + * Sets the out-of-office data. + * + * @param enabled Whether the out-of-office functionality is enabled. + * @param msg The out-of-office message. + */ + SetOutOfOfficeJob* setOutOfOffice( KIO::Slave* slave, const KURL& url, bool enabled, const QString& msg ); + + /** + * Retrieves the out-of-office data. + */ + GetOutOfOfficeJob* getOutOfOffice( KIO::Slave* slave, const KURL& url ); + + + class SetPasswordJob : public KIO::SimpleJob + { + public: + SetPasswordJob( const KURL& url, const QByteArray &packedArgs, bool showProgressInfo ); + }; + + class SetDelegateJob : public KIO::SimpleJob + { + public: + SetDelegateJob( const KURL& url, const QByteArray &packedArgs, bool showProgressInfo ); + }; + + class DeleteDelegateJob : public KIO::SimpleJob + { + public: + DeleteDelegateJob( const KURL& url, const QByteArray &packedArgs, bool showProgressInfo ); + }; + + class GetDelegatesJob : public KIO::SimpleJob + { + Q_OBJECT + + public: + GetDelegatesJob( const KURL& url, const QByteArray &packedArgs, bool showProgressInfo ); + + Delegate::List delegates() const; + + private slots: + void slotInfoMessage( KIO::Job*, const QString& ); + + private: + Delegate::List mDelegates; + }; + + class AddOtherUserJob : public KIO::SimpleJob + { + public: + AddOtherUserJob( const KURL& url, const QByteArray &packedArgs, bool showProgressInfo ); + }; + + class DeleteOtherUserJob : public KIO::SimpleJob + { + public: + DeleteOtherUserJob( const KURL& url, const QByteArray &packedArgs, bool showProgressInfo ); + }; + + class GetOtherUsersJob : public KIO::SimpleJob + { + Q_OBJECT + + public: + GetOtherUsersJob( const KURL& url, const QByteArray &packedArgs, bool showProgressInfo ); + + QStringList otherUsers() const; + + private slots: + void slotInfoMessage( KIO::Job*, const QString& ); + + private: + QStringList mOtherUsers; + }; + + class SetOutOfOfficeJob : public KIO::SimpleJob + { + public: + SetOutOfOfficeJob( const KURL& url, const QByteArray &packedArgs, bool showProgressInfo ); + }; + + class GetOutOfOfficeJob : public KIO::SimpleJob + { + Q_OBJECT + + public: + GetOutOfOfficeJob( const KURL& url, const QByteArray &packedArgs, bool showProgressInfo ); + + bool enabled() const; + QString message() const; + + private slots: + void slotInfoMessage( KIO::Job*, const QString& ); + + private: + bool mEnabled; + QString mMessage; + }; +} + +#endif diff --git a/kresources/scalix/scalixadmin/ldapdialog.cpp b/kresources/scalix/scalixadmin/ldapdialog.cpp new file mode 100644 index 000000000..be624f131 --- /dev/null +++ b/kresources/scalix/scalixadmin/ldapdialog.cpp @@ -0,0 +1,43 @@ +/* + * 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 <klocale.h> + +#include "ldapview.h" + +#include "ldapdialog.h" + +LdapDialog::LdapDialog( QWidget *parent ) + : KDialogBase( parent, "", true, "", Ok | Cancel, Ok, true ) +{ + setCaption( i18n( "User Account Selection" ) ); + + mView = new LdapView( this ); + setMainWidget( mView ); + + mView->setQuery( "cn=*" ); + + resize( 400, 250 ); +} + +QString LdapDialog::selectedUser() const +{ + return mView->selectedUser(); +} diff --git a/kresources/scalix/scalixadmin/ldapdialog.h b/kresources/scalix/scalixadmin/ldapdialog.h new file mode 100644 index 000000000..6b326f550 --- /dev/null +++ b/kresources/scalix/scalixadmin/ldapdialog.h @@ -0,0 +1,39 @@ +/* + * 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. + */ +#ifndef LDAPDIALOG_H +#define LDAPDIALOG_H + +#include <kdialogbase.h> + +class LdapView; + +class LdapDialog : public KDialogBase +{ + public: + LdapDialog( QWidget *parent = 0 ); + + QString selectedUser() const; + + + private: + LdapView *mView; +}; + +#endif diff --git a/kresources/scalix/scalixadmin/ldapview.cpp b/kresources/scalix/scalixadmin/ldapview.cpp new file mode 100644 index 000000000..660f1944a --- /dev/null +++ b/kresources/scalix/scalixadmin/ldapview.cpp @@ -0,0 +1,99 @@ +/* + * 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 <kabc/ldapclient.h> +#include <klocale.h> +#include <kmessagebox.h> + +#include "settings.h" + +#include "ldapview.h" + +class LdapItem : public QListViewItem +{ + public: + LdapItem( QListView *parent, const QString &text, const QString &email ) + : QListViewItem( parent ) + { + setText( 0, text ); + setText( 1, email ); + } +}; + + +LdapView::LdapView( QWidget *parent ) + : KListView( parent ) +{ + addColumn( i18n( "User" ) ); + setFullWidth( true ); + + mClient = new KABC::LdapClient; + + mClient->setHost( Settings::self()->ldapHost() ); + mClient->setPort( Settings::self()->ldapPort() ); + mClient->setBase( Settings::self()->ldapBase() ); + mClient->setBindDN( Settings::self()->ldapBindDn() ); + mClient->setPwdBindDN( Settings::self()->ldapPassword() ); + + QStringList attrs; + attrs << "surname" << "mail"; + mClient->setAttrs( attrs ); + + connect( mClient, SIGNAL( result( const KABC::LdapObject& ) ), + this, SLOT( entryAdded( const KABC::LdapObject& ) ) ); + connect( mClient, SIGNAL( error( const QString& ) ), + this, SLOT( error( const QString& ) ) ); +} + +LdapView::~LdapView() +{ + mClient->cancelQuery(); + delete mClient; +} + +QString LdapView::selectedUser() const +{ + QListViewItem *item = selectedItem(); + if ( !item ) + return QString(); + else + return item->text( 1 ); +} + +void LdapView::setQuery( const QString &query ) +{ + clear(); + mClient->startQuery( query ); +} + +void LdapView::entryAdded( const KABC::LdapObject &obj ) +{ + const QString text = QString( "%1 (%2)" ).arg( obj.attrs[ "surname" ].first() ) + .arg( obj.attrs[ "mail" ].first() ); + + new LdapItem( this, text, obj.attrs[ "mail" ].first() ); +} + +void LdapView::error( const QString &msg ) +{ + KMessageBox::error( this, msg ); +} + +#include "ldapview.moc" diff --git a/kresources/scalix/scalixadmin/ldapview.h b/kresources/scalix/scalixadmin/ldapview.h new file mode 100644 index 000000000..0acb3602c --- /dev/null +++ b/kresources/scalix/scalixadmin/ldapview.h @@ -0,0 +1,51 @@ +/* + * 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. + */ +#ifndef LDAPVIEW_H +#define LDAPVIEW_H + +#include <klistview.h> + +namespace KABC { +class LdapClient; +class LdapObject; +} + +class LdapView : public KListView +{ + Q_OBJECT + + public: + LdapView( QWidget *parent = 0 ); + ~LdapView(); + + QString selectedUser() const; + + public slots: + void setQuery( const QString &query ); + + private slots: + void entryAdded( const KABC::LdapObject& ); + void error( const QString& ); + + private: + KABC::LdapClient *mClient; +}; + +#endif diff --git a/kresources/scalix/scalixadmin/main.cpp b/kresources/scalix/scalixadmin/main.cpp new file mode 100644 index 000000000..d27399210 --- /dev/null +++ b/kresources/scalix/scalixadmin/main.cpp @@ -0,0 +1,53 @@ +/* + * 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 <kaboutdata.h> +#include <kapplication.h> +#include <kcmdlineargs.h> +#include <klocale.h> + +#include "mainwindow.h" + +static const char description[] = I18N_NOOP("Configuration Tool for Scalix Groupware Konnector"); + +static KCmdLineOptions options[] = +{ + KCmdLineLastOption +}; + +int main( int argc, char **argv ) +{ + KAboutData aboutData( "scalixadmin", I18N_NOOP("ScalixAdmin"), "1.0", description, + KAboutData::License_GPL, "(c) 2007, Tobias Koenig" ); + aboutData.addAuthor( "Tobias Koenig",0, "tokoe@kde.org" ); + KCmdLineArgs::init( argc, argv, &aboutData ); + KCmdLineArgs::addCmdLineOptions( options ); + + KApplication app; + + KGlobal::locale()->insertCatalogue( "scalixadmin" ); + + MainWindow *window = new MainWindow; + window->show(); + + app.setMainWidget( window ); + + return app.exec(); +} diff --git a/kresources/scalix/scalixadmin/mainwindow.cpp b/kresources/scalix/scalixadmin/mainwindow.cpp new file mode 100644 index 000000000..e6cac550d --- /dev/null +++ b/kresources/scalix/scalixadmin/mainwindow.cpp @@ -0,0 +1,59 @@ +/* + * 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 <qvbox.h> + +#include <kglobal.h> +#include <kiconloader.h> +#include <kjanuswidget.h> +#include <klocale.h> + +#include "delegatepage.h" +#include "otheruserpage.h" +#include "outofofficepage.h" +#include "passwordpage.h" + +#include "mainwindow.h" + +MainWindow::MainWindow() + : KMainWindow( 0 ) +{ + KJanusWidget *wdg = new KJanusWidget( this, "", KJanusWidget::IconList ); + + QPixmap icon = KGlobal::iconLoader()->loadIcon( "folder_yellow", KIcon::Desktop ); + QVBox *page = wdg->addVBoxPage( i18n( "Other Accounts" ), i18n( "Register other accounts" ), icon ); + new OtherUserPage( page ); + + icon = KGlobal::iconLoader()->loadIcon( "edu_languages", KIcon::Desktop ); + page = wdg->addVBoxPage( i18n( "Delegates" ), i18n( "Setup delegates for my account" ), icon ); + new DelegatePage( page ); + + icon = KGlobal::iconLoader()->loadIcon( "kontact_summary_green", KIcon::Desktop ); + page = wdg->addVBoxPage( i18n( "Out of Office..." ), i18n( "Setup Out of Office Message" ), icon ); + new OutOfOfficePage( page ); + + icon = KGlobal::iconLoader()->loadIcon( "password", KIcon::Desktop ); + page = wdg->addVBoxPage( i18n( "Password" ), i18n( "Change the password" ), icon ); + new PasswordPage( page ); + + setCentralWidget( wdg ); + + resize( 540, 450 ); +} diff --git a/kresources/scalix/scalixadmin/mainwindow.h b/kresources/scalix/scalixadmin/mainwindow.h new file mode 100644 index 000000000..38c955980 --- /dev/null +++ b/kresources/scalix/scalixadmin/mainwindow.h @@ -0,0 +1,32 @@ +/* + * 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. + */ + +#ifndef MAINWINDOW_H +#define MAINWINDOW_H + +#include <kmainwindow.h> + +class MainWindow : public KMainWindow +{ + public: + MainWindow(); +}; + +#endif diff --git a/kresources/scalix/scalixadmin/otherusermanager.cpp b/kresources/scalix/scalixadmin/otherusermanager.cpp new file mode 100644 index 000000000..b5b3d3ccf --- /dev/null +++ b/kresources/scalix/scalixadmin/otherusermanager.cpp @@ -0,0 +1,51 @@ +/* + * 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 "otherusermanager.h" + +OtherUserManager::OtherUserManager() +{ +} + +OtherUserManager::~OtherUserManager() +{ +} + +void OtherUserManager::addOtherUser( const QString &email ) +{ + if ( !mOtherUsers.contains( email ) ) { + mOtherUsers.append( email ); + emit changed(); + } +} + +void OtherUserManager::clear() +{ + mOtherUsers.clear(); + + emit changed(); +} + +QStringList OtherUserManager::otherUsers() const +{ + return mOtherUsers; +} + +#include "otherusermanager.moc" diff --git a/kresources/scalix/scalixadmin/otherusermanager.h b/kresources/scalix/scalixadmin/otherusermanager.h new file mode 100644 index 000000000..6f7f9ac77 --- /dev/null +++ b/kresources/scalix/scalixadmin/otherusermanager.h @@ -0,0 +1,47 @@ +/* + * 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. + */ + +#ifndef OTHERUSERMANAGER_H +#define OTHERUSERMANAGER_H + +#include <qobject.h> +#include <qstringlist.h> + +class OtherUserManager : public QObject +{ + Q_OBJECT + + public: + OtherUserManager(); + ~OtherUserManager(); + + void addOtherUser( const QString &email ); + void clear(); + + QStringList otherUsers() const; + + signals: + void changed(); + + private: + QStringList mOtherUsers; +}; + +#endif diff --git a/kresources/scalix/scalixadmin/otheruserpage.cpp b/kresources/scalix/scalixadmin/otheruserpage.cpp new file mode 100644 index 000000000..ae12290c7 --- /dev/null +++ b/kresources/scalix/scalixadmin/otheruserpage.cpp @@ -0,0 +1,173 @@ +/* + * 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 <qapplication.h> +#include <qlayout.h> +#include <qpushbutton.h> + +#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" + +OtherUserPage::OtherUserPage( QWidget *parent ) + : QWidget( parent ) +{ + QGridLayout *layout = new QGridLayout( this, 2, 2, 11, 6 ); + + mView = new OtherUserView( &mManager, this ); + layout->addMultiCellWidget( mView, 0, 0, 0, 1 ); + + mAddButton = new QPushButton( i18n( "Add Account..." ), this ); + layout->addWidget( mAddButton, 1, 0 ); + + mDeleteButton = new QPushButton( i18n( "Remove Account" ), this ); + mDeleteButton->setEnabled( false ); + layout->addWidget( mDeleteButton, 1, 1 ); + + connect( mView, SIGNAL( selectionChanged() ), SLOT( selectionChanged() ) ); + connect( mAddButton, SIGNAL( clicked() ), SLOT( addUser() ) ); + connect( mDeleteButton, SIGNAL( clicked() ), SLOT( removeUser() ) ); + + loadAllUsers(); +} + +OtherUserPage::~OtherUserPage() +{ +} + +void OtherUserPage::loadAllUsers() +{ + Scalix::GetOtherUsersJob *job = Scalix::getOtherUsers( Settings::self()->globalSlave(), + Settings::self()->accountUrl() ); + connect( job, SIGNAL( result( KIO::Job* ) ), SLOT( allUsers( KIO::Job* ) ) ); +} + +void OtherUserPage::addUser() +{ + LdapDialog dlg( this ); + if ( !dlg.exec() ) + return; + + const QString email = dlg.selectedUser(); + if ( email.isEmpty() ) + return; + + Scalix::AddOtherUserJob *job = Scalix::addOtherUser( Settings::self()->globalSlave(), + Settings::self()->accountUrl(), email ); + connect( job, SIGNAL( result( KIO::Job* ) ), SLOT( userAdded( KIO::Job* ) ) ); +} + +void OtherUserPage::removeUser() +{ + const QString email = mView->selectedUser(); + if ( email.isEmpty() ) + return; + + Scalix::DeleteOtherUserJob *job = Scalix::deleteOtherUser( Settings::self()->globalSlave(), + Settings::self()->accountUrl(), email ); + connect( job, SIGNAL( result( KIO::Job* ) ), SLOT( userRemoved( KIO::Job* ) ) ); +} + +void OtherUserPage::allUsers( KIO::Job *job ) +{ + if ( job->error() ) + KMessageBox::error( this, job->errorString() ); + + Scalix::GetOtherUsersJob *userJob = static_cast<Scalix::GetOtherUsersJob*>( job ); + + mManager.clear(); + + const QStringList users = userJob->otherUsers(); + for ( uint i = 0; i < users.count(); ++i ) + mManager.addOtherUser( users[ i ] ); + + selectionChanged(); +} + +void OtherUserPage::userAdded( KIO::Job *job ) +{ + if ( job->error() ) + KMessageBox::error( this, job->errorString() ); + else + loadAllUsers(); // update the GUI + + updateKmail(); +} + +void OtherUserPage::userRemoved( KIO::Job *job ) +{ + 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() +{ + QMessageBox *msg = new QMessageBox( qApp->mainWidget() ); + msg->setText( i18n( "Updating account..." ) ); + msg->show(); + qApp->processEvents(); + sleep( 1 ); + qApp->processEvents(); + + QString error; + QCString dcopService; + int result = KDCOPServiceStarter::self()-> + findServiceFor( "DCOP/ResourceBackend/IMAP", QString::null, + QString::null, &error, &dcopService ); + 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 + QStringList list; + while ( list.isEmpty() ) { + ref.call( "accounts()" ).get( list ); + } + + ref.call( "checkAccount(QString)", i18n( "Scalix Server" ) ); + + delete msg; +} + +#include "otheruserpage.moc" diff --git a/kresources/scalix/scalixadmin/otheruserpage.h b/kresources/scalix/scalixadmin/otheruserpage.h new file mode 100644 index 000000000..f847a05d3 --- /dev/null +++ b/kresources/scalix/scalixadmin/otheruserpage.h @@ -0,0 +1,60 @@ +/* + * 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. + */ + +#ifndef OTHERUSERPAGE_H +#define OTHERUSERPAGE_H + +#include <qwidget.h> + +#include "otherusermanager.h" + +class QPushButton; +class OtherUserView; + +class OtherUserPage : public QWidget +{ + Q_OBJECT + + public: + OtherUserPage( QWidget *parent = 0 ); + ~OtherUserPage(); + + private slots: + void loadAllUsers(); + void addUser(); + void removeUser(); + + void userAdded( KIO::Job* ); + void userRemoved( KIO::Job* ); + void allUsers( KIO::Job* ); + + void selectionChanged(); + + private: + void updateKmail(); + + QPushButton *mAddButton; + QPushButton *mDeleteButton; + + OtherUserManager mManager; + OtherUserView *mView; +}; + +#endif diff --git a/kresources/scalix/scalixadmin/otheruserview.cpp b/kresources/scalix/scalixadmin/otheruserview.cpp new file mode 100644 index 000000000..70bc9e3d5 --- /dev/null +++ b/kresources/scalix/scalixadmin/otheruserview.cpp @@ -0,0 +1,71 @@ +/* + * 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 <klocale.h> + +#include "otherusermanager.h" + +#include "otheruserview.h" + +class OtherUserItem : public QListViewItem +{ + public: + OtherUserItem( QListView *parent, const QString &user ) + : QListViewItem( parent ), mUser( user ) + { + setText( 0, mUser ); + } + + QString user() const { return mUser; } + + private: + QString mUser; +}; + +OtherUserView::OtherUserView( OtherUserManager *manager, QWidget *parent ) + : KListView( parent ), mManager( manager ) +{ + addColumn( i18n( "Registered Accounts" ) ); + setFullWidth( true ); + + connect( mManager, SIGNAL( changed() ), SLOT( userChanged() ) ); + + userChanged(); +} + +QString OtherUserView::selectedUser() const +{ + OtherUserItem *item = dynamic_cast<OtherUserItem*>( selectedItem() ); + if ( item ) + return item->user(); + + return QString(); +} + +void OtherUserView::userChanged() +{ + clear(); + + QStringList users = mManager->otherUsers(); + for ( uint i = 0; i < users.count(); ++i ) + new OtherUserItem( this, users[ i ] ); +} + +#include "otheruserview.moc" diff --git a/kresources/scalix/scalixadmin/otheruserview.h b/kresources/scalix/scalixadmin/otheruserview.h new file mode 100644 index 000000000..6eacc93c9 --- /dev/null +++ b/kresources/scalix/scalixadmin/otheruserview.h @@ -0,0 +1,44 @@ +/* + * 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. + */ + +#ifndef OTHERUSERVIEW_H +#define OTHERUSERVIEW_H + +#include <klistview.h> + +class OtherUserManager; + +class OtherUserView : public KListView +{ + Q_OBJECT + + public: + OtherUserView( OtherUserManager *manager, QWidget *parent = 0 ); + + QString selectedUser() const; + + private slots: + void userChanged(); + + private: + OtherUserManager *mManager; +}; + +#endif diff --git a/kresources/scalix/scalixadmin/outofofficepage.cpp b/kresources/scalix/scalixadmin/outofofficepage.cpp new file mode 100644 index 000000000..0b8d3f803 --- /dev/null +++ b/kresources/scalix/scalixadmin/outofofficepage.cpp @@ -0,0 +1,125 @@ +/* + * 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 <qbuttongroup.h> +#include <qlabel.h> +#include <qlayout.h> +#include <qpushbutton.h> +#include <qradiobutton.h> +#include <qtextedit.h> + +#include <klocale.h> +#include <kmessagebox.h> + +#include "jobs.h" +#include "settings.h" + +#include "outofofficepage.h" + +OutOfOfficePage::OutOfOfficePage( QWidget *parent ) + : QWidget( parent ) +{ + QGridLayout *layout = new QGridLayout( this, 4, 2, 11, 6 ); + + QButtonGroup *group = new QButtonGroup( 1, Qt::Vertical, this ); + + mDisabled = new QRadioButton( i18n( "I am in the office" ), group ); + mDisabled->setChecked( true ); + mEnabled = new QRadioButton( i18n( "I am out of the office" ), group ); + + mLabel = new QLabel( i18n( "Auto-reply once to each sender with the following text:" ), this ); + mMessage = new QTextEdit( this ); + mSaveButton = new QPushButton( i18n( "Save" ), this ); + + layout->addMultiCellWidget( group, 0, 0, 0, 1 ); + layout->addMultiCellWidget( mLabel, 1, 1, 0, 1 ); + layout->addMultiCellWidget( mMessage, 2, 2, 0, 1 ); + layout->addWidget( mSaveButton, 3, 1 ); + + statusChanged(); + + connect( mEnabled, SIGNAL( toggled( bool ) ), this, SLOT( statusChanged() ) ); + connect( mEnabled, SIGNAL( toggled( bool ) ), this, SLOT( changed() ) ); + connect( mSaveButton, SIGNAL( clicked() ), this, SLOT( store() ) ); + connect( mMessage, SIGNAL( textChanged() ), this, SLOT( changed() ) ); + + load(); +} + +OutOfOfficePage::~OutOfOfficePage() +{ +} + +void OutOfOfficePage::load() +{ + Scalix::GetOutOfOfficeJob *job = Scalix::getOutOfOffice( Settings::self()->globalSlave(), + Settings::self()->accountUrl() ); + connect( job, SIGNAL( result( KIO::Job* ) ), SLOT( loaded( KIO::Job* ) ) ); +} + +void OutOfOfficePage::loaded( KIO::Job* job ) +{ + if ( job->error() ) { + KMessageBox::error( this, job->errorString() ); + return; + } + + Scalix::GetOutOfOfficeJob *outOfOfficeJob = static_cast<Scalix::GetOutOfOfficeJob*>( job ); + + mEnabled->setChecked( outOfOfficeJob->enabled() ); + mMessage->setText( outOfOfficeJob->message() ); + + statusChanged(); + + mSaveButton->setEnabled( false ); +} + +void OutOfOfficePage::store() +{ + Scalix::SetOutOfOfficeJob *job = Scalix::setOutOfOffice( Settings::self()->globalSlave(), + Settings::self()->accountUrl(), + mEnabled->isChecked(), + mMessage->text() ); + + connect( job, SIGNAL( result( KIO::Job* ) ), SLOT( stored( KIO::Job* ) ) ); + + mSaveButton->setEnabled( false ); +} + +void OutOfOfficePage::stored( KIO::Job* job ) +{ + if ( job->error() ) + KMessageBox::error( this, job->errorString() ); +} + +void OutOfOfficePage::statusChanged() +{ + bool state = mEnabled->isChecked(); + + mLabel->setEnabled( state ); + mMessage->setEnabled( state ); +} + +void OutOfOfficePage::changed() +{ + mSaveButton->setEnabled( true ); +} + +#include "outofofficepage.moc" diff --git a/kresources/scalix/scalixadmin/outofofficepage.h b/kresources/scalix/scalixadmin/outofofficepage.h new file mode 100644 index 000000000..cc5b2591a --- /dev/null +++ b/kresources/scalix/scalixadmin/outofofficepage.h @@ -0,0 +1,57 @@ +/* + * 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. + */ + +#ifndef OUTOFOFFICEPAGE_H +#define OUTOFOFFICEPAGE_H + +#include <qwidget.h> + +class QLabel; +class QPushButton; +class QRadioButton; +class QTextEdit; + +class OutOfOfficePage : public QWidget +{ + Q_OBJECT + + public: + OutOfOfficePage( QWidget *parent = 0 ); + ~OutOfOfficePage(); + + private slots: + void load(); + void loaded( KIO::Job* ); + void store(); + void stored( KIO::Job* ); + void statusChanged(); + void changed(); + + private: + QRadioButton *mEnabled; + QRadioButton *mDisabled; + QLabel *mLabel; + QTextEdit *mMessage; + QPushButton *mSaveButton; + + bool mChanged; +}; + +#endif diff --git a/kresources/scalix/scalixadmin/passwordpage.cpp b/kresources/scalix/scalixadmin/passwordpage.cpp new file mode 100644 index 000000000..7d4182348 --- /dev/null +++ b/kresources/scalix/scalixadmin/passwordpage.cpp @@ -0,0 +1,190 @@ +/* + * 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 <qapplication.h> +#include <qlabel.h> +#include <qlayout.h> +#include <qlineedit.h> +#include <qpushbutton.h> + +#include <kconfig.h> +#include <klocale.h> +#include <kmessagebox.h> +#include <kstringhandler.h> +#include <kwallet.h> + +#include "jobs.h" +#include "settings.h" + +#include "passwordpage.h" + +PasswordPage::PasswordPage( QWidget *parent ) + : QWidget( parent ), mJob( 0 ) +{ + QGridLayout *layout = new QGridLayout( this, 2, 3, 11, 6 ); + + QLabel *label = new QLabel( i18n( "New password:" ), this ); + layout->addWidget( label, 0, 0 ); + + mPassword = new QLineEdit( this ); + mPassword->setEchoMode( QLineEdit::Password ); + label->setBuddy( mPassword ); + layout->addWidget( mPassword, 0, 1 ); + + label = new QLabel( i18n( "Retype new password:" ), this ); + layout->addWidget( label, 1, 0 ); + + mPasswordRetype = new QLineEdit( this ); + mPasswordRetype->setEchoMode( QLineEdit::Password ); + label->setBuddy( mPasswordRetype ); + layout->addWidget( mPasswordRetype, 1, 1 ); + + mButton = new QPushButton( i18n( "Change" ), this ); + mButton->setEnabled( false ); + layout->addWidget( mButton, 2, 1 ); + + layout->setRowSpacing( 3, 1 ); + + connect( mPassword, SIGNAL( textChanged( const QString& ) ), this, SLOT( textChanged() ) ); + connect( mPasswordRetype, SIGNAL( textChanged( const QString& ) ), this, SLOT( textChanged() ) ); + connect( mButton, SIGNAL( clicked() ), this, SLOT( buttonClicked() ) ); +} + +void PasswordPage::buttonClicked() +{ + if ( !mJob ) { + if ( mPassword->text() != mPasswordRetype->text() ) { + KMessageBox::error( this, i18n( "The two passwords differ!" ) ); + return; + } + + mJob = Scalix::setPassword( Settings::self()->globalSlave(), Settings::self()->accountUrl(), + Settings::self()->accountPassword(), mPassword->text() ); + connect( mJob, SIGNAL( result( KIO::Job* ) ), this, SLOT( finished( KIO::Job* ) ) ); + + updateState( true ); + } else { + mJob->kill(); + mJob = 0; + + updateState( false ); + } +} + +void PasswordPage::updateState( bool isWorking ) +{ + if ( isWorking ) { + mPassword->setEnabled( false ); + mPasswordRetype->setEnabled( false ); + mButton->setText( i18n( "Stop" ) ); + } else { + mPassword->setEnabled( true ); + mPasswordRetype->setEnabled( true ); + mButton->setText( i18n( "Change" ) ); + } +} + +void PasswordPage::textChanged() +{ + mButton->setEnabled( !mPassword->text().isEmpty() && + !mPasswordRetype->text().isEmpty() ); +} + +void PasswordPage::finished( KIO::Job* job ) +{ + mJob = 0; + + updateState( false ); + + if ( job->error() ) { + KMessageBox::error( this, i18n( "Unable to change the password" ) + "\n" + job->errorString() ); + return; + } + + // Update configuration files to the new password as well + + const QString newPassword = mPassword->text(); + + { // ScalixAdmin config + KConfig config( "scalixadminrc" ); + KConfigGroup group( &config, "Account" ); + group.writeEntry( "pass", KStringHandler::obscure( newPassword ) ); + } + + { // ScalixWizard config + KConfig config( "scalixrc" ); + KConfigGroup group( &config, "General" ); + group.writeEntry( "Password", KStringHandler::obscure( newPassword ) ); + } + + { // KMail config + KConfig config( "kmailrc" ); + + // Try to find account group for Scalix + QString scalixAccount; + const QStringList groupList = config.groupList(); + for ( uint i = 0; i < groupList.count(); ++i ) { + if ( groupList[ i ].startsWith( "Account " ) ) { + KConfigGroup group( &config, groupList[ i ] ); + if ( group.hasKey( "groupwareType" ) && group.readNumEntry( "groupwareType" ) == 2 ) { + scalixAccount = groupList[ i ]; + break; + } + } + } + + if ( scalixAccount.isEmpty() ) { + qWarning( "No Scalix Groupware Account found in kmailrc!" ); + return; + } + + const int accountId = scalixAccount.mid( 8 ).toInt(); + + KConfigGroup group( &config, scalixAccount ); + + // Save only if the user choose it before + bool storePassword = group.readBoolEntry( "store-passwd", false ); + if ( storePassword ) { + // First try to store in KWallet + if ( KWallet::Wallet::isEnabled() ) { + WId window = 0; + if ( qApp->activeWindow() ) + window = qApp->activeWindow()->winId(); + + KWallet::Wallet *wallet = KWallet::Wallet::openWallet( KWallet::Wallet::NetworkWallet(), window ); + if ( wallet ) { + if ( !wallet->hasFolder( "kmail" ) ) + wallet->createFolder( "kmail" ); + wallet->setFolder( "kmail" ); + wallet->writePassword( "account-" + QString::number( accountId ), newPassword ); + } + } else { + group.writeEntry( "pass", KStringHandler::obscure( newPassword ) ); + } + + KConfigGroup fileGroup( &config, QString( "Folder-%1" ).arg( group.readNumEntry( "Folder" ) ) ); + fileGroup.writeEntry( "pass", KStringHandler::obscure( newPassword ) ); + } + } + + KMessageBox::information( this, i18n( "Password was changed successfully" ) ); +} + +#include "passwordpage.moc" diff --git a/kresources/scalix/scalixadmin/passwordpage.h b/kresources/scalix/scalixadmin/passwordpage.h new file mode 100644 index 000000000..a397be416 --- /dev/null +++ b/kresources/scalix/scalixadmin/passwordpage.h @@ -0,0 +1,55 @@ +/* + * 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. + */ + +#ifndef PASSWORDPAGE_H +#define PASSWORDPAGE_H + +#include <qwidget.h> + +class QLineEdit; +class QPushButton; + +namespace KIO { +class Job; +} + +class PasswordPage : public QWidget +{ + Q_OBJECT + + public: + PasswordPage( QWidget *parent = 0 ); + + private slots: + void buttonClicked(); + void finished( KIO::Job* ); + void textChanged(); + + private: + void updateState( bool ); + + QLineEdit *mPassword; + QLineEdit *mPasswordRetype; + QPushButton *mButton; + + KIO::Job *mJob; +}; + +#endif diff --git a/kresources/scalix/scalixadmin/settings.cpp b/kresources/scalix/scalixadmin/settings.cpp new file mode 100644 index 000000000..2f6b49bad --- /dev/null +++ b/kresources/scalix/scalixadmin/settings.cpp @@ -0,0 +1,136 @@ +/* + * 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 <kconfig.h> +#include <kio/scheduler.h> +#include <kstringhandler.h> + +#include "settings.h" + +Settings* Settings::mSelf = 0; + +Settings::Settings() +{ + mSlave = KIO::Scheduler::getConnectedSlave( accountUrl(), + accountData() ); +} + +Settings::~Settings() +{ +} + +Settings* Settings::self() +{ + if ( !mSelf ) + mSelf = new Settings; + + return mSelf; +} + +KIO::MetaData Settings::accountData() const +{ + KConfig config( "scalixadminrc" ); + KConfigGroup group( &config, "Account" ); + + KIO::MetaData data; + data.insert( "auth", group.readEntry( "auth" ) ); + data.insert( "tls", group.readBoolEntry( "use-tls" ) ? "on" : "off" ); + + return data; +} + +KURL Settings::accountUrl() const +{ + KConfig config( "scalixadminrc" ); + KConfigGroup group( &config, "Account" ); + + KURL url; + url.setProtocol( group.readBoolEntry( "use-ssl" ) ? "imaps" : "imap" ); + url.setUser( group.readEntry( "user" ) ); + url.setPass( KStringHandler::obscure( group.readEntry( "pass" ) ) ); + url.setHost( group.readEntry( "host" ) ); + url.setPort( group.readNumEntry( "port" ) ); + + return url; +} + +QString Settings::accountPassword() const +{ + KConfig config( "scalixadminrc" ); + KConfigGroup group( &config, "Account" ); + + return KStringHandler::obscure( group.readEntry( "pass" ) ); +} + +KIO::Slave* Settings::globalSlave() const +{ + return mSlave; +} + +QString Settings::rulesWizardUrl() const +{ + KConfig config( "scalixadminrc" ); + KConfigGroup group( &config, "Misc" ); + + QString url = group.readEntry( "rulesWizardUrl" ); + if ( url.isEmpty() ) { + KConfigGroup group( &config, "Account" ); + url = QString( "http://%1/Scalix/rw/?username=%2" ).arg( group.readEntry( "host" ) ) + .arg( group.readEntry( "user" ) ); + } + + return url; +} + +QString Settings::ldapHost() const +{ + KConfig config( "scalixadminrc" ); + KConfigGroup group( &config, "LDAP" ); + return group.readEntry( "host" ); +} + +QString Settings::ldapPort() const +{ + KConfig config( "scalixadminrc" ); + KConfigGroup group( &config, "LDAP" ); + return group.readEntry( "port" ); +} + +QString Settings::ldapBase() const +{ + KConfig config( "scalixadminrc" ); + KConfigGroup group( &config, "LDAP" ); + return group.readEntry( "base" ); +} + +QString Settings::ldapBindDn() const +{ + KConfig config( "scalixadminrc" ); + KConfigGroup group( &config, "LDAP" ); + return group.readEntry( "bindDn" ); +} + +QString Settings::ldapPassword() const +{ + KConfig config( "scalixadminrc" ); + KConfigGroup group( &config, "LDAP" ); + return group.readEntry( "password" ); +} + diff --git a/kresources/scalix/scalixadmin/settings.h b/kresources/scalix/scalixadmin/settings.h new file mode 100644 index 000000000..17ed9a2c9 --- /dev/null +++ b/kresources/scalix/scalixadmin/settings.h @@ -0,0 +1,56 @@ +/* + * 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. + */ + +#ifndef SETTINGS_H +#define SETTINGS_H + +#include <kurl.h> +#include <kio/global.h> +#include <kio/slave.h> + +class Settings +{ + public: + ~Settings(); + + static Settings* self(); + + KIO::MetaData accountData() const; + KURL accountUrl() const; + QString accountPassword() const; + + KIO::Slave *globalSlave() const; + + QString rulesWizardUrl() const; + + QString ldapHost() const; + QString ldapPort() const; + QString ldapBase() const; + QString ldapBindDn() const; + QString ldapPassword() const; + + private: + Settings(); + KIO::Slave *mSlave; + + static Settings* mSelf; +}; + +#endif |