<commit_before>// $Id$

#include <qlayout.h>
#include <qtextbrowser.h>
#include <qtextcodec.h>
#include <qfileinfo.h>
#include <qlabel.h>

#include <klocale.h>
#include <kdebug.h>
#include <kiconloader.h>
#include <kstddirs.h>
#include <kmessagebox.h>

#include "calendar.h"
#include "calprinter.h"
#include "calendarview.h"
#include "koeventviewerdialog.h"

#include "kowhatsnextview.h"
#include "kowhatsnextview.moc"

void WhatsNextTextBrowser::setSource(const QString& name)
{
  if (name.startsWith("event:")) {
    emit showIncidence(name);
    return;
  } else if (name.startsWith("todo:")) {
    emit showIncidence(name);
    return;
  } else {
    QTextBrowser::setSource(name);
  }
}

KOWhatsNextView::KOWhatsNextView(Calendar *calendar, QWidget *parent,
                                 const char *name)
  : KOBaseView(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 &)));

  mEventViewer = 0;

  QBoxLayout *topLayout = new QVBoxLayout(this);
  topLayout->addWidget(dateLabel);
  topLayout->addWidget(mView);
}

KOWhatsNextView::~KOWhatsNextView()
{
}

int KOWhatsNextView::maxDatesHint()
{
  return 0;
}

int KOWhatsNextView::currentDateCount()
{
  return 0;
}

QList<Incidence> KOWhatsNextView::getSelected()
{
  QList<Incidence> eventList;

  return eventList;
}


void KOWhatsNextView::printPreview(CalPrinter *calPrinter, const QDate &fd,
                               const QDate &td)
{
  calPrinter->preview(CalPrinter::Day, fd, td);
}

void KOWhatsNextView::updateView()
{
  mText = i18n("<h1>What's next?</h1>");

  QList<Event> events = mCalendar->getEvents(QDate::currentDate(),
                                             QDate::currentDate());
  if (events.count() > 0) {
    mText += i18n("<h2>Events:</h2>");
    mText += i18n("<table>");
    Event *ev = events.first();
    while(ev) {
      appendEvent(ev);
      ev = events.next();
    }
    mText += i18n("</table>");
  }

  QList<Todo> todos = mCalendar->getTodoList();
  if (todos.count() > 0) {  
    mText += i18n("<h2>Todo:</h2>");
    mText += i18n("<table>");
    Todo *ev = todos.first();
    while(ev) {
      if (ev->priority() == 1 ||
          (ev->hasDueDate() && ev->dtDue().date() == QDate::currentDate()))
        appendTodo(ev);
      ev = todos.next();
    }
    mText += i18n("</table>");
  }

  mView->setText(mText);
}

void KOWhatsNextView::selectDates(const QDateList dateList)
{
  updateView();
}

void KOWhatsNextView::selectEvents(QList<Event> eventList)
{
}

void KOWhatsNextView::changeEventDisplay(Event *event, int action)
{
  switch(action) {
    case CalendarView::EVENTADDED:
      break;
    case CalendarView::EVENTEDITED:
      break;
    case CalendarView::EVENTDELETED:
      break;
    default:
      kdDebug() << "KOWhatsNextView::changeEventDisplay(): Illegal action " << action << endl;
  }
}

void KOWhatsNextView::appendEvent(Event *ev)
{
  mText += "<tr><td><b>";
  if (!ev->doesFloat()) {
    mText += ev->dtStartTimeStr() + " - " + ev->dtEndTimeStr();
  }
  mText += "</b></td><td><a href=\"event:" + ev->VUID() + "\">";
  mText += ev->summary();
  mText += "</a></td></tr>";
}

void KOWhatsNextView::appendTodo(Todo *ev)
{
  mText += "<tr><td><b>";
  mText += QString::number(ev->priority());
  mText += "</b></td><td><a href=\"todo:" + ev->VUID() + "\">";
  mText += ev->summary();
  mText += "</a></td></tr>";
}

void KOWhatsNextView::createEventViewer()<commit_msg>Don't show completed todos.<commit_after>// $Id$

#include <qlayout.h>
#include <qtextbrowser.h>
#include <qtextcodec.h>
#include <qfileinfo.h>
#include <qlabel.h>

