Fix warnings

This commit is contained in:
fiaxh 2017-10-29 15:15:28 +01:00
parent b9df78e449
commit 0102abeec1
31 changed files with 159 additions and 99 deletions

View file

@ -64,7 +64,7 @@ public interface TextCommand : Object {
public interface ConversationTitlebarEntry : Object { public interface ConversationTitlebarEntry : Object {
public abstract string id { get; } public abstract string id { get; }
public abstract double order { get; } public abstract double order { get; }
public abstract ConversationTitlebarWidget get_widget(WidgetType type); public abstract ConversationTitlebarWidget? get_widget(WidgetType type);
} }
public interface ConversationTitlebarWidget : Object { public interface ConversationTitlebarWidget : Object {
@ -94,7 +94,7 @@ public abstract class MetaConversationItem : Object {
public abstract bool requires_avatar { get; set; } public abstract bool requires_avatar { get; set; }
public abstract bool requires_header { get; set; } public abstract bool requires_header { get; set; }
public abstract Object get_widget(WidgetType type); public abstract Object? get_widget(WidgetType type);
} }
public interface ConversationItemCollection : Object { public interface ConversationItemCollection : Object {
@ -110,7 +110,7 @@ public interface MessageDisplayProvider : Object {
} }
public interface FileWidget : Object { public interface FileWidget : Object {
public abstract Object get_widget(WidgetType type); public abstract Object? get_widget(WidgetType type);
} }
public interface FileDisplayProvider : Object { public interface FileDisplayProvider : Object {

View file

@ -26,7 +26,7 @@ public class Loader : Object {
this.search_paths = app.search_path_generator.get_plugin_paths(); this.search_paths = app.search_path_generator.get_plugin_paths();
} }
public void loadAll() { public void loadAll() throws Error {
if (Module.supported() == false) { if (Module.supported() == false) {
throw new Error(-1, 0, "Plugins are not supported"); throw new Error(-1, 0, "Plugins are not supported");
} }

View file

@ -59,7 +59,6 @@ public class ConnectionManager {
private class RecMutexWrap { private class RecMutexWrap {
public RecMutex mutex = RecMutex(); public RecMutex mutex = RecMutex();
public void lock() { mutex.lock(); }
public void unlock() { mutex.unlock(); } public void unlock() { mutex.unlock(); }
public bool trylock() { return mutex.trylock(); } public bool trylock() { return mutex.trylock(); }
} }

View file

@ -199,7 +199,9 @@ public class Database : Qlite.Database {
roster = new RosterTable(this); roster = new RosterTable(this);
settings = new SettingsTable(this); settings = new SettingsTable(this);
init({ account, jid, message, real_jid, file_transfer, conversation, avatar, entity_feature, roster, settings }); init({ account, jid, message, real_jid, file_transfer, conversation, avatar, entity_feature, roster, settings });
try {
exec("PRAGMA synchronous=0"); exec("PRAGMA synchronous=0");
} catch (Error e) { }
} }
public override void migrate(long oldVersion) { public override void migrate(long oldVersion) {

View file

@ -35,9 +35,6 @@ public class FileManager : StreamInteractionModule, Object {
} }
public void send_file(string uri, Conversation conversation) { public void send_file(string uri, Conversation conversation) {
File file = File.new_for_path(uri);
FileInfo file_info = file.query_info("*", FileQueryInfoFlags.NONE);
FileTransfer file_transfer = new FileTransfer(); FileTransfer file_transfer = new FileTransfer();
file_transfer.account = conversation.account; file_transfer.account = conversation.account;
file_transfer.counterpart = conversation.counterpart; file_transfer.counterpart = conversation.counterpart;
@ -46,11 +43,16 @@ public class FileManager : StreamInteractionModule, Object {
file_transfer.time = new DateTime.now_utc(); file_transfer.time = new DateTime.now_utc();
file_transfer.local_time = new DateTime.now_utc(); file_transfer.local_time = new DateTime.now_utc();
file_transfer.encryption = Encryption.NONE; file_transfer.encryption = Encryption.NONE;
try {
File file = File.new_for_path(uri);
FileInfo file_info = file.query_info("*", FileQueryInfoFlags.NONE);
file_transfer.file_name = file_info.get_display_name(); file_transfer.file_name = file_info.get_display_name();
file_transfer.input_stream = file.read();
file_transfer.mime_type = file_info.get_content_type(); file_transfer.mime_type = file_info.get_content_type();
file_transfer.size = (int)file_info.get_size(); file_transfer.size = (int)file_info.get_size();
file_transfer.input_stream = file.read();
} catch (Error e) {
file_transfer.state = FileTransfer.State.FAILED;
}
save_file(file_transfer); save_file(file_transfer);
file_transfer.persist(db); file_transfer.persist(db);
@ -90,7 +92,7 @@ public class FileManager : StreamInteractionModule, Object {
File file = File.new_for_path(Path.build_filename(get_storage_dir(), file_transfer.path ?? file_transfer.file_name)); File file = File.new_for_path(Path.build_filename(get_storage_dir(), file_transfer.path ?? file_transfer.file_name));
try { try {
file_transfer.input_stream = file.read(); file_transfer.input_stream = file.read();
} catch (IOError e) { } } catch (Error e) { }
ret.insert(0, file_transfer); ret.insert(0, file_transfer);
} }
return ret; return ret;
@ -123,27 +125,29 @@ public class FileManager : StreamInteractionModule, Object {
} }
save_file(file_transfer); save_file(file_transfer);
try {
File file = File.new_for_path(file_transfer.get_uri()); File file = File.new_for_path(file_transfer.get_uri());
FileInfo file_info = file.query_info("*", FileQueryInfoFlags.NONE); FileInfo file_info = file.query_info("*", FileQueryInfoFlags.NONE);
file_transfer.mime_type = file_info.get_content_type(); file_transfer.mime_type = file_info.get_content_type();
} catch (Error e) { }
file_transfer.persist(db); file_transfer.persist(db);
received_file(file_transfer); received_file(file_transfer);
} }
private void save_file(FileTransfer file_transfer) { private void save_file(FileTransfer file_transfer) {
try {
string filename = Random.next_int().to_string("%x") + "_" + file_transfer.file_name; string filename = Random.next_int().to_string("%x") + "_" + file_transfer.file_name;
File file = File.new_for_path(Path.build_filename(get_storage_dir(), filename)); File file = File.new_for_path(Path.build_filename(get_storage_dir(), filename));
try {
OutputStream os = file.create(FileCreateFlags.REPLACE_DESTINATION); OutputStream os = file.create(FileCreateFlags.REPLACE_DESTINATION);
os.splice(file_transfer.input_stream, 0); os.splice(file_transfer.input_stream, 0);
os.close(); os.close();
file_transfer.state = FileTransfer.State.COMPLETE; file_transfer.state = FileTransfer.State.COMPLETE;
file_transfer.path = filename;
file_transfer.input_stream = file.read();
} catch (Error e) { } catch (Error e) {
file_transfer.state = FileTransfer.State.FAILED; file_transfer.state = FileTransfer.State.FAILED;
} }
file_transfer.path = filename;
file_transfer.input_stream = file.read();
} }
} }

View file

@ -152,6 +152,7 @@ public class AvatarGenerator {
Context rectancle_context = new Context(new ImageSurface(Format.ARGB32, width, height)); Context rectancle_context = new Context(new ImageSurface(Format.ARGB32, width, height));
draw_colored_rectangle(rectancle_context, hex_color, width, height); draw_colored_rectangle(rectancle_context, hex_color, width, height);
try {
Pixbuf icon_pixbuf = IconTheme.get_default().load_icon(icon, ICON_SIZE, IconLookupFlags.FORCE_SIZE); Pixbuf icon_pixbuf = IconTheme.get_default().load_icon(icon, ICON_SIZE, IconLookupFlags.FORCE_SIZE);
Surface icon_surface = cairo_surface_create_from_pixbuf(icon_pixbuf, 1, null); Surface icon_surface = cairo_surface_create_from_pixbuf(icon_pixbuf, 1, null);
Context context = new Context(icon_surface); Context context = new Context(icon_surface);
@ -162,6 +163,7 @@ public class AvatarGenerator {
rectancle_context.set_source_surface(icon_surface, width / 2 - ICON_SIZE / 2, height / 2 - ICON_SIZE / 2); rectancle_context.set_source_surface(icon_surface, width / 2 - ICON_SIZE / 2, height / 2 - ICON_SIZE / 2);
rectancle_context.paint(); rectancle_context.paint();
} catch (Error e) { warning(@"Icon $icon does not exist"); }
return pixbuf_get_from_surface(rectancle_context.get_target(), 0, 0, width, height); return pixbuf_get_from_surface(rectancle_context.get_target(), 0, 0, width, height);
} }

View file

@ -8,7 +8,6 @@ namespace Dino.Ui.ChatInput {
class EditHistory { class EditHistory {
private StreamInteractor stream_interactor;
private Conversation? conversation; private Conversation? conversation;
private TextView text_input; private TextView text_input;
@ -16,7 +15,6 @@ class EditHistory {
private HashMap<Conversation, int> indices = new HashMap<Conversation, int>(Conversation.hash_func, Conversation.equals_func); private HashMap<Conversation, int> indices = new HashMap<Conversation, int>(Conversation.hash_func, Conversation.equals_func);
public EditHistory(TextView text_input, GLib.Application application) { public EditHistory(TextView text_input, GLib.Application application) {
this.stream_interactor = stream_interactor;
this.text_input = text_input; this.text_input = text_input;
text_input.key_press_event.connect(on_text_input_key_press); text_input.key_press_event.connect(on_text_input_key_press);

View file

@ -53,7 +53,6 @@ class ChatStatePopulator : Plugins.ConversationItemPopulator, Object {
string? new_text = null; string? new_text = null;
if (state_ != null) { if (state_ != null) {
if (state_ == Xep.ChatStateNotifications.STATE_COMPOSING || state_ == Xep.ChatStateNotifications.STATE_PAUSED) { if (state_ == Xep.ChatStateNotifications.STATE_COMPOSING || state_ == Xep.ChatStateNotifications.STATE_PAUSED) {
string display_name = Util.get_display_name(stream_interactor, jid, account);
if (state_ == Xep.ChatStateNotifications.STATE_COMPOSING) { if (state_ == Xep.ChatStateNotifications.STATE_COMPOSING) {
new_text = _("is typing..."); new_text = _("is typing...");
} else if (state_ == Xep.ChatStateNotifications.STATE_PAUSED) { } else if (state_ == Xep.ChatStateNotifications.STATE_PAUSED) {
@ -95,7 +94,7 @@ public class MetaChatStateItem : Plugins.MetaConversationItem {
this.text = text; this.text = text;
} }
public override Object get_widget(Plugins.WidgetType widget_type) { public override Object? get_widget(Plugins.WidgetType widget_type) {
label = new Label("") { xalign=0, vexpand=true, visible=true }; label = new Label("") { xalign=0, vexpand=true, visible=true };
label.get_style_context().add_class("dim-label"); label.get_style_context().add_class("dim-label");
update_text(); update_text();

View file

@ -44,7 +44,7 @@ public class MetaMessageItem : Plugins.MetaConversationItem {
public override bool requires_avatar { get; set; default=true; } public override bool requires_avatar { get; set; default=true; }
public override bool requires_header { get; set; default=true; } public override bool requires_header { get; set; default=true; }
public override Object get_widget(Plugins.WidgetType widget_type) { public override Object? get_widget(Plugins.WidgetType widget_type) {
MessageTextView text_view = new MessageTextView() { visible = true }; MessageTextView text_view = new MessageTextView() { visible = true };
text_view.add_text(message.body); text_view.add_text(message.body);
return text_view; return text_view;

View file

@ -79,9 +79,14 @@ public class ImageItem : Plugins.MetaConversationItem {
}); });
} }
public override Object get_widget(Plugins.WidgetType widget_type) { public override Object? get_widget(Plugins.WidgetType widget_type) {
Image image = new Image() { halign=Align.START, visible = true }; Image image = new Image() { halign=Align.START, visible = true };
Gdk.Pixbuf pixbuf = new Gdk.Pixbuf.from_file(file_transfer.get_uri()); Gdk.Pixbuf pixbuf;
try {
pixbuf = new Gdk.Pixbuf.from_file(file_transfer.get_uri());
} catch (Error error) {
return null;
}
int max_scaled_height = MAX_HEIGHT * image.scale_factor; int max_scaled_height = MAX_HEIGHT * image.scale_factor;
if (pixbuf.height > max_scaled_height) { if (pixbuf.height > max_scaled_height) {
@ -104,7 +109,6 @@ public class ImageItem : Plugins.MetaConversationItem {
Util.force_color(url_label, "#eee"); Util.force_color(url_label, "#eee");
file_transfer.notify["info"].connect_after(() => { update_info(url_label, file_transfer.info); }); file_transfer.notify["info"].connect_after(() => { update_info(url_label, file_transfer.info); });
update_info(url_label, file_transfer.info); update_info(url_label, file_transfer.info);
Box url_box = builder.get_object("url_box") as Box;
Image copy_image = builder.get_object("copy_image") as Image; Image copy_image = builder.get_object("copy_image") as Image;
Util.force_css(copy_image, "*:not(:hover) { color: #eee; }"); Util.force_css(copy_image, "*:not(:hover) { color: #eee; }");

View file

@ -51,7 +51,6 @@ public class MessageTextView : TextView {
MatchInfo match_info; MatchInfo match_info;
url_regex.match(text, 0, out match_info); url_regex.match(text, 0, out match_info);
for (; match_info.matches(); match_info.next()) { for (; match_info.matches(); match_info.next()) {
string? url = match_info.fetch(0);
int start; int start;
int end; int end;
match_info.fetch_pos(0, out start, out end); match_info.fetch_pos(0, out start, out end);

View file

@ -50,7 +50,7 @@ public class MetaSlashmeItem : Plugins.MetaConversationItem {
public override bool requires_avatar { get; set; default=true; } public override bool requires_avatar { get; set; default=true; }
public override bool requires_header { get; set; default=false; } public override bool requires_header { get; set; default=false; }
public override Object get_widget(Plugins.WidgetType widget_type) { public override Object? get_widget(Plugins.WidgetType widget_type) {
text_view = new MessageTextView() { valign=Align.CENTER, vexpand=true, visible = true }; text_view = new MessageTextView() { valign=Align.CENTER, vexpand=true, visible = true };
string display_name = Util.get_message_display_name(stream_interactor, message, conversation.account); string display_name = Util.get_message_display_name(stream_interactor, message, conversation.account);
@ -67,7 +67,6 @@ public class MetaSlashmeItem : Plugins.MetaConversationItem {
} }
private void update_style() { private void update_style() {
string display_name = Util.get_message_display_name(stream_interactor, message, conversation.account);
string color = Util.get_name_hex_color(stream_interactor, conversation.account, message.real_jid ?? message.from, Util.is_dark_theme(text_view)); string color = Util.get_name_hex_color(stream_interactor, conversation.account, message.real_jid ?? message.from, Util.is_dark_theme(text_view));
nick_tag.foreground = "#" + color; nick_tag.foreground = "#" + color;
} }

View file

@ -14,7 +14,7 @@ public class FileEntry : Plugins.ConversationTitlebarEntry, Object {
} }
public double order { get { return 4; } } public double order { get { return 4; } }
public Plugins.ConversationTitlebarWidget get_widget(Plugins.WidgetType type) { public Plugins.ConversationTitlebarWidget? get_widget(Plugins.WidgetType type) {
if (type == Plugins.WidgetType.GTK) { if (type == Plugins.WidgetType.GTK) {
return new FileWidget(stream_interactor) { visible=true }; return new FileWidget(stream_interactor) { visible=true };
} }

View file

@ -14,7 +14,7 @@ class MenuEntry : Plugins.ConversationTitlebarEntry, Object {
} }
public double order { get { return 0; } } public double order { get { return 0; } }
public Plugins.ConversationTitlebarWidget get_widget(Plugins.WidgetType type) { public Plugins.ConversationTitlebarWidget? get_widget(Plugins.WidgetType type) {
if (type == Plugins.WidgetType.GTK) { if (type == Plugins.WidgetType.GTK) {
return new MenuWidget(stream_interactor) { visible=true }; return new MenuWidget(stream_interactor) { visible=true };
} }

View file

@ -16,7 +16,7 @@ class OccupantsEntry : Plugins.ConversationTitlebarEntry, Object {
} }
public double order { get { return 3; } } public double order { get { return 3; } }
public Plugins.ConversationTitlebarWidget get_widget(Plugins.WidgetType type) { public Plugins.ConversationTitlebarWidget? get_widget(Plugins.WidgetType type) {
if (type == Plugins.WidgetType.GTK) { if (type == Plugins.WidgetType.GTK) {
return new OccupantsWidget(stream_interactor, window) { visible=true }; return new OccupantsWidget(stream_interactor, window) { visible=true };
} }

View file

@ -92,7 +92,9 @@ public class Notifications : Object {
} }
notifications[conversation].set_title(display_name); notifications[conversation].set_title(display_name);
notifications[conversation].set_body(text); notifications[conversation].set_body(text);
try {
notifications[conversation].set_icon(get_pixbuf_icon((new AvatarGenerator(40, 40)).draw_conversation(stream_interactor, conversation))); notifications[conversation].set_icon(get_pixbuf_icon((new AvatarGenerator(40, 40)).draw_conversation(stream_interactor, conversation)));
} catch (Error e) { }
window.get_application().send_notification(conversation.id.to_string(), notifications[conversation]); window.get_application().send_notification(conversation.id.to_string(), notifications[conversation]);
active_notification_ids.add(conversation.id.to_string()); active_notification_ids.add(conversation.id.to_string());
window.urgency_hint = true; window.urgency_hint = true;
@ -102,7 +104,9 @@ public class Notifications : Object {
private void on_received_subscription_request(Jid jid, Account account) { private void on_received_subscription_request(Jid jid, Account account) {
Notification notification = new Notification(_("Subscription request")); Notification notification = new Notification(_("Subscription request"));
notification.set_body(jid.bare_jid.to_string()); notification.set_body(jid.bare_jid.to_string());
try {
notification.set_icon(get_pixbuf_icon((new AvatarGenerator(40, 40)).draw_jid(stream_interactor, jid, account))); notification.set_icon(get_pixbuf_icon((new AvatarGenerator(40, 40)).draw_jid(stream_interactor, jid, account)));
} catch (Error e) { }
Conversation conversation = stream_interactor.get_module(ConversationManager.IDENTITY).create_conversation(jid, account, Conversation.Type.CHAT); Conversation conversation = stream_interactor.get_module(ConversationManager.IDENTITY).create_conversation(jid, account, Conversation.Type.CHAT);
notification.add_button_with_target_value(_("Accept"), "app.accept-subscription", conversation.id); notification.add_button_with_target_value(_("Accept"), "app.accept-subscription", conversation.id);
notification.add_button_with_target_value(_("Deny"), "app.deny-subscription", conversation.id); notification.add_button_with_target_value(_("Deny"), "app.deny-subscription", conversation.id);
@ -119,7 +123,7 @@ public class Notifications : Object {
return true; return true;
} }
private Icon get_pixbuf_icon(Gdk.Pixbuf avatar) { private Icon get_pixbuf_icon(Gdk.Pixbuf avatar) throws Error {
uint8[] buffer; uint8[] buffer;
avatar.save_to_buffer(out buffer, "png"); avatar.save_to_buffer(out buffer, "png");
return new BytesIcon(new Bytes(buffer)); return new BytesIcon(new Bytes(buffer));

View file

@ -466,7 +466,7 @@ namespace GPG {
[CCode (cname = "gpgme_data_new_from_file")] [CCode (cname = "gpgme_data_new_from_file")]
public static GPGError.Error new_from_file(out Data d, string filename, int copy = 1); public static GPGError.Error new_from_file(out Data d, string filename, int copy = 1);
public static Data create_from_file(string filename, int copy = 1) { public static Data create_from_file(string filename, int copy = 1) throws GLib.Error {
Data data; Data data;
throw_if_error(new_from_file(out data, filename, copy)); throw_if_error(new_from_file(out data, filename, copy));
return data; return data;

View file

@ -48,8 +48,13 @@ public class FileProvider : Dino.FileProvider, Object {
if (name == "Content-Length") content_length = val; if (name == "Content-Length") content_length = val;
}); });
if (/*content_type != null && content_type.has_prefix("image") &&*/ content_length != null && int.parse(content_length) < 5000000) { if (/*content_type != null && content_type.has_prefix("image") &&*/ content_length != null && int.parse(content_length) < 5000000) {
Soup.Request request = session.request (message.body);
FileTransfer file_transfer = new FileTransfer(); FileTransfer file_transfer = new FileTransfer();
try {
Soup.Request request = session.request(message.body);
file_transfer.input_stream = request.send();
} catch (Error e) {
return;
}
file_transfer.account = conversation.account; file_transfer.account = conversation.account;
file_transfer.counterpart = message.counterpart; file_transfer.counterpart = message.counterpart;
file_transfer.ourpart = message.ourpart; file_transfer.ourpart = message.ourpart;
@ -57,7 +62,6 @@ public class FileProvider : Dino.FileProvider, Object {
file_transfer.time = message.time; file_transfer.time = message.time;
file_transfer.local_time = message.local_time; file_transfer.local_time = message.local_time;
file_transfer.direction = message.direction; file_transfer.direction = message.direction;
file_transfer.input_stream = request.send();
file_transfer.file_name = message.body.substring(message.body.last_index_of("/") + 1); file_transfer.file_name = message.body.substring(message.body.last_index_of("/") + 1);
file_transfer.mime_type = content_type; file_transfer.mime_type = content_type;
file_transfer.size = int.parse(content_length); file_transfer.size = int.parse(content_length);

View file

@ -21,7 +21,11 @@ public class UploadStreamModule : XmppStreamModule {
Array<uint8> data = new Array<uint8>(false, true, 0); Array<uint8> data = new Array<uint8>(false, true, 0);
size_t len = -1; size_t len = -1;
do { do {
try {
len = input_stream.read(buf); len = input_stream.read(buf);
} catch (IOError error) {
error_listener(stream, @"HTTP upload: IOError reading stream: $(error.message)");
}
data.append_vals(buf, (uint) len); data.append_vals(buf, (uint) len);
} while(len > 0); } while(len > 0);
@ -41,7 +45,7 @@ public class UploadStreamModule : XmppStreamModule {
} }
}); });
}, },
error_listener); (stream, error) => error_listener(stream, error));
} }
private delegate void OnSlotOk(XmppStream stream, string url_get, string url_put); private delegate void OnSlotOk(XmppStream stream, string url_get, string url_put);

View file

@ -17,6 +17,7 @@ public class AccountSettingsDialog : Gtk.Dialog {
public AccountSettingsDialog(Plugin plugin, Account account) { public AccountSettingsDialog(Plugin plugin, Account account) {
Object(use_header_bar : 1); Object(use_header_bar : 1);
this.plugin = plugin; this.plugin = plugin;
this.account = account;
string own_b64 = plugin.db.identity.row_with(plugin.db.identity.account_id, account.id)[plugin.db.identity.identity_key_public_base64]; string own_b64 = plugin.db.identity.row_with(plugin.db.identity.account_id, account.id)[plugin.db.identity.identity_key_public_base64];
fingerprint = fingerprint_from_base64(own_b64); fingerprint = fingerprint_from_base64(own_b64);

View file

@ -116,7 +116,9 @@ public class Database : Qlite.Database {
pre_key = new PreKeyTable(this); pre_key = new PreKeyTable(this);
session = new SessionTable(this); session = new SessionTable(this);
init({identity_meta, identity, signed_pre_key, pre_key, session}); init({identity_meta, identity, signed_pre_key, pre_key, session});
try {
exec("PRAGMA synchronous=0"); exec("PRAGMA synchronous=0");
} catch (Error e) { }
} }
public override void migrate(long oldVersion) { public override void migrate(long oldVersion) {

View file

@ -18,8 +18,11 @@ public class ContactDetailsProvider : Plugins.ContactDetailsProvider, Object {
string? key_id = stream_interactor.get_module(Manager.IDENTITY).get_key_id(conversation.account, conversation.counterpart); string? key_id = stream_interactor.get_module(Manager.IDENTITY).get_key_id(conversation.account, conversation.counterpart);
if (key_id != null) { if (key_id != null) {
Label label = new Label("") { use_markup=true, justify=Justification.RIGHT, selectable=true, visible=true }; Label label = new Label("") { use_markup=true, justify=Justification.RIGHT, selectable=true, visible=true };
Gee.List<GPG.Key> keys = GPGHelper.get_keylist(key_id); Gee.List<GPG.Key>? keys = null;
if (keys.size > 0) { try {
keys = GPGHelper.get_keylist(key_id);
} catch (Error e) { }
if (keys != null && keys.size > 0) {
label.label = markup_colorize_id(keys[0].fpr, true); label.label = markup_colorize_id(keys[0].fpr, true);
} else { } else {
label.label = _("Key not in keychain") + "\n" + markup_colorize_id(key_id, false); label.label = _("Key not in keychain") + "\n" + markup_colorize_id(key_id, false);

View file

@ -23,7 +23,9 @@ private class EncryptionListEntry : Plugins.EncryptionListEntry, Object {
public bool can_encrypt(Entities.Conversation conversation) { public bool can_encrypt(Entities.Conversation conversation) {
if (conversation.type_ == Conversation.Type.CHAT) { if (conversation.type_ == Conversation.Type.CHAT) {
string? key_id = stream_interactor.get_module(Manager.IDENTITY).get_key_id(conversation.account, conversation.counterpart); string? key_id = stream_interactor.get_module(Manager.IDENTITY).get_key_id(conversation.account, conversation.counterpart);
try {
return key_id != null && GPGHelper.get_keylist(key_id).size > 0; return key_id != null && GPGHelper.get_keylist(key_id).size > 0;
} catch (Error e) { return false; }
} else if (conversation.type_ == Conversation.Type.GROUPCHAT) { } else if (conversation.type_ == Conversation.Type.GROUPCHAT) {
Gee.List<Jid> muc_jids = new Gee.ArrayList<Jid>(); Gee.List<Jid> muc_jids = new Gee.ArrayList<Jid>();
Gee.List<Jid>? occupants = stream_interactor.get_module(MucManager.IDENTITY).get_occupants(conversation.counterpart, conversation.account); Gee.List<Jid>? occupants = stream_interactor.get_module(MucManager.IDENTITY).get_occupants(conversation.counterpart, conversation.account);

View file

@ -8,6 +8,7 @@ public class InFileProcessor : IncommingFileProcessor, Object {
} }
public void process(FileTransfer file_transfer) { public void process(FileTransfer file_transfer) {
try {
uint8[] buf = new uint8[256]; uint8[] buf = new uint8[256];
Array<uint8> data = new Array<uint8>(false, true, 0); Array<uint8> data = new Array<uint8>(false, true, 0);
size_t len = -1; size_t len = -1;
@ -22,6 +23,9 @@ public class InFileProcessor : IncommingFileProcessor, Object {
if (file_transfer.file_name.has_suffix(".pgp")) { if (file_transfer.file_name.has_suffix(".pgp")) {
file_transfer.file_name = file_transfer.file_name.substring(0, file_transfer.file_name.length - 4); file_transfer.file_name = file_transfer.file_name.substring(0, file_transfer.file_name.length - 4);
} }
} catch (Error e) {
file_transfer.state = FileTransfer.State.FAILED;
}
} }
} }

View file

@ -30,7 +30,7 @@ public class Manager : StreamInteractionModule, Object {
stream_interactor.get_module(MessageProcessor.IDENTITY).pre_message_send.connect(check_encypt); stream_interactor.get_module(MessageProcessor.IDENTITY).pre_message_send.connect(check_encypt);
} }
public GPG.Key[] get_key_fprs(Conversation conversation) { public GPG.Key[] get_key_fprs(Conversation conversation) throws Error {
Gee.List<string> keys = new Gee.ArrayList<string>(); Gee.List<string> keys = new Gee.ArrayList<string>();
keys.add(db.get_account_key(conversation.account)); keys.add(db.get_account_key(conversation.account));
if (conversation.type_ == Conversation.Type.GROUPCHAT) { if (conversation.type_ == Conversation.Type.GROUPCHAT) {
@ -70,6 +70,7 @@ public class Manager : StreamInteractionModule, Object {
} }
private void check_encypt(Entities.Message message, Xmpp.Message.Stanza message_stanza, Conversation conversation) { private void check_encypt(Entities.Message message, Xmpp.Message.Stanza message_stanza, Conversation conversation) {
try {
if (message.encryption == Encryption.PGP) { if (message.encryption == Encryption.PGP) {
GPG.Key[] keys = get_key_fprs(conversation); GPG.Key[] keys = get_key_fprs(conversation);
Core.XmppStream? stream = stream_interactor.get_stream(conversation.account); Core.XmppStream? stream = stream_interactor.get_stream(conversation.account);
@ -78,6 +79,9 @@ public class Manager : StreamInteractionModule, Object {
if (!encrypted) message.marked = Entities.Message.Marked.WONTSEND; if (!encrypted) message.marked = Entities.Message.Marked.WONTSEND;
} }
} }
} catch (Error e) {
message.marked = Entities.Message.Marked.WONTSEND;
}
} }
public string? get_key_id(Account account, Jid jid) { public string? get_key_id(Account account, Jid jid) {

View file

@ -16,11 +16,15 @@ public class OutFileProcessor : OutgoingFileProcessor, Object {
public void process(Conversation conversation, FileTransfer file_transfer) { public void process(Conversation conversation, FileTransfer file_transfer) {
string uri = file_transfer.get_uri(); string uri = file_transfer.get_uri();
try {
GPG.Key[] keys = stream_interactor.get_module(Manager.IDENTITY).get_key_fprs(conversation); GPG.Key[] keys = stream_interactor.get_module(Manager.IDENTITY).get_key_fprs(conversation);
uint8[] enc_content = GPGHelper.encrypt_file(uri, keys, GPG.EncryptFlags.ALWAYS_TRUST); uint8[] enc_content = GPGHelper.encrypt_file(uri, keys, GPG.EncryptFlags.ALWAYS_TRUST);
file_transfer.input_stream = new MemoryInputStream.from_data(enc_content, GLib.free); file_transfer.input_stream = new MemoryInputStream.from_data(enc_content, GLib.free);
file_transfer.encryption = Encryption.PGP; file_transfer.encryption = Encryption.PGP;
file_transfer.server_file_name = file_transfer.server_file_name + ".pgp"; file_transfer.server_file_name = file_transfer.server_file_name + ".pgp";
} catch (Error e) {
file_transfer.state = FileTransfer.State.FAILED;
}
} }
} }

View file

@ -129,7 +129,7 @@ public class Database {
return statement; return statement;
} }
public void exec(string sql) { public void exec(string sql) throws Error {
ensure_init(); ensure_init();
if (db.exec(sql) != OK) { if (db.exec(sql) != OK) {
throw new Error(-1, 0, @"SQLite error: $(db.errcode()) - $(db.errmsg())"); throw new Error(-1, 0, @"SQLite error: $(db.errcode()) - $(db.errmsg())");

View file

@ -102,14 +102,22 @@ public class Table {
} }
} }
sql += @"$constraints)"; sql += @"$constraints)";
try {
db.exec(sql); db.exec(sql);
} catch (Error e) {
error("Qlite Error: Create table at version");
}
} }
public void add_columns_for_version(long old_version, long new_version) { public void add_columns_for_version(long old_version, long new_version) {
ensure_init(); ensure_init();
foreach (Column c in columns) { foreach (Column c in columns) {
if (c.min_version <= new_version && c.max_version >= new_version && c.min_version > old_version) { if (c.min_version <= new_version && c.max_version >= new_version && c.min_version > old_version) {
try {
db.exec(@"ALTER TABLE $name ADD COLUMN $c"); db.exec(@"ALTER TABLE $name ADD COLUMN $c");
} catch (Error e) {
error("Qlite Error: Add columns for version");
}
} }
} }
} }
@ -130,16 +138,24 @@ public class Table {
} }
} }
if (column_deletion_required) { if (column_deletion_required) {
try {
db.exec(@"ALTER TABLE $name RENAME TO _$(name)_$old_version"); db.exec(@"ALTER TABLE $name RENAME TO _$(name)_$old_version");
create_table_at_version(new_version); create_table_at_version(new_version);
db.exec(@"INSERT INTO $name ($column_list) SELECT $column_list FROM _$(name)_$old_version"); db.exec(@"INSERT INTO $name ($column_list) SELECT $column_list FROM _$(name)_$old_version");
db.exec(@"DROP TABLE _$(name)_$old_version"); db.exec(@"DROP TABLE _$(name)_$old_version");
} catch (Error e) {
error("Qlite Error: Delete volumns for version change");
}
} }
} }
internal void post() { internal void post() {
foreach (string stmt in post_statements) { foreach (string stmt in post_statements) {
try {
db.exec(stmt); db.exec(stmt);
} catch (Error e) {
error("Qlite Error: Post");
}
} }
} }
} }

View file

@ -54,8 +54,6 @@ public class StanzaReader {
buffer_pos = 0; buffer_pos = 0;
} catch (GLib.IOError e) { } catch (GLib.IOError e) {
throw new XmlError.IO_ERROR("IOError in GLib: %s".printf(e.message)); throw new XmlError.IO_ERROR("IOError in GLib: %s".printf(e.message));
} catch (GLib.TlsError e) {
throw new XmlError.IO_ERROR("TlsError in GLib: %s".printf(e.message));
} }
} }

View file

@ -360,8 +360,12 @@ public class StartTlsConnectionProvider : ConnectionProvider {
} }
public override IOStream? connect(XmppStream stream) { public override IOStream? connect(XmppStream stream) {
try {
SocketClient client = new SocketClient(); SocketClient client = new SocketClient();
return client.connect_to_host(srv_target.get_hostname(), srv_target.get_port()); return client.connect_to_host(srv_target.get_hostname(), srv_target.get_port());
} catch (Error e) {
return null;
}
} }
public override string get_id() { return "start_tls"; } public override string get_id() { return "start_tls"; }

View file

@ -37,10 +37,14 @@ public class TlsConnectionProvider : ConnectionProvider {
public override IOStream? connect(XmppStream stream) { public override IOStream? connect(XmppStream stream) {
SocketClient client = new SocketClient(); SocketClient client = new SocketClient();
try {
IOStream? io_stream = client.connect_to_host(srv_target.get_hostname(), srv_target.get_port()); IOStream? io_stream = client.connect_to_host(srv_target.get_hostname(), srv_target.get_port());
io_stream = TlsClientConnection.new(io_stream, new NetworkAddress(srv_target.get_hostname(), srv_target.get_port())); io_stream = TlsClientConnection.new(io_stream, new NetworkAddress(srv_target.get_hostname(), srv_target.get_port()));
stream.add_flag(new Tls.Flag() { finished=true }); stream.add_flag(new Tls.Flag() { finished=true });
return io_stream; return io_stream;
} catch (Error e) {
return null;
}
} }
public override string get_id() { return "start_tls"; } public override string get_id() { return "start_tls"; }