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/>.
37 log
= logging
.getLogger('model')
39 #conn = sqlite3.connect('/home/freyes/photos.db')
43 curr_dir
= os
.path
.abspath(".")
44 sys
.path
.append(curr_dir
)
48 class Photo(gobject
.GObject
, object):
49 """Contains the information of a photo
51 def __init__(self
, id, uri
, pixbuf_size
=64, cursor
=None):
55 - `id`: the id of the photo
57 gobject
.GObject
.__init
__(self
)
59 if not os
.path
.isfile(gnomevfs
.get_local_path_from_uri(uri
)):
60 print gnomevfs
.get_local_path_from_uri(uri
)
61 raise RuntimeError("File %s not found" % (uri
))
66 f
= open(self
.path
, 'rb')
67 tags
= EXIF
.process_file(f
, stop_tag
='DateTimeOriginal')
69 if tags
.has_key('EXIF DateTimeOriginal'):
70 (aux_date
, aux_time
) = str(tags
['EXIF DateTimeOriginal']).split(' ')
71 (year
, month
, day
) = aux_date
.split(':')
72 (hour
, minute
, secs
) = aux_time
.split(':')
73 self
.original_date
= datetime
.datetime(int(year
),
80 self
.original_date
= time
.localtime(os
.path
.getmtime(self
.path
))
84 if (cursor
is not None) and (id > -1):
85 c
.execute("select tag_id from photo_tags where id = ?", self
._id
)
87 c
.execute("select name from tags where id=?", row
[0])
89 self
.tags
.append(tag
[0])
91 self
.thumbnail_path
= thumbnail_path_from_uri(self
.uri
, "large")
94 self
.pixbuf
= gtk
.gdk
.pixbuf_new_from_file_at_size (self
.thumbnail_path
, pixbuf_size
, pixbuf_size
)
96 thumb_pixbuf
= gtk
.gdk
.pixbuf_new_from_file_at_size(self
.path
, 256, 256)
97 thumb_pixbuf
.save(self
.thumbnail_path
, "png", {"quality":"100"})
98 self
.pixbuf
= gtk
.gdk
.pixbuf_new_from_file_at_size (self
.thumbnail_path
, pixbuf_size
, pixbuf_size
)
99 log
.info("Thumbnail for %s created" % self
.uri
)
101 def create_thumbnail(self
):
102 cmd
= "convert '%s' -resize 256x256 '%s'" % (self
.path
, thumbnail_path_from_uri(self
.uri
, "large"))
110 return gnomevfs
.get_local_path_from_uri(self
.uri
)
112 path
= property(get_path
, None, None, "the path where the photo is stored")
114 gobject
.type_register(Photo
)
116 class PhotoListStore (gtk
.ListStore
):
120 super(PhotoListStore
, self
).__init
__(Photo
)
122 gobject
.type_register(PhotoListStore
)
124 def thumbnail_path_from_uri(uri
, size
='normal'):
125 """Construct the path for the thumbnail of the given uri
128 - `uri`: the uri that points to the file that is looking for the thumbnail.
129 - `size`: the size of the thumbnail (normal or large)
132 assert isinstance(uri
, basestring
), \
133 TypeError("The uri must be a str")
135 assert isinstance(size
, basestring
) and (size
== 'large' or size
=='normal'), \
136 TypeError("The size for thumbnail can be normal or large")
140 path
= os
.path
.join(os
.path
.expanduser('~'), ".thumbnails", size
, str("%s.png" % hash.hexdigest()))
145 db_path
= os
.path
.join(os
.path
.expanduser('~'), ".gnome2", "f-spot", "photos.db")
146 conn
= sqlite3
.connect(db_path
)
149 class ConfigurationManager(gobject
.GObject
):
156 super(ConfigurationManager
, self
).__init
__()
157 self
._client
= gconf
.client_get_default()
158 self
._base
= "/apps/marvin"
159 self
._client
.add_dir (self
._base
, gconf
.CLIENT_PRELOAD_NONE
)
163 # window_default_size
164 def set_window_default_size(self
, value
):
166 assert isinstance(value
, tuple) and len(value
)==2, "The value must be a tuple of int, like (200, 200)"
167 assert isinstance(value
[0], int) and value
[0] > 0, "The pair must int > 0"
168 assert isinstance(value
[1], int) and value
[1] > 0, "The pair must int > 0"
170 self
._client
.set_pair(self
._base
+ "/window_size",
171 gconf
.VALUE_INT
, gconf
.VALUE_INT
,
174 def get_window_default_size(self
):
175 return self
._client
.get_pair(self
._base
+ "/window_size",
176 gconf
.VALUE_INT
, gconf
.VALUE_INT
)
178 window_default_size
= property(get_window_default_size
,
179 set_window_default_size
,
181 "The default size that will use the main window")
184 def set_wallpaper(cls
, path
):
186 base
= "/desktop/gnome/background"
187 client
= gconf
.client_get_default()
188 client
.add_dir(base
, gconf
.CLIENT_PRELOAD_NONE
)
190 client
.set_string(base
+ "/picture_filename", path
)
192 gobject
.type_register(ConfigurationManager
)