00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include <qwidget.h>
00027 #include <qtooltip.h>
00028 #include <qlayout.h>
00029 #include <qvbox.h>
00030 #include <qhbox.h>
00031 #include <qbuttongroup.h>
00032 #include <qvgroupbox.h>
00033 #include <qwidgetstack.h>
00034 #include <qdatetime.h>
00035 #include <qlineedit.h>
00036 #include <qlabel.h>
00037 #include <qcheckbox.h>
00038 #include <qpushbutton.h>
00039 #include <qcombobox.h>
00040 #include <qspinbox.h>
00041 #include <qwhatsthis.h>
00042
00043 #include <kglobal.h>
00044 #include <kdialog.h>
00045 #include <kdebug.h>
00046 #include <klocale.h>
00047 #include <kiconloader.h>
00048 #include <kmessagebox.h>
00049 #include <kfiledialog.h>
00050 #include <ksqueezedtextlabel.h>
00051 #include <kstandarddirs.h>
00052 #include <ktextedit.h>
00053 #include <krestrictedline.h>
00054
00055 #include <libkcal/todo.h>
00056 #include <libkcal/event.h>
00057
00058 #include <libkdepim/kdateedit.h>
00059 #include <libkdepim/categoryselectdialog.h>
00060
00061 #include "koprefs.h"
00062 #include "koglobals.h"
00063
00064 #include "koeditorgeneral.h"
00065 #include "koeditoralarms.h"
00066 #include "koeditorattachments.h"
00067 #include "koeditorgeneral.moc"
00068 #include "kohelper.h"
00069
00070 KOEditorGeneral::KOEditorGeneral(QObject* parent, const char* name) :
00071 QObject( parent, name ), mAttachments(0)
00072 {
00073 mAlarmList.setAutoDelete( true );
00074 }
00075
00076 KOEditorGeneral::~KOEditorGeneral()
00077 {
00078 }
00079
00080
00081 FocusLineEdit::FocusLineEdit( QWidget *parent )
00082 : QLineEdit( parent ), mSkipFirst( true )
00083 {
00084 }
00085
00086 void FocusLineEdit::focusInEvent ( QFocusEvent *e )
00087 {
00088 if ( !mSkipFirst ) {
00089 emit focusReceivedSignal();
00090 } else {
00091 mSkipFirst = false;
00092 }
00093 QLineEdit::focusInEvent( e );
00094 }
00095
00096
00097 void KOEditorGeneral::initHeader( QWidget *parent,QBoxLayout *topLayout)
00098 {
00099 QGridLayout *headerLayout = new QGridLayout();
00100 headerLayout->setSpacing( topLayout->spacing() );
00101 topLayout->addLayout( headerLayout );
00102
00103 #if 0
00104 mOwnerLabel = new QLabel(i18n("Owner:"),parent);
00105 headerLayout->addMultiCellWidget(mOwnerLabel,0,0,0,1);
00106 #endif
00107
00108 QString whatsThis = i18n("Sets the Title of this event or to-do.");
00109 QLabel *summaryLabel = new QLabel( i18n("T&itle:"), parent );
00110 QWhatsThis::add( summaryLabel, whatsThis );
00111 QFont f = summaryLabel->font();
00112 f.setBold( true );
00113 summaryLabel->setFont(f);
00114 headerLayout->addWidget(summaryLabel,1,0);
00115
00116 mSummaryEdit = new FocusLineEdit( parent );
00117 QWhatsThis::add( mSummaryEdit, whatsThis );
00118 connect( mSummaryEdit, SIGNAL( focusReceivedSignal() ),
00119 SIGNAL( focusReceivedSignal() ) );
00120 headerLayout->addWidget(mSummaryEdit,1,1);
00121 summaryLabel->setBuddy( mSummaryEdit );
00122
00123 mAttendeeSummaryLabel = new QLabel( parent );
00124 updateAttendeeSummary( 0 );
00125 headerLayout->addWidget( mAttendeeSummaryLabel, 1, 2 );
00126
00127 whatsThis = i18n("Sets where the event or to-do will take place.");
00128 QLabel *locationLabel = new QLabel( i18n("&Location:"), parent );
00129 QWhatsThis::add( locationLabel, whatsThis );
00130 headerLayout->addWidget(locationLabel,2,0);
00131
00132 mLocationEdit = new QLineEdit( parent );
00133 QWhatsThis::add( mLocationEdit, whatsThis );
00134 headerLayout->addMultiCellWidget( mLocationEdit, 2, 2, 1, 2 );
00135 locationLabel->setBuddy( mLocationEdit );
00136
00137 QBoxLayout *thirdLineLayout = new QHBoxLayout();
00138 headerLayout->addMultiCellLayout( thirdLineLayout, 3, 3, 0, 2 );
00139
00140 mResourceLabel = new QLabel( parent );
00141 mResourceLabel->hide();
00142 thirdLineLayout->addWidget( mResourceLabel );
00143
00144 whatsThis = i18n("Allows you to select the categories that this event or to-do belongs to.");
00145 QLabel *categoriesLabel = new QLabel( i18n("Categories:"), parent );
00146 QWhatsThis::add( categoriesLabel, whatsThis );
00147 thirdLineLayout->addWidget( categoriesLabel );
00148 mCategoriesLabel = new KSqueezedTextLabel( parent );
00149 QWhatsThis::add( mCategoriesLabel, whatsThis );
00150 mCategoriesLabel->setFrameStyle(QFrame::Panel|QFrame::Sunken);
00151 thirdLineLayout->addWidget( mCategoriesLabel );
00152
00153 mCategoriesButton = new QPushButton( parent );
00154 mCategoriesButton->setText(i18n("&Select..."));
00155 QWhatsThis::add( mCategoriesButton, whatsThis );
00156 connect(mCategoriesButton,SIGNAL(clicked()),SLOT(selectCategories()));
00157 thirdLineLayout->addWidget( mCategoriesButton );
00158 }
00159
00160 void KOEditorGeneral::initSecrecy(QWidget *parent, QBoxLayout *topLayout)
00161 {
00162 QBoxLayout *secrecyLayout = new QHBoxLayout( topLayout );
00163
00164 QLabel *secrecyLabel = new QLabel(i18n("Acc&ess:"),parent);
00165 QString whatsThis = i18n("Sets whether the access to this event or to-do "
00166 "is restricted. Please note that KOrganizer "
00167 "currently does not use this setting, so the "
00168 "implementation of the restrictions will depend "
00169 "on the groupware server. This means that events "
00170 "or to-dos marked as private or confidential may "
00171 "be visible to others.");
00172 QWhatsThis::add( secrecyLabel, whatsThis );
00173 secrecyLayout->addWidget(secrecyLabel);
00174
00175 mSecrecyCombo = new QComboBox(parent);
00176 QWhatsThis::add( mSecrecyCombo, whatsThis );
00177 mSecrecyCombo->insertStringList(Incidence::secrecyList());
00178 secrecyLayout->addWidget(mSecrecyCombo);
00179 secrecyLabel->setBuddy( mSecrecyCombo );
00180 }
00181
00182 void KOEditorGeneral::initDescription(QWidget *parent,QBoxLayout *topLayout)
00183 {
00184 mDescriptionEdit = new KTextEdit(parent);
00185 QWhatsThis::add( mDescriptionEdit,
00186 i18n("Sets the description for this event or to-do. This "
00187 "will be displayed in a reminder if one is set, "
00188 "as well as in a tooltip when you hover over the "
00189 "event.") );
00190 mDescriptionEdit->append("");
00191 mDescriptionEdit->setReadOnly(false);
00192 mDescriptionEdit->setOverwriteMode(false);
00193 mDescriptionEdit->setWordWrap( KTextEdit::WidgetWidth );
00194 mDescriptionEdit->setTabChangesFocus( true );;
00195 topLayout->addWidget(mDescriptionEdit, 4);
00196 }
00197
00198 void KOEditorGeneral::initAlarm(QWidget *parent,QBoxLayout *topLayout)
00199 {
00200 QBoxLayout *alarmLayout = new QHBoxLayout(topLayout);
00201
00202 mAlarmBell = new QLabel(parent);
00203 mAlarmBell->setPixmap(KOGlobals::self()->smallIcon("bell"));
00204 alarmLayout->addWidget( mAlarmBell );
00205
00206
00207 mAlarmStack = new QWidgetStack( parent );
00208 alarmLayout->addWidget( mAlarmStack );
00209
00210 mAlarmInfoLabel = new QLabel( i18n("No reminders configured"), mAlarmStack );
00211 mAlarmStack->addWidget( mAlarmInfoLabel, AdvancedAlarmLabel );
00212
00213 QHBox *simpleAlarmBox = new QHBox( mAlarmStack );
00214 mAlarmStack->addWidget( simpleAlarmBox, SimpleAlarmPage );
00215
00216 mAlarmButton = new QCheckBox(i18n("&Reminder:"), simpleAlarmBox );
00217 QWhatsThis::add( mAlarmButton,
00218 i18n("Activates a reminder for this event or to-do.") );
00219
00220 QString whatsThis = i18n("Sets how long before the event occurs "
00221 "the reminder will be triggered.");
00222 mAlarmTimeEdit = new QSpinBox( 0, 99999, 1, simpleAlarmBox, "alarmTimeEdit" );
00223 mAlarmTimeEdit->setValue( 0 );
00224 QWhatsThis::add( mAlarmTimeEdit, whatsThis );
00225
00226 mAlarmIncrCombo = new QComboBox( false, simpleAlarmBox );
00227 QWhatsThis::add( mAlarmIncrCombo, whatsThis );
00228 mAlarmIncrCombo->insertItem( i18n("minute(s)") );
00229 mAlarmIncrCombo->insertItem( i18n("hour(s)") );
00230 mAlarmIncrCombo->insertItem( i18n("day(s)") );
00231
00232 connect(mAlarmButton, SIGNAL(toggled(bool)), mAlarmTimeEdit, SLOT(setEnabled(bool)));
00233 connect(mAlarmButton, SIGNAL(toggled(bool)), mAlarmIncrCombo, SLOT(setEnabled(bool)));
00234 mAlarmTimeEdit->setEnabled( false );
00235 mAlarmIncrCombo->setEnabled( false );
00236
00237 mAlarmEditButton = new QPushButton( i18n("Advanced"), parent );
00238 mAlarmEditButton->setEnabled( false );
00239 alarmLayout->addWidget( mAlarmEditButton );
00240 connect( mAlarmButton, SIGNAL(toggled(bool)), mAlarmEditButton, SLOT(setEnabled( bool)));
00241 connect( mAlarmEditButton, SIGNAL( clicked() ),
00242 SLOT( editAlarms() ) );
00243
00244 }
00245
00246 void KOEditorGeneral::initAttachments(QWidget *parent,QBoxLayout *topLayout)
00247 {
00248 mAttachments = new KOEditorAttachments( KDialog::spacingHint(), parent );
00249 connect( mAttachments, SIGNAL( openURL( const KURL & ) ) ,
00250 this, SIGNAL( openURL( const KURL & ) ) );
00251 topLayout->addWidget( mAttachments, 1 );
00252 }
00253
00254 void KOEditorGeneral::addAttachments( const QStringList &attachments,
00255 const QStringList &mimeTypes,
00256 bool inlineAttachments )
00257 {
00258 QStringList::ConstIterator it;
00259 uint i = 0;
00260 for ( it = attachments.begin(); it != attachments.end(); ++it, ++i ) {
00261 QString mimeType;
00262 if ( mimeTypes.count() > i )
00263 mimeType = mimeTypes[ i ];
00264 mAttachments->addAttachment( *it, mimeType, !inlineAttachments );
00265 }
00266 }
00267
00268 void KOEditorGeneral::selectCategories()
00269 {
00270 KPIM::CategorySelectDialog *categoryDialog = new KPIM::CategorySelectDialog( KOPrefs::instance(), mCategoriesButton );
00271 KOGlobals::fitDialogToScreen( categoryDialog );
00272 categoryDialog->setSelected( mCategories );
00273
00274 connect(categoryDialog, SIGNAL(editCategories()), this, SIGNAL(openCategoryDialog()));
00275 connect(this, SIGNAL(updateCategoryConfig()), categoryDialog, SLOT(updateCategoryConfig()));
00276
00277 if ( categoryDialog->exec() ) {
00278 setCategories( categoryDialog->selectedCategories() );
00279 }
00280 delete categoryDialog;
00281 }
00282
00283
00284 void KOEditorGeneral::editAlarms()
00285 {
00286 if ( mAlarmStack->id( mAlarmStack->visibleWidget() ) == SimpleAlarmPage ) {
00287 mAlarmList.clear();
00288 Alarm *al = alarmFromSimplePage();
00289 if ( al ) {
00290 mAlarmList.append( al );
00291 }
00292 }
00293
00294 KOEditorAlarms *dlg = new KOEditorAlarms( &mAlarmList, mAlarmEditButton );
00295 if ( dlg->exec() != KDialogBase::Cancel ) {
00296 updateAlarmWidgets();
00297 }
00298 }
00299
00300
00301 void KOEditorGeneral::enableAlarm( bool enable )
00302 {
00303 mAlarmStack->setEnabled( enable );
00304 mAlarmEditButton->setEnabled( enable );
00305 }
00306
00307 void KOEditorGeneral::setCategories( const QStringList &categories )
00308 {
00309 mCategoriesLabel->setText( categories.join(",") );
00310 mCategories = categories;
00311 }
00312
00313 void KOEditorGeneral::setDefaults(bool )
00314 {
00315 #if 0
00316 mOwnerLabel->setText(i18n("Owner: ") + KOPrefs::instance()->fullName());
00317 #endif
00318
00319 mAlarmList.clear();
00320 updateDefaultAlarmTime();
00321 updateAlarmWidgets();
00322
00323 mSecrecyCombo->setCurrentItem(Incidence::SecrecyPublic);
00324 mAttachments->setDefaults();
00325 }
00326
00327 void KOEditorGeneral::updateDefaultAlarmTime()
00328 {
00329
00330
00331 int alarmTime;
00332 int a[] = { 1,5,10,15,30 };
00333 int index = KOPrefs::instance()->mAlarmTime;
00334 if (index < 0 || index > 4) {
00335 alarmTime = 0;
00336 } else {
00337 alarmTime = a[index];
00338 }
00339 mAlarmTimeEdit->setValue(alarmTime);
00340 }
00341
00342 void KOEditorGeneral::updateAlarmWidgets()
00343 {
00344 if ( mAlarmList.isEmpty() ) {
00345 mAlarmStack->raiseWidget( SimpleAlarmPage );
00346 mAlarmButton->setChecked( false );
00347 mAlarmEditButton->setEnabled( false );
00348 } else if ( mAlarmList.count() > 1 ) {
00349 mAlarmStack->raiseWidget( AdvancedAlarmLabel );
00350 mAlarmInfoLabel->setText( i18n("1 advanced reminder configured",
00351 "%n advanced reminders configured",
00352 mAlarmList.count() ) );
00353 mAlarmEditButton->setEnabled( true );
00354 } else {
00355 Alarm *alarm = mAlarmList.first();
00356
00357
00358
00359 if ( alarm->type() == Alarm::Display && alarm->text().isEmpty()
00360 && alarm->repeatCount() == 0 && !alarm->hasTime()
00361 && alarm->hasStartOffset() && alarm->startOffset().asSeconds() < 0 ) {
00362 mAlarmStack->raiseWidget( SimpleAlarmPage );
00363 mAlarmButton->setChecked( true );
00364 int offset = alarm->startOffset().asSeconds();
00365
00366 offset = offset / -60;
00367 int useoffset = offset;
00368 if (offset % (24*60) == 0) {
00369 useoffset = offset / (24*60);
00370 mAlarmIncrCombo->setCurrentItem(2);
00371 } else if (offset % 60 == 0) {
00372 useoffset = offset / 60;
00373 mAlarmIncrCombo->setCurrentItem(1);
00374 }
00375 mAlarmTimeEdit->setValue( useoffset );
00376 } else {
00377 mAlarmStack->raiseWidget( AdvancedAlarmLabel );
00378 mAlarmInfoLabel->setText( i18n("1 advanced reminder configured") );
00379 mAlarmEditButton->setEnabled( true );
00380 }
00381 }
00382 }
00383
00384 void KOEditorGeneral::readIncidence(Incidence *event, Calendar *calendar)
00385 {
00386 mSummaryEdit->setText(event->summary());
00387 mLocationEdit->setText(event->location());
00388
00389 mDescriptionEdit->setText(event->description());
00390
00391 #if 0
00392
00393 mOwnerLabel->setText(i18n("Owner: ") + event->organizer().fullName() );
00394 #endif
00395
00396 mSecrecyCombo->setCurrentItem(event->secrecy());
00397
00398
00399 mAlarmList.clear();
00400 Alarm::List::ConstIterator it;
00401 Alarm::List alarms = event->alarms();
00402 for( it = alarms.begin(); it != alarms.end(); ++it ) {
00403 Alarm *al = new Alarm( *(*it) );
00404 al->setParent( 0 );
00405 mAlarmList.append( al );
00406 }
00407 updateDefaultAlarmTime();
00408 updateAlarmWidgets();
00409
00410 setCategories(event->categories());
00411
00412 mAttachments->readIncidence( event );
00413
00414 QString resLabel = KOHelper::resourceLabel( calendar, event );
00415 if ( !resLabel.isEmpty() ) {
00416 mResourceLabel->setText( i18n( "Calendar: %1" ).arg( resLabel ) );
00417 mResourceLabel->show();
00418 }
00419 }
00420
00421 Alarm *KOEditorGeneral::alarmFromSimplePage() const
00422 {
00423 if ( mAlarmButton->isChecked() ) {
00424 Alarm *alarm = new Alarm( 0 );
00425 alarm->setDisplayAlarm("");
00426 alarm->setEnabled(true);
00427 QString tmpStr = mAlarmTimeEdit->text();
00428 int j = mAlarmTimeEdit->value() * -60;
00429 if (mAlarmIncrCombo->currentItem() == 1)
00430 j = j * 60;
00431 else if (mAlarmIncrCombo->currentItem() == 2)
00432 j = j * (60 * 24);
00433 alarm->setStartOffset( j );
00434 return alarm;
00435 } else {
00436 return 0;
00437 }
00438 }
00439 void KOEditorGeneral::writeIncidence(Incidence *event)
00440 {
00441
00442
00443 event->setSummary(mSummaryEdit->text());
00444 event->setLocation(mLocationEdit->text());
00445 event->setDescription(mDescriptionEdit->text());
00446 event->setCategories(mCategories);
00447 event->setSecrecy(mSecrecyCombo->currentItem());
00448
00449
00450 event->clearAlarms();
00451 if ( mAlarmStack->id( mAlarmStack->visibleWidget() ) == SimpleAlarmPage ) {
00452 Alarm *al = alarmFromSimplePage();
00453 if ( al ) {
00454 al->setParent( event );
00455 event->addAlarm( al );
00456 }
00457 } else {
00458
00459 Alarm::List::ConstIterator it;
00460 for( it = mAlarmList.begin(); it != mAlarmList.end(); ++it ) {
00461 Alarm *al = new Alarm( *(*it) );
00462 al->setParent( event );
00463 al->setEnabled( true );
00464 event->addAlarm( al );
00465 }
00466 }
00467 mAttachments->writeIncidence( event );
00468 }
00469
00470 void KOEditorGeneral::setSummary( const QString &text )
00471 {
00472 mSummaryEdit->setText( text );
00473 }
00474
00475 void KOEditorGeneral::setDescription( const QString &text )
00476 {
00477 mDescriptionEdit->setText( text );
00478 }
00479
00480 QObject *KOEditorGeneral::typeAheadReceiver() const
00481 {
00482 return mSummaryEdit;
00483 }
00484
00485 void KOEditorGeneral::updateAttendeeSummary(int count)
00486 {
00487 if ( count <= 0 )
00488 mAttendeeSummaryLabel->setText( "No attendees" );
00489 else
00490 mAttendeeSummaryLabel->setText( i18n( "One attendee", "%n attendees", count ) );
00491 }