• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepim API Reference
  • KDE Home
  • Contact Us
 

kalarm

  • sources
  • kde-4.12
  • kdepim
  • kalarm
commandoptions.cpp
Go to the documentation of this file.
1 /*
2  * commandoptions.cpp - extract command line options
3  * Program: kalarm
4  * Copyright © 2001-2012 by David Jarvie <djarvie@kde.org>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with this program; if not, write to the Free Software Foundation, Inc.,
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19  */
20 
21 #include "kalarm.h" //krazy:exclude=includes (kalarm.h must be first)
22 #include "commandoptions.h"
23 #include "alarmtime.h"
24 #include "kalarmapp.h"
25 #include "kamail.h"
26 
27 #include <kalarmcal/identities.h>
28 
29 #include <kcmdlineargs.h>
30 
31 #include <iostream>
32 
33 static bool convInterval(const QByteArray& timeParam, KARecurrence::Type&, int& timeInterval, bool allowMonthYear = false);
34 
35 void CommandOptions::setError(const QString& error)
36 {
37  if (mError.isEmpty())
38  mError = error;
39 }
40 
41 CommandOptions::CommandOptions()
42  : mCommand(NONE),
43  mEditActionSet(false),
44  mRecurrence(0),
45  mRepeatCount(0),
46  mRepeatInterval(0),
47  mLateCancel(0),
48  mBgColour(Preferences::defaultBgColour()),
49  mFgColour(Preferences::defaultFgColour()),
50  mReminderMinutes(0),
51  mAudioVolume(-1),
52  mFromID(0),
53  mFlags(KAEvent::DEFAULT_FONT),
54  mDisableAll(false)
55 {
56  mArgs = KCmdLineArgs::parsedArgs();
57 #ifndef NDEBUG
58  if (mArgs->isSet("test-set-time"))
59  {
60  QString time = mArgs->getOption("test-set-time");
61  if (!AlarmTime::convertTimeString(time.toLatin1(), mSimulationTime, KDateTime::realCurrentLocalDateTime(), true))
62  setErrorParameter("--test-set-time");
63  }
64 #endif
65  if (checkCommand("tray", TRAY))
66  {
67  }
68  if (checkCommand("list", LIST))
69  {
70  if (mArgs->count())
71  setErrorParameter("--list");
72  }
73  if (checkCommand("triggerEvent", TRIGGER_EVENT)
74  || checkCommand("cancelEvent", CANCEL_EVENT)
75  || checkCommand("edit", EDIT))
76  {
77 #ifdef USE_AKONADI
78  // Fetch the event ID. This can optionally include a prefix of the
79  // resource ID followed by a colon delimiter.
80  mEventId = EventId(mArgs->getOption(mCommandName));
81 #else
82  mEventId = mArgs->getOption(mCommandName);
83 #endif
84  }
85  if (checkCommand("edit-new-preset", EDIT_NEW_PRESET))
86  {
87  mTemplateName = mArgs->getOption(mCommandName);
88  }
89  if (checkCommand("file", NEW))
90  {
91  mEditType = EditAlarmDlg::DISPLAY;
92  mEditAction = KAEvent::FILE;
93  mEditActionSet = true;
94  mText = mArgs->getOption(mCommandName);
95  }
96  if (checkCommand("exec-display", NEW))
97  {
98  mEditType = EditAlarmDlg::DISPLAY;
99  mEditAction = KAEvent::COMMAND;
100  mEditActionSet = true;
101  mFlags |= KAEvent::DISPLAY_COMMAND;
102  mText = mArgs->getOption(mCommandName);
103  int n = mArgs->count();
104  for (int i = 0; i < n; ++i)
105  {
106  mText += QLatin1Char(' ');
107  mText += mArgs->arg(i);
108  }
109  }
110  if (checkCommand("exec", NEW))
111  {
112  mEditType = EditAlarmDlg::COMMAND;
113  mEditAction = KAEvent::COMMAND;
114  mEditActionSet = true;
115  mText = mArgs->getOption(mCommandName);
116  int n = mArgs->count();
117  for (int i = 0; i < n; ++i)
118  {
119  mText += QLatin1Char(' ');
120  mText += mArgs->arg(i);
121  }
122  }
123  if (checkCommand("mail", NEW))
124  {
125  mEditType = EditAlarmDlg::EMAIL;
126  mEditAction = KAEvent::EMAIL;
127  mEditActionSet = true;
128  }
129  if (checkCommand("edit-new-display", EDIT_NEW, EditAlarmDlg::DISPLAY))
130  {
131  mEditType = EditAlarmDlg::DISPLAY;
132  if (!mEditActionSet || (mEditAction != KAEvent::COMMAND && mEditAction != KAEvent::FILE))
133  {
134  mEditAction = KAEvent::MESSAGE;
135  mEditActionSet = true;
136  }
137  if (mArgs->count())
138  mText = mArgs->arg(0);
139  }
140  if (checkCommand("edit-new-command", EDIT_NEW))
141  {
142  mEditType = EditAlarmDlg::COMMAND;
143  mEditAction = KAEvent::COMMAND;
144  mEditActionSet = true;
145  }
146  if (checkCommand("edit-new-email", EDIT_NEW, EditAlarmDlg::EMAIL))
147  {
148  mEditType = EditAlarmDlg::EMAIL;
149  mEditAction = KAEvent::EMAIL;
150  mEditActionSet = true;
151  }
152  if (checkCommand("edit-new-audio", EDIT_NEW, EditAlarmDlg::AUDIO))
153  {
154  mEditType = EditAlarmDlg::AUDIO;
155  mEditAction = KAEvent::AUDIO;
156  mEditActionSet = true;
157  }
158  if (mError.isEmpty() && mCommand == NONE)
159  {
160  if (!mArgs->count())
161  {
162  if (checkCommand("play", NEW) || checkCommand("play-repeat", NEW))
163  {
164  mEditType = EditAlarmDlg::AUDIO;
165  mEditAction = KAEvent::AUDIO;
166  mEditActionSet = true;
167  }
168  }
169  else
170  {
171  kDebug() << "Message";
172  mCommand = NEW;
173  mCommandName = "message";
174  mEditType = EditAlarmDlg::DISPLAY;
175  mEditAction = KAEvent::MESSAGE;
176  mEditActionSet = true;
177  mText = mArgs->arg(0);
178  }
179  }
180  if (mEditActionSet && mEditAction == KAEvent::EMAIL)
181  {
182  if (mArgs->isSet("subject"))
183  mSubject = mArgs->getOption("subject");
184  if (mArgs->isSet("from-id"))
185  mFromID = Identities::identityUoid(mArgs->getOption("from-id"));
186  QStringList params = mArgs->getOptionList("mail");
187  for (int i = 0, count = params.count(); i < count; ++i)
188  {
189  QString addr = params[i];
190  if (!KAMail::checkAddress(addr))
191  setError(i18nc("@info:shell", "<icode>%1</icode>: invalid email address", QLatin1String("--mail")));
192 #ifdef USE_AKONADI
193  KCalCore::Person::Ptr person(new KCalCore::Person(QString(), addr));
194  mAddressees += person;
195 #else
196  mAddressees += KCal::Person(QString(), addr);
197 #endif
198  }
199  params = mArgs->getOptionList("attach");
200  for (int i = 0, count = params.count(); i < count; ++i)
201  mAttachments += params[i];
202  if (mArgs->count())
203  mText = mArgs->arg(0);
204  }
205  if (mArgs->isSet("disable-all"))
206  {
207  if (mCommand == TRIGGER_EVENT || mCommand == LIST)
208  setErrorIncompatible("--disable-all", mCommandName);
209  mDisableAll = true;
210  }
211 
212  // Check that other options are only specified for the
213  // correct main command options.
214  checkEditType(EditAlarmDlg::DISPLAY, "color");
215  checkEditType(EditAlarmDlg::DISPLAY, "colorfg");
216  checkEditType(EditAlarmDlg::DISPLAY, EditAlarmDlg::AUDIO, "play");
217  checkEditType(EditAlarmDlg::DISPLAY, EditAlarmDlg::AUDIO, "play-repeat");
218  checkEditType(EditAlarmDlg::DISPLAY, EditAlarmDlg::AUDIO, "volume");
219  checkEditType(EditAlarmDlg::DISPLAY, "speak");
220  checkEditType(EditAlarmDlg::DISPLAY, "beep");
221  checkEditType(EditAlarmDlg::DISPLAY, "reminder");
222  checkEditType(EditAlarmDlg::DISPLAY, "reminder-once");
223  checkEditType(EditAlarmDlg::DISPLAY, "ack-confirm");
224  checkEditType(EditAlarmDlg::DISPLAY, "auto-close");
225  checkEditType(EditAlarmDlg::EMAIL, "subject");
226  checkEditType(EditAlarmDlg::EMAIL, "from-id");
227  checkEditType(EditAlarmDlg::EMAIL, "attach");
228  checkEditType(EditAlarmDlg::EMAIL, "bcc");
229 
230  switch (mCommand)
231  {
232  case EDIT_NEW:
233  if (mArgs->isSet("disable"))
234  setErrorIncompatible("--disable", mCommandName);
235  // Fall through to NEW
236  case NEW:
237  {
238  // Display a message or file, execute a command, or send an email
239  if (mArgs->isSet("color"))
240  {
241  // Background colour is specified
242  QString colourText = mArgs->getOption("color");
243  if (colourText[0] == QLatin1Char('0') && colourText[1].toLower() == QLatin1Char('x'))
244  colourText.replace(0, 2, QLatin1String("#"));
245  mBgColour.setNamedColor(colourText);
246  if (!mBgColour.isValid())
247  setErrorParameter("--color");
248  }
249  if (mArgs->isSet("colorfg"))
250  {
251  // Foreground colour is specified
252  QString colourText = mArgs->getOption("colorfg");
253  if (colourText[0] == QLatin1Char('0') && colourText[1].toLower() == QLatin1Char('x'))
254  colourText.replace(0, 2, QLatin1String("#"));
255  mFgColour.setNamedColor(colourText);
256  if (!mFgColour.isValid())
257  setErrorParameter("--colorfg");
258  }
259 
260  if (mArgs->isSet("time"))
261  {
262  QByteArray dateTime = mArgs->getOption("time").toLocal8Bit();
263  if (!AlarmTime::convertTimeString(dateTime, mAlarmTime))
264  setErrorParameter("--time");
265  }
266  else
267  mAlarmTime = KDateTime::currentLocalDateTime();
268 
269  bool haveRecurrence = mArgs->isSet("recurrence");
270  if (haveRecurrence)
271  {
272  if (mArgs->isSet("login"))
273  setErrorIncompatible("--login", "--recurrence");
274  else if (mArgs->isSet("until"))
275  setErrorIncompatible("--until", "--recurrence");
276  QString rule = mArgs->getOption("recurrence");
277  mRecurrence = new KARecurrence;
278  mRecurrence->set(rule);
279  }
280  if (mArgs->isSet("interval"))
281  {
282  // Repeat count is specified
283  int count = 0;
284  KDateTime endTime;
285  if (mArgs->isSet("login"))
286  setErrorIncompatible("--login", "--interval");
287  bool ok;
288  if (mArgs->isSet("repeat"))
289  {
290  count = mArgs->getOption("repeat").toInt(&ok);
291  if (!ok || !count || count < -1 || (count < 0 && haveRecurrence))
292  setErrorParameter("--repeat");
293  }
294  else if (haveRecurrence)
295  setErrorRequires("--interval", "--repeat");
296  else if (mArgs->isSet("until"))
297  {
298  count = 0;
299  QByteArray dateTime = mArgs->getOption("until").toLocal8Bit();
300  bool ok;
301  if (mArgs->isSet("time"))
302  ok = AlarmTime::convertTimeString(dateTime, endTime, mAlarmTime);
303  else
304  ok = AlarmTime::convertTimeString(dateTime, endTime);
305  if (!ok)
306  setErrorParameter("--until");
307  else if (mAlarmTime.isDateOnly() && !endTime.isDateOnly())
308  setError(i18nc("@info:shell", "Invalid <icode>%1</icode> parameter for date-only alarm", QLatin1String("--until")));
309  if (!mAlarmTime.isDateOnly() && endTime.isDateOnly())
310  endTime.setTime(QTime(23,59,59));
311  if (endTime < mAlarmTime)
312  setError(i18nc("@info:shell", "<icode>%1</icode> earlier than <icode>%2</icode>", QLatin1String("--until"), QLatin1String("--time")));
313  }
314  else
315  count = -1;
316 
317  // Get the recurrence interval
318  int interval;
319  KARecurrence::Type recurType;
320  if (!convInterval(mArgs->getOption("interval").toLocal8Bit(), recurType, interval, !haveRecurrence))
321  setErrorParameter("--interval");
322  else if (mAlarmTime.isDateOnly() && recurType == KARecurrence::MINUTELY)
323  setError(i18nc("@info:shell", "Invalid <icode>%1</icode> parameter for date-only alarm", QLatin1String("--interval")));
324 
325  if (haveRecurrence)
326  {
327  if (mRecurrence)
328  {
329  // There is a also a recurrence specified, so set up a sub-repetition
330  int longestInterval = mRecurrence->longestInterval();
331  if (count * interval > longestInterval)
332  setError(i18nc("@info:shell", "Invalid <icode>%1</icode> and <icode>%2</icode> parameters: repetition is longer than <icode>%3</icode> interval",
333  QLatin1String("--interval"), QLatin1String("--repeat"), QLatin1String("--recurrence")));
334  mRepeatCount = count;
335  mRepeatInterval = interval;
336  }
337  }
338  else
339  {
340  // There is no other recurrence specified, so convert the repetition
341  // parameters into a KCal::Recurrence
342  mRecurrence = new KARecurrence;
343  mRecurrence->set(recurType, interval, count, mAlarmTime, endTime);
344  }
345  }
346  else
347  {
348  if (mArgs->isSet("repeat"))
349  setErrorRequires("--repeat", "--interval");
350  else if (mArgs->isSet("until"))
351  setErrorRequires("--until", "--interval");
352  }
353 
354  bool audioRepeat = mArgs->isSet("play-repeat");
355  if (audioRepeat || mArgs->isSet("play"))
356  {
357  // Play a sound with the alarm
358  const char* opt = audioRepeat ? "--play-repeat" : "--play";
359  if (audioRepeat && mArgs->isSet("play"))
360  setErrorIncompatible("--play", "--play-repeat");
361  if (mArgs->isSet("beep"))
362  setErrorIncompatible("--beep", opt);
363  else if (mArgs->isSet("speak"))
364  setErrorIncompatible("--speak", opt);
365  mAudioFile = mArgs->getOption(audioRepeat ? "play-repeat" : "play");
366  if (mArgs->isSet("volume"))
367  {
368  bool ok;
369  int volumepc = mArgs->getOption("volume").toInt(&ok);
370  if (!ok || volumepc < 0 || volumepc > 100)
371  setErrorParameter("--volume");
372  mAudioVolume = static_cast<float>(volumepc) / 100;
373  }
374  }
375  else if (mArgs->isSet("volume"))
376  setErrorRequires("--volume", "--play", "--play-repeat");
377  if (mArgs->isSet("speak"))
378  {
379  if (mArgs->isSet("beep"))
380  setErrorIncompatible("--beep", "--speak");
381  else if (!theApp()->speechEnabled())
382  setError(i18nc("@info:shell", "<icode>%1</icode> requires speech synthesis to be configured using Jovie", QLatin1String("--speak")));
383  }
384  bool onceOnly = mArgs->isSet("reminder-once");
385  if (mArgs->isSet("reminder") || onceOnly)
386  {
387  // Issue a reminder alarm in advance of or after the main alarm
388  if (onceOnly && mArgs->isSet("reminder"))
389  setErrorIncompatible("--reminder", "--reminder-once");
390  const char* opt = onceOnly ? "--reminder-once" : "--reminder";
391  KARecurrence::Type recurType;
392  QByteArray optval = mArgs->getOption(onceOnly ? "reminder-once" : "reminder").toLocal8Bit();
393  bool after = (optval[0] == '+');
394  if (after)
395  optval = optval.right(1);
396  if (!convInterval(optval, recurType, mReminderMinutes))
397  setErrorParameter(opt);
398  else if (recurType == KARecurrence::MINUTELY && mAlarmTime.isDateOnly())
399  setError(i18nc("@info:shell", "Invalid <icode>%1</icode> parameter for date-only alarm", QLatin1String(opt)));
400  if (after)
401  mReminderMinutes = -mReminderMinutes;
402  if (onceOnly)
403  mFlags |= KAEvent::REMINDER_ONCE;
404  }
405 
406  if (mArgs->isSet("late-cancel"))
407  {
408  KARecurrence::Type recurType;
409  bool ok = convInterval(mArgs->getOption("late-cancel").toLocal8Bit(), recurType, mLateCancel);
410  if (!ok)
411  setErrorParameter("--late-cancel");
412  }
413  else if (mArgs->isSet("auto-close"))
414  setErrorRequires("--auto-close", "--late-cancel");
415 
416  if (mArgs->isSet("ack-confirm"))
417  mFlags |= KAEvent::CONFIRM_ACK;
418  if (mArgs->isSet("auto-close"))
419  mFlags |= KAEvent::AUTO_CLOSE;
420  if (mArgs->isSet("beep"))
421  mFlags |= KAEvent::BEEP;
422  if (mArgs->isSet("speak"))
423  mFlags |= KAEvent::SPEAK;
424  if (mArgs->isSet("korganizer"))
425  mFlags |= KAEvent::COPY_KORGANIZER;
426  if (mArgs->isSet("disable"))
427  mFlags |= KAEvent::DISABLED;
428  if (audioRepeat)
429  mFlags |= KAEvent::REPEAT_SOUND;
430  if (mArgs->isSet("login"))
431  mFlags |= KAEvent::REPEAT_AT_LOGIN;
432  if (mArgs->isSet("bcc"))
433  mFlags |= KAEvent::EMAIL_BCC;
434  if (mAlarmTime.isDateOnly())
435  mFlags |= KAEvent::ANY_TIME;
436  break;
437  }
438  case NONE:
439  // No arguments - run interactively & display the main window
440  if (!mError.isEmpty())
441  break;
442  kDebug() << "Interactive";
443  if (mArgs->isSet("ack-confirm"))
444  mError += QLatin1String("--ack-confirm ");
445  if (mArgs->isSet("attach"))
446  mError += QLatin1String("--attach ");
447  if (mArgs->isSet("auto-close"))
448  mError += QLatin1String("--auto-close ");
449  if (mArgs->isSet("bcc"))
450  mError += QLatin1String("--bcc ");
451  if (mArgs->isSet("beep"))
452  mError += QLatin1String("--beep ");
453  if (mArgs->isSet("color"))
454  mError += QLatin1String("--color ");
455  if (mArgs->isSet("colorfg"))
456  mError += QLatin1String("--colorfg ");
457  if (mArgs->isSet("disable"))
458  mError += QLatin1String("--disable ");
459  if (mArgs->isSet("from-id"))
460  mError += QLatin1String("--from-id ");
461  if (mArgs->isSet("korganizer"))
462  mError += QLatin1String("--korganizer ");
463  if (mArgs->isSet("late-cancel"))
464  mError += QLatin1String("--late-cancel ");
465  if (mArgs->isSet("login"))
466  mError += QLatin1String("--login ");
467  if (mArgs->isSet("play"))
468  mError += QLatin1String("--play ");
469  if (mArgs->isSet("play-repeat"))
470  mError += QLatin1String("--play-repeat ");
471  if (mArgs->isSet("reminder"))
472  mError += QLatin1String("--reminder ");
473  if (mArgs->isSet("reminder-once"))
474  mError += QLatin1String("--reminder-once ");
475  if (mArgs->isSet("speak"))
476  mError += QLatin1String("--speak ");
477  if (mArgs->isSet("subject"))
478  mError += QLatin1String("--subject ");
479  if (mArgs->isSet("time"))
480  mError += QLatin1String("--time ");
481  if (mArgs->isSet("volume"))
482  mError += QLatin1String("--volume ");
483  if (!mError.isEmpty())
484  mError += i18nc("@info:shell", ": option(s) only valid with an appropriate action option or message");
485  break;
486  default:
487  break;
488  }
489 
490  mArgs->clear(); // free up memory
491 
492  if (!mError.isEmpty())
493  {
494  printError(mError);
495  mCommand = CMD_ERROR;
496  }
497 }
498 
499 void CommandOptions::printError(const QString& errmsg)
500 {
501  // Note: we can't use mArgs->usage() since that also quits any other
502  // running 'instances' of the program.
503  std::cerr << errmsg.toLocal8Bit().data()
504  << i18nc("@info:shell", "\nUse --help to get a list of available command line options.\n").toLocal8Bit().data();
505 }
506 
507 /******************************************************************************
508 * Check if the given command option is specified, and if so set mCommand etc.
509 * If another command option has also been detected, issue an error.
510 * If 'allowedEditType' is set, supersede any previous specification of that
511 * edit type with the given command option - this allows, e.g., --mail to be
512 * used along with --edit-new-email so the user can specify addressees.
513 */
514 bool CommandOptions::checkCommand(const QByteArray& command, Command code, EditAlarmDlg::Type allowedEditType)
515 {
516  if (!mError.isEmpty()
517  || !mArgs->isSet(command))
518  return false;
519  if (mCommand != NONE
520  && (allowedEditType == EditAlarmDlg::NO_TYPE
521  || (allowedEditType != EditAlarmDlg::NO_TYPE && (mCommand != NEW || mEditType != allowedEditType))))
522  setErrorIncompatible(mCommandName, "--" + command);
523  kDebug().nospace() << " --" << command;
524  mCommand = code;
525  mCommandName = command;
526  return true;
527 }
528 
529 // Set the error message to "--opt requires --opt2" or "--opt requires --opt2 or --opt3".
530 void CommandOptions::setErrorRequires(const char* opt, const char* opt2, const char* opt3)
531 {
532  if (!opt3)
533  setError(i18nc("@info:shell", "<icode>%1</icode> requires <icode>%2</icode>", QLatin1String(opt), QLatin1String(opt2)));
534  else
535  setError(i18nc("@info:shell", "<icode>%1</icode> requires <icode>%2</icode> or <icode>%3</icode>", QLatin1String(opt), QLatin1String(opt2), QLatin1String(opt3)));
536 }
537 
538 void CommandOptions::setErrorParameter(const char* opt)
539 {
540  setError(i18nc("@info:shell", "Invalid <icode>%1</icode> parameter", QLatin1String(opt)));
541 }
542 
543 void CommandOptions::setErrorIncompatible(const QByteArray& opt1, const QByteArray& opt2)
544 {
545  QByteArray o1 = opt1;
546  if (!opt1.startsWith("--") && opt1 != "message") //krazy:exclude=strings (it's a QByteArray)
547  o1.prepend("--");
548  QByteArray o2 = opt2;
549  if (!opt2.startsWith("--") && opt2 != "message") //krazy:exclude=strings (it's a QByteArray)
550  o2.prepend("--");
551  setError(i18nc("@info:shell", "<icode>%1</icode> incompatible with <icode>%2</icode>", QString::fromLatin1(o1), QString::fromLatin1(o2)));
552 }
553 
554 void CommandOptions::checkEditType(EditAlarmDlg::Type type1, EditAlarmDlg::Type type2, const QByteArray& optName)
555 {
556  if (mArgs->isSet(optName) && mCommand != NONE
557  && ((mCommand != NEW && mCommand != EDIT_NEW) || (mEditType != type1 && (type2 == EditAlarmDlg::NO_TYPE || mEditType != type2))))
558  setErrorIncompatible(optName, mCommandName);
559 }
560 
561 /******************************************************************************
562 * Convert a non-zero positive time interval command line parameter.
563 * 'timeInterval' receives the count for the recurType. If 'allowMonthYear' is
564 * false, weeks are converted to days in 'timeInterval'.
565 * Reply = true if successful.
566 */
567 static bool convInterval(const QByteArray& timeParam, KARecurrence::Type& recurType, int& timeInterval, bool allowMonthYear)
568 {
569  QByteArray timeString = timeParam;
570  // Get the recurrence interval
571  bool ok = true;
572  uint interval = 0;
573  uint length = timeString.length();
574  switch (timeString[length - 1])
575  {
576  case 'Y':
577  if (!allowMonthYear)
578  ok = false;
579  recurType = KARecurrence::ANNUAL_DATE;
580  timeString = timeString.left(length - 1);
581  break;
582  case 'W':
583  recurType = KARecurrence::WEEKLY;
584  timeString = timeString.left(length - 1);
585  break;
586  case 'D':
587  recurType = KARecurrence::DAILY;
588  timeString = timeString.left(length - 1);
589  break;
590  case 'M':
591  {
592  int i = timeString.indexOf('H');
593  if (i < 0)
594  {
595  if (!allowMonthYear)
596  ok = false;
597  recurType = KARecurrence::MONTHLY_DAY;
598  timeString = timeString.left(length - 1);
599  }
600  else
601  {
602  recurType = KARecurrence::MINUTELY;
603  interval = timeString.left(i).toUInt(&ok) * 60;
604  timeString = timeString.mid(i + 1, length - i - 2);
605  }
606  break;
607  }
608  default: // should be a digit
609  recurType = KARecurrence::MINUTELY;
610  break;
611  }
612  if (ok)
613  interval += timeString.toUInt(&ok);
614  if (!allowMonthYear)
615  {
616  // Convert time interval to minutes
617  switch (recurType)
618  {
619  case KARecurrence::WEEKLY:
620  interval *= 7;
621  // fall through to DAILY
622  case KARecurrence::DAILY:
623  interval *= 24*60;
624  break;
625  default:
626  break;
627  }
628  }
629  timeInterval = static_cast<int>(interval);
630  return ok && interval;
631 }
632 
633 // vim: et sw=4:
EditAlarmDlg::EMAIL
Definition: editdlg.h:65
CommandOptions::CMD_ERROR
Definition: commandoptions.h:45
CommandOptions::printError
static void printError(const QString &errmsg)
Definition: commandoptions.cpp:499
EditAlarmDlg::DISPLAY
Definition: editdlg.h:65
EditAlarmDlg::COMMAND
Definition: editdlg.h:65
CommandOptions::LIST
Definition: commandoptions.h:54
alarmtime.h
KAMail::checkAddress
static int checkAddress(QString &address)
Definition: kamail.cpp:507
CommandOptions::CANCEL_EVENT
Definition: commandoptions.h:49
CommandOptions::NEW
Definition: commandoptions.h:53
commandoptions.h
CommandOptions::EDIT
Definition: commandoptions.h:50
kalarmapp.h
the KAlarm application object
AlarmTime::convertTimeString
static bool convertTimeString(const QByteArray &timeString, KDateTime &dateTime, const KDateTime &defaultDt=KDateTime(), bool allowTZ=true)
Definition: alarmtime.cpp:111
CommandOptions::command
Command command() const
Definition: commandoptions.h:57
CommandOptions::CommandOptions
CommandOptions()
Definition: commandoptions.cpp:41
CommandOptions::NONE
Definition: commandoptions.h:46
convInterval
static bool convInterval(const QByteArray &timeParam, KARecurrence::Type &, int &timeInterval, bool allowMonthYear=false)
Definition: commandoptions.cpp:567
theApp
KAlarmApp * theApp()
Definition: kalarmapp.h:259
EditAlarmDlg::NO_TYPE
Definition: editdlg.h:65
CommandOptions::EDIT_NEW
Definition: commandoptions.h:52
CommandOptions::TRIGGER_EVENT
Definition: commandoptions.h:48
kamail.h
EventId
Unique event identifier for Akonadi.
Definition: eventid.h:38
EditAlarmDlg::Type
Type
Definition: editdlg.h:65
kalarm.h
Preferences
Definition: preferences.h:36
EditAlarmDlg::AUDIO
Definition: editdlg.h:65
CommandOptions::EDIT_NEW_PRESET
Definition: commandoptions.h:51
KAlarmApp::speechEnabled
bool speechEnabled() const
Definition: kalarmapp.h:64
CommandOptions::TRAY
Definition: commandoptions.h:47
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:59:10 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kalarm

Skip menu "kalarm"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal