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 <qobject.h>
00025 #include <qlabel.h>
00026 #include <qlayout.h>
00027 #include <qtooltip.h>
00028
00029 #include <dcopclient.h>
00030 #include <dcopref.h>
00031 #include <kapplication.h>
00032 #include <kdebug.h>
00033 #include <kglobal.h>
00034 #include <kiconloader.h>
00035 #include <klocale.h>
00036 #include <kurllabel.h>
00037 #include <kstandarddirs.h>
00038
00039 #include <knotes/resourcenotes.h>
00040 #include <knotes/resourcemanager.h>
00041
00042 #include "core.h"
00043 #include "plugin.h"
00044
00045 #include "summarywidget.h"
00046
00047 KNotesSummaryWidget::KNotesSummaryWidget( Kontact::Plugin *plugin,
00048 QWidget *parent, const char *name )
00049 : Kontact::Summary( parent, name ), mLayout( 0 ), mPlugin( plugin )
00050 {
00051 QVBoxLayout *mainLayout = new QVBoxLayout( this, 3, 3 );
00052
00053 QPixmap icon = KGlobal::iconLoader()->loadIcon( "kontact_notes",
00054 KIcon::Desktop, KIcon::SizeMedium );
00055 QWidget* header = createHeader( this, icon, i18n( "Notes" ) );
00056 mainLayout->addWidget( header );
00057
00058 mLayout = new QGridLayout( mainLayout, 7, 3, 3 );
00059 mLayout->setRowStretch( 6, 1 );
00060
00061 mCalendar = new KCal::CalendarLocal( QString::fromLatin1("UTC") );
00062 KNotesResourceManager *manager = new KNotesResourceManager();
00063
00064 QObject::connect( manager, SIGNAL( sigRegisteredNote( KCal::Journal* ) ),
00065 this, SLOT( addNote( KCal::Journal* ) ) );
00066 QObject::connect( manager, SIGNAL( sigDeregisteredNote( KCal::Journal* ) ),
00067 this, SLOT( removeNote( KCal::Journal* ) ) );
00068 manager->load();
00069
00070
00071 updateView();
00072 }
00073
00074 void KNotesSummaryWidget::updateView()
00075 {
00076 mNotes = mCalendar->journals();
00077
00078 mLabels.setAutoDelete( true );
00079 mLabels.clear();
00080 mLabels.setAutoDelete( false );
00081
00082 KIconLoader loader( "knotes" );
00083
00084 QLabel *label = 0;
00085 int counter = 0;
00086 QPixmap pm = loader.loadIcon( "knotes", KIcon::Small );
00087
00088 KCal::Journal::List::Iterator it;
00089 if ( mNotes.count() ) {
00090 for (it = mNotes.begin(); it != mNotes.end(); ++it) {
00091
00092
00093 label = new QLabel( this );
00094 label->setPixmap( pm );
00095 label->setMaximumWidth( label->minimumSizeHint().width() );
00096 label->setAlignment( AlignVCenter );
00097 mLayout->addWidget( label, counter, 0 );
00098 mLabels.append( label );
00099
00100
00101 QString newtext = (*it)->summary();
00102
00103 KURLLabel *urlLabel = new KURLLabel( (*it)->uid(), newtext, this );
00104 urlLabel->installEventFilter( this );
00105 urlLabel->setTextFormat(RichText);
00106 urlLabel->setAlignment( urlLabel->alignment() | Qt::WordBreak );
00107 mLayout->addWidget( urlLabel, counter, 1 );
00108 mLabels.append( urlLabel );
00109
00110 if ( !(*it)->description().isEmpty() ) {
00111 QToolTip::add( urlLabel, (*it)->description().left( 80 ) );
00112 }
00113
00114 connect( urlLabel, SIGNAL( leftClickedURL( const QString& ) ),
00115 this, SLOT( urlClicked( const QString& ) ) );
00116 counter++;
00117 }
00118
00119 } else {
00120 QLabel *noNotes = new QLabel( i18n( "No Notes Available" ), this );
00121 noNotes->setAlignment( AlignHCenter | AlignVCenter );
00122 mLayout->addWidget( noNotes, 0, 1 );
00123 mLabels.append( noNotes );
00124 }
00125
00126 for ( label = mLabels.first(); label; label = mLabels.next() )
00127 label->show();
00128 }
00129
00130 void KNotesSummaryWidget::urlClicked( const QString & )
00131 {
00132 if ( !mPlugin->isRunningStandalone() )
00133 mPlugin->core()->selectPlugin( mPlugin );
00134 else
00135 mPlugin->bringToForeground();
00136 }
00137
00138 bool KNotesSummaryWidget::eventFilter( QObject *obj, QEvent* e )
00139 {
00140 if ( obj->inherits( "KURLLabel" ) ) {
00141 KURLLabel* label = static_cast<KURLLabel*>( obj );
00142 if ( e->type() == QEvent::Enter )
00143 emit message( i18n( "Read Note: \"%1\"" ).arg( label->text() ) );
00144 if ( e->type() == QEvent::Leave )
00145 emit message( QString::null );
00146 }
00147
00148 return Kontact::Summary::eventFilter( obj, e );
00149 }
00150
00151 void KNotesSummaryWidget::addNote( KCal::Journal *j )
00152 {
00153 mCalendar->addJournal( j );
00154 updateView();
00155 }
00156
00157 void KNotesSummaryWidget::removeNote( KCal::Journal *j )
00158 {
00159 mCalendar->deleteJournal( j );
00160 updateView();
00161 }
00162
00163
00164 #include "summarywidget.moc"