Actually decrement usage count when releasing a service
[gregoa/zavai.git] / gtkfisheyelist / demo.vala
1 /*
2  * Demo for FisheyeListView
3  *
4  * Copyright (C) 2009  Enrico Zini <enrico@enricozini.org>
5  *
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.
10  *
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.
15  *
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
19  */
20
21 using GLib;
22
23 public class Fisheye : Gtk.Window
24 {
25         Gtk.ListStore model;
26         FisheyeListView flv;
27
28         public Fisheye()
29         {
30                 title = "Fisheye";
31                 destroy += Gtk.main_quit;
32
33                 flv = new FisheyeListView();
34                 add(flv);
35
36                 model = new Gtk.ListStore(1, typeof(string));
37                 Gtk.TreeIter iter;
38                 var infd = FileStream.open("/tmp/names", "r");
39                 if (infd == null)
40                 {
41                         for (int i = 0; i < 300; ++i)
42                         {
43                                 model.append(out iter);
44                                 model.set(iter, 0, "Antani %d".printf(i), -1);
45                         }
46                 } else {
47                         char buf[255];
48                         while (true)
49                         {
50                                 string line = infd.gets(buf);
51                                 if (line == null)
52                                         break;
53                                 model.append(out iter);
54                                 model.set(iter, 0, line, -1);
55                         }
56                 }
57
58                 flv.set_model(model);
59
60                 flv.row_activated += on_row_activated;
61         }
62
63         public void on_row_activated(Gtk.TreePath path)
64         {
65                 Gtk.TreeIter iter;
66                 model.get_iter(out iter, path);
67                 string val;
68                 model.get(iter, 0, out val, -1);
69                 stdout.printf("Clicked on %s\n", val);
70         }
71 }
72
73 static int main (string[] args) {
74         Gtk.init (ref args);
75
76         var fe = new Fisheye();
77         fe.set_size_request(200, 300);
78         fe.show_all();
79
80         Gtk.main();
81
82         return 0;
83 }