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("Acc&ess:"),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 if (!mAlarmSoundButton->isOn()) { 00202 mAlarmSound = ""; 00203 QToolTip::remove(mAlarmSoundButton); 00204 QToolTip::add(mAlarmSoundButton, i18n("No sound set")); 00205 } else { 00206 QString fileName(KFileDialog::getOpenFileName(prefix, 00207 i18n("*.wav|Wav Files"), 0)); 00208 if (!fileName.isEmpty()) { 00209 mAlarmSound = fileName; 00210 QToolTip::remove(mAlarmSoundButton); 00211 QString dispStr = i18n("Playing '%1'").arg(fileName); 00212 QToolTip::add(mAlarmSoundButton, dispStr); 00213 mAlarmProgramButton->setOn(false); 00214 } 00215 } 00216 if (mAlarmSound.isEmpty()) 00217 mAlarmSoundButton->setOn(false); 00218 } 00219 00220 void KOEditorGeneral::pickAlarmProgram() 00221 { 00222 if (!mAlarmProgramButton->isOn()) { 00223 mAlarmProgram = ""; 00224 QToolTip::remove(mAlarmProgramButton); 00225 QToolTip::add(mAlarmProgramButton, i18n("No program set")); 00226 } else { 00227 QString fileName(KFileDialog::getOpenFileName(QString::null, QString::null, 0)); 00228 if (!fileName.isEmpty()) { 00229 mAlarmProgram = fileName; 00230 QToolTip::remove(mAlarmProgramButton); 00231 QString dispStr = i18n("Running '%1'").arg(fileName); 00232 QToolTip::add(mAlarmProgramButton, dispStr); 00233 mAlarmSoundButton->setOn(false); 00234 } 00235 } 00236 if (mAlarmProgram.isEmpty()) 00237 mAlarmProgramButton->setOn(false); 00238 } 00239 00240 00241 00242 void KOEditorGeneral::enableAlarmEdit(bool enable) 00243 { 00244 mAlarmTimeEdit->setEnabled(enable); 00245 mAlarmSoundButton->setEnabled(enable); 00246 mAlarmProgramButton->setEnabled(enable); 00247 mAlarmIncrCombo->setEnabled(enable); 00248 } 00249 00250 void KOEditorGeneral::disableAlarmEdit(bool disable) 00251 { 00252 enableAlarmEdit( !disable ); 00253 } 00254 00255 void KOEditorGeneral::enableAlarm( bool enable ) 00256 { 00257 enableAlarmEdit( enable ); 00258 } 00259 00260 void KOEditorGeneral::alarmDisable(bool disable) 00261 { 00262 if (!disable) { 00263 mAlarmBell->setEnabled(true); 00264 mAlarmButton->setEnabled(true); 00265 } else { 00266 mAlarmBell->setEnabled(false); 00267 mAlarmButton->setEnabled(false); 00268 mAlarmButton->setChecked(false); 00269 mAlarmTimeEdit->setEnabled(false); 00270 mAlarmSoundButton->setEnabled(false); 00271 mAlarmProgramButton->setEnabled(false); 00272 mAlarmIncrCombo->setEnabled(false); 00273 } 00274 } 00275 00276 void KOEditorGeneral::setCategories(const QString &str) 00277 { 00278 mCategoriesLabel->setText(str); 00279 mCategories = str; 00280 } 00281 00282 void KOEditorGeneral::setDefaults(bool allDay) 00283 { 00284 #if 0 00285 mOwnerLabel->setText(i18n("Owner: ") + KOPrefs::instance()->fullName()); 00286 #endif 00287 00288 enableAlarmEdit( !allDay ); 00289 00290 // TODO: Implement a KPrefsComboItem to solve this in a clean way. 00291 int alarmTime; 00292 int a[] = { 1,5,10,15,30 }; 00293 int index = KOPrefs::instance()->mAlarmTime; 00294 if (index < 0 || index > 4) { 00295 alarmTime = 0; 00296 } else { 00297 alarmTime = a[index]; 00298 } 00299 mAlarmTimeEdit->setText(QString::number(alarmTime)); 00300 00301 enableAlarmEdit( false ); 00302 00303 mSecrecyCombo->setCurrentItem(Incidence::SecrecyPublic); 00304 } 00305 00306 void KOEditorGeneral::readIncidence(Incidence *event) 00307 { 00308 mSummaryEdit->setText(event->summary()); 00309 mLocationEdit->setText(event->location()); 00310 00311 mDescriptionEdit->setText(event->description()); 00312 00313 #if 0 00314 // organizer information 00315 mOwnerLabel->setText(i18n("Owner: ") + event->organizer()); 00316 #endif 00317 00318 enableAlarmEdit( event->isAlarmEnabled() ); 00319 00320 if(!event->isAlarmEnabled()) { 00321 // TODO: Implement a KPrefsComboItem to solve this in a clean way. 00322 int alarmTime; 00323 int a[] = { 1,5,10,15,30 }; 00324 int index = KOPrefs::instance()->mAlarmTime; 00325 if (index < 0 || index > 4) { 00326 alarmTime = 0; 00327 } else { 00328 alarmTime = a[index]; 00329 } 00330 mAlarmTimeEdit->setText(QString::number(alarmTime)); 00331 } 00332 00333 mSecrecyCombo->setCurrentItem(event->secrecy()); 00334 00335 // set up alarm stuff 00336 Alarm::List alarms = event->alarms(); 00337 Alarm::List::ConstIterator it; 00338 for( it = alarms.begin(); it != alarms.end(); ++it ) { 00339 Alarm *alarm = *it; 00340 int offset; 00341 if ( alarm->hasTime() ) { 00342 QDateTime t = alarm->time(); 00343 offset = event->dtStart().secsTo( t ); 00344 } else { 00345 offset = alarm->startOffset().asSeconds(); 00346 } 00347 offset = offset / -60; // make minutes 00348 if (offset % 60 == 0) { // divides evenly into hours? 00349 offset = offset / 60; 00350 mAlarmIncrCombo->setCurrentItem(1); 00351 } 00352 if (offset % 24 == 0) { // divides evenly into days? 00353 offset = offset / 24; 00354 mAlarmIncrCombo->setCurrentItem(2); 00355 } 00356 mAlarmTimeEdit->setText(QString::number( offset )); 00357 00358 if (alarm->type() == Alarm::Procedure) { 00359 mAlarmProgram = alarm->programFile(); 00360 mAlarmProgramButton->setOn(true); 00361 QString dispStr = i18n("Running '%1'").arg(mAlarmProgram); 00362 QToolTip::add(mAlarmProgramButton, dispStr); 00363 } 00364 else if (alarm->type() == Alarm::Audio) { 00365 mAlarmSound = alarm->audioFile(); 00366 mAlarmSoundButton->setOn(true); 00367 QString dispStr = i18n("Playing '%1'").arg(mAlarmSound); 00368 QToolTip::add(mAlarmSoundButton, dispStr); 00369 } 00370 mAlarmButton->setChecked(alarm->enabled()); 00371 enableAlarmEdit( alarm->enabled() ); 00372 // TODO: Deal with multiple alarms 00373 break; // For now, stop after the first alarm 00374 } 00375 00376 setCategories(event->categoriesStr()); 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 if (mAlarmButton->isChecked()) { 00391 if (event->alarms().count() == 0) event->newAlarm(); 00392 Alarm::List alarms = event->alarms(); 00393 Alarm::List::ConstIterator it; 00394 for( it = alarms.begin(); it != alarms.end(); ++it ) { 00395 Alarm *alarm = *it; 00396 alarm->setEnabled(true); 00397 00398 QString tmpStr = mAlarmTimeEdit->text(); 00399 int j = tmpStr.toInt() * -60; 00400 if (mAlarmIncrCombo->currentItem() == 1) 00401 j = j * 60; 00402 else if (mAlarmIncrCombo->currentItem() == 2) 00403 j = j * (60 * 24); 00404 alarm->setStartOffset( j ); 00405 00406 if (!mAlarmSound.isEmpty() && mAlarmSoundButton->isOn()) 00407 alarm->setAudioAlarm(mAlarmSound); 00408 else 00409 alarm->setDisplayAlarm(QString::null); 00410 // TODO: Make sure all alarm options are correctly set and don't erase other options! 00411 if (!mAlarmProgram.isEmpty() && mAlarmProgramButton->isOn()) 00412 alarm->setProcedureAlarm(mAlarmProgram); 00413 00414 // TODO: Deal with multiple alarms 00415 break; // For now, stop after the first alarm 00416 } 00417 } else { 00418 if ( !event->alarms().isEmpty() ) { 00419 Alarm *alarm = event->alarms().first(); 00420 alarm->setEnabled(false); 00421 alarm->setType(Alarm::Invalid); 00422 } 00423 } 00424 } 00425 00426 void KOEditorGeneral::setSummary( const QString &text ) 00427 { 00428 mSummaryEdit->setText( text ); 00429 } 00430 00431 void KOEditorGeneral::setDescription( const QString &text ) 00432 { 00433 mDescriptionEdit->setText( text ); 00434 } 00435 00436 QObject *KOEditorGeneral::typeAheadReceiver() const 00437 { 00438 return mSummaryEdit; 00439 }
KDE Logo
This file is part of the documentation for korganizer Library Version 3.3.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Thu Oct 21 19:46:56 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003