2018-04-14 14:09:06 +02:00
|
|
|
using Gtk;
|
|
|
|
using Granite;
|
|
|
|
|
2018-10-23 12:05:24 +02:00
|
|
|
namespace Tootle {
|
2018-04-14 14:09:06 +02:00
|
|
|
|
|
|
|
public static Application app;
|
2018-05-03 10:56:04 +02:00
|
|
|
public static MainWindow? window;
|
2018-05-08 18:09:38 +02:00
|
|
|
public static Window window_dummy;
|
2018-04-27 20:50:08 +02:00
|
|
|
|
2018-06-17 09:48:18 +02:00
|
|
|
public static Settings settings;
|
|
|
|
public static Accounts accounts;
|
|
|
|
public static Network network;
|
2018-05-24 21:52:59 +02:00
|
|
|
public static ImageCache image_cache;
|
2018-07-14 10:37:41 +02:00
|
|
|
public static Watchlist watchlist;
|
2018-04-14 14:09:06 +02:00
|
|
|
|
2018-10-27 10:55:40 +02:00
|
|
|
public static bool start_hidden = false;
|
|
|
|
|
2018-04-14 14:09:06 +02:00
|
|
|
public class Application : Granite.Application {
|
|
|
|
|
2018-05-05 17:38:01 +02:00
|
|
|
public abstract signal void refresh ();
|
|
|
|
public abstract signal void toast (string title);
|
|
|
|
public abstract signal void error (string title, string text);
|
2018-08-27 03:45:25 +02:00
|
|
|
|
2018-10-27 10:55:40 +02:00
|
|
|
public const GLib.OptionEntry[] app_options = {
|
|
|
|
{ "hidden", 0, 0, OptionArg.NONE, ref start_hidden, "Do not show main window on start", null },
|
|
|
|
{ null }
|
|
|
|
};
|
|
|
|
|
|
|
|
public const GLib.ActionEntry[] app_entries = {
|
2018-08-27 03:45:25 +02:00
|
|
|
{"compose-toot", compose_toot_activated },
|
|
|
|
{"back", back_activated },
|
|
|
|
{"refresh", refresh_activated },
|
|
|
|
{"switch-timeline", switch_timeline_activated, "i" }
|
|
|
|
};
|
2018-04-14 14:09:06 +02:00
|
|
|
|
|
|
|
construct {
|
|
|
|
application_id = "com.github.bleakgrey.tootle";
|
|
|
|
flags = ApplicationFlags.FLAGS_NONE;
|
2018-05-03 10:56:04 +02:00
|
|
|
program_name = "Tootle";
|
2018-10-31 13:36:56 +01:00
|
|
|
build_version = "0.2.0";
|
2018-04-14 14:09:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public static int main (string[] args) {
|
2018-05-03 10:56:04 +02:00
|
|
|
Gtk.init (ref args);
|
2018-10-27 10:55:40 +02:00
|
|
|
|
|
|
|
try {
|
|
|
|
var opt_context = new OptionContext ("- Options");
|
|
|
|
opt_context.add_main_entries (app_options, null);
|
|
|
|
opt_context.parse (ref args);
|
|
|
|
}
|
|
|
|
catch (GLib.OptionError e) {
|
|
|
|
warning (e.message);
|
|
|
|
}
|
|
|
|
|
2018-04-14 14:09:06 +02:00
|
|
|
app = new Application ();
|
2018-05-31 14:13:21 +02:00
|
|
|
return app.run (args);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void startup () {
|
|
|
|
base.startup ();
|
2018-06-19 12:51:04 +02:00
|
|
|
Granite.Services.Logger.DisplayLevel = Granite.Services.LogLevel.INFO;
|
2018-05-08 18:09:38 +02:00
|
|
|
|
2018-06-17 09:48:18 +02:00
|
|
|
settings = new Settings ();
|
|
|
|
accounts = new Accounts ();
|
|
|
|
network = new Network ();
|
2018-05-24 21:52:59 +02:00
|
|
|
image_cache = new ImageCache ();
|
2018-07-14 10:37:41 +02:00
|
|
|
watchlist = new Watchlist ();
|
2018-05-27 18:25:16 +02:00
|
|
|
accounts.init ();
|
2018-07-14 10:37:41 +02:00
|
|
|
|
2018-05-27 18:25:16 +02:00
|
|
|
app.error.connect (app.on_error);
|
2018-05-08 18:09:38 +02:00
|
|
|
|
|
|
|
window_dummy = new Window ();
|
|
|
|
add_window (window_dummy);
|
2018-08-27 03:45:25 +02:00
|
|
|
|
2018-10-23 12:22:43 +02:00
|
|
|
set_accels_for_action ("app.compose-toot", {"<Ctrl>T"});
|
|
|
|
set_accels_for_action ("app.back", {"<Alt>BackSpace", "<Alt>Left"});
|
|
|
|
set_accels_for_action ("app.refresh", {"<Ctrl>R", "F5"});
|
|
|
|
set_accels_for_action ("app.switch-timeline(0)", {"<Alt>1"});
|
|
|
|
set_accels_for_action ("app.switch-timeline(1)", {"<Alt>2"});
|
|
|
|
set_accels_for_action ("app.switch-timeline(2)", {"<Alt>3"});
|
|
|
|
set_accels_for_action ("app.switch-timeline(3)", {"<Alt>4"});
|
|
|
|
add_action_entries (app_entries, this);
|
2018-04-14 14:09:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
protected override void activate () {
|
2018-10-27 10:55:40 +02:00
|
|
|
if (window != null) {
|
|
|
|
window.present ();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (start_hidden) {
|
|
|
|
start_hidden = false;
|
2018-05-31 14:13:21 +02:00
|
|
|
return;
|
2018-10-27 10:55:40 +02:00
|
|
|
}
|
2018-05-31 14:13:21 +02:00
|
|
|
|
|
|
|
debug ("Creating new window");
|
|
|
|
if (accounts.is_empty ())
|
|
|
|
NewAccountDialog.open ();
|
2018-05-03 10:56:04 +02:00
|
|
|
else {
|
2018-05-31 14:13:21 +02:00
|
|
|
window = new MainWindow (this);
|
|
|
|
window.present ();
|
2018-05-03 10:56:04 +02:00
|
|
|
}
|
2018-04-14 14:09:06 +02:00
|
|
|
}
|
2018-05-27 18:25:16 +02:00
|
|
|
|
|
|
|
protected void on_error (string title, string msg){
|
|
|
|
var message_dialog = new Granite.MessageDialog.with_image_from_icon_name (title, msg, "dialog-warning");
|
|
|
|
message_dialog.transient_for = window;
|
|
|
|
message_dialog.run ();
|
|
|
|
message_dialog.destroy ();
|
|
|
|
}
|
2018-08-27 03:45:25 +02:00
|
|
|
|
|
|
|
private void compose_toot_activated () {
|
|
|
|
PostDialog.open ();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void back_activated () {
|
|
|
|
window.back ();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void refresh_activated () {
|
|
|
|
refresh ();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void switch_timeline_activated (SimpleAction a, Variant? parameter) {
|
|
|
|
int32 timeline_no = parameter.get_int32 ();
|
|
|
|
window.switch_timeline (timeline_no);
|
|
|
|
}
|
2018-04-14 14:09:06 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|