| 1 | /* i4ucmainwindowview.vala |
|---|
| 2 | * |
|---|
| 3 | * Copyright (C) 2010 Matias De la Puente |
|---|
| 4 | * |
|---|
| 5 | * This program is free software: you can redistribute it and/or modify |
|---|
| 6 | * it under the terms of the GNU General Public License as published by |
|---|
| 7 | * the Free Software Foundation, either version 3 of the License, or |
|---|
| 8 | * (at your option) any later version. |
|---|
| 9 | * |
|---|
| 10 | * This program is distributed in the hope that it will be useful, |
|---|
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 13 | * GNU General Public License for more details. |
|---|
| 14 | * |
|---|
| 15 | * You should have received a copy of the GNU General Public License |
|---|
| 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
|---|
| 17 | * |
|---|
| 18 | * Author: |
|---|
| 19 | * Matias De la Puente <mfpuente.ar@gmail.com> |
|---|
| 20 | */ |
|---|
| 21 | using Gtk; |
|---|
| 22 | using Gee; |
|---|
| 23 | |
|---|
| 24 | public class I4uc.MainWindowView : Gtk.Window, MainWindowViewIface |
|---|
| 25 | { |
|---|
| 26 | private ActionGroup _action_group; |
|---|
| 27 | private UIManager _ui_manager = new UIManager (); |
|---|
| 28 | private PagesPanel _pages_panel = new PagesPanel (); |
|---|
| 29 | private PagesPanel _side_panel = new PagesPanel (); |
|---|
| 30 | private PagesPanel _bottom_panel = new PagesPanel (); |
|---|
| 31 | |
|---|
| 32 | public UIManager ui_manager { get { return _ui_manager; } } |
|---|
| 33 | public PagesPanel pages_panel { get { return _pages_panel; } } |
|---|
| 34 | public PagesPanel side_panel { get { return _side_panel; } } |
|---|
| 35 | public PagesPanel bottom_panel { get { return _bottom_panel; } } |
|---|
| 36 | |
|---|
| 37 | public bool show_side_panel_active |
|---|
| 38 | { |
|---|
| 39 | set { (_action_group.get_action ("ShowSidePanelAction") as ToggleAction).active = value; } |
|---|
| 40 | get { return (_action_group.get_action ("ShowSidePanelAction") as ToggleAction).active; } |
|---|
| 41 | } |
|---|
| 42 | |
|---|
| 43 | public bool side_panel_visible |
|---|
| 44 | { |
|---|
| 45 | set { _side_panel.visible = value; } |
|---|
| 46 | get { return _side_panel.visible; } |
|---|
| 47 | } |
|---|
| 48 | |
|---|
| 49 | public bool show_bottom_panel_active |
|---|
| 50 | { |
|---|
| 51 | set { (_action_group.get_action ("ShowBottomPanelAction") as ToggleAction).active = value; } |
|---|
| 52 | get { return (_action_group.get_action ("ShowBottomPanelAction") as ToggleAction).active; } |
|---|
| 53 | } |
|---|
| 54 | |
|---|
| 55 | public bool bottom_panel_visible |
|---|
| 56 | { |
|---|
| 57 | set { _bottom_panel.visible = value; } |
|---|
| 58 | get { return _bottom_panel.visible; } |
|---|
| 59 | } |
|---|
| 60 | |
|---|
| 61 | public MainWindowView () |
|---|
| 62 | { |
|---|
| 63 | this.destroy.connect (Gtk.main_quit); |
|---|
| 64 | this.delete_event.connect (() => { return this.exit_clicked (); }); |
|---|
| 65 | this.configure_event.connect (on_configure_event); |
|---|
| 66 | this.window_state_event.connect (on_window_state_event); |
|---|
| 67 | |
|---|
| 68 | _action_group = new ActionGroup ("I4ucMainWindowActions"); |
|---|
| 69 | _action_group.set_translation_domain (Config.GETTEXT_PACKAGE); |
|---|
| 70 | _action_group.add_actions (_action_entries, this); |
|---|
| 71 | _action_group.add_toggle_actions (_toggle_action_entries, this); |
|---|
| 72 | |
|---|
| 73 | _ui_manager.insert_action_group (_action_group, 0); |
|---|
| 74 | |
|---|
| 75 | try |
|---|
| 76 | { |
|---|
| 77 | _ui_manager.add_ui_from_string (_UI, -1); |
|---|
| 78 | this.icon = new Gdk.Pixbuf.from_file (Path.build_filename (Config.PIXMAPS_DIR, "icon.png")); |
|---|
| 79 | } |
|---|
| 80 | catch (GLib.Error e) |
|---|
| 81 | { |
|---|
| 82 | warning (e.message); |
|---|
| 83 | } |
|---|
| 84 | |
|---|
| 85 | add_accel_group (_ui_manager.get_accel_group ()); |
|---|
| 86 | |
|---|
| 87 | var menubar = (MenuBar)_ui_manager.get_widget ("/MainMenu"); |
|---|
| 88 | var toolbar = (Toolbar)_ui_manager.get_widget ("/MainToolbar"); |
|---|
| 89 | toolbar.set_style (ToolbarStyle.ICONS); |
|---|
| 90 | |
|---|
| 91 | _side_panel.page_position = PagePosition.LEFT; |
|---|
| 92 | _bottom_panel.page_position = PagePosition.BOTTOM; |
|---|
| 93 | |
|---|
| 94 | var vpaned = new VPaned (); |
|---|
| 95 | vpaned.add1 (_pages_panel); |
|---|
| 96 | vpaned.add2 (_bottom_panel); |
|---|
| 97 | |
|---|
| 98 | var hpaned = new HPaned (); |
|---|
| 99 | hpaned.add1 (_side_panel); |
|---|
| 100 | hpaned.add2 (vpaned); |
|---|
| 101 | |
|---|
| 102 | var vbox = new VBox (false, 0); |
|---|
| 103 | vbox.pack_start (menubar, false, false, 0); |
|---|
| 104 | vbox.pack_start (toolbar, false, false, 0); |
|---|
| 105 | vbox.pack_start (hpaned, true, true, 0); |
|---|
| 106 | add (vbox); |
|---|
| 107 | } |
|---|
| 108 | |
|---|
| 109 | public void show_about_dialog (Gee.Map<string, string> app_info, Gee.List<string> authors) |
|---|
| 110 | { |
|---|
| 111 | var about_dialog = new AboutDialog (); |
|---|
| 112 | about_dialog.program_name = app_info["program_name"]; |
|---|
| 113 | about_dialog.comments = app_info["comments"]; |
|---|
| 114 | about_dialog.version = app_info["version"]; |
|---|
| 115 | var authors_array = new string[authors.size + 1]; |
|---|
| 116 | for (int i=0; i<authors.size; i++) |
|---|
| 117 | authors_array[i] = authors[i]; |
|---|
| 118 | authors_array[authors.size + 1] = null; |
|---|
| 119 | about_dialog.set_authors (authors_array); |
|---|
| 120 | about_dialog.copyright = app_info["copyright"]; |
|---|
| 121 | about_dialog.website = app_info["website"]; |
|---|
| 122 | about_dialog.logo = this.icon; |
|---|
| 123 | about_dialog.run (); |
|---|
| 124 | about_dialog.destroy (); |
|---|
| 125 | } |
|---|
| 126 | |
|---|
| 127 | public void set_size (int width, int height) |
|---|
| 128 | { |
|---|
| 129 | resize (width, height); |
|---|
| 130 | } |
|---|
| 131 | |
|---|
| 132 | private bool on_configure_event (Gdk.EventConfigure event) |
|---|
| 133 | { |
|---|
| 134 | this.size_changed (event.width, event.height); |
|---|
| 135 | return false; |
|---|
| 136 | } |
|---|
| 137 | |
|---|
| 138 | private bool on_window_state_event (Gdk.EventWindowState event) |
|---|
| 139 | { |
|---|
| 140 | if (Gdk.WindowState.MAXIMIZED in event.changed_mask) |
|---|
| 141 | this.state_changed (Gdk.WindowState.MAXIMIZED in event.new_window_state); |
|---|
| 142 | return false; |
|---|
| 143 | } |
|---|
| 144 | |
|---|
| 145 | private void on_show_side_panel () |
|---|
| 146 | { |
|---|
| 147 | this.show_side_panel_changed (); |
|---|
| 148 | } |
|---|
| 149 | |
|---|
| 150 | private void on_show_bottom_panel () |
|---|
| 151 | { |
|---|
| 152 | this.show_bottom_panel_changed (); |
|---|
| 153 | } |
|---|
| 154 | |
|---|
| 155 | private void on_quit () |
|---|
| 156 | { |
|---|
| 157 | if (!this.exit_clicked ()) |
|---|
| 158 | Gtk.main_quit (); |
|---|
| 159 | } |
|---|
| 160 | |
|---|
| 161 | private void on_about () |
|---|
| 162 | { |
|---|
| 163 | this.about_clicked (); |
|---|
| 164 | } |
|---|
| 165 | |
|---|
| 166 | private const ActionEntry[] _action_entries = |
|---|
| 167 | { |
|---|
| 168 | { "FileMenuAction", null, N_("_File") }, |
|---|
| 169 | { "QuitAction", STOCK_QUIT, null, null, N_("Quit from i4uc"), on_quit }, |
|---|
| 170 | { "EditMenuAction", null, N_("_Edit") }, |
|---|
| 171 | { "ViewMenuAction", null, N_("_View") }, |
|---|
| 172 | { "HelpMenuAction", null, N_("_Help") }, |
|---|
| 173 | { "AboutAction", STOCK_ABOUT, null, null, N_("About i4uc"), on_about } |
|---|
| 174 | }; |
|---|
| 175 | |
|---|
| 176 | private const ToggleActionEntry[] _toggle_action_entries = |
|---|
| 177 | { |
|---|
| 178 | { "ShowSidePanelAction", null, N_("Side Panel"), "F9", N_("Show or hide side panel"), on_show_side_panel, false }, |
|---|
| 179 | { "ShowBottomPanelAction", null, N_("Bottom Panel"), "<Control>F9", N_("Show or hide bottom panel"), on_show_bottom_panel, false } |
|---|
| 180 | }; |
|---|
| 181 | |
|---|
| 182 | private const string _UI = """ |
|---|
| 183 | <ui> |
|---|
| 184 | <menubar name="MainMenu"> |
|---|
| 185 | <menu name="FileMenu" action="FileMenuAction"> |
|---|
| 186 | <placeholder name="FileMenuOps"/> |
|---|
| 187 | <separator/> |
|---|
| 188 | <menuitem action="QuitAction" /> |
|---|
| 189 | </menu> |
|---|
| 190 | <menu name="EditMenu" action="EditMenuAction"> |
|---|
| 191 | <placeholder name="EditMenuOps"/> |
|---|
| 192 | </menu> |
|---|
| 193 | <menu name="ViewMenu" action="ViewMenuAction"> |
|---|
| 194 | <menuitem action="ShowSidePanelAction"/> |
|---|
| 195 | <menuitem action="ShowBottomPanelAction"/> |
|---|
| 196 | <separator/> |
|---|
| 197 | <placeholder name="ViewMenuOps"/> |
|---|
| 198 | </menu> |
|---|
| 199 | <placeholder name="MenuBarOps"/> |
|---|
| 200 | <menu name="HelpMenu" action="HelpMenuAction"> |
|---|
| 201 | <placeholder name="HelpMenuOps"/> |
|---|
| 202 | <separator/> |
|---|
| 203 | <menuitem action="AboutAction"/> |
|---|
| 204 | </menu> |
|---|
| 205 | </menubar> |
|---|
| 206 | <toolbar name="MainToolbar"> |
|---|
| 207 | <placeholder name="ToolbarStartOps"/> |
|---|
| 208 | <placeholder name="ToolbarEndOps"/> |
|---|
| 209 | </toolbar> |
|---|
| 210 | </ui>"""; |
|---|
| 211 | } |
|---|