<commit_before>/*
  This file is part of KOrganizer.
  Copyright (c) 2000,2001 <NAME> <<EMAIL>>
  Copyright (C) 2003-2004 <NAME> <<EMAIL>>

  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; either version 2 of the License, or
  (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License along
  with this program; if not, write to the Free Software Foundation, Inc.,
  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

  As a special exception, permission is given to link this program
  with any edition of Qt, and distribute the resulting executable,
  without including the source code for Qt in the source distribution.
*/

#include "koeditorgeneraltodo.h"

#include <libkdepim/kdateedit.h>
#include <libkdepim/ktimeedit.h>
#include <libkdepim/ktimezonecombobox.h>

#include <KCal/Todo>

#include <KDialog>
#include <KLineEdit>
#include <KLocale>
#include <KMessageBox>
#include <KRichTextWidget>
#include <KSystemTimeZone>

#include <QBoxLayout>
#include <QCheckBox>
#include <QGroupBox>
#include <QLabel>
#include <QPushButton>
#include <QSpinBox>

KOEditorGeneralTodo::KOEditorGeneralTodo( KOrg::CalendarBase *calendar, QObject *parent )
  : KOEditorGeneral( calendar, parent )
{
  setType( "Todo" );
}

KOEditorGeneralTodo::~KOEditorGeneralTodo()
{
}

void KOEditorGeneralTodo::finishSetup()
{
  QWidget::setTabOrder( mSummaryEdit, mLocationEdit );
  QWidget::setTabOrder( mLocationEdit, mCategoriesButton );
  QWidget::setTabOrder( mCategoriesButton, mStartCheck );
  QWidget::setTabOrder( mStartCheck, mStartDateEdit );
  QWidget::setTabOrder( mStartDateEdit, mStartTimeEdit );
  QWidget::setTabOrder( mStartTimeEdit, mDueCheck );
  QWidget::setTabOrder( mDueCheck, mTimeZoneComboStart );
  QWidget::setTabOrder( mTimeZoneComboStart, mDueCheck );
  QWidget::setTabOrder( mDueCheck, mDueDateEdit );
  QWidget::setTabOrder( mDueDateEdit, mDueTimeEdit );
  QWidget::setTabOrder( mDueTimeEdit, mTimeZoneComboDue );
  QWidget::setTabOrder( mTimeZoneComboDue, mTimeButton );
  QWidget::setTabOrder( mTimeButton, mSecrecyCombo );
  QWidget::setTabOrder( mSecrecyCombo, mCompletedCombo );
  QWidget::setTabOrder( mCompletedCombo, mPriorityCombo );
  QWidget::setTabOrder( mPriorityCombo, mAlarmButton );
  QWidget::setTabOrder( mAlarmButton, mAlarmTimeEdit );
  QWidget::setTabOrder( mAlarmTimeEdit, mAlarmIncrCombo );
  QWidget::setTabOrder( mAlarmIncrCombo, mAlarmEditButton );
  QWidget::setTabOrder( mAlarmEditButton, mDescriptionEdit );

  mSummaryEdit->setFocus();
}

