26 #include <tdeapplication.h>
28 #include <klibloader.h>
32 #include "customfieldswidget.h"
33 #include "freebusywidget.h"
34 #include "geowidget.h"
35 #include "imagewidget.h"
36 #include "soundwidget.h"
38 #include "contacteditorwidget.h"
39 #include "contacteditorwidgetmanager.h"
41 ContactEditorWidgetManager *ContactEditorWidgetManager::mSelf = 0;
43 ContactEditorWidgetManager::ContactEditorWidgetManager()
49 ContactEditorWidgetManager::~ContactEditorWidgetManager()
54 ContactEditorWidgetManager *ContactEditorWidgetManager::self()
56 kdWarning( !kapp, 7520 ) <<
"No TQApplication object available!" << endl;
59 mSelf =
new ContactEditorWidgetManager();
64 int ContactEditorWidgetManager::count()
const
66 return mFactories.count();
69 KAB::ContactEditorWidgetFactory *ContactEditorWidgetManager::factory(
int pos )
const
71 return mFactories[ pos ];
74 void ContactEditorWidgetManager::reload()
77 kdDebug(5720) <<
"ContactEditorWidgetManager::reload()" << endl;
78 const TDETrader::OfferList plugins = TDETrader::self()->query(
"KAddressBook/ContactEditorWidget",
79 TQString(
"[X-TDE-KAddressBook-CEWPluginVersion] == %1" ).arg( KAB_CEW_PLUGIN_VERSION ) );
81 TDETrader::OfferList::ConstIterator it;
82 for ( it = plugins.begin(); it != plugins.end(); ++it ) {
83 KLibFactory *factory = KLibLoader::self()->factory( (*it)->library().latin1() );
85 kdDebug(5720) <<
"ContactEditorWidgetManager::reload(): Factory creation failed" << endl;
89 KAB::ContactEditorWidgetFactory *pageFactory =
90 static_cast<KAB::ContactEditorWidgetFactory*
>( factory );
93 kdDebug(5720) <<
"ContactEditorWidgetManager::reload(): Cast failed" << endl;
97 mFactories.append( pageFactory );
101 mFactories.append(
new FreeBusyWidgetFactory );
102 mFactories.append(
new ImageWidgetFactory );
103 mFactories.append(
new SoundWidgetFactory );
104 mFactories.append(
new GeoWidgetFactory );
105 mFactories.append(
new CustomFieldsWidgetFactory );
110 ContactEditorTabPage::ContactEditorTabPage( TQWidget *parent,
const char *name )
111 : TQWidget( parent, name )
113 mLayout =
new TQGridLayout(
this, 0, 2, KDialog::marginHint(),
114 KDialog::spacingHint() );
117 void ContactEditorTabPage::addWidget( KAB::ContactEditorWidget *widget )
119 if ( widget->logicalWidth() == 2 ) {
120 mWidgets.prepend( widget );
121 connect( widget, TQ_SIGNAL( changed() ), TQ_SIGNAL( changed() ) );
126 KAB::ContactEditorWidget::List::Iterator it;
127 for ( it = mWidgets.begin(); it != mWidgets.end(); ++it ) {
128 if ( widget->logicalHeight() > (*it)->logicalHeight() &&
129 (*it)->logicalWidth() == 1 ) {
134 mWidgets.insert( ++it, widget );
136 connect( widget, TQ_SIGNAL( changed() ), TQ_SIGNAL( changed() ) );
139 void ContactEditorTabPage::loadContact( TDEABC::Addressee *addr )
141 KAB::ContactEditorWidget::List::Iterator it;
142 for ( it = mWidgets.begin(); it != mWidgets.end(); ++it ) {
143 (*it)->setModified(
false );
144 (*it)->loadContact( addr );
148 void ContactEditorTabPage::storeContact( TDEABC::Addressee *addr )
150 KAB::ContactEditorWidget::List::Iterator it;
151 for ( it = mWidgets.begin(); it != mWidgets.end(); ++it ) {
152 if ( (*it)->modified() ) {
153 (*it)->storeContact( addr );
154 (*it)->setModified(
false );
159 void ContactEditorTabPage::setReadOnly(
bool readOnly )
161 KAB::ContactEditorWidget::List::Iterator it;
162 for ( it = mWidgets.begin(); it != mWidgets.end(); ++it )
163 (*it)->setReadOnly( readOnly );
166 void ContactEditorTabPage::updateLayout()
168 KAB::ContactEditorWidget::List::ConstIterator it;
171 for ( it = mWidgets.begin(); it != mWidgets.end(); ++it ) {
172 if ( (*it)->logicalWidth() == 2 ) {
173 mLayout->addMultiCellWidget( *it, row, row + (*it)->logicalHeight() - 1, 0, 1 );
174 row += (*it)->logicalHeight();
176 if ( it != mWidgets.fromLast() ) {
177 TQFrame *frame =
new TQFrame(
this );
178 frame->setFrameStyle( TQFrame::HLine | TQFrame::Sunken );
179 mLayout->addMultiCellWidget( frame, row, row, 0, 1 );
186 int leftHeight = (*it)->logicalHeight();
188 if ( it == mWidgets.fromLast() ) {
189 mLayout->addMultiCellWidget( *it, row, row + leftHeight - 1, 0, 1 );
192 mLayout->addMultiCellWidget( *it, row, row + leftHeight - 1, 0, 0 );
193 TQFrame *frame =
new TQFrame(
this );
194 frame->setFrameStyle( TQFrame::HLine | TQFrame::Sunken );
195 mLayout->addMultiCellWidget( frame, row + leftHeight, row + leftHeight, 0, 1 );
199 for (
int i = 0; i < leftHeight; ++i ) {
201 if ( it == mWidgets.end() )
204 int rightHeight = (*it)->logicalHeight();
205 if ( rightHeight + i <= leftHeight )
206 mLayout->addMultiCellWidget( *it, row + i, row + i + rightHeight - 1, 1, 1 );
217 #include "contacteditorwidgetmanager.moc"