27 #include <tqtooltip.h>
30 #include <tdeglobal.h>
31 #include <kiconloader.h>
32 #include <tdelocale.h>
33 #include <tdeparts/part.h>
34 #include <tdepopupmenu.h>
35 #include <kstandarddirs.h>
36 #include <kurllabel.h>
37 #include <libkcal/event.h>
38 #include <libkcal/resourcecalendar.h>
39 #include <libkcal/resourcelocal.h>
40 #include <libkcal/incidenceformatter.h>
41 #include <libtdepim/kpimprefs.h>
43 #include "korganizeriface_stub.h"
47 #include "korganizerplugin.h"
49 #include "korganizer/stdcalendar.h"
51 #include "summarywidget.h"
53 SummaryWidget::SummaryWidget( KOrganizerPlugin *plugin, TQWidget *parent,
55 : Kontact::Summary( parent, name ), mPlugin( plugin ), mCalendar( 0 )
57 TQVBoxLayout *mainLayout =
new TQVBoxLayout(
this, 3, 3 );
59 TQPixmap icon = TDEGlobal::iconLoader()->loadIcon(
"kontact_date",
60 TDEIcon::Desktop, TDEIcon::SizeMedium );
61 TQWidget *header = createHeader(
this, icon, i18n(
"Calendar" ) );
62 mainLayout->addWidget( header );
64 mLayout =
new TQGridLayout( mainLayout, 7, 5, 3 );
65 mLayout->setRowStretch( 6, 1 );
67 mCalendar = KOrg::StdCalendar::self();
69 connect( mCalendar, TQ_SIGNAL( calendarChanged() ), TQ_SLOT( updateView() ) );
70 connect( mPlugin->core(), TQ_SIGNAL( dayChanged(
const TQDate& ) ),
71 TQ_SLOT( updateView() ) );
76 SummaryWidget::~SummaryWidget()
80 void SummaryWidget::updateView()
82 mLabels.setAutoDelete(
true );
84 mLabels.setAutoDelete(
false );
86 TDEIconLoader loader(
"tdepim" );
88 TDEConfig config(
"kcmkorgsummaryrc" );
90 config.setGroup(
"Calendar" );
91 int days = config.readNumEntry(
"DaysToShow", 1 );
95 TQPixmap pm = loader.loadIcon(
"appointment", TDEIcon::Small );
96 TQPixmap pmb = loader.loadIcon(
"calendarbirthday", TDEIcon::Small );
97 TQPixmap pma = loader.loadIcon(
"calendaranniversary", TDEIcon::Small );
100 TQDate currentDate = TQDate::currentDate();
101 for ( dt=currentDate;
102 dt<=currentDate.addDays( days - 1 );
105 KCal::Event::List events = mCalendar->events( dt );
110 KCal::EventSortSummary,
111 KCal::SortDirectionAscending );
115 KCal::EventSortStartDate,
116 KCal::SortDirectionAscending );
118 KCal::Event::List::ConstIterator it = events.begin();
119 for ( it=events.begin(); it!=events.end(); ++it ) {
123 int span=1;
int dayof=1;
125 TQDate d = ev->
dtStart().date();
126 if ( d < currentDate ) {
129 while ( d < ev->dtEnd().date() ) {
143 label =
new TQLabel(
this );
144 if ( ev->
categories().contains(
"Birthday" ) ) {
145 label->setPixmap( pmb );
146 }
else if ( ev->
categories().contains(
"Anniversary" ) ) {
147 label->setPixmap( pma );
149 label->setPixmap( pm );
151 label->setMaximumWidth( label->minimumSizeHint().width() );
152 label->setAlignment( AlignVCenter );
153 mLayout->addWidget( label, counter, 0 );
154 mLabels.append( label );
157 bool makeBold =
false;
161 TQDate sD = TQDate( dt.year(), dt.month(), dt.day() );
162 if ( ( sD.month() == currentDate.month() ) &&
163 ( sD.day() == currentDate.day() ) ) {
164 datestr = i18n(
"Today" );
166 }
else if ( ( sD.month() == currentDate.addDays( 1 ).month() ) &&
167 ( sD.day() == currentDate.addDays( 1 ).day() ) ) {
168 datestr = i18n(
"Tomorrow" );
170 datestr = TDEGlobal::locale()->formatDate( sD );
176 datestr = TDEGlobal::locale()->formatDate( ev->
dtStart().date() );
178 TDEGlobal::locale()->formatDate( sD.addDays( span-1 ) );
181 label =
new TQLabel( datestr,
this );
182 label->setAlignment( AlignLeft | AlignVCenter );
184 TQFont font = label->font();
185 font.setBold(
true );
186 label->setFont( font );
188 mLayout->addWidget( label, counter, 1 );
189 mLabels.append( label );
192 TQString newtext = ev->
summary();
194 newtext.append( TQString(
" (%1/%2)").arg( dayof ).arg( span ) );
197 KURLLabel *urlLabel =
new KURLLabel(
this );
198 urlLabel->setText( newtext );
199 urlLabel->setURL( ev->
uid() );
200 urlLabel->installEventFilter(
this );
201 urlLabel->setAlignment( urlLabel->alignment() | TQt::WordBreak );
202 mLayout->addWidget( urlLabel, counter, 2 );
203 mLabels.append( urlLabel );
205 connect( urlLabel, TQ_SIGNAL( leftClickedURL(
const TQString& ) ),
206 this, TQ_SLOT( viewEvent(
const TQString& ) ) );
207 connect( urlLabel, TQ_SIGNAL( rightClickedURL(
const TQString& ) ),
208 this, TQ_SLOT( popupMenu(
const TQString& ) ) );
210 TQString tipText( KCal::IncidenceFormatter::toolTipStr( mCalendar, ev, dt,
true ) );
211 if ( !tipText.isEmpty() ) {
212 TQToolTip::add( urlLabel, tipText );
217 TQTime sST = ev->
dtStart().time();
218 TQTime sET = ev->
dtEnd().time();
220 if ( ev->
dtStart().date() < dt ) {
221 sST = TQTime( 0, 0 );
223 if ( ev->
dtEnd().date() > dt ) {
224 sET = TQTime( 23, 59 );
227 datestr = i18n(
"Time from - to",
"%1 - %2" )
228 .arg( TDEGlobal::locale()->formatTime( sST ) )
229 .arg( TDEGlobal::locale()->formatTime( sET ) );
230 label =
new TQLabel( datestr,
this );
231 label->setAlignment( AlignLeft | AlignVCenter );
232 mLayout->addWidget( label, counter, 3 );
233 mLabels.append( label );
241 TQLabel *noEvents =
new TQLabel(
242 i18n(
"No appointments pending within the next day",
243 "No appointments pending within the next %n days",
244 days ),
this,
"nothing to see" );
245 noEvents->setAlignment( AlignHCenter | AlignVCenter );
246 mLayout->addWidget( noEvents, 0, 2 );
247 mLabels.append( noEvents );
250 for ( label = mLabels.first(); label; label = mLabels.next() )
254 void SummaryWidget::viewEvent(
const TQString &uid )
256 mPlugin->core()->selectPlugin(
"kontact_korganizerplugin" );
257 KOrganizerIface_stub iface(
"korganizer",
"KOrganizerIface" );
258 iface.editIncidence( uid );
261 void SummaryWidget::removeEvent(
const TQString &uid )
263 mPlugin->core()->selectPlugin(
"kontact_korganizerplugin" );
264 KOrganizerIface_stub iface(
"korganizer",
"KOrganizerIface" );
265 iface.deleteIncidence( uid,
false );
268 void SummaryWidget::popupMenu(
const TQString &uid )
270 TDEPopupMenu popup(
this );
271 TQToolTip::remove(
this );
272 popup.insertItem( i18n(
"&Edit Appointment..." ), 0 );
273 popup.insertItem( TDEGlobal::iconLoader()->loadIcon(
"edit-delete", TDEIcon::Small),
274 i18n(
"&Delete Appointment" ), 1 );
276 switch ( popup.exec( TQCursor::pos() ) ) {
286 bool SummaryWidget::eventFilter( TQObject *obj, TQEvent* e )
288 if ( obj->inherits(
"KURLLabel" ) ) {
289 KURLLabel* label =
static_cast<KURLLabel*
>( obj );
290 if ( e->type() == TQEvent::Enter )
291 emit message( i18n(
"Edit Appointment: \"%1\"" ).arg( label->text() ) );
292 if ( e->type() == TQEvent::Leave )
293 emit message( TQString() );
296 return Kontact::Summary::eventFilter( obj, e );
299 TQStringList SummaryWidget::configModules()
const
301 return TQStringList(
"kcmkorgsummary.desktop" );
304 #include "summarywidget.moc"
static Event::List sortEventsForDate(Event::List *eventList, const TQDate &date, EventSortField sortField, SortDirection sortDirection)
virtual TQDateTime dtEnd() const
virtual TQDateTime dtStart() const
TQStringList categories() const