void KOEditorGeneralTodo::initTime( QWidget *parent, QBoxLayout *topLayout )
{
  QBoxLayout *timeLayout = new QVBoxLayout();
  topLayout->addItem( timeLayout );

  QGroupBox *timeGroupBox = new QGroupBox( i18n( "Date && Time" ), parent );
  timeGroupBox->setWhatsThis(
    i18n( "Sets options for due and start dates and times for this to-do." ) );
  timeLayout->addWidget( timeGroupBox );

  QGridLayout *layoutTimeBox = new QGridLayout( timeGroupBox );
  layoutTimeBox->setSpacing( KDialog::spacingHint() );

  // Timezone
  QString whatsThis = i18n( "Select the timezone for this event. It will also affect recurrences" );
#ifdef AKONADI_PORT_DISABLED
  mTimeZoneComboStart = new KPIM::KTimeZoneComboBox( mCalendar ? mCalendar->timeZones() : 0, timeGroupBox );
  mTimeZoneComboDue = new KPIM::KTimeZoneComboBox( mCalendar ? mCalendar->timeZones() : 0, timeGroupBox );

  if ( !KOPrefs::instance()->showTimeZoneSelectorInIncidenceEditor() ) {
    mTimeZoneComboStart->hide();
    mTimeZoneComboDue->hide();
  }
#endif
  layoutTimeBox->addWidget( mTimeZoneComboStart, 0, 3 );
  layoutTimeBox->addWidget( mTimeZoneComboDue, 1, 3 );
  mTimeZoneComboStart->setWhatsThis( whatsThis );
  mTimeZoneComboDue->setWhatsThis( whatsThis );
  mTimeZoneComboStart->selectLocalTimeSpec();
  mTimeZoneComboDue->selectLocalTimeSpec();

  whatsThis = i18n( "Sets the start date for this to-do" );
  mStartCheck = new QCheckBox( i18nc( "@option:check to-do start datetime",
                                      "Sta&rt:" ), timeGroupBox );
  mStartCheck->setWhatsThis( whatsThis );
  layoutTimeBox->addWidget( mStartCheck, 0, 0 );
  connect( mStartCheck, SIGNAL(toggled(bool)), SLOT(enableStartEdit(bool)) );
  connect( mStartCheck, SIGNAL(toggled(bool)), SLOT(startDateModified()) );

  mStartDateEdit = new KPIM::KDateEdit( timeGroupBox );
  mStartDateEdit->setWhatsThis( whatsThis );
  layoutTimeBox->addWidget( mStartDateEdit, 0, 1 );
  connect( mStartDateEdit, SIGNAL(dateChanged(const QDate&)), SLOT(startDateModified()) );

  mStartTimeEdit = new KPIM::KTimeEdit( timeGroupBox );
  mStartTimeEdit->setWhatsThis( i18n( "Sets the start time for this to-do." ) );
  layoutTimeBox->addWidget( mStartTimeEdit, 0, 2 );
  connect( mStartTimeEdit, SIGNAL(timeChanged(QTime)), SLOT(startDateModified()) );

  whatsThis = i18n( "Sets the due date for this to-do." );
  mDueCheck = new QCheckBox( i18nc( "to-do due datetime", "&Due:" ), timeGroupBox );
  mDueCheck->setWhatsThis( whatsThis );
  layoutTimeBox->addWidget( mDueCheck, 1, 0 );
  connect( mDueCheck, SIGNAL(toggled(bool)), SLOT(enableDueEdit(bool)) );
  connect( mDueCheck, SIGNAL(toggled(bool)), SLOT(showAlarm()) );
  connect( mDueCheck, SIGNAL(toggled(bool)), SIGNAL(dueDateEditToggle(bool)) );
  connect( mDueCheck, SIGNAL(toggled(bool)), SLOT(dateChanged()) );

  mDueDateEdit = new KPIM::KDateEdit( timeGroupBox );
  mDueDateEdit->setWhatsThis( whatsThis );
  layoutTimeBox->addWidget( mDueDateEdit, 1, 1 );
  connect( mDueDateEdit, SIGNAL(dateChanged(const QDate&)), SLOT(dateChanged()) );

  mDueTimeEdit = new KPIM::KTimeEdit( timeGroupBox );
  mDueTimeEdit->setWhatsThis( i18n( "Sets the due time for this to-do." ) );
  layoutTimeBox->addWidget( mDueTimeEdit, 1, 2 );
  connect( mDueTimeEdit, SIGNAL(timeChanged( QTime )), SLOT(dateChanged()) );

  mTimeButton = new QCheckBox( i18n( "Ti&me associated" ), timeGroupBox );
  mTimeButton->setWhatsThis(
    i18n( "Set if this to-do's start and due dates have times associated with them." ) );
  layoutTimeBox->addWidget( mTimeButton, 2, 0, 1, 3 );

  connect( mTimeButton, SIGNAL(toggled(bool)), SLOT(enableTimeEdits(bool)));
  connect( mTimeButton, SIGNAL(toggled(bool)), SLOT(dateChanged()) );

  connect( mTimeZoneComboStart, SIGNAL(currentIndexChanged(int)),
           this, SLOT(startDateModified()) );
  connect( mTimeZoneComboDue, SIGNAL(currentIndexChanged(int)),
           this, SLOT(dateChanged()) );

  // some more layouting
  layoutTimeBox->setColumnStretch( 3, 1 );

  QBoxLayout *secLayout = new QHBoxLayout();
  layoutTimeBox->addLayout( secLayout, 0, 4 );
  initSecrecy( timeGroupBox, secLayout );
}

