summaryrefslogtreecommitdiff
path: root/core/pim/todo/mainwindow.cpp
Side-by-side diff
Diffstat (limited to 'core/pim/todo/mainwindow.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--core/pim/todo/mainwindow.cpp213
1 files changed, 156 insertions, 57 deletions
diff --git a/core/pim/todo/mainwindow.cpp b/core/pim/todo/mainwindow.cpp
index 9b2423b..b2b3b8f 100644
--- a/core/pim/todo/mainwindow.cpp
+++ b/core/pim/todo/mainwindow.cpp
@@ -35,40 +35,43 @@
#include <qwidgetstack.h>
#include <qaction.h>
#include <qtimer.h>
#include <qvbox.h>
#include <qlineedit.h>
#include <qpe/applnk.h>
#include <qpe/config.h>
#include <qpe/ir.h>
#include <qpe/resource.h>
#include <qpe/qpemessagebox.h>
+#include <opie/orecur.h>
#include <opie/otodoaccessvcal.h>
#include "quickeditimpl.h"
#include "todotemplatemanager.h"
#include "templateeditor.h"
#include "tableview.h"
#include "textviewshow.h"
#include "todoeditor.h"
#include "mainwindow.h"
using namespace Todo;
MainWindow::MainWindow( QWidget* parent,
- const char* name ) {
+ const char* name )
+ : OPimMainWindow("Todolist")
+{
m_syncing = false;
m_counter = 0;
m_tempManager = new TemplateManager();
m_tempManager->load();
initUI();
initConfig();
initViews();
initActions();
initEditor();
initShow();
@@ -168,31 +171,28 @@ void MainWindow::initActions() {
connect(m_showDeadLineAction, SIGNAL(toggled(bool) ),
this, SLOT( slotShowDeadLine( bool ) ) );
m_options->insertSeparator();
m_bar->insertItem( tr("Data") ,m_edit );
m_bar->insertItem( tr("Category"), m_catMenu );
m_bar->insertItem( tr("Options"), m_options );
/* initialize the view menu */
a = new QAction( QString::null, tr("Show only over due"),
0, this, 0, TRUE );
- a->addTo( m_view );
+ a->addTo( m_options );
a->setOn( showOverDue() );
connect(a, SIGNAL(toggled(bool)),
this, SLOT(slotShowDue(bool) ) );
- m_view->insertSeparator();
-
- m_bar->insertItem( tr("View"), m_view );
/* templates */
m_edit->insertItem(tr("New from template"), m_template,
-1, 0 );
}
/* m_curCat from Config */
void MainWindow::initConfig() {
Config config( "todo" );
config.setGroup( "View" );
m_completed = config.readBoolEntry( "ShowComplete", TRUE );
m_curCat = config.readEntry( "Category", QString::null );
@@ -211,25 +211,24 @@ void MainWindow::initUI() {
setCentralWidget( m_mainBox );
setToolBarsMovable( FALSE );
m_tool = new QToolBar( this );
m_tool->setHorizontalStretchable( TRUE );
m_bar = new QMenuBar( m_tool );
/** QPopupMenu */
m_edit = new QPopupMenu( this );
m_options = new QPopupMenu( this );
- m_view = new QPopupMenu( this );
m_catMenu = new QPopupMenu( this );
m_template = new QPopupMenu( this );
m_catMenu->setCheckable( TRUE );
m_template->setCheckable( TRUE );
connect(m_catMenu, SIGNAL(activated(int) ),
this, SLOT(setCategory(int) ) );
connect(m_template, SIGNAL(activated(int) ),
this, SLOT(slotNewFromTemplate(int) ) );
}
void MainWindow::initViews() {
@@ -245,54 +244,53 @@ void MainWindow::initViews() {
}
void MainWindow::initEditor() {
m_curEdit = new Editor();
}
void MainWindow::initShow() {
m_curShow = new TextViewShow(this);
m_stack->addWidget( m_curShow->widget() , m_counter++ );
}
MainWindow::~MainWindow() {
delete templateManager();
}
void MainWindow::connectBase( ViewBase* base) {
- base->connectShow( this, SLOT(slotShow(int) ) );
- base->connectEdit( this, SLOT(slotEdit(int) ) );
- base->connectUpdateSmall( this,
- SLOT(slotUpate1(int, const Todo::SmallTodo&) ));
- base->connectUpdateBig( this,
- SLOT(slotUpate2(int, const OTodo& ) ) );
- base->connectUpdateView( this, SLOT(slotUpdate3( QWidget* ) ) ) ;
- base->connectRemove(&m_todoMgr,
- SLOT(remove(int)) );
-}
-QPopupMenu* MainWindow::contextMenu( int uid ) {
+ // once templates and signals mix we'll use it again
+}
+QPopupMenu* MainWindow::contextMenu( int , bool recur ) {
QPopupMenu* menu = new QPopupMenu();
m_editAction->addTo( menu );
m_deleteAction->addTo( menu );
m_duplicateAction->addTo( menu );
+
menu->insertSeparator();
+ /*
+ * if this event recurs we allow
+ * to detach it.
+ * remove all
+ */
+ if ( recur ) {
+ ; // FIXME
+ }
+
return menu;
}
QPopupMenu* MainWindow::options() {
qWarning("Options");
return m_options;
}
QPopupMenu* MainWindow::edit() {
return m_edit;
}
-QPopupMenu* MainWindow::view() {
- return m_view;
-}
QToolBar* MainWindow::toolbar() {
return m_tool;
}
OTodoAccess::List MainWindow::list()const {
return m_todoMgr.list();
}
OTodoAccess::List MainWindow::sorted( bool asc, int sortOrder ) {
int cat = 0;
if ( m_curCat != tr("All Categories") )
cat = currentCatId();
int filter = 1;
@@ -404,46 +402,25 @@ void MainWindow::slotNewFromTemplate( int id ) {
event );
if ( currentEditor()->accepted() ) {
/* assign new todo */
event.setUid( -1 );
currentView()->addEvent( event );
m_todoMgr.add( event );
populateCategories();
}
}
void MainWindow::slotNew() {
- if(m_syncing) {
- QMessageBox::warning(this, tr("Todo"),
- tr("Can not edit data, currently syncing"));
- return;
- }
-
-
- OTodo todo = currentEditor()->newTodo( currentCatId(),
- this );
-
- if ( currentEditor()->accepted() ) {
- //todo.assignUid();
- m_todoMgr.add( todo );
- currentView()->addEvent( todo );
-
-
- // I'm afraid we must call this every time now, otherwise
- // spend expensive time comparing all these strings...
- // but only call if we changed something -zecke
- populateCategories();
- }
- raiseCurrentView( );
+ create();
}
void MainWindow::slotDuplicate() {
if(m_syncing) {
QMessageBox::warning(this, tr("Todo"),
tr("Can not edit data, currently syncing"));
return;
}
OTodo ev = m_todoMgr.event( currentView()->current() );
/* let's generate a new uid */
ev.setUid(-1);
m_todoMgr.add( ev );
@@ -465,46 +442,45 @@ void MainWindow::slotDelete() {
m_todoMgr.remove( currentView()->current() );
currentView()->removeEvent( currentView()->current() );
raiseCurrentView();
}
void MainWindow::slotDeleteAll() {
if(m_syncing) {
QMessageBox::warning(this, tr("Todo"),
tr("Can not edit data, currently syncing"));
return;
}
- //QString strName = table->text( table->currentRow(), 2 ).left( 30 );
if ( !QPEMessageBox::confirmDelete( this, tr( "Todo" ), tr("all tasks?") ) )
return;
m_todoMgr.removeAll();
currentView()->clear();
raiseCurrentView();
}
void MainWindow::slotDeleteCompleted() {
if(m_syncing) {
QMessageBox::warning(this, tr("Todo"),
tr("Can not edit data, currently syncing"));
return;
}
if ( !QPEMessageBox::confirmDelete( this, tr( "Todo" ), tr("all completed tasks?") ) )
return;
- // FIXME
- //m_todoMgr.remove( currentView()->completed() );
+
+ m_todoMgr.removeCompleted();
currentView()->updateView( );
}
void MainWindow::slotFind() {
}
void MainWindow::slotEdit() {
slotEdit( currentView()->current() );
}
/*
* set the category
*/
void MainWindow::setCategory( int c) {
@@ -543,36 +519,25 @@ bool MainWindow::showOverDue()const {
return m_overdue;
}
void MainWindow::setDocument( const QString& fi) {
DocLnk doc(fi);
if (doc.isValid() )
receiveFile(doc.file() );
else
receiveFile(fi );
}
static const char *beamfile = "/tmp/opie-todo.vcs";
void MainWindow::slotBeam() {
- ::unlink( beamfile );
- OTodo todo = event( currentView()->current() );
- OTodoAccessVCal* cal = new OTodoAccessVCal(QString::fromLatin1(beamfile) );
- OTodoAccess acc( cal );
- acc.load();
- acc.add( todo );
- acc.save();
- Ir* ir = new Ir(this );
- connect(ir, SIGNAL(done(Ir*) ),
- this, SLOT(beamDone(Ir*) ) );
- ir->send( beamfile, todo.summary(), "text/x-vCalendar" );
-
+ beam( currentView()->current() );
}
void MainWindow::beamDone( Ir* ir) {
delete ir;
::unlink( beamfile );
}
void MainWindow::receiveFile( const QString& filename ) {
OTodoAccessVCal* cal = new OTodoAccessVCal(filename );
OTodoAccess acc( cal );
acc.load();
OTodoAccess::List list = acc.allRecords();
QString message = tr("<P>%1 new tasks arrived.<p>Would you like to add them to your Todolist?").arg(list.count() );
@@ -695,12 +660,146 @@ void MainWindow::slotQuickEntered() {
qWarning("entered");
OTodo todo = quickEditor()->todo();
if (todo.isEmpty() )
return;
m_todoMgr.add( todo );
currentView()->addEvent( todo );
raiseCurrentView();
}
QuickEditBase* MainWindow::quickEditor() {
return m_curQuick;
}
+void MainWindow::slotComplete( int uid ) {
+ slotComplete( event(uid) );
+}
+void MainWindow::slotComplete( const OTodo& todo ) {
+ OTodo to = todo;
+ to.setCompleted( !to.isCompleted() );
+ to.setCompletedDate( QDate::currentDate() );
+
+ /*
+ * if the item does recur
+ * we need to spin it off
+ * and update the items duedate to the next
+ * possible recurrance of this item...
+ * the spinned off one will loose the
+ */
+ if ( to.recurrence().doesRecur() && to.isCompleted() ) {
+ OTodo to2( to );
+
+ /* the spinned off one won't recur anymore */
+ to.setRecurrence( ORecur() );
+
+ ORecur rec = to2.recurrence();
+ rec.setStart( to.dueDate() );
+ to2.setRecurrence( rec );
+ /*
+ * if there is a next occurence
+ * from the duedate of the last recurrance
+ */
+ QDate date;
+ if ( to2.recurrence().nextOcurrence( to2.dueDate().addDays(1), date ) ) {
+ QDate inval;
+ /* generate a new uid for the old record */
+ to.setUid( 1 );
+
+ /* add the old one cause it has a new UID here cause it was spin off */
+ m_todoMgr.add( to );
+
+ /*
+ * update the due date
+ * start date
+ * and complete date
+ */
+ to2.setDueDate( date );
+ to2.setStartDate( inval );
+ to2.setCompletedDate( inval );
+ to2.setCompleted( false );
+ updateTodo( to2 );
+ }else
+ updateTodo( to );
+ }else
+ updateTodo( to );
+
+ currentView()->updateView();
+ raiseCurrentView();
+}
+void MainWindow::flush() {
+ slotFlush();
+}
+void MainWindow::reload() {
+ slotReload();
+}
+int MainWindow::create() {
+ int uid = 0;
+ if(m_syncing) {
+ QMessageBox::warning(this, tr("Todo"),
+ tr("Can not edit data, currently syncing"));
+ return uid;
+ }
+
+
+ OTodo todo = currentEditor()->newTodo( currentCatId(),
+ this );
+
+ if ( currentEditor()->accepted() ) {
+ //todo.assignUid();
+ uid = todo.uid();
+ m_todoMgr.add( todo );
+ currentView()->addEvent( todo );
+
+
+ // I'm afraid we must call this every time now, otherwise
+ // spend expensive time comparing all these strings...
+ // but only call if we changed something -zecke
+ populateCategories();
+ }
+ raiseCurrentView( );
+
+ return uid;
+}
+/* delete it silently... */
+bool MainWindow::remove( int uid ) {
+ if (m_syncing) return false;
+
+ return m_todoMgr.remove( uid );
+}
+void MainWindow::beam( int uid, int ) {
+ ::unlink( beamfile );
+ OTodo todo = event( uid );
+ OTodoAccessVCal* cal = new OTodoAccessVCal(QString::fromLatin1(beamfile) );
+ OTodoAccess acc( cal );
+ acc.load();
+ acc.add( todo );
+ acc.save();
+ Ir* ir = new Ir(this );
+ connect(ir, SIGNAL(done(Ir*) ),
+ this, SLOT(beamDone(Ir*) ) );
+ ir->send( beamfile, todo.summary(), "text/x-vCalendar" );
+}
+void MainWindow::show( int uid ) {
+ slotShow( uid );
+}
+void MainWindow::edit( int uid ) {
+ slotEdit( uid );
+}
+void MainWindow::add( const OPimRecord& rec) {
+ if ( rec.rtti() != OTodo::rtti() ) return;
+
+ const OTodo& todo = static_cast<const OTodo&>(rec);
+
+ m_todoMgr.add(todo );
+ currentView()->addEvent( todo );
+
+
+ // I'm afraid we must call this every time now, otherwise
+ // spend expensive time comparing all these strings...
+ // but only call if we changed something -zecke
+ populateCategories();
+}
+/* todo does not have the QDataStream<< and >> operators implemented :(
+ * FIXME
+ */
+OPimRecord* MainWindow::record( int rtti, const QByteArray& ) {
+ return 0l;
+}