Merge lp:~evfool/scratch/lp1100193 into lp:~elementary-apps/scratch/scratch

Proposed by Robert Roth
Status: Merged
Approved by: Cody Garver
Approved revision: 1328
Merged at revision: 1329
Proposed branch: lp:~evfool/scratch/lp1100193
Merge into: lp:~elementary-apps/scratch/scratch
Diff against target: 115 lines (+24/-20)
3 files modified
plugins/folder-manager/FileView.vala (+20/-16)
plugins/folder-manager/FolderManagerPlugin.vala (+2/-2)
src/Services/Encoding.vala (+2/-2)
To merge this branch: bzr merge lp:~evfool/scratch/lp1100193
Reviewer Review Type Date Requested Status
elementary Apps team Pending
Review via email: mp+226950@code.launchpad.net

Commit message

* Use fallback charset in case chardet.py fails
* Change fallback charset to ISO-8859-1, in case encoding could not be detected. UTF-n encoding can usually be detected from the first byte
(based on the docs of chardet [1])

[1] http://www.tech.co.bydgoszcz.pl/doc/python-chardet/how-it-works.html

Description of the change

This branch includes the following changes:
* uses fallback charset in case chardet.py fails
* changes fallback charset to ISO-8859-1, in case encoding could not be detected. This might be controversial, but as UTF-n encoding can usually be detected from the first byte
(based on the docs of chardet [1]) this won't affect UTF-n encoded files, as it's unlikely for a file whose encoding could not be detected to be UTF-n

[1] http://www.tech.co.bydgoszcz.pl/doc/python-chardet/how-it-works.html

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'plugins/folder-manager/FileView.vala'
2--- plugins/folder-manager/FileView.vala 2014-04-28 17:07:31 +0000
3+++ plugins/folder-manager/FileView.vala 2014-07-16 02:36:44 +0000
4@@ -37,10 +37,6 @@
5 });
6
7 settings = new Settings ();
8-
9- this.set_sort_func ((a, b) => {
10- return File.compare ((a as Item).file, (b as Item).file);
11- });
12 }
13
14 public void restore_saved_state () {
15@@ -147,25 +143,36 @@
16 }
17
18 /**
19- * Common interface for normal and expandable items.
20+ * Common abstract class for file and filder items.
21 */
22- internal interface Item : Granite.Widgets.SourceList.Item {
23- public abstract File file { get; construct; }
24- public abstract string path { get; }
25+ internal class Item: Granite.Widgets.SourceList.ExpandableItem, Granite.Widgets.SourceListSortable {
26+ public File file { get; construct; }
27+ public string path { get { return file.path; } }
28+
29+ public int compare (Granite.Widgets.SourceList.Item a,
30+ Granite.Widgets.SourceList.Item b) {
31+ if (a is FolderItem && b is FileItem) {
32+ return -1;
33+ } else if (a is FileItem && b is FolderItem) {
34+ return 1;
35+ }
36+ return File.compare ((a as Item).file, (b as Item).file);;
37+ }
38+
39+ public bool allow_dnd_sorting () {
40+ return false;
41+ }
42 }
43
44 /**
45 * Normal item in the source list, represents a textfile.
46 * TODO Remove, Rename
47 */
48- internal class FileItem : Granite.Widgets.SourceList.Item, Item {
49+ internal class FileItem : Item {
50
51 //Gtk.Menu menu;
52 //Gtk.MenuItem item_trash;
53
54- public File file { get; construct; }
55- public string path { get { return file.path; } }
56-
57 public FileItem (File file) requires (file.is_valid_textfile) {
58 Object (file: file);
59
60@@ -194,7 +201,7 @@
61 * Monitored for changes inside the directory.
62 * TODO remove, rename, create new file
63 */
64- internal class FolderItem : Granite.Widgets.SourceList.ExpandableItem, Item {
65+ internal class FolderItem : Item {
66
67 //Gtk.Menu menu;
68 //Gtk.MenuItem item_trash;
69@@ -203,9 +210,6 @@
70 private GLib.FileMonitor monitor;
71 private bool children_loaded = false;
72
73- public File file { get; construct; }
74- public string path { get { return file.path; } }
75-
76 public FolderItem (File file) requires (file.is_valid_directory) {
77 Object (file: file);
78
79
80=== modified file 'plugins/folder-manager/FolderManagerPlugin.vala'
81--- plugins/folder-manager/FolderManagerPlugin.vala 2014-06-25 10:54:07 +0000
82+++ plugins/folder-manager/FolderManagerPlugin.vala 2014-07-16 02:36:44 +0000
83@@ -92,8 +92,8 @@
84 Gtk.Window window = plugins.manager.window;
85 Gtk.FileChooserDialog chooser = new Gtk.FileChooserDialog (
86 "Select a folder.", window, Gtk.FileChooserAction.SELECT_FOLDER,
87- Gtk.Stock.CANCEL, Gtk.ResponseType.CANCEL,
88- Gtk.Stock.OPEN, Gtk.ResponseType.ACCEPT);
89+ _("_Cancel"), Gtk.ResponseType.CANCEL,
90+ _("_Open"), Gtk.ResponseType.ACCEPT);
91 chooser.select_multiple = true;
92
93 if (chooser.run () == Gtk.ResponseType.ACCEPT) {
94
95=== modified file 'src/Services/Encoding.vala'
96--- src/Services/Encoding.vala 2014-03-14 01:43:10 +0000
97+++ src/Services/Encoding.vala 2014-07-16 02:36:44 +0000
98@@ -259,7 +259,7 @@
99 public static string get_charset (string path) {
100 // Get correct encoding via chardect.py script
101
102- const string FALLBACK_CHARSET = "UTF-8";
103+ const string FALLBACK_CHARSET = "ISO-8859-1";
104 string script = Constants.SCRIPTDIR + "/chardetect.py";
105 string command = "python " + script + " \"" + path.replace ("\\ ", " ") + "\"";
106 string? charset = null;
107@@ -269,7 +269,7 @@
108 } catch (SpawnError e) {
109 warning ("Could not execute \"%s\": %s", script, e.message);
110 }
111- if ( charset == null ) {
112+ if ( charset == null || strcmp (charset, "error") != 0) {
113 warning ("Could not automatically detect encoding, assuming %s", FALLBACK_CHARSET);
114 charset = FALLBACK_CHARSET; //TODO: prompt the user to meddle with encoding manually, until satisfied
115 } else {

Subscribers

People subscribed via source and target branches