~ubuntu-branches/ubuntu/trusty/miro/trusty

« back to all changes in this revision

Viewing changes to portable/messages.py

  • Committer: Daniel Hahler
  • Date: 2010-04-13 18:51:35 UTC
  • mfrom: (1.2.10 upstream)
  • Revision ID: ubuntu-launchpad@thequod.de-20100413185135-xi24v1diqg8w406x
Merging shared upstream rev into target branch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# Miro - an RSS based video player application
2
 
# Copyright (C) 2005-2009 Participatory Culture Foundation
 
2
# Copyright (C) 2005-2010 Participatory Culture Foundation
3
3
#
4
4
# This program is free software; you can redistribute it and/or modify
5
5
# it under the terms of the GNU General Public License as published by
116
116
        try:
117
117
            handler = self.handler
118
118
        except AttributeError:
119
 
            logging.warn("No handler for backend messages (%s)", repr(self))
 
119
            logging.warn("No handler for backend messages")
120
120
        else:
121
121
            handler.handle(self)
122
122
 
127
127
        try:
128
128
            handler = self.handler
129
129
        except AttributeError:
130
 
            logging.warn("No handler for frontend messages (%s)", repr(self))
 
130
            logging.warn("No handler for frontend messages")
131
131
        else:
132
132
            handler.handle(self)
133
133
 
358
358
    def __init__(self, type, id, new_name):
359
359
        self.type = type
360
360
        self.id = id
361
 
        self.new_name = util.toUni(new_name)
 
361
        self.new_name = util.to_uni(new_name)
362
362
 
363
363
class UpdateFeed(BackendMessage):
364
364
    """Updates a feed.
397
397
        self.id = id
398
398
        self.resume_time = time
399
399
 
 
400
class SetItemMediaType(BackendMessage):
 
401
    """Adds a list of videos to a playlist.
 
402
    """
 
403
    def __init__(self, media_type, video_ids):
 
404
        self.media_type = media_type
 
405
        self.video_ids = video_ids
 
406
 
400
407
class UpdateAllFeeds(BackendMessage):
401
408
    """Updates all feeds.
402
409
    """
438
445
    """Create a new channel guide.
439
446
    """
440
447
    def __init__(self, url):
441
 
        self.url = util.toUni(url)
 
448
        self.url = util.to_uni(url)
442
449
 
443
450
class NewFeed(BackendMessage):
444
451
    """Creates a new feed.
445
452
    """
446
453
    def __init__(self, url, section=u"video"):
447
 
        self.url = util.toUni(url)
 
454
        self.url = util.to_uni(url)
448
455
        self.section = section
449
456
 
450
457
class NewFeedSearchFeed(BackendMessage):
488
495
    """Create a new playlist.
489
496
    """
490
497
    def __init__(self, name, ids):
491
 
        self.name = util.toUni(name)
 
498
        self.name = util.to_uni(name)
492
499
        self.ids = ids
493
500
 
494
501
class NewFeedFolder(BackendMessage):
495
502
    """Create a new feed folder.
496
503
    """
497
504
    def __init__(self, name, section, child_feed_ids):
498
 
        self.name = util.toUni(name)
 
505
        self.name = util.to_uni(name)
499
506
        self.section = section
500
507
        self.child_feed_ids = child_feed_ids
501
508
 
503
510
    """Create a new playlist folder.
504
511
    """
505
512
    def __init__(self, name, child_playlist_ids):
506
 
        self.name = util.toUni(name)
 
513
        self.name = util.to_uni(name)
507
514
        self.child_playlist_ids = child_playlist_ids
508
515
 
509
516
class ChangeMoviesDirectory(BackendMessage):
542
549
    :param metadata: dict of name/value pairs to include in the item.
543
550
    """
544
551
    def __init__(self, url, handle_unknown_callback=None, metadata=None):
545
 
        self.url = util.toUni(url)
 
552
        self.url = util.to_uni(url)
546
553
        self.handle_unknown_callback = handle_unknown_callback
547
554
        self.metadata = metadata
548
555
 
663
670
    def __repr__(self):
664
671
        return BackendMessage.__repr__(self) + (", id: %s" % self.id)
665
672
 
666
 
class RenameVideo(BackendMessage):
667
 
    """Renames the video.
 
673
class EditItem(BackendMessage):
 
674
    """Changes a bunch of things on an item.
668
675
    """
669
 
    def __init__(self, id, new_name):
670
 
        self.id = id
671
 
        self.new_name = new_name
 
676
    def __init__(self, item_id, change_dict):
 
677
        self.item_id = item_id
 
678
        self.change_dict = change_dict
672
679
 
673
680
class RevertFeedTitle(BackendMessage):
674
681
    """Reverts the feed's title back to the original.
676
683
    def __init__(self, id):
677
684
        self.id = id
678
685
 
679
 
class RevertItemTitle(BackendMessage):
680
 
    """Reverts the item's title back to the original.
681
 
    """
