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