00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include "todopluginwidget.h"
00018
00019 #include <qpe/config.h>
00020 #include <qpe/qcopenvelope_qws.h>
00021
00022 using namespace Opie::Ui;
00023 using namespace Opie;
00024
00025 TodolistPluginWidget::TodolistPluginWidget( QWidget *parent, const char* name )
00026 : QWidget( parent, name ) {
00027
00028 todo = 0l;
00029 layoutTodo = 0l;
00030 todoLabel = 0l;
00031
00032 if ( todo ) {
00033 delete todo;
00034 }
00035 todo = new OPimTodoAccess();
00036 todo->load();
00037
00038 if ( layoutTodo ) {
00039 delete layoutTodo;
00040 }
00041 layoutTodo = new QVBoxLayout( this );
00042 layoutTodo->setAutoAdd( true );
00043
00044 if ( todoLabel ) {
00045 delete todoLabel;
00046 }
00047 todoLabel = new OClickableLabel( this );
00048
00049 connect( todoLabel, SIGNAL( clicked() ), this, SLOT( startTodolist() ) );
00050
00051 readConfig();
00052 getTodo();
00053 }
00054
00055 TodolistPluginWidget::~TodolistPluginWidget() {
00056 delete todo;
00057 delete todoLabel;
00058 delete layoutTodo;
00059 }
00060
00061
00062 void TodolistPluginWidget::readConfig() {
00063 Config cfg( "todaytodoplugin" );
00064 cfg.setGroup( "config" );
00065 m_maxLinesTask = cfg.readNumEntry( "maxlinestask", 5 );
00066 m_maxCharClip = cfg.readNumEntry( "maxcharclip", 38 );
00067 }
00068
00069 void TodolistPluginWidget:: refresh() {
00070 todo->reload();
00071 getTodo();
00072 }
00073
00074 void TodolistPluginWidget::reinitialize() {
00075 readConfig();
00076 todo->reload();
00077 getTodo();
00078 }
00079
00083 void TodolistPluginWidget::getTodo() {
00084
00085
00086 QString output;
00087 QString tmpout;
00088 int count = 0;
00089 int ammount = 0;
00090
00091
00092 m_list = todo->sorted( true, OPimTodoAccess::Deadline, OPimTodoAccess::OnlyOverDue, 1);
00093
00094 for ( m_it = m_list.begin(); m_it != m_list.end(); ++m_it ) {
00095 if (!(*m_it).isCompleted() && ( ammount < m_maxLinesTask ) ) {
00096 QString desc = (*m_it).summary();
00097 if( desc.isEmpty() ) {
00098 desc = (*m_it).description();
00099 }
00100 tmpout += "<font color=#e00000><b>[" + QString("%1").arg((*m_it).priority() ) + "]" + desc.mid( 0, m_maxCharClip ) + "</b></font><br>";
00101 ammount++ ;
00102 }
00103 }
00104
00105
00106 m_list = todo->sorted( true, 1, OPimTodoAccess::DoNotShowCompleted, 1);
00107
00108 for ( m_it = m_list.begin(); m_it != m_list.end(); ++m_it ) {
00109 count +=1;
00110
00111
00112 if ( !(*m_it).isOverdue() && ( ammount < m_maxLinesTask ) ) {
00113 QString desc = (*m_it).summary();
00114 if( desc.isEmpty() ) {
00115 desc = (*m_it).description();
00116 }
00117 tmpout += "<b> [" + QString("%1").arg((*m_it).priority() ) + "] </b>" + desc.mid( 0, m_maxCharClip ) + "<br>";
00118 ammount++;
00119 }
00120 }
00121
00122 if ( count > 0 ) {
00123 if( count == 1 ) {
00124 output += QObject::tr( "There is <b> 1</b> active task: <br>" );
00125 } else {
00126 output += QObject::tr( "There are <b> %1</b> active tasks: <br>" ).arg( count );
00127 }
00128 output += tmpout;
00129 } else {
00130 output = QObject::tr( "No active tasks" );
00131 }
00132 todoLabel->setText( output );
00133 }
00134
00138 void TodolistPluginWidget::startTodolist() {
00139 QCopEnvelope e( "QPE/System", "execute(QString)" );
00140 e << QString( "todolist" );
00141 }