Esempio n. 1
0
    def __init__(self, cb_object, group):
        RadioToolButton.__init__(self, group=group)

        self.props.palette_invoker = FrameWidgetInvoker(self)

        self._cb_object = cb_object
        self.owns_clipboard = False
        self.props.sensitive = False
        self.props.active = False
        self._notif_icon = None
        self._current_percent = None

        self._icon = Icon()
        client = gconf.client_get_default()
        color = XoColor(client.get_string('/desktop/sugar/user/color'))
        self._icon.props.xo_color = color
        self.set_icon_widget(self._icon)
        self._icon.show()

        cb_service = clipboard.get_instance()
        cb_service.connect('object-state-changed',
                           self._object_state_changed_cb)
        cb_service.connect('object-selected', self._object_selected_cb)

        child = self.get_child()
        child.connect('drag_data_get', self._drag_data_get_cb)
        self.connect('notify::active', self._notify_active_cb)
Esempio n. 2
0
    def __init__(self, cb_object, group):
        RadioToolButton.__init__(self, group=group)

        self.props.palette_invoker = FrameWidgetInvoker(self)
        self.palette_invoker.props.toggle_palette = True

        self._cb_object = cb_object
        self.owns_clipboard = False
        self.props.sensitive = False
        self.props.active = False
        self._notif_icon = None
        self._current_percent = None

        self._icon = Icon()
        color = profile.get_color()
        self._icon.props.xo_color = color
        self.set_icon_widget(self._icon)
        self._icon.show()

        cb_service = clipboard.get_instance()
        cb_service.connect("object-state-changed", self._object_state_changed_cb)
        cb_service.connect("object-selected", self._object_selected_cb)

        child = self.get_child()
        child.connect("drag_data_get", self._drag_data_get_cb)
        self.connect("notify::active", self._notify_active_cb)
Esempio n. 3
0
    def drag_data_received_cb(self, widget, context, x, y, selection,
                              targetType, time):
        logging.debug('ClipboardTray: got data for target %r',
                      selection.target)

        object_id = self._context_map.get_object_id(context)
        try:
            if selection is None:
                logging.warn('ClipboardTray: empty selection for target %s',
                             selection.target)
            elif selection.target == 'XdndDirectSave0':
                if selection.data == 'S':
                    window = context.source_window

                    prop_type, format_, dest = window.property_get(
                        'XdndDirectSave0', 'text/plain')

                    clipboardservice = clipboard.get_instance()
                    clipboardservice.add_object_format(object_id,
                                                       'XdndDirectSave0',
                                                       dest,
                                                       on_disk=True)
            else:
                self._add_selection(object_id, selection)

        finally:
            # If it's the last target to be processed, finish
            # the dnd transaction
            if not self._context_map.has_context(context):
                context.drop_finish(True, gtk.get_current_event_time())
Esempio n. 4
0
    def _add_selection(object_id, selection):
        if not selection.get_data():
            return

        selection_data = selection.get_data()

        selection_type_atom = selection.get_data_type()
        selection_type = selection_type_atom.name()

        logging.debug('ClipboardTray: adding type %r', selection_type)

        cb_service = clipboard.get_instance()
        if selection_type == 'text/uri-list':
            uris = selection.get_uris()
            if len(uris) > 1:
                raise NotImplementedError('Multiple uris in text/uri-list'
                                          ' still not supported.')

            cb_service.add_object_format(object_id,
                                         selection_type,
                                         uris[0],
                                         on_disk=True)
        else:
            cb_service.add_object_format(object_id,
                                         selection_type,
                                         selection_data,
                                         on_disk=False)
Esempio n. 5
0
    def __init__(self, cb_object):
        Palette.__init__(self, text_maxlen=100)

        self._cb_object = cb_object

        self.set_group_id('frame')

        cb_service = clipboard.get_instance()
        cb_service.connect('object-state-changed',
                           self._object_state_changed_cb)

        self._remove_item = MenuItem(pgettext('Clipboard', 'Remove'),
                                     'list-remove')
        self._remove_item.connect('activate', self._remove_item_activate_cb)
        self.menu.append(self._remove_item)
        self._remove_item.show()

        self._open_item = MenuItem(_('Open'), 'zoom-activity')
        self._open_item.connect('activate', self._open_item_activate_cb)
        self.menu.append(self._open_item)
        self._open_item.show()

        self._journal_item = MenuItem(_('Keep'))
        client = GConf.Client.get_default()
        color = XoColor(client.get_string('/desktop/sugar/user/color'))
        icon = Icon(icon_name='document-save',
                    icon_size=Gtk.IconSize.MENU,
                    xo_color=color)
        self._journal_item.set_image(icon)

        self._journal_item.connect('activate', self._journal_item_activate_cb)
        self.menu.append(self._journal_item)
        self._journal_item.show()

        self._update()
