1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
|
# Copyright (C) 2009 Canonical
#
# Authors:
# Michael Vogt
#
# 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; version 3.
#
# 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 Street, Fifth Floor, Boston, MA 02110-1301 USA
import apt
import gettext
import glib
import gobject
import gtk
import logging
import os
import sys
import string
import xapian
from gettext import gettext as _
from softwarecenter.enums import *
from appview import AppView, AppStore, AppViewFilter
from softwarepane import SoftwarePane, wait_for_apt_cache_ready
class InstalledPane(SoftwarePane):
"""Widget that represents the installed panel in software-center
It contains a search entry and navigation buttons
"""
(PAGE_APPLIST,
PAGE_APP_DETAILS) = range(2)
def __init__(self, cache, db, icons, datadir):
# parent
SoftwarePane.__init__(self, cache, db, icons, datadir)
# state
self.apps_filter = AppViewFilter(cache)
self.apps_filter.set_installed_only(True)
# UI
self._build_ui()
def _build_ui(self):
# appview and details into the notebook in the bottom
self.app_view.connect("application-activated",
self.on_application_activated)
self.notebook.append_page(self.scroll_app_list, gtk.Label("installed"))
# details
self.notebook.append_page(self.scroll_details, gtk.Label("details"))
# initial refresh
self.search_terms = ""
self.refresh_apps()
@wait_for_apt_cache_ready
def refresh_apps(self):
"""refresh the applist after search changes and update the
navigation bar
"""
if self.search_terms:
query = self.xapiandb.get_query_from_search_entry(self.search_terms)
else:
query = None
self.navigation_bar.add_with_id(_("Installed Software"),
self.on_navigation_list,
"list")
# get a new store and attach it to the view
new_model = AppStore(self.cache,
self.xapiandb,
self.icons,
query,
filter=self.apps_filter)
self.app_view.set_model(new_model)
self.emit("app-list-changed", len(new_model))
return False
def on_search_terms_changed(self, searchentry, terms):
"""callback when the search entry widget changes"""
logging.debug("on_search_terms_changed: '%s'" % terms)
self.search_terms = terms
self.refresh_apps()
self.notebook.set_current_page(self.PAGE_APPLIST)
def on_application_activated(self, appview, name, pkgname):
"""callback when a app is clicked"""
logging.debug("on_application_activated: '%s'" % name)
self.navigation_bar.add_with_id(name,
self.on_navigation_details,
"details")
self.notebook.set_current_page(self.PAGE_APP_DETAILS)
self.app_details.show_app(name, pkgname)
def on_navigation_list(self, button):
"""callback when the navigation button with id 'list' is clicked"""
if not button.get_active():
return
# remove the details and clear the search
self.searchentry.clear()
self.navigation_bar.remove_id("details")
self.notebook.set_current_page(self.PAGE_APPLIST)
self.searchentry.show()
# only emit something if the model is there
model = self.app_view.get_model()
if model:
self.emit("app-list-changed", len(model))
def on_navigation_details(self, button):
"""callback when the navigation button with id 'details' is clicked"""
if not button.get_active():
return
self.notebook.set_current_page(self.PAGE_APP_DETAILS)
self.searchentry.hide()
def get_status_text(self):
"""return user readable status text suitable for a status bar"""
# no status text in the details page
if self.notebook.get_current_page() == self.PAGE_APP_DETAILS:
return ""
# otherwise, show status based on search or not
length = len(self.app_view.get_model())
if len(self.searchentry.get_text()) > 0:
return gettext.ngettext("%s matching item",
"%s matching items",
length) % length
else:
return gettext.ngettext("%s installed item",
"%s installed items",
length) % length
if __name__ == "__main__":
#logging.basicConfig(level=logging.DEBUG)
xapian_base_path = XAPIAN_BASE_PATH
pathname = os.path.join(xapian_base_path, "xapian")
if len(sys.argv) > 1:
datadir = sys.argv[1]
elif os.path.exists("./data"):
datadir = "./data"
else:
datadir = "/usr/share/software-center"
db = xapian.Database(pathname)
icons = gtk.icon_theme_get_default()
icons.append_search_path("/usr/share/app-install/icons/")
cache = apt.Cache(apt.progress.OpTextProgress())
cache.ready = True
w = InstalledPane(cache, db, icons, datadir)
w.show()
win = gtk.Window()
win.add(w)
win.set_size_request(400,600)
win.show_all()
gtk.main()
|