682
 
    def __init__(self, id):
683
 
        self.id = id
684
 
 
685
686
class PlayAllUnwatched(BackendMessage):
686
687
    """Figures out all the unwatched items and plays them.
687
688
    """
916
917
        self.name = guide.get_title()
917
918
        self.id = guide.id
918
919
        self.url = guide.get_url()
919
 
        self.default = guide.get_default()
 
920
        self.default = guide.is_default()
920
921
        self.allowed_urls = guide.allowedURLs
921
922
        self.favicon = guide.get_favicon_path()
922
923
        self.faviconIsDefault = not (guide.icon_cache and
951
952
    :param video_watched: has the user watched the video for the item?
952
953
    :param video_path: the file path to the video for this item (or None)
953
954
    :param file_type: type of the downloaded file (video/audio/other)
 
955
    :param media_type_checked: has the movie data util checked file_type?
954
956
    :param seeding_status: Torrent seeding status ('seeding', 'stopped',
955
957
                           or None)
956
958
    :param thumbnail: path to the thumbnail for this file
975
977
    :param down_rate: (Torrent only) how fast we're downloading data
976
978
    :param up_total: (Torrent only) total amount we've uploaded
977
979
    :param down_total: (Torrent only) total amount we've downloaded
 
980
    :param up_down_ratio: (Torrent only) ratio of uploaded to downloaded
978
981
    """
979
982
    def __init__(self, item):
980
983
        self.name = item.get_title()
981
 
        self.has_original_name = item.has_original_title()
982
984
        self.id = item.id
983
985
        self.feed_id = item.feed_id
984
986
        self.feed_name = item.get_source()
1017
1019
        else:
1018
1020
            self.children = []
1019
1021
        self.file_type = item.file_type
 
1022
        self.media_type_checked = item.media_type_checked
1020
1023
        self.seeding_status = item.torrent_seeding_status()
1021
1024
        self.mime_type = item.enclosure_type
1022
1025
        self.file_url = item.url
1031
1034
        ## Torrent-specific stuff
1032
1035
        self.leechers = self.seeders = self.up_rate = None
1033
1036
        self.down_rate = self.up_total = self.down_total = None
 
1037
        self.up_down_ratio = 0.0
1034
1038
        if item.looks_like_torrent() and hasattr(item.downloader, 'status'):
1035
1039
            status = item.downloader.status
1036
1040
            if item.is_transferring():
1043
1047
            # gettorrentdetailsfinished & gettorrentdetails
1044
1048
            self.up_total = status.get('uploaded', 0)
1045
1049
            self.down_total = status.get('currentSize', 0)
 
1050
            if self.down_total <= 0:
 
1051
                self.up_down_ratio = 0.0
 
1052
            else:
 
1053
                self.up_down_ratio = self.up_total * 1.0 / self.down_total
1046
1054
 
1047
1055
class DownloadInfo(object):
1048
1056
    """Tracks the download state of an item.
1060
1068
    """
1061
1069
    def __init__(self, downloader):
1062
1070
        self.downloaded_size = downloader.get_current_size()
1063
 
        self.rate = downloader.getRate()
 
1071
        self.rate = downloader.get_rate()
1064
1072
        self.state = downloader.get_state()
1065
1073
        self.startup_activity = downloader.get_startup_activity()
1066
 
        self.finished = downloader.isFinished()
 
1074
        self.finished = downloader.is_finished()
1067
1075
        self.torrent = (downloader.get_type() == 'bittorrent')
1068
1076
        if self.state == 'failed':
1069
 
            self.reason_failed = downloader.getReasonFailed()
1070
 
            self.short_reason_failed = downloader.getShortReasonFailed()
 
1077
            self.reason_failed = downloader.get_reason_failed()
 
1078
            self.short_reason_failed = downloader.get_short_reason_failed()
1071
1079
        else:
1072
1080
            self.reason_failed = u""
1073
1081
            self.short_reason_failed = u""
1074
 
        self.eta = downloader.getETA()
 
1082
        self.eta = downloader.get_eta()
1075
1083
 
1076
1084
class PendingDownloadInfo(DownloadInfo):
1077
1085
    """DownloadInfo object for pending downloads (downloads queued,
1113
1121
            # for it to have a default channel guide persisted, but when you
1114
1122
            # set the channel guide via the DTV_CHANNELGUIDE_URL, then there's
1115
1123
            # no default guide.  So we generate one here.  Bug #11027.
1116
 
            cg = guide.ChannelGuide(util.toUni(config.get(prefs.CHANNEL_GUIDE_URL)))
 
1124
            cg = guide.ChannelGuide(util.to_uni(config.get(prefs.CHANNEL_GUIDE_URL)))
1117
1125
            cg_info = GuideInfo(cg)
1118
1126
            self.default_guide = [cg_info]
1119
1127
        elif len(self.default_guide) > 1: