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

Subscribers

People subscribed via source and target branches

to all changes: