Merge lp:~ivaldi/midori/devpet into lp:midori

Proposed by André Stösel
Status: Merged
Approved by: Cris Dywan
Approved revision: 6292
Merged at revision: 6296
Proposed branch: lp:~ivaldi/midori/devpet
Merge into: lp:midori
Diff against target: 162 lines (+158/-0)
1 file modified
extensions/devpet.vala (+158/-0)
To merge this branch: bzr merge lp:~ivaldi/midori/devpet
Reviewer Review Type Date Requested Status
Cris Dywan Approve
Paweł Forysiuk Approve
Review via email: mp+177678@code.launchpad.net

Commit message

New extesion for developers which shows error messages in systray

Description of the change

Use case: daily usage, when midori isn't attached to a terminal

To post a comment you must log in.
Revision history for this message
Paweł Forysiuk (tuxator) wrote :

Looks ok.

review: Approve
Revision history for this message
Cris Dywan (kalikiana) wrote :

This requires an X11 systray, any plans to make it work without? How about a statusbar icon?
I don't feel personally it should actually show up anywhere outside Midori itself, though that might be debatable.

review: Needs Information
Revision history for this message
André Stösel (ivaldi) wrote :

Honestly, I don't like the statusbar very much :/

The systray is a "standardized" spot where I'm used to get notified.
The statusbar is inside a midori window, which wouldn't work well for multi window users.

Revision history for this message
Cris Dywan (kalikiana) wrote :

As discussed, it's a good start even if it only works with a system tray. We should look into a notification API for core/ extensions to add actionable status icons irrespective of where it'll appear and devpet can be modified to take advantage of it then.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'extensions/devpet.vala'
2--- extensions/devpet.vala 1970-01-01 00:00:00 +0000
3+++ extensions/devpet.vala 2013-07-30 19:46:28 +0000
4@@ -0,0 +1,158 @@
5+/*
6+ Copyright (C) 2013 André Stösel <andre@stoesel.de>
7+
8+ This library is free software; you can redistribute it and/or
9+ modify it under the terms of the GNU Lesser General Public
10+ License as published by the Free Software Foundation; either
11+ version 2.1 of the License, or (at your option) any later version.
12+
13+ See the file COPYING for the full license text.
14+*/
15+
16+Gtk.IconTheme theme;
17+
18+namespace DevPet {
19+ enum TreeCells {
20+ MESSAGE,
21+ STOCK,
22+ COUNT
23+ }
24+
25+ private class LogWindow : Gtk.Window {
26+ private Manager manager;
27+
28+ private void clear_list () {
29+ this.manager.clear_list ();
30+ this.destroy ();
31+ }
32+
33+ private void create_content () {
34+ this.title = "Midori - DevPet";
35+ this.set_default_size (500, 250);
36+ this.destroy.connect (this.manager.log_window_closed);
37+
38+ Gtk.VBox vbox = new Gtk.VBox (false, 1);
39+ this.add (vbox);
40+
41+ Gtk.ScrolledWindow scroll_windows = new Gtk.ScrolledWindow (null, null);
42+ scroll_windows.set_policy (Gtk.PolicyType.NEVER , Gtk.PolicyType.AUTOMATIC);
43+ scroll_windows.set_shadow_type (Gtk.ShadowType.ETCHED_IN);
44+
45+
46+ Gtk.Button clear = new Gtk.Button.from_stock ("gtk-clear");
47+ clear.clicked.connect (this.clear_list);
48+
49+ vbox.pack_start (scroll_windows, true, true, 0);
50+ vbox.pack_start (clear, false, false, 0);
51+
52+
53+ Gtk.TreeView treeview = new Gtk.TreeView.with_model (this.manager.list_store);
54+ scroll_windows.add (treeview);
55+
56+ treeview.insert_column_with_attributes (
57+ -1, "Type",
58+ new Gtk.CellRendererPixbuf (), "pixbuf", TreeCells.STOCK);
59+ treeview.insert_column_with_attributes (
60+ -1, "Message",
61+ new Gtk.CellRendererText (), "text", TreeCells.MESSAGE);
62+
63+ this.show_all ();
64+ }
65+
66+ internal LogWindow (Manager manager) {
67+ GLib.Object (type: Gtk.WindowType.TOPLEVEL,
68+ window_position: Gtk.WindowPosition.CENTER);
69+
70+ this.manager = manager;
71+ this.create_content ();
72+ }
73+ }
74+
75+ private class Manager : Midori.Extension {
76+ public Gtk.ListStore list_store;
77+ private Gtk.StatusIcon trayicon;
78+ private LogWindow? log_window;
79+ private GLib.LogFunc default_log_func;
80+ private GLib.LogLevelFlags icon_flag = GLib.LogLevelFlags.LEVEL_DEBUG;
81+
82+ public void clear_list() {
83+ this.icon_flag = GLib.LogLevelFlags.LEVEL_DEBUG;
84+ this.trayicon.set_visible (false);
85+ this.list_store.clear ();
86+ }
87+
88+ public void log_window_closed () {
89+ this.log_window = null;
90+ }
91+
92+ private unowned string get_stock_from_log_level (GLib.LogLevelFlags flags) {
93+ if ((flags & LogLevelFlags.LEVEL_CRITICAL) == flags || (flags & LogLevelFlags.LEVEL_ERROR) == flags) {
94+ return Gtk.Stock.DIALOG_ERROR;
95+ } else if ((flags & LogLevelFlags.LEVEL_WARNING) == flags) {
96+ return Gtk.Stock.DIALOG_WARNING;
97+ }
98+ return Gtk.Stock.DIALOG_INFO;
99+ }
100+
101+ private void log_handler(string? domain, GLib.LogLevelFlags flags, string message) {
102+ Gtk.TreeIter iter;
103+ unowned string stock = this.get_stock_from_log_level (flags);
104+
105+ if (flags < this.icon_flag) {
106+ this.icon_flag = flags;
107+ this.trayicon.set_from_stock (stock);
108+ }
109+
110+ this.list_store.append (out iter);
111+ this.list_store.set (iter, TreeCells.MESSAGE, message, TreeCells.STOCK, theme.load_icon (stock, 16, 0));
112+
113+ this.trayicon.set_visible (true);
114+ }
115+
116+ private void show_error_log () {
117+ if (this.log_window == null) {
118+ this.log_window = new LogWindow (this);
119+ this.log_window.show ();
120+ } else {
121+ if (this.log_window.is_active) {
122+ this.log_window.hide ();
123+ } else {
124+ this.log_window.present ();
125+ }
126+ }
127+ }
128+
129+ private void activated (Midori.App app) {
130+ this.trayicon.set_visible (false);
131+ this.default_log_func = GLib.Log.default_handler;
132+ GLib.Log.set_default_handler (this.log_handler);
133+ }
134+
135+ private void deactivated () {
136+ this.trayicon.set_visible (false);
137+ GLib.Log.set_default_handler (this.default_log_func);
138+ }
139+
140+ internal Manager () {
141+ GLib.Object (name: _("DevPet"),
142+ description: _("This extension shows glib error messages in systray."),
143+ version: "0.1",
144+ authors: "André Stösel <andre@stoesel.de>");
145+
146+ this.trayicon = new Gtk.StatusIcon ();
147+ this.trayicon.set_tooltip_text ("Midori - DevPet");
148+ this.trayicon.activate.connect(this.show_error_log);
149+
150+ this.list_store = new Gtk.ListStore (TreeCells.COUNT, typeof(string), typeof (Gdk.Pixbuf));
151+
152+ this.activate.connect (this.activated);
153+ this.deactivate.connect (this.deactivated);
154+ }
155+ }
156+}
157+
158+public Midori.Extension extension_init () {
159+ theme = Gtk.IconTheme.get_default ();
160+ return new DevPet.Manager ();
161+}
162+

Subscribers

People subscribed via source and target branches

to all changes: