00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
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
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"