~ubuntu-branches/ubuntu/intrepid/miro/intrepid

« back to all changes in this revision

Viewing changes to portable/item.py

  • Committer: Bazaar Package Importer
  • Author(s): Christopher James Halse Rogers
  • Date: 2008-02-09 13:37:10 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20080209133710-9rs90q6gckvp1b6i
Tags: 1.1.2-0ubuntu1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
# You should have received a copy of the GNU General Public License
15
15
# along with this program; if not, write to the Free Software
16
16
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
 
17
#
 
18
# In addition, as a special exception, the copyright holders give
 
19
# permission to link the code of portions of this program with the OpenSSL
 
20
# library.
 
21
#
 
22
# You must obey the GNU General Public License in all respects for all of
 
23
# the code used other than OpenSSL. If you modify file(s) with this
 
24
# exception, you may extend this exception to your version of the file(s),
 
25
# but you are not obligated to do so. If you do not wish to do so, delete
 
26
# this exception statement from your version. If you delete this exception
 
27
# statement from all source files in the program, then also delete it here.
17
28
 
18
29
from copy import copy
19
30
from datetime import datetime, timedelta
27
38
import os
28
39
import os.path
29
40
import urllib
 
41
import urlparse
30
42
import shutil
31
43
import traceback
32
44
 
63
75
import searchengines
64
76
import fileutil
65
77
import imageresize
 
78
import license
66
79
 
67
80
_charset = locale.getpreferredencoding()
68
81
 
95
108
        self.screenshot = None
96
109
        self.resized_screenshots = {}
97
110
        self.resumeTime = 0
 
111
        self.channelTitle = None
98
112
 
99
113
        self.iconCache = IconCache(self)
100
114
        
670
684
 
671
685
    ##
672
686
    # Marks the item as seen
673
 
    def markItemSeen(self):
 
687
    def markItemSeen(self, markOtherItems=True):
674
688
        self.confirmDBThread()
675
689
        if self.seen == False:
676
690
            self.seen = True
678
692
                self.watchedTime = datetime.now()
679
693
            self.clearParentsChildrenSeen()
680
694
            self.signalChange()
 
695
            if markOtherItems and self.downloader:
 
696
                for item in self.downloader.itemList:
 
697
                    if item != self:
 
698
                        item.markItemSeen(False)
681
699
 
682
700
    def clearParentsChildrenSeen(self):
683
701
        if self.parent_id:
685
703
            parent.childrenSeen = None
686
704
            parent.signalChange()
687
705
 
688
 
    def markItemUnseen(self):
 
706
    def markItemUnseen(self, markOtherItems=True):
689
707
        self.confirmDBThread()
690
708
        if self.isContainerItem:
691
709
            self.childrenSeen = False
700
718
            self.watchedTime = None
701
719
            self.clearParentsChildrenSeen()
702
720
            self.signalChange()
 
721
            if markOtherItems and self.downloader:
 
722
                for item in self.downloader.itemList:
 
723
                    if item != self:
 
724
                        item.markItemUnseen(False)
703
725
 
704
726
    @returnsUnicode
705
727
    def getRSSID(self):
829
851
        except:
830
852
            return None
831
853
 
 
854
    # When changing this function, change feed.iconChanged to signal the right set of items
832
855
    @returnsUnicode
833
856
    def getThumbnail (self):
834
857
        self.confirmDBThread()
872
895
    def getQuotedTitle(self):
873
896
        return urllib.quote_plus(self.getTitle().encode('utf8')).decode('ascii', 'replace')
874
897
 
 
898
    def setChannelTitle(self, title):
 
899
        checkU(title)
 
900
        self.channelTitle = title
 
901
 
875
902
    @returnsUnicode
876
903
    def getChannelTitle(self, allowSearchFeedTitle=False):
877
904
        implClass = self.getFeed().actualFeed.__class__
879
906
            return self.getFeed().getTitle()
880
907
        elif implClass == feed.SearchFeedImpl and allowSearchFeedTitle:
881
908
            return searchengines.getLastEngineTitle()
 
909
        elif self.channelTitle:
 
910
            return self.channelTitle
882
911
        else:
883
912
            return u''
884
913
 
971
1000
 
972
1001
    def getTorrentDetails(self):
973
1002
        status = self.downloader.status
974
 
        return [
975
 
#            (_('Seeders:'), status.get('seeders', 0)),
976
 
#            (_('Leechers:'), status.get('leechers', 0)),
 
1003
        retval = []
 
1004
        seeders = status.get('seeders', -1)
 
1005
        leechers = status.get('leechers', -1)
 
1006
        if seeders != -1:
 
1007
            retval.append((_('Seeders:'), seeders))
 
1008
        if leechers != -1:
 
1009
            retval.append((_('Leechers:'), leechers))
 
1010
        retval.extend ([
977
1011
            (_('Down Rate:'), formatRateForDetails(status.get('rate', 0))),
978
1012
            (_('Down Total:'), formatSizeForDetails(
979
1013
                status.get('currentSize', 0))),
980
1014
            (_('Up Rate:'), formatRateForDetails(status.get('upRate', 0))),
981
 
            (_('Up Total:'), formatSizeForDetails(status.get('uploaded', 0) * 1024 * 1024)),
982
 
        ]
 
1015
            (_('Up Total:'), formatSizeForDetails(status.get('uploaded', 0))),
 
1016
        ])
 
1017
 
 
1018
        return retval
983
1019
 
984
1020
    def getItemDetails(self):
985
1021
        rv = []
994
1030
                                              url)))
995
1031
        rv.append((_('File type:'), self.getFormat()))
996
1032
 
 
1033
        if self.getLicence():
 
1034
            # check the license to see if it's a url by seeing if it has a 
 
1035
            # protocol
 
1036
            if urlparse.urlparse(self.getLicence())[0]:
 
1037
                ln = license.license_name(self.getLicence())
 
1038
                rv.append((_('License:'), util.makeAnchor(ln,
 
1039
                                                          self.getLicence())))
 
1040
            else:
 
1041
                rv.append((_('License:'), _('see permalink')))
 
1042
        else:
 
1043
            rv.append((_('License:'), _('see permalink')))
 
1044
 
997
1045
        if self.isDownloaded():
998
1046
            basename = os.path.basename(self.getFilename())
999
1047
            basename = util.clampText(basename, 40)
1012
1060
        return [
1013
1061
            (_('Down Total'), formatSizeForDetails(
1014
1062
                status.get('currentSize', 0))),
1015
 
            (_('Up Total'), formatSizeForDetails(status.get('uploaded', 0) * 1024 * 1024)),
 
1063
            (_('Up Total'), formatSizeForDetails(status.get('uploaded', 0))),
1016
1064
        ]
1017
1065
 
1018
1066
    def makeMoreInfoTable(self, title, moreInfoData):
1259
1307
    def downloadETA(self):
1260
1308
        if self.downloader is not None:
1261
1309
            totalSecs = self.downloader.getETA()
1262
 
            if totalSecs == -1:
 
1310
            if totalSecs <= 0:
1263
1311
                return _('downloading...')
1264
1312
        else:
1265
1313
            totalSecs = 0
1399
1447
    # return the license associated with the video
1400
1448
    @returnsUnicode
1401
1449
    def getLicence(self):
 
1450
 
1402
1451
        self.confirmDBThread()
1403
1452
        try:
1404
1453
            return self.entry.license