summaryrefslogtreecommitdiff
path: root/core/pim/today/plugins/todolist/todopluginwidget.cpp
blob: d793aae0576105d065676c6a10dfd99ef82c47be (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/*
 * todopluginwidget.cpp
 *
 * copyright   : (c) 2002 by Maximilian Reiß
 * email       : harlekin@handhelds.org
 *
 */
/***************************************************************************
 *                                                                         *
 *   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.                                   *
 *                                                                         *
 ***************************************************************************/

#include "todopluginwidget.h"

#include <qvaluelist.h>
#include <qtl.h>
#include <qstring.h>
#include <qscrollview.h>
#include <qobject.h>
#include <qlayout.h>

#include <qpe/config.h>
#include <qpe/timestring.h>
#include <qpe/qcopenvelope_qws.h>

TodolistPluginWidget::TodolistPluginWidget( QWidget *parent,  const char* name )
    : QWidget( parent, name ) {

    todoLabel= 0l;
    todo = 0l;

    if ( todo ) {
        delete todo;
    }
    todo = new ToDoDB();

    readConfig();
    getTodo();
}

TodolistPluginWidget::~TodolistPluginWidget() {
    delete todo;
}


void TodolistPluginWidget::readConfig() {
    Config cfg( "todaytodoplugin" );
    cfg.setGroup( "config" );
    m_maxLinesTask = cfg.readNumEntry( "maxlinestask", 5 );
    m_maxCharClip =  cfg.readNumEntry( "maxcharclip", 38 );
}


/**
 * Get the todos
 */
void TodolistPluginWidget::getTodo() {

    QVBoxLayout* layoutTodo = new QVBoxLayout( this );

    if ( todoLabel ) {
        delete todoLabel;
    }

    todoLabel = new OClickableLabel( this );
    todoLabel->setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum ) );
    connect( todoLabel, SIGNAL( clicked() ), this, SLOT( startTodolist() ) );

    QString output;
    QString tmpout;
    int count = 0;
    int ammount = 0;

    // get overdue todos first
    QValueList<ToDoEvent> overDueList = todo->overDue();
    qBubbleSort( overDueList );
    for ( QValueList<ToDoEvent>::Iterator it = overDueList.begin();
          it != overDueList.end(); ++it ) {
        if (!(*it).isCompleted() && ( ammount < m_maxLinesTask ) ) {
            QString desc = (*it).summary();
            if( desc.isEmpty() ) {
                desc = (*it).description();
            }
            tmpout += "<font color=#e00000><b>-" + desc.mid( 0, m_maxCharClip ) + "</b></font><br>";
            ammount++;
        }
    }

    // get total number of still open todos
    QValueList<ToDoEvent> openTodo = todo->rawToDos();
    qBubbleSort( openTodo );
    for ( QValueList<ToDoEvent>::Iterator it = openTodo.begin();
          it != openTodo.end(); ++it ) {
        if ( !(*it).isCompleted() ){
            count +=1;
            // not the overdues, we allready got them, and not if we are
            // over the maxlines
            if ( !(*it).isOverdue() && ( ammount < m_maxLinesTask ) ) {
                QString desc = (*it).summary();
                if( desc.isEmpty() ) {
                    desc = (*it).description();
                }
                tmpout += "<b>-</b>" + desc.mid( 0, m_maxCharClip ) + "<br>";
                ammount++;
            }
        }
    }


    if ( count > 0 ) {
        if( count == 1 ) {
            output += QObject::tr( "There is <b> 1</b> active task:  <br>" );
        } else {
            output += QObject::tr( "There are <b> %1</b> active tasks: <br>" ).arg( count );
        }
        output += tmpout;
    } else {
        output = QObject::tr( "No active tasks" );
    }
    todoLabel->setText( output );
    layoutTodo->addWidget( todoLabel );
}

/**
 * start the todolist
 */
void TodolistPluginWidget::startTodolist() {
    QCopEnvelope e( "QPE/System", "execute(QString)" );
    e << QString( "todolist" );
}