korganizer

koeditorgeneral.cpp

00001 /*
00002     This file is part of KOrganizer.
00003     Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
00004     Copyright (C) 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com>
00005 
00006     This program is free software; you can redistribute it and/or modify
00007     it under the terms of the GNU General Public License as published by
00008     the Free Software Foundation; either version 2 of the License, or
00009     (at your option) any later version.
00010 
00011     This program is distributed in the hope that it will be useful,
00012     but WITHOUT ANY WARRANTY; without even the implied warranty of
00013     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00014     GNU General Public License for more details.
00015 
00016     You should have received a copy of the GNU General Public License
00017     along with this program; if not, write to the Free Software
00018     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00019 
00020     As a special exception, permission is given to link this program
00021     with any edition of Qt, and distribute the resulting executable,
00022     without including the source code for Qt in the source distribution.
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 <kdebug.h>
00045 #include <klocale.h>
00046 #include <kiconloader.h>
00047 #include <kmessagebox.h>
00048 #include <kfiledialog.h>
00049 #include <ksqueezedtextlabel.h>
00050 #include <kstandarddirs.h>
00051 #include <ktextedit.h>
00052 #include <krestrictedline.h>
00053 
00054 #include <libkcal/todo.h>
00055 #include <libkcal/event.h>
00056 
00057 #include <libkdepim/kdateedit.h>
00058 #include <libkdepim/categoryselectdialog.h>
00059 
00060 #include "koprefs.h"
00061 #include "koglobals.h"
00062 
00063 #include "koeditorgeneral.h"
00064 #include "koeditoralarms.h"
00065 #include "koeditorgeneral.moc"
00066 
00067 KOEditorGeneral::KOEditorGeneral(QObject* parent, const char* name) :
00068   QObject( parent, name )
00069 {
00070   mAlarmList.setAutoDelete( true );
00071 }
00072 
00073 KOEditorGeneral::~KOEditorGeneral()
00074 {
00075 }
00076 
00077 
00078 FocusLineEdit::FocusLineEdit( QWidget *parent )
00079   : QLineEdit( parent ), mSkipFirst( true )
00080 {
00081 }
00082 
00083 void FocusLineEdit::focusInEvent ( QFocusEvent *e )
00084 {
00085   if ( !mSkipFirst ) {
00086     emit focusReceivedSignal();
00087   } else {
00088     mSkipFirst = false;
00089   }
00090   QLineEdit::focusInEvent( e );
00091 }
00092 
00093 
00094 void KOEditorGeneral::initHeader(QWidget *parent,QBoxLayout *topLayout)
00095 {
00096   QGridLayout *headerLayout = new QGridLayout(topLayout);
00097 
00098 #if 0
00099   mOwnerLabel = new QLabel(i18n("Owner:"),parent);
00100   headerLayout->addMultiCellWidget(mOwnerLabel,0,0,0,1);
00101 #endif
00102 
00103   QString whatsThis = i18n("Sets the Title of this event or to-do.");
00104   QLabel *summaryLabel = new QLabel(i18n("T&itle:"),parent);
00105   QWhatsThis::add( summaryLabel, whatsThis );
00106   QFont f = summaryLabel->font();
00107   f.setBold( true );
00108   summaryLabel->setFont(f);
00109   headerLayout->addWidget(summaryLabel,1,0);
00110 
00111   mSummaryEdit = new FocusLineEdit(parent);
00112   QWhatsThis::add( mSummaryEdit, whatsThis );
00113   connect( mSummaryEdit, SIGNAL( focusReceivedSignal() ),
00114            SIGNAL( focusReceivedSignal() ) );
00115   headerLayout->addWidget(mSummaryEdit,1,1);
00116   summaryLabel->setBuddy( mSummaryEdit );
00117 
00118   whatsThis = i18n("Sets where the event or to-do will take place.");
00119   QLabel *locationLabel = new QLabel(i18n("&Location:"),parent);
00120   QWhatsThis::add( locationLabel, whatsThis );
00121   headerLayout->addWidget(locationLabel,2,0);
00122 
00123   mLocationEdit = new QLineEdit(parent);
00124   QWhatsThis::add( mLocationEdit, whatsThis );
00125   headerLayout->addWidget(mLocationEdit,2,1);
00126   locationLabel->setBuddy( mLocationEdit );
00127 }
00128 
00129 void KOEditorGeneral::initCategories(QWidget *parent, QBoxLayout *topLayout)
00130 {
00131   QBoxLayout *categoriesLayout = new QHBoxLayout( topLayout );
00132 
00133   QString whatsThis = i18n("Allows you to select the categories that this "
00134                "event or to-do belongs to.");
00135 
00136   mCategoriesButton = new QPushButton(parent);
00137   mCategoriesButton->setText(i18n("Select Cate&gories..."));
00138   QWhatsThis::add( mCategoriesButton, whatsThis );
00139   connect(mCategoriesButton,SIGNAL(clicked()),SLOT(selectCategories()));
00140   categoriesLayout->addWidget(mCategoriesButton);
00141 
00142   mCategoriesLabel = new KSqueezedTextLabel(parent);
00143   QWhatsThis::add( mCategoriesLabel, whatsThis );
00144   mCategoriesLabel->setFrameStyle(QFrame::Panel|QFrame::Sunken);
00145   categoriesLayout->addWidget(mCategoriesLabel,1);
00146 }
00147 
00148 void KOEditorGeneral::initSecrecy(QWidget *parent, QBoxLayout *topLayout)
00149 {
00150   QBoxLayout *secrecyLayout = new QHBoxLayout( topLayout );
00151 
00152   QLabel *secrecyLabel = new QLabel(i18n("Acc&ess:"),parent);
00153   QString whatsThis = i18n("Sets whether the access to this event or to-do "
00154                "is restricted. Please note that KOrganizer "
00155                "currently does not use this setting, so the "
00156                "implementation of the restrictions will depend "
00157                "on the groupware server. This means that events "
00158                "or to-dos marked as private or confidential may "
00159                "be visible to others.");
00160   QWhatsThis::add( secrecyLabel, whatsThis );
00161   secrecyLayout->addWidget(secrecyLabel);
00162 
00163   mSecrecyCombo = new QComboBox(parent);
00164   QWhatsThis::add( mSecrecyCombo, whatsThis );
00165   mSecrecyCombo->insertStringList(Incidence::secrecyList());
00166   secrecyLayout->addWidget(mSecrecyCombo);
00167   secrecyLabel->setBuddy( mSecrecyCombo );
00168 }
00169 
00170 void KOEditorGeneral::initDescription(QWidget *parent,QBoxLayout *topLayout)
00171 {
00172   mDescriptionEdit = new KTextEdit(parent);
00173   QWhatsThis::add( mDescriptionEdit,
00174            i18n("Sets the description for this event or to-do. This "
00175             "will be displayed in a reminder if one is set, "
00176             "as well as in a tooltip when you hover over the "
00177             "event.") );
00178   mDescriptionEdit->append("");
00179   mDescriptionEdit->setReadOnly(false);
00180   mDescriptionEdit->setOverwriteMode(false);
00181   mDescriptionEdit->setWordWrap( KTextEdit::WidgetWidth );
00182   mDescriptionEdit->setTabChangesFocus( true );;
00183   topLayout->addWidget(mDescriptionEdit);
00184 }
00185 
00186 void KOEditorGeneral::initAlarm(QWidget *parent,QBoxLayout *topLayout)
00187 {
00188   QBoxLayout *alarmLayout = new QHBoxLayout(topLayout);
00189 
00190   mAlarmBell = new QLabel(parent);
00191   mAlarmBell->setPixmap(KOGlobals::self()->smallIcon("bell"));
00192   alarmLayout->addWidget( mAlarmBell );
00193 
00194 
00195   mAlarmStack = new QWidgetStack( parent );
00196   alarmLayout->addWidget( mAlarmStack );
00197 
00198   mAlarmInfoLabel = new QLabel( i18n("No reminders configured"), mAlarmStack );
00199   mAlarmStack->addWidget( mAlarmInfoLabel, AdvancedAlarmLabel );
00200 
00201   QHBox *simpleAlarmBox = new QHBox( mAlarmStack );
00202   mAlarmStack->addWidget( simpleAlarmBox, SimpleAlarmPage );
00203 
00204   mAlarmButton = new QCheckBox(i18n("&Reminder:"), simpleAlarmBox );
00205   QWhatsThis::add( mAlarmButton,
00206        i18n("Activates a reminder for this event or to-do.") );
00207 
00208   QString whatsThis = i18n("Sets how long before the event occurs "
00209                            "the reminder will be triggered.");
00210   mAlarmTimeEdit = new QSpinBox( 0, 99999, 1, simpleAlarmBox, "alarmTimeEdit" );
00211   mAlarmTimeEdit->setValue( 0 );
00212   QWhatsThis::add( mAlarmTimeEdit, whatsThis );
00213 
00214   mAlarmIncrCombo = new QComboBox( false, simpleAlarmBox );
00215   QWhatsThis::add( mAlarmIncrCombo, whatsThis );
00216   mAlarmIncrCombo->insertItem( i18n("minute(s)") );
00217   mAlarmIncrCombo->insertItem( i18n("hour(s)") );
00218   mAlarmIncrCombo->insertItem( i18n("day(s)") );
00219 //  mAlarmIncrCombo->setMinimumHeight(20);
00220   connect(mAlarmButton, SIGNAL(toggled(bool)), mAlarmTimeEdit, SLOT(setEnabled(bool)));
00221   connect(mAlarmButton, SIGNAL(toggled(bool)), mAlarmIncrCombo, SLOT(setEnabled(bool)));
00222   mAlarmTimeEdit->setEnabled( false );
00223   mAlarmIncrCombo->setEnabled( false );
00224 
00225   mAlarmEditButton = new QPushButton( i18n("Advanced"), parent );
00226   mAlarmEditButton->setEnabled( false );
00227   alarmLayout->addWidget( mAlarmEditButton );
00228   connect( mAlarmButton, SIGNAL(toggled(bool)), mAlarmEditButton, SLOT(setEnabled( bool)));
00229   connect( mAlarmEditButton, SIGNAL( clicked() ),
00230       SLOT( editAlarms() ) );
00231 
00232 }
00233 
00234 void KOEditorGeneral::selectCategories()
00235 {
00236   KPIM::CategorySelectDialog *categoryDialog = new KPIM::CategorySelectDialog( KOPrefs::instance(), mCategoriesButton    );
00237   KOGlobals::fitDialogToScreen( categoryDialog );
00238   categoryDialog->setSelected( mCategories );
00239 
00240   connect(categoryDialog, SIGNAL(editCategories()), this, SIGNAL(openCategoryDialog()));
00241 
00242   if ( categoryDialog->exec() ) {
00243     setCategories( categoryDialog->selectedCategories() );
00244   }
00245   delete categoryDialog;
00246 }
00247 
00248 
00249 void KOEditorGeneral::editAlarms()
00250 {
00251   if ( mAlarmStack->id( mAlarmStack->visibleWidget() ) == SimpleAlarmPage ) {
00252     mAlarmList.clear();
00253     Alarm *al = alarmFromSimplePage();
00254     if ( al ) {
00255       mAlarmList.append( al );
00256     }
00257   }
00258 
00259   KOEditorAlarms *dlg = new KOEditorAlarms( &mAlarmList, mAlarmEditButton );
00260   if ( dlg->exec() != KDialogBase::Cancel ) {
00261     updateAlarmWidgets();
00262   }
00263 }
00264 
00265 
00266 void KOEditorGeneral::enableAlarm( bool enable )
00267 {
00268   mAlarmStack->setEnabled( enable );
00269   mAlarmEditButton->setEnabled( enable );
00270 }
00271 
00272 void KOEditorGeneral::setCategories( const QStringList &categories )
00273 {
00274   mCategoriesLabel->setText( categories.join(",") );
00275   mCategories = categories;
00276 }
00277 
00278 void KOEditorGeneral::setDefaults(bool /*allDay*/)
00279 {
00280 #if 0
00281   mOwnerLabel->setText(i18n("Owner: ") + KOPrefs::instance()->fullName());
00282 #endif
00283 
00284   mAlarmList.clear();
00285   updateDefaultAlarmTime();
00286   updateAlarmWidgets();
00287 
00288   mSecrecyCombo->setCurrentItem(Incidence::SecrecyPublic);
00289 }
00290 
00291 void KOEditorGeneral::updateDefaultAlarmTime()
00292 {
00293   // FIXME: Implement a KPrefsComboItem to solve this in a clean way.
00294 // FIXME: Use an int value for minutes instead of 5 hardcoded values
00295   int alarmTime;
00296   int a[] = { 1,5,10,15,30 };
00297   int index = KOPrefs::instance()->mAlarmTime;
00298   if (index < 0 || index > 4) {
00299     alarmTime = 0;
00300   } else {
00301     alarmTime = a[index];
00302   }
00303   mAlarmTimeEdit->setValue(alarmTime);
00304 }
00305 
00306 void KOEditorGeneral::updateAlarmWidgets()
00307 {
00308   if ( mAlarmList.isEmpty() ) {
00309     mAlarmStack->raiseWidget( SimpleAlarmPage );
00310     mAlarmButton->setChecked( false );
00311     mAlarmEditButton->setEnabled( false );
00312   } else if ( mAlarmList.count() > 1 ) {
00313     mAlarmStack->raiseWidget( AdvancedAlarmLabel );
00314     mAlarmInfoLabel->setText( i18n("1 advanced reminder configured",
00315                                    "%n advanced reminders configured",
00316                                    mAlarmList.count() ) );
00317     mAlarmEditButton->setEnabled( true );
00318   } else {
00319     Alarm *alarm = mAlarmList.first();
00320     // Check if its the trivial type of alarm, which can be
00321     // configured with a simply spin box...
00322 
00323     if ( alarm->type() == Alarm::Display && alarm->text().isEmpty()
00324          && alarm->repeatCount() == 0 && !alarm->hasTime()
00325          && alarm->hasStartOffset() && alarm->startOffset().asSeconds() < 0 )  {
00326       mAlarmStack->raiseWidget( SimpleAlarmPage );
00327       mAlarmButton->setChecked( true );
00328       int offset = alarm->startOffset().asSeconds();
00329 
00330       offset = offset / -60; // make minutes
00331       int useoffset = offset;
00332       if (offset % (24*60) == 0) { // divides evenly into days?
00333         useoffset = offset / (24*60);
00334         mAlarmIncrCombo->setCurrentItem(2);
00335       } else if (offset % 60 == 0) { // divides evenly into hours?
00336         useoffset = offset / 60;
00337         mAlarmIncrCombo->setCurrentItem(1);
00338       }
00339       mAlarmTimeEdit->setValue( useoffset );
00340     } else {
00341       mAlarmStack->raiseWidget( AdvancedAlarmLabel );
00342       mAlarmInfoLabel->setText( i18n("1 advanced reminder configured") );
00343       mAlarmEditButton->setEnabled( true );
00344     }
00345   }
00346 }
00347 
00348 void KOEditorGeneral::readIncidence(Incidence *event)
00349 {
00350   mSummaryEdit->setText(event->summary());
00351   mLocationEdit->setText(event->location());
00352 
00353   mDescriptionEdit->setText(event->description());
00354 
00355 #if 0
00356   // organizer information
00357   mOwnerLabel->setText(i18n("Owner: ") + event->organizer().fullName() );
00358 #endif
00359 
00360   mSecrecyCombo->setCurrentItem(event->secrecy());
00361 
00362   // set up alarm stuff
00363   mAlarmList.clear();
00364   Alarm::List::ConstIterator it;
00365   Alarm::List alarms = event->alarms();
00366   for( it = alarms.begin(); it != alarms.end(); ++it ) {
00367     Alarm *al = new Alarm( *(*it) );
00368     al->setParent( 0 );
00369     mAlarmList.append( al );
00370   }
00371   updateDefaultAlarmTime();
00372   updateAlarmWidgets();
00373 
00374   setCategories(event->categories());
00375 }
00376 
00377 Alarm *KOEditorGeneral::alarmFromSimplePage() const
00378 {
00379   if ( mAlarmButton->isChecked() ) {
00380     Alarm *alarm = new Alarm( 0 );
00381     alarm->setDisplayAlarm("");
00382     alarm->setEnabled(true);
00383     QString tmpStr = mAlarmTimeEdit->text();
00384     int j = mAlarmTimeEdit->value() * -60;
00385     if (mAlarmIncrCombo->currentItem() == 1)
00386       j = j * 60;
00387     else if (mAlarmIncrCombo->currentItem() == 2)
00388       j = j * (60 * 24);
00389     alarm->setStartOffset( j );
00390     return alarm;
00391   } else {
00392     return 0;
00393   }
00394 }
00395 void KOEditorGeneral::writeIncidence(Incidence *event)
00396 {
00397 //  kdDebug(5850) << "KOEditorGeneral::writeEvent()" << endl;
00398 
00399   event->setSummary(mSummaryEdit->text());
00400   event->setLocation(mLocationEdit->text());
00401   event->setDescription(mDescriptionEdit->text());
00402   event->setCategories(mCategories);
00403   event->setSecrecy(mSecrecyCombo->currentItem());
00404 
00405   // alarm stuff
00406   event->clearAlarms();
00407   if ( mAlarmStack->id( mAlarmStack->visibleWidget() ) == SimpleAlarmPage ) {
00408     Alarm *al = alarmFromSimplePage();
00409     if ( al ) {
00410       al->setParent( event );
00411       event->addAlarm( al );
00412     }
00413   } else {
00414     // simply assign the list of alarms
00415     Alarm::List::ConstIterator it;
00416     for( it = mAlarmList.begin(); it != mAlarmList.end(); ++it ) {
00417       Alarm *al = new Alarm( *(*it) );
00418       al->setParent( event );
00419       al->setEnabled( true );
00420       event->addAlarm( al );
00421     }
00422   }
00423 }
00424 
00425 void KOEditorGeneral::setSummary( const QString &text )
00426 {
00427   mSummaryEdit->setText( text );
00428 }
00429 
00430 void KOEditorGeneral::setDescription( const QString &text )
00431 {
00432   mDescriptionEdit->setText( text );
00433 }
00434 
00435 QObject *KOEditorGeneral::typeAheadReceiver() const
00436 {
00437   return mSummaryEdit;
00438 }
KDE Home | KDE Accessibility Home | Description of Access Keys