Skip to content

Commit

Permalink
Merge branch 'remove-deprecated' into integration
Browse files Browse the repository at this point in the history
  • Loading branch information
multani committed Apr 6, 2012
2 parents d575dc4 + ffc6b65 commit 81dc8fc
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 175 deletions.
5 changes: 5 additions & 0 deletions README.rst
Expand Up @@ -112,6 +112,11 @@ Currently, the following things have been changed since the Berlios's version:

Thanks to Zhihao Yuan for the fixes!

* Remove a bunch of code used for old or deprecated components (MPD, pyGtk,
DBus, etc.)

This is the `remove-deprecated` branch.

Personal todo list
------------------

Expand Down
24 changes: 12 additions & 12 deletions sonata/current.py
Expand Up @@ -556,18 +556,18 @@ def on_dnd(self, treeview, drag_context, x, y, selection, _info,
for item in listallinfo:
if 'file' in item:
mpdpaths.append(mpdh.get(item, 'file'))
elif self.mpd.version >= (0, 14):
# Add local file, available in mpd 0.14. This currently
# work because python-mpd does not support unix socket
# paths, won't which is needed for authentication for
# local files. It's also therefore untested.
if os.path.isdir(misc.file_from_utf8(paths[i])):
filenames = misc.get_files_recursively(paths[i])
else:
filenames = [paths[i]]
for filename in filenames:
if os.path.exists(misc.file_from_utf8(filename)):
mpdpaths.append("file://" + urllib.quote(filename))

# Add local file, available in mpd 0.14. This currently
# work because python-mpd does not support unix socket
# paths, won't which is needed for authentication for
# local files. It's also therefore untested.
if os.path.isdir(misc.file_from_utf8(paths[i])):
filenames = misc.get_files_recursively(paths[i])
else:
filenames = [paths[i]]
for filename in filenames:
if os.path.exists(misc.file_from_utf8(filename)):
mpdpaths.append("file://" + urllib.quote(filename))
if len(mpdpaths) > 0:
# Items found, add to list at drop position:
if drop_info:
Expand Down
20 changes: 5 additions & 15 deletions sonata/dbus_plugin.py
Expand Up @@ -26,14 +26,7 @@
try:
import dbus
import dbus.service
if getattr(dbus, "version", (0, 0, 0)) >= (0, 41, 0):
import dbus.glib
if getattr(dbus, "version", (0, 0, 0)) >= (0, 80, 0):
import _dbus_bindings as dbus_bindings
NEW_DBUS = True
else:
import dbus.dbus_bindings as dbus_bindings
NEW_DBUS = False
import _dbus_bindings as dbus_bindings
HAVE_DBUS = True
except:
HAVE_DBUS = False
Expand Down Expand Up @@ -137,13 +130,10 @@ def start_dbus_interface():
if HAVE_DBUS:
try:
bus = get_session_bus()
if NEW_DBUS:
retval = bus.request_name("org.MPD.Sonata",
dbus_bindings.NAME_FLAG_DO_NOT_QUEUE)
else:
retval = dbus_bindings.bus_request_name(bus.get_connection(),
"org.MPD.Sonata",
dbus_bindings.NAME_FLAG_DO_NOT_QUEUE)

retval = bus.request_name("org.MPD.Sonata",
dbus_bindings.NAME_FLAG_DO_NOT_QUEUE)

if retval in (dbus_bindings.REQUEST_NAME_REPLY_PRIMARY_OWNER,
dbus_bindings.REQUEST_NAME_REPLY_ALREADY_OWNER):
pass
Expand Down
11 changes: 0 additions & 11 deletions sonata/launcher.py
Expand Up @@ -68,10 +68,6 @@ def run():

## Apply global fixes:

# the following line is to fix python-zsi 2.0 and thus lyrics in ubuntu:
# https://bugs.launchpad.net/ubuntu/+source/zsi/+bug/208855
sys.path.append('/usr/lib/python2.5/site-packages/oldxml')

# hint for gnome.init to set the process name to 'sonata'
if platform.system() == 'Linux':
sys.argv[0] = 'sonata'
Expand Down Expand Up @@ -135,9 +131,6 @@ def run():
if not args.skip_gui:
# importing gtk does sys.setdefaultencoding("utf-8"), sets locale etc.
import gtk
if gtk.pygtk_version < (2, 12, 0):
logger.critical("Sonata requires PyGTK 2.12.0 or newer. Aborting...")
sys.exit(1)
# fix locale
misc.setlocale()
else:
Expand All @@ -163,10 +156,6 @@ class FakeModule(object):
if not args.skip_gui:
gtk.gdk.threads_init()

# we don't use gtk.LinkButton, but gtk.AboutDialog does;
# in gtk 2.16.0 without this, the about uri opens doubly:
gtk.link_button_set_uri_hook(lambda *args:None)

## CLI actions:

args.execute_cmds()
Expand Down
35 changes: 4 additions & 31 deletions sonata/library.py
Expand Up @@ -890,20 +890,9 @@ def library_return_count(self, genre=None, artist=None, album=None,
playtime = 0
num_songs = 0
for s in searches:

if '' in s and self.mpd.version <= (0, 13):

# Can't return count for empty tags, use search instead:

_results, playtime, num_songs = \
self.library_return_search_items(
genre=genre, artist=artist, album=album, year=year)

else:

count = self.mpd.count(*s)
playtime += mpdh.get(count, 'playtime', 0, True)
num_songs += mpdh.get(count, 'songs', 0, True)
count = self.mpd.count(*s)
playtime += mpdh.get(count, 'playtime', 0, True)
num_songs += mpdh.get(count, 'songs', 0, True)

return (playtime, num_songs)

Expand Down Expand Up @@ -1001,23 +990,7 @@ def library_return_search_items(self, genre=None, artist=None, album=None,
playtime = 0
num_songs = 0
results = []

if '' in s and self.mpd.version <= (0, 13):

# Can't search for empty tags, search broader and
# filter instead:

# Strip empty tag args from tuple:
pos = list(args_tuple).index('')
strip_type = list(args_tuple)[pos-1]
new_lst = []
for i, item in enumerate(list(args_tuple)):
if i != pos and i != pos-1:
new_lst.append(item)
args_tuple = tuple(new_lst)

else:
strip_type = None
strip_type = None

if len(args_tuple) == 0:
return None, 0, 0
Expand Down
5 changes: 2 additions & 3 deletions sonata/main.py
Expand Up @@ -2834,7 +2834,7 @@ def systemtray_activate(self, _status_icon):
self.tooltip_set_ignore_toggle_signal_false)

def systemtray_click(self, _widget, event):
# Clicking on an egg system tray icon:
# Clicking on a system tray icon:
# Left button shows/hides window(s)
if event.button == 1 and not self.ignore_toggle_signal:
self.systemtray_activate(None)
Expand Down Expand Up @@ -3427,8 +3427,7 @@ def update_menu_visibility(self, show_songinfo_only=False):
for menu in ['add', 'replace', 'playafter', 'rm']:
self.UIManager.get_widget('/mainmenu/%smenu/' % \
(menu,)).show()
if self.playlists_selection.count_selected_rows() == 1 and \
self.mpd.version >= (0, 13):
if self.playlists_selection.count_selected_rows() == 1:
self.UIManager.get_widget('/mainmenu/renamemenu/').show()
else:
self.UIManager.get_widget('/mainmenu/renamemenu/').hide()
Expand Down
2 changes: 1 addition & 1 deletion sonata/mpdhelper.py
Expand Up @@ -94,7 +94,7 @@ def update(self, paths):
dirs.append(os.path.dirname(path))
dirs = remove_list_duplicates(dirs, True)

if len(dirs) > 32 and self.version >= (0, 14):
if len(dirs) > 32:
self._client.update('/')
else:
self._client.command_list_ok_begin()
Expand Down
4 changes: 2 additions & 2 deletions sonata/playlists.py
Expand Up @@ -224,8 +224,8 @@ def populate(self):
playlistinfo.sort(key=lambda x: x.lower())
for item in playlistinfo:
self.playlistsdata.append([gtk.STOCK_JUSTIFY_FILL, item])
if self.mpd.version >= (0, 13):
self.populate_playlists_for_menu(playlistinfo)

self.populate_playlists_for_menu(playlistinfo)

def on_playlist_rename(self, _action):
plname = self.prompt_for_playlist_name(_("Rename Playlist"),
Expand Down
103 changes: 3 additions & 100 deletions sonata/tray.py
Expand Up @@ -129,27 +129,15 @@ def get_tray_icon_factory():
This will detect the best way to create a tray icon:
* if the egg.trayicon module is available, then use it
* if the gtk.StatusIcon is available, then use it
* else, use a dummy tray icon, we should show no tray icon at all
"""

# Prevent deprecation warning for egg:
import warnings
warnings.simplefilter('ignore', DeprecationWarning)
try:
import egg.trayicon
factory = TrayIconEgg
from sugar.activity import activity
return TrayIconDummy
except ImportError:
try:
from sugar.activity import activity
factory = TrayIconDummy
except ImportError:
factory = TrayIconGtk
# Reset so that we can see any other deprecation warnings
warnings.simplefilter('default', DeprecationWarning)

return factory
return TrayIconGtk


class TrayIconDummy(object):
Expand Down Expand Up @@ -180,91 +168,6 @@ def is_available(self):
return False


class TrayIconEgg(object):
"""Tray icon which use egg.trayicon module"""

def __init__(self, window, traymenu, traytips):
self.trayicon = None
self.trayimage = None
self.eggtrayfile = None
self.eggtrayheight = None
self.trayeventbox = None
self.traytips = traytips

def compute_pos(self):
widget = self.trayeventbox
x, y = widget.window.get_origin()
if widget.flags() & gtk.NO_WINDOW:
x += widget.allocation.x
y += widget.allocation.y
height = widget.allocation.height
width = widget.allocation.width
return x, y, width, height

def initialize(self, on_click, on_scroll, on_activate):
# Local import to not break if egg.trayicon is not available
import egg.trayicon
self.trayimage = ui.image()
self.trayeventbox = ui.eventbox(add=self.trayimage)
self.trayeventbox.connect('button_press_event', on_click)
self.trayeventbox.connect('scroll-event', on_scroll)
self.trayeventbox.connect('size-allocate', self._systemtray_size)
self.trayeventbox.connect_after("event-after", self._motion_cb)
self.trayicon = egg.trayicon.TrayIcon("TrayIcon")
self.trayicon.add(self.trayeventbox)

def is_visible(self):
return self.trayicon.get_property('visible')

def update_icon(self, icon_path):
self.eggtrayfile = icon_path
self._set_tray_image()

def show(self):
self.trayicon.show_all()

def hide(self):
self.trayicon.hide_all()

def is_available(self):
# TODO: does eggtray as any way to know it the systray is available in
# the current window manager?
return True

def _set_tray_image(self):
if self.eggtrayheight is None:
# The tray height has not been computed yet, so we can't display the
# tray icon yet.
return

self.trayimage.set_from_pixbuf(
img.get_pixbuf_of_size(
gtk.gdk.pixbuf_new_from_file(self.eggtrayfile),
self.eggtrayheight)[0])

def _event_handler(self):
self.trayeventbox.connect_after("event-after", self._motion_cb)

def _motion_cb(self, tray_icon, event):
if self.traytips.notif_handler != None:
return
if event.type == gtk.gdk.LEAVE_NOTIFY:
self.traytips._remove_timer()
if event.type == gtk.gdk.ENTER_NOTIFY:
self.traytips._start_delay(self)

def _systemtray_size(self, widget, _allocation):
if widget.allocation.height <= 5:
# For vertical panels, height can be 1px, so use width
size = widget.allocation.width
else:
size = widget.allocation.height
if not self.eggtrayheight or self.eggtrayheight != size:
self.eggtrayheight = size
if size > 5 and self.eggtrayfile:
self._set_tray_image()


class TrayIconGtk(object):
"""Tray icon which use gtk.StatusIcon"""

Expand Down

0 comments on commit 81dc8fc

Please sign in to comment.