Skip to content

Commit

Permalink
Fixed to addon database management. There is now a function in aodb t…
Browse files Browse the repository at this point in the history
…hat handles the refresh operation and sends the appropriate notification. The Refresh buttons in the Maps and Addons tabs use this function to reload all addons.
  • Loading branch information
skyjake committed Dec 31, 2006
1 parent 8a5679b commit fecec3b
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 35 deletions.
3 changes: 3 additions & 0 deletions snowberry/lang/english.lang
Expand Up @@ -571,6 +571,9 @@ error-read-profile-text: The profile <tt>%1</tt> could not be loaded because an
error-read-manifest: Addon Manifest Error
error-read-manifest-text: An error was detected in the manifest file <tt>%1</tt>.<p><b>Reason:</b><p>%2

error-remove-addon-path-not-found: Internal Error
error-remove-addon-path-not-found-text: Someone attempted to remove an addon path that has not been registered: <tt>%1</tt>

warning-obsolete-plugin: Obsolete Plugin
warning-obsolete-plugin-text: The plugin <b>%1</b> loaded from <tt>%2</tt> is from an obsolete version. You should delete this plugin. Otherwise unexpected behavior may occur.

Expand Down
7 changes: 7 additions & 0 deletions snowberry/logger.py
Expand Up @@ -53,6 +53,13 @@ def add(severity, identifier, *args):
global allIssues

allIssues.append((severity, identifier, list(args)))


def immediate(severity, identifier, *args):
"""Show a logger issue immediately. See logger.add() for the params."""

add(severity, identifier, *args)
show()


def show():
Expand Down
4 changes: 3 additions & 1 deletion snowberry/paths.py
Expand Up @@ -28,7 +28,7 @@
## installation directory, and also contains Doomsday.

import os, re, sys
import host, events
import host, events, logger


