~lemonboy/capnet-assist/ssl-status

« back to all changes in this revision

Viewing changes to src/CaptiveLogin.vala

  • Committer: LemonBoy
  • Date: 2015-10-26 01:12:42 UTC
  • Revision ID: thatlemon@gmail.com-20151026011242-2nrs0ivrad9707j1
Stylistic touchups

Show diffs side-by-side

added added

removed removed

Lines of Context:
42
42
 
43
43
        this.set_titlebar (header);
44
44
 
45
 
        this.tls_button = new Gtk.ToggleButton ();
46
 
        this.tls_button.set_image (new Gtk.Image.from_icon_name ("content-loading-symbolic", Gtk.IconSize.BUTTON));
47
 
        this.tls_button.get_style_context ().add_class (Gtk.STYLE_CLASS_FLAT);
48
 
        this.tls_button.get_style_context ().add_class ("titlebutton");
49
 
        this.tls_button.set_sensitive (false);
50
 
        this.tls_button.toggled.connect (on_tls_button_click);
 
45
        tls_button = new Gtk.ToggleButton ();
 
46
        tls_button.set_image (new Gtk.Image.from_icon_name ("content-loading-symbolic", Gtk.IconSize.BUTTON));
 
47
        var tls_button_style_context = tls_button.get_style_context ();
 
48
        tls_button_style_context.add_class (Gtk.STYLE_CLASS_FLAT);
 
49
        tls_button_style_context.add_class ("titlebutton");
 
50
        tls_button.set_sensitive (false);
 
51
        tls_button.toggled.connect (on_tls_button_click);
51
52
 
52
53
        var hbox = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 6);
53
54
        hbox.set_margin_top (3);
54
55
        hbox.set_margin_bottom (3);
55
 
        hbox.pack_start (this.tls_button);
56
 
        this.title_label = new Gtk.Label (ValaBrowser.TITLE);
57
 
        this.title_label.get_style_context ().add_class (Gtk.STYLE_CLASS_TITLE);
 
56
        hbox.pack_start (tls_button);
 
57
 
 
58
        title_label = new Gtk.Label (ValaBrowser.TITLE);
 
59
        title_label.get_style_context ().add_class (Gtk.STYLE_CLASS_TITLE);
58
60
        hbox.pack_start (title_label);
59
61
 
60
62
        header.set_custom_title (hbox);
61
63
 
62
 
        this.web_view = new WebKit.WebView ();
 
64
        web_view = new WebKit.WebView ();
63
65
 
64
66
        var scrolled_window = new Gtk.ScrolledWindow (null, null);
65
67
        scrolled_window.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
66
 
        scrolled_window.add (this.web_view);
 
68
        scrolled_window.add (web_view);
67
69
 
68
70
        var vbox = new Gtk.Box (Gtk.Orientation.VERTICAL, 0);
69
 
        vbox.set_homogeneous (false);
70
71
        vbox.pack_start (scrolled_window, true, true, 0);
71
72
 
72
73
        add (vbox);
99
100
        Icon icon;
100
101
        bool is_secure;
101
102
 
102
 
        if (!this.web_view.get_tls_info (out cert, out cert_flags)) {
 
103
        if (!web_view.get_tls_info (out cert, out cert_flags)) {
103
104
            // The page is served over HTTP
104
105
            is_secure = false;
105
106
        } else {
110
111
 
111
112
        if (is_secure) {
112
113
            icon = new ThemedIcon.from_names ({"channel-secure-symbolic", "security-high"});
113
 
            this.tls_button.set_tooltip_text ("The page is served over a protected connection.");
 
114
            tls_button.set_tooltip_text ("The page is served over a protected connection.");
114
115
        } else {
115
116
            icon = new ThemedIcon.from_names ({"channel-insecure-symbolic", "security-low"});
116
 
            this.tls_button.set_tooltip_text ("The page is served over an unprotected connection.");
 
117
            tls_button.set_tooltip_text ("The page is served over an unprotected connection.");
117
118
        }
118
119
 
119
120
        var image = new Gtk.Image.from_gicon (icon, Gtk.IconSize.BUTTON);
120
 
        this.tls_button.set_image (image);
 
121
        tls_button.set_image (image);
121
122
    }
122
123
 
123
124
    private void on_tls_button_click () {
124
125
        TlsCertificate cert;
125
126
        TlsCertificateFlags cert_flags;
126
127
 
127
 
        if (!this.tls_button.get_active ()) {
128
 
            return;
129
 
        }
130
 
 
131
 
        if (!this.web_view.get_tls_info (out cert, out cert_flags)) {
132
 
            return;
133
 
        }
134
 
 
135
 
        var popover = new Gtk.Popover (this.tls_button);
 
128
        if (!tls_button.get_active ()) {
 
129
            return;
 
130
        }
 
131
        if (!web_view.get_tls_info (out cert, out cert_flags)) {
 
132
            return;
 
133
        }
 
134
 
 
135
        var popover = new Gtk.Popover (tls_button);
136
136
        popover.set_border_width (6);
137
137
        var vbox = new Gtk.Box (Gtk.Orientation.VERTICAL, 6);
138
 
        vbox.set_homogeneous (false);
139
138
        popover.add (vbox);
140
 
        var hbox = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 6);
141
 
        hbox.set_homogeneous (false);
 
139
 
142
140
        // Wonderful hack we got here, the vapi for Gtk has a wrong definition
143
141
        // for the get_gicon () method, it's not reported as an out parameter
144
142
        // hence we're stuck with passing everything by value.
145
143
        // Since we're badass we pass the INVALID constant that evaluates to 0
146
144
        // which is casted into a NULL pointer and allows us to save the date.
147
145
        Icon button_icon;
148
 
        (this.tls_button.get_image () as Gtk.Image).get_gicon (out button_icon, Gtk.IconSize.INVALID);
 
146
        (tls_button.get_image () as Gtk.Image).get_gicon (out button_icon, Gtk.IconSize.INVALID);
 
147
 
 
148
        var hbox = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 6);
