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 <kdcopservicestarter.h>
00033 #include <kdebug.h>
00034 #include <kdialog.h>
00035 #include <klocale.h>
00036 #include <kmessagebox.h>
00037 #include <kservice.h>
00038 #include <ktrader.h>
00039 #include <kstandarddirs.h>
00040 #include <kstatusbar.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/statusbarextension.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 namespace Kontact
00058 {
00059   class MainWindow;
00060 }
00061 
00062 SummaryViewPart::SummaryViewPart( Kontact::Core *core, const char *widgetName,
00063                                   const KAboutData *aboutData,
00064                                   QObject *parent, const char *name )
00065   : KParts::ReadOnlyPart( parent, name ),
00066     mCore( core ), mOptionsDialog( 0 ), mConfigAction( 0 )
00067 {
00068   mStatusExt = new KParts::StatusBarExtension( this );
00069   setInstance( new KInstance( aboutData ) );
00070 
00071   QScrollView *sv = new QScrollView( core );
00072 
00073   sv->setResizePolicy( QScrollView::AutoOneFit );
00074   sv->setFrameStyle( QFrame::NoFrame | QFrame::Plain );
00075 
00076   mFrame = new QFrame( sv->viewport(), widgetName );
00077   sv->addChild(mFrame);
00078 
00079   mFrame->setFrameStyle( QFrame::Panel | QFrame::Sunken );
00080   connect(kapp, SIGNAL(kdisplayPaletteChanged()), SLOT(slotAdjustPalette()));
00081   slotAdjustPalette();
00082   sv->setFocusPolicy( QWidget::StrongFocus );
00083   setWidget( sv );
00084 
00085   mLayout = new QGridLayout( mFrame, 6, 3, KDialog::marginHint(),
00086                              KDialog::spacingHint() );
00087 
00088   getWidgets();
00089 
00090   KParts::InfoExtension *info = new KParts::InfoExtension( this, "Summary" );
00091   connect( this, SIGNAL( textChanged( const QString& ) ),
00092            info, SIGNAL( textChanged( const QString& ) ) );
00093 
00094   if ( !configModules().isEmpty() ) {
00095     mConfigAction = new KAction( i18n( "&Configure"),
00096                                  "configure", 0, this,
00097                                  SLOT( slotConfigure() ), actionCollection(),
00098                                  "summaryview_configure" );
00099   }
00100 
00101   setXMLFile( "kontactsummary_part.rc" );
00102 
00103   QTimer::singleShot( 0, this, SLOT( slotTextChanged() ) );
00104 }
00105 
00106 SummaryViewPart::~SummaryViewPart()
00107 {
00108 }
00109 
00110 bool SummaryViewPart::openFile()
00111 {
00112   kdDebug(5006) << "SummaryViewPart:openFile()" << endl;
00113   return true;
00114 }
00115 
00116 void SummaryViewPart::getWidgets()
00117 {
00118   int totalHeight = 0;
00119 
00120   // Collect all summary widgets with a summaryHeight > 0
00121   QValueList<Kontact::Plugin*> plugins = mCore->pluginList();
00122   QValueList<Kontact::Plugin*>::ConstIterator end = plugins.end();
00123   QValueList<Kontact::Plugin*>::ConstIterator it = plugins.begin();
00124   for ( ; it != end; ++it ) {
00125     Kontact::Plugin *plugin = *it;
00126     Kontact::Summary *s = plugin->createSummaryWidget( mFrame );
00127     if ( s ) {
00128       int h = s->summaryHeight();
00129       kdDebug() << "Summary for " << plugin->title() << " Height: " << h
00130                 << endl;
00131       if ( h ) {
00132         totalHeight += s->summaryHeight();
00133         connect(s, SIGNAL(message(const QString&)),
00134                 mStatusExt->statusBar(), SLOT(message(const QString&)));
00135         mSummaries.append( s );
00136       } else {
00137         s->hide();
00138       }
00139     }
00140   }
00141 
00142   // Layout the summary widgets. Put widgets in two columns. Each widget gets as
00143   // many rows in the layout as Summary::summaryHeight() defines. Separator
00144   // lines are automatically added as appropriate.
00145 
00146   int column = 0;
00147 
00148   int currentHeight = 0;
00149   int currentRow = 2;
00150   int maxRow = 2;
00151   mDateLabel = new QLabel( mFrame );
00152   mDateLabel->setAlignment( AlignRight );
00153   mLayout->addMultiCellWidget( mDateLabel, 0, 0, 0, 2 );
00154   setDate( QDate::currentDate() );
00155   connect(mCore, SIGNAL( dayChanged( const QDate& ) ),
00156                 SLOT( setDate( const QDate& ) ) );
00157 
00158   QFrame *hline = new QFrame( mFrame );
00159   hline->setFrameStyle( QFrame::HLine | QFrame::Plain );
00160   mLayout->addMultiCellWidget( hline, 1, 1, 0, 2 );
00161 
00162   for( uint i = 0; i < mSummaries.count(); ++i ) {
00163     Kontact::Summary *summary = mSummaries.at( i );
00164 
00165     int h = summary->summaryHeight();
00166 
00167     // Add summary widget using as many rows of the layout as specified by
00168     // Kontact::Summary::summaryHeight().
00169     if ( h == 1 ) {
00170       mLayout->addWidget( summary, currentRow, column );
00171     } else {
00172       mLayout->addMultiCellWidget( summary, currentRow, currentRow + h - 1,
00173                                    column, column );
00174     }
00175     
00176     currentHeight += h;
00177     currentRow += h;
00178     
00179     if ( currentHeight * 2 >= totalHeight ) {
00180       // Start second row
00181       currentHeight = 0;
00182       maxRow = currentRow;
00183       currentRow = 2;
00184       column += 2;
00185     }
00186   }
00187 
00188   // Add vertical line between the two rows of summary widgets.
00189   QFrame *vline = new QFrame( mFrame );
00190   vline->setFrameStyle( QFrame::VLine | QFrame::Plain );
00191   mLayout->addMultiCellWidget( vline, 2, maxRow, 1, 1 );
00192 
00193   // space out remaining space to avoid ugly stretching
00194   mLayout->addItem(new QSpacerItem( 1, 1, QSizePolicy::MinimumExpanding,
00195         QSizePolicy::MinimumExpanding ), maxRow+2, 0 );
00196 }
00197 
00198 void SummaryViewPart::slotTextChanged()
00199 {
00200   emit textChanged( i18n( "What's next?" ) );
00201 }
00202 
00203 void SummaryViewPart::slotAdjustPalette()
00204 {
00205     mFrame->setPaletteBackgroundColor( kapp->palette().active().base() );
00206 }
00207 
00208 void SummaryViewPart::setDate( const QDate& newDate )
00209 {
00210   QString date("<b>%1<b>");
00211   date = date.arg( KGlobal::locale()->formatDate( newDate ) );
00212   mDateLabel->setText( date );
00213 }
00214 
00215 void SummaryViewPart::slotConfigure()
00216 {
00217   if ( !mOptionsDialog ) {
00218     mOptionsDialog = new KCMultiDialog( mFrame );
00219 
00220     QStringList modules = configModules();
00221 
00222     Kontact::Summary *summary;
00223     for ( summary = mSummaries.first(); summary; summary = mSummaries.next() )
00224       connect( mOptionsDialog, SIGNAL( configCommitted() ),
00225                summary, SLOT( configChanged() ) );
00226 
00227     QStringList::ConstIterator it;
00228     for ( it = modules.begin(); it != modules.end(); ++it ) {
00229       mOptionsDialog->addModule( *it );
00230     }
00231   }
00232 
00233   mOptionsDialog->show();
00234   mOptionsDialog->raise();
00235 }
00236 
00237 QStringList SummaryViewPart::configModules() const
00238 {
00239   QStringList modules;
00240 
00241   QPtrListIterator<Kontact::Summary> it( mSummaries );
00242   while ( it.current() ) {
00243     QStringList cm = it.current()->configModules();
00244     QStringList::ConstIterator sit;
00245     for ( sit = cm.begin(); sit != cm.end(); ++sit )
00246       modules.append( *sit );
00247 
00248     ++it;
00249   }
00250 
00251   return modules;
00252 }
00253 
00254 #include "summaryview_part.moc"
00255 
00256 // vim: sw=2 sts=2 et tw=80
KDE Logo
This file is part of the documentation for kontact Library Version 3.2.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sat May 1 11:39:00 2004 by doxygen 1.2.15 written by Dimitri van Heesch, © 1997-2003