author | zecke <zecke> | 2003-02-24 13:34:03 (UTC) |
---|---|---|
committer | zecke <zecke> | 2003-02-24 13:34:03 (UTC) |
commit | b04ced09167d910e5cab1981bde295e2e8185fee (patch) (side-by-side diff) | |
tree | 2623e1553968654b133343ce7333995243216201 | |
parent | cfecfd53c433a3b530e4abcef51e81feae3c8641 (diff) | |
download | opie-b04ced09167d910e5cab1981bde295e2e8185fee.zip opie-b04ced09167d910e5cab1981bde295e2e8185fee.tar.gz opie-b04ced09167d910e5cab1981bde295e2e8185fee.tar.bz2 |
Add Implementation for Templates, Locations, Descriptions
add some more stuff
-rw-r--r-- | core/pim/datebook2/datebook2.pro | 3 | ||||
-rw-r--r-- | core/pim/datebook2/editor.cpp | 24 | ||||
-rw-r--r-- | core/pim/datebook2/editor.h | 13 | ||||
-rw-r--r-- | core/pim/datebook2/mainwindow.cpp | 97 | ||||
-rw-r--r-- | core/pim/datebook2/mainwindow.h | 24 | ||||
-rw-r--r-- | core/pim/datebook2/managertemplate.h | 23 | ||||
-rw-r--r-- | core/pim/datebook2/stringmanager.cpp | 108 | ||||
-rw-r--r-- | core/pim/datebook2/stringmanager.h | 14 | ||||
-rw-r--r-- | core/pim/datebook2/templatemanager.cpp | 167 | ||||
-rw-r--r-- | core/pim/datebook2/templatemanager.h | 22 | ||||
-rw-r--r-- | core/pim/datebook2/view.h | 10 |
11 files changed, 447 insertions, 58 deletions
diff --git a/core/pim/datebook2/datebook2.pro b/core/pim/datebook2/datebook2.pro index 2ad906e..0b59309 100644 --- a/core/pim/datebook2/datebook2.pro +++ b/core/pim/datebook2/datebook2.pro @@ -1,28 +1,29 @@ TEMPLATE = app CONFIG += qt warn_on release DESTDIR = $(OPIEDIR)/bin 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 \ bookmanager.cpp \ stringmanager.cpp \ templatemanager.cpp \ show.cpp \ - view.cpp + view.cpp \ + editor.cpp INCLUDEPATH += $(OPIEDIR)/include DEPENDPATH += $(OPIEDIR)/include LIBS += -lqpe -lopie TARGET = datebook2 include ( $(OPIEDIR)/include.pro ) diff --git a/core/pim/datebook2/editor.cpp b/core/pim/datebook2/editor.cpp new file mode 100644 index 0000000..a51aab6 --- a/dev/null +++ b/core/pim/datebook2/editor.cpp @@ -0,0 +1,24 @@ +#include "mainwindow.h" + +#include "editor.h" + +using namespace Datebook; + +Editor::Editor( MainWindow* win, QWidget*) + : m_win( win ) +{} +Editor::~Editor() { + +} +DescriptionManager Editor::descriptions()const { + return m_win->descriptionManager(); +} +LocationManager Editor::locations()const { + return m_win->locationManager(); +} +void Editor::setDescriptions( const DescriptionManager& dsc) { + m_win->setDescriptionManager( dsc ); +} +void Editor::setLocations( const LocationManager& loc) { + m_win->setLocationManager( loc ); +} diff --git a/core/pim/datebook2/editor.h b/core/pim/datebook2/editor.h index 53e8718..3fcfaa4 100644 --- a/core/pim/datebook2/editor.h +++ b/core/pim/datebook2/editor.h @@ -1,36 +1,39 @@ #ifndef OPIE_DATEBOOK_EDITOR_H #define OPIE_DATEBOOK_EDITOR_H #include <qdialog.h> #include <opie/oevent.h> #include "descriptionmanager.h" #include "locationmanager.h" namespace Datebook { class MainWindow; /** * This is the editor interface */ class Editor { public: Editor( MainWindow*, QWidget* parent ); - virtual Editor(); + virtual ~Editor(); - bool newEvent( const QDate& ); - bool newEvent( const QDateTime& start, const QDateTime& end ); - bool edit( const OEvent& ); + virtual bool newEvent( const QDate& ) = 0; + virtual bool newEvent( const QDateTime& start, const QDateTime& end ) = 0; + virtual bool edit( const OEvent&, bool showRec = TRUE ) = 0; - OEvent event()const; + virtual OEvent event()const = 0; protected: DescriptionManager descriptions()const; LocationManager locations()const; void setDescriptions( const DescriptionManager& ); void setLocations( const LocationManager& ); + private: + MainWindow* m_win; + }; } #endif diff --git a/core/pim/datebook2/mainwindow.cpp b/core/pim/datebook2/mainwindow.cpp index 44de6b0..68525b3 100644 --- a/core/pim/datebook2/mainwindow.cpp +++ b/core/pim/datebook2/mainwindow.cpp @@ -1,226 +1,305 @@ #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 "editor.h" #include "show.h" #include "templatemanager.h" #include "bookmanager.h" #include "mainwindow.h" using namespace Datebook; MainWindow::MainWindow() - : OPimMainWindow( "Datebook", 0, 0 ) { + : OPimMainWindow( "Datebook", 0, 0 ), m_descMan( "Descriptions" ), m_locMan( "Locations" ) +{ setIcon( Resource::loadPixmap( "datebook_icon" ) ); initUI(); 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() { + m_tempMan.save(); + m_locMan.save(); + m_descMan.save(); + + manager()->save(); + delete m_manager; } 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& 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_popTemplate->setCheckable( TRUE ); + connect( m_popTemplate, SIGNAL(activated(int) ), + this, SLOT(slotNewFromTemplate(int) ) ); 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() ) ); + a = new QAction( tr("Configure Templates"), QString::null, 0, 0 ); + a->addTo( m_popSetting ); + connect(a, SIGNAL( activated() ), this, SLOT(slotConfigureTemp() ) ); + 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() { } void MainWindow::initView() { } void MainWindow::initManagers() { m_manager = new BookManager; - m_locMan = new LocationManager( tr("Locations") ); - m_descMan = new DescriptionManager( tr("Descriptions") ); + + m_tempMan.load(); + m_locMan.load(); + m_descMan.load(); + + setTemplateMenu(); } 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() { +TemplateManager MainWindow::templateManager() { return m_tempMan; } -LocationManager* MainWindow::locationManager() { +LocationManager MainWindow::locationManager() { return m_locMan; } -DescriptionManager* MainWindow::descriptionManager() { +DescriptionManager MainWindow::descriptionManager() { return m_descMan; } +void MainWindow::setLocationManager( const LocationManager& loc) { + m_locMan = loc; +} +void MainWindow::setDescriptionManager( const DescriptionManager& dsc ) { + m_descMan = dsc; +} Show* MainWindow::eventShow() { return m_show; } void MainWindow::slotAction( QAction* act ) { } void MainWindow::slotConfigureLocs() { - + LocationManagerDialog dlg( locationManager() ); + dlg.setCaption( tr("Configure Locations") ); + dlg.showMaximized(); + if (dlg.exec() == QDialog::Accepted ) { + setLocationManager( dlg.manager() ); + } } void MainWindow::slotConfigureDesc() { - + DescriptionManagerDialog dlg( descriptionManager() ); + dlg.setCaption( tr("Configure Descriptions") ); + dlg.showMaximized(); + if (dlg.exec() == QDialog::Accepted ) { + setDescriptionManager( dlg.manager() ); + } +} +void MainWindow::slotConfigureTemp() { + TemplateDialog dlg( templateManager(), editor() ); + dlg.setCaption( tr("Configure Templates") ); + dlg.showMaximized(); + if ( dlg.exec() == QDialog::Accepted ) { + m_tempMan = dlg.manager(); + setTemplateMenu(); + } } 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 { } +void MainWindow::setTemplateMenu() { + m_popTemplate->clear(); + + QStringList list = templateManager().names(); + for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) { + m_popTemplate->insertItem( (*it) ); + } +} +/* + * get the name of the item with the id id + * then ask for an OEvent from the manager + */ +void MainWindow::slotNewFromTemplate(int id ) { + QString name = m_popTemplate->text( id ); + + OEvent ev = templateManager().value( name ); + + if ( editor()->edit( ev ) ) { + ev = editor()->event(); + ev.setUid( -1 ); + manager()->add( ev ); + + /* + * no we'll find out if the current view + * should show the new event + * and then we will ask it to refresh + * FIXME for now we'll call a refresh + */ + currentView()->reschedule(); + raiseCurrentView(); + } +} +Editor* MainWindow::editor() { + return m_edit; +} diff --git a/core/pim/datebook2/mainwindow.h b/core/pim/datebook2/mainwindow.h index 60ea4c4..3c22637 100644 --- a/core/pim/datebook2/mainwindow.h +++ b/core/pim/datebook2/mainwindow.h @@ -1,99 +1,107 @@ #ifndef DATE_BOOK_MAIN_WINDOW_H #define DATE_BOOK_MAIN_WINDOW_H #include <qlist.h> #include <opie/opimmainwindow.h> #include "descriptionmanager.h" #include "locationmanager.h" +#include "templatemanager.h" #include "view.h" class QAction; class QWidgetStack; class QPopupMenu; class QPEToolBar; namespace Datebook { - - class TemplateManager; class BookManager; class Show; + class Editor; class MainWindow : public OPimMainWindow { Q_OBJECT friend class Show; // to avoid QObject friend class View; // to avoid QObject + friend class Editor; public: MainWindow(); ~MainWindow(); private slots: void initUI(); // init the UI void initConfig(); // apply the config 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 + void slotConfigureTemp(); + void slotNewFromTemplate(int ); // called when someone chooses the template menu + void setTemplateMenu(); // updates the templateMenu protected slots: void populate(); void doSetDocument( const QString& str ); void flush(); void reload(); int create(); bool remove( int uid ); void beam( int uid ); void show( int uid ); void edit( int uid ); void edit(); void add( const OPimRecord& ); private: QPEToolBar* toolbar(); QPopupMenu* viewMenu(); QPopupMenu* settingsMenu(); QPopupMenu* templateMenu(); View* currentView(); BookManager* manager(); - TemplateManager* templateManager(); - LocationManager* locationManager(); - DescriptionManager* descriptionManager(); + TemplateManager templateManager(); + LocationManager locationManager(); + DescriptionManager descriptionManager(); + void setLocationManager( const LocationManager& ); + void setDescriptionManager( const DescriptionManager& ); Show* eventShow(); + Editor* editor(); 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; + TemplateManager m_tempMan; + DescriptionManager m_descMan; + LocationManager m_locMan; Show* m_show; + Editor* m_edit; }; } #endif diff --git a/core/pim/datebook2/managertemplate.h b/core/pim/datebook2/managertemplate.h index cdf121d..72fab3a 100644 --- a/core/pim/datebook2/managertemplate.h +++ b/core/pim/datebook2/managertemplate.h @@ -1,73 +1,60 @@ #ifndef OPIE_DATE_BOOK_MANAGER_TEMPLATE_H #define OPIE_DATE_BOOK_MANAGER_TEMPLATE_H #include <qdialog.h> #include <qmap.h> #include <qstring.h> namespace Datebook { /** * ManagerTemplate is a template which manages * all kind of managers :) */ template<class T> class ManagerTemplate { - typedef typename QMap<QString, T>::Iterator Iterator; + typedef typename QMap<QString, T>::ConstIterator Iterator; public: ManagerTemplate(); virtual ~ManagerTemplate(); virtual void add( const QString&, const T& t ); void remove( const QString& ); - bool load(); - bool save(); + virtual bool load() = 0; + virtual bool save() = 0; - QStringList names(); + QStringList names()const; T value(const QString&)const; protected: QMap<QString, T> m_map; - - private: - virtual bool doSave() = 0; - 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 ManagerTemplate<T>::names()const { 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/stringmanager.cpp b/core/pim/datebook2/stringmanager.cpp index 77bc88a..715a4b1 100644 --- a/core/pim/datebook2/stringmanager.cpp +++ b/core/pim/datebook2/stringmanager.cpp @@ -1,42 +1,138 @@ +#include <qhbox.h> +#include <qpushbutton.h> +#include <qlayout.h> +#include <qlistview.h> +#include <qlineedit.h> + #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() { +bool StringManager::load() { 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 ); +bool StringManager::save() { + Config qpe( "datebook-"+m_base ); qpe.setGroup(m_base); qpe.writeEntry( "Names", names(), 0x1f ); return false; } +QString StringManager::baseName()const { + return m_base; +} + -StringManagerDialog::StringManagerDialog(const StringManager& ) +StringManagerDialog::StringManagerDialog(const StringManager& man) : QDialog(0, 0, true ) { + m_base = man.baseName(); + + QVBoxLayout* lay = new QVBoxLayout( this ); + + m_view = new QListView( this ); + m_view->addColumn( QString::null ); + lay->addWidget( m_view ); + + QHBox* box = new QHBox( this ); + + QPushButton* b = new QPushButton( box ); + b->setText( tr("&Add") ); + connect(b, SIGNAL(clicked() ), this, SLOT(slotAdd() ) ); + + b = new QPushButton( box ); + b->setText( tr("&Remove") ); + connect(b, SIGNAL(clicked() ), this, SLOT(slotRemove() ) ); + + b = new QPushButton( box ); + b->setText( tr("Rename") ); + connect(b, SIGNAL(clicked() ), this, SLOT(slotRename() ) ); + + lay->addWidget( box ); + + init( man ); } StringManagerDialog::~StringManagerDialog() { - } StringManager StringManagerDialog::manager()const { - return StringManager(); + StringManager man(m_base ); + QListViewItemIterator it(m_view); + while ( it.current() ) { + man.add( it.current()->text(0) ); + ++it; + } + + return man; +} +void StringManagerDialog::init( const StringManager& _man ) { + QStringList::Iterator it; + QStringList man = _man.names(); + for ( it = man.begin(); it != man.end(); ++it ) + (void)new QListViewItem( m_view, (*it) ); + +} + +namespace { + class InputDialog : public QDialog{ + public: + InputDialog( const QString& text ); + ~InputDialog(); + + QString text()const; + private: + QLineEdit* m_lneEdit; + }; + InputDialog::InputDialog(const QString& text ) + : QDialog(0, 0, true ) { + m_lneEdit = new QLineEdit( this ); + m_lneEdit->setText( text ); + } + InputDialog::~InputDialog() { + } + QString InputDialog::text() const{ + return m_lneEdit->text(); + } + +} + +void StringManagerDialog::slotAdd() { + InputDialog dlg(QString::null); + dlg.setCaption( tr("Add") ); + if ( dlg.exec() == QDialog::Accepted ) + (void)new QListViewItem( m_view, dlg.text() ); + +} +void StringManagerDialog::slotRename() { + QListViewItem* item = m_view->currentItem(); + if (!item) return; + + InputDialog dlg(item->text(0) ); + dlg.setCaption( tr("Rename") ); + + if ( dlg.exec() == QDialog::Accepted ) + item->setText( 0, dlg.text() ); +} +void StringManagerDialog::slotRemove() { + QListViewItem* item = m_view->currentItem(); + if (!item) return; + + m_view->takeItem( item ); + delete item; } diff --git a/core/pim/datebook2/stringmanager.h b/core/pim/datebook2/stringmanager.h index ac0d4bd..2eee43f 100644 --- a/core/pim/datebook2/stringmanager.h +++ b/core/pim/datebook2/stringmanager.h @@ -1,47 +1,57 @@ #ifndef OPIE_STRING_DATEBOOK_MANAGER_H #define OPIE_STRING_DATEBOOK_MANAGER_H #include <qstring.h> #include "managertemplate.h" +class QListView; namespace Datebook { /** * StringManager is a generic manager * whick keeps track of strings * It'll be used with the Location * and the Description Manager */ class StringManager : public ManagerTemplate<QString> { public: /** * baseName is used for storing */ StringManager(const QString& baseName = QString::null); ~StringManager(); /** * override the add implementation * cause we do not have a value :) */ void add( const QString& ); + bool load(); + bool save(); + QString baseName()const; private: QString m_base; - bool doLoad(); - bool doSave(); }; /** * A Generic Editor for StringManager */ class StringManagerDialog : public QDialog { Q_OBJECT public: StringManagerDialog( const StringManager&); ~StringManagerDialog(); StringManager manager()const; + private slots: + void init( const StringManager& ); + void slotAdd(); + void slotRemove(); + void slotRename(); + private: + QListView* m_view; + QString m_base; }; } #endif diff --git a/core/pim/datebook2/templatemanager.cpp b/core/pim/datebook2/templatemanager.cpp index b620cf7..541fec0 100644 --- a/core/pim/datebook2/templatemanager.cpp +++ b/core/pim/datebook2/templatemanager.cpp @@ -1,25 +1,184 @@ +#include <qdatetime.h> +#include <qlistview.h> +#include <qlayout.h> +#include <qhbox.h> +#include <qlineedit.h> +#include <qpushbutton.h> + +#include <qpe/config.h> + +#include <opie/odatebookaccess.h> +#include <opie/odatebookaccessbackend_xml.h> + +#include "editor.h" #include "templatemanager.h" using namespace Datebook; TemplateManager::TemplateManager() { } TemplateManager::~TemplateManager() { } -bool TemplateManager::doSave() { +bool TemplateManager::save() { + QStringList lst = names(); + Config conf( "datebook-templates"); + conf.setGroup( "___Names___"); + conf.writeEntry( "Names", names(), 0x1f ); + + for ( QStringList::Iterator it = lst.begin(); it != lst.end(); ++it ) { + conf.setGroup( (*it) ); + conf.writeEntry( "Uid", value( (*it) ).uid() ); + } + return true; } -bool TemplateManager::doLoad() { +bool TemplateManager::load() { + Config conf( "datebook-templates"); + conf.setGroup( "___Names___"); + QStringList lst = conf.readListEntry( "Names", 0x1f ); + for ( QStringList::Iterator it = lst.begin(); it != lst.end(); ++it ) { + conf.setGroup( (*it) ); + add( (*it), OEvent() ); + } return true; } -TemplateDialog::TemplateDialog( const TemplateManager& ) +namespace { + class TemplateItem : public QListViewItem { + public: + TemplateItem( QListView*, const QString& text, + const OEvent& ); + ~TemplateItem(); + + QString text()const; + OEvent event()const; + + void setText( const QString& text ); + void setEvent( const OEvent& ); + private: + QString m_text; + OEvent m_event; + }; + TemplateItem::TemplateItem( QListView* view, + const QString& text, + const OEvent& ev ) + : QListViewItem( view ), m_event(ev) { + QListViewItem::setText( 0, text ); + } + TemplateItem::~TemplateItem() { + } + void TemplateItem::setText( const QString& text ) { + QListViewItem::setText( 0, text ); + m_text = text; + } + void TemplateItem::setEvent( const OEvent& ev ) { + m_event = ev; + } + QString TemplateItem::text()const { + return m_text; + } + OEvent TemplateItem::event()const { + + } + + class InputDialog : public QDialog{ + public: + InputDialog( const QString& text ); + ~InputDialog(); + + QString text()const; + private: + QLineEdit* m_lneEdit; + }; + InputDialog::InputDialog(const QString& text ) + : QDialog(0, 0, true ) { + m_lneEdit = new QLineEdit( this ); + m_lneEdit->setText( text ); + } + InputDialog::~InputDialog() { + } + QString InputDialog::text() const{ + return m_lneEdit->text(); + } +} + +TemplateDialog::TemplateDialog( const TemplateManager& man, Editor* edit ) : QDialog(0, 0, true ) { + QVBoxLayout* lay = new QVBoxLayout(this); + m_view = new QListView( this ); + m_view->addColumn( tr("Template Names") ); + lay->addWidget( m_view ); + + QHBox* box = new QHBox( this ); + lay->addWidget( box ); + + QPushButton* b = new QPushButton( box ); + b->setText(tr("&Add") ); + connect( b, SIGNAL(clicked() ), this, SLOT(slotAdd() ) ); + + b = new QPushButton( box ); + b->setText(tr("&Edit") ); + connect( b, SIGNAL(clicked() ), this, SLOT(slotEdit() ) ); + + b = new QPushButton( box ); + b->setText(tr("&Rename") ); + connect(b, SIGNAL(clicked() ), this, SLOT(slotRename() ) ); + + b = new QPushButton( box ); + b->setText(tr("Re&move") ); + connect(b, SIGNAL(clicked() ), this, SLOT(slotRemove() ) ); + + init( man ); + m_edit = edit; } TemplateDialog::~TemplateDialog() { } +void TemplateDialog::slotAdd() { + if ( m_edit->newEvent( QDate::currentDate() ) ) { + (void)new TemplateItem( m_view, tr("New Template"), m_edit->event() ); + } +} +void TemplateDialog::slotEdit() { + TemplateItem* item = static_cast<TemplateItem*>( m_view->currentItem() ); + if (!item) return; + + if (m_edit->edit( item->event() ) ) + item->setEvent( m_edit->event() ); + +} +void TemplateDialog::slotRemove() { + QListViewItem* item = m_view->currentItem(); + if (!item) return; + + m_view->takeItem( item ); + delete item; +} +void TemplateDialog::slotRename() { + TemplateItem* item = static_cast<TemplateItem*>( m_view->currentItem() ); + if (!item) return; + + InputDialog dlg( item->text() ); + dlg.setCaption( tr("Rename") ); + if ( dlg.exec() == QDialog::Accepted ) + item->setText( dlg.text() ); + +} TemplateManager TemplateDialog::manager()const { - return TemplateManager(); + TemplateManager manager; + + QListViewItemIterator it(m_view); + while ( it.current() ) { + TemplateItem* item = static_cast<TemplateItem*>( it.current() ); + manager.add( item->text(), item->event() ); + ++it; + } + return manager; +} +void TemplateDialog::init( const TemplateManager& man ) { + QStringList list = man.names(); + for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) { + (void)new TemplateItem( m_view, (*it), man.value( (*it) ) ); + } } diff --git a/core/pim/datebook2/templatemanager.h b/core/pim/datebook2/templatemanager.h index f885677..91d8b2e 100644 --- a/core/pim/datebook2/templatemanager.h +++ b/core/pim/datebook2/templatemanager.h @@ -1,36 +1,48 @@ #ifndef OPIE_DATEBOOK_TEMPLATE_MANAGER_ZECKE_H_RANDOM_CAUSE_BJARNE #define OPIE_DATEBOOK_TEMPLATE_MANAGER_ZECKE_H_RANDOM_CAUSE_BJARNE #include <qobject.h> #include <opie/oevent.h> #include "managertemplate.h" +class QListView; namespace Datebook { /** * The OEvent Template Manager */ + class Editor; class TemplateManager : public ManagerTemplate<OEvent> { public: TemplateManager(); ~TemplateManager(); - private: - virtual bool doSave(); - virtual bool doLoad(); + bool save(); + bool load(); }; /** * a QDialog for editing it */ class TemplateDialog : public QDialog { Q_OBJECT public: - TemplateDialog(const TemplateManager& man); + TemplateDialog(const TemplateManager& man, Editor*); ~TemplateDialog(); - virtual TemplateManager manager()const; + TemplateManager manager()const; + + private slots: + void init( const TemplateManager& ); + void slotAdd(); + void slotEdit(); + void slotRename(); + void slotRemove(); + + private: + QListView* m_view; + Editor* m_edit; }; } #endif diff --git a/core/pim/datebook2/view.h b/core/pim/datebook2/view.h index e2312a3..2236aad 100644 --- a/core/pim/datebook2/view.h +++ b/core/pim/datebook2/view.h @@ -1,117 +1,127 @@ #ifndef OPIE_DATE_BOOK_VIEW_H #define OPIE_DATE_BOOK_VIEW_H #include <qpixmap.h> #include <qwidget.h> #include <opie/oevent.h> #include <opie/odatebookaccess.h> class Config; namespace Datebook { class MainWindow; class View { public: View( MainWindow* window, QWidget* parent ); virtual ~View(); static QDate dateFromWeek( int week, int year, bool startOnMonda ); static bool calcWeek( const QDate& d, int &week, int &year, bool startOnMonday = false ); virtual QPixmap pixmap()const = 0; + + /** + * non translatable name or type + */ + virtual QCString type()const = 0; + + /** + * shown to the user + */ + virtual QString name()const = 0; virtual QString description()const = 0; /** * return the uid of the current item or 0 */ virtual int currentItem()const = 0; /** * loadConfig * saveConfig */ void loadConfig( Config* ); void saveConfig( Config* ); /** * the current range * @param src Where to write the start datetime * @param dest Where to write the end datetime */ virtual void currentRange( const QDateTime& src, const QDateTime& from) = 0; /** * the clock format changed */ virtual void clockChanged() = 0; /** * the day change means that either * monday or sunday is the week start */ virtual void dayChanged() = 0; /** * 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() = 0; /** * the view needs an update! */ virtual void reschedule() = 0; protected: void popup( int uid); QString toShortText(const OEffectiveEvent& eff)const; QString toText(const OEffectiveEvent& eff)const; virtual void doLoadConfig( Config* ) = 0; virtual void doSaveConfig( Config* ) = 0; /** * create a new event starting * on start */ void add( const QDate& start ); /** * create a new event in a given range */ void add( const QDateTime& start, const QDateTime& end ); /** * will make the MainWindow to open the editor */ void edit( int uid ); /** * remove item with uid */ void remove( int uid ); /** * give access to all events */ ODateBookAccess::List allEvents()const; /** * return events */ OEffectiveEvent::ValueList events( const QDate& start, const QDate& end ); /** * return an Event */ OEvent event( int uid )const; /** * Is the clock AP/PM or 24h? */ bool isAP()const; /** |