~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-05-16 15:04:53 UTC
  • Revision ID: eco.stefi@fastwebent.it-20120516150453-ldidynmwbc1qfq41
Working on

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
//  Stephen Smally © 2012
 
1
//  Copyright © 2012 Stephen Smally
2
2
//      This program is free software; you can redistribute it and/or modify
3
3
//      it under the terms of the GNU General Public License as published by
4
4
//      the Free Software Foundation; either version 2 of the License, or
54
54
        public PagesView pages_view;
55
55
        public ProgressInfo progress_info;
56
56
        
 
57
        // Vars
57
58
        private int _width = 0;
58
59
        
 
60
        public Frontend () {
 
61
            apps_manager = new AppsManager();
 
62
            
 
63
            destroy.connect(Gtk.main_quit);
 
64
            size_allocate.connect(on_size_allocate);
 
65
            
 
66
            window_position = WindowPosition.CENTER;
 
67
            title = "Light Software Center";
 
68
            set_default_size(600, 400);
 
69
            has_resize_grip = true;
 
70
            
 
71
            main_box = new Box(Orientation.VERTICAL, 0);
 
72
            
 
73
            toolbar = new MainToolbar();
 
74
            main_box.pack_start(toolbar, false, false, 0);
 
75
            
 
76
            progress_info = new ProgressInfo();
 
77
            main_box.pack_start(progress_info, false, false, 0);
 
78
            
 
79
            pages_view = new PagesView();
 
80
            
 
81
            main_box.pack_start(pages_view, true, true, 0);
 
82
            
 
83
            connect_signals();
 
84
            apps_manager.get_categories();
 
85
            
 
86
            add(main_box);
 
87
            show_all();
 
88
            
 
89
            progress_info.set_visible(false);
 
90
            pages_view.apps_info.reviews_box.set_visible(false);
 
91
            
 
92
            set_focus(null);
 
93
            
 
94
            load_packages("gui;application");
 
95
        }
 
96
        
59
97
        public void load_packages (string filters) {
60
98
            pages_view.set_current_page(PageType.APPSVIEW);
61
99
            pages_view.apps_view.apps_tree.clear();
63
101
        }
64
102
        
65
103
        public void update_back_button (Notebook nb, Widget pg, uint page_n) {
66
 
            stdout.printf("Page: %s\n", ((PageType) page_n).to_string());
 
104
            stdout.printf("Page->%s\n", ((PageType) page_n).to_string());
67
105
            switch ((PageType) page_n) {
68
106
                case PageType.HOMEPAGE:
69
107
                    toolbar.searchbar.set_sensitive(true);
88
126
        public void connect_signals () {
89
127
            apps_manager.app_added.connect(pages_view.apps_view.apps_tree.append_app);
90
128
            apps_manager.loading_started.connect(progress_info.load_undefined);
91
 
            apps_manager.loading_finished.connect(progress_info.clear);
 
129
            apps_manager.loading_finished.connect(on_load_finished);
92
130
            apps_manager.category_added.connect(pages_view.home_page.categories_view.add_category);
93
131
            apps_manager.details_received.connect(pages_view.apps_info.set_details);
 
132
            pages_view.home_page.categories_view.category_choosed.connect((gr) => {
 
133
                stdout.printf("%s\n", gr);
 
134
            });
94
135
            pages_view.switch_page.connect(update_back_button);
95
136
            pages_view.switch_page.connect(toolbar.update_label);
96
137
        }
97
138
        
98
 
        public void on_size_allocate (Allocation alloc) {
 
139
        public void rework_categories_columns () {
99
140
            if (_width != get_allocated_width() && get_allocated_width()/150 != pages_view.home_page.categories_view.columns) {
100
 
                stdout.printf("Allocating main window to width: %d, need to rework columns\n", get_allocated_width());
 
141
                stdout.printf("Window.width->%d rework columns\n", get_allocated_width());
101
142
                int size = get_allocated_width();
102
143
                if (size < 150 ) {
103
144
                    size = 150;
108
149
            }
109
150
        }
110
151
        
111
 
        public Frontend () {
112
 
            apps_manager = new AppsManager();
113
 
            
114
 
            destroy.connect(Gtk.main_quit);
115
 
            
116
 
            window_position = WindowPosition.CENTER;
117
 
            title = "Light Software Center";
118
 
            set_default_size(600, 400);
119
 
            set_has_resize_grip(true);
120
 
            
121
 
            main_box = new Box(Orientation.VERTICAL, 0);
122
 
            
123
 
            toolbar = new MainToolbar();
124
 
            main_box.pack_start(toolbar, false, false, 0);
125
 
            
126
 
            progress_info = new ProgressInfo();
127
 
            main_box.pack_start(progress_info, false, false, 0);
128
 
            
129
 
            pages_view = new PagesView();
130
 
            
131
 
            main_box.pack_start(pages_view, true, true, 0);
132
 
            
133
 
            add(main_box);
134
 
            show_all();
135
 
            
136
 
            connect_signals();
137
 
            
138
 
            apps_manager.get_categories();
139
 
            size_allocate.connect(on_size_allocate);
140
 
            
141
 
            progress_info.set_visible(false);
142
 
            pages_view.apps_info.reviews_box.set_visible(false);
143
 
            
144
 
            pages_view.set_page(PageType.HOMEPAGE);
145
 
            
146
 
            set_focus(null);
 
152
        public void on_size_allocate (Allocation alloc) {
 
153
            rework_categories_columns();
 
154
        }
 
155
        
 
156
        public void on_load_finished (LoadingType load) {
 
157
            switch (load) {
 
158
                case LoadingType.CATEGORIES:
 
159
                    rework_categories_columns();
 
160
                    break;
 
161
                case LoadingType.PACKAGES:
 
162
                    progress_info.clear();
 
163
                    break;
 
164
                default:
 
165
                    break;
 
166
            }
147
167
        }
148
168
    }
149
169
}