summaryrefslogtreecommitdiff
path: root/libopie
authorzecke <zecke>2002-04-15 20:53:57 (UTC)
committer zecke <zecke>2002-04-15 20:53:57 (UTC)
commite010d922ac415558e5efd35e69e39e45908b5501 (patch) (side-by-side diff)
tree7b6dac3a82613fdefb15c818541891f577ecf48d /libopie
parent15244683bb97d303d0d3b6104b46a9b429aaed85 (diff)
downloadopie-e010d922ac415558e5efd35e69e39e45908b5501.zip
opie-e010d922ac415558e5efd35e69e39e45908b5501.tar.gz
opie-e010d922ac415558e5efd35e69e39e45908b5501.tar.bz2
updates?
too much to remember
Diffstat (limited to 'libopie') (more/less context) (show whitespace changes)
-rw-r--r--libopie/ofontmenu.cc34
-rw-r--r--libopie/ofontmenu.h6
-rw-r--r--libopie/tododb.cpp20
-rw-r--r--libopie/tododb.h4
-rw-r--r--libopie/todoevent.cpp2
5 files changed, 63 insertions, 3 deletions
diff --git a/libopie/ofontmenu.cc b/libopie/ofontmenu.cc
index 2acae1c..52ff3ee 100644
--- a/libopie/ofontmenu.cc
+++ b/libopie/ofontmenu.cc
@@ -1,78 +1,112 @@
+
+#include <qpe/config.h>
#include "ofontmenu.h"
OFontMenu::OFontMenu(QWidget *parent, const char *name, const QList<QWidget> &list )
: QPopupMenu( parent, name )
{
m_list = list;
+ m_wids.setAutoDelete( TRUE );
+
insertItem(tr("Large"), this, SLOT(slotLarge() ),
0, 10);
insertItem(tr("Medium"), this, SLOT(slotMedium() ),
0, 11 );
insertItem(tr("Small"), this, SLOT(slotSmall() ),
0, 12 );
setCheckable( true );
+ m_size=10;
+}
+void OFontMenu::save(Config *cfg )
+{
+ cfg->setGroup("OFontMenu" );
+ cfg->writeEntry("size", m_size );
+}
+void OFontMenu::restore(Config *cfg )
+{
+ cfg->setGroup("OFontMeny" );
+ m_size = cfg->readNumEntry("size" );
+ setItemChecked(10, false );
+ setItemChecked(11, false );
+ setItemChecked(12, false );
+ switch( m_size ){
+ case 8:
+ setItemChecked(12, true );
+ break;
+ case 14:
+ setItemChecked(10, true );
+ break;
+ case 10:// fall through
+ default:
+ setItemChecked(11, true );
+ m_size = 10;
+ break;
+ }
+ setFontSize( m_size );
}
void OFontMenu::setWidgets(const QList<QWidget> &list )
{
m_list = list;
}
void OFontMenu::addWidget( QWidget *wid )
{
m_list.append(wid );
}
void OFontMenu::removeWidget( QWidget *wid )
{
m_list.remove( wid );
}
const QList<QWidget> &OFontMenu::widgets()const
{
return m_list;
}
void OFontMenu::forceSize(QWidget *wid, int size )
{
WidSize *widz = new WidSize;
widz->wid = wid;
widz->size = size;
m_wids.append( widz );
}
void OFontMenu::slotSmall()
{
setItemChecked(10, false );
setItemChecked(11, false );
setItemChecked(12, true );
setFontSize( 8 );
}
void OFontMenu::slotMedium()
{
setItemChecked(10, false );
setItemChecked(11, true );
setItemChecked(12, false );
setFontSize(10 );
}
void OFontMenu::slotLarge()
{
setItemChecked(10, true );
setItemChecked(11, false );
setItemChecked(12, false );
setFontSize(14 );
}
void OFontMenu::setFontSize(int size )
{
+ m_size = size;
QWidget *wid;
for(wid = m_list.first(); wid !=0; wid = m_list.next() ){
QFont font = wid->font();
font.setPointSize( size );
wid->setFont( font );
}
if(!m_wids.isEmpty() ){
WidSize *wids;
for( wids = m_wids.first(); wids != 0; wids = m_wids.next() ){
QFont font = wids->wid->font();
font.setPointSize( wids->size );
wids->wid->setFont( font );
}
}
+ emit fontChanged(size );
}
diff --git a/libopie/ofontmenu.h b/libopie/ofontmenu.h
index 37a628e..609f240 100644
--- a/libopie/ofontmenu.h
+++ b/libopie/ofontmenu.h
@@ -1,77 +1,83 @@
/*
               =. This file is part of the OPIE Project
             .=l. Copyright (c) 2002 zekce <zecke@handhelds.org>
           .>+-=
 _;:,     .>    :=|. This library is free software; you can
.> <`_,   >  .   <= redistribute it and/or modify it under
:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
.="- .-=="i,     .._ License as published by the Free Software
 - .   .-<_>     .<> Foundation; either version 2 of the License,
     ._= =}       : or (at your option) any later version.
    .%`+i>       _;_.
    .i_,=:_.      -<s. This library is distributed in the hope that
     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
    : ..    .:,     . . . without even the implied warranty of
    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
..}^=.=       =       ; Library General Public License for more
++=   -.     .`     .: details.
 :     =  ...= . :.=-
 -.   .:....=;==+<; You should have received a copy of the GNU
  -_. . .   )=.  = Library General Public License along with
    --        :-=` this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#ifndef ofontmenu_h
#define ofontmenu_h
#include <qpopupmenu.h>
#include <qlist.h>
namespace {
struct WidSize {
QWidget *wid;
int size;
};
};
// if i would be on kde this would be a KActionMenu...
+class Config;
class OFontMenu : public QPopupMenu {
Q_OBJECT
public:
OFontMenu(QWidget *parent, const char* name, const QList<QWidget> &list );
+ void save(Config *cfg );
+ void restore(Config *cfg );
void setWidgets(const QList<QWidget> &list );
void addWidget(QWidget *wid );
void forceSize(QWidget *wid, int size );
void removeWidget(QWidget *wid );
const QList<QWidget> &widgets()const;
+ signals:
+ void fontChanged(int size );
private:
QList<QWidget> m_list;
QList<WidSize> m_wids;
+ int m_size;
class OFontMenuPrivate;
OFontMenuPrivate *d;
private slots:
virtual void slotSmall();
virtual void slotMedium();
virtual void slotLarge();
void setFontSize(int size );
};
#endif
diff --git a/libopie/tododb.cpp b/libopie/tododb.cpp
index 3f6dc30..4d6711d 100644
--- a/libopie/tododb.cpp
+++ b/libopie/tododb.cpp
@@ -1,227 +1,247 @@
#include <qdir.h>
#include <opie/tododb.h>
#include <opie/xmltree.h>
#include <opie/todoresource.h>
#include <qpe/palmtoprecord.h>
#include <qpe/global.h>
namespace {
class FileToDoResource : public ToDoResource {
public:
FileToDoResource() {};
bool save(const QString &name, const QValueList<ToDoEvent> &m_todos ){
// prepare the XML
XMLElement *tasks = new XMLElement( );
tasks->setTagName("Tasks" );
for( QValueList<ToDoEvent>::ConstIterator it = m_todos.begin(); it != m_todos.end(); ++it ){
XMLElement::AttributeMap map;
XMLElement *task = new XMLElement();
map.insert( "Completed", QString::number((int)(*it).isCompleted() ) );
map.insert( "HasDate", QString::number((int)(*it).hasDate() ) );
map.insert( "Priority", QString::number( (*it).priority() ) );
QArray<int> arrat = (*it).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 );
map.insert( "Categories", attr );
//else
//map.insert( "Categories", QString::null );
map.insert( "Description", (*it).description() );
if( (*it).hasDate() ){
map.insert("DateYear", QString::number( (*it).date().year() ) );
map.insert("DateMonth", QString::number( (*it).date().month() ) );
map.insert("DateDay", QString::number( (*it).date().day() ) );
}
map.insert("Uid", QString::number( (*it).uid() ) );
task->setTagName("Task" );
task->setAttributes( map );
tasks->appendChild(task);
}
QFile file( name);
if( file.open(IO_WriteOnly ) ){
QTextStream stream(&file );
stream << "<!DOCTYPE Tasks>" << endl;
tasks->save(stream );
delete tasks;
stream << "</Tasks>" << endl;
file.close();
return true;
}
return false;
}
QValueList<ToDoEvent> load( const QString &name ){
qWarning("loading tododb" );
QValueList<ToDoEvent> m_todos;
XMLElement *root = XMLElement::load( name );
if(root != 0l ){ // start parsing
qWarning("ToDoDB::load tagName(): %s", root->tagName().latin1() );
//if( root->tagName() == QString::fromLatin1("Tasks" ) ){// Start
XMLElement *element = root->firstChild();
element = element->firstChild();
while( element ){
qWarning("ToDoDB::load element tagName() : %s", element->tagName().latin1() );
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 );
m_todos.append( event );
element = element->nextChild(); // next element
}
//}
}else {
qWarning("could not load" );
}
delete root;
qWarning("returning" );
return m_todos;
}
};
}
ToDoDB::ToDoDB(const QString &fileName, ToDoResource *res ){
m_fileName = fileName;
if( fileName.isEmpty() && res == 0 ){
m_fileName = Global::applicationFileName("todolist","todolist.xml");
res = new FileToDoResource();
//qWarning("%s", m_fileName.latin1() );
}else if(res == 0 ){ // let's create a ToDoResource for xml
res = new FileToDoResource();
}
m_res = res;
load();
}
ToDoResource* ToDoDB::resource(){
return m_res;
};
void ToDoDB::setResource( ToDoResource *res )
{
delete m_res;
m_res = res;
}
ToDoDB::~ToDoDB()
{
delete m_res;
}
QValueList<ToDoEvent> ToDoDB::effectiveToDos(const QDate &from, const QDate &to,
bool all )
{
QValueList<ToDoEvent> events;
for( QValueList<ToDoEvent>::Iterator it = m_todos.begin(); it!= m_todos.end(); ++it ){
if( (*it).hasDate() ){
if( (*it).date() >= from && (*it).date() <= to )
events.append( (*it) );
}else if( all ){
events.append( (*it) );
}
}
return events;
}
QValueList<ToDoEvent> ToDoDB::effectiveToDos(const QDate &from,
bool all)
{
return effectiveToDos( from, QDate::currentDate(), all );
}
QValueList<ToDoEvent> ToDoDB::overDue()
{
QValueList<ToDoEvent> events;
for( QValueList<ToDoEvent>::Iterator it = m_todos.begin(); it!= m_todos.end(); ++it ){
if( (*it).isOverdue() )
events.append((*it) );
}
return events;
}
QValueList<ToDoEvent> ToDoDB::rawToDos()
{
return m_todos;
}
void ToDoDB::addEvent( const ToDoEvent &event )
{
m_todos.append( event );
}
void ToDoDB::editEvent( const ToDoEvent &event )
{
m_todos.remove( event );
m_todos.append( event );
}
void ToDoDB::removeEvent( const ToDoEvent &event )
{
m_todos.remove( event );
}
+void ToDoDB::replaceEvent(const ToDoEvent &event )
+{
+ QValueList<ToDoEvent>::Iterator it;
+ int uid = event.uid();
+ // == is not overloaded as we would like :( so let's search for the uid
+ for(it = m_todos.begin(); it != m_todos.end(); ++it ){
+ if( (*it).uid() == uid ){
+ m_todos.remove( (*it) );
+ break; // should save us the iterate is now borked
+ }
+ }
+ m_todos.append(event);
+}
void ToDoDB::reload()
{
load();
}
+void ToDoDB::mergeWith(const QValueList<ToDoEvent>& events )
+{
+ QValueList<ToDoEvent>::ConstIterator it;
+ for( it = events.begin(); it != events.end(); ++it ){
+ replaceEvent( (*it) );
+ }
+}
void ToDoDB::setFileName(const QString &file )
{
m_fileName =file;
}
QString ToDoDB::fileName()const
{
return m_fileName;
}
void ToDoDB::load()
{
m_todos = m_res->load( m_fileName );
}
bool ToDoDB::save()
{
return m_res->save( m_fileName, m_todos );
}
diff --git a/libopie/tododb.h b/libopie/tododb.h
index e77a0f4..7fd9f96 100644
--- a/libopie/tododb.h
+++ b/libopie/tododb.h
@@ -1,44 +1,46 @@
#ifndef tododb_h
#define tododb_h
#include <qvaluelist.h>
#include <opie/todoevent.h>
class ToDoResource;
class ToDoDB
{
public:
// if no argument is supplied pick the default book
ToDoDB(const QString &fileName = QString::null, ToDoResource* resource= 0 );
~ToDoDB();
QValueList<ToDoEvent> effectiveToDos(const QDate &from,
const QDate &to,
bool includeNoDates = true);
QValueList<ToDoEvent> effectiveToDos(const QDate &start, bool includeNoDates = true );
QValueList<ToDoEvent> rawToDos(); // all events
QValueList<ToDoEvent> overDue();
void addEvent(const ToDoEvent &event );
void editEvent(const ToDoEvent &editEvent );
void removeEvent(const ToDoEvent &event);
-
+ void replaceEvent(const ToDoEvent &event );
+ // QValueList<ToDoEvents will overwrite existing ones no smart code at all ;)
+ void mergeWith(const QValueList<ToDoEvent>& );
void reload();
void setFileName(const QString & );
QString fileName()const;
bool save();
ToDoResource *resource();
void setResource(ToDoResource* res);
private:
class ToDoDBPrivate;
ToDoDBPrivate *d;
QString m_fileName;
ToDoResource *m_res;
QValueList<ToDoEvent> m_todos;
void load();
};
#endif
diff --git a/libopie/todoevent.cpp b/libopie/todoevent.cpp
index 28b2e98..a5dba4f 100644
--- a/libopie/todoevent.cpp
+++ b/libopie/todoevent.cpp
@@ -1,191 +1,189 @@
#include <opie/todoevent.h>
#include <qpe/palmtopuidgen.h>
#include <qpe/stringutil.h>
#include <qpe/palmtoprecord.h>
ToDoEvent::ToDoEvent(const ToDoEvent &event )
{
*this = event;
}
ToDoEvent::ToDoEvent(bool completed, int priority, const QStringList &category,
const QString &description, bool hasDate, QDate date, int uid )
{
- qWarning("todoEvent c'tor" );
m_date = date;
m_isCompleted = completed;
m_hasDate = hasDate;
m_priority = priority;
m_category = category;
m_desc = Qtopia::simplifyMultiLineSpace(description );
if (uid == -1 ) {
Qtopia::UidGen *uidgen = new Qtopia::UidGen();
uid = uidgen->generate();
delete uidgen;
}// generate the ids
m_uid = uid;
}
QArray<int> ToDoEvent::categories()const
{
QArray<int> array(m_category.count() ); // currently the datebook can be only in one category
array = Qtopia::Record::idsFromString( m_category.join(";") );
return array;
}
bool ToDoEvent::match( const QRegExp &regExp )const
{
if( QString::number( m_priority ).find( regExp ) != -1 ){
return true;
}else if( m_hasDate && m_date.toString().find( regExp) != -1 ){
return true;
}else if(m_desc.find( regExp ) != -1 ){
return true;
}
return false;
}
bool ToDoEvent::isCompleted() const
{
return m_isCompleted;
}
bool ToDoEvent::hasDate() const
{
return m_hasDate;
}
int ToDoEvent::priority()const
{
return m_priority;
}
QStringList ToDoEvent::allCategories()const
{
return m_category;
}
void ToDoEvent::insertCategory(const QString &str )
{
m_category.append( str );
}
void ToDoEvent::clearCategories()
{
m_category.clear();
}
void ToDoEvent::setCategories(const QStringList &list )
{
m_category = list;
- qWarning("todoevent: %s", list.join(";" ).latin1() );
}
QDate ToDoEvent::date()const
{
return m_date;
}
QString ToDoEvent::description()const
{
return m_desc;
}
void ToDoEvent::setCompleted( bool completed )
{
m_isCompleted = completed;
}
void ToDoEvent::setHasDate( bool hasDate )
{
m_hasDate = hasDate;
}
void ToDoEvent::setDescription(const QString &desc )
{
m_desc = Qtopia::simplifyMultiLineSpace(desc );
}
void ToDoEvent::setCategory( const QString &cat )
{
qWarning("setCategory %s", cat.latin1() );
m_category.clear();
m_category << cat;
}
void ToDoEvent::setPriority(int prio )
{
m_priority = prio;
}
void ToDoEvent::setDate( QDate date )
{
m_date = date;
}
bool ToDoEvent::isOverdue( )
{
if( m_hasDate )
return QDate::currentDate() > m_date;
return false;
}
bool ToDoEvent::operator<( const ToDoEvent &toDoEvent )const{
if( !hasDate() && !toDoEvent.hasDate() ) return true;
if( !hasDate() && toDoEvent.hasDate() ) return true;
if( hasDate() && toDoEvent.hasDate() ){
if( date() == toDoEvent.date() ){ // let's the priority decide
return priority() < toDoEvent.priority();
}else{
return date() < toDoEvent.date();
}
}
return false;
}
bool ToDoEvent::operator<=(const ToDoEvent &toDoEvent )const
{
if( !hasDate() && !toDoEvent.hasDate() ) return true;
if( !hasDate() && toDoEvent.hasDate() ) return true;
if( hasDate() && toDoEvent.hasDate() ){
if( date() == toDoEvent.date() ){ // let's the priority decide
return priority() <= toDoEvent.priority();
}else{
return date() <= toDoEvent.date();
}
}
return true;
}
bool ToDoEvent::operator>(const ToDoEvent &toDoEvent )const
{
if( !hasDate() && !toDoEvent.hasDate() ) return false;
if( !hasDate() && toDoEvent.hasDate() ) return false;
if( hasDate() && toDoEvent.hasDate() ){
if( date() == toDoEvent.date() ){ // let's the priority decide
return priority() > toDoEvent.priority();
}else{
return date() > toDoEvent.date();
}
}
return false;
}
bool ToDoEvent::operator>=(const ToDoEvent &toDoEvent )const
{
if( !hasDate() && !toDoEvent.hasDate() ) return true;
if( !hasDate() && toDoEvent.hasDate() ) return false;
if( hasDate() && toDoEvent.hasDate() ){
if( date() == toDoEvent.date() ){ // let's the priority decide
return priority() > toDoEvent.priority();
}else{
return date() > toDoEvent.date();
}
}
return true;
}
bool ToDoEvent::operator==(const ToDoEvent &toDoEvent )const
{
if( m_date == toDoEvent.m_date && m_isCompleted == toDoEvent.m_isCompleted && m_hasDate == toDoEvent.m_hasDate && m_priority == toDoEvent.m_priority && m_category == toDoEvent.m_category && m_desc == toDoEvent.m_desc )
return true;
return false;
}
ToDoEvent &ToDoEvent::operator=(const ToDoEvent &item )
{
m_date = item.m_date;
m_isCompleted = item.m_isCompleted;
m_hasDate = item.m_hasDate;
m_priority = item.m_priority;
m_category = item.m_category;
m_desc = item.m_desc;
m_uid = item.m_uid;
return *this;
}