-rw-r--r-- | core/pim/datebook/datebook.cpp | 1 | ||||
-rw-r--r-- | core/pim/datebook/datebooksettings.cpp | 28 | ||||
-rw-r--r-- | core/pim/datebook/datebooksettings.h | 6 | ||||
-rw-r--r-- | core/pim/datebook/holiday/national/national-holidays.pro | 4 | ||||
-rw-r--r-- | core/pim/datebook/holiday/national/nationalcfg.cpp | 11 | ||||
-rw-r--r-- | core/pim/datebook/holiday/national/nationalcfgwidget.cpp | 99 | ||||
-rw-r--r-- | core/pim/datebook/holiday/national/nationalcfgwidget.h | 39 | ||||
-rw-r--r-- | core/pim/datebook/holiday/national/nationalholiday.cpp | 13 | ||||
-rw-r--r-- | core/pim/datebook/holiday/national/nationalholiday.h | 2 | ||||
-rw-r--r-- | libopie2/opiepim/ui/oholidayplugin.h | 6 | ||||
-rw-r--r-- | libopie2/opiepim/ui/oholidayplugincfgwidget.cpp | 14 | ||||
-rw-r--r-- | libopie2/opiepim/ui/oholidayplugincfgwidget.h | 30 | ||||
-rw-r--r-- | libopie2/opiepim/ui/oholidaypluginif.h | 8 | ||||
-rw-r--r-- | libopie2/opiepim/ui/ui.pro | 8 |
14 files changed, 247 insertions, 22 deletions
diff --git a/core/pim/datebook/datebook.cpp b/core/pim/datebook/datebook.cpp index 8ae4f84..70dd7b5 100644 --- a/core/pim/datebook/datebook.cpp +++ b/core/pim/datebook/datebook.cpp @@ -74,384 +74,385 @@ DateBook::DateBook( QWidget *parent, const char *, WFlags f ) inSearch(FALSE), alarmCounter(0) { bool needEvilHack= false; // if we need an Evil Hack QTime t; t.start(); db = new DateBookDBHoliday; odebug << "loading db t=" << t.elapsed() << oendl; db_holiday = new DateBookHoliday(); db->db_holiday=db_holiday; 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; // QToolBar *bar = new QToolBar( this ); // bar->setHorizontalStretchable( TRUE ); // QMenuBar *mb = new QMenuBar( bar ); // mb->setMargin( 0 ); // QPopupMenu *view = new QPopupMenu( this ); // mb->insertItem( tr( "View" ), view ); QToolBar *sub_bar = new QToolBar(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)) ); #if defined(Q_WS_QWS) && !defined(QT_NO_COP) 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&)) ); #endif #endif odebug << "done t=" << t.elapsed() << oendl; connect( qApp, SIGNAL( flush() ), this, SLOT( flush() ) ); connect( qApp, SIGNAL( reload()), this, SLOT( reload() ) ); /* * 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 * so we'll call it then via a singleShot * from view() */ if( needEvilHack ){ QTimer::singleShot( 500, this, SLOT(viewWeek()) ); } } void DateBook::receive( const QCString &msg, const QByteArray &data ) { QDataStream stream( data, IO_ReadOnly ); if ( msg == "timeChange(QString)" ) { // update active view! if ( dayAction->isOn() ) viewDay(); else if ( weekAction->isOn() ) viewWeek(); else if ( monthAction->isOn() ) viewMonth(); } else if (msg == "editEvent(int)") { int uid; stream >> uid; Event e=db->eventByUID(uid); editEvent(e); }else if (msg == "viewDefault(QDate)"){ QDate day; stream >> day; viewDefault(day); } } DateBook::~DateBook() { delete db_holiday; } void DateBook::slotSettings() { DateBookSettings frmSettings( ampm, this ); frmSettings.setStartTime( startTime ); frmSettings.setAlarmPreset( aPreset, presetTime ); frmSettings.setJumpToCurTime( bJumpToCurTime ); frmSettings.setRowStyle( rowStyle ); frmSettings.comboDefaultView->setCurrentItem(defaultView-1); frmSettings.comboWeekListView->setCurrentItem(weeklistviewconfig); frmSettings.setPluginList(db_holiday->pluginManager(),db_holiday->pluginLoader()); bool found=false; for (int i=0; i<(frmSettings.comboLocation->count()); i++) { if ( frmSettings.comboLocation->text(i) == defaultLocation ) { frmSettings.comboLocation->setCurrentItem(i); found=true; break; } } if(!found) { frmSettings.comboLocation->insertItem(defaultLocation); frmSettings.comboLocation->setCurrentItem(frmSettings.comboLocation->count()-1); } frmSettings.comboCategory->setCategories(defaultCategories,"Calendar", tr("Calendar")); if ( QPEApplication::execDialog( &frmSettings ) ) { + frmSettings.savePlugins(); db_holiday->pluginManager()->save(); db_holiday->reloadPlugins(); aPreset = frmSettings.alarmPreset(); presetTime = frmSettings.presetTime(); startTime = frmSettings.startTime(); bJumpToCurTime = frmSettings.jumpToCurTime(); rowStyle = frmSettings.rowStyle(); defaultView=frmSettings.comboDefaultView->currentItem()+1; weeklistviewconfig=frmSettings.comboWeekListView->currentItem(); defaultLocation=frmSettings.comboLocation->currentText(); defaultCategories=frmSettings.comboCategory->currentCategories(); if ( dayView ) { dayView->setStartViewTime( startTime ); dayView->setJumpToCurTime( bJumpToCurTime ); dayView->setRowStyle( rowStyle ); } if ( weekView ) { weekView->setStartViewTime( startTime ); } saveSettings(); // make the change obvious if ( views->visibleWidget() ) { if ( views->visibleWidget() == dayView ) dayView->redraw(); else if ( views->visibleWidget() == weekView ) weekView->redraw(); else if ( views->visibleWidget() == weekLstView ) weekLstView->redraw(); } } } void DateBook::fileNew() { slotNewEventFromKey(""); } QString DateBook::checkEvent(const Event &e) { /* check if overlaps with itself */ bool checkFailed = FALSE; /* check the next 12 repeats. should catch most problems */ QDate current_date = e.start().date(); Event previous = e; for(int i = 0; i < 12; i++) { QDateTime next; if (!nextOccurance(previous, current_date.addDays(1), next)) { break; // no more repeats } if(next < previous.end()) { checkFailed = TRUE; break; } current_date = next.date(); } if(checkFailed) return tr("Event duration is potentially longer\n" "than interval between repeats."); return QString::null; } QDate DateBook::currentDate() { QDate d = QDate::currentDate(); if ( dayView && views->visibleWidget() == dayView ) { d = dayView->date(); } else if ( weekView && views->visibleWidget() == weekView ) { d = weekView->date(); } else if ( weekLstView && views->visibleWidget() == weekLstView ) { d = weekLstView->date(); } else if ( monthView && views->visibleWidget() == monthView ) { d = monthView->selectedDate(); } return d; } void DateBook::view(int v, const QDate &d) { if (v==DAY) { initDay(); dayAction->setOn( TRUE ); dayView->setDate( d ); views->raiseWidget( dayView ); dayView->redraw(); } else if (v==WEEK) { initWeek(); weekAction->setOn( TRUE ); weekView->setDate( d ); views->raiseWidget( weekView ); weekView->redraw(); } else if (v==WEEKLST) { initWeekLst(); weekLstAction->setOn( TRUE ); weekLstView->setDate(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) { view(defaultView,d); } void DateBook::viewDay() { view(DAY,currentDate()); } void DateBook::viewWeek() { view(WEEK,currentDate()); } void DateBook::viewWeekLst() { view(WEEKLST,currentDate()); } void DateBook::viewMonth() { view(MONTH,currentDate()); } void DateBook::insertEvent( const Event &e ) { Event dupEvent=e; if(!dupEvent.isValidUid() ) // tkcRom seems to be different dupEvent.assignUid(); dupEvent.setLocation(defaultLocation); dupEvent.setCategories(defaultCategories); db->addEvent(dupEvent); emit newEvent(); } void DateBook::duplicateEvent( const Event &e ) { // Alot of code duplication, as this is almost like editEvent(); if (syncing) { QMessageBox::warning( this, tr("Calendar"), tr( "Can not edit data, currently syncing") ); return; } Event dupevent(e); // Make a duplicate. // workaround added for text input. QDialog editDlg( this, 0, TRUE ); DateEntry *entry; editDlg.setCaption( tr("Duplicate Event") ); QVBoxLayout *vb = new QVBoxLayout( &editDlg ); QScrollView *sv = new QScrollView( &editDlg, "scrollview" ); sv->setResizePolicy( QScrollView::AutoOneFit ); // KLUDGE!!! sv->setHScrollBarMode( QScrollView::AlwaysOff ); vb->addWidget( sv ); entry = new DateEntry( onMonday, dupevent, ampm, &editDlg, "editor" ); entry->timezone->setEnabled( FALSE ); sv->addChild( entry ); while ( QPEApplication::execDialog( &editDlg ) ) { Event newEv = entry->event(); QString error = checkEvent(newEv); if (!error.isNull()) { if (QMessageBox::warning(this, tr("error box"), error, tr("Fix it"), tr("Continue"), 0, 0, 1) == 0) continue; } /* * The problem: * DateBookDB does remove repeating events not by uid but by the time * the recurrence was created * so we need to update that time as well */ Event::RepeatPattern rp = newEv.repeatPattern(); rp.createTime = ::time( NULL ); newEv.setRepeat( TRUE, rp ); // has repeat and repeatPattern... if( newEv.uid() == e.uid() || !newEv.isValidUid() ) newEv.assignUid(); db->addEvent(newEv); emit newEvent(); break; } } diff --git a/core/pim/datebook/datebooksettings.cpp b/core/pim/datebook/datebooksettings.cpp index 861e266..561dc38 100644 --- a/core/pim/datebook/datebooksettings.cpp +++ b/core/pim/datebook/datebooksettings.cpp @@ -1,191 +1,219 @@ /********************************************************************** ** Copyright (C) 2000 Trolltech AS. All rights reserved. ** ** This file is part of Qtopia Environment. ** ** This file may be distributed and/or modified under the terms of the ** GNU General Public License version 2 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** ** See http://www.trolltech.com/gpl/ for GPL licensing information. ** ** Contact info@trolltech.com if any conditions of this licensing are ** not clear to you. ** **********************************************************************/ #include "datebooksettings.h" #include <opie2/opluginloader.h> #include <opie2/odebug.h> +#include <opie2/oholidaypluginif.h> +#include <opie2/oholidayplugin.h> +#include <opie2/oholidayplugincfgwidget.h> #include <qpe/qpeapplication.h> #include <qspinbox.h> #include <qcheckbox.h> #include <qlistview.h> #include <qheader.h> +#include <qtabwidget.h> +#include <qlayout.h> DateBookSettings::DateBookSettings( bool whichClock, QWidget *parent, const char *name, bool modal, WFlags fl ) : DateBookSettingsBase( parent, name, modal, fl ), ampm( whichClock ) { init(); QObject::connect( qApp, SIGNAL( clockChanged(bool) ), this, SLOT( slotChangeClock(bool) ) ); QArray<int> categories; comboCategory->setCategories( categories, "Calendar", tr("Calendar") ); m_loader = 0; m_manager = 0; m_PluginListView->header()->hide(); m_PluginListView->setSorting(-1); } DateBookSettings::~DateBookSettings() { } void DateBookSettings::setStartTime( int newStartViewTime ) { if ( ampm ) { if ( newStartViewTime >= 12 ) { newStartViewTime %= 12; if ( newStartViewTime == 0 ) newStartViewTime = 12; spinStart->setSuffix( tr(":00 PM") ); } else if ( newStartViewTime == 0 ) { newStartViewTime = 12; spinStart->setSuffix( tr(":00 AM") ); } oldtime = newStartViewTime; } spinStart->setValue( newStartViewTime ); } int DateBookSettings::startTime() const { int returnMe = spinStart->value(); if ( ampm ) { if ( returnMe != 12 && spinStart->suffix().contains(tr("PM"), FALSE) ) returnMe += 12; else if (returnMe == 12 && spinStart->suffix().contains(tr("AM"), TRUE)) returnMe = 0; } return returnMe; } void DateBookSettings::setPluginList(Opie::Core::OPluginManager*aManager,Opie::Core::OPluginLoader*aLoader) { m_manager = aManager; m_loader = aLoader; if (!aManager||!aLoader) return; Opie::Core::OPluginItem::List inLst = m_loader->allAvailable(true); QCheckListItem *pitem = 0; for ( Opie::Core::OPluginItem::List::Iterator it = inLst.begin(); it != inLst.end(); ++it ) { pitem = new QCheckListItem(m_PluginListView,(*it).name(),QCheckListItem::CheckBox); pitem->setOn( (*it).isEnabled() ); + + Opie::Datebook::HolidayPluginIf*hif = m_loader->load<Opie::Datebook::HolidayPluginIf>(*it,IID_HOLIDAY_PLUGIN); + if (!hif) continue; + Opie::Datebook::HolidayPlugin*pl = hif->plugin(); + if (!pl) continue; + Opie::Datebook::HolidayPluginConfigWidget*cfg = pl->configWidget(); + if (!cfg) continue; + QWidget * dtab = new QWidget(TabWidget,pl->description()); + QVBoxLayout*dlayout = new QVBoxLayout(dtab); + dlayout->setMargin(2); + dlayout->setSpacing(2); + cfg->reparent(dtab,0,QPoint(0,0)); + dlayout->addWidget(cfg); + TabWidget->insertTab(dtab,pl->description()); + + m_cfgWidgets.append(cfg); + } +} +void DateBookSettings::savePlugins() +{ + QValueList<Opie::Datebook::HolidayPluginConfigWidget*>::Iterator it; + for (it=m_cfgWidgets.begin();it!=m_cfgWidgets.end();++it) { + (*it)->saveConfig(); } } void DateBookSettings::pluginItemClicked(QListViewItem *aItem) { if (!aItem||!m_manager||!m_loader) return; QCheckListItem*pitem = ((QCheckListItem*)aItem); Opie::Core::OPluginItem::List lst = m_loader->allAvailable( true ); for ( Opie::Core::OPluginItem::List::Iterator it = lst.begin(); it != lst.end(); ++it ) { if ( QString::compare( (*it).name() , pitem->text(0) ) == 0 ) { m_manager->setEnabled((*it),pitem->isOn()); break; } } } void DateBookSettings::setAlarmPreset( bool bAlarm, int presetTime ) { chkAlarmPreset->setChecked( bAlarm ); if ( presetTime >=5 ) spinPreset->setValue( presetTime ); } bool DateBookSettings::alarmPreset() const { return chkAlarmPreset->isChecked(); } int DateBookSettings::presetTime() const { return spinPreset->value(); } void DateBookSettings::slot12Hour( int i ) { if ( ampm ) { if ( spinStart->suffix().contains( tr("AM"), FALSE ) ) { if ( oldtime == 12 && i == 11 || oldtime == 11 && i == 12 ) spinStart->setSuffix( tr(":00 PM") ); } else { if ( oldtime == 12 && i == 11 || oldtime == 11 && i == 12 ) spinStart->setSuffix( tr(":00 AM") ); } oldtime = i; } } void DateBookSettings::init() { if ( ampm ) { spinStart->setMinValue( 1 ); spinStart->setMaxValue( 12 ); spinStart->setValue( 12 ); spinStart->setSuffix( tr(":00 AM") ); oldtime = 12; } else { spinStart->setMinValue( 0 ); spinStart->setMaxValue( 23 ); spinStart->setSuffix( tr(":00") ); } } void DateBookSettings::slotChangeClock( bool whichClock ) { int saveMe; saveMe = spinStart->value(); if ( ampm && spinStart->suffix().contains( tr("AM"), FALSE ) ) { if ( saveMe == 12 ) saveMe = 0; } else if ( ampm && spinStart->suffix().contains( tr("PM"), FALSE ) ) { if ( saveMe != 12 ) saveMe += 12; } ampm = whichClock; init(); setStartTime( saveMe ); } void DateBookSettings::setJumpToCurTime( bool bJump ) { chkJumpToCurTime->setChecked( bJump ); } bool DateBookSettings::jumpToCurTime() const { return chkJumpToCurTime->isChecked(); } void DateBookSettings::setRowStyle( int style ) { comboRowStyle->setCurrentItem( style ); } int DateBookSettings::rowStyle() const { return comboRowStyle->currentItem(); } diff --git a/core/pim/datebook/datebooksettings.h b/core/pim/datebook/datebooksettings.h index df7d32c..912088f 100644 --- a/core/pim/datebook/datebooksettings.h +++ b/core/pim/datebook/datebooksettings.h @@ -1,71 +1,77 @@ /********************************************************************** ** Copyright (C) 2000 Trolltech AS. All rights reserved. ** ** This file is part of Qtopia Environment. ** ** This file may be distributed and/or modified under the terms of the ** GNU General Public License version 2 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** ** See http://www.trolltech.com/gpl/ for GPL licensing information. ** ** Contact info@trolltech.com if any conditions of this licensing are ** not clear to you. ** **********************************************************************/ #ifndef DATEBOOKSETTINGS_H #define DATEBOOKSETTINGS_H #include "datebooksettingsbase.h" #include <qpe/categoryselect.h> +#include <qvaluelist.h> namespace Opie { namespace Core { class OPluginManager; class OGenericPluginLoader; class OPluginLoader; } namespace Ui { class OPluginConfigWidget; } +namespace Datebook { + class HolidayPluginConfigWidget; +} } class DateBookSettings : public DateBookSettingsBase { Q_OBJECT public: DateBookSettings( bool whichClock, QWidget *parent = 0, const char *name = 0, bool modal = TRUE, WFlags = 0 ); ~DateBookSettings(); void setStartTime( int newStartViewTime ); int startTime() const; void setAlarmPreset( bool bAlarm, int presetTime ); bool alarmPreset() const; int presetTime() const; void setAlarmType( int alarmType ); int alarmType() const; void setJumpToCurTime( bool bJump ); bool jumpToCurTime() const; void setRowStyle( int style ); int rowStyle() const; void setPluginList(Opie::Core::OPluginManager*,Opie::Core::OPluginLoader*); + void savePlugins(); private slots: void slot12Hour( int ); void slotChangeClock( bool ); protected slots: virtual void pluginItemClicked(QListViewItem *); protected: void init(); bool ampm; int oldtime; Opie::Core::OPluginManager*m_manager; Opie::Core::OPluginLoader*m_loader; + QValueList<Opie::Datebook::HolidayPluginConfigWidget*> m_cfgWidgets; }; #endif diff --git a/core/pim/datebook/holiday/national/national-holidays.pro b/core/pim/datebook/holiday/national/national-holidays.pro index 8b2b33e..3da9c3b 100644 --- a/core/pim/datebook/holiday/national/national-holidays.pro +++ b/core/pim/datebook/holiday/national/national-holidays.pro @@ -1,20 +1,20 @@ TEMPLATE = lib CONFIG -= moc CONFIG += qt plugin # Input -HEADERS = nationalholiday.h nationalcfg.h -SOURCES = nationalholiday.cpp nationalcfg.cpp +HEADERS = nationalholiday.h nationalcfg.h nationalcfgwidget.h +SOURCES = nationalholiday.cpp nationalcfg.cpp nationalcfgwidget.cpp INTERFACES= INCLUDEPATH += $(OPIEDIR)/include \ ../ ../library DEPENDPATH += $(OPIEDIR)/include \ ../ ../library LIBS+= -lqpe -lopiecore2 -lopieui2 DESTDIR = $(OPIEDIR)/plugins/holidays TARGET = nationaldayplugin include( $(OPIEDIR)/include.pro ) diff --git a/core/pim/datebook/holiday/national/nationalcfg.cpp b/core/pim/datebook/holiday/national/nationalcfg.cpp index a293251..52c453f 100644 --- a/core/pim/datebook/holiday/national/nationalcfg.cpp +++ b/core/pim/datebook/holiday/national/nationalcfg.cpp @@ -1,149 +1,142 @@ #include "nationalcfg.h"
#include <opie2/odebug.h>
#include <qfile.h>
static QString _key_desc="description";
static QString _key_doc="nationaldays";
static QString _key_list="entries";
static QString _key_entry="entry";
static QString _content_name="name";
static QString _content_date="date";
NHcfg::NHcfg()
:QXmlDefaultHandler(),err(""),_path("")
{
}
NHcfg::~NHcfg()
{
}
bool NHcfg::load(const QString&aPath)
{
_path=aPath;
stage = 0;
_content.clear();
- odebug << "Start loading file "<<_path<<oendl;
QFile *f=new QFile(_path);
if (!f) {
oerr << "Could not open file" << oendl;
return false;
}
- odebug << "Source" << oendl;
QXmlInputSource is(*f);
- odebug << "Reader" << oendl;
QXmlSimpleReader reader;
- odebug << "Handler" << oendl;
reader.setContentHandler(this);
- odebug << "Error handler" << oendl;
reader.setErrorHandler(this);
err = "";
- odebug << "parse it" << oendl;
bool ret = reader.parse(is);
- odebug << "Errors: " << err << oendl;
+ if (err.length()>0)
+ odebug << "Errors: " << err << oendl;
return ret;
}
const tholidaylist&NHcfg::days()const
{
return _content;
}
bool NHcfg::warning(const QXmlParseException& e)
{
QString tmp;
tmp.sprintf("%d: warning: %s\n", e.lineNumber(),
(const char*) e.message().utf8());
err += tmp;
return true;
}
bool NHcfg::error(const QXmlParseException& e)
{
QString tmp;
tmp.sprintf("%d: error: %s\n", e.lineNumber(),
(const char*) e.message().utf8());
err += tmp;
return true;
}
bool NHcfg::fatalError(const QXmlParseException& e)
{
QString tmp;
tmp.sprintf("%d: fatal error: %s\n", e.lineNumber(),
(const char*) e.message().utf8());
err += tmp;
return false;
}
bool NHcfg::startElement(const QString&, const QString&,const QString& name, const QXmlAttributes& attr)
{
bool ret = false;
- odebug << "startElement: " << name << oendl;
if (name==_key_doc) {
stage = 1;
return true;
}
if (stage == 0) {
err = "This is not a national holiday config file";
return false;
}
if (name==_key_desc) {
stage = 2;
ret = setName(attr);
return ret;
}
if (stage<2) {return false;}
if (name==_key_list) {stage=3;return true;}
if (stage<3) {return false;}
return parsevalue(name,attr);
}
bool NHcfg::parsevalue(const QString&name,const QXmlAttributes&attr)
{
int nindex = attr.index(_content_name);
int dindex = attr.index(_content_date);
if (name != _key_entry) {err = "Not a valid entry"; return false;}
if (dindex == -1 || nindex == -1) {err = QString("Listentry %i is invalid").arg(1);return false;}
QString txt = attr.value(nindex);
QString dstring = attr.value(dindex);
QStringList e = QStringList::split("-",dstring);
if (e.count()!=2){err=QString("Datestring %1 is invalid").arg(dstring);return false;}
QDate d(0,e[0].toInt(),e[1].toInt());
odebug << "Found entry \"" << txt<<"\" on "<<d<<oendl;
_content[d].append(txt);
return true;
}
bool NHcfg::endElement(const QString&, const QString&,const QString& name)
{
return true;
}
const QString&NHcfg::errorString()const
{
return err;
}
bool NHcfg::setName(const QXmlAttributes&attr)
{
int nindx = attr.index("value");
if (nindx==-1) {
return false;
}
_contentname = attr.value(nindx);
- odebug << "Contentname = " << _contentname<<oendl;
return true;
}
diff --git a/core/pim/datebook/holiday/national/nationalcfgwidget.cpp b/core/pim/datebook/holiday/national/nationalcfgwidget.cpp new file mode 100644 index 0000000..6e3dd7d --- a/dev/null +++ b/core/pim/datebook/holiday/national/nationalcfgwidget.cpp @@ -0,0 +1,99 @@ +#include "nationalcfgwidget.h" + +#include <opie2/odebug.h> + +#include <qpe/config.h> +#include <qpe/qpeapplication.h> + +#include <qheader.h> +#include <qlabel.h> +#include <qlistview.h> +#include <qpushbutton.h> +#include <qlayout.h> +#include <qvariant.h> +#include <qtooltip.h> +#include <qwhatsthis.h> +#include <qheader.h> +#include <qdir.h> + +/* + * Constructs a NationalHolidayConfig which is a child of 'parent', with the + * name 'name' and widget flags set to 'f' + */ +NationalHolidayConfigWidget::NationalHolidayConfigWidget( QWidget* parent, const char* name, WFlags fl ) + : Opie::Datebook::HolidayPluginConfigWidget( parent, name, fl ) +{ + if ( !name ) + setName( "NationalHolidayConfig" ); + resize( 206, 210 ); + setCaption( tr( "Select national config" ) ); + NationalHolidayConfigLayout = new QVBoxLayout( this ); + NationalHolidayConfigLayout->setSpacing( 2 ); + NationalHolidayConfigLayout->setMargin( 2 ); + + m_headLabel = new QLabel( this, "m_headLabel" ); + m_headLabel->setText( tr( "Select one or more configs to load" ) ); + m_headLabel->setAlignment( int( QLabel::AlignCenter ) ); + NationalHolidayConfigLayout->addWidget( m_headLabel ); + + m_Configlist = new QListView( this, "m_Configlist" ); + m_Configlist->addColumn( tr( "configfiles" ) ); + QWhatsThis::add( m_Configlist, tr( "List of found xml-files which may load." ) ); + NationalHolidayConfigLayout->addWidget( m_Configlist ); + + // signals and slots connections + connect( m_Configlist, SIGNAL( clicked(QListViewItem*) ), this, SLOT( listItemClicked(QListViewItem*) ) ); + init(); +} + +void NationalHolidayConfigWidget::init() +{ + m_Configlist->header()->hide(); + m_Configlist->setSorting(-1); + + QString path = QPEApplication::qpeDir() + "etc/nationaldays"; + QDir dir( path, "*.xml" ); + QStringList list = dir.entryList(); + QStringList::Iterator it; + Config cfg("nationaldays"); + cfg.setGroup("entries"); + files = cfg.readListEntry("files"); + QCheckListItem *pitem = 0; + + for (it=list.begin();it!=list.end();++it) { + pitem = new QCheckListItem(m_Configlist,(*it),QCheckListItem::CheckBox); + if (files.find((*it)) != files.end()) { + pitem->setOn(true); + } else { + pitem->setOn(false); + } + } +} + +/* + * Destroys the object and frees any allocated resources + */ +NationalHolidayConfigWidget::~NationalHolidayConfigWidget() +{ + // no need to delete child widgets, Qt does it all for us +} + +void NationalHolidayConfigWidget::listItemClicked(QListViewItem*item) +{ + if (!item) return; + QCheckListItem*pitem = ((QCheckListItem*)item); + QStringList::Iterator it = files.find(pitem->text(0)); + if (pitem->isOn()&&it==files.end()) { + files.append(pitem->text(0)); + } else if (!pitem->isOn() && it!=files.end()) { + files.remove(it); + } +} + +void NationalHolidayConfigWidget::saveConfig() +{ + Config cfg("nationaldays"); + cfg.setGroup("entries"); + cfg.writeEntry("files",files); +} + diff --git a/core/pim/datebook/holiday/national/nationalcfgwidget.h b/core/pim/datebook/holiday/national/nationalcfgwidget.h new file mode 100644 index 0000000..9f16aa4 --- a/dev/null +++ b/core/pim/datebook/holiday/national/nationalcfgwidget.h @@ -0,0 +1,39 @@ +#ifndef NATIONALHOLIDAYCONFIGWIDGET_H +#define NATIONALHOLIDAYCONFIGWIDGET_H + +#include <opie2/oholidayplugincfgwidget.h> + +#include <qvariant.h> +#include <qwidget.h> +#include <qstringlist.h> + +class QVBoxLayout; +class QHBoxLayout; +class QGridLayout; +class QLabel; +class QListView; +class QListViewItem; + +class NationalHolidayConfigWidget : public Opie::Datebook::HolidayPluginConfigWidget +{ + Q_OBJECT + +public: + NationalHolidayConfigWidget( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 ); + virtual ~NationalHolidayConfigWidget(); + + virtual void saveConfig(); + +protected slots: + virtual void listItemClicked(QListViewItem*); + +protected: + void init(); + + QVBoxLayout* NationalHolidayConfigLayout; + QLabel* m_headLabel; + QListView* m_Configlist; + QStringList files; +}; + +#endif // NATIONALHOLIDAYCONFIG_H diff --git a/core/pim/datebook/holiday/national/nationalholiday.cpp b/core/pim/datebook/holiday/national/nationalholiday.cpp index 26cd913..52f3489 100644 --- a/core/pim/datebook/holiday/national/nationalholiday.cpp +++ b/core/pim/datebook/holiday/national/nationalholiday.cpp @@ -1,123 +1,130 @@ #include "nationalholiday.h" #include "nationalcfg.h" +#include "nationalcfgwidget.h" #include <opie2/odebug.h> #include <qobject.h> #include <qpe/event.h> #include <qpe/config.h> #include <qpe/qpeapplication.h> NationalHoliday::NationalHoliday() :Opie::Datebook::HolidayPlugin() { _lastyear=0; init_done = false; init(); } QString NationalHoliday::description() { return QObject::tr("National holidays","holidays"); } void NationalHoliday::init() { Config cfg("nationaldays"); cfg.setGroup("entries"); files = cfg.readListEntry("files"); - odebug << "Read " << files << oendl; } void NationalHoliday::load_days() { if (init_done) return; + Config cfg("nationaldays"); + cfg.setGroup("entries"); QStringList::ConstIterator it; NHcfg readit; for (it=files.begin();it!=files.end();++it) { - odebug << QPEApplication::qpeDir()+"/etc/nationaldays/"+(*it) << oendl; - if (!readit.load(QPEApplication::qpeDir()+"/etc/nationaldays/"+(*it))) + if (!readit.load(QPEApplication::qpeDir()+"/etc/nationaldays/"+(*it))) { continue; + } tholidaylist::ConstIterator it; for (it=readit.days().begin();it!=readit.days().end();++it) { _days[it.key()]+=(it.data()); } } init_done = true; } QStringList NationalHoliday::entries(const QDate&aDate) { load_days(); QStringList ret; QDate d(0,aDate.month(),aDate.day()); tholidaylist::Iterator it = _days.find(d); if (it!=_days.end()) { ret+=*it; } return ret; } QStringList NationalHoliday::entries(unsigned year, unsigned month, unsigned day) { return entries(QDate(0,month,day)); } QMap<QDate,QStringList> NationalHoliday::entries(const QDate&start,const QDate&end) { load_days(); QMap<QDate,QStringList> ret; if (start==end) { ret[start]=entries(start); return ret; } QDate d; int daysto; if (end < start) { d = end; daysto = end.daysTo(start); } else { d = start; daysto = start.daysTo(end); } QStringList temp; for (int i=0;i<=daysto;++i) { temp = entries(d.addDays(i)); if (temp.count()==0) continue; ret[d.addDays(i)]+=temp; temp.clear(); } return ret; } QValueList<EffectiveEvent> NationalHoliday::events(const QDate&start,const QDate&end) { QValueList<EffectiveEvent> ret; QDate d = (start<end?start:end); int daysto = start.daysTo(end); if (daysto < 0) { daysto = end.daysTo(start); } QStringList temp; for (int i =0; i<=daysto;++i) { temp = entries(d.addDays(i)); if (temp.count()==0) { continue; } for (unsigned j=0;j<temp.count();++j) { Event ev; ev.setDescription(temp[j]); ev.setStart(d.addDays(i)); ev.setAllDay(true); ret.append(EffectiveEvent(ev,d.addDays(i))); } } return ret; } +Opie::Datebook::HolidayPluginConfigWidget*NationalHoliday::configWidget(QWidget *parent, const char *name, QWidget::WFlags fl) +{ + return new NationalHolidayConfigWidget(parent,name,fl); +} + EXPORT_HOLIDAY_PLUGIN(NationalHoliday); diff --git a/core/pim/datebook/holiday/national/nationalholiday.h b/core/pim/datebook/holiday/national/nationalholiday.h index 6581263..afce3f4 100644 --- a/core/pim/datebook/holiday/national/nationalholiday.h +++ b/core/pim/datebook/holiday/national/nationalholiday.h @@ -1,34 +1,36 @@ #ifndef __NATIONAL_HOLIDAY_H #define __NATIONAL_HOLIDAY_H #include "nationalcfg.h" #include <opie2/oholidayplugin.h> #include <opie2/oholidaypluginif.h> +#include <opie2/oholidayplugincfgwidget.h> #include <qmap.h> #include <qstringlist.h> class NationalHoliday:public Opie::Datebook::HolidayPlugin { public: NationalHoliday(); virtual ~NationalHoliday(){} virtual QString description(); virtual QStringList entries(const QDate&); virtual QStringList entries(unsigned year, unsigned month, unsigned day); virtual QMap<QDate,QStringList> entries(const QDate&,const QDate&); virtual QValueList<EffectiveEvent> events(const QDate&,const QDate&); + virtual Opie::Datebook::HolidayPluginConfigWidget*configWidget(QWidget *parent=0, const char *name = 0, QWidget::WFlags fl = 0); protected: void init(); unsigned int _lastyear; tholidaylist _days; QStringList files; bool init_done:1; void load_days(); }; #endif diff --git a/libopie2/opiepim/ui/oholidayplugin.h b/libopie2/opiepim/ui/oholidayplugin.h index 52db0eb..192a020 100644 --- a/libopie2/opiepim/ui/oholidayplugin.h +++ b/libopie2/opiepim/ui/oholidayplugin.h @@ -1,29 +1,33 @@ #ifndef _HOLIDAY_PLUGIN_H #define _HOLIDAY_PLUGIN_H #include <qstring.h> #include <qstringlist.h> #include <qdatetime.h> #include <qmap.h> +#include <qwidget.h> class EffectiveEvent; namespace Opie { namespace Datebook { +class HolidayPluginConfigWidget; + class HolidayPlugin { public: HolidayPlugin(){}; virtual ~HolidayPlugin(){}; virtual QString description()=0; virtual QStringList entries(const QDate&)=0; virtual QStringList entries(unsigned year, unsigned month, unsigned day)=0; virtual QMap<QDate,QStringList> entries(const QDate&,const QDate&)=0; virtual QValueList<EffectiveEvent> events(const QDate&,const QDate&)=0; -}; + virtual HolidayPluginConfigWidget*configWidget(QWidget *parent=0, const char *name = 0, QWidget::WFlags fl = 0 ){return 0;} +}; } } #endif diff --git a/libopie2/opiepim/ui/oholidayplugincfgwidget.cpp b/libopie2/opiepim/ui/oholidayplugincfgwidget.cpp new file mode 100644 index 0000000..43380bb --- a/dev/null +++ b/libopie2/opiepim/ui/oholidayplugincfgwidget.cpp @@ -0,0 +1,14 @@ +#include "oholidayplugincfgwidget.h" + +namespace Opie { +namespace Datebook { +HolidayPluginConfigWidget::HolidayPluginConfigWidget( QWidget* parent, const char* name, WFlags fl ) + : QWidget( parent, name, fl ) +{} + +HolidayPluginConfigWidget::~HolidayPluginConfigWidget() +{} + +} +} + diff --git a/libopie2/opiepim/ui/oholidayplugincfgwidget.h b/libopie2/opiepim/ui/oholidayplugincfgwidget.h new file mode 100644 index 0000000..17af467 --- a/dev/null +++ b/libopie2/opiepim/ui/oholidayplugincfgwidget.h @@ -0,0 +1,30 @@ +#ifndef _HOLIDAY_PLUGIN_CFG_WIDGET +#define _HOLIDAY_PLUGIN_CFG_WIDGET +#include <qwidget.h> + +namespace Opie { +namespace Datebook { +class HolidayPluginConfigWidget:public QWidget +{ + Q_OBJECT +public: + /** + * This will construct the widget. The widget gets deleted once the parent + * gets deleted as in any Qt application + * + * A Parent is required! + * + * @param parent The parent of the widget + * @param name The name of the object + */ + HolidayPluginConfigWidget(QWidget *parent, const char *name = 0, WFlags fl = 0 ); + virtual ~HolidayPluginConfigWidget(); + + virtual void saveConfig()=0; +}; + +} +} + +#endif + diff --git a/libopie2/opiepim/ui/oholidaypluginif.h b/libopie2/opiepim/ui/oholidaypluginif.h index 825d3ad..618d371 100644 --- a/libopie2/opiepim/ui/oholidaypluginif.h +++ b/libopie2/opiepim/ui/oholidaypluginif.h @@ -1,62 +1,60 @@ #ifndef _O_HOLIDAY_PLUGIN_IF_H #define _O_HOLIDAY_PLUGIN_IF_H #include <opie2/odebug.h> #include <qpe/qcom.h> #ifndef QT_NO_COMPONENT -//017f90d4-34fc-4dc5-aed7-498c6da6571e -#define IID_HOLIDAY_PLUGIN QUuid(0x017f90d4,0x34fc,0x4dc5,0xae,0xd7,0x49,0x8c,0x6d,0xa6,0x57,0x1e) +//c0a5f73f-975e-4492-9285-af555284c4ab +#define IID_HOLIDAY_PLUGIN QUuid(0xc0a5f73f,0x975e,0x4492,0x92,0x85,0xaf,0x55,0x52,0x84,0xc4,0xab) #endif namespace Opie { namespace Datebook { class HolidayPlugin; class HolidayPluginIf:public QUnknownInterface { public: HolidayPluginIf():QUnknownInterface(){} virtual ~HolidayPluginIf(){} - + virtual HolidayPlugin*plugin()=0; }; template<class T> class HolidayPluginWrapper:public HolidayPluginIf { public: HolidayPluginWrapper():HolidayPluginIf(),_plugin(0){} virtual ~HolidayPluginWrapper(){if (_plugin) delete _plugin;} QRESULT queryInterface( const QUuid& uuid, QUnknownInterface** iface ) { - odebug << "HolidayPluginWrapper::queryInterface()" << oendl; *iface = 0; if (uuid == IID_HOLIDAY_PLUGIN || uuid == IID_QUnknown) { *iface = this; } else { return QS_FALSE; } if (*iface) (*iface)->addRef(); return QS_OK; } // from qcom Q_REFCOUNT virtual T*plugin() { if (!_plugin) {_plugin = new T();} return _plugin; } protected: T*_plugin; }; #define EXPORT_HOLIDAY_PLUGIN( Plugin ) \ Q_EXPORT_INTERFACE() { \ Q_CREATE_INSTANCE( Opie::Datebook::HolidayPluginWrapper<Plugin> ) \ } - } } #endif diff --git a/libopie2/opiepim/ui/ui.pro b/libopie2/opiepim/ui/ui.pro index 53c7ae2..97c8d81 100644 --- a/libopie2/opiepim/ui/ui.pro +++ b/libopie2/opiepim/ui/ui.pro @@ -1,10 +1,14 @@ HEADERS += ui/opimmainwindow.h \ ui/opimrecurrencewidget.h \ ui/todayconfigwidget.h \ - ui/todayplugininterface.h + ui/todayplugininterface.h \ + ui/oholidayplugin.h \ + ui/oholidayplugincfgwidget.h \ + ui/oholidaypluginif.h SOURCES += ui/opimmainwindow.cpp \ ui/opimrecurrencewidget.cpp \ - ui/todayconfigwidget.cpp + ui/todayconfigwidget.cpp \ + ui/oholidayplugincfgwidget.cpp INTERFACES += ui/opimrecurrencebase.ui |