LeechCraft Azoth 0.6.70-17335-ge406ffdcaf
Modular multiprotocol IM plugin for LeechCraft
Loading...
Searching...
No Matches
azothutil.h
Go to the documentation of this file.
1/**********************************************************************
2 * LeechCraft - modular cross-platform feature rich internet client.
3 * Copyright (C) 2006-2014 Georg Rudoy
4 *
5 * Distributed under the Boost Software License, Version 1.0.
6 * (See accompanying file LICENSE or copy at https://www.boost.org/LICENSE_1_0.txt)
7 **********************************************************************/
8
9#pragma once
10
11#include <QList>
12#include <QDateTime>
13#include <QtDebug>
15
16namespace LC
17{
18namespace Azoth
19{
20namespace AzothUtil
21{
22 namespace detail
23 {
25 {
26 return msg;
27 }
28
29 template<typename T>
30 IMessage* GetIMessage (T *msgObj)
31 {
32 return qobject_cast<IMessage*> (msgObj);
33 }
34 }
35
58 template<typename T>
59 void StandardPurgeMessages (QList<T*>& messages, const QDateTime& before)
60 {
61 if (!before.isValid ())
62 {
63 qDeleteAll (messages);
64 messages.clear ();
65 return;
66 }
67
68 while (!messages.isEmpty ())
69 {
70 const auto msg = detail::GetIMessage (messages.at (0));
71 if (!msg)
72 {
73 qWarning () << Q_FUNC_INFO
74 << "unable to cast"
75 << messages.at (0)
76 << "to IMessage; just blindly removing it and hoping for the best";
77 messages.removeAt (0);
78 continue;
79 }
80 if (msg->GetDateTime () < before)
81 delete messages.takeAt (0);
82 else
83 break;
84 }
85 }
86}
87}
88}
This interface is used to represent a message.
Definition imessage.h:43
IMessage * GetIMessage(IMessage *msg)
Definition azothutil.h:24
void StandardPurgeMessages(QList< T * > &messages, const QDateTime &before)
Standard function to purge messages before the given date.
Definition azothutil.h:59