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., 675 Mass Ave, Cambridge, MA 02139, 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 #include <qwidget.h>
00025 #include <qtooltip.h>
00026 #include <qlayout.h>
00027 #include <qvbox.h>
00028 #include <qbuttongroup.h>
00029 #include <qvgroupbox.h>
00030 #include <qwidgetstack.h>
00031 #include <qdatetime.h>
00032 
00033 #include <kglobal.h>
00034 #include <kdebug.h>
00035 #include <klocale.h>
00036 #include <kiconloader.h>
00037 #include <kmessagebox.h>
00038 #include <kfiledialog.h>
00039 #include <kstandarddirs.h>
00040 
00041 #include <libkcal/todo.h>
00042 #include <libkcal/event.h>
00043 
00044 #include <libkdepim/kdateedit.h>
00045 
00046 #include "koprefs.h"
00047 
00048 #include "koeditorgeneral.h"
00049 #include "koeditorgeneral.moc"
00050 
00051 KOEditorGeneral::KOEditorGeneral(QObject* parent, const char* name) :
00052   QObject( parent, name)
00053 {
00054 }
00055 
00056 KOEditorGeneral::~KOEditorGeneral()
00057 {
00058 }
00059 
00060 void KOEditorGeneral::initHeader(QWidget *parent,QBoxLayout *topLayout)
00061 {
00062   QGridLayout *headerLayout = new QGridLayout(topLayout);
00063 
00064 #if 0
00065   mOwnerLabel = new QLabel(i18n("Owner:"),parent);
00066   headerLayout->addMultiCellWidget(mOwnerLabel,0,0,0,1);
00067 #endif
00068 
00069   QLabel *summaryLabel = new QLabel(i18n("Summary:"),parent);
00070   headerLayout->addWidget(summaryLabel,1,0);
00071 
00072   mSummaryEdit = new QLineEdit(parent);
00073   headerLayout->addWidget(mSummaryEdit,1,1);
00074   
00075   QLabel *locationLabel = new QLabel(i18n("Location:"),parent);
00076   headerLayout->addWidget(locationLabel,2,0);
00077 
00078   mLocationEdit = new QLineEdit(parent);
00079   headerLayout->addWidget(mLocationEdit,2,1);
00080 }
00081 
00082 void KOEditorGeneral::initCategories(QWidget *parent, QBoxLayout *topLayout)
00083 {
00084   QBoxLayout *categoriesLayout = new QHBoxLayout( topLayout );
00085 
00086   mCategoriesButton = new QPushButton(parent);
00087   mCategoriesButton->setText(i18n("Categories..."));
00088   connect(mCategoriesButton,SIGNAL(clicked()),SIGNAL(openCategoryDialog()));
00089   categoriesLayout->addWidget(mCategoriesButton);
00090 
00091   mCategoriesLabel = new QLabel(parent);
00092   mCategoriesLabel->setFrameStyle(QFrame::Panel|QFrame::Sunken);
00093   categoriesLayout->addWidget(mCategoriesLabel,1);
00094 }
00095 
00096 void KOEditorGeneral::initSecrecy(QWidget *parent, QBoxLayout *topLayout)
00097 {
00098   QBoxLayout *secrecyLayout = new QHBoxLayout( topLayout );
00099 
00100   QLabel *secrecyLabel = new QLabel(i18n("Access:"),parent);
00101   secrecyLayout->addWidget(secrecyLabel);
00102 
00103   mSecrecyCombo = new QComboBox(parent);
00104   mSecrecyCombo->insertStringList(Incidence::secrecyList());
00105   secrecyLayout->addWidget(mSecrecyCombo);
00106 }
00107 
00108 void KOEditorGeneral::initDescription(QWidget *parent,QBoxLayout *topLayout)
00109 {
00110   mDescriptionEdit = new KTextEdit(parent);
00111   mDescriptionEdit->append("");
00112   mDescriptionEdit->setReadOnly(false);
00113   mDescriptionEdit->setOverwriteMode(false);
00114   mDescriptionEdit->setWordWrap(QTextEdit::WidgetWidth);
00115   topLayout->addWidget(mDescriptionEdit);
00116 }
00117 
00118 void KOEditorGeneral::initAlarm(QWidget *parent,QBoxLayout *topLayout)
00119 {
00120   QBoxLayout *alarmLayout = new QHBoxLayout(topLayout);
00121 
00122   mAlarmBell = new QLabel(parent);
00123   mAlarmBell->setPixmap(SmallIcon("bell"));
00124   alarmLayout->addWidget(mAlarmBell);
00125 
00126   mAlarmButton = new QCheckBox(i18n("Reminder:"),parent);
00127   connect(mAlarmButton, SIGNAL(toggled(bool)), SLOT(enableAlarmEdit(bool)));
00128   alarmLayout->addWidget(mAlarmButton);
00129 
00130   mAlarmTimeEdit = new KRestrictedLine(parent, "alarmTimeEdit",
00131                                        "1234567890");
00132   mAlarmTimeEdit->setText("");
00133   alarmLayout->addWidget(mAlarmTimeEdit);
00134 
00135   mAlarmIncrCombo = new QComboBox(false, parent);
00136   mAlarmIncrCombo->insertItem(i18n("minute(s)"));
00137   mAlarmIncrCombo->insertItem(i18n("hour(s)"));
00138   mAlarmIncrCombo->insertItem(i18n("day(s)"));
00139 //  mAlarmIncrCombo->setMinimumHeight(20);
00140   alarmLayout->addWidget(mAlarmIncrCombo);
00141 
00142   mAlarmSoundButton = new QPushButton(parent);
00143   mAlarmSoundButton->setPixmap(SmallIcon("playsound"));
00144   mAlarmSoundButton->setToggleButton(true);
00145   QToolTip::add(mAlarmSoundButton, i18n("No sound set"));
00146   connect(mAlarmSoundButton, SIGNAL(clicked()), SLOT(pickAlarmSound()));
00147   alarmLayout->addWidget(mAlarmSoundButton);
00148 
00149   mAlarmProgramButton = new QPushButton(parent);
00150   mAlarmProgramButton->setPixmap(SmallIcon("runprog"));
00151   mAlarmProgramButton->setToggleButton(true);
00152   QToolTip::add(mAlarmProgramButton, i18n("No program set"));
00153   connect(mAlarmProgramButton, SIGNAL(clicked()), SLOT(pickAlarmProgram()));
00154   alarmLayout->addWidget(mAlarmProgramButton);
00155 }
00156 
00157 void KOEditorGeneral::pickAlarmSound()
00158 {
00159   QString prefix = KGlobal::dirs()->findResourceDir("appdata", "sounds/alert.wav");
00160   if (!mAlarmSoundButton->isOn()) {
00161     mAlarmSound = "";
00162     QToolTip::remove(mAlarmSoundButton);
00163     QToolTip::add(mAlarmSoundButton, i18n("No sound set"));
00164   } else {
00165     QString fileName(KFileDialog::getOpenFileName(prefix,
00166                                                   i18n("*.wav|Wav Files"), 0));
00167     if (!fileName.isEmpty()) {
00168       mAlarmSound = fileName;
00169       QToolTip::remove(mAlarmSoundButton);
00170       QString dispStr = i18n("Playing '%1'").arg(fileName);
00171       QToolTip::add(mAlarmSoundButton, dispStr);
00172       mAlarmProgramButton->setOn(false);
00173     }
00174   }
00175   if (mAlarmSound.isEmpty())
00176     mAlarmSoundButton->setOn(false);
00177 }
00178 
00179 void KOEditorGeneral::pickAlarmProgram()
00180 {
00181   if (!mAlarmProgramButton->isOn()) {
00182     mAlarmProgram = "";
00183     QToolTip::remove(mAlarmProgramButton);
00184     QToolTip::add(mAlarmProgramButton, i18n("No program set"));
00185   } else {
00186     QString fileName(KFileDialog::getOpenFileName(QString::null, QString::null, 0));
00187     if (!fileName.isEmpty()) {
00188       mAlarmProgram = fileName;
00189       QToolTip::remove(mAlarmProgramButton);
00190       QString dispStr = i18n("Running '%1'").arg(fileName);
00191       QToolTip::add(mAlarmProgramButton, dispStr);
00192       mAlarmSoundButton->setOn(false);
00193     }
00194   }
00195   if (mAlarmProgram.isEmpty())
00196     mAlarmProgramButton->setOn(false);
00197 }
00198 
00199 
00200 
00201 void KOEditorGeneral::enableAlarmEdit(bool enable)
00202 {
00203   mAlarmTimeEdit->setEnabled(enable);
00204   mAlarmSoundButton->setEnabled(enable);
00205   mAlarmProgramButton->setEnabled(enable);
00206   mAlarmIncrCombo->setEnabled(enable);
00207 }
00208 
00209 void KOEditorGeneral::disableAlarmEdit(bool disable)
00210 {
00211   enableAlarmEdit( !disable );
00212 }
00213 
00214 void KOEditorGeneral::enableAlarm( bool enable )
00215 {
00216   enableAlarmEdit( enable );
00217 }
00218 
00219 void KOEditorGeneral::alarmDisable(bool disable)
00220 {
00221   if (!disable) {
00222     mAlarmBell->setEnabled(true);
00223     mAlarmButton->setEnabled(true);
00224   } else {
00225     mAlarmBell->setEnabled(false);
00226     mAlarmButton->setEnabled(false);
00227     mAlarmButton->setChecked(false);
00228     mAlarmTimeEdit->setEnabled(false);
00229     mAlarmSoundButton->setEnabled(false);
00230     mAlarmProgramButton->setEnabled(false);
00231     mAlarmIncrCombo->setEnabled(false);
00232   }
00233 }
00234 
00235 void KOEditorGeneral::setCategories(const QString &str)
00236 {
00237   mCategoriesLabel->setText(str);
00238 }
00239 
00240 void KOEditorGeneral::setDefaults(bool allDay)
00241 {
00242 #if 0
00243   mOwnerLabel->setText(i18n("Owner: ") + KOPrefs::instance()->fullName());
00244 #endif
00245 
00246   enableAlarmEdit( !allDay );
00247 
00248   // TODO: Implement a KPrefsComboItem to solve this in a clean way.
00249   int alarmTime;
00250   int a[] = { 1,5,10,15,30 };
00251   int index = KOPrefs::instance()->mAlarmTime;
00252   if (index < 0 || index > 4) {
00253     alarmTime = 0;
00254   } else {
00255     alarmTime = a[index];
00256   }
00257   mAlarmTimeEdit->setText(QString::number(alarmTime));
00258 
00259   enableAlarmEdit( false );
00260 
00261   mSecrecyCombo->setCurrentItem(Incidence::SecrecyPublic);
00262 }
00263 
00264 void KOEditorGeneral::readIncidence(Incidence *event)
00265 {
00266   mSummaryEdit->setText(event->summary());
00267   mLocationEdit->setText(event->location());
00268   
00269   mDescriptionEdit->setText(event->description());
00270 
00271 #if 0
00272   // organizer information
00273   mOwnerLabel->setText(i18n("Owner: ") + event->organizer());
00274 #endif
00275   
00276   enableAlarmEdit( event->isAlarmEnabled() );
00277   
00278   if(!event->isAlarmEnabled()) {
00279     // TODO: Implement a KPrefsComboItem to solve this in a clean way.
00280     int alarmTime;
00281     int a[] = { 1,5,10,15,30 };
00282     int index = KOPrefs::instance()->mAlarmTime;
00283     if (index < 0 || index > 4) {
00284       alarmTime = 0;
00285     } else {
00286       alarmTime = a[index];
00287     }
00288     mAlarmTimeEdit->setText(QString::number(alarmTime));
00289   }
00290 
00291   mSecrecyCombo->setCurrentItem(event->secrecy());
00292 
00293   // set up alarm stuff
00294   QPtrList<Alarm> alarms = event->alarms();
00295   Alarm* alarm;
00296   for ( alarm = alarms.first(); alarm; alarm = alarms.next() ) {
00297     int offset;
00298     if ( alarm->hasTime() ) {
00299       QDateTime t = alarm->time();
00300       offset = event->dtStart().secsTo( t );
00301     } else {
00302       offset = alarm->offset().asSeconds();
00303     }
00304     offset = offset / -60; // make minutes
00305     if (offset % 60 == 0) { // divides evenly into hours?
00306       offset = offset / 60;
00307       mAlarmIncrCombo->setCurrentItem(1);
00308     }
00309     if (offset % 24 == 0) { // divides evenly into days?
00310       offset = offset / 24;
00311       mAlarmIncrCombo->setCurrentItem(2);
00312     }
00313     mAlarmTimeEdit->setText(QString::number( offset ));
00314 
00315     if (!alarm->programFile().isEmpty()) {
00316       mAlarmProgram = alarm->programFile();
00317       mAlarmProgramButton->setOn(true);
00318       QString dispStr = i18n("Running '%1'").arg(mAlarmProgram);
00319       QToolTip::add(mAlarmProgramButton, dispStr);
00320     }
00321     if (!alarm->audioFile().isEmpty()) {
00322       mAlarmSound = alarm->audioFile();
00323       mAlarmSoundButton->setOn(true);
00324       QString dispStr = i18n("Playing '%1'").arg(mAlarmSound);
00325       QToolTip::add(mAlarmSoundButton, dispStr);
00326     }
00327     mAlarmButton->setChecked(alarm->enabled());
00328     enableAlarmEdit( alarm->enabled() );
00329 // TODO: Deal with multiple alarms
00330     break; // For now, stop after the first alarm
00331   }
00332 
00333   setCategories(event->categoriesStr());
00334 }
00335 
00336 void KOEditorGeneral::writeIncidence(Incidence *event)
00337 {
00338 //  kdDebug() << "KOEditorGeneral::writeEvent()" << endl;
00339 
00340   event->setSummary(mSummaryEdit->text());
00341   event->setLocation(mLocationEdit->text());
00342   event->setDescription(mDescriptionEdit->text());
00343   event->setCategories(mCategoriesLabel->text());
00344   event->setSecrecy(mSecrecyCombo->currentItem());
00345 
00346   // alarm stuff
00347   if (mAlarmButton->isChecked()) {
00348     if (event->alarms().count() == 0) event->newAlarm();
00349     QPtrList<Alarm> alarms = event->alarms();
00350     Alarm *alarm;
00351     for (alarm = alarms.first(); alarm; alarm = alarms.next() ) {
00352       alarm->setEnabled(true);
00353 
00354       QString tmpStr = mAlarmTimeEdit->text();
00355       int j = tmpStr.toInt() * -60;
00356       if (mAlarmIncrCombo->currentItem() == 1)
00357         j = j * 60;
00358       else if (mAlarmIncrCombo->currentItem() == 2)
00359         j = j * (60 * 24);
00360       alarm->setOffset( j );
00361 
00362       if (!mAlarmProgram.isEmpty() && mAlarmProgramButton->isOn())
00363         alarm->setProgramFile(mAlarmProgram);
00364       else
00365         alarm->setProgramFile("");
00366 
00367       if (!mAlarmSound.isEmpty() && mAlarmSoundButton->isOn())
00368         alarm->setAudioFile(mAlarmSound);
00369       else
00370         alarm->setAudioFile("");
00371 
00372 // TODO: Deal with multiple alarms
00373       break; // For now, stop after the first alarm
00374     }
00375   } else {
00376     Alarm* alarm = event->alarms().first();
00377     if ( alarm ) {
00378       alarm->setEnabled(false);
00379       alarm->setProgramFile("");
00380       alarm->setAudioFile("");
00381     }
00382   }
00383 }
KDE Logo
This file is part of the documentation for kdelibs Version 3.1.5.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Sun Feb 15 11:41:09 2004 by doxygen 1.3.5 written by Dimitri van Heesch, © 1997-2001