29 #include <dcopclient.h>
30 #include <tdeaction.h>
31 #include <tdeapplication.h>
32 #include <tdeconfig.h>
33 #include <kdcopservicestarter.h>
36 #include <tdelocale.h>
37 #include <tdemessagebox.h>
40 #include <kstandarddirs.h>
41 #include <tqscrollview.h>
42 #include <tdeglobal.h>
43 #include <tdelocale.h>
44 #include <kcmultidialog.h>
46 #include <tdeparts/componentfactory.h>
47 #include <tdeparts/event.h>
49 #include <libkpimidentities/identity.h>
50 #include <libkpimidentities/identitymanager.h>
52 #include <infoextension.h>
53 #include <sidebarextension.h>
58 #include "summaryview_part.h"
60 #include "broadcaststatus.h"
61 using KPIM::BroadcastStatus;
68 SummaryViewPart::SummaryViewPart(
Kontact::Core *core,
const char*,
69 const TDEAboutData *aboutData,
70 TQObject *parent,
const char *name )
71 : KParts::ReadOnlyPart( parent, name ),
72 mCore( core ), mFrame( 0 ), mConfigAction( 0 )
74 setInstance(
new TDEInstance( aboutData ) );
80 connect( kapp, TQ_SIGNAL( tdedisplayPaletteChanged() ), TQ_SLOT( slotAdjustPalette() ) );
83 setDate( TQDate::currentDate() );
84 connect( mCore, TQ_SIGNAL( dayChanged(
const TQDate& ) ),
85 TQ_SLOT( setDate(
const TQDate& ) ) );
87 KParts::InfoExtension *info =
new KParts::InfoExtension(
this,
"Summary" );
88 connect(
this, TQ_SIGNAL( textChanged(
const TQString& ) ),
89 info, TQ_SIGNAL( textChanged(
const TQString& ) ) );
91 mConfigAction =
new TDEAction( i18n(
"&Configure Summary View..." ),
93 TQ_SLOT( slotConfigure() ), actionCollection(),
94 "summaryview_configure" );
96 setXMLFile(
"kontactsummary_part.rc" );
98 TQTimer::singleShot( 0,
this, TQ_SLOT( slotTextChanged() ) );
101 SummaryViewPart::~SummaryViewPart()
106 bool SummaryViewPart::openFile()
108 kdDebug(5006) <<
"SummaryViewPart:openFile()" << endl;
112 void SummaryViewPart::partActivateEvent( KParts::PartActivateEvent *event )
116 if ( event->activated() && ( event->part() ==
this ) ) {
120 KParts::ReadOnlyPart::partActivateEvent( event );
123 void SummaryViewPart::updateSummaries()
125 TQMap<TQString, Kontact::Summary*>::Iterator it;
126 for ( it = mSummaries.begin(); it != mSummaries.end(); ++it )
127 it.data()->updateSummary(
false );
130 void SummaryViewPart::updateWidgets()
132 mMainWidget->setUpdatesEnabled(
false );
136 KPIM::IdentityManager idm(
true,
this );
137 const KPIM::Identity &
id = idm.defaultIdentity();
139 TQString currentUser = i18n(
"Summary for %1" ).arg(
id.fullName() );
140 mUsernameLabel->setText( TQString::fromLatin1(
"<b>%1</b>" ).arg( currentUser ) );
144 mFrame =
new DropWidget( mMainWidget );
145 connect( mFrame, TQ_SIGNAL( summaryWidgetDropped( TQWidget*, TQWidget*,
int ) ),
146 this, TQ_SLOT( summaryWidgetMoved( TQWidget*, TQWidget*,
int ) ) );
148 mMainLayout->insertWidget( 2, mFrame );
150 TQStringList activeSummaries;
152 TDEConfig config(
"kontact_summaryrc" );
153 if ( !config.hasKey(
"ActiveSummaries" ) ) {
154 activeSummaries <<
"kontact_kmailplugin";
155 activeSummaries <<
"kontact_specialdatesplugin";
156 activeSummaries <<
"kontact_korganizerplugin";
157 activeSummaries <<
"kontact_todoplugin";
158 activeSummaries <<
"kontact_newstickerplugin";
160 activeSummaries = config.readListEntry(
"ActiveSummaries" );
164 TQStringList loadedSummaries;
166 TQValueList<Kontact::Plugin*> plugins = mCore->pluginList();
167 TQValueList<Kontact::Plugin*>::ConstIterator end = plugins.end();
168 TQValueList<Kontact::Plugin*>::ConstIterator it = plugins.begin();
169 for ( ; it != end; ++it ) {
171 if ( activeSummaries.find( plugin->
identifier() ) == activeSummaries.end() )
177 mSummaries.insert( plugin->
identifier(), summary );
179 connect( summary, TQ_SIGNAL( message(
const TQString& ) ),
180 BroadcastStatus::instance(), TQ_SLOT( setStatusMsg(
const TQString& ) ) );
181 connect( summary, TQ_SIGNAL( summaryWidgetDropped( TQWidget*, TQWidget*,
int ) ),
182 this, TQ_SLOT( summaryWidgetMoved( TQWidget*, TQWidget*,
int ) ) );
184 if ( !mLeftColumnSummaries.contains( plugin->
identifier() ) &&
185 !mRightColumnSummaries.contains( plugin->
identifier() ) ) {
186 mLeftColumnSummaries.append( plugin->
identifier() );
189 loadedSummaries.append( plugin->
identifier() );
198 TQStringList::Iterator strIt;
199 for ( strIt = mLeftColumnSummaries.begin(); strIt != mLeftColumnSummaries.end(); ++strIt ) {
200 if ( loadedSummaries.find( *strIt ) == loadedSummaries.end() ) {
201 strIt = mLeftColumnSummaries.remove( strIt );
205 for ( strIt = mRightColumnSummaries.begin(); strIt != mRightColumnSummaries.end(); ++strIt ) {
206 if ( loadedSummaries.find( *strIt ) == loadedSummaries.end() ) {
207 strIt = mRightColumnSummaries.remove( strIt );
214 TQFrame *vline =
new TQFrame( mFrame );
215 vline->setFrameStyle( TQFrame::VLine | TQFrame::Plain );
217 TQHBoxLayout *layout =
new TQHBoxLayout( mFrame );
219 mLeftColumn =
new TQVBoxLayout( layout, KDialog::spacingHint() );
220 layout->addWidget( vline );
221 mRightColumn =
new TQVBoxLayout( layout, KDialog::spacingHint() );
224 TQStringList::Iterator strIt;
225 for ( strIt = mLeftColumnSummaries.begin(); strIt != mLeftColumnSummaries.end(); ++strIt ) {
226 if ( mSummaries.find( *strIt ) != mSummaries.end() )
227 mLeftColumn->addWidget( mSummaries[ *strIt ] );
230 for ( strIt = mRightColumnSummaries.begin(); strIt != mRightColumnSummaries.end(); ++strIt ) {
231 if ( mSummaries.find( *strIt ) != mSummaries.end() )
232 mRightColumn->addWidget( mSummaries[ *strIt ] );
237 mMainWidget->setUpdatesEnabled(
true );
238 mMainWidget->update();
240 mLeftColumn->addStretch();
241 mRightColumn->addStretch();
244 void SummaryViewPart::summaryWidgetMoved( TQWidget *target, TQWidget *widget,
int alignment )
246 if ( target == widget )
249 if ( target == mFrame ) {
250 if ( mLeftColumn->findWidget( widget ) == -1 && mRightColumn->findWidget( widget ) == -1 )
253 if ( mLeftColumn->findWidget( target ) == -1 && mRightColumn->findWidget( target ) == -1 ||
254 mLeftColumn->findWidget( widget ) == -1 && mRightColumn->findWidget( widget ) == -1 )
258 if ( mLeftColumn->findWidget( widget ) != -1 ) {
259 mLeftColumn->remove( widget );
260 mLeftColumnSummaries.remove( widgetName( widget ) );
261 }
else if ( mRightColumn->findWidget( widget ) != -1 ) {
262 mRightColumn->remove( widget );
263 mRightColumnSummaries.remove( widgetName( widget ) );
266 if ( target == mFrame ) {
269 if ( alignment & TQt::AlignTop )
272 if ( alignment & TQt::AlignLeft ) {
273 if ( alignment & TQt::AlignBottom )
274 pos = mLeftColumnSummaries.count();
276 mLeftColumn->insertWidget( pos, widget );
277 mLeftColumnSummaries.insert( mLeftColumnSummaries.at( pos ), widgetName( widget ) );
279 if ( alignment & TQt::AlignBottom )
280 pos = mRightColumnSummaries.count();
282 mRightColumn->insertWidget( pos, widget );
283 mRightColumnSummaries.insert( mRightColumnSummaries.at( pos ), widgetName( widget ) );
289 int targetPos = mLeftColumn->findWidget( target );
290 if ( targetPos != -1 ) {
291 if ( alignment == TQt::AlignBottom )
294 mLeftColumn->insertWidget( targetPos, widget );
295 mLeftColumnSummaries.insert( mLeftColumnSummaries.at( targetPos ), widgetName( widget ) );
297 targetPos = mRightColumn->findWidget( target );
299 if ( alignment == TQt::AlignBottom )
302 mRightColumn->insertWidget( targetPos, widget );
303 mRightColumnSummaries.insert( mRightColumnSummaries.at( targetPos ), widgetName( widget ) );
307 void SummaryViewPart::slotTextChanged()
309 emit textChanged( i18n(
"What's next?" ) );
312 void SummaryViewPart::slotAdjustPalette()
314 mMainWidget->setPaletteBackgroundColor( kapp->palette().active().base() );
317 void SummaryViewPart::setDate(
const TQDate& newDate )
319 TQString date(
"<b>%1</b>" );
320 date = date.arg( TDEGlobal::locale()->formatDate( newDate ) );
321 mDateLabel->setText( date );
324 void SummaryViewPart::slotConfigure()
326 KCMultiDialog dlg( mMainWidget,
"ConfigDialog",
true );
328 TQStringList modules = configModules();
329 modules.prepend(
"kcmkontactsummary.desktop" );
330 connect( &dlg, TQ_SIGNAL( configCommitted() ),
331 this, TQ_SLOT( updateWidgets() ) );
333 TQStringList::ConstIterator strIt;
334 for ( strIt = modules.begin(); strIt != modules.end(); ++strIt )
335 dlg.addModule( *strIt );
340 TQStringList SummaryViewPart::configModules()
const
342 TQStringList modules;
344 TQMap<TQString, Kontact::Summary*>::ConstIterator it;
345 for ( it = mSummaries.begin(); it != mSummaries.end(); ++it ) {
346 TQStringList cm = it.data()->configModules();
347 TQStringList::ConstIterator strIt;
348 for ( strIt = cm.begin(); strIt != cm.end(); ++strIt )
349 if ( !(*strIt).isEmpty() && !modules.contains( *strIt ) )
350 modules.append( *strIt );
358 TQScrollView *sv =
new TQScrollView( core );
360 sv->setResizePolicy( TQScrollView::AutoOneFit );
361 sv->setFrameStyle( TQFrame::NoFrame | TQFrame::Plain );
362 sv->setHScrollBarMode( TQScrollView::AlwaysOff );
364 mMainWidget =
new TQFrame( sv->viewport() );
365 sv->addChild( mMainWidget );
366 mMainWidget->setFrameStyle( TQFrame::Panel | TQFrame::Sunken );
367 sv->setFocusPolicy( TQWidget::StrongFocus );
370 mMainLayout =
new TQVBoxLayout( mMainWidget,KDialog::marginHint(),
371 KDialog::spacingHint() );
373 TQHBoxLayout *hbl =
new TQHBoxLayout( mMainLayout );
374 mUsernameLabel =
new TQLabel( mMainWidget );
375 hbl->addWidget( mUsernameLabel );
376 mDateLabel =
new TQLabel( mMainWidget );
377 mDateLabel->setAlignment( AlignRight );
378 hbl->addWidget( mDateLabel );
380 TQFrame *hline =
new TQFrame( mMainWidget );
381 hline->setFrameStyle( TQFrame::HLine | TQFrame::Plain );
382 mMainLayout->insertWidget( 1, hline );
384 mFrame =
new DropWidget( mMainWidget );
385 mMainLayout->insertWidget( 2, mFrame );
387 connect( mFrame, TQ_SIGNAL( summaryWidgetDropped( TQWidget*, TQWidget*,
int ) ),
388 this, TQ_SLOT( summaryWidgetMoved( TQWidget*, TQWidget*,
int ) ) );
393 void SummaryViewPart::loadLayout()
395 TDEConfig config(
"kontact_summaryrc" );
397 if ( !config.hasKey(
"LeftColumnSummaries" ) ) {
398 mLeftColumnSummaries <<
"kontact_korganizerplugin";
399 mLeftColumnSummaries <<
"kontact_todoplugin";
400 mLeftColumnSummaries <<
"kontact_kaddressbookplugin";
401 mLeftColumnSummaries <<
"kontact_specialdatesplugin";
403 mLeftColumnSummaries = config.readListEntry(
"LeftColumnSummaries" );
406 if ( !config.hasKey(
"RightColumnSummaries" ) ) {
407 mRightColumnSummaries <<
"kontact_newstickerplugin";
409 mRightColumnSummaries = config.readListEntry(
"RightColumnSummaries" );
413 void SummaryViewPart::saveLayout()
415 TDEConfig config(
"kontact_summaryrc" );
417 config.writeEntry(
"LeftColumnSummaries", mLeftColumnSummaries );
418 config.writeEntry(
"RightColumnSummaries", mRightColumnSummaries );
423 TQString SummaryViewPart::widgetName( TQWidget *widget )
const
425 TQMap<TQString, Kontact::Summary*>::ConstIterator it;
426 for ( it = mSummaries.begin(); it != mSummaries.end(); ++it ) {
427 if ( it.data() == widget )
434 #include "summaryview_part.moc"
This class provides the interface to the Kontact core for the plugins.
Base class for all Plugins in Kontact.
virtual Summary * createSummaryWidget(TQWidget *)
Reimplement this method if you want to add a widget for your application to Kontact's summary page.
TQString identifier() const
Returns the identifier.
Summary widget for display in the Summary View plugin.
virtual int summaryHeight() const
Return logical height of summary widget.