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