Fix cyclic references => let objects be freed
This commit is contained in:
parent
a9e6a9c3d5
commit
8fe723bccb
|
@ -282,13 +282,7 @@ public class MessageItem : ContentItem {
|
|||
|
||||
this.message = message;
|
||||
this.conversation = conversation;
|
||||
|
||||
WeakRef weak_message = WeakRef(message);
|
||||
message.notify["marked"].connect(() => {
|
||||
Message? m = weak_message.get() as Message;
|
||||
if (m == null) return;
|
||||
mark = m.marked;
|
||||
});
|
||||
message.bind_property("marked", this, "mark");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -310,16 +304,13 @@ public class FileItem : ContentItem {
|
|||
this.file_transfer = file_transfer;
|
||||
this.conversation = conversation;
|
||||
|
||||
// TODO those don't work
|
||||
if (message != null) {
|
||||
WeakRef weak_message = WeakRef(message);
|
||||
message.notify["marked"].connect(() => {
|
||||
Message? m = weak_message.get() as Message;
|
||||
if (m == null) return;
|
||||
this.mark = m.marked;
|
||||
});
|
||||
message.bind_property("marked", this, "mark");
|
||||
} else if (file_transfer.direction == FileTransfer.DIRECTION_SENT) {
|
||||
file_transfer.notify["state"].connect_after(() => {
|
||||
this.mark = file_to_message_state(file_transfer.state);
|
||||
file_transfer.bind_property("state", this, "mark", BindingFlags.DEFAULT, (_, from_value, ref to_value) => {
|
||||
to_value = file_to_message_state((FileTransfer.State)from_value.get_enum());
|
||||
return true;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -86,12 +86,7 @@ public abstract class ContentMetaItem : Plugins.MetaConversationItem {
|
|||
this.encryption = content_item.encryption;
|
||||
this.mark = content_item.mark;
|
||||
|
||||
WeakRef weak_item = WeakRef(content_item);
|
||||
content_item.notify["mark"].connect(() => {
|
||||
ContentItem? ci = weak_item.get() as ContentItem;
|
||||
if (ci == null) return;
|
||||
this.mark = ci.mark;
|
||||
});
|
||||
content_item.bind_property("mark", this, "mark");
|
||||
|
||||
this.can_merge = true;
|
||||
this.requires_avatar = true;
|
||||
|
|
|
@ -15,6 +15,7 @@ public class ConversationItemSkeleton : EventBox {
|
|||
public StreamInteractor stream_interactor;
|
||||
public Conversation conversation { get; set; }
|
||||
public Plugins.MetaConversationItem item;
|
||||
public bool item_in_edit_mode { get; set; }
|
||||
public ContentMetaItem? content_meta_item = null;
|
||||
public Widget? widget = null;
|
||||
|
||||
|
@ -30,7 +31,8 @@ public class ConversationItemSkeleton : EventBox {
|
|||
this.content_meta_item = item as ContentMetaItem;
|
||||
this.get_style_context().add_class("message-box");
|
||||
|
||||
item.notify["in-edit-mode"].connect(() => {
|
||||
item.bind_property("in-edit-mode", this, "item-in-edit-mode");
|
||||
this.notify["item-in-edit-mode"].connect(() => {
|
||||
if (item.in_edit_mode) {
|
||||
this.get_style_context().add_class("edit-mode");
|
||||
} else {
|
||||
|
@ -112,7 +114,9 @@ public class ItemMetaDataHeader : Box {
|
|||
private StreamInteractor stream_interactor;
|
||||
private Conversation conversation;
|
||||
private Plugins.MetaConversationItem item;
|
||||
public Entities.Message.Marked item_mark { get; set; }
|
||||
private ArrayList<Plugins.MetaConversationItem> items = new ArrayList<Plugins.MetaConversationItem>();
|
||||
private uint time_update_timeout = 0;
|
||||
|
||||
public ItemMetaDataHeader(StreamInteractor stream_interactor, Conversation conversation, Plugins.MetaConversationItem item) {
|
||||
this.stream_interactor = stream_interactor;
|
||||
|
@ -151,7 +155,8 @@ public class ItemMetaDataHeader : Box {
|
|||
update_time();
|
||||
}
|
||||
|
||||
item.notify["mark"].connect_after(update_received_mark);
|
||||
item.bind_property("mark", this, "item-mark");
|
||||
this.notify["item-mark"].connect_after(update_received_mark);
|
||||
update_received_mark();
|
||||
}
|
||||
|
||||
|
@ -172,7 +177,7 @@ public class ItemMetaDataHeader : Box {
|
|||
private void update_time() {
|
||||
time_label.label = get_relative_time(item.display_time.to_local()).to_string();
|
||||
|
||||
Timeout.add_seconds((int) get_next_time_change(), () => {
|
||||
time_update_timeout = Timeout.add_seconds((int) get_next_time_change(), () => {
|
||||
if (this.parent == null) return false;
|
||||
update_time();
|
||||
return false;
|
||||
|
@ -276,6 +281,15 @@ public class ItemMetaDataHeader : Box {
|
|||
return _("Just now");
|
||||
}
|
||||
}
|
||||
|
||||
public override void dispose() {
|
||||
base.dispose();
|
||||
|
||||
if (time_update_timeout != 0) {
|
||||
Source.remove(time_update_timeout);
|
||||
time_update_timeout = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -37,6 +37,8 @@ public class FileWidget : SizeRequestBox {
|
|||
|
||||
private StreamInteractor stream_interactor;
|
||||
private FileTransfer file_transfer;
|
||||
public FileTransfer.State file_transfer_state { get; set; }
|
||||
public string file_transfer_mime_type { get; set; }
|
||||
private State? state = null;
|
||||
|
||||
private FileDefaultWidgetController default_widget_controller;
|
||||
|
@ -58,8 +60,11 @@ public class FileWidget : SizeRequestBox {
|
|||
}
|
||||
});
|
||||
|
||||
file_transfer.notify["state"].connect(update_widget);
|
||||
file_transfer.notify["mime-type"].connect(update_widget);
|
||||
file_transfer.bind_property("state", this, "file-transfer-state");
|
||||
file_transfer.bind_property("mime-type", this, "file-transfer-mime-type");
|
||||
|
||||
this.notify["file-transfer-state"].connect(update_widget);
|
||||
this.notify["file-transfer-mime-type"].connect(update_widget);
|
||||
}
|
||||
|
||||
private async void update_widget() {
|
||||
|
@ -115,6 +120,10 @@ public class FileDefaultWidgetController : Object {
|
|||
|
||||
private FileDefaultWidget widget;
|
||||
private FileTransfer? file_transfer;
|
||||
public string file_transfer_path { get; set; }
|
||||
public string file_transfer_state { get; set; }
|
||||
public string file_transfer_mime_type { get; set; }
|
||||
|
||||
private StreamInteractor? stream_interactor;
|
||||
private string file_uri;
|
||||
private FileTransfer.State state;
|
||||
|
@ -130,9 +139,13 @@ public class FileDefaultWidgetController : Object {
|
|||
|
||||
widget.name_label.label = file_transfer.file_name;
|
||||
|
||||
file_transfer.notify["path"].connect(update_file_info);
|
||||
file_transfer.notify["state"].connect(update_file_info);
|
||||
file_transfer.notify["mime-type"].connect(update_file_info);
|
||||
file_transfer.bind_property("path", this, "file-transfer-path");
|
||||
file_transfer.bind_property("state", this, "file-transfer-state");
|
||||
file_transfer.bind_property("mime-type", this, "file-transfer-mime-type");
|
||||
|
||||
this.notify["file-transfer-path"].connect(update_file_info);
|
||||
this.notify["file-transfer-state"].connect(update_file_info);
|
||||
this.notify["file-transfer-mime-type"].connect(update_file_info);
|
||||
|
||||
update_file_info();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue