Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions core/Objects/Source.vala
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ public class Objects.Source : Objects.BaseObject {

public signal void sync_started ();
public signal void sync_finished ();
public signal void sync_failed ();

public Source.from_import_json (Json.Node node) {
id = node.get_object ().get_string_member ("id");
Expand Down
3 changes: 2 additions & 1 deletion core/Services/CalDAV/Core.vala
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,8 @@ public class Services.CalDAV.Core : GLib.Object {
source.sync_finished ();
source.last_sync = new GLib.DateTime.now_local ().to_string ();
} catch (Error e) {
debug (e.message);
debug ("Failed to sync: " + e.message);
source.sync_failed ();
}
}

Expand Down
3 changes: 2 additions & 1 deletion core/Services/Todoist.vala
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,8 @@ public class Services.Todoist : GLib.Object {
yield queue (source);
}
} catch (Error e) {
debug (e.message);
debug ("Failed to sync: " + e.message);
source.sync_failed ();
}

source.last_sync = new GLib.DateTime.now_local ().to_string ();
Expand Down
6 changes: 5 additions & 1 deletion src/Layouts/SidebarSourceRow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ public class Layouts.SidebarSourceRow : Gtk.ListBoxRow {
source.sync_finished.connect (() => {
sync_button.sync_finished ();
});

source.sync_failed.connect (() => {
sync_button.sync_failed ();
});
}

var add_button = new Gtk.Button.from_icon_name ("plus-large-symbolic") {
Expand Down Expand Up @@ -191,4 +195,4 @@ public class Layouts.SidebarSourceRow : Gtk.ListBoxRow {
int ordered = Services.Settings.get_default ().settings.get_enum ("projects-ordered");
return ordered == 0 ? project2.name.collate (project1.name) : project1.name.collate (project2.name);
}
}
}
15 changes: 7 additions & 8 deletions src/MainWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -200,14 +200,13 @@ public class MainWindow : Adw.ApplicationWindow {

return GLib.Source.REMOVE;
});

Services.NetworkMonitor.instance ().network_changed.connect (() => {
if (Services.NetworkMonitor.instance ().network_available) {
foreach (Objects.Source source in Services.Store.instance ().sources) {
source.run_server ();
}
}
});

var network_monitor = GLib.NetworkMonitor.get_default ();
network_monitor.network_changed.connect (() => {
foreach (Objects.Source source in Services.Store.instance ().sources) {
source.run_server ();
}
});
});

var granite_settings = Granite.Settings.get_default ();
Expand Down
68 changes: 0 additions & 68 deletions src/Services/NetworkMonitor.vala

This file was deleted.

31 changes: 14 additions & 17 deletions src/Widgets/SyncButton.vala
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,17 @@ public class Widgets.SyncButton : Adw.Bin {
css_classes = { "flat", "header-item-button", "dim-label" }
};

var error_image = new Gtk.Image () {
gicon = new ThemedIcon ("dialog-warning-symbolic"),
pixel_size = 13
var error_button = new Gtk.Button.from_icon_name ("dialog-warning-symbolic") {
valign = Gtk.Align.CENTER,
css_classes = { "flat", "header-item-button", "dim-label" }
};

stack = new Gtk.Stack () {
transition_type = Gtk.StackTransitionType.CROSSFADE
};

stack.add_named (sync_button, "sync");
stack.add_named (error_image, "error");
stack.add_named (error_button, "error");

main_revealer = new Gtk.Revealer () {
transition_type = Gtk.RevealerTransitionType.CROSSFADE,
Expand All @@ -58,34 +58,31 @@ public class Widgets.SyncButton : Adw.Bin {
child = main_revealer;

Timeout.add (main_revealer.transition_duration, () => {
network_available ();
return GLib.Source.REMOVE;
});

sync_button.clicked.connect (() => {
clicked ();
});

Services.NetworkMonitor.instance ().network_changed.connect (() => {
network_available ();
error_button.clicked.connect (() => {
clicked ();
});
}

private void network_available () {
if (Services.NetworkMonitor.instance ().network_available) {
stack.visible_child_name = "sync";
tooltip_markup = "";
} else {
stack.visible_child_name = "error";
tooltip_markup = "<b>%s</b>\n%s".printf (_("Offline Mode Is On"), _("Looks like you'are not connected to the\ninternet. Changes you make in offline\nmode will be synced when you reconnect")); // vala-lint=line-length
}
}

public void sync_started () {
stack.visible_child_name = "sync";
tooltip_markup = "";
sync_button.add_css_class ("is_loading");
}

public void sync_finished () {
sync_button.remove_css_class ("is_loading");
}

public void sync_failed () {
sync_button.remove_css_class ("is_loading");
stack.visible_child_name = "error";
tooltip_markup = "<b>%s</b>\n%s".printf (_("Failed to connect to server"), _("It looks like the server is unreachable,\nare you connected to the internet?\nAny changes you make while disconnected\nwill be synchronized when you reconnect.")); // vala-lint=line-length
}
}
2 changes: 1 addition & 1 deletion src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ sources = files(
'Services/DBusServer.vala',
'Services/Backups.vala',
'Services/MigrateFromPlanner.vala',
'Services/NetworkMonitor.vala',

'Services/CalendarEvents/CalendarEvents.vala',
'Services/CalendarEvents/DateIterator.vala',
Expand Down Expand Up @@ -115,3 +114,4 @@ executable(
dependencies: deps,
install: true
)

Loading