2 * app_wm - zavai window management functions
4 * Copyright (C) 2009 Enrico Zini <enrico@enricozini.org>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 protected class PolygenPage : Object
29 public string name { get; construct; }
30 public Gtk.ListStore model;
31 public Gtk.TreeView list;
32 public Gtk.ScrolledWindow scroll;
33 public signal void selected(string page, string name);
35 public PolygenPage(string name)
38 model = new Gtk.ListStore(2, typeof(string), typeof(string));
39 list = new Gtk.TreeView.with_model(model);
40 list.insert_column_with_attributes (-1, "Name", new Gtk.CellRendererText(), "text", 0);
41 list.insert_column_with_attributes (-1, "Title", new Gtk.CellRendererText(), "text", 1);
42 scroll = new Gtk.ScrolledWindow (null, null);
43 scroll.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC);
46 list.row_activated += on_row_activated;
49 private void on_row_activated(Gtk.TreeView tv, Gtk.TreePath path, Gtk.TreeViewColumn column)
52 if (!model.get_iter(out iter, path)) return;
54 model.get_value(iter, 0, out grm_name);
55 selected(name, (string)grm_name);
59 protected class PolygenRun : Gtk.VBox
61 protected Gtk.Label text;
62 protected Gtk.Button text_button;
64 private string _grammar;
65 public string grammar {
66 get { return _grammar; }
76 text = new Gtk.Label("");
77 text.use_markup = true;
79 text_button = new Gtk.Button();
80 text_button.set_image(text);
81 pack_start(text_button, true, true, 0);
82 text_button.clicked += on_clicked;
85 public void on_clicked(Gtk.Button button) { update(); }
89 text.label = "ciao " + _grammar;
93 public class Polygen : Applet
95 protected Gee.ArrayList<PolygenPage> pages;
96 protected Gtk.Notebook notebook;
97 protected PolygenRun result;
99 private void add(string page, string name, string title)
101 PolygenPage pg = null;
102 foreach (PolygenPage p in pages)
112 pg = new PolygenPage(page);
113 pg.selected += on_selected;
118 pg.model.append (out iter);
119 pg.model.set(iter, 0, name);
120 pg.model.set(iter, 1, title);
123 protected void on_selected(string page, string name)
125 result.grammar = page + "/" + name;
126 notebook.set_current_page(notebook.get_n_pages()-1);
129 public Polygen(string label, IOChannel data)
132 pages = new Gee.ArrayList<PolygenPage>();
137 var res = data.read_line(out line, null, null);
138 if (res != IOStatus.NORMAL) break;
139 string[] vals = line.split(" ", 2);
140 if (vals == null) break;
141 string[] np = vals[0].split("/", 2);
142 if (np == null) break;
143 add(np[0], np[1], vals[1].strip());
146 notebook = new Gtk.Notebook();
147 foreach (PolygenPage p in pages)
149 notebook.append_page(p.scroll, new Gtk.Label(p.name));
151 result = new PolygenRun();
152 notebook.append_page(result, new Gtk.Label("Result"));
154 pack_start(notebook, true, true, 0);
163 var data = new IOChannel.file(zavai.config.homedir + "/polygen-info", "r");
164 polygen = new Polygen("Polygen", data);
165 data.shutdown(false);
167 zavai.registry.register_applet("ui.polygen", polygen);
168 zavai.registry.getmenu("menu.main").add_applet("ui.polygen");
169 } catch (FileError e) {
171 zavai.log.error("Skipping polygen plugin: " + e.message);
175 window_list = new WindowList("Current apps");
176 zavai.registry.register_applet("wm.list", window_list);
177 zavai.registry.getmenu("menu.main").add_applet("wm.list");
180 launcher = new Launcher("Run program");
182 zavai.log.error("Not running launcher: " + e.message);
186 if (launcher != null)
188 zavai.registry.register_applet("wm.launcher", launcher);
189 zavai.registry.getmenu("menu.main").add_applet("wm.launcher");