Browse the code

 

Differences between 214 and 215 on /.
Number of edited files: 4 (0 added, 0 deleted and 4 modified)
Revision 215

About 9 days and 12 hours ago.

* Added the duration in day/hours/minutes/seconds of a playlist underneath its name
Added file(s) Deleted file(s) Modified file(s)

 

Old New Code
46
46
from os import remove
47
47
from os.path import join
48
48

                                        
 
49
from gi.repository.GLib import set_prgname
 
50
set_prgname('Bluemindo')
 
51

                                    
49
52
from common.config import ConfigLoader
50
53
from common.functions import Functions
51
54
config = ConfigLoader()
155
158

                                        
156
159
            pid_filename = join(config.datadir, 'pid')
157
160
            if isfile(pid_filename):
158
 
                # Get PID connected with the existing socket 
 
161
                # Get PID connected with the existing socket
159
162
                pid_filename = join(config.datadir, 'pid')
160
163
                pid_file = open(pid_filename, 'r')
161
164
                pid_stored = pid_file.read()
186
189
    bluemindo = Bluemindo()
187
190

                                        
188
191
if __name__ == "__main__":
189
 
    main()
 
192
    main()
190
193

                                        

 

Old New Code
21
21
from os.path import join, isfile, isdir, exists
22
22
from os import remove
23
23
from gi.repository.GLib import markup_escape_text
 
24
from gettext import gettext as _
24
25

                                        
25
26
from common.config import ConfigLoader
26
27

                                        
53
54
        md5 = md5_new()
54
55
        md5.update(str1.encode('utf-8'))
55
56
        md5.update(str2.encode('utf-8'))
56
 
        
 
57

                                    
57
58
        return str(md5.hexdigest())
58
59

                                        
59
60
    def view_encode(self, string, limit=25):
69
70

                                        
70
71
        return _str
71
72

                                        
72
 
    def human_length(self, length):
 
73
    def human_length(self, length, modern=False):
73
74
        """Return the length in a human-readable way"""
74
 
        lg0 = int(length / 60)
75
 
        lg1 = int(length % 60)
 
75
        if modern:
 
76
            days = length // 86400
 
77
            hours = length // 3600 % 24
 
78
            minutes = length // 60 % 60
 
79
            seconds = length % 60
76
80

                                        
77
 
        if lg0 >= 0 and lg0 < 10:
78
 
            lg0 = '0' + str(lg0)
 
81
            txt = ''
 
82
            if days > 0:
 
83
                txt += _('%dj ' % int(days))
 
84
            if hours > 0:
 
85
                txt += _('%dh ' % int(hours))
 
86
            if minutes > 0:
 
87
                txt += _('%dm ' % int(minutes))
 
88
            if seconds > 0:
 
89
                txt += _('%ds ' % int(seconds))
79
90

                                        
80
 
        if lg1 >= 0 and lg1 < 10:
81
 
            lg1 = '0' + str(lg1)
 
91
            return txt
 
92
        else:
 
93
            lg0 = int(length / 60)
 
94
            lg1 = int(length % 60)
82
95

                                        
83
 
        lg = str(lg0) + ':' + str(lg1)
84
 
        return lg
 
96
            if lg0 >= 0 and lg0 < 10:
 
97
                lg0 = '0' + str(lg0)
85
98

                                        
 
99
            if lg1 >= 0 and lg1 < 10:
 
100
                lg1 = '0' + str(lg1)
 
101

                                    
 
102
            lg = str(lg0) + ':' + str(lg1)
 
103
            return lg
 
104

                                    
86
105
    def clear_html(self, text, only_bold=False):
87
106
        """Return the text without html"""
88
107
        if text.startswith('<b>') and text.endswith('</b>'):
139
158
        # Hide window
140
159
        else:
141
160
            if window.get_properties('visible')[0]:
142
 
                window.hide()
 
161
                window.hide()
143
162

                                        

 

Old New Code
63
63
        icon_file = join(functions.datadir, 'image', 'logo_head_small.png')
64
64
        pixbuf = Pixbuf.new_from_file(icon_file)
