author | zecke <zecke> | 2003-02-24 13:34:03 (UTC) |
---|---|---|
committer | zecke <zecke> | 2003-02-24 13:34:03 (UTC) |
commit | b04ced09167d910e5cab1981bde295e2e8185fee (patch) (unidiff) | |
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 | |||
@@ -18,7 +18,8 @@ SOURCES = main.cpp \ | |||
18 | stringmanager.cpp \ | 18 | stringmanager.cpp \ |
19 | templatemanager.cpp \ | 19 | templatemanager.cpp \ |
20 | show.cpp \ | 20 | show.cpp \ |
21 | view.cpp | 21 | view.cpp \ |
22 | editor.cpp | ||
22 | 23 | ||
23 | INCLUDEPATH += $(OPIEDIR)/include | 24 | INCLUDEPATH += $(OPIEDIR)/include |
24 | DEPENDPATH+= $(OPIEDIR)/include | 25 | DEPENDPATH+= $(OPIEDIR)/include |
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 @@ | |||
1 | #include "mainwindow.h" | ||
2 | |||
3 | #include "editor.h" | ||
4 | |||
5 | using namespace Datebook; | ||
6 | |||
7 | Editor::Editor( MainWindow* win, QWidget*) | ||
8 | : m_win( win ) | ||
9 | {} | ||
10 | Editor::~Editor() { | ||
11 | |||
12 | } | ||
13 | DescriptionManager Editor::descriptions()const { | ||
14 | return m_win->descriptionManager(); | ||
15 | } | ||
16 | LocationManager Editor::locations()const { | ||
17 | return m_win->locationManager(); | ||
18 | } | ||
19 | void Editor::setDescriptions( const DescriptionManager& dsc) { | ||
20 | m_win->setDescriptionManager( dsc ); | ||
21 | } | ||
22 | void Editor::setLocations( const LocationManager& loc) { | ||
23 | m_win->setLocationManager( loc ); | ||
24 | } | ||
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 | |||
@@ -16,13 +16,13 @@ namespace Datebook { | |||
16 | class Editor { | 16 | class Editor { |
17 | public: | 17 | public: |
18 | Editor( MainWindow*, QWidget* parent ); | 18 | Editor( MainWindow*, QWidget* parent ); |
19 | virtual Editor(); | 19 | virtual ~Editor(); |
20 | 20 | ||
21 | bool newEvent( const QDate& ); | 21 | virtual bool newEvent( const QDate& ) = 0; |
22 | bool newEvent( const QDateTime& start, const QDateTime& end ); | 22 | virtual bool newEvent( const QDateTime& start, const QDateTime& end ) = 0; |
23 | bool edit( const OEvent& ); | 23 | virtual bool edit( const OEvent&, bool showRec = TRUE ) = 0; |
24 | 24 | ||
25 | OEvent event()const; | 25 | virtual OEvent event()const = 0; |
26 | 26 | ||
27 | protected: | 27 | protected: |
28 | DescriptionManager descriptions()const; | 28 | DescriptionManager descriptions()const; |
@@ -30,6 +30,9 @@ namespace Datebook { | |||
30 | void setDescriptions( const DescriptionManager& ); | 30 | void setDescriptions( const DescriptionManager& ); |
31 | void setLocations( const LocationManager& ); | 31 | void setLocations( const LocationManager& ); |
32 | 32 | ||
33 | private: | ||
34 | MainWindow* m_win; | ||
35 | |||
33 | }; | 36 | }; |
34 | } | 37 | } |
35 | 38 | ||
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 | |||
@@ -13,6 +13,7 @@ | |||
13 | #include <qpe/qpemessagebox.h> | 13 | #include <qpe/qpemessagebox.h> |
14 | #include <qpe/resource.h> | 14 | #include <qpe/resource.h> |
15 | 15 | ||
16 | #include "editor.h" | ||
16 | #include "show.h" | 17 | #include "show.h" |
17 | #include "templatemanager.h" | 18 | #include "templatemanager.h" |
18 | #include "bookmanager.h" | 19 | #include "bookmanager.h" |
@@ -22,14 +23,14 @@ | |||
22 | using namespace Datebook; | 23 | using namespace Datebook; |
23 | 24 | ||
24 | MainWindow::MainWindow() | 25 | MainWindow::MainWindow() |
25 | : OPimMainWindow( "Datebook", 0, 0 ) { | 26 | : OPimMainWindow( "Datebook", 0, 0 ), m_descMan( "Descriptions" ), m_locMan( "Locations" ) |
27 | { | ||
26 | setIcon( Resource::loadPixmap( "datebook_icon" ) ); | 28 | setIcon( Resource::loadPixmap( "datebook_icon" ) ); |
27 | initUI(); | 29 | initUI(); |
28 | initManagers(); | 30 | initManagers(); |
29 | initView(); | 31 | initView(); |
30 | initConfig(); | 32 | initConfig(); |
31 | 33 | ||
32 | raiseCurrentView(); | ||
33 | QTimer::singleShot(0, this, SLOT(populate() ) ); | 34 | QTimer::singleShot(0, this, SLOT(populate() ) ); |
34 | 35 | ||
35 | QCopChannel* chan = new QCopChannel( "QPE/System", this ); | 36 | QCopChannel* chan = new QCopChannel( "QPE/System", this ); |
@@ -41,6 +42,12 @@ MainWindow::MainWindow() | |||
41 | this, SLOT( slotReceive( const QCString&, const QByteArray& ) ) ); | 42 | this, SLOT( slotReceive( const QCString&, const QByteArray& ) ) ); |
42 | } | 43 | } |
43 | MainWindow::~MainWindow() { | 44 | MainWindow::~MainWindow() { |
45 | m_tempMan.save(); | ||
46 | m_locMan.save(); | ||
47 | m_descMan.save(); | ||
48 | |||
49 | manager()->save(); | ||
50 | delete m_manager; | ||
44 | } | 51 | } |
45 | void MainWindow::doSetDocument( const QString& str ) { | 52 | void MainWindow::doSetDocument( const QString& str ) { |
46 | 53 | ||
@@ -95,8 +102,12 @@ void MainWindow::initUI() { | |||
95 | mb->insertItem( tr("Settings" ), m_popSetting ); | 102 | mb->insertItem( tr("Settings" ), m_popSetting ); |
96 | 103 | ||
97 | m_popTemplate = new QPopupMenu( this ); | 104 | m_popTemplate = new QPopupMenu( this ); |
105 | m_popTemplate->setCheckable( TRUE ); | ||
106 | connect( m_popTemplate, SIGNAL(activated(int) ), | ||
107 | this, SLOT(slotNewFromTemplate(int) ) ); | ||
98 | m_popView->insertItem(tr("New from template"), m_popTemplate, -1, 0); | 108 | m_popView->insertItem(tr("New from template"), m_popTemplate, -1, 0); |
99 | 109 | ||
110 | |||
100 | QAction* a = new QAction( tr("New Event"), Resource::loadPixmap("new"), | 111 | QAction* a = new QAction( tr("New Event"), Resource::loadPixmap("new"), |
101 | QString::null, 0, this, 0 ); | 112 | QString::null, 0, this, 0 ); |
102 | a->addTo( m_toolBar ); | 113 | a->addTo( m_toolBar ); |
@@ -130,6 +141,10 @@ void MainWindow::initUI() { | |||
130 | a->addTo( m_popSetting ); | 141 | a->addTo( m_popSetting ); |
131 | connect(a, SIGNAL( activated() ), this, SLOT(slotConfigureDesc() ) ); | 142 | connect(a, SIGNAL( activated() ), this, SLOT(slotConfigureDesc() ) ); |
132 | 143 | ||
144 | a = new QAction( tr("Configure Templates"), QString::null, 0, 0 ); | ||
145 | a->addTo( m_popSetting ); | ||
146 | connect(a, SIGNAL( activated() ), this, SLOT(slotConfigureTemp() ) ); | ||
147 | |||
133 | connect( qApp, SIGNAL(clockChanged(bool) ), | 148 | connect( qApp, SIGNAL(clockChanged(bool) ), |
134 | this, SLOT(slotClockChanged(bool) ) ); | 149 | this, SLOT(slotClockChanged(bool) ) ); |
135 | connect( qApp, SIGNAL(weekChanged(bool) ), | 150 | connect( qApp, SIGNAL(weekChanged(bool) ), |
@@ -146,8 +161,12 @@ void MainWindow::initView() { | |||
146 | } | 161 | } |
147 | void MainWindow::initManagers() { | 162 | void MainWindow::initManagers() { |
148 | m_manager = new BookManager; | 163 | m_manager = new BookManager; |
149 | m_locMan = new LocationManager( tr("Locations") ); | 164 | |
150 | m_descMan = new DescriptionManager( tr("Descriptions") ); | 165 | m_tempMan.load(); |
166 | m_locMan.load(); | ||
167 | m_descMan.load(); | ||
168 | |||
169 | setTemplateMenu(); | ||
151 | } | 170 | } |
152 | void MainWindow::raiseCurrentView() { | 171 | void MainWindow::raiseCurrentView() { |
153 | 172 | ||
@@ -186,15 +205,21 @@ void MainWindow::slotReceive( const QCString&, const QByteArray& ) { | |||
186 | BookManager* MainWindow::manager() { | 205 | BookManager* MainWindow::manager() { |
187 | return m_manager; | 206 | return m_manager; |
188 | } | 207 | } |
189 | TemplateManager* MainWindow::templateManager() { | 208 | TemplateManager MainWindow::templateManager() { |
190 | return m_tempMan; | 209 | return m_tempMan; |
191 | } | 210 | } |
192 | LocationManager* MainWindow::locationManager() { | 211 | LocationManager MainWindow::locationManager() { |
193 | return m_locMan; | 212 | return m_locMan; |
194 | } | 213 | } |
195 | DescriptionManager* MainWindow::descriptionManager() { | 214 | DescriptionManager MainWindow::descriptionManager() { |
196 | return m_descMan; | 215 | return m_descMan; |
197 | } | 216 | } |
217 | void MainWindow::setLocationManager( const LocationManager& loc) { | ||
218 | m_locMan = loc; | ||
219 | } | ||
220 | void MainWindow::setDescriptionManager( const DescriptionManager& dsc ) { | ||
221 | m_descMan = dsc; | ||
222 | } | ||
198 | Show* MainWindow::eventShow() { | 223 | Show* MainWindow::eventShow() { |
199 | return m_show; | 224 | return m_show; |
200 | } | 225 | } |
@@ -202,10 +227,29 @@ void MainWindow::slotAction( QAction* act ) { | |||
202 | 227 | ||
203 | } | 228 | } |
204 | void MainWindow::slotConfigureLocs() { | 229 | void MainWindow::slotConfigureLocs() { |
205 | 230 | LocationManagerDialog dlg( locationManager() ); | |
231 | dlg.setCaption( tr("Configure Locations") ); | ||
232 | dlg.showMaximized(); | ||
233 | if (dlg.exec() == QDialog::Accepted ) { | ||
234 | setLocationManager( dlg.manager() ); | ||
235 | } | ||
206 | } | 236 | } |
207 | void MainWindow::slotConfigureDesc() { | 237 | void MainWindow::slotConfigureDesc() { |
208 | 238 | DescriptionManagerDialog dlg( descriptionManager() ); | |
239 | dlg.setCaption( tr("Configure Descriptions") ); | ||
240 | dlg.showMaximized(); | ||
241 | if (dlg.exec() == QDialog::Accepted ) { | ||
242 | setDescriptionManager( dlg.manager() ); | ||
243 | } | ||
244 | } | ||
245 | void MainWindow::slotConfigureTemp() { | ||
246 | TemplateDialog dlg( templateManager(), editor() ); | ||
247 | dlg.setCaption( tr("Configure Templates") ); | ||
248 | dlg.showMaximized(); | ||
249 | if ( dlg.exec() == QDialog::Accepted ) { | ||
250 | m_tempMan = dlg.manager(); | ||
251 | setTemplateMenu(); | ||
252 | } | ||
209 | } | 253 | } |
210 | void MainWindow::hideShow() { | 254 | void MainWindow::hideShow() { |
211 | 255 | ||
@@ -224,3 +268,38 @@ bool MainWindow::viewAP()const{ | |||
224 | bool MainWindow::viewStartMonday()const { | 268 | bool MainWindow::viewStartMonday()const { |
225 | 269 | ||
226 | } | 270 | } |
271 | void MainWindow::setTemplateMenu() { | ||
272 | m_popTemplate->clear(); | ||
273 | |||
274 | QStringList list = templateManager().names(); | ||
275 | for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) { | ||
276 | m_popTemplate->insertItem( (*it) ); | ||
277 | } | ||
278 | } | ||
279 | /* | ||
280 | * get the name of the item with the id id | ||
281 | * then ask for an OEvent from the manager | ||
282 | */ | ||
283 | void MainWindow::slotNewFromTemplate(int id ) { | ||
284 | QString name = m_popTemplate->text( id ); | ||
285 | |||
286 | OEvent ev = templateManager().value( name ); | ||
287 | |||
288 | if ( editor()->edit( ev ) ) { | ||
289 | ev = editor()->event(); | ||
290 | ev.setUid( -1 ); | ||
291 | manager()->add( ev ); | ||
292 | |||
293 | /* | ||
294 | * no we'll find out if the current view | ||
295 | * should show the new event | ||
296 | * and then we will ask it to refresh | ||
297 | * FIXME for now we'll call a refresh | ||
298 | */ | ||
299 | currentView()->reschedule(); | ||
300 | raiseCurrentView(); | ||
301 | } | ||
302 | } | ||
303 | Editor* MainWindow::editor() { | ||
304 | return m_edit; | ||
305 | } | ||
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 | |||
@@ -7,6 +7,7 @@ | |||
7 | 7 | ||
8 | #include "descriptionmanager.h" | 8 | #include "descriptionmanager.h" |
9 | #include "locationmanager.h" | 9 | #include "locationmanager.h" |
10 | #include "templatemanager.h" | ||
10 | #include "view.h" | 11 | #include "view.h" |
11 | 12 | ||
12 | class QAction; | 13 | class QAction; |
@@ -14,14 +15,14 @@ class QWidgetStack; | |||
14 | class QPopupMenu; | 15 | class QPopupMenu; |
15 | class QPEToolBar; | 16 | class QPEToolBar; |
16 | namespace Datebook { | 17 | namespace Datebook { |
17 | |||
18 | class TemplateManager; | ||
19 | class BookManager; | 18 | class BookManager; |
20 | class Show; | 19 | class Show; |
20 | class Editor; | ||
21 | class MainWindow : public OPimMainWindow { | 21 | class MainWindow : public OPimMainWindow { |
22 | Q_OBJECT | 22 | Q_OBJECT |
23 | friend class Show; // to avoid QObject | 23 | friend class Show; // to avoid QObject |
24 | friend class View; // to avoid QObject | 24 | friend class View; // to avoid QObject |
25 | friend class Editor; | ||
25 | public: | 26 | public: |
26 | MainWindow(); | 27 | MainWindow(); |
27 | ~MainWindow(); | 28 | ~MainWindow(); |
@@ -42,7 +43,10 @@ namespace Datebook { | |||
42 | void slotAction( QAction* ); // View changed | 43 | void slotAction( QAction* ); // View changed |
43 | void slotConfigureLocs(); // Configure the Locations | 44 | void slotConfigureLocs(); // Configure the Locations |
44 | void slotConfigureDesc(); // Configure the Desc | 45 | void slotConfigureDesc(); // Configure the Desc |
46 | void slotConfigureTemp(); | ||
47 | void slotNewFromTemplate(int ); // called when someone chooses the template menu | ||
45 | 48 | ||
49 | void setTemplateMenu(); // updates the templateMenu | ||
46 | 50 | ||
47 | protected slots: | 51 | protected slots: |
48 | void populate(); | 52 | void populate(); |
@@ -64,10 +68,13 @@ namespace Datebook { | |||
64 | QPopupMenu* templateMenu(); | 68 | QPopupMenu* templateMenu(); |
65 | View* currentView(); | 69 | View* currentView(); |
66 | BookManager* manager(); | 70 | BookManager* manager(); |
67 | TemplateManager* templateManager(); | 71 | TemplateManager templateManager(); |
68 | LocationManager* locationManager(); | 72 | LocationManager locationManager(); |
69 | DescriptionManager* descriptionManager(); | 73 | DescriptionManager descriptionManager(); |
74 | void setLocationManager( const LocationManager& ); | ||
75 | void setDescriptionManager( const DescriptionManager& ); | ||
70 | Show* eventShow(); | 76 | Show* eventShow(); |
77 | Editor* editor(); | ||
71 | 78 | ||
72 | private: // friend functions for Show | 79 | private: // friend functions for Show |
73 | void hideShow(); // to hide the view | 80 | void hideShow(); // to hide the view |
@@ -89,10 +96,11 @@ namespace Datebook { | |||
89 | QPopupMenu* m_popSetting; | 96 | QPopupMenu* m_popSetting; |
90 | QPopupMenu* m_popTemplate; | 97 | QPopupMenu* m_popTemplate; |
91 | BookManager* m_manager; | 98 | BookManager* m_manager; |
92 | TemplateManager* m_tempMan; | 99 | TemplateManager m_tempMan; |
93 | DescriptionManager* m_descMan; | 100 | DescriptionManager m_descMan; |
94 | LocationManager* m_locMan; | 101 | LocationManager m_locMan; |
95 | Show* m_show; | 102 | Show* m_show; |
103 | Editor* m_edit; | ||
96 | }; | 104 | }; |
97 | } | 105 | } |
98 | 106 | ||
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 | |||
@@ -12,26 +12,21 @@ namespace Datebook { | |||
12 | */ | 12 | */ |
13 | template<class T> | 13 | template<class T> |
14 | class ManagerTemplate { | 14 | class ManagerTemplate { |
15 | typedef typename QMap<QString, T>::Iterator Iterator; | 15 | typedef typename QMap<QString, T>::ConstIterator Iterator; |
16 | public: | 16 | public: |
17 | ManagerTemplate(); | 17 | ManagerTemplate(); |
18 | virtual ~ManagerTemplate(); | 18 | virtual ~ManagerTemplate(); |
19 | 19 | ||
20 | virtual void add( const QString&, const T& t ); | 20 | virtual void add( const QString&, const T& t ); |
21 | void remove( const QString& ); | 21 | void remove( const QString& ); |
22 | bool load(); | 22 | virtual bool load() = 0; |
23 | bool save(); | 23 | virtual bool save() = 0; |
24 | 24 | ||
25 | QStringList names(); | 25 | QStringList names()const; |
26 | T value(const QString&)const; | 26 | T value(const QString&)const; |
27 | 27 | ||
28 | protected: | 28 | protected: |
29 | QMap<QString, T> m_map; | 29 | QMap<QString, T> m_map; |
30 | |||
31 | private: | ||
32 | virtual bool doSave() = 0; | ||
33 | virtual bool doLoad() = 0; | ||
34 | |||
35 | }; | 30 | }; |
36 | template<class T> | 31 | template<class T> |
37 | ManagerTemplate<T>::ManagerTemplate() { | 32 | ManagerTemplate<T>::ManagerTemplate() { |
@@ -48,15 +43,7 @@ namespace Datebook { | |||
48 | m_map.remove( str ); | 43 | m_map.remove( str ); |
49 | } | 44 | } |
50 | template<class T> | 45 | template<class T> |
51 | bool ManagerTemplate<T>::load() { | 46 | QStringList ManagerTemplate<T>::names()const { |
52 | return doLoad(); | ||
53 | } | ||
54 | template<class T> | ||
55 | bool ManagerTemplate<T>::save() { | ||
56 | return doSave(); | ||
57 | } | ||
58 | template<class T> | ||
59 | QStringList ManagerTemplate<T>::names() { | ||
60 | QStringList lst; | 47 | QStringList lst; |
61 | Iterator it; | 48 | Iterator it; |
62 | for ( it = m_map.begin(); it != m_map.end(); ++it ) { | 49 | for ( it = m_map.begin(); it != m_map.end(); ++it ) { |
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,3 +1,9 @@ | |||
1 | #include <qhbox.h> | ||
2 | #include <qpushbutton.h> | ||
3 | #include <qlayout.h> | ||
4 | #include <qlistview.h> | ||
5 | #include <qlineedit.h> | ||
6 | |||
1 | #include <qpe/config.h> | 7 | #include <qpe/config.h> |
2 | 8 | ||
3 | #include "stringmanager.h" | 9 | #include "stringmanager.h" |
@@ -13,7 +19,7 @@ StringManager::~StringManager() { | |||
13 | void StringManager::add( const QString& str ) { | 19 | void StringManager::add( const QString& str ) { |
14 | ManagerTemplate<QString>::add(str, str); | 20 | ManagerTemplate<QString>::add(str, str); |
15 | } | 21 | } |
16 | bool StringManager::doLoad() { | 22 | bool StringManager::load() { |
17 | Config qpe( "datebook-"+m_base ); | 23 | Config qpe( "datebook-"+m_base ); |
18 | qpe.setGroup(m_base ); | 24 | qpe.setGroup(m_base ); |
19 | QStringList list = qpe.readListEntry( "Names", 0x1f ); | 25 | QStringList list = qpe.readListEntry( "Names", 0x1f ); |
@@ -22,21 +28,111 @@ bool StringManager::doLoad() { | |||
22 | 28 | ||
23 | return true; | 29 | return true; |
24 | } | 30 | } |
25 | bool StringManager::doSave() { | 31 | bool StringManager::save() { |
26 | Config qpe( "datebook"+m_base ); | 32 | Config qpe( "datebook-"+m_base ); |
27 | qpe.setGroup(m_base); | 33 | qpe.setGroup(m_base); |
28 | qpe.writeEntry( "Names", names(), 0x1f ); | 34 | qpe.writeEntry( "Names", names(), 0x1f ); |
29 | 35 | ||
30 | return false; | 36 | return false; |
31 | } | 37 | } |
38 | QString StringManager::baseName()const { | ||
39 | return m_base; | ||
40 | } | ||
41 | |||
32 | 42 | ||
33 | 43 | ||
34 | StringManagerDialog::StringManagerDialog(const StringManager& ) | 44 | StringManagerDialog::StringManagerDialog(const StringManager& man) |
35 | : QDialog(0, 0, true ) { | 45 | : QDialog(0, 0, true ) { |
46 | m_base = man.baseName(); | ||
47 | |||
48 | QVBoxLayout* lay = new QVBoxLayout( this ); | ||
49 | |||
50 | m_view = new QListView( this ); | ||
51 | m_view->addColumn( QString::null ); | ||
52 | lay->addWidget( m_view ); | ||
53 | |||
54 | QHBox* box = new QHBox( this ); | ||
55 | |||
56 | QPushButton* b = new QPushButton( box ); | ||
57 | b->setText( tr("&Add") ); | ||
58 | connect(b, SIGNAL(clicked() ), this, SLOT(slotAdd() ) ); | ||
59 | |||
60 | b = new QPushButton( box ); | ||
61 | b->setText( tr("&Remove") ); | ||
62 | connect(b, SIGNAL(clicked() ), this, SLOT(slotRemove() ) ); | ||
63 | |||
64 | b = new QPushButton( box ); | ||
65 | b->setText( tr("Rename") ); | ||
66 | connect(b, SIGNAL(clicked() ), this, SLOT(slotRename() ) ); | ||
67 | |||
68 | lay->addWidget( box ); | ||
69 | |||
70 | init( man ); | ||
36 | } | 71 | } |
37 | StringManagerDialog::~StringManagerDialog() { | 72 | StringManagerDialog::~StringManagerDialog() { |
38 | |||
39 | } | 73 | } |
40 | StringManager StringManagerDialog::manager()const { | 74 | StringManager StringManagerDialog::manager()const { |
41 | return StringManager(); | 75 | StringManager man(m_base ); |
76 | QListViewItemIterator it(m_view); | ||
77 | while ( it.current() ) { | ||
78 | man.add( it.current()->text(0) ); | ||
79 | ++it; | ||
80 | } | ||
81 | |||
82 | return man; | ||
83 | } | ||
84 | void StringManagerDialog::init( const StringManager& _man ) { | ||
85 | QStringList::Iterator it; | ||
86 | QStringList man = _man.names(); | ||
87 | for ( it = man.begin(); it != man.end(); ++it ) | ||
88 | (void)new QListViewItem( m_view, (*it) ); | ||
89 | |||
90 | } | ||
91 | |||
92 | namespace { | ||
93 | class InputDialog : public QDialog{ | ||
94 | public: | ||
95 | InputDialog( const QString& text ); | ||
96 | ~InputDialog(); | ||
97 | |||
98 | QString text()const; | ||
99 | private: | ||
100 | QLineEdit* m_lneEdit; | ||
101 | }; | ||
102 | InputDialog::InputDialog(const QString& text ) | ||
103 | : QDialog(0, 0, true ) { | ||
104 | m_lneEdit = new QLineEdit( this ); | ||
105 | m_lneEdit->setText( text ); | ||
106 | } | ||
107 | InputDialog::~InputDialog() { | ||
108 | } | ||
109 | QString InputDialog::text() const{ | ||
110 | return m_lneEdit->text(); | ||
111 | } | ||
112 | |||
113 | } | ||
114 | |||
115 | void StringManagerDialog::slotAdd() { | ||
116 | InputDialog dlg(QString::null); | ||
117 | dlg.setCaption( tr("Add") ); | ||
118 | if ( dlg.exec() == QDialog::Accepted ) | ||
119 | (void)new QListViewItem( m_view, dlg.text() ); | ||
120 | |||
121 | } | ||
122 | void StringManagerDialog::slotRename() { | ||
123 | QListViewItem* item = m_view->currentItem(); | ||
124 | if (!item) return; | ||
125 | |||
126 | InputDialog dlg(item->text(0) ); | ||
127 | dlg.setCaption( tr("Rename") ); | ||
128 | |||
129 | if ( dlg.exec() == QDialog::Accepted ) | ||
130 | item->setText( 0, dlg.text() ); | ||
131 | } | ||
132 | void StringManagerDialog::slotRemove() { | ||
133 | QListViewItem* item = m_view->currentItem(); | ||
134 | if (!item) return; | ||
135 | |||
136 | m_view->takeItem( item ); | ||
137 | delete item; | ||
42 | } | 138 | } |
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 | |||
@@ -5,6 +5,7 @@ | |||
5 | 5 | ||
6 | #include "managertemplate.h" | 6 | #include "managertemplate.h" |
7 | 7 | ||
8 | class QListView; | ||
8 | namespace Datebook { | 9 | namespace Datebook { |
9 | /** | 10 | /** |
10 | * StringManager is a generic manager | 11 | * StringManager is a generic manager |
@@ -25,10 +26,11 @@ namespace Datebook { | |||
25 | * cause we do not have a value :) | 26 | * cause we do not have a value :) |
26 | */ | 27 | */ |
27 | void add( const QString& ); | 28 | void add( const QString& ); |
29 | bool load(); | ||
30 | bool save(); | ||
31 | QString baseName()const; | ||
28 | private: | 32 | private: |
29 | QString m_base; | 33 | QString m_base; |
30 | bool doLoad(); | ||
31 | bool doSave(); | ||
32 | }; | 34 | }; |
33 | 35 | ||
34 | /** | 36 | /** |
@@ -41,6 +43,14 @@ namespace Datebook { | |||
41 | ~StringManagerDialog(); | 43 | ~StringManagerDialog(); |
42 | 44 | ||
43 | StringManager manager()const; | 45 | StringManager manager()const; |
46 | private slots: | ||
47 | void init( const StringManager& ); | ||
48 | void slotAdd(); | ||
49 | void slotRemove(); | ||
50 | void slotRename(); | ||
51 | private: | ||
52 | QListView* m_view; | ||
53 | QString m_base; | ||
44 | }; | 54 | }; |
45 | } | 55 | } |
46 | 56 | ||
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,3 +1,16 @@ | |||
1 | #include <qdatetime.h> | ||
2 | #include <qlistview.h> | ||
3 | #include <qlayout.h> | ||
4 | #include <qhbox.h> | ||
5 | #include <qlineedit.h> | ||
6 | #include <qpushbutton.h> | ||
7 | |||
8 | #include <qpe/config.h> | ||
9 | |||
10 | #include <opie/odatebookaccess.h> | ||
11 | #include <opie/odatebookaccessbackend_xml.h> | ||
12 | |||
13 | #include "editor.h" | ||
1 | #include "templatemanager.h" | 14 | #include "templatemanager.h" |
2 | 15 | ||
3 | using namespace Datebook; | 16 | using namespace Datebook; |
@@ -8,18 +21,164 @@ TemplateManager::TemplateManager() { | |||
8 | } | 21 | } |
9 | TemplateManager::~TemplateManager() { | 22 | TemplateManager::~TemplateManager() { |
10 | } | 23 | } |
11 | bool TemplateManager::doSave() { | 24 | bool TemplateManager::save() { |
25 | QStringList lst = names(); | ||
26 | Config conf( "datebook-templates"); | ||
27 | conf.setGroup( "___Names___"); | ||
28 | conf.writeEntry( "Names", names(), 0x1f ); | ||
29 | |||
30 | for ( QStringList::Iterator it = lst.begin(); it != lst.end(); ++it ) { | ||
31 | conf.setGroup( (*it) ); | ||
32 | conf.writeEntry( "Uid", value( (*it) ).uid() ); | ||
33 | } | ||
34 | |||
12 | return true; | 35 | return true; |
13 | } | 36 | } |
14 | bool TemplateManager::doLoad() { | 37 | bool TemplateManager::load() { |
38 | Config conf( "datebook-templates"); | ||
39 | conf.setGroup( "___Names___"); | ||
40 | QStringList lst = conf.readListEntry( "Names", 0x1f ); | ||
41 | for ( QStringList::Iterator it = lst.begin(); it != lst.end(); ++it ) { | ||
42 | conf.setGroup( (*it) ); | ||
43 | add( (*it), OEvent() ); | ||
44 | } | ||
15 | return true; | 45 | return true; |
16 | } | 46 | } |
17 | 47 | ||
18 | TemplateDialog::TemplateDialog( const TemplateManager& ) | 48 | namespace { |
49 | class TemplateItem : public QListViewItem { | ||
50 | public: | ||
51 | TemplateItem( QListView*, const QString& text, | ||
52 | const OEvent& ); | ||
53 | ~TemplateItem(); | ||
54 | |||
55 | QString text()const; | ||
56 | OEvent event()const; | ||
57 | |||
58 | void setText( const QString& text ); | ||
59 | void setEvent( const OEvent& ); | ||
60 | private: | ||
61 | QString m_text; | ||
62 | OEvent m_event; | ||
63 | }; | ||
64 | TemplateItem::TemplateItem( QListView* view, | ||
65 | const QString& text, | ||
66 | const OEvent& ev ) | ||
67 | : QListViewItem( view ), m_event(ev) { | ||
68 | QListViewItem::setText( 0, text ); | ||
69 | } | ||
70 | TemplateItem::~TemplateItem() { | ||
71 | } | ||
72 | void TemplateItem::setText( const QString& text ) { | ||
73 | QListViewItem::setText( 0, text ); | ||
74 | m_text = text; | ||
75 | } | ||
76 | void TemplateItem::setEvent( const OEvent& ev ) { | ||
77 | m_event = ev; | ||
78 | } | ||
79 | QString TemplateItem::text()const { | ||
80 | return m_text; | ||
81 | } | ||
82 | OEvent TemplateItem::event()const { | ||
83 | |||
84 | } | ||
85 | |||
86 | class InputDialog : public QDialog{ | ||
87 | public: | ||
88 | InputDialog( const QString& text ); | ||
89 | ~InputDialog(); | ||
90 | |||
91 | QString text()const; | ||
92 | private: | ||
93 | QLineEdit* m_lneEdit; | ||
94 | }; | ||
95 | InputDialog::InputDialog(const QString& text ) | ||
96 | : QDialog(0, 0, true ) { | ||
97 | m_lneEdit = new QLineEdit( this ); | ||
98 | m_lneEdit->setText( text ); | ||
99 | } | ||
100 | InputDialog::~InputDialog() { | ||
101 | } | ||
102 | QString InputDialog::text() const{ | ||
103 | return m_lneEdit->text(); | ||
104 | } | ||
105 | } | ||
106 | |||
107 | TemplateDialog::TemplateDialog( const TemplateManager& man, Editor* edit ) | ||
19 | : QDialog(0, 0, true ) { | 108 | : QDialog(0, 0, true ) { |
109 | QVBoxLayout* lay = new QVBoxLayout(this); | ||
110 | m_view = new QListView( this ); | ||
111 | m_view->addColumn( tr("Template Names") ); | ||
112 | lay->addWidget( m_view ); | ||
113 | |||
114 | QHBox* box = new QHBox( this ); | ||
115 | lay->addWidget( box ); | ||
116 | |||
117 | QPushButton* b = new QPushButton( box ); | ||
118 | b->setText(tr("&Add") ); | ||
119 | connect( b, SIGNAL(clicked() ), this, SLOT(slotAdd() ) ); | ||
120 | |||
121 | b = new QPushButton( box ); | ||
122 | b->setText(tr("&Edit") ); | ||
123 | connect( b, SIGNAL(clicked() ), this, SLOT(slotEdit() ) ); | ||
124 | |||
125 | b = new QPushButton( box ); | ||
126 | b->setText(tr("&Rename") ); | ||
127 | connect(b, SIGNAL(clicked() ), this, SLOT(slotRename() ) ); | ||
128 | |||
129 | b = new QPushButton( box ); | ||
130 | b->setText(tr("Re&move") ); | ||
131 | connect(b, SIGNAL(clicked() ), this, SLOT(slotRemove() ) ); | ||
132 | |||
133 | init( man ); | ||
134 | m_edit = edit; | ||
20 | } | 135 | } |
21 | TemplateDialog::~TemplateDialog() { | 136 | TemplateDialog::~TemplateDialog() { |
22 | } | 137 | } |
138 | void TemplateDialog::slotAdd() { | ||
139 | if ( m_edit->newEvent( QDate::currentDate() ) ) { | ||
140 | (void)new TemplateItem( m_view, tr("New Template"), m_edit->event() ); | ||
141 | } | ||
142 | } | ||
143 | void TemplateDialog::slotEdit() { | ||
144 | TemplateItem* item = static_cast<TemplateItem*>( m_view->currentItem() ); | ||
145 | if (!item) return; | ||
146 | |||
147 | if (m_edit->edit( item->event() ) ) | ||
148 | item->setEvent( m_edit->event() ); | ||
149 | |||
150 | } | ||
151 | void TemplateDialog::slotRemove() { | ||
152 | QListViewItem* item = m_view->currentItem(); | ||
153 | if (!item) return; | ||
154 | |||
155 | m_view->takeItem( item ); | ||
156 | delete item; | ||
157 | } | ||
158 | void TemplateDialog::slotRename() { | ||
159 | TemplateItem* item = static_cast<TemplateItem*>( m_view->currentItem() ); | ||
160 | if (!item) return; | ||
161 | |||
162 | InputDialog dlg( item->text() ); | ||
163 | dlg.setCaption( tr("Rename") ); | ||
164 | if ( dlg.exec() == QDialog::Accepted ) | ||
165 | item->setText( dlg.text() ); | ||
166 | |||
167 | } | ||
23 | TemplateManager TemplateDialog::manager()const { | 168 | TemplateManager TemplateDialog::manager()const { |
24 | return TemplateManager(); | 169 | TemplateManager manager; |
170 | |||
171 | QListViewItemIterator it(m_view); | ||
172 | while ( it.current() ) { | ||
173 | TemplateItem* item = static_cast<TemplateItem*>( it.current() ); | ||
174 | manager.add( item->text(), item->event() ); | ||
175 | ++it; | ||
176 | } | ||
177 | return manager; | ||
178 | } | ||
179 | void TemplateDialog::init( const TemplateManager& man ) { | ||
180 | QStringList list = man.names(); | ||
181 | for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) { | ||
182 | (void)new TemplateItem( m_view, (*it), man.value( (*it) ) ); | ||
183 | } | ||
25 | } | 184 | } |
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 | |||
@@ -7,18 +7,19 @@ | |||
7 | 7 | ||
8 | #include "managertemplate.h" | 8 | #include "managertemplate.h" |
9 | 9 | ||
10 | class QListView; | ||
10 | namespace Datebook { | 11 | namespace Datebook { |
11 | /** | 12 | /** |
12 | * The OEvent Template Manager | 13 | * The OEvent Template Manager |
13 | */ | 14 | */ |
15 | class Editor; | ||
14 | class TemplateManager : public ManagerTemplate<OEvent> { | 16 | class TemplateManager : public ManagerTemplate<OEvent> { |
15 | public: | 17 | public: |
16 | TemplateManager(); | 18 | TemplateManager(); |
17 | ~TemplateManager(); | 19 | ~TemplateManager(); |
18 | 20 | ||
19 | private: | 21 | bool save(); |
20 | virtual bool doSave(); | 22 | bool load(); |
21 | virtual bool doLoad(); | ||
22 | }; | 23 | }; |
23 | /** | 24 | /** |
24 | * a QDialog for editing it | 25 | * a QDialog for editing it |
@@ -26,10 +27,21 @@ namespace Datebook { | |||
26 | class TemplateDialog : public QDialog { | 27 | class TemplateDialog : public QDialog { |
27 | Q_OBJECT | 28 | Q_OBJECT |
28 | public: | 29 | public: |
29 | TemplateDialog(const TemplateManager& man); | 30 | TemplateDialog(const TemplateManager& man, Editor*); |
30 | ~TemplateDialog(); | 31 | ~TemplateDialog(); |
31 | 32 | ||
32 | virtual TemplateManager manager()const; | 33 | TemplateManager manager()const; |
34 | |||
35 | private slots: | ||
36 | void init( const TemplateManager& ); | ||
37 | void slotAdd(); | ||
38 | void slotEdit(); | ||
39 | void slotRename(); | ||
40 | void slotRemove(); | ||
41 | |||
42 | private: | ||
43 | QListView* m_view; | ||
44 | Editor* m_edit; | ||
33 | }; | 45 | }; |
34 | } | 46 | } |
35 | 47 | ||
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 | |||
@@ -19,6 +19,16 @@ namespace Datebook { | |||
19 | static bool calcWeek( const QDate& d, int &week, int &year, bool startOnMonday = false ); | 19 | static bool calcWeek( const QDate& d, int &week, int &year, bool startOnMonday = false ); |
20 | 20 | ||
21 | virtual QPixmap pixmap()const = 0; | 21 | virtual QPixmap pixmap()const = 0; |
22 | |||
23 | /** | ||
24 | * non translatable name or type | ||
25 | */ | ||
26 | virtual QCString type()const = 0; | ||
27 | |||
28 | /** | ||
29 | * shown to the user | ||
30 | */ | ||
31 | virtual QString name()const = 0; | ||
22 | virtual QString description()const = 0; | 32 | virtual QString description()const = 0; |
23 | 33 | ||
24 | /** | 34 | /** |