First implementation of ClipboardService. Implement pdf viewing and downloading via ClipboardService.
This commit is contained in:
+47
-9
@@ -35,11 +35,18 @@
|
||||
(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")
|
||||
)
|
||||
|
||||
(define-object Download
|
||||
(in-module "Sugar")
|
||||
(parent "GObject")
|
||||
(c-name "SugarDownload")
|
||||
(gtype-id "SUGAR_TYPE_DOWNLOAD")
|
||||
)
|
||||
|
||||
;; Enumerations and flags ...
|
||||
@@ -181,14 +188,45 @@
|
||||
)
|
||||
)
|
||||
|
||||
;; 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*")
|
||||
)
|
||||
|
||||
;; From sugar-download.h
|
||||
|
||||
(define-function sugar_download_get_type
|
||||
(c-name "sugar_download_get_type")
|
||||
(return-type "GType")
|
||||
)
|
||||
|
||||
(define-method get_file_name
|
||||
(of-object "SugarDownload")
|
||||
(c-name "sugar_download_get_file_name")
|
||||
(return-type "const-gchar*")
|
||||
)
|
||||
|
||||
(define-method get_url
|
||||
(of-object "SugarDownload")
|
||||
(c-name "sugar_download_get_url")
|
||||
(return-type "const-gchar*")
|
||||
)
|
||||
|
||||
(define-method get_mime_type
|
||||
(of-object "SugarDownload")
|
||||
(c-name "sugar_download_get_mime_type")
|
||||
(return-type "const-gchar*")
|
||||
)
|
||||
|
||||
(define-method get_percent
|
||||
(of-object "SugarDownload")
|
||||
(c-name "sugar_download_get_percent")
|
||||
(return-type "gint")
|
||||
)
|
||||
|
||||
@@ -9,7 +9,8 @@ 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"
|
||||
#include "sugar-download.h"
|
||||
|
||||
%%
|
||||
modulename gecko
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
#include <nsCExternalHandlerService.h>
|
||||
#include <nsIFile.h>
|
||||
|
||||
#include "GeckoContentHandler.h"
|
||||
|
||||
GeckoContentHandler::GeckoContentHandler()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
GeckoContentHandler::~GeckoContentHandler()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS1(GeckoContentHandler, nsIHelperAppLauncherDialog)
|
||||
|
||||
NS_IMETHODIMP
|
||||
GeckoContentHandler::Show (nsIHelperAppLauncher *aLauncher,
|
||||
nsISupports *aContext,
|
||||
PRUint32 aReason)
|
||||
{
|
||||
nsCOMPtr<nsIFile> tmpFile;
|
||||
aLauncher->GetTargetFile(getter_AddRefs(tmpFile));
|
||||
|
||||
aLauncher->SaveToDisk (tmpFile, PR_FALSE);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
GeckoContentHandler::PromptForSaveToFile (nsIHelperAppLauncher *aLauncher,
|
||||
nsISupports *aWindowContext,
|
||||
const PRUnichar *aDefaultFile,
|
||||
const PRUnichar *aSuggestedFileExtension,
|
||||
nsILocalFile **_retval)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
#ifndef __SUGAR_CONTENT_HANDLER_H__
|
||||
#define __SUGAR_CONTENT_HANDLER_H__
|
||||
#ifndef __GECKO_CONTENT_HANDLER_H__
|
||||
#define __GECKO_CONTENT_HANDLER_H__
|
||||
|
||||
#include <nsCOMPtr.h>
|
||||
#include <nsIHelperAppLauncherDialog.h>
|
||||
|
||||
#define G_SUGARCONTENTHANDLER_CID \
|
||||
#define GECKOCONTENTHANDLER_CID \
|
||||
{ /* 2321843e-6377-11db-967b-00e08161165f */ \
|
||||
0x2321843e, \
|
||||
0x6377, \
|
||||
@@ -12,17 +12,17 @@
|
||||
{0x96, 0x7b, 0x0, 0xe0, 0x81, 0x61, 0x16, 0x5f} \
|
||||
}
|
||||
|
||||
class GSugarContentHandler : public nsIHelperAppLauncherDialog
|
||||
class GeckoContentHandler : public nsIHelperAppLauncherDialog
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIHELPERAPPLAUNCHERDIALOG
|
||||
|
||||
GSugarContentHandler();
|
||||
virtual ~GSugarContentHandler();
|
||||
GeckoContentHandler();
|
||||
virtual ~GeckoContentHandler();
|
||||
|
||||
private:
|
||||
|
||||
};
|
||||
|
||||
#endif /* __SUGAR_CONTENT_HANDLER_H */
|
||||
#endif /* __GECKO_CONTENT_HANDLER_H */
|
||||
@@ -0,0 +1,129 @@
|
||||
#include "sugar-download-manager.h"
|
||||
|
||||
#include "GeckoDownload.h"
|
||||
|
||||
GeckoDownload::GeckoDownload ()
|
||||
{
|
||||
}
|
||||
|
||||
GeckoDownload::~GeckoDownload ()
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS3 (GeckoDownload,
|
||||
nsIWebProgressListener,
|
||||
nsIWebProgressListener2,
|
||||
nsITransfer)
|
||||
|
||||
NS_IMETHODIMP
|
||||
GeckoDownload::Init (nsIURI *aSource,
|
||||
nsIURI *aTarget,
|
||||
const nsAString &aDisplayName,
|
||||
nsIMIMEInfo *aMIMEInfo,
|
||||
PRTime aStartTime,
|
||||
nsILocalFile *aTempFile,
|
||||
nsICancelable *aCancelable)
|
||||
{
|
||||
mSource = aSource;
|
||||
aTarget->GetPath (mTargetFileName);
|
||||
mMIMEInfo = aMIMEInfo;
|
||||
mTempFile = aTempFile;
|
||||
// mCancelable = aCancelable; Just a reminder for when we implement cancelling downloads.
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
GeckoDownload::OnStateChange (nsIWebProgress *aWebProgress,
|
||||
nsIRequest *aRequest,
|
||||
PRUint32 aStateFlags,
|
||||
nsresult aStatus)
|
||||
{
|
||||
SugarDownloadManager *download_manager = sugar_get_download_manager ();
|
||||
|
||||
if (aStateFlags == STATE_START) {
|
||||
|
||||
nsCString url;
|
||||
nsCString mimeType;
|
||||
|
||||
mMIMEInfo->GetMIMEType (mimeType);
|
||||
mSource->GetSpec (url);
|
||||
|
||||
sugar_download_manager_download_started (download_manager,
|
||||
url.get (),
|
||||
mimeType.get (),
|
||||
mTargetFileName.get ());
|
||||
|
||||
} else if (aStateFlags == STATE_STOP) {
|
||||
|
||||
if (NS_SUCCEEDED (aStatus)) {
|
||||
sugar_download_manager_download_completed (download_manager,
|
||||
mTargetFileName.get ());
|
||||
} else {
|
||||
sugar_download_manager_download_cancelled (download_manager,
|
||||
mTargetFileName.get ());
|
||||
}
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
GeckoDownload::OnProgressChange (nsIWebProgress *aWebProgress,
|
||||
nsIRequest *aRequest,
|
||||
PRInt32 aCurSelfProgress,
|
||||
PRInt32 aMaxSelfProgress,
|
||||
PRInt32 aCurTotalProgress,
|
||||
PRInt32 aMaxTotalProgress)
|
||||
{
|
||||
return OnProgressChange64 (aWebProgress,
|
||||
aRequest,
|
||||
aCurSelfProgress,
|
||||
aMaxSelfProgress,
|
||||
aCurTotalProgress,
|
||||
aMaxTotalProgress);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
GeckoDownload::OnProgressChange64 (nsIWebProgress *aWebProgress,
|
||||
nsIRequest *aRequest,
|
||||
PRInt64 aCurSelfProgress,
|
||||
PRInt64 aMaxSelfProgress,
|
||||
PRInt64 aCurTotalProgress,
|
||||
PRInt64 aMaxTotalProgress)
|
||||
{
|
||||
SugarDownloadManager *download_manager = sugar_get_download_manager ();
|
||||
PRInt32 percentComplete =
|
||||
(PRInt32)(((float)aCurSelfProgress / (float)aMaxSelfProgress) * 100.0);
|
||||
|
||||
sugar_download_manager_update_progress (download_manager,
|
||||
mTargetFileName.get (),
|
||||
percentComplete);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
GeckoDownload::OnLocationChange (nsIWebProgress *aWebProgress,
|
||||
nsIRequest *aRequest,
|
||||
nsIURI *location)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
GeckoDownload::OnStatusChange (nsIWebProgress *aWebProgress,
|
||||
nsIRequest *aRequest,
|
||||
nsresult aStatus,
|
||||
const PRUnichar *aMessage)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
GeckoDownload::OnSecurityChange (nsIWebProgress *aWebProgress,
|
||||
nsIRequest *aRequest,
|
||||
PRUint32 state)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
#ifndef SugarDownload_h__
|
||||
#define SugarDownload_h__
|
||||
#ifndef __GECKO_DOWNLOAD_H__
|
||||
#define __GECKO_DOWNLOAD_H__
|
||||
|
||||
#include <nsCOMPtr.h>
|
||||
#include <nsIInterfaceRequestor.h>
|
||||
@@ -10,7 +10,7 @@
|
||||
#include <nsILocalFile.h>
|
||||
#include <nsStringAPI.h>
|
||||
|
||||
#define G_SUGARDOWNLOAD_CID \
|
||||
#define GECKODOWNLOAD_CID \
|
||||
{ /* b1813bbe-6518-11db-967e-00e08161165f */ \
|
||||
0xb1813bbe, \
|
||||
0x6518, \
|
||||
@@ -18,11 +18,11 @@
|
||||
{0x96, 0x7e, 0x0, 0xe0, 0x81, 0x61, 0x16, 0x5f} \
|
||||
}
|
||||
|
||||
class GSugarDownload : public nsITransfer
|
||||
class GeckoDownload : public nsITransfer
|
||||
{
|
||||
public:
|
||||
GSugarDownload();
|
||||
virtual ~GSugarDownload();
|
||||
GeckoDownload();
|
||||
virtual ~GeckoDownload();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIWEBPROGRESSLISTENER
|
||||
@@ -36,4 +36,4 @@ protected:
|
||||
nsILocalFile *mTempFile;
|
||||
};
|
||||
|
||||
#endif // SugarDownload_h__
|
||||
#endif // __GECKO_DOWNLOAD_H__
|
||||
+8
-6
@@ -15,16 +15,18 @@ libsugarprivate_la_SOURCES = \
|
||||
$(BUILT_SOURCES) \
|
||||
eggaccelerators.h \
|
||||
eggaccelerators.c \
|
||||
GeckoContentHandler.h \
|
||||
GeckoContentHandler.cpp \
|
||||
GeckoDownload.h \
|
||||
GeckoDownload.cpp \
|
||||
sugar-address-entry.h \
|
||||
sugar-address-entry.c \
|
||||
sugar-browser.h \
|
||||
sugar-browser.cpp \
|
||||
sugar-browser-chandler.h \
|
||||
sugar-browser-chandler.c \
|
||||
SugarContentHandler.h \
|
||||
SugarContentHandler.cpp \
|
||||
SugarDownload.h \
|
||||
SugarDownload.cpp \
|
||||
sugar-download.h \
|
||||
sugar-download.c \
|
||||
sugar-download-manager.h \
|
||||
sugar-download-manager.c \
|
||||
sugar-key-grabber.h \
|
||||
sugar-key-grabber.c \
|
||||
sugar-push-scroller.c \
|
||||
|
||||
@@ -1,43 +0,0 @@
|
||||
#include <nsCExternalHandlerService.h>
|
||||
#include <nsIFile.h>
|
||||
|
||||
#include "sugar-browser-chandler.h"
|
||||
#include "SugarDownload.h"
|
||||
|
||||
#include "SugarContentHandler.h"
|
||||
|
||||
GSugarContentHandler::GSugarContentHandler()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
GSugarContentHandler::~GSugarContentHandler()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS1(GSugarContentHandler, nsIHelperAppLauncherDialog)
|
||||
|
||||
NS_IMETHODIMP
|
||||
GSugarContentHandler::Show (nsIHelperAppLauncher *aLauncher,
|
||||
nsISupports *aContext,
|
||||
PRUint32 aReason)
|
||||
{
|
||||
nsCOMPtr<nsIFile> tmpFile;
|
||||
aLauncher->GetTargetFile(getter_AddRefs(tmpFile));
|
||||
|
||||
aLauncher->SaveToDisk (tmpFile, PR_FALSE);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP GSugarContentHandler::PromptForSaveToFile(
|
||||
nsIHelperAppLauncher *aLauncher,
|
||||
nsISupports *aWindowContext,
|
||||
const PRUnichar *aDefaultFile,
|
||||
const PRUnichar *aSuggestedFileExtension,
|
||||
nsILocalFile **_retval)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@@ -1,103 +0,0 @@
|
||||
#include "sugar-browser-chandler.h"
|
||||
|
||||
#include "SugarDownload.h"
|
||||
|
||||
GSugarDownload::GSugarDownload()
|
||||
{
|
||||
}
|
||||
|
||||
GSugarDownload::~GSugarDownload()
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS3 (GSugarDownload,
|
||||
nsIWebProgressListener,
|
||||
nsIWebProgressListener2,
|
||||
nsITransfer)
|
||||
|
||||
NS_IMETHODIMP
|
||||
GSugarDownload::Init (nsIURI *aSource,
|
||||
nsIURI *aTarget,
|
||||
const nsAString &aDisplayName,
|
||||
nsIMIMEInfo *aMIMEInfo,
|
||||
PRTime aStartTime,
|
||||
nsILocalFile *aTempFile,
|
||||
nsICancelable *aCancelable)
|
||||
{
|
||||
mSource = aSource;
|
||||
aTarget->GetPath(mTargetFileName);
|
||||
mMIMEInfo = aMIMEInfo;
|
||||
mTempFile = aTempFile;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
GSugarDownload::OnStateChange (nsIWebProgress *aWebProgress, nsIRequest *aRequest,
|
||||
PRUint32 aStateFlags, nsresult aStatus)
|
||||
{
|
||||
nsCString url;
|
||||
nsCString mimeType;
|
||||
nsCString targetURI;
|
||||
|
||||
if ((((aStateFlags & STATE_IS_REQUEST) &&
|
||||
(aStateFlags & STATE_IS_NETWORK) &&
|
||||
(aStateFlags & STATE_STOP)) ||
|
||||
aStateFlags == STATE_STOP) &&
|
||||
NS_SUCCEEDED (aStatus)) {
|
||||
|
||||
mMIMEInfo->GetMIMEType(mimeType);
|
||||
mSource->GetSpec(url);
|
||||
|
||||
SugarBrowserChandler *browser_chandler = sugar_get_browser_chandler();
|
||||
sugar_browser_chandler_handle_content(browser_chandler,
|
||||
url.get(),
|
||||
mimeType.get(),
|
||||
mTargetFileName.get());
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
GSugarDownload::OnProgressChange (nsIWebProgress *aWebProgress,
|
||||
nsIRequest *aRequest,
|
||||
PRInt32 aCurSelfProgress,
|
||||
PRInt32 aMaxSelfProgress,
|
||||
PRInt32 aCurTotalProgress,
|
||||
PRInt32 aMaxTotalProgress)
|
||||
{
|
||||
return OnProgressChange64 (aWebProgress, aRequest,
|
||||
aCurSelfProgress, aMaxSelfProgress,
|
||||
aCurTotalProgress, aMaxTotalProgress);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
GSugarDownload::OnProgressChange64 (nsIWebProgress *aWebProgress,
|
||||
nsIRequest *aRequest,
|
||||
PRInt64 aCurSelfProgress,
|
||||
PRInt64 aMaxSelfProgress,
|
||||
PRInt64 aCurTotalProgress,
|
||||
PRInt64 aMaxTotalProgress)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
GSugarDownload::OnLocationChange (nsIWebProgress *aWebProgress, nsIRequest *aRequest, nsIURI *location)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
GSugarDownload::OnStatusChange (nsIWebProgress *aWebProgress, nsIRequest *aRequest,
|
||||
nsresult aStatus, const PRUnichar *aMessage)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
GSugarDownload::OnSecurityChange (nsIWebProgress *aWebProgress, nsIRequest *aRequest, PRUint32 state)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
@@ -1,56 +0,0 @@
|
||||
#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);
|
||||
}
|
||||
@@ -1,39 +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_handle_content (SugarBrowserChandler *chandler,
|
||||
const char *url,
|
||||
const char *mime_type,
|
||||
const char *tmp_file_name);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif
|
||||
+11
-11
@@ -18,8 +18,8 @@
|
||||
*/
|
||||
|
||||
#include "sugar-browser.h"
|
||||
#include "SugarContentHandler.h"
|
||||
#include "SugarDownload.h"
|
||||
#include "GeckoContentHandler.h"
|
||||
#include "GeckoDownload.h"
|
||||
|
||||
#include <gtkmozembed_internal.h>
|
||||
#include <nsCOMPtr.h>
|
||||
@@ -35,8 +35,8 @@
|
||||
#include <nsIComponentRegistrar.h>
|
||||
#include <nsIComponentManager.h>
|
||||
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(GSugarContentHandler)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(GSugarDownload)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(GeckoContentHandler)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(GeckoDownload)
|
||||
|
||||
enum {
|
||||
PROP_0,
|
||||
@@ -50,16 +50,16 @@ enum {
|
||||
|
||||
static const nsModuleComponentInfo sSugarComponents[] = {
|
||||
{
|
||||
"Sugar Content Handler",
|
||||
G_SUGARCONTENTHANDLER_CID,
|
||||
"Gecko Content Handler",
|
||||
GECKOCONTENTHANDLER_CID,
|
||||
NS_IHELPERAPPLAUNCHERDLG_CONTRACTID,
|
||||
GSugarContentHandlerConstructor
|
||||
GeckoContentHandlerConstructor
|
||||
},
|
||||
{
|
||||
"Sugar Download",
|
||||
G_SUGARDOWNLOAD_CID,
|
||||
"Gecko Download",
|
||||
GECKODOWNLOAD_CID,
|
||||
NS_TRANSFER_CONTRACTID,
|
||||
GSugarDownloadConstructor
|
||||
GeckoDownloadConstructor
|
||||
}
|
||||
};
|
||||
|
||||
@@ -78,7 +78,7 @@ sugar_browser_startup(void)
|
||||
PR_TRUE, getter_AddRefs(file));
|
||||
NS_ENSURE_TRUE(file, FALSE);
|
||||
|
||||
rv = prefService->ReadUserPrefs (file);
|
||||
rv = prefService->ReadUserPrefs (file);
|
||||
if (NS_FAILED(rv)) {
|
||||
g_warning ("failed to read default preferences, error: %x", rv);
|
||||
return FALSE;
|
||||
|
||||
@@ -0,0 +1,165 @@
|
||||
#include "sugar-marshal.h"
|
||||
#include "sugar-download.h"
|
||||
#include "sugar-download-manager.h"
|
||||
|
||||
enum {
|
||||
DOWNLOAD_STARTED,
|
||||
DOWNLOAD_COMPLETED,
|
||||
DOWNLOAD_CANCELLED,
|
||||
DOWNLOAD_PROGRESS,
|
||||
LAST_SIGNAL
|
||||
};
|
||||
static guint signals[LAST_SIGNAL] = { 0 };
|
||||
|
||||
static void sugar_download_manager_finalize (GObject *object);
|
||||
static void sugar_download_remove_download (gpointer key, gpointer value, gpointer user_data);
|
||||
|
||||
G_DEFINE_TYPE (SugarDownloadManager, sugar_download_manager, G_TYPE_OBJECT)
|
||||
|
||||
SugarDownloadManager *DownloadManager = NULL;
|
||||
|
||||
static void
|
||||
sugar_download_manager_init (SugarDownloadManager *download_manager)
|
||||
{
|
||||
download_manager->downloads = g_hash_table_new (g_str_hash, g_str_equal);
|
||||
}
|
||||
|
||||
static void
|
||||
sugar_download_manager_class_init (SugarDownloadManagerClass *download_manager_class)
|
||||
{
|
||||
GObjectClass *gobject_class = G_OBJECT_CLASS (download_manager_class);
|
||||
|
||||
gobject_class->finalize = sugar_download_manager_finalize;
|
||||
|
||||
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__OBJECT,
|
||||
G_TYPE_NONE, 1,
|
||||
G_TYPE_OBJECT);
|
||||
|
||||
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__OBJECT,
|
||||
G_TYPE_NONE, 1,
|
||||
G_TYPE_OBJECT);
|
||||
|
||||
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__OBJECT,
|
||||
G_TYPE_NONE, 1,
|
||||
G_TYPE_OBJECT);
|
||||
|
||||
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__OBJECT,
|
||||
G_TYPE_NONE, 1,
|
||||
G_TYPE_OBJECT);
|
||||
}
|
||||
|
||||
static void
|
||||
sugar_download_manager_finalize (GObject *object)
|
||||
{
|
||||
SugarDownloadManager *download_manager = SUGAR_DOWNLOAD_MANAGER (object);
|
||||
g_hash_table_foreach (download_manager->downloads, sugar_download_remove_download, NULL);
|
||||
g_hash_table_destroy (download_manager->downloads);
|
||||
}
|
||||
|
||||
static void
|
||||
sugar_download_remove_download (gpointer key, gpointer value, gpointer user_data)
|
||||
{
|
||||
g_free (value);
|
||||
}
|
||||
|
||||
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 *file_name)
|
||||
{
|
||||
SugarDownload *download = (SugarDownload *) g_hash_table_lookup (
|
||||
download_manager->downloads,
|
||||
file_name);
|
||||
|
||||
g_return_if_fail (download == NULL);
|
||||
|
||||
download = g_object_new (SUGAR_TYPE_DOWNLOAD, NULL);
|
||||
sugar_download_set_url (download, url);
|
||||
sugar_download_set_mime_type (download, mime_type);
|
||||
sugar_download_set_file_name (download, file_name);
|
||||
|
||||
g_hash_table_insert (download_manager->downloads,
|
||||
(gpointer)file_name,
|
||||
download);
|
||||
|
||||
g_signal_emit (download_manager, signals[DOWNLOAD_STARTED], 0, download);
|
||||
}
|
||||
|
||||
void
|
||||
sugar_download_manager_download_completed (SugarDownloadManager *download_manager,
|
||||
const char *file_name)
|
||||
{
|
||||
SugarDownload *download = (SugarDownload *) g_hash_table_lookup (
|
||||
download_manager->downloads,
|
||||
file_name);
|
||||
|
||||
g_return_if_fail (download);
|
||||
|
||||
g_signal_emit (download_manager, signals[DOWNLOAD_COMPLETED], 0, download);
|
||||
|
||||
g_hash_table_remove (download_manager->downloads, file_name);
|
||||
}
|
||||
|
||||
void sugar_download_manager_download_cancelled (SugarDownloadManager *download_manager,
|
||||
const char *file_name)
|
||||
{
|
||||
SugarDownload *download = (SugarDownload *) g_hash_table_lookup (
|
||||
download_manager->downloads,
|
||||
file_name);
|
||||
|
||||
g_return_if_fail (download);
|
||||
|
||||
g_signal_emit (download_manager, signals[DOWNLOAD_CANCELLED], 0, download);
|
||||
|
||||
g_hash_table_remove (download_manager->downloads, file_name);
|
||||
}
|
||||
|
||||
void
|
||||
sugar_download_manager_update_progress (SugarDownloadManager *download_manager,
|
||||
const char *file_name,
|
||||
const int percent)
|
||||
{
|
||||
SugarDownload *download = (SugarDownload *) g_hash_table_lookup (
|
||||
download_manager->downloads,
|
||||
file_name);
|
||||
|
||||
g_return_if_fail (download);
|
||||
|
||||
sugar_download_set_percent (download, percent);
|
||||
|
||||
g_signal_emit (download_manager, signals [DOWNLOAD_PROGRESS], 0, download);
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
#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;
|
||||
|
||||
GHashTable *downloads;
|
||||
};
|
||||
|
||||
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
|
||||
@@ -0,0 +1,108 @@
|
||||
#include "sugar-download.h"
|
||||
|
||||
static void sugar_download_finalize (GObject *object);
|
||||
|
||||
G_DEFINE_TYPE (SugarDownload, sugar_download, G_TYPE_OBJECT)
|
||||
|
||||
static void
|
||||
sugar_download_init (SugarDownload *download)
|
||||
{
|
||||
download->file_name = NULL;
|
||||
download->url = NULL;
|
||||
download->mime_type = NULL;
|
||||
download->percent = 0;
|
||||
}
|
||||
|
||||
static void
|
||||
sugar_download_class_init (SugarDownloadClass *download_class)
|
||||
{
|
||||
GObjectClass *gobject_class = G_OBJECT_CLASS (download_class);
|
||||
|
||||
gobject_class->finalize = sugar_download_finalize;
|
||||
}
|
||||
|
||||
void
|
||||
sugar_download_set_file_name (SugarDownload *download, const gchar *file_name)
|
||||
{
|
||||
gchar *new_file_name;
|
||||
|
||||
g_return_if_fail (SUGAR_IS_DOWNLOAD (download));
|
||||
|
||||
new_file_name = g_strdup (file_name);
|
||||
g_free (download->file_name);
|
||||
download->file_name = new_file_name;
|
||||
}
|
||||
|
||||
void
|
||||
sugar_download_set_url (SugarDownload *download, const gchar *url)
|
||||
{
|
||||
gchar *new_url;
|
||||
|
||||
g_return_if_fail (SUGAR_IS_DOWNLOAD (download));
|
||||
|
||||
new_url = g_strdup (url);
|
||||
g_free (download->url);
|
||||
download->url = new_url;
|
||||
}
|
||||
|
||||
void
|
||||
sugar_download_set_mime_type (SugarDownload *download, const gchar *mime_type)
|
||||
{
|
||||
gchar *new_mime_type;
|
||||
|
||||
g_return_if_fail (SUGAR_IS_DOWNLOAD (download));
|
||||
|
||||
new_mime_type = g_strdup (mime_type);
|
||||
g_free (download->mime_type);
|
||||
download->mime_type = new_mime_type;
|
||||
}
|
||||
|
||||
void
|
||||
sugar_download_set_percent (SugarDownload *download, const gint percent)
|
||||
{
|
||||
g_return_if_fail (SUGAR_IS_DOWNLOAD (download));
|
||||
|
||||
download->percent = percent;
|
||||
}
|
||||
|
||||
const gchar *
|
||||
sugar_download_get_file_name (SugarDownload *download)
|
||||
{
|
||||
g_return_val_if_fail (SUGAR_IS_DOWNLOAD (download), NULL);
|
||||
|
||||
return download->file_name;
|
||||
}
|
||||
|
||||
const gchar *
|
||||
sugar_download_get_url (SugarDownload *download)
|
||||
{
|
||||
g_return_val_if_fail (SUGAR_IS_DOWNLOAD (download), NULL);
|
||||
|
||||
return download->url;
|
||||
}
|
||||
|
||||
const gchar *
|
||||
sugar_download_get_mime_type (SugarDownload *download)
|
||||
{
|
||||
g_return_val_if_fail (SUGAR_IS_DOWNLOAD (download), NULL);
|
||||
|
||||
return download->mime_type;
|
||||
}
|
||||
|
||||
gint
|
||||
sugar_download_get_percent (SugarDownload *download)
|
||||
{
|
||||
g_return_val_if_fail (SUGAR_IS_DOWNLOAD (download), -1);
|
||||
|
||||
return download->percent;
|
||||
}
|
||||
|
||||
static void
|
||||
sugar_download_finalize (GObject *object)
|
||||
{
|
||||
SugarDownload *download = SUGAR_DOWNLOAD (object);
|
||||
|
||||
g_free (download->file_name);
|
||||
g_free (download->url);
|
||||
g_free (download->mime_type);
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
#ifndef __SUGAR_DOWNLOAD_H__
|
||||
#define __SUGAR_DOWNLOAD_H__
|
||||
|
||||
#include <glib-object.h>
|
||||
#include <glib.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
typedef struct _SugarDownload SugarDownload;
|
||||
typedef struct _SugarDownloadClass SugarDownloadClass;
|
||||
|
||||
#define SUGAR_TYPE_DOWNLOAD (sugar_download_get_type())
|
||||
#define SUGAR_DOWNLOAD(object) (G_TYPE_CHECK_INSTANCE_CAST((object), SUGAR_TYPE_DOWNLOAD, SugarDownload))
|
||||
#define SUGAR_DOWNLOAD_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), SUGAR_TYPE_DOWNLOAD, SugarDownloadClass))
|
||||
#define SUGAR_IS_DOWNLOAD(object) (G_TYPE_CHECK_INSTANCE_TYPE((object), SUGAR_TYPE_DOWNLOAD))
|
||||
#define SUGAR_IS_DOWNLOAD_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), SUGAR_TYPE_DOWNLOAD))
|
||||
#define SUGAR_DOWNLOAD_GET_CLASS(object) (G_TYPE_INSTANCE_GET_CLASS((object), SUGAR_TYPE_DOWNLOAD, SugarDownloadClass))
|
||||
|
||||
struct _SugarDownload {
|
||||
GObject base_instance;
|
||||
|
||||
gchar *file_name;
|
||||
gchar *url;
|
||||
gchar *mime_type;
|
||||
gint percent;
|
||||
};
|
||||
|
||||
struct _SugarDownloadClass {
|
||||
GObjectClass base_class;
|
||||
};
|
||||
|
||||
GType sugar_download_get_type(void);
|
||||
|
||||
void sugar_download_set_file_name (SugarDownload *download,
|
||||
const gchar *file_name);
|
||||
void sugar_download_set_url (SugarDownload *download,
|
||||
const gchar *url);
|
||||
void sugar_download_set_mime_type (SugarDownload *download,
|
||||
const gchar *mime_type);
|
||||
void sugar_download_set_percent (SugarDownload *download,
|
||||
const gint percent);
|
||||
|
||||
const gchar *sugar_download_get_file_name (SugarDownload *download);
|
||||
const gchar *sugar_download_get_url (SugarDownload *download);
|
||||
const gchar *sugar_download_get_mime_type (SugarDownload *download);
|
||||
gint sugar_download_get_percent (SugarDownload *download);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __SUGAR_DOWNLOAD_H__ */
|
||||
@@ -1,3 +1,3 @@
|
||||
VOID:OBJECT,STRING,LONG,LONG
|
||||
VOID:OBJECT,LONG
|
||||
VOID:STRING,STRING,STRING
|
||||
VOID:OBJECT
|
||||
|
||||
Reference in New Issue
Block a user