3 ## Login : <freyes@yoda>
4 ## Started on Tue Jul 1 20:50:04 2008 Felipe Reyes
7 ## Copyright (C) 2008 Felipe Reyes
9 ## This file is part of Marvin.
11 ## Marvin is free software: you can redistribute it and/or modify
12 ## it under the terms of the GNU General Public License as published by
13 ## the Free Software Foundation, either version 3 of the License, or
14 ## (at your option) any later version.
16 ## Marvin is distributed in the hope that it will be useful,
17 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ## GNU General Public License for more details.
21 ## You should have received a copy of the GNU General Public License
22 ## along with this program. If not, see <http://www.gnu.org/licenses/>.
36 log
= logging
.getLogger('model')
38 #conn = sqlite3.connect('/home/freyes/photos.db')
42 curr_dir
= os
.path
.abspath(".")
43 sys
.path
.append(curr_dir
)
47 class Photo(gobject
.GObject
, object):
48 """Contains the information of a photo
50 def __init__(self
, id, uri
, pixbuf_size
=64, cursor
=None):
54 - `id`: the id of the photo
56 gobject
.GObject
.__init
__(self
)
58 if not os
.path
.isfile(gnomevfs
.get_local_path_from_uri(uri
)):
59 print gnomevfs
.get_local_path_from_uri(uri
)
60 raise RuntimeError("File %s not found" % (uri
))
65 f
= open(self
.path
, 'rb')
66 tags
= EXIF
.process_file(f
, stop_tag
='DateTimeOriginal')
68 if tags
.has_key('EXIF DateTimeOriginal'):
69 (aux_date
, aux_time
) = str(tags
['EXIF DateTimeOriginal']).split(' ')
70 (year
, month
, day
) = aux_date
.split(':')
71 (hour
, minute
, secs
) = aux_time
.split(':')
72 self
.original_date
= datetime
.datetime(int(year
),
79 self
.original_date
= time
.localtime(os
.path
.getmtime(self
.path
))
83 if (cursor
is not None) and (id > -1):
84 c
.execute("select tag_id from photo_tags where id = ?", self
._id
)
86 c
.execute("select name from tags where id=?", row
[0])
88 self
.tags
.append(tag
[0])
90 self
.thumbnail_path
= thumbnail_path_from_uri(self
.uri
, "large")
93 self
.pixbuf
= gtk
.gdk
.pixbuf_new_from_file_at_size (self
.thumbnail_path
, pixbuf_size
, pixbuf_size
)
95 thumb_pixbuf
= gtk
.gdk
.pixbuf_new_from_file_at_size(self
.path
, 256, 256)
96 thumb_pixbuf
.save(self
.thumbnail_path
, "png", {"quality":"100"})
97 self
.pixbuf
= gtk
.gdk
.pixbuf_new_from_file_at_size (self
.thumbnail_path
, pixbuf_size
, pixbuf_size
)
98 log
.info("Thumbnail for %s created" % self
.uri
)
100 def create_thumbnail(self
):
101 cmd
= "convert '%s' -resize 256x256 '%s'" % (self
.path
, thumbnail_path_from_uri(self
.uri
, "large"))
109 return gnomevfs
.get_local_path_from_uri(self
.uri
)
111 path
= property(get_path
, None, None, "the path where the photo is stored")
113 gobject
.type_register(Photo
)
115 class PhotoListStore (gtk
.ListStore
):
119 super(PhotoListStore
, self
).__init
__(Photo
)
121 gobject
.type_register(PhotoListStore
)
123 def thumbnail_path_from_uri(uri
, size
='normal'):
124 """Construct the path for the thumbnail of the given uri
127 - `uri`: the uri that points to the file that is looking for the thumbnail.
128 - `size`: the size of the thumbnail (normal or large)
131 assert isinstance(uri
, basestring
), \
132 TypeError("The uri must be a str")
134 assert isinstance(size
, basestring
) and (size
== 'large' or size
=='normal'), \
135 TypeError("The size for thumbnail can be normal or large")
139 path
= os
.path
.join(os
.path
.expanduser('~'), ".thumbnails", size
, str("%s.png" % hash.hexdigest()))
144 db_path
= os
.path
.join(os
.path
.expanduser('~'), ".gnome2", "f-spot", "photos.db")
145 conn
= sqlite3
.connect(db_path
)