Created SugarDownloadManager and ClipboardService's wrapper. Show and hide the frame when adding an object to the clipboard.
This commit is contained in:
parent
b9f75c1472
commit
a7e4092b0e
1
.gitignore
vendored
1
.gitignore
vendored
@ -53,3 +53,4 @@ lib/src/sugar-marshal.c
|
||||
lib/src/sugar-marshal.h
|
||||
lib/src/stamp-sugar-marshal.c
|
||||
lib/src/stamp-sugar-marshal.h
|
||||
services/clipboard/org.laptop.Clipboard.service
|
||||
|
@ -23,6 +23,7 @@ import dbus
|
||||
import _sugar
|
||||
from sugar.activity import ActivityFactory
|
||||
from sugar.activity.Activity import Activity
|
||||
from sugar.clipboard import ClipboardService
|
||||
from sugar import env
|
||||
from sugar.graphics import style
|
||||
import web.stylesheet
|
||||
@ -105,35 +106,28 @@ def start():
|
||||
|
||||
style.load_stylesheet(web.stylesheet)
|
||||
|
||||
chandler = _sugar.get_browser_chandler()
|
||||
chandler.connect('download-started', download_started_cb)
|
||||
chandler.connect('download-completed', download_completed_cb)
|
||||
chandler.connect('download-cancelled', download_started_cb)
|
||||
chandler.connect('download-progress', download_progress_cb)
|
||||
download_manager = _sugar.get_download_manager()
|
||||
download_manager.connect('download-started', download_started_cb)
|
||||
download_manager.connect('download-completed', download_completed_cb)
|
||||
download_manager.connect('download-cancelled', download_started_cb)
|
||||
download_manager.connect('download-progress', download_progress_cb)
|
||||
|
||||
def stop():
|
||||
gtkmozembed.pop_startup()
|
||||
|
||||
def download_started_cb(chandler, url, mimeType, tmpFileName):
|
||||
bus = dbus.SessionBus()
|
||||
proxy_obj = bus.get_object('org.laptop.Clipboard', '/org/laptop/Clipboard')
|
||||
iface = dbus.Interface(proxy_obj, 'org.laptop.Clipboard')
|
||||
iface.add_object(mimeType, tmpFileName)
|
||||
def download_started_cb(download_manager, url, mimeType, tmpFileName):
|
||||
cbService = ClipboardService.get_instance()
|
||||
cbService.add_object(mimeType, tmpFileName)
|
||||
|
||||
def download_completed_cb(chandler, tmpFileName):
|
||||
bus = dbus.SessionBus()
|
||||
proxy_obj = bus.get_object('org.laptop.Clipboard', '/org/laptop/Clipboard')
|
||||
iface = dbus.Interface(proxy_obj, 'org.laptop.Clipboard')
|
||||
iface.update_object_state(tmpFileName, 100)
|
||||
def download_completed_cb(download_manager, tmpFileName):
|
||||
cbService = ClipboardService.get_instance()
|
||||
cbService.update_object_state(tmpFileName, 100)
|
||||
|
||||
def download_cancelled_cb(chandler, tmpFileName):
|
||||
bus = dbus.SessionBus()
|
||||
proxy_obj = bus.get_object('org.laptop.Clipboard', '/org/laptop/Clipboard')
|
||||
iface = dbus.Interface(proxy_obj, 'org.laptop.Clipboard')
|
||||
iface.delete_object(tmpFileName, 100)
|
||||
def download_cancelled_cb(download_manager, tmpFileName):
|
||||
cbService = ClipboardService.get_instance()
|
||||
#FIXME: Needs to update the state of the object to 'download stopped'
|
||||
#cbService.update_object_state(tmpFileName, 100)
|
||||
|
||||
def download_progress_cb(chandler, tmpFileName, progress):
|
||||
bus = dbus.SessionBus()
|
||||
proxy_obj = bus.get_object('org.laptop.Clipboard', '/org/laptop/Clipboard')
|
||||
iface = dbus.Interface(proxy_obj, 'org.laptop.Clipboard')
|
||||
iface.update_object_state(tmpFileName, progress)
|
||||
def download_progress_cb(download_manager, tmpFileName, progress):
|
||||
cbService = ClipboardService.get_instance()
|
||||
cbService.update_object_state(tmpFileName, progress)
|
||||
|
@ -78,6 +78,7 @@ sugar/__installed__.py
|
||||
sugar/activity/Makefile
|
||||
sugar/chat/Makefile
|
||||
sugar/chat/sketchpad/Makefile
|
||||
sugar/clipboard/Makefile
|
||||
sugar/graphics/Makefile
|
||||
sugar/p2p/Makefile
|
||||
sugar/presence/Makefile
|
||||
|
@ -35,11 +35,11 @@
|
||||
(gtype-id "SUGAR_TYPE_PUSH_SCROLLER")
|
||||
)
|
||||
|
||||
(define-object BrowserChandler
|
||||
(define-object DownloadManager
|
||||
(in-module "Sugar")
|
||||
(parent "GObject")
|
||||
(c-name "SugarBrowserChandler")
|
||||
(gtype-id "SUGAR_TYPE_BROWSER_CHANDLER")
|
||||
(c-name "SugarDownloadManager")
|
||||
(gtype-id "SUGAR_TYPE_DOWNLOAD_MANAGER")
|
||||
)
|
||||
|
||||
;; Enumerations and flags ...
|
||||
@ -181,14 +181,14 @@
|
||||
)
|
||||
)
|
||||
|
||||
;; From sugar-browser-chandler.h
|
||||
;; From sugar-download-manager.h
|
||||
|
||||
(define-function sugar_browser_chandler_get_type
|
||||
(c-name "sugar_browser_chandler_get_type")
|
||||
(define-function sugar_download_manager_get_type
|
||||
(c-name "sugar_download_manager_get_type")
|
||||
(return-type "GType")
|
||||
)
|
||||
|
||||
(define-function get_browser_chandler
|
||||
(c-name "sugar_get_browser_chandler")
|
||||
(return-type "SugarBrowserChandler*")
|
||||
(define-function get_download_manager
|
||||
(c-name "sugar_get_download_manager")
|
||||
(return-type "SugarDownloadManager*")
|
||||
)
|
||||
|
@ -9,7 +9,7 @@ headers
|
||||
#include "sugar-address-entry.h"
|
||||
#include "sugar-tray-manager.h"
|
||||
#include "sugar-push-scroller.h"
|
||||
#include "sugar-browser-chandler.h"
|
||||
#include "sugar-download-manager.h"
|
||||
|
||||
%%
|
||||
modulename gecko
|
||||
|
@ -19,8 +19,8 @@ libsugarprivate_la_SOURCES = \
|
||||
sugar-address-entry.c \
|
||||
sugar-browser.h \
|
||||
sugar-browser.cpp \
|
||||
sugar-browser-chandler.h \
|
||||
sugar-browser-chandler.c \
|
||||
sugar-download-manager.h \
|
||||
sugar-download-manager.c \
|
||||
SugarContentHandler.h \
|
||||
SugarContentHandler.cpp \
|
||||
SugarDownload.h \
|
||||
|
@ -1,9 +1,6 @@
|
||||
#include <nsCExternalHandlerService.h>
|
||||
#include <nsIFile.h>
|
||||
|
||||
#include "sugar-browser-chandler.h"
|
||||
#include "SugarDownload.h"
|
||||
|
||||
#include "SugarContentHandler.h"
|
||||
|
||||
GSugarContentHandler::GSugarContentHandler()
|
||||
|
@ -1,4 +1,4 @@
|
||||
#include "sugar-browser-chandler.h"
|
||||
#include "sugar-download-manager.h"
|
||||
|
||||
#include "SugarDownload.h"
|
||||
|
||||
@ -36,7 +36,7 @@ NS_IMETHODIMP
|
||||
GSugarDownload::OnStateChange (nsIWebProgress *aWebProgress, nsIRequest *aRequest,
|
||||
PRUint32 aStateFlags, nsresult aStatus)
|
||||
{
|
||||
SugarBrowserChandler *browser_chandler = sugar_get_browser_chandler();
|
||||
SugarDownloadManager *download_manager = sugar_get_download_manager();
|
||||
|
||||
if (((aStateFlags & STATE_IS_REQUEST) &&
|
||||
(aStateFlags & STATE_IS_NETWORK) &&
|
||||
@ -49,7 +49,7 @@ GSugarDownload::OnStateChange (nsIWebProgress *aWebProgress, nsIRequest *aReques
|
||||
mMIMEInfo->GetMIMEType(mimeType);
|
||||
mSource->GetSpec(url);
|
||||
|
||||
sugar_browser_chandler_download_started(browser_chandler,
|
||||
sugar_download_manager_download_started(download_manager,
|
||||
url.get(),
|
||||
mimeType.get(),
|
||||
mTargetFileName.get());
|
||||
@ -60,10 +60,10 @@ GSugarDownload::OnStateChange (nsIWebProgress *aWebProgress, nsIRequest *aReques
|
||||
aStateFlags == STATE_STOP) {
|
||||
|
||||
if (NS_SUCCEEDED (aStatus)) {
|
||||
sugar_browser_chandler_download_completed(browser_chandler,
|
||||
sugar_download_manager_download_completed(download_manager,
|
||||
mTargetFileName.get());
|
||||
} else {
|
||||
sugar_browser_chandler_download_cancelled(browser_chandler,
|
||||
sugar_download_manager_download_cancelled(download_manager,
|
||||
mTargetFileName.get());
|
||||
}
|
||||
}
|
||||
@ -92,11 +92,11 @@ GSugarDownload::OnProgressChange64 (nsIWebProgress *aWebProgress,
|
||||
PRInt64 aCurTotalProgress,
|
||||
PRInt64 aMaxTotalProgress)
|
||||
{
|
||||
SugarBrowserChandler *browser_chandler = sugar_get_browser_chandler();
|
||||
SugarDownloadManager *download_manager = sugar_get_download_manager();
|
||||
PRInt32 percentComplete =
|
||||
(PRInt32)(((float)aCurSelfProgress / (float)aMaxSelfProgress) * 100.0);
|
||||
|
||||
sugar_browser_chandler_update_progress(browser_chandler,
|
||||
sugar_download_manager_update_progress(download_manager,
|
||||
mTargetFileName.get(),
|
||||
percentComplete);
|
||||
|
||||
|
@ -1,46 +0,0 @@
|
||||
#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_download_started (SugarBrowserChandler *chandler,
|
||||
const char *url,
|
||||
const char *mime_type,
|
||||
const char *tmp_file_name);
|
||||
void sugar_browser_chandler_download_completed (SugarBrowserChandler *chandler,
|
||||
const char *tmp_file_name);
|
||||
void sugar_browser_chandler_download_cancelled (SugarBrowserChandler *chandler,
|
||||
const char *tmp_file_name);
|
||||
void sugar_browser_chandler_update_progress (SugarBrowserChandler *chandler,
|
||||
const char *tmp_file_name,
|
||||
const int percent);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif
|
@ -1,5 +1,5 @@
|
||||
#include "sugar-marshal.h"
|
||||
#include "sugar-browser-chandler.h"
|
||||
#include "sugar-download-manager.h"
|
||||
|
||||
enum {
|
||||
DOWNLOAD_STARTED,
|
||||
@ -10,23 +10,23 @@ enum {
|
||||
};
|
||||
static guint signals[LAST_SIGNAL] = { 0 };
|
||||
|
||||
G_DEFINE_TYPE(SugarBrowserChandler, sugar_browser_chandler, G_TYPE_OBJECT)
|
||||
G_DEFINE_TYPE(SugarDownloadManager, sugar_download_manager, G_TYPE_OBJECT)
|
||||
|
||||
SugarBrowserChandler *browserChandler = NULL;
|
||||
SugarDownloadManager *DownloadManager = NULL;
|
||||
|
||||
static void
|
||||
sugar_browser_chandler_init(SugarBrowserChandler *browserChandler)
|
||||
sugar_download_manager_init(SugarDownloadManager *DownloadManager)
|
||||
{
|
||||
}
|
||||
|
||||
static void
|
||||
sugar_browser_chandler_class_init(SugarBrowserChandlerClass *browser_chandler_class)
|
||||
sugar_download_manager_class_init(SugarDownloadManagerClass *download_manager_class)
|
||||
{
|
||||
signals[DOWNLOAD_STARTED] =
|
||||
g_signal_new ("download-started",
|
||||
G_OBJECT_CLASS_TYPE (browser_chandler_class),
|
||||
G_OBJECT_CLASS_TYPE (download_manager_class),
|
||||
G_SIGNAL_RUN_LAST,
|
||||
G_STRUCT_OFFSET (SugarBrowserChandlerClass, handle_content),
|
||||
G_STRUCT_OFFSET (SugarDownloadManagerClass, handle_content),
|
||||
NULL, NULL,
|
||||
sugar_marshal_VOID__STRING_STRING_STRING,
|
||||
G_TYPE_NONE, 3,
|
||||
@ -36,9 +36,9 @@ sugar_browser_chandler_class_init(SugarBrowserChandlerClass *browser_chandler_cl
|
||||
|
||||
signals[DOWNLOAD_COMPLETED] =
|
||||
g_signal_new ("download-completed",
|
||||
G_OBJECT_CLASS_TYPE (browser_chandler_class),
|
||||
G_OBJECT_CLASS_TYPE (download_manager_class),
|
||||
G_SIGNAL_RUN_LAST,
|
||||
G_STRUCT_OFFSET (SugarBrowserChandlerClass, handle_content),
|
||||
G_STRUCT_OFFSET (SugarDownloadManagerClass, handle_content),
|
||||
NULL, NULL,
|
||||
sugar_marshal_VOID__STRING,
|
||||
G_TYPE_NONE, 1,
|
||||
@ -46,9 +46,9 @@ sugar_browser_chandler_class_init(SugarBrowserChandlerClass *browser_chandler_cl
|
||||
|
||||
signals[DOWNLOAD_CANCELLED] =
|
||||
g_signal_new ("download-cancelled",
|
||||
G_OBJECT_CLASS_TYPE (browser_chandler_class),
|
||||
G_OBJECT_CLASS_TYPE (download_manager_class),
|
||||
G_SIGNAL_RUN_LAST,
|
||||
G_STRUCT_OFFSET (SugarBrowserChandlerClass, handle_content),
|
||||
G_STRUCT_OFFSET (SugarDownloadManagerClass, handle_content),
|
||||
NULL, NULL,
|
||||
sugar_marshal_VOID__STRING,
|
||||
G_TYPE_NONE, 1,
|
||||
@ -56,9 +56,9 @@ sugar_browser_chandler_class_init(SugarBrowserChandlerClass *browser_chandler_cl
|
||||
|
||||
signals[DOWNLOAD_PROGRESS] =
|
||||
g_signal_new ("download-progress",
|
||||
G_OBJECT_CLASS_TYPE (browser_chandler_class),
|
||||
G_OBJECT_CLASS_TYPE (download_manager_class),
|
||||
G_SIGNAL_RUN_LAST,
|
||||
G_STRUCT_OFFSET (SugarBrowserChandlerClass, handle_content),
|
||||
G_STRUCT_OFFSET (SugarDownloadManagerClass, handle_content),
|
||||
NULL, NULL,
|
||||
sugar_marshal_VOID__STRING_INT,
|
||||
G_TYPE_NONE, 2,
|
||||
@ -66,22 +66,22 @@ sugar_browser_chandler_class_init(SugarBrowserChandlerClass *browser_chandler_cl
|
||||
G_TYPE_INT);
|
||||
}
|
||||
|
||||
SugarBrowserChandler *
|
||||
sugar_get_browser_chandler()
|
||||
SugarDownloadManager *
|
||||
sugar_get_download_manager()
|
||||
{
|
||||
if(browserChandler == NULL)
|
||||
browserChandler = g_object_new(SUGAR_TYPE_BROWSER_CHANDLER, NULL);
|
||||
if(DownloadManager == NULL)
|
||||
DownloadManager = g_object_new(SUGAR_TYPE_DOWNLOAD_MANAGER, NULL);
|
||||
|
||||
return browserChandler;
|
||||
return DownloadManager;
|
||||
}
|
||||
|
||||
void
|
||||
sugar_browser_chandler_download_started (SugarBrowserChandler *browser_chandler,
|
||||
sugar_download_manager_download_started (SugarDownloadManager *download_manager,
|
||||
const char *url,
|
||||
const char *mime_type,
|
||||
const char *tmp_file_name)
|
||||
{
|
||||
g_signal_emit(browser_chandler,
|
||||
g_signal_emit(download_manager,
|
||||
signals[DOWNLOAD_STARTED],
|
||||
0 /* details */,
|
||||
url,
|
||||
@ -90,30 +90,30 @@ sugar_browser_chandler_download_started (SugarBrowserChandler *browser_chandler,
|
||||
}
|
||||
|
||||
void
|
||||
sugar_browser_chandler_download_completed (SugarBrowserChandler *browser_chandler,
|
||||
sugar_download_manager_download_completed (SugarDownloadManager *download_manager,
|
||||
const char *tmp_file_name)
|
||||
{
|
||||
g_signal_emit(browser_chandler,
|
||||
g_signal_emit(download_manager,
|
||||
signals[DOWNLOAD_COMPLETED],
|
||||
0 /* details */,
|
||||
tmp_file_name);
|
||||
}
|
||||
|
||||
void sugar_browser_chandler_download_cancelled (SugarBrowserChandler *browser_chandler,
|
||||
void sugar_download_manager_download_cancelled (SugarDownloadManager *download_manager,
|
||||
const char *tmp_file_name)
|
||||
{
|
||||
g_signal_emit(browser_chandler,
|
||||
g_signal_emit(download_manager,
|
||||
signals[DOWNLOAD_CANCELLED],
|
||||
0 /* details */,
|
||||
tmp_file_name);
|
||||
}
|
||||
|
||||
void
|
||||
sugar_browser_chandler_update_progress (SugarBrowserChandler *browser_chandler,
|
||||
sugar_download_manager_update_progress (SugarDownloadManager *download_manager,
|
||||
const char *tmp_file_name,
|
||||
const int percent)
|
||||
{
|
||||
g_signal_emit(browser_chandler,
|
||||
g_signal_emit(download_manager,
|
||||
signals[DOWNLOAD_PROGRESS],
|
||||
0 /* details */,
|
||||
tmp_file_name,
|
55
lib/src/sugar-download-manager.h
Normal file
55
lib/src/sugar-download-manager.h
Normal file
@ -0,0 +1,55 @@
|
||||
#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
|
@ -22,30 +22,30 @@ import dbus
|
||||
import dbus.service
|
||||
from sugar import env
|
||||
|
||||
_CLIPBOARD_SERVICE = "org.laptop.Clipboard"
|
||||
_CLIPBOARD_DBUS_INTERFACE = "org.laptop.Clipboard"
|
||||
_CLIPBOARD_OBJECT_PATH = "/org/laptop/Clipboard"
|
||||
|
||||
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(_CLIPBOARD_DBUS_INTERFACE, bus=bus)
|
||||
dbus.service.Object.__init__(self, bus_name, _CLIPBOARD_OBJECT_PATH)
|
||||
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):
|
||||
logging.debug('Added object of type ' + mimeType + ' with path at ' + 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):
|
||||
logging.debug('Deleted object with path at ' + 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):
|
||||
|
@ -1,10 +1,12 @@
|
||||
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='stock-written-doc')
|
||||
MenuIcon.__init__(self, menu_shell, icon_name='activity-xbook')
|
||||
self._file_name = file_name
|
||||
self._percent = 0
|
||||
self.connect('activated', self._icon_activated_cb)
|
||||
@ -21,13 +23,15 @@ class ClipboardIcon(MenuIcon):
|
||||
self._menu.set_percent(percent)
|
||||
|
||||
def _icon_activated_cb(self, icon):
|
||||
activity = ActivityFactory.create("org.laptop.sugar.Xbook")
|
||||
activity.execute("open_document", [self._file_name])
|
||||
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_DELETE:
|
||||
# activity = self._shell.get_current_activity()
|
||||
# activity.invite(ps_buddy)
|
||||
pass
|
||||
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)
|
||||
|
@ -43,16 +43,32 @@ class ClipboardMenu(Menu):
|
||||
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)
|
||||
#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:
|
||||
icon = CanvasIcon(icon_name='stock-remove')
|
||||
self.add_action(icon, ClipboardMenu.ACTION_DELETE)
|
||||
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:
|
||||
icon = CanvasIcon(icon_name='stock-close')
|
||||
self.add_action(icon, ClipboardMenu.ACTION_STOP_DOWNLOAD)
|
||||
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)
|
||||
|
@ -4,58 +4,39 @@ import hippo
|
||||
|
||||
from sugar.graphics import style
|
||||
from view.ClipboardIcon import ClipboardIcon
|
||||
from sugar.clipboard import ClipboardService
|
||||
|
||||
class ClipboardBox(hippo.CanvasBox):
|
||||
|
||||
_CLIPBOARD_SERVICE = "org.laptop.Clipboard"
|
||||
_CLIPBOARD_OBJECT_PATH = "/org/laptop/Clipboard"
|
||||
|
||||
def __init__(self, shell, menu_shell):
|
||||
def __init__(self, frame, menu_shell):
|
||||
hippo.CanvasBox.__init__(self)
|
||||
self._shell = shell
|
||||
self._frame = frame
|
||||
self._menu_shell = menu_shell
|
||||
self._icons = {}
|
||||
|
||||
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(self._CLIPBOARD_SERVICE, self._CLIPBOARD_OBJECT_PATH)
|
||||
iface = dbus.Interface(proxy_obj, self._CLIPBOARD_SERVICE)
|
||||
iface.connect_to_signal('object_added', self.object_added_callback)
|
||||
iface.connect_to_signal('object_deleted', self.object_deleted_callback)
|
||||
iface.connect_to_signal('object_state_updated', self.object_state_updated_callback)
|
||||
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 name_owner_changed_cb(self, name, old, new):
|
||||
if name != self._CLIPBOARD_SERVICE:
|
||||
return
|
||||
if (not old and not len(old)) and (new and len(new)):
|
||||
# ClipboardService started up
|
||||
self._connect_clipboard_signals()
|
||||
|
||||
def object_added_callback(self, mimeType, fileName):
|
||||
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_callback(self, fileName):
|
||||
def _object_deleted_cb(self, cb_service, fileName):
|
||||
icon = self._icons[fileName]
|
||||
self.remove(icon)
|
||||
self._icons.remove(icon)
|
||||
del self._icons[fileName]
|
||||
logging.debug('ClipboardBox: ' + fileName + ' was deleted.')
|
||||
|
||||
def object_state_updated_callback(self, fileName, percent):
|
||||
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.')
|
||||
|
@ -201,7 +201,7 @@ class Frame:
|
||||
# Left panel
|
||||
[menu_shell, root] = self._create_panel(grid, 0, 1, 1, 10)
|
||||
|
||||
box = ClipboardBox(self._shell, menu_shell)
|
||||
box = ClipboardBox(self, menu_shell)
|
||||
root.append(box)
|
||||
|
||||
def _create_panel(self, grid, x, y, width, height):
|
||||
|
@ -1,4 +1,4 @@
|
||||
SUBDIRS = activity chat graphics p2p presence
|
||||
SUBDIRS = activity chat clipboard graphics p2p presence
|
||||
|
||||
sugardir = $(pythondir)/sugar
|
||||
sugar_PYTHON = \
|
||||
|
73
sugar/clipboard/ClipboardService.py
Normal file
73
sugar/clipboard/ClipboardService.py
Normal file
@ -0,0 +1,73 @@
|
||||
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
|
5
sugar/clipboard/Makefile.am
Normal file
5
sugar/clipboard/Makefile.am
Normal file
@ -0,0 +1,5 @@
|
||||
sugardir = $(pythondir)/sugar/clipboard
|
||||
sugar_PYTHON = \
|
||||
__init__.py \
|
||||
ClipboardService.py
|
||||
|
0
sugar/clipboard/__init__.py
Normal file
0
sugar/clipboard/__init__.py
Normal file
@ -4,6 +4,7 @@ sugar_PYTHON = \
|
||||
bubble.py \
|
||||
canvasicon.py \
|
||||
colors.py \
|
||||
ClipboardBubble.py \
|
||||
grid.py \
|
||||
iconcolor.py \
|
||||
menu.py \
|
||||
|
@ -49,6 +49,7 @@ class Menu(gtk.Window):
|
||||
self._root.append(content_box)
|
||||
|
||||
self._action_box = None
|
||||
self._action_box_separator = None
|
||||
|
||||
def _create_separator(self):
|
||||
separator = hippo.CanvasBox()
|
||||
@ -56,8 +57,8 @@ class Menu(gtk.Window):
|
||||
return separator
|
||||
|
||||
def _create_action_box(self):
|
||||
separator = self._create_separator()
|
||||
self._root.append(separator)
|
||||
self._action_box_separator = self._create_separator()
|
||||
self._root.append(self._action_box_separator)
|
||||
|
||||
self._action_box = hippo.CanvasBox(
|
||||
orientation=hippo.ORIENTATION_HORIZONTAL)
|
||||
@ -71,5 +72,8 @@ class Menu(gtk.Window):
|
||||
icon.connect('activated', self._action_clicked_cb, action_id)
|
||||
self._action_box.append(icon)
|
||||
|
||||
def remove_action(self, icon):
|
||||
self._action_box.remove(icon)
|
||||
|
||||
def _action_clicked_cb(self, icon, action):
|
||||
self.emit('action', action)
|
||||
|
Loading…
Reference in New Issue
Block a user