contacteditorwidgetmanager.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include <qlayout.h>
00025
00026 #include <kapplication.h>
00027 #include <kdialog.h>
00028 #include <klibloader.h>
00029 #include <ktrader.h>
00030
00031
00032 #include "customfieldswidget.h"
00033 #include "freebusywidget.h"
00034 #include "geowidget.h"
00035 #include "imagewidget.h"
00036 #include "soundwidget.h"
00037
00038 #include "contacteditorwidget.h"
00039 #include "contacteditorwidgetmanager.h"
00040
00041 ContactEditorWidgetManager *ContactEditorWidgetManager::mSelf = 0;
00042
00043 ContactEditorWidgetManager::ContactEditorWidgetManager()
00044 : QObject( qApp )
00045 {
00046 reload();
00047 }
00048
00049 ContactEditorWidgetManager::~ContactEditorWidgetManager()
00050 {
00051 mFactories.clear();
00052 }
00053
00054 ContactEditorWidgetManager *ContactEditorWidgetManager::self()
00055 {
00056 kdWarning( !kapp, 7520 ) << "No QApplication object available!" << endl;
00057
00058 if ( !mSelf )
00059 mSelf = new ContactEditorWidgetManager();
00060
00061 return mSelf;
00062 }
00063
00064 int ContactEditorWidgetManager::count() const
00065 {
00066 return mFactories.count();
00067 }
00068
00069 KAB::ContactEditorWidgetFactory *ContactEditorWidgetManager::factory( int pos ) const
00070 {
00071 return mFactories[ pos ];
00072 }
00073
00074 void ContactEditorWidgetManager::reload()
00075 {
00076 mFactories.clear();
00077 kdDebug(5720) << "ContactEditorWidgetManager::reload()" << endl;
00078 KTrader::OfferList plugins = KTrader::self()->query( "KAddressBook/ContactEditorWidget" );
00079 KTrader::OfferList::ConstIterator it;
00080
00081 for ( it = plugins.begin(); it != plugins.end(); ++it ) {
00082 KLibFactory *factory = KLibLoader::self()->factory( (*it)->library().latin1() );
00083 if ( !factory ) {
00084 kdDebug(5720) << "ContactEditorWidgetManager::reload(): Factory creation failed" << endl;
00085 continue;
00086 }
00087
00088 KAB::ContactEditorWidgetFactory *pageFactory =
00089 static_cast<KAB::ContactEditorWidgetFactory*>( factory );
00090
00091 if ( !pageFactory ) {
00092 kdDebug(5720) << "ContactEditorWidgetManager::reload(): Cast failed" << endl;
00093 continue;
00094 }
00095
00096 mFactories.append( pageFactory );
00097 }
00098
00099
00100 mFactories.append( new FreeBusyWidgetFactory );
00101 mFactories.append( new ImageWidgetFactory );
00102 mFactories.append( new SoundWidgetFactory );
00103 mFactories.append( new GeoWidgetFactory );
00104 mFactories.append( new CustomFieldsWidgetFactory );
00105 }
00106
00108
00109 ContactEditorTabPage::ContactEditorTabPage( QWidget *parent, const char *name )
00110 : QWidget( parent, name )
00111 {
00112 mLayout = new QGridLayout( this, 0, 2, KDialog::marginHint(),
00113 KDialog::spacingHint() );
00114 }
00115
00116 void ContactEditorTabPage::addWidget( KAB::ContactEditorWidget *widget )
00117 {
00118 if ( widget->logicalWidth() == 2 ) {
00119 mWidgets.prepend( widget );
00120 connect( widget, SIGNAL( changed() ), SIGNAL( changed() ) );
00121 return;
00122 }
00123
00124
00125 KAB::ContactEditorWidget::List::Iterator it;
00126 for ( it = mWidgets.begin(); it != mWidgets.end(); ++it ) {
00127 if ( widget->logicalHeight() > (*it)->logicalHeight() &&
00128 (*it)->logicalWidth() == 1 ) {
00129 --it;
00130 break;
00131 }
00132 }
00133 mWidgets.insert( ++it, widget );
00134
00135 connect( widget, SIGNAL( changed() ), SIGNAL( changed() ) );
00136 }
00137
00138 void ContactEditorTabPage::loadContact( KABC::Addressee *addr )
00139 {
00140 KAB::ContactEditorWidget::List::Iterator it;
00141 for ( it = mWidgets.begin(); it != mWidgets.end(); ++it ) {
00142 (*it)->setModified( false );
00143 (*it)->loadContact( addr );
00144 }
00145 }
00146
00147 void ContactEditorTabPage::storeContact( KABC::Addressee *addr )
00148 {
00149 KAB::ContactEditorWidget::List::Iterator it;
00150 for ( it = mWidgets.begin(); it != mWidgets.end(); ++it ) {
00151 if ( (*it)->modified() ) {
00152 (*it)->storeContact( addr );
00153 (*it)->setModified( false );
00154 }
00155 }
00156 }
00157
00158 void ContactEditorTabPage::setReadOnly( bool readOnly )
00159 {
00160 KAB::ContactEditorWidget::List::Iterator it;
00161 for ( it = mWidgets.begin(); it != mWidgets.end(); ++it )
00162 (*it)->setReadOnly( readOnly );
00163 }
00164
00165 void ContactEditorTabPage::updateLayout()
00166 {
00167 KAB::ContactEditorWidget::List::Iterator it;
00168
00169 int row = 0;
00170 for ( it = mWidgets.begin(); it != mWidgets.end(); ++it ) {
00171 if ( (*it)->logicalWidth() == 2 ) {
00172 mLayout->addMultiCellWidget( *it, row, row + (*it)->logicalHeight() - 1, 0, 1 );
00173 row += (*it)->logicalHeight();
00174
00175 if ( it != mWidgets.fromLast() ) {
00176 QFrame *frame = new QFrame( this );
00177 frame->setFrameStyle( QFrame::HLine | QFrame::Sunken );
00178 mLayout->addMultiCellWidget( frame, row, row, 0, 1 );
00179 row++;
00180 }
00181 continue;
00182 }
00183
00184
00185 int leftHeight = (*it)->logicalHeight();
00186
00187 if ( it == mWidgets.fromLast() ) {
00188 mLayout->addMultiCellWidget( *it, row, row + leftHeight - 1, 0, 1 );
00189 return;
00190 } else {
00191 mLayout->addMultiCellWidget( *it, row, row + leftHeight - 1, 0, 0 );
00192 QFrame *frame = new QFrame( this );
00193 frame->setFrameStyle( QFrame::HLine | QFrame::Sunken );
00194 mLayout->addMultiCellWidget( frame, row + leftHeight, row + leftHeight, 0, 1 );
00195 }
00196
00197
00198 for ( int i = 0; i < leftHeight; ++i ) {
00199 ++it;
00200 if ( it == mWidgets.end() )
00201 break;
00202
00203 int rightHeight = (*it)->logicalHeight();
00204 if ( rightHeight + i <= leftHeight )
00205 mLayout->addMultiCellWidget( *it, row + i, row + i + rightHeight - 1, 1, 1 );
00206 else {
00207 --i;
00208 break;
00209 }
00210 }
00211
00212 row += 2;
00213 }
00214 }
00215
00216 #include "contacteditorwidgetmanager.moc"
This file is part of the documentation for kaddressbook Library Version 3.3.2.