summaryrefslogtreecommitdiffstats
blob: 38d8c3efb0d1563d0953c5cb85597673b340723f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/*
 * Copyright (c) 2010-2014 Kevin Smith
 * Licensed under the GNU General Public License v3.
 * See Documentation/Licenses/GPLv3.txt for more information.
 */

#pragma once

#include <list>
#include <set>
#include <map>
#include <boost/shared_ptr.hpp>
#include <Swiften/MUC/MUCBookmark.h>
#include <Swiften/Elements/StatusShow.h>
#include <boost/filesystem/path.hpp>
#include <Swiften/Base/foreach.h>
#include <Swiften/Base/boost_bsignals.h>

namespace Swift {
	class ChatListWindow {
		public:
			class Chat {
				public:
					Chat() : statusType(StatusShow::None), isMUC(false), unreadCount(0) {}
					Chat(const JID& jid, const std::string& chatName, const std::string& activity, int unreadCount, StatusShow::Type statusType, const boost::filesystem::path& avatarPath, bool isMUC, const std::string& nick = "", const boost::optional<std::string> password = boost::optional<std::string>())
					: jid(jid), chatName(chatName), activity(activity), statusType(statusType), isMUC(isMUC), nick(nick), password(password), unreadCount(unreadCount), avatarPath(avatarPath) {}
					/** Assume that nicks and other transient features aren't important for equality */
					bool operator==(const Chat& other) const {
						if (impromptuJIDs.empty()) {
							return jid.toBare() == other.jid.toBare()
									&& isMUC == other.isMUC;
						} else { /* compare the chat occupant lists */
							typedef std::map<std::string, JID> JIDMap;
							foreach (const JIDMap::value_type& jid, impromptuJIDs) {
								bool found = false;
								foreach (const JIDMap::value_type& otherJID, other.impromptuJIDs) {
									if (jid.second.toBare() == otherJID.second.toBare()) {
										found = true;
										break;
									}
								}
								if (!found) {
									return false;
								}
							}
							return true;
						}
					}
					void setUnreadCount(int unread) {
						unreadCount = unread;
					}
					void setStatusType(StatusShow::Type type) {
						statusType = type;
					}
					void setAvatarPath(const boost::filesystem::path& path) {
						avatarPath = path;
					}
					std::string getImpromptuTitle() const {
						typedef std::pair<std::string, JID> StringJIDPair;
						std::string title;
						foreach(StringJIDPair pair, impromptuJIDs) {
							if (title.empty()) {
								title += pair.first;
							} else {
								title += ", " + pair.first;
							}
						}
						return title;
					}
					JID jid;
					std::string chatName;
					std::string activity;
					StatusShow::Type statusType;
					bool isMUC;
					std::string nick;
					boost::optional<std::string> password;
					int unreadCount;
					boost::filesystem::path avatarPath;
					std::map<std::string, JID> impromptuJIDs;
			};
			virtual ~ChatListWindow();

			virtual void setBookmarksEnabled(bool enabled) = 0;
			virtual void addMUCBookmark(const MUCBookmark& bookmark) = 0;
			virtual void addWhiteboardSession(const ChatListWindow::Chat& chat) = 0;
			virtual void removeWhiteboardSession(const JID& jid) = 0;
			virtual void removeMUCBookmark(const MUCBookmark& bookmark) = 0;
			virtual void setRecents(const std::list<Chat>& recents) = 0;
			virtual void setUnreadCount(int unread) = 0;
			virtual void clearBookmarks() = 0;

			boost::signal<void (const MUCBookmark&)> onMUCBookmarkActivated;
			boost::signal<void (const Chat&)> onRecentActivated;
			boost::signal<void (const JID&)> onWhiteboardActivated;
			boost::signal<void ()> onClearRecentsRequested;
	};
}