From 460c52653ab0dcca6f19a4f492ed2c5e4e963ab0 Mon Sep 17 00:00:00 2001 From: toma Date: Wed, 25 Nov 2009 17:56:58 +0000 Subject: Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features. BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdepim@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- korganizer/kowhatsnextview.cpp | 335 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 335 insertions(+) create mode 100644 korganizer/kowhatsnextview.cpp (limited to 'korganizer/kowhatsnextview.cpp') diff --git a/korganizer/kowhatsnextview.cpp b/korganizer/kowhatsnextview.cpp new file mode 100644 index 000000000..d4b6618aa --- /dev/null +++ b/korganizer/kowhatsnextview.cpp @@ -0,0 +1,335 @@ +/* + This file is part of KOrganizer. + + Copyright (c) 2001 Cornelius Schumacher + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + As a special exception, permission is given to link this program + with any edition of Qt, and distribute the resulting executable, + without including the source code for Qt in the source distribution. +*/ + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include + +#include "koglobals.h" +#include "koprefs.h" +#include "koeventviewerdialog.h" + +#include "kowhatsnextview.h" + +using namespace KOrg; + +void WhatsNextTextBrowser::setSource(const QString& n) +{ + kdDebug(5850) << "WhatsNextTextBrowser::setSource(): " << n << endl; + + if (n.startsWith("event:")) { + emit showIncidence(n); + return; + } else if (n.startsWith("todo:")) { + emit showIncidence(n); + return; + } else { + QTextBrowser::setSource(n); + } +} + +KOWhatsNextView::KOWhatsNextView(Calendar *calendar, QWidget *parent, + const char *name) + : KOrg::BaseView(calendar, parent, name) +{ +// QLabel *dateLabel = +// new QLabel(KGlobal::locale()->formatDate(QDate::currentDate()),this); +// dateLabel->setMargin(2); +// dateLabel->setAlignment(AlignCenter); + + mView = new WhatsNextTextBrowser(this); + connect(mView,SIGNAL(showIncidence(const QString &)),SLOT(showIncidence(const QString &))); + + QBoxLayout *topLayout = new QVBoxLayout(this); +// topLayout->addWidget(dateLabel); + topLayout->addWidget(mView); +} + +KOWhatsNextView::~KOWhatsNextView() +{ +} + +int KOWhatsNextView::currentDateCount() +{ + return mStartDate.daysTo( mEndDate ); +} + +void KOWhatsNextView::updateView() +{ + KIconLoader kil("kdepim"); + QString *ipath = new QString(); + kil.loadIcon("kdepim",KIcon::NoGroup,32,KIcon::DefaultState,ipath); + + mText = "\n"; + mText += "\n\n

"; + mText += ""; + mText += " "; + mText += i18n("What's Next?") + "

"; + mText += "
"; + + mText += "

"; + if ( mStartDate.daysTo( mEndDate ) < 1 ) { + mText += KGlobal::locale()->formatDate( mStartDate ); + } else { + mText += i18n("Date from - to", "%1 - %2") + .arg( KGlobal::locale()->formatDate( mStartDate ) ) + .arg( KGlobal::locale()->formatDate( mEndDate ) ); + } + mText+="

\n"; + + Event::List events; + for ( QDate date = mStartDate; date <= mEndDate; date = date.addDays( 1 ) ) + events += calendar()->events(date, EventSortStartDate, SortDirectionAscending); + + if (events.count() > 0) { + mText += "

"; + kil.loadIcon("appointment",KIcon::NoGroup,22,KIcon::DefaultState,ipath); + mText += "

"; + mText += i18n("Events:") + "

\n"; + mText += "\n"; + Event::List::ConstIterator it; + for( it = events.begin(); it != events.end(); ++it ) { + Event *ev = *it; + if ( !ev->doesRecur() ){ + appendEvent(ev); + } else { + // FIXME: This should actually be cleaned up. Libkcal should + // provide a method to return a list of all recurrences in a + // given time span. + Recurrence *recur = ev->recurrence(); + int duration = ev->dtStart().secsTo( ev->dtEnd() ); + QDateTime start = recur->getPreviousDateTime( + QDateTime( mStartDate, QTime() ) ); + QDateTime end = start.addSecs( duration ); + if ( end.date() >= mStartDate ) { + appendEvent( ev, start, end ); + } + start = recur->getNextDateTime( start ); + while ( start.isValid() && start.date() <= mEndDate ) { + appendEvent( ev, start ); + start = recur->getNextDateTime( start ); + } + } + } + mText += "
\n"; + } + + mTodos.clear(); + Todo::List todos = calendar()->todos( TodoSortDueDate, SortDirectionAscending ); + if ( todos.count() > 0 ) { + kil.loadIcon("todo",KIcon::NoGroup,22,KIcon::DefaultState,ipath); + mText += "

"; + mText += i18n("To-do:") + "

\n"; + mText += "
    \n"; + Todo::List::ConstIterator it; + for( it = todos.begin(); it != todos.end(); ++it ) { + Todo *todo = *it; + if ( !todo->isCompleted() && todo->hasDueDate() && todo->dtDue().date() <= mEndDate ) + appendTodo(todo); + } + bool gotone = false; + int priority = 1; + while (!gotone && priority<=9 ) { + for( it = todos.begin(); it != todos.end(); ++it ) { + Todo *todo = *it; + if (!todo->isCompleted() && (todo->priority() == priority) ) { + appendTodo(todo); + gotone = true; + } + } + priority++; + kdDebug(5850) << "adding the todos..." << endl; + } + mText += "
