1
public class Arrive.Widgets.DownloadingList : Object {
2
private static int REFRESH_TIME=1000;
3
public Gtk.ScrolledWindow widget;
4
private Gtk.ListStore list_store;
5
private Gtk.TreeView tree_view;
7
public DownloadingList () {
8
/*Gtk.ListStore*/ list_store = new Gtk.ListStore (1, typeof(Arrive.Model.DownloadItem));
9
/*Gtk.TreeView*/ tree_view = new Gtk.TreeView.with_model (list_store);
10
tree_view.set_headers_visible (false);
11
tree_view.get_selection().set_mode(Gtk.SelectionMode.MULTIPLE);
12
widget = new Gtk.ScrolledWindow(null, null);
13
widget.add(tree_view);
15
tree_view.button_press_event.connect((event)=>{
17
show_popup_menu(event);
22
Arrive.App.aria2.download_list.list_changed.connect(()=>{
23
populate_list_store();
26
var cell_renderer = new Arrive.Widgets.DownloadCellRenderer ();
27
tree_view.insert_column_with_attributes (-1, "column", cell_renderer, "file", 0);
29
var refresh_timer = new TimeoutSource(REFRESH_TIME);
30
refresh_timer.set_callback(()=>{
31
tree_view.queue_draw();
1
namespace Arrive.Widgets {
2
public class DownloadingList : Object {
3
private static int REFRESH_TIME=1000;
4
public Gtk.ScrolledWindow widget;
5
private Gtk.ListStore list_store;
6
private Gtk.TreeView tree_view;
8
public DownloadingList () {
9
/*Gtk.ListStore*/ list_store = new Gtk.ListStore (1, typeof(Arrive.Model.DownloadItem));
10
/*Gtk.TreeView*/ tree_view = new Gtk.TreeView.with_model (list_store);
11
tree_view.set_headers_visible (false);
12
tree_view.get_selection ().set_mode (Gtk.SelectionMode.MULTIPLE);
13
widget = new Gtk.ScrolledWindow (null, null);
14
widget.add (tree_view);
16
tree_view.button_press_event.connect ((event)=>{
18
show_popup_menu (event);
22
Arrive.App.aria2.download_list.list_changed.connect (()=>{
23
populate_list_store ();
26
var cell_renderer = new DownloadCellRenderer ();
27
tree_view.insert_column_with_attributes (-1, "column", cell_renderer, "file", 0);
29
var refresh_timer = new TimeoutSource (REFRESH_TIME);
30
refresh_timer.set_callback (()=>{
31
tree_view.queue_draw ();
34
refresh_timer.attach (null);
36
populate_list_store ();
37
debug ("DownloadingList created");
39
private void populate_list_store(){
41
debug ("list lenght %u", Arrive.App.aria2.download_list._list.length ());
42
foreach(Arrive.Model.DownloadItem file in Arrive.App.aria2.download_list._list) {
44
list_store.append (out iter);
45
list_store.set (iter, 0, file);
48
private void show_popup_menu(Gdk.EventButton event){
49
List<Arrive.Model.DownloadItem> selected_files;
50
selected_files=get_selected_files ();
51
var menu = new Gtk.Menu ();
52
var start = new Gtk.MenuItem.with_label (_("Continue"));
53
var pause = new Gtk.MenuItem.with_label (_("Pause"));
54
var cancel = new Gtk.MenuItem.with_label (_("Cancel"));
55
var properties = new Gtk.MenuItem.with_label (_("Properties"));
56
//TODO:implement right click event
57
start.activate.connect (()=>{
58
foreach(Arrive.Model.DownloadItem d_item in selected_files) {
59
if(d_item.status == "paused") d_item.unpause ();
60
if(d_item.status == "") d_item.start (null);
61
if(d_item.status == "stopped") d_item.start (null);
64
pause.activate.connect (()=>{
65
foreach(Arrive.Model.DownloadItem d_item in selected_files)
68
cancel.activate.connect (()=>{
69
foreach(Arrive.Model.DownloadItem d_item in selected_files)
72
//~ properties.connect();
74
if(allow_start (selected_files)) menu.add (start);
75
if(allow_pause (selected_files)) menu.add (pause);
76
if(allow_cancel (selected_files)) menu.add (cancel);
77
if(allow_properties (selected_files)) menu.add (properties);
79
menu.attach_to_widget (tree_view, null);
81
menu.popup (null, null, null, event.button, event.time);
83
private bool allow_start(List<Arrive.Model.DownloadItem> selected_files){
85
foreach(Arrive.Model.DownloadItem d_item in selected_files) {
86
if(d_item.status == "paused") allow=true;
87
if(d_item.status == "") allow=true;
91
private bool allow_pause(List<Arrive.Model.DownloadItem> selected_files){
93
foreach(Arrive.Model.DownloadItem d_item in selected_files)
94
if(d_item.status == "active") allow=true;
97
private bool allow_cancel(List<Arrive.Model.DownloadItem> selected_files){
99
foreach(Arrive.Model.DownloadItem d_item in selected_files)
100
if(d_item.status == "active"||d_item.status == "paused") allow=true;
103
private bool allow_properties(List<Arrive.Model.DownloadItem> selected_files){
34
refresh_timer.attach(null);
36
populate_list_store();
37
debug("DownloadingList created");
39
private void populate_list_store(){
41
debug("list lenght %u",Arrive.App.aria2.download_list._list.length());
42
foreach(Arrive.Model.DownloadItem file in Arrive.App.aria2.download_list._list){
44
list_store.append(out iter);
45
list_store.set(iter,0,file);
48
private void show_popup_menu(Gdk.EventButton event){
49
List<Arrive.Model.DownloadItem> selected_files;
50
selected_files=get_selected_files();
51
var menu = new Gtk.Menu();
52
var start = new Gtk.MenuItem.with_label(_("Continue"));
53
var pause = new Gtk.MenuItem.with_label(_("Pause"));
54
var cancel = new Gtk.MenuItem.with_label(_("Cancel"));
55
var properties = new Gtk.MenuItem.with_label(_("Properties"));
56
//TODO:implement right click event
57
start.activate.connect(()=>{
58
foreach(Arrive.Model.DownloadItem d_item in selected_files){
59
if(d_item.status=="paused")d_item.unpause();
60
if(d_item.status=="")d_item.start(null);
61
if(d_item.status=="stopped")d_item.start(null);
64
pause.activate.connect(()=>{
65
foreach(Arrive.Model.DownloadItem d_item in selected_files){
69
cancel.activate.connect(()=>{
70
foreach(Arrive.Model.DownloadItem d_item in selected_files){
74
//~ properties.connect();
76
if(allow_start(selected_files))menu.add(start);
77
if(allow_pause(selected_files))menu.add(pause);
78
if(allow_cancel(selected_files))menu.add(cancel);
79
if(allow_properties(selected_files))menu.add(properties);
81
menu.attach_to_widget(tree_view,null);
83
menu.popup(null,null,null,event.button,event.time);
85
private bool allow_start(List<Arrive.Model.DownloadItem> selected_files){
87
foreach(Arrive.Model.DownloadItem d_item in selected_files){
88
if(d_item.status=="paused")allow=true;
89
if(d_item.status=="")allow=true;
93
private bool allow_pause(List<Arrive.Model.DownloadItem> selected_files){
95
foreach(Arrive.Model.DownloadItem d_item in selected_files){
96
if(d_item.status=="active")allow=true;
100
private bool allow_cancel(List<Arrive.Model.DownloadItem> selected_files){
102
foreach(Arrive.Model.DownloadItem d_item in selected_files){
103
if(d_item.status=="active"||d_item.status=="paused")allow=true;
107
private bool allow_properties(List<Arrive.Model.DownloadItem> selected_files){
110
private List<Arrive.Model.DownloadItem> get_selected_files(){
111
var list = new List<Arrive.Model.DownloadItem>();
112
Gtk.TreeIter selection_iter;
113
Gtk.TreeSelection selection=tree_view.get_selection();
114
GLib.List<Gtk.TreePath> d_items = selection.get_selected_rows(null);
115
Gtk.TreeModel model = tree_view.get_model();
116
foreach(Gtk.TreePath selection_item in d_items){
117
/*Arrive.Model.DownloadItem*/Value d_item;
118
model.get_iter (out selection_iter, selection_item);
119
model.get_value(selection_iter,0, out d_item);
120
if(d_item.holds(typeof(Arrive.Model.DownloadItem))){
121
list.append((Arrive.Model.DownloadItem)d_item);
123
debug("value arent download item");
106
private List<Arrive.Model.DownloadItem> get_selected_files(){
107
var list = new List<Arrive.Model.DownloadItem>();
108
Gtk.TreeIter selection_iter;
109
Gtk.TreeSelection selection=tree_view.get_selection ();
110
GLib.List<Gtk.TreePath> d_items = selection.get_selected_rows (null);
111
Gtk.TreeModel model = tree_view.get_model ();
112
foreach(Gtk.TreePath selection_item in d_items) {
113
/*Arrive.Model.DownloadItem*/ Value d_item;
114
model.get_iter (out selection_iter, selection_item);
115
model.get_value (selection_iter, 0, out d_item);
116
if(d_item.holds (typeof(Arrive.Model.DownloadItem)))
117
list.append ((Arrive.Model.DownloadItem)d_item);
119
debug ("value arent download item");