-rw-r--r-- | core/pim/datebook2/bookmanager.cpp | 67 | ||||
-rw-r--r-- | core/pim/datebook2/bookmanager.h | 7 | ||||
-rw-r--r-- | core/pim/datebook2/datebook2.pro | 19 | ||||
-rw-r--r-- | core/pim/datebook2/mainwindow.cpp | 178 | ||||
-rw-r--r-- | core/pim/datebook2/mainwindow.h | 60 | ||||
-rw-r--r-- | core/pim/datebook2/managertemplate.h | 39 | ||||
-rw-r--r-- | core/pim/datebook2/show.cpp | 25 | ||||
-rw-r--r-- | core/pim/datebook2/show.h | 15 | ||||
-rw-r--r-- | core/pim/datebook2/stringmanager.cpp | 42 | ||||
-rw-r--r-- | core/pim/datebook2/stringmanager.h | 11 | ||||
-rw-r--r-- | core/pim/datebook2/templatemanager.cpp | 25 | ||||
-rw-r--r-- | core/pim/datebook2/view.cpp | 62 | ||||
-rw-r--r-- | core/pim/datebook2/view.h | 25 |
13 files changed, 546 insertions, 29 deletions
diff --git a/core/pim/datebook2/bookmanager.cpp b/core/pim/datebook2/bookmanager.cpp new file mode 100644 index 0000000..4fcd413 --- a/dev/null +++ b/core/pim/datebook2/bookmanager.cpp @@ -0,0 +1,67 @@ +#include "bookmanager.h" + +using namespace Datebook; + +BookManager::BookManager() { + m_db = 0; +} +BookManager::~BookManager() { + delete m_db; +} +void BookManager::add( const OEvent& ev) { + if (!m_db ) return; + + m_db->add( ev ); +} +void BookManager::add( const OPimRecord& rec ) { + if (!m_db) load(); // we might where called by setDocument... before we even fully initialized + m_db->add( rec ); +} +void BookManager::update( const OEvent& up) { + if ( !m_db ) return; + m_db->replace( up ); +} +void BookManager::remove( int uid ) { + if ( !m_db ) return; + m_db->remove( uid ); +} +void BookManager::remove( const QArray<int>& ar) { + uint count = ar.count(); + for (uint i = 0; i < count; i++ ) + remove( ar[i] ); +} +QList<OPimRecord> BookManager::records( const QDate& , const QDate& ) { + return QList<OPimRecord>(); +} +bool BookManager::isLoaded() const{ + return ( m_db != 0 ); +} +bool BookManager::load() { + m_db = new ODateBookAccess; + return m_db->load(); +} +void BookManager::reload() { + if (!m_db ) return; + + m_db->reload(); +} +OEvent BookManager::event( int uid ) { + if (!m_db ) return OEvent(); + + return m_db->find( uid ); +} +ODateBookAccess::List BookManager::allRecords()const { + if (!m_db) return ODateBookAccess::List(); + + return m_db->rawEvents(); +} +OEffectiveEvent::ValueList BookManager::list( const QDate& from, + const QDate& to ) { + if (!m_db) return OEffectiveEvent::ValueList(); + + return m_db->effectiveEvents( from, to ); +} +bool BookManager::save() { + if (!m_db) return false; + return m_db->save(); +} diff --git a/core/pim/datebook2/bookmanager.h b/core/pim/datebook2/bookmanager.h index 44ad8ed..c5dee4a 100644 --- a/core/pim/datebook2/bookmanager.h +++ b/core/pim/datebook2/bookmanager.h @@ -20,6 +20,7 @@ namespace Datebook { bool isLoaded()const; bool load(); + void reload(); bool save(); OEvent event( int uid ); @@ -28,12 +29,16 @@ namespace Datebook { ODateBookAccess::List allRecords()const; void add( const OEvent& ); + void add( const OPimRecord& ); void update( const OEvent& ); void remove( int uid ); void remove( const QArray<int>& ); - QPtrList<OPimRecord> records( const QDate& from, + QList<OPimRecord> records( const QDate& from, const QDate& to ); + + private: + ODateBookAccess* m_db; }; } diff --git a/core/pim/datebook2/datebook2.pro b/core/pim/datebook2/datebook2.pro index 9d6ef4c..2ad906e 100644 --- a/core/pim/datebook2/datebook2.pro +++ b/core/pim/datebook2/datebook2.pro @@ -1,9 +1,24 @@ TEMPLATE = app CONFIG += qt warn_on release DESTDIR = $(OPIEDIR)/bin -HEADERS = mainwindow.h +HEADERS = mainwindow.h \ + bookmanager.h \ + locationmanager.h \ + show.h \ + view.h \ + descriptionmanager.h \ + stringmanager.h \ + editor.h \ + managertemplate.h \ + templatemanager.h + SOURCES = main.cpp \ - mainwindow.cpp + mainwindow.cpp \ + bookmanager.cpp \ + stringmanager.cpp \ + templatemanager.cpp \ + show.cpp \ + view.cpp INCLUDEPATH += $(OPIEDIR)/include DEPENDPATH += $(OPIEDIR)/include diff --git a/core/pim/datebook2/mainwindow.cpp b/core/pim/datebook2/mainwindow.cpp index 2f214b8..44de6b0 100644 --- a/core/pim/datebook2/mainwindow.cpp +++ b/core/pim/datebook2/mainwindow.cpp @@ -1,13 +1,21 @@ + +#include <qcopchannel_qws.h> #include <qwidgetstack.h> #include <qlabel.h> #include <qaction.h> +#include <qpopupmenu.h> +#include <qtimer.h> +#include <qpe/qpeapplication.h> #include <qpe/ir.h> #include <qpe/qpemenubar.h> +#include <qpe/qpetoolbar.h> #include <qpe/qpemessagebox.h> #include <qpe/resource.h> - +#include "show.h" +#include "templatemanager.h" +#include "bookmanager.h" #include "mainwindow.h" @@ -15,46 +23,120 @@ using namespace Datebook; MainWindow::MainWindow() : OPimMainWindow( "Datebook", 0, 0 ) { + setIcon( Resource::loadPixmap( "datebook_icon" ) ); initUI(); - initConfig(); - initView(); initManagers(); + initView(); + initConfig(); raiseCurrentView(); QTimer::singleShot(0, this, SLOT(populate() ) ); + + QCopChannel* chan = new QCopChannel( "QPE/System", this ); + connect( chan, SIGNAL( received(const QCString&, const QByteArray& ) ), + this, SLOT( slotReceive( const QCString&, const QByteArray& ) ) ); + + chan = new QCopChannel( "QPE/Datebook", this ); + connect( chan, SIGNAL( received(const QCString&, const QByteArray& ) ), + this, SLOT( slotReceive( const QCString&, const QByteArray& ) ) ); } MainWindow::~MainWindow() { - } void MainWindow::doSetDocument( const QString& str ) { } void MainWindow::flush() { - + manager()->save(); } void MainWindow::reload() { - + manager()->reload(); } int MainWindow::create() { - + return 0; } bool MainWindow::remove( int uid ) { - + manager()->remove( uid ); + return true; } void MainWindow::beam( int uid ) { } void MainWindow::show( int uid ) { + eventShow()->show( manager()->event( uid ) ); } -void MainWindow::add( const OPimRecord& ) { - +void MainWindow::add( const OPimRecord& ad) { + manager()->add( ad ); +} +void MainWindow::edit() { + edit ( currentView()->currentItem() ); } void MainWindow::edit( int uid ) { } +/* + * init tool bars layout and so on + */ void MainWindow::initUI() { + setToolBarsMovable( false ); + + m_stack = new QWidgetStack( this ); + setCentralWidget( m_stack ); + + m_toolBar = new QPEToolBar( this ); + m_toolBar->setHorizontalStretchable( TRUE ); + + QPEMenuBar* mb = new QPEMenuBar( m_toolBar ); + m_popView = new QPopupMenu( this ); + m_popSetting = new QPopupMenu( this ); + + mb->insertItem( tr("View"), m_popView ); + mb->insertItem( tr("Settings" ), m_popSetting ); + + m_popTemplate = new QPopupMenu( this ); + m_popView->insertItem(tr("New from template"), m_popTemplate, -1, 0); + + QAction* a = new QAction( tr("New Event"), Resource::loadPixmap("new"), + QString::null, 0, this, 0 ); + a->addTo( m_toolBar ); + a->addTo( m_popView ); + connect(a, SIGNAL( activated() ), this, SLOT( create() ) ); + + a = new QAction( tr("Edit Event"), Resource::loadPixmap("edit"), + QString::null, 0, this, 0 ); + a->addTo( m_popView ); + connect(a, SIGNAL( activated() ), this, SLOT( edit() ) ); + + a = new QAction( tr("Today" ), Resource::loadPixmap( "datebook/to_day"), + QString::null, 0, this, 0 ); + a->addTo( m_toolBar ); + connect(a, SIGNAL( activated() ), this, SLOT( slotGoToNow() ) ); + + a = new QAction( tr("Find"), Resource::loadPixmap( "mag" ), + QString::null, 0, this, 0 ); + a->addTo( m_toolBar ); + connect(a, SIGNAL( activated() ), this, SLOT( slotFind() ) ); + + a = new QAction( tr("Configure"), QString::null, 0, 0 ); + a->addTo( m_popSetting ); + connect(a, SIGNAL( activated() ), this, SLOT( slotConfigure() ) ); + + a = new QAction( tr("Configure Locations"), QString::null, 0, 0 ); + a->addTo( m_popSetting ); + connect(a, SIGNAL( activated() ), this, SLOT( slotConfigureLocs() ) ); + + a = new QAction( tr("Configure Descriptions"), QString::null, 0, 0 ); + a->addTo( m_popSetting ); + connect(a, SIGNAL( activated() ), this, SLOT(slotConfigureDesc() ) ); + + connect( qApp, SIGNAL(clockChanged(bool) ), + this, SLOT(slotClockChanged(bool) ) ); + connect( qApp, SIGNAL(weekChanged(bool) ), + this, SLOT(slotWeekChanged(bool) ) ); + + connect( qApp, SIGNAL(appMessage(const QCString&, const QByteArray& ) ), + this, SLOT(slotAppMessage( const QCString&, const QByteArray& ) ) ); } void MainWindow::initConfig() { @@ -63,8 +145,82 @@ void MainWindow::initView() { } void MainWindow::initManagers() { - + m_manager = new BookManager; + m_locMan = new LocationManager( tr("Locations") ); + m_descMan = new DescriptionManager( tr("Descriptions") ); } void MainWindow::raiseCurrentView() { } +/* + * populate the view + */ +void MainWindow::populate() { + if (!manager()->isLoaded() ) + manager()->load(); +} +void MainWindow::slotGoToNow() { + +} +View* MainWindow::currentView() { + +} +void MainWindow::slotFind() { + +} +void MainWindow::slotConfigure() { + +} +void MainWindow::slotClockChanged( bool ) { + +} +void MainWindow::slotWeekChanged(bool ) { + +} +void MainWindow::slotAppMessage( const QCString&, const QByteArray& ) { + +} +void MainWindow::slotReceive( const QCString&, const QByteArray& ) { + +} +BookManager* MainWindow::manager() { + return m_manager; +} +TemplateManager* MainWindow::templateManager() { + return m_tempMan; +} +LocationManager* MainWindow::locationManager() { + return m_locMan; +} +DescriptionManager* MainWindow::descriptionManager() { + return m_descMan; +} +Show* MainWindow::eventShow() { + return m_show; +} +void MainWindow::slotAction( QAction* act ) { + +} +void MainWindow::slotConfigureLocs() { + +} +void MainWindow::slotConfigureDesc() { + +} +void MainWindow::hideShow() { + +} +void MainWindow::viewPopup(int ) { + +} +void MainWindow::viewAdd(const QDate& ) { + +} +void MainWindow::viewAdd( const QDateTime&, const QDateTime& ) { + +} +bool MainWindow::viewAP()const{ +} +bool MainWindow::viewStartMonday()const { + +} diff --git a/core/pim/datebook2/mainwindow.h b/core/pim/datebook2/mainwindow.h index 5ea0c89..60ea4c4 100644 --- a/core/pim/datebook2/mainwindow.h +++ b/core/pim/datebook2/mainwindow.h @@ -5,10 +5,23 @@ #include <opie/opimmainwindow.h> +#include "descriptionmanager.h" +#include "locationmanager.h" +#include "view.h" + +class QAction; +class QWidgetStack; +class QPopupMenu; +class QPEToolBar; namespace Datebook { + class TemplateManager; + class BookManager; + class Show; class MainWindow : public OPimMainWindow { Q_OBJECT + friend class Show; // to avoid QObject + friend class View; // to avoid QObject public: MainWindow(); ~MainWindow(); @@ -19,6 +32,17 @@ namespace Datebook { void initView(); // init the Views.. void initManagers(); // init the Managers including templates, location and description void raiseCurrentView(); // raise the current View + void slotGoToNow(); // will switch the currentView to the curren date time + void slotFind(); // find!!! + void slotConfigure(); // configure the app + void slotClockChanged(bool); // clock changed + void slotWeekChanged( bool ); // week changed + void slotAppMessage( const QCString&, const QByteArray& ); // qApp message QPE/Application/datebook + void slotReceive( const QCString&, const QByteArray& ); // QPE/System and QPE/Datebook + void slotAction( QAction* ); // View changed + void slotConfigureLocs(); // Configure the Locations + void slotConfigureDesc(); // Configure the Desc + protected slots: void populate(); @@ -30,11 +54,45 @@ namespace Datebook { void beam( int uid ); void show( int uid ); void edit( int uid ); + void edit(); void add( const OPimRecord& ); private: - QList<View> m_view; // the Views.. not autoDelete + QPEToolBar* toolbar(); + QPopupMenu* viewMenu(); + QPopupMenu* settingsMenu(); + QPopupMenu* templateMenu(); + View* currentView(); + BookManager* manager(); + TemplateManager* templateManager(); + LocationManager* locationManager(); + DescriptionManager* descriptionManager(); + Show* eventShow(); + + private: // friend functions for Show + void hideShow(); // to hide the view + // off friend Show + // friend of the view + private: + void viewPopup( int ); + void viewAdd( const QDate& date ); + void viewAdd( const QDateTime&, const QDateTime& ); + bool viewAP()const; + bool viewStartMonday()const; + // off view show + private: + QList<View> m_view; // the Views.. not autoDelete + QWidgetStack* m_stack; + QPEToolBar *m_toolBar; + QPopupMenu* m_popView; + QPopupMenu* m_popSetting; + QPopupMenu* m_popTemplate; + BookManager* m_manager; + TemplateManager* m_tempMan; + DescriptionManager* m_descMan; + LocationManager* m_locMan; + Show* m_show; }; } diff --git a/core/pim/datebook2/managertemplate.h b/core/pim/datebook2/managertemplate.h index 668fda7..cdf121d 100644 --- a/core/pim/datebook2/managertemplate.h +++ b/core/pim/datebook2/managertemplate.h @@ -2,6 +2,7 @@ #define OPIE_DATE_BOOK_MANAGER_TEMPLATE_H #include <qdialog.h> +#include <qmap.h> #include <qstring.h> namespace Datebook { @@ -11,9 +12,10 @@ namespace Datebook { */ template<class T> class ManagerTemplate { + typedef typename QMap<QString, T>::Iterator Iterator; public: ManagerTemplate(); - ~ManagerTemplate(); + virtual ~ManagerTemplate(); virtual void add( const QString&, const T& t ); void remove( const QString& ); @@ -31,6 +33,41 @@ namespace Datebook { virtual bool doLoad() = 0; }; + template<class T> + ManagerTemplate<T>::ManagerTemplate() { + } + template<class T> + ManagerTemplate<T>::~ManagerTemplate() { + } + template<class T> + void ManagerTemplate<T>::add( const QString& str, const T& t ) { + m_map.insert( str, t ); + } + template<class T> + void ManagerTemplate<T>::remove( const QString& str ) { + m_map.remove( str ); + } + template<class T> + bool ManagerTemplate<T>::load() { + return doLoad(); + } + template<class T> + bool ManagerTemplate<T>::save() { + return doSave(); + } + template<class T> + QStringList ManagerTemplate<T>::names() { + QStringList lst; + Iterator it; + for ( it = m_map.begin(); it != m_map.end(); ++it ) { + lst << it.key(); + } + return lst; + } + template<class T> + T ManagerTemplate<T>::value( const QString& str)const { + return m_map[str]; + } } #endif diff --git a/core/pim/datebook2/show.cpp b/core/pim/datebook2/show.cpp new file mode 100644 index 0000000..ca06394 --- a/dev/null +++ b/core/pim/datebook2/show.cpp @@ -0,0 +1,25 @@ +#include "mainwindow.h" +#include "show.h" + +using namespace Datebook; + +Show::Show( MainWindow* win ) + : m_win(win ) { +} +Show::~Show() { +} +void Show::hideMe() { + m_win->hideShow(); +} + +TextShow::TextShow( QWidget* parent, MainWindow* ) + : QTextView( parent ){ +} +TextShow::~TextShow() { +} +QWidget* TextShow::widget() { + return this; +} +void TextShow::show(const OEvent& ev) { + setText( ev.toRichText() ); +} diff --git a/core/pim/datebook2/show.h b/core/pim/datebook2/show.h index 37d22fe..72775a9 100644 --- a/core/pim/datebook2/show.h +++ b/core/pim/datebook2/show.h @@ -2,6 +2,7 @@ #define OPIE_DATEBOOK_SHOW_H #include <qstring.h> +#include <qtextview.h> #include <opie/oevent.h> @@ -25,7 +26,7 @@ namespace Datebook { /** * show the OEvent */ - void show(const OEvent& str); + virtual void show(const OEvent& str) = 0; /** * the Widget @@ -38,6 +39,18 @@ namespace Datebook { */ void hideMe(); + private: + MainWindow* m_win; + }; + class TextShow : public QTextView { + Q_OBJECT + public: + TextShow( QWidget* parent, MainWindow* win ); + ~TextShow(); + + QWidget* widget(); + void show(const OEvent&); + }; } diff --git a/core/pim/datebook2/stringmanager.cpp b/core/pim/datebook2/stringmanager.cpp new file mode 100644 index 0000000..77bc88a --- a/dev/null +++ b/core/pim/datebook2/stringmanager.cpp @@ -0,0 +1,42 @@ +#include <qpe/config.h> + +#include "stringmanager.h" + +using namespace Datebook; + +StringManager::StringManager( const QString& str ) + : m_base( str ) { +} +StringManager::~StringManager() { + +} +void StringManager::add( const QString& str ) { + ManagerTemplate<QString>::add(str, str); +} +bool StringManager::doLoad() { + Config qpe( "datebook-"+m_base ); + qpe.setGroup(m_base ); + QStringList list = qpe.readListEntry( "Names", 0x1f ); + for (QStringList::Iterator it = list.begin(); it != list.end(); ++it ) + add( (*it) ); + + return true; +} +bool StringManager::doSave() { + Config qpe( "datebook"+m_base ); + qpe.setGroup(m_base); + qpe.writeEntry( "Names", names(), 0x1f ); + + return false; +} + + +StringManagerDialog::StringManagerDialog(const StringManager& ) + : QDialog(0, 0, true ) { +} +StringManagerDialog::~StringManagerDialog() { + +} +StringManager StringManagerDialog::manager()const { + return StringManager(); +} diff --git a/core/pim/datebook2/stringmanager.h b/core/pim/datebook2/stringmanager.h index a11bd2a..ac0d4bd 100644 --- a/core/pim/datebook2/stringmanager.h +++ b/core/pim/datebook2/stringmanager.h @@ -17,7 +17,7 @@ namespace Datebook { /** * baseName is used for storing */ - StringManager(const QString& baseName); + StringManager(const QString& baseName = QString::null); ~StringManager(); /** @@ -26,8 +26,9 @@ namespace Datebook { */ void add( const QString& ); private: - void doLoad(); - void doSave(); + QString m_base; + bool doLoad(); + bool doSave(); }; /** @@ -36,8 +37,8 @@ namespace Datebook { class StringManagerDialog : public QDialog { Q_OBJECT public: - StringManagerDialog( const StringManager& ); - ~StringManager(); + StringManagerDialog( const StringManager&); + ~StringManagerDialog(); StringManager manager()const; }; diff --git a/core/pim/datebook2/templatemanager.cpp b/core/pim/datebook2/templatemanager.cpp new file mode 100644 index 0000000..b620cf7 --- a/dev/null +++ b/core/pim/datebook2/templatemanager.cpp @@ -0,0 +1,25 @@ +#include "templatemanager.h" + +using namespace Datebook; + + +TemplateManager::TemplateManager() { + +} +TemplateManager::~TemplateManager() { +} +bool TemplateManager::doSave() { + return true; +} +bool TemplateManager::doLoad() { + return true; +} + +TemplateDialog::TemplateDialog( const TemplateManager& ) + : QDialog(0, 0, true ) { +} +TemplateDialog::~TemplateDialog() { +} +TemplateManager TemplateDialog::manager()const { + return TemplateManager(); +} diff --git a/core/pim/datebook2/view.cpp b/core/pim/datebook2/view.cpp new file mode 100644 index 0000000..b07c89a --- a/dev/null +++ b/core/pim/datebook2/view.cpp @@ -0,0 +1,62 @@ + +#include <opie/odatebookaccess.h> + +#include "bookmanager.h" +#include "mainwindow.h" +#include "view.h" + +using namespace Datebook; + +View::View( MainWindow* window, QWidget* ) { + m_win = window; +} +View::~View() { +} +QDate View::dateFromWeek( int week, int year, bool startOnMon ) { + +} +bool View::calcWeek( const QDate& d, int & week, int & year, bool ) { + +} +void View::loadConfig( Config* conf ) { + doLoadConfig( conf ); +} +void View::saveConfig( Config* conf ) { + doSaveConfig( conf ); +} +void View::popup( int uid ) { + m_win->viewPopup( uid ); +} +void View::add( const QDate& start ) { + m_win->viewAdd( start ); +} +void View::add( const QDateTime& start, const QDateTime& end ) { + m_win->viewAdd( start, end ); +} +void View::edit( int uid ) { + m_win->edit( uid ); +} +void View::remove( int uid ) { + m_win->remove( uid ); +} +ODateBookAccess::List View::allEvents() const{ + return m_win->manager()->allRecords(); +} +OEffectiveEvent::ValueList View::events( const QDate& from, const QDate& to ) { + return m_win->manager()->list( from, to ); +} +OEvent View::event( int uid ) const{ + return m_win->manager()->event( uid ); +} +bool View::isAP()const { + return m_win->viewAP(); +} +bool View::weekStartOnMonday()const { + return m_win->viewStartMonday(); +} +QList<OPimRecord> View::records( const QDate& on ) { + return m_win->manager()->records( on, on ); +} +QList<OPimRecord> View::records( const QDate& on, const QDate& to ) { + return m_win->manager()->records( on, to ); +} diff --git a/core/pim/datebook2/view.h b/core/pim/datebook2/view.h index a7bc1d8..e2312a3 100644 --- a/core/pim/datebook2/view.h +++ b/core/pim/datebook2/view.h @@ -13,7 +13,7 @@ namespace Datebook { class View { public: View( MainWindow* window, QWidget* parent ); - virtual ~View() = 0; + virtual ~View(); static QDate dateFromWeek( int week, int year, bool startOnMonda ); static bool calcWeek( const QDate& d, int &week, int &year, bool startOnMonday = false ); @@ -22,6 +22,11 @@ namespace Datebook { virtual QString description()const = 0; /** + * return the uid of the current item or 0 + */ + virtual int currentItem()const = 0; + + /** * loadConfig * saveConfig */ @@ -30,8 +35,10 @@ namespace Datebook { /** * the current range + * @param src Where to write the start datetime + * @param dest Where to write the end datetime */ - void currentRange( const QDateTime& src, const QDateTime& from); + virtual void currentRange( const QDateTime& src, const QDateTime& from) = 0; /** * the clock format changed @@ -46,20 +53,21 @@ namespace Datebook { /** * show date in your view!! + * make the date visible in the current view */ virtual void showDay( const QDate& date ) = 0; /** * return the widget */ - virtual QWidget* widget(); + virtual QWidget* widget() = 0; /** * the view needs an update! */ - virtual void reschedule() = 0 + virtual void reschedule() = 0; protected: - void popup( int ); + void popup( int uid); QString toShortText(const OEffectiveEvent& eff)const; QString toText(const OEffectiveEvent& eff)const; virtual void doLoadConfig( Config* ) = 0; @@ -114,8 +122,11 @@ namespace Datebook { /** * return related records for days */ - QPtrList<OPimRecord> records( const QDate& on ); - QPtrList<OPimRecord> records( const QDate& start, const QDate& to ); + QList<OPimRecord> records( const QDate& on ); + QList<OPimRecord> records( const QDate& start, const QDate& to ); + + private: + MainWindow* m_win; }; } |