Esempio n. 6
0
    def __init__(self, cb_object):
        Palette.__init__(self, text_maxlen=100)

        self._cb_object = cb_object

        self.set_group_id('frame')

        cb_service = clipboard.get_instance()
        cb_service.connect('object-state-changed',
                           self._object_state_changed_cb)

        self._remove_item = MenuItem(pgettext('Clipboard', 'Remove'),
                                     'list-remove')
        self._remove_item.connect('activate', self._remove_item_activate_cb)
        self.menu.append(self._remove_item)
        self._remove_item.show()

        self._open_item = MenuItem(_('Open'), 'zoom-activity')
        self._open_item.connect('activate', self._open_item_activate_cb)
        self.menu.append(self._open_item)
        self._open_item.show()

        self._journal_item = MenuItem(_('Keep'))
        client = GConf.Client.get_default()
        color = XoColor(client.get_string('/desktop/sugar/user/color'))
        icon = Icon(icon_name='document-save', icon_size=Gtk.IconSize.MENU,
                    xo_color=color)
        self._journal_item.set_image(icon)

        self._journal_item.connect('activate', self._journal_item_activate_cb)
        self.menu.append(self._journal_item)
        self._journal_item.show()

        self._update()
Esempio n. 7
0
    def __init__(self, cb_object):
        Palette.__init__(self, text_maxlen=100)

        self._cb_object = cb_object

        self.set_group_id('frame')

        cb_service = clipboard.get_instance()
        cb_service.connect('object-state-changed',
                           self._object_state_changed_cb)

        self._remove_item = MenuItem(pgettext('Clipboard', 'Remove'),
                                     'list-remove')
        self._remove_item.connect('activate', self._remove_item_activate_cb)
        self.menu.append(self._remove_item)
        self._remove_item.show()

        self._open_item = MenuItem(_('Open'), 'zoom-activity')
        self._open_item.connect('activate', self._open_item_activate_cb)
        self.menu.append(self._open_item)
        self._open_item.show()

        self._journal_item = MenuItem(_('Keep'))
        color = profile.get_color()
        icon = Icon(icon_name='document-save',
                    pixel_size=style.SMALL_ICON_SIZE,
                    xo_color=color)
        self._journal_item.set_image(icon)

        self._journal_item.connect('activate', self._journal_item_activate_cb)
        self.menu.append(self._journal_item)
        self._journal_item.show()

        self._update()
Esempio n. 8
0
    def _object_added_cb(self, cb_service, cb_object):
        """ Code snippet to tag clipboard objects from shared activities """
        shell = get_model()
        logging.debug(shell.get_active_activity())
        current = shell.get_active_activity()
        active_id = current.get_activity_id()
        logging.debug(active_id)
        pservice = presenceservice.get_instance()
        instance = pservice.get_activity(active_id, warn_if_none=False)

        """ For a shared activity should have a pservice entry """
        if instance is None:
            return
        logging.debug("cbobject path " + str(cb_object.get_id()))
        if self._icons:
            group = self._icons.values()[0]
        else:
            group = None

        icon = ClipboardIcon(cb_object, group)
        self.add_item(icon)
        icon.show()
        self._icons[cb_object.get_id()] = icon

        objects_to_delete = self.get_children()[:-self.MAX_ITEMS]
        for icon in objects_to_delete:
            logging.debug('ClipboardTray: deleting surplus object')
            cb_service = clipboard.get_instance()
            cb_service.delete_object(icon.get_object_id())

        logging.debug('ClipboardTray: %r was added', cb_object.get_id())
