コード例 #1
0
 def on_ok(widget):
     target_path = dialog.get_filename()
     if os.path.exists(target_path):
         # check if we have write permissions
         if not os.access(target_path, os.W_OK):
             file_name = os.path.basename(target_path)
             dialogs.ErrorDialog(
                 _('Cannot overwrite existing file "%s"') % file_name,
                 _('A file with this name already exists and you do '
                   'not have permission to overwrite it.'))
             return
         dialog2 = dialogs.FTOverwriteConfirmationDialog(
             _('This file already exists'),
             _('What do you want to do?'),
             propose_resume=False,
             on_response=(on_continue, target_path),
             transient_for=dialog)
         dialog2.set_destroy_with_parent(True)
     else:
         dirname = os.path.dirname(target_path)
         if not os.access(dirname, os.W_OK):
             dialogs.ErrorDialog(
                 _('Directory "%s" is not writable') % dirname,
                 _('You do not have permission to '
                   'create files in this directory.'))
             return
         on_continue(0, target_path)
コード例 #2
0
ファイル: gtkgui_helpers.py プロジェクト: tdruiva/gajim
    def on_ok(widget):
        def on_ok2(file_path, pixbuf):
            pixbuf.save(file_path, 'jpeg')
            dialog.destroy()

        file_path = dialog.get_filename()
        file_path = decode_filechooser_file_paths((file_path, ))[0]
        if os.path.exists(file_path):
            # check if we have write permissions
            if not os.access(file_path, os.W_OK):
                file_name = os.path.basename(file_path)
                dialogs.ErrorDialog(
                    _('Cannot overwrite existing file "%s"' % file_name),
                    _('A file with this name already exists and you do not have '
                      'permission to overwrite it.'))
                return
            dialog2 = dialogs.FTOverwriteConfirmationDialog(
                _('This file already exists'),
                _('What do you want to do?'),
                propose_resume=False,
                on_response=(on_continue, file_path))
            dialog2.set_transient_for(dialog)
            dialog2.set_destroy_with_parent(True)
        else:
            dirname = os.path.dirname(file_path)
            if not os.access(dirname, os.W_OK):
                dialogs.ErrorDialog(_('Directory "%s" is not writable') % \
                dirname, _('You do not have permission to create files in this'
                ' directory.'))
                return

        on_continue(0, file_path)
コード例 #3
0
        def on_ok(widget, account, contact, file_props):
            file_path = dialog2.get_filename()
            if os.path.exists(file_path):
                # check if we have write permissions
                if not os.access(file_path, os.W_OK):
                    file_name = GLib.markup_escape_text(os.path.basename(
                        file_path))
                    dialogs.ErrorDialog(
                        _('Cannot overwrite existing file "%s"' % file_name),
                        _('A file with this name already exists and you do not '
                        'have permission to overwrite it.'))
                    return
                stat = os.stat(file_path)
                dl_size = stat.st_size
                file_size = file_props.size
                dl_finished = dl_size >= file_size

                def on_response(response):
                    if response < 0:
                        return
                    elif response == 100:
                        file_props.offset = dl_size
                    dialog2.destroy()
                    self._start_receive(file_path, account, contact, file_props)

                dialog = dialogs.FTOverwriteConfirmationDialog(
                    _('This file already exists'), _('What do you want to do?'),
                    propose_resume=not dl_finished, on_response=on_response,
                    transient_for=dialog2)
                dialog.set_destroy_with_parent(True)
                return
            else:
                dirname = os.path.dirname(file_path)
                if not os.access(dirname, os.W_OK) and os.name != 'nt':
                    # read-only bit is used to mark special folder under
                    # windows, not to mark that a folder is read-only.
                    # See ticket #3587
                    dialogs.ErrorDialog(_('Directory "%s" is not writable') % \
                        dirname, _('You do not have permission to create files '
                        'in this directory.'))
                    return
            dialog2.destroy()
            self._start_receive(file_path, account, contact, file_props)