Diffstat (limited to 'core/pim/datebook/datebook.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | core/pim/datebook/datebook.cpp | 276 |
1 files changed, 126 insertions, 150 deletions
diff --git a/core/pim/datebook/datebook.cpp b/core/pim/datebook/datebook.cpp index cf1eeca..b7e89b0 100644 --- a/core/pim/datebook/datebook.cpp +++ b/core/pim/datebook/datebook.cpp @@ -72,131 +72,134 @@ DateBook::DateBook( QWidget *parent, const char *, WFlags f ) : QMainWindow( parent, "datebook", f ), aPreset( FALSE ), presetTime( -1 ), startTime( 8 ), // an acceptable default rowStyle( 0 ), bJumpToCurTime(FALSE), syncing(FALSE), inSearch(FALSE), alarmCounter(0) { - bool needEvilHack= false; // if we need an Evil Hack - QTime t; - t.start(); - db = new DateBookDBHack; - qDebug("loading db t=%d", t.elapsed() ); - loadSettings(); - setCaption( tr("Calendar") ); - setIcon( Resource::loadPixmap( "datebook_icon" ) ); - - setToolBarsMovable( FALSE ); - - views = new QWidgetStack( this ); - setCentralWidget( views ); - - dayView = 0; - weekView = 0; - weekLstView = 0; - monthView = 0; - - QPEToolBar *bar = new QPEToolBar( this ); - bar->setHorizontalStretchable( TRUE ); - - QPEMenuBar *mb = new QPEMenuBar( bar ); - mb->setMargin( 0 ); - - QPEToolBar *sub_bar = new QPEToolBar(this); - - QPopupMenu *view = new QPopupMenu( this ); - QPopupMenu *settings = new QPopupMenu( this ); - - mb->insertItem( tr( "View" ), view ); - mb->insertItem( tr( "Settings" ), settings ); - - QActionGroup *g = new QActionGroup( this ); - g->setExclusive( TRUE ); - - QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ), - QString::null, 0, this, 0 ); - connect( a, SIGNAL( activated() ), this, SLOT( fileNew() ) ); - a->addTo( sub_bar ); - - a = new QAction( tr( "Today" ), Resource::loadPixmap( "datebook/to_day" ), QString::null, 0, g, 0 ); - connect( a, SIGNAL( activated() ), this, SLOT( slotToday() ) ); - a->addTo( sub_bar ); - a->addTo( view ); - - a = new QAction( tr( "Day" ), Resource::loadPixmap( "day" ), QString::null, 0, g, 0 ); - connect( a, SIGNAL( activated() ), this, SLOT( viewDay() ) ); - a->addTo( sub_bar ); - a->addTo( view ); - a->setToggleAction( TRUE ); - a->setOn( TRUE ); - dayAction = a; - - a = new QAction( tr( "Week" ), Resource::loadPixmap( "week" ), QString::null, 0, g, 0 ); - connect( a, SIGNAL( activated() ), this, SLOT( viewWeek() ) ); - a->addTo( sub_bar ); - a->addTo( view ); - a->setToggleAction( TRUE ); - weekAction = a; - - a = new QAction( tr( "WeekLst" ), Resource::loadPixmap( "datebook/weeklst" ), QString::null, 0, g, 0 ); - connect( a, SIGNAL( activated() ), this, SLOT( viewWeekLst() ) ); - a->addTo( sub_bar ); - a->addTo( view ); - a->setToggleAction( TRUE ); - weekLstAction = a; - - a = new QAction( tr( "Month" ), Resource::loadPixmap( "month" ), QString::null, 0, g, 0 ); - connect( a, SIGNAL( activated() ), this, SLOT( viewMonth() ) ); - a->addTo( sub_bar ); - a->addTo( view ); - a->setToggleAction( TRUE ); - monthAction = a; - - a = new QAction( tr( "Find" ), Resource::loadPixmap( "mag" ), QString::null, 0, g, 0 ); - connect( a, SIGNAL(activated()), this, SLOT(slotFind()) ); - a->addTo( sub_bar ); - - a = new QAction( tr( "Edit..." ), QString::null, 0, 0 ); - connect( a, SIGNAL( activated() ), this, SLOT( slotSettings() ) ); - a->addTo( settings ); + bool needEvilHack= false; // if we need an Evil Hack + QTime t; + t.start(); + db = new DateBookDBHack; + qDebug("loading db t=%d", t.elapsed() ); + loadSettings(); + setCaption( tr("Calendar") ); + setIcon( Resource::loadPixmap( "datebook_icon" ) ); + + setToolBarsMovable( FALSE ); + + views = new QWidgetStack( this ); + setCentralWidget( views ); + + dayView = 0; + weekView = 0; + weekLstView = 0; + monthView = 0; + +// QPEToolBar *bar = new QPEToolBar( this ); +// bar->setHorizontalStretchable( TRUE ); + +// QPEMenuBar *mb = new QPEMenuBar( bar ); +// mb->setMargin( 0 ); + +// QPopupMenu *view = new QPopupMenu( this ); +// mb->insertItem( tr( "View" ), view ); + + QPEToolBar *sub_bar = new QPEToolBar(this); + sub_bar->setHorizontalStretchable(TRUE); + + QActionGroup *g = new QActionGroup( this ); + g->setExclusive( TRUE ); + + QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ), QString::null, 0, this, 0 ); + connect( a, SIGNAL( activated() ), this, SLOT( fileNew() ) ); + a->addTo( sub_bar ); + + sub_bar->addSeparator(); + + a = new QAction( tr( "Today" ), Resource::loadPixmap( "datebook/to_day" ), QString::null, 0, g, 0 ); + connect( a, SIGNAL( activated() ), this, SLOT( slotToday() ) ); + a->addTo( sub_bar ); +// a->addTo( view ); + + sub_bar->addSeparator(); + + a = new QAction( tr( "Day" ), Resource::loadPixmap( "day" ), QString::null, 0, g, 0 ); + connect( a, SIGNAL( activated() ), this, SLOT( viewDay() ) ); + a->addTo( sub_bar ); +// a->addTo( view ); + a->setToggleAction( TRUE ); + a->setOn( TRUE ); + dayAction = a; + + a = new QAction( tr( "Week" ), Resource::loadPixmap( "week" ), QString::null, 0, g, 0 ); + connect( a, SIGNAL( activated() ), this, SLOT( viewWeek() ) ); + a->addTo( sub_bar ); +// a->addTo( view ); + a->setToggleAction( TRUE ); + weekAction = a; + + a = new QAction( tr( "WeekLst" ), Resource::loadPixmap( "datebook/weeklst" ), QString::null, 0, g, 0 ); + connect( a, SIGNAL( activated() ), this, SLOT( viewWeekLst() ) ); + a->addTo( sub_bar ); +// a->addTo( view ); + a->setToggleAction( TRUE ); + weekLstAction = a; + + a = new QAction( tr( "Month" ), Resource::loadPixmap( "month" ), QString::null, 0, g, 0 ); + connect( a, SIGNAL( activated() ), this, SLOT( viewMonth() ) ); + a->addTo( sub_bar ); +// a->addTo( view ); + a->setToggleAction( TRUE ); + monthAction = a; + + sub_bar->addSeparator(); + + a = new QAction( tr( "Find" ), Resource::loadPixmap( "mag" ), QString::null, 0, this, 0 ); + connect( a, SIGNAL(activated()), this, SLOT(slotFind()) ); + a->addTo( sub_bar ); + + a = new QAction( tr( "Edit..." ), Resource::loadPixmap("SettingsIcon"), QString::null, 0, this, 0 ); + connect( a, SIGNAL( activated() ), this, SLOT( slotSettings() ) ); + a->addTo( sub_bar ); if(defaultView==DAY) viewDay(); if(defaultView==WEEK) needEvilHack=true; // viewWeek(); if(defaultView==WEEKLST) viewWeekLst(); if(defaultView==MONTH) viewMonth(); connect( qApp, SIGNAL(clockChanged(bool)), this, SLOT(changeClock(bool)) ); - connect( qApp, SIGNAL(weekChanged(bool)), this, SLOT(changeWeek(bool)) ); + connect( qApp, SIGNAL(weekChanged(bool)), this, SLOT(changeWeek(bool)) ); #if defined(Q_WS_QWS) && !defined(QT_NO_COP) - connect( qApp, SIGNAL(appMessage(const QCString&, const QByteArray&)), this, SLOT(appMessage(const QCString&, const QByteArray&)) ); + connect( qApp, SIGNAL(appMessage(const QCString&, const QByteArray&)), this, SLOT(appMessage(const QCString&, const QByteArray&)) ); #endif // listen on QPE/System #if defined(Q_WS_QWS) #if !defined(QT_NO_COP) - QCopChannel *channel = new QCopChannel( "QPE/System", this ); - connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), this, SLOT(receive(const QCString&, const QByteArray&)) ); - channel = new QCopChannel( "QPE/Datebook", this ); - connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), this, SLOT(receive(const QCString&, const QByteArray&)) ); - qDebug("olle\n"); + QCopChannel *channel = new QCopChannel( "QPE/System", this ); + connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), this, SLOT(receive(const QCString&, const QByteArray&)) ); + channel = new QCopChannel( "QPE/Datebook", this ); + connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), this, SLOT(receive(const QCString&, const QByteArray&)) ); + qDebug("olle\n"); #endif #endif - qDebug("done t=%d", t.elapsed() ); + qDebug("done t=%d", t.elapsed() ); /* * Here is a problem description: * When Weekview is the default view * a DateBookWeekView get's created * redraw() get's called. So what? * Remember that we're still in the c'tor * and no final layout has happened? Ok * now all Events get arranged. Their x * position get's determined by a QHeader * position. But the QHeader isn't layouted or * at the right position. redraw() is a slot @@ -364,48 +367,41 @@ void DateBook::view(int v, const QDate &d) { views->raiseWidget( weekLstView ); weekLstView->redraw(); } else if (v==MONTH) { initMonth(); monthAction->setOn( TRUE ); monthView->setDate( d.year(), d.month(), d.day() ); views->raiseWidget( monthView ); monthView->redraw(); } } void DateBook::viewDefault(const QDate &d) { -/* - Config config("DateBook"); - config.setGroup("Main"); - int current=config.readNumEntry("defaultview", DAY); - - view(current,d); -*/ view(defaultView,d); } void DateBook::viewDay() { - view(DAY,currentDate()); + view(DAY,currentDate()); } void DateBook::viewWeek() { - view(WEEK,currentDate()); + view(WEEK,currentDate()); } void DateBook::viewWeekLst() { - view(WEEKLST,currentDate()); + view(WEEKLST,currentDate()); } void DateBook::viewMonth() { - view(MONTH,currentDate()); + view(MONTH,currentDate()); } void DateBook::insertEvent( const Event &e ) { Event dupEvent=e; dupEvent.setLocation(defaultLocation); dupEvent.setCategories(defaultCategories); db->addEvent(dupEvent); emit newEvent(); } void DateBook::duplicateEvent( const Event &e ) @@ -517,127 +513,107 @@ void DateBook::showDay( int year, int month, int day ) QDate d(year, month, day); view(DAY,d); } void DateBook::initDay() { if ( !dayView ) { dayView = new DateBookDay( ampm, onMonday, db, views, "day view" ); views->addWidget( dayView, DAY ); dayView->setStartViewTime( startTime ); dayView->setJumpToCurTime( bJumpToCurTime ); dayView->setRowStyle( rowStyle ); - connect( this, SIGNAL( newEvent() ), - dayView, SLOT( redraw() ) ); - connect( dayView, SIGNAL( newEvent() ), - this, SLOT( fileNew() ) ); - connect( dayView, SIGNAL( removeEvent( const Event & ) ), - this, SLOT( removeEvent( const Event & ) ) ); - connect( dayView, SIGNAL( editEvent( const Event & ) ), - this, SLOT( editEvent( const Event & ) ) ); - connect( dayView, SIGNAL( duplicateEvent( const Event & ) ), - this, SLOT( duplicateEvent( const Event & ) ) ); - connect( dayView, SIGNAL( beamEvent( const Event & ) ), - this, SLOT( beamEvent( const Event & ) ) ); - connect( dayView, SIGNAL(sigNewEvent(const QString &)), - this, SLOT(slotNewEventFromKey(const QString &)) ); - } + connect( this, SIGNAL( newEvent() ), dayView, SLOT( redraw() ) ); + connect( dayView, SIGNAL( newEvent() ), this, SLOT( fileNew() ) ); + connect( dayView, SIGNAL( removeEvent( const Event & ) ), this, SLOT( removeEvent( const Event & ) ) ); + connect( dayView, SIGNAL( editEvent( const Event & ) ), this, SLOT( editEvent( const Event & ) ) ); + connect( dayView, SIGNAL( duplicateEvent( const Event & ) ), this, SLOT( duplicateEvent( const Event & ) ) ); + connect( dayView, SIGNAL( beamEvent( const Event & ) ), this, SLOT( beamEvent( const Event & ) ) ); + connect( dayView, SIGNAL(sigNewEvent(const QString &)), this, SLOT(slotNewEventFromKey(const QString &)) ); + } } void DateBook::initWeek() { if ( !weekView ) { weekView = new DateBookWeek( ampm, onMonday, db, views, "week view" ); weekView->setStartViewTime( startTime ); views->addWidget( weekView, WEEK ); - connect( weekView, SIGNAL( showDate( int, int, int ) ), - this, SLOT( showDay( int, int, int ) ) ); - connect( this, SIGNAL( newEvent() ), - weekView, SLOT( redraw() ) ); + connect( weekView, SIGNAL( showDate( int, int, int ) ), this, SLOT( showDay( int, int, int ) ) ); + connect( this, SIGNAL( newEvent() ), weekView, SLOT( redraw() ) ); } //But also get it right: the year that we display can be different //from the year of the current date. So, first find the year //number of the current week. int yearNumber, totWeeks; calcWeek( currentDate(), totWeeks, yearNumber, onMonday ); QDate d = QDate( yearNumber, 12, 31 ); calcWeek( d, totWeeks, yearNumber, onMonday ); while ( totWeeks == 1 ) { d = d.addDays( -1 ); calcWeek( d, totWeeks, yearNumber, onMonday ); } - if ( totWeeks != weekView->totalWeeks() ) - weekView->setTotalWeeks( totWeeks ); } void DateBook::initWeekLst() { - if ( !weekLstView ) { - weekLstView = new DateBookWeekLst( ampm, onMonday, db, - views, "weeklst view" ); - views->addWidget( weekLstView, WEEKLST ); - - //weekLstView->setStartViewTime( startTime ); - connect( weekLstView, SIGNAL( showDate( int, int, int ) ), - this, SLOT( showDay( int, int, int ) ) ); - connect( weekLstView, SIGNAL( addEvent( const QDateTime &, - const QDateTime &, - const QString & , const QString &) ), - this, SLOT( slotNewEntry( const QDateTime &, - const QDateTime &, - const QString & , const QString &) ) ); - connect( this, SIGNAL( newEvent() ), - weekLstView, SLOT( redraw() ) ); - connect( weekLstView, SIGNAL( editEvent( const Event & ) ), - this, SLOT( editEvent( const Event & ) ) ); - } + if ( !weekLstView ) { + weekLstView = new DateBookWeekLst( ampm, onMonday, db, views, "weeklst view" ); + views->addWidget( weekLstView, WEEKLST ); + + //weekLstView->setStartViewTime( startTime ); + connect( weekLstView, SIGNAL( showDate( int, int, int ) ), this, SLOT( showDay( int, int, int ) ) ); + connect( weekLstView, SIGNAL( addEvent( const QDateTime &, const QDateTime &, const QString & , const QString &) ), + this, SLOT( slotNewEntry( const QDateTime &, const QDateTime &, const QString & , const QString &) ) ); + connect( this, SIGNAL( newEvent() ), weekLstView, SLOT( redraw() ) ); + connect( weekLstView, SIGNAL( editEvent( const Event & ) ), this, SLOT( editEvent( const Event & ) ) ); + } } void DateBook::initMonth() { - if ( !monthView ) { - monthView = new DateBookMonth( views, "month view", FALSE, db ); - views->addWidget( monthView, MONTH ); - connect( monthView, SIGNAL( dateClicked( int, int, int ) ), - this, SLOT( showDay( int, int, int ) ) ); - connect( this, SIGNAL( newEvent() ), - monthView, SLOT( redraw() ) ); - qApp->processEvents(); - } + if ( !monthView ) { + monthView = new DateBookMonth( views, "month view", FALSE, db ); + views->addWidget( monthView, MONTH ); + connect( monthView, SIGNAL( dateClicked( int, int, int ) ), this, SLOT( showDay( int, int, int ) ) ); + connect( this, SIGNAL( newEvent() ), monthView, SLOT( redraw() ) ); + qApp->processEvents(); + } } void DateBook::loadSettings() { Config qpeconfig( "qpe" ); qpeconfig.setGroup("Time"); ampm = qpeconfig.readBoolEntry( "AMPM", TRUE ); onMonday = qpeconfig.readBoolEntry( "MONDAY" ); Config config("DateBook"); config.setGroup("Main"); startTime = config.readNumEntry("startviewtime", 8); aPreset = config.readBoolEntry("alarmpreset"); presetTime = config.readNumEntry("presettime"); bJumpToCurTime = config.readBoolEntry("jumptocurtime"); rowStyle = config.readNumEntry("rowstyle"); defaultView = config.readNumEntry("defaultview",DAY); weeklistviewconfig = config.readNumEntry("weeklistviewconfig",NORMAL); defaultLocation=config.readEntry("defaultLocation"); QString tmpString=config.readEntry("defaultCategories"); QStringList tmpStringList=QStringList::split(",",tmpString); defaultCategories.truncate(0); + for( QStringList::Iterator i=tmpStringList.begin(); i!=tmpStringList.end(); i++) { defaultCategories.resize(defaultCategories.count()+1); defaultCategories[defaultCategories.count()-1]=(*i).toInt(); } } void DateBook::saveSettings() { Config config( "qpe" ); Config configDB( "DateBook" ); configDB.setGroup( "Main" ); configDB.writeEntry("startviewtime",startTime); |