Diffstat (limited to 'core/pim/datebook2/mainwindow.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | core/pim/datebook2/mainwindow.cpp | 97 |
1 files changed, 88 insertions, 9 deletions
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 | } | ||