Esempio n. 9
0
    def __init__(self, cb_object, group):
        RadioToolButton.__init__(self, group=group)

        self.props.palette_invoker = FrameWidgetInvoker(self)
        self.palette_invoker.props.toggle_palette = True

        self._cb_object = cb_object
        self.owns_clipboard = False
        self.props.sensitive = False
        self.props.active = False
        self._notif_icon = None
        self._current_percent = None

        self._icon = Icon()
        client = GConf.Client.get_default()
        color = XoColor(client.get_string('/desktop/sugar/user/color'))
        self._icon.props.xo_color = color
        self.set_icon_widget(self._icon)
        self._icon.show()

        cb_service = clipboard.get_instance()
        cb_service.connect('object-state-changed',
                           self._object_state_changed_cb)
        cb_service.connect('object-selected', self._object_selected_cb)

        child = self.get_child()
        child.connect('drag_data_get', self._drag_data_get_cb)
        self.connect('notify::active', self._notify_active_cb)
Esempio n. 10
0
    def drag_data_received_cb(self, widget, context, x, y, selection,
                              targetType, time):
        logging.debug('ClipboardTray: got data for target %r',
            selection.target)

        object_id = self._context_map.get_object_id(context)
        try:
            if selection is None:
                logging.warn('ClipboardTray: empty selection for target %s',
                    selection.target)
            elif selection.target == 'XdndDirectSave0':
                if selection.data == 'S':
                    window = context.source_window

                    prop_type, format_, dest = window.property_get(
                        'XdndDirectSave0', 'text/plain')

                    clipboardservice = clipboard.get_instance()
                    clipboardservice.add_object_format(object_id,
                                                       'XdndDirectSave0',
                                                       dest, on_disk=True)
            else:
                self._add_selection(object_id, selection)

        finally:
            # If it's the last target to be processed, finish
            # the dnd transaction
            if not self._context_map.has_context(context):
                context.drop_finish(True, gtk.get_current_event_time())
Esempio n. 11
0
    def _add_selection(self, key, selection):
        if not selection.get_data():
            logging.warning('no data for selection target %s.',
                            selection.get_data_type())
            return

        selection_type = str(selection.get_data_type())
        logging.debug('adding type ' + selection_type + '.')

        cb_service = clipboard.get_instance()
        if selection_type == 'text/uri-list':
            uris = selection.get_uris()

            if len(uris) > 1:
                raise NotImplementedError('Multiple uris in text/uri-list'
                                          ' still not supported.')
            uri = uris[0]
            scheme, netloc_, path_, parameters_, query_, fragment_ = \
                urlparse(uri)
            on_disk = (scheme == 'file')

            cb_service.add_object_format(key, selection_type, uri, on_disk)
        else:
            cb_service.add_object_format(key,
                                         selection_type,
                                         selection.get_data(),
                                         on_disk=False)
    def _add_selection(self, key, selection):
        if not selection.data:
            logging.warning('no data for selection target %s.', selection.type)
            return

        logging.debug('adding type ' + selection.type + '.')

        cb_service = clipboard.get_instance()
        if selection.type == 'text/uri-list':
            uris = selection.get_uris()

            if len(uris) > 1:
                raise NotImplementedError('Multiple uris in text/uri-list' \
                                          ' still not supported.')
            uri = uris[0]
            scheme, netloc_, path_, parameters_, query_, fragment_ = \
                    urlparse(uri)
            on_disk = (scheme == 'file')

            cb_service.add_object_format(key,
                                         selection.type,
                                         uri,
                                         on_disk)
        else:
            cb_service.add_object_format(key,
                                         selection.type,
                                         selection.data,
                                         on_disk=False)
Esempio n. 13
0
    def __init__(self, cb_object):
        Palette.__init__(self, text_maxlen=100)

        self._cb_object = cb_object

        self.set_group_id('frame')

        cb_service = clipboard.get_instance()
        cb_service.connect('object-state-changed',
                           self._object_state_changed_cb)

        self._remove_item = MenuItem(pgettext('Clipboard', 'Remove'),
                                     'list-remove')
        self._remove_item.connect('activate', self._remove_item_activate_cb)
        self.menu.append(self._remove_item)
        self._remove_item.show()

        self._open_item = MenuItem(_('Open'), 'zoom-activity')
        self._open_item.connect('activate', self._open_item_activate_cb)
        self.menu.append(self._open_item)
        self._open_item.show()

        self._journal_item = MenuItem(_('Keep'))
        color = profile.get_color()
        icon = Icon(icon_name='document-save',
                    pixel_size=style.SMALL_ICON_SIZE,
                    xo_color=color)
        self._journal_item.set_image(icon)

        self._journal_item.connect('activate', self._journal_item_activate_cb)
        self.menu.append(self._journal_item)
        self._journal_item.show()

        self._update()
