summaryrefslogtreecommitdiffstats
blob: 3c28bdbff7785ad2a95a1881f21d139b4a253651 (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
/*
 * Copyright (c) 2010 Remko Tronçon
 * Licensed under the GNU General Public License v3.
 * See Documentation/Licenses/GPLv3.txt for more information.
 */

#pragma once

#include <boost/optional.hpp>

#include <string>
#include <Swiften/JID/JID.h>
#include <Swiften/Elements/Storage.h>

namespace Swift {
	class MUCBookmark {
		public:
			MUCBookmark(const Storage::Room& room) {
				name_ = room.name;
				room_ = room.jid;
				nick_ = room.nick;
				password_ = room.password;
				autojoin_ = room.autoJoin;
			}

			MUCBookmark(const JID& room, const std::string& bookmarkName) : room_(room), name_(bookmarkName), autojoin_(false) {
			}

			void setAutojoin(bool enabled) {
				autojoin_ = enabled; 
			}

			bool getAutojoin() const {
				return autojoin_;
			}

			void setNick(const boost::optional<std::string>& nick) {
				nick_ = nick;
			}

			void setPassword(const boost::optional<std::string>& password) {
				password_ = password;
			}

			const boost::optional<std::string>& getNick() const {
				return nick_;
			}

			const boost::optional<std::string>& getPassword() const {
				return password_;
			}

			const std::string& getName() const {
				return name_;
			}

			const JID& getRoom() const {
				return room_;
			}

			bool operator==(const MUCBookmark& rhs) const {
				/* FIXME: not checking passwords for equality - which might make sense, perhaps */
				return rhs.room_ == room_ && rhs.name_ == name_ && rhs.nick_ == nick_ /*&& rhs.password_ == password_*/ && rhs.autojoin_ == autojoin_;
			}

			Storage::Room toStorage() const {
				Storage::Room room;
				room.name = name_;
				room.jid = room_;
				if (nick_) {
					room.nick = *nick_;
				}
				if (password_) {
					room.password = *password_;
				}
				room.autoJoin = autojoin_;
				return room;
			}

		private:
			JID room_;
			std::string name_;
			boost::optional<std::string> nick_;
			boost::optional<std::string> password_;
			bool autojoin_;
	};
}