korganizer Library API Documentation

koeditorgeneral.cpp

00001 /*
00002     This file is part of KOrganizer.
00003     Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
00004 
00005     This program is free software; you can redistribute it and/or modify
00006     it under the terms of the GNU General Public License as published by
00007     the Free Software Foundation; either version 2 of the License, or
00008     (at your option) any later version.
00009 
00010     This program is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00013     GNU General Public License for more details.
00014 
00015     You should have received a copy of the GNU General Public License
00016     along with this program; if not, write to the Free Software
00017     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00018 
00019     As a special exception, permission is given to link this program
00020     with any edition of Qt, and distribute the resulting executable,
00021     without including the source code for Qt in the source distribution.
00022 */
00023 
00024 
00025 #include <qwidget.h>
00026 #include <qtooltip.h>
00027 #include <qlayout.h>
00028 #include <qvbox.h>
00029 #include <qbuttongroup.h>
00030 #include <qvgroupbox.h>
00031 #include <qwidgetstack.h>
00032 #include <qdatetime.h>
00033 #include <qlineedit.h>
00034 #include <qlabel.h>
00035 #include <qcheckbox.h>
00036 #include <qpushbutton.h>
00037 #include <qcombobox.h>
00038 
00039 #include <kglobal.h>
00040 #include <kdebug.h>
00041 #include <klocale.h>
00042 #include <kiconloader.h>
00043 #include <kmessagebox.h>
00044 #include <kfiledialog.h>
00045 #include <ksqueezedtextlabel.h>
00046 #include <kstandarddirs.h>
00047 #include <ktextedit.h>
00048 #include <krestrictedline.h>
00049 
00050 #include <libkcal/todo.h>
00051 #include <libkcal/event.h>
00052 
00053 #include <libkdepim/kdateedit.h>
00054 
00055 #include "koprefs.h"
00056 #include "koglobals.h"
00057 
00058 #include "koeditorgeneral.h"
00059 #include "koeditorgeneral.moc"
00060 
00061 KOEditorGeneral::KOEditorGeneral(QObject* parent, const char* name) :
00062   QObject( parent, name)
00063 {
00064 }
00065 
00066 KOEditorGeneral::~KOEditorGeneral()
00067 {
00068 }
00069 
00070 
00071 FocusLineEdit::FocusLineEdit( QWidget *parent )
00072   : QLineEdit( parent ), mSkipFirst( true )
00073 {
00074 }
00075 
00076 void FocusLineEdit::focusInEvent ( QFocusEvent *e )
00077 {
00078   if ( !mSkipFirst ) {
00079     emit focusReceivedSignal();
00080   } else {
00081     mSkipFirst = false;
00082   }
00083   QLineEdit::focusInEvent( e );
00084 }
00085 
00086 
00087 void KOEditorGeneral::initHeader(QWidget *parent,QBoxLayout *topLayout)
00088 {
00089   QGridLayout *headerLayout = new QGridLayout(topLayout);
00090 
00091 #if 0
00092   mOwnerLabel = new QLabel(i18n("Owner:"),parent);
00093   headerLayout->addMultiCellWidget(mOwnerLabel,0,0,0,1);
00094 #endif
00095 
00096   QLabel *summaryLabel = new QLabel(i18n("T&itle:"),parent);
00097   QFont f = summaryLabel->font();
00098   f.setBold( true );
00099   summaryLabel->setFont(f);
00100   headerLayout->addWidget(summaryLabel,1,0);
00101 
00102   mSummaryEdit = new FocusLineEdit(parent);
00103   connect( mSummaryEdit, SIGNAL( focusReceivedSignal() ),
00104            SIGNAL( focusReceivedSignal() ) );
00105   headerLayout->addWidget(mSummaryEdit,1,1);
00106   summaryLabel->setBuddy( mSummaryEdit );
00107 
00108   QLabel *locationLabel = new QLabel(i18n("&Location:"),parent);
00109   headerLayout->addWidget(locationLabel,2,0);
00110 
00111   mLocationEdit = new QLineEdit(parent);
00112   headerLayout->addWidget(mLocationEdit,2,1);
00113   locationLabel->setBuddy( mLocationEdit );
00114 }
00115 
00116 void KOEditorGeneral::initCategories(QWidget *parent, QBoxLayout *topLayout)
00117 {
00118   QBoxLayout *categoriesLayout = new QHBoxLayout( topLayout );
00119 
00120   mCategoriesButton = new QPushButton(parent);
00121   mCategoriesButton->setText(i18n("Select Cate&gories..."));
00122   connect(mCategoriesButton,SIGNAL(clicked()),SIGNAL(openCategoryDialog()));
00123   categoriesLayout->addWidget(mCategoriesButton);
00124 
00125   mCategoriesLabel = new KSqueezedTextLabel(parent);
00126   mCategoriesLabel->setFrameStyle(QFrame::Panel|QFrame::Sunken);
00127   categoriesLayout->addWidget(mCategoriesLabel,1);
00128 }
00129 
00130 void KOEditorGeneral::initSecrecy(QWidget *parent, QBoxLayout *topLayout)
00131 {
00132   QBoxLayout *secrecyLayout = new QHBoxLayout( topLayout );
00133 
00134   QLabel *secrecyLabel = new QLabel(i18n("S&ensitivity:"),parent);
00135   secrecyLayout->addWidget(secrecyLabel);
00136 
00137   mSecrecyCombo = new QComboBox(parent);
00138   mSecrecyCombo->insertStringList(Incidence::secrecyList());
00139   secrecyLayout->addWidget(mSecrecyCombo);
00140   secrecyLabel->setBuddy( mSecrecyCombo );
00141 }
00142 
00143 void KOEditorGeneral::initDescription(QWidget *parent,QBoxLayout *topLayout)
00144 {
00145   mDescriptionEdit = new KTextEdit(parent);
00146   mDescriptionEdit->append("");
00147   mDescriptionEdit->setReadOnly(false);
00148   mDescriptionEdit->setOverwriteMode(false);
00149   mDescriptionEdit->setWordWrap( KTextEdit::WidgetWidth );
00150   mDescriptionEdit->setTabChangesFocus( true );;
00151   topLayout->addWidget(mDescriptionEdit);
00152 }
00153 
00154 void KOEditorGeneral::initAlarm(QWidget *parent,QBoxLayout *topLayout)
00155 {
00156   QBoxLayout *alarmLayout = new QHBoxLayout(topLayout);
00157 
00158   mAlarmBell = new QLabel(parent);
00159   mAlarmBell->setPixmap(KOGlobals::self()->smallIcon("bell"));
00160   alarmLayout->addWidget(mAlarmBell);
00161 
00162   mAlarmButton = new QCheckBox(i18n("&Reminder:"),parent);
00163   connect(mAlarmButton, SIGNAL(toggled(bool)), SLOT(enableAlarmEdit(bool)));
00164   alarmLayout->addWidget(mAlarmButton);
00165 
00166   mAlarmTimeEdit = new KRestrictedLine(parent, "alarmTimeEdit",
00167                   "1234567890");
00168   mAlarmTimeEdit->setText("");
00169   alarmLayout->addWidget(mAlarmTimeEdit);
00170 
00171   mAlarmIncrCombo = new QComboBox(false, parent);
00172   mAlarmIncrCombo->insertItem(i18n("minute(s)"));
00173   mAlarmIncrCombo->insertItem(i18n("hour(s)"));
00174   mAlarmIncrCombo->insertItem(i18n("day(s)"));
00175 //  mAlarmIncrCombo->setMinimumHeight(20);
00176   alarmLayout->addWidget(mAlarmIncrCombo);
00177 
00178   mAlarmSoundButton = new QPushButton(parent);
00179   mAlarmSoundButton->setPixmap(KOGlobals::self()->smallIcon("playsound"));
00180   mAlarmSoundButton->setToggleButton(true);
00181   QToolTip::add(mAlarmSoundButton, i18n("No sound set"));
00182   connect(mAlarmSoundButton, SIGNAL(clicked()), SLOT(pickAlarmSound()));
00183   alarmLayout->addWidget(mAlarmSoundButton);
00184 
00185   mAlarmProgramButton = new QPushButton(parent);
00186   mAlarmProgramButton->setPixmap(KOGlobals::self()->smallIcon("runprog"));
00187   mAlarmProgramButton->setToggleButton(true);
00188   QToolTip::add(mAlarmProgramButton, i18n("No program set"));
00189   connect(mAlarmProgramButton, SIGNAL(clicked()), SLOT(pickAlarmProgram()));
00190   alarmLayout->addWidget(mAlarmProgramButton);
00191 
00192   if ( KOPrefs::instance()->mCompactDialogs ) {
00193     mAlarmSoundButton->hide();
00194     mAlarmProgramButton->hide();
00195   }
00196 }
00197 
00198 void KOEditorGeneral::pickAlarmSound()
00199 {
00200   QString prefix = KGlobal::dirs()->findResourceDir("data", "korganizer/sounds/alert.wav");
00201   prefix += "/korganizer/sounds/alert.wav";
00202   if (!mAlarmSoundButton->isOn()) {
00203     mAlarmSound = "";
00204     QToolTip::remove(mAlarmSoundButton);
00205     QToolTip::add(mAlarmSoundButton, i18n("No sound set"));
00206   } else {
00207     QString fileName(KFileDialog::getOpenFileName(prefix,
00208                                                   i18n("*.wav|Wav Files"), 0));
00209     if (!fileName.isEmpty()) {
00210       mAlarmSound = fileName;
00211       QToolTip::remove(mAlarmSoundButton);
00212       QString dispStr = i18n("Playing '%1'").arg(fileName);
00213       QToolTip::add(mAlarmSoundButton, dispStr);
00214       mAlarmProgramButton->setOn(false);
00215     }
00216   }
00217   if (mAlarmSound.isEmpty())
00218     mAlarmSoundButton->setOn(false);
00219 }
00220 
00221 void KOEditorGeneral::pickAlarmProgram()
00222 {
00223   if (!mAlarmProgramButton->isOn()) {
00224     mAlarmProgram = "";
00225     QToolTip::remove(mAlarmProgramButton);
00226     QToolTip::add(mAlarmProgramButton, i18n("No program set"));
00227   } else {
00228     QString fileName(KFileDialog::getOpenFileName(QString::null, QString::null, 0));
00229     if (!fileName.isEmpty()) {
00230       mAlarmProgram = fileName;
00231       QToolTip::remove(mAlarmProgramButton);
00232       QString dispStr = i18n("Running '%1'").arg(fileName);
00233       QToolTip::add(mAlarmProgramButton, dispStr);
00234       mAlarmSoundButton->setOn(false);
00235     }
00236   }
00237   if (mAlarmProgram.isEmpty())
00238     mAlarmProgramButton->setOn(false);
00239 }
00240 
00241 
00242 
00243 void KOEditorGeneral::enableAlarmEdit(bool enable)
00244 {
00245   mAlarmTimeEdit->setEnabled(enable);
00246   mAlarmSoundButton->setEnabled(enable);
00247   mAlarmProgramButton->setEnabled(enable);
00248   mAlarmIncrCombo->setEnabled(enable);
00249 }
00250 
00251 void KOEditorGeneral::disableAlarmEdit(bool disable)
00252 {
00253   enableAlarmEdit( !disable );
00254 }
00255 
00256 void KOEditorGeneral::enableAlarm( bool enable )
00257 {
00258   enableAlarmEdit( enable );
00259 }
00260 
00261 void KOEditorGeneral::alarmDisable(bool disable)
00262 {
00263   if (!disable) {
00264     mAlarmBell->setEnabled(true);
00265     mAlarmButton->setEnabled(true);
00266   } else {
00267     mAlarmBell->setEnabled(false);
00268     mAlarmButton->setEnabled(false);
00269     mAlarmButton->setChecked(false);
00270     mAlarmTimeEdit->setEnabled(false);
00271     mAlarmSoundButton->setEnabled(false);
00272     mAlarmProgramButton->setEnabled(false);
00273     mAlarmIncrCombo->setEnabled(false);
00274   }
00275 }
00276 
00277 void KOEditorGeneral::setCategories(const QString &str)
00278 {
00279   mCategoriesLabel->setText(str);
00280   mCategories = str;
00281 }
00282 
00283 void KOEditorGeneral::setDefaults(bool allDay)
00284 {
00285 #if 0
00286   mOwnerLabel->setText(i18n("Owner: ") + KOPrefs::instance()->fullName());
00287 #endif
00288 
00289   enableAlarmEdit( !allDay );
00290 
00291   // TODO: Implement a KPrefsComboItem to solve this in a clean way.
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->setText(QString::number(alarmTime));
00301 
00302   enableAlarmEdit( false );
00303 
00304   mSecrecyCombo->setCurrentItem(Incidence::SecrecyPublic);
00305 }
00306 
00307 void KOEditorGeneral::readIncidence(Incidence *event)
00308 {
00309   mSummaryEdit->setText(event->summary());
00310   mLocationEdit->setText(event->location());
00311 
00312   mDescriptionEdit->setText(event->description());
00313 
00314 #if 0
00315   // organizer information
00316   mOwnerLabel->setText(i18n("Owner: ") + event->organizer().fullName() );
00317 #endif
00318 
00319   enableAlarmEdit( event->isAlarmEnabled() );
00320 
00321   if(!event->isAlarmEnabled()) {
00322     // TODO: Implement a KPrefsComboItem to solve this in a clean way.
00323     int alarmTime;
00324     int a[] = { 1,5,10,15,30 };
00325     int index = KOPrefs::instance()->mAlarmTime;
00326     if (index < 0 || index > 4) {
00327       alarmTime = 0;
00328     } else {
00329       alarmTime = a[index];
00330     }
00331     mAlarmTimeEdit->setText(QString::number(alarmTime));
00332   }
00333 
00334   mSecrecyCombo->setCurrentItem(event->secrecy());
00335 
00336   // set up alarm stuff
00337   Alarm::List alarms = event->alarms();
00338   Alarm::List::ConstIterator it;
00339   for( it = alarms.begin(); it != alarms.end(); ++it ) {
00340     Alarm *alarm = *it;
00341     int offset;
00342     if ( alarm->hasTime() ) {
00343       QDateTime t = alarm->time();
00344       offset = event->dtStart().secsTo( t );
00345     } else {
00346       offset = alarm->startOffset().asSeconds();
00347     }
00348     offset = offset / -60; // make minutes
00349     if (offset % 60 == 0) { // divides evenly into hours?
00350       offset = offset / 60;
00351       mAlarmIncrCombo->setCurrentItem(1);
00352     }
00353     if (offset % 24 == 0) { // divides evenly into days?
00354       offset = offset / 24;
00355       mAlarmIncrCombo->setCurrentItem(2);
00356     }
00357     mAlarmTimeEdit->setText(QString::number( offset ));
00358 
00359     if (alarm->type() == Alarm::Procedure) {
00360       mAlarmProgram = alarm->programFile();
00361       mAlarmProgramButton->setOn(true);
00362       QString dispStr = i18n("Running '%1'").arg(mAlarmProgram);
00363       QToolTip::add(mAlarmProgramButton, dispStr);
00364     }
00365     else if (alarm->type() == Alarm::Audio) {
00366       mAlarmSound = alarm->audioFile();
00367       mAlarmSoundButton->setOn(true);
00368       QString dispStr = i18n("Playing '%1'").arg(mAlarmSound);
00369       QToolTip::add(mAlarmSoundButton, dispStr);
00370     }
00371     mAlarmButton->setChecked(alarm->enabled());
00372     enableAlarmEdit( alarm->enabled() );
00373 // TODO: Deal with multiple alarms
00374     break; // For now, stop after the first alarm
00375   }
00376 
00377   setCategories(event->categoriesStr());
00378 }
00379 
00380 void KOEditorGeneral::writeIncidence(Incidence *event)
00381 {
00382 //  kdDebug(5850) << "KOEditorGeneral::writeEvent()" << endl;
00383 
00384   event->setSummary(mSummaryEdit->text());
00385   event->setLocation(mLocationEdit->text());
00386   event->setDescription(mDescriptionEdit->text());
00387   event->setCategories(mCategories);
00388   event->setSecrecy(mSecrecyCombo->currentItem());
00389 
00390   // alarm stuff
00391   if (mAlarmButton->isChecked()) {
00392     if (event->alarms().count() == 0) event->newAlarm();
00393     Alarm::List alarms = event->alarms();
00394     Alarm::List::ConstIterator it;
00395     for( it = alarms.begin(); it != alarms.end(); ++it ) {
00396       Alarm *alarm = *it;
00397       alarm->setEnabled(true);
00398 
00399       QString tmpStr = mAlarmTimeEdit->text();
00400       int j = tmpStr.toInt() * -60;
00401       if (mAlarmIncrCombo->currentItem() == 1)
00402         j = j * 60;
00403       else if (mAlarmIncrCombo->currentItem() == 2)
00404         j = j * (60 * 24);
00405       alarm->setStartOffset( j );
00406 
00407       if (!mAlarmSound.isEmpty() && mAlarmSoundButton->isOn())
00408         alarm->setAudioAlarm(mAlarmSound);
00409       else
00410         alarm->setDisplayAlarm(QString::null);
00411       // TODO: Make sure all alarm options are correctly set and don't erase other options!
00412       if (!mAlarmProgram.isEmpty() && mAlarmProgramButton->isOn())
00413         alarm->setProcedureAlarm(mAlarmProgram);
00414 
00415 // TODO: Deal with multiple alarms
00416       break; // For now, stop after the first alarm
00417     }
00418   } else {
00419     if ( !event->alarms().isEmpty() ) {
00420       Alarm *alarm = event->alarms().first();
00421       alarm->setEnabled(false);
00422       alarm->setType(Alarm::Invalid);
00423     }
00424   }
00425 }
00426 
00427 void KOEditorGeneral::setSummary( const QString &text )
00428 {
00429   mSummaryEdit->setText( text );
00430 }
00431 
00432 void KOEditorGeneral::setDescription( const QString &text )
00433 {
00434   mDescriptionEdit->setText( text );
00435 }
00436 
00437 QObject *KOEditorGeneral::typeAheadReceiver() const
00438 {
00439   return mSummaryEdit;
00440 }
KDE Logo
This file is part of the documentation for korganizer Library Version 3.3.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Thu May 3 20:24:54 2007 by doxygen 1.4.2 written by Dimitri van Heesch, © 1997-2003