kitchensync Library API Documentation

viewer.cpp

00001 /* 00002 This file is part of KitchenSync. 00003 00004 Copyright (c) 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., 59 Temple Place - Suite 330, 00019 Boston, MA 02111-1307, USA. 00020 */ 00021 00022 #include "viewer.h" 00023 00024 #include <core.h> 00025 #include <engine.h> 00026 #include <konnector.h> 00027 00028 #include <kaboutdata.h> 00029 #include <kdialog.h> 00030 #include <kdialogbase.h> 00031 #include <kiconloader.h> 00032 #include <kmessagebox.h> 00033 #include <kparts/genericfactory.h> 00034 #include <kprocess.h> 00035 #include <kstandarddirs.h> 00036 00037 #include <qlabel.h> 00038 #include <qlayout.h> 00039 #include <qpushbutton.h> 00040 00041 using namespace KSync; 00042 00043 typedef KParts::GenericFactory<Viewer> ViewerFactory; 00044 K_EXPORT_COMPONENT_FACTORY( libksync_viewer, ViewerFactory ) 00045 00046 Viewer::Viewer( QWidget *parent, const char *name, QObject *, const char *, 00047 const QStringList & ) 00048 : ActionPart( parent, name ), mTopWidget( 0 ) 00049 { 00050 mPixmap = KGlobal::iconLoader()->loadIcon( "xmag", KIcon::Desktop, 48 ); 00051 } 00052 00053 KAboutData *Viewer::createAboutData() 00054 { 00055 return new KAboutData( "KSyncViewer", I18N_NOOP( "Sync Viewer Part" ), "0.0" ); 00056 } 00057 00058 Viewer::~Viewer() 00059 { 00060 delete mTopWidget; 00061 } 00062 00063 QString Viewer::type() const 00064 { 00065 return QString::fromLatin1( "viewer" ); 00066 } 00067 00068 QString Viewer::title() const 00069 { 00070 return i18n( "Data Viewer" ); 00071 } 00072 00073 QString Viewer::description() const 00074 { 00075 return i18n( "Viewer for data handled by KitchenSync." ); 00076 } 00077 00078 QPixmap *Viewer::pixmap() 00079 { 00080 return &mPixmap; 00081 } 00082 00083 QString Viewer::iconName() const 00084 { 00085 return QString::fromLatin1( "xmag" ); 00086 } 00087 00088 bool Viewer::hasGui() const 00089 { 00090 return true; 00091 } 00092 00093 QWidget *Viewer::widget() 00094 { 00095 if ( !mTopWidget ) { 00096 mTopWidget = new QWidget; 00097 QBoxLayout *topLayout = new QVBoxLayout( mTopWidget ); 00098 topLayout->setSpacing( KDialog::spacingHint() ); 00099 00100 mListView = new KListView( mTopWidget ); 00101 mListView->setRootIsDecorated( true ); 00102 mListView->addColumn( i18n( "Konnector Data" ) ); 00103 mListView->setAllColumnsShowFocus( true ); 00104 mListView->setFullWidth( true ); 00105 topLayout->addWidget( mListView ); 00106 00107 QBoxLayout *buttonLayout = new QHBoxLayout( topLayout ); 00108 QPushButton *button = new QPushButton( i18n( "Expand All" ), mTopWidget ); 00109 connect( button, SIGNAL( clicked() ), SLOT( expandAll() ) ); 00110 buttonLayout->addWidget( button ); 00111 00112 button = new QPushButton( i18n( "Collapse All" ), mTopWidget ); 00113 connect( button, SIGNAL( clicked() ), SLOT( collapseAll() ) ); 00114 buttonLayout->addWidget( button ); 00115 00116 buttonLayout->addStretch( 1 ); 00117 } 00118 00119 return mTopWidget; 00120 } 00121 00122 void Viewer::expandAll() 00123 { 00124 QListViewItemIterator it( mListView ); 00125 while ( it.current() ) { 00126 if ( it.current()->childCount() > 0 ) it.current()->setOpen( true ); 00127 ++it; 00128 } 00129 } 00130 00131 void Viewer::collapseAll() 00132 { 00133 QListViewItemIterator it( mListView ); 00134 while ( it.current() ) { 00135 if ( it.current()->childCount() > 0 ) it.current()->setOpen( false ); 00136 ++it; 00137 } 00138 } 00139 00140 void Viewer::executeAction() 00141 { 00142 mListView->clear(); 00143 00144 Konnector::List konnectors = core()->engine()->konnectors(); 00145 Konnector *k; 00146 for ( k = konnectors.first(); k; k = konnectors.next() ) { 00147 QListViewItem *topItem = new QListViewItem( mListView, k->resourceName() ); 00148 SynceeList syncees = k->syncees(); 00149 SynceeList::ConstIterator it2; 00150 for ( it2 = syncees.begin(); it2 != syncees.end(); ++it2 ) { 00151 Syncee *s = *it2; 00152 if ( !s->isValid() ) continue; 00153 00154 QListViewItem *synceeItem = new QListViewItem( topItem, 00155 s->identifier() ); 00156 SyncEntry *entry; 00157 for ( entry = s->firstEntry(); entry; entry = s->nextEntry() ) { 00158 new QListViewItem( synceeItem, entry->name() ); 00159 } 00160 } 00161 } 00162 00163 expandAll(); 00164 } 00165 00166 #include "viewer.moc"
KDE Logo
This file is part of the documentation for kitchensync Library Version 3.3.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Thu Oct 21 19:46:33 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003