Esempio n. 14
0
    def __init__(self, cb_object, group):
        RadioToolButton.__init__(self, group=group)

        self.props.palette_invoker = FrameWidgetInvoker(self)
        self.palette_invoker.props.toggle_palette = True

        self._cb_object = cb_object
        self.owns_clipboard = False
        self.props.sensitive = False
        self.props.active = False
        self._notif_icon = None
        self._current_percent = None

        self._icon = Icon()
        color = profile.get_color()
        self._icon.props.xo_color = color
        self.set_icon_widget(self._icon)
        self._icon.show()

        cb_service = clipboard.get_instance()
        cb_service.connect('object-state-changed',
                           self._object_state_changed_cb)
        cb_service.connect('object-selected', self._object_selected_cb)

        child = self.get_child()
        child.connect('drag_data_get', self._drag_data_get_cb)
        self.connect('notify::active', self._notify_active_cb)
Esempio n. 15
0
    def _add_selection(self, object_id, selection):
        if not selection.get_data():
            return

        selection_data = selection.get_data()

        selection_type_atom = selection.get_data_type()
        selection_type = selection_type_atom.name()

        logging.debug('ClipboardTray: adding type %r', selection_type)

        cb_service = clipboard.get_instance()
        if selection_type == 'text/uri-list':
            uris = selection.get_uris()
            if len(uris) > 1:
                raise NotImplementedError('Multiple uris in text/uri-list'
                                          ' still not supported.')

            cb_service.add_object_format(object_id,
                                         selection_type,
                                         uris[0],
                                         on_disk=True)
        else:
            cb_service.add_object_format(object_id,
                                         selection_type,
                                         selection_data,
                                         on_disk=False)
Esempio n. 16
0
    def __init__(self):
        tray.VTray.__init__(self, align=tray.ALIGN_TO_END)
        self._icons = {}
        self._context_map = _ContextMap()

        cb_service = clipboard.get_instance()
        cb_service.connect('object-added', self._object_added_cb)
        cb_service.connect('object-deleted', self._object_deleted_cb)
Esempio n. 17
0
    def __init__(self):
        tray.VTray.__init__(self, align=tray.ALIGN_TO_END)
        self._icons = {}
        self._context_map = _ContextMap()

        cb_service = clipboard.get_instance()
        cb_service.connect('object-added', self._object_added_cb)
        cb_service.connect('object-deleted', self._object_deleted_cb)
Esempio n. 18
0
    def _object_added_cb(self, cb_service, cb_object):
        if self._icons:
            group = list(self._icons.values())[0]
        else:
            group = None

        icon = ClipboardIcon(cb_object, group)
        self.add_item(icon)
        icon.show()
        self._icons[cb_object.get_id()] = icon

        objects_to_delete = self.get_children()[:-self.MAX_ITEMS]
        for icon in objects_to_delete:
            logging.debug('ClipboardTray: deleting surplus object')
            cb_service = clipboard.get_instance()
            cb_service.delete_object(icon.get_object_id())

        logging.debug('ClipboardTray: %r was added', cb_object.get_id())
Esempio n. 19
0
    def _object_added_cb(self, cb_service, cb_object):
        if self._icons:
            group = self._icons.values()[0]
        else:
            group = None

        icon = ClipboardIcon(cb_object, group)
        self.add_item(icon)
        icon.show()
        self._icons[cb_object.get_id()] = icon

        objects_to_delete = self.get_children()[:-self.MAX_ITEMS]
        for icon in objects_to_delete:
            logging.debug('ClipboardTray: deleting surplus object')
            cb_service = clipboard.get_instance()
            cb_service.delete_object(icon.get_object_id())

        logging.debug('ClipboardTray: %r was added', cb_object.get_id())
Esempio n. 20
0
    def _owner_change_cb(self, x_clipboard, event):
        logging.debug('owner_change_cb')

        if self._clipboard_tray.owns_clipboard():
            return

        cb_service = clipboard.get_instance()

        result, targets = x_clipboard.wait_for_targets()
        cb_selections = []
        if not result:
            return

        target_is_uri = False
        for target in targets:
            if target not in ('TIMESTAMP', 'TARGETS', 'MULTIPLE',
                              'SAVE_TARGETS'):
                logging.debug('Asking for target %s.', target)
                if target == 'text/uri-list':
                    target_is_uri = True

                selection = x_clipboard.wait_for_contents(target)
                if not selection:
                    logging.warning('no data for selection target %s.', target)
                    continue
                cb_selections.append(selection)

        if target_is_uri:
            uri = selection.get_uris()[0]
            filename = uri[len('file://'):].strip()
            md5 = self._md5_for_file(filename)
            data_hash = hash(md5)
        else:
            data_hash = hash(selection.get_data())

        if len(cb_selections) > 0:
            key = cb_service.add_object(name="", data_hash=data_hash)
            if key is None:
                return
            cb_service.set_object_percent(key, percent=0)
            for selection in cb_selections:
                self._add_selection(key, selection)
            cb_service.set_object_percent(key, percent=100)
    def _owner_change_cb(self, x_clipboard, event):
        logging.debug('owner_change_cb')

        if self._clipboard_tray.owns_clipboard():
            return

        cb_service = clipboard.get_instance()

        targets = x_clipboard.wait_for_targets()
        cb_selections = []
        if targets is None:
            return

        target_is_uri = False
        for target in targets:
            if target not in ('TIMESTAMP', 'TARGETS',
                              'MULTIPLE', 'SAVE_TARGETS'):
                logging.debug('Asking for target %s.', target)
                if target == 'text/uri-list':
                    target_is_uri = True

                selection = x_clipboard.wait_for_contents(target)
                if not selection:
                    logging.warning('no data for selection target %s.', target)
                    continue
                cb_selections.append(selection)

        if target_is_uri:
            uri = selection.data
            filename = uri[len('file://'):].strip()
            md5 = self._md5_for_file(filename)
            data_hash = hash(md5)
        else:
            data_hash = hash(selection.data)

        if len(cb_selections) > 0:
            key = cb_service.add_object(name="", data_hash=data_hash)
            if key is None:
                return
            cb_service.set_object_percent(key, percent=0)
            for selection in cb_selections:
                self._add_selection(key, selection)
            cb_service.set_object_percent(key, percent=100)
Esempio n. 22
0
    def drag_drop_cb(self, widget, context, x, y, time):
        logging.debug('ClipboardTray._drag_drop_cb')

        if self._internal_drag(context):
            # TODO: We should move the object within the clipboard here
            if not self._context_map.has_context(context):
                context.drop_finish(False, Gtk.get_current_event_time())
            return False

        cb_service = clipboard.get_instance()
        object_id = cb_service.add_object(name="")

        self._context_map.add_context(context, object_id, len(context.targets))

        for target in context.targets:
            if str(target) not in ('TIMESTAMP', 'TARGETS', 'MULTIPLE'):
                widget.drag_get_data(context, target, time)

        cb_service.set_object_percent(object_id, percent=100)

        return True
Esempio n. 23
0
    def drag_drop_cb(self, widget, context, x, y, time):
        logging.debug('ClipboardTray._drag_drop_cb')

        if self._internal_drag(context):
            # TODO: We should move the object within the clipboard here
            if not self._context_map.has_context(context):
                context.drop_finish(False, gtk.get_current_event_time())
            return False

        cb_service = clipboard.get_instance()
        object_id = cb_service.add_object(name="")

        self._context_map.add_context(context, object_id, len(context.targets))

        if 'XdndDirectSave0' in context.targets:
            window = context.source_window
            prop_type, format_, filename = \
                window.property_get('XdndDirectSave0', 'text/plain')

            # FIXME query the clipboard service for a filename?
            base_dir = tempfile.gettempdir()
            dest_filename = util.unique_id()

            name_, dot, extension = filename.rpartition('.')
            dest_filename += dot + extension

            dest_uri = 'file://' + os.path.join(base_dir, dest_filename)

            window.property_change('XdndDirectSave0', prop_type, format_,
                                   gtk.gdk.PROP_MODE_REPLACE, dest_uri)

            widget.drag_get_data(context, 'XdndDirectSave0', time)
        else:
            for target in context.targets:
                if str(target) not in ('TIMESTAMP', 'TARGETS', 'MULTIPLE'):
                    widget.drag_get_data(context, target, time)

        cb_service.set_object_percent(object_id, percent=100)

        return True
