Merge lp:~3v1n0/bamf/class-to-index-file into lp:bamf/0.4

Proposed by Marco Trevisan (Treviño)
Status: Merged
Approved by: Marco Trevisan (Treviño)
Approved revision: 530
Merged at revision: 526
Proposed branch: lp:~3v1n0/bamf/class-to-index-file
Merge into: lp:bamf/0.4
Diff against target: 188 lines (+120/-6)
2 files modified
debian/bamfdaemon.postinst (+74/-3)
src/bamf-matcher.c (+46/-3)
To merge this branch: bzr merge lp:~3v1n0/bamf/class-to-index-file
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
Loïc Minier Approve
Brandon Schaefer (community) Approve
Review via email: mp+155979@code.launchpad.net

Commit message

debian/bamfdaemon.postinst: write it in multiline and add support for StartupWMClass

And other properties such as NoDisplay and OnlyShowIn.

Also rewritten the bamfdaemon.postinst to use a multi-line perl script for easier review.

Description of the change

Save to the /usr/share/applications/bamf.index columns containing extra parameters such as StartupWMClass, NoDisplay and OnlyShowIn. Update the bamf-matcher to use them instead of parse these from .desktop files, saving some IO.

To post a comment you must log in.
lp:~3v1n0/bamf/class-to-index-file updated
527. By Marco Trevisan (Treviño)

debian/bamfdaemon.postinst: indentation fix

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Loïc Minier (lool) wrote :

Hey,

r525: ok; the bits of Perl are written like C, but eh decently readable and it seems like they will work :-)

r526:
- strstr() seems a bit weak to match OnlyShowIn; that would work for now, but what if we want to implement e.g. Unity-Next in .desktop files? might be best to split on ";" properly here
- is it ok to g_hash_table_insert direclty instead of using something like insert_desktop_file_class_into_table?

r527: ok

Some problems not directly related, but worth fixing:
* no version information in bamf index; you could have a version depending on the filename (e.g. this could be bamf-2.0.index)
* should this be in /var/cache or /var/lib, but not in /usr/share? it's actually only modified when packages are added/removed (.desktop files), but seems a bit weird to have a locally generated file under /usr/share
* generally, I haven't checked how whitespace is handled in .desktop files (e.g. if the .desktop file contains trailing or leading spaces or tabs around key names / key values)

(not sure how ~/ .desktop are handled, but I guess that's another story)

Thanks,

Revision history for this message
Marco Trevisan (Treviño) (3v1n0) wrote :

> Hey,
>
> r525: ok; the bits of Perl are written like C, but eh decently readable and it
> seems like they will work :-)

We needed to clean them up :)

> r526:
> - strstr() seems a bit weak to match OnlyShowIn; that would work for now, but
> what if we want to implement e.g. Unity-Next in .desktop files? might be best
> to split on ";" properly here

Ok, it was my same idea at the beginning, then I forgot to finish it waiting to test this :)

> - is it ok to g_hash_table_insert direclty instead of using something like
> insert_desktop_file_class_into_table?

Yes. Using insert_desktop_file_class_into_table causes to open the file again, and so to use io-blocking functions, while we want to avoid this since this data is already provided by the index file.

> r527: ok
>
> Some problems not directly related, but worth fixing:
> * no version information in bamf index; you could have a version depending on
> the filename (e.g. this could be bamf-2.0.index)

Yes, it makes sense... Even if this file will be always built before the new bamf will able to use it so it should be quite safe.

> * should this be in /var/cache or /var/lib, but not in /usr/share? it's
> actually only modified when packages are added/removed (.desktop files), but
> seems a bit weird to have a locally generated file under /usr/share

Yes, probably true. But the idea is that you can also add a bamf.index file inside another monitored folder and use it instead of manual directory parsing.

> * generally, I haven't checked how whitespace is handled in .desktop files
> (e.g. if the .desktop file contains trailing or leading spaces or tabs around
> key names / key values)

There shouldn't be issues for this. Also luckily there are no problems with the provided .desktop files in raring, but maybe having stronger regex could help.

Revision history for this message
Brandon Schaefer (brandontschaefer) wrote :

LGTM. Tests pass as well.

review: Approve
lp:~3v1n0/bamf/class-to-index-file updated
528. By Marco Trevisan (Treviño)

