27 #include <tqtooltip.h>
31 #include <tqbuttongroup.h>
32 #include <tqvgroupbox.h>
33 #include <tqdatetime.h>
34 #include <tqlineedit.h>
36 #include <tqcheckbox.h>
37 #include <tqpushbutton.h>
38 #include <tqcombobox.h>
39 #include <tqspinbox.h>
40 #include <tqwhatsthis.h>
42 #include <tdeglobal.h>
45 #include <tdelocale.h>
46 #include <kiconloader.h>
47 #include <tdemessagebox.h>
48 #include <tdefiledialog.h>
49 #include <ksqueezedtextlabel.h>
50 #include <kstandarddirs.h>
51 #include <ktextedit.h>
52 #include <krestrictedline.h>
54 #include <libkcal/todo.h>
55 #include <libkcal/event.h>
56 #include <libkcal/incidenceformatter.h>
57 #include <libkcal/resourcecached.h>
59 #include <libtdepim/kdateedit.h>
60 #include <libtdepim/categoryselectdialog.h>
63 #include "koglobals.h"
65 #include "koeditorgeneral.h"
66 #include "koeditoralarms.h"
67 #include "koeditorattachments.h"
68 #include "koeditorgeneral.moc"
71 KOEditorGeneral::KOEditorGeneral( TQObject *parent,
const char* name) :
72 TQObject( parent, name ), mAttachments(0)
75 ResourceCached::setEditorWindowOpen(
true);
76 mAlarmList.setAutoDelete(
true );
79 KOEditorGeneral::~KOEditorGeneral()
81 ResourceCached::setEditorWindowOpen(
false);
85 FocusLineEdit::FocusLineEdit( TQWidget *parent )
86 : TQLineEdit( parent ), mSkipFirst( true )
90 void FocusLineEdit::focusInEvent ( TQFocusEvent *e )
93 emit focusReceivedSignal();
97 TQLineEdit::focusInEvent( e );
101 void KOEditorGeneral::initHeader( TQWidget *parent,TQBoxLayout *topLayout)
103 TQGridLayout *headerLayout =
new TQGridLayout();
104 headerLayout->setSpacing( topLayout->spacing() );
105 topLayout->addLayout( headerLayout );
107 TQString whatsThis = i18n(
"Sets the Title of this event or to-do.");
108 TQLabel *summaryLabel =
new TQLabel( i18n(
"T&itle:"), parent );
109 TQWhatsThis::add( summaryLabel, whatsThis );
110 TQFont f = summaryLabel->font();
112 summaryLabel->setFont(f);
113 headerLayout->addWidget(summaryLabel,1,0);
115 mSummaryEdit =
new FocusLineEdit( parent );
116 TQWhatsThis::add( mSummaryEdit, whatsThis );
117 connect( mSummaryEdit, TQ_SIGNAL( focusReceivedSignal() ),
118 TQ_SIGNAL( focusReceivedSignal() ) );
119 headerLayout->addWidget(mSummaryEdit,1,1);
120 summaryLabel->setBuddy( mSummaryEdit );
122 mAttendeeSummaryLabel =
new TQLabel( parent );
123 updateAttendeeSummary( 0 );
124 headerLayout->addWidget( mAttendeeSummaryLabel, 1, 2 );
126 whatsThis = i18n(
"Sets where the event or to-do will take place.");
127 TQLabel *locationLabel =
new TQLabel( i18n(
"&Location:"), parent );
128 TQWhatsThis::add( locationLabel, whatsThis );
129 headerLayout->addWidget(locationLabel,2,0);
131 mLocationEdit =
new TQLineEdit( parent );
132 TQWhatsThis::add( mLocationEdit, whatsThis );
133 headerLayout->addMultiCellWidget( mLocationEdit, 2, 2, 1, 2 );
134 locationLabel->setBuddy( mLocationEdit );
136 TQBoxLayout *thirdLineLayout =
new TQHBoxLayout();
137 headerLayout->addMultiCellLayout( thirdLineLayout, 3, 3, 0, 2 );
139 mResourceLabel =
new TQLabel( parent );
140 mResourceLabel->hide();
141 thirdLineLayout->addWidget( mResourceLabel );
143 whatsThis = i18n(
"Allows you to select the categories that this event or to-do belongs to.");
144 TQLabel *categoriesLabel =
new TQLabel( i18n(
"Categories:"), parent );
145 TQWhatsThis::add( categoriesLabel, whatsThis );
146 thirdLineLayout->addWidget( categoriesLabel );
147 mCategoriesLabel =
new KSqueezedTextLabel( parent );
148 TQWhatsThis::add( mCategoriesLabel, whatsThis );
149 mCategoriesLabel->setFrameStyle(TQFrame::Panel|TQFrame::Sunken);
150 thirdLineLayout->addWidget( mCategoriesLabel );
152 mCategoriesButton =
new TQPushButton( parent );
153 mCategoriesButton->setText(i18n(
"Select..."));
154 TQWhatsThis::add( mCategoriesButton, whatsThis );
155 connect(mCategoriesButton,TQ_SIGNAL(clicked()),TQ_SLOT(selectCategories()));
156 thirdLineLayout->addWidget( mCategoriesButton );
159 void KOEditorGeneral::initSecrecy(TQWidget *parent, TQBoxLayout *topLayout)
161 TQBoxLayout *secrecyLayout =
new TQHBoxLayout( topLayout );
163 TQLabel *secrecyLabel =
new TQLabel(i18n(
"Acc&ess:"),parent);
164 TQString whatsThis = i18n(
"Sets whether the access to this event or to-do "
165 "is restricted. Please note that KOrganizer "
166 "currently does not use this setting, so the "
167 "implementation of the restrictions will depend "
168 "on the groupware server. This means that events "
169 "or to-dos marked as private or confidential may "
170 "be visible to others.");
171 TQWhatsThis::add( secrecyLabel, whatsThis );
172 secrecyLayout->addWidget(secrecyLabel);
174 mSecrecyCombo =
new TQComboBox(parent);
175 TQWhatsThis::add( mSecrecyCombo, whatsThis );
176 mSecrecyCombo->insertStringList(Incidence::secrecyList());
177 secrecyLayout->addWidget(mSecrecyCombo);
178 secrecyLabel->setBuddy( mSecrecyCombo );
181 void KOEditorGeneral::initDescription(TQWidget *parent,TQBoxLayout *topLayout)
183 mDescriptionEdit =
new KTextEdit(parent);
184 TQWhatsThis::add( mDescriptionEdit,
185 i18n(
"Sets the description for this event or to-do. This "
186 "will be displayed in a reminder if one is set, "
187 "as well as in a tooltip when you hover over the "
189 mDescriptionEdit->append(
"");
190 mDescriptionEdit->setReadOnly(
false);
191 mDescriptionEdit->setOverwriteMode(
false);
192 mDescriptionEdit->setWordWrap( KTextEdit::WidgetWidth );
193 mDescriptionEdit->setTabChangesFocus(
true );;
194 topLayout->addWidget(mDescriptionEdit, 4);
197 void KOEditorGeneral::initAlarm( TQWidget *parent, TQBoxLayout *topLayout )
199 TQBoxLayout *alarmLayout =
new TQHBoxLayout( topLayout );
201 mAlarmButton =
new TQCheckBox( parent );
202 TQWhatsThis::add( mAlarmButton, i18n(
"Enable reminders for this event or to-do." ) );
203 TQToolTip::add( mAlarmButton, i18n(
"Enable reminders" ) );
204 alarmLayout->addWidget( mAlarmButton );
206 mAlarmAdvancedButton =
new TQPushButton( parent );
207 mAlarmAdvancedButton->setIconSet( KOGlobals::self()->smallIconSet(
"bell", 16 ) );
208 TQWhatsThis::add( mAlarmAdvancedButton,
209 i18n(
"Push this button to create an advanced set of reminders "
210 "for this event or to-do." ) );
211 TQToolTip::add( mAlarmAdvancedButton, i18n(
"Set an advanced reminder" ) );
212 connect( mAlarmAdvancedButton, TQ_SIGNAL(clicked()), TQ_SLOT(editAlarms()) );
213 alarmLayout->addWidget( mAlarmAdvancedButton );
215 mSimpleAlarmBox =
new TQHBox( parent );
216 alarmLayout->addWidget( mSimpleAlarmBox );
218 TQString whatsThis, toolTip;
219 if ( mType ==
"Event" ) {
220 whatsThis = i18n(
"Set the time before the event starts when the reminder will be triggered." );
221 toolTip = i18n(
"Set the start time trigger offset" );
223 whatsThis = i18n(
"Set the time before the to-do is due when the reminder will be triggered." );
224 toolTip = i18n(
"Set the due time trigger offset" );
226 mAlarmTimeEdit =
new TQSpinBox( 0, 99999, 1, mSimpleAlarmBox,
"alarmTimeEdit" );
227 mAlarmTimeEdit->setValue( 0 );
228 TQWhatsThis::add( mAlarmTimeEdit, whatsThis );
229 TQToolTip::add( mAlarmTimeEdit, toolTip );
231 mAlarmIncrCombo =
new TQComboBox(
false, mSimpleAlarmBox );
232 mAlarmIncrCombo->insertItem( i18n(
"minute(s)") );
233 mAlarmIncrCombo->insertItem( i18n(
"hour(s)") );
234 mAlarmIncrCombo->insertItem( i18n(
"day(s)") );
235 TQWhatsThis::add( mAlarmIncrCombo, whatsThis );
236 TQToolTip::add( mAlarmIncrCombo, toolTip );
238 mAlarmInfoLabel =
new TQLabel( parent );
239 if ( mType ==
"Event" ) {
240 mAlarmInfoLabel->setText( i18n(
"before the start" ) );
242 mAlarmInfoLabel->setText( i18n(
"before the due time" ) );
244 alarmLayout->addWidget( mAlarmInfoLabel );
246 mAlarmAdvancedButton->setEnabled(
false );
247 mAlarmTimeEdit->setEnabled(
false );
248 mAlarmIncrCombo->setEnabled(
false );
249 mAlarmInfoLabel->setEnabled(
false );
250 connect( mAlarmButton, TQ_SIGNAL(toggled(
bool)), mAlarmAdvancedButton, TQ_SLOT(setEnabled(
bool)) );
251 connect( mAlarmButton, TQ_SIGNAL(toggled(
bool)), mAlarmTimeEdit, TQ_SLOT(setEnabled(
bool)) );
252 connect( mAlarmButton, TQ_SIGNAL(toggled(
bool)), mAlarmIncrCombo, TQ_SLOT(setEnabled(
bool)) );
253 connect( mAlarmButton, TQ_SIGNAL(toggled(
bool)), mAlarmInfoLabel, TQ_SLOT(setEnabled(
bool)) );
256 void KOEditorGeneral::initAttachments(TQWidget *parent,TQBoxLayout *topLayout)
258 mAttachments =
new KOEditorAttachments( KDialog::spacingHint(), parent );
259 connect( mAttachments, TQ_SIGNAL( openURL(
const KURL & ) ) ,
260 this, TQ_SIGNAL( openURL(
const KURL & ) ) );
261 topLayout->addWidget( mAttachments, 1 );
264 void KOEditorGeneral::setType(
const TQCString &type )
270 void KOEditorGeneral::addAttachments(
const TQStringList &attachments,
271 const TQStringList &mimeTypes,
272 bool inlineAttachments )
274 TQStringList::ConstIterator it;
276 for ( it = attachments.begin(); it != attachments.end(); ++it, ++i ) {
277 if ( !(*it).isEmpty() ) {
279 if ( mimeTypes.count() > i ) {
280 mimeType = mimeTypes[ i ];
282 mAttachments->addUriAttachment( *it, mimeType, TQString(), inlineAttachments );
287 void KOEditorGeneral::selectCategories()
289 KPIM::CategorySelectDialog *categoryDialog =
new KPIM::CategorySelectDialog( KOPrefs::instance(), mCategoriesButton );
290 KOGlobals::fitDialogToScreen( categoryDialog );
291 categoryDialog->setSelected( mCategories );
293 connect(categoryDialog, TQ_SIGNAL(editCategories()),
this, TQ_SIGNAL(openCategoryDialog()));
294 connect(
this, TQ_SIGNAL(updateCategoryConfig()), categoryDialog, TQ_SLOT(updateCategoryConfig()));
296 if ( categoryDialog->exec() ) {
297 setCategories( categoryDialog->selectedCategories() );
299 delete categoryDialog;
303 void KOEditorGeneral::editAlarms()
305 if ( mAlarmIsSimple ) {
307 Alarm *al = alarmFromSimplePage( 0 );
309 mAlarmList.append( al );
313 KOEditorAlarms *dlg =
new KOEditorAlarms( mType, &mAlarmList, mAlarmAdvancedButton );
314 if ( dlg->exec() != KDialogBase::Cancel ) {
315 if ( mType ==
"Event" ) {
317 Alarm::List::ConstIterator it;
318 for( it = mAlarmList.begin(); it != mAlarmList.end(); ++it ) {
323 updateAlarmWidgets( e );
327 Alarm::List::ConstIterator it;
328 for( it = mAlarmList.begin(); it != mAlarmList.end(); ++it ) {
333 updateAlarmWidgets( t );
339 void KOEditorGeneral::enableAlarm(
bool enable )
341 mAlarmAdvancedButton->setEnabled( enable );
344 void KOEditorGeneral::toggleAlarm(
bool on )
346 mAlarmButton->setChecked( on );
349 void KOEditorGeneral::setCategories(
const TQStringList &categories )
351 mCategoriesLabel->setText( categories.join(
",") );
352 mCategories = categories;
355 void KOEditorGeneral::setDefaults(
bool )
358 updateDefaultAlarmTime();
359 updateAlarmWidgets( 0 );
361 mSecrecyCombo->setCurrentItem( Incidence::SecrecyPublic );
362 mAttachments->setDefaults();
365 void KOEditorGeneral::updateDefaultAlarmTime()
367 int reminderTime = KOPrefs::instance()->mReminderTime;
368 int index = KOPrefs::instance()->mReminderTimeUnits;
369 if ( index < 0 || index > 2 ) {
372 mAlarmTimeEdit->setValue( reminderTime );
373 mAlarmIncrCombo->setCurrentItem( index );
376 bool KOEditorGeneral::isSimpleAlarm(
Alarm *alarm )
const
382 if ( alarm->
type() == Alarm::Display && alarm->
text().isEmpty() &&
384 if ( mType ==
"Event" &&
388 if ( mType ==
"Todo" &&
396 static TQString etc = i18n(
"elipsis",
"..." );
397 void KOEditorGeneral::updateAlarmWidgets(
Incidence *incidence )
405 if ( mAlarmList.isEmpty() ) {
406 mAlarmIsSimple =
true;
407 mSimpleAlarmBox->show();
409 if ( mType ==
"Event" ) {
410 on = KOPrefs::instance()->defaultEventReminders();
411 }
else if ( mType ==
"Todo" ) {
412 on = KOPrefs::instance()->defaultTodoReminders();
416 mAlarmButton->setChecked( on );
417 mAlarmAdvancedButton->setEnabled( on );
418 }
else if ( mAlarmList.count() > 1 ) {
419 mAlarmIsSimple =
false;
420 mAlarmAdvancedButton->setEnabled(
true );
421 mSimpleAlarmBox->hide();
423 TQString remStr = IncidenceFormatter::reminderStringList( incidence ).join(
", " );
424 if ( remStr.length() > maxLen ) {
425 maxLen -= etc.length();
426 remStr = remStr.left( maxLen );
429 mAlarmInfoLabel->setText( i18n(
"Triggers %1" ).arg( remStr ) );
432 Alarm *alarm = mAlarmList.first();
433 if ( isSimpleAlarm( alarm ) ) {
434 mAlarmIsSimple =
true;
435 mSimpleAlarmBox->show();
437 if ( mType ==
"Event" ) {
439 mAlarmInfoLabel->setText( i18n(
"before the start" ) );
441 if ( mType ==
"Todo" ) {
444 mAlarmInfoLabel->setText( i18n(
"before the start" ) );
447 mAlarmInfoLabel->setText( i18n(
"before the due time" ) );
450 offset = offset / -60;
451 int useoffset = offset;
453 mAlarmIncrCombo->setCurrentItem( 0 );
454 }
else if (offset % (24*60) == 0) {
455 useoffset = offset / (24*60);
456 mAlarmIncrCombo->setCurrentItem(2);
457 }
else if (offset % 60 == 0) {
458 useoffset = offset / 60;
459 mAlarmIncrCombo->setCurrentItem(1);
461 mAlarmTimeEdit->setValue( useoffset );
463 mAlarmIsSimple =
false;
464 mAlarmAdvancedButton->setEnabled(
true );
465 mSimpleAlarmBox->hide();
467 TQString remStr = IncidenceFormatter::reminderStringList( incidence ).first();
468 mAlarmInfoLabel->setText( i18n(
"Triggers %1" ).arg( remStr ) );
476 mSummaryEdit->setText( incidence->
summary() );
477 mLocationEdit->setText( incidence->
location() );
478 mDescriptionEdit->setText( incidence->
description() );
480 mSecrecyCombo->setCurrentItem( incidence->
secrecy() );
484 Alarm::List::ConstIterator it;
485 Alarm::List alarms = incidence->
alarms();
486 for( it = alarms.begin(); it != alarms.end(); ++it ) {
489 mAlarmList.append( al );
491 updateDefaultAlarmTime();
492 updateAlarmWidgets( incidence );
496 mAttachments->readIncidence( incidence );
498 TQString resLabel = IncidenceFormatter::resourceString( calendar, incidence );
499 if ( !resLabel.isEmpty() ) {
500 mResourceLabel->setText( i18n(
"Calendar: %1" ).arg( resLabel ) );
501 mResourceLabel->show();
505 Alarm *KOEditorGeneral::alarmFromSimplePage(
Incidence *incidence )
const
507 if ( mAlarmButton->isChecked() ) {
511 TQString tmpStr = mAlarmTimeEdit->text();
512 int j = mAlarmTimeEdit->value() * -60;
513 if ( mAlarmIncrCombo->currentItem() == 1 ) {
515 }
else if ( mAlarmIncrCombo->currentItem() == 2 ) {
518 if ( mType ==
"Event" ) {
521 if ( mType ==
"Todo" ) {
522 Todo *todo =
static_cast<Todo *
>( incidence );
534 void KOEditorGeneral::writeIncidence(
Incidence *incidence )
540 incidence->
setSecrecy(mSecrecyCombo->currentItem());
544 if ( mAlarmIsSimple ) {
545 Alarm *al = alarmFromSimplePage( incidence );
553 Alarm::List::ConstIterator it;
554 for( it = mAlarmList.begin(); it != mAlarmList.end(); ++it ) {
561 mAttachments->writeIncidence( incidence );
564 void KOEditorGeneral::setSummary(
const TQString &text )
566 mSummaryEdit->setText( text );
569 void KOEditorGeneral::setDescription(
const TQString &text )
571 mDescriptionEdit->setText( text );
574 TQObject *KOEditorGeneral::typeAheadReceiver()
const
579 void KOEditorGeneral::updateAttendeeSummary(
int count)
582 mAttendeeSummaryLabel->setText( i18n(
"No attendees") );
584 mAttendeeSummaryLabel->setText( i18n(
"One attendee",
"%n attendees", count ) );
bool hasStartOffset() const
void setEnabled(bool enable)
Duration endOffset() const
bool hasEndOffset() const
void setDisplayAlarm(const TQString &text=TQString())
Duration startOffset() const
void setEndOffset(const Duration &)
void setStartOffset(const Duration &)
void setParent(Incidence *)
void setLocation(const TQString &location)
const Alarm::List & alarms() const
void setSummary(const TQString &summary)
TQString description() const
TQStringList categories() const
void setDescription(const TQString &description)
bool isAlarmEnabled() const
void setCategories(const TQStringList &categories)
TQString location() const
bool hasStartDate() const