30 #include "korganizer/korganizerinterface.h"
32 #include <calendarsupport/utils.h>
33 #include <calendarsupport/calendarsingleton.h>
35 #include <Akonadi/Collection>
36 #include <Akonadi/Calendar/IncidenceChanger>
38 #include <KCalCore/Calendar>
39 #include <KCalCore/Event>
41 #include <KontactInterface/Core>
43 #include <KConfigGroup>
44 #include <KIconLoader>
47 #include <KSystemTimeZones>
50 #include <QGridLayout>
52 #include <QVBoxLayout>
55 : KontactInterface::Summary( parent ), mPlugin( plugin )
57 QVBoxLayout *mainLayout =
new QVBoxLayout(
this );
58 mainLayout->setSpacing( 3 );
59 mainLayout->setMargin( 3 );
62 this, QLatin1String(
"view-calendar-upcoming-events"), i18n(
"Upcoming Events" ) );
63 mainLayout->addWidget( header );
65 mLayout =
new QGridLayout();
66 mainLayout->addItem( mLayout );
67 mLayout->setSpacing( 3 );
68 mLayout->setRowStretch( 6, 1 );
70 QStringList mimeTypes;
71 mimeTypes << KCalCore::Event::eventMimeType();
72 mCalendar = CalendarSupport::calendarSingleton();
74 mChanger =
new Akonadi::IncidenceChanger( parent );
76 connect( mCalendar.data(), SIGNAL(calendarChanged()),
this, SLOT(updateView()) );
77 connect( mPlugin->core(), SIGNAL(dayChanged(QDate)),
this, SLOT(updateView()) );
89 KConfig config( QLatin1String(
"kcmapptsummaryrc") );
91 KConfigGroup group = config.group(
"Days" );
92 mDaysAhead = group.readEntry(
"DaysToShow", 7 );
94 group = config.group(
"Show" );
95 mShowBirthdaysFromCal = group.readEntry(
"BirthdaysFromCalendar",
true );
96 mShowAnniversariesFromCal = group.readEntry(
"AnniversariesFromCalendar",
true );
98 group = config.group(
"Groupware" );
99 mShowMineOnly = group.readEntry(
"ShowMineOnly",
false );
104 void ApptSummaryWidget::updateView()
106 qDeleteAll( mLabels );
121 KIconLoader loader( QLatin1String(
"korganizer") );
122 QPixmap pm = loader.loadIcon( QLatin1String(
"view-calendar-day"), KIconLoader::Small );
123 QPixmap pmb = loader.loadIcon( QLatin1String(
"view-calendar-birthday"), KIconLoader::Small );
124 QPixmap pma = loader.loadIcon( QLatin1String(
"view-calendar-wedding-anniversary"), KIconLoader::Small );
128 mShowAnniversariesFromCal );
129 QDate currentDate = QDate::currentDate();
143 KCalCore::Event::Ptr ev =
event->ev;
145 if ( ev->recurs() ) {
146 if ( uidList.contains( ev->instanceIdentifier() ) ) {
149 uidList.append( ev->instanceIdentifier() );
153 label =
new QLabel(
this );
154 if ( ev->categories().contains( QLatin1String(
"BIRTHDAY"), Qt::CaseInsensitive ) ) {
155 label->setPixmap( pmb );
156 }
else if ( ev->categories().contains( QLatin1String(
"ANNIVERSARY"), Qt::CaseInsensitive ) ) {
157 label->setPixmap( pma );
159 label->setPixmap( pm );
161 label->setMaximumWidth( label->minimumSizeHint().width() );
162 mLayout->addWidget( label, counter, 0 );
163 mLabels.append( label );
166 QString dateToDisplay =
event->startDate;
168 dateToDisplay =
event->dateSpan;
170 label =
new QLabel( dateToDisplay,
this );
171 label->setAlignment( Qt::AlignLeft | Qt::AlignVCenter );
172 mLayout->addWidget( label, counter, 1 );
173 mLabels.append( label );
175 QFont font = label->font();
176 font.setBold(
true );
177 label->setFont( font );
182 label->setAlignment( Qt::AlignLeft | Qt::AlignVCenter );
183 mLayout->addWidget( label, counter, 2 );
184 mLabels.append( label );
187 KUrlLabel *urlLabel =
new KUrlLabel(
this );
190 urlLabel->installEventFilter(
this );
191 urlLabel->setTextFormat( Qt::RichText );
192 urlLabel->setWordWrap(
true );
193 mLayout->addWidget( urlLabel, counter, 3 );
194 mLabels.append( urlLabel );
196 connect( urlLabel, SIGNAL(leftClickedUrl(QString)),
197 this, SLOT(viewEvent(QString)) );
198 connect( urlLabel, SIGNAL(rightClickedUrl(QString)),
199 this, SLOT(popupMenu(QString)) );
207 label->setAlignment( Qt::AlignLeft | Qt::AlignVCenter );
208 mLayout->addWidget( label, counter, 4 );
209 mLabels.append( label );
215 qDeleteAll( events );
219 i18np(
"No upcoming events starting within the next day",
220 "No upcoming events starting within the next %1 days",
221 mDaysAhead ),
this );
222 noEvents->setAlignment( Qt::AlignHCenter | Qt::AlignVCenter );
223 mLayout->addWidget( noEvents, 0, 0 );
224 mLabels.append( noEvents );
227 Q_FOREACH ( label, mLabels ) {
232 void ApptSummaryWidget::viewEvent(
const QString &uid )
234 Akonadi::Item::Id
id = mCalendar->item( uid ).id();
237 mPlugin->core()->selectPlugin( QLatin1String(
"kontact_korganizerplugin") );
238 OrgKdeKorganizerKorganizerInterface korganizer(
239 QLatin1String(
"org.kde.korganizer"), QLatin1String(
"/Korganizer"), QDBusConnection::sessionBus() );
240 korganizer.editIncidence( QString::number(
id ) );
244 void ApptSummaryWidget::removeEvent(
const Akonadi::Item &item )
246 mChanger->deleteIncidence( item );
249 void ApptSummaryWidget::popupMenu(
const QString &uid )
255 QAction *editIt = popup.addAction( i18n(
"&Edit Appointment..." ) );
257 QAction *delIt = popup.addAction( i18n(
"&Delete Appointment" ) );
258 delIt->setIcon( KIconLoader::global()->
259 loadIcon( QLatin1String(
"edit-delete"), KIconLoader::Small ) );
261 Akonadi::Item item = mCalendar->item( uid );
262 delIt->setEnabled( mCalendar->hasRight( item, Akonadi::Collection::CanDeleteItem ) );
264 const QAction *selectedAction = popup.exec( QCursor::pos() );
265 if ( selectedAction == editIt ) {
267 }
else if ( selectedAction == delIt ) {
274 if ( obj->inherits(
"KUrlLabel" ) ) {
275 KUrlLabel *label =
static_cast<KUrlLabel*
>( obj );
276 if ( e->type() == QEvent::Enter ) {
277 emit message( i18n(
"Edit Event: \"%1\"", label->text() ) );
279 if ( e->type() == QEvent::Leave ) {
280 emit message( QString::null );
284 return KontactInterface::Summary::eventFilter( obj, e );
289 return QStringList()<< QLatin1String(
"kcmapptsummary.desktop");
292 #include "apptsummarywidget.moc"
static void setShowSpecialEvents(bool skipBirthdays, bool skipAnniversaries)
static List eventsForRange(const QDate &start, const QDate &end, const KCalCore::Calendar::Ptr &calendar)
static