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   if ( categoryDialog->exec() ) {
00240     setCategories( categoryDialog->selectedCategories() );
00241   }
00242   delete categoryDialog;
00243 }
00244 
00245 
00246 void KOEditorGeneral::editAlarms()
00247 {
00248   if ( mAlarmStack->id( mAlarmStack->visibleWidget() ) == SimpleAlarmPage ) {
00249     mAlarmList.clear();
00250     Alarm *al = alarmFromSimplePage();
00251     if ( al ) {
00252       mAlarmList.append( al );
00253     }
00254   }
00255 
00256   KOEditorAlarms *dlg = new KOEditorAlarms( &mAlarmList, mAlarmEditButton );
00257   if ( dlg->exec() != KDialogBase::Cancel ) {
00258     updateAlarmWidgets();
00259   }
00260 }
00261 
00262 
00263 void KOEditorGeneral::enableAlarm( bool enable )
00264 {
00265   mAlarmStack->setEnabled( enable );
00266   mAlarmEditButton->setEnabled( enable );
00267 }
00268 
00269 void KOEditorGeneral::setCategories( const QStringList &categories )
00270 {
00271   mCategoriesLabel->setText( categories.join(",") );
00272   mCategories = categories;
00273 }
00274 
00275 void KOEditorGeneral::setDefaults(bool /*allDay*/)
00276 {
00277 #if 0
00278   mOwnerLabel->setText(i18n("Owner: ") + KOPrefs::instance()->fullName());
00279 #endif
00280 
00281   mAlarmList.clear();
00282   updateDefaultAlarmTime();
00283   updateAlarmWidgets();
00284 
00285   mSecrecyCombo->setCurrentItem(Incidence::SecrecyPublic);
00286 }
00287 
00288 void KOEditorGeneral::updateDefaultAlarmTime()
00289 {
00290   // FIXME: Implement a KPrefsComboItem to solve this in a clean way.
00291 // FIXME: Use an int value for minutes instead of 5 hardcoded values
00292   int alarmTime;
00293   int a[] = { 1,5,10,15,30 };
00294   int index = KOPrefs::instance()->mAlarmTime;
00295   if (index < 0 || index > 4) {
00296     alarmTime = 0;
00297   } else {
00298     alarmTime = a[index];
00299   }
00300   mAlarmTimeEdit->setValue(alarmTime);
00301 }
00302 
00303 void KOEditorGeneral::updateAlarmWidgets()
00304 {
00305   if ( mAlarmList.isEmpty() ) {
00306     mAlarmStack->raiseWidget( SimpleAlarmPage );
00307     mAlarmButton->setChecked( false );
00308     mAlarmEditButton->setEnabled( false );
00309   } else if ( mAlarmList.count() > 1 ) {
00310     mAlarmStack->raiseWidget( AdvancedAlarmLabel );
00311     mAlarmInfoLabel->setText( i18n("1 advanced reminder configured",
00312                                    "%n advanced reminders configured",
00313                                    mAlarmList.count() ) );
00314     mAlarmEditButton->setEnabled( true );
00315   } else {
00316     Alarm *alarm = mAlarmList.first();
00317     // Check if its the trivial type of alarm, which can be
00318     // configured with a simply spin box...
00319 
00320     if ( alarm->type() == Alarm::Display && alarm->text().isEmpty()
00321          && alarm->repeatCount() == 0 && !alarm->hasTime()
00322          && alarm->hasStartOffset() && alarm->startOffset().asSeconds() < 0 )  {
00323       mAlarmStack->raiseWidget( SimpleAlarmPage );
00324       mAlarmButton->setChecked( true );
00325       int offset = alarm->startOffset().asSeconds();
00326 
00327       offset = offset / -60; // make minutes
00328       int useoffset = offset;
00329       if (offset % (24*60) == 0) { // divides evenly into days?
00330         useoffset = offset / (24*60);
00331         mAlarmIncrCombo->setCurrentItem(2);
00332       } else if (offset % 60 == 0) { // divides evenly into hours?
00333         useoffset = offset / 60;
00334         mAlarmIncrCombo->setCurrentItem(1);
00335       }
00336       mAlarmTimeEdit->setValue( useoffset );
00337     } else {
00338       mAlarmStack->raiseWidget( AdvancedAlarmLabel );
00339       mAlarmInfoLabel->setText( i18n("1 advanced reminder configured") );
00340       mAlarmEditButton->setEnabled( true );
00341     }
00342   }
00343 }
00344 
00345 void KOEditorGeneral::readIncidence(Incidence *event)
00346 {
00347   mSummaryEdit->setText(event->summary());
00348   mLocationEdit->setText(event->location());
00349 
00350   mDescriptionEdit->setText(event->description());
00351 
00352 #if 0
00353   // organizer information
00354   mOwnerLabel->setText(i18n("Owner: ") + event->organizer().fullName() );
00355 #endif
00356 
00357   mSecrecyCombo->setCurrentItem(event->secrecy());
00358 
00359   // set up alarm stuff
00360   mAlarmList.clear();
00361   Alarm::List::ConstIterator it;
00362   Alarm::List alarms = event->alarms();
00363   for( it = alarms.begin(); it != alarms.end(); ++it ) {
00364     Alarm *al = new Alarm( *(*it) );
00365     al->setParent( 0 );
00366     mAlarmList.append( al );
00367   }
00368   updateDefaultAlarmTime();
00369   updateAlarmWidgets();
00370 
00371   setCategories(event->categories());
00372 }
00373 
00374 Alarm *KOEditorGeneral::alarmFromSimplePage() const
00375 {
00376   if ( mAlarmButton->isChecked() ) {
00377     Alarm *alarm = new Alarm( 0 );
00378     alarm->setDisplayAlarm("");
00379     alarm->setEnabled(true);
00380     QString tmpStr = mAlarmTimeEdit->text();
00381     int j = mAlarmTimeEdit->value() * -60;
00382     if (mAlarmIncrCombo->currentItem() == 1)
00383       j = j * 60;
00384     else if (mAlarmIncrCombo->currentItem() == 2)
00385       j = j * (60 * 24);
00386     alarm->setStartOffset( j );
00387     return alarm;
00388   } else {
00389     return 0;
00390   }
00391 }
00392 void KOEditorGeneral::writeIncidence(Incidence *event)
00393 {
00394 //  kdDebug(5850) << "KOEditorGeneral::writeEvent()" << endl;
00395 
00396   event->setSummary(mSummaryEdit->text());
00397   event->setLocation(mLocationEdit->text());
00398   event->setDescription(mDescriptionEdit->text());
00399   event->setCategories(mCategories);
00400   event->setSecrecy(mSecrecyCombo->currentItem());
00401 
00402   // alarm stuff
00403   event->clearAlarms();
00404   if ( mAlarmStack->id( mAlarmStack->visibleWidget() ) == SimpleAlarmPage ) {
00405     Alarm *al = alarmFromSimplePage();
00406     if ( al ) {
00407       al->setParent( event );
00408       event->addAlarm( al );
00409     }
00410   } else {
00411     // simply assign the list of alarms
00412     Alarm::List::ConstIterator it;
00413     for( it = mAlarmList.begin(); it != mAlarmList.end(); ++it ) {
00414       Alarm *al = new Alarm( *(*it) );
00415       al->setParent( event );
00416       al->setEnabled( true );
00417       event->addAlarm( al );
00418     }
00419   }
00420 }
00421 
00422 void KOEditorGeneral::setSummary( const QString &text )
00423 {
00424   mSummaryEdit->setText( text );
00425 }
00426 
00427 void KOEditorGeneral::setDescription( const QString &text )
00428 {
00429   mDescriptionEdit->setText( text );
00430 }
00431 
00432 QObject *KOEditorGeneral::typeAheadReceiver() const
00433 {
00434   return mSummaryEdit;
00435 }
KDE Home | KDE Accessibility Home | Description of Access Keys