Update copyright information
[debian/pino.git] / src / main_window.vala
1 using Gtk;
2 using Gee;
3
4 public class MainWindow : Window {
5         
6         private Accounts accounts;
7
8         //GUI
9         private Widget menubar;
10         public MenuIndicator indicator;
11         private TreeWidget tree;
12         //private ContentView content_view;
13         private ViewArea view_area;
14         private StatusBox status_box;
15         //private VisualStyle visual_style;
16         private VPaned vpaned;
17         private HPaned hpaned;
18         
19         public MainWindow() {
20                 set_size_request(550, 600);
21                 accounts = new Accounts();
22                 
23                 tree = new TreeWidget(this, accounts);
24                 
25                 menu_setup();
26                 
27                 indicator = new MenuIndicator(this);
28                 
29                 accounts.message_indicate.connect((msg) => {
30                         indicator.add_queue(msg);
31                 });
32                 accounts.stop_indicate.connect(() => {
33                         indicator.hide_queue();
34                 });
35                 
36                 ((MenuBar) menubar).append(indicator);
37                 
38                 var vbox = new VBox(false, 0);
39                 vbox.pack_start(tree.frame, true, true, 0);
40                 
41                 var treebox = new HBox(false, 0);
42                 treebox.pack_start(vbox, true, true, 0);
43                 
44                 visual_style = new VisualStyle(this);
45                 
46                 //content_view = new ContentView(accounts, visual_style);
47                 view_area = new ViewArea(accounts);
48                 
49                 HBox webbox = new HBox(false, 0);
50                 //webbox.pack_start(content_view.frame, true, true, 0);
51                 webbox.pack_start(view_area, true, true, 0);
52                 
53                 status_box = new StatusBox(this, accounts);
54                 
55                 HBox statbox = new HBox(false, 0);
56                 statbox.pack_start(status_box.vbox, true, true, 0);
57                 
58                 vpaned = new VPaned();
59                 vpaned.add1(webbox);
60                 vpaned.add2(statbox);
61                 vpaned.set_position(settings.vpaned_position);
62                 vpaned.notify["position"].connect((s) => {
63                         settings.vpaned_position = vpaned.get_position();
64                 });
65                 
66                 hpaned = new HPaned();
67                 hpaned.add1(treebox);
68                 hpaned.add2(vpaned);
69                 hpaned.set_position(settings.hpaned_position);
70                 hpaned.notify["position"].connect((s) => {
71                         settings.hpaned_position = hpaned.get_position();
72                 });
73                 
74                 VBox main_box = new VBox(false, 0);
75                 main_box.pack_start(menubar, false, false, 0);
76                 main_box.pack_start(hpaned, true, true, 0);
77                 
78                 add(main_box);
79                 show_all();
80                 
81                 //hide some widgets
82                 indicator.hide();
83                 view_area.generate_views();
84                 
85                 signals_setup();
86                 
87                 tree.set_current(settings.current_item);
88         }
89         
90         private void menu_setup() {
91                 ActionGroup act_group = new ActionGroup("main");
92                 
93                 Action file_menu = new Action("FileMenu", "Pino", null, null);
94                 Action edit_menu = new Action("EditMenu", "Edit", null, null);
95                 Action view_menu = new Action("ViewMenu", "View", null, null);
96                 Action help_menu = new Action("HelpMenu", "Help", null, null);
97                 
98                 Action create_account_act = new Action("CreateAccount", _("New account"),
99                         _("Create new account"), null);
100                 
101                 //setup all account types
102                 string accounts_string = "";
103                 foreach(Type t in accounts_types.keys) {
104                         Action acc_act = new Action(t.name(), accounts_types.get(t).name,
105                                 accounts_types.get(t).description, null);
106                         
107                         try {
108                                 acc_act.set_gicon(Icon.new_for_string(accounts_types.get(t).icon_name));
109                         } catch(GLib.Error e) {
110                                 debug(e.message);
111                         }
112                         
113                         acc_act.activate.connect(() => { //create new account
114                                 accounts.add_account(t, this);
115                         });
116                         
117                         act_group.add_action(acc_act);
118                         
119                         accounts_string += "<menuitem action=\"%s\" />\n".printf(t.name());
120                 }
121                 
122                 act_group.add_action(file_menu);
123                 act_group.add_action(edit_menu);
124                 act_group.add_action(view_menu);
125                 act_group.add_action(help_menu);
126                 
127                 act_group.add_action(create_account_act);
128                 
129                 UIManager ui = new UIManager();
130                 ui.insert_action_group(act_group, 0);
131                 add_accel_group(ui.get_accel_group());
132                 
133                 var ui_string = """
134                 <ui>
135                         <menubar name="MenuBar">
136                                 <menu action="FileMenu">
137                                 </menu>
138                                 <menu action="EditMenu">
139                                         <menu action="CreateAccount">
140                                                 %s
141                                         </menu>
142                                 </menu>
143                                 <menu action="ViewMenu">
144                                 </menu>
145                                 <menu action="HelpMenu">
146                                 </menu>
147                         </menubar>
148                 </ui>
149                 """.printf(accounts_string);
150                 
151                 try {
152                         ui.add_ui_from_string(ui_string, ui_string.length);
153                 } catch(GLib.Error e) {
154                         debug(e.message); //TODO
155                 }
156                 
157                 menubar = ui.get_widget("/MenuBar");
158         }
159         
160         private void signals_setup() {
161                 destroy.connect(() => {
162                         accounts.sync();
163                         
164                         settings.current_item = tree.current_tree_path.to_string();
165                         
166                         settings.sync();
167                         main_quit();
168                 });
169                 
170                 tree.cursor_moved.connect((stream) => {
171                         //content_view.set_current_list(hash);
172                         view_area.set_current_view(stream);
173                 });
174         }
175 }