File: header.hpp

package info (click to toggle)
gobby 0.4.12-2
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 2,712 kB
  • ctags: 1,488
  • sloc: cpp: 11,818; sh: 3,918; makefile: 221
file content (191 lines) | stat: -rw-r--r-- 5,867 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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
/* gobby - A GTKmm driven libobby client
 * Copyright (C) 2005 0x539 dev group
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public
 * License along with this program; if not, write to the Free
 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

#ifndef _GOBBY_HEADER_HPP_
#define _GOBBY_HEADER_HPP_

#include <list>

#include <gtkmm/box.h>
#include <gtkmm/uimanager.h>
#include <gtkmm/radioaction.h>
#include <gtkmm/menubar.h>
#include <gtkmm/toolbar.h>

#include "preferences.hpp" // Defines GtkSourceLanguageManager (gtksourceview1)
#include "application_state.hpp"

namespace Gobby
{

class Header: public Gtk::VBox
{
public:
	class Error: public Glib::Error
	{
	public:
		enum Code {
			MENUBAR_MISSING,
			TOOLBAR_MISSING
		};

		Error(Code error_code, const Glib::ustring& error_message);
		Code code() const;
	};

	/** @brief Action that automatically chances sensitivity depending
	 * on application state.
	 */
	class AutoAction
	{
	public:
		typedef Glib::RefPtr<Gtk::Action> action_type;

		AutoAction(action_type action,
		           const ApplicationState& state,
		           ApplicationFlags inc_flags,
			   ApplicationFlags exc_flags);

	protected:
		void on_state_change(const ApplicationState& state);

		action_type m_action;
		ApplicationFlags m_inc_flags;
		ApplicationFlags m_exc_flags;
	};

	/** @brief Class that stores multiple AutoActions.
	 *
	 * Once an AutoAction has been created, it works without any further
	 * need to access the AutoAction object again, one just needs to
	 * keep the AutoAction somewhere and release it when the application
	 * exits.
	 *
	 * So this class does just keep auto actions without providing access
	 * to them.
	 */
	class AutoList
	{
	public:
		typedef AutoAction::action_type action_type;

		void add(action_type action,
		         const ApplicationState& state,
			 ApplicationFlags inc_flags,
			 ApplicationFlags exc_flags);

		~AutoList();

	protected:
		std::list<AutoAction*> m_list;
	};

	class LanguageWrapper
	{
	public:
		//typedef AutoAction<Gtk::RadioAction> Action;
		typedef Glib::RefPtr<Gtk::RadioAction> Action;

		LanguageWrapper(Action action,
		                GtkSourceLanguage* language);
		~LanguageWrapper();

		Action get_action() const;
		GtkSourceLanguage* get_language() const;
	protected:
		Action m_action;
		GtkSourceLanguage* m_language;
	};

	Header(const ApplicationState& state,
	       GtkSourceLanguageManager* lang_mgr);

	// Access to accelerator groups of the ui manager
	Glib::RefPtr<Gtk::AccelGroup> get_accel_group();
	Glib::RefPtr<const Gtk::AccelGroup> get_accel_group() const;

	// Access to toolbar & menubar
	Gtk::MenuBar& get_menubar();
	Gtk::Toolbar& get_toolbar();

	const Glib::RefPtr<Gtk::ActionGroup> group_app;
	const Glib::RefPtr<Gtk::ActionGroup> group_session;
	const Glib::RefPtr<Gtk::ActionGroup> group_edit;
	const Glib::RefPtr<Gtk::ActionGroup> group_user;
	const Glib::RefPtr<Gtk::ActionGroup> group_window;
	const Glib::RefPtr<Gtk::ActionGroup> group_help;

	const Glib::RefPtr<Gtk::Action> action_app;
	const Glib::RefPtr<Gtk::Action> action_app_session_create;
	const Glib::RefPtr<Gtk::Action> action_app_session_join;
	const Glib::RefPtr<Gtk::Action> action_app_session_save;
	const Glib::RefPtr<Gtk::Action> action_app_session_save_as;
	const Glib::RefPtr<Gtk::Action> action_app_session_quit;
	const Glib::RefPtr<Gtk::Action> action_app_quit;

	const Glib::RefPtr<Gtk::Action> action_session;
	const Glib::RefPtr<Gtk::Action> action_session_document_create;
	const Glib::RefPtr<Gtk::Action> action_session_document_open;
	const Glib::RefPtr<Gtk::Action> action_session_document_save;
	const Glib::RefPtr<Gtk::Action> action_session_document_save_as;
	const Glib::RefPtr<Gtk::Action> action_session_document_save_all;
	const Glib::RefPtr<Gtk::Action> action_session_document_close;

	const Glib::RefPtr<Gtk::Action> action_edit;
	const Glib::RefPtr<Gtk::Action> action_edit_search;
	const Glib::RefPtr<Gtk::Action> action_edit_search_replace;
	const Glib::RefPtr<Gtk::Action> action_edit_goto_line;
	const Glib::RefPtr<Gtk::Action> action_edit_preferences;
	const Glib::RefPtr<Gtk::Action> action_edit_document_preferences;
	const Glib::RefPtr<Gtk::Action> action_edit_syntax;
	std::list<LanguageWrapper> action_edit_syntax_languages;

	const Glib::RefPtr<Gtk::Action> action_user;
	const Glib::RefPtr<Gtk::Action> action_user_set_password;
	const Glib::RefPtr<Gtk::Action> action_user_set_colour;

	const Glib::RefPtr<Gtk::Action> action_window;
	const Glib::RefPtr<Gtk::ToggleAction> action_window_userlist;
	const Glib::RefPtr<Gtk::ToggleAction> action_window_documentlist;
	const Glib::RefPtr<Gtk::ToggleAction> action_window_chat;

	const Glib::RefPtr<Gtk::Action> action_help;
	const Glib::RefPtr<Gtk::Action> action_help_about;

protected:
	void set_action_auto(const Glib::RefPtr<Gtk::Action>& action,
	                     const ApplicationState& state,
	                     ApplicationFlags inc_flags,
	                     ApplicationFlags exc_flags);

	const Glib::RefPtr<Gtk::UIManager> m_ui_manager;

	Gtk::MenuBar* m_menubar;
	Gtk::Toolbar* m_toolbar;

	Gtk::RadioButtonGroup m_lang_group;

	/** @brief List that just stores internally the auto actions to have
	 * the actions change sensitivity automatically.
	 */
	AutoList m_auto_actions;
};

}

#endif // _GOBBY_HEADER_HPP_