1 /*
2  * Nautilus-Actions
3  * A Nautilus extension which offers configurable context menu actions.
4  *
5  * Copyright (C) 2005 The GNOME Foundation
6  * Copyright (C) 2006-2008 Frederic Ruaudel and others (see AUTHORS)
7  * Copyright (C) 2009-2014 Pierre Wieser and others (see AUTHORS)
8  *
9  * Nautilus-Actions is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License as
11  * published by the Free Software Foundation; either version 2 of
12  * the License, or (at your option) any later version.
13  *
14  * Nautilus-Actions is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with Nautilus-Actions; see the file COPYING. If not, see
21  * <http://www.gnu.org/licenses/>.
22  *
23  * Authors:
24  *   Frederic Ruaudel <grumz@grumz.net>
25  *   Rodrigo Moya <rodrigo@gnome-db.org>
26  *   Pierre Wieser <pwieser@trychlos.org>
27  *   ... and many others (see AUTHORS)
28  */
29 
30 #ifndef __NACT_MAIN_WINDOW_H__
31 #define __NACT_MAIN_WINDOW_H__
32 
33 /**
34  * SECTION: main-window
35  * @title: NactMainWindow
36  * @short_description: The Main Window class definition
37  * @include: nact-main-window.h
38  *
39  * This class is derived from NactWindow and manages the main window.
40  *
41  * It embeds:
42  * - the menubar,
43  * - the toolbar,
44  * - a button bar with sort buttons,
45  * - the hierarchical list of items,
46  * - a notebook which displays the content of the current item,
47  * - a status bar.
48  *
49  * NactApplication    NactMainWindow    NactTreeView    NactTreeModel   NactMenubar
50  *  |
51  *  +-> nact_main_window_new()
52  *  |   |
53  *  |   +-> NactMainWindow::instance_contructed()
54  *  |   |   |
55  *  |   |   +-> connect to base-init-gtk       [window]
56  *  |   |   |              base-init-window    [window]
57  *  |   |   |              base-show-widgets   [window]
58  *  |   |   |              pivot-items-changed [updater]
59  *  |   |   |              tab-item-updated    [window]
60  *  |   |   |
61  *  |   |   +-> nact_menubar_new()
62  *  |   |   |   |
63  *  |   |   |   +-> NactMenubar::nact_menubar_new()
64  *  |   |   |   |   |
65  *  |   |   |   |   +-> nact_sort_buttons_new()
66  *  |   |   |   |   +-> connect to base-init-window [window]
67  *  |   |   |   |   |
68  *  |   |   |   |  <-
69  *  |   |   |  <-
70  *  |   |   |
71  *  |   |   +-> nact_clipboard_new()
72  *  |   |   |
73  *  |   |   +-> initialize each notebook tab
74  *  |   |   |
75  *  |   |   |   NactMainWindow has connected to "base-init-window" signal _before_
76  *  |   |   |   other widgets have been created or initialized. We so are sure that
77  *  |   |   |   the NactMainWindow handlers will be called first.
78  *  |   |  <-
79  *  |   |
80  *  |   +-> base_window_init()
81  *  |   |   |
82  *  |   |   +-> setup builder
83  *  |   |   +-> load gtk toplevel
84  *  |   |   +-> emit signal base-initialize-gtk
85  *  |   |   |
86  *  |   |   |   [H]-> NactMainWindow::on_base_initialize_gtk()
87  *  |   |   |         |
88  *  |   |   |         +-> nact_tree_view_new()
89  *  |   |   |         |   |
90  *  |   |   |         |   +-> NactTreeView::instance_contructed()
91  *  |   |   |         |   |   |
92  *  |   |   |         |   |   +-> connect to base-init-window  [window]
93  *  |   |   |         |   |   |              base-show-widgets [window]
94  *  |   |   |         |   |   |
95  *  |   |   |         |   |   +-> initialize_gtk()
96  *  |   |   |         |   |   |   |
97  *  |   |   |         |   |   |   +-> nact_tree_model_new()
98  *  |   |   |         |   |   |   |   |
99  *  |   |   |         |   |   |   |   +-> NactTreeModel::nact_tree_model_new()
100  *  |   |   |         |   |   |   |   |
101  *  |   |   |         |   |   |   |  <-
102  *  |   |   |         |   |   |  <-
103  *  |   |   |         |   |  <-
104  *  |   |   |         |  <-
105  *  |   |   |         |
106  *  |   |   |         +-> nact_main_statusbar_initialize_load_toplevel()
107  *  |   |   |
108  *  |   |   |   [H]-> NactIxxxxxxTab::on_base_initialize_gtk()
109  *  |   |   |
110  *  |   |   +-> emit signal base-initialize-window
111  *  |   |   |
112  *  |   |   |   [H]-> NactMainWindow::on_base_initialize_base_window()
113  *  |   |   |         |
114  *  |   |   |         +-> connect to delete-event
115  *  |   |   |         |              base-quit-requested
116  *  |   |   |         |
117  *  |   |   |         +-> connect to tree-selection-changed
118  *  |   |   |         |              tree-modified-status-changed
119  *  |   |   |         |
120  *  |   |   |         |   Because NactMainWindow was the first class to connect to
121  *  |   |   |         |   "base-initialize-window" signal, then this handler has been
122  *  |   |   |         |   the first to be called. And so the "tree-selection-changed"
123  *  |   |   |         |   signal handler will also the first to be called, and we can
124  *  |   |   |         |   safely rely on that.
125  *  |   |   |        <-
126  *  |   |   |
127  *  |   |   |   [H]-> NactIxxxxxxTab::on_base_initialize_window()
128  *  |   |   |
129  *  |   |   |   [H]-> NactTreeView::on_base_initialize_view()
130  *  |   |   |         |
131  *  |   |   |         +-> monitors the selection in the tree
132  *  |   |   |         |   in order to be able to send the "tree-selection-changed" signal
133  *  |   |   |         |
134  *  |   |   |         +- nact_tree_ieditable_initialize()
135  *  |   |   |         |
136  *  |   |   |        <-
137  *  |   |   |
138  *  |   |   +-> emit signal base-show-widgets
139  *  |   |   |
140  *  |   |   |   [H]-> NactMainWindow::on_base_show_widgets()
141  *  |   |   |         |
142  *  |   |   |         +-> load items from pivot
143  *  |   |   |
144  *  |   |   |   [H]-> NactIxxxxxxTab::on_base_show_widgets()
145  *  |   |   |
146  *  |   |   +-> gtk_widget_show_all()
147  *  |   |   |
148  *  |   |  <-
149  *  |  <-
150  *  |
151  *  +-> gtk_main()
152  *  |
153  * [X] End of initialization process
154  *
155  * Some signals and their usages
156  * =============================
157  * MAIN_SIGNAL_SELECTION_CHANGED
158  *   The signal is sent by the tree view on the BaseWindow each time the
159  *   selection has changed. By construction (cf. initialization process),
160  *   the main window handler is the first to be triggered by this signal:
161  *   it sets the 'current' main window properties to reflect this new
162  *   selection.
163  *   Args:
164  *   - the list of selected items, may be NULL.
165  *   Consumers:
166  *   - all tabs should take advantage of this signal to enable/disable
167  *     their page, setup the content of their widgets, and so on.
168  *   - the menubar updates its indicator depending of the current selection
169  *
170  * TAB_UPDATABLE_SIGNAL_ITEM_UPDATED
171  *   The signal is sent on the BaseWindow each time a widget is updated; the widget
172  *   callback must setup the edited object with the new value, and then should call
173  *   this signal with a flag indicating if the tree display should be refreshed now.
174  *   Args:
175  *   - an OR-ed list of modified flags, or 0 if not relevant
176  *   Consumers are:
177  *   - the main window checks the modification/validity status of the object
178  *   - if the 'refresh tree display' flag is set, then the tree model refreshes
179  *     the current row with current label and icon, then flags current row as
180  *     modified
181  *
182  * MAIN_SIGNAL_ITEM_UPDATED
183  *   The signal is sent on the BaseWindow after a data has been modified elsewhere
184  *   that in a tab: either the label has been edited inline in the tree view,
185  *   or a new i/o provider has been identified. The relevant NAObject has
186  *   been updated accordingly.
187  *   Args:
188  *   - an OR-ed list of modified flags, or 0 if not relevant
189  *   Consumers are:
190  *   - IActionTab and ICommandTab should update their label widgets
191  *   - IPropertiesTab updates its provider label
192  *
193  * MAIN_SIGNAL_CONTEXT_MENU
194  *   Opens the specified context menu.
195  *
196  * TREE_SIGNAL_FOCUS_IN
197  * TREE_SIGNAL_FOCUS_OUT
198  * TREE_SIGNAL_COUNT_CHANGED
199  * TREE_SIGNAL_LEVEL_ZERO_CHANGED
200  * TREE_SIGNAL_MODIFIED_STATUS_CHANGED
201  *
202  * TAB_UPDATABLE_SIGNAL_PROVIDER_CHANGED
203  *
204  * Object
205  */
206 
207 #include "nact-application.h"
208 #include "nact-clipboard.h"
209 #include "nact-tree-view.h"
210 
211 G_BEGIN_DECLS
212 
213 #define NACT_TYPE_MAIN_WINDOW                ( nact_main_window_get_type())
214 #define NACT_MAIN_WINDOW( object )           ( G_TYPE_CHECK_INSTANCE_CAST( object, NACT_TYPE_MAIN_WINDOW, NactMainWindow ))
215 #define NACT_MAIN_WINDOW_CLASS( klass )      ( G_TYPE_CHECK_CLASS_CAST( klass, NACT_TYPE_MAIN_WINDOW, NactMainWindowClass ))
216 #define NACT_IS_MAIN_WINDOW( object )        ( G_TYPE_CHECK_INSTANCE_TYPE( object, NACT_TYPE_MAIN_WINDOW ))
217 #define NACT_IS_MAIN_WINDOW_CLASS( klass )   ( G_TYPE_CHECK_CLASS_TYPE(( klass ), NACT_TYPE_MAIN_WINDOW ))
218 #define NACT_MAIN_WINDOW_GET_CLASS( object ) ( G_TYPE_INSTANCE_GET_CLASS(( object ), NACT_TYPE_MAIN_WINDOW, NactMainWindowClass ))
219 
220 typedef struct _NactMainWindowPrivate        NactMainWindowPrivate;
221 
222 typedef struct {
223 	/*< private >*/
224 	BaseWindow             parent;
225 	NactMainWindowPrivate *private;
226 }
227 	NactMainWindow;
228 
229 typedef struct _NactMainWindowClassPrivate   NactMainWindowClassPrivate;
230 
231 typedef struct {
232 	/*< private >*/
233 	BaseWindowClass             parent;
234 	NactMainWindowClassPrivate *private;
235 }
236 	NactMainWindowClass;
237 
238 /**
239  * Signals emitted by the main window
240  */
241 #define MAIN_SIGNAL_ITEM_UPDATED			"main-item-updated"
242 #define MAIN_SIGNAL_SELECTION_CHANGED		"main-selection-changed"
243 #define MAIN_SIGNAL_CONTEXT_MENU			"main-signal-open-popup"
244 
245 /**
246  * The data which, when modified, should be redisplayed asap.
247  * This is used by MAIN_SIGNAL_ITEM_UPDATED and TAB_UPDATABLE_SIGNAL_ITEM_UPDATED
248  * signals.
249  */
250 enum {
251 	MAIN_DATA_LABEL    = 1<<0,
252 	MAIN_DATA_ICON     = 1<<1,
253 	MAIN_DATA_PROVIDER = 1<<2,
254 };
255 
256 /**
257  * Properties set against the main window
258  */
259 #define MAIN_PROP_ITEM						"main-current-item"
260 #define MAIN_PROP_PROFILE					"main-current-profile"
261 #define MAIN_PROP_CONTEXT					"main-current-context"
262 #define MAIN_PROP_EDITABLE					"main-editable"
263 #define MAIN_PROP_REASON					"main-reason"
264 
265 GType           nact_main_window_get_type( void );
266 
267 NactMainWindow *nact_main_window_new           ( const NactApplication *application );
268 
269 NactClipboard  *nact_main_window_get_clipboard ( const NactMainWindow *window );
270 NactTreeView   *nact_main_window_get_items_view( const NactMainWindow *window );
271 
272 void            nact_main_window_reload      ( NactMainWindow *window );
273 void            nact_main_window_block_reload( NactMainWindow *window );
274 gboolean        nact_main_window_quit        ( NactMainWindow *window );
275 
276 G_END_DECLS
277 
278 #endif /* __NACT_MAIN_WINDOW_H__ */
279