2013-04-12 12:31:58 -07:00
|
|
|
/* Copyright 2011-2013 Yorba Foundation
|
2011-05-24 19:40:06 -07:00
|
|
|
*
|
|
|
|
|
* This software is licensed under the GNU Lesser General Public License
|
2013-04-12 12:31:58 -07:00
|
|
|
* (version 2.1 or later). See the COPYING file in this distribution.
|
2011-05-24 19:40:06 -07:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
public class MainWindow : Gtk.Window {
|
2011-10-04 18:24:13 -07:00
|
|
|
private const int MESSAGE_LIST_WIDTH = 250;
|
2012-02-01 12:32:07 -08:00
|
|
|
private const int FOLDER_LIST_WIDTH = 100;
|
2011-09-21 18:03:41 -07:00
|
|
|
|
2013-02-14 16:01:51 -08:00
|
|
|
public FolderList.Tree folder_list { get; private set; default = new FolderList.Tree(); }
|
2012-09-07 20:01:12 -07:00
|
|
|
public ConversationListStore conversation_list_store { get; private set; default = new ConversationListStore(); }
|
2011-11-22 18:55:07 -08:00
|
|
|
public MainToolbar main_toolbar { get; private set; }
|
2012-09-07 20:01:12 -07:00
|
|
|
public ConversationListView conversation_list_view { get; private set; }
|
|
|
|
|
public ConversationViewer conversation_viewer { get; private set; default = new ConversationViewer(); }
|
2011-11-16 18:14:17 -08:00
|
|
|
|
2012-11-07 19:05:38 -08:00
|
|
|
public int window_width { get; set; }
|
|
|
|
|
public int window_height { get; set; }
|
|
|
|
|
public bool window_maximized { get; set; }
|
2012-09-24 16:31:31 -07:00
|
|
|
|
2012-07-12 11:52:14 -07:00
|
|
|
private Gtk.Paned folder_paned = new Gtk.Paned(Gtk.Orientation.HORIZONTAL);
|
2012-09-07 20:01:12 -07:00
|
|
|
private Gtk.Paned conversations_paned = new Gtk.Paned(Gtk.Orientation.HORIZONTAL);
|
2013-03-12 15:18:12 -07:00
|
|
|
|
|
|
|
|
private Gtk.ScrolledWindow conversation_list_scrolled;
|
2011-11-30 15:37:16 -08:00
|
|
|
private Gtk.Spinner spinner = new Gtk.Spinner();
|
2011-05-24 19:40:06 -07:00
|
|
|
|
|
|
|
|
public MainWindow() {
|
2011-06-10 19:17:35 -07:00
|
|
|
title = GearyApplication.NAME;
|
2011-05-24 19:40:06 -07:00
|
|
|
|
2012-09-07 20:01:12 -07:00
|
|
|
conversation_list_view = new ConversationListView(conversation_list_store);
|
2011-05-27 17:19:24 -07:00
|
|
|
|
2012-11-07 19:05:38 -08:00
|
|
|
// This code both loads AND saves the pane positions with live
|
|
|
|
|
// updating. This is more resilient against crashes because
|
|
|
|
|
// the value in dconf changes *immediately*, and stays saved
|
|
|
|
|
// in the event of a crash.
|
|
|
|
|
Configuration config = GearyApplication.instance.config;
|
|
|
|
|
config.bind(Configuration.FOLDER_LIST_PANE_POSITION_NAME, folder_paned, "position");
|
|
|
|
|
config.bind(Configuration.MESSAGES_PANE_POSITION_NAME, conversations_paned, "position");
|
|
|
|
|
config.bind(Configuration.WINDOW_WIDTH_NAME, this, "window-width");
|
|
|
|
|
config.bind(Configuration.WINDOW_HEIGHT_NAME, this, "window-height");
|
|
|
|
|
config.bind(Configuration.WINDOW_MAXIMIZE_NAME, this, "window-maximized");
|
|
|
|
|
|
2011-10-11 19:12:20 -07:00
|
|
|
add_accel_group(GearyApplication.instance.ui_manager.get_accel_group());
|
|
|
|
|
|
2012-02-10 11:33:54 -08:00
|
|
|
GLib.List<Gdk.Pixbuf> pixbuf_list = new GLib.List<Gdk.Pixbuf>();
|
2012-09-03 12:48:48 -07:00
|
|
|
pixbuf_list.append(IconFactory.instance.application_icon);
|
2012-02-10 11:33:54 -08:00
|
|
|
set_default_icon_list(pixbuf_list);
|
|
|
|
|
|
2012-05-22 14:04:24 -07:00
|
|
|
delete_event.connect(on_delete_event);
|
|
|
|
|
|
2011-05-24 19:40:06 -07:00
|
|
|
create_layout();
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-14 17:38:53 -07:00
|
|
|
public override void show_all() {
|
|
|
|
|
set_default_size(GearyApplication.instance.config.window_width,
|
|
|
|
|
GearyApplication.instance.config.window_height);
|
|
|
|
|
if (GearyApplication.instance.config.window_maximize)
|
|
|
|
|
maximize();
|
|
|
|
|
|
|
|
|
|
base.show_all();
|
2012-05-22 14:04:24 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool on_delete_event() {
|
2011-05-24 19:40:06 -07:00
|
|
|
GearyApplication.instance.exit();
|
|
|
|
|
|
2012-05-22 14:04:24 -07:00
|
|
|
return true;
|
2011-05-24 19:40:06 -07:00
|
|
|
}
|
|
|
|
|
|
2011-09-14 17:38:53 -07:00
|
|
|
public override bool configure_event(Gdk.EventConfigure event) {
|
|
|
|
|
// Get window dimensions.
|
2011-09-22 13:11:35 -07:00
|
|
|
window_maximized = (get_window().get_state() == Gdk.WindowState.MAXIMIZED);
|
2012-11-07 19:05:38 -08:00
|
|
|
if (!window_maximized) {
|
|
|
|
|
int width, height;
|
|
|
|
|
get_size(out width, out height);
|
|
|
|
|
|
|
|
|
|
// can't use properties as out variables
|
|
|
|
|
window_width = width;
|
|
|
|
|
window_height = height;
|
|
|
|
|
}
|
2011-09-14 17:38:53 -07:00
|
|
|
|
|
|
|
|
return base.configure_event(event);
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-30 15:37:16 -08:00
|
|
|
// Displays or stops displaying busy spinner.
|
|
|
|
|
public void set_busy(bool is_busy) {
|
|
|
|
|
if (is_busy) {
|
|
|
|
|
spinner.start();
|
|
|
|
|
spinner.show();
|
|
|
|
|
} else {
|
|
|
|
|
spinner.stop();
|
|
|
|
|
spinner.hide();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-24 19:40:06 -07:00
|
|
|
private void create_layout() {
|
2012-01-27 15:00:24 -08:00
|
|
|
Gtk.Box main_layout = new Gtk.Box(Gtk.Orientation.VERTICAL, 0);
|
2011-05-26 18:26:36 -07:00
|
|
|
|
2011-10-11 19:12:20 -07:00
|
|
|
// Toolbar.
|
|
|
|
|
main_toolbar = new MainToolbar();
|
|
|
|
|
main_layout.pack_start(main_toolbar, false, false, 0);
|
2011-05-26 18:26:36 -07:00
|
|
|
|
2011-05-27 17:19:24 -07:00
|
|
|
// folder list
|
|
|
|
|
Gtk.ScrolledWindow folder_list_scrolled = new Gtk.ScrolledWindow(null, null);
|
2012-02-01 12:32:07 -08:00
|
|
|
folder_list_scrolled.set_size_request(FOLDER_LIST_WIDTH, -1);
|
2011-05-27 17:19:24 -07:00
|
|
|
folder_list_scrolled.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC);
|
2012-02-01 12:32:07 -08:00
|
|
|
folder_list_scrolled.add(folder_list);
|
2011-05-27 17:19:24 -07:00
|
|
|
|
2011-05-26 18:26:36 -07:00
|
|
|
// message list
|
2013-03-12 15:18:12 -07:00
|
|
|
conversation_list_scrolled = new Gtk.ScrolledWindow(null, null);
|
2012-09-07 20:01:12 -07:00
|
|
|
conversation_list_scrolled.set_size_request(MESSAGE_LIST_WIDTH, -1);
|
|
|
|
|
conversation_list_scrolled.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
|
|
|
|
|
conversation_list_scrolled.add(conversation_list_view);
|
2011-05-27 17:19:24 -07:00
|
|
|
|
2012-05-18 13:02:19 -07:00
|
|
|
// Three-pane display.
|
2011-11-30 15:37:16 -08:00
|
|
|
Gtk.Box status_bar_box = new Gtk.Box(Gtk.Orientation.VERTICAL, 0);
|
|
|
|
|
Gtk.Statusbar status_bar = new Gtk.Statusbar();
|
|
|
|
|
status_bar.add(spinner);
|
2012-05-18 13:02:19 -07:00
|
|
|
status_bar_box.pack_start(folder_list_scrolled);
|
2011-11-30 15:37:16 -08:00
|
|
|
status_bar_box.pack_start(status_bar, false, false, 0);
|
2012-09-24 16:31:31 -07:00
|
|
|
|
|
|
|
|
#if !HAVE_LIBGRANITE
|
|
|
|
|
folder_paned.get_style_context().add_class("sidebar-pane-separator");
|
|
|
|
|
#endif
|
2011-11-30 15:37:16 -08:00
|
|
|
|
2012-05-18 13:02:19 -07:00
|
|
|
// Message list left of message viewer.
|
2012-09-07 20:01:12 -07:00
|
|
|
conversations_paned.pack1(conversation_list_scrolled, false, false);
|
2013-01-08 18:37:38 -08:00
|
|
|
conversations_paned.pack2(conversation_viewer, true, true);
|
2011-06-02 17:57:04 -07:00
|
|
|
|
2012-05-18 13:02:19 -07:00
|
|
|
// Folder list to the left of everything.
|
|
|
|
|
folder_paned.pack1(status_bar_box, false, false);
|
2012-09-07 20:01:12 -07:00
|
|
|
folder_paned.pack2(conversations_paned, true, false);
|
2012-05-18 13:02:19 -07:00
|
|
|
|
|
|
|
|
main_layout.pack_end(folder_paned, true, true, 0);
|
2011-05-24 19:40:06 -07:00
|
|
|
|
2011-05-26 18:26:36 -07:00
|
|
|
add(main_layout);
|
|
|
|
|
}
|
2013-03-12 15:18:12 -07:00
|
|
|
|
|
|
|
|
// Returns true when there's a conversation list scrollbar visible, i.e. the list is tall
|
|
|
|
|
// enough to need one. Otherwise returns false.
|
|
|
|
|
public bool conversation_list_has_scrollbar() {
|
|
|
|
|
Gtk.Scrollbar? scrollbar = conversation_list_scrolled.get_vscrollbar() as Gtk.Scrollbar;
|
|
|
|
|
return scrollbar != null && scrollbar.get_visible();
|
|
|
|
|
}
|
2011-05-24 19:40:06 -07:00
|
|
|
}
|
|
|
|
|
|