kontact Library API Documentation

summaryview_part.cpp

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 
00008    This library is free software; you can redistribute it and/or
00009    modify it under the terms of the GNU Library General Public
00010    License as published by the Free Software Foundation; either
00011    version 2 of the License, or (at your option) any later version.
00012 
00013    This library is distributed in the hope that it will be useful,
00014    but WITHOUT ANY WARRANTY; without even the implied warranty of
00015    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016    Library General Public License for more details.
00017 
00018    You should have received a copy of the GNU Library General Public License
00019    along with this library; see the file COPYING.LIB.  If not, write to
00020    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00021    Boston, MA 02111-1307, USA.
00022 */
00023 
00024 #include <qframe.h>
00025 #include <qlabel.h>
00026 #include <qlayout.h>
00027 #include <qtimer.h>
00028 
00029 #include <dcopclient.h>
00030 #include <kaction.h>
00031 #include <kapplication.h>
00032 #include <kconfig.h>
00033 #include <kdcopservicestarter.h>
00034 #include <kdebug.h>
00035 #include <kdialog.h>
00036 #include <klocale.h>
00037 #include <kmessagebox.h>
00038 #include <kservice.h>
00039 #include <ktrader.h>
00040 #include <kstandarddirs.h>
00041 #include <qscrollview.h>
00042 #include <kglobal.h>
00043 #include <klocale.h>
00044 #include <kcmultidialog.h>
00045 
00046 #include <kparts/componentfactory.h>
00047 #include <kparts/event.h>
00048 
00049 #include <infoextension.h>
00050 #include <sidebarextension.h>
00051 
00052 #include "plugin.h"
00053 #include "summary.h"
00054 
00055 #include "summaryview_part.h"
00056 
00057 #include "broadcaststatus.h"
00058 using KPIM::BroadcastStatus;
00059 
00060 namespace Kontact
00061 {
00062   class MainWindow;
00063 }
00064 
00065 SummaryViewPart::SummaryViewPart( Kontact::Core *core, const char*,
00066                                   const KAboutData *aboutData,
00067                                   QObject *parent, const char *name )
00068   : KParts::ReadOnlyPart( parent, name ),
00069     mCore( core ), mFrame( 0 ), mConfigAction( 0 )
00070 {
00071   setInstance( new KInstance( aboutData ) );
00072 
00073   initGUI( core );
00074 
00075   connect( kapp, SIGNAL( kdisplayPaletteChanged() ), SLOT( slotAdjustPalette() ) );
00076   slotAdjustPalette();
00077 
00078   setDate( QDate::currentDate() );
00079   connect( mCore, SIGNAL( dayChanged( const QDate& ) ),
00080            SLOT( setDate( const QDate& ) ) );
00081 
00082   KParts::InfoExtension *info = new KParts::InfoExtension( this, "Summary" );
00083   connect( this, SIGNAL( textChanged( const QString& ) ),
00084            info, SIGNAL( textChanged( const QString& ) ) );
00085 
00086   mConfigAction = new KAction( i18n( "&Configure Summary View..." ),
00087                                "configure", 0, this,
00088                                SLOT( slotConfigure() ), actionCollection(),
00089                                "summaryview_configure" );
00090 
00091   setXMLFile( "kontactsummary_part.rc" );
00092 
00093   QTimer::singleShot( 0, this, SLOT( slotTextChanged() ) );
00094 }
00095 
00096 SummaryViewPart::~SummaryViewPart()
00097 {
00098 }
00099 
00100 bool SummaryViewPart::openFile()
00101 {
00102   kdDebug(5006) << "SummaryViewPart:openFile()" << endl;
00103   return true;
00104 }
00105 
00106 void SummaryViewPart::partActivateEvent( KParts::PartActivateEvent *event )
00107 {
00108   // inform the plugins that the part has been activated so that they can
00109   // update the displayed information
00110   if ( event->activated() && ( event->part() == this ) ) {
00111     QPtrListIterator<Kontact::Summary> it( mSummaries );
00112     for ( ; it.current(); ++it ) {
00113       it.current()->updateSummary( false );
00114     }
00115   }
00116 
00117   KParts::ReadOnlyPart::partActivateEvent( event );
00118 }
00119 
00120 void SummaryViewPart::updateWidgets()
00121 {
00122   mMainWidget->setUpdatesEnabled( false );
00123 
00124   delete mFrame;
00125 
00126   mSummaries.clear();
00127 
00128   mFrame = new QFrame( mMainWidget );
00129   mMainLayout->insertWidget( 2, mFrame );
00130 
00131   int totalHeight = 0;
00132 
00133   QStringList activeSummaries;
00134 
00135   KConfig config( "kontact_summaryrc" );
00136   if ( !config.hasKey( "ActiveSummaries" ) ) {
00137     activeSummaries << "kontact_kmailplugin";
00138     activeSummaries << "kontact_knotesplugin";
00139     activeSummaries << "kontact_kaddressbookplugin";
00140     activeSummaries << "kontact_korganizerplugin";
00141     activeSummaries << "kontact_todoplugin";
00142     activeSummaries << "kontact_newstickerplugin";
00143   } else {
00144     activeSummaries = config.readListEntry( "ActiveSummaries" );
00145   }
00146 
00147   // Collect all summary widgets with a summaryHeight > 0
00148   QValueList<Kontact::Plugin*> plugins = mCore->pluginList();
00149   QValueList<Kontact::Plugin*>::ConstIterator end = plugins.end();
00150   QValueList<Kontact::Plugin*>::ConstIterator it = plugins.begin();
00151   for ( ; it != end; ++it ) {
00152     Kontact::Plugin *plugin = *it;
00153     if ( activeSummaries.find( plugin->identifier() ) == activeSummaries.end() )
00154       continue;
00155 
00156     Kontact::Summary *s = plugin->createSummaryWidget( mFrame );
00157     if ( s ) {
00158       int h = s->summaryHeight();
00159       kdDebug(5602) << "Summary for " << plugin->title() << " Height: " << h
00160                 << endl;
00161       if ( h ) {
00162         totalHeight += s->summaryHeight();
00163         connect( s, SIGNAL( message( const QString& ) ),
00164                  BroadcastStatus::instance(), SLOT( setStatusMsg( const QString& ) ) );
00165         mSummaries.append( s );
00166       } else {
00167         s->hide();
00168       }
00169     }
00170   }
00171 
00172   // Layout the summary widgets. Put widgets in two columns. Each widget gets as
00173   // many rows in the layout as Summary::summaryHeight() defines. Separator
00174   // lines are automatically added as appropriate.
00175 
00176   int column = 0;
00177 
00178   int currentHeight = 0;
00179   int currentRow = 0;
00180   int maxRow = 0;
00181 
00182   QGridLayout *layout = new QGridLayout( mFrame, 6, 3, KDialog::marginHint(),
00183                                          KDialog::spacingHint() );
00184 
00185   for( uint i = 0; i < mSummaries.count(); ++i ) {
00186     Kontact::Summary *summary = mSummaries.at( i );
00187 
00188     int h = summary->summaryHeight();
00189 
00190     // Add summary widget using as many rows of the layout as specified by
00191     // Kontact::Summary::summaryHeight().
00192     if ( h == 1 ) {
00193       layout->addWidget( summary, currentRow, column );
00194     } else {
00195       layout->addMultiCellWidget( summary, currentRow, currentRow + h - 1,
00196                                    column, column );
00197     }
00198 
00199     currentHeight += h;
00200     currentRow += h;
00201 
00202     if ( currentHeight * 2 >= totalHeight ) {
00203       // Start second row
00204       currentHeight = 0;
00205       maxRow = currentRow;
00206       currentRow = 0;
00207       column += 2;
00208     }
00209   }
00210 
00211   // Add vertical line between the two rows of summary widgets.
00212   QFrame *vline = new QFrame( mFrame );
00213   vline->setFrameStyle( QFrame::VLine | QFrame::Plain );
00214   layout->addMultiCellWidget( vline, 0, maxRow, 1, 1 );
00215 
00216   // space out remaining space to avoid ugly stretching
00217   layout->addItem( new QSpacerItem( 1, 1, QSizePolicy::MinimumExpanding,
00218                    QSizePolicy::MinimumExpanding ), maxRow, 0 );
00219 
00220   mFrame->show();
00221 
00222   mMainWidget->setUpdatesEnabled( true );
00223   mMainWidget->update();
00224 }
00225 
00226 void SummaryViewPart::slotTextChanged()
00227 {
00228   emit textChanged( i18n( "What's next?" ) );
00229 }
00230 
00231 void SummaryViewPart::slotAdjustPalette()
00232 {
00233   mMainWidget->setPaletteBackgroundColor( kapp->palette().active().base() );
00234 }
00235 
00236 void SummaryViewPart::setDate( const QDate& newDate )
00237 {
00238   QString date( "<b>%1<b>" );
00239   date = date.arg( KGlobal::locale()->formatDate( newDate ) );
00240   mDateLabel->setText( date );
00241 }
00242 
00243 void SummaryViewPart::slotConfigure()
00244 {
00245   KCMultiDialog dlg( mMainWidget, "ConfigDialog", true );
00246 
00247   QStringList modules = configModules();
00248   modules.prepend( "kcmkontactsummary.desktop" );
00249   connect( &dlg, SIGNAL( configCommitted() ),
00250            this, SLOT( updateWidgets() ) );
00251 
00252   Kontact::Summary *summary;
00253   for ( summary = mSummaries.first(); summary; summary = mSummaries.next() )
00254     connect( &dlg, SIGNAL( configCommitted() ),
00255              summary, SLOT( configChanged() ) );
00256 
00257   QStringList::ConstIterator it;
00258   for ( it = modules.begin(); it != modules.end(); ++it )
00259     dlg.addModule( *it );
00260 
00261   dlg.exec();
00262 }
00263 
00264 QStringList SummaryViewPart::configModules() const
00265 {
00266   QStringList modules;
00267 
00268   QPtrListIterator<Kontact::Summary> it( mSummaries );
00269   while ( it.current() ) {
00270     QStringList cm = it.current()->configModules();
00271     QStringList::ConstIterator sit;
00272     for ( sit = cm.begin(); sit != cm.end(); ++sit )
00273       if ( !modules.contains( *sit ) )
00274         modules.append( *sit );
00275 
00276     ++it;
00277   }
00278 
00279   return modules;
00280 }
00281 
00282 void SummaryViewPart::initGUI( Kontact::Core *core )
00283 {
00284   QScrollView *sv = new QScrollView( core );
00285 
00286   sv->setResizePolicy( QScrollView::AutoOneFit );
00287   sv->setFrameStyle( QFrame::NoFrame | QFrame::Plain );
00288 
00289   mMainWidget = new QFrame( sv->viewport() );
00290   sv->addChild( mMainWidget );
00291   mMainWidget->setFrameStyle( QFrame::Panel | QFrame::Sunken );
00292   sv->setFocusPolicy( QWidget::StrongFocus );
00293   setWidget( sv );
00294 
00295   mMainLayout = new QVBoxLayout( mMainWidget,KDialog::marginHint(),
00296                                  KDialog::spacingHint() );
00297 
00298   mDateLabel = new QLabel( mMainWidget );
00299   mDateLabel->setAlignment( AlignRight );
00300   mMainLayout->insertWidget( 0, mDateLabel );
00301 
00302   QFrame *hline = new QFrame( mMainWidget );
00303   hline->setFrameStyle( QFrame::HLine | QFrame::Plain );
00304   mMainLayout->insertWidget( 1, hline );
00305 
00306   mFrame = new QFrame( mMainWidget );
00307   mMainLayout->insertWidget( 2, mFrame );
00308 
00309   updateWidgets();
00310 }
00311 
00312 #include "summaryview_part.moc"
KDE Logo
This file is part of the documentation for kontact Library Version 3.3.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Jan 31 15:56:21 2007 by doxygen 1.4.2 written by Dimitri van Heesch, © 1997-2003