• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • kdepim
  • Sitemap
  • Contact Us
 

kontact

summaryview_part.cpp

Go to the documentation of this file.
00001 /*
00002   This file is part of KDE Kontact.
00003 
00004   Copyright (C) 2003 Sven Lüppken <sven@kde.org>
00005   Copyright (C) 2003 Tobias König <tokoe@kde.org>
00006   Copyright (C) 2003 Daniel Molkentin <molkentin@kde.org>
00007   Copyright (C) 2008 Allen Winter <winter@kde.org>
00008 
00009   This library is free software; you can redistribute it and/or
00010   modify it under the terms of the GNU Library General Public
00011   License as published by the Free Software Foundation; either
00012   version 2 of the License, or (at your option) any later version.
00013 
00014   This library is distributed in the hope that it will be useful,
00015   but WITHOUT ANY WARRANTY; without even the implied warranty of
00016   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017   Library General Public License for more details.
00018 
00019   You should have received a copy of the GNU Library General Public License
00020   along with this library; see the file COPYING.LIB.  If not, write to
00021   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00022    Boston, MA 02110-1301, USA.
00023 */
00024 
00025 #include "summaryview_part.h"
00026 
00027 #include <kontactinterfaces/summary.h>
00028 #include <kontactinterfaces/plugin.h>
00029 #include <libkdepim/broadcaststatus.h>
00030 using KPIM::BroadcastStatus;
00031 
00032 #include <kpimidentities/identity.h>
00033 #include <kpimidentities/identitymanager.h>
00034 
00035 #include <kaction.h>
00036 #include <kactioncollection.h>
00037 #include <kconfig.h>
00038 #include <kdbusservicestarter.h>
00039 #include <kdialog.h>
00040 #include <kcomponentdata.h>
00041 #include <kglobal.h>
00042 #include <kglobalsettings.h>
00043 #include <kicon.h>
00044 #include <klocale.h>
00045 #include <kmessagebox.h>
00046 #include <kservice.h>
00047 #include <kstandarddirs.h>
00048 #include <kcmultidialog.h>
00049 #include <kparts/componentfactory.h>
00050 #include <kparts/event.h>
00051 
00052 #include <QApplication>
00053 #include <QHBoxLayout>
00054 #include <QLabel>
00055 #include <QLayout>
00056 #include <QScrollArea>
00057 #include <QSpacerItem>
00058 #include <QTimer>
00059 #include <QVBoxLayout>
00060 
00061 namespace Kontact
00062 {
00063   class MainWindow;
00064 }
00065 
00066 SummaryViewPart::SummaryViewPart( Kontact::Core *core, const char *,
00067                                   const KAboutData *aboutData, QObject *parent )
00068   : KParts::ReadOnlyPart( parent ), mCore( core ), mFrame( 0 ), mConfigAction( 0 )
00069 {
00070   setComponentData( KComponentData( aboutData ) );
00071 
00072   loadLayout();
00073 
00074   initGUI( core );
00075 
00076   connect( KGlobalSettings::self(), SIGNAL(kdisplayPaletteChanged()), SLOT(slotAdjustPalette()) );
00077   slotAdjustPalette();
00078 
00079   setDate( QDate::currentDate() );
00080   connect( mCore, SIGNAL(dayChanged(const QDate&)),
00081            SLOT(setDate(const QDate&)) );
00082 
00083   mConfigAction = new KAction( KIcon( "configure" ), i18n( "&Configure Summary View..." ), this );
00084   actionCollection()->addAction( "summaryview_configure", mConfigAction );
00085   connect( mConfigAction, SIGNAL(triggered(bool)), SLOT(slotConfigure()) );
00086 
00087   setXMLFile( "kontactsummary_part.rc" );
00088 
00089   QTimer::singleShot( 0, this, SLOT(slotTextChanged()) );
00090 }
00091 
00092 SummaryViewPart::~SummaryViewPart()
00093 {
00094   saveLayout();
00095 }
00096 
00097 bool SummaryViewPart::openFile()
00098 {
00099   return true;
00100 }
00101 
00102 void SummaryViewPart::partActivateEvent( KParts::PartActivateEvent *event )
00103 {
00104   // inform the plugins that the part has been activated so that they can
00105   // update the displayed information
00106   if ( event->activated() && ( event->part() == this ) ) {
00107     updateSummaries();
00108   }
00109 
00110   KParts::ReadOnlyPart::partActivateEvent( event );
00111 }
00112 
00113 void SummaryViewPart::updateSummaries()
00114 {
00115   QMap<QString, Kontact::Summary*>::Iterator it;
00116   for ( it = mSummaries.begin(); it != mSummaries.end(); ++it ) {
00117     it.value()->updateSummary( false );
00118   }
00119 }
00120 
00121 void SummaryViewPart::updateWidgets()
00122 {
00123   mMainWidget->setUpdatesEnabled( false );
00124 
00125   delete mFrame;
00126 
00127   KPIMIdentities::IdentityManager idm( true, this );
00128   const KPIMIdentities::Identity &id = idm.defaultIdentity();
00129 
00130   QString currentUser = i18n( "Summary for %1", id.fullName() );
00131   mUsernameLabel->setText( QString::fromLatin1( "<b>%1</b>" ).arg( currentUser ) );
00132 
00133   mSummaries.clear();
00134 
00135   mFrame = new DropWidget( mMainWidget );
00136   connect( mFrame, SIGNAL(summaryWidgetDropped(QWidget*,QWidget*,int) ),
00137            this, SLOT(summaryWidgetMoved(QWidget*,QWidget*,int)) );
00138 
00139   mMainLayout->insertWidget( 2, mFrame );
00140 
00141   QStringList activeSummaries;
00142 
00143   KConfig config( "kontact_summaryrc" );
00144   KConfigGroup grp( &config, QString() );
00145   if ( !grp.hasKey( "ActiveSummaries" ) ) {
00146     activeSummaries << "kontact_korganizerplugin";
00147     activeSummaries << "kontact_todoplugin";
00148     activeSummaries << "kontact_specialdatesplugin";
00149     activeSummaries << "kontact_kmailplugin";
00150     activeSummaries << "kontact_knotesplugin";
00151   } else {
00152     activeSummaries = grp.readEntry( "ActiveSummaries", QStringList() );
00153   }
00154 
00155   // Collect all summary widgets with a summaryHeight > 0
00156   QStringList loadedSummaries;
00157 
00158   QList<Kontact::Plugin*> plugins = mCore->pluginList();
00159   QList<Kontact::Plugin*>::ConstIterator end = plugins.end();
00160   QList<Kontact::Plugin*>::ConstIterator it = plugins.begin();
00161   for ( ; it != end; ++it ) {
00162     Kontact::Plugin *plugin = *it;
00163     if ( !activeSummaries.contains( plugin->identifier() ) ) {
00164       continue;
00165     }
00166 
00167     Kontact::Summary *summary = plugin->createSummaryWidget( mFrame );
00168     if ( summary ) {
00169       if ( summary->summaryHeight() > 0 ) {
00170         summary->layout()->setAlignment( Qt::AlignLeft | Qt::AlignTop );
00171         summary->layout()->setContentsMargins( 3, 3, 3, 3 );
00172         mSummaries.insert( plugin->identifier(), summary );
00173 
00174         connect( summary, SIGNAL(message(const QString&)),
00175                  BroadcastStatus::instance(), SLOT(setStatusMsg(const QString&)) );
00176         connect( summary, SIGNAL(summaryWidgetDropped(QWidget*,QWidget*,int)),
00177                  this, SLOT(summaryWidgetMoved(QWidget*,QWidget*,int)) );
00178 
00179         if ( !mLeftColumnSummaries.contains( plugin->identifier() ) &&
00180              !mRightColumnSummaries.contains( plugin->identifier() ) ) {
00181           mLeftColumnSummaries.append( plugin->identifier() );
00182         }
00183 
00184         loadedSummaries.append( plugin->identifier() );
00185       } else {
00186         summary->hide();
00187       }
00188     }
00189   }
00190 
00191   // Remove all unavailable summary widgets
00192   {
00193     QStringList::Iterator strIt;
00194     for ( strIt = mLeftColumnSummaries.begin(); strIt != mLeftColumnSummaries.end(); ++strIt ) {
00195       if ( !loadedSummaries.contains( *strIt ) ) {
00196         strIt = mLeftColumnSummaries.erase( strIt );
00197         --strIt;
00198       }
00199     }
00200     for ( strIt = mRightColumnSummaries.begin(); strIt != mRightColumnSummaries.end(); ++strIt ) {
00201       if ( !loadedSummaries.contains( *strIt ) ) {
00202         strIt = mRightColumnSummaries.erase( strIt );
00203         --strIt;
00204       }
00205     }
00206   }
00207 
00208   // Add vertical line between the two rows of summary widgets.
00209   QFrame *vline = new QFrame( mFrame );
00210   vline->setFrameStyle( QFrame::VLine | QFrame::Plain );
00211 
00212   QHBoxLayout *layout = new QHBoxLayout( mFrame );
00213 
00214   mLeftColumn = new QVBoxLayout();
00215   layout->addLayout( mLeftColumn );
00216   mLeftColumn->setSpacing( KDialog::spacingHint() );
00217   layout->addWidget( vline );
00218   mRightColumn = new QVBoxLayout();
00219   layout->addLayout( mRightColumn );
00220   mRightColumn->setSpacing( KDialog::spacingHint() );
00221   mRightColumn->addSpacerItem( new QSpacerItem( 200, 1 ) );
00222 
00223   QStringList::Iterator strIt;
00224   for ( strIt = mLeftColumnSummaries.begin(); strIt != mLeftColumnSummaries.end(); ++strIt ) {
00225     if ( mSummaries.contains( *strIt ) ) {
00226       mLeftColumn->addWidget( mSummaries[ *strIt ] );
00227     }
00228   }
00229 
00230   for ( strIt = mRightColumnSummaries.begin(); strIt != mRightColumnSummaries.end(); ++strIt ) {
00231     if ( mSummaries.contains( *strIt ) ) {
00232       mRightColumn->addWidget( mSummaries[ *strIt ] );
00233     }
00234   }
00235 
00236   mFrame->show();
00237 
00238   mMainWidget->setUpdatesEnabled( true );
00239   mMainWidget->update();
00240 
00241   mLeftColumn->addStretch();
00242   mRightColumn->addStretch();
00243 }
00244 
00245 void SummaryViewPart::summaryWidgetMoved( QWidget *target, QWidget *widget, int alignment )
00246 {
00247   if ( target == widget ) {
00248     return;
00249   }
00250 
00251   if ( target == mFrame ) {
00252     if ( mLeftColumn->indexOf( widget ) == -1 && mRightColumn->indexOf( widget ) == -1 ) {
00253       return;
00254     }
00255   } else {
00256     if ( ( mLeftColumn->indexOf( target ) == -1 && mRightColumn->indexOf( target ) == -1 ) ||
00257          ( mLeftColumn->indexOf( widget ) == -1 && mRightColumn->indexOf( widget ) == -1 ) ) {
00258       return;
00259     }
00260   }
00261 
00262   if ( !QApplication::isRightToLeft() ) {
00263     drawLtoR( target, widget, alignment );
00264   } else {
00265     drawRtoL( target, widget, alignment );
00266   }
00267 }
00268 
00269 void SummaryViewPart::drawLtoR( QWidget *target, QWidget *widget, int alignment )
00270 {
00271   if ( mLeftColumn->indexOf( widget ) != -1 ) {
00272     mLeftColumn->removeWidget( widget );
00273     mLeftColumnSummaries.removeAll( widgetName( widget ) );
00274   } else if ( mRightColumn->indexOf( widget ) != -1 ) {
00275     mRightColumn->removeWidget( widget );
00276     mRightColumnSummaries.removeAll( widgetName( widget ) );
00277   }
00278 
00279   if ( target == mFrame ) {
00280     int pos = 0;
00281 
00282     if ( alignment & Qt::AlignTop ) {
00283       pos = 0;
00284     }
00285 
00286     if ( alignment & Qt::AlignLeft ) {
00287       if ( alignment & Qt::AlignBottom ) {
00288         pos = mLeftColumnSummaries.count();
00289       }
00290 
00291       mLeftColumn->insertWidget( pos, widget );
00292       mLeftColumnSummaries.insert( pos, widgetName( widget ) );
00293     } else {
00294       if ( alignment & Qt::AlignBottom ) {
00295         pos = mRightColumnSummaries.count();
00296       }
00297 
00298       mRightColumn->insertWidget( pos, widget );
00299       mRightColumnSummaries.insert( pos, widgetName( widget ) );
00300     }
00301 
00302     mFrame->updateGeometry();
00303     return;
00304   }
00305 
00306   int targetPos = mLeftColumn->indexOf( target );
00307   if ( targetPos != -1 ) {
00308     if ( alignment == Qt::AlignBottom ) {
00309       targetPos++;
00310     }
00311 
00312     mLeftColumn->insertWidget( targetPos, widget );
00313     mLeftColumnSummaries.insert( targetPos, widgetName( widget ) );
00314   } else {
00315     targetPos = mRightColumn->indexOf( target );
00316 
00317     if ( alignment == Qt::AlignBottom ) {
00318       targetPos++;
00319     }
00320 
00321     mRightColumn->insertWidget( targetPos, widget );
00322     mRightColumnSummaries.insert( targetPos, widgetName( widget ) );
00323   }
00324   mFrame->updateGeometry();
00325 }
00326 
00327 void SummaryViewPart::drawRtoL( QWidget *target, QWidget *widget, int alignment )
00328 {
00329   if ( mRightColumn->indexOf( widget ) != -1 ) {
00330     mRightColumn->removeWidget( widget );
00331     mRightColumnSummaries.removeAll( widgetName( widget ) );
00332   } else if ( mLeftColumn->indexOf( widget ) != -1 ) {
00333     mLeftColumn->removeWidget( widget );
00334     mLeftColumnSummaries.removeAll( widgetName( widget ) );
00335   }
00336 
00337   if ( target == mFrame ) {
00338     int pos = 0;
00339 
00340     if ( alignment & Qt::AlignTop ) {
00341       pos = 0;
00342     }
00343 
00344     if ( alignment & Qt::AlignLeft ) {
00345       if ( alignment & Qt::AlignBottom ) {
00346         pos = mRightColumnSummaries.count();
00347       }
00348 
00349       mRightColumn->insertWidget( pos, widget );
00350       mRightColumnSummaries.insert( pos, widgetName( widget ) );
00351     } else {
00352       if ( alignment & Qt::AlignBottom ) {
00353         pos = mLeftColumnSummaries.count();
00354       }
00355 
00356       mLeftColumn->insertWidget( pos, widget );
00357       mLeftColumnSummaries.insert( pos, widgetName( widget ) );
00358     }
00359 
00360     mFrame->updateGeometry();
00361     return;
00362   }
00363 
00364   int targetPos = mRightColumn->indexOf( target );
00365   if ( targetPos != -1 ) {
00366     if ( alignment == Qt::AlignBottom ) {
00367       targetPos++;
00368     }
00369 
00370     mRightColumn->insertWidget( targetPos, widget );
00371     mRightColumnSummaries.insert( targetPos, widgetName( widget ) );
00372   } else {
00373     targetPos = mLeftColumn->indexOf( target );
00374 
00375     if ( alignment == Qt::AlignBottom ) {
00376       targetPos++;
00377     }
00378 
00379     mLeftColumn->insertWidget( targetPos, widget );
00380     mLeftColumnSummaries.insert( targetPos, widgetName( widget ) );
00381   }
00382   mFrame->updateGeometry();
00383 }
00384 
00385 void SummaryViewPart::slotTextChanged()
00386 {
00387   emit textChanged( i18n( "What's next?" ) );
00388 }
00389 
00390 void SummaryViewPart::slotAdjustPalette()
00391 {
00392   mMainWidget->setBackgroundRole( QPalette::Base );
00393   mMainWidget->setForegroundRole( QPalette::Text );
00394 }
00395 
00396 void SummaryViewPart::setDate( const QDate &newDate )
00397 {
00398   QString date( "<b>%1</b>" );
00399   date = date.arg( KGlobal::locale()->formatDate( newDate ) );
00400   mDateLabel->setText( date );
00401 }
00402 
00403 void SummaryViewPart::slotConfigure()
00404 {
00405   KCMultiDialog dlg( mMainWidget );
00406   dlg.setObjectName( "ConfigDialog" );
00407   dlg.setModal( true );
00408 
00409   QStringList modules = configModules();
00410   modules.prepend( "kcmkontactsummary.desktop" );
00411   connect( &dlg, SIGNAL(configCommitted()),
00412            this, SLOT(updateWidgets()) );
00413 
00414   QStringList::ConstIterator strIt;
00415   for ( strIt = modules.begin(); strIt != modules.end(); ++strIt ) {
00416     dlg.addModule( *strIt );
00417   }
00418 
00419   dlg.exec();
00420 }
00421 
00422 QStringList SummaryViewPart::configModules() const
00423 {
00424   QStringList modules;
00425 
00426   QMap<QString, Kontact::Summary*>::ConstIterator it;
00427   for ( it = mSummaries.begin(); it != mSummaries.end(); ++it ) {
00428     QStringList cm = it.value()->configModules();
00429     QStringList::ConstIterator strIt;
00430     for ( strIt = cm.begin(); strIt != cm.end(); ++strIt ) {
00431       if ( !(*strIt).isEmpty() && !modules.contains( *strIt ) ) {
00432         modules.append( *strIt );
00433       }
00434     }
00435   }
00436 
00437   return modules;
00438 }
00439 
00440 void SummaryViewPart::initGUI( Kontact::Core *core )
00441 {
00442   QScrollArea *sa = new QScrollArea( core );
00443 
00444   sa->setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
00445   sa->setFrameStyle( QFrame::StyledPanel | QFrame::Sunken );
00446   sa->setWidgetResizable( true );
00447 
00448   mMainWidget = new QFrame;
00449   sa->setWidget( mMainWidget );
00450   mMainWidget->setFocusPolicy( Qt::StrongFocus );
00451   setWidget( sa );
00452 
00453   mMainLayout = new QVBoxLayout( mMainWidget );
00454   mMainLayout->setSpacing( KDialog::spacingHint() );
00455   mMainLayout->setMargin( KDialog::marginHint() );
00456 
00457   QHBoxLayout *hbl = new QHBoxLayout();
00458   mMainLayout->addItem( hbl );
00459   mUsernameLabel = new QLabel( mMainWidget );
00460   mUsernameLabel->setFont( KGlobalSettings::generalFont() );
00461   mDateLabel = new QLabel( mMainWidget );
00462   mDateLabel->setFont( KGlobalSettings::generalFont() );
00463   if ( !QApplication::isRightToLeft() ) {
00464     mUsernameLabel->setAlignment( Qt::AlignLeft );
00465     hbl->addWidget( mUsernameLabel );
00466     mDateLabel->setAlignment( Qt::AlignRight );
00467     hbl->addWidget( mDateLabel );
00468   } else {
00469     mDateLabel->setAlignment( Qt::AlignRight );
00470     hbl->addWidget( mDateLabel );
00471     mUsernameLabel->setAlignment( Qt::AlignLeft );
00472     hbl->addWidget( mUsernameLabel );
00473   }
00474 
00475   QFrame *hline = new QFrame( mMainWidget );
00476   hline->setFrameStyle( QFrame::HLine | QFrame::Plain );
00477   mMainLayout->insertWidget( 1, hline );
00478 
00479   mFrame = new DropWidget( mMainWidget );
00480   mMainLayout->insertWidget( 2, mFrame );
00481 
00482   connect( mFrame, SIGNAL(summaryWidgetDropped(QWidget*,QWidget*,int)),
00483            this, SLOT(summaryWidgetMoved(QWidget*,QWidget*,int)) );
00484 
00485   updateWidgets();
00486 }
00487 
00488 void SummaryViewPart::loadLayout()
00489 {
00490   KConfig config( "kontact_summaryrc" );
00491   KConfigGroup grp( &config, QString() );
00492 
00493   if ( !grp.hasKey( "LeftColumnSummaries" ) ) {
00494     mLeftColumnSummaries << "kontact_korganizerplugin";
00495     mLeftColumnSummaries << "kontact_todoplugin";
00496     mLeftColumnSummaries << "kontact_specialdatesplugin";
00497   } else {
00498     mLeftColumnSummaries = grp.readEntry( "LeftColumnSummaries", QStringList() );
00499   }
00500 
00501   if ( !grp.hasKey( "RightColumnSummaries" ) ) {
00502     mRightColumnSummaries << "kontact_kmailplugin";
00503     mRightColumnSummaries << "kontact_knotesplugin";
00504   } else {
00505     mRightColumnSummaries = grp.readEntry( "RightColumnSummaries", QStringList() );
00506   }
00507 }
00508 
00509 void SummaryViewPart::saveLayout()
00510 {
00511   KConfig config( "kontact_summaryrc" );
00512   KConfigGroup grp( &config, QString() );
00513 
00514   grp.writeEntry( "LeftColumnSummaries", mLeftColumnSummaries );
00515   grp.writeEntry( "RightColumnSummaries", mRightColumnSummaries );
00516 
00517   config.sync();
00518 }
00519 
00520 QString SummaryViewPart::widgetName( QWidget *widget ) const
00521 {
00522   QMap<QString, Kontact::Summary*>::ConstIterator it;
00523   for ( it = mSummaries.begin(); it != mSummaries.end(); ++it ) {
00524     if ( it.value() == widget ) {
00525       return it.key();
00526     }
00527   }
00528 
00529   return QString();
00530 }
00531 
00532 #include "summaryview_part.moc"

kontact

Skip menu "kontact"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members

kdepim

Skip menu "kdepim"
  • akonadi
  •   clients
  •   kabc
  •   kcal
  •   kcm
  • akregator
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt
  • kdgantt1
  • kjots
  • kleopatra
  • kmail
  • kmobiletools
  • knode
  • knotes
  • kontact
  • kontactinterfaces
  • korganizer
  •   korgac
  • kpilot
  • ktimetracker
  •   doc
  • libkdepim
  • libkholidays
  • libkleo
  • libkpgp
  • maildir
Generated for kdepim by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal