~l-admin-3/evnc/automatic-cleanup-branch

« back to all changes in this revision

Viewing changes to src/Widgets/TitleBar.vala

  • Committer: Marcus Wichelmann
  • Date: 2015-07-09 18:17:05 UTC
  • Revision ID: marcus.wichelmann@hotmail.de-20150709181705-aliu5vv3gvha1p0a
Automatic code cleanup

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
*/
18
18
 
19
19
namespace evnc.Widgets {
20
 
        public class TitleBar : Gtk.HeaderBar {
21
 
                public signal void on_take_screenshot_clicked ();
22
 
                public signal void on_connect_request (string host, string port, string user);
23
 
 
24
 
                private SettingsManager options;
25
 
 
26
 
                private Granite.Widgets.ModeButton display_mode;
27
 
 
28
 
                public Gtk.ToolButton btn_screenshot;
29
 
 
30
 
                private Gtk.ToggleToolButton btn_readonly;
31
 
 
32
 
                private Gtk.MenuToolButton btn_connect;
33
 
                public Widgets.BookmarksMenu bookmarksmenu;
34
 
 
35
 
                private Gtk.Menu main_menu;
36
 
                private Gtk.MenuItem preferences_item;
37
 
                private Granite.Widgets.AppMenu app_menu;
38
 
 
39
 
                public TitleBar (MainWindow parent) {
40
 
                        options = new SettingsManager ();
41
 
 
42
 
                        this.get_style_context ().add_class ("primary-toolbar");
43
 
                        this.show_close_button = true;
44
 
                        this.set_title (_("VNC-Client"));
45
 
 
46
 
                        display_mode = new Granite.Widgets.ModeButton ();
47
 
                        display_mode.set_margin_top (4);
48
 
                        display_mode.set_margin_bottom (4);
49
 
                        display_mode.append_icon ("zoom-fit-best-symbolic", Gtk.IconSize.BUTTON);
50
 
                        display_mode.append_icon ("zoom-original-symbolic", Gtk.IconSize.BUTTON);
51
 
                        // FIXME: Using settings.bind only, won't work if you click on the buttons.
52
 
                        display_mode.mode_changed.connect (() =>{
53
 
                                options.display_mode = display_mode.selected;
54
 
                        });
55
 
                        options.settings.bind("display-mode", display_mode, "selected", SettingsBindFlags.DEFAULT);
56
 
 
57
 
 
58
 
                        this.pack_start (display_mode);
59
 
 
60
 
                        btn_screenshot = new Gtk.ToolButton (new Gtk.Image.from_icon_name ("camera-photo", Gtk.IconSize.SMALL_TOOLBAR), null);
61
 
                        btn_screenshot.set_tooltip_text (_("Take Screenshot"));
62
 
                        btn_screenshot.set_sensitive (false);
63
 
                        btn_screenshot.clicked.connect (() => {
64
 
                                on_take_screenshot_clicked ();
65
 
                        });
66
 
 
67
 
                        this.pack_start (btn_screenshot);
68
 
 
69
 
                        btn_readonly = new Gtk.ToggleToolButton ();
70
 
                        btn_readonly.set_icon_name("locked");
71
 
                        btn_readonly.set_tooltip_text (_("Input Lock"));
72
 
                        options.settings.bind("readonly", btn_readonly, "active", SettingsBindFlags.DEFAULT);
73
 
 
74
 
                        this.pack_start (btn_readonly);
75
 
 
76
 
                        preferences_item = new Gtk.MenuItem.with_label (_("Preferences"));
77
 
                        preferences_item.activate.connect (() => {
78
 
                                var dialog = new Dialogs.PreferencesDialog ();
79
 
                                dialog.response.connect ((source, response_id) => {
80
 
                                        dialog.destroy ();
81
 
                                });
82
 
                        });
83
 
 
84
 
                        main_menu = new Gtk.Menu ();
85
 
                        main_menu.add (preferences_item);
86
 
 
87
 
                        app_menu = parent.app.create_appmenu (main_menu);
88
 
 
89
 
                        this.pack_end (app_menu);
90
 
 
91
 
                        btn_connect = new Gtk.MenuToolButton (new Gtk.Image.from_icon_name ("user-bookmarks", Gtk.IconSize.SMALL_TOOLBAR), null);
92
 
                        btn_connect.set_tooltip_text (_("Server list"));
93
 
                        btn_connect.clicked.connect (() => {
94
 
                                show_connect_dialog (options.save_new_servers);
95
 
                        });
96
 
 
97
 
                        this.pack_end (btn_connect);
98
 
 
99
 
                        bookmarksmenu = new Widgets.BookmarksMenu ();
100
 
                        bookmarksmenu.on_bookmark_selected.connect ((host, port, user) => {
101
 
                                on_connect_request (host, port, user);
102
 
                        });
103
 
                        bookmarksmenu.on_new_bookmark_clicked.connect (() => {
104
 
                                show_connect_dialog (true);
105
 
                        });
106
 
                        btn_connect.set_menu (bookmarksmenu);
107
 
                }
108
 
 
109
 