149
149
        hbox.pack_start (new Gtk.Image.from_gicon (button_icon, Gtk.IconSize.LARGE_TOOLBAR), false, false);
150
 
        hbox.pack_start (new Gtk.Label (this.tls_button.get_tooltip_text ()), false, false);
 
150
        hbox.pack_start (new Gtk.Label (tls_button.get_tooltip_text ()), false, false);
151
151
        vbox.pack_start (hbox, false, false);
152
152
 
153
153
        var gcr_cert = new Gcr.SimpleCertificate (cert.certificate.data);
173
173
                    event.y < child_alloc.y ||
174
174
                    event.y > child_alloc.y + child_alloc.height) {
175
175
                    popover.hide ();
176
 
                    this.tls_button.set_active (false);
 
176
                    tls_button.set_active (false);
177
177
                }
178
 
 
179
178
            } 
180
179
            else if (event_widget != null && !event_widget.is_ancestor (popover)) {
181
180
                popover.hide ();
182
 
                this.tls_button.set_active (false);
 
181
                tls_button.set_active (false);
183
182
            }
184
183
 
185
184
            return true;
193
192
    private void connect_signals () {
194
193
        this.destroy.connect (Gtk.main_quit);
195
194
        //should title change?
196
 
        this.web_view.notify["title"].connect ((view, param_spec) => {
197
 
            this.title_label.set_text (this.web_view.get_title ());
 
195
        web_view.notify["title"].connect ((view, param_spec) => {
 
196
            title_label.set_text (web_view.get_title ());
198
197
        });
199
198
 
200
 
        this.web_view.load_changed.connect ((view, event) => {
 
199
        web_view.load_changed.connect ((view, event) => {
201
200
            switch (event) {
202
 
            case WebKit.LoadEvent.FINISHED:
203
 
                if (isLoggedIn ()) {
204
 
                    debug ("Logged in!");
205
 
                    Gtk.main_quit ();
206
 
                } else {
207
 
                    debug ("Still not logged in.");
208
 
                }
209
 
                break;
210
 
 
211
 
            case WebKit.LoadEvent.STARTED:
212
 
                this.tls_button.set_sensitive (false);
213
 
                break;
214
 
 
215
 
            case WebKit.LoadEvent.COMMITTED:
216
 
                update_tls_info ();
217
 
                this.tls_button.set_sensitive (true);
218
 
                break;
 
201
                case WebKit.LoadEvent.FINISHED:
 
202
                    if (isLoggedIn ()) {
 
203
                        debug ("Logged in!");
 
204
                        Gtk.main_quit ();
 
205
                    } else {
 
206
                        debug ("Still not logged in.");
 
207
                    }
 
208
                    break;
 
209
 
 
210
                case WebKit.LoadEvent.STARTED:
 
211
                    tls_button.set_sensitive (false);
 
212
                    break;
 
213
 
 
214
                case WebKit.LoadEvent.COMMITTED:
 
215
                    update_tls_info ();
 
216
                    tls_button.set_sensitive (true);
 
217
                    break;
219
218
            }
220
219
        });
221
220
 
222
 
        this.web_view.load_failed.connect ((event, uri, error) => {
 
221
        web_view.load_failed.connect ((event, uri, error) => {
223
222
            // The user has canceled the page loading eg. by clicking on a link.
224
223
            if ((Error)error is WebKit.NetworkError.CANCELLED) {
225
224
                return true;
232
231
 
233
232
    public void start () {
234
233
        show_all ();
235
 
        this.web_view.load_uri (ValaBrowser.DUMMY_URL);
 
234
        web_view.load_uri (ValaBrowser.DUMMY_URL);
236
235
    }
237
236
 
238
237
    public static int main (string[] args) {