~lubuntu-software-center-team/lubuntu-software-center/vala-port

« back to all changes in this revision

Viewing changes to src/Frontend.vala

  • Committer: Stephen Smally
  • Date: 2012-03-04 12:59:13 UTC
  • Revision ID: eco.stefi@fastwebnet.it-20120304125913-bk1iutifwoeoyo0i
Worked a lot!

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//  Stephen Smally © 2012
 
2
//      This program is free software; you can redistribute it and/or modify
 
3
//      it under the terms of the GNU General Public License as published by
 
4
//      the Free Software Foundation; either version 2 of the License, or
 
5
//      (at your option) any later version.
 
6
//      
 
7
//      This program is distributed in the hope that it will be useful,
 
8
//      but WITHOUT ANY WARRANTY; without even the implied warranty of
 
9
//      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
10
//      GNU General Public License for more details.
 
11
//      
 
12
//      You should have received a copy of the GNU General Public License
 
13
//      along with this program; if not, write to the Free Software
 
14
//      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 
15
//      MA 02110-1301, USA.
 
16
//      
 
17
 
 
18
using Gtk;
 
19
using Lsc.Backend;
 
20
using Lsc.Widgets;
 
21
 
 
22
namespace Lsc {
 
23
    // Elements which should be accessible to every void or class
 
24
    public enum PageType {
 
25
        HOMEPAGE,
 
26
        APPSVIEW,
 
27
        APPSINFO;
 
28
        
 
29
        public string to_string () {
 
30
            switch (this) {
 
31
                case HOMEPAGE:
 
32
                    return "Home Page";
 
33
                case APPSVIEW:
 
34
                    return "Apps View";
 
35
                case APPSINFO:
 
36
                    return "Apps Info";
 
37
                default:
 
38
                    assert_not_reached();
 
39
            }
 
40
        }
 
41
        
 
42
        public PageType[] get_all () {
 
43
            return { HOMEPAGE, APPSVIEW, APPSINFO };
 
44
        }
 
45
    }
 
46
    
 
47
    // Apps Manager which handle the PackageKit connection
 
48
    public AppsManager apps_manager;
 
49
    
 
50
    public class Frontend : Window {
 
51
        // Widgets
 
52
        public Box main_box;
 
53
        public MainToolbar toolbar;
 
54
        public PagesView pages_view;
 
55
        public ProgressInfo progress_info;
 
56
        
 
57
        public void load_packages (string filters) {
 
58
            pages_view.set_current_page(PageType.APPSVIEW);
 
59
            pages_view.apps_view.apps_tree.clear();
 
60
            apps_manager.get_pkgs(filters);
 
61
        }
 
62
        
 
63
        public void update_back_button (Notebook nb, Widget pg, uint page_n) {
 
64
            switch ((PageType) page_n) {
 
65
                
 
66
            }
 
67
        }
 
68
        
 
69
        public void connect_signals () {
 
70
            apps_manager.app_added.connect(pages_view.apps_view.apps_tree.append_app);
 
71
            apps_manager.loading_started.connect(progress_info.load_undefined);
 
72
            apps_manager.loading_finished.connect(progress_info.clear);
 
73
            apps_manager.category_added.connect(pages_view.home_page.categories_view.add_category);
 
74
            apps_manager.details_received.connect(pages_view.apps_info.set_details);
 
75
            pages_view.switch_page.connect(update_back_button);
 
76
            pages_view.home_page.categories_view.category_choosed.connect(() => {
 
77
                load_packages("installed;gui");
 
78
            });
 
79
        }
 
80
        
 
81
        public Frontend () {            
 
82
            apps_manager = new AppsManager();
 
83
            
 
84
            destroy.connect(Gtk.main_quit);
 
85
            window_position = WindowPosition.CENTER;
 
86
            title = "Light Software Center";
 
87
            set_default_size(600, 400);
 
88
            
 
89
            main_box = new Box(Orientation.VERTICAL, 0);
 
90
            
 
91
            toolbar = new MainToolbar();
 
92
            main_box.pack_start(toolbar, false, false, 0);
 
93
            
 
94
            progress_info = new ProgressInfo();
 
95
            main_box.pack_start(progress_info, false, false, 0);
 
96
            
 
97
            pages_view = new PagesView();
 
98
            
 
99
            main_box.pack_start(pages_view, true, true, 0);
 
100
            
 
101
            add(main_box);
 
102
            show_all();
 
103
            
 
104
            connect_signals();
 
105
            
 
106
            apps_manager.get_categories();
 
107
            pages_view.home_page.categories_view.fill_space();
 
108
            
 
109
            progress_info.set_visible(false);
 
110
            
 
111
            pages_view.set_current_page(PageType.APPSINFO);
 
112
            apps_manager.get_details("app-install-data;0.11.10.6;all;");
 
113
        }
 
114
    }
 
115
}
 
116
 
 
117
int main (string[] args) {
 
118
    Gtk.init(ref args);
 
119
    new Lsc.Frontend();
 
120
    Gtk.main();
 
121
    return 0;
 
122
}