kitchensync

konnectorview.cpp

00001 /*
00002     This file is part of KitchenSync.
00003 
00004     Copyright (c) 2003,2004 Cornelius Schumacher <schumacher@kde.org>
00005 
00006     This library is free software; you can redistribute it and/or
00007     modify it under the terms of the GNU Library General Public
00008     License as published by the Free Software Foundation; either
00009     version 2 of the License, or (at your option) any later version.
00010 
00011     This library 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 GNU
00014     Library General Public License for more details.
00015 
00016     You should have received a copy of the GNU Library General Public License
00017     along with this library; see the file COPYING.LIB.  If not, write to
00018     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00019     Boston, MA 02110-1301, USA.
00020 */
00021 
00022 #include <kdebug.h>
00023 
00024 #include <klocale.h>
00025 #include <konnector.h>
00026 #include <konnectorinfo.h>
00027 #include <konnectormanager.h>
00028 
00029 
00030 
00031 #include <qlayout.h>
00032 #include <qlistview.h>
00033 
00034 #include "konnectorview.h"
00035 
00036 using namespace KSync;
00037 
00038 class KonnectorCheckItem : public QCheckListItem
00039 {
00040   public:
00041     KonnectorCheckItem( Konnector *konnector, QListView *view )
00042       : QCheckListItem( view, konnector->resourceName(), CheckBox ),
00043         mKonnector( konnector )
00044     {
00045     }
00046 
00047     Konnector *konnector() const { return mKonnector; }
00048 
00049   private:
00050     Konnector *mKonnector;
00051 };
00052 
00053 
00054 KonnectorView::KonnectorView( QWidget *parent, const char *name )
00055   : QWidget( parent, name )
00056 {
00057   QBoxLayout *topLayout = new QVBoxLayout( this );
00058 
00059   mKonnectorList = new KListView( this );
00060   mKonnectorList->addColumn( i18n( "Konnector" ) );
00061   mKonnectorList->setAllColumnsShowFocus( true );
00062   mKonnectorList->setFullWidth( true );
00063 
00064   topLayout->addWidget( mKonnectorList, 1 );
00065 
00066   updateKonnectorList();
00067 }
00068 
00069 void KonnectorView::updateKonnectorList()
00070 {
00071   mKonnectorList->clear();
00072 
00073   KRES::Manager<Konnector> *manager = KonnectorManager::self();
00074 
00075   KRES::Manager<Konnector>::ActiveIterator it;
00076   for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) {
00077     KonnectorCheckItem *item = new KonnectorCheckItem( *it, mKonnectorList );
00078     item->setOn( true );
00079   }
00080 }
00081 
00082 Konnector::List KonnectorView::selectedKonnectors()
00083 {
00084   Konnector::List result;
00085 
00086   QListViewItemIterator it( mKonnectorList );
00087   while ( it.current() ) {
00088     KonnectorCheckItem *item = static_cast<KonnectorCheckItem *>( it.current() );
00089     if ( item->isOn() ) {
00090       result.append( item->konnector() );
00091     }
00092     ++it;
00093   }
00094 
00095   return result;
00096 }
00097 
00098 
00111 void KonnectorView::setSelectedKonnectors( const QStringList& lst)
00112 {
00113   QListViewItemIterator it( mKonnectorList );
00114   while ( it.current() ) {
00115     KonnectorCheckItem *item = static_cast<KonnectorCheckItem *>( it.current() );
00116     kdDebug() << "Items " << lst << " " << item->konnector()->identifier() << endl;
00117     item->setOn( lst.contains( item->konnector()->identifier() ) );
00118     ++it;
00119   }
00120 }
00121 
00132 QStringList KonnectorView::selectedKonnectorsList()const
00133 {
00134   QStringList lst;
00135 
00136 
00137   QListViewItemIterator it( mKonnectorList );
00138   while ( it.current() ) {
00139     KonnectorCheckItem *item = static_cast<KonnectorCheckItem *>( it.current() );
00140     if ( item->isOn() )
00141       lst.append( item->konnector()->identifier() );
00142     ++it;
00143   }
00144 
00145   return lst;
00146 }
00147 
00148 #include "konnectorview.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys