author | zecke <zecke> | 2002-04-29 10:17:33 (UTC) |
---|---|---|
committer | zecke <zecke> | 2002-04-29 10:17:33 (UTC) |
commit | e4d0908ec054b71a9b97e9c35efbd5a697d0b58d (patch) (side-by-side diff) | |
tree | 1c483d82624c8af936af99399db9c7ea7922c90c | |
parent | 9e2a233287309bdb6bcb228aaf075f8c14a1a687 (diff) | |
download | opie-e4d0908ec054b71a9b97e9c35efbd5a697d0b58d.zip opie-e4d0908ec054b71a9b97e9c35efbd5a697d0b58d.tar.gz opie-e4d0908ec054b71a9b97e9c35efbd5a697d0b58d.tar.bz2 |
Create an Event. And modify it and try to view it
The Event gets "losed" this was reported by Stefan Eilers
Currently I'm searching my brown paper bag but I just wanted to say
I fixed it it was introduced with the change from Task-> ToDoDB
-rw-r--r-- | core/pim/todo/mainwindow.cpp | 3 | ||||
-rw-r--r-- | core/pim/todo/todotable.cpp | 3 |
2 files changed, 3 insertions, 3 deletions
diff --git a/core/pim/todo/mainwindow.cpp b/core/pim/todo/mainwindow.cpp index a28fc3e..294f37c 100644 --- a/core/pim/todo/mainwindow.cpp +++ b/core/pim/todo/mainwindow.cpp @@ -183,394 +183,395 @@ TodoWindow::TodoWindow( QWidget *parent, const char *name, WFlags f = 0 ) : 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() ), this, SLOT( slotBeam() ) ); a->addTo( edit ); a->addTo( bar ); } a = new QAction( tr( "Find" ), Resource::loadIconSet( "mag" ), QString::null, 0, this, 0 ); connect( a, SIGNAL( activated() ), this, SLOT( slotFind() ) ); a->addTo( bar ); a->addTo( options ); options->insertSeparator(); if ( table->numRows() ) a->setEnabled( TRUE ); else a->setEnabled( FALSE ); //a->setEnabled( FALSE ); findAction = a; // qDebug("mainwindow #2: t=%d", t.elapsed() ); completedAction = new QAction( QString::null, tr("Completed tasks"), 0, this, 0, TRUE ); showdeadlineAction = new QAction( QString::null, tr( "Show Deadline" ), 0, this, 0, TRUE ); catMenu->setCheckable( true ); populateCategories(); 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() ), this, SLOT( slotEdit() ) ); connect( table, SIGNAL(signalShowMenu(const QPoint &)), this, SLOT( slotShowPopup(const QPoint &)) ); // qDebug("mainwindow #3: t=%d", t.elapsed() ); table->updateVisible(); table->setUpdatesEnabled( TRUE ); table->setPaintingEnabled( TRUE ); table->viewport()->setUpdatesEnabled( TRUE ); connect( completedAction, SIGNAL( toggled(bool) ), this, SLOT( showCompleted(bool) ) ); connect( showdeadlineAction, SIGNAL( toggled(bool) ), this, SLOT( showDeadline(bool) ) ); connect( catMenu, SIGNAL(activated(int)), this, SLOT(setCategory(int)) ); connect( table, SIGNAL( currentChanged( int, int ) ), this, SLOT( currentEntryChanged( int, int ) ) ); connect( table, SIGNAL(showDetails(const ToDoEvent &) ), this, SLOT(slotShowDetails(const ToDoEvent & ) ) ); // qDebug("done: t=%d", t.elapsed() ); } void TodoWindow::slotNew() { if(syncing) { QMessageBox::warning(this, tr("Todo"), tr("Can not edit data, currently syncing")); return; } int id; id = -1; QArray<int> ids; ids = table->currentEntry().categories(); if ( ids.count() ) id = ids[0]; NewTaskDialog e( id, this, 0, TRUE ); ToDoEvent todo; #if defined(Q_WS_QWS) || defined(_WS_QWS_) e.showMaximized(); #endif int ret = e.exec(); // qWarning("finished" ); if ( ret == QDialog::Accepted ) { table->setPaintingEnabled( false ); todo = e.todoEntry(); //todo.assignUid(); table->addEntry( todo ); table->setPaintingEnabled( true ); findAction->setEnabled( TRUE ); } // I'm afraid we must call this every time now, otherwise // spend expensive time comparing all these strings... populateCategories(); mStack->raiseWidget(1 ); } TodoWindow::~TodoWindow() { } void TodoWindow::slotDelete() { if(syncing) { QMessageBox::warning(this, tr("Todo"), tr("Can not edit data, currently syncing")); return; } if ( table->currentRow() == -1 ) return; QString strName = table->text( table->currentRow(), 2 ).left( 30 ); if ( !QPEMessageBox::confirmDelete( this, tr( "Todo" ), strName ) ) return; table->setPaintingEnabled( false ); table->removeCurrentEntry(); table->setPaintingEnabled( true ); if ( table->numRows() == 0 ) { currentEntryChanged( -1, 0 ); findAction->setEnabled( FALSE ); } mStack->raiseWidget(1); } 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("Delete all tasks?") ) ) return; table->setPaintingEnabled( false ); table->removeAllEntries(); table->setPaintingEnabled( true ); if ( table->numRows() == 0 ) { currentEntryChanged( -1, 0 ); findAction->setEnabled( FALSE ); } mStack->raiseWidget(1 ); } void TodoWindow::slotEdit() { if(syncing) { QMessageBox::warning(this, tr("Todo"), tr("Can not edit data, currently syncing")); return; } ToDoEvent todo = table->currentEntry(); - + qWarning("slotEdit" ); NewTaskDialog e( todo, this, 0, TRUE ); e.setCaption( tr( "Edit Task" ) ); #if defined(Q_WS_QWS) || defined(_WS_QWS_) e.showMaximized(); #endif int ret = e.exec(); if ( ret == QDialog::Accepted ) { + qWarning("Replacing now" ); table->setPaintingEnabled( false ); todo = e.todoEntry(); table->replaceCurrentEntry( todo ); table->setPaintingEnabled( true ); } populateCategories(); mStack->raiseWidget( 1 ); } 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 ); // what about the uid int uid; { // uid Qtopia::UidGen *uidgen = new Qtopia::UidGen(); uid = uidgen->generate(); delete uidgen; } ev2.setUid( uid ); table->setPaintingEnabled( false ); table->addEntry( ev2 ); table->setPaintingEnabled( true ); mStack->raiseWidget( 1 ); } void TodoWindow::slotShowPopup( const QPoint &p ) { contextMenu->popup( p ); } void TodoWindow::showCompleted( bool s ) { if ( !table->isUpdatesEnabled() ) return; table->setPaintingEnabled( false ); table->setShowCompleted( s ); table->setPaintingEnabled( true ); mStack->raiseWidget( 1 ); } 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 ) { if ( c <= 0 ) return; if ( !table->isUpdatesEnabled() ) return; table->setPaintingEnabled( false ); for ( unsigned int i = 1; i < catMenu->count(); i++ ) catMenu->setItemChecked( i, c == (int)i ); if ( c == 1 ) { table->setShowCategory( QString::null ); setCaption( tr("Todo") + " - " + tr( "All Categories" ) ); } else if ( c == (int)catMenu->count() - 1 ) { table->setShowCategory( tr( "Unfiled" ) ); setCaption( tr("Todo") + " - " + tr( "Unfiled" ) ); } else { QString cat = table->categories()[c - 2]; table->setShowCategory( cat ); setCaption( tr("Todo") + " - " + cat ); } table->setPaintingEnabled( true ); mStack->raiseWidget( 1 ); } void TodoWindow::populateCategories() { catMenu->clear(); int id, rememberId; id = 1; rememberId = 0; catMenu->insertItem( tr( "All Categories" ), id++ ); catMenu->insertSeparator(); QStringList categories = table->categories(); categories.append( tr( "Unfiled" ) ); for ( QStringList::Iterator it = categories.begin(); it != categories.end(); ++it ) { catMenu->insertItem( *it, id ); if ( *it == table->showCategory() ) rememberId = id; ++id; } if ( table->showCategory().isEmpty() ) setCategory( 1 ); else setCategory( rememberId ); } void TodoWindow::reload() { table->clear(); table->load( todolistXMLFilename() ); syncing = FALSE; } void TodoWindow::flush() { syncing = TRUE; table->save( todolistXMLFilename() ); } void TodoWindow::closeEvent( QCloseEvent *e ) { if( mStack->visibleWidget() != table ){ mStack->raiseWidget( 1 ); e->ignore(); return; } if(syncing) { /* no need to save if in the middle of syncing */ e->accept(); return; } if ( table->save( todolistXMLFilename() ) ) { e->accept(); // repeat for categories... // if writing configs fail, it will emit an // error, but I feel that it is "ok" for us to exit // espically since we aren't told if the write succeeded... Config config( "todo" ); config.setGroup( "View" ); config.writeEntry( "ShowComplete", table->showCompleted() ); config.writeEntry( "Category", table->showCategory() ); /* added 20.01.2k2 by se */ config.writeEntry( "ShowDeadLine", table->showDeadline()); } else { if ( QMessageBox::critical( this, tr("Out of space"), tr("Todo was unable\n" "to save your changes.\n" "Free up some space\n" "and try again.\n" "\nQuit Anyway?"), QMessageBox::Yes|QMessageBox::Escape, QMessageBox::No|QMessageBox::Default) != QMessageBox::No ) e->accept(); else e->ignore(); } } void TodoWindow::slotFind() { // put everything back to view all for searching... mStack->raiseWidget( 1 ); if ( !catMenu->isItemChecked( 0 ) ) setCategory( 0 ); FindDialog dlg( "Todo List", this ); QObject::connect( &dlg, SIGNAL(signalFindClicked(const QString &, bool, bool, int)), table, SLOT(slotDoFind(const QString&, bool, bool, int)) ); QObject::connect( table, SIGNAL(signalNotFound()), &dlg, SLOT(slotNotFound()) ); QObject::connect( table, SIGNAL(signalWrapAround()), &dlg, SLOT(slotWrapAround()) ); dlg.exec(); if ( table->numSelections() ) table->clearSelection(); table->clearFindRow(); } void TodoWindow::setDocument( const QString &filename ) { if ( filename.find(".vcs") != int(filename.length()) - 4 ) return; ToDoDB todoDB(filename, new ToDoVCalResource() ); QValueList<ToDoEvent> tl = todoDB.rawToDos(); for( QValueList<ToDoEvent>::Iterator it = tl.begin(); it != tl.end(); ++it ) { diff --git a/core/pim/todo/todotable.cpp b/core/pim/todo/todotable.cpp index dc60cc4..208a084 100644 --- a/core/pim/todo/todotable.cpp +++ b/core/pim/todo/todotable.cpp @@ -452,386 +452,385 @@ void TodoTable::updateVisible() int visible = 0; int id = mCat.id( "Todo List", showCat ); for ( int row = 0; row < numRows(); row++ ) { CheckItem *ci = (CheckItem *)item( row, 0 ); ToDoEvent *t = todoList[ci]; QArray<int> vlCats = t->categories(); bool hide = false; if ( !showComp && ci->isChecked() ) hide = true; if ( !showCat.isEmpty() ) { if ( showCat == tr( "Unfiled" ) ) { if ( vlCats.count() > 0 ) hide = true; } else { // 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 ) { hide = false; break; } } } } } if ( hide ) { if ( currentRow() == row ) setCurrentCell( -1, 0 ); if ( rowHeight( row ) > 0 ) hideRow( row ); } else { if ( rowHeight( row ) == 0 ) { showRow( row ); adjustRow( row ); } visible++; } } if ( !visible ) setCurrentCell( -1, 0 ); } void TodoTable::viewportPaintEvent( QPaintEvent *pe ) { if ( enablePainting ) QTable::viewportPaintEvent( pe ); } void TodoTable::setPaintingEnabled( bool e ) { if ( e != enablePainting ) { if ( !enablePainting ) { enablePainting = true; rowHeightChanged( 0 ); viewport()->update(); } else { enablePainting = false; } } } void TodoTable::clear() { for ( QMap<CheckItem*, ToDoEvent *>::Iterator it = todoList.begin(); it != todoList.end(); ++it ) { ToDoEvent *todo = it.data(); updateJournal( *todo, ACTION_REMOVE ); delete todo; } todoList.clear(); for ( int r = 0; r < numRows(); ++r ) { for ( int c = 0; c < numCols(); ++c ) { if ( cellWidget( r, c ) ) clearCellWidget( r, c ); clearCell( r, c ); } } setNumRows( 0 ); } void TodoTable::sortColumn( int col, bool ascending, bool /*wholeRows*/ ) { // The default for wholeRows is false, however // for this todo table we want to exchange complete // rows when sorting. Also, we always want ascending, since // the values have a logical order. QTable::sortColumn( col, ascending, TRUE ); updateVisible(); } void TodoTable::slotCheckPriority(int row, int col ) { // kludgey work around to make forward along the updated priority... if ( col == 1 ) { // let everyone know!! ComboItem* i = static_cast<ComboItem*>( item( row, col ) ); emit signalPriorityChanged( i->text().toInt() ); } } void TodoTable::updateJournal( const ToDoEvent &todo, journal_action action ) { QFile f( journalFileName() ); if ( !f.open(IO_WriteOnly|IO_Append) ) return; QString buf; QCString str; buf = "<Task"; // todo.save( buf ); buf += " Action=\"" + QString::number( int(action) ) + "\""; 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(); } void TodoTable::rowHeightChanged( int row ) { if ( enablePainting ) QTable::rowHeightChanged( row ); } void TodoTable::loadFile( const QString &/*we use the standard*/ ) { QList<ToDoEvent> list; ToDoDB todoDB; QValueList<ToDoEvent> vaList = todoDB.rawToDos(); for(QValueList<ToDoEvent>::ConstIterator it = vaList.begin(); it != vaList.end(); ++it ){ ToDoEvent *event = new ToDoEvent( (*it) ); list.append( event ); } vaList.clear(); // qDebug("parsing done=%d", t.elapsed() ); if ( list.count() > 0 ) { internalAddEntries( list ); list.clear(); } // qDebug("loading done: t=%d", t.elapsed() ); } void TodoTable::journalFreeReplaceEntry( const ToDoEvent &todo, int row ) { QString strTodo; strTodo = todo.description().left(40).simplifyWhiteSpace(); if ( row == -1 ) { QMapIterator<CheckItem*, ToDoEvent *> it; for ( it = todoList.begin(); it != todoList.end(); ++it ) { if ( *(*it) == todo ) { row = it.key()->row(); it.key()->setChecked( todo.isCompleted() ); static_cast<ComboItem*>(item(row, 1))->setText( QString::number(todo.priority()) ); item( row, 2 )->setText( strTodo ); if (showDeadl){ static_cast<DueTextItem*>(item(row,3))->setToDoEvent(&todo ); } *(*it) = todo; } } } else { ToDoEvent *t = todoList[static_cast<CheckItem*>(item(row, 0))]; todoList.remove( static_cast<CheckItem*>(item(row, 0)) ); delete t; static_cast<CheckItem*>(item(row, 0))->setChecked( todo.isCompleted() ); static_cast<ComboItem*>(item(row, 1))->setText( QString::number(todo.priority()) ); item( row, 2 )->setText( strTodo ); if (showDeadl){ static_cast<DueTextItem*>(item(row,3))->setToDoEvent(&todo ); } - ToDoEvent *ev = new ToDoEvent( todo ); - todoList.insert( static_cast<CheckItem*>(item(row,0)), new ToDoEvent(ev) ); + todoList.insert( static_cast<CheckItem*>(item(row,0)), new ToDoEvent(todo) ); } } void TodoTable::journalFreeRemoveEntry( int row ) { CheckItem *chk; chk = static_cast<CheckItem*>(item(row, 0 )); if ( !chk ) return; todoList.remove( chk ); realignTable( row ); } void TodoTable::keyPressEvent( QKeyEvent *e ) { if ( e->key() == Key_Space || e->key() == Key_Return ) { switch ( currentColumn() ) { case 0: { CheckItem *i = static_cast<CheckItem*>(item(currentRow(), currentColumn())); if ( i ) i->toggle(); break; } case 1: break; case 2: emit signalEdit(); default: break; } } else { QTable::keyPressEvent( e ); } } QStringList TodoTable::categories() { // This is called seldom, so calling a load in here // should be fine. mCat.load( categoryFileName() ); QStringList categoryList = mCat.labels( "Todo List" ); return categoryList; } void TodoTable::slotDoFind( const QString &findString, bool caseSensitive, bool backwards, int category ) { // we have to iterate through the table, this gives the illusion that // sorting is actually being used. if ( currFindRow < -1 ) currFindRow = currentRow() - 1; clearSelection( TRUE ); int rows, row; CheckItem *chk; QRegExp r( findString ); r.setCaseSensitive( caseSensitive ); rows = numRows(); static bool wrapAround = true; if ( !backwards ) { for ( row = currFindRow + 1; row < rows; row++ ) { chk = static_cast<CheckItem*>( item(row, 0) ); if ( taskCompare(*(todoList[chk]), r, category) ) break; } } else { for ( row = currFindRow - 1; row > -1; row-- ) { chk = static_cast<CheckItem*>( item(row, 0) ); if ( taskCompare(*(todoList[chk]), r, category) ) break; } } if ( row >= rows || row < 0 ) { if ( row < 0 ) currFindRow = rows; else currFindRow = -1; if ( wrapAround ) emit signalWrapAround(); else emit signalNotFound(); wrapAround = !wrapAround; } else { currFindRow = row; QTableSelection foundSelection; foundSelection.init( currFindRow, 0 ); foundSelection.expandTo( currFindRow, numCols() - 1 ); addSelection( foundSelection ); setCurrentCell( currFindRow, numCols() - 1 ); // we should always be able to wrap around and find this again, // so don't give confusing not found message... wrapAround = true; } } int TodoTable::showCategoryId() const { int id; id = -1; // if allcategories are selected, you get unfiled... 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(); ToDoDB tododb; // allready loaded ;) bool ok; int action; QString dummy; while( el ){ dummy = el->attribute("Action" ); action = dummy.toInt(&ok ); ToDoEvent ev = xmlToEvent( el ); if(ok ){ switch( action){ case ACTION_ADD: tododb.addEvent(ev ); break; case ACTION_REMOVE: tododb.removeEvent( ev ); break; case ACTION_REPLACE: tododb.replaceEvent( ev ); break; } } el = el->nextChild(); } QFile::remove(journalFileName()+ "_new" ); tododb.save(); } } void TodoTable::slotCheckDay() { QDate date = QDate::currentDate(); if( mDay.daysTo(date )!= 0 ){ setPaintingEnabled( FALSE ); for(int i=0; i < numRows(); i++ ){ ToDoEvent *t = todoList[static_cast<CheckItem*>(item(i, 0))]; static_cast<DueTextItem*>(item(i, 3) )->setToDoEvent( t ); } setPaintingEnabled( TRUE ); mDay = date; } mDayTimer->start( 60 * 1000 ); // 60 seconds } // 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; } } } */ |