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