summaryrefslogtreecommitdiffstats
blob: 7250846d42e588d84aecfdbe30f4ebfd971f2c0e (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
98
99
100
101
102
103
104
105
106
107
108
/*
 * Copyright (c) 2010 Kevin Smith
 * Licensed under the GNU General Public License v3.
 * See Documentation/Licenses/GPLv3.txt for more information.
 */

#pragma once

#include <vector>
#include <map>

#include <boost/shared_ptr.hpp>
#include "Swiften/Base/boost_signalslib.h"

#include "Swiften/Base/String.h"
#include "Swiften/JID/JID.h"

#include "Swift/Controllers/UIEvents/UIEvent.h"
#include "Swift/Controllers/Chat/MUCSearchController.h"
#include "Swiften/Elements/DiscoInfo.h"
#include "Swiften/Elements/DiscoItems.h"
#include "Swiften/Elements/ErrorPayload.h"

namespace Swift {
	class UIEventStream;
	class MUCSearchWindow;
	class MUCSearchWindowFactory;
	class IQRouter;

	class MUCService {
		public:
			class MUCRoom {
				public:
					MUCRoom(const String& node, const String& name, int occupants) : node_(node), name_(name), occupants_(occupants) {}
					String getNode() {return node_;}
					String getName() {return name_;}
					int getOccupantCount() {return occupants_;}
				private:
					String node_;
					String name_;
					int occupants_;
			};

			MUCService() {error_ = false; complete_ = false;}

			void setComplete(bool complete) {
				complete_ = complete;
			}

			void setName(const String& name) {
				name_ = name;
			}

			void setJID(const JID& jid) {
				jid_ = jid;
			}

			bool getComplete() const {
				return complete_;
			}

			JID getJID() const {
				return jid_;
			}

			String getName() const {
				return name_;
			}

			void setError(const String& errorText) {error_ = true; errorText_ = errorText;}

			void clearRooms() {rooms_.clear();}

			void addRoom(const MUCRoom& room) {rooms_.push_back(room);}

			std::vector<MUCRoom> getRooms() const {return rooms_;}
		private:
			String name_;
			JID jid_;
			std::vector<MUCRoom> rooms_;
			bool complete_;
			bool error_;
			String errorText_;
	};

	class MUCSearchController {
		public:
		MUCSearchController(const JID& jid, UIEventStream* uiEventStream, MUCSearchWindowFactory* mucSearchWindowFactory, IQRouter* iqRouter);
			~MUCSearchController();
		private:
			void handleUIEvent(boost::shared_ptr<UIEvent> event);
			void handleAddService(const JID& jid, bool userTriggered=false);
			void handleDiscoInfoResponse(boost::shared_ptr<DiscoInfo> info, const boost::optional<ErrorPayload>& error, const JID& jid);
			void handleRoomsItemsResponse(boost::shared_ptr<DiscoItems> items, const boost::optional<ErrorPayload>& error, const JID& jid);
			void handleServerItemsResponse(boost::shared_ptr<DiscoItems> items, const boost::optional<ErrorPayload>& error, const JID& jid);
			void handleDiscoError(const JID& jid, const ErrorPayload& error);
			void removeService(const JID& jid);
			void refreshView();
			UIEventStream* uiEventStream_;
			MUCSearchWindow* window_;
			MUCSearchWindowFactory* factory_;
			boost::bsignals::scoped_connection uiEventConnection_;
			std::vector<JID> services_;
			std::map<JID, MUCService> serviceDetails_;
			IQRouter* iqRouter_;
			JID jid_;
	};
}