diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/Commands.vala | 2 | ||||
| -rw-r--r-- | src/PhotoPage.vala | 8 | ||||
| -rw-r--r-- | src/PixbufCache.vala | 6 | ||||
| -rw-r--r-- | src/camera/ImportPage.vala | 2 | ||||
| -rw-r--r-- | src/db/DatabaseTable.vala | 51 | ||||
| -rw-r--r-- | src/db/Db.vala | 4 | ||||
| -rw-r--r-- | src/db/PhotoTable.vala | 7 | ||||
| -rw-r--r-- | src/db/VideoTable.vala | 7 | ||||
| -rw-r--r-- | src/photos/PhotoMetadata.vala | 8 | 
9 files changed, 90 insertions, 5 deletions
| diff --git a/src/Commands.vala b/src/Commands.vala index 76aecb4..25bdbc2 100644 --- a/src/Commands.vala +++ b/src/Commands.vala @@ -321,7 +321,7 @@ public abstract class MultipleDataSourceCommand : PageCommand {      private void on_source_destroyed(DataSource source) {          // as with SingleDataSourceCommand, too risky to selectively remove commands from the stack,          // although this could be reconsidered in the future -        if (source_list.contains(source)) +        if (source_list.contains(source) && get_command_manager() != null)              get_command_manager().reset();      } diff --git a/src/PhotoPage.vala b/src/PhotoPage.vala index a28ab44..3ab0f6b 100644 --- a/src/PhotoPage.vala +++ b/src/PhotoPage.vala @@ -835,7 +835,9 @@ public abstract class EditingHostPage : SinglePhotoPage {          photo_changing(photo);          DataView view = get_view().get_view_for_source(photo); -        assert(view != null); +        if (view == null) { +            return; +        }          // Select photo.          get_view().unselect_all(); @@ -1255,6 +1257,10 @@ public abstract class EditingHostPage : SinglePhotoPage {      }      private void quick_update_pixbuf() { +        if (get_photo() == null) { +            return; +        } +          Gdk.Pixbuf? pixbuf = cache.get_ready_pixbuf(get_photo());          if (pixbuf != null) {              set_pixbuf(pixbuf, get_photo().get_dimensions()); diff --git a/src/PixbufCache.vala b/src/PixbufCache.vala index 6ff740e..76fdbd3 100644 --- a/src/PixbufCache.vala +++ b/src/PixbufCache.vala @@ -120,7 +120,11 @@ public class PixbufCache : Object {      }      // This call never blocks.  Returns null if the pixbuf is not present. -    public Gdk.Pixbuf? get_ready_pixbuf(Photo photo) { +    public Gdk.Pixbuf? get_ready_pixbuf(Photo? photo) { +        if (photo == null) { +            return null; +        } +                  return get_cached(photo);      } diff --git a/src/camera/ImportPage.vala b/src/camera/ImportPage.vala index 463317b..20a6a58 100644 --- a/src/camera/ImportPage.vala +++ b/src/camera/ImportPage.vala @@ -1086,7 +1086,7 @@ public class ImportPage : CheckerboardPage {          progress_bar.set_text("");          progress_bar.visible = false; -        try_refreshing_camera(true); +        Timeout.add_seconds(3, () => { try_refreshing_camera(true); return false; });      }      private void clear_all_import_sources() { diff --git a/src/db/DatabaseTable.vala b/src/db/DatabaseTable.vala index dea797a..be45e5e 100644 --- a/src/db/DatabaseTable.vala +++ b/src/db/DatabaseTable.vala @@ -29,10 +29,61 @@ public abstract class DatabaseTable {      public string table_name = null; +    static Gee.HashMap<string, Regex> regex_map; + +    private static void regexp_replace(Sqlite.Context context, Sqlite.Value[] args) { +        var pattern = args[0].to_text(); +        if (pattern == null) { +            context.result_error("Missing regular expression", Sqlite.ERROR); +            return; +        } + +        var text = args[1].to_text(); +        if (text == null) { +            return; +        } + +        var replacement = args[2].to_text(); +        if (replacement == null) { +            context.result_value(args[1]); +            return; +        } +         +        Regex re; +        if (regex_map == null) { +            regex_map = new Gee.HashMap<string, Regex>(); +        } +        if (regex_map.has_key(pattern)) { +            re = regex_map[pattern]; +        } else { +            try { +                re = new Regex(pattern, RegexCompileFlags.DEFAULT, RegexMatchFlags.DEFAULT); +                regex_map[pattern] = re; +            } catch (Error err) { +                context.result_error("Invalid pattern: %s".printf(err.message), Sqlite.ERROR); +                return; +            } +        } + +        try { +            var result = re.replace(text, -1, 0, replacement, RegexMatchFlags.DEFAULT); +            context.result_text(result); +        } catch (Error err) { +            context.result_error("Replacement failed: %s".printf(err.message), Sqlite.ERROR); +        } +    } + +    [CCode (cname="SQLITE_DETERMINISTIC", cheader_filename="sqlite3.h")] +    extern static int SQLITE_DETERMINISTIC; +      private static void prepare_db(string filename) {          // Open DB.          int res = Sqlite.Database.open_v2(filename, out db, Sqlite.OPEN_READWRITE | Sqlite.OPEN_CREATE,               null); + +        db.create_function("regexp_replace", 3, Sqlite.UTF8 | SQLITE_DETERMINISTIC, null, +            DatabaseTable.regexp_replace, null, null); +          if (res != Sqlite.OK)              AppWindow.panic(_("Unable to open/create photo database %s: error code %d").printf(filename,                  res)); diff --git a/src/db/Db.vala b/src/db/Db.vala index 5072967..7f76f2d 100644 --- a/src/db/Db.vala +++ b/src/db/Db.vala @@ -55,6 +55,10 @@ public VerifyResult verify_database(out string app_version, out int schema_versi          if (result != VerifyResult.OK)              return result;      } + +    PhotoTable.clean_comments(); +    VideoTable.clean_comments(); +      return VerifyResult.OK;  } diff --git a/src/db/PhotoTable.vala b/src/db/PhotoTable.vala index 420b209..d74cbd1 100644 --- a/src/db/PhotoTable.vala +++ b/src/db/PhotoTable.vala @@ -1123,6 +1123,13 @@ public class PhotoTable : DatabaseTable {              throw_error("PhotoTable.upgrade_for_unset_timestamp", res);          }      } + +    public static void clean_comments() throws DatabaseError { +        var result = db.exec("UPDATE PhotoTable SET comment = regexp_replace('^charset=\\w+\\s*', comment, '') WHERE comment like 'charset=%'"); +        if (result != Sqlite.OK) { +            throw_error("Cleaning comments from charset", result); +        } +    }  } diff --git a/src/db/VideoTable.vala b/src/db/VideoTable.vala index 8af1278..67c50ba 100644 --- a/src/db/VideoTable.vala +++ b/src/db/VideoTable.vala @@ -480,5 +480,12 @@ public class VideoTable : DatabaseTable {          }      } +    public static void clean_comments() throws DatabaseError { +        var result = db.exec("UPDATE VideoTable SET comment = regexp_replace('^charset=\\w+\\s*', comment, '') WHERE comment like 'charset=%'"); +        if (result != Sqlite.OK) { +            throw_error("Cleaning comments from charset", result); +        } +    } +  } diff --git a/src/photos/PhotoMetadata.vala b/src/photos/PhotoMetadata.vala index 3bf77d6..0624b41 100644 --- a/src/photos/PhotoMetadata.vala +++ b/src/photos/PhotoMetadata.vala @@ -1043,7 +1043,13 @@ public class PhotoMetadata : MediaMetadata {      };      public override string? get_comment() { -        return get_first_string_interpreted (COMMENT_TAGS); +        var comment = get_first_string_interpreted (COMMENT_TAGS); +        try { +            var re = new Regex("^charset=\\w+\\s*"); +            return re.replace(comment, -1, 0, "", RegexMatchFlags.DEFAULT); +        } catch (Error err) { +            return comment; +        }      }      public void set_comment(string? comment, | 
