Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
PIM
KAlarm
Commits
d4d3468a
Commit
d4d3468a
authored
Sep 10, 2020
by
David Jarvie
Browse files
Use C++11 to prevent copying
parent
d8034092
Pipeline
#33836
passed with stage
in 12 minutes and 2 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
src/lib/autodeletelist.h
View file @
d4d3468a
/*
* autodeletelist.h - pointer list with auto-delete on destruction
* Program: kalarm
* SPDX-FileCopyrightText: 2008
, 2009
David Jarvie <djarvie@kde.org>
* SPDX-FileCopyrightText: 2008
-2020
David Jarvie <djarvie@kde.org>
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
...
...
@@ -20,19 +20,19 @@
template
<
class
T
>
class
AutoDeleteList
:
public
QList
<
T
*>
{
public:
AutoDeleteList
()
:
QList
<
T
*>
()
{}
~
AutoDeleteList
()
{
// Remove from list first before deleting the pointer, in
// case the pointer's destructor removes it from the list.
while
(
!
this
->
isEmpty
())
delete
this
->
takeFirst
();
}
private:
// Prevent copying since that would create two owners of the pointers
AutoDeleteList
(
const
AutoDeleteList
&
);
AutoDeleteList
&
operator
=
(
const
AutoDeleteList
&
);
public:
AutoDeleteList
()
:
QList
<
T
*>
()
{}
~
AutoDeleteList
()
{
// Remove from list first before deleting the pointer, in
// case the pointer's destructor removes it from the list.
while
(
!
this
->
isEmpty
())
delete
this
->
takeFirst
();
}
// Prevent copying since that would create two owners of the pointers
AutoDeleteList
(
const
AutoDeleteList
&
)
=
delete
;
AutoDeleteList
&
operator
=
(
const
AutoDeleteList
&
)
=
delete
;
};
#endif // AUTODELETELIST_H
...
...
src/lib/synchtimer.h
View file @
d4d3468a
/*
* synchtimer.h - timers which synchronize to time boundaries
* Program: kalarm
* SPDX-FileCopyrightText: 2004
, 2005
David Jarvie <djarvie@kde.org>
* SPDX-FileCopyrightText: 2004
-2020
David Jarvie <djarvie@kde.org>
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
...
...
@@ -25,36 +25,38 @@ class QTimer;
*/
class
SynchTimer
:
public
QObject
{
Q_OBJECT
public:
~
SynchTimer
()
override
;
struct
Connection
{
Connection
()
{
}
Connection
(
QObject
*
r
,
const
char
*
s
)
:
receiver
(
r
),
slot
(
s
)
{
}
bool
operator
==
(
const
Connection
&
c
)
const
{
return
receiver
==
c
.
receiver
&&
slot
==
c
.
slot
;
}
QObject
*
receiver
;
QByteArray
slot
;
};
protected:
SynchTimer
();
virtual
void
start
()
=
0
;
void
connecT
(
QObject
*
receiver
,
const
char
*
member
);
void
disconnecT
(
QObject
*
receiver
,
const
char
*
member
=
nullptr
);
bool
hasConnections
()
const
{
return
!
mConnections
.
isEmpty
();
}
QTimer
*
mTimer
;
protected
Q_SLOTS
:
virtual
void
slotTimer
()
=
0
;
private
Q_SLOTS
:
void
slotReceiverGone
(
QObject
*
r
)
{
disconnecT
(
r
);
}
private:
SynchTimer
(
const
SynchTimer
&
);
// prohibit copying
QList
<
Connection
>
mConnections
;
// list of current clients
Q_OBJECT
public:
~
SynchTimer
()
override
;
// Prevent copying.
SynchTimer
(
const
SynchTimer
&
)
=
delete
;
SynchTimer
&
operator
=
(
const
SynchTimer
&
)
=
delete
;
struct
Connection
{
Connection
()
{
}
Connection
(
QObject
*
r
,
const
char
*
s
)
:
receiver
(
r
),
slot
(
s
)
{
}
bool
operator
==
(
const
Connection
&
c
)
const
{
return
receiver
==
c
.
receiver
&&
slot
==
c
.
slot
;
}
QObject
*
receiver
;
QByteArray
slot
;
};
protected:
SynchTimer
();
virtual
void
start
()
=
0
;
void
connecT
(
QObject
*
receiver
,
const
char
*
member
);
void
disconnecT
(
QObject
*
receiver
,
const
char
*
member
=
nullptr
);
bool
hasConnections
()
const
{
return
!
mConnections
.
isEmpty
();
}
QTimer
*
mTimer
;
protected
Q_SLOTS
:
virtual
void
slotTimer
()
=
0
;
private
Q_SLOTS
:
void
slotReceiverGone
(
QObject
*
r
)
{
disconnecT
(
r
);
}
private:
QList
<
Connection
>
mConnections
;
// list of current clients
};
...
...
@@ -64,99 +66,100 @@ class SynchTimer : public QObject
*/
class
MinuteTimer
:
public
SynchTimer
{
Q_OBJECT
public:
virtual
~
MinuteTimer
()
{
mInstance
=
nullptr
;
}
/** Connect to the timer signal.
* @param receiver Receiving object.
* @param member Slot to activate.
*/
static
void
connect
(
QObject
*
receiver
,
const
char
*
member
)
{
instance
()
->
connecT
(
receiver
,
member
);
}
/** Disconnect from the timer signal.
* @param receiver Receiving object.
* @param member Slot to disconnect. If null, all slots belonging to
* @p receiver will be disconnected.
*/
static
void
disconnect
(
QObject
*
receiver
,
const
char
*
member
=
nullptr
)
{
if
(
mInstance
)
mInstance
->
disconnecT
(
receiver
,
member
);
}
protected:
MinuteTimer
()
:
SynchTimer
()
{
}
static
MinuteTimer
*
instance
();
void
start
()
override
{
slotTimer
();
}
protected
Q_SLOTS
:
void
slotTimer
()
override
;
private:
static
MinuteTimer
*
mInstance
;
// the one and only instance
Q_OBJECT
public:
virtual
~
MinuteTimer
()
{
mInstance
=
nullptr
;
}
/** Connect to the timer signal.
* @param receiver Receiving object.
* @param member Slot to activate.
*/
static
void
connect
(
QObject
*
receiver
,
const
char
*
member
)
{
instance
()
->
connecT
(
receiver
,
member
);
}
/** Disconnect from the timer signal.
* @param receiver Receiving object.
* @param member Slot to disconnect. If null, all slots belonging to
* @p receiver will be disconnected.
*/
static
void
disconnect
(
QObject
*
receiver
,
const
char
*
member
=
nullptr
)
{
if
(
mInstance
)
mInstance
->
disconnecT
(
receiver
,
member
);
}
protected:
MinuteTimer
()
:
SynchTimer
()
{
}
static
MinuteTimer
*
instance
();
void
start
()
override
{
slotTimer
();
}
protected
Q_SLOTS
:
void
slotTimer
()
override
;
private:
static
MinuteTimer
*
mInstance
;
// the one and only instance
};
/** DailyTimer is an application-wide timer synchronized to a specified time of day, local time.
*
* Daily timers come in two flavors: fixed, which can only be accessed through static methods,
* and variable, whose time can be adjusted and which are accessed through non-static methods.
* Daily timers come in two flavors: fixed, which can only be accessed through
* static methods, and variable, whose time can be adjusted and which are
* accessed through non-static methods.
*
* @author David Jarvie <djarvie@kde.org>
*/
class
DailyTimer
:
public
SynchTimer
{
Q_OBJECT
public:
~
DailyTimer
()
override
;
/** Connect to the timer signal which triggers at the given fixed time of day.
* A new timer is created if necessary.
* @param timeOfDay Time at which the timer is to trigger.
* @param receiver Receiving object.
* @param member Slot to activate.
*/
static
void
connect
(
const
QTime
&
timeOfDay
,
QObject
*
receiver
,
const
char
*
member
)
{
fixedInstance
(
timeOfDay
)
->
connecT
(
receiver
,
member
);
}
/** Disconnect from the timer signal which triggers at the given fixed time of day.
* If there are no remaining connections to that timer, it is destroyed.
* @param timeOfDay Time at which the timer triggers.
* @param receiver Receiving object.
* @param member Slot to disconnect. If null, all slots belonging to
* @p receiver will be disconnected.
*/
static
void
disconnect
(
const
QTime
&
timeOfDay
,
QObject
*
receiver
,
const
char
*
member
=
nullptr
);
/** Change the time at which this variable timer triggers.
* @param newTimeOfDay New time at which the timer should trigger.
* @param triggerMissed If true, and if @p newTimeOfDay < @p oldTimeOfDay, and if the current
* time is between @p newTimeOfDay and @p oldTimeOfDay, the timer will be
* triggered immediately so as to avoid missing today's trigger.
*/
void
changeTime
(
const
QTime
&
newTimeOfDay
,
bool
triggerMissed
=
true
);
/** Return the current time of day at which this variable timer triggers. */
QTime
timeOfDay
()
const
{
return
mTime
;
}
protected:
/** Construct an instance.
* The constructor is protected to ensure that for variable timers, only
derived classes
*
can construct instances. This ensures that multiple
timers are not created for the same
*
use.
*/
DailyTimer
(
const
QTime
&
,
bool
fixed
);
/** Return the instance which triggers at the specified fixed time of day,
* optionally creating a new instance if necessary.
* @param timeOfDay Time at which the timer triggers.
* @param create If true, create a new instance if none already exists
* for @p timeOfDay.
* @return The instance for @p timeOfDay, or 0 if it does not exist.
*/
static
DailyTimer
*
fixedInstance
(
const
QTime
&
timeOfDay
,
bool
create
=
true
);
void
start
()
override
;
protected
Q_SLOTS
:
void
slotTimer
()
override
;
private:
static
QList
<
DailyTimer
*>
mFixedTimers
;
// list of timers whose trigger time is fixed
QTime
mTime
;
QDate
mLastDate
;
// the date on which the timer was last triggered
bool
mFixed
;
// the time at which the timer triggers cannot be changed
Q_OBJECT
public:
~
DailyTimer
()
override
;
/** Connect to the timer signal which triggers at the given fixed time of day.
* A new timer is created if necessary.
* @param timeOfDay Time at which the timer is to trigger.
* @param receiver Receiving object.
* @param member Slot to activate.
*/
static
void
connect
(
const
QTime
&
timeOfDay
,
QObject
*
receiver
,
const
char
*
member
)
{
fixedInstance
(
timeOfDay
)
->
connecT
(
receiver
,
member
);
}
/** Disconnect from the timer signal which triggers at the given fixed time of day.
* If there are no remaining connections to that timer, it is destroyed.
* @param timeOfDay Time at which the timer triggers.
* @param receiver Receiving object.
* @param member Slot to disconnect. If null, all slots belonging to
* @p receiver will be disconnected.
*/
static
void
disconnect
(
const
QTime
&
timeOfDay
,
QObject
*
receiver
,
const
char
*
member
=
nullptr
);
/** Change the time at which this variable timer triggers.
* @param newTimeOfDay New time at which the timer should trigger.
* @param triggerMissed If true, and if @p newTimeOfDay < @p oldTimeOfDay, and if the current
* time is between @p newTimeOfDay and @p oldTimeOfDay, the timer will be
* triggered immediately so as to avoid missing today's trigger.
*/
void
changeTime
(
const
QTime
&
newTimeOfDay
,
bool
triggerMissed
=
true
);
/** Return the current time of day at which this variable timer triggers. */
QTime
timeOfDay
()
const
{
return
mTime
;
}
protected:
/** Construct an instance.
* The constructor is protected to ensure that for variable timers, only
*
derived classes
can construct instances. This ensures that multiple
*
timers are not created for the same
use.
*/
DailyTimer
(
const
QTime
&
,
bool
fixed
);
/** Return the instance which triggers at the specified fixed time of day,
* optionally creating a new instance if necessary.
* @param timeOfDay Time at which the timer triggers.
* @param create If true, create a new instance if none already exists
* for @p timeOfDay.
* @return The instance for @p timeOfDay, or 0 if it does not exist.
*/
static
DailyTimer
*
fixedInstance
(
const
QTime
&
timeOfDay
,
bool
create
=
true
);
void
start
()
override
;
protected
Q_SLOTS
:
void
slotTimer
()
override
;
private:
static
QList
<
DailyTimer
*>
mFixedTimers
;
// list of timers whose trigger time is fixed
QTime
mTime
;
QDate
mLastDate
;
// the date on which the timer was last triggered
bool
mFixed
;
// the time at which the timer triggers cannot be changed
};
...
...
@@ -166,20 +169,20 @@ class DailyTimer : public SynchTimer
*/
class
MidnightTimer
{
public:
/** Connect to the timer signal.
* @param receiver Receiving object.
* @param member Slot to activate.
*/
static
void
connect
(
QObject
*
receiver
,
const
char
*
member
)
{
DailyTimer
::
connect
(
QTime
(
0
,
0
),
receiver
,
member
);
}
/** Disconnect from the timer signal.
* @param receiver Receiving object.
* @param member Slot to disconnect. If null, all slots belonging to
* @p receiver will be disconnected.
*/
static
void
disconnect
(
QObject
*
receiver
,
const
char
*
member
=
nullptr
)
{
DailyTimer
::
disconnect
(
QTime
(
0
,
0
),
receiver
,
member
);
}
public:
/** Connect to the timer signal.
* @param receiver Receiving object.
* @param member Slot to activate.
*/
static
void
connect
(
QObject
*
receiver
,
const
char
*
member
)
{
DailyTimer
::
connect
(
QTime
(
0
,
0
),
receiver
,
member
);
}
/** Disconnect from the timer signal.
* @param receiver Receiving object.
* @param member Slot to disconnect. If null, all slots belonging to
* @p receiver will be disconnected.
*/
static
void
disconnect
(
QObject
*
receiver
,
const
char
*
member
=
nullptr
)
{
DailyTimer
::
disconnect
(
QTime
(
0
,
0
),
receiver
,
member
);
}
};
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment