summaryrefslogtreecommitdiff
path: root/src/photos/PhotoFileAdapter.vala
diff options
context:
space:
mode:
authorJörg Frings-Fürst <debian@jff-webhosting.net>2014-07-23 09:06:59 +0200
committerJörg Frings-Fürst <debian@jff-webhosting.net>2014-07-23 09:06:59 +0200
commit4ea2cc3bd4a7d9b1c54a9d33e6a1cf82e7c8c21d (patch)
treed2e54377d14d604356c86862a326f64ae64dadd6 /src/photos/PhotoFileAdapter.vala
Imported Upstream version 0.18.1upstream/0.18.1
Diffstat (limited to 'src/photos/PhotoFileAdapter.vala')
-rw-r--r--src/photos/PhotoFileAdapter.vala112
1 files changed, 112 insertions, 0 deletions
diff --git a/src/photos/PhotoFileAdapter.vala b/src/photos/PhotoFileAdapter.vala
new file mode 100644
index 0000000..38b00ea
--- /dev/null
+++ b/src/photos/PhotoFileAdapter.vala
@@ -0,0 +1,112 @@
+/* Copyright 2010-2014 Yorba Foundation
+ *
+ * This software is licensed under the GNU Lesser General Public License
+ * (version 2.1 or later). See the COPYING file in this distribution.
+ */
+
+//
+// PhotoFileAdapter
+//
+// PhotoFileAdapter (and its immediate children, PhotoFileReader and PhotoFileWriter) are drivers
+// hiding details of reading and writing image files and their metadata. They should keep
+// minimal state beyond the filename, if any stat at all. In particular, they should avoid caching
+// values, especially the readers, as writers may be created at any time and invalidate that
+// information, unless the readers monitor the file for these changes.
+//
+// PhotoFileAdapters should be entirely thread-safe. They are not, however, responsible for
+// atomicity on the filesystem.
+//
+
+public abstract class PhotoFileAdapter {
+ private string filepath;
+ private PhotoFileFormat file_format;
+ private File file = null;
+
+ public PhotoFileAdapter(string filepath, PhotoFileFormat file_format) {
+ this.filepath = filepath;
+ this.file_format = file_format;
+ }
+
+ public bool file_exists() {
+ return FileUtils.test(filepath, FileTest.IS_REGULAR);
+ }
+
+ public string get_filepath() {
+ return filepath;
+ }
+
+ public File get_file() {
+ File result;
+ lock (file) {
+ if (file == null)
+ file = File.new_for_path(filepath);
+
+ result = file;
+ }
+
+ return result;
+ }
+
+ public PhotoFileFormat get_file_format() {
+ return file_format;
+ }
+}
+
+//
+// PhotoFileReader
+//
+
+public abstract class PhotoFileReader : PhotoFileAdapter {
+ protected PhotoFileReader(string filepath, PhotoFileFormat file_format) {
+ base (filepath, file_format);
+ }
+
+ public PhotoFileWriter create_writer() throws PhotoFormatError {
+ return get_file_format().create_writer(get_filepath());
+ }
+
+ public PhotoFileMetadataWriter create_metadata_writer() throws PhotoFormatError {
+ return get_file_format().create_metadata_writer(get_filepath());
+ }
+
+ public abstract PhotoMetadata read_metadata() throws Error;
+
+ public abstract Gdk.Pixbuf unscaled_read() throws Error;
+
+ public virtual Gdk.Pixbuf scaled_read(Dimensions full, Dimensions scaled) throws Error {
+ return resize_pixbuf(unscaled_read(), scaled, Gdk.InterpType.BILINEAR);
+ }
+}
+
+//
+// PhotoFileWriter
+//
+
+public abstract class PhotoFileWriter : PhotoFileAdapter {
+ protected PhotoFileWriter(string filepath, PhotoFileFormat file_format) {
+ base (filepath, file_format);
+ }
+
+ public PhotoFileReader create_reader() {
+ return get_file_format().create_reader(get_filepath());
+ }
+
+ public abstract void write(Gdk.Pixbuf pixbuf, Jpeg.Quality quality) throws Error;
+}
+
+//
+// PhotoFileMetadataWriter
+//
+
+public abstract class PhotoFileMetadataWriter : PhotoFileAdapter {
+ protected PhotoFileMetadataWriter(string filepath, PhotoFileFormat file_format) {
+ base (filepath, file_format);
+ }
+
+ public PhotoFileReader create_reader() {
+ return get_file_format().create_reader(get_filepath());
+ }
+
+ public abstract void write_metadata(PhotoMetadata metadata) throws Error;
+}
+