                public void show_connect_dialog (bool save_as_bookmark) {
110
 
                        var dialog = new Dialogs.ConnectDialog ();
111
 
                        dialog.btn_bookmark.set_active (save_as_bookmark);
112
 
                        dialog.response.connect ((source, response_id) => {
113
 
                                switch (response_id) {
114
 
                                        case Gtk.ResponseType.CLOSE:
115
 
                                                dialog.destroy ();
116
 
                                                break;
117
 
                                        case Gtk.ResponseType.APPLY:
118
 
                                                on_connect_request (dialog.entry_host.text, dialog.entry_port.text, dialog.entry_user.text);
119
 
 
120
 
                                                if (dialog.btn_bookmark.active) {
121
 
                                                        var new_bookmark = "";
122
 
 
123
 
                                                        if (dialog.entry_bookmark.text == "") {
124
 
                                                                if (dialog.entry_user.text != "") {
125
 
                                                                        new_bookmark += dialog.entry_user.text + "@";
126
 
                                                                }
127
 
                                                                new_bookmark += dialog.entry_host.text + ":" + dialog.entry_port.text;
128
 
                                                        } else {
129
 
                                                                new_bookmark += dialog.entry_bookmark.text.replace ("|", "/");
130
 
                                                        }
131
 
 
132
 
                                                        new_bookmark += "|" + dialog.entry_host.text + "|" + dialog.entry_port.text + "|" + dialog.entry_user.text;
133
 
                                                        bookmarksmenu.add_bookmark (new_bookmark);
134
 
                                                }
135
 
 
136
 
                                                dialog.destroy ();
137
 
                                                break;
138
 
                                }
139
 
                        });
140
 
                }
141
 
        }
 
20
    public class TitleBar : Gtk.HeaderBar {
 
21
        public signal void on_take_screenshot_clicked ();
 
22
        public signal void on_connect_request (string host, string port, string user);
 
23
 
 
24
        private SettingsManager options;
 
25
 
 
26
        private Granite.Widgets.ModeButton display_mode;
 
27
 
 
28
        public Gtk.ToolButton btn_screenshot;
 
29
 
 
30
        private Gtk.ToggleToolButton btn_readonly;
 
31
 
 
32
        private Gtk.MenuToolButton btn_connect;
 
33
        public Widgets.BookmarksMenu bookmarksmenu;
 
34
 
 
35
        private Gtk.Menu main_menu;
 
36
        private Gtk.MenuItem preferences_item;
 
37
        private Granite.Widgets.AppMenu app_menu;
 
38
 
 
39
        public TitleBar (MainWindow parent) {
 
40
            options = new SettingsManager ();
 
41
 
 
42
            this.get_style_context ().add_class ("primary-toolbar");
 
43
            this.show_close_button = true;
 
44
            this.set_title (_ ("VNC-Client"));
 
45
 
 
46
            display_mode = new Granite.Widgets.ModeButton ();
 
47
            display_mode.set_margin_top (4);
 
48
            display_mode.set_margin_bottom (4);
 
49
            display_mode.append_icon ("zoom-fit-best-symbolic", Gtk.IconSize.BUTTON);
 
50
            display_mode.append_icon ("zoom-original-symbolic", Gtk.IconSize.BUTTON);
 
51
            // FIXME: Using settings.bind only, won't work if you click on the buttons.
 
52
            display_mode.mode_changed.connect (() => {
 
53
                options.display_mode = display_mode.selected;
 
54
            });
 
55
            options.settings.bind ("display-mode", display_mode, "selected", SettingsBindFlags.DEFAULT);
 
56
 
 
57
 
 
58
            this.pack_start (display_mode);
 
59
 
 
60
            btn_screenshot = new Gtk.ToolButton (new Gtk.Image.from_icon_name ("camera-photo", Gtk.IconSize.SMALL_TOOLBAR), null);
 
61
            btn_screenshot.set_tooltip_text (_ ("Take Screenshot"));
 
62
            btn_screenshot.set_sensitive (false);
 
63
            btn_screenshot.clicked.connect (() => {
 
64
                on_take_screenshot_clicked ();
 
65
            });
 
66
 
 
67
            this.pack_start (btn_screenshot);
 
68
 
 
69
            btn_readonly = new Gtk.ToggleToolButton ();
 
70
            btn_readonly.set_icon_name ("locked");
 
71
            btn_readonly.set_tooltip_text (_ ("Input Lock"));
 
72
            options.settings.bind ("readonly", btn_readonly, "active", SettingsBindFlags.DEFAULT);
 
73
 
 
74
            this.pack_start (btn_readonly);
 
75
 
 
76
            preferences_item = new Gtk.MenuItem.with_label (_ ("Preferences"));
 
77
            preferences_item.activate.connect (() => {
 
78
                var dialog = new Dialogs.PreferencesDialog ();
 
79
                dialog.response.connect ((source, response_id) => {
 
80
                    dialog.destroy ();
 
81
                });
 
82
            });
 
83
 
 
84
            main_menu = new Gtk.Menu ();
 
85
            main_menu.add (preferences_item);
 
86
 
 
87
            app_menu = parent.app.create_appmenu (main_menu);
 
88
 
 
89
            this.pack_end (app_menu);
 
90
 
 
91
            btn_connect = new Gtk.MenuToolButton (new Gtk.Image.from_icon_name ("user-bookmarks", Gtk.IconSize.SMALL_TOOLBAR),
 
92
                                                  null);
 
93
            btn_connect.set_tooltip_text (_ ("Server list"));
 
94
            btn_connect.clicked.connect (() => {
 
95
                show_connect_dialog (options.save_new_servers);
 
96
            });
 
97
 
 
98
            this.pack_end (btn_connect);
 
99
 
 
100
            bookmarksmenu = new Widgets.BookmarksMenu ();
 
101
            bookmarksmenu.on_bookmark_selected.connect ((host, port, user) => {
 
102
                on_connect_request (host, port, user);
 
103
            });
 
104
            bookmarksmenu.on_new_bookmark_clicked.connect (() => {
 
105
                show_connect_dialog (true);
 
106
            });
 
107
            btn_connect.set_menu (bookmarksmenu);
 
108
        }
 
109
 
 
110
        public void show_connect_dialog (bool save_as_bookmark) {
 
111
            var dialog = new Dialogs.ConnectDialog ();
 
112
            dialog.btn_bookmark.set_active (save_as_bookmark);
 
113
            dialog.response.connect ((source, response_id) => {
 
114
                switch (response_id) {
 
115
                    case Gtk.ResponseType.CLOSE:
 
116
                        dialog.destroy ();
 
117
                        break;
 
118
 
 
119
                    case Gtk.ResponseType.APPLY:
 
120
                        on_connect_request (dialog.entry_host.text, dialog.entry_port.text, dialog.entry_user.text);
 
121
 
 
122
                        if (dialog.btn_bookmark.active) {
 
123
                            var new_bookmark = "";
 
124
 
 
125
                            if (dialog.entry_bookmark.text == "") {
 
126
                                if (dialog.entry_user.text != "") {
 
127
                                    new_bookmark += dialog.entry_user.text + "@";
 
128
                                }
 
129
 
 
130
                                new_bookmark += dialog.entry_host.text + ":" + dialog.entry_port.text;
 
131
                            } else {
 
132
                                new_bookmark += dialog.entry_bookmark.text.replace ("|", "/");
 
133
                            }
 
134
 
 
135
                            new_bookmark += "|" + dialog.entry_host.text + "|" + dialog.entry_port.text + "|" + dialog.entry_user.text;
 
136
                            bookmarksmenu.add_bookmark (new_bookmark);
 
137
                        }
 
138
 
 
139
                        dialog.destroy ();
 
140
                        break;
 
141
                }
 
142
            });
 
143
        }
 
144
    }
142
145
}
 
 
b'\\ No newline at end of file'