reorg: separate dbus code out of conversation list model and into repository
This commit is contained in:
@@ -8,8 +8,6 @@ public class ConversationListModel : Object, ListModel
|
||||
}
|
||||
|
||||
private SortedSet<Conversation> _conversations;
|
||||
private DBusService.Repository repository;
|
||||
private uint dbus_watch_id;
|
||||
|
||||
public ConversationListModel() {
|
||||
_conversations = new TreeSet<Conversation>((a, b) => {
|
||||
@@ -17,62 +15,12 @@ public class ConversationListModel : Object, ListModel
|
||||
return (int)(b.date - a.date);
|
||||
});
|
||||
|
||||
connect_to_dbus.begin();
|
||||
}
|
||||
|
||||
~ConversationListModel() {
|
||||
if (dbus_watch_id > 0) {
|
||||
Bus.unwatch_name(dbus_watch_id);
|
||||
}
|
||||
}
|
||||
|
||||
private async void connect_to_dbus() {
|
||||
bool connected = false;
|
||||
const string path = "/net/buzzert/kordophonecd/daemon";
|
||||
|
||||
try {
|
||||
debug("Trying to connect to DBus service at path: %s", path);
|
||||
repository = yield Bus.get_proxy(BusType.SESSION,
|
||||
"net.buzzert.kordophonecd",
|
||||
path);
|
||||
|
||||
// Test the connection
|
||||
repository.get_version();
|
||||
|
||||
// If we get here, connection succeeded
|
||||
debug("Connected to DBus service at path: %s", path);
|
||||
connected = true;
|
||||
|
||||
// Listen for updates
|
||||
repository.conversations_updated.connect(load_conversations);
|
||||
|
||||
// Initial load
|
||||
load_conversations();
|
||||
} catch (Error e) {
|
||||
debug("Failed to connect to kordophonecd at %s: %s", path, e.message);
|
||||
}
|
||||
|
||||
if (!connected) {
|
||||
warning("Failed to connect to kordophonecd on any known path");
|
||||
|
||||
// Watch for the service to appear
|
||||
dbus_watch_id = Bus.watch_name(BusType.SESSION,
|
||||
"net.buzzert.kordophonecd",
|
||||
BusNameWatcherFlags.AUTO_START,
|
||||
() => {
|
||||
connect_to_dbus.begin();
|
||||
},
|
||||
null);
|
||||
}
|
||||
Repository.get_instance().conversations_updated.connect(load_conversations);
|
||||
}
|
||||
|
||||
public void load_conversations() {
|
||||
if (repository == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
Variant conversations_variant = repository.get_conversations();
|
||||
Conversation[] conversations = Repository.get_instance().get_conversations();
|
||||
|
||||
// Clear existing set
|
||||
uint old_count = _conversations.size;
|
||||
@@ -84,12 +32,10 @@ public class ConversationListModel : Object, ListModel
|
||||
}
|
||||
|
||||
// Process each conversation
|
||||
size_t n_children = conversations_variant.n_children();
|
||||
uint position = 0;
|
||||
|
||||
for (size_t i = 0; i < n_children; i++) {
|
||||
Variant child = conversations_variant.get_child_value(i);
|
||||
var conversation = new Conversation.from_variant(child);
|
||||
for (int i = 0; i < conversations.length; i++) {
|
||||
var conversation = conversations[i];
|
||||
_conversations.add(conversation);
|
||||
position++;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user