2018-04-14 14:09:06 +02:00
|
|
|
using Gtk;
|
|
|
|
|
|
|
|
public class Tootle.MainWindow: Gtk.Window {
|
|
|
|
|
|
|
|
HeaderBar header;
|
2018-04-19 20:38:30 +02:00
|
|
|
Stack primary_stack;
|
|
|
|
Stack secondary_stack;
|
2018-04-20 13:21:51 +02:00
|
|
|
AccountsButton button_accounts;
|
2018-04-19 20:38:30 +02:00
|
|
|
Granite.Widgets.ModeButton button_mode;
|
2018-04-14 14:09:06 +02:00
|
|
|
Spinner spinner;
|
|
|
|
Button button_toot;
|
2018-04-19 20:38:30 +02:00
|
|
|
Button button_back;
|
2018-04-14 14:09:06 +02:00
|
|
|
|
2018-04-15 14:28:23 +02:00
|
|
|
public HomeView home = new HomeView ();
|
|
|
|
public LocalView feed_local = new LocalView ();
|
2018-04-17 14:01:55 +02:00
|
|
|
public FederatedView feed_federated = new FederatedView ();
|
|
|
|
public NotificationsView notifications = new NotificationsView ();
|
2018-04-14 14:09:06 +02:00
|
|
|
|
|
|
|
public MainWindow (Gtk.Application application) {
|
|
|
|
Object (application: application,
|
|
|
|
icon_name: "com.github.bleakgrey.tootle",
|
|
|
|
title: "Tootle",
|
|
|
|
resizable: true
|
|
|
|
);
|
|
|
|
set_titlebar (header);
|
|
|
|
window_position = WindowPosition.CENTER;
|
|
|
|
|
2018-04-14 19:53:09 +02:00
|
|
|
AccountManager.instance.changed_current.connect(on_account_changed);
|
2018-04-14 14:09:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
construct {
|
|
|
|
var provider = new Gtk.CssProvider ();
|
|
|
|
provider.load_from_resource ("/com/github/bleakgrey/tootle/Application.css");
|
|
|
|
StyleContext.add_provider_for_screen (Gdk.Screen.get_default (), provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
|
|
|
|
|
2018-04-19 20:38:30 +02:00
|
|
|
secondary_stack = new Stack();
|
|
|
|
secondary_stack.transition_type = Gtk.StackTransitionType.SLIDE_LEFT_RIGHT;
|
|
|
|
secondary_stack.show ();
|
|
|
|
secondary_stack.set_size_request (400, 500);
|
|
|
|
primary_stack = new Stack();
|
|
|
|
primary_stack.transition_type = Gtk.StackTransitionType.SLIDE_LEFT_RIGHT;
|
|
|
|
primary_stack.show ();
|
|
|
|
primary_stack.add_named (secondary_stack, "modes");
|
2018-04-14 14:09:06 +02:00
|
|
|
|
|
|
|
spinner = new Spinner ();
|
|
|
|
spinner.active = true;
|
|
|
|
|
2018-04-20 13:21:51 +02:00
|
|
|
button_accounts = new AccountsButton ();
|
2018-04-14 14:09:06 +02:00
|
|
|
|
2018-04-19 20:38:30 +02:00
|
|
|
button_back = new Button ();
|
2018-04-19 21:03:28 +02:00
|
|
|
button_back.label = _("Back");
|
2018-04-19 20:38:30 +02:00
|
|
|
button_back.get_style_context ().add_class (Granite.STYLE_CLASS_BACK_BUTTON);
|
2018-04-19 21:03:28 +02:00
|
|
|
button_back.clicked.connect (() => {
|
|
|
|
primary_stack.set_visible_child_name ("modes");
|
|
|
|
var child = primary_stack.get_child_by_name ("details");
|
|
|
|
child.destroy ();
|
2018-04-20 13:21:51 +02:00
|
|
|
update_header (true);
|
2018-04-19 21:03:28 +02:00
|
|
|
});
|
2018-04-19 20:38:30 +02:00
|
|
|
|
2018-04-14 14:09:06 +02:00
|
|
|
button_toot = new Button ();
|
|
|
|
button_toot.tooltip_text = "Toot";
|
|
|
|
button_toot.image = new Gtk.Image.from_icon_name ("edit-symbolic", Gtk.IconSize.LARGE_TOOLBAR);
|
|
|
|
button_toot.clicked.connect (() => {
|
2018-04-19 21:03:28 +02:00
|
|
|
PostDialog.open (this);
|
2018-04-14 14:09:06 +02:00
|
|
|
});
|
|
|
|
|
2018-04-19 20:38:30 +02:00
|
|
|
button_mode = new Granite.Widgets.ModeButton ();
|
|
|
|
button_mode.get_style_context ().add_class ("mode");
|
|
|
|
button_mode.mode_changed.connect(widget => {
|
|
|
|
secondary_stack.set_visible_child_name(widget.tooltip_text);
|
2018-04-14 14:09:06 +02:00
|
|
|
});
|
2018-04-20 13:21:51 +02:00
|
|
|
button_mode.show ();
|
2018-04-14 14:09:06 +02:00
|
|
|
|
|
|
|
header = new HeaderBar ();
|
2018-04-19 20:38:30 +02:00
|
|
|
header.custom_title = button_mode;
|
2018-04-14 14:09:06 +02:00
|
|
|
header.show_close_button = true;
|
2018-04-19 21:03:28 +02:00
|
|
|
header.pack_start (button_back);
|
2018-04-14 14:09:06 +02:00
|
|
|
header.pack_start (button_toot);
|
2018-04-20 13:21:51 +02:00
|
|
|
header.pack_end (button_accounts);
|
2018-04-14 14:09:06 +02:00
|
|
|
header.pack_end (spinner);
|
2018-04-19 20:38:30 +02:00
|
|
|
button_mode.valign = Gtk.Align.FILL;
|
2018-04-14 14:09:06 +02:00
|
|
|
header.show ();
|
|
|
|
|
2018-04-19 20:38:30 +02:00
|
|
|
add (primary_stack);
|
2018-04-14 14:09:06 +02:00
|
|
|
show_all ();
|
|
|
|
|
|
|
|
NetManager.instance.started.connect (() => spinner.show ());
|
|
|
|
NetManager.instance.finished.connect (() => spinner.hide ());
|
|
|
|
}
|
|
|
|
|
2018-04-14 19:53:09 +02:00
|
|
|
private void on_account_changed(Account? account){
|
2018-04-19 20:38:30 +02:00
|
|
|
secondary_stack.forall (widget => secondary_stack.remove (widget));
|
2018-04-14 14:09:06 +02:00
|
|
|
|
2018-04-14 19:53:09 +02:00
|
|
|
if(account == null)
|
2018-04-14 14:09:06 +02:00
|
|
|
show_setup_views ();
|
|
|
|
else
|
|
|
|
show_main_views ();
|
|
|
|
}
|
|
|
|
|
2018-04-20 13:21:51 +02:00
|
|
|
private void update_header (bool primary_mode, bool hide_all = false){
|
|
|
|
if (hide_all){
|
|
|
|
button_mode.opacity = 0;
|
|
|
|
button_mode.sensitive = false;
|
|
|
|
button_toot.hide ();
|
|
|
|
button_back.hide ();
|
|
|
|
button_accounts.hide ();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
button_mode.opacity = primary_mode ? 1 : 0;
|
|
|
|
button_mode.sensitive = primary_mode ? true : false;
|
|
|
|
button_toot.set_visible (primary_mode);
|
|
|
|
button_back.set_visible (!primary_mode);
|
|
|
|
button_accounts.set_visible (true);
|
|
|
|
}
|
|
|
|
|
2018-04-14 14:09:06 +02:00
|
|
|
private void show_setup_views (){
|
|
|
|
var add_account = new AddAccountView ();
|
2018-04-19 20:38:30 +02:00
|
|
|
secondary_stack.add_named (add_account, add_account.get_name ());
|
2018-04-20 13:21:51 +02:00
|
|
|
update_header (false, true);
|
2018-04-14 14:09:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private void show_main_views (){
|
2018-04-19 20:38:30 +02:00
|
|
|
button_mode.clear_children ();
|
2018-04-14 14:09:06 +02:00
|
|
|
add_view (home);
|
2018-04-17 19:28:07 +02:00
|
|
|
add_view (notifications);
|
2018-04-14 14:09:06 +02:00
|
|
|
add_view (feed_local);
|
|
|
|
add_view (feed_federated);
|
2018-04-19 20:38:30 +02:00
|
|
|
button_mode.set_active (0);
|
2018-04-20 13:21:51 +02:00
|
|
|
update_header (true);
|
2018-04-14 14:09:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private void add_view (AbstractView view) {
|
|
|
|
if (view.show_in_header){
|
2018-04-17 14:01:55 +02:00
|
|
|
var img = new Gtk.Image.from_icon_name(view.get_icon (), Gtk.IconSize.LARGE_TOOLBAR);
|
|
|
|
img.tooltip_text = view.get_name ();
|
2018-04-19 20:38:30 +02:00
|
|
|
button_mode.append (img);
|
2018-04-17 14:01:55 +02:00
|
|
|
view.image = img;
|
2018-04-19 20:38:30 +02:00
|
|
|
secondary_stack.add_named(view, view.get_name ());
|
2018-04-14 14:09:06 +02:00
|
|
|
}
|
|
|
|
}
|
2018-04-19 21:03:28 +02:00
|
|
|
|
|
|
|
public void open_secondary_view (Widget widget) {
|
|
|
|
widget.show ();
|
|
|
|
primary_stack.add_named (widget, "details");
|
|
|
|
primary_stack.set_visible_child_name ("details");
|
2018-04-20 13:21:51 +02:00
|
|
|
update_header (false);
|
2018-04-19 21:03:28 +02:00
|
|
|
}
|
2018-04-14 14:09:06 +02:00
|
|
|
|
|
|
|
}
|