fix: no more warnings

This commit is contained in:
Evangelos Paterakis 2022-12-11 02:23:29 +02:00
parent b6d9b9478d
commit aa96602543
No known key found for this signature in database
GPG Key ID: FE5185F095BFC8C9
23 changed files with 142 additions and 100 deletions

View File

@ -93,7 +93,11 @@ public class Tooth.API.Account : Entity, Widgetizable {
open ();
else {
account.resolve.begin (url, (obj, res) => {
account.resolve.end (res).open ();
try {
account.resolve.end (res).open ();
} catch (Error e) {
warning (@"Error opening account: $(account.handle) - $(e.message)");
}
});
}
}

View File

@ -7,9 +7,7 @@ public class Tooth.API.Attachment : Entity, Widgetizable {
public string? t_preview_url { get; set; }
public string? preview_url {
set { this.t_preview_url = value; }
get { return (bool.parse( this.t_preview_url )) ?
this.t_preview_url : this.url;
}
get { return (this.t_preview_url == null || this.t_preview_url == "") ? url : t_preview_url; }
}
public File? source_file { get; set; }

View File

@ -104,14 +104,18 @@ public class Tooth.Entity : GLib.Object, Widgetizable, Json.Serializable {
}
public static bool des_list (out Value val, Json.Node node, Type type) {
var arr = new Gee.ArrayList<Entity> ();
if (!node.is_null ()) {
var arr = new Gee.ArrayList<Entity> ();
node.get_array ().foreach_element ((array, i, elem) => {
var obj = Entity.from_json (type, elem);
arr.add (obj);
try {
var obj = Entity.from_json (type, elem);
arr.add (obj);
} catch (Error e) {
warning (@"Error getting Entity from json: $(e.message)");
}
});
val = arr;
}
val = arr;
return true;
}

View File

@ -19,7 +19,7 @@ public class Tooth.API.Poll : GLib.Object, Json.Serializable{
public override bool deserialize_property (string prop, out Value val, ParamSpec spec, Json.Node node) {
var success = default_deserialize_property (prop, out val, spec, node);
var type = spec.value_type;
// var type = spec.value_type;
if (prop=="options"){
return Entity.des_list (out val, node, typeof (API.PollOption));
}
@ -29,13 +29,13 @@ public class Tooth.API.Poll : GLib.Object, Json.Serializable{
return success;
}
public static bool des_list_int (out Value val, Json.Node node) {
var arr = new Gee.ArrayList<int> ();
if (!node.is_null ()) {
var arr = new Gee.ArrayList<int> ();
node.get_array ().foreach_element ((array, i, elem) => {
arr.add ((int)elem.get_int());
});
val = arr;
}
val = arr;
return true;
}
public static Poll from_json (Type type, Json.Node? node) throws Oopsie {

View File

@ -150,7 +150,7 @@ namespace Tooth {
message ("Presenting MainWindow");
if (main_window == null) {
main_window = new Dialogs.MainWindow (this);
is_rtl = main_window.get_default_direction() == Gtk.TextDirection.RTL;
is_rtl = Gtk.Widget.get_default_direction() == Gtk.TextDirection.RTL;
}
main_window.present ();
}

View File

@ -40,7 +40,9 @@ public class Tooth.EditorPage : ComposerPage {
status.spoiler_text = cw_entry.text;
}
status.visibility = (visibility_button.selected_item as InstanceAccount.Visibility).id;
var instance_visibility = (visibility_button.selected_item as InstanceAccount.Visibility);
if (visibility_button != null && visibility_button.selected_item != null && instance_visibility != null)
status.visibility = instance_visibility.id;
}
public override void on_modify_req (Request req) {

View File

@ -35,7 +35,7 @@ public class Tooth.Dialogs.MainWindow: Adw.ApplicationWindow, Saveable {
}
public Views.Base open_view (Views.Base view) {
if (last_view.label == view.label && !view.is_profile) return view;
if (last_view != null && last_view.label == view.label && !view.is_profile) return view;
if (last_view != null && !last_view.is_main && view.is_sidebar_item) {
leaflet.remove(last_view);
@ -79,23 +79,16 @@ public class Tooth.Dialogs.MainWindow: Adw.ApplicationWindow, Saveable {
// }
void on_zoom_level_changed () {
try {
var scale = settings.post_text_size;
var css = "";
if (scale > 100) {
css ="""
.%s label {
font-size: %i%;
}
""".printf (ZOOM_CLASS, scale);
}
// app.zoom_css_provider.load_from_data (css.data);
}
catch (Error e) {
warning (@"Can't set zoom level: $(e.message)");
var scale = settings.post_text_size;
var css = "";
if (scale > 100) {
css ="""
.%s label {
font-size: %i%;
}
""".printf (ZOOM_CLASS, scale);
}
// app.zoom_css_provider.load_from_data (css.data);
}
[GtkCallback]

View File

@ -65,7 +65,7 @@ public class Tooth.Dialogs.NewAccount: Adw.Window {
[GtkCallback]
bool on_activate_code_label_link (string uri) {
use_auto_auth = false;
register_client ();
register_client.begin ();
// reset();
return true;
}

View File

@ -221,24 +221,29 @@ public class Tooth.InstanceAccount : API.Account, Streamable {
public bool subscribed { get; set; }
public virtual string? get_stream_url () {
if (instance == null || access_token == null) return null;
return @"$instance/api/v1/streaming/?stream=user&access_token=$access_token";
}
public virtual void on_notification_event (Streamable.Event ev) {
var entity = create_entity<API.Notification> (ev.get_node ());
try {
var entity = create_entity<API.Notification> (ev.get_node ());
var id = int.parse (entity.id);
if (id > last_received_id) {
last_received_id = id;
var id = int.parse (entity.id);
if (id > last_received_id) {
last_received_id = id;
if (notification_inhibitors.is_empty) {
unread_count++;
has_unread = true;
send_toast (entity);
}
else {
read_notifications (last_received_id);
if (notification_inhibitors.is_empty) {
unread_count++;
has_unread = true;
send_toast (entity);
}
else {
read_notifications (last_received_id);
}
}
} catch (Error e) {
warning (@"on_notification_event: $(e.message)");
}
}

View File

@ -19,9 +19,14 @@ public class Tooth.Mastodon.Account : InstanceAccount {
public static void register (AccountStore store) {
store.backend_tests.add (new Test ());
store.create_for_backend[BACKEND].connect ((node) => {
var account = Entity.from_json (typeof (Account), node) as Account;
account.backend = BACKEND;
return account;
try {
var account = Entity.from_json (typeof (Account), node) as Account;
account.backend = BACKEND;
return account;
} catch (Error e) {
warning (@"Error creating backend: $(e.message)");
}
return null;
});
}

View File

@ -16,7 +16,11 @@ public class Tooth.EntityCache : AbstractCache {
// Entity can't be cached
if (id == null) {
entity = Entity.from_json (type, node);
try {
entity = Entity.from_json (type, node);
} catch (Error e) {
warning (@"Error getting Entity from json: $(e.message)");
}
}
else {
@ -27,7 +31,11 @@ public class Tooth.EntityCache : AbstractCache {
}
// It's a new instance and we need to store it
else {
entity = Entity.from_json (type, node);
try {
entity = Entity.from_json (type, node);
} catch (Error e) {
warning (@"Error getting Entity from json: $(e.message)");
}
insert (id, entity);
}
}

View File

@ -48,22 +48,20 @@ public class Tooth.Network : GLib.Object {
message (@"$(mess.method): $(mess.uri.to_string (false))");
try {
session.queue_message (mess, (sess, msg) => {
var status = msg.status_code;
if (status == Soup.Status.OK)
session.queue_message (mess, (sess, msg) => {
var status = msg.status_code;
if (status == Soup.Status.OK)
try {
cb (session, msg);
else if (status == Soup.Status.CANCELLED)
debug ("Message is cancelled. Ignoring callback invocation.");
else
critical (@"Should be ecb: $status $(msg.reason_phrase)");
// ecb ((int32) status, msg.reason_phrase);
});
}
catch (Error e) {
warning (@"Exception in network queue: $(e.message)");
ecb (0, e.message);
}
} catch (Error e) {
warning (@"Error in session: $(e.message)");
}
else if (status == Soup.Status.CANCELLED)
debug ("Message is cancelled. Ignoring callback invocation.");
else
critical (@"Should be ecb: $status $(msg.reason_phrase)");
// ecb ((int32) status, msg.reason_phrase);
});
}
public void on_error (int32 code, string message) {
@ -97,7 +95,11 @@ public class Tooth.Network : GLib.Object {
var parser = new Json.Parser ();
parser.load_from_data ((string) msg.response_body.flatten ().data, -1);
parser.get_root ().get_array ().foreach_element ((array, i, node) => {
cb (node, msg);
try {
cb (node, msg);
} catch (Error e) {
warning (@"Error parsing array: $(e.message)");
}
});
}

View File

@ -67,10 +67,14 @@ public class Tooth.Streams : Object {
public bool start () {
message (@"Opening stream: $name");
network.session.websocket_connect_async.begin (msg, null, null, null, (obj, res) => {
socket = network.session.websocket_connect_async.end (res);
socket.error.connect (on_error);
socket.closed.connect (on_closed);
socket.message.connect (on_message);
try {
socket = network.session.websocket_connect_async.end (res);
socket.error.connect (on_error);
socket.closed.connect (on_closed);
socket.message.connect (on_message);
} catch (Error e) {
warning (@"Error opening stream: $(e.message)");
}
});
return false;
}

View File

@ -16,13 +16,7 @@ public class Tooth.Host {
throw new Oopsie.USER (_("launch_default_for_uri() failed"));
}
catch (Error e){
try {
Gtk.show_uri(app.active_window, uri, Gdk.CURRENT_TIME);
}
catch (Error e){
warning (@"Gtk.show_uri failed too: $(e.message)");
return false;
}
Gtk.show_uri(app.active_window, uri, Gdk.CURRENT_TIME);
}
return true;
}

View File

@ -75,10 +75,12 @@ public class Tooth.Views.Base : Box {
}
public virtual void on_shown () {
app.main_window.insert_action_group ("view", actions);
if (app != null && app.main_window != null)
app.main_window.insert_action_group ("view", actions);
}
public virtual void on_hidden () {
app.main_window.insert_action_group ("view", null);
if (app != null && app.main_window != null)
app.main_window.insert_action_group ("view", null);
}
public virtual void on_content_changed () {}

View File

@ -56,7 +56,15 @@ public class Tooth.Views.ContentBase : Views.Base {
public virtual Widget on_create_model_widget (Object obj) {
return (obj as Widgetizable).to_widget ();
var obj_widgetable = obj as Widgetizable;
if (obj_widgetable == null)
Process.exit (0);
try {
return obj_widgetable.to_widget ();
} catch (Oopsie e) {
warning(@"Error on_create_model_widget: $(e.message)");
Process.exit (0);
}
}
public virtual void on_bottom_reached () {}

View File

@ -13,9 +13,14 @@ public class Tooth.Views.TabbedBase : Views.Base {
construct {
state = "content";
(states.get_parent () as Box).remove (states);
var states_box = states.get_parent () as Box;
if (states_box != null)
states_box.remove (states);
view.get_style_context ().remove_class ("ttl-view");
(scrolled.get_parent () as Box).remove (scrolled);
var scrolled_box = scrolled.get_parent () as Box;
if (scrolled_box != null)
scrolled_box.remove (scrolled);
insert_child_after (states, header);
stack = new Adw.ViewStack ();

View File

@ -88,13 +88,8 @@ public class Tooth.Views.Timeline : AccountHolder, Streamable, Views.ContentBase
.with_ctx (this)
.then ((sess, msg) => {
Network.parse_array (msg, node => {
try {
var e = entity_cache.lookup_or_insert (node, accepts);
model.append (e); //FIXME: use splice();
}
catch (Error e) {
warning (@"Timeline item parse error: $(e.message)");
}
var e = entity_cache.lookup_or_insert (node, accepts);
model.append (e); //FIXME: use splice();
});
get_pages (msg.response_headers.get_one ("Link"));
@ -150,8 +145,12 @@ public class Tooth.Views.Timeline : AccountHolder, Streamable, Views.ContentBase
}
public virtual void on_new_post (Streamable.Event ev) {
var entity = Entity.from_json (accepts, ev.get_node ());
model.insert (0, entity);
try {
var entity = Entity.from_json (accepts, ev.get_node ());
model.insert (0, entity);
} catch (Error e) {
warning (@"Error getting Entity from json: $(e.message)");
}
}
public virtual void on_delete_post (Streamable.Event ev) {

View File

@ -40,8 +40,12 @@ public class Tooth.Widgets.Attachment.Box : Adw.Bin {
}
list.@foreach (item => {
var widget = item.to_widget ();
box.insert (widget, -1);
try {
var widget = item.to_widget ();
box.insert (widget, -1);
} catch (Oopsie e) {
warning(@"Error updating attachements: $(e.message)");
}
return true;
});

View File

@ -16,6 +16,8 @@ public class Tooth.Widgets.Emoji : Adw.Bin {
}
void on_cache_response (bool is_loaded, owned Paintable? data) {
(child as Image).paintable = data;
var image_widget = (child as Image);
if (child != null && image_widget != null)
image_widget.paintable = data;
}
}

View File

@ -42,9 +42,9 @@ public class Tooth.Widgets.RelationshipButton : Button {
// icon_name = "changes-allow-symbolic";
fn = () => {
if (rs.domain_blocking)
activate_action ("domain_blocking", null);
activate_action ("domain_blocking", "");
else if (rs.blocking)
activate_action ("view.blocking", null);
activate_action ("view.blocking", "");
return true;
};
add_css_class ("destructive-action");

View File

@ -330,7 +330,10 @@ public class Tooth.Widgets.Status : ListBoxRow {
content.selectable = true;
content.get_style_context ().add_class ("ttl-large-body");
var mgr = (content_column.get_parent () as Grid).get_layout_manager ();
var content_grid = content_column.get_parent () as Grid;
if (content_grid == null)
return;
var mgr = content_grid.get_layout_manager ();
var child = mgr.get_layout_child (content_column);
child.set_property ("column", 0);
child.set_property ("column_span", 2);
@ -357,7 +360,7 @@ public class Tooth.Widgets.Status : ListBoxRow {
prev.thread_role = START;
curr.thread_role = END;
break;
case END:
default:
prev.thread_role = MIDDLE;
curr.thread_role = END;
break;

View File

@ -4,11 +4,11 @@ using Gee;
[GtkTemplate (ui = "/dev/geopjr/tooth/ui/widgets/votebox.ui")]
public class Tooth.Widgets.VoteBox: Box {
[GtkChild] protected ListBox pollBox;
[GtkChild] protected Button button_vote;
[GtkChild] protected Box pollActionBox;
[GtkChild] protected Label people_label;
[GtkChild] protected Label expires_label;
[GtkChild] protected unowned ListBox pollBox;
[GtkChild] protected unowned Button button_vote;
[GtkChild] protected unowned Box pollActionBox;
[GtkChild] protected unowned Label people_label;
[GtkChild] protected unowned Label expires_label;
public API.Poll? poll { get; set;}
public API.Status? status_parent{ get; set;}