65
65
        self.main_window.set_icon(pixbuf)
 
66
        self.main_window.set_default_icon_list([pixbuf])
66
67

                                        
67
68
        # Add the about button
68
69
        about_button = Button(relief=2)
69
70

                                        

 

Old New Code
63
63
        self.user_playlists = {}
64
64
        self.last_user_playlist = None
65
65

                                        
 
66
        self.playlist_length = 0
 
67
        self.playlist_info = ''
 
68

                                    
66
69
        self.similar_artists = []
67
70
        self.is_in_similar_thread = False
68
71

                                        
105
108
            column_text.set_fixed_width(36)
106
109
            self.playlist_tree.append_column(column_text)
107
110

                                        
 
111
            def row_modified(model, path, _iter=None):
 
112
                total = len(model)
 
113

                                    
 
114
                length = 0
 
115
                for item in model:
 
116
                    element = self.playlist_content[item[4]]
 
117

                                    
 
118
                    try:
 
119
                        length += element.length
 
120
                    except AttributeError:
 
121
                        for sng in element.tracks:
 
122
                            length += sng.length
 
123

                                    
 
124
                self.playlist_length = length
 
125
                time = self.functions.human_length(length, True)
 
126

                                    
 
127
                self.playlist_info = _('%d items (%s)' % (total, time))
 
128
                self.update_combobox_text()
 
129

                                    
 
130
            self.liststore.connect('row-deleted', row_modified)
 
131

                                    
108
132
            self.repeat_btn = self.widgets.get_object('tool-repeat')
109
133
            if self.config['repeat']:
110
134
                self.repeat_btn.set_active(True)
154
178
            renderer_text.props.ellipsize = EllipsizeMode.END
155
179
            self.combobox.pack_start(renderer_text, True)
156
180
            self.combobox.set_entry_text_column(1)
157
 
            self.combobox.add_attribute(renderer_text, 'text', 1)
 
181
            self.combobox.add_attribute(renderer_text, 'markup', 1)
158
182

                                        
159
183
            self.combolist.append([0, _('Current')])
160
184
            self.combolist.append([1, _('Top 50 songs')])
402
426

                                        
403
427
        self.playlists_mgmnt.write_playlist(user_plist, plist_content)
404
428

                                        
 
429
    def update_combobox_text(self):
 
430
        item = self.combolist[self.combobox.get_active_iter()]
 
431
        plist_infos = item[1].split('\n')
 
432
        plist_name = plist_infos[0]
 
433

                                    
 
434
        if self.playlist_length > 0:
 
435
            item[1] = (plist_name + '\n<small><i>' +
 
436
                       self.playlist_info + '</i></small>')
 
437
        else:
 
438
            item[1] = plist_name
 
439

                                    
 
440
    def on_new_item_in_playlist(self, data, kind='song'):
 
441
        total = len(self.liststore)
 
442
        length = 0
 
443

                                    
 
444
        if kind == 'song':
 
445
            length += data.length
 
446
        else:
 
447
            length = 0
 
448
            for item in data.tracks:
 
449
                length += item.length
 
450

                                    
 
451
        self.playlist_length += length
 
452
        time = self.functions.human_length(self.playlist_length, True)
 
453

                                    
 
454
        self.playlist_info = _('%d items (%s)' % (total, time))
 
455
        self.update_combobox_text()
 
456

                                    
405
457
    def on_new_song_queued(self, song_info):
406
458
        title = song_info.title
407
459
        artist = song_info.artist
420
472
        self.playlist_identifier += 1
421
473

                                        
422
474
        # Update GUI
 
475
        self.on_new_item_in_playlist(song_info, 'song')
423
476
        self.clean_btn.set_sensitive(True)
424
477
        self.tool_save.set_sensitive(True)
425
478

                                        
439
492
        self.playlist_identifier += 1
440
493

                                        
441
494
        # Update GUI
 
495
        self.on_new_item_in_playlist(album_info, 'album')
442
496
        self.clean_btn.set_sensitive(True)
443
497
        self.tool_save.set_sensitive(True)
444
498

                                        
445
499