File: operations.hpp

package info (click to toggle)
gobby-infinote 0.5.0-4
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 3,756 kB
  • ctags: 2,474
  • sloc: cpp: 19,816; sh: 4,337; xml: 456; makefile: 395
file content (177 lines) | stat: -rw-r--r-- 5,025 bytes parent folder | download | duplicates (2)
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
/* Gobby - GTK-based collaborative text editor
 * Copyright (C) 2008-2014 Armin Burgmeier <armin@arbur.net>
 *
 * Permission to use, copy, modify, and/or distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

#ifndef _GOBBY_OPERATIONS_OPERATIONS_HPP_
#define _GOBBY_OPERATIONS_OPERATIONS_HPP_

#include "core/browser.hpp"
#include "core/statusbar.hpp"
#include "core/documentinfostorage.hpp"
#include "core/foldermanager.hpp"
#include "core/textsessionview.hpp"

#include <libinfinity/client/infc-browser.h>

#include <gtkmm/window.h>
#include <sigc++/trackable.h>

#include <set>

namespace Gobby
{

class OperationNew;
class OperationOpen;
class OperationOpenMultiple;
class OperationSave;
class OperationDelete;
class OperationSubscribePath;
class OperationExportHtml;

class Operations: public sigc::trackable
{
public:
	class Operation
	{
	public:
		typedef sigc::signal<void, bool> SignalFinished;

		Operation(Operations& operations):
			m_operations(operations) {}
		virtual ~Operation() = 0;

		virtual void start() = 0;

		StatusBar& get_status_bar()
		{
			return m_operations.m_status_bar;
		}

		Browser& get_browser()
		{
			return m_operations.m_browser;
		}

		FolderManager& get_folder_manager()
		{
			return m_operations.m_folder_manager;
		}

		DocumentInfoStorage& get_info_storage()
		{
			return m_operations.m_info_storage;
		}

		SignalFinished signal_finished() const
		{
			return m_signal_finished;
		}

	protected:
		void fail()
		{
			m_operations.fail_operation(this);
		}

		void finish()
		{
			m_operations.finish_operation(this);
		}

		Operations& m_operations;

	private:
		SignalFinished m_signal_finished;
	};

	typedef sigc::signal<void, OperationSave*> SignalBeginSaveOperation;
	typedef std::vector<Glib::ustring> uri_list;

	Operations(DocumentInfoStorage& info_storage,
	           Browser& browser,
	           FolderManager& folder_manager,
	           StatusBar& status_bar);
	~Operations();

	OperationNew* create_directory(InfBrowser* browser,
	                               const InfBrowserIter* parent,
	                               const Glib::ustring& name);

	OperationNew* create_document(InfBrowser* browser,
	                              const InfBrowserIter* parent,
	                              const Glib::ustring& name);

	OperationOpen* create_document(InfBrowser* browser,
	                               const InfBrowserIter* parent,
	                               const Glib::ustring& name,
	                               const Preferences& preferences,
	                               const Glib::ustring& from_uri,
	                               const char* encoding);

	OperationOpenMultiple* create_documents(InfBrowser* browser,
	                                        const InfBrowserIter* parent,
	                                        const Preferences& prefs,
	                                        const uri_list& uris);

	OperationSave* save_document(TextSessionView& view,
	                             const std::string& uri,
	                             const std::string& encoding,
	                             DocumentInfoStorage::EolStyle eol_style);

	OperationDelete* delete_node(InfBrowser* browser,
	                             const InfBrowserIter* iter);

	// uri must be of kind infinote://[hostname]/[path]
	OperationSubscribePath* subscribe_path(const std::string& uri);
	OperationSubscribePath* subscribe_path(InfBrowser* browser,
	                                       const std::string& path);

	OperationExportHtml* export_html(TextSessionView& view,
	                                 const std::string& uri);

	OperationSave* get_save_operation_for_document(TextSessionView& view);

	SignalBeginSaveOperation signal_begin_save_operation() const
	{
		return m_signal_begin_save_operation;
	}

protected:
	void fail_operation(Operation* operation);
	void finish_operation(Operation* operation);

	DocumentInfoStorage& m_info_storage;
	Browser& m_browser;
	FolderManager& m_folder_manager;
	StatusBar& m_status_bar;

	typedef std::set<Operation*> OperationSet;
	OperationSet m_operations;

	SignalBeginSaveOperation m_signal_begin_save_operation;
private:
	template<typename OperationType>
	OperationType* check_operation(OperationType* op)
	{
		if(m_operations.find(op) == m_operations.end())
			return NULL;
		return op;
	}
};

}
	
#endif // _GOBBY_OPERATIONS_OPERATIONS_HPP_