def isHomeless():
Expand Down Expand Up @@ -312,6 +312,8 @@ def removeAddonPath(path):
"""
if path in addonPaths:
addonPaths.remove(path)
else:
logger.immediate(logger.HIGH, 'error-remove-addon-path-not-found', path)


def getAddonPaths():
Expand Down
27 changes: 16 additions & 11 deletions snowberry/plugins/profilelist.py
Expand Up @@ -58,6 +58,15 @@
'unhide-profiles']


def iconSizeString():
"""Determines the size of profile icons.
@return Size of profile icons in pixels, as a string."""
if st.getSystemBoolean('profile-large-icons'):
return '50'
else:
return '28'


def makeHTML(name, game):
# The icon for the game component.
iconName = language.translate(game + '-icon')
Expand All @@ -66,10 +75,7 @@ def makeHTML(name, game):
# The name of the game.
gameName = language.translate(game)

if st.getSystemBoolean('profile-large-icons'):
iconSize = '50'
else:
iconSize = '24'
iconSize = iconSizeString()

return '<table width="100%" border=0 cellspacing=2 cellpadding=5>' + \
'<tr><td width="' + iconSize + '"><img width="' + iconSize + \
Expand All @@ -81,15 +87,14 @@ def makeHTML(name, game):

def makeProfileHTML(profile):
if profile is pr.getDefaults():
# There should be a real icon for the Defaults profile.
iconPath = paths.findBitmap('defaults')
iconSize = iconSizeString()
return '<table width="100%" border=0 cellspacing=2 cellpadding=5>' + \
'<tr><td align=left >' + \
'<font size="+1"><b>' + \
profile.getName() + \
'</b></font>' + \
'<td width="48"><img src="' + iconPath + '"></table>'

'<tr><td width="' + iconSize + \
'"><img width="%s" height="%s"' % (iconSize, iconSize) + \
' src="' + iconPath + \
'"><td align=left><font size="+1"><b>' + profile.getName() + \
'</b></font></table>'
else:
game = 'game-undefined'
for c in profile.getComponents():
Expand Down
14 changes: 10 additions & 4 deletions snowberry/plugins/tab20_maps.py
Expand Up @@ -28,6 +28,7 @@
import os
import ui, events, language
import widgets as wg
import sb.widget.button as wb
import sb.widget.list
import sb.aodb as ao
import sb.profdb as pr
Expand Down Expand Up @@ -61,11 +62,12 @@ def init():
area.setWeight(0)
area.setBorderDirs(ui.BORDER_NOT_TOP)
buttonArea = area.createArea(alignment=ui.ALIGN_HORIZONTAL, border=4)
buttonArea.setBorderDirs(ui.BORDER_TOP)
buttonArea.setBorderDirs(ui.BORDER_TOP | ui.BORDER_RIGHT)
buttonArea.setWeight(0)
clearButton = buttonArea.createButton('maps-list-clear',
sb.widget.button.Button.STYLE_MINI)
clearButton = buttonArea.createButton('maps-list-clear', wb.Button.STYLE_MINI)
clearButton.resizeToBestSize()
refreshButton = buttonArea.createButton('refresh-addon-database', wb.Button.STYLE_MINI)
refreshButton.resizeToBestSize()

# Listen to our commands.
events.addCommandListener(handleCommand, ['maps-list-clear'])
Expand All @@ -74,7 +76,8 @@ def init():
'maps-list-selected',
'maps-list-deselected',
'addon-attached',
'addon-detached'])
'addon-detached',
'addon-database-reloaded'])


def handleCommand(event):
Expand Down Expand Up @@ -107,6 +110,9 @@ def handleNotify(event):
listenSelections = False
mapListBox.deselectItem(event.getAddon())
listenSelections = True

if event.hasId('addon-database-reloaded'):
refreshList()


def refreshList():
Expand Down
10 changes: 4 additions & 6 deletions snowberry/plugins/tab30_addons.py
Expand Up @@ -105,7 +105,7 @@ def init():
'addon-tree-selected',
'addon-installed',
'addon-uninstalled',
'addon-paths-changed'])
'addon-database-reloaded'])

# Registering a command listener to handle the Command events sent
# by the buttons created above.
Expand Down Expand Up @@ -166,7 +166,7 @@ def handleNotification(event):
tree.populateWithAddons(pr.getActive())
tree.selectAddon(event.addon)

elif event.hasId('addon-paths-changed'):
elif event.hasId('addon-database-reloaded'):
tree.removeAll()
tree.createCategories()
tree.populateWithAddons(pr.getActive())
Expand Down Expand Up @@ -195,8 +195,7 @@ def handleCommand(event):
selected = ''

if event.hasId('refresh-addon-database'):
ao.loadAll()
events.send(events.Notify('addon-paths-changed'))
ao.refresh()
return

elif event.hasId('install-addon'):
Expand Down Expand Up @@ -576,8 +575,7 @@ def browseAction():

elif result == 'addon-dialog-add-to-custom-folders':
paths.addAddonPath(pathField.getText())
ao.loadAll()
events.send(events.Notify('addon-paths-changed'))
ao.refresh()
return []

# The dialog was canceled.
Expand Down
47 changes: 34 additions & 13 deletions snowberry/sb/aodb.py
Expand Up @@ -669,35 +669,56 @@ def loadAll():
# Load all the installed addons in the system and user addon
# databases.
for repository in [paths.ADDONS] + paths.getAddonPaths():
print "repo:", repository
for name in paths.listFiles(repository):
# Case insensitive.
if re.search("(?i)^([^.#].*)\.(" + \
string.join(ao.EXTENSIONS, '|') + ")$",
os.path.basename(name)):
load(name)

# Load all the manifests.
for folder in [paths.getSystemPath(paths.MANIFESTS),
paths.getUserPath(paths.MANIFESTS)] + \
paths.getAddonPaths():
for name in paths.listFiles(folder):
# Case insensitive.
if paths.hasExtension('manifest', name):
loadManifest(name)


def refresh():
"""Empties the data of all loaded addons from the database and reloads
everything. Sends out a 'addon-database-reloaded' notification."""

init()
loadAll()
events.send(events.Notify('addon-database-reloaded'))


def init():
"""Initialize the addon database."""

global categories, rootCategory, addons

# Empty the cache.
categories = []
addons = {}

# Create the root category (for unclassified/generic addons).
rootCategory = Category('')
categories.append(rootCategory)


#
# Module Initialization
#

# Create the root category (for unclassified/generic addons).
rootCategory = Category('')
categories.append(rootCategory)

# Load the metadata cache.
init()
readMetaCache()

loadAll()

# Load all the manifests.
for folder in [paths.getSystemPath(paths.MANIFESTS),
paths.getUserPath(paths.MANIFESTS)] + \
paths.getAddonPaths():
for name in paths.listFiles(folder):
# Case insensitive.
if paths.hasExtension('manifest', name):
loadManifest(name)

# Save the updated cache.
writeMetaCache()

0 comments on commit fecec3b

Please sign in to comment.