ported select_file to Qt

This commit is contained in:
Micah Lee 2014-06-19 16:36:49 -04:00
parent 1c59072a2b
commit ff7791939b
2 changed files with 8 additions and 14 deletions

View File

@ -16,7 +16,8 @@
"other_page_loaded": "Other page has been loaded", "other_page_loaded": "Other page has been loaded",
"tails_requires_root": "You must run OnionShare as root in Tails", "tails_requires_root": "You must run OnionShare as root in Tails",
"close_on_finish": "Close automatically", "close_on_finish": "Close automatically",
"close_countdown": "Closing in {0} seconds..." "close_countdown": "Closing in {0} seconds...",
"choose_file": "Choose a file to share"
}, "no": { }, "no": {
"punching_a_hole": "Åpner port i brannmuren.", "punching_a_hole": "Åpner port i brannmuren.",
"closing_hole": "Lukker port i brannmuren.", "closing_hole": "Lukker port i brannmuren.",

View File

@ -24,23 +24,16 @@ def select_file(strings):
if len(sys.argv) == 2: if len(sys.argv) == 2:
filename = sys.argv[1] filename = sys.argv[1]
else: else:
canceled = False args = {}
chooser = gtk.FileChooserDialog(
title="Choose a file to share",
action=gtk.FILE_CHOOSER_ACTION_OPEN,
buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_OPEN, gtk.RESPONSE_OK))
if onionshare.get_platform() == 'Tails': if onionshare.get_platform() == 'Tails':
chooser.set_current_folder('/home/amnesia/') args['directory'] = '/home/amnesia'
response = chooser.run()
if response == gtk.RESPONSE_OK:
filename = chooser.get_filename()
elif response == gtk.RESPONSE_CANCEL:
canceled = True
chooser.destroy()
if canceled: filename = QFileDialog.getOpenFileName(caption=strings['choose_file'], options=QFileDialog.ReadOnly, **args)
if not filename:
return False, False return False, False
filename = str(filename)
# validate filename # validate filename
if not os.path.isfile(filename): if not os.path.isfile(filename):
alert(strings["not_a_file"].format(filename), gtk.MESSAGE_ERROR) alert(strings["not_a_file"].format(filename), gtk.MESSAGE_ERROR)