1
# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
3
# Copyright (C) 2012 David Planella <david.planella@ubuntu.com>
4
# This program is free software: you can redistribute it and/or modify it
5
# under the terms of the GNU General Public License version 3, as published
6
# by the Free Software Foundation.
8
# This program is distributed in the hope that it will be useful, but
9
# WITHOUT ANY WARRANTY; without even the implied warranties of
10
# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
11
# PURPOSE. See the GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License along
14
# with this program. If not, see <http://www.gnu.org/licenses/>.
17
from qreator_lib.i18n import _
18
from qreator_lib.helpers import get_data_file
19
from gi.repository import Gtk, GdkPixbuf, GLib
21
sys.path.insert(0, "/usr/share/software-center/")
22
import softwarecenter.db.database
26
class QRCodeSoftwareCenterAppGtk(object):
27
def __init__(self, qr_code_update_func):
28
self.qr_code_update_func = qr_code_update_func
29
self.builder = Gtk.Builder()
31
self.builder.add_from_file(
32
get_data_file('ui', '%s.ui' % ('QrCodeSoftwareCentreApp',)))
33
self.grid = self.builder.get_object('qr_code_softwarecenterapp')
34
self.builder.connect_signals(self)
37
# Initialize the Software Center apps autocompletion
38
self.softwarecenterapps = None
40
self.usc_apps_complete = Complete()
42
self.usc_apps_complete.set_hexpand(True)
43
self.usc_apps_complete.connect("changed",
44
self.on_usc_apps_complete_changed, None)
45
#self.usc_apps_complete.connect("icon-press",
46
# self.on_usc_apps_complete_icon_pressed)
47
self.usc_apps_complete.set_icon_from_icon_name(
48
Gtk.EntryIconPosition.PRIMARY, 'edit-find-symbolic')
49
self.usc_apps_complete.set_icon_from_stock(
50
Gtk.EntryIconPosition.SECONDARY, None)
52
self.grid.attach(self.usc_apps_complete, 1, 0, 1, 1)
53
self.softwarecenter_apps_init = False
56
def on_activated(self):
58
#if not self.softwarecenter_apps_init:
59
# GLib.idle_add(self.init_softwarecenter_apps)
61
def init_softwarecenter_apps(self):
62
deferred = defer.defer(self.get_softwarecenterapps)
63
deferred.add_callback(self.on_get_softwarecenterapps)
64
self.softwarecenter_apps_init = True
66
def on_usc_apps_complete_changed(self, widget, data=None):
67
#self._check_style(widget)
68
USC_APPS_BASE_URL = 'https://apps.ubuntu.com/cat/applications/'
69
self.qr_code_update_func(USC_APPS_BASE_URL + widget.get_text())
71
def get_softwarecenterapps(self):
73
db = softwarecenter.db.database.StoreDatabase()
75
db.open(use_axi=False, use_agent=False)
78
app = db.get_application(doc)
79
appdetails = app.get_details(db)
80
appinfo = App(app.appname, app.pkgname, appdetails.icon)
82
self.softwarecenterapps = apps
85
def on_get_softwarecenterapps(self, result):
86
print 'Task FINISHED!'
87
self.usc_apps_complete.add(self.softwarecenterapps)
91
def __init__(self, name, package, icon):
93
self.package = package
97
class Complete(Gtk.Entry):
98
'''a class to autocomplete'''
100
def __init__(self, apps=None):
101
Gtk.Entry.__init__(self)
102
self.completion = Gtk.EntryCompletion()
103
self.set_completion(self.completion)
104
self.model = Gtk.ListStore(str, GdkPixbuf.Pixbuf, str)
105
self.completion.set_model(self.model)
106
self.completion_img = Gtk.CellRendererPixbuf()
107
self.completion.pack_start(self.completion_img, True)
108
self.completion.add_attribute(self.completion_img, "pixbuf", 1)
109
self.completion.set_text_column(0)
110
self.completion.set_popup_set_width(False)
111
self.completion.set_inline_completion(True)
112
self.icons = Gtk.IconTheme.get_default()
113
self.icons.append_search_path("/usr/share/app-install/icons/")
118
# TRANSLATORS: this message appears for a few seconds on the
119
# Software Center apps text entry until the app names to
120
# suggest for autocompletion have been read from the Software
122
self.set_placeholder_text(
123
_('[Wait a few seconds to enable autocompletion...]'))
128
self.set_placeholder_text(
129
_('[Type the name of an app]'))
131
def _remember(self, app):
132
'''Add a value to the list of strings to suggest'''
134
icon = self.icons.load_icon(
135
"{0}".format(app.icon),
136
16, Gtk.IconLookupFlags.USE_BUILTIN)
138
icon = self.icons.load_icon(
140
16, Gtk.IconLookupFlags.USE_BUILTIN)
141
self.model.append([app.package, icon, app.name])