Akonadi Calendar

blockalarmsattribute.cpp
1 /*
2  SPDX-FileCopyrightText: 2009 Constantin Berzan <[email protected]>
3 
4  SPDX-FileCopyrightText: 2010 Klarälvdalens Datakonsult AB,
5  a KDAB Group company, [email protected],
6  author Tobias Koenig <[email protected]>
7 
8  SPDX-License-Identifier: LGPL-2.0-or-later
9 */
10 
11 #include "blockalarmsattribute.h"
12 #include <QByteArray>
13 #include <QDataStream>
14 #include <attributefactory.h>
15 
16 using namespace Akonadi;
17 
18 class Q_DECL_HIDDEN BlockAlarmsAttribute::Private
19 {
20 public:
21  int audio = 1;
22  int display = 1;
23  int email = 1;
24  int procedure = 1;
25 };
26 
28  : d(new Private)
29 {
30 }
31 
33 {
34  delete d;
35 }
36 
38 {
39  switch (type) {
41  d->audio = block;
42  return;
44  d->display = block;
45  return;
47  d->email = block;
48  return;
50  d->procedure = block;
51  return;
52  default:
53  return;
54  }
55 }
56 
58 {
63 }
64 
66 {
67  switch (type) {
69  return d->audio;
71  return d->display;
73  return d->email;
75  return d->procedure;
76  default:
77  return false;
78  }
79 }
80 
82 {
85 }
86 
87 QByteArray BlockAlarmsAttribute::type() const
88 {
89  static const QByteArray sType("BlockAlarmsAttribute");
90  return sType;
91 }
92 
93 BlockAlarmsAttribute *BlockAlarmsAttribute::clone() const
94 {
95  auto copy = new BlockAlarmsAttribute();
96  copy->d->audio = d->audio;
97  copy->d->display = d->display;
98  copy->d->email = d->email;
99  copy->d->procedure = d->procedure;
100 
101  return copy;
102 }
103 
104 QByteArray BlockAlarmsAttribute::serialized() const
105 {
106  QByteArray ba;
107  QDataStream stream(&ba, QIODevice::WriteOnly);
108  stream << d->audio;
109  stream << d->display;
110  stream << d->email;
111  stream << d->procedure;
112 
113  return ba;
114 }
115 
116 void BlockAlarmsAttribute::deserialize(const QByteArray &data)
117 {
118  // Pre-4.11, default behavior
119  if (data.isEmpty()) {
120  d->audio = 1;
121  d->display = 1;
122  d->email = 1;
123  d->procedure = 1;
124  } else {
125  QByteArray ba = data;
126  QDataStream stream(&ba, QIODevice::ReadOnly);
127  int i;
128  stream >> i;
129  d->audio = i;
130  stream >> i;
131  d->display = i;
132  stream >> i;
133  d->email = i;
134  stream >> i;
135  d->procedure = i;
136  }
137 }
138 
139 namespace
140 {
141 // Anonymous namespace; function is invisible outside this file.
142 bool dummy()
143 {
144  Akonadi::AttributeFactory::registerAttribute<Akonadi::BlockAlarmsAttribute>();
145 
146  return true;
147 }
148 
149 // Called when this library is loaded.
150 const bool registered = dummy();
151 } // namespace
void blockAlarmType(KCalendarCore::Alarm::Type type, bool block=true)
Blocks or unblocks given alarm type.
void blockEverything(bool block=true)
Blocks or unblocks every alarm type.
bool isEmpty() const const
bool isEverythingBlocked() const
Returns whether all alarms are blocked or not.
BlockAlarmsAttribute()
Creates a new block alarms attribute.
~BlockAlarmsAttribute() override
Destroys the block alarms attribute.
bool isAlarmTypeBlocked(KCalendarCore::Alarm::Type type) const
Returns whether given alarm type is blocked or not.
FreeBusyManager::Singleton.
An Attribute that marks that alarms from a calendar collection are blocked.
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Sat Jun 19 2021 23:12:24 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.