summaryrefslogtreecommitdiffstats
blob: c6c22bf42eec151fa06f71be04cb1aa453976fd1 (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
/*
 * 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 "Swiften/Base/String.h"
#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;
			}

			MUCBookmark(const JID& room, const String& bookmarkName) : room_(room), name_(bookmarkName) {
			}

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

			bool getAutojoin() const {
				return autojoin_;
			}

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

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

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

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

			const String& getName() const {
				return name_;
			}

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

			bool operator==(const MUCBookmark& rhs) const {
				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_;
				}
				return room;
			}

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