kitchensync

groupconfig.cpp

00001 /*
00002     This file is part of KitchenSync.
00003 
00004     Copyright (c) 2005 Cornelius Schumacher <schumacher@kde.org>
00005 
00006     This program is free software; you can redistribute it and/or modify
00007     it under the terms of the GNU General Public License as published by
00008     the Free Software Foundation; either version 2 of the License, or
00009     (at your option) any later version.
00010 
00011     This program is distributed in the hope that it will be useful,
00012     but WITHOUT ANY WARRANTY; without even the implied warranty of
00013     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00014     GNU General Public License for more details.
00015 
00016     You should have received a copy of the GNU General Public License
00017     along with this program; if not, write to the Free Software
00018     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00019 */
00020 
00021 #include "groupconfig.h"
00022 
00023 #include "groupconfigcommon.h"
00024 #include "memberconfig.h"
00025 #include "memberinfo.h"
00026 #include "pluginpicker.h"
00027 #include "syncprocess.h"
00028 #include "syncprocessmanager.h"
00029 
00030 #include <libqopensync/group.h>
00031 #include <libqopensync/plugin.h>
00032 
00033 #include <kdialog.h>
00034 #include <kiconloader.h>
00035 #include <kjanuswidget.h>
00036 #include <klocale.h>
00037 #include <kmessagebox.h>
00038 
00039 
00040 #include <qlabel.h>
00041 #include <qlayout.h>
00042 #include <qpushbutton.h>
00043 
00044 GroupConfig::GroupConfig( QWidget *parent )
00045   : QWidget( parent )
00046 {
00047   QBoxLayout *topLayout = new QVBoxLayout( this );
00048   topLayout->setSpacing( KDialog::spacingHint() );
00049 
00050   QFrame *titleFrame = new QFrame( this );
00051   topLayout->addWidget( titleFrame );
00052 
00053   titleFrame->setPaletteForegroundColor( colorGroup().light() );
00054   titleFrame->setPaletteBackgroundColor( colorGroup().mid() );
00055 
00056   QBoxLayout *nameLayout = new QHBoxLayout( titleFrame );
00057   nameLayout->setMargin( 4 );
00058 
00059   QPixmap icon = KGlobal::iconLoader()->loadIcon( "kontact_summary",
00060     KIcon::Desktop );
00061 
00062   QLabel *iconLabel = new QLabel( titleFrame );
00063   iconLabel->setPixmap( icon );
00064   nameLayout->addWidget( iconLabel );
00065 
00066   nameLayout->addSpacing( 8 );
00067 
00068   QLabel *label = new QLabel( i18n("Group:"), titleFrame );
00069   QFont font = label->font();
00070   font.setBold( true );
00071   font.setPointSize( font.pointSize() + 2 );
00072   label->setFont( font );
00073   nameLayout->addWidget( label );
00074 
00075   mNameLabel = new QLabel( titleFrame );
00076   font = mNameLabel->font();
00077   font.setBold( true );
00078   font.setPointSize( font.pointSize() + 2 );
00079   mNameLabel->setFont( font );
00080   nameLayout->addWidget( mNameLabel );
00081 
00082   nameLayout->addStretch( 1 );
00083 
00084   mMemberView = new KJanusWidget( this, 0, KJanusWidget::IconList );
00085   topLayout->addWidget( mMemberView );
00086 
00087   QBoxLayout *buttonLayout = new QHBoxLayout( topLayout );
00088 
00089   QPushButton *addButton = new QPushButton( i18n("Add Member..."), this );
00090   connect( addButton, SIGNAL( clicked() ), SLOT( addMember() ) );
00091   buttonLayout->addWidget( addButton );
00092 
00093   buttonLayout->addStretch( 1 );
00094 
00095   icon = KGlobal::iconLoader()->loadIcon( "bookmark", KIcon::Desktop );
00096   QFrame *page = mMemberView->addPage( i18n("Group"),
00097     i18n("General Group Settings"), icon );
00098   QBoxLayout *pageLayout = new QVBoxLayout( page );
00099 
00100   mCommonConfig = new GroupConfigCommon( page );
00101   pageLayout->addWidget( mCommonConfig );
00102 }
00103 
00104 void GroupConfig::setSyncProcess( SyncProcess *process )
00105 {
00106   mProcess = process;
00107 
00108   mNameLabel->setText( mProcess->group().name() );
00109   mCommonConfig->setSyncProcess( mProcess );
00110 
00111   updateMembers();
00112 }
00113 
00114 void GroupConfig::updateMembers()
00115 {
00116   QValueList<MemberConfig *>::ConstIterator memberIt;
00117   for ( memberIt = mMemberConfigs.begin(); memberIt != mMemberConfigs.end(); ++memberIt )
00118     (*memberIt)->saveData();
00119 
00120   QValueList<QFrame *>::ConstIterator it2;
00121   for ( it2 = mConfigPages.begin(); it2 != mConfigPages.end(); ++it2 ) {
00122     mMemberView->removePage( *it2 );
00123     delete *it2;
00124   }
00125   mConfigPages.clear();
00126   mMemberConfigs.clear();
00127 
00128   QSync::Group group = mProcess->group();
00129   QSync::Group::Iterator it( group.begin() );
00130   for ( ; it != group.end(); ++it ) {
00131     QSync::Member member = *it;
00132     MemberInfo mi( member );
00133     QFrame *page = mMemberView->addPage( mi.name(), 
00134       QString( "%1 (%2)" ).arg( mi.name() ).arg(member.pluginName()), mi.desktopIcon() );
00135 
00136     QBoxLayout *pageLayout = new QVBoxLayout( page );
00137     mConfigPages.append( page );
00138 
00139     MemberConfig *memberConfig = new MemberConfig( page, member );
00140     mMemberConfigs.append( memberConfig );
00141     pageLayout->addWidget( memberConfig );
00142 
00143     memberConfig->loadData();
00144   }
00145 }
00146 
00147 void GroupConfig::saveConfig()
00148 {
00149   mProcess->group().save();
00150 
00151   QValueList<MemberConfig *>::ConstIterator it;
00152   for ( it = mMemberConfigs.begin(); it != mMemberConfigs.end(); ++it )
00153     (*it)->saveData();
00154 
00155   mCommonConfig->save();
00156 
00157   mProcess->reinitEngine();
00158 }
00159 
00160 void GroupConfig::addMember()
00161 {
00162   QSync::Plugin plugin = PluginPickerDialog::getPlugin( this );
00163 
00164   if ( plugin.isValid() ) {
00165     QSync::Result result = SyncProcessManager::self()->addMember( mProcess, plugin );
00166     if ( result.isError() ) {
00167       KMessageBox::error( this, i18n("Error adding member %1\n%2\nType: %3")
00168         .arg( plugin.name() ).arg( result.message() ).arg( result.type() ) );
00169     } else {
00170       updateMembers();
00171 
00172       // select last (added) page
00173       int index = mMemberView->pageIndex( mConfigPages.last() );
00174       mMemberView->showPage( index );
00175     }
00176   }
00177 }
00178 
00179 #include "groupconfig.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys