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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00018 00019 As a special exception, permission is given to link this program 00020 with any edition of TQt, and distribute the resulting executable, 00021 without including the source code for TQt in the source distribution. 00022 */ 00023 00024 #include <tqobject.h> 00025 #include <tqlabel.h> 00026 #include <tqlayout.h> 00027 #include <tqtooltip.h> 00028 00029 #include <dcopclient.h> 00030 #include <dcopref.h> 00031 #include <tdeapplication.h> 00032 #include <kdebug.h> 00033 #include <tdeglobal.h> 00034 #include <kiconloader.h> 00035 #include <tdelocale.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 TQWidget *parent, const char *name ) 00049 : Kontact::Summary( parent, name ), mLayout( 0 ), mPlugin( plugin ) 00050 { 00051 TQVBoxLayout *mainLayout = new TQVBoxLayout( this, 3, 3 ); 00052 00053 TQPixmap icon = TDEGlobal::iconLoader()->loadIcon( "kontact_notes", 00054 TDEIcon::Desktop, TDEIcon::SizeMedium ); 00055 TQWidget* header = createHeader( this, icon, i18n( "Notes" ) ); 00056 mainLayout->addWidget( header ); 00057 00058 mLayout = new TQGridLayout( mainLayout, 7, 3, 3 ); 00059 mLayout->setRowStretch( 6, 1 ); 00060 00061 mCalendar = new KCal::CalendarLocal( TQString::fromLatin1("UTC") ); 00062 KNotesResourceManager *manager = new KNotesResourceManager(); 00063 00064 TQObject::connect( manager, TQT_SIGNAL( sigRegisteredNote( KCal::Journal* ) ), 00065 this, TQT_SLOT( addNote( KCal::Journal* ) ) ); 00066 TQObject::connect( manager, TQT_SIGNAL( sigDeregisteredNote( KCal::Journal* ) ), 00067 this, TQT_SLOT( removeNote( KCal::Journal* ) ) ); 00068 manager->load(); 00069 00070 00071 updateView(); 00072 } 00073 00074 void KNotesSummaryWidget::updateView() 00075 { 00076 mNotes = mCalendar->journals(); 00077 TQLabel *label; 00078 00079 for ( label = mLabels.first(); label; label = mLabels.next() ) 00080 label->deleteLater(); 00081 mLabels.clear(); 00082 00083 TDEIconLoader loader( "knotes" ); 00084 00085 int counter = 0; 00086 TQPixmap pm = loader.loadIcon( "knotes", TDEIcon::Small ); 00087 00088 KCal::Journal::List::Iterator it; 00089 if ( mNotes.count() ) { 00090 for (it = mNotes.begin(); it != mNotes.end(); ++it) { 00091 00092 // Fill Note Pixmap Field 00093 label = new TQLabel( 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 // File Note Summary Field 00101 TQString 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() | TQt::WordBreak ); 00107 mLayout->addWidget( urlLabel, counter, 1 ); 00108 mLabels.append( urlLabel ); 00109 00110 if ( !(*it)->description().isEmpty() ) { 00111 TQToolTip::add( urlLabel, (*it)->description().left( 80 ) ); 00112 } 00113 00114 connect( urlLabel, TQT_SIGNAL( leftClickedURL( const TQString& ) ), 00115 this, TQT_SLOT( urlClicked( const TQString& ) ) ); 00116 counter++; 00117 } 00118 00119 } else { 00120 TQLabel *noNotes = new TQLabel( 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 TQString &/*uid*/ ) 00131 { 00132 if ( !mPlugin->isRunningStandalone() ) 00133 mPlugin->core()->selectPlugin( mPlugin ); 00134 else 00135 mPlugin->bringToForeground(); 00136 } 00137 00138 bool KNotesSummaryWidget::eventFilter( TQObject *obj, TQEvent* e ) 00139 { 00140 if ( obj->inherits( "KURLLabel" ) ) { 00141 KURLLabel* label = static_cast<KURLLabel*>( TQT_TQWIDGET(obj) ); 00142 if ( e->type() == TQEvent::Enter ) 00143 emit message( i18n( "Read Note: \"%1\"" ).arg( label->text() ) ); 00144 if ( e->type() == TQEvent::Leave ) 00145 emit message( TQString() ); 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"