\n"; + } + + QStringList myEmails( KOPrefs::instance()->allEmails() ); + int replies = 0; + events = calendar()->events( QDate::currentDate(), QDate(2975,12,6) ); + Event::List::ConstIterator it2; + for( it2 = events.begin(); it2 != events.end(); ++it2 ) { + Event *ev = *it2; + Attendee *me = ev->attendeeByMails( myEmails ); + if (me!=0) { + if (me->status()==Attendee::NeedsAction && me->RSVP()) { + if (replies == 0) { + mText += "

"; + kil.loadIcon("reply",KIcon::NoGroup,22,KIcon::DefaultState,ipath); + mText += "

"; + mText += i18n("Events and to-dos that need a reply:") + "

\n"; + mText += "\n"; + } + replies++; + appendEvent( ev ); + } + } + } + todos = calendar()->todos(); + Todo::List::ConstIterator it3; + for( it3 = todos.begin(); it3 != todos.end(); ++it3 ) { + Todo *to = *it3; + Attendee *me = to->attendeeByMails( myEmails ); + if (me!=0) { + if (me->status()==Attendee::NeedsAction && me->RSVP()) { + if (replies == 0) { + mText += "

"; + kil.loadIcon("reply",KIcon::NoGroup,22,KIcon::DefaultState,ipath); + mText += "

"; + mText += i18n("Events and to-dos that need a reply:") + "

\n"; + mText += "
\n"; + } + replies++; + appendEvent(to); + } + } + kdDebug () << "check for todo-replies..." << endl; + } + if (replies > 0 ) mText += "
\n"; + + + mText += "
\n"; + + kdDebug(5850) << "KOWhatsNextView::updateView: text: " << mText << endl; + + delete ipath; + + mView->setText(mText); +} + +void KOWhatsNextView::showDates( const QDate &start, const QDate &end ) +{ + mStartDate = start; + mEndDate = end; + updateView(); +} + +void KOWhatsNextView::showIncidences( const Incidence::List & ) +{ +} + +void KOWhatsNextView::changeIncidenceDisplay(Incidence *, int action) +{ + switch(action) { + case KOGlobals::INCIDENCEADDED: + case KOGlobals::INCIDENCEEDITED: + case KOGlobals::INCIDENCEDELETED: + updateView(); + break; + default: + kdDebug(5850) << "KOWhatsNextView::changeIncidenceDisplay(): Illegal action " << action << endl; + } +} + +void KOWhatsNextView::appendEvent( Incidence *ev, const QDateTime &start, + const QDateTime &end ) +{ + kdDebug(5850) << "KOWhatsNextView::appendEvent(): " << ev->uid() << endl; + + mText += ""; +// if (!ev->doesFloat()) { + if (ev->type()=="Event") { + Event *event = static_cast(ev); + QDateTime starttime( start ); + if ( !starttime.isValid() ) + starttime = event->dtStart(); + QDateTime endtime( end ); + if ( !endtime.isValid() ) + endtime = starttime.addSecs( + event->dtStart().secsTo( event->dtEnd() ) ); + + if ( starttime.date().daysTo( endtime.date() ) >= 1 ) { + mText += i18n("date from - to", "%1 - %2") + .arg( KGlobal::locale()->formatDateTime( starttime ) ) + .arg( KGlobal::locale()->formatDateTime( endtime ) ); + } else { + /*if (reply) */ + mText += i18n("date, from - to", "%1, %2 - %3") + .arg( KGlobal::locale()->formatDate( starttime.date(), true ) ) + .arg( KGlobal::locale()->formatTime( starttime.time() ) ) + .arg( KGlobal::locale()->formatTime( endtime.time() ) ); + } + } +// } + mText += "type()=="Event") mText += "href=\"event:"; + if (ev->type()=="Todo") mText += "href=\"todo:"; + mText += ev->uid() + "\">"; + mText += ev->summary(); + mText += "\n"; +} + +void KOWhatsNextView::appendTodo( Incidence *ev ) +{ + if ( mTodos.find( ev ) != mTodos.end() ) return; + + mTodos.append( ev ); + + mText += "
  • uid() + "\">"; + mText += ev->summary(); + mText += ""; + + if ( ev->type()=="Todo" ) { + Todo *todo = static_cast(ev); + if ( todo->hasDueDate() ) { + mText += i18n(" (Due: %1)") + .arg( (todo->doesFloat())?(todo->dtDueDateStr()):(todo->dtDueStr()) ); + } + } + mText += "
  • \n"; +} + +void KOWhatsNextView::showIncidence( const QString &uid ) +{ + kdDebug(5850) << "KOWhatsNextView::showIncidence(): " << uid << endl; + Incidence *incidence = 0; + + if ( uid.startsWith( "event://" ) ) { + incidence = calendar()->incidence( uid.mid( 8 ) ); + } else if ( uid.startsWith( "todo://" ) ) { + incidence = calendar()->incidence( uid.mid( 7 ) ); + } + if ( incidence ) emit showIncidenceSignal( incidence ); +} + +#include "kowhatsnextview.moc" -- cgit v1.2.1