Merge lp:~michaelaquilina/synapse-project/tomboy-notes-plugin into lp:synapse-project

Proposed by Michael Aquilina
Status: Needs review
Proposed branch: lp:~michaelaquilina/synapse-project/tomboy-notes-plugin
Merge into: lp:synapse-project
Diff against target: 242 lines (+194/-0)
5 files modified
po/POTFILES.in (+1/-0)
po/POTFILES.skip (+1/-0)
src/plugins/Makefile.am (+1/-0)
src/plugins/tomboy-notes-plugin.vala (+190/-0)
src/ui/synapse-main.vala (+1/-0)
To merge this branch: bzr merge lp:~michaelaquilina/synapse-project/tomboy-notes-plugin
Reviewer Review Type Date Requested Status
Synapse core team Pending
Review via email: mp+286745@code.launchpad.net

Description of the change

This simple plugin adds support for searching and opening existing tomboy notes.

To post a comment you must log in.
Revision history for this message
Michael Aquilina (michaelaquilina) wrote :

This new plugin is a lot more simple than the pass plugin if you want to give it a quick look

Revision history for this message
Rico Tzschichholz (ricotz) wrote :

The clean up diff of "pass" should provide some hints which can be applied here too.

Also keep the files in Makefile.am in alphabetical order.
Cache values which are reused like "info.get_name ()"

637. By Michael Aquilina

Add tomboy notes plugin

Revision history for this message
Michael Aquilina (michaelaquilina) wrote :

Updated

Revision history for this message
Michael Aquilina (michaelaquilina) wrote :

any feedback on this?

Revision history for this message
Michael Aquilina (michaelaquilina) wrote :

@ricotz are we good to merge this in?

Unmerged revisions

637. By Michael Aquilina

