summaryrefslogtreecommitdiff
authorzecke <zecke>2003-03-14 08:20:59 (UTC)
committer zecke <zecke>2003-03-14 08:20:59 (UTC)
commit7e04934c4b7b9f8ad0d74d2da1c7c1273d9fe1d4 (patch) (unidiff)
tree9d8cb73a1b6013ab409b496cf2b99503f239c0c9
parent08094624777d78bcd09f6ba6e2157599960ef7f3 (diff)
downloadopie-7e04934c4b7b9f8ad0d74d2da1c7c1273d9fe1d4.zip
opie-7e04934c4b7b9f8ad0d74d2da1c7c1273d9fe1d4.tar.gz
opie-7e04934c4b7b9f8ad0d74d2da1c7c1273d9fe1d4.tar.bz2
Do not crash when trying to edit and there is no data
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/pim/todo/mainwindow.cpp3
-rw-r--r--core/pim/todo/tableview.cpp1
2 files changed, 3 insertions, 1 deletions
diff --git a/core/pim/todo/mainwindow.cpp b/core/pim/todo/mainwindow.cpp
index 7810285..58981ca 100644
--- a/core/pim/todo/mainwindow.cpp
+++ b/core/pim/todo/mainwindow.cpp
@@ -1,818 +1,819 @@
1/* 1/*
2               =. This file is part of the OPIE Project 2               =. This file is part of the OPIE Project
3             .=l. Copyright (c) 2002 <> 3             .=l. Copyright (c) 2002 <>
4           .>+-= 4           .>+-=
5 _;:,     .>    :=|. This program is free software; you can 5 _;:,     .>    :=|. This program is free software; you can
6.> <`_,   >  .   <= redistribute it and/or modify it under 6.> <`_,   >  .   <= redistribute it and/or modify it under
7:`=1 )Y*s>-.--   : the terms of the GNU General Public 7:`=1 )Y*s>-.--   : the terms of the GNU General Public
8.="- .-=="i,     .._ License as published by the Free Software 8.="- .-=="i,     .._ License as published by the Free Software
9 - .   .-<_>     .<> Foundation; either version 2 of the License, 9 - .   .-<_>     .<> Foundation; either version 2 of the License,
10     ._= =}       : or (at your option) any later version. 10     ._= =}       : or (at your option) any later version.
11    .%`+i>       _;_. 11    .%`+i>       _;_.
12    .i_,=:_.      -<s. This program is distributed in the hope that 12    .i_,=:_.      -<s. This program is distributed in the hope that
13     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 13     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
14    : ..    .:,     . . . without even the implied warranty of 14    : ..    .:,     . . . without even the implied warranty of
15    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 15    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
16  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 16  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
17..}^=.=       =       ; Library General Public License for more 17..}^=.=       =       ; Library General Public License for more
18++=   -.     .`     .: details. 18++=   -.     .`     .: details.
19 :     =  ...= . :.=- 19 :     =  ...= . :.=-
20 -.   .:....=;==+<; You should have received a copy of the GNU 20 -.   .:....=;==+<; You should have received a copy of the GNU
21  -_. . .   )=.  = General Public License along with 21  -_. . .   )=.  = General Public License along with
22    --        :-=` this library; see the file COPYING.LIB. 22    --        :-=` this library; see the file COPYING.LIB.
23 If not, write to the Free Software Foundation, 23 If not, write to the Free Software Foundation,
24 Inc., 59 Temple Place - Suite 330, 24 Inc., 59 Temple Place - Suite 330,
25 Boston, MA 02111-1307, USA. 25 Boston, MA 02111-1307, USA.
26 26
27*/ 27*/
28 28
29#include <unistd.h> 29#include <unistd.h>
30 30
31#include <qmenubar.h> 31#include <qmenubar.h>
32#include <qmessagebox.h> 32#include <qmessagebox.h>
33#include <qtoolbar.h> 33#include <qtoolbar.h>
34#include <qpopupmenu.h> 34#include <qpopupmenu.h>
35#include <qwidgetstack.h> 35#include <qwidgetstack.h>
36#include <qaction.h> 36#include <qaction.h>
37#include <qtimer.h> 37#include <qtimer.h>
38#include <qvbox.h> 38#include <qvbox.h>
39#include <qlineedit.h> 39#include <qlineedit.h>
40#include <qwhatsthis.h> 40#include <qwhatsthis.h>
41 41
42#include <qpe/applnk.h> 42#include <qpe/applnk.h>
43#include <qpe/config.h> 43#include <qpe/config.h>
44#include <qpe/ir.h> 44#include <qpe/ir.h>
45#include <qpe/resource.h> 45#include <qpe/resource.h>
46#include <qpe/qpemessagebox.h> 46#include <qpe/qpemessagebox.h>
47#include <qpe/qpetoolbar.h> 47#include <qpe/qpetoolbar.h>
48 48
49#include <opie/orecur.h> 49#include <opie/orecur.h>
50#include <opie/otodoaccessvcal.h> 50#include <opie/otodoaccessvcal.h>
51 51
52#include "quickeditimpl.h" 52#include "quickeditimpl.h"
53#include "todotemplatemanager.h" 53#include "todotemplatemanager.h"
54#include "templateeditor.h" 54#include "templateeditor.h"
55#include "tableview.h" 55#include "tableview.h"
56 56
57#include "textviewshow.h" 57#include "textviewshow.h"
58#include "todoeditor.h" 58#include "todoeditor.h"
59#include "mainwindow.h" 59#include "mainwindow.h"
60 60
61 61
62using namespace Todo; 62using namespace Todo;
63 63
64MainWindow::MainWindow( QWidget* parent, 64MainWindow::MainWindow( QWidget* parent,
65 const char* name ) 65 const char* name )
66 : OPimMainWindow( "Todolist", parent, name, WType_TopLevel | WStyle_ContextHelp ) 66 : OPimMainWindow( "Todolist", parent, name, WType_TopLevel | WStyle_ContextHelp )
67{ 67{
68 m_syncing = false; 68 m_syncing = false;
69 m_counter = 0; 69 m_counter = 0;
70 m_tempManager = new TemplateManager(); 70 m_tempManager = new TemplateManager();
71 m_tempManager->load(); 71 m_tempManager->load();
72 72
73 initUI(); 73 initUI();
74 initConfig(); 74 initConfig();
75 initViews(); 75 initViews();
76 initActions(); 76 initActions();
77 initEditor(); 77 initEditor();
78 initShow(); 78 initShow();
79 initTemplate(); 79 initTemplate();
80 80
81 populateTemplates(); 81 populateTemplates();
82 raiseCurrentView(); 82 raiseCurrentView();
83 QTimer::singleShot(0, this, SLOT(populateCategories() ) ); 83 QTimer::singleShot(0, this, SLOT(populateCategories() ) );
84} 84}
85void MainWindow::initTemplate() { 85void MainWindow::initTemplate() {
86 m_curTempEd = new TemplateEditor( this, templateManager() ); 86 m_curTempEd = new TemplateEditor( this, templateManager() );
87} 87}
88void MainWindow::initActions() { 88void MainWindow::initActions() {
89 89
90 // Data menu 90 // Data menu
91 m_edit->insertItem(QWidget::tr("New from template"), m_template, 91 m_edit->insertItem(QWidget::tr("New from template"), m_template,
92 -1, 0 ); 92 -1, 0 );
93 93
94 QAction* a = new QAction( QWidget::tr("New Task" ), Resource::loadPixmap( "new" ), 94 QAction* a = new QAction( QWidget::tr("New Task" ), Resource::loadPixmap( "new" ),
95 QString::null, 0, this, 0 ); 95 QString::null, 0, this, 0 );
96 connect(a, SIGNAL( activated() ), 96 connect(a, SIGNAL( activated() ),
97 this, SLOT( slotNew() ) ); 97 this, SLOT( slotNew() ) );
98 a->setWhatsThis( QWidget::tr( "Click here to create a new task." ) ); 98 a->setWhatsThis( QWidget::tr( "Click here to create a new task." ) );
99 a->addTo(m_tool ); 99 a->addTo(m_tool );
100 a->addTo(m_edit ); 100 a->addTo(m_edit );
101 101
102 a = new QAction( QWidget::tr("Edit Task"), Resource::loadIconSet( "edit" ), 102 a = new QAction( QWidget::tr("Edit Task"), Resource::loadIconSet( "edit" ),
103 QString::null, 0, this, 0 ); 103 QString::null, 0, this, 0 );
104 connect(a, SIGNAL(activated() ), 104 connect(a, SIGNAL(activated() ),
105 this, SLOT( slotEdit() ) ); 105 this, SLOT( slotEdit() ) );
106 a->setWhatsThis( QWidget::tr( "Click here to modify the current task." ) ); 106 a->setWhatsThis( QWidget::tr( "Click here to modify the current task." ) );
107 a->addTo( m_tool ); 107 a->addTo( m_tool );
108 a->addTo( m_edit ); 108 a->addTo( m_edit );
109 m_editAction = a; 109 m_editAction = a;
110 110
111 a = new QAction( QString::null, QWidget::tr("View Task"), 0, this, 0 ); 111 a = new QAction( QString::null, QWidget::tr("View Task"), 0, this, 0 );
112 connect(a, SIGNAL( activated() ), 112 connect(a, SIGNAL( activated() ),
113 this, SLOT( slotShowDetails() ) ); 113 this, SLOT( slotShowDetails() ) );
114 a->addTo( m_edit ); 114 a->addTo( m_edit );
115 115
116 m_edit->insertSeparator(); 116 m_edit->insertSeparator();
117 117
118 a = new QAction( QWidget::tr("Delete..."), Resource::loadIconSet( "trash" ), 118 a = new QAction( QWidget::tr("Delete..."), Resource::loadIconSet( "trash" ),
119 QString::null, 0, this, 0 ); 119 QString::null, 0, this, 0 );
120 connect(a, SIGNAL(activated() ), 120 connect(a, SIGNAL(activated() ),
121 this, SLOT(slotDelete() ) ); 121 this, SLOT(slotDelete() ) );
122 a->setWhatsThis( QWidget::tr( "Click here to remove the current task." ) ); 122 a->setWhatsThis( QWidget::tr( "Click here to remove the current task." ) );
123 a->addTo( m_tool ); 123 a->addTo( m_tool );
124 a->addTo( m_edit ); 124 a->addTo( m_edit );
125 m_deleteAction = a; 125 m_deleteAction = a;
126 126
127 a = new QAction( QString::null, QWidget::tr("Delete all..."), 0, this, 0 ); 127 a = new QAction( QString::null, QWidget::tr("Delete all..."), 0, this, 0 );
128 connect(a, SIGNAL( activated() ), 128 connect(a, SIGNAL( activated() ),
129 this, SLOT( slotDeleteAll() ) ); 129 this, SLOT( slotDeleteAll() ) );
130 a->addTo(m_edit ); 130 a->addTo(m_edit );
131 m_deleteAllAction = a; 131 m_deleteAllAction = a;
132 132
133 a = new QAction( QString::null, QWidget::tr("Delete completed"), 133 a = new QAction( QString::null, QWidget::tr("Delete completed"),
134 0, this, 0 ); 134 0, this, 0 );
135 connect(a, SIGNAL( activated() ), 135 connect(a, SIGNAL( activated() ),
136 this, SLOT( slotDeleteCompleted() ) ); 136 this, SLOT( slotDeleteCompleted() ) );
137 a->addTo(m_edit ); 137 a->addTo(m_edit );
138 a->setEnabled( TRUE ); 138 a->setEnabled( TRUE );
139 m_deleteCompleteAction = a; 139 m_deleteCompleteAction = a;
140 140
141 m_edit->insertSeparator(); 141 m_edit->insertSeparator();
142 142
143 a = new QAction( QString::null, QWidget::tr("Duplicate"), 0, this, 0 ); 143 a = new QAction( QString::null, QWidget::tr("Duplicate"), 0, this, 0 );
144 connect(a, SIGNAL( activated() ), 144 connect(a, SIGNAL( activated() ),
145 this, SLOT( slotDuplicate() ) ); 145 this, SLOT( slotDuplicate() ) );
146 a->addTo(m_edit ); 146 a->addTo(m_edit );
147 m_duplicateAction = a; 147 m_duplicateAction = a;
148 148
149 m_edit->insertSeparator(); 149 m_edit->insertSeparator();
150 150
151 if ( Ir::supported() ) { 151 if ( Ir::supported() ) {
152 a = new QAction( QWidget::tr( "Beam" ), Resource::loadPixmap( "beam" ), QString::null, 0, this, 0 ); 152 a = new QAction( QWidget::tr( "Beam" ), Resource::loadPixmap( "beam" ), QString::null, 0, this, 0 );
153 connect( a, SIGNAL( activated() ), this, SLOT( slotBeam() ) ); 153 connect( a, SIGNAL( activated() ), this, SLOT( slotBeam() ) );
154 a->setWhatsThis( QWidget::tr( "Click here to send the current task to another device." ) ); 154 a->setWhatsThis( QWidget::tr( "Click here to send the current task to another device." ) );
155 a->addTo( m_edit ); 155 a->addTo( m_edit );
156 a->addTo( m_tool ); 156 a->addTo( m_tool );
157 } 157 }
158 158
159 // Options menu 159 // Options menu
160 a = new QAction( QWidget::tr("Find"), Resource::loadIconSet( "mag" ), 160 a = new QAction( QWidget::tr("Find"), Resource::loadIconSet( "mag" ),
161 QString::null, 0, this, 0 ); 161 QString::null, 0, this, 0 );
162 connect(a, SIGNAL( activated() ), this, SLOT( slotFind() ) ); 162 connect(a, SIGNAL( activated() ), this, SLOT( slotFind() ) );
163 a->addTo( m_options ); 163 a->addTo( m_options );
164 m_findAction = a; 164 m_findAction = a;
165 165
166 m_options->insertSeparator(); 166 m_options->insertSeparator();
167 167
168 m_completedAction = new QAction( QString::null, QWidget::tr("Show completed tasks"), 168 m_completedAction = new QAction( QString::null, QWidget::tr("Show completed tasks"),
169 0, this, 0, TRUE ); 169 0, this, 0, TRUE );
170 m_completedAction->addTo( m_options ); 170 m_completedAction->addTo( m_options );
171 m_completedAction->setOn( showCompleted() ); 171 m_completedAction->setOn( showCompleted() );
172 connect(m_completedAction, SIGNAL( toggled(bool) ), this, SLOT(slotShowCompleted(bool) ) ); 172 connect(m_completedAction, SIGNAL( toggled(bool) ), this, SLOT(slotShowCompleted(bool) ) );
173 173
174 a = new QAction( QString::null, QWidget::tr("Show only over-due tasks"), 174 a = new QAction( QString::null, QWidget::tr("Show only over-due tasks"),
175 0, this, 0, TRUE ); 175 0, this, 0, TRUE );
176 a->addTo( m_options ); 176 a->addTo( m_options );
177 a->setOn( showOverDue() ); 177 a->setOn( showOverDue() );
178 connect(a, SIGNAL(toggled(bool)), this, SLOT(slotShowDue(bool) ) ); 178 connect(a, SIGNAL(toggled(bool)), this, SLOT(slotShowDue(bool) ) );
179 179
180 m_showDeadLineAction = new QAction( QString::null, QWidget::tr("Show task deadlines"), 180 m_showDeadLineAction = new QAction( QString::null, QWidget::tr("Show task deadlines"),
181 0, this, 0, TRUE ); 181 0, this, 0, TRUE );
182 m_showDeadLineAction->addTo( m_options ); 182 m_showDeadLineAction->addTo( m_options );
183 m_showDeadLineAction->setOn( showDeadline() ); 183 m_showDeadLineAction->setOn( showDeadline() );
184 connect(m_showDeadLineAction, SIGNAL(toggled(bool) ), this, SLOT( slotShowDeadLine( bool ) ) ); 184 connect(m_showDeadLineAction, SIGNAL(toggled(bool) ), this, SLOT( slotShowDeadLine( bool ) ) );
185 185
186 m_showQuickTaskAction = new QAction( QString::null, QWidget::tr("Show quick task bar"), 186 m_showQuickTaskAction = new QAction( QString::null, QWidget::tr("Show quick task bar"),
187 0, this, 0, TRUE ); 187 0, this, 0, TRUE );
188 m_showQuickTaskAction->addTo( m_options ); 188 m_showQuickTaskAction->addTo( m_options );
189 m_showQuickTaskAction->setOn( showQuickTask() ); 189 m_showQuickTaskAction->setOn( showQuickTask() );
190 connect(m_showQuickTaskAction, SIGNAL( toggled(bool) ), this, SLOT(slotShowQuickTask(bool) ) ); 190 connect(m_showQuickTaskAction, SIGNAL( toggled(bool) ), this, SLOT(slotShowQuickTask(bool) ) );
191 191
192 m_options->insertSeparator(); 192 m_options->insertSeparator();
193 193
194 m_bar->insertItem( QWidget::tr("Data") ,m_edit ); 194 m_bar->insertItem( QWidget::tr("Data") ,m_edit );
195 m_bar->insertItem( QWidget::tr("Category"), m_catMenu ); 195 m_bar->insertItem( QWidget::tr("Category"), m_catMenu );
196 m_bar->insertItem( QWidget::tr("Options"), m_options ); 196 m_bar->insertItem( QWidget::tr("Options"), m_options );
197 197
198 m_curQuick = new QuickEditImpl( this, m_quicktask ); 198 m_curQuick = new QuickEditImpl( this, m_quicktask );
199 addToolBar( (QPEToolBar *)m_curQuick->widget(), QWidget::tr( "QuickEdit" ), QMainWindow::Top, TRUE ); 199 addToolBar( (QPEToolBar *)m_curQuick->widget(), QWidget::tr( "QuickEdit" ), QMainWindow::Top, TRUE );
200 m_curQuick->signal()->connect( this, SLOT(slotQuickEntered() ) ); 200 m_curQuick->signal()->connect( this, SLOT(slotQuickEntered() ) );
201 201
202} 202}
203/* m_curCat from Config */ 203/* m_curCat from Config */
204void MainWindow::initConfig() { 204void MainWindow::initConfig() {
205 Config config( "todo" ); 205 Config config( "todo" );
206 config.setGroup( "View" ); 206 config.setGroup( "View" );
207 m_completed = config.readBoolEntry( "ShowComplete", TRUE ); 207 m_completed = config.readBoolEntry( "ShowComplete", TRUE );
208 m_curCat = config.readEntry( "Category", QString::null ); 208 m_curCat = config.readEntry( "Category", QString::null );
209 m_deadline = config.readBoolEntry( "ShowDeadLine", TRUE); 209 m_deadline = config.readBoolEntry( "ShowDeadLine", TRUE);
210 m_overdue = config.readBoolEntry("ShowOverDue", FALSE ); 210 m_overdue = config.readBoolEntry("ShowOverDue", FALSE );
211 m_quicktask = config.readBoolEntry("ShowQuickTask", TRUE); 211 m_quicktask = config.readBoolEntry("ShowQuickTask", TRUE);
212} 212}
213void MainWindow::initUI() { 213void MainWindow::initUI() {
214 m_stack = new QWidgetStack(this, "main stack"); 214 m_stack = new QWidgetStack(this, "main stack");
215 setCentralWidget( m_stack ); 215 setCentralWidget( m_stack );
216 216
217 setToolBarsMovable( FALSE ); 217 setToolBarsMovable( FALSE );
218 218
219 m_tool = new QPEToolBar( this ); 219 m_tool = new QPEToolBar( this );
220 m_tool->setHorizontalStretchable( TRUE ); 220 m_tool->setHorizontalStretchable( TRUE );
221 221
222 m_bar = new QMenuBar( m_tool ); 222 m_bar = new QMenuBar( m_tool );
223 223
224 /** QPopupMenu */ 224 /** QPopupMenu */
225 m_edit = new QPopupMenu( this ); 225 m_edit = new QPopupMenu( this );
226 m_options = new QPopupMenu( this ); 226 m_options = new QPopupMenu( this );
227 m_catMenu = new QPopupMenu( this ); 227 m_catMenu = new QPopupMenu( this );
228 m_template = new QPopupMenu( this ); 228 m_template = new QPopupMenu( this );
229 229
230 m_catMenu->setCheckable( TRUE ); 230 m_catMenu->setCheckable( TRUE );
231 m_template->setCheckable( TRUE ); 231 m_template->setCheckable( TRUE );
232 232
233 connect(m_catMenu, SIGNAL(activated(int) ), 233 connect(m_catMenu, SIGNAL(activated(int) ),
234 this, SLOT(setCategory(int) ) ); 234 this, SLOT(setCategory(int) ) );
235 connect(m_template, SIGNAL(activated(int) ), 235 connect(m_template, SIGNAL(activated(int) ),
236 this, SLOT(slotNewFromTemplate(int) ) ); 236 this, SLOT(slotNewFromTemplate(int) ) );
237} 237}
238void MainWindow::initViews() { 238void MainWindow::initViews() {
239 TableView* tableView = new TableView( this, m_stack ); 239 TableView* tableView = new TableView( this, m_stack );
240 QWhatsThis::add( tableView, QWidget::tr( "This is a listing of all current tasks.\n\nThe list displays the following information:\n1. Completed - A green checkmark indicates task is completed. Click here to complete a task.\n2. Priority - a graphical representation of task priority. Double-click here to modify.\n3. Description - description of task. Click here to select the task.\n4. Deadline - shows when task is due. This column can be shown or hidden by selecting Options->'Show task deadlines' from the menu above." ) ); 240 QWhatsThis::add( tableView, QWidget::tr( "This is a listing of all current tasks.\n\nThe list displays the following information:\n1. Completed - A green checkmark indicates task is completed. Click here to complete a task.\n2. Priority - a graphical representation of task priority. Double-click here to modify.\n3. Description - description of task. Click here to select the task.\n4. Deadline - shows when task is due. This column can be shown or hidden by selecting Options->'Show task deadlines' from the menu above." ) );
241 m_stack->addWidget( tableView, m_counter++ ); 241 m_stack->addWidget( tableView, m_counter++ );
242 m_views.append( tableView ); 242 m_views.append( tableView );
243 m_curView = tableView; 243 m_curView = tableView;
244 connectBase( tableView ); 244 connectBase( tableView );
245 /* add QString type + QString configname to 245 /* add QString type + QString configname to
246 * the View menu 246 * the View menu
247 * and subdirs for multiple views 247 * and subdirs for multiple views
248 */ 248 */
249} 249}
250void MainWindow::initEditor() { 250void MainWindow::initEditor() {
251 m_curEdit = new Editor(); 251 m_curEdit = new Editor();
252} 252}
253void MainWindow::initShow() { 253void MainWindow::initShow() {
254 m_curShow = new TextViewShow(this, this); 254 m_curShow = new TextViewShow(this, this);
255 m_stack->addWidget( m_curShow->widget() , m_counter++ ); 255 m_stack->addWidget( m_curShow->widget() , m_counter++ );
256} 256}
257MainWindow::~MainWindow() { 257MainWindow::~MainWindow() {
258 delete templateManager(); 258 delete templateManager();
259} 259}
260void MainWindow::connectBase( ViewBase* ) { 260void MainWindow::connectBase( ViewBase* ) {
261 // once templates and signals mix we'll use it again 261 // once templates and signals mix we'll use it again
262} 262}
263QPopupMenu* MainWindow::contextMenu( int , bool recur ) { 263QPopupMenu* MainWindow::contextMenu( int , bool recur ) {
264 QPopupMenu* menu = new QPopupMenu(); 264 QPopupMenu* menu = new QPopupMenu();
265 265
266 m_editAction->addTo( menu ); 266 m_editAction->addTo( menu );
267 m_deleteAction->addTo( menu ); 267 m_deleteAction->addTo( menu );
268 m_duplicateAction->addTo( menu ); 268 m_duplicateAction->addTo( menu );
269 269
270 menu->insertSeparator(); 270 menu->insertSeparator();
271 271
272 /* 272 /*
273 * if this event recurs we allow 273 * if this event recurs we allow
274 * to detach it. 274 * to detach it.
275 * remove all 275 * remove all
276 */ 276 */
277 if ( recur ) { 277 if ( recur ) {
278 ; // FIXME 278 ; // FIXME
279 } 279 }
280 280
281 return menu; 281 return menu;
282} 282}
283QPopupMenu* MainWindow::options() { 283QPopupMenu* MainWindow::options() {
284 qWarning("Options"); 284 qWarning("Options");
285 return m_options; 285 return m_options;
286} 286}
287QPopupMenu* MainWindow::edit() { 287QPopupMenu* MainWindow::edit() {
288 return m_edit; 288 return m_edit;
289} 289}
290QToolBar* MainWindow::toolbar() { 290QToolBar* MainWindow::toolbar() {
291 return m_tool; 291 return m_tool;
292} 292}
293OTodoAccess::List MainWindow::list()const { 293OTodoAccess::List MainWindow::list()const {
294 return m_todoMgr.list(); 294 return m_todoMgr.list();
295} 295}
296OTodoAccess::List MainWindow::sorted( bool asc, int sortOrder ) { 296OTodoAccess::List MainWindow::sorted( bool asc, int sortOrder ) {
297 int cat = 0; 297 int cat = 0;
298 if ( m_curCat != QWidget::tr("All Categories") ) 298 if ( m_curCat != QWidget::tr("All Categories") )
299 cat = currentCatId(); 299 cat = currentCatId();
300 300
301 int filter = 1; 301 int filter = 1;
302 302
303 if (!m_completed ) 303 if (!m_completed )
304 filter |= 4; 304 filter |= 4;
305 if (m_overdue) 305 if (m_overdue)
306 filter |= 2; 306 filter |= 2;
307 307
308 return m_todoMgr.sorted( asc, sortOrder, filter, cat ); 308 return m_todoMgr.sorted( asc, sortOrder, filter, cat );
309} 309}
310OTodoAccess::List MainWindow::sorted( bool asc, int sortOrder, int addFilter) { 310OTodoAccess::List MainWindow::sorted( bool asc, int sortOrder, int addFilter) {
311 int cat = 0; 311 int cat = 0;
312 if ( m_curCat != QWidget::tr("All Categories") ) 312 if ( m_curCat != QWidget::tr("All Categories") )
313 cat = currentCatId(); 313 cat = currentCatId();
314 314
315 return m_todoMgr.sorted(asc, sortOrder, addFilter, cat ); 315 return m_todoMgr.sorted(asc, sortOrder, addFilter, cat );
316} 316}
317OTodo MainWindow::event( int uid ) { 317OTodo MainWindow::event( int uid ) {
318 return m_todoMgr.event( uid ); 318 return m_todoMgr.event( uid );
319} 319}
320bool MainWindow::isSyncing()const { 320bool MainWindow::isSyncing()const {
321 return m_syncing; 321 return m_syncing;
322} 322}
323TemplateManager* MainWindow::templateManager() { 323TemplateManager* MainWindow::templateManager() {
324 return m_tempManager; 324 return m_tempManager;
325} 325}
326Editor* MainWindow::currentEditor() { 326Editor* MainWindow::currentEditor() {
327 return m_curEdit; 327 return m_curEdit;
328} 328}
329TodoShow* MainWindow::currentShow() { 329TodoShow* MainWindow::currentShow() {
330 return m_curShow; 330 return m_curShow;
331} 331}
332void MainWindow::slotReload() { 332void MainWindow::slotReload() {
333 m_todoMgr.reload(); 333 m_todoMgr.reload();
334 currentView()->updateView( ); 334 currentView()->updateView( );
335 raiseCurrentView(); 335 raiseCurrentView();
336} 336}
337void MainWindow::closeEvent( QCloseEvent* e ) { 337void MainWindow::closeEvent( QCloseEvent* e ) {
338 if (m_stack->visibleWidget() == currentShow()->widget() ) { 338 if (m_stack->visibleWidget() == currentShow()->widget() ) {
339 raiseCurrentView(); 339 raiseCurrentView();
340 e->ignore(); 340 e->ignore();
341 return; 341 return;
342 } 342 }
343 /* 343 /*
344 * we should have flushed and now we're still saving 344 * we should have flushed and now we're still saving
345 * so there is no need to flush 345 * so there is no need to flush
346 */ 346 */
347 if (m_syncing ) { 347 if (m_syncing ) {
348 e->accept(); 348 e->accept();
349 return; 349 return;
350 } 350 }
351 bool quit = false; 351 bool quit = false;
352 if ( m_todoMgr.saveAll() ){ 352 if ( m_todoMgr.saveAll() ){
353 qWarning("saved"); 353 qWarning("saved");
354 quit = true; 354 quit = true;
355 }else { 355 }else {
356 if ( QMessageBox::critical( this, QWidget::tr("Out of space"), 356 if ( QMessageBox::critical( this, QWidget::tr("Out of space"),
357 QWidget::tr("Todo was unable\n" 357 QWidget::tr("Todo was unable\n"
358 "to save your changes.\n" 358 "to save your changes.\n"
359 "Free up some space\n" 359 "Free up some space\n"
360 "and try again.\n" 360 "and try again.\n"
361 "\nQuit Anyway?"), 361 "\nQuit Anyway?"),
362 QMessageBox::Yes|QMessageBox::Escape, 362 QMessageBox::Yes|QMessageBox::Escape,
363 QMessageBox::No|QMessageBox::Default) 363 QMessageBox::No|QMessageBox::Default)
364 != QMessageBox::No ) { 364 != QMessageBox::No ) {
365 e->accept(); 365 e->accept();
366 quit = true; 366 quit = true;
367 }else 367 }else
368 e->ignore(); 368 e->ignore();
369 369
370 } 370 }
371 371
372 if (quit ) { 372 if (quit ) {
373 Config config( "todo" ); 373 Config config( "todo" );
374 config.setGroup( "View" ); 374 config.setGroup( "View" );
375 config.writeEntry( "ShowComplete", showCompleted() ); 375 config.writeEntry( "ShowComplete", showCompleted() );
376 config.writeEntry( "Category", currentCategory() ); 376 config.writeEntry( "Category", currentCategory() );
377 config.writeEntry( "ShowDeadLine", showDeadline()); 377 config.writeEntry( "ShowDeadLine", showDeadline());
378 config.writeEntry( "ShowOverDue", showOverDue() ); 378 config.writeEntry( "ShowOverDue", showOverDue() );
379 config.writeEntry( "ShowQuickTask", showQuickTask() ); 379 config.writeEntry( "ShowQuickTask", showQuickTask() );
380 /* save templates */ 380 /* save templates */
381 templateManager()->save(); 381 templateManager()->save();
382 e->accept(); 382 e->accept();
383 } 383 }
384} 384}
385void MainWindow::populateTemplates() { 385void MainWindow::populateTemplates() {
386 m_template->clear(); 386 m_template->clear();
387 QStringList list = templateManager()->templates(); 387 QStringList list = templateManager()->templates();
388 QStringList::Iterator it; 388 QStringList::Iterator it;
389 for ( it = list.begin(); it != list.end(); ++it ) { 389 for ( it = list.begin(); it != list.end(); ++it ) {
390 m_template->insertItem( (*it) ); 390 m_template->insertItem( (*it) );
391 } 391 }
392} 392}
393/* 393/*
394 * slotNewFromTemplate 394 * slotNewFromTemplate
395 * We use the edit widget to do 395 * We use the edit widget to do
396 * the config but we setUid(-1) 396 * the config but we setUid(-1)
397 * to get a new uid 397 * to get a new uid
398 */ 398 */
399/* 399/*
400 * first we get the name of the template 400 * first we get the name of the template
401 * then we will use the TemplateManager 401 * then we will use the TemplateManager
402 */ 402 */
403void MainWindow::slotNewFromTemplate( int id ) { 403void MainWindow::slotNewFromTemplate( int id ) {
404 QString name = m_template->text( id ); 404 QString name = m_template->text( id );
405 405
406 OTodo event = templateManager()->templateEvent( name ); 406 OTodo event = templateManager()->templateEvent( name );
407 event = currentEditor()->edit(this, 407 event = currentEditor()->edit(this,
408 event ); 408 event );
409 409
410 if ( currentEditor()->accepted() ) { 410 if ( currentEditor()->accepted() ) {
411 /* assign new todo */ 411 /* assign new todo */
412 event.setUid( -1 ); 412 event.setUid( -1 );
413 currentView()->addEvent( event ); 413 currentView()->addEvent( event );
414 m_todoMgr.add( event ); 414 m_todoMgr.add( event );
415 415
416 populateCategories(); 416 populateCategories();
417 } 417 }
418} 418}
419void MainWindow::slotNew() { 419void MainWindow::slotNew() {
420 create(); 420 create();
421} 421}
422void MainWindow::slotDuplicate() { 422void MainWindow::slotDuplicate() {
423 if(m_syncing) { 423 if(m_syncing) {
424 QMessageBox::warning(this, QWidget::tr("Todo"), 424 QMessageBox::warning(this, QWidget::tr("Todo"),
425 QWidget::tr("Can not edit data, currently syncing")); 425 QWidget::tr("Can not edit data, currently syncing"));
426 return; 426 return;
427 } 427 }
428 OTodo ev = m_todoMgr.event( currentView()->current() ); 428 OTodo ev = m_todoMgr.event( currentView()->current() );
429 /* let's generate a new uid */ 429 /* let's generate a new uid */
430 ev.setUid(-1); 430 ev.setUid(-1);
431 m_todoMgr.add( ev ); 431 m_todoMgr.add( ev );
432 432
433 currentView()->addEvent( ev ); 433 currentView()->addEvent( ev );
434 raiseCurrentView(); 434 raiseCurrentView();
435} 435}
436void MainWindow::slotDelete() { 436void MainWindow::slotDelete() {
437 if (!currentView()->current() ) 437 if (!currentView()->current() )
438 return; 438 return;
439 439
440 if(m_syncing) { 440 if(m_syncing) {
441 QMessageBox::warning(this, QWidget::tr("Todo"), 441 QMessageBox::warning(this, QWidget::tr("Todo"),
442 QWidget::tr("Can not edit data, currently syncing")); 442 QWidget::tr("Can not edit data, currently syncing"));
443 return; 443 return;
444 } 444 }
445 QString strName = currentView()->currentRepresentation(); 445 QString strName = currentView()->currentRepresentation();
446 if (!QPEMessageBox::confirmDelete(this, QWidget::tr("Todo"), strName ) ) 446 if (!QPEMessageBox::confirmDelete(this, QWidget::tr("Todo"), strName ) )
447 return; 447 return;
448 448
449 m_todoMgr.remove( currentView()->current() ); 449 m_todoMgr.remove( currentView()->current() );
450 currentView()->removeEvent( currentView()->current() ); 450 currentView()->removeEvent( currentView()->current() );
451 raiseCurrentView(); 451 raiseCurrentView();
452} 452}
453void MainWindow::slotDeleteAll() { 453void MainWindow::slotDeleteAll() {
454 if(m_syncing) { 454 if(m_syncing) {
455 QMessageBox::warning(this, QWidget::tr("Todo"), 455 QMessageBox::warning(this, QWidget::tr("Todo"),
456 QWidget::tr("Can not edit data, currently syncing")); 456 QWidget::tr("Can not edit data, currently syncing"));
457 return; 457 return;
458 } 458 }
459 459
460 460
461 if ( !QPEMessageBox::confirmDelete( this, QWidget::tr( "Todo" ), QWidget::tr("all tasks?") ) ) 461 if ( !QPEMessageBox::confirmDelete( this, QWidget::tr( "Todo" ), QWidget::tr("all tasks?") ) )
462 return; 462 return;
463 463
464 m_todoMgr.removeAll(); 464 m_todoMgr.removeAll();
465 currentView()->clear(); 465 currentView()->clear();
466 466
467 raiseCurrentView(); 467 raiseCurrentView();
468} 468}
469void MainWindow::slotDeleteCompleted() { 469void MainWindow::slotDeleteCompleted() {
470 if(m_syncing) { 470 if(m_syncing) {
471 QMessageBox::warning(this, QWidget::tr("Todo"), 471 QMessageBox::warning(this, QWidget::tr("Todo"),
472 QWidget::tr("Can not edit data, currently syncing")); 472 QWidget::tr("Can not edit data, currently syncing"));
473 return; 473 return;
474 } 474 }
475 475
476 if ( !QPEMessageBox::confirmDelete( this, QWidget::tr( "Todo" ), QWidget::tr("all completed tasks?") ) ) 476 if ( !QPEMessageBox::confirmDelete( this, QWidget::tr( "Todo" ), QWidget::tr("all completed tasks?") ) )
477 return; 477 return;
478 478
479 479
480 m_todoMgr.removeCompleted(); 480 m_todoMgr.removeCompleted();
481 currentView()->updateView( ); 481 currentView()->updateView( );
482} 482}
483void MainWindow::slotFind() { 483void MainWindow::slotFind() {
484 484
485} 485}
486void MainWindow::slotEdit() { 486void MainWindow::slotEdit() {
487 slotEdit( currentView()->current() ); 487 slotEdit( currentView()->current() );
488} 488}
489/* 489/*
490 * set the category 490 * set the category
491 */ 491 */
492void MainWindow::setCategory( int c) { 492void MainWindow::setCategory( int c) {
493 if ( c <= 0 ) return; 493 if ( c <= 0 ) return;
494 494
495 495
496 qWarning("Iterating over cats %d", c ); 496 qWarning("Iterating over cats %d", c );
497 for ( unsigned int i = 1; i < m_catMenu->count(); i++ ) 497 for ( unsigned int i = 1; i < m_catMenu->count(); i++ )
498 m_catMenu->setItemChecked(i, c == (int)i ); 498 m_catMenu->setItemChecked(i, c == (int)i );
499 499
500 if (c == 1 ) { 500 if (c == 1 ) {
501 m_curCat = QString::null; 501 m_curCat = QString::null;
502 setCaption( QWidget::tr("Todo") + " - " + QWidget::tr("All Categories" ) ); 502 setCaption( QWidget::tr("Todo") + " - " + QWidget::tr("All Categories" ) );
503 503
504 }else if ( c == (int)m_catMenu->count() - 1 ) { 504 }else if ( c == (int)m_catMenu->count() - 1 ) {
505 m_curCat = QWidget::tr("Unfiled"); 505 m_curCat = QWidget::tr("Unfiled");
506 setCaption( QWidget::tr("Todo") + " - " + QWidget::tr("Unfiled") ); 506 setCaption( QWidget::tr("Todo") + " - " + QWidget::tr("Unfiled") );
507 }else { 507 }else {
508 m_curCat = m_todoMgr.categories()[c-2]; 508 m_curCat = m_todoMgr.categories()[c-2];
509 setCaption( QWidget::tr("Todo") + " - " + m_curCat ); 509 setCaption( QWidget::tr("Todo") + " - " + m_curCat );
510 } 510 }
511 m_catMenu->setItemChecked( c, true ); 511 m_catMenu->setItemChecked( c, true );
512 512
513 currentView()->setShowCategory( m_curCat ); 513 currentView()->setShowCategory( m_curCat );
514 raiseCurrentView(); 514 raiseCurrentView();
515} 515}
516void MainWindow::slotShowDeadLine( bool dead) { 516void MainWindow::slotShowDeadLine( bool dead) {
517 m_deadline = dead; 517 m_deadline = dead;
518 currentView()->setShowDeadline( dead ); 518 currentView()->setShowDeadline( dead );
519} 519}
520void MainWindow::slotShowCompleted( bool show) { 520void MainWindow::slotShowCompleted( bool show) {
521 m_completed = show; 521 m_completed = show;
522 currentView()->setShowCompleted( m_completed ); 522 currentView()->setShowCompleted( m_completed );
523} 523}
524void MainWindow::slotShowQuickTask( bool show ) { 524void MainWindow::slotShowQuickTask( bool show ) {
525 m_quicktask = show; 525 m_quicktask = show;
526 if ( m_quicktask ) 526 if ( m_quicktask )
527 m_curQuick->widget()->show(); 527 m_curQuick->widget()->show();
528 else 528 else
529 m_curQuick->widget()->hide(); 529 m_curQuick->widget()->hide();
530} 530}
531bool MainWindow::showOverDue()const { 531bool MainWindow::showOverDue()const {
532 return m_overdue; 532 return m_overdue;
533} 533}
534void MainWindow::setDocument( const QString& fi) { 534void MainWindow::setDocument( const QString& fi) {
535 DocLnk doc(fi); 535 DocLnk doc(fi);
536 if (doc.isValid() ) 536 if (doc.isValid() )
537 receiveFile(doc.file() ); 537 receiveFile(doc.file() );
538 else 538 else
539 receiveFile(fi ); 539 receiveFile(fi );
540} 540}
541 541
542static const char *beamfile = "/tmp/opie-todo.vcs"; 542static const char *beamfile = "/tmp/opie-todo.vcs";
543void MainWindow::slotBeam() { 543void MainWindow::slotBeam() {
544 beam( currentView()->current() ); 544 beam( currentView()->current() );
545} 545}
546void MainWindow::beamDone( Ir* ir) { 546void MainWindow::beamDone( Ir* ir) {
547 delete ir; 547 delete ir;
548 ::unlink( beamfile ); 548 ::unlink( beamfile );
549} 549}
550void MainWindow::receiveFile( const QString& filename ) { 550void MainWindow::receiveFile( const QString& filename ) {
551 OTodoAccessVCal* cal = new OTodoAccessVCal(filename ); 551 OTodoAccessVCal* cal = new OTodoAccessVCal(filename );
552 OTodoAccess acc( cal ); 552 OTodoAccess acc( cal );
553 acc.load(); 553 acc.load();
554 OTodoAccess::List list = acc.allRecords(); 554 OTodoAccess::List list = acc.allRecords();
555 555
556 QString message = QWidget::tr("<P>%1 new tasks arrived.<p>Would you like to add them to your Todolist?").arg(list.count() ); 556 QString message = QWidget::tr("<P>%1 new tasks arrived.<p>Would you like to add them to your Todolist?").arg(list.count() );
557 557
558 if ( QMessageBox::information(this, QWidget::tr("New Tasks"), 558 if ( QMessageBox::information(this, QWidget::tr("New Tasks"),
559 message, QMessageBox::Ok, 559 message, QMessageBox::Ok,
560 QMessageBox::Cancel ) == QMessageBox::Ok ) { 560 QMessageBox::Cancel ) == QMessageBox::Ok ) {
561 OTodoAccess::List::Iterator it; 561 OTodoAccess::List::Iterator it;
562 for ( it = list.begin(); it != list.end(); ++it ) 562 for ( it = list.begin(); it != list.end(); ++it )
563 m_todoMgr.add( (*it) ); 563 m_todoMgr.add( (*it) );
564 564
565 currentView()->updateView(); 565 currentView()->updateView();
566 } 566 }
567} 567}
568 568
569void MainWindow::slotFlush() { 569void MainWindow::slotFlush() {
570 m_syncing = FALSE; 570 m_syncing = FALSE;
571 m_todoMgr.save(); 571 m_todoMgr.save();
572} 572}
573void MainWindow::slotShowDetails() { 573void MainWindow::slotShowDetails() {
574 slotShow( currentView()->current() ); 574 slotShow( currentView()->current() );
575} 575}
576/* 576/*
577 * populate the Categories 577 * populate the Categories
578 * Menu 578 * Menu
579 */ 579 */
580void MainWindow::populateCategories() { 580void MainWindow::populateCategories() {
581 m_todoMgr.load(); 581 m_todoMgr.load();
582 582
583 m_catMenu->clear(); 583 m_catMenu->clear();
584 int id, rememberId; 584 int id, rememberId;
585 id = 1; 585 id = 1;
586 rememberId = 1; 586 rememberId = 1;
587 587
588 m_catMenu->insertItem( QWidget::tr( "All Categories" ), id++ ); 588 m_catMenu->insertItem( QWidget::tr( "All Categories" ), id++ );
589 m_catMenu->insertSeparator(); 589 m_catMenu->insertSeparator();
590 QStringList categories = m_todoMgr.categories(); 590 QStringList categories = m_todoMgr.categories();
591 categories.append( QWidget::tr( "Unfiled" ) ); 591 categories.append( QWidget::tr( "Unfiled" ) );
592 for ( QStringList::Iterator it = categories.begin(); 592 for ( QStringList::Iterator it = categories.begin();
593 it != categories.end(); ++it ) { 593 it != categories.end(); ++it ) {
594 m_catMenu->insertItem( *it, id ); 594 m_catMenu->insertItem( *it, id );
595 if ( *it == currentCategory() ) 595 if ( *it == currentCategory() )
596 rememberId = id; 596 rememberId = id;
597 ++id; 597 ++id;
598 } 598 }
599 setCategory( rememberId ); 599 setCategory( rememberId );
600} 600}
601bool MainWindow::showCompleted()const { 601bool MainWindow::showCompleted()const {
602 return m_completed; 602 return m_completed;
603} 603}
604bool MainWindow::showDeadline()const { 604bool MainWindow::showDeadline()const {
605 return m_deadline; 605 return m_deadline;
606} 606}
607bool MainWindow::showQuickTask()const { 607bool MainWindow::showQuickTask()const {
608 return m_quicktask; 608 return m_quicktask;
609} 609}
610QString MainWindow::currentCategory()const { 610QString MainWindow::currentCategory()const {
611 return m_curCat; 611 return m_curCat;
612} 612}
613int MainWindow::currentCatId() { 613int MainWindow::currentCatId() {
614 return m_todoMgr.catId( m_curCat ); 614 return m_todoMgr.catId( m_curCat );
615} 615}
616ViewBase* MainWindow::currentView() { 616ViewBase* MainWindow::currentView() {
617 return m_curView; 617 return m_curView;
618} 618}
619void MainWindow::raiseCurrentView() { 619void MainWindow::raiseCurrentView() {
620 m_stack->raiseWidget( m_curView->widget() ); 620 m_stack->raiseWidget( m_curView->widget() );
621} 621}
622void MainWindow::slotShowDue(bool ov) { 622void MainWindow::slotShowDue(bool ov) {
623 m_overdue = ov; 623 m_overdue = ov;
624 currentView()->showOverDue( ov ); 624 currentView()->showOverDue( ov );
625 raiseCurrentView(); 625 raiseCurrentView();
626} 626}
627void MainWindow::slotShow( int uid ) { 627void MainWindow::slotShow( int uid ) {
628 qWarning("slotShow"); 628 qWarning("slotShow");
629 currentShow()->slotShow( event( uid ) ); 629 currentShow()->slotShow( event( uid ) );
630 m_stack->raiseWidget( currentShow()->widget() ); 630 m_stack->raiseWidget( currentShow()->widget() );
631} 631}
632void MainWindow::slotEdit( int uid ) { 632void MainWindow::slotEdit( int uid ) {
633 if (uid == 1 ) return;
633 if(m_syncing) { 634 if(m_syncing) {
634 QMessageBox::warning(this, QWidget::tr("Todo"), 635 QMessageBox::warning(this, QWidget::tr("Todo"),
635 QWidget::tr("Can not edit data, currently syncing")); 636 QWidget::tr("Can not edit data, currently syncing"));
636 return; 637 return;
637 } 638 }
638 639
639 OTodo todo = m_todoMgr.event( uid ); 640 OTodo todo = m_todoMgr.event( uid );
640 641
641 todo = currentEditor()->edit(this, todo ); 642 todo = currentEditor()->edit(this, todo );
642 643
643 /* if completed */ 644 /* if completed */
644 if ( currentEditor()->accepted() ) { 645 if ( currentEditor()->accepted() ) {
645 qWarning("Replacing now" ); 646 qWarning("Replacing now" );
646 m_todoMgr.update( todo.uid(), todo ); 647 m_todoMgr.update( todo.uid(), todo );
647 currentView()->replaceEvent( todo ); 648 currentView()->replaceEvent( todo );
648 /* a Category might have changed */ 649 /* a Category might have changed */
649 populateCategories(); 650 populateCategories();
650 } 651 }
651 652
652 raiseCurrentView(); 653 raiseCurrentView();
653} 654}
654/* 655/*
655void MainWindow::slotUpdate1( int uid, const SmallTodo& ev) { 656void MainWindow::slotUpdate1( int uid, const SmallTodo& ev) {
656 m_todoMgr.update( uid, ev ); 657 m_todoMgr.update( uid, ev );
657} 658}
658*/ 659*/
659void MainWindow::updateTodo( const OTodo& ev) { 660void MainWindow::updateTodo( const OTodo& ev) {
660 m_todoMgr.update( ev.uid() , ev ); 661 m_todoMgr.update( ev.uid() , ev );
661} 662}
662/* The view changed it's configuration 663/* The view changed it's configuration
663 * update the view menu 664 * update the view menu
664 */ 665 */
665void MainWindow::slotUpdate3( QWidget* ) { 666void MainWindow::slotUpdate3( QWidget* ) {
666 667
667} 668}
668void MainWindow::updateList() { 669void MainWindow::updateList() {
669 m_todoMgr.updateList(); 670 m_todoMgr.updateList();
670} 671}
671void MainWindow::setReadAhead( uint count ) { 672void MainWindow::setReadAhead( uint count ) {
672 if (m_todoMgr.todoDB() ) 673 if (m_todoMgr.todoDB() )
673 m_todoMgr.todoDB()->setReadAhead( count ); 674 m_todoMgr.todoDB()->setReadAhead( count );
674} 675}
675void MainWindow::slotQuickEntered() { 676void MainWindow::slotQuickEntered() {
676 qWarning("entered"); 677 qWarning("entered");
677 OTodo todo = quickEditor()->todo(); 678 OTodo todo = quickEditor()->todo();
678 if (todo.isEmpty() ) 679 if (todo.isEmpty() )
679 return; 680 return;
680 681
681 m_todoMgr.add( todo ); 682 m_todoMgr.add( todo );
682 currentView()->addEvent( todo ); 683 currentView()->addEvent( todo );
683 raiseCurrentView(); 684 raiseCurrentView();
684} 685}
685QuickEditBase* MainWindow::quickEditor() { 686QuickEditBase* MainWindow::quickEditor() {
686 return m_curQuick; 687 return m_curQuick;
687} 688}
688void MainWindow::slotComplete( int uid ) { 689void MainWindow::slotComplete( int uid ) {
689 slotComplete( event(uid) ); 690 slotComplete( event(uid) );
690} 691}
691void MainWindow::slotComplete( const OTodo& todo ) { 692void MainWindow::slotComplete( const OTodo& todo ) {
692 OTodo to = todo; 693 OTodo to = todo;
693 to.setCompleted( !to.isCompleted() ); 694 to.setCompleted( !to.isCompleted() );
694 to.setCompletedDate( QDate::currentDate() ); 695 to.setCompletedDate( QDate::currentDate() );
695 696
696 /* 697 /*
697 * if the item does recur 698 * if the item does recur
698 * we need to spin it off 699 * we need to spin it off
699 * and update the items duedate to the next 700 * and update the items duedate to the next
700 * possible recurrance of this item... 701 * possible recurrance of this item...
701 * the spinned off one will loose the 702 * the spinned off one will loose the
702 */ 703 */
703 if ( to.recurrence().doesRecur() && to.isCompleted() ) { 704 if ( to.recurrence().doesRecur() && to.isCompleted() ) {
704 OTodo to2( to ); 705 OTodo to2( to );
705 706
706 /* the spinned off one won't recur anymore */ 707 /* the spinned off one won't recur anymore */
707 to.setRecurrence( ORecur() ); 708 to.setRecurrence( ORecur() );
708 709
709 ORecur rec = to2.recurrence(); 710 ORecur rec = to2.recurrence();
710 rec.setStart( to.dueDate() ); 711 rec.setStart( to.dueDate() );
711 to2.setRecurrence( rec ); 712 to2.setRecurrence( rec );
712 /* 713 /*
713 * if there is a next occurence 714 * if there is a next occurence
714 * from the duedate of the last recurrance 715 * from the duedate of the last recurrance
715 */ 716 */
716 QDate date; 717 QDate date;
717 if ( to2.recurrence().nextOcurrence( to2.dueDate().addDays(1), date ) ) { 718 if ( to2.recurrence().nextOcurrence( to2.dueDate().addDays(1), date ) ) {
718 QDate inval; 719 QDate inval;
719 /* generate a new uid for the old record */ 720 /* generate a new uid for the old record */
720 to.setUid( 1 ); 721 to.setUid( 1 );
721 722
722 /* add the old one cause it has a new UID here cause it was spin off */ 723 /* add the old one cause it has a new UID here cause it was spin off */
723 m_todoMgr.add( to ); 724 m_todoMgr.add( to );
724 725
725 /* 726 /*
726 * update the due date 727 * update the due date
727 * start date 728 * start date
728 * and complete date 729 * and complete date
729 */ 730 */
730 to2.setDueDate( date ); 731 to2.setDueDate( date );
731 to2.setStartDate( inval ); 732 to2.setStartDate( inval );
732 to2.setCompletedDate( inval ); 733 to2.setCompletedDate( inval );
733 to2.setCompleted( false ); 734 to2.setCompleted( false );
734 updateTodo( to2 ); 735 updateTodo( to2 );
735 }else 736 }else
736 updateTodo( to ); 737 updateTodo( to );
737 }else 738 }else
738 updateTodo( to ); 739 updateTodo( to );
739 740
740 currentView()->updateView(); 741 currentView()->updateView();
741 raiseCurrentView(); 742 raiseCurrentView();
742} 743}
743void MainWindow::flush() { 744void MainWindow::flush() {
744 slotFlush(); 745 slotFlush();
745} 746}
746void MainWindow::reload() { 747void MainWindow::reload() {
747 slotReload(); 748 slotReload();
748} 749}
749int MainWindow::create() { 750int MainWindow::create() {
750 int uid = 0; 751 int uid = 0;
751 if(m_syncing) { 752 if(m_syncing) {
752 QMessageBox::warning(this, QWidget::tr("Todo"), 753 QMessageBox::warning(this, QWidget::tr("Todo"),
753 QWidget::tr("Can not edit data, currently syncing")); 754 QWidget::tr("Can not edit data, currently syncing"));
754 return uid; 755 return uid;
755 } 756 }
756 757
757 758
758 OTodo todo = currentEditor()->newTodo( currentCatId(), 759 OTodo todo = currentEditor()->newTodo( currentCatId(),
759 this ); 760 this );
760 761
761 if ( currentEditor()->accepted() ) { 762 if ( currentEditor()->accepted() ) {
762 //todo.assignUid(); 763 //todo.assignUid();
763 uid = todo.uid(); 764 uid = todo.uid();
764 m_todoMgr.add( todo ); 765 m_todoMgr.add( todo );
765 currentView()->addEvent( todo ); 766 currentView()->addEvent( todo );
766 767
767 768
768 // I'm afraid we must call this every time now, otherwise 769 // I'm afraid we must call this every time now, otherwise
769 // spend expensive time comparing all these strings... 770 // spend expensive time comparing all these strings...
770 // but only call if we changed something -zecke 771 // but only call if we changed something -zecke
771 populateCategories(); 772 populateCategories();
772 } 773 }
773 raiseCurrentView( ); 774 raiseCurrentView( );
774 775
775 return uid; 776 return uid;
776} 777}
777/* delete it silently... */ 778/* delete it silently... */
778bool MainWindow::remove( int uid ) { 779bool MainWindow::remove( int uid ) {
779 if (m_syncing) return false; 780 if (m_syncing) return false;
780 781
781 return m_todoMgr.remove( uid ); 782 return m_todoMgr.remove( uid );
782} 783}
783void MainWindow::beam( int uid) { 784void MainWindow::beam( int uid) {
784 ::unlink( beamfile ); 785 ::unlink( beamfile );
785 OTodo todo = event( uid ); 786 OTodo todo = event( uid );
786 OTodoAccessVCal* cal = new OTodoAccessVCal(QString::fromLatin1(beamfile) ); 787 OTodoAccessVCal* cal = new OTodoAccessVCal(QString::fromLatin1(beamfile) );
787 OTodoAccess acc( cal ); 788 OTodoAccess acc( cal );
788 acc.load(); 789 acc.load();
789 acc.add( todo ); 790 acc.add( todo );
790 acc.save(); 791 acc.save();
791 Ir* ir = new Ir(this ); 792 Ir* ir = new Ir(this );
792 connect(ir, SIGNAL(done(Ir*) ), 793 connect(ir, SIGNAL(done(Ir*) ),
793 this, SLOT(beamDone(Ir*) ) ); 794 this, SLOT(beamDone(Ir*) ) );
794 ir->send( beamfile, todo.summary(), "text/x-vCalendar" ); 795 ir->send(beamfile, todo.summary(), "text/x-vCalendar" );
795} 796}
796void MainWindow::show( int uid ) { 797void MainWindow::show( int uid ) {
797 slotShow( uid ); 798 slotShow( uid );
798} 799}
799void MainWindow::edit( int uid ) { 800void MainWindow::edit( int uid ) {
800 slotEdit( uid ); 801 slotEdit( uid );
801} 802}
802void MainWindow::add( const OPimRecord& rec) { 803void MainWindow::add( const OPimRecord& rec) {
803 if ( rec.rtti() != OTodo::rtti() ) return; 804 if ( rec.rtti() != OTodo::rtti() ) return;
804 805
805 const OTodo& todo = static_cast<const OTodo&>(rec); 806 const OTodo& todo = static_cast<const OTodo&>(rec);
806 807
807 m_todoMgr.add(todo ); 808 m_todoMgr.add(todo );
808 currentView()->addEvent( todo ); 809 currentView()->addEvent( todo );
809 810
810 811
811 // I'm afraid we must call this every time now, otherwise 812 // I'm afraid we must call this every time now, otherwise
812 // spend expensive time comparing all these strings... 813 // spend expensive time comparing all these strings...
813 // but only call if we changed something -zecke 814 // but only call if we changed something -zecke
814 populateCategories(); 815 populateCategories();
815} 816}
816void MainWindow::slotReturnFromView() { 817void MainWindow::slotReturnFromView() {
817 raiseCurrentView(); 818 raiseCurrentView();
818} 819}
diff --git a/core/pim/todo/tableview.cpp b/core/pim/todo/tableview.cpp
index ae27fab..d9cda09 100644
--- a/core/pim/todo/tableview.cpp
+++ b/core/pim/todo/tableview.cpp
@@ -1,553 +1,554 @@
1/* 1/*
2               =. This file is part of the OPIE Project 2               =. This file is part of the OPIE Project
3             .=l. Copyright (c) 2002 <zecke> 3             .=l. Copyright (c) 2002 <zecke>
4           .>+-= 4           .>+-=
5 _;:,     .>    :=|. This program is free software; you can 5 _;:,     .>    :=|. This program is free software; you can
6.> <`_,   >  .   <= redistribute it and/or modify it under 6.> <`_,   >  .   <= redistribute it and/or modify it under
7:`=1 )Y*s>-.--   : the terms of the GNU General Public 7:`=1 )Y*s>-.--   : the terms of the GNU General Public
8.="- .-=="i,     .._ License as published by the Free Software 8.="- .-=="i,     .._ License as published by the Free Software
9 - .   .-<_>     .<> Foundation; either version 2 of the License, 9 - .   .-<_>     .<> Foundation; either version 2 of the License,
10     ._= =}       : or (at your option) any later version. 10     ._= =}       : or (at your option) any later version.
11    .%`+i>       _;_. 11    .%`+i>       _;_.
12    .i_,=:_.      -<s. This program is distributed in the hope that 12    .i_,=:_.      -<s. This program is distributed in the hope that
13     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 13     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
14    : ..    .:,     . . . without even the implied warranty of 14    : ..    .:,     . . . without even the implied warranty of
15    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 15    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
16  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 16  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
17..}^=.=       =       ; Library General Public License for more 17..}^=.=       =       ; Library General Public License for more
18++=   -.     .`     .: details. 18++=   -.     .`     .: details.
19 :     =  ...= . :.=- 19 :     =  ...= . :.=-
20 -.   .:....=;==+<; You should have received a copy of the GNU 20 -.   .:....=;==+<; You should have received a copy of the GNU
21  -_. . .   )=.  = Library General Public License along with 21  -_. . .   )=.  = Library General Public License along with
22    --        :-=` this library; see the file COPYING.LIB. 22    --        :-=` this library; see the file COPYING.LIB.
23 If not, write to the Free Software Foundation, 23 If not, write to the Free Software Foundation,
24 Inc., 59 Temple Place - Suite 330, 24 Inc., 59 Temple Place - Suite 330,
25 Boston, MA 02111-1307, USA. 25 Boston, MA 02111-1307, USA.
26 26
27*/ 27*/
28#include <stdlib.h> 28#include <stdlib.h>
29#include <cmath> 29#include <cmath>
30 30
31#include <qcombobox.h> 31#include <qcombobox.h>
32#include <qlineedit.h> 32#include <qlineedit.h>
33#include <qtimer.h> 33#include <qtimer.h>
34#include <qpoint.h> 34#include <qpoint.h>
35#include <qpopupmenu.h> 35#include <qpopupmenu.h>
36 36
37#include <qpe/config.h> 37#include <qpe/config.h>
38#include <qpe/resource.h> 38#include <qpe/resource.h>
39 39
40#include <opie/orecur.h> 40#include <opie/orecur.h>
41 41
42#include "mainwindow.h" 42#include "mainwindow.h"
43//#include "tableitems.h" 43//#include "tableitems.h"
44#include "tableview.h" 44#include "tableview.h"
45 45
46using namespace Todo; 46using namespace Todo;
47 47
48namespace { 48namespace {
49 static const int BoxSize = 14; 49 static const int BoxSize = 14;
50 static const int RowHeight = 20; 50 static const int RowHeight = 20;
51} 51}
52 52
53 53
54void TableView::initConfig() { 54void TableView::initConfig() {
55 Config config( "todo" ); 55 Config config( "todo" );
56 config.setGroup( "Options" ); 56 config.setGroup( "Options" );
57 m_completeStrokeWidth = config.readNumEntry( "CompleteStrokeWidth", 8 ); 57 m_completeStrokeWidth = config.readNumEntry( "CompleteStrokeWidth", 8 );
58 for (int i = 0; i < numCols(); i++ ) { 58 for (int i = 0; i < numCols(); i++ ) {
59 int width = config.readNumEntry("Width"+QString::number(i), -1 ); 59 int width = config.readNumEntry("Width"+QString::number(i), -1 );
60 setColumnWidth(i, width == -1 ? columnWidth(i) : width ); 60 setColumnWidth(i, width == -1 ? columnWidth(i) : width );
61 } 61 }
62} 62}
63 63
64TableView::TableView( MainWindow* window, QWidget* wid ) 64TableView::TableView( MainWindow* window, QWidget* wid )
65 : QTable( wid ), TodoView( window ) { 65 : QTable( wid ), TodoView( window ) {
66 66
67 // Load icons 67 // Load icons
68 // TODO - probably should be done globally somewhere else, 68 // TODO - probably should be done globally somewhere else,
69 // see also quickeditimpl.cpp/h, taskeditoroverview.cpp/h 69 // see also quickeditimpl.cpp/h, taskeditoroverview.cpp/h
70 m_pic_completed = Resource::loadPixmap( "todo/completed" ); 70 m_pic_completed = Resource::loadPixmap( "todo/completed" );
71 QString namestr; 71 QString namestr;
72 for ( unsigned int i = 1; i < 6; i++ ) { 72 for ( unsigned int i = 1; i < 6; i++ ) {
73 namestr = "todo/priority"; 73 namestr = "todo/priority";
74 namestr.append( QString::number( i ) ); 74 namestr.append( QString::number( i ) );
75 m_pic_priority[ i - 1 ] = Resource::loadPixmap( namestr ); 75 m_pic_priority[ i - 1 ] = Resource::loadPixmap( namestr );
76 } 76 }
77 77
78 setUpdatesEnabled( false ); 78 setUpdatesEnabled( false );
79 viewport()->setUpdatesEnabled( false ); 79 viewport()->setUpdatesEnabled( false );
80 m_enablePaint = false; 80 m_enablePaint = false;
81 setNumRows(0); 81 setNumRows(0);
82 setNumCols(4); 82 setNumCols(4);
83 83
84 horizontalHeader()->setLabel( 0, QWidget::tr("C.") ); 84 horizontalHeader()->setLabel( 0, QWidget::tr("C.") );
85 horizontalHeader()->setLabel( 1, QWidget::tr("Priority") ); 85 horizontalHeader()->setLabel( 1, QWidget::tr("Priority") );
86 horizontalHeader()->setLabel( 2, QWidget::tr("Description" ) ); 86 horizontalHeader()->setLabel( 2, QWidget::tr("Description" ) );
87 horizontalHeader()->setLabel( 3, QWidget::tr("Deadline") ); 87 horizontalHeader()->setLabel( 3, QWidget::tr("Deadline") );
88 88
89 setShowDeadline( todoWindow()->showDeadline() ); 89 setShowDeadline( todoWindow()->showDeadline() );
90 90
91 setSorting( TRUE ); 91 setSorting( TRUE );
92 setSelectionMode( NoSelection ); 92 setSelectionMode( NoSelection );
93 93
94 setLeftMargin( 0 ); 94 setLeftMargin( 0 );
95 verticalHeader()->hide(); 95 verticalHeader()->hide();
96 96
97 connect((QTable*)this, SIGNAL( clicked( int, int, int, const QPoint& ) ), 97 connect((QTable*)this, SIGNAL( clicked( int, int, int, const QPoint& ) ),
98 this, SLOT( slotClicked(int, int, int, const QPoint& ) ) ); 98 this, SLOT( slotClicked(int, int, int, const QPoint& ) ) );
99 connect((QTable*)this, SIGNAL( pressed( int, int, int, const QPoint& ) ), 99 connect((QTable*)this, SIGNAL( pressed( int, int, int, const QPoint& ) ),
100 this, SLOT( slotPressed(int, int, int, const QPoint& ) ) ); 100 this, SLOT( slotPressed(int, int, int, const QPoint& ) ) );
101 connect((QTable*)this, SIGNAL(valueChanged(int, int) ), 101 connect((QTable*)this, SIGNAL(valueChanged(int, int) ),
102 this, SLOT( slotValueChanged(int, int) ) ); 102 this, SLOT( slotValueChanged(int, int) ) );
103 connect((QTable*)this, SIGNAL(currentChanged(int, int) ), 103 connect((QTable*)this, SIGNAL(currentChanged(int, int) ),
104 this, SLOT( slotCurrentChanged(int, int) ) ); 104 this, SLOT( slotCurrentChanged(int, int) ) );
105 105
106 m_menuTimer = new QTimer( this ); 106 m_menuTimer = new QTimer( this );
107 connect( m_menuTimer, SIGNAL(timeout()), 107 connect( m_menuTimer, SIGNAL(timeout()),
108 this, SLOT(slotShowMenu()) ); 108 this, SLOT(slotShowMenu()) );
109 109
110 /* now let's init the config */ 110 /* now let's init the config */
111 initConfig(); 111 initConfig();
112 112
113 113
114 m_enablePaint = true; 114 m_enablePaint = true;
115 setUpdatesEnabled( true ); 115 setUpdatesEnabled( true );
116 viewport()->setUpdatesEnabled( true ); 116 viewport()->setUpdatesEnabled( true );
117 viewport()->update(); 117 viewport()->update();
118 setSortOrder( 0 ); 118 setSortOrder( 0 );
119 setAscending( TRUE ); 119 setAscending( TRUE );
120 m_first = true; 120 m_first = true;
121 121
122 122
123} 123}
124/* a new day has started 124/* a new day has started
125 * update the day 125 * update the day
126 */ 126 */
127void TableView::newDay() { 127void TableView::newDay() {
128 clear(); 128 clear();
129 updateView(); 129 updateView();
130} 130}
131TableView::~TableView() { 131TableView::~TableView() {
132 Config config( "todo" ); 132 Config config( "todo" );
133 config.setGroup( "Options" ); 133 config.setGroup( "Options" );
134 for (int i = 0; i < numCols(); i++ ) 134 for (int i = 0; i < numCols(); i++ )
135 config.writeEntry("Width"+QString::number(i), columnWidth(i) ); 135 config.writeEntry("Width"+QString::number(i), columnWidth(i) );
136} 136}
137void TableView::slotShowMenu() { 137void TableView::slotShowMenu() {
138 QPopupMenu *menu = todoWindow()->contextMenu( current(), sorted()[currentRow()].recurrence().doesRecur() ); 138 QPopupMenu *menu = todoWindow()->contextMenu( current(), sorted()[currentRow()].recurrence().doesRecur() );
139 menu->exec(QCursor::pos() ); 139 menu->exec(QCursor::pos() );
140 delete menu; 140 delete menu;
141} 141}
142QString TableView::type() const { 142QString TableView::type() const {
143 return QString::fromLatin1( tr("Table View") ); 143 return QString::fromLatin1( tr("Table View") );
144} 144}
145int TableView::current() { 145int TableView::current() {
146 if (numRows() == 0 ) return 1;
146 int uid = sorted().uidAt(currentRow() ); 147 int uid = sorted().uidAt(currentRow() );
147 148
148 return uid; 149 return uid;
149} 150}
150QString TableView::currentRepresentation() { 151QString TableView::currentRepresentation() {
151 OTodo to = sorted()[currentRow()]; 152 OTodo to = sorted()[currentRow()];
152 return to.summary().isEmpty() ? to.description().left(20) : to.summary() ; 153 return to.summary().isEmpty() ? to.description().left(20) : to.summary() ;
153} 154}
154/* show overdue */ 155/* show overdue */
155void TableView::showOverDue( bool ) { 156void TableView::showOverDue( bool ) {
156 clear(); 157 clear();
157 updateView(); 158 updateView();
158} 159}
159 160
160void TableView::updateView( ) { 161void TableView::updateView( ) {
161 qWarning("update view"); 162 qWarning("update view");
162 m_row = false; 163 m_row = false;
163 static int id; 164 static int id;
164 id = startTimer(4000 ); 165 id = startTimer(4000 );
165 /* FIXME we want one page to be read! 166 /* FIXME we want one page to be read!
166 * 167 *
167 * Calculate that screensize 168 * Calculate that screensize
168 */ 169 */
169 todoWindow()->setReadAhead( 4 ); 170 todoWindow()->setReadAhead( 4 );
170 sort(); 171 sort();
171 OTodoAccess::List::Iterator it, end; 172 OTodoAccess::List::Iterator it, end;
172 it = sorted().begin(); 173 it = sorted().begin();
173 end = sorted().end(); 174 end = sorted().end();
174 175
175 qWarning("setTodos"); 176 qWarning("setTodos");
176 QTime time; 177 QTime time;
177 time.start(); 178 time.start();
178 m_enablePaint = false; 179 m_enablePaint = false;
179 setUpdatesEnabled( false ); 180 setUpdatesEnabled( false );
180 viewport()->setUpdatesEnabled( false ); 181 viewport()->setUpdatesEnabled( false );
181 182
182 setNumRows( it.count() ); 183 setNumRows( it.count() );
183 if ( it.count() == 0 ) 184 if ( it.count() == 0 )
184 killTimer(id); 185 killTimer(id);
185 186
186// int elc = time.elapsed(); 187// int elc = time.elapsed();
187 setUpdatesEnabled( true ); 188 setUpdatesEnabled( true );
188 viewport()->setUpdatesEnabled( true ); 189 viewport()->setUpdatesEnabled( true );
189 viewport()->update(); 190 viewport()->update();
190 191
191 m_enablePaint = true; 192 m_enablePaint = true;
192// int el = time.elapsed(); 193// int el = time.elapsed();
193} 194}
194void TableView::setTodo( int, const OTodo&) { 195void TableView::setTodo( int, const OTodo&) {
195 sort(); 196 sort();
196 197
197 /* repaint */ 198 /* repaint */
198 repaint(); 199 repaint();
199} 200}
200void TableView::addEvent( const OTodo&) { 201void TableView::addEvent( const OTodo&) {
201 202
202 /* fix problems of not showing the 'Haken' */ 203 /* fix problems of not showing the 'Haken' */
203 updateView(); 204 updateView();
204} 205}
205/* 206/*
206 * find the event 207 * find the event
207 * and then replace the complete row 208 * and then replace the complete row
208 */ 209 */
209void TableView::replaceEvent( const OTodo& ev) { 210void TableView::replaceEvent( const OTodo& ev) {
210 addEvent( ev ); 211 addEvent( ev );
211} 212}
212/* 213/*
213 * re aligning table can be slow too 214 * re aligning table can be slow too
214 * FIXME: look what performs better 215 * FIXME: look what performs better
215 * either this or the old align table 216 * either this or the old align table
216 */ 217 */
217void TableView::removeEvent( int ) { 218void TableView::removeEvent( int ) {
218 updateView(); 219 updateView();
219} 220}
220void TableView::setShowCompleted( bool b) { 221void TableView::setShowCompleted( bool b) {
221 qWarning("Show Completed %d" + b ); 222 qWarning("Show Completed %d" + b );
222 updateView(); 223 updateView();
223} 224}
224void TableView::setShowDeadline( bool b ) { 225void TableView::setShowDeadline( bool b ) {
225 qWarning( "Show DeadLine %d" + b ); 226 qWarning( "Show DeadLine %d" + b );
226 if ( b ) 227 if ( b )
227 showColumn( 3 ); 228 showColumn( 3 );
228 else 229 else
229 hideColumn( 3 ); 230 hideColumn( 3 );
230 231
231 // Try to intelligently size columns 232 // Try to intelligently size columns
232 // TODO - would use width() below, but doesn't have valid value at time of c'tor 233 // TODO - would use width() below, but doesn't have valid value at time of c'tor
233 int col2width = 238; 234 int col2width = 238;
234 int width = m_pic_completed.width(); 235 int width = m_pic_completed.width();
235 setColumnWidth( 0, width ); 236 setColumnWidth( 0, width );
236 col2width -= width; 237 col2width -= width;
237 width = fontMetrics().boundingRect( horizontalHeader()->label( 1 ) ).width() + 8; 238 width = fontMetrics().boundingRect( horizontalHeader()->label( 1 ) ).width() + 8;
238 setColumnWidth( 1, width ); 239 setColumnWidth( 1, width );
239 col2width -= width; 240 col2width -= width;
240 if ( b ) { 241 if ( b ) {
241 width = fontMetrics().boundingRect( horizontalHeader()->label( 3 ) ).width() + 8; 242 width = fontMetrics().boundingRect( horizontalHeader()->label( 3 ) ).width() + 8;
242 setColumnWidth( 3, width ); 243 setColumnWidth( 3, width );
243 col2width -= width; 244 col2width -= width;
244 } 245 }
245 setColumnWidth( 2, col2width ); 246 setColumnWidth( 2, col2width );
246} 247}
247void TableView::setShowCategory( const QString& str) { 248void TableView::setShowCategory( const QString& str) {
248 qWarning("setShowCategory"); 249 qWarning("setShowCategory");
249 if ( str != m_oleCat || m_first ) 250 if ( str != m_oleCat || m_first )
250 updateView(); 251 updateView();
251 252
252 m_oleCat = str; 253 m_oleCat = str;
253 m_first = false; 254 m_first = false;
254 255
255} 256}
256void TableView::clear() { 257void TableView::clear() {
257 setNumRows(0); 258 setNumRows(0);
258} 259}
259void TableView::slotClicked(int row, int col, int, 260void TableView::slotClicked(int row, int col, int,
260 const QPoint& point) { 261 const QPoint& point) {
261 if ( !cellGeometry(row, col ).contains(point ) ) 262 if ( !cellGeometry(row, col ).contains(point ) )
262 return; 263 return;
263 264
264 int ui= sorted().uidAt( row ); 265 int ui= sorted().uidAt( row );
265 266
266 267
267 switch( col ) { 268 switch( col ) {
268 case 0:{ 269 case 0:{
269 int x = point.x() -columnPos( col ); 270 int x = point.x() -columnPos( col );
270 int y = point.y() -rowPos( row ); 271 int y = point.y() -rowPos( row );
271 int w = columnWidth( col ); 272 int w = columnWidth( col );
272 int h = rowHeight( row ); 273 int h = rowHeight( row );
273 if ( x >= ( w - BoxSize ) / 2 && 274 if ( x >= ( w - BoxSize ) / 2 &&
274 x <= ( w - BoxSize ) / 2 + BoxSize && 275 x <= ( w - BoxSize ) / 2 + BoxSize &&
275 y >= ( h - BoxSize ) / 2 && 276 y >= ( h - BoxSize ) / 2 &&
276 y <= ( h - BoxSize ) / 2 + BoxSize ) { 277 y <= ( h - BoxSize ) / 2 + BoxSize ) {
277 TodoView::complete(sorted()[row] ); 278 TodoView::complete(sorted()[row] );
278 } 279 }
279 } 280 }
280 break; 281 break;
281 282
282 case 1: 283 case 1:
283 break; 284 break;
284 285
285 case 2: { 286 case 2: {
286 m_menuTimer->stop(); 287 m_menuTimer->stop();
287 showTodo( ui ); 288 showTodo( ui );
288 break; 289 break;
289 } 290 }
290 case 3: { 291 case 3: {
291 m_menuTimer->stop(); 292 m_menuTimer->stop();
292 TodoView::edit( ui ); 293 TodoView::edit( ui );
293 break; 294 break;
294 } 295 }
295 } 296 }
296 297
297 298
298} 299}
299void TableView::slotPressed(int row, int col, int, 300void TableView::slotPressed(int row, int col, int,
300 const QPoint& point) { 301 const QPoint& point) {
301 302
302 qWarning("pressed row %d col %d x:%d+y:%d", row,col,point.x(),point.y() ); 303 qWarning("pressed row %d col %d x:%d+y:%d", row,col,point.x(),point.y() );
303 m_prevP = point; 304 m_prevP = point;
304 /* TextColumn column */ 305 /* TextColumn column */
305 if ( col == 2 && cellGeometry( row, col ).contains( point ) ) 306 if ( col == 2 && cellGeometry( row, col ).contains( point ) )
306 m_menuTimer->start( 750, TRUE ); 307 m_menuTimer->start( 750, TRUE );
307} 308}
308void TableView::slotValueChanged( int, int ) { 309void TableView::slotValueChanged( int, int ) {
309 qWarning("Value Changed"); 310 qWarning("Value Changed");
310} 311}
311void TableView::slotCurrentChanged(int, int ) { 312void TableView::slotCurrentChanged(int, int ) {
312 m_menuTimer->stop(); 313 m_menuTimer->stop();
313} 314}
314QWidget* TableView::widget() { 315QWidget* TableView::widget() {
315 return this; 316 return this;
316} 317}
317/* 318/*
318 * We need to overwrite sortColumn 319 * We need to overwrite sortColumn
319 * because we want to sort whole row 320 * because we want to sort whole row
320 * based 321 * based
321 * We event want to set the setOrder 322 * We event want to set the setOrder
322 * to a sort() and update() 323 * to a sort() and update()
323 */ 324 */
324void TableView::sortColumn( int col, bool asc, bool ) { 325void TableView::sortColumn( int col, bool asc, bool ) {
325 qWarning("bool %d", asc ); 326 qWarning("bool %d", asc );
326 setSortOrder( col ); 327 setSortOrder( col );
327 setAscending( asc ); 328 setAscending( asc );
328 updateView(); 329 updateView();
329} 330}
330void TableView::viewportPaintEvent( QPaintEvent* e) { 331void TableView::viewportPaintEvent( QPaintEvent* e) {
331 if (m_enablePaint ) 332 if (m_enablePaint )
332 QTable::viewportPaintEvent( e ); 333 QTable::viewportPaintEvent( e );
333} 334}
334/* 335/*
335 * This segment is copyrighted by TT 336 * This segment is copyrighted by TT
336 * it was taken from their todolist 337 * it was taken from their todolist
337 * application this code is GPL 338 * application this code is GPL
338 */ 339 */
339void TableView::paintCell(QPainter* p, int row, int col, const QRect& cr, bool ) { 340void TableView::paintCell(QPainter* p, int row, int col, const QRect& cr, bool ) {
340 const QColorGroup &cg = colorGroup(); 341 const QColorGroup &cg = colorGroup();
341 342
342 p->save(); 343 p->save();
343 344
344 OTodo task = sorted()[row]; 345 OTodo task = sorted()[row];
345 346
346 // TODO - give user option for grid or bars? 347 // TODO - give user option for grid or bars?
347 348
348 // Paint alternating background bars 349 // Paint alternating background bars
349 if ( (row % 2 ) == 0 ) { 350 if ( (row % 2 ) == 0 ) {
350 p->fillRect( 0, 0, cr.width(), cr.height(), cg.brush( QColorGroup::Base ) ); 351 p->fillRect( 0, 0, cr.width(), cr.height(), cg.brush( QColorGroup::Base ) );
351 p->setPen( QPen( cg.text() ) ); 352 p->setPen( QPen( cg.text() ) );
352 } 353 }
353 else { 354 else {
354 p->fillRect( 0, 0, cr.width(), cr.height(), cg.brush( QColorGroup::Background ) ); 355 p->fillRect( 0, 0, cr.width(), cr.height(), cg.brush( QColorGroup::Background ) );
355 p->setPen( QPen( cg.buttonText() ) ); 356 p->setPen( QPen( cg.buttonText() ) );
356 } 357 }
357 358
358 // Paint grid 359 // Paint grid
359 //p->fillRect( 0, 0, cr.width(), cr.height(), cg.brush( QColorGroup::Base ) ); 360 //p->fillRect( 0, 0, cr.width(), cr.height(), cg.brush( QColorGroup::Base ) );
360 //QPen op = p->pen(); 361 //QPen op = p->pen();
361 //p->setPen(cg.mid()); 362 //p->setPen(cg.mid());
362 //p->drawLine( 0, cr.height() - 1, cr.width() - 1, cr.height() - 1 ); 363 //p->drawLine( 0, cr.height() - 1, cr.width() - 1, cr.height() - 1 );
363 //p->drawLine( cr.width() - 1, 0, cr.width() - 1, cr.height() - 1 ); 364 //p->drawLine( cr.width() - 1, 0, cr.width() - 1, cr.height() - 1 );
364 //p->setPen(op); 365 //p->setPen(op);
365 366
366 QFont f = p->font(); 367 QFont f = p->font();
367 QFontMetrics fm(f); 368 QFontMetrics fm(f);
368 369
369 int marg = ( cr.width() - BoxSize ) / 2; 370 int marg = ( cr.width() - BoxSize ) / 2;
370 int x = 0; 371 int x = 0;
371 int y = ( cr.height() - BoxSize ) / 2; 372 int y = ( cr.height() - BoxSize ) / 2;
372 373
373 switch(col) { 374 switch(col) {
374 case 0: // completed field 375 case 0: // completed field
375 { 376 {
376 //p->setPen( QPen( cg.text() ) ); 377 //p->setPen( QPen( cg.text() ) );
377 //p->drawRect( x + marg, y, BoxSize, BoxSize ); 378 //p->drawRect( x + marg, y, BoxSize, BoxSize );
378 //p->drawRect( x + marg+1, y+1, BoxSize-2, BoxSize-2 ); 379 //p->drawRect( x + marg+1, y+1, BoxSize-2, BoxSize-2 );
379 if ( task.isCompleted() ) { 380 if ( task.isCompleted() ) {
380 p->drawPixmap( x + marg, y, m_pic_completed ); 381 p->drawPixmap( x + marg, y, m_pic_completed );
381 } 382 }
382 } 383 }
383 break; 384 break;
384 case 1: // priority field 385 case 1: // priority field
385 { 386 {
386 p->drawPixmap( x + marg, y, m_pic_priority[ task.priority() - 1 ] ); 387 p->drawPixmap( x + marg, y, m_pic_priority[ task.priority() - 1 ] );
387 } 388 }
388 break; 389 break;
389 case 2: // description field 390 case 2: // description field
390 { 391 {
391 QString text = task.summary().isEmpty() ? 392 QString text = task.summary().isEmpty() ?
392 task.description().left(20) : 393 task.description().left(20) :
393 task.summary(); 394 task.summary();
394 p->drawText(2,2 + fm.ascent(), text); 395 p->drawText(2,2 + fm.ascent(), text);
395 } 396 }
396 break; 397 break;
397 case 3: 398 case 3:
398 { 399 {
399 QString text; 400 QString text;
400 if (task.hasDueDate()) { 401 if (task.hasDueDate()) {
401 int off = QDate::currentDate().daysTo( task.dueDate() ); 402 int off = QDate::currentDate().daysTo( task.dueDate() );
402 text = tr( "%1 day(s)").arg(QString::number(off)); 403 text = tr( "%1 day(s)").arg(QString::number(off));
403 /* 404 /*
404 * set color if not completed 405 * set color if not completed
405 */ 406 */
406 if (!task.isCompleted() ) { 407 if (!task.isCompleted() ) {
407 QColor color = Qt::black; 408 QColor color = Qt::black;
408 if ( off < 0 ) 409 if ( off < 0 )
409 color = Qt::red; 410 color = Qt::red;
410 else if ( off == 0 ) 411 else if ( off == 0 )
411 color = Qt::yellow; 412 color = Qt::yellow;
412 else if ( off > 0 ) 413 else if ( off > 0 )
413 color = Qt::green; 414 color = Qt::green;
414 p->setPen(color ); 415 p->setPen(color );
415 } 416 }
416 } else { 417 } else {
417 text = tr("None"); 418 text = tr("None");
418 } 419 }
419 p->drawText(2,2 + fm.ascent(), text); 420 p->drawText(2,2 + fm.ascent(), text);
420 } 421 }
421 break; 422 break;
422 } 423 }
423 p->restore(); 424 p->restore();
424} 425}
425QWidget* TableView::createEditor(int row, int col, bool )const { 426QWidget* TableView::createEditor(int row, int col, bool )const {
426 switch( col ) { 427 switch( col ) {
427 case 1: { 428 case 1: {
428 /* the priority stuff */ 429 /* the priority stuff */
429 QComboBox* combo = new QComboBox( viewport() ); 430 QComboBox* combo = new QComboBox( viewport() );
430 for ( int i = 0; i < 5; i++ ) { 431 for ( int i = 0; i < 5; i++ ) {
431 combo->insertItem( m_pic_priority[ i ] ); 432 combo->insertItem( m_pic_priority[ i ] );
432 } 433 }
433 combo->setCurrentItem( sorted()[row].priority()-1 ); 434 combo->setCurrentItem( sorted()[row].priority()-1 );
434 return combo; 435 return combo;
435 } 436 }
436 /* summary */ 437 /* summary */
437 case 2:{ 438 case 2:{
438 QLineEdit* edit = new QLineEdit( viewport() ); 439 QLineEdit* edit = new QLineEdit( viewport() );
439 edit->setText( sorted()[row].summary() ); 440 edit->setText( sorted()[row].summary() );
440 return edit; 441 return edit;
441 } 442 }
442 case 0: 443 case 0:
443 default: 444 default:
444 return 0l; 445 return 0l;
445 } 446 }
446} 447}
447void TableView::setCellContentFromEditor(int row, int col ) { 448void TableView::setCellContentFromEditor(int row, int col ) {
448 if ( col == 1 ) { 449 if ( col == 1 ) {
449 QWidget* wid = cellWidget(row, 1 ); 450 QWidget* wid = cellWidget(row, 1 );
450 if ( wid->inherits("QComboBox") ) { 451 if ( wid->inherits("QComboBox") ) {
451 int pri = ((QComboBox*)wid)->currentItem() + 1; 452 int pri = ((QComboBox*)wid)->currentItem() + 1;
452 OTodo todo = sorted()[row]; 453 OTodo todo = sorted()[row];
453 if ( todo.priority() != pri ) { 454 if ( todo.priority() != pri ) {
454 todo.setPriority( pri ); 455 todo.setPriority( pri );
455 TodoView::update( todo.uid(), todo ); 456 TodoView::update( todo.uid(), todo );
456 updateView(); 457 updateView();
457 } 458 }
458 } 459 }
459 }else if ( col == 2) { 460 }else if ( col == 2) {
460 QWidget* wid = cellWidget(row, 2); 461 QWidget* wid = cellWidget(row, 2);
461 if ( wid->inherits("QLineEdit") ) { 462 if ( wid->inherits("QLineEdit") ) {
462 QString text = ((QLineEdit*)wid)->text(); 463 QString text = ((QLineEdit*)wid)->text();
463 OTodo todo = sorted()[row]; 464 OTodo todo = sorted()[row];
464 if ( todo.summary() != text ) { 465 if ( todo.summary() != text ) {
465 todo.setSummary( text ); 466 todo.setSummary( text );
466 TodoView::update( todo.uid(), todo ); 467 TodoView::update( todo.uid(), todo );
467 updateView(); 468 updateView();
468 } 469 }
469 } 470 }
470 } 471 }
471} 472}
472void TableView::slotPriority() { 473void TableView::slotPriority() {
473 setCellContentFromEditor( currentRow(), currentColumn() ); 474 setCellContentFromEditor( currentRow(), currentColumn() );
474} 475}
475/* 476/*
476 * We'll use the TimerEvent to read ahead or to keep the cahce always 477 * We'll use the TimerEvent to read ahead or to keep the cahce always
477 * filled enough. 478 * filled enough.
478 * We will try to read ahead 4 items in both ways 479 * We will try to read ahead 4 items in both ways
479 * up and down. On odd or even we will currentRow()+-4 or +-9 480 * up and down. On odd or even we will currentRow()+-4 or +-9
480 * 481 *
481 */ 482 */
482void TableView::timerEvent( QTimerEvent* ) { 483void TableView::timerEvent( QTimerEvent* ) {
483// qWarning("sorted %d", sorted().count() ); 484// qWarning("sorted %d", sorted().count() );
484 if (sorted().count() == 0 ) 485 if (sorted().count() == 0 )
485 return; 486 return;
486 487
487 int row = currentRow(); 488 int row = currentRow();
488 if ( m_row ) { 489 if ( m_row ) {
489 int ro = row-4; 490 int ro = row-4;
490 if (ro < 0 ) ro = 0; 491 if (ro < 0 ) ro = 0;
491 sorted()[ro]; 492 sorted()[ro];
492 493
493 ro = row+4; 494 ro = row+4;
494 sorted()[ro]; 495 sorted()[ro];
495 } else { 496 } else {
496 int ro = row + 8; 497 int ro = row + 8;
497 sorted()[ro]; 498 sorted()[ro];
498 499
499 ro = row-8; 500 ro = row-8;
500 if (ro < 0 ) ro = 0; 501 if (ro < 0 ) ro = 0;
501 sorted()[ro]; 502 sorted()[ro];
502 } 503 }
503 504
504 m_row = !m_row; 505 m_row = !m_row;
505} 506}
506 507
507// We want a strike through completed ;) 508// We want a strike through completed ;)
508// durchstreichen to complete 509// durchstreichen to complete
509/* 510/*
510 * MouseTracking is off this mean we only receive 511 * MouseTracking is off this mean we only receive
511 * these events if the mouse button is pressed 512 * these events if the mouse button is pressed
512 * We've the previous point saved 513 * We've the previous point saved
513 * We check if the previous and current Point are 514 * We check if the previous and current Point are
514 * in the same row. 515 * in the same row.
515 * Then we check if they're some pixel horizontal away 516 * Then we check if they're some pixel horizontal away
516 * if the distance between the two points is greater than 517 * if the distance between the two points is greater than
517 * 8 we mark the underlying todo as completed and do a repaint 518 * 8 we mark the underlying todo as completed and do a repaint
518 * 519 *
519 * BUG: When clicking on the Due column and it's scrollable 520 * BUG: When clicking on the Due column and it's scrollable
520 * the todo is marked as completed... 521 * the todo is marked as completed...
521 * REASON: QTable is doing auto scrolling which leads to a move 522 * REASON: QTable is doing auto scrolling which leads to a move
522 * in the x coordinate and this way it's able to pass the 523 * in the x coordinate and this way it's able to pass the
523 * m_completeStrokeWidth criteria 524 * m_completeStrokeWidth criteria
524 * WORKAROUND: strike through needs to strike through the same 525 * WORKAROUND: strike through needs to strike through the same
525 * row and two columns! 526 * row and two columns!
526 */ 527 */
527void TableView::contentsMouseReleaseEvent( QMouseEvent* e) { 528void TableView::contentsMouseReleaseEvent( QMouseEvent* e) {
528 int row = rowAt(m_prevP.y()); 529 int row = rowAt(m_prevP.y());
529 int colOld = columnAt(m_prevP.x() ); 530 int colOld = columnAt(m_prevP.x() );
530 int colNew = columnAt(e->x() ); 531 int colNew = columnAt(e->x() );
531 qWarning("colNew: %d colOld: %d", colNew, colOld ); 532 qWarning("colNew: %d colOld: %d", colNew, colOld );
532 if ( row == rowAt( e->y() ) && row != -1 && 533 if ( row == rowAt( e->y() ) && row != -1 &&
533 colOld != colNew ) { 534 colOld != colNew ) {
534 TodoView::complete( sorted()[row] ); 535 TodoView::complete( sorted()[row] );
535 return; 536 return;
536 } 537 }
537 QTable::contentsMouseReleaseEvent( e ); 538 QTable::contentsMouseReleaseEvent( e );
538} 539}
539void TableView::contentsMouseMoveEvent( QMouseEvent* e ) { 540void TableView::contentsMouseMoveEvent( QMouseEvent* e ) {
540 m_menuTimer->stop(); 541 m_menuTimer->stop();
541 QTable::contentsMouseMoveEvent( e ); 542 QTable::contentsMouseMoveEvent( e );
542} 543}
543void TableView::keyPressEvent( QKeyEvent* event) { 544void TableView::keyPressEvent( QKeyEvent* event) {
544 switch( event->key() ) { 545 switch( event->key() ) {
545 case Qt::Key_F33: 546 case Qt::Key_F33:
546 case Qt::Key_Enter: 547 case Qt::Key_Enter:
547 case Qt::Key_Return: 548 case Qt::Key_Return:
548 showTodo( sorted().uidAt( currentRow() ) ); 549 showTodo( sorted().uidAt( currentRow() ) );
549 break; 550 break;
550 default: 551 default:
551 QTable::keyPressEvent( event ); 552 QTable::keyPressEvent( event );
552 } 553 }
553} 554}