#include <klocale.h>
#include <kdebug.h>
#include <kiconloader.h>
#include <kstddirs.h>
#include <kmessagebox.h>

#include "calendar.h"
#include "calprinter.h"
#include "calendarview.h"
#include "koeventviewerdialog.h"

#include "kowhatsnextview.h"
#include "kowhatsnextview.moc"

void WhatsNextTextBrowser::setSource(const QString& name)
{
  if (name.startsWith("event:")) {
    emit showIncidence(name);
    return;
  } else if (name.startsWith("todo:")) {
    emit showIncidence(name);
    return;
  } else {
    QTextBrowser::setSource(name);
  }
}

KOWhatsNextView::KOWhatsNextView(Calendar *calendar, QWidget *parent,
                                 const char *name)
  : KOBaseView(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 &)));

  mEventViewer = 0;

  QBoxLayout *topLayout = new QVBoxLayout(this);
  topLayout->addWidget(dateLabel);
  topLayout->addWidget(mView);
}

KOWhatsNextView::~KOWhatsNextView()
{
}

int KOWhatsNextView::maxDatesHint()
{
  return 0;
}

int KOWhatsNextView::currentDateCount()
{
  return 0;
}

QList<Incidence> KOWhatsNextView::getSelected()
{
  QList<Incidence> eventList;

  return eventList;
}


void KOWhatsNextView::printPreview(CalPrinter *calPrinter, const QDate &fd,
                               const QDate &td)
{
  calPrinter->preview(CalPrinter::Day, fd, td);
}

void KOWhatsNextView::updateView()
{
  mText = i18n("<h1>What's next?</h1>");

  QList<Event> events = mCalendar->getEvents(QDate::currentDate(),
                                             QDate::currentDate());
  if (events.count() > 0) {
    mText += i18n("<h2>Events:</h2>");
    mText += i18n("<table>");
    Event *ev = events.first();
    while(ev) {
      appendEvent(ev);
      ev = events.next();
    }
    mText += i18n("</table>");
  }

  QList<Todo> todos = mCalendar->getTodoList();
  if (todos.count() > 0) {  
    mText += i18n("<h2>Todo:</h2>");
    mText += i18n("<ul>");
    Todo *todo = todos.first();
    while(todo) {
      if (!todo->isCompleted() && (todo->priority() == 1 ||
          (todo->hasDueDate() && todo->dtDue().date() == QDate::currentDate())))
        appendTodo(todo);
      todo = todos.next();
    }
    mText += i18n("</ul>");
  }

  mView->setText(mText);
}

void KOWhatsNextView::selectDates(const QDateList dateList)
{
  updateView();
}

void KOWhatsNextView::selectEvents(QList<Event> eventList)
{
}

void KOWhatsNextView::changeEventDisplay(Event *event, int action)
{
  switch(action) {
    case CalendarView::EVENTADDED:
      break;
    case CalendarView::EVENTEDITED:
      break;
    case CalendarView::EVENTDELETED:
      break;
    default:
      kdDebug() << "KOWhatsNextView::changeEventDisplay(): Illegal action " << action << endl;
  }
}

void KOWhatsNextView::appendEvent(Event *ev)
{
  mText += "<tr><td><b>";
  if (!ev->doesFloat()) {
    mText += ev->dtStartTimeStr() + " - " + ev->dtEndTimeStr();
  }
  mText += "</b></td><td><a href=\"event:" + ev->VUID() + "\">";
  mText += ev->summary();
  mText += "</a></td></tr>";
}

void KOWhatsNextView::appendTodo(Todo *ev)
{
  mText += "<li><a href=\"todo:" + ev->VUID() + "\">";
  mText += ev->summary();
  mText += "</a></li>";
}

void KOWhatsNextView::createEventViewer()
{'fraction_non_alphanumeric': 0.18221614227086183, 'fraction_numerical': 0.007387140902872777, 'mean_word_length': 3.8035479632063076, 'pattern_counts': {'":': 0, '<': 99, '<?xml version=': 0, '>': 131, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2737577', 'n_tokens_mistral': 2743, 'n_tokens_neox': 2648, 'n_words': 449}