Reverting clipboard changes pushed by mistake. These are commits 23565cfd48
and a7e4092b0e
.
parent
d958e20df7
commit
61f24de748
@ -0,0 +1,56 @@
|
|||||||
|
#include "sugar-marshal.h"
|
||||||
|
#include "sugar-browser-chandler.h"
|
||||||
|
|
||||||
|
enum {
|
||||||
|
HANDLE_CONTENT,
|
||||||
|
LAST_SIGNAL
|
||||||
|
};
|
||||||
|
static guint signals[LAST_SIGNAL] = { 0 };
|
||||||
|
|
||||||
|
G_DEFINE_TYPE(SugarBrowserChandler, sugar_browser_chandler, G_TYPE_OBJECT)
|
||||||
|
|
||||||
|
SugarBrowserChandler *browserChandler = NULL;
|
||||||
|
|
||||||
|
static void
|
||||||
|
sugar_browser_chandler_init(SugarBrowserChandler *browserChandler)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
sugar_browser_chandler_class_init(SugarBrowserChandlerClass *browser_chandler_class)
|
||||||
|
{
|
||||||
|
signals[HANDLE_CONTENT] =
|
||||||
|
g_signal_new ("handle-content",
|
||||||
|
G_OBJECT_CLASS_TYPE (browser_chandler_class),
|
||||||
|
G_SIGNAL_RUN_LAST,
|
||||||
|
G_STRUCT_OFFSET (SugarBrowserChandlerClass, handle_content),
|
||||||
|
NULL, NULL,
|
||||||
|
sugar_marshal_VOID__STRING_STRING_STRING,
|
||||||
|
G_TYPE_NONE, 3,
|
||||||
|
G_TYPE_STRING,
|
||||||
|
G_TYPE_STRING,
|
||||||
|
G_TYPE_STRING);
|
||||||
|
}
|
||||||
|
|
||||||
|
SugarBrowserChandler *
|
||||||
|
sugar_get_browser_chandler()
|
||||||
|
{
|
||||||
|
if(browserChandler == NULL)
|
||||||
|
browserChandler = g_object_new(SUGAR_TYPE_BROWSER_CHANDLER, NULL);
|
||||||
|
|
||||||
|
return browserChandler;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
sugar_browser_chandler_handle_content (SugarBrowserChandler *browser_chandler,
|
||||||
|
const char *url,
|
||||||
|
const char *mime_type,
|
||||||
|
const char *tmp_file_name)
|
||||||
|
{
|
||||||
|
g_signal_emit(browser_chandler,
|
||||||
|
signals[HANDLE_CONTENT],
|
||||||
|
0 /* details */,
|
||||||
|
url,
|
||||||
|
mime_type,
|
||||||
|
tmp_file_name);
|
||||||
|
}
|
@ -0,0 +1,39 @@
|
|||||||
|
#ifndef __SUGAR_BROWSER_CHANDLER_H__
|
||||||
|
#define __SUGAR_BROWSER_CHANDLER_H__
|
||||||
|
|
||||||
|
#include <glib-object.h>
|
||||||
|
#include <glib.h>
|
||||||
|
|
||||||
|
G_BEGIN_DECLS
|
||||||
|
|
||||||
|
typedef struct _SugarBrowserChandler SugarBrowserChandler;
|
||||||
|
typedef struct _SugarBrowserChandlerClass SugarBrowserChandlerClass;
|
||||||
|
|
||||||
|
#define SUGAR_TYPE_BROWSER_CHANDLER (sugar_browser_chandler_get_type())
|
||||||
|
#define SUGAR_BROWSER_CHANDLER(object) (G_TYPE_CHECK_INSTANCE_CAST((object), SUGAR_TYPE_BROWSER_CHANDLER, SugarBrowserChandler))
|
||||||
|
#define SUGAR_BROWSER_CHANDLER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), SUGAR_TYPE_BROWSER_CHANDLER, SugarBrowserChandlerClass))
|
||||||
|
#define SUGAR_IS_BROWSER_CHANDLER(object) (G_TYPE_CHECK_INSTANCE_TYPE((object), SUGAR_TYPE_BROWSER_CHANDLER))
|
||||||
|
#define SUGAR_IS_BROWSER_CHANDLER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), SUGAR_TYPE_BROWSER_CHANDLER))
|
||||||
|
#define SUGAR_BROWSER_CHANDLER_GET_CLASS(object) (G_TYPE_INSTANCE_GET_CLASS((object), SUGAR_TYPE_BROWSER_CHANDLER, SugarBrowserChandlerClass))
|
||||||
|
|
||||||
|
struct _SugarBrowserChandler {
|
||||||
|
GObject base_instance;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct _SugarBrowserChandlerClass {
|
||||||
|
GObjectClass base_class;
|
||||||
|
|
||||||
|
void (* handle_content) (char *url, char *tmp_file_name);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
GType sugar_browser_chandler_get_type (void);
|
||||||
|
SugarBrowserChandler *sugar_get_browser_chandler (void);
|
||||||
|
void sugar_browser_chandler_handle_content (SugarBrowserChandler *chandler,
|
||||||
|
const char *url,
|
||||||
|
const char *mime_type,
|
||||||
|
const char *tmp_file_name);
|
||||||
|
|
||||||
|
G_END_DECLS
|
||||||
|
|
||||||
|
#endif
|
@ -1,121 +0,0 @@
|
|||||||
#include "sugar-marshal.h"
|
|
||||||
#include "sugar-download-manager.h"
|
|
||||||
|
|
||||||
enum {
|
|
||||||
DOWNLOAD_STARTED,
|
|
||||||
DOWNLOAD_COMPLETED,
|
|
||||||
DOWNLOAD_CANCELLED,
|
|
||||||
DOWNLOAD_PROGRESS,
|
|
||||||
LAST_SIGNAL
|
|
||||||
};
|
|
||||||
static guint signals[LAST_SIGNAL] = { 0 };
|
|
||||||
|
|
||||||
G_DEFINE_TYPE(SugarDownloadManager, sugar_download_manager, G_TYPE_OBJECT)
|
|
||||||
|
|
||||||
SugarDownloadManager *DownloadManager = NULL;
|
|
||||||
|
|
||||||
static void
|
|
||||||
sugar_download_manager_init(SugarDownloadManager *DownloadManager)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
sugar_download_manager_class_init(SugarDownloadManagerClass *download_manager_class)
|
|
||||||
{
|
|
||||||
signals[DOWNLOAD_STARTED] =
|
|
||||||
g_signal_new ("download-started",
|
|
||||||
G_OBJECT_CLASS_TYPE (download_manager_class),
|
|
||||||
G_SIGNAL_RUN_LAST,
|
|
||||||
G_STRUCT_OFFSET (SugarDownloadManagerClass, handle_content),
|
|
||||||
NULL, NULL,
|
|
||||||
sugar_marshal_VOID__STRING_STRING_STRING,
|
|
||||||
G_TYPE_NONE, 3,
|
|
||||||
G_TYPE_STRING,
|
|
||||||
G_TYPE_STRING,
|
|
||||||
G_TYPE_STRING);
|
|
||||||
|
|
||||||
signals[DOWNLOAD_COMPLETED] =
|
|
||||||
g_signal_new ("download-completed",
|
|
||||||
G_OBJECT_CLASS_TYPE (download_manager_class),
|
|
||||||
G_SIGNAL_RUN_LAST,
|
|
||||||
G_STRUCT_OFFSET (SugarDownloadManagerClass, handle_content),
|
|
||||||
NULL, NULL,
|
|
||||||
sugar_marshal_VOID__STRING,
|
|
||||||
G_TYPE_NONE, 1,
|
|
||||||
G_TYPE_STRING);
|
|
||||||
|
|
||||||
signals[DOWNLOAD_CANCELLED] =
|
|
||||||
g_signal_new ("download-cancelled",
|
|
||||||
G_OBJECT_CLASS_TYPE (download_manager_class),
|
|
||||||
G_SIGNAL_RUN_LAST,
|
|
||||||
G_STRUCT_OFFSET (SugarDownloadManagerClass, handle_content),
|
|
||||||
NULL, NULL,
|
|
||||||
sugar_marshal_VOID__STRING,
|
|
||||||
G_TYPE_NONE, 1,
|
|
||||||
G_TYPE_STRING);
|
|
||||||
|
|
||||||
signals[DOWNLOAD_PROGRESS] =
|
|
||||||
g_signal_new ("download-progress",
|
|
||||||
G_OBJECT_CLASS_TYPE (download_manager_class),
|
|
||||||
G_SIGNAL_RUN_LAST,
|
|
||||||
G_STRUCT_OFFSET (SugarDownloadManagerClass, handle_content),
|
|
||||||
NULL, NULL,
|
|
||||||
sugar_marshal_VOID__STRING_INT,
|
|
||||||
G_TYPE_NONE, 2,
|
|
||||||
G_TYPE_STRING,
|
|
||||||
G_TYPE_INT);
|
|
||||||
}
|
|
||||||
|
|
||||||
SugarDownloadManager *
|
|
||||||
sugar_get_download_manager()
|
|
||||||
{
|
|
||||||
if(DownloadManager == NULL)
|
|
||||||
DownloadManager = g_object_new(SUGAR_TYPE_DOWNLOAD_MANAGER, NULL);
|
|
||||||
|
|
||||||
return DownloadManager;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
sugar_download_manager_download_started (SugarDownloadManager *download_manager,
|
|
||||||
const char *url,
|
|
||||||
const char *mime_type,
|
|
||||||
const char *tmp_file_name)
|
|
||||||
{
|
|
||||||
g_signal_emit(download_manager,
|
|
||||||
signals[DOWNLOAD_STARTED],
|
|
||||||
0 /* details */,
|
|
||||||
url,
|
|
||||||
mime_type,
|
|
||||||
tmp_file_name);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
sugar_download_manager_download_completed (SugarDownloadManager *download_manager,
|
|
||||||
const char *tmp_file_name)
|
|
||||||
{
|
|
||||||
g_signal_emit(download_manager,
|
|
||||||
signals[DOWNLOAD_COMPLETED],
|
|
||||||
0 /* details */,
|
|
||||||
tmp_file_name);
|
|
||||||
}
|
|
||||||
|
|
||||||
void sugar_download_manager_download_cancelled (SugarDownloadManager *download_manager,
|
|
||||||
const char *tmp_file_name)
|
|
||||||
{
|
|
||||||
g_signal_emit(download_manager,
|
|
||||||
signals[DOWNLOAD_CANCELLED],
|
|
||||||
0 /* details */,
|
|
||||||
tmp_file_name);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
sugar_download_manager_update_progress (SugarDownloadManager *download_manager,
|
|
||||||
const char *tmp_file_name,
|
|
||||||
const int percent)
|
|
||||||
{
|
|
||||||
g_signal_emit(download_manager,
|
|
||||||
signals[DOWNLOAD_PROGRESS],
|
|
||||||
0 /* details */,
|
|
||||||
tmp_file_name,
|
|
||||||
percent);
|
|
||||||
}
|
|
@ -1,55 +0,0 @@
|
|||||||
#ifndef __SUGAR_DOWNLOAD_MANAGER_H__
|
|
||||||
#define __SUGAR_DOWNLOAD_MANAGER_H__
|
|
||||||
|
|
||||||
#include <glib-object.h>
|
|
||||||
#include <glib.h>
|
|
||||||
|
|
||||||
G_BEGIN_DECLS
|
|
||||||
|
|
||||||
typedef struct _SugarDownloadManager SugarDownloadManager;
|
|
||||||
typedef struct _SugarDownloadManagerClass SugarDownloadManagerClass;
|
|
||||||
|
|
||||||
#define SUGAR_TYPE_DOWNLOAD_MANAGER (sugar_download_manager_get_type())
|
|
||||||
#define SUGAR_DOWNLOAD_MANAGER(object) (G_TYPE_CHECK_INSTANCE_CAST((object), SUGAR_TYPE_DOWNLOAD_MANAGER, SugarDownloadManager))
|
|
||||||
#define SUGAR_DOWNLOAD_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), SUGAR_TYPE_DOWNLOAD_MANAGER, SugarDownloadManagerClass))
|
|
||||||
#define SUGAR_IS_DOWNLOAD_MANAGER(object) (G_TYPE_CHECK_INSTANCE_TYPE((object), SUGAR_TYPE_DOWNLOAD_MANAGER))
|
|
||||||
#define SUGAR_IS_DOWNLOAD_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), SUGAR_TYPE_DOWNLOAD_MANAGER))
|
|
||||||
#define SUGAR_DOWNLOAD_MANAGER_GET_CLASS(object) (G_TYPE_INSTANCE_GET_CLASS((object), SUGAR_TYPE_DOWNLOAD_MANAGER, SugarDownloadManagerClass))
|
|
||||||
|
|
||||||
struct _SugarDownloadManager {
|
|
||||||
GObject base_instance;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct _SugarDownloadManagerClass {
|
|
||||||
GObjectClass base_class;
|
|
||||||
|
|
||||||
void (* handle_content) (char *url, char *tmp_file_name);
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
GType sugar_download_manager_get_type(void);
|
|
||||||
|
|
||||||
SugarDownloadManager *sugar_get_download_manager(void);
|
|
||||||
|
|
||||||
void sugar_download_manager_download_started(
|
|
||||||
SugarDownloadManager *download_manager,
|
|
||||||
const char *url,
|
|
||||||
const char *mime_type,
|
|
||||||
const char *tmp_file_name);
|
|
||||||
|
|
||||||
void sugar_download_manager_download_completed(
|
|
||||||
SugarDownloadManager *download_manager,
|
|
||||||
const char *tmp_file_name);
|
|
||||||
|
|
||||||
void sugar_download_manager_download_cancelled(
|
|
||||||
SugarDownloadManager *download_manager,
|
|
||||||
const char *tmp_file_name);
|
|
||||||
|
|
||||||
void sugar_download_manager_update_progress(
|
|
||||||
SugarDownloadManager *download_manager,
|
|
||||||
const char *tmp_file_name,
|
|
||||||
const int percent);
|
|
||||||
|
|
||||||
G_END_DECLS
|
|
||||||
|
|
||||||
#endif
|
|
@ -1 +1 @@
|
|||||||
SUBDIRS = presence nm clipboard
|
SUBDIRS = presence nm
|
||||||
|
@ -1,76 +0,0 @@
|
|||||||
# vi: ts=4 ai noet
|
|
||||||
#
|
|
||||||
# Copyright (C) 2006, Red Hat, Inc.
|
|
||||||
#
|
|
||||||
# This program is free software; you can redistribute it and/or modify
|
|
||||||
# it under the terms of the GNU General Public License as published by
|
|
||||||
# the Free Software Foundation; either version 2 of the License, or
|
|
||||||
# (at your option) any later version.
|
|
||||||
#
|
|
||||||
# This program is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU General Public License for more details.
|
|
||||||
#
|
|
||||||
# You should have received a copy of the GNU General Public License
|
|
||||||
# along with this program; if not, write to the Free Software
|
|
||||||
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
||||||
|
|
||||||
import logging
|
|
||||||
import gobject
|
|
||||||
import dbus
|
|
||||||
import dbus.service
|
|
||||||
from sugar import env
|
|
||||||
|
|
||||||
class ClipboardDBusServiceHelper(dbus.service.Object):
|
|
||||||
|
|
||||||
_CLIPBOARD_DBUS_INTERFACE = "org.laptop.Clipboard"
|
|
||||||
_CLIPBOARD_OBJECT_PATH = "/org/laptop/Clipboard"
|
|
||||||
|
|
||||||
def __init__(self, parent):
|
|
||||||
self._parent = parent
|
|
||||||
|
|
||||||
bus = dbus.SessionBus()
|
|
||||||
bus_name = dbus.service.BusName(self._CLIPBOARD_DBUS_INTERFACE, bus=bus)
|
|
||||||
dbus.service.Object.__init__(self, bus_name, self._CLIPBOARD_OBJECT_PATH)
|
|
||||||
|
|
||||||
@dbus.service.method(_CLIPBOARD_DBUS_INTERFACE,
|
|
||||||
in_signature="ss", out_signature="")
|
|
||||||
def add_object(self, mimeType, fileName):
|
|
||||||
self.object_added(mimeType, fileName)
|
|
||||||
logging.debug('Added object of type ' + mimeType + ' with path at ' + fileName)
|
|
||||||
|
|
||||||
@dbus.service.method(_CLIPBOARD_DBUS_INTERFACE,
|
|
||||||
in_signature="s", out_signature="")
|
|
||||||
def delete_object(self, fileName):
|
|
||||||
self.object_deleted(fileName)
|
|
||||||
logging.debug('Deleted object with path at ' + fileName)
|
|
||||||
|
|
||||||
@dbus.service.method(_CLIPBOARD_DBUS_INTERFACE,
|
|
||||||
in_signature="si", out_signature="")
|
|
||||||
def update_object_state(self, fileName, percent):
|
|
||||||
logging.debug('Updated object with path at ' + fileName + ' with percent ' + str(percent))
|
|
||||||
self.object_state_updated(fileName, percent)
|
|
||||||
|
|
||||||
@dbus.service.signal(_CLIPBOARD_DBUS_INTERFACE, signature="ss")
|
|
||||||
def object_added(self, mimeType, fileName):
|
|
||||||
pass
|
|
||||||
|
|
||||||
@dbus.service.signal(_CLIPBOARD_DBUS_INTERFACE, signature="s")
|
|
||||||
def object_deleted(self, fileName):
|
|
||||||
pass
|
|
||||||
|
|
||||||
@dbus.service.signal(_CLIPBOARD_DBUS_INTERFACE, signature="si")
|
|
||||||
def object_state_updated(self, fileName, percent):
|
|
||||||
pass
|
|
||||||
|
|
||||||
class ClipboardService(object):
|
|
||||||
def __init__(self):
|
|
||||||
self._dbus_helper = ClipboardDBusServiceHelper(self)
|
|
||||||
|
|
||||||
def run(self):
|
|
||||||
loop = gobject.MainLoop()
|
|
||||||
try:
|
|
||||||
loop.run()
|
|
||||||
except KeyboardInterrupt:
|
|
||||||
print 'Ctrl+C pressed, exiting...'
|
|
@ -1,15 +0,0 @@
|
|||||||
servicedir = $(datadir)/sugar/services
|
|
||||||
service_in_files = org.laptop.Clipboard.service.in
|
|
||||||
service_DATA = $(service_in_files:.service.in=.service)
|
|
||||||
|
|
||||||
$(service_DATA): $(service_in_files) Makefile
|
|
||||||
@sed -e "s|\@bindir\@|$(bindir)|" $< > $@
|
|
||||||
|
|
||||||
sugardir = $(pkgdatadir)/services/clipboard
|
|
||||||
sugar_PYTHON = \
|
|
||||||
__init__.py \
|
|
||||||
ClipboardService.py
|
|
||||||
|
|
||||||
bin_SCRIPTS = sugar-clipboard
|
|
||||||
|
|
||||||
EXTRA_DIST = $(service_in_files) $(bin_SCRIPTS)
|
|
@ -1,4 +0,0 @@
|
|||||||
[D-BUS Service]
|
|
||||||
Name = org.laptop.Clipboard
|
|
||||||
Exec = @bindir@/sugar-clipboard
|
|
||||||
|
|
@ -1,44 +0,0 @@
|
|||||||
#!/usr/bin/python
|
|
||||||
# vi: ts=4 ai noet
|
|
||||||
#
|
|
||||||
# Copyright (C) 2006, Red Hat, Inc.
|
|
||||||
#
|
|
||||||
# This program is free software; you can redistribute it and/or modify
|
|
||||||
# it under the terms of the GNU General Public License as published by
|
|
||||||
# the Free Software Foundation; either version 2 of the License, or
|
|
||||||
# (at your option) any later version.
|
|
||||||
#
|
|
||||||
# This program is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU General Public License for more details.
|
|
||||||
#
|
|
||||||
# You should have received a copy of the GNU General Public License
|
|
||||||
# along with this program; if not, write to the Free Software
|
|
||||||
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
||||||
|
|
||||||
import sys
|
|
||||||
import logging
|
|
||||||
|
|
||||||
from sugar import logger
|
|
||||||
logger.start('clipboard')
|
|
||||||
|
|
||||||
import gobject
|
|
||||||
import pygtk
|
|
||||||
pygtk.require('2.0')
|
|
||||||
|
|
||||||
import dbus.glib
|
|
||||||
|
|
||||||
from sugar import env
|
|
||||||
|
|
||||||
sys.path.insert(0, env.get_services_dir())
|
|
||||||
|
|
||||||
from clipboard.ClipboardService import ClipboardService
|
|
||||||
|
|
||||||
logging.info('Starting clipboard service.')
|
|
||||||
|
|
||||||
gobject.threads_init()
|
|
||||||
dbus.glib.threads_init()
|
|
||||||
|
|
||||||
app = ClipboardService()
|
|
||||||
app.run()
|
|
@ -1,37 +0,0 @@
|
|||||||
from sugar.graphics.menuicon import MenuIcon
|
|
||||||
from view.ClipboardMenu import ClipboardMenu
|
|
||||||
from sugar.activity import ActivityFactory
|
|
||||||
from sugar.clipboard import ClipboardService
|
|
||||||
|
|
||||||
class ClipboardIcon(MenuIcon):
|
|
||||||
|
|
||||||
def __init__(self, menu_shell, file_name):
|
|
||||||
MenuIcon.__init__(self, menu_shell, icon_name='activity-xbook')
|
|
||||||
self._file_name = file_name
|
|
||||||
self._percent = 0
|
|
||||||
self.connect('activated', self._icon_activated_cb)
|
|
||||||
self._menu = None
|
|
||||||
|
|
||||||
def create_menu(self):
|
|
||||||
self._menu = ClipboardMenu(self._file_name, self._percent)
|
|
||||||
self._menu.connect('action', self._popup_action_cb)
|
|
||||||
return self._menu
|
|
||||||
|
|
||||||
def set_percent(self, percent):
|
|
||||||
self._percent = percent
|
|
||||||
if self._menu:
|
|
||||||
self._menu.set_percent(percent)
|
|
||||||
|
|
||||||
def _icon_activated_cb(self, icon):
|
|
||||||
if self._percent == 100:
|
|
||||||
activity = ActivityFactory.create("org.laptop.sugar.Xbook")
|
|
||||||
activity.execute("open_document", [self._file_name])
|
|
||||||
|
|
||||||
def _popup_action_cb(self, popup, action):
|
|
||||||
self.popdown()
|
|
||||||
|
|
||||||
if action == ClipboardMenu.ACTION_STOP_DOWNLOAD:
|
|
||||||
raise "Stopping downloads still not implemented."
|
|
||||||
elif action == ClipboardMenu.ACTION_DELETE:
|
|
||||||
cb_service = ClipboardService.get_instance()
|
|
||||||
cb_service.delete_object(self._file_name)
|
|
@ -1,74 +0,0 @@
|
|||||||
import gtk
|
|
||||||
import gobject
|
|
||||||
import hippo
|
|
||||||
|
|
||||||
from sugar.graphics.menu import Menu
|
|
||||||
from sugar.graphics.canvasicon import CanvasIcon
|
|
||||||
from sugar.graphics.ClipboardBubble import ClipboardBubble
|
|
||||||
from sugar.graphics import style
|
|
||||||
|
|
||||||
clipboard_bubble = {
|
|
||||||
'fill-color' : 0x646464FF,
|
|
||||||
'stroke-color' : 0x646464FF,
|
|
||||||
'progress-color': 0x333333FF,
|
|
||||||
'spacing' : style.space_unit,
|
|
||||||
'padding' : style.space_unit * 1.5
|
|
||||||
}
|
|
||||||
|
|
||||||
clipboard_menu_item_title = {
|
|
||||||
'xalign': hippo.ALIGNMENT_START,
|
|
||||||
'padding-left': 5,
|
|
||||||
'color' : 0xFFFFFFFF,
|
|
||||||
'font' : style.get_font_description('Bold', 1.2)
|
|
||||||
}
|
|
||||||
|
|
||||||
style.register_stylesheet("clipboard.Bubble", clipboard_bubble)
|
|
||||||
style.register_stylesheet("clipboard.MenuItem.Title", clipboard_menu_item_title)
|
|
||||||
|
|
||||||
class ClipboardMenuItem(ClipboardBubble):
|
|
||||||
|
|
||||||
def __init__(self, percent = 0, stylesheet="clipboard.Bubble"):
|
|
||||||
ClipboardBubble.__init__(self, percent = percent)
|
|
||||||
style.apply_stylesheet(self, stylesheet)
|
|
||||||
|
|
||||||
class ClipboardMenu(Menu):
|
|
||||||
|
|
||||||
ACTION_DELETE = 0
|
|
||||||
ACTION_SHARE = 1
|
|
||||||
ACTION_STOP_DOWNLOAD = 2
|
|
||||||
|
|
||||||
def __init__(self, file_name, percent):
|
|
||||||
Menu.__init__(self, file_name)
|
|
||||||
|
|
||||||
self._progress_bar = ClipboardMenuItem(percent)
|
|
||||||
self._root.append(self._progress_bar)
|
|
||||||
|
|
||||||
#icon = CanvasIcon(icon_name='stock-share-mesh')
|
|
||||||
#self.add_action(icon, ClipboardMenu.ACTION_SHARE)
|
|
||||||
|
|
||||||
self._remove_icon = None
|
|
||||||
self._stop_icon = None
|
|
||||||
|
|
||||||
self._create_icons(percent)
|
|
||||||
|
|
||||||
def _create_icons(self, percent):
|
|
||||||
if percent == 100:
|
|
||||||
if not self._remove_icon:
|
|
||||||
self._remove_icon = CanvasIcon(icon_name='stock-remove')
|
|
||||||
self.add_action(self._remove_icon, ClipboardMenu.ACTION_DELETE)
|
|
||||||
|
|
||||||
if self._stop_icon:
|
|
||||||
self.remove_action(self._stop_icon)
|
|
||||||
self._stop_icon = None
|
|
||||||
else:
|
|
||||||
if not self._stop_icon:
|
|
||||||
self._stop_icon = CanvasIcon(icon_name='stock-close')
|
|
||||||
self.add_action(self._stop_icon, ClipboardMenu.ACTION_STOP_DOWNLOAD)
|
|
||||||
|
|
||||||
if self._remove_icon:
|
|
||||||
self.remove_action(self._remove_icon)
|
|
||||||
self._remove_icon = None
|
|
||||||
|
|
||||||
def set_percent(self, percent):
|
|
||||||
self._progress_bar.set_property('percent', percent)
|
|
||||||
self._create_icons(percent)
|
|
@ -1,42 +0,0 @@
|
|||||||
import logging
|
|
||||||
import dbus
|
|
||||||
import hippo
|
|
||||||
|
|
||||||
from sugar.graphics import style
|
|
||||||
from view.ClipboardIcon import ClipboardIcon
|
|
||||||
from sugar.clipboard import ClipboardService
|
|
||||||
|
|
||||||
class ClipboardBox(hippo.CanvasBox):
|
|
||||||
|
|
||||||
def __init__(self, frame, menu_shell):
|
|
||||||
hippo.CanvasBox.__init__(self)
|
|
||||||
self._frame = frame
|
|
||||||
self._menu_shell = menu_shell
|
|
||||||
self._icons = {}
|
|
||||||
|
|
||||||
cb_service = ClipboardService.get_instance()
|
|
||||||
cb_service.connect('object-added', self._object_added_cb)
|
|
||||||
cb_service.connect('object-deleted', self._object_deleted_cb)
|
|
||||||
cb_service.connect('object-state-updated', self._object_state_updated_cb)
|
|
||||||
|
|
||||||
def _object_added_cb(self, cb_service, mimeType, fileName):
|
|
||||||
icon = ClipboardIcon(self._menu_shell, fileName)
|
|
||||||
style.apply_stylesheet(icon, 'frame.BuddyIcon')
|
|
||||||
self.append(icon)
|
|
||||||
self._icons[fileName] = icon
|
|
||||||
|
|
||||||
if not self._frame.is_visible():
|
|
||||||
self._frame.show_and_hide(0.1)
|
|
||||||
|
|
||||||
logging.debug('ClipboardBox: ' + fileName + ' was added.')
|
|
||||||
|
|
||||||
def _object_deleted_cb(self, cb_service, fileName):
|
|
||||||
icon = self._icons[fileName]
|
|
||||||
self.remove(icon)
|
|
||||||
del self._icons[fileName]
|
|
||||||
logging.debug('ClipboardBox: ' + fileName + ' was deleted.')
|
|
||||||
|
|
||||||
def _object_state_updated_cb(self, cb_service, fileName, percent):
|
|
||||||
icon = self._icons[fileName]
|
|
||||||
icon.set_percent(percent)
|
|
||||||
logging.debug('ClipboardBox: ' + fileName + ' state was updated.')
|
|
@ -1,73 +0,0 @@
|
|||||||
import dbus
|
|
||||||
import gobject
|
|
||||||
|
|
||||||
DBUS_SERVICE = "org.laptop.Clipboard"
|
|
||||||
DBUS_INTERFACE = "org.laptop.Clipboard"
|
|
||||||
DBUS_PATH = "/org/laptop/Clipboard"
|
|
||||||
|
|
||||||
class ClipboardService(gobject.GObject):
|
|
||||||
|
|
||||||
__gsignals__ = {
|
|
||||||
'object-added': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
|
|
||||||
([str, str])),
|
|
||||||
'object-deleted': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
|
|
||||||
([str])),
|
|
||||||
'object-state-updated': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
|
|
||||||
([str, int])),
|
|
||||||
}
|
|
||||||
|
|
||||||
def __init__(self):
|
|
||||||
gobject.GObject.__init__(self)
|
|
||||||
|
|
||||||
self._dbus_service = None
|
|
||||||
bus = dbus.SessionBus()
|
|
||||||
bus.add_signal_receiver(self._name_owner_changed_cb,
|
|
||||||
signal_name="NameOwnerChanged",
|
|
||||||
dbus_interface="org.freedesktop.DBus")
|
|
||||||
# Try to register to ClipboardService, if we fail, we'll try later.
|
|
||||||
try:
|
|
||||||
self._connect_clipboard_signals()
|
|
||||||
except dbus.DBusException, exception:
|
|
||||||
pass
|
|
||||||
|
|
||||||
def _connect_clipboard_signals(self):
|
|
||||||
bus = dbus.SessionBus()
|
|
||||||
proxy_obj = bus.get_object(DBUS_SERVICE, DBUS_PATH)
|
|
||||||
self._dbus_service = dbus.Interface(proxy_obj, DBUS_SERVICE)
|
|
||||||
self._dbus_service.connect_to_signal('object_added', self._object_added_cb)
|
|
||||||
self._dbus_service.connect_to_signal('object_deleted', self._object_deleted_cb)
|
|
||||||
self._dbus_service.connect_to_signal('object_state_updated',
|
|
||||||
self._object_state_updated_cb)
|
|
||||||
|
|
||||||
def _name_owner_changed_cb(self, name, old, new):
|
|
||||||
if name != DBUS_SERVICE:
|
|
||||||
return
|
|
||||||
|
|
||||||
if (not old and not len(old)) and (new and len(new)):
|
|
||||||
# ClipboardService started up
|
|
||||||
self._connect_clipboard_signals()
|
|
||||||
|
|
||||||
def _object_added_cb(self, mimeType, fileName):
|
|
||||||
self.emit('object-added', mimeType, fileName)
|
|
||||||
|
|
||||||
def _object_deleted_cb(self, fileName):
|
|
||||||
self.emit('object-deleted', fileName)
|
|
||||||
|
|
||||||
def _object_state_updated_cb(self, fileName, percent):
|
|
||||||
self.emit('object-state-updated', fileName, percent)
|
|
||||||
|
|
||||||
def add_object(self, mimeType, fileName):
|
|
||||||
self._dbus_service.add_object(mimeType, fileName)
|
|
||||||
|
|
||||||
def delete_object(self, fileName):
|
|
||||||
self._dbus_service.delete_object(fileName)
|
|
||||||
|
|
||||||
def update_object_state(self, fileName, percent):
|
|
||||||
self._dbus_service.update_object_state(fileName, percent)
|
|
||||||
|
|
||||||
_clipboard_service = None
|
|
||||||
def get_instance():
|
|
||||||
global _clipboard_service
|
|
||||||
if not _clipboard_service:
|
|
||||||
_clipboard_service = ClipboardService()
|
|
||||||
return _clipboard_service
|
|
@ -1,5 +0,0 @@
|
|||||||
sugardir = $(pythondir)/sugar/clipboard
|
|
||||||
sugar_PYTHON = \
|
|
||||||
__init__.py \
|
|
||||||
ClipboardService.py
|
|
||||||
|
|
@ -1,133 +0,0 @@
|
|||||||
# Copyright (C) 2006, Red Hat, Inc.
|
|
||||||
#
|
|
||||||
# This library is free software; you can redistribute it and/or
|
|
||||||
# modify it under the terms of the GNU Lesser General Public
|
|
||||||
# License as published by the Free Software Foundation; either
|
|
||||||
# version 2 of the License, or (at your option) any later version.
|
|
||||||
#
|
|
||||||
# This library is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
||||||
# Lesser General Public License for more details.
|
|
||||||
#
|
|
||||||
# You should have received a copy of the GNU Lesser General Public
|
|
||||||
# License along with this library; if not, write to the
|
|
||||||
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
||||||
# Boston, MA 02111-1307, USA.
|
|
||||||
|
|
||||||
#TODO: has to be merged with all the existing bubbles in a generic progress bar widget
|
|
||||||
|
|
||||||
import math
|
|
||||||
|
|
||||||
import gobject
|
|
||||||
import gtk
|
|
||||||
import hippo
|
|
||||||
|
|
||||||
class ClipboardBubble(hippo.CanvasBox, hippo.CanvasItem):
|
|
||||||
__gtype_name__ = 'ClipboardBubble'
|
|
||||||
|
|
||||||
__gproperties__ = {
|
|
||||||
'fill-color': (object, None, None,
|
|
||||||
gobject.PARAM_READWRITE),
|
|
||||||
'stroke-color': (object, None, None,
|
|
||||||
gobject.PARAM_READWRITE),
|
|
||||||
'progress-color': (object, None, None,
|
|
||||||
gobject.PARAM_READWRITE),
|
|
||||||
'percent' : (object, None, None,
|
|
||||||
gobject.PARAM_READWRITE),
|
|
||||||
}
|
|
||||||
|
|
||||||
def __init__(self, **kwargs):
|
|
||||||
self._stroke_color = 0xFFFFFFFF
|
|
||||||
self._fill_color = 0xFFFFFFFF
|
|
||||||
self._progress_color = 0x000000FF
|
|
||||||
self._percent = 0
|
|
||||||
self._radius = 8
|
|
||||||
|
|
||||||
hippo.CanvasBox.__init__(self, **kwargs)
|
|
||||||
|
|
||||||
def do_set_property(self, pspec, value):
|
|
||||||
if pspec.name == 'fill-color':
|
|
||||||
self._fill_color = value
|
|
||||||
self.emit_paint_needed(0, 0, -1, -1)
|
|
||||||
elif pspec.name == 'stroke-color':
|
|
||||||
self._stroke_color = value
|
|
||||||
self.emit_paint_needed(0, 0, -1, -1)
|
|
||||||
elif pspec.name == 'progress-color':
|
|
||||||
self._progress_color = value
|
|
||||||
self.emit_paint_needed(0, 0, -1, -1)
|
|
||||||
elif pspec.name == 'percent':
|
|
||||||
self._percent = value
|
|
||||||
self.emit_paint_needed(0, 0, -1, -1)
|
|
||||||
|
|
||||||
def do_get_property(self, pspec):
|
|
||||||
if pspec.name == 'fill-color':
|
|
||||||
return self._fill_color
|
|
||||||
elif pspec.name == 'stroke-color':
|
|
||||||
return self._stroke_color
|
|
||||||
elif pspec.name == 'progress-color':
|
|
||||||
return self._progress_color
|
|
||||||
elif pspec.name == 'percent':
|
|
||||||
return self._percent
|
|
||||||
|
|
||||||
def _int_to_rgb(self, int_color):
|
|
||||||
red = (int_color >> 24) & 0x000000FF
|
|
||||||
green = (int_color >> 16) & 0x000000FF
|
|
||||||
blue = (int_color >> 8) & 0x000000FF
|
|
||||||
alpha = int_color & 0x000000FF
|
|
||||||
return (red / 255.0, green / 255.0, blue / 255.0)
|
|
||||||
|
|
||||||
def do_paint_below_children(self, cr, damaged_box):
|
|
||||||
[width, height] = self.get_allocation()
|
|
||||||
|
|
||||||
line_width = 3.0
|
|
||||||
x = line_width
|
|
||||||
y = line_width
|
|
||||||
width -= line_width * 2
|
|
||||||
height -= line_width * 2
|
|
||||||
|
|
||||||
cr.move_to(x + self._radius, y);
|
|
||||||
cr.arc(x + width - self._radius, y + self._radius,
|
|
||||||
self._radius, math.pi * 1.5, math.pi * 2);
|
|
||||||
cr.arc(x + width - self._radius, x + height - self._radius,
|
|
||||||
self._radius, 0, math.pi * 0.5);
|
|
||||||
cr.arc(x + self._radius, y + height - self._radius,
|
|
||||||
self._radius, math.pi * 0.5, math.pi);
|
|
||||||
cr.arc(x + self._radius, y + self._radius, self._radius,
|
|
||||||
math.pi, math.pi * 1.5);
|
|
||||||
|
|
||||||
color = self._int_to_rgb(self._fill_color)
|
|
||||||
cr.set_source_rgb(*color)
|
|
||||||
cr.fill_preserve();
|
|
||||||
|
|
||||||
color = self._int_to_rgb(self._stroke_color)
|
|
||||||
cr.set_source_rgb(*color)
|
|
||||||
cr.set_line_width(line_width)
|
|
||||||
cr.stroke();
|
|
||||||
|
|
||||||
self._paint_progress_bar(cr, x, y, width, height, line_width)
|
|
||||||
|
|
||||||
def _paint_progress_bar(self, cr, x, y, width, height, line_width):
|
|
||||||
prog_x = x + line_width
|
|
||||||
prog_y = y + line_width
|
|
||||||
prog_width = (width - (line_width * 2)) * (self._percent / 100.0)
|
|
||||||
prog_height = (height - (line_width * 2))
|
|
||||||
|
|
||||||
x = prog_x
|
|
||||||
y = prog_y
|
|
||||||
width = prog_width
|
|
||||||
height = prog_height
|
|
||||||
|
|
||||||
cr.move_to(x + self._radius, y);
|
|
||||||
cr.arc(x + width - self._radius, y + self._radius,
|
|
||||||
self._radius, math.pi * 1.5, math.pi * 2);
|
|
||||||
cr.arc(x + width - self._radius, x + height - self._radius,
|
|
||||||
self._radius, 0, math.pi * 0.5);
|
|
||||||
cr.arc(x + self._radius, y + height - self._radius,
|
|
||||||
self._radius, math.pi * 0.5, math.pi);
|
|
||||||
cr.arc(x + self._radius, y + self._radius, self._radius,
|
|
||||||
math.pi, math.pi * 1.5);
|
|
||||||
|
|
||||||
color = self._int_to_rgb(self._progress_color)
|
|
||||||
cr.set_source_rgb(*color)
|
|
||||||
cr.fill_preserve();
|
|
Loading…
Reference in New Issue