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 @@ -13,16 +13,17 @@ HEADERS = mainwindow.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 @@ -11,26 +11,29 @@ 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 @@ -8,44 +8,51 @@ #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() { @@ -90,18 +97,22 @@ void MainWindow::initUI() { 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 ); @@ -125,34 +136,42 @@ void MainWindow::initUI() { 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() { @@ -181,36 +200,61 @@ 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& ) { @@ -219,8 +263,43 @@ 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 @@ -2,31 +2,32 @@ #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.. @@ -37,17 +38,20 @@ namespace Datebook { 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 ); @@ -59,20 +63,23 @@ namespace Datebook { 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 ); @@ -84,16 +91,17 @@ namespace Datebook { 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 @@ -7,61 +7,48 @@ 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> 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,15 +1,16 @@ #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> { @@ -20,28 +21,37 @@ namespace Datebook { 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 @@ -2,35 +2,47 @@ #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 @@ -14,16 +14,26 @@ namespace Datebook { 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; /** |