Merge lp:~shnatsel/scratch/fix-1101448 into lp:~elementary-apps/scratch/scratch

Proposed by Sergey "Shnatsel" Davidoff
Status: Merged
Approved by: Mario Guerriero
Approved revision: 981
Merged at revision: 977
Proposed branch: lp:~shnatsel/scratch/fix-1101448
Merge into: lp:~elementary-apps/scratch/scratch
Diff against target: 36 lines (+16/-8)
1 file modified
src/Services/Encoding.vala (+16/-8)
To merge this branch: bzr merge lp:~shnatsel/scratch/fix-1101448
Reviewer Review Type Date Requested Status
elementary Apps team Pending
Review via email: mp+143962@code.launchpad.net

Description of the change

* Use Process.spawn_sync instead of Process.spawn_command_line_sync, for proper handling of filenames with spaces in them and GREAT JUSTICE
* Fall back to UTF-8 if encoding detection fails //TODO: prompt the user to meddle with encoding until satisfied

To post a comment you must log in.
lp:~shnatsel/scratch/fix-1101448 updated
977. By Sergey "Shnatsel" Davidoff

Turns out the proper value for no spawn flags is 0

978. By Sergey "Shnatsel" Davidoff

added a pair of empty lines to make Munchor happy

979. By Sergey "Shnatsel" Davidoff

more meaningful debug message

980. By Sergey "Shnatsel" Davidoff

renamed 'output' variable into 'charset' that it actually is; renamed FALLBACK_ENCODING constant into FALLBACK_CHARSET

981. By Sergey "Shnatsel" Davidoff

oops, forgot this

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/Services/Encoding.vala'
2--- src/Services/Encoding.vala 2012-11-24 13:46:56 +0000
3+++ src/Services/Encoding.vala 2013-01-21 14:44:21 +0000
4@@ -259,16 +259,24 @@
5
6 public static string get_charset (string path) {
7 // Get correct encoding via chardect.py script
8- string script = Constants.SCRIPTDIR + "/chardetect.py ";
9- string command = "python " + script + path;
10- string? output = null;
11+
12+ const string FALLBACK_CHARSET = "UTF-8";
13+ string script = Constants.SCRIPTDIR + "/chardetect.py";
14+ string[] command = { "python", script, path };
15+ string? charset = null;
16+
17 try {
18- GLib.Process.spawn_command_line_sync (command, out output);
19+ GLib.Process.spawn_sync (null, command, null, 0, null, out charset, null, null);
20 } catch (SpawnError e) {
21- warning (e.message);
22- }
23- debug (output);
24- return output;
25+ warning ("Could not execute \"%s\": %s", script, e.message);
26+ }
27+ if ( charset == null ) {
28+ warning ("Could not automatically detect encoding, assuming %s", FALLBACK_CHARSET);
29+ charset = FALLBACK_CHARSET; //TODO: prompt the user to meddle with encoding manually, until satisfied
30+ } else {
31+ debug ("Detected encoding of file \"%s\" to be \"%s\"", path, charset);
32+ }
33+ return charset;
34 }
35
36 public string? file_content_to_utf8 (File file, string content, string mode = "r" /* it means read or write */) {

Subscribers

People subscribed via source and target branches