00001 #include "durationfocus.h"
00002
00003 #include <controldata.h>
00004 #include <domain/schedule.h>
00005 #include <tools/stringexception.h>
00006
00007 using namespace control;
00008
00009 QString DurationFocus::description() const
00010 {
00011 return "Duration-based focus";
00012 }
00013
00014 bool taskLessThan(domain::Task* left, domain::Task* right)
00015 {
00016 return left->schedule().duration() < right->schedule().duration();
00017 }
00018
00019 bool DurationFocus::applyFocus(QList<domain::Task*>* tasks)
00020 {
00021 QString message = "Please enter the minimum and maximum duration "
00022 "for the tasks to be shown.\n"
00023 "You can disable one or both of the limits by "
00024 "unchecking the check boxes.";
00025
00026 control::data::MinMaxDurationData input;
00027
00028 try
00029 {
00030 input = ui->getMinMaxDuration(message);
00031 }
00032 catch (tools::StringException& e)
00033 {
00034 ui->showError(e.message());
00035 return false;
00036 }
00037
00038 if (!input.processData)
00039 return false;
00040
00041
00042 qSort(tasks->begin(), tasks->end(), taskLessThan);
00043
00044
00045 if (input.minDurationSet)
00046 {
00047 while (!tasks->isEmpty() &&
00048 tasks->first()->schedule().duration() < input.minDuration)
00049 {
00050 tasks->removeFirst();
00051 }
00052 }
00053
00054
00055 if (input.maxDurationSet)
00056 {
00057 while (!tasks->isEmpty() &&
00058 tasks->last()->schedule().duration() > input.maxDuration)
00059 {
00060 tasks->removeLast();
00061 }
00062 }
00063
00064 return true;
00065 }
00066
00067 Q_EXPORT_PLUGIN2(focus_duration, DurationFocus)