summaryrefslogtreecommitdiffabout
path: root/korganizer/koeditorgeneral.cpp
Unidiff
Diffstat (limited to 'korganizer/koeditorgeneral.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/koeditorgeneral.cpp505
1 files changed, 505 insertions, 0 deletions
diff --git a/korganizer/koeditorgeneral.cpp b/korganizer/koeditorgeneral.cpp
new file mode 100644
index 0000000..ad1389f
--- a/dev/null
+++ b/korganizer/koeditorgeneral.cpp
@@ -0,0 +1,505 @@
1/*
2 This file is part of KOrganizer.
3 Copyright (c) 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 As a special exception, permission is given to link this program
20 with any edition of Qt, and distribute the resulting executable,
21 without including the source code for Qt in the source distribution.
22*/
23
24#include <qwidget.h>
25#include <qtooltip.h>
26#include <qlayout.h>
27#include <qvbox.h>
28#include <qbuttongroup.h>
29#include <qvgroupbox.h>
30#include <qwidgetstack.h>
31#include <qdatetime.h>
32#include <qfile.h>
33
34
35#include <kglobal.h>
36#include <kdebug.h>
37#include <klocale.h>
38#include <kiconloader.h>
39#include <kmessagebox.h>
40#include <kfiledialog.h>
41#include <kstandarddirs.h>
42
43#include <libkcal/todo.h>
44#include <libkcal/event.h>
45#include <libkdepim/categoryselectdialog.h>
46#include <libkdepim/kdateedit.h>
47
48#include "koprefs.h"
49#include "koglobals.h"
50
51#include "koeditorgeneral.h"
52#include "kolocationbox.h"
53#include "koeditorgeneral.moc"
54#ifndef DESKTOP_VERSION
55#include <qpe/qpeapplication.h>
56#else
57#include <qapplication.h>
58#endif
59
60KOEditorGeneral::KOEditorGeneral(QObject* parent, const char* name) :
61 QObject( parent, name)
62{
63}
64
65KOEditorGeneral::~KOEditorGeneral()
66{
67}
68
69void KOEditorGeneral::initHeader(QWidget *parent,QBoxLayout *topLayout)
70{
71 QGridLayout *headerLayout = new QGridLayout(topLayout);
72
73#if 0
74 mOwnerLabel = new QLabel(i18n("Owner:"),parent);
75 headerLayout->addMultiCellWidget(mOwnerLabel,0,0,0,1);
76#endif
77
78 QLabel *summaryLabel = new QLabel(i18n("Summary:"),parent);
79 headerLayout->addWidget(summaryLabel,1,0);
80
81 mSummaryEdit = new KOLocationBox(TRUE,parent, 10);
82 mSummaryEdit->setSizePolicy( QSizePolicy( QSizePolicy::Preferred ,QSizePolicy::MinimumExpanding ,FALSE) );
83 //mSummaryEdit->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)5 ,(QSizePolicy::SizeType)3 ,FALSE) );
84 //qDebug("h %d %d ", summaryLabel->sizeHint().height(),mSummaryEdit->sizeHint().height() );
85 int hei = (summaryLabel->sizeHint().height() + mSummaryEdit->sizeHint().height())/2;
86 if ( QApplication::desktop()->width() > 320 )
87 mSummaryEdit->setMaximumHeight( hei +6 );
88 //qDebug("%d %d %d %d %d %d ", QSizePolicy::Fixed , QSizePolicy::Minimum , QSizePolicy:: Maximum , QSizePolicy:: Preferred , QSizePolicy:: MinimumExpanding , QSizePolicy::Expanding );
89 // SizeType { Fixed = 0, Minimum = MayGrow, Maximum = MayShrink, Preferred = MayGrow|MayShrink, MinimumExpanding = Minimum|ExpMask, Expanding = MinimumExpanding|MayShrink }
90 // mSummaryEdit = new QLineEdit(parent);
91 headerLayout->addWidget(mSummaryEdit,1,1);
92 connect ( mSummaryEdit->lineEdit(), SIGNAL ( returnPressed() ), this, SIGNAL (allAccepted () ) );
93
94 QLabel *locationLabel = new QLabel(i18n("Location:"),parent);
95 headerLayout->addWidget(locationLabel,2,0);
96
97 mLocationEdit = new KOLocationBox(TRUE,parent,10);
98 mLocationEdit->setSizePolicy( QSizePolicy( QSizePolicy::Preferred ,QSizePolicy::MinimumExpanding ,FALSE) );
99 if ( QApplication::desktop()->width() > 320 )
100 mLocationEdit->setMaximumHeight( hei + 6);
101
102 // mLocationEdit = new QLineEdit(parent);
103 connect ( mLocationEdit->lineEdit(), SIGNAL ( returnPressed() ), this, SIGNAL (allAccepted () ) );
104 headerLayout->addWidget(mLocationEdit,2,1);
105 headerLayout->setColStretch( 1, 10);
106}
107void KOEditorGeneral::setFocusOn( int i )
108{
109 qApp->processEvents();
110 if ( i == 1 ) {
111 mDescriptionEdit->setFocus();
112 mDescriptionEdit->setCursorPosition( mDescriptionEdit->numLines (), 333);
113 }
114 if ( i == 2 ) {
115 mSummaryEdit->setFocus();
116 }
117
118}
119void KOEditorGeneral::editCategories()
120{
121 // qDebug("KOEditorGeneral::editCategories() ");
122 KPIM::CategorySelectDialog* csd = new KPIM::CategorySelectDialog( KOPrefs::instance(), 0 );
123 connect(csd,SIGNAL(categoriesSelected(const QString &)), this ,SLOT(setCategories(const QString &)));
124 //KOGlobals::fitDialogToScreen( csd );
125 csd->setSelected( QStringList::split (",", mCategoriesLabel->text()) );
126 csd->exec();
127 delete csd;
128}
129void KOEditorGeneral::initCategories(QWidget *parent, QBoxLayout *topLayout)
130{
131 QBoxLayout *categoriesLayout = new QHBoxLayout( topLayout );
132
133 mCategoriesButton = new QPushButton(parent);
134 mCategoriesButton->setText(i18n("Categories..."));
135 connect(mCategoriesButton,SIGNAL(clicked()),this, SLOT(editCategories() ));
136 categoriesLayout->addWidget(mCategoriesButton);
137
138 mCategoriesLabel = new QLabel(parent);
139 mCategoriesLabel->setFrameStyle(QFrame::Panel|QFrame::Sunken);
140 categoriesLayout->addWidget(mCategoriesLabel,1);
141}
142
143void KOEditorGeneral::initSecrecy(QWidget *parent, QBoxLayout *topLayout)
144{
145 QBoxLayout *secrecyLayout = new QHBoxLayout( topLayout );
146
147 QLabel *secrecyLabel = new QLabel(i18n("Access:"),parent);
148 mCancelBox = new QCheckBox ( i18n("Cancelled"), parent);
149 secrecyLayout->addWidget(mCancelBox);
150 secrecyLayout->addWidget(secrecyLabel);
151
152 mSecrecyCombo = new QComboBox(parent);
153 mSecrecyCombo->insertStringList(Incidence::secrecyList());
154 secrecyLayout->addWidget(mSecrecyCombo);
155}
156
157void KOEditorGeneral::initDescription(QWidget *parent,QBoxLayout *topLayout)
158{
159 mDescriptionEdit = new KTextEdit(parent);
160 mDescriptionEdit->setFont(KOPrefs::instance()->mEditBoxFont );
161 mDescriptionEdit->append("");
162 mDescriptionEdit->setReadOnly(false);
163 mDescriptionEdit->setOverwriteMode(false);
164 mDescriptionEdit->setWordWrap( KTextEdit::WidgetWidth );
165 topLayout->addWidget(mDescriptionEdit);
166#ifndef DESKTOP_VERSION
167 QPEApplication::setStylusOperation( mDescriptionEdit, QPEApplication::RightOnHold );
168#endif
169
170}
171
172void KOEditorGeneral::initAlarm(QWidget *parent,QBoxLayout *topLayout)
173{
174 QBoxLayout *alarmLayout = new QHBoxLayout(topLayout);
175
176 //mAlarmBell = new QLabel(parent);
177 //mAlarmBell->setPixmap(SmallIcon("bell"));
178 //alarmLayout->addWidget(mAlarmBell);
179 if ( QApplication::desktop()->width() < 320 )
180 mAlarmButton = new QCheckBox(i18n("Rem."),parent);
181 else
182 mAlarmButton = new QCheckBox(i18n("Reminder:"),parent);
183
184 connect(mAlarmButton, SIGNAL(toggled(bool)), SLOT(enableAlarmEdit(bool)));
185 alarmLayout->addWidget(mAlarmButton);
186
187 mAlarmTimeEdit = new QSpinBox ( 0, 9999, 1, parent, "mAlarmTimeEdit " ) ;
188 alarmLayout->addWidget(mAlarmTimeEdit);
189 mAlarmIncrCombo = new QComboBox(false, parent);
190 if ( QApplication::desktop()->width() < 320 ) {
191 mAlarmIncrCombo->insertItem(i18n("min"));
192 mAlarmIncrCombo->insertItem(i18n("hou"));
193 mAlarmIncrCombo->insertItem(i18n("day"));
194 mAlarmTimeEdit->setMaximumWidth( mAlarmTimeEdit->sizeHint().width() );
195 mAlarmIncrCombo->setMaximumWidth( mAlarmIncrCombo->sizeHint().width() );
196 } else {
197 mAlarmIncrCombo->insertItem(i18n("minute(s)"));
198 mAlarmIncrCombo->insertItem(i18n("hour(s)"));
199 mAlarmIncrCombo->insertItem(i18n("day(s)"));
200 }
201
202 // mAlarmIncrCombo->setMinimumHeight(20);
203 alarmLayout->addWidget(mAlarmIncrCombo);
204 mAlarmSoundButton = new QPushButton(parent);
205 mAlarmSoundButton->setPixmap(SmallIcon("playsound"));
206 mAlarmSoundButton->setToggleButton(true);
207 QToolTip::add(mAlarmSoundButton, i18n("No sound set"));
208 connect(mAlarmSoundButton, SIGNAL(clicked()), SLOT(pickAlarmSound()));
209 alarmLayout->addWidget(mAlarmSoundButton);
210
211 mAlarmProgramButton = new QPushButton(parent);
212 mAlarmProgramButton->setPixmap(SmallIcon("run"));
213 mAlarmProgramButton->setToggleButton(true);
214 QToolTip::add(mAlarmProgramButton, i18n("No program set"));
215 connect(mAlarmProgramButton, SIGNAL(clicked()), SLOT(pickAlarmProgram()));
216 alarmLayout->addWidget(mAlarmProgramButton);
217 mAlarmSoundButton->setMaximumWidth( mAlarmSoundButton->sizeHint().width() + 4 );
218 mAlarmProgramButton->setMaximumWidth(mAlarmProgramButton->sizeHint().width() + 4 );
219 // if ( KOPrefs::instance()->mCompactDialogs ) {
220 // mAlarmSoundButton->hide();
221 // mAlarmProgramButton->hide();
222 // }
223}
224
225void KOEditorGeneral::pickAlarmSound()
226{
227
228 //QString prefix = mAlarmSound;
229 if (!mAlarmSoundButton->isOn()) {
230 //mAlarmSound = "";
231 QToolTip::remove(mAlarmSoundButton);
232 QToolTip::add(mAlarmSoundButton, i18n("No sound set"));
233 mAlarmProgramButton->setOn(true);
234 mAlarmSoundButton->setOn(false);
235 } else {
236 QString fileName(KFileDialog::getOpenFileName(mAlarmSound,
237 i18n("*.wav|Wav Files"), 0));
238 if (!fileName.isEmpty()) {
239 mAlarmSound = fileName;
240 QToolTip::remove(mAlarmSoundButton);
241 QString dispStr = i18n("Playing '%1'").arg(fileName);
242 QToolTip::add(mAlarmSoundButton, dispStr);
243 mAlarmProgramButton->setOn(false);
244 mAlarmSoundButton->setOn(true);
245 } else {
246 mAlarmProgramButton->setOn(true);
247 mAlarmSoundButton->setOn(false);
248
249 }
250 }
251
252 if (mAlarmProgramButton->isOn())
253 ((QWidget*)parent())->topLevelWidget()->setCaption(i18n("Proc.Al.: ") + mAlarmProgram );
254 if ( mAlarmSoundButton->isOn())
255 ((QWidget*)parent())->topLevelWidget()->setCaption(i18n("Audio.Al.: ") + mAlarmSound );
256}
257
258void KOEditorGeneral::pickAlarmProgram()
259{
260 if (!mAlarmProgramButton->isOn()) {
261 //mAlarmProgram = "";
262 QToolTip::remove(mAlarmProgramButton);
263 QToolTip::add(mAlarmProgramButton, i18n("No program set"));
264 mAlarmProgramButton->setOn(false);
265 mAlarmSoundButton->setOn(true);
266 } else {
267 QString fileName(KFileDialog::getOpenFileName(mAlarmProgram,i18n("Procedure Alarm.: ") , 0));
268 if (!fileName.isEmpty()) {
269 mAlarmProgram = fileName;
270 QToolTip::remove(mAlarmProgramButton);
271 QString dispStr = i18n("Running '%1'").arg(fileName);
272 QToolTip::add(mAlarmProgramButton, dispStr);
273 mAlarmSoundButton->setOn(false);
274 mAlarmProgramButton->setOn(true);
275 } else {
276 mAlarmProgramButton->setOn(false);
277 mAlarmSoundButton->setOn(true);
278 }
279 }
280 if (mAlarmProgramButton->isOn())
281 ((QWidget*)parent())->topLevelWidget()->setCaption(i18n("Proc.Al.: ") + mAlarmProgram );
282 if ( mAlarmSoundButton->isOn())
283 ((QWidget*)parent())->topLevelWidget()->setCaption(i18n("Sound.Al.: ") + mAlarmSound );
284}
285
286
287
288void KOEditorGeneral::enableAlarmEdit(bool enable)
289{
290 if ( enable ) {
291 if (!mAlarmProgramButton->isOn() && !mAlarmSoundButton->isOn()) {
292 mAlarmSoundButton->setOn( true );
293 if ( mAlarmSound.isEmpty() )
294 mAlarmSound = KOPrefs::instance()->mDefaultAlarmFile;
295 else {
296 if ( ! QFile::exists( mAlarmSound ) )
297 mAlarmSound = KOPrefs::instance()->mDefaultAlarmFile;
298 }
299 }
300 if (mAlarmProgramButton->isOn())
301 ((QWidget*)parent())->topLevelWidget()->setCaption(i18n("Proc.Al.: ") + mAlarmProgram );
302 if (!mAlarmSound.isEmpty() && mAlarmSoundButton->isOn())
303 ((QWidget*)parent())->topLevelWidget()->setCaption(i18n("Sound.Al.: ") + mAlarmSound );
304 }
305 else {
306 ((QWidget*)parent())->topLevelWidget()->setCaption(i18n("Alarm disabled"));
307
308 }
309 mAlarmTimeEdit->setEnabled(enable);
310 mAlarmSoundButton->setEnabled(enable);
311 mAlarmProgramButton->setEnabled(enable);
312 mAlarmIncrCombo->setEnabled(enable);
313}
314
315void KOEditorGeneral::disableAlarmEdit(bool disable)
316{
317 enableAlarmEdit( !disable );
318}
319
320void KOEditorGeneral::enableAlarm( bool enable )
321{
322 enableAlarmEdit( enable );
323}
324
325void KOEditorGeneral::alarmDisable(bool disable)
326{
327 if (!disable) {
328 //mAlarmBell->setEnabled(true);
329 mAlarmButton->setEnabled(true);
330 } else {
331 //mAlarmBell->setEnabled(false);
332 mAlarmButton->setEnabled(false);
333 mAlarmButton->setChecked(false);
334 mAlarmTimeEdit->setEnabled(false);
335 mAlarmSoundButton->setEnabled(false);
336 mAlarmProgramButton->setEnabled(false);
337 mAlarmIncrCombo->setEnabled(false);
338 }
339}
340
341void KOEditorGeneral::setCategories(const QString &str)
342{
343 mCategoriesLabel->setText(str);
344}
345
346void KOEditorGeneral::setDefaults(bool allDay)
347{
348#if 0
349 mOwnerLabel->setText(i18n("Owner: ") + KOPrefs::instance()->fullName());
350#endif
351
352 enableAlarmEdit( !allDay );
353
354 // TODO: Implement a KPrefsComboItem to solve this in a clean way.
355 int alarmTime;
356 int a[] = { 1,5,10,15,30,60,180, 1440 };
357 int index = KOPrefs::instance()->mAlarmTime;
358 if (index < 0 || index > 7) {
359 alarmTime = 15;
360 } else {
361 alarmTime = a[index];
362 }
363 mAlarmButton ->setChecked( false );
364 mAlarmTimeEdit->setValue(alarmTime);
365 mAlarmIncrCombo->setCurrentItem(0);
366 enableAlarmEdit( false );
367 //alarmDisable (false);
368 mSecrecyCombo->setCurrentItem(Incidence::SecrecyPublic);
369 mCancelBox->setChecked( false );
370 mSummaryEdit->setEditText("");
371 mLocationEdit->setEditText("");
372 mDescriptionEdit->setText("");
373 mAlarmSound = KOPrefs::instance()->mDefaultAlarmFile;
374 setCategories("");
375}
376void KOEditorGeneral::setSecrecy( int num )
377{
378 mSecrecyCombo->setCurrentItem(num);
379}
380void KOEditorGeneral::readIncidence(Incidence *event)
381{
382
383 mAlarmIncrCombo->setCurrentItem(0);
384 mSummaryEdit->setEditText(event->summary());
385 mLocationEdit->setEditText(event->location());
386 mDescriptionEdit->setText(event->description());
387
388#if 0
389 // organizer information
390 mOwnerLabel->setText(i18n("Owner: ") + event->organizer());
391#endif
392
393 enableAlarmEdit( event->isAlarmEnabled() );
394 //qDebug("KOEditorGeneral::readIncidence(Incidence *event) ");
395 if(!event->isAlarmEnabled()) {
396 // TODO: Implement a KPrefsComboItem to solve this in a clean way.
397 int alarmTime;
398 int a[] = { 1,5,10,15,30,60,180, 1440 };
399 int index = KOPrefs::instance()->mAlarmTime;
400 if (index < 0 || index > 7) {
401 alarmTime = 15;
402 } else {
403 alarmTime = a[index];
404 }
405 mAlarmTimeEdit->setValue(alarmTime);
406 }
407 mAlarmButton->setChecked( event->isAlarmEnabled() );
408 mSecrecyCombo->setCurrentItem(event->secrecy());
409 mCancelBox->setChecked( event->cancelled() );
410 mAlarmProgramButton->setOn(false);
411 mAlarmSoundButton->setOn(false);
412
413 // set up alarm stuff
414 QPtrList<Alarm> alarms = event->alarms();
415 Alarm* alarm;
416 mAlarmIncrCombo->setCurrentItem(0);
417 for ( alarm = alarms.first(); alarm; alarm = alarms.next() ) {
418 int offset;
419 if ( alarm->hasTime() ) {
420 QDateTime t = alarm->time();
421 offset = event->dtStart().secsTo( t );
422 } else {
423 offset = alarm->startOffset().asSeconds();
424 }
425 if ( offset != 0 ) {
426 offset = offset / -60; // make minutes
427 if (offset % 60 == 0) { // divides evenly into hours?
428 offset = offset / 60;
429 mAlarmIncrCombo->setCurrentItem(1);
430 if (offset % 24 == 0) { // divides evenly into days?
431 offset = offset / 24;
432 mAlarmIncrCombo->setCurrentItem(2);
433 }
434 }
435 }
436 mAlarmTimeEdit->setValue( offset );
437 if (alarm->type() == Alarm::Procedure) {
438
439 mAlarmProgram = alarm->programFile();
440 mAlarmProgramButton->setOn(true);
441 QString dispStr = i18n("Running '%1'").arg(mAlarmProgram);
442 QToolTip::add(mAlarmProgramButton, dispStr);
443 }
444 else if (alarm->type() == Alarm::Audio) {
445 mAlarmSound = alarm->audioFile();
446 if ( ! QFile::exists( mAlarmSound ) )
447 mAlarmSound = KOPrefs::instance()->mDefaultAlarmFile;
448 mAlarmSoundButton->setOn(true);
449 QString dispStr = i18n("Playing '%1'").arg(mAlarmSound);
450 QToolTip::add(mAlarmSoundButton, dispStr);
451 }
452 mAlarmButton->setChecked(alarm->enabled());
453 enableAlarmEdit( alarm->enabled() );
454 //qDebug("nableAlarmEdit( alarm->enabled() )********* ");
455 // TODO: Deal with multiple alarms
456 break; // For now, stop after the first alarm
457 }
458
459 setCategories(event->categoriesStr());
460}
461
462void KOEditorGeneral::writeIncidence(Incidence *event)
463{
464 // kdDebug() << "KOEditorGeneral::writeEvent()" << endl;
465 mLocationEdit->save(KOLocationBox::LOCATION);
466 event->setSummary(mSummaryEdit->currentText());
467 event->setLocation(mLocationEdit->currentText());
468 event->setDescription(mDescriptionEdit->text());
469 event->setCategories(mCategoriesLabel->text());
470 event->setSecrecy(mSecrecyCombo->currentItem());
471 event->setCancelled(mCancelBox->isChecked() );;
472 // alarm stuff
473 if (mAlarmButton->isChecked()) {
474 if (event->alarms().count() == 0)
475 event->newAlarm();
476 QPtrList<Alarm> alarms = event->alarms();
477 Alarm *alarm;
478 for (alarm = alarms.first(); alarm; alarm = alarms.next() ) {
479 alarm->setEnabled(true);
480 int j = mAlarmTimeEdit->value()* -60;
481 if (mAlarmIncrCombo->currentItem() == 1)
482 j = j * 60;
483 else if (mAlarmIncrCombo->currentItem() == 2)
484 j = j * (60 * 24);
485 alarm->setStartOffset( j );
486
487 if (!mAlarmProgram.isEmpty() && mAlarmProgramButton->isOn()) {
488 alarm->setProcedureAlarm(mAlarmProgram);
489 }
490 else if (!mAlarmSound.isEmpty() && mAlarmSoundButton->isOn())
491 alarm->setAudioAlarm(mAlarmSound);
492 else
493 alarm->setType(Alarm::Invalid);
494 //alarm->setAudioAlarm("default");
495 // TODO: Deal with multiple alarms
496 break; // For now, stop after the first alarm
497 }
498 } else {
499 Alarm* alarm = event->alarms().first();
500 if ( alarm ) {
501 alarm->setEnabled(false);
502 alarm->setType(Alarm::Invalid);
503 }
504 }
505}