-
Notifications
You must be signed in to change notification settings - Fork 2
/
0004-Support-download-to.patch
139 lines (131 loc) · 5.61 KB
/
0004-Support-download-to.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
From e74a79abfa88952f8b69bfdcaf38e763fae710fa Mon Sep 17 00:00:00 2001
From: LiuLang <[email protected]>
Date: Sat, 2 Jan 2016 12:04:53 +0800
Subject: [PATCH 04/10] Support "download to..."
https://github.com/LiuLang/bcloud/issues/199
---
bcloud/DownloadPage.py | 26 ++++++++++++++------------
bcloud/IconWindow.py | 24 ++++++++++++++++++++++++
2 files changed, 38 insertions(+), 12 deletions(-)
diff --git a/bcloud/DownloadPage.py b/bcloud/DownloadPage.py
index f696455..4647d02 100644
--- a/bcloud/DownloadPage.py
+++ b/bcloud/DownloadPage.py
@@ -81,7 +81,7 @@ class DownloadPage(Gtk.Box):
path - 文件在服务器上的绝对路径
name - 文件在服务器上的名称
savePath - 保存到的绝对路径
- saveName - 保存时的文件名
+ save_name - 保存时的文件名
currRange - 当前下载的进度, 以字节为单位, 在HTTP Header中可用.
state - 任务状态
link - 文件的下载最终URL, 有效期大约是8小时, 超时后要重新获取.
@@ -223,7 +223,7 @@ class DownloadPage(Gtk.Box):
self.pack_start(scrolled_win, True, True, 0)
# name, path, fs_id, size, currsize, link,
- # isdir, saveDir, saveName, state, statename,
+ # isdir, save_dir, save_name, state, statename,
# humansize, percent, tooltip
self.liststore = Gtk.ListStore(str, str, str, GObject.TYPE_INT64,
GObject.TYPE_INT64, str,
@@ -402,7 +402,7 @@ class DownloadPage(Gtk.Box):
self.app_infos.pop(fs_id, None)
# Open API
- def add_tasks(self, pcs_files):
+ def add_tasks(self, pcs_files, dirname=''):
'''建立批量下载任务, 包括目录'''
def on_list_dir(info, error=None):
path, pcs_files = info
@@ -416,7 +416,7 @@ class DownloadPage(Gtk.Box):
dialog.run()
dialog.destroy()
return
- self.add_tasks(pcs_files)
+ self.add_tasks(pcs_files, dirname)
self.check_first()
for pcs_file in pcs_files:
@@ -425,10 +425,10 @@ class DownloadPage(Gtk.Box):
self.app.tokens, pcs_file['path'],
callback=on_list_dir)
else:
- self.add_task(pcs_file)
+ self.add_task(pcs_file, dirname)
self.check_commit(force=True)
- def add_task(self, pcs_file):
+ def add_task(self, pcs_file, dirname=''):
'''加入新的下载任务'''
if pcs_file['isdir']:
return
@@ -441,12 +441,14 @@ class DownloadPage(Gtk.Box):
if row[STATE_COL] == State.FINISHED:
self.launch_app(fs_id)
return
- saveDir = os.path.split(self.app.profile['save-dir'] +
- pcs_file['path'])[0]
- saveName = pcs_file['server_filename']
+ if not dirname:
+ dirname = self.app.profile['save-dir']
+ save_dir = os.path.dirname(
+ os.path.join(dirname, pcs_file['path'][1:]))
+ save_name = pcs_file['server_filename']
human_size = util.get_human_size(pcs_file['size'])[0]
tooltip = gutil.escape(_('From {0}\nTo {1}').format(pcs_file['path'],
- saveDir))
+ save_dir))
task = (
pcs_file['server_filename'],
pcs_file['path'],
@@ -455,8 +457,8 @@ class DownloadPage(Gtk.Box):
0,
'', # pcs['dlink' removed in new version.
pcs_file['isdir'],
- saveName,
- saveDir,
+ save_name,
+ save_dir,
State.WAITING,
StateNames[State.WAITING],
human_size,
diff --git a/bcloud/IconWindow.py b/bcloud/IconWindow.py
index b8be429..c4e0741 100644
--- a/bcloud/IconWindow.py
+++ b/bcloud/IconWindow.py
@@ -346,6 +346,9 @@ class IconWindow(Gtk.ScrolledWindow):
download_item = Gtk.MenuItem.new_with_label(_('Download'))
download_item.connect('activate', self.on_download_activated)
menu.append(download_item)
+ download_to_item = Gtk.MenuItem.new_with_label(_('Download to...'))
+ download_to_item.connect('activate', self.on_download_to_activated)
+ menu.append(download_to_item)
share_item = Gtk.MenuItem.new_with_label(_('Share'))
share_item.connect('activate', self.on_share_activated)
menu.append(share_item)
@@ -525,6 +528,27 @@ class IconWindow(Gtk.ScrolledWindow):
self.app.blink_page(self.app.download_page)
self.app.download_page.add_tasks(pcs_files)
+ def on_download_to_activated(self, menu_item):
+ '''下载文件/目录到指定的文件夹里.'''
+ tree_paths = self.iconview.get_selected_items()
+ if not tree_paths:
+ return
+
+ dialog = Gtk.FileChooserDialog(_('Save to...'), self.app.window,
+ Gtk.FileChooserAction.SELECT_FOLDER,
+ (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
+ Gtk.STOCK_OK, Gtk.ResponseType.OK))
+ response = dialog.run()
+ if response != Gtk.ResponseType.OK:
+ dialog.destroy()
+ return
+ dirname = dialog.get_filename()
+ dialog.destroy()
+
+ pcs_files = [self.get_pcs_file(p) for p in tree_paths]
+ self.app.blink_page(self.app.download_page)
+ self.app.download_page.add_tasks(pcs_files, dirname)
+
def on_share_activated(self, menu_item):
def on_share(info, error=None):
if error or not info or info['errno'] != 0:
--
2.9.0