kontact Library API Documentation

summarywidget.cpp

00001 /*
00002     This file is part of Kontact.
00003     Copyright (c) 2003 Tobias Koenig <tokoe@kde.org>
00004 
00005     This program is free software; you can redistribute it and/or modify
00006     it under the terms of the GNU General Public License as published by
00007     the Free Software Foundation; either version 2 of the License, or
00008     (at your option) any later version.
00009 
00010     This program is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00013     GNU General Public License for more details.
00014 
00015     You should have received a copy of the GNU General Public License
00016     along with this program; if not, write to the Free Software
00017     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00018 
00019     As a special exception, permission is given to link this program
00020     with any edition of Qt, and distribute the resulting executable,
00021     without including the source code for Qt in the source distribution.
00022 */
00023 
00024 #include <qlabel.h>
00025 #include <qlayout.h>
00026 
00027 #include <dcopclient.h>
00028 #include <dcopref.h>
00029 #include <kapplication.h>
00030 #include <kdebug.h>
00031 #include <kglobal.h>
00032 #include <kiconloader.h>
00033 #include <klocale.h>
00034 #include <kurllabel.h>
00035 #include <kstandarddirs.h>
00036 
00037 #include "summarywidget.h"
00038 
00039 SummaryWidget::SummaryWidget( QWidget *parent, const char *name )
00040   : Kontact::Summary( parent, name )
00041 {
00042   mMainLayout = new QVBoxLayout( this, 3, 3 );
00043 
00044   mICal = new KCal::CalendarLocal;
00045 
00046   // doesn't get triggered (danimo)
00047   connect(mICal, SIGNAL(calendarChanged()), SLOT(updateView()));
00048 
00049   QPixmap icon = KGlobal::iconLoader()->loadIcon( "knotes", KIcon::Desktop, KIcon::SizeMedium );
00050   QWidget* heading = createHeader( this, icon, i18n( "Notes" ) );
00051 
00052   mMainLayout->addWidget(heading);
00053   mLayout = new QVBoxLayout( mMainLayout );
00054 
00055   updateView();
00056 }
00057 
00058 bool SummaryWidget::ensureKNotesRunning()
00059 {
00060   QString error;
00061   if ( !kapp->dcopClient()->isApplicationRegistered( "knotes" ) ) {
00062     if ( KApplication::startServiceByDesktopName( 
00063           "knotes", QStringList(), &error ) != 0 ) 
00064     {
00065       kdDebug() << error << endl;
00066       return false;
00067     }
00068   }
00069   return true;
00070 }
00071 
00072 void SummaryWidget::updateView()
00073 {
00074   mICal->load(::locate("data", "knotes/notes.ics"));
00075   mNotes = mICal->journals();
00076 
00077   delete mLayout;
00078   mLayout = new QVBoxLayout( mMainLayout );
00079 
00080   mLabels.setAutoDelete( true );
00081   mLabels.clear();
00082   mLabels.setAutoDelete( false );
00083 
00084   KCal::Journal::List::Iterator it;
00085   for (it = mNotes.begin(); it != mNotes.end(); ++it) {
00086     KURLLabel *urlLabel = new KURLLabel( 
00087         (*it)->uid(), (*it)->summary(), this );
00088     urlLabel->setTextFormat(RichText);
00089     mLayout->addWidget( urlLabel );
00090     mLabels.append( urlLabel );
00091 
00092     connect( urlLabel, SIGNAL( leftClickedURL( const QString& ) ),
00093         this, SLOT( urlClicked( const QString& ) ) );
00094   }
00095 
00096   mLayout->addStretch();
00097 }
00098 
00099 void SummaryWidget::urlClicked( const QString &uid )
00100 {
00101   if (ensureKNotesRunning())
00102   {
00103     DCOPRef dcopCall( "knotes", "KNotesIface" );
00104     dcopCall.send( "showNote(QString)", uid );
00105   }
00106 }
00107 
00108 #include "summarywidget.moc"
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