00001 #include "deadlinefocus.h"
00002
00003 #include <domain/taskstates.h>
00004 #include <domain/schedule.h>
00005
00006 using namespace control;
00007
00008 QString DeadlineFocus::description() const
00009 {
00010 return "Deadline-based focus";
00011 }
00012
00013 bool taskLessThan(domain::Task* left, domain::Task* right)
00014 {
00015 return left->schedule().dueDate() < right->schedule().dueDate();
00016 }
00017
00018 bool DeadlineFocus::applyFocus(QList<domain::Task*>* tasks)
00019 {
00020 control::data::SimpleInputData<int> nbTasksInput =
00021 ui->getInt("Maximum number of tasks to be show", 10, 0);
00022
00023 if (!nbTasksInput.processData)
00024 return false;
00025
00026 int maxNbTasks = nbTasksInput.data;
00027
00028 if (maxNbTasks == 0)
00029 {
00030 tasks->clear();
00031 return true;
00032 }
00033
00034
00035 Q_FOREACH (domain::Task* task, *tasks)
00036 {
00037 if (!task->isAvailable())
00038 tasks->removeAll(task);
00039 }
00040
00041 if (tasks->isEmpty())
00042 return true;
00043
00044
00045 qSort(tasks->begin(), tasks->end(), taskLessThan);
00046
00047 while (tasks->size() > maxNbTasks)
00048 tasks->removeLast();
00049
00050 return true;
00051 }
00052
00053 Q_EXPORT_PLUGIN2(focus_deadline, DeadlineFocus)