kitchensync
konnectorview.cpp00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
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"
|