25
namespace Unity.FilesLens.Utils {
27
const string icon_attribs = FileAttribute.PREVIEW_ICON + "," +
28
FileAttribute.STANDARD_ICON + "," +
29
FileAttribute.THUMBNAIL_PATH;
31
const string file_attribs = FileAttribute.STANDARD_NAME + "," +
32
FileAttribute.STANDARD_DISPLAY_NAME + "," +
33
FileAttribute.STANDARD_CONTENT_TYPE + "," +
34
FileAttribute.STANDARD_IS_HIDDEN + "," +
35
FileAttribute.STANDARD_IS_BACKUP + "," +
36
FileAttribute.STANDARD_SIZE + "," +
37
FileAttribute.TIME_MODIFIED + "," +
38
FileAttribute.TIME_ACCESS;
25
namespace Unity.FilesPlace.Utils {
27
const string icon_attribs = FILE_ATTRIBUTE_PREVIEW_ICON + "," +
28
FILE_ATTRIBUTE_STANDARD_ICON + "," +
29
FILE_ATTRIBUTE_THUMBNAIL_PATH;
31
const string file_attribs = FILE_ATTRIBUTE_STANDARD_NAME + "," +
32
FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME + "," +
33
FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE + "," +
34
FILE_ATTRIBUTE_STANDARD_IS_HIDDEN + "," +
35
FILE_ATTRIBUTE_STANDARD_IS_BACKUP + "," +
36
FILE_ATTRIBUTE_TIME_MODIFIED + "," +
37
FILE_ATTRIBUTE_TIME_ACCESS;
40
const string hide_attribs = FileAttribute.STANDARD_IS_BACKUP + "," +
41
FileAttribute.STANDARD_IS_HIDDEN;
39
const string hide_attribs = FILE_ATTRIBUTE_STANDARD_IS_BACKUP + "," +
40
FILE_ATTRIBUTE_STANDARD_IS_HIDDEN;
43
42
const string all_attribs = icon_attribs + "," + file_attribs + "," + hide_attribs;
86
85
public string check_icon_string (string uri, string mimetype, FileInfo info)
88
Icon icon = info.get_icon ();
89
string thumbnail_path = info.get_attribute_byte_string (FileAttribute.THUMBNAIL_PATH);
87
Icon icon = info.get_icon();
88
string thumbnail_path = info.get_attribute_byte_string (FILE_ATTRIBUTE_THUMBNAIL_PATH);
91
if (thumbnail_path == null && icon != null)
92
return icon.to_string ();
93
else if (icon == null)
94
return ContentType.get_icon (mimetype).to_string ();
90
if (thumbnail_path == null)
91
return icon.to_string();
96
return new FileIcon (File.new_for_path (thumbnail_path)).to_string ();
93
return new FileIcon(File.new_for_path (thumbnail_path)).to_string ();
99
public int cmp_file_info_by_mtime (FileInfo info1, FileInfo info2)
102
tv1 = info1.get_modification_time ();
103
tv2 = info2.get_modification_time ();
104
long cmp = tv1.tv_sec - tv2.tv_sec;
105
return cmp < 0 ? 1 : ( cmp > 0 ? -1 : 0);
96
public int cmp_file_info_by_mtime (FileInfo info1, FileInfo info2)
99
info1.get_modification_time (out tv1);
100
info2.get_modification_time (out tv2);
101
long cmp = tv1.tv_sec - tv2.tv_sec;
102
return cmp < 0 ? 1 : ( cmp > 0 ? -1 : 0);
108
105
public string get_month_name (DateMonth month)
304
298
result.sort (cmpfunc);
308
* Asynchronously list the contents of a directory given by a path,
309
* and return a list of FileInfos filled with the attributes specified
310
* by Utils.all_attribs
312
public async SList<FileInfo> list_dir (File folder) throws Error
314
return yield list_dir_internal (folder, null);
318
* Similar to list_dir, but only return list of FileInfos matching
321
public async SList<FileInfo> list_dir_filtered (File folder,
322
string name_filter) throws Error
324
return yield list_dir_internal (folder, name_filter);
327
public bool file_info_matches_any (FileInfo info, string[] types)
329
foreach (unowned string type_id in types)
331
if (file_info_matches_type (info, type_id)) return true;
302
/* Run through @filter_set and remove any row from the result set's model
303
* in which URI is not in @valid_uris */
304
public void apply_uri_filter (Set<string> valid_uris,
305
Dee.ResultSet filter_set)
307
var model = filter_set.get_model ();
311
/* Anything in filter_set that is not in the event_uris set, is removed
312
* from the results_model */
313
foreach (var row in filter_set)
315
uri = model.get_string (row, ResultsColumn.URI);
316
if (!(uri in valid_uris))
320
//debug (" - %s", uri);
325
debug ("Removed %u rows from result set", n_removed);
328
/* Returns true iff new_search is a query that simply restricts the
329
* result set of old_query */
330
public bool check_is_filter_search (PlaceSearch new_search, PlaceSearch? old_search)
332
bool is_filter_search = false;
333
if (old_search != null)
335
string previous_search_string = old_search.get_search_string();
336
if (previous_search_string != null && previous_search_string != "")
337
is_filter_search = new_search.get_search_string().has_prefix (
338
previous_search_string);
341
return is_filter_search;
344
/* Extract a hash set of all subject uris in a Zeitgeist.ResultSet */
345
public Set<string> get_uri_set (Zeitgeist.ResultSet results)
347
Set<string> uris = new HashSet<string> ();
349
foreach (var ev in results)
351
for (int i = 0; i < ev.num_subjects(); i++)
352
uris.add (ev.get_subject (i).get_uri ());
358
/* Sloppy and null-safe equality checking. null == "" and strings
359
* are stripped of whitespace before comparison */
360
private bool search_has_really_changed (PlaceSearch? old_search,
361
PlaceSearch? new_search)
363
if (old_search == null && new_search == null)
336
public bool file_info_matches_type (FileInfo info, string type_id)
338
unowned string interpretation;
339
unowned string content_type = info.get_content_type ();
340
if (content_type == null)
341
content_type = info.get_attribute_string (FileAttribute.STANDARD_FAST_CONTENT_TYPE);
343
if (content_type == null) content_type = "application/octet-stream";
345
interpretation = Zeitgeist.interpretation_for_mimetype (content_type);
346
if (interpretation == null) return type_id == "other" || type_id == "all";
348
/* type_id is one of: documents, folders, images, audio, videos,
349
* presentations, other */
353
return Zeitgeist.Symbol.is_a (interpretation, Zeitgeist.NFO.DOCUMENT)
354
&& !Zeitgeist.Symbol.is_a (interpretation, Zeitgeist.NFO.PRESENTATION);
356
return content_type == "inode/directory";
358
return Zeitgeist.Symbol.is_a (interpretation, Zeitgeist.NFO.IMAGE);
360
return Zeitgeist.Symbol.is_a (interpretation, Zeitgeist.NFO.AUDIO);
362
return Zeitgeist.Symbol.is_a (interpretation, Zeitgeist.NFO.VIDEO);
363
case "presentations":
364
return Zeitgeist.Symbol.is_a (interpretation, Zeitgeist.NFO.PRESENTATION);
366
bool is_recognized = false;
367
is_recognized |= content_type == "inode/directory";
368
// DOCUMENT includes PRESENTATION
369
is_recognized |= Zeitgeist.Symbol.is_a (interpretation, Zeitgeist.NFO.DOCUMENT);
370
// MEDIA includes AUDIO, VIDEO, IMAGE
371
is_recognized |= Zeitgeist.Symbol.is_a (interpretation, Zeitgeist.NFO.MEDIA);
372
return !is_recognized;
376
warning ("Unrecognized type: \"%s\"", type_id);
381
/* Extract a hash set of all subject uris in a Zeitgeist.ResultSet */
382
public Set<string> get_uri_set (Zeitgeist.ResultSet results)
384
Set<string> uris = new HashSet<string> ();
386
foreach (var ev in results)
388
for (int i = 0; i < ev.num_subjects(); i++)
389
uris.add (ev.get_subject (i).uri);
395
public string normalize_string (string input)
397
return input.normalize (-1, NormalizeMode.ALL_COMPOSE).casefold ();
368
if (old_search == null)
370
s1 = new_search.get_search_string ();
371
if (s1 == null || s1.strip() == "")
376
else if (new_search == null)
378
s2 = old_search.get_search_string ();
379
if (s2 == null || s2.strip() == "")
386
s1 = new_search.get_search_string ();
387
s2 = old_search.get_search_string ();
390
if (s2 == null || s2.strip() == "")
397
if (s1 == null || s1.strip() == "")
403
return s1.strip () != s2.strip ();
407
public string normalize_string (string input)
409
return input.normalize (-1, NormalizeMode.ALL_COMPOSE).casefold ();
400
412
} /* namespace */