Skip to content
This repository has been archived by the owner on Dec 17, 2019. It is now read-only.

Commit

Permalink
Fixed: failed to handle file drop action; #39
Browse files Browse the repository at this point in the history
  • Loading branch information
LiuLang committed Oct 27, 2014
1 parent 5f09b61 commit e69cf76
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 26 deletions.
20 changes: 9 additions & 11 deletions bcloud/App.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from bcloud import Config
Config.check_first()
_ = Config._
from bcloud import const
from bcloud import gutil
from bcloud.log import logger
from bcloud import util
Expand Down Expand Up @@ -70,13 +71,7 @@ def on_app_startup(self, app):
self.window.connect('delete-event', self.on_main_window_deleted)
app.add_window(self.window)

# set drop action
targets = [
['text/plain', Gtk.TargetFlags.OTHER_APP, 0],
['*.*', Gtk.TargetFlags.OTHER_APP, 1]
]
target_list =[Gtk.TargetEntry.new(*t) for t in targets]
self.window.drag_dest_set(Gtk.DestDefaults.ALL, target_list,
self.window.drag_dest_set(Gtk.DestDefaults.ALL, const.DnD_TARGET_LIST,
Gdk.DragAction.COPY)
self.window.connect('drag-data-received',
self.on_main_window_drag_data_received)
Expand Down Expand Up @@ -222,10 +217,13 @@ def on_main_window_drag_data_received(self, window, drag_context, x, y,
这里, 会弹出一个选择目标文件夹的对话框
'''
uris = data.get_text()
source_paths = util.uris_to_paths(uris)
if source_paths and self.profile:
self.upload_page.upload_files(source_paths)
if not self.profile:
return
if info == const.TARGET_TYPE_URI_LIST:
uris = data.get_uris()
source_paths = util.uris_to_paths(uris)
if source_paths:
self.upload_page.upload_files(source_paths)

def on_preferences_action_activated(self, action, params):
if self.profile:
Expand Down
19 changes: 8 additions & 11 deletions bcloud/HomePage.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,13 +169,7 @@ def __init__(self, app):
super().__init__(orientation=Gtk.Orientation.VERTICAL)
self.app = app

# set drop action
targets = [
['text/plain', Gtk.TargetFlags.OTHER_APP, 0],
['*.*', Gtk.TargetFlags.OTHER_APP, 1]
]
target_list = [Gtk.TargetEntry.new(*t) for t in targets]
self.drag_dest_set(Gtk.DestDefaults.ALL, target_list,
self.drag_dest_set(Gtk.DestDefaults.ALL, const.DnD_TARGET_LIST,
Gdk.DragAction.COPY)

if Config.GTK_GE_312:
Expand Down Expand Up @@ -398,10 +392,13 @@ def do_drag_data_received(self, drag_context, x, y, data, info, time):
这里, 会直接把文件上传到当前目录(self.path).
拖放事件已经被处理, 所以不会触发self.app.window的拖放动作.
'''
uris = data.get_text()
source_paths = util.uris_to_paths(uris)
if source_paths and self.app.profile:
self.app.upload_page.add_file_tasks(source_paths, self.path)
if not self.app.profile:
return
if info == const.TARGET_TYPE_URI_LIST:
uris = data.get_uris()
source_paths = util.uris_to_paths(uris)
if source_paths:
self.app.upload_page.upload_files(source_paths, self.path)

def on_search_button_toggled(self, search_button):
status = search_button.get_active()
Expand Down
14 changes: 12 additions & 2 deletions bcloud/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
与界面相关的常量, 都位于Config.py.
'''

from gi.repository import Gtk

from bcloud import Config
_ = Config._

Expand Down Expand Up @@ -86,9 +88,17 @@ class ValidatePathState:
CHAR_ERROR2 = 2
CHAR_ERROR3 = 3

ValidatePathStateText = [
ValidatePathStateText = (
'',
_('Max characters in filepath shall no more than 1000'),
_('Filepath should not contain "\\ ? | \" > < : *"'),
_('"\\r \\n \\t \\0 \\x0B" or SPACE should not appear in start or end of filename'),
]
)


# 拖放目标, 接收从其它程序拖进来的目录
TARGET_TYPE_URI_LIST = 0
DnD_LIST = (
('text/uri-list', Gtk.TargetFlags.OTHER_APP, TARGET_TYPE_URI_LIST),
)
DnD_TARGET_LIST = [Gtk.TargetEntry.new(*t) for t in DnD_LIST]
4 changes: 2 additions & 2 deletions bcloud/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,12 @@ def list_remove_by_index(l, index):
def uri_to_path(uri):
if not uri or len(uri) < 7:
return ''
return urllib.parse.unquote(uri).replace('file://', '')
return urllib.parse.unquote(uri[7:])

def uris_to_paths(uris):
'''将一串URI地址转为绝对路径, 用于处理桌面程序中的文件拖放'''
source_paths = []
for uri in uris.split('\n'):
for uri in uris:
source_path = uri_to_path(uri)
if source_path:
source_paths.append(source_path)
Expand Down

0 comments on commit e69cf76

Please sign in to comment.