Commit 08f8cda3 authored by Alex Muñoz's avatar Alex Muñoz Committed by John Stowers
parent 04e31501
# This file is part of gnome-tweak-tool.
#
# Copyright (c) 2011 John Stowers
#
# gnome-tweak-tool 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 3 of the License, or
# (at your option) any later version.
#
# gnome-tweak-tool 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 gnome-tweak-tool. If not, see <http://www.gnu.org/licenses/>.
import json
import logging
from gi.repository import GObject
from gi.repository import Soup, SoupGNOME
class ExtensionsDotGnomeDotOrg(GObject.GObject):
__gsignals__ = {
"got-extensions": (GObject.SIGNAL_RUN_FIRST, GObject.TYPE_NONE,
(GObject.TYPE_PYOBJECT,)),
"got-extension-info": (GObject.SIGNAL_RUN_FIRST, GObject.TYPE_NONE,
(GObject.TYPE_PYOBJECT,GObject.TYPE_STRING)),
}
def __init__(self, shell_version_tuple):
GObject.GObject.__init__(self)
self._session = Soup.SessionAsync.new()
self._session.add_feature_by_type(SoupGNOME.ProxyResolverGNOME)
self._shell_version_tuple = shell_version_tuple
self._extensions = {}
def _query_extensions_finished(self, msg, url):
if msg.status_code == 200:
#server returns a list of extensions which may contain duplicates, dont know
resp = json.loads(msg.response_body.data)
print resp
for e in resp["extensions"]:
self._extensions[e["uuid"]] = e
self.emit("got-extensions", self._extensions)
def _query_extension_info_finished(self, msg, uuid):
if msg.status_code == 200:
self.emit("got-extension-info", json.loads(msg.response_body.data), uuid)
def query_extensions(self):
url = "https://extensions.gnome.org/extension-query/?"
ver = self._shell_version_tuple
if ver[1] % 2:
#if this is a development version (odd) then query the full version
url += "shell_version=%d.%d.%d&" % ver
else:
#else query in point releases up to the current version, and filter duplicates
#from the reply
url += "shell_version=%d.%d&" % (ver[0],ver[1])
for i in range(1,ver[2]+1):
url += "shell_version=%d.%d.%d&" % (ver[0],ver[1], i)
#non-paginated
url += "n_per_page=-1"
logging.debug("Query URL: %s" % url)
message = Soup.Message.new('GET', url)
message.connect("finished", self._query_extensions_finished, url)
self._session.queue_message(message, None, None)
def query_extension_info(self, extension_uuid):
if extension_uuid in self._extensions:
print "CACHED"
self.emit("got-extension-info", self._extensions[extension_uuid])
return
url = "https://extensions.gnome.org/extension-info/?uuid=%s" % extension_uuid
logging.debug("Query URL: %s" % url)
message = Soup.Message.new('GET', url)
message.connect("finished", self._query_extension_info_finished, extension_uuid)
self._session.queue_message(message, None, None)
def get_download_url(self, extinfo):
url = "https://extensions.gnome.org/download-extension/%s.shell-extension.zip?version_tag=%d"
#version tag is the pk in the shell_version_map
#url = url % (extinfo["uuid"],
if __name__ == "__main__":
import pprint
from gi.repository import Gtk, GLib
def _got_ext(ego, extensions):
print "="*80
pprint.pprint(extensions.values())
def _got_ext_info(ego, extension):
pprint.pprint(extension)
logging.basicConfig(format="%(levelname)-8s: %(message)s", level=logging.DEBUG)
e = ExtensionsDotGnomeDotOrg((3,4,1))
e.connect("got-extensions", _got_ext)
e.connect("got-extension-info", _got_ext_info)
e.query_extensions()
#e.query_extensions((3,4,0))
#e.query_extensions((3,3,2))
e.query_extension_info("user-theme@gnome-shell-extensions.gcampax.github.com")
Gtk.main()
......@@ -164,6 +164,9 @@ class GnomeShell36(GnomeShell34):
def uninstall_extension(self, uuid):
return self._proxy.proxy_extensions.UninstallExtension('(s)', uuid)
def install_remote_extension(self, uuid):
return self._proxy.proxy_extensions.InstallRemoteExtension('(s)', uuid)
@gtweak.utils.singleton
class GnomeShellFactory:
def __init__(self):
......
......@@ -3,17 +3,21 @@ import zipfile
import tempfile
import logging
import json
import threading
from gi.repository import Gtk
from gi.repository import GLib
from gi.repository import GObject
from operator import itemgetter
from gtweak.utils import extract_zip_file, execute_subprocess
from gtweak.gshellwrapper import GnomeShell, GnomeShellFactory
from gtweak.tweakmodel import Tweak, TweakGroup
from gtweak.widgets import FileChooserButton, build_label_beside_widget, build_horizontal_sizegroup, build_tight_button, UI_BOX_SPACING
from gtweak.egowrapper import ExtensionsDotGnomeDotOrg
def N_(x): return x
GObject.threads_init()
class _ShellExtensionTweak(Tweak):
......@@ -99,6 +103,27 @@ class _ShellExtensionTweak(Tweak):
self.widget.set_sensitive(False)
dialog.destroy()
def _on_extension_update(self, btn, uuid):
self._shell.uninstall_extension(uuid)
self.widget.set_sensitive(False)
thread = threading.Thread(target=self.download_extension, args=(btn,uuid,))
thread.start()
def download_extension(self, btn,uuid):
status = self._shell.install_remote_extension(uuid)
if status == 's':
GObject.idle_add(btn.set_sensitive, False)
GObject.idle_add(self.widget.set_sensitive, True)
def add_update_button(self, uuid):
button = build_tight_button(Gtk.STOCK_REFRESH)
button.connect("clicked", self._on_extension_update, uuid)
self.widget.pack_start(button, False, False, 0)
self.widget.reorder_child(button, 1)
#if the widget calls directly the show_all method, This will be shown in any visible parent widget.
if self.widget.get_visible() == True:
self.widget.show_all()
class _ShellExtensionInstallerTweak(Tweak):
def __init__(self, shell, **options):
......@@ -201,14 +226,19 @@ class ShellExtensionTweakGroup(TweakGroup):
#add the extension installer
extension_tweaks.append(
_ShellExtensionInstallerTweak(shell, size_group=sg))
version = tuple(shell.version.split("."))
ego = ExtensionsDotGnomeDotOrg(version)
try:
#add a tweak for each installed extension
extensions = sorted(shell.list_extensions().values(), key=itemgetter("name"))
for extension in extensions:
try:
extension_tweaks.append(
_ShellExtensionTweak(shell, extension, size_group=sg))
extension_widget = _ShellExtensionTweak(shell, extension, size_group=sg)
extension_tweaks.append(extension_widget)
if extension.get("type") == GnomeShell.EXTENSION_TYPE["PER_USER"]:
ego.connect("got-extension-info", self._got_info, extension, extension_widget)
ego.query_extension_info(extension["uuid"])
except:
logging.warning("Invalid extension", exc_info=True)
except:
......@@ -218,6 +248,19 @@ class ShellExtensionTweakGroup(TweakGroup):
self.set_tweaks(*extension_tweaks)
def _got_info(self, ego, resp, uuid, extension, widget):
if uuid == extension["uuid"]:
resp = resp['shell_version_map']
shell = GnomeShellFactory().get_shell()
version = shell.version[0:3]
try:
resp = resp[version]
if int(resp["version"]) > extension["version"]:
widget.add_update_button(uuid)
except KeyError:
print "Older/Unknown Version"
TWEAK_GROUPS = (
ShellExtensionTweakGroup(),
)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment