author | alwin <alwin> | 2005-03-18 16:57:24 (UTC) |
---|---|---|
committer | alwin <alwin> | 2005-03-18 16:57:24 (UTC) |
commit | 977193cc46768da220ddb01aca74286b28e6b7ee (patch) (side-by-side diff) | |
tree | eff59fc4011b0b3a6fd610b2b04e934eb21a0687 /core | |
parent | f32b76432aeb554204f06ca15ed1ec8d5387fb12 (diff) | |
download | opie-977193cc46768da220ddb01aca74286b28e6b7ee.zip opie-977193cc46768da220ddb01aca74286b28e6b7ee.tar.gz opie-977193cc46768da220ddb01aca74286b28e6b7ee.tar.bz2 |
work on plugins finished.
these plugins now may have a config-widget (sorry guys - I had to change the
plugininterface and so the UUID again.)
the plugin for nationalholidays now has such a widget, the datebook will insert
configwidgets into its settingsdialog.
corrected the .pro file of opiepim2/ui so it contains the header/cpp files
for that pluginsystem.
-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 |
9 files changed, 189 insertions, 14 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 @@ -258,16 +258,17 @@ void DateBook::slotSettings() } 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(); 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 @@ -17,23 +17,28 @@ ** 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) ) ); @@ -85,16 +90,39 @@ void DateBookSettings::setPluginList(Opie::Core::OPluginManager*aManager,Opie::C 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); 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 @@ -17,26 +17,30 @@ ** 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 ); @@ -50,22 +54,24 @@ public: 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,15 +1,15 @@ 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 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 @@ -20,35 +20,30 @@ 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;
}
@@ -86,17 +81,16 @@ bool NHcfg::fatalError(const QXmlParseException& e) 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;
}
@@ -139,11 +133,10 @@ const QString&NHcfg::errorString()const 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,10 +1,11 @@ #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> @@ -21,28 +22,29 @@ 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; } @@ -115,9 +117,14 @@ QValueList<EffectiveEvent> NationalHoliday::events(const QDate&start,const QDate 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,31 +1,33 @@ #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(); |