Diffstat (limited to 'korganizer/koeventviewerdialog.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | korganizer/koeventviewerdialog.cpp | 240 |
1 files changed, 240 insertions, 0 deletions
diff --git a/korganizer/koeventviewerdialog.cpp b/korganizer/koeventviewerdialog.cpp new file mode 100644 index 0000000..64ab94d --- a/dev/null +++ b/korganizer/koeventviewerdialog.cpp | |||
@@ -0,0 +1,240 @@ | |||
1 | /* | ||
2 | This file is part of KOrganizer. | ||
3 | Copyright (c) 2000,2001 Cornelius Schumacher <schumacher@kde.org> | ||
4 | |||
5 | This program is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published by | ||
7 | the Free Software Foundation; either version 2 of the License, or | ||
8 | (at your option) any later version. | ||
9 | |||
10 | This program is distributed in the hope that it will be useful, | ||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | GNU General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with this program; if not, write to the Free Software | ||
17 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | ||
18 | */ | ||
19 | |||
20 | #include <klocale.h> | ||
21 | |||
22 | #include <libkcal/event.h> | ||
23 | #include <qpushbutton.h> | ||
24 | |||
25 | #include "koeventviewer.h" | ||
26 | #include "koprefs.h" | ||
27 | #include <libkcal/todo.h> | ||
28 | #include "qapp.h" | ||
29 | |||
30 | #include "koeventviewerdialog.h" | ||
31 | #include "koeventviewerdialog.moc" | ||
32 | extern int globalFlagBlockAgenda; | ||
33 | |||
34 | KOEventViewerDialog::KOEventViewerDialog(QWidget *parent,const char *name) | ||
35 | : KDialogBase(parent,name, | ||
36 | #ifndef DESKTOP_VERSION | ||
37 | true , | ||
38 | #else | ||
39 | false, | ||
40 | #endif | ||
41 | i18n("Event Viewer"),Ok|User1|Close,Close, false, i18n("Agenda")) | ||
42 | { | ||
43 | |||
44 | mEventViewer = new KOEventViewer(this); | ||
45 | mEventViewer->setFont( KOPrefs::instance()->mEventViewFont ); | ||
46 | setMainWidget(mEventViewer); | ||
47 | setButtonText(Ok, i18n("Edit") ); | ||
48 | |||
49 | QObject::connect(findButton( Ok ),SIGNAL(clicked()), | ||
50 | SLOT(editIncidence())); | ||
51 | QObject::connect(this,SIGNAL(user1Clicked()), | ||
52 | SLOT(showIncidence())); | ||
53 | mIncidence = 0; | ||
54 | // TODO: Set a sensible size (based on the content?). | ||
55 | //showMaximized(); | ||
56 | //qDebug("++++++++++++KOEventViewerDialog() "); | ||
57 | // if ( KOPrefs::instance()->mCompactDialogs ) { | ||
58 | // setFixedSize( 240,284 ); | ||
59 | // move( 0, 15 ); | ||
60 | // } else { | ||
61 | // setMinimumSize(300,200); | ||
62 | // resize(320,300); | ||
63 | // } | ||
64 | mSyncMode = false; | ||
65 | mSyncResult = 0; | ||
66 | |||
67 | } | ||
68 | |||
69 | KOEventViewerDialog::~KOEventViewerDialog() | ||
70 | { | ||
71 | //qDebug("-------~KOEventViewerDialog() "); | ||
72 | } | ||
73 | void KOEventViewerDialog::showMe() | ||
74 | { | ||
75 | |||
76 | #ifdef DESKTOP_VERSION | ||
77 | show(); | ||
78 | #else | ||
79 | showMaximized(); | ||
80 | #endif | ||
81 | setFocus(); | ||
82 | setActiveWindow(); | ||
83 | |||
84 | } | ||
85 | void KOEventViewerDialog::setSyncMode( bool b ) | ||
86 | { | ||
87 | mSyncMode = b; | ||
88 | //qDebug("KOEventViewerDialog::setSyncMode %d ",mSyncMode ); | ||
89 | if ( mSyncMode ) { | ||
90 | findButton( Close )->setText( i18n("Cancel Sync")); | ||
91 | findButton( Ok )->setText( i18n("Remote")); | ||
92 | findButton( User1 )->setText( i18n("Local")); | ||
93 | } else { | ||
94 | findButton( Close )->setText( i18n("Close")); | ||
95 | findButton( Ok )->setText( i18n("Edit")); | ||
96 | findButton( User1 )->setText( i18n("Agenda")); | ||
97 | } | ||
98 | mEventViewer->setSyncMode( b ); | ||
99 | } | ||
100 | void KOEventViewerDialog::setColorMode( int m ) | ||
101 | { | ||
102 | mEventViewer->setColorMode( m ); | ||
103 | } | ||
104 | int KOEventViewerDialog::executeS( bool local ) | ||
105 | { | ||
106 | mSyncResult = 3; | ||
107 | if ( local ) | ||
108 | findButton( User1 )->setFocus(); | ||
109 | else | ||
110 | findButton( Ok )->setFocus(); | ||
111 | exec(); | ||
112 | return mSyncResult; | ||
113 | } | ||
114 | |||
115 | void KOEventViewerDialog::updateConfig() | ||
116 | { | ||
117 | mEventViewer->setFont( KOPrefs::instance()->mEventViewFont ); | ||
118 | |||
119 | } | ||
120 | void KOEventViewerDialog::setEvent(Event *event) | ||
121 | { | ||
122 | mEventViewer->setEvent(event); | ||
123 | mIncidence = event; | ||
124 | findButton( Close )->setFocus(); | ||
125 | } | ||
126 | void KOEventViewerDialog::setIncidence(Incidence *in ) | ||
127 | { | ||
128 | if ( in->type() == "Event" ) | ||
129 | setEvent( (Event*) in ); | ||
130 | else if ( in->type() =="Todo" ) | ||
131 | setTodo( (Todo*) in ); | ||
132 | else if ( in->type() =="Journal" ) | ||
133 | setJournal( (Journal*) in ); | ||
134 | } | ||
135 | void KOEventViewerDialog::addIncidence(Incidence *in) | ||
136 | { | ||
137 | if ( in->type() == "Event" ) | ||
138 | addEvent( (Event*) in ); | ||
139 | else if ( in->type() =="Todo" ) | ||
140 | mEventViewer->setTodo( (Todo*) in, false ); | ||
141 | else if ( in->type() =="Journal" ) | ||
142 | mEventViewer->setJournal( (Journal*) in, false ); | ||
143 | if ( mSyncMode ) { | ||
144 | findButton( User1 )->setFocus(); | ||
145 | setCaption(i18n("Conflict! Please choose entry")); | ||
146 | } | ||
147 | } | ||
148 | |||
149 | void KOEventViewerDialog::addEvent(Event *event) | ||
150 | { | ||
151 | mEventViewer->addEvent(event); | ||
152 | mIncidence = event; | ||
153 | findButton( Close )->setFocus(); | ||
154 | } | ||
155 | |||
156 | void KOEventViewerDialog::setTodo(Todo *event) | ||
157 | { | ||
158 | mEventViewer->setTodo(event); | ||
159 | mIncidence = (Incidence*)event; | ||
160 | findButton( Close )->setFocus(); | ||
161 | } | ||
162 | void KOEventViewerDialog::setJournal(Journal *j) | ||
163 | { | ||
164 | mEventViewer->setJournal(j); | ||
165 | mIncidence = (Incidence*)j; | ||
166 | findButton( Close )->setFocus(); | ||
167 | } | ||
168 | |||
169 | void KOEventViewerDialog::addText(QString text) | ||
170 | { | ||
171 | mEventViewer->addText(text); | ||
172 | findButton( Close )->setFocus(); | ||
173 | } | ||
174 | void KOEventViewerDialog::editIncidence() | ||
175 | { | ||
176 | if ( mSyncMode ) { | ||
177 | mSyncResult = 2; | ||
178 | accept(); | ||
179 | return; | ||
180 | } | ||
181 | if ( mIncidence ){ | ||
182 | #ifndef DESKTOP_VERSION | ||
183 | hide(); | ||
184 | #endif | ||
185 | emit editIncidence( mIncidence ); | ||
186 | } | ||
187 | } | ||
188 | void KOEventViewerDialog::showIncidence() | ||
189 | { | ||
190 | |||
191 | if ( mSyncMode ) { | ||
192 | mSyncResult = 1; | ||
193 | accept(); | ||
194 | return; | ||
195 | } | ||
196 | |||
197 | if ( mIncidence ){ | ||
198 | #ifndef DESKTOP_VERSION | ||
199 | hide(); | ||
200 | #endif | ||
201 | QDate date; | ||
202 | if ( mIncidence->type() == "Todo" ) { | ||
203 | if ( ((Todo*)mIncidence)->hasDueDate() ) | ||
204 | date = ((Todo*)mIncidence)->dtDue().date(); | ||
205 | else { | ||
206 | globalFlagBlockAgenda = 2; | ||
207 | emit showAgendaView( false ); | ||
208 | return; | ||
209 | } | ||
210 | } else | ||
211 | date = mIncidence->dtStart().date(); | ||
212 | globalFlagBlockAgenda = 1; | ||
213 | emit showAgendaView( false ); | ||
214 | globalFlagBlockAgenda = 2; | ||
215 | emit jumpToTime( date ); | ||
216 | } | ||
217 | } | ||
218 | void KOEventViewerDialog::keyPressEvent ( QKeyEvent * e ) | ||
219 | { | ||
220 | switch ( e->key() ) { | ||
221 | |||
222 | case Qt::Key_A : | ||
223 | case Qt::Key_L : | ||
224 | showIncidence(); | ||
225 | break; | ||
226 | case Qt::Key_E : | ||
227 | case Qt::Key_R : | ||
228 | editIncidence(); | ||
229 | break; | ||
230 | case Qt::Key_C: | ||
231 | close(); | ||
232 | break; | ||
233 | case Qt::Key_I: | ||
234 | accept(); | ||
235 | break; | ||
236 | default: | ||
237 | break; | ||
238 | } | ||
239 | |||
240 | } | ||