00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
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 <ksqueezedtextlabel.h>
00040 #include <kstandarddirs.h>
00041
00042 #include <libkcal/todo.h>
00043 #include <libkcal/event.h>
00044
00045 #include <libkdepim/kdateedit.h>
00046
00047 #include "koprefs.h"
00048 #include "koglobals.h"
00049
00050 #include "koeditorgeneral.h"
00051 #include "koeditorgeneral.moc"
00052
00053 KOEditorGeneral::KOEditorGeneral(QObject* parent, const char* name) :
00054 QObject( parent, name)
00055 {
00056 }
00057
00058 KOEditorGeneral::~KOEditorGeneral()
00059 {
00060 }
00061
00062
00063 FocusLineEdit::FocusLineEdit( QWidget *parent )
00064 : QLineEdit( parent ), mSkipFirst( true )
00065 {
00066 }
00067
00068 void FocusLineEdit::focusInEvent ( QFocusEvent *e )
00069 {
00070 if ( !mSkipFirst ) {
00071 emit focusReceivedSignal();
00072 } else {
00073 mSkipFirst = false;
00074 }
00075 QLineEdit::focusInEvent( e );
00076 }
00077
00078
00079 void KOEditorGeneral::initHeader(QWidget *parent,QBoxLayout *topLayout)
00080 {
00081 QGridLayout *headerLayout = new QGridLayout(topLayout);
00082
00083 #if 0
00084 mOwnerLabel = new QLabel(i18n("Owner:"),parent);
00085 headerLayout->addMultiCellWidget(mOwnerLabel,0,0,0,1);
00086 #endif
00087
00088 QLabel *summaryLabel = new QLabel(i18n("T&itle:"),parent);
00089 QFont f = summaryLabel->font();
00090 f.setBold( true );
00091 summaryLabel->setFont(f);
00092 headerLayout->addWidget(summaryLabel,1,0);
00093
00094 mSummaryEdit = new FocusLineEdit(parent);
00095 connect( mSummaryEdit, SIGNAL( focusReceivedSignal() ),
00096 SIGNAL( focusReceivedSignal() ) );
00097 headerLayout->addWidget(mSummaryEdit,1,1);
00098 summaryLabel->setBuddy( mSummaryEdit );
00099
00100 QLabel *locationLabel = new QLabel(i18n("&Location:"),parent);
00101 headerLayout->addWidget(locationLabel,2,0);
00102
00103 mLocationEdit = new QLineEdit(parent);
00104 headerLayout->addWidget(mLocationEdit,2,1);
00105 locationLabel->setBuddy( mLocationEdit );
00106 }
00107
00108 void KOEditorGeneral::initCategories(QWidget *parent, QBoxLayout *topLayout)
00109 {
00110 QBoxLayout *categoriesLayout = new QHBoxLayout( topLayout );
00111
00112 mCategoriesButton = new QPushButton(parent);
00113 mCategoriesButton->setText(i18n("Select Cate&gories..."));
00114 connect(mCategoriesButton,SIGNAL(clicked()),SIGNAL(openCategoryDialog()));
00115 categoriesLayout->addWidget(mCategoriesButton);
00116
00117 mCategoriesLabel = new KSqueezedTextLabel(parent);
00118 mCategoriesLabel->setFrameStyle(QFrame::Panel|QFrame::Sunken);
00119 categoriesLayout->addWidget(mCategoriesLabel,1);
00120 }
00121
00122 void KOEditorGeneral::initSecrecy(QWidget *parent, QBoxLayout *topLayout)
00123 {
00124 QBoxLayout *secrecyLayout = new QHBoxLayout( topLayout );
00125
00126 QLabel *secrecyLabel = new QLabel(i18n("Acc&ess:"),parent);
00127 secrecyLayout->addWidget(secrecyLabel);
00128
00129 mSecrecyCombo = new QComboBox(parent);
00130 mSecrecyCombo->insertStringList(Incidence::secrecyList());
00131 secrecyLayout->addWidget(mSecrecyCombo);
00132 secrecyLabel->setBuddy( mSecrecyCombo );
00133 }
00134
00135 void KOEditorGeneral::initDescription(QWidget *parent,QBoxLayout *topLayout)
00136 {
00137 mDescriptionEdit = new KTextEdit(parent);
00138 mDescriptionEdit->append("");
00139 mDescriptionEdit->setReadOnly(false);
00140 mDescriptionEdit->setOverwriteMode(false);
00141 mDescriptionEdit->setWordWrap( KTextEdit::WidgetWidth );
00142 mDescriptionEdit->setTabChangesFocus( true );;
00143 topLayout->addWidget(mDescriptionEdit);
00144 }
00145
00146 void KOEditorGeneral::initAlarm(QWidget *parent,QBoxLayout *topLayout)
00147 {
00148 QBoxLayout *alarmLayout = new QHBoxLayout(topLayout);
00149
00150 mAlarmBell = new QLabel(parent);
00151 mAlarmBell->setPixmap(KOGlobals::self()->smallIcon("bell"));
00152 alarmLayout->addWidget(mAlarmBell);
00153
00154 mAlarmButton = new QCheckBox(i18n("&Reminder:"),parent);
00155 connect(mAlarmButton, SIGNAL(toggled(bool)), SLOT(enableAlarmEdit(bool)));
00156 alarmLayout->addWidget(mAlarmButton);
00157
00158 mAlarmTimeEdit = new KRestrictedLine(parent, "alarmTimeEdit",
00159 "1234567890");
00160 mAlarmTimeEdit->setText("");
00161 alarmLayout->addWidget(mAlarmTimeEdit);
00162
00163 mAlarmIncrCombo = new QComboBox(false, parent);
00164 mAlarmIncrCombo->insertItem(i18n("minute(s)"));
00165 mAlarmIncrCombo->insertItem(i18n("hour(s)"));
00166 mAlarmIncrCombo->insertItem(i18n("day(s)"));
00167
00168 alarmLayout->addWidget(mAlarmIncrCombo);
00169
00170 mAlarmSoundButton = new QPushButton(parent);
00171 mAlarmSoundButton->setPixmap(KOGlobals::self()->smallIcon("playsound"));
00172 mAlarmSoundButton->setToggleButton(true);
00173 QToolTip::add(mAlarmSoundButton, i18n("No sound set"));
00174 connect(mAlarmSoundButton, SIGNAL(clicked()), SLOT(pickAlarmSound()));
00175 alarmLayout->addWidget(mAlarmSoundButton);
00176
00177 mAlarmProgramButton = new QPushButton(parent);
00178 mAlarmProgramButton->setPixmap(KOGlobals::self()->smallIcon("runprog"));
00179 mAlarmProgramButton->setToggleButton(true);
00180 QToolTip::add(mAlarmProgramButton, i18n("No program set"));
00181 connect(mAlarmProgramButton, SIGNAL(clicked()), SLOT(pickAlarmProgram()));
00182 alarmLayout->addWidget(mAlarmProgramButton);
00183
00184 if ( KOPrefs::instance()->mCompactDialogs ) {
00185 mAlarmSoundButton->hide();
00186 mAlarmProgramButton->hide();
00187 }
00188 }
00189
00190 void KOEditorGeneral::pickAlarmSound()
00191 {
00192 QString prefix = KGlobal::dirs()->findResourceDir("data", "korganizer/sounds/alert.wav");
00193 if (!mAlarmSoundButton->isOn()) {
00194 mAlarmSound = "";
00195 QToolTip::remove(mAlarmSoundButton);
00196 QToolTip::add(mAlarmSoundButton, i18n("No sound set"));
00197 } else {
00198 QString fileName(KFileDialog::getOpenFileName(prefix,
00199 i18n("*.wav|Wav Files"), 0));
00200 if (!fileName.isEmpty()) {
00201 mAlarmSound = fileName;
00202 QToolTip::remove(mAlarmSoundButton);
00203 QString dispStr = i18n("Playing '%1'").arg(fileName);
00204 QToolTip::add(mAlarmSoundButton, dispStr);
00205 mAlarmProgramButton->setOn(false);
00206 }
00207 }
00208 if (mAlarmSound.isEmpty())
00209 mAlarmSoundButton->setOn(false);
00210 }
00211
00212 void KOEditorGeneral::pickAlarmProgram()
00213 {
00214 if (!mAlarmProgramButton->isOn()) {
00215 mAlarmProgram = "";
00216 QToolTip::remove(mAlarmProgramButton);
00217 QToolTip::add(mAlarmProgramButton, i18n("No program set"));
00218 } else {
00219 QString fileName(KFileDialog::getOpenFileName(QString::null, QString::null, 0));
00220 if (!fileName.isEmpty()) {
00221 mAlarmProgram = fileName;
00222 QToolTip::remove(mAlarmProgramButton);
00223 QString dispStr = i18n("Running '%1'").arg(fileName);
00224 QToolTip::add(mAlarmProgramButton, dispStr);
00225 mAlarmSoundButton->setOn(false);
00226 }
00227 }
00228 if (mAlarmProgram.isEmpty())
00229 mAlarmProgramButton->setOn(false);
00230 }
00231
00232
00233
00234 void KOEditorGeneral::enableAlarmEdit(bool enable)
00235 {
00236 mAlarmTimeEdit->setEnabled(enable);
00237 mAlarmSoundButton->setEnabled(enable);
00238 mAlarmProgramButton->setEnabled(enable);
00239 mAlarmIncrCombo->setEnabled(enable);
00240 }
00241
00242 void KOEditorGeneral::disableAlarmEdit(bool disable)
00243 {
00244 enableAlarmEdit( !disable );
00245 }
00246
00247 void KOEditorGeneral::enableAlarm( bool enable )
00248 {
00249 enableAlarmEdit( enable );
00250 }
00251
00252 void KOEditorGeneral::alarmDisable(bool disable)
00253 {
00254 if (!disable) {
00255 mAlarmBell->setEnabled(true);
00256 mAlarmButton->setEnabled(true);
00257 } else {
00258 mAlarmBell->setEnabled(false);
00259 mAlarmButton->setEnabled(false);
00260 mAlarmButton->setChecked(false);
00261 mAlarmTimeEdit->setEnabled(false);
00262 mAlarmSoundButton->setEnabled(false);
00263 mAlarmProgramButton->setEnabled(false);
00264 mAlarmIncrCombo->setEnabled(false);
00265 }
00266 }
00267
00268 void KOEditorGeneral::setCategories(const QString &str)
00269 {
00270 mCategoriesLabel->setText(str);
00271 mCategories = str;
00272 }
00273
00274 void KOEditorGeneral::setDefaults(bool allDay)
00275 {
00276 #if 0
00277 mOwnerLabel->setText(i18n("Owner: ") + KOPrefs::instance()->fullName());
00278 #endif
00279
00280 enableAlarmEdit( !allDay );
00281
00282
00283 int alarmTime;
00284 int a[] = { 1,5,10,15,30 };
00285 int index = KOPrefs::instance()->mAlarmTime;
00286 if (index < 0 || index > 4) {
00287 alarmTime = 0;
00288 } else {
00289 alarmTime = a[index];
00290 }
00291 mAlarmTimeEdit->setText(QString::number(alarmTime));
00292
00293 enableAlarmEdit( false );
00294
00295 mSecrecyCombo->setCurrentItem(Incidence::SecrecyPublic);
00296 }
00297
00298 void KOEditorGeneral::readIncidence(Incidence *event)
00299 {
00300 mSummaryEdit->setText(event->summary());
00301 mLocationEdit->setText(event->location());
00302
00303 mDescriptionEdit->setText(event->description());
00304
00305 #if 0
00306
00307 mOwnerLabel->setText(i18n("Owner: ") + event->organizer());
00308 #endif
00309
00310 enableAlarmEdit( event->isAlarmEnabled() );
00311
00312 if(!event->isAlarmEnabled()) {
00313
00314 int alarmTime;
00315 int a[] = { 1,5,10,15,30 };
00316 int index = KOPrefs::instance()->mAlarmTime;
00317 if (index < 0 || index > 4) {
00318 alarmTime = 0;
00319 } else {
00320 alarmTime = a[index];
00321 }
00322 mAlarmTimeEdit->setText(QString::number(alarmTime));
00323 }
00324
00325 mSecrecyCombo->setCurrentItem(event->secrecy());
00326
00327
00328 Alarm::List alarms = event->alarms();
00329 Alarm::List::ConstIterator it;
00330 for( it = alarms.begin(); it != alarms.end(); ++it ) {
00331 Alarm *alarm = *it;
00332 int offset;
00333 if ( alarm->hasTime() ) {
00334 QDateTime t = alarm->time();
00335 offset = event->dtStart().secsTo( t );
00336 } else {
00337 offset = alarm->startOffset().asSeconds();
00338 }
00339 offset = offset / -60;
00340 if (offset % 60 == 0) {
00341 offset = offset / 60;
00342 mAlarmIncrCombo->setCurrentItem(1);
00343 }
00344 if (offset % 24 == 0) {
00345 offset = offset / 24;
00346 mAlarmIncrCombo->setCurrentItem(2);
00347 }
00348 mAlarmTimeEdit->setText(QString::number( offset ));
00349
00350 if (alarm->type() == Alarm::Procedure) {
00351 mAlarmProgram = alarm->programFile();
00352 mAlarmProgramButton->setOn(true);
00353 QString dispStr = i18n("Running '%1'").arg(mAlarmProgram);
00354 QToolTip::add(mAlarmProgramButton, dispStr);
00355 }
00356 else if (alarm->type() == Alarm::Audio) {
00357 mAlarmSound = alarm->audioFile();
00358 mAlarmSoundButton->setOn(true);
00359 QString dispStr = i18n("Playing '%1'").arg(mAlarmSound);
00360 QToolTip::add(mAlarmSoundButton, dispStr);
00361 }
00362 mAlarmButton->setChecked(alarm->enabled());
00363 enableAlarmEdit( alarm->enabled() );
00364
00365 break;
00366 }
00367
00368 setCategories(event->categoriesStr());
00369 }
00370
00371 void KOEditorGeneral::writeIncidence(Incidence *event)
00372 {
00373
00374
00375 event->setSummary(mSummaryEdit->text());
00376 event->setLocation(mLocationEdit->text());
00377 event->setDescription(mDescriptionEdit->text());
00378 event->setCategories(mCategories);
00379 event->setSecrecy(mSecrecyCombo->currentItem());
00380
00381
00382 if (mAlarmButton->isChecked()) {
00383 if (event->alarms().count() == 0) event->newAlarm();
00384 Alarm::List alarms = event->alarms();
00385 Alarm::List::ConstIterator it;
00386 for( it = alarms.begin(); it != alarms.end(); ++it ) {
00387 Alarm *alarm = *it;
00388 alarm->setEnabled(true);
00389
00390 QString tmpStr = mAlarmTimeEdit->text();
00391 int j = tmpStr.toInt() * -60;
00392 if (mAlarmIncrCombo->currentItem() == 1)
00393 j = j * 60;
00394 else if (mAlarmIncrCombo->currentItem() == 2)
00395 j = j * (60 * 24);
00396 alarm->setStartOffset( j );
00397
00398 if (!mAlarmProgram.isEmpty() && mAlarmProgramButton->isOn())
00399 alarm->setProcedureAlarm(mAlarmProgram);
00400 if (!mAlarmSound.isEmpty() && mAlarmSoundButton->isOn())
00401 alarm->setAudioAlarm(mAlarmSound);
00402 else
00403 alarm->setDisplayAlarm(QString::null);
00404
00405
00406 break;
00407 }
00408 } else {
00409 if ( !event->alarms().isEmpty() ) {
00410 Alarm *alarm = event->alarms().first();
00411 alarm->setEnabled(false);
00412 alarm->setType(Alarm::Invalid);
00413 }
00414 }
00415 }
00416
00417 void KOEditorGeneral::setSummary( const QString &text )
00418 {
00419 mSummaryEdit->setText( text );
00420 }
00421
00422 void KOEditorGeneral::setDescription( const QString &text )
00423 {
00424 mDescriptionEdit->setText( text );
00425 }
00426
00427 QObject *KOEditorGeneral::typeAheadReceiver() const
00428 {
00429 return mSummaryEdit;
00430 }