Esempio n. 24
0
    def drag_drop_cb(self, widget, context, x, y, time):
        logging.debug('ClipboardTray._drag_drop_cb')

        if self._internal_drag(context):
            # TODO: We should move the object within the clipboard here
            if not self._context_map.has_context(context):
                context.drop_finish(False, gtk.get_current_event_time())
            return False

        cb_service = clipboard.get_instance()
        object_id = cb_service.add_object(name="")

        self._context_map.add_context(context, object_id, len(context.targets))

        if 'XdndDirectSave0' in context.targets:
            window = context.source_window
            prop_type, format_, filename = \
                window.property_get('XdndDirectSave0', 'text/plain')

            # FIXME query the clipboard service for a filename?
            base_dir = tempfile.gettempdir()
            dest_filename = util.unique_id()

            name_, dot, extension = filename.rpartition('.')
            dest_filename += dot + extension

            dest_uri = 'file://' + os.path.join(base_dir, dest_filename)

            window.property_change('XdndDirectSave0', prop_type, format_,
                                   gtk.gdk.PROP_MODE_REPLACE, dest_uri)

            widget.drag_get_data(context, 'XdndDirectSave0', time)
        else:
            for target in context.targets:
                if str(target) not in ('TIMESTAMP', 'TARGETS', 'MULTIPLE'):
                    widget.drag_get_data(context, target, time)

        cb_service.set_object_percent(object_id, percent=100)

        return True
Esempio n. 25
0
    def _add_selection(self, object_id, selection):
        if not selection.data:
            return

        logging.debug('ClipboardTray: adding type %r', selection.type)

        cb_service = clipboard.get_instance()
        if selection.type == 'text/uri-list':
            uris = selection.data.split('\n')
            if len(uris) > 1:
                raise NotImplementedError('Multiple uris in text/uri-list' \
                                          ' still not supported.')

            cb_service.add_object_format(object_id,
                                         selection.type,
                                         uris[0],
                                         on_disk=True)
        else:
            cb_service.add_object_format(object_id,
                                         selection.type,
                                         selection.data,
                                         on_disk=False)
Esempio n. 26
0
    def _add_selection(self, object_id, selection):
        if not selection.get_data():
            return

        selection_data = selection.get_data()

        selection_type_atom = selection.get_data_type()
        selection_type = selection_type_atom.name()

        logging.debug('ClipboardTray: adding type %r', selection_type)

        cb_service = clipboard.get_instance()
        if selection_type == 'text/uri-list':
            uris = selection.get_uris()
            if len(uris) > 1:
                raise NotImplementedError('Multiple uris in text/uri-list'
                                          ' still not supported.')
            file_name = uris[0]
            buddies = neighborhood.get_model().get_buddies()
            mime_type = mime.get_for_file(file_name)
            title = os.path.basename(file_name)
            dialog = Gtk.MessageDialog(None, Gtk.DialogFlags.MODAL, Gtk.MessageType.INFO, Gtk.ButtonsType.YES_NO, "Do you want to start file transfer ?")
            response = dialog.run()
            dialog.destroy()
            if response == Gtk.ResponseType.YES:
                for buddy in buddies:
                    if buddy != get_owner_instance():
                        filetransfer.start_transfer(buddy, file_name, title, "dummy", mime_type)
            cb_service.add_object_format(object_id,
                                         selection_type,
                                         uris[0],
                                         on_disk=True)
        else:
            cb_service.add_object_format(object_id,
                                         selection_type,
                                         selection_data,
                                         on_disk=False)
Esempio n. 27
0
 def _remove_item_activate_cb(self, menu_item):
     cb_service = clipboard.get_instance()
     cb_service.delete_object(self._cb_object.get_id())
Esempio n. 28
0
 def _remove_item_activate_cb(self, menu_item):
     cb_service = clipboard.get_instance()
     cb_service.delete_object(self._cb_object.get_id())