2017-03-02 14:37:32 +00:00
|
|
|
using Gdk;
|
|
|
|
|
|
|
|
using Xmpp;
|
|
|
|
|
|
|
|
namespace Dino {
|
|
|
|
public class AvatarStorage : Xep.PixbufStorage, Object {
|
|
|
|
|
|
|
|
string folder;
|
|
|
|
|
|
|
|
public AvatarStorage(string folder) {
|
|
|
|
this.folder = folder;
|
2017-03-12 12:19:04 +00:00
|
|
|
DirUtils.create_with_parents(folder, 0700);
|
2017-03-02 14:37:32 +00:00
|
|
|
}
|
|
|
|
|
2019-04-18 20:37:21 +00:00
|
|
|
public void store(string id, Bytes data) {
|
2017-03-12 12:19:04 +00:00
|
|
|
File file = File.new_for_path(Path.build_filename(folder, id));
|
|
|
|
try {
|
|
|
|
if (file.query_exists()) file.delete(); //TODO y?
|
|
|
|
DataOutputStream fos = new DataOutputStream(file.create(FileCreateFlags.REPLACE_DESTINATION));
|
2019-04-18 20:37:21 +00:00
|
|
|
fos.write_bytes_async.begin(data);
|
2017-03-12 12:19:04 +00:00
|
|
|
} catch (Error e) {
|
|
|
|
// Ignore: we failed in storing, so we refuse to display later...
|
|
|
|
}
|
2017-03-02 14:37:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public bool has_image(string id) {
|
2017-03-12 12:19:04 +00:00
|
|
|
File file = File.new_for_path(Path.build_filename(folder, id));
|
2017-03-02 14:37:32 +00:00
|
|
|
return file.query_exists();
|
|
|
|
}
|
|
|
|
|
|
|
|
public Pixbuf? get_image(string id) {
|
|
|
|
try {
|
2017-03-12 12:19:04 +00:00
|
|
|
return new Pixbuf.from_file(Path.build_filename(folder, id));
|
2017-03-02 14:37:32 +00:00
|
|
|
} catch (Error e) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-02-13 20:50:15 +00:00
|
|
|
}
|