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 | |||
@@ -20,3 +20,4 @@ SOURCES = main.cpp \ | |||
20 | show.cpp \ | 20 | show.cpp \ |
21 | view.cpp | 21 | view.cpp \ |
22 | editor.cpp | ||
22 | 23 | ||
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 | |||
@@ -18,9 +18,9 @@ namespace Datebook { | |||
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 | ||
@@ -32,2 +32,5 @@ namespace Datebook { | |||
32 | 32 | ||
33 | private: | ||
34 | MainWindow* m_win; | ||
35 | |||
33 | }; | 36 | }; |
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 | |||
@@ -15,2 +15,3 @@ | |||
15 | 15 | ||
16 | #include "editor.h" | ||
16 | #include "show.h" | 17 | #include "show.h" |
@@ -24,3 +25,4 @@ using namespace Datebook; | |||
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" ) ); |
@@ -31,3 +33,2 @@ MainWindow::MainWindow() | |||
31 | 33 | ||
32 | raiseCurrentView(); | ||
33 | QTimer::singleShot(0, this, SLOT(populate() ) ); | 34 | QTimer::singleShot(0, this, SLOT(populate() ) ); |
@@ -43,2 +44,8 @@ MainWindow::MainWindow() | |||
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 | } |
@@ -97,4 +104,8 @@ void MainWindow::initUI() { | |||
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"), |
@@ -132,2 +143,6 @@ void MainWindow::initUI() { | |||
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) ), |
@@ -148,4 +163,8 @@ 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 | } |
@@ -188,11 +207,17 @@ BookManager* MainWindow::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() { |
@@ -204,6 +229,25 @@ void MainWindow::slotAction( QAction* act ) { | |||
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 | } |
@@ -226 +270,36 @@ bool MainWindow::viewStartMonday()const { | |||
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 | |||
@@ -9,2 +9,3 @@ | |||
9 | #include "locationmanager.h" | 9 | #include "locationmanager.h" |
10 | #include "templatemanager.h" | ||
10 | #include "view.h" | 11 | #include "view.h" |
@@ -16,6 +17,5 @@ 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 { |
@@ -24,2 +24,3 @@ namespace Datebook { | |||
24 | friend class View; // to avoid QObject | 24 | friend class View; // to avoid QObject |
25 | friend class Editor; | ||
25 | public: | 26 | public: |
@@ -44,3 +45,6 @@ namespace Datebook { | |||
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 | ||
@@ -66,6 +70,9 @@ namespace Datebook { | |||
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 | ||
@@ -91,6 +98,7 @@ namespace Datebook { | |||
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 | }; |
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 | |||
@@ -14,3 +14,3 @@ namespace Datebook { | |||
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: |
@@ -21,6 +21,6 @@ namespace Datebook { | |||
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; |
@@ -29,7 +29,2 @@ namespace Datebook { | |||
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 | }; |
@@ -50,11 +45,3 @@ namespace Datebook { | |||
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; |
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 +1,7 @@ | |||
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> |
@@ -15,3 +21,3 @@ void StringManager::add( const QString& str ) { | |||
15 | } | 21 | } |
16 | bool StringManager::doLoad() { | 22 | bool StringManager::load() { |
17 | Config qpe( "datebook-"+m_base ); | 23 | Config qpe( "datebook-"+m_base ); |
@@ -24,4 +30,4 @@ bool StringManager::doLoad() { | |||
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); |
@@ -31,12 +37,102 @@ bool StringManager::doSave() { | |||
31 | } | 37 | } |
38 | QString StringManager::baseName()const { | ||
39 | return m_base; | ||
40 | } | ||
32 | 41 | ||
33 | 42 | ||
34 | StringManagerDialog::StringManagerDialog(const StringManager& ) | 43 | |
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 | |||
@@ -7,2 +7,3 @@ | |||
7 | 7 | ||
8 | class QListView; | ||
8 | namespace Datebook { | 9 | namespace Datebook { |
@@ -27,6 +28,7 @@ namespace Datebook { | |||
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 | }; |
@@ -43,2 +45,10 @@ namespace Datebook { | |||
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 | }; |
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 +1,14 @@ | |||
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" |
@@ -10,6 +23,23 @@ 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; |
@@ -17,4 +47,89 @@ bool TemplateManager::doLoad() { | |||
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 | } |
@@ -22,4 +137,48 @@ 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 | |||
@@ -9,2 +9,3 @@ | |||
9 | 9 | ||
10 | class QListView; | ||
10 | namespace Datebook { | 11 | namespace Datebook { |
@@ -13,2 +14,3 @@ namespace Datebook { | |||
13 | */ | 14 | */ |
15 | class Editor; | ||
14 | class TemplateManager : public ManagerTemplate<OEvent> { | 16 | class TemplateManager : public ManagerTemplate<OEvent> { |
@@ -18,5 +20,4 @@ namespace Datebook { | |||
18 | 20 | ||
19 | private: | 21 | bool save(); |
20 | virtual bool doSave(); | 22 | bool load(); |
21 | virtual bool doLoad(); | ||
22 | }; | 23 | }; |
@@ -28,6 +29,17 @@ namespace Datebook { | |||
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 | }; |
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 | |||
@@ -21,2 +21,12 @@ namespace Datebook { | |||
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; |