author | alwin <alwin> | 2005-03-16 13:14:26 (UTC) |
---|---|---|
committer | alwin <alwin> | 2005-03-16 13:14:26 (UTC) |
commit | 3d43b9e40e562957e1a3fcbe9268634db45951ce (patch) (side-by-side diff) | |
tree | 637f67a6768f6a90e7834b96100f6c70bb66950b | |
parent | 4fef85eb55dbef5f8546caee084e4f0ce51081d3 (diff) | |
download | opie-3d43b9e40e562957e1a3fcbe9268634db45951ce.zip opie-3d43b9e40e562957e1a3fcbe9268634db45951ce.tar.gz opie-3d43b9e40e562957e1a3fcbe9268634db45951ce.tar.bz2 |
ho.
in dayview a holiday will displayed (if plugin found)
generated a straight forward dummy-holiday-plugin for testing the
stuff.
-rw-r--r-- | core/pim/datebook/datebook.cpp | 78 | ||||
-rw-r--r-- | core/pim/datebook/datebook.h | 29 | ||||
-rw-r--r-- | core/pim/datebook/datebookday.cpp | 14 | ||||
-rw-r--r-- | core/pim/datebook/datebookday.h | 4 | ||||
-rw-r--r-- | core/pim/datebook/datebookdayallday.cpp | 37 | ||||
-rw-r--r-- | core/pim/datebook/datebookdayallday.h | 4 | ||||
-rw-r--r-- | core/pim/datebook/holiday/dummy/config.in | 8 | ||||
-rw-r--r-- | core/pim/datebook/holiday/dummy/dummy.pro | 20 | ||||
-rw-r--r-- | core/pim/datebook/holiday/dummy/dummyholiday.cpp | 20 | ||||
-rw-r--r-- | core/pim/datebook/holiday/dummy/dummyholiday.h | 19 |
10 files changed, 229 insertions, 4 deletions
diff --git a/core/pim/datebook/datebook.cpp b/core/pim/datebook/datebook.cpp index a18a5b4..f6aab0c 100644 --- a/core/pim/datebook/datebook.cpp +++ b/core/pim/datebook/datebook.cpp @@ -30,6 +30,8 @@ #include "dateentryimpl.h" #include <opie2/odebug.h> +#include <opie2/oholidaypluginif.h> +#include <opie2/oholidayplugin.h> #include <qpe/datebookmonth.h> #include <qpe/qpeapplication.h> @@ -49,6 +51,8 @@ #include <qtl.h> #include <qtoolbar.h> #include <qwidgetstack.h> +#include <qdir.h> +#include <qtopia/qlibrary.h> #include <sys/stat.h> #include <sys/types.h> @@ -73,6 +77,8 @@ DateBook::DateBook( QWidget *parent, const char *, WFlags f ) t.start(); db = new DateBookDBHack; odebug << "loading db t=" << t.elapsed() << oendl; + db_holiday = new DateBookHoliday(); + loadSettings(); setCaption( tr("Calendar") ); setIcon( Resource::loadPixmap( "datebook_icon" ) ); @@ -225,6 +231,7 @@ void DateBook::receive( const QCString &msg, const QByteArray &data ) DateBook::~DateBook() { + delete db_holiday; } void DateBook::slotSettings() @@ -512,7 +519,7 @@ void DateBook::showDay( int year, int month, int day ) void DateBook::initDay() { if ( !dayView ) { - dayView = new DateBookDay( ampm, onMonday, db, views, "day view" ); + dayView = new DateBookDay( ampm, onMonday, db, db_holiday, views, "day view" ); views->addWidget( dayView, DAY ); dayView->setJumpToCurTime( bJumpToCurTime ); dayView->setStartViewTime( startTime ); @@ -1073,3 +1080,72 @@ Event DateBookDBHack::eventByUID(int uid) { Event ev; return ev; // return at least } + +DateBookHoliday::DateBookHoliday() +{ + _pluginlist.clear(); + init(); +} + +DateBookHoliday::~DateBookHoliday() +{ + deinit(); +} + +void DateBookHoliday::deinit() +{ + QValueList<HPlugin*>::Iterator it; + for (it=_pluginlist.begin();it!=_pluginlist.end();++it) { + HPlugin*_pl = *it; + // destructs itself? + _pl->_if->release(); + _pl->_lib->unload(); + delete _pl->_lib; + delete _pl; + } + _pluginlist.clear(); +} + +void DateBookHoliday::init() +{ + deinit(); + QString path = QPEApplication::qpeDir() + "plugins/datebook/holiday"; + QDir dir( path, "lib*.so" ); + QStringList list = dir.entryList(); + QStringList::Iterator it; + for (it=list.begin();it!=list.end();++it) { + Opie::Datebook::HolidayPluginIf*hif = 0; + QLibrary*lib=new QLibrary(path+"/"+*it); + if ((lib->queryInterface(IID_HOLIDAY_PLUGIN,(QUnknownInterface**)&hif) == QS_OK) && hif) { + Opie::Datebook::HolidayPlugin*pl = hif->plugin(); + if (pl) { + HPlugin*_pl=new HPlugin; + _pl->_plugin = pl; + odebug << "Found holiday " << pl->description()<<oendl; + _pl->_lib = lib; + _pl->_if = hif; + _pluginlist.append(_pl); + } else { + } + } else { + delete lib; + } + } +} + +QStringList DateBookHoliday::holidaylist(const QDate&aDate) +{ + QStringList ret; + QValueList<HPlugin*>::Iterator it; + for (it=_pluginlist.begin();it!=_pluginlist.end();++it) { + HPlugin*_pl = *it; + ret+=_pl->_plugin->entries(aDate); + } + return ret; +} + +QStringList DateBookHoliday::holidaylist(unsigned year, unsigned month, unsigned day) +{ + return holidaylist(QDate(year,month,day)); +} + diff --git a/core/pim/datebook/datebook.h b/core/pim/datebook/datebook.h index d7cfb33..54ffcfb 100644 --- a/core/pim/datebook/datebook.h +++ b/core/pim/datebook/datebook.h @@ -36,12 +36,40 @@ class DateBookMonth; class Event; class QDate; class Ir; +class QLibrary; + +namespace Opie { +namespace Datebook { + class HolidayPlugin; + class HolidayPluginIf; +} +} class DateBookDBHack : public DateBookDB { public: Event eventByUID(int id); }; +class DateBookHoliday +{ +public: + DateBookHoliday(); + virtual ~DateBookHoliday(); + + QStringList holidaylist(const QDate&); + QStringList holidaylist(unsigned year, unsigned month, unsigned day); +protected: + void init(); + void deinit(); + + struct HPlugin { + Opie::Datebook::HolidayPlugin*_plugin; + QLibrary*_lib; + Opie::Datebook::HolidayPluginIf*_if; + }; + QValueList<HPlugin*>_pluginlist; +}; + class DateBook : public QMainWindow { Q_OBJECT @@ -110,6 +138,7 @@ private: private: DateBookDBHack *db; + DateBookHoliday*db_holiday; QWidgetStack *views; DateBookDay *dayView; DateBookWeek *weekView; diff --git a/core/pim/datebook/datebookday.cpp b/core/pim/datebook/datebookday.cpp index ca63dc5..dfe39e5 100644 --- a/core/pim/datebook/datebookday.cpp +++ b/core/pim/datebook/datebookday.cpp @@ -22,6 +22,7 @@ #include "datebookdayheaderimpl.h" #include "datebookdayallday.h" +#include <opie2/oholidayplugin.h> #include <qpe/resource.h> #include <qpe/qpeapplication.h> #include <qpe/ir.h> @@ -226,10 +227,11 @@ void DateBookDayViewQuickLineEdit::focusOutEvent ( QFocusEvent* /* e */) //=========================================================================== -DateBookDay::DateBookDay( bool ampm, bool startOnMonday, DateBookDB *newDb, QWidget *parent, const char *name ) +DateBookDay::DateBookDay( bool ampm, bool startOnMonday, DateBookDB *newDb, DateBookHoliday*newHdb, QWidget *parent, const char *name ) : QVBox( parent, name ), currDate( QDate::currentDate() ), db( newDb ), startTime( 0 ) { widgetList.setAutoDelete( true ); + _holiday_db = newHdb; header = new DateBookDayHeader( startOnMonday, this, "day header" ); header->setDate( currDate.year(), currDate.month(), currDate.day() ); @@ -357,9 +359,17 @@ void DateBookDay::getEvents() m_allDays->hide(); // just in case m_allDays->removeAllEvents(); + QStringList hdays = _holiday_db->holidaylist(currDate); + QStringList::Iterator sit; + QObject* object = 0; + for (sit=hdays.begin();sit!=hdays.end();++sit) { + object = m_allDays->addHoliday(*sit); + if (!object) continue; + /* not to do something with it */ + } QValueList<EffectiveEvent> eventList = db->getEffectiveEvents( currDate, currDate ); QValueListIterator<EffectiveEvent> it; - QObject* object = 0; + for ( it = eventList.begin(); it != eventList.end(); ++it ) { EffectiveEvent ev=*it; if(!((ev.end().hour()==0) && (ev.end().minute()==0) && (ev.startDate()!=ev.date()))) { // Skip events ending at 00:00 starting at another day. diff --git a/core/pim/datebook/datebookday.h b/core/pim/datebook/datebookday.h index c8cb26b..3e44364 100644 --- a/core/pim/datebook/datebookday.h +++ b/core/pim/datebook/datebookday.h @@ -180,9 +180,10 @@ class DateBookDay : public QVBox friend class DateBookDayWidget; // for beam this occurence and access to DateBookDB public: - DateBookDay( bool ampm, bool startOnMonday, DateBookDB *newDb, + DateBookDay( bool ampm, bool startOnMonday, DateBookDB *newDb,DateBookHoliday*newHdb, QWidget *parent, const char *name ); void selectedDates( QDateTime &start, QDateTime &end ); + QDate date() const; DateBookDayView *dayView() const { return view; } void setStartViewTime( int startHere ); @@ -231,6 +232,7 @@ private: int rowStyle; DateBookDayWidget *selectedWidget; //actual selected widget (obviously) DateBookDayTimeMarker *timeMarker; //marker for current time + DateBookHoliday*_holiday_db; }; #endif diff --git a/core/pim/datebook/datebookdayallday.cpp b/core/pim/datebook/datebookdayallday.cpp index a0aefd3..3c3f482 100644 --- a/core/pim/datebook/datebookdayallday.cpp +++ b/core/pim/datebook/datebookdayallday.cpp @@ -66,6 +66,20 @@ DatebookAlldayDisp* DatebookdayAllday::addEvent(const EffectiveEvent&ev) return lb; } +DatebookAlldayDisp* DatebookdayAllday::addHoliday(const QString&e) +{ + DatebookAlldayDisp * lb; + lb = new DatebookAlldayDisp(e,m_MainFrame,NULL); + lb->show(); + datebookdayalldayLayout->addWidget(lb); + subWidgets.append(lb); + + connect(lb,SIGNAL(displayMe(const Event&)),lblDesc,SLOT(disp_event(const Event&))); + ++item_count; + + return lb; +} + void DatebookdayAllday::removeAllEvents() { subWidgets.clear(); @@ -85,6 +99,26 @@ DatebookAlldayDisp::DatebookAlldayDisp(DateBookDB *db,const EffectiveEvent& ev, int s = QFontMetrics(font()).height()+4; setMaximumHeight( s ); setMinimumSize( QSize( 0, s ) ); + m_holiday = false; +} + +DatebookAlldayDisp::DatebookAlldayDisp(const QString&aholiday,QWidget* parent,const char* name, WFlags fl) + : QLabel(parent,name,fl),m_Ev(),dateBook(0) +{ + QString strDesc = aholiday; + strDesc = strDesc.replace(QRegExp("<"),"<"); + Event ev; + ev.setDescription(strDesc); + ev.setAllDay(true); + m_Ev.setEvent(ev); + setBackgroundColor(yellow); + setText(strDesc); + setFrameStyle(QFrame::Raised|QFrame::Panel); + + int s = QFontMetrics(font()).height()+4; + setMaximumHeight( s ); + setMinimumSize( QSize( 0, s ) ); + m_holiday = true; } DatebookAlldayDisp::~DatebookAlldayDisp() @@ -93,6 +127,7 @@ DatebookAlldayDisp::~DatebookAlldayDisp() void DatebookAlldayDisp::beam_single_event() { + if (m_holiday) return; // create an Event and beam it... /* * Start with the easy stuff. If start and end date is the same we can just use @@ -151,11 +186,13 @@ void DatebookAlldayDisp::mousePressEvent(QMouseEvent*e) setBackgroundColor(green); update(); QPopupMenu m; + if (!m_holiday) { m.insertItem( DateBookDayWidget::tr( "Edit" ), 1 ); m.insertItem( DateBookDayWidget::tr( "Duplicate" ), 4 ); m.insertItem( DateBookDayWidget::tr( "Delete" ), 2 ); if(Ir::supported()) m.insertItem( DateBookDayWidget::tr( "Beam" ), 3 ); if(Ir::supported() && m_Ev.event().doRepeat() ) m.insertItem( DateBookDayWidget::tr( "Beam this occurence"), 5 ); + } m.insertItem( tr( "Info"),6); int r = m.exec( e->globalPos() ); setBackgroundColor(b); diff --git a/core/pim/datebook/datebookdayallday.h b/core/pim/datebook/datebookdayallday.h index f5867e5..4f5cffa 100644 --- a/core/pim/datebook/datebookdayallday.h +++ b/core/pim/datebook/datebookdayallday.h @@ -24,6 +24,7 @@ public: QWidget* parent = 0, const char* name = 0, WFlags fl = 0); ~DatebookdayAllday(); DatebookAlldayDisp* addEvent(const EffectiveEvent&e); + DatebookAlldayDisp* addHoliday(const QString&e); const unsigned int items()const{return item_count;} public slots: @@ -45,6 +46,8 @@ class DatebookAlldayDisp : public QLabel public: DatebookAlldayDisp(DateBookDB* db,const EffectiveEvent& e, QWidget* parent=0,const char* name = 0, WFlags fl=0); + DatebookAlldayDisp(const QString&aholiday, + QWidget* parent=0,const char* name = 0, WFlags fl=0); virtual ~DatebookAlldayDisp(); signals: @@ -61,6 +64,7 @@ protected: DateBookDB* dateBook; void mousePressEvent( QMouseEvent *e ); void beam_single_event(); + bool m_holiday:1; }; class DatebookEventDesc: public QLabel diff --git a/core/pim/datebook/holiday/dummy/config.in b/core/pim/datebook/holiday/dummy/config.in new file mode 100644 index 0000000..caa90bc --- a/dev/null +++ b/core/pim/datebook/holiday/dummy/config.in @@ -0,0 +1,8 @@ + config DATEBOOK_DUMMY_HOLIDAY + boolean "opie-datebook-dummyholidayplugin" + default "n" + depends ( LIBQPE || LIBQPE-X11 ) && LIBOPIE2CORE && LIBOPIE2UI && LIBOPIE2PIM + + comment "opie-datebook-dummyholidayplugin requires libopie2core, libopie2ui, libopie2pim" + depends !( ( LIBQPE || LIBQPE-X11 ) && LIBOPIE2CORE && LIBOPIE2UI && LIBOPIE2PIM ) + diff --git a/core/pim/datebook/holiday/dummy/dummy.pro b/core/pim/datebook/holiday/dummy/dummy.pro new file mode 100644 index 0000000..768bb77 --- a/dev/null +++ b/core/pim/datebook/holiday/dummy/dummy.pro @@ -0,0 +1,20 @@ +TEMPLATE = lib +CONFIG -= moc +CONFIG += qt plugin + +# Input +HEADERS = dummyholiday.h +SOURCES = dummyholiday.cpp +INTERFACES= + +INCLUDEPATH += $(OPIEDIR)/include \ + ../ ../library +DEPENDPATH += $(OPIEDIR)/include \ + ../ ../library + +LIBS+= -lqpe -lopiecore2 -lopieui2 + +DESTDIR = $(OPIEDIR)/plugins/datebook/holiday +TARGET = dummyholidayplugin + +include( $(OPIEDIR)/include.pro ) diff --git a/core/pim/datebook/holiday/dummy/dummyholiday.cpp b/core/pim/datebook/holiday/dummy/dummyholiday.cpp new file mode 100644 index 0000000..dd00b9b --- a/dev/null +++ b/core/pim/datebook/holiday/dummy/dummyholiday.cpp @@ -0,0 +1,20 @@ +#include "dummyholiday.h"
+
+#include <qobject.h>
+
+QString DummyHoliday::description()
+{
+ return QObject::tr("Test holiday plugin","dummyholiday");
+}
+
+QStringList DummyHoliday::entries(const QDate&aDate)
+{
+ return entries(0,0,aDate.day());
+}
+
+QStringList DummyHoliday::entries(unsigned year, unsigned month, unsigned day)
+{
+ QStringList ret;
+ if (day%2==0) ret.append(QObject::tr("You have a holiday!","dummyholiday"));
+ return ret;
+}
diff --git a/core/pim/datebook/holiday/dummy/dummyholiday.h b/core/pim/datebook/holiday/dummy/dummyholiday.h new file mode 100644 index 0000000..9b28f24 --- a/dev/null +++ b/core/pim/datebook/holiday/dummy/dummyholiday.h @@ -0,0 +1,19 @@ +#ifndef __DUMMY_HOLIDAY_H
+#define __DUMMY_HOLIDAY_H
+
+#include <opie2/oholidayplugin.h>
+#include <opie2/oholidaypluginif.h>
+
+class DummyHoliday:public Opie::Datebook::HolidayPlugin
+{
+public:
+ DummyHoliday():Opie::Datebook::HolidayPlugin(){}
+ virtual ~DummyHoliday(){}
+
+ virtual QString description();
+ virtual QStringList entries(const QDate&);
+ virtual QStringList entries(unsigned year, unsigned month, unsigned day);
+};
+
+EXPORT_HOLIDAY_PLUGIN(DummyHoliday);
+#endif
|