diff options
author | Raul Gutierrez Segales <rgs@itevenworks.net> | 2013-02-01 17:47:05 (GMT) |
---|---|---|
committer | Raul Gutierrez Segales <rgs@itevenworks.net> | 2013-02-03 07:37:18 (GMT) |
commit | 7757e04f8bc92f616108e2b4d138272810028f3f (patch) | |
tree | ed0b8cdeb1cb0d316b86034e2256e9741c239cf6 /extensions | |
parent | 9227fd84f4399b4a1181aed0dc465754c30350e7 (diff) |
[sharing] Add's 'Share to Facebook' capability
This also sets the foundations for adding sharing
capabilities for other services out there.
I guess this is mainly RFC for now, some thinking
is needed for the whole workflow of sharing out and
into the Journal.
Diffstat (limited to 'extensions')
-rw-r--r-- | extensions/cpsection/Makefile.am | 2 | ||||
-rw-r--r-- | extensions/cpsection/facebook/Makefile.am | 7 | ||||
-rw-r--r-- | extensions/cpsection/facebook/__init__.py | 21 | ||||
-rw-r--r-- | extensions/cpsection/facebook/model.py | 30 | ||||
-rw-r--r-- | extensions/cpsection/facebook/view.py | 77 |
5 files changed, 136 insertions, 1 deletions
diff --git a/extensions/cpsection/Makefile.am b/extensions/cpsection/Makefile.am index a92b5dd..0c4e852 100644 --- a/extensions/cpsection/Makefile.am +++ b/extensions/cpsection/Makefile.am @@ -1,5 +1,5 @@ SUBDIRS = aboutme aboutcomputer datetime frame keyboard language \ - modemconfiguration network power updater + modemconfiguration network power updater facebook sugardir = $(pkgdatadir)/extensions/cpsection sugar_PYTHON = __init__.py diff --git a/extensions/cpsection/facebook/Makefile.am b/extensions/cpsection/facebook/Makefile.am new file mode 100644 index 0000000..471c047 --- /dev/null +++ b/extensions/cpsection/facebook/Makefile.am @@ -0,0 +1,7 @@ +sugardir = $(pkgdatadir)/extensions/cpsection/facebook + +sugar_PYTHON = \ + __init__.py \ + model.py \ + view.py + diff --git a/extensions/cpsection/facebook/__init__.py b/extensions/cpsection/facebook/__init__.py new file mode 100644 index 0000000..28c0cca --- /dev/null +++ b/extensions/cpsection/facebook/__init__.py @@ -0,0 +1,21 @@ +# Copyright (C) 2013, Walter Bender - Raul Gutierrez Segales +# +# 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 + +from gettext import gettext as _ + +CLASS = 'FacebookConfig' +ICON = 'facebook-share' +TITLE = _('Configure your Facebook account') diff --git a/extensions/cpsection/facebook/model.py b/extensions/cpsection/facebook/model.py new file mode 100644 index 0000000..6eed773 --- /dev/null +++ b/extensions/cpsection/facebook/model.py @@ -0,0 +1,30 @@ +# Copyright (C) 2013 Walter Bender - Raul Gutierrez Segales +# +# 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 +# + +from gettext import gettext as _ +from gi.repository import GConf + +import time + +from jarabe.util import facebook_online_account as fboa + +def save_access_token(access_token, expires_in): + client = GConf.Client.get_default() + client.set_string(fboa.FacebookOnlineAccount.ACCESS_TOKEN_KEY, access_token) + expiry_time = int(time.time()) + expires_in + client.set_int(fboa.FacebookOnlineAccount.ACCESS_TOKEN_KEY_EXPIRATION_DATE, + expiry_time) diff --git a/extensions/cpsection/facebook/view.py b/extensions/cpsection/facebook/view.py new file mode 100644 index 0000000..fa394f7 --- /dev/null +++ b/extensions/cpsection/facebook/view.py @@ -0,0 +1,77 @@ +# Copyright (C) 2013, Walter Bender - Raul Gutierrez Segales +# +# 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 + +from gi.repository import Gtk +from gi.repository import GObject +from gi.repository import WebKit + +import urllib +import urlparse + +from gettext import gettext as _ + +from jarabe.controlpanel.sectionview import SectionView + +class FacebookConfig(SectionView): + APP_ID = "172917389475707" + REDIRECT_URI = "http://www.sugarlabs.org" + + def __init__(self, model, alerts): + SectionView.__init__(self) + + self._model = model + self.restart_alerts = alerts + + scrolled = Gtk.ScrolledWindow() + self.add(scrolled) + scrolled.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC) + scrolled.show() + + workspace = Gtk.VBox() + scrolled.add_with_viewport(workspace) + workspace.show() + + wkv = WebKit.WebView() + wkv.load_uri(self._auth_url()) + wkv.grab_focus() + wkv.connect('navigation-policy-decision-requested', self._nav_policy_cb) + workspace.add(wkv) + workspace.show_all() + + def undo(self): + pass + + def _auth_url(self): + url = 'http://www.facebook.com/dialog/oauth' + params = [ + ('client_id', self.APP_ID), + ('redirect_uri', self.REDIRECT_URI), + ('response_type', 'token'), + ('scope', 'publish_stream') + ] + + return "%s?%s" % (url, urllib.urlencode(params)) + + def _nav_policy_cb(self, view, frame, req, action, param): + uri = req.get_uri() + if uri is None: + return + + url_o = urlparse.urlparse(uri) + params = urlparse.parse_qs(url_o.fragment) + if params.has_key('access_token') and params.has_key('expires_in'): + self._model.save_access_token(params['access_token'][0], + int(params['expires_in'][0])) |