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

kalarm

  • sources
  • kde-4.14
  • 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-2016 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 intervalOfType;
319  KARecurrence::Type recurType;
320  if (!convInterval(mArgs->getOption("interval").toLocal8Bit(), recurType, intervalOfType, !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  // In this case, 'intervalOfType' is in minutes.
331  mRepeatInterval = KCalCore::Duration(intervalOfType * 60);
332  KCalCore::Duration longestInterval = mRecurrence->longestInterval();
333  if (mRepeatInterval * count > longestInterval)
334  setError(i18nc("@info:shell", "Invalid <icode>%1</icode> and <icode>%2</icode> parameters: repetition is longer than <icode>%3</icode> interval",
335  QLatin1String("--interval"), QLatin1String("--repeat"), QLatin1String("--recurrence")));
336  mRepeatCount = count;
337  }
338  }
339  else
340  {
341  // There is no other recurrence specified, so convert the repetition
342  // parameters into a KCal::Recurrence
343  mRecurrence = new KARecurrence;
344  mRecurrence->set(recurType, intervalOfType, count, mAlarmTime, endTime);
345  }
346  }
347  else
348  {
349  if (mArgs->isSet("repeat"))
350  setErrorRequires("--repeat", "--interval");
351  else if (mArgs->isSet("until"))
352  setErrorRequires("--until", "--interval");
353  }
354 
355  bool audioRepeat = mArgs->isSet("play-repeat");
356  if (audioRepeat || mArgs->isSet("play"))
357  {
358  // Play a sound with the alarm
359  const char* opt = audioRepeat ? "--play-repeat" : "--play";
360  if (audioRepeat && mArgs->isSet("play"))
361  setErrorIncompatible("--play", "--play-repeat");
362  if (mArgs->isSet("beep"))
363  setErrorIncompatible("--beep", opt);
364  else if (mArgs->isSet("speak"))
365  setErrorIncompatible("--speak", opt);
366  mAudioFile = mArgs->getOption(audioRepeat ? "play-repeat" : "play");
367  if (mArgs->isSet("volume"))
368  {
369  bool ok;
370  int volumepc = mArgs->getOption("volume").toInt(&ok);
371  if (!ok || volumepc < 0 || volumepc > 100)
372  setErrorParameter("--volume");
373  mAudioVolume = static_cast<float>(volumepc) / 100;
374  }
375  }
376  else if (mArgs->isSet("volume"))
377  setErrorRequires("--volume", "--play", "--play-repeat");
378  if (mArgs->isSet("speak"))
379  {
380  if (mArgs->isSet("beep"))
381  setErrorIncompatible("--beep", "--speak");
382  else if (!theApp()->speechEnabled())
383  setError(i18nc("@info:shell", "<icode>%1</icode> requires speech synthesis to be configured using Jovie", QLatin1String("--speak")));
384  }
385  bool onceOnly = mArgs->isSet("reminder-once");
386  if (mArgs->isSet("reminder") || onceOnly)
387  {
388  // Issue a reminder alarm in advance of or after the main alarm
389  if (onceOnly && mArgs->isSet("reminder"))
390  setErrorIncompatible("--reminder", "--reminder-once");
391  const char* opt = onceOnly ? "--reminder-once" : "--reminder";
392  KARecurrence::Type recurType;
393  QByteArray optval = mArgs->getOption(onceOnly ? "reminder-once" : "reminder").toLocal8Bit();
394  bool after = (optval[0] == '+');
395  if (after)
396  optval.remove(0, 1); // it's a reminder after the main alarm
397  if (!convInterval(optval, recurType, mReminderMinutes))
398  setErrorParameter(opt);
399  else if (recurType == KARecurrence::MINUTELY && mAlarmTime.isDateOnly())
400  setError(i18nc("@info:shell", "Invalid <icode>%1</icode> parameter for date-only alarm", QLatin1String(opt)));
401  if (after)
402  mReminderMinutes = -mReminderMinutes;
403  if (onceOnly)
404  mFlags |= KAEvent::REMINDER_ONCE;
405  }
406 
407  if (mArgs->isSet("late-cancel"))
408  {
409  KARecurrence::Type recurType;
410  bool ok = convInterval(mArgs->getOption("late-cancel").toLocal8Bit(), recurType, mLateCancel);
411  if (!ok)
412  setErrorParameter("--late-cancel");
413  }
414  else if (mArgs->isSet("auto-close"))
415  setErrorRequires("--auto-close", "--late-cancel");
416 
417  if (mArgs->isSet("ack-confirm"))
418  mFlags |= KAEvent::CONFIRM_ACK;
419  if (mArgs->isSet("auto-close"))
420  mFlags |= KAEvent::AUTO_CLOSE;
421  if (mArgs->isSet("beep"))
422  mFlags |= KAEvent::BEEP;
423  if (mArgs->isSet("speak"))
424  mFlags |= KAEvent::SPEAK;
425  if (mArgs->isSet("korganizer"))
426  mFlags |= KAEvent::COPY_KORGANIZER;
427  if (mArgs->isSet("disable"))
428  mFlags |= KAEvent::DISABLED;
429  if (audioRepeat)
430  mFlags |= KAEvent::REPEAT_SOUND;
431  if (mArgs->isSet("login"))
432  mFlags |= KAEvent::REPEAT_AT_LOGIN;
433  if (mArgs->isSet("bcc"))
434  mFlags |= KAEvent::EMAIL_BCC;
435  if (mAlarmTime.isDateOnly())
436  mFlags |= KAEvent::ANY_TIME;
437  break;
438  }
439  case NONE:
440  // No arguments - run interactively & display the main window
441  if (!mError.isEmpty())
442  break;
443  kDebug() << "Interactive";
444  if (mArgs->isSet("ack-confirm"))
445  mError += QLatin1String("--ack-confirm ");
446  if (mArgs->isSet("attach"))
447  mError += QLatin1String("--attach ");
448  if (mArgs->isSet("auto-close"))
449  mError += QLatin1String("--auto-close ");
450  if (mArgs->isSet("bcc"))
451  mError += QLatin1String("--bcc ");
452  if (mArgs->isSet("beep"))
453  mError += QLatin1String("--beep ");
454  if (mArgs->isSet("color"))
455  mError += QLatin1String("--color ");
456  if (mArgs->isSet("colorfg"))
457  mError += QLatin1String("--colorfg ");
458  if (mArgs->isSet("disable"))
459  mError += QLatin1String("--disable ");
460  if (mArgs->isSet("from-id"))
461  mError += QLatin1String("--from-id ");
462  if (mArgs->isSet("korganizer"))
463  mError += QLatin1String("--korganizer ");
464  if (mArgs->isSet("late-cancel"))
465  mError += QLatin1String("--late-cancel ");
466  if (mArgs->isSet("login"))
467  mError += QLatin1String("--login ");
468  if (mArgs->isSet("play"))
469  mError += QLatin1String("--play ");
470  if (mArgs->isSet("play-repeat"))
471  mError += QLatin1String("--play-repeat ");
472  if (mArgs->isSet("reminder"))
473  mError += QLatin1String("--reminder ");
474  if (mArgs->isSet("reminder-once"))
475  mError += QLatin1String("--reminder-once ");
476  if (mArgs->isSet("speak"))
477  mError += QLatin1String("--speak ");
478  if (mArgs->isSet("subject"))
479  mError += QLatin1String("--subject ");
480  if (mArgs->isSet("time"))
481  mError += QLatin1String("--time ");
482  if (mArgs->isSet("volume"))
483  mError += QLatin1String("--volume ");
484  if (!mError.isEmpty())
485  mError += i18nc("@info:shell", ": option(s) only valid with an appropriate action option or message");
486  break;
487  default:
488  break;
489  }
490 
491  mArgs->clear(); // free up memory
492 
493  if (!mError.isEmpty())
494  {
495  printError(mError);
496  mCommand = CMD_ERROR;
497  }
498 }
499 
500 void CommandOptions::printError(const QString& errmsg)
501 {
502  // Note: we can't use mArgs->usage() since that also quits any other
503  // running 'instances' of the program.
504  std::cerr << errmsg.toLocal8Bit().data()
505  << i18nc("@info:shell", "\nUse --help to get a list of available command line options.\n").toLocal8Bit().data();
506 }
507 
508 /******************************************************************************
509 * Check if the given command option is specified, and if so set mCommand etc.
510 * If another command option has also been detected, issue an error.
511 * If 'allowedEditType' is set, supersede any previous specification of that
512 * edit type with the given command option - this allows, e.g., --mail to be
513 * used along with --edit-new-email so the user can specify addressees.
514 */
515 bool CommandOptions::checkCommand(const QByteArray& command, Command code, EditAlarmDlg::Type allowedEditType)
516 {
517  if (!mError.isEmpty()
518  || !mArgs->isSet(command))
519  return false;
520  if (mCommand != NONE
521  && (allowedEditType == EditAlarmDlg::NO_TYPE
522  || (allowedEditType != EditAlarmDlg::NO_TYPE && (mCommand != NEW || mEditType != allowedEditType))))
523  setErrorIncompatible(mCommandName, "--" + command);
524  kDebug().nospace() << " --" << command;
525  mCommand = code;
526  mCommandName = command;
527  return true;
528 }
529 
530 // Set the error message to "--opt requires --opt2" or "--opt requires --opt2 or --opt3".
531 void CommandOptions::setErrorRequires(const char* opt, const char* opt2, const char* opt3)
532 {
533  if (!opt3)
534  setError(i18nc("@info:shell", "<icode>%1</icode> requires <icode>%2</icode>", QLatin1String(opt), QLatin1String(opt2)));
535  else
536  setError(i18nc("@info:shell", "<icode>%1</icode> requires <icode>%2</icode> or <icode>%3</icode>", QLatin1String(opt), QLatin1String(opt2), QLatin1String(opt3)));
537 }
538 
539 void CommandOptions::setErrorParameter(const char* opt)
540 {
541  setError(i18nc("@info:shell", "Invalid <icode>%1</icode> parameter", QLatin1String(opt)));
542 }
543 
544 void CommandOptions::setErrorIncompatible(const QByteArray& opt1, const QByteArray& opt2)
545 {
546  QByteArray o1 = opt1;
547  if (!opt1.startsWith("--") && opt1 != "message") //krazy:exclude=strings (it's a QByteArray)
548  o1.prepend("--");
549  QByteArray o2 = opt2;
550  if (!opt2.startsWith("--") && opt2 != "message") //krazy:exclude=strings (it's a QByteArray)
551  o2.prepend("--");
552  setError(i18nc("@info:shell", "<icode>%1</icode> incompatible with <icode>%2</icode>", QString::fromLatin1(o1), QString::fromLatin1(o2)));
553 }
554 
555 void CommandOptions::checkEditType(EditAlarmDlg::Type type1, EditAlarmDlg::Type type2, const QByteArray& optName)
556 {
557  if (mArgs->isSet(optName) && mCommand != NONE
558  && ((mCommand != NEW && mCommand != EDIT_NEW) || (mEditType != type1 && (type2 == EditAlarmDlg::NO_TYPE || mEditType != type2))))
559  setErrorIncompatible(optName, mCommandName);
560 }
561 
562 /******************************************************************************
563 * Convert a non-zero positive time interval command line parameter.
564 * 'timeInterval' receives the count for the recurType. If 'allowMonthYear' is
565 * false, weeks and days are converted to minutes.
566 * Reply = true if successful.
567 */
568 static bool convInterval(const QByteArray& timeParam, KARecurrence::Type& recurType, int& timeInterval, bool allowMonthYear)
569 {
570  QByteArray timeString = timeParam;
571  // Get the recurrence interval
572  bool ok = true;
573  uint interval = 0;
574  uint length = timeString.length();
575  switch (timeString[length - 1])
576  {
577  case 'Y':
578  if (!allowMonthYear)
579  ok = false;
580  recurType = KARecurrence::ANNUAL_DATE;
581  timeString = timeString.left(length - 1);
582  break;
583  case 'W':
584  recurType = KARecurrence::WEEKLY;
585  timeString = timeString.left(length - 1);
586  break;
587  case 'D':
588  recurType = KARecurrence::DAILY;
589  timeString = timeString.left(length - 1);
590  break;
591  case 'M':
592  {
593  int i = timeString.indexOf('H');
594  if (i < 0)
595  {
596  if (!allowMonthYear)
597  ok = false;
598  recurType = KARecurrence::MONTHLY_DAY;
599  timeString = timeString.left(length - 1);
600  }
601  else
602  {
603  recurType = KARecurrence::MINUTELY;
604  interval = timeString.left(i).toUInt(&ok) * 60;
605  timeString = timeString.mid(i + 1, length - i - 2);
606  }
607  break;
608  }
609  default: // should be a digit
610  recurType = KARecurrence::MINUTELY;
611  break;
612  }
613  if (ok)
614  interval += timeString.toUInt(&ok);
615  if (!allowMonthYear)
616  {
617  // Convert time interval to minutes
618  switch (recurType)
619  {
620  case KARecurrence::WEEKLY:
621  interval *= 7;
622  // fall through to DAILY
623  case KARecurrence::DAILY:
624  interval *= 24*60;
625  recurType = KARecurrence::MINUTELY;
626  break;
627  default:
628  break;
629  }
630  }
631  timeInterval = static_cast<int>(interval);
632  return ok && interval;
633 }
634 
635 // vim: et sw=4:
QByteArray::toUInt
uint toUInt(bool *ok, int base) const
EditAlarmDlg::EMAIL
Definition: editdlg.h:64
CommandOptions::CMD_ERROR
Definition: commandoptions.h:45
CommandOptions::printError
static void printError(const QString &errmsg)
Definition: commandoptions.cpp:500
EditAlarmDlg::DISPLAY
Definition: editdlg.h:64
EditAlarmDlg::COMMAND
Definition: editdlg.h:64
QByteArray
CommandOptions::LIST
Definition: commandoptions.h:54
alarmtime.h
KAMail::checkAddress
static int checkAddress(QString &address)
Definition: kamail.cpp:511
QByteArray::startsWith
bool startsWith(const QByteArray &ba) const
CommandOptions::CANCEL_EVENT
Definition: commandoptions.h:49
CommandOptions::NEW
Definition: commandoptions.h:53
QByteArray::length
int length() const
QColor::setNamedColor
void setNamedColor(const QString &name)
commandoptions.h
QTime
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
QByteArray::indexOf
int indexOf(char ch, int from) const
CommandOptions::command
Command command() const
Definition: commandoptions.h:57
QList::count
int count(const T &value) const
CommandOptions::CommandOptions
CommandOptions()
Definition: commandoptions.cpp:41
QByteArray::prepend
QByteArray & prepend(char ch)
QString::isEmpty
bool isEmpty() const
QString
CommandOptions::NONE
Definition: commandoptions.h:46
convInterval
static bool convInterval(const QByteArray &timeParam, KARecurrence::Type &, int &timeInterval, bool allowMonthYear=false)
Definition: commandoptions.cpp:568
QByteArray::mid
QByteArray mid(int pos, int len) const
theApp
KAlarmApp * theApp()
Definition: kalarmapp.h:263
EditAlarmDlg::NO_TYPE
Definition: editdlg.h:64
QStringList
CommandOptions::EDIT_NEW
Definition: commandoptions.h:52
QString::toLocal8Bit
QByteArray toLocal8Bit() const
QLatin1Char
CommandOptions::TRIGGER_EVENT
Definition: commandoptions.h:48
QString::replace
QString & replace(int position, int n, QChar after)
kamail.h
EventId
Unique event identifier for Akonadi.
Definition: eventid.h:38
QByteArray::left
QByteArray left(int len) const
QString::toLatin1
QByteArray toLatin1() const
EditAlarmDlg::Type
Type
Definition: editdlg.h:64
QLatin1String
kalarm.h
QByteArray::data
char * data()
QString::fromLatin1
QString fromLatin1(const char *str, int size)
Preferences
Definition: preferences.h:36
EditAlarmDlg::AUDIO
Definition: editdlg.h:64
QByteArray::remove
QByteArray & remove(int pos, int len)
CommandOptions::EDIT_NEW_PRESET
Definition: commandoptions.h:51
QColor::isValid
bool isValid() const
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-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:34:51 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
  • pimprint

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