void KOEditorGeneralTodo::initCompletion( QWidget *parent, QBoxLayout *topLayout )
{
  QString whatsThis = i18n( "Sets the current completion status of this to-do as a percentage." );
  mCompletedCombo = new KComboBox( parent );
  mCompletedCombo->setWhatsThis( whatsThis );
  for ( int i = 0; i <= 100; i+=10 ) {
    // xgettext:no-c-format
    QString label = i18nc( "Percent complete", "%1 %", i );
    mCompletedCombo->addItem( label );<commit_msg>don't crash on startup<commit_after>/*
  This file is part of KOrganizer.
  Copyright (c) 2000,2001 <NAME> <<EMAIL>>
  Copyright (C) 2003-2004 <NAME> <<EMAIL>>

  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; either version 2 of the License, or
  (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License along
  with this program; if not, write to the Free Software Foundation, Inc.,
  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

  As a special exception, permission is given to link this program
  with any edition of Qt, and distribute the resulting executable,
  without including the source code for Qt in the source distribution.
*/

#include "koeditorgeneraltodo.h"

#include <libkdepim/kdateedit.h>
#include <libkdepim/ktimeedit.h>
#include <libkdepim/ktimezonecombobox.h>

#include <KCal/Todo>

#include <KDialog>
#include <KLineEdit>
#include <KLocale>
#include <KMessageBox>
#include <KRichTextWidget>
#include <KSystemTimeZone>

#include <QBoxLayout>
#include <QCheckBox>
#include <QGroupBox>
#include <QLabel>
#include <QPushButton>
#include <QSpinBox>

KOEditorGeneralTodo::KOEditorGeneralTodo( KOrg::CalendarBase *calendar, QObject *parent )
  : KOEditorGeneral( calendar, parent )
{
  setType( "Todo" );
}

KOEditorGeneralTodo::~KOEditorGeneralTodo()
{
}

void KOEditorGeneralTodo::finishSetup()
{
  QWidget::setTabOrder( mSummaryEdit, mLocationEdit );
  QWidget::setTabOrder( mLocationEdit, mCategoriesButton );
  QWidget::setTabOrder( mCategoriesButton, mStartCheck );
  QWidget::setTabOrder( mStartCheck, mStartDateEdit );
  QWidget::setTabOrder( mStartDateEdit, mStartTimeEdit );
  QWidget::setTabOrder( mStartTimeEdit, mDueCheck );
  QWidget::setTabOrder( mDueCheck, mTimeZoneComboStart );
  QWidget::setTabOrder( mTimeZoneComboStart, mDueCheck );
  QWidget::setTabOrder( mDueCheck, mDueDateEdit );
  QWidget::setTabOrder( mDueDateEdit, mDueTimeEdit );
  QWidget::setTabOrder( mDueTimeEdit, mTimeZoneComboDue );
  QWidget::setTabOrder( mTimeZoneComboDue, mTimeButton );
  QWidget::setTabOrder( mTimeButton, mSecrecyCombo );
  QWidget::setTabOrder( mSecrecyCombo, mCompletedCombo );
  QWidget::setTabOrder( mCompletedCombo, mPriorityCombo );
  QWidget::setTabOrder( mPriorityCombo, mAlarmButton );
  QWidget::setTabOrder( mAlarmButton, mAlarmTimeEdit );
  QWidget::setTabOrder( mAlarmTimeEdit, mAlarmIncrCombo );
  QWidget::setTabOrder( mAlarmIncrCombo, mAlarmEditButton );
  QWidget::setTabOrder( mAlarmEditButton, mDescriptionEdit );

  mSummaryEdit->setFocus();
}

void KOEditorGeneralTodo::initTime( QWidget *parent, QBoxLayout *topLayout )
{
  QBoxLayout *timeLayout = new QVBoxLayout();
  topLayout->addItem( timeLayout );

  QGroupBox *timeGroupBox = new QGroupBox( i18n( "Date && Time" ), parent );
  timeGroupBox->setWhatsThis(
    i18n( "Sets options for due and start dates and times for this to-do." ) );
  timeLayout->addWidget( timeGroupBox );

  QGridLayout *layoutTimeBox = new QGridLayout( timeGroupBox );
  layoutTimeBox->setSpacing( KDialog::spacingHint() );

  // Timezone
  QString whatsThis = i18n( "Select the timezone for this event. It will also affect recurrences" );
#ifdef AKONADI_PORT_DISABLED
  mTimeZoneComboStart = new KPIM::KTimeZoneComboBox( mCalendar ? mCalendar->timeZones() : 0, timeGroupBox );
  mTimeZoneComboDue = new KPIM::KTimeZoneComboBox( mCalendar ? mCalendar->timeZones() : 0, timeGroupBox );

  if ( !KOPrefs::instance()->showTimeZoneSelectorInIncidenceEditor() ) {
    mTimeZoneComboStart->hide();
    mTimeZoneComboDue->hide();
  }

  layoutTimeBox->addWidget( mTimeZoneComboStart, 0, 3 );
  layoutTimeBox->addWidget( mTimeZoneComboDue, 1, 3 );
  mTimeZoneComboStart->setWhatsThis( whatsThis );
  mTimeZoneComboDue->setWhatsThis( whatsThis );
  mTimeZoneComboStart->selectLocalTimeSpec();
  mTimeZoneComboDue->selectLocalTimeSpec();
#endif

  whatsThis = i18n( "Sets the start date for this to-do" );
  mStartCheck = new QCheckBox( i18nc( "@option:check to-do start datetime",
                                      "Sta&rt:" ), timeGroupBox );
  mStartCheck->setWhatsThis( whatsThis );
  layoutTimeBox->addWidget( mStartCheck, 0, 0 );
  connect( mStartCheck, SIGNAL(toggled(bool)), SLOT(enableStartEdit(bool)) );
  connect( mStartCheck, SIGNAL(toggled(bool)), SLOT(startDateModified()) );

  mStartDateEdit = new KPIM::KDateEdit( timeGroupBox );
  mStartDateEdit->setWhatsThis( whatsThis );
  layoutTimeBox->addWidget( mStartDateEdit, 0, 1 );
  connect( mStartDateEdit, SIGNAL(dateChanged(const QDate&)), SLOT(startDateModified()) );

  mStartTimeEdit = new KPIM::KTimeEdit( timeGroupBox );
  mStartTimeEdit->setWhatsThis( i18n( "Sets the start time for this to-do." ) );
  layoutTimeBox->addWidget( mStartTimeEdit, 0, 2 );
  connect( mStartTimeEdit, SIGNAL(timeChanged(QTime)), SLOT(startDateModified()) );

  whatsThis = i18n( "Sets the due date for this to-do." );
  mDueCheck = new QCheckBox( i18nc( "to-do due datetime", "&Due:" ), timeGroupBox );
  mDueCheck->setWhatsThis( whatsThis );
  layoutTimeBox->addWidget( mDueCheck, 1, 0 );
  connect( mDueCheck, SIGNAL(toggled(bool)), SLOT(enableDueEdit(bool)) );
  connect( mDueCheck, SIGNAL(toggled(bool)), SLOT(showAlarm()) );
  connect( mDueCheck, SIGNAL(toggled(bool)), SIGNAL(dueDateEditToggle(bool)) );
  connect( mDueCheck, SIGNAL(toggled(bool)), SLOT(dateChanged()) );

  mDueDateEdit = new KPIM::KDateEdit( timeGroupBox );
  mDueDateEdit->setWhatsThis( whatsThis );
  layoutTimeBox->addWidget( mDueDateEdit, 1, 1 );
  connect( mDueDateEdit, SIGNAL(dateChanged(const QDate&)), SLOT(dateChanged()) );

  mDueTimeEdit = new KPIM::KTimeEdit( timeGroupBox );
  mDueTimeEdit->setWhatsThis( i18n( "Sets the due time for this to-do." ) );
  layoutTimeBox->addWidget( mDueTimeEdit, 1, 2 );
  connect( mDueTimeEdit, SIGNAL(timeChanged( QTime )), SLOT(dateChanged()) );

  mTimeButton = new QCheckBox( i18n( "Ti&me associated" ), timeGroupBox );
  mTimeButton->setWhatsThis(
    i18n( "Set if this to-do's start and due dates have times associated with them." ) );
  layoutTimeBox->addWidget( mTimeButton, 2, 0, 1, 3 );

  connect( mTimeButton, SIGNAL(toggled(bool)), SLOT(enableTimeEdits(bool)));
  connect( mTimeButton, SIGNAL(toggled(bool)), SLOT(dateChanged()) );

#ifdef AKONADI_PORT_DISABLED
  connect( mTimeZoneComboStart, SIGNAL(currentIndexChanged(int)),
           this, SLOT(startDateModified()) );
  connect( mTimeZoneComboDue, SIGNAL(currentIndexChanged(int)),
           this, SLOT(dateChanged()) );
#endif

  // some more layouting
  layoutTimeBox->setColumnStretch( 3, 1 );

  QBoxLayout *secLayout = new QHBoxLayout();
  layoutTimeBox->addLayout( secLayout, 0, 4 );
  initSecrecy( timeGroupBox, secLayout );
}

void KOEditorGeneralTodo::initCompletion( QWidget *parent, QBoxLayout *topLayout )
{
  QString whatsThis = i18n( "Sets the current completion status of this to-do as a percentage." );
  mCompletedCombo = new KComboBox( parent );
  mCompletedCombo->setWhatsThis( whatsThis );
  for ( int i = 0; i <= 100; i+=10 ) {
    // xgettext:no-c-format
    QString label = i18nc( "Percent complete", "%1 %", i );
    mCompletedCombo->addItem( label );
{'fraction_non_alphanumeric': 0.11719583778014941, 'fraction_numerical': 0.011606189967982924, 'mean_word_length': 5.445829750644884, 'pattern_counts': {'":': 0, '<': 49, '<?xml version=': 0, '>': 115, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7653710', 'n_tokens_mistral': 5157, 'n_tokens_neox': 4873, 'n_words': 1236}