[shotwell/wip/723835-camera-hang] Potential fix for bgo#723835
- From: Jim Nelson <jnelson src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [shotwell/wip/723835-camera-hang] Potential fix for bgo#723835
- Date: Mon, 10 Feb 2014 22:43:26 +0000 (UTC)
commit 722b325585d5ccab4cfd81a09df32f922d20aa7c
Author: Jim Nelson <jim yorba org>
Date: Mon Feb 10 14:43:10 2014 -0800
Potential fix for bgo#723835
src/MediaDataRepresentation.vala | 20 +------------
src/Photo.vala | 56 ++++++++++++++++++++++++++++++++++++++
2 files changed, 58 insertions(+), 18 deletions(-)
---
diff --git a/src/MediaDataRepresentation.vala b/src/MediaDataRepresentation.vala
index 21b4a63..b63ad64 100644
--- a/src/MediaDataRepresentation.vala
+++ b/src/MediaDataRepresentation.vala
@@ -80,16 +80,15 @@ public abstract class MediaSource : ThumbnailSource, Indexable {
}
private void update_indexable_keywords() {
- string[] indexables = new string[4];
+ string[] indexables = new string[3];
indexables[0] = get_title();
indexables[1] = get_basename();
indexables[2] = get_comment();
- indexables[3] = get_keywords_from_path();
indexable_keywords = prepare_indexable_strings(indexables);
}
- public unowned string? get_indexable_keywords() {
+ public virtual unowned string? get_indexable_keywords() {
return indexable_keywords;
}
@@ -149,21 +148,6 @@ public abstract class MediaSource : ThumbnailSource, Indexable {
return get_file().get_basename();
}
- // If in library, match anywhere along the library's children directories, otherwise
- // only match against the photo's parent directory
- public string get_keywords_from_path(){
- File parent = get_master_file().get_parent();
- string path_keywords = parent.get_basename();
- if (AppDirs.is_in_import_dir(get_file())){
- parent = parent.get_parent();
- while(!parent.equal(AppDirs.get_import_dir())){
- path_keywords += " " + parent.get_basename();
- parent = parent.get_parent();
- }
- }
- return path_keywords;
- }
-
public abstract File get_file();
public abstract File get_master_file();
public abstract uint64 get_master_filesize();
diff --git a/src/Photo.vala b/src/Photo.vala
index ab449dc..57cf3db 100644
--- a/src/Photo.vala
+++ b/src/Photo.vala
@@ -4851,6 +4851,8 @@ public class LibraryPhoto : Photo, Flaggable, Monitorable {
private bool block_thumbnail_generation = false;
private OneShotScheduler thumbnail_scheduler = null;
private Gee.Collection<string>? import_keywords;
+ private string? photo_keywords = null;
+ private string? indexable_keywords = null;
private LibraryPhoto(PhotoRow row) {
base (row);
@@ -4966,6 +4968,18 @@ public class LibraryPhoto : Photo, Flaggable, Monitorable {
global.notify_baseline_reimported(this, metadata);
}
+ // use this method as a kind of post-constructor initializer; it means the DataSource has been
+ // added or removed to a SourceCollection.
+ protected override void notify_membership_changed(DataCollection? collection) {
+ if (collection != null && photo_keywords == null) {
+ // don't fire the alteration here, as the MediaSource is only being added to its
+ // SourceCollection
+ update_photo_keywords();
+ }
+
+ base.notify_membership_changed(collection);
+ }
+
private void generate_thumbnails() {
try {
ThumbnailCache.import_from_source(this, true);
@@ -4986,12 +5000,54 @@ public class LibraryPhoto : Photo, Flaggable, Monitorable {
import_keywords = null;
}
+ public override unowned string? get_indexable_keywords() {
+ // combine LibraryPhoto's keywords with the base's keywords
+ unowned string? base_keywords = base.get_indexable_keywords();
+ indexable_keywords = (base_keywords != null) ? base_keywords + " " + photo_keywords : photo_keywords;
+
+ return indexable_keywords;
+ }
+
+ // Returns true if the keywords changed
+ private bool update_photo_keywords(){
+ StringBuilder builder = new StringBuilder();
+
+ // If in library, match anywhere along the library's children directories, otherwise
+ // only match against the photo's parent directory
+ File parent = get_master_file().get_parent();
+ builder.append(parent.get_basename());
+ if (AppDirs.is_in_import_dir(get_file())){
+ parent = parent.get_parent();
+ while(!parent.equal(AppDirs.get_import_dir())){
+ builder.append(" ");
+ builder.append(parent.get_basename());
+ parent = parent.get_parent();
+ }
+ }
+
+ bool changed = (photo_keywords == null || photo_keywords != builder.str);
+
+ photo_keywords = builder.str;
+
+ return changed;
+ }
+
public override void notify_altered(Alteration alteration) {
// generate new thumbnails in the background
if (!block_thumbnail_generation && alteration.has_subject("image"))
thumbnail_scheduler.at_priority_idle(Priority.LOW);
+ // if the master file changed, update the path_keywords ... if other backings are indexed,
+ // will need to be included here
+ bool keywords_changed = false;
+ if (alteration.has_detail("backing", "master"))
+ keywords_changed = update_photo_keywords();
+
base.notify_altered(alteration);
+
+ // fire this notification after processing current one
+ if (keywords_changed)
+ notify_altered(new Alteration("indexable", "keywords"));
}
public override Gdk.Pixbuf get_preview_pixbuf(Scaling scaling) throws Error {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]