Diffstat (limited to 'core/pim/datebook2/templatemanager.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | core/pim/datebook2/templatemanager.cpp | 167 |
1 files changed, 163 insertions, 4 deletions
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 @@ | |||
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; |
4 | 17 | ||
5 | 18 | ||
6 | TemplateManager::TemplateManager() { | 19 | TemplateManager::TemplateManager() { |
7 | 20 | ||
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 | } |