/* * 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 #include #include #include #include #include #include #include #include TodolistPluginWidget::TodolistPluginWidget( QWidget *parent, const char* name) : QWidget(parent, name ) { todoLabel= 0l; todo = 0l; if ( todo ) { delete todo; } todo = new ToDoDB(); readConfig(); m_maxCharClip = 36; getTodo(); } TodolistPluginWidget::~TodolistPluginWidget() { delete todo; } void TodolistPluginWidget::readConfig() { Config cfg( "todaytodolistplugin" ); cfg.setGroup( "config" ); m_maxLinesTask = cfg.readNumEntry( "maxlinestask", 5 ); } /** * 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 overDueList = todo->overDue(); qBubbleSort(overDueList); for ( QValueList::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 += "-" + desc.mid(0, m_maxCharClip) + "
"; ammount++; } } // get total number of still open todos QValueList openTodo = todo->rawToDos(); qBubbleSort( openTodo ); for ( QValueList::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 += "-" + desc.mid(0, m_maxCharClip) + "
"; ammount++; } } } if ( count > 0 ) { if( count == 1 ) { output += QObject::tr( "There is 1 active task:
" ); } else { output += QObject::tr( "There are %1 active tasks:
" ).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"); }