summaryrefslogtreecommitdiff
Side-by-side diff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/pim/todo/mainwindow.cpp106
-rw-r--r--core/pim/todo/mainwindow.h14
-rw-r--r--core/pim/todo/todotable.cpp148
-rw-r--r--core/pim/todo/todotable.h7
4 files changed, 238 insertions, 37 deletions
diff --git a/core/pim/todo/mainwindow.cpp b/core/pim/todo/mainwindow.cpp
index b5cace9..883d78c 100644
--- a/core/pim/todo/mainwindow.cpp
+++ b/core/pim/todo/mainwindow.cpp
@@ -123,8 +123,10 @@ TodoWindow::TodoWindow( QWidget *parent, const char *name, WFlags f = 0 ) :
QPEMenuBar *mb = new QPEMenuBar( bar );
catMenu = new QPopupMenu( this );
QPopupMenu *edit = new QPopupMenu( this );
+ QPopupMenu *options = new QPopupMenu(this );
+
contextMenu = new QPopupMenu( this );
bar = new QPEToolBar( this );
@@ -134,19 +136,20 @@ TodoWindow::TodoWindow( QWidget *parent, const char *name, WFlags f = 0 ) :
this, SLOT( slotNew() ) );
a->addTo( bar );
a->addTo( edit );
- a = new QAction( tr( "Edit" ), Resource::loadIconSet( "edit" ),
+ a = new QAction( tr( "Edit Task" ), Resource::loadIconSet( "edit" ),
QString::null, 0, this, 0 );
connect( a, SIGNAL( activated() ),
this, SLOT( slotEdit() ) );
a->addTo( bar );
a->addTo( edit );
a->addTo( contextMenu );
a->setEnabled( FALSE );
editAction = a;
+ edit->insertSeparator();
- a = new QAction( tr( "Delete" ), Resource::loadIconSet( "trash" ),
+ a = new QAction( tr( "Delete..." ), Resource::loadIconSet( "trash" ),
QString::null, 0, this, 0 );
connect( a, SIGNAL( activated() ),
this, SLOT( slotDelete() ) );
a->addTo( bar );
@@ -154,8 +157,28 @@ TodoWindow::TodoWindow( QWidget *parent, const char *name, WFlags f = 0 ) :
a->addTo( contextMenu );
a->setEnabled( FALSE );
deleteAction = a;
+ // delete All in category is missing....
+ // set All Done
+ // set All Done in category
+
+ a = new QAction( QString::null, tr( "Delete all..."), 0, this, 0 );
+ connect(a, SIGNAL( activated() ),
+ this, SLOT( slotDeleteAll() ) );
+ a->addTo(edit );
+ a->setEnabled( FALSE );
+ deleteAllAction = a;
+
+ edit->insertSeparator();
+ a = new QAction( QString::null, tr("Duplicate" ), 0, this, 0 );
+ connect(a, SIGNAL( activated() ),
+ this, SLOT( slotDuplicate() ) );
+ a->addTo(edit );
+ a->setEnabled( FALSE );
+ duplicateAction = a;
+
+ edit->insertSeparator();
if ( Ir::supported() ) {
a = new QAction( tr( "Beam" ), Resource::loadPixmap( "beam" ),
QString::null, 0, this, 0 );
connect( a, SIGNAL( activated() ),
@@ -168,9 +191,11 @@ TodoWindow::TodoWindow( QWidget *parent, const char *name, WFlags f = 0 ) :
QString::null, 0, this, 0 );
connect( a, SIGNAL( activated() ),
this, SLOT( slotFind() ) );
a->addTo( bar );
- a->addTo( edit );
+ a->addTo( options );
+ options->insertSeparator();
+
if ( table->numRows() )
a->setEnabled( TRUE );
else
a->setEnabled( FALSE );
@@ -185,11 +210,26 @@ TodoWindow::TodoWindow( QWidget *parent, const char *name, WFlags f = 0 ) :
catMenu->setCheckable( true );
populateCategories();
- mb->insertItem( tr( "Data" ), edit );
- mb->insertItem( tr( "View" ), catMenu );
+
+ completedAction->addTo( options );
+ completedAction->setOn( table->showCompleted() );
+ showdeadlineAction->addTo( options );
+ showdeadlineAction->setOn( table->showDeadline() );
+ options->insertSeparator( );
+ QList<QWidget> list;
+ list.append(table );
+ OFontMenu *menu = new OFontMenu(this, "menu",list );
+ menu->forceSize( table->horizontalHeader(), 10 );
+ //catMenu->insertItem(tr("Fonts"), menu );
+ list.clear();
+ options->insertItem( tr("Fonts"), menu );
+
+ mb->insertItem( tr( "Data" ), edit );
+ mb->insertItem( tr( "Category" ), catMenu );
+ mb->insertItem( tr( "Options"), options );
resize( 200, 300 );
if ( table->numRows() > 0 )
currentEntryChanged( 0, 0 );
connect( table, SIGNAL( signalEdit() ),
@@ -278,8 +318,32 @@ void TodoWindow::slotDelete()
currentEntryChanged( -1, 0 );
findAction->setEnabled( FALSE );
}
}
+void TodoWindow::slotDeleteAll()
+{
+ if(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("Should I delete all tasks?") ) )
+ return;
+
+
+
+ table->setPaintingEnabled( false );
+ table->removeAllEntries();
+ table->setPaintingEnabled( true );
+
+ if ( table->numRows() == 0 ) {
+ currentEntryChanged( -1, 0 );
+ findAction->setEnabled( FALSE );
+ }
+}
void TodoWindow::slotEdit()
{
if(syncing) {
@@ -306,9 +370,21 @@ void TodoWindow::slotEdit()
}
populateCategories();
}
-
+void TodoWindow::slotDuplicate()
+{
+ if(syncing) {
+ QMessageBox::warning(this, tr("Todo"),
+ tr("Can not edit data, currently syncing"));
+ return;
+ }
+ ToDoEvent ev = table->currentEntry();
+ ToDoEvent ev2 = ToDoEvent( ev );
+ table->setPaintingEnabled( false );
+ table->addEntry( ev2 );
+ table->setPaintingEnabled( true );
+}
void TodoWindow::slotShowPopup( const QPoint &p )
{
contextMenu->popup( p );
}
@@ -326,11 +402,15 @@ void TodoWindow::currentEntryChanged( int r, int )
{
if ( r != -1 && table->rowHeight( r ) > 0 ) {
editAction->setEnabled( TRUE );
deleteAction->setEnabled( TRUE );
+ duplicateAction->setEnabled( TRUE );
+ deleteAllAction->setEnabled( TRUE );
} else {
editAction->setEnabled( FALSE );
deleteAction->setEnabled( FALSE );
+ duplicateAction->setEnabled( FALSE );
+ deleteAllAction->setEnabled( FALSE );
}
}
void TodoWindow::setCategory( int c )
@@ -357,24 +437,12 @@ void TodoWindow::setCategory( int c )
void TodoWindow::populateCategories()
{
catMenu->clear();
-
- QList<QWidget> list;
- list.append(table );
- OFontMenu *menu = new OFontMenu(this, "menu",list );
- menu->forceSize( table->horizontalHeader(), 10 );
- catMenu->insertItem(tr("Fonts"), menu );
-
- completedAction->addTo( catMenu );
- completedAction->setOn( table->showCompleted() );
- showdeadlineAction->addTo( catMenu );
- showdeadlineAction->setOn( table->showDeadline() );
- catMenu->insertSeparator();
int id, rememberId;
id = 1;
catMenu->insertItem( tr( "All Categories" ), id++ );
-// catMenu->insertSeparator();
+ catMenu->insertSeparator();
QStringList categories = table->categories();
categories.append( tr( "Unfiled" ) );
for ( QStringList::Iterator it = categories.begin();
it != categories.end(); ++it ) {
diff --git a/core/pim/todo/mainwindow.h b/core/pim/todo/mainwindow.h
index 9be7c66..b9172e1 100644
--- a/core/pim/todo/mainwindow.h
+++ b/core/pim/todo/mainwindow.h
@@ -57,9 +57,11 @@ protected slots:
void slotFind();
void setDocument( const QString & );
void slotBeam();
void beamDone( Ir * );
-
+ void slotDeleteAll();
+ void slotDuplicate();
+
protected:
void closeEvent( QCloseEvent *e );
private:
@@ -67,12 +69,14 @@ private:
private:
TodoTable *table;
QAction *editAction,
- *deleteAction,
- *findAction,
- * completedAction,
- *showdeadlineAction ;
+ *deleteAction,
+ *findAction,
+ *completedAction,
+ *showdeadlineAction,
+ *deleteAllAction,
+ *duplicateAction;
QPopupMenu *contextMenu, *catMenu;
bool syncing;
};
diff --git a/core/pim/todo/todotable.cpp b/core/pim/todo/todotable.cpp
index 2acd03c..401d2c8 100644
--- a/core/pim/todo/todotable.cpp
+++ b/core/pim/todo/todotable.cpp
@@ -21,8 +21,10 @@
*/
#include "todotable.h"
#include <opie/tododb.h>
+#include <opie/xmltree.h>
+
#include <qpe/categoryselect.h>
#include <qpe/xmlreader.h>
#include <qasciidict.h>
@@ -31,23 +33,25 @@
#include <qpainter.h>
#include <qtextcodec.h>
#include <qtimer.h>
#include <qdatetime.h>
+#include <qtextstream.h>
#include <qcursor.h>
#include <qregexp.h>
#include <errno.h>
#include <stdlib.h>
#include <stdio.h>
+#include <iostream>
+namespace {
-
-static bool taskCompare( const ToDoEvent &task, const QRegExp &r, int category );
-
-static QString journalFileName();
-
+ static bool taskCompare( const ToDoEvent &task, const QRegExp &r, int category );
+ static QString journalFileName();
+ static ToDoEvent xmlToEvent( XMLElement *ev );
+}
CheckItem::CheckItem( QTable *t, const QString &key )
: QTableItem( t, Never, "" ), checked( FALSE ), sortKey( key )
{
}
@@ -408,18 +412,17 @@ bool TodoTable::save( const QString &fn )
void TodoTable::load( const QString &fn )
{
loadFile( fn, false );
if ( QFile::exists(journalFileName()) ) {
- loadFile( journalFileName(), true );
+ applyJournal( );
save( fn );
}
// QTable::sortColumn(2,TRUE,TRUE);
// QTable::sortColumn(1,TRUE,TRUE);
QTable::sortColumn(0,TRUE,TRUE);
setCurrentCell( 0, 2 );
setSorting(true );
}
-
void TodoTable::updateVisible()
{
if ( !isUpdatesEnabled() )
return;
@@ -445,9 +448,9 @@ void TodoTable::updateVisible()
if ( showCat == tr( "Unfiled" ) ) {
if ( vlCats.count() > 0 )
hide = true;
} else {
- // do some comparing, we have to reverse our idea here... which idea - zecke
+ // do some comparing, we have to reverse our idea here... which idea? - zecke
if ( !hide ) {
hide = true;
for ( uint it = 0; it < vlCats.count(); ++it ) {
if ( vlCats[it] == id ) {
@@ -498,8 +501,9 @@ void TodoTable::clear()
{
for ( QMap<CheckItem*, ToDoEvent *>::Iterator it = todoList.begin();
it != todoList.end(); ++it ) {
ToDoEvent *todo = *it;
+ updateJournal( todo, ACTION_REMOVE, 0 );
delete todo;
}
todoList.clear();
for ( int r = 0; r < numRows(); ++r ) {
@@ -532,9 +536,9 @@ void TodoTable::slotCheckPriority(int row, int col )
}
}
-void TodoTable::updateJournal( const ToDoEvent &/*todo*/, journal_action action, int row )
+void TodoTable::updateJournal( const ToDoEvent &todo, journal_action action, int row )
{
QFile f( journalFileName() );
if ( !f.open(IO_WriteOnly|IO_Append) )
return;
@@ -542,9 +546,26 @@ void TodoTable::updateJournal( const ToDoEvent &/*todo*/, journal_action action,
QCString str;
buf = "<Task";
// todo.save( buf );
buf += " Action=\"" + QString::number( int(action) ) + "\"";
- buf += " Row=\"" + QString::number( row ) + "\""; // better write the id
+ buf += " Uid=\"" + QString::number( todo.uid() ) + "\""; // better write the id
+ buf += " Completed=\""+ QString::number((int)todo.isCompleted() ) + "\"";
+ buf += " HasDate=\""+ QString::number((int)todo.hasDate() ) +"\"";
+ buf += " Priority=\"" + QString::number( todo.priority() ) + "\"";
+ QArray<int> arrat = todo.categories();
+ QString attr;
+ for(uint i=0; i < arrat.count(); i++ ){
+ attr.append(QString::number(arrat[i])+";" );
+ }
+ if(!attr.isEmpty() ) // remove the last ;
+ attr.remove(attr.length()-1, 1 );
+ buf += " Categories=\"" + attr + "\"";
+ buf += " Description=\"" + todo.description() + "\"";
+ if(todo.hasDate() ) {
+ buf += " DateYear=\""+QString::number( todo.date().year() ) + "\"";
+ buf += " DateMonth=\"" + QString::number( todo.date().month() ) + "\"";
+ buf += " DateDay=\"" + QString::number( todo.date().day() ) + "\"";
+ }
buf += "/>\n";
str = buf.utf8();
f.writeBlock( str.data(), str.length() );
f.close();
@@ -714,9 +735,57 @@ int TodoTable::showCategoryId() const
if ( showCat != tr( "Unfiled" ) && showCat != tr( "All" ) )
id = mCat.id( "Todo List", showCat );
return id;
}
-
+void TodoTable::applyJournal()
+{
+ // we need to hack
+ QFile file( journalFileName() );
+ if( file.open(IO_ReadOnly ) ) {
+ QByteArray ar = file.readAll();
+ file.close();
+ QFile file2( journalFileName() + "_new" );
+ if( file2.open(IO_WriteOnly ) ){
+ QTextStream str(&file2 );
+ str << QString::fromLatin1("<Tasks>") << endl;
+ str << ar.data();
+ str << QString::fromLatin1("</Tasks>") << endl;
+ file2.close();
+ }
+ XMLElement *root = XMLElement::load(journalFileName()+ "_new");
+ XMLElement *el = root->firstChild();
+ el = el->firstChild();
+ while( el ){
+ qWarning("journal: %s %s", el->attribute("Uid" ).latin1(), el->tagName().latin1() );
+ doApply( el );
+ el = el->nextChild();
+ }
+ QFile::remove(journalFileName()+ "_new" );
+ }
+}
+// check Action and decide
+void TodoTable::doApply(XMLElement *el )
+{
+ QString dummy;
+ bool ok;
+ int action;
+ dummy = el->attribute("Action" );
+ action = dummy.toInt(&ok );
+ ToDoEvent ev = xmlToEvent( el );
+ if( ok ){
+ switch( action ){
+ case ACTION_ADD:
+ addEntry( ev );
+ break;
+ case ACTION_REMOVE:{ // find an entry with the same uid and remove it then
+ break;
+ }
+ case ACTION_REPLACE:
+ break;
+ }
+ }
+}
+namespace {
static bool taskCompare( const ToDoEvent &task, const QRegExp &r, int category )
{
bool returnMe;
QArray<int> cats;
@@ -740,12 +809,66 @@ static bool taskCompare( const ToDoEvent &task, const QRegExp &r, int category )
static QString journalFileName()
{
QString str;
str = getenv( "HOME" );
- str += "/.todojournal";
+ str += "/.opie_todojournal";
return str;
}
+static ToDoEvent xmlToEvent( XMLElement *element )
+{
+ QString dummy;
+ ToDoEvent event;
+ bool ok;
+ int dumInt;
+ // completed
+ dummy = element->attribute("Completed" );
+ dumInt = dummy.toInt(&ok );
+ if(ok ) event.setCompleted( dumInt == 0 ? false : true );
+ // hasDate
+ dummy = element->attribute("HasDate" );
+ dumInt = dummy.toInt(&ok );
+ if(ok ) event.setHasDate( dumInt == 0 ? false: true );
+ // set the date
+ bool hasDa = dumInt;
+ if ( hasDa ) { //parse the date
+ int year, day, month = 0;
+ year = day = month;
+ // year
+ dummy = element->attribute("DateYear" );
+ dumInt = dummy.toInt(&ok );
+ if( ok ) year = dumInt;
+ // month
+ dummy = element->attribute("DateMonth" );
+ dumInt = dummy.toInt(&ok );
+ if(ok ) month = dumInt;
+ dummy = element->attribute("DateDay" );
+ dumInt = dummy.toInt(&ok );
+ if(ok ) day = dumInt;
+ // set the date
+ QDate date( year, month, day );
+ event.setDate( date);
+ }
+ dummy = element->attribute("Priority" );
+ dumInt = dummy.toInt(&ok );
+ if(!ok ) dumInt = ToDoEvent::NORMAL;
+ event.setPriority( dumInt );
+ //description
+ dummy = element->attribute("Description" );
+ event.setDescription( dummy );
+ // category
+ dummy = element->attribute("Categories" );
+ QStringList ids = QStringList::split(";", dummy );
+ event.setCategories( ids );
+
+ //uid
+ dummy = element->attribute("Uid" );
+ dumInt = dummy.toInt(&ok );
+ if(ok ) event.setUid( dumInt );
+
+ return event;
+}
+}
// int TodoTable::rowHeight( int ) const
// {
// return 18;
// }
@@ -758,4 +881,5 @@ static QString journalFileName()
// int TodoTable::rowAt( int pos ) const
// {
// return QMIN( pos/18, numRows()-1 );
// }
+
diff --git a/core/pim/todo/todotable.h b/core/pim/todo/todotable.h
index 32df514..6917e04 100644
--- a/core/pim/todo/todotable.h
+++ b/core/pim/todo/todotable.h
@@ -91,10 +91,11 @@ class DueTextItem : public QTableItem
};
-enum journal_action { ACTION_ADD, ACTION_REMOVE, ACTION_REPLACE };
+enum journal_action { ACTION_ADD=0, ACTION_REMOVE, ACTION_REPLACE };
+class XMLElement;
class TodoTable : public QTable
{
Q_OBJECT
@@ -119,10 +120,13 @@ public:
int showCategoryId() const;
bool save( const QString &fn );
void load( const QString &fn );
+ void applyJournal( );
void clear();
void removeCurrentEntry();
+ void removeAllEntries() { clear(); };
+ //void removeAllEntriesInCategory(const QString &category );
void setPaintingEnabled( bool e );
virtual void sortColumn( int col, bool ascending, bool /*wholeRows*/ );
@@ -152,8 +156,9 @@ private:
void journalFreeReplaceEntry( const ToDoEvent &todo, int row );
void journalFreeRemoveEntry( int row );
inline void realignTable( int row );
void loadFile( const QString &strFile, bool fromJournal = false );
+ void doApply(XMLElement *el );
private slots:
void slotClicked( int row, int col, int button, const QPoint &pos );
void slotPressed( int row, int col, int button, const QPoint &pos );