2007-04-17 21:53:34 +02:00
|
|
|
import os
|
|
|
|
import logging
|
2007-06-17 14:24:46 +02:00
|
|
|
import urlparse
|
2007-04-17 21:53:34 +02:00
|
|
|
|
2007-04-11 18:22:52 +02:00
|
|
|
import typeregistry
|
|
|
|
|
2006-12-13 22:36:05 +01:00
|
|
|
class ClipboardObject:
|
2007-04-11 18:22:52 +02:00
|
|
|
|
2007-03-14 05:50:06 +01:00
|
|
|
def __init__(self, object_path, name):
|
|
|
|
self._id = object_path
|
2006-12-13 22:36:05 +01:00
|
|
|
self._name = name
|
|
|
|
self._percent = 0
|
|
|
|
self._formats = {}
|
2007-03-14 05:50:06 +01:00
|
|
|
|
2007-04-17 21:53:34 +02:00
|
|
|
def destroy(self):
|
|
|
|
for type, format in self._formats.iteritems():
|
|
|
|
format.destroy()
|
|
|
|
|
2006-12-13 22:36:05 +01:00
|
|
|
def get_id(self):
|
|
|
|
return self._id
|
2007-01-05 21:13:46 +01:00
|
|
|
|
2007-04-11 18:22:52 +02:00
|
|
|
def _get_type_info(self):
|
|
|
|
type_registry = typeregistry.get_instance()
|
|
|
|
return type_registry.get_type(self._formats)
|
|
|
|
|
2006-12-13 22:36:05 +01:00
|
|
|
def get_name(self):
|
2007-04-11 18:22:52 +02:00
|
|
|
if self._name:
|
|
|
|
return self._name
|
|
|
|
else:
|
|
|
|
return self._get_type_info().get_name()
|
|
|
|
|
|
|
|
def get_icon(self):
|
|
|
|
return self._get_type_info().get_icon()
|
|
|
|
|
|
|
|
def get_preview(self):
|
|
|
|
return self._get_type_info().get_preview()
|
|
|
|
|
|
|
|
def get_activity(self):
|
|
|
|
return self._get_type_info().get_activity()
|
2007-01-05 21:13:46 +01:00
|
|
|
|
2006-12-13 22:36:05 +01:00
|
|
|
def get_percent(self):
|
|
|
|
return self._percent
|
|
|
|
|
|
|
|
def set_percent(self, percent):
|
|
|
|
self._percent = percent
|
|
|
|
|
|
|
|
def add_format(self, format):
|
|
|
|
self._formats[format.get_type()] = format
|
|
|
|
|
|
|
|
def get_formats(self):
|
|
|
|
return self._formats
|
2007-01-05 21:13:46 +01:00
|
|
|
|
2006-12-13 22:36:05 +01:00
|
|
|
class Format:
|
2007-04-11 18:22:52 +02:00
|
|
|
|
2006-12-13 22:36:05 +01:00
|
|
|
def __init__(self, type, data, on_disk):
|
|
|
|
self._type = type
|
|
|
|
self._data = data
|
|
|
|
self._on_disk = on_disk
|
|
|
|
|
2007-04-17 21:53:34 +02:00
|
|
|
def destroy(self):
|
|
|
|
if self._on_disk:
|
2007-06-17 14:24:46 +02:00
|
|
|
uri = urlparse.urlparse(self._data)
|
|
|
|
os.remove(uri.path)
|
2007-04-17 21:53:34 +02:00
|
|
|
|
2006-12-13 22:36:05 +01:00
|
|
|
def get_type(self):
|
|
|
|
return self._type
|
|
|
|
|
|
|
|
def get_data(self):
|
|
|
|
return self._data
|
2007-03-14 18:04:10 +01:00
|
|
|
|
|
|
|
def _set_data(self, data):
|
|
|
|
self._data = data
|
|
|
|
|
2007-06-17 20:55:16 +02:00
|
|
|
def is_on_disk(self):
|
2007-03-14 18:04:10 +01:00
|
|
|
return self._on_disk
|