Add tomboy notes plugin

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'po/POTFILES.in'
--- po/POTFILES.in 2016-02-26 16:57:32 +0000
+++ po/POTFILES.in 2016-03-03 12:14:31 +0000
@@ -40,6 +40,7 @@
40src/plugins/selection-plugin.vala40src/plugins/selection-plugin.vala
41src/plugins/ssh-plugin.vala41src/plugins/ssh-plugin.vala
42src/plugins/system-management.vala42src/plugins/system-management.vala
43src/plugins/tomboy-notes-plugin.vala
43src/plugins/xnoise-media-player-plugin.vala44src/plugins/xnoise-media-player-plugin.vala
44src/plugins/zeitgeist-plugin.vala45src/plugins/zeitgeist-plugin.vala
45src/plugins/zeitgeist-related.vala46src/plugins/zeitgeist-related.vala
4647
=== modified file 'po/POTFILES.skip'
--- po/POTFILES.skip 2016-02-26 16:57:32 +0000
+++ po/POTFILES.skip 2016-03-03 12:14:31 +0000
@@ -41,6 +41,7 @@
41src/plugins/selection-plugin.c41src/plugins/selection-plugin.c
42src/plugins/ssh-plugin.c42src/plugins/ssh-plugin.c
43src/plugins/system-management.c43src/plugins/system-management.c
44src/plugins/tomboy-notes-plugin.c
44src/plugins/xnoise-media-player-plugin.c45src/plugins/xnoise-media-player-plugin.c
45src/plugins/zeitgeist-plugin.c46src/plugins/zeitgeist-plugin.c
46src/plugins/zeitgeist-related.c47src/plugins/zeitgeist-related.c
4748
=== modified file 'src/plugins/Makefile.am'
--- src/plugins/Makefile.am 2016-02-26 16:57:32 +0000
+++ src/plugins/Makefile.am 2016-03-03 12:14:31 +0000
@@ -50,6 +50,7 @@
50 rhythmbox-plugin.vala \50 rhythmbox-plugin.vala \
51 selection-plugin.vala \51 selection-plugin.vala \
52 test-slow-plugin.vala \52 test-slow-plugin.vala \
53 tomboy-notes-plugin.vala \
53 xnoise-media-player-plugin.vala \54 xnoise-media-player-plugin.vala \
54 system-management.vala \55 system-management.vala \
55 zeal-plugin.vala \56 zeal-plugin.vala \
5657
=== added file 'src/plugins/tomboy-notes-plugin.vala'
--- src/plugins/tomboy-notes-plugin.vala 1970-01-01 00:00:00 +0000
+++ src/plugins/tomboy-notes-plugin.vala 2016-03-03 12:14:31 +0000
@@ -0,0 +1,190 @@
1/*
2 * Copyright (C) 2011 Michael Aquilina <michaelaquilina@gmail.com>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
17 *
18 * Authored by Michael Aquilina <michaelaquilina@gmail.com>
19 *
20 */
21
22namespace Synapse
23{
24 public class TomboyNotesPlugin : Object, Activatable, ItemProvider
25 {
26 public bool enabled { get; set; default = true; }
27
28 private List<TomboyNoteMatch> notes;
29 private FileMonitor tomboy_monitor;
30
31 public void activate ()
32 {
33 File note_storage = File.new_for_path (
34 "%s/.local/share/tomboy".printf (Environment.get_home_dir ())
35 );
36 try {
37 notes = list_tomboy_notes (note_storage);
38 } catch (Error err) {
39 warning ("%s", err.message);
40 }
41
42 tomboy_monitor = note_storage.monitor (FileMonitorFlags.SEND_MOVED, null);
43 tomboy_monitor.set_rate_limit (500);
44 tomboy_monitor.changed.connect ( (src, dest, event) => {
45 string src_path = src.get_path ();
46 if (src_path.has_suffix (".note")) {
47 message ("Reloading notes due to change in %s (%s)", src_path, event.to_string ());
48 try {
49 notes = list_tomboy_notes (note_storage);
50 } catch (Error err) {
51 warning ("Unable to list tomboy notes: %s", err.message);
52 }
53 }
54 });
55 }
56
57 public void deactivate ()
58 {
59 tomboy_monitor.cancel();
60 }
61
62 static void register_plugin ()
63 {
64 PluginRegistry.get_default ().register_plugin (
65 typeof (TomboyNotesPlugin),
66 _("Tomboy Notes"),
67 _("Search for tomboy notes."),
68 "tomboy",
69 register_plugin,
70 Environment.find_program_in_path ("tomboy") != null,
71 _("Tomboy Notes is not installed")
72 );
73 }
74
75 static construct
76 {
77 register_plugin ();
78 }
79
80 public string? get_note_title (File note_file) throws Error {
81 FileIOStream ios = note_file.open_readwrite ();
82 FileInputStream @is = ios.input_stream as FileInputStream;
83 DataInputStream dis = new DataInputStream (@is);
84
85 string line;
86 while ((line = dis.read_line ()) != null) {
87 if (Regex.match_simple ("<title>.*</title>", line)) {
88 line = line.replace ("<title>", "");
89 line = line.replace ("</title>", "");
90 return line.strip ();
91 }
92 }
93 dis.close();
94 is.close();
95 ios.close();
96
97 return null;
98 }
99
100 private List<TomboyNoteMatch> list_tomboy_notes (File directory) throws Error {
101 List<TomboyNoteMatch> result = new List<TomboyNoteMatch> ();
102
103 FileEnumerator enumerator = directory.enumerate_children (
104 FileAttribute.STANDARD_NAME + "," +
105 FileAttribute.STANDARD_TYPE,
106 FileQueryInfoFlags.NOFOLLOW_SYMLINKS,
107 null
108 );
109
110 FileInfo? info = null;
111 while ((info = enumerator.next_file (null)) != null) {
112 string file_name = info.get_name ();
113 File note_file = directory.get_child (file_name);
114
115 if (info.get_file_type () == FileType.REGULAR && file_name.has_suffix (".note")) {
116 try {
117 var match = new TomboyNoteMatch(
118 get_note_title (note_file),
119 note_file.get_path ()
120 );
121 result.append (match);
122 } catch (Error err) {
123 warning ("%s", err.message);
124 }
125 }
126 }
127 return result;
128 }
129
130 public bool handles_query (Query query)
131 {
132 return (QueryFlags.ACTIONS in query.query_type);
133 }
134
135 public async ResultSet? search (Query query) throws SearchError
136 {
137 var matchers = Query.get_matchers_for_query (
138 query.query_string, 0,
139 RegexCompileFlags.OPTIMIZE | RegexCompileFlags.CASELESS
140 );
141
142 var results = new ResultSet ();
143 foreach (unowned TomboyNoteMatch note in notes)
144 {
145 foreach (var matcher in matchers)
146 {
147 if (matcher.key.match (note.title)) {
148 results.add (note, MatchScore.GOOD);
149 break;
150 }
151 }
152 }
153
154 // make sure this method is called before returning any results
155 query.check_cancellable ();
156 if (results.size > 0) {
157 return results;
158 } else {
159 return null;
160 }
161 }
162
163 private class TomboyNoteMatch : ActionMatch
164 {
165 private string url;
166
167 public TomboyNoteMatch (string note_title, string url)
168 {
169 Object (title: note_title,
170 description: _("Open Tomboy Note"),
171 has_thumbnail: false,
172 icon_name: "tomboy");
173 this.url = url;
174 }
175
176 public override void do_action ()
177 {
178 try
179 {
180 AppInfo ai = AppInfo.create_from_commandline (
181 "tomboy --open-note %s".printf (url), "tomboy", 0
182 );
183 ai.launch (null, null);
184 } catch (Error err) {
185 warning ("%s", err.message);
186 }
187 }
188 }
189 }
190}
0191
=== modified file 'src/ui/synapse-main.vala'
--- src/ui/synapse-main.vala 2016-02-27 15:19:21 +0000
+++ src/ui/synapse-main.vala 2016-03-03 12:14:31 +0000
@@ -175,6 +175,7 @@
175 typeof (FileOpPlugin),175 typeof (FileOpPlugin),
176 typeof (PidginPlugin),176 typeof (PidginPlugin),
177 typeof (ChatActions),177 typeof (ChatActions),
178 typeof (TomboyNotesPlugin),
178 typeof (ZealPlugin),179 typeof (ZealPlugin),
179#if HAVE_ZEITGEIST180#if HAVE_ZEITGEIST
180 typeof (ZeitgeistPlugin),181 typeof (ZeitgeistPlugin),