summaryrefslogtreecommitdiff
path: root/core/pim/todo/taskeditorstatus.cpp
blob: 16351e0502e2a2dbec1a6f5554ad5adcce5f5e20 (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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
/*
               =.            This file is part of the OPIE Project
             .=l.            Copyright (c)  2002 <>
           .>+-=
 _;:,     .>    :=|.         This program is free software; you can
.> <`_,   >  .   <=          redistribute it and/or  modify it under
:`=1 )Y*s>-.--   :           the terms of the GNU General Public
.="- .-=="i,     .._         License as published by the Free Software
 - .   .-<_>     .<>         Foundation; either version 2 of the License,
     ._= =}       :          or (at your option) any later version.
    .%`+i>       _;_.
    .i_,=:_.      -<s.       This program is distributed in the hope that
     +  .  -:.       =       it will be useful,  but WITHOUT ANY WARRANTY;
    : ..    .:,     . . .    without even the implied warranty of
    =_        +     =;=|`    MERCHANTABILITY or FITNESS FOR A
  _.=:.       :    :=>`:     PARTICULAR PURPOSE. See the GNU
..}^=.=       =       ;      Library General Public License for more
++=   -.     .`     .:       details.
 :     =  ...= . :.=-
 -.   .:....=;==+<;          You should have received a copy of the GNU
  -_. . .   )=.  =           General Public License along with
    --        :-=`           this library; see the file COPYING.LIB.
                             If not, write to the Free Software Foundation,
                             Inc., 59 Temple Place - Suite 330,
                             Boston, MA 02111-1307, USA.

*/

#include "taskeditorstatus.h"

#include <opie2/opimmaintainer.h>
#include <opie2/opimstate.h>

#include <qpe/datebookmonth.h>

#include <qcheckbox.h>
#include <qcombobox.h>
#include <qlabel.h>
#include <qlayout.h>
#include <qwhatsthis.h>

// FIXME add the hack slots instead of setPopup!!!!
// drw you shouldn't have removed them

TaskEditorStatus::TaskEditorStatus( QWidget* parent,  const char* name, WFlags fl )
    : QWidget( parent, name, fl )
{
    QDate curDate = QDate::currentDate();
    m_start = m_comp = m_due = curDate;
    QString curDateStr = TimeString::longDateString( curDate );

    QVBoxLayout *vb = new QVBoxLayout( this );

    QScrollView *sv = new QScrollView( this );
    vb->addWidget( sv );
    sv->setResizePolicy( QScrollView::AutoOneFit );
    sv->setFrameStyle( QFrame::NoFrame );

    QWidget *container = new QWidget( sv->viewport() );
    sv->addChild( container );

    QGridLayout *layout = new QGridLayout( container, 7, 3, 4, 4 );

    // Status
    QLabel *label = new QLabel( tr( "Status:" ), container );
    layout->addWidget( label, 0, 0 );
    QWhatsThis::add( label, tr( "Click here to set the current status of this task." ) );
    cmbStatus = new QComboBox( FALSE, container );
    cmbStatus->insertItem( tr( "Started" ) );
    cmbStatus->insertItem( tr( "Postponed" ) );
    cmbStatus->insertItem( tr( "Finished" ) );
    cmbStatus->insertItem( tr( "Not started" ) );
    layout->addMultiCellWidget( cmbStatus, 0, 0, 1, 2 );
    QWhatsThis::add( cmbStatus, tr( "Click here to set the current status of this task." ) );

    // Progress
    label = new QLabel( tr( "Progress:" ), container );
    layout->addWidget( label, 1, 0 );
    QWhatsThis::add( label, tr( "Select progress made on this task here." ) );
    cmbProgress = new QComboBox( FALSE, container );
    cmbProgress->insertItem( tr( "0 %" ) );
    cmbProgress->insertItem( tr( "20 %" ) );
    cmbProgress->insertItem( tr( "40 %" ) );
    cmbProgress->insertItem( tr( "60 %" ) );
    cmbProgress->insertItem( tr( "80 %" ) );
    cmbProgress->insertItem( tr( "100 %" ) );
    layout->addMultiCellWidget( cmbProgress, 1, 1, 1, 2 );
    QWhatsThis::add( cmbProgress, tr( "Select progress made on this task here." ) );

    // Start date
    ckbStart = new QCheckBox( tr( "Start Date:" ), container );
    layout->addWidget( ckbStart, 2, 0 );
    QWhatsThis::add( ckbStart, tr( "Click here to set the date this task was started." ) );
    connect( ckbStart, SIGNAL( clicked() ), this, SLOT( slotStartChecked() ) );
    btnStart = new QPushButton( curDateStr, container );
    btnStart->setEnabled( FALSE );
    layout->addMultiCellWidget( btnStart, 2, 2, 1, 2 );
    QWhatsThis::add( btnStart, tr( "Click here to set the date this task was started." ) );
    QPopupMenu *popup = new QPopupMenu( this );
    m_startBook = new DateBookMonth( popup, 0, TRUE );
    popup->insertItem( m_startBook );
    btnStart->setPopup( popup );
    connect( m_startBook, SIGNAL( dateClicked(int,int,int) ),
             this, SLOT( slotStartChanged(int,int,int) ) );

    // Due date
    ckbDue = new QCheckBox( tr( "Due Date:" ), container );
    layout->addWidget( ckbDue, 3, 0 );
    QWhatsThis::add( ckbDue, tr( "Click here to set the date this task needs to be completed by." ) );
    connect( ckbDue, SIGNAL( clicked() ), this, SLOT( slotDueChecked() ) );
    btnDue = new QPushButton( curDateStr, container );
    btnDue->setEnabled( FALSE );
    layout->addMultiCellWidget( btnDue, 3, 3, 1, 2 );
    QWhatsThis::add( btnDue, tr( "Click here to set the date this task needs to be completed by." ) );
    popup = new QPopupMenu( this );
    m_dueBook = new DateBookMonth( popup, 0, TRUE );
    popup->insertItem( m_dueBook );
    btnDue->setPopup( popup );
    connect( m_dueBook, SIGNAL( dateClicked(int,int,int) ),
             this, SLOT( slotDueChanged(int,int,int) ) );

    // Completed
    ckbComp = new QCheckBox( tr( "Completed:" ), container );
    layout->addWidget( ckbComp, 4, 0 );
    QWhatsThis::add( ckbComp, tr( "Click here to mark this task as completed." ) );
    connect( ckbComp, SIGNAL( clicked() ), this, SLOT( slotCompChecked() ) );
    btnComp = new QPushButton( curDateStr, container );
    btnComp->setEnabled( FALSE );
    layout->addMultiCellWidget( btnComp, 4, 4, 1, 2 );
    QWhatsThis::add( btnComp, tr( "Click here to set the date this task was completed." ) );
    popup = new QPopupMenu( this );
    m_compBook = new DateBookMonth( popup, 0, TRUE );
    popup->insertItem( m_compBook );
    btnComp->setPopup( popup );
    connect( m_compBook, SIGNAL( dateClicked(int,int,int) ),
             this, SLOT( slotCompChanged(int,int,int) ) );

    QSpacerItem *spacer = new QSpacerItem( 5, 5, QSizePolicy::Minimum, QSizePolicy::MinimumExpanding );
    layout->addItem( spacer, 5, 0 );

    // Maintainer mode
#if 0
    label = new QLabel( tr( "Maintainer Mode:" ), container );
    layout->addWidget( label, 6, 0 );
    QWhatsThis::add( label, tr( "Click here to set the maintainer's role." ) );
    cmbMaintMode = new QComboBox( FALSE, container );
    cmbMaintMode->insertItem( tr( "Nothing" ) );
    cmbMaintMode->insertItem( tr( "Responsible" ) );
    cmbMaintMode->insertItem( tr( "Done By" ) );
    cmbMaintMode->insertItem( tr( "Coordinating" ) );
//    layout->addMultiCellWidget( cmbMaintMode, 6, 6, 1, 2 );
    QWhatsThis::add( cmbMaintMode, tr( "Click here to set the maintainer's role." ) );

    // Maintainer
    label = new QLabel( tr( "Maintainer:" ), container );
    layout->addWidget( label, 7, 0 );
    QWhatsThis::add( label, tr( "This is the name of the current task maintainer." ) );
    txtMaintainer = new QLabel( tr( "test" ), container );
    txtMaintainer->setTextFormat( QLabel::RichText );
    layout->addWidget( txtMaintainer, 7, 1 );
    QWhatsThis::add( txtMaintainer, tr( "This is the name of the current task maintainer." ) );
    tbtMaintainer = new QToolButton( container );
    tbtMaintainer->setPixmap( Resource::loadPixmap( "todo/more" ) );
//    layout->addWidget( tbtMaintainer, 7, 2 );
    QWhatsThis::add( tbtMaintainer, tr( "Click here to select the task maintainer." ) );
#endif
}

TaskEditorStatus::~TaskEditorStatus()
{
}

void TaskEditorStatus::load( const OPimTodo &todo )
{
    QDate date = QDate::currentDate();
    QString str = TimeString::longDateString( date );

    // Status
    int state = todo.hasState()? todo.state().state() : OPimState::NotStarted;
    if ( state == OPimState::Undefined )
        state = OPimState::NotStarted;
    cmbStatus->setCurrentItem( state );

    // Progress
    cmbProgress->setCurrentItem( todo.progress() / 20 );

    // Start date
    ckbStart->setChecked( todo.hasStartDate() );
    btnStart->setEnabled( todo.hasStartDate() );
    if ( todo.hasStartDate() )
    {
        m_start = todo.startDate();
        btnStart->setText( TimeString::longDateString( m_start ) );
    }
    else
        btnStart->setText( str );

    // Due date
    ckbDue->setChecked( todo.hasDueDate() );
    btnDue->setText( TimeString::longDateString( todo.dueDate() ) );
    btnDue->setEnabled( todo.hasDueDate() );
    m_due = todo.dueDate();

    // Completed
    ckbComp->setChecked( todo.isCompleted() );
    btnComp->setEnabled( todo.hasCompletedDate() );
    if ( todo.hasCompletedDate() )
    {
        m_comp = todo.completedDate();
        btnComp->setText( TimeString::longDateString( m_comp ) );
    }
    else
        btnComp->setText( str );

    // Maintainer Mode
#if 0
    state = todo.hasMaintainer() ? todo.maintainer().mode() : OPimMaintainer::Nothing;
    if ( state == OPimMaintainer::Undefined )
        state = OPimMaintainer::Nothing;
    cmbMaintMode->setCurrentItem( state );
#endif
    // Maintainer - not implemented yet
}

void TaskEditorStatus::save( OPimTodo &todo )
{
    QDate inval;

    // Status
    todo.setState( OPimState( cmbStatus->currentItem() ) );

    // Progress
    todo.setProgress( cmbProgress->currentItem() * 20 );

    // Start date
    if ( ckbStart->isChecked() )
    {
        todo.setStartDate( m_start );
    }
    else
        todo.setStartDate( inval );

    // Due date
    if ( ckbDue->isChecked() )
    {
        todo.setDueDate( m_due );
        todo.setHasDueDate( true );
    }
    else
        todo.setHasDueDate( false );

    // Completed
    todo.setCompleted( ckbComp->isChecked() );
    if ( ckbComp->isChecked() )
    {
        todo.setCompletedDate( m_comp );
    }
    else
        todo.setCompletedDate( inval );

#if 0
    // Maintainer mode - not implemented yet

    // Maintainer
    /* TODO - resolve name to uid.....*/
    todo.setMaintainer( OPimMaintainer( cmbMaintMode->currentItem(), -10 ) );
#endif
}

void TaskEditorStatus::slotStartChecked()
{
    btnStart->setEnabled( ckbStart->isChecked() );
}

void TaskEditorStatus::slotCompChecked()
{
    btnComp->setEnabled( ckbComp->isChecked() );
}

void TaskEditorStatus::slotDueChecked()
{
    btnDue->setEnabled( ckbDue->isChecked() );
}

void TaskEditorStatus::slotStartChanged(int y, int m, int d)
{
    m_start.setYMD( y, m, d );
    btnStart->setText( TimeString::longDateString( m_start ) );
}

void TaskEditorStatus::slotCompChanged(int y, int m, int d)
{
    m_comp.setYMD( y, m, d );
    btnComp->setText( TimeString::longDateString( m_comp ) );
}

void TaskEditorStatus::slotDueChanged(int y, int m, int d)
{
    m_due.setYMD( y, m, d );
    btnDue->setText( TimeString::longDateString( m_due ) );
    emit dueDateChanged( m_due );
}