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 <Akonadi/AttributeFactory>
13 #include <QByteArray>
14 #include <QDataStream>
15 #include <QIODevice>
16 
17 using namespace Akonadi;
18 
19 class Akonadi::BlockAlarmsAttributePrivate
20 {
21 public:
22  int audio = 1;
23  int display = 1;
24  int email = 1;
25  int procedure = 1;
26 };
27 
29  : d(new BlockAlarmsAttributePrivate)
30 {
31 }
32 
34 
36 {
37  switch (type) {
39  d->audio = block;
40  return;
42  d->display = block;
43  return;
45  d->email = block;
46  return;
48  d->procedure = block;
49  return;
50  default:
51  return;
52  }
53 }
54 
56 {
61 }
62 
64 {
65  switch (type) {
67  return d->audio;
69  return d->display;
71  return d->email;
73  return d->procedure;
74  default:
75  return false;
76  }
77 }
78 
80 {
83 }
84 
85 QByteArray BlockAlarmsAttribute::type() const
86 {
87  static const QByteArray sType("BlockAlarmsAttribute");
88  return sType;
89 }
90 
91 BlockAlarmsAttribute *BlockAlarmsAttribute::clone() const
92 {
93  auto copy = new BlockAlarmsAttribute();
94  copy->d->audio = d->audio;
95  copy->d->display = d->display;
96  copy->d->email = d->email;
97  copy->d->procedure = d->procedure;
98 
99  return copy;
100 }
101 
102 QByteArray BlockAlarmsAttribute::serialized() const
103 {
104  QByteArray ba;
105  QDataStream stream(&ba, QIODevice::WriteOnly);
106  stream << d->audio;
107  stream << d->display;
108  stream << d->email;
109  stream << d->procedure;
110 
111  return ba;
112 }
113 
114 void BlockAlarmsAttribute::deserialize(const QByteArray &data)
115 {
116  // Pre-4.11, default behavior
117  if (data.isEmpty()) {
118  d->audio = 1;
119  d->display = 1;
120  d->email = 1;
121  d->procedure = 1;
122  } else {
123  QByteArray ba = data;
124  QDataStream stream(&ba, QIODevice::ReadOnly);
125  int i;
126  stream >> i;
127  d->audio = i;
128  stream >> i;
129  d->display = i;
130  stream >> i;
131  d->email = i;
132  stream >> i;
133  d->procedure = i;
134  }
135 }
136 
137 namespace
138 {
139 // Anonymous namespace; function is invisible outside this file.
140 bool dummy()
141 {
142  Akonadi::AttributeFactory::registerAttribute<Akonadi::BlockAlarmsAttribute>();
143 
144  return true;
145 }
146 
147 // Called when this library is loaded.
148 const bool registered = dummy();
149 } // namespace
~BlockAlarmsAttribute() override
Destroys the block alarms attribute.
bool isAlarmTypeBlocked(KCalendarCore::Alarm::Type type) const
Returns whether given alarm type is blocked or not.
bool isEverythingBlocked() const
Returns whether all alarms are blocked or not.
void blockAlarmType(KCalendarCore::Alarm::Type type, bool block=true)
Blocks or unblocks given alarm type.
BlockAlarmsAttribute()
Creates a new block alarms attribute.
void blockEverything(bool block=true)
Blocks or unblocks every alarm type.
bool isEmpty() const const
An Attribute that marks that alarms from a calendar collection are blocked.
FreeBusyManager::Singleton.
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Mon Oct 3 2022 03:53:48 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.