Logo Search packages:      
Sourcecode: kdeadmin version File versions

KTTask::KTTask ( CTTask _cttask = 0,
const QString &  _caption = "" 
)

Initialize from CTTask.

Definition at line 102 of file kttask.cpp.

References CTTask::command, CTTask::comment, cttask, CTTask::dayOfMonth, CTTask::dayOfWeek, CTTask::enabled, CTUnit< min, max >::get(), CTDayOfWeek::getName(), CTMonth::getName(), CTTask::hour, key_accel, CTTask::minute, CTTask::month, CTTask::silent, slotAllDaysOfMonth(), slotAllDaysOfWeek(), slotAllHours(), slotAllMinutes(), slotAllMonths(), slotBrowse(), slotCancel(), slotCommandChanged(), slotDailyChanged(), slotDayOfMonthChanged(), slotDayOfWeekChanged(), slotHourChanged(), slotMinuteChanged(), slotMonthChanged(), slotOK(), CTTask::system(), and CTTask::user.

       :KDialog( 0, "kttask", true, WStyle_DialogBorder )
{
  cttask = _cttask;

  bool everyDay(true);

  QVBoxLayout *ml = new QVBoxLayout( this, KDialogBase::spacingHint() );

  QHBoxLayout *h1 = new QHBoxLayout( ml, KDialogBase::spacingHint() );

  // user
  labUser = new QLabel( i18n("&Run as:"), this, "labUser" );
  h1->addWidget( labUser );

  leUser = new QLineEdit( this, "leUser");
  labUser->setBuddy(leUser);
  h1->addWidget( leUser );

  if (cttask->system())
  {
    leUser->setText(QString::fromLocal8Bit(cttask->user.c_str()));
  }
  else
  {
    labUser->hide();
    leUser->hide();
  }

  // icon
  labIcon = new QLabel(this, "labIcon");
  labIcon->setFixedSize(32, 32);
  h1->addStretch( 1 );
  h1->addWidget( labIcon );

  // comment
  QHBoxLayout *h2 = new QHBoxLayout( ml, KDialogBase::spacingHint() );

  labComment = new QLabel( i18n("&Comment:"), this, "labComment" );
  h2->addWidget( labComment );

  leComment = new QLineEdit(this, "leComment");
  labComment->setBuddy(leComment);
  h2->addWidget( leComment );

  leComment->setText(QString::fromLocal8Bit(cttask->comment.c_str()));

  // command
  QHBoxLayout *h3 = new QHBoxLayout( ml, KDialogBase::spacingHint() );

  labCommand = new QLabel( i18n("&Program:"), this, "labCommand" );
  h3->addWidget( labCommand );

  leCommand = new QLineEdit(this, "leCommand");
  labCommand->setBuddy(leCommand);
  h3->addWidget( leCommand );

  leCommand->setText(QString::fromLocal8Bit(cttask->command.c_str()));

  labComment->setFixedWidth( QMAX( labComment->width(), labCommand->width()) );
  labCommand->setFixedWidth( QMAX( labComment->width(), labCommand->width()) );

  slotCommandChanged();

  pbBrowse = new QPushButton(this, "pbBrowse");
  pbBrowse->setText(i18n("&Browse..."));
  h3->addWidget( pbBrowse );
  
  QHBoxLayout *h3a = new QHBoxLayout( ml, KDialogBase::spacingHint() );

  // enabled
  chkEnabled = new QCheckBox(i18n("&Enabled"), this, "chkEnabled");
  chkEnabled->setChecked(cttask->enabled);
  h3a->addWidget( chkEnabled );

  // enabled
  chkSilent = new QCheckBox(i18n("&Silent"), this, "chkSilent");
  chkSilent->setChecked(cttask->silent);
  h3a->addWidget( chkSilent );

  QHBoxLayout *h4 = new QHBoxLayout( ml, KDialogBase::spacingHint() );

  ml->addSpacing( 2 * KDialogBase::spacingHint() );

  // months
  bgMonth = new QButtonGroup( i18n("Months"), this, "bgMonth");
  h4->addWidget( bgMonth );

  QVBoxLayout *vmonths = new QVBoxLayout( bgMonth, KDialogBase::spacingHint() );
  vmonths->addSpacing( 2 * KDialogBase::spacingHint() );

  for (int mo = 1; mo <= 12; mo++)
  {
    cbMonth[mo] = new QCheckBox(bgMonth, "cbMonth");
    cbMonth[mo]->setText(QString::fromLocal8Bit(cttask->month.getName(mo).c_str()));
    cbMonth[mo]->setChecked(cttask->month.get(mo));
    vmonths->addWidget( cbMonth[mo], AlignLeft );

    if (!cttask->month.get(mo)) everyDay = false;
  }
  pbAllMonths = new QPushButton(bgMonth, "pbAllMonths");
  pbAllMonths->setText( i18n("Set All") );
  vmonths->addWidget( pbAllMonths, AlignLeft );

  QVBoxLayout *v1 = new QVBoxLayout( h4, KDialogBase::spacingHint() );

  // days of the month
  bgDayOfMonth = new QButtonGroup( i18n("Days of Month"), this, "bgDayOfMonth");
  v1->addWidget( bgDayOfMonth );

  QPushButton* day;
  QString tmp;

  QVBoxLayout *vdays = new QVBoxLayout( bgDayOfMonth, KDialogBase::spacingHint() );
  vdays->addSpacing( 2 * KDialogBase::spacingHint() );
  QHBoxLayout *hdays = 0;

  for (int dm = 1; dm <= 31; dm++)
  {
    if( (dm % 7) == 1 )
      hdays = new QHBoxLayout( vdays, KDialogBase::spacingHint() );

    day = new KTPushButton(bgDayOfMonth);
    day->setFixedSize(25, 25);
    day->setText(tmp.setNum(dm));
    day->setToggleButton(true);
    day->setOn(cttask->dayOfMonth.get(dm));
    pbDayOfMonth[dm] = day;
    if (!cttask->dayOfMonth.get(dm)) everyDay = false;

    hdays->addWidget( day, AlignLeft );
  }
  hdays->addStretch( 1 );
  pbAllDaysOfMonth = new QPushButton(bgDayOfMonth, "pbAllDaysOfMonth");
  pbAllDaysOfMonth->setText( i18n("Set All") );
  hdays->addWidget( pbAllDaysOfMonth, AlignLeft );

  // days of the week
  bgDayOfWeek = new QButtonGroup( i18n("Days of Week"), this, "bgDayOfWeek");
  v1->addWidget( bgDayOfWeek );

  QVBoxLayout *v3 = new QVBoxLayout( bgDayOfWeek, KDialogBase::spacingHint() );
  v3->addSpacing( 2 * KDialogBase::spacingHint() );

  for (int dw = 1; dw <= 7; dw++)
  {
    cbDayOfWeek[dw] = new QCheckBox(bgDayOfWeek);
    cbDayOfWeek[dw]->setText(QString::fromLocal8Bit(cttask->dayOfWeek.getName(dw).c_str()));
    cbDayOfWeek[dw]->setChecked(cttask->dayOfWeek.get(dw));
    v3->addWidget( cbDayOfWeek[dw] );

    if (!cttask->dayOfWeek.get(dw)) everyDay = false;
  }
  pbAllDaysOfWeek = new QPushButton(bgDayOfWeek, "pbAllDaysOfWeek");
  pbAllDaysOfWeek->setText( i18n("Set All") );
  v3->addWidget( pbAllDaysOfWeek, AlignLeft );

  QVBoxLayout *v2 = new QVBoxLayout( h4, KDialogBase::spacingHint() );

  // daily
  bgEveryDay = new QButtonGroup( i18n("Daily"), this, "bgEveryDay");
  v2->addWidget( bgEveryDay );

  QVBoxLayout *v9 = new QVBoxLayout( bgEveryDay, KDialogBase::spacingHint() );
  v9->addSpacing( 2 * KDialogBase::spacingHint() );

  cbEveryDay = new QCheckBox( i18n("Run every day"), bgEveryDay, "cbEveryDay");
  cbEveryDay->setChecked(everyDay);
  v9->addWidget( cbEveryDay );

  // hours
  bgHour = new QButtonGroup( i18n("Hours"), this, "bgHour");
  v2->addWidget( bgHour );
  QVBoxLayout *v4 = new QVBoxLayout( bgHour, KDialogBase::spacingHint() );
  v4->addSpacing( 2 * KDialogBase::spacingHint() );

  labAM = new QLabel( i18n("AM"), bgHour, "labAM");
  labAM->setAlignment(AlignRight | AlignVCenter);
  v4->addWidget( labAM );


  for (int ho = 0; ho <= 23; ho++)
  {
    pbHour[ho] = new KTPushButton(bgHour);
    pbHour[ho]->setText(tmp.setNum(ho));
    pbHour[ho]->setToggleButton(true);
    pbHour[ho]->setOn(cttask->hour.get(ho));
    pbHour[ho]->setFixedSize(25, 25);
  }

  QHBoxLayout *hhours = new QHBoxLayout( v4, KDialogBase::spacingHint() );
  for (int ho1 = 0; ho1 <= 11; ho1++)
  {
    if( ho1 == 6 )
      hhours = new QHBoxLayout( v4, KDialogBase::spacingHint() );

    hhours->addWidget( pbHour[ho1] );
  }

  labPM = new QLabel( i18n("PM"), bgHour, "labPM");
  labPM->setAlignment(AlignRight | AlignVCenter);
  v4->addWidget( labPM );

  hhours = new QHBoxLayout( v4, KDialogBase::spacingHint() );
  for (int ho1 = 12; ho1 <= 23; ho1++)
  {
    if( ho1 == 18 )
      hhours = new QHBoxLayout( v4, KDialogBase::spacingHint() );

    hhours->addWidget( pbHour[ho1] );
  }
  
  hhours = new QHBoxLayout( v4, KDialogBase::spacingHint() );
  pbAllHours = new QPushButton(bgHour, "pbAllHours");
  pbAllHours->setText( i18n("Set All") );
  hhours->addWidget( pbAllHours, AlignLeft );
  
  // minutes
  bgMinute = new QButtonGroup( i18n("Minutes"), this, "bgMinute");
  v2->addWidget( bgMinute );
  QVBoxLayout *vmin = new QVBoxLayout( bgMinute, KDialogBase::spacingHint() );
  vmin->addSpacing( 2 * KDialogBase::spacingHint() );

  for (int mi = 0; mi <= 55; mi+=5)
  {
    pbMinute[mi] = new KTPushButton(bgMinute);
    pbMinute[mi]->setText(tmp.setNum(mi));
    pbMinute[mi]->setToggleButton(true);
    pbMinute[mi]->setOn(cttask->minute.get(mi));
    pbMinute[mi]->setFixedSize(25, 25);
  }

  QHBoxLayout *hmin = new QHBoxLayout( vmin, KDialogBase::spacingHint() );
  for (int mi1 = 0; mi1 <= 55; mi1+=5)
  {
    if( mi1 == 30 )
      hmin = new QHBoxLayout( vmin, KDialogBase::spacingHint() );

    hmin->addWidget( pbMinute[mi1] );
  }
  
  hmin = new QHBoxLayout( vmin, KDialogBase::spacingHint() );
  pbAllMinutes = new QPushButton(bgMinute, "pbAllMinutes");
  pbAllMinutes->setText( i18n("Set All") );
  hmin->addWidget( pbAllMinutes, AlignLeft );

  QHBoxLayout *h5 = new QHBoxLayout( ml, KDialogBase::spacingHint() );
  h5->addStretch( 1 );

  // OK
  pbOk = new KPushButton(KStdGuiItem::ok(), this, "pbOk");
  pbOk->setDefault(true);
  h5->addWidget( pbOk );

  // Cancel
  pbCancel = new KPushButton(KStdGuiItem::cancel(), this, "pbCancel");
  h5->addWidget( pbCancel );

  // window
  setIcon(KTIcon::application(true));
  setCaption(_caption/*i18n("Edit Task")*/);

  // set focus to first widget
  if (cttask->system())
  {
    leUser->setFocus();
  }
  else
  {
    leComment->setFocus();
  }

  // connect them up
  connect(pbBrowse, SIGNAL(clicked()), SLOT(slotBrowse()));
  connect(leCommand, SIGNAL(textChanged(const QString&)),
    SLOT(slotCommandChanged()));
  connect(cbEveryDay, SIGNAL(clicked()), SLOT(slotDailyChanged()));
  connect(pbOk, SIGNAL(clicked()), SLOT(slotOK()));
  connect(pbCancel, SIGNAL(clicked()), SLOT(slotCancel()));
  connect(pbAllMonths, SIGNAL(clicked()), SLOT(slotAllMonths()));
  for (int mo = 1; mo <= 12; mo++) {
    connect(cbMonth[mo], SIGNAL(clicked()), SLOT(slotMonthChanged()));
  }
  connect(pbAllDaysOfMonth, SIGNAL(clicked()), SLOT(slotAllDaysOfMonth()));
  for (int dm = 1; dm <= 31; dm++)
  {
    connect(pbDayOfMonth[dm], SIGNAL(clicked()), SLOT(slotDayOfMonthChanged()));
  }
  connect(pbAllDaysOfWeek, SIGNAL(clicked()), SLOT(slotAllDaysOfWeek()));
  for (int dw = 1; dw <= 7; dw++)
  {
    connect(cbDayOfWeek[dw], SIGNAL(clicked()), SLOT(slotDayOfWeekChanged()));
  }
  connect(pbAllHours, SIGNAL(clicked()), SLOT(slotAllHours()));
  for (int ho = 0; ho <= 23; ho++)
  {
    connect(pbHour[ho], SIGNAL(clicked()), SLOT(slotHourChanged()));
  }
  connect(pbAllMinutes, SIGNAL(clicked()), SLOT(slotAllMinutes()));
  for (int mi = 0; mi <= 55; mi+=5)
  {
    connect(pbMinute[mi], SIGNAL(clicked()), SLOT(slotMinuteChanged()));
  }
 
  // key acceleration
  key_accel = new KAccel(this);
  key_accel->insert(KStdAccel::Open, this, SLOT(slotOK()));
  key_accel->insert(KStdAccel::Close, this, SLOT(slotCancel()));
  key_accel->insert(KStdAccel::Quit, this, SLOT(slotCancel()));
  key_accel->readSettings();

  setFixedSize( minimumSize() );
  slotDailyChanged();
  slotMonthChanged();
  slotDayOfMonthChanged();
  slotDayOfWeekChanged();
  slotHourChanged();
  slotMinuteChanged();
}


Generated by  Doxygen 1.6.0   Back to index