Statistics
| Branch: | Tag: | Revision:

root / kadu-core / chat / recent-chat-manager.h @ f38188d2

History | View | Annotate | Download (3.9 kB)

1
/*
2
 * %kadu copyright begin%
3
 * Copyright 2009, 2010 RafaƂ Malinowski (rafal.przemyslaw.malinowski@gmail.com)
4
 * %kadu copyright end%
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License as
8
 * published by the Free Software Foundation; either version 2 of
9
 * the License, or (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
17
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18
 */
19
20
#ifndef RECENT_CHAT_MANAGER_H
21
#define RECENT_CHAT_MANAGER_H
22
23
#include <QtCore/QObject>
24
25
#include "configuration/configuration-aware-object.h"
26
#include "storage/storable-object.h"
27
28
class QTimer;
29
30
class Chat;
31
32
/**
33
 * @addtogroup Chat
34
 * @{
35
 */
36
37
/**
38
 * @class RecentChatManager
39
 * @author Rafal 'Vogel' Malinowski
40
 * @short Manager for recently used chats.
41
 *
42
 * This class manages recently used chats in application (maximum 20). Depending on configuration
43
 * it either stores and loads the recent chats between program runs or clears it at program exit
44
 * (and after specified amount of time). This manager is used for 'Recent chats' menu item.
45
 *
46
 * Use @link addRecentChat @endlink to add new recent chat. Old recent chats are automatially
47
 * removed after configurable period of time or when count of items would be bigger than 20.
48
 * If item is already on list it will be moved to the first place.
49
 */
50
class KADUAPI RecentChatManager : public QObject, public StorableObject, private ConfigurationAwareObject
51
{
52
        Q_OBJECT
53
        Q_DISABLE_COPY(RecentChatManager)
54
55
        static RecentChatManager * Instance;
56
57
        QList<Chat> RecentChats;
58
        QTimer *CleanUpTimer;
59
60
        RecentChatManager();
61
        virtual ~RecentChatManager();
62
63
        virtual void load();
64
65
        void removeRecentChat(Chat chat);
66
67
private slots:
68
        void cleanUp();
69
70
protected:
71
        virtual void configurationUpdated();
72
73
public:
74
        static RecentChatManager * instance();
75
76
        /**
77
         * @author Rafal 'Vogel' Malinowski
78
         * @short Returns node name for storage of recent chat ids.
79
         * @return node name for storage of recent chat ids
80
         *
81
         * Returns node name for storage of recent chat ids - "RecentChat".
82
         * This node is only used when configuration allows of storing that data.
83
         */
84
        virtual QString storageNodeName() { return QLatin1String("RecentChats"); }
85
86
        /**
87
         * @author Rafal 'Vogel' Malinowski
88
         * @short Returns parent node for storage - the main node.
89
         * @return parent node for storage - root node
90
         *
91
         * Returns parent node for storage - the main node.
92
         */
93
        virtual StorableObject* storageParent() { return 0; }
94
95
        virtual void store();
96
97
        void addRecentChat(Chat chat);
98
        QList<Chat> recentChats();
99
100
signals:
101
        /**
102
         * @author Rafal 'Vogel' Malinowski
103
         * @short Emited just before recent chat is added to manager.
104
         * @param chat added recent chat
105
         *
106
         * Signal is emited just before recent chat is added to manager.
107
         */
108
        void recentChatAboutToBeAdded(Chat chat);
109
110
        /**
111
         * @author Rafal 'Vogel' Malinowski
112
         * @short Emited just after recent chat is added to manager.
113
         * @param chat added recent chat
114
         *
115
         * Signal is emited just after recent chat is added to manager.
116
         */
117
        void recentChatAdded(Chat chat);
118
119
        /**
120
         * @author Rafal 'Vogel' Malinowski
121
         * @short Emited just before recent chat is removed from manager.
122
         * @param chat added recent chat
123
         *
124
         * Signal is emited just before recent chat is removed from manager.
125
         */
126
        void recentChatAboutToBeRemoved(Chat chat);
127
128
        /**
129
         * @author Rafal 'Vogel' Malinowski
130
         * @short Emited just after recent chat is removed from manager.
131
         * @param chat added recent chat
132
         *
133
         * Signal is emited just after recent chat is removed from manager.
134
         */
135
        void recentChatRemoved(Chat chat);
136
137
};
138
139
/**
140
 * @}
141
 */
142
143
#include "chat/chat.h" // for MOC
144
145
#endif // RECENT_CHAT_MANAGER_H