debian/bamfdaemon.postinst: trim the parsed strings

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
lp:~3v1n0/bamf/class-to-index-file updated
529. By Marco Trevisan (Treviño)

Use g_strsplit to handle OnlyShowIn values

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
lp:~3v1n0/bamf/class-to-index-file updated
530. By Marco Trevisan (Treviño)

BamfMatcher: use bamf-2.index file

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Loïc Minier (lool) wrote :

Looks good; thanks for the fixes, now why does it break jenkins?
cc: error: unrecognized command line option '--c-include=libbamf/libbamf.h'

review: Approve
Revision history for this message
Marco Trevisan (Treviño) (3v1n0) wrote :

> Looks good; thanks for the fixes, now why does it break jenkins?
> cc: error: unrecognized command line option '--c-include=libbamf/libbamf.h'

There have been changes to glib and the gobject introspection not related to this branch, the fixes are landing right now in lp:~3v1n0/bamf/fix-trunk-compilation-tests

Revision history for this message
PS Jenkins bot (ps-jenkins) :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'debian/bamfdaemon.postinst'
2--- debian/bamfdaemon.postinst 2012-10-17 06:02:25 +0000
3+++ debian/bamfdaemon.postinst 2013-03-28 20:01:22 +0000
4@@ -1,13 +1,84 @@
5 #! /bin/sh
6 set -e
7
8+BAMF_INDEX_NAME="bamf-2.index"
9+
10 if [ "$1" = "configure" ] || [ "$1" = "triggered" ]; then
11 if [ -d /usr/share/applications ]; then
12 # rebuild index
13- I=/usr/share/applications/bamf.index
14- echo "Rebuilding $I..."
15+ I=/usr/share/applications/$BAMF_INDEX_NAME
16+ echo "Rebuilding $I..."
17 rm -f $I
18- perl -e 'use File::Find; my $dir_name; sub strip_exec { my $f = $_; return unless $f =~ /\.desktop$/; return unless ("$File::Find::dir" eq "$dir_name"); my @lines; open F, $f; @lines = <F>; close F; my $in_desktop_entry = 0; foreach (@lines) { if (/^\[\s*(.+)\s*\]/) { $in_desktop_entry = ($1 eq "Desktop Entry"); } if (/^Exec=(.+)$/ && $in_desktop_entry) { print "$f\t$1\n"; } } }; $dir_name = $ARGV[-1]; $dir_name = $1 if($dir_name=~/(.*)\/$/); find(\&strip_exec, $dir_name);' /usr/share/applications > $I.new || rm -f $I.new
19+ perl -e '
20+use File::Find;
21+my $dir_name;
22+
23+sub strip_exec
24+{
25+ my $f = $_;
26+ return unless $f =~ /\.desktop$/;
27+ return unless ("$File::Find::dir" eq "$dir_name");
28+ my @lines;
29+ open F, $f;
30+ @lines = <F>;
31+ close F;
32+ my $in_desktop_entry = 0;
33+ my $exec = "";
34+ my $class = "";
35+ my $no_display = "false";
36+ my $only_show_in = "";
37+
38+ foreach (@lines)
39+ {
40+ if (/^\[\s*(.+)\s*\]/)
41+ {
42+ $was_in_desktop = $in_desktop_entry;
43+ $in_desktop_entry = ($1 eq "Desktop Entry");
44+
45+ if ($was_in_desktop and !$in_desktop_entry)
46+ {
47+ last;
48+ }
49+ }
50+
51+ if ($in_desktop_entry)
52+ {
53+ if (/^Exec=(.+)$/)
54+ {
55+ $exec = $1;
56+ $exec =~ s/^\s+|\s+$//g;
57+ }
58+
59+ if (/^NoDisplay=(.+)$/)
60+ {
61+ $no_display = $1;
62+ $no_display =~ s/^\s+|\s+$//g;
63+ }
64+
65+ if (/^OnlyShowIn=(.+)$/)
66+ {
67+ $only_show_in = $1;
68+ $only_show_in =~ s/^\s+|\s+$//g;
69+ }
70+
71+ if (/^StartupWMClass=(.+)$/)
72+ {
73+ $class = $1;
74+ $class =~ s/^\s+|\s+$//g;
75+ }
76+ }
77+ }
78+
79+ if ($exec ne "")
80+ {
81+ print "$f\t$exec\t$class\t$only_show_in\t$no_display\n";
82+ }
83+};
84+
85+$dir_name = $ARGV[-1];
86+$dir_name = $1 if($dir_name=~/(.*)\/$/);
87+find(\&strip_exec, $dir_name);' /usr/share/applications > $I.new || rm -f $I.new
88+
89 [ -e $I.new ] && mv $I.new $I || true
90 fi
91 fi
92
93=== modified file 'src/bamf-matcher.c'
94--- src/bamf-matcher.c 2013-03-06 04:29:49 +0000
95+++ src/bamf-matcher.c 2013-03-28 20:01:22 +0000
96@@ -31,6 +31,8 @@
97 #endif
98 #include <strings.h>
99
100+#define BAMF_INDEX_NAME "bamf-2.index"
101+
102 G_DEFINE_TYPE (BamfMatcher, bamf_matcher, BAMF_DBUS_TYPE_MATCHER_SKELETON);
103 #define BAMF_MATCHER_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE(obj, \
104 BAMF_TYPE_MATCHER, BamfMatcherPrivate))
105@@ -938,6 +940,7 @@
106 GDataInputStream *input;
107 char *line;
108 char *directory;
109+ const char *current_desktop;
110 gsize length;
111
112 file = g_file_new_for_path (index_file);
113@@ -952,16 +955,51 @@
114 return;
115 }
116
117+ length = 0;
118+ current_desktop = g_getenv ("XDG_CURRENT_DESKTOP");
119 directory = g_path_get_dirname (index_file);
120 input = g_data_input_stream_new (G_INPUT_STREAM (stream));
121
122+ if (current_desktop && current_desktop[0] == '\0')
123+ current_desktop = NULL;
124+
125 while ((line = g_data_input_stream_read_line (input, &length, NULL, NULL)))
126 {
127 char *exec;
128 char *filename;
129+ const char *class;
130+ const char *show_in;
131 GString *desktop_id;
132
133- gchar **parts = g_strsplit (line, "\t", 3);
134+ /* Order is: 0 Desktop-Id, 1 Exec, 2 class, 3 ShowIn, 4 NoDisplay */
135+ gchar **parts = g_strsplit (line, "\t", 5);
136+
137+ show_in = parts[3];
138+
139+ if (current_desktop && show_in && show_in[0] != '\0')
140+ {
141+ gchar **sub_parts = g_strsplit (show_in, ";", -1);
142+ gboolean found_current = FALSE;
143+ int i = 0;
144+
145+ for (i = 0; sub_parts[i]; ++i)
146+ {
147+ if (g_ascii_strcasecmp (sub_parts[i], current_desktop) == 0)
148+ {
149+ found_current = TRUE;
150+ break;
151+ }
152+ }
153+
154+ g_strfreev (sub_parts);
155+
156+ if (!found_current)
157+ {
158+ length = 0;
159+ g_strfreev (parts);
160+ continue;
161+ }
162+ }
163
164 char *tmp = bamf_matcher_get_trimmed_exec (self, parts[1]);
165 g_free (parts[1]);
166@@ -974,7 +1012,12 @@
167 g_string_truncate (desktop_id, desktop_id->len - 8);
168
169 insert_data_into_tables (self, filename, exec, desktop_id->str, desktop_file_table, desktop_id_table);
170- insert_desktop_file_class_into_table (self, filename, desktop_class_table);
171+
172+ class = parts[2];
173+ if (class && class[0] != '\0')
174+ {
175+ g_hash_table_insert (desktop_class_table, g_strdup (filename), g_strdup (class));
176+ }
177
178 g_string_free (desktop_id, TRUE);
179 g_free (line);
180@@ -1349,7 +1392,7 @@
181
182 bamf_matcher_add_new_monitored_directory (self, directory);
183
184- bamf_file = g_build_filename (directory, "bamf.index", NULL);
185+ bamf_file = g_build_filename (directory, BAMF_INDEX_NAME, NULL);
186
187 if (g_file_test (bamf_file, G_FILE_TEST_EXISTS))
188 {

Subscribers

People subscribed via source and target branches