2 # Copyright (C) 2008 jerous <jerous@gmail.com>
3 # Copyright (C) 2009 Anton Khirnov <wyskas@gmail.com>
5 # Nephilim is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
10 # Nephilim is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with Nephilim. If not, see <http://www.gnu.org/licenses/>.
19 from PyQt4
import QtCore
, QtGui
24 socket
.setdefaulttimeout(8)
26 appIcon
= 'gfx/nephilim_small.png'
31 """Converts seconds to min:sec."""
34 if sec
<10:sec
='0'+str(sec
)
35 return str(min)+':'+str(sec
)
37 class Button(QtGui
.QPushButton
):
39 """A simple Button class which calls $onClick when clicked."""
40 def __init__(self
, caption
, onClick
=None, iconPath
=None, iconOnly
=False, parent
=None):
41 QtGui
.QPushButton
.__init
__(self
, parent
)
44 self
.connect(self
, QtCore
.SIGNAL('clicked(bool)'), onClick
)
46 self
.changeIcon(iconPath
)
48 if not(iconPath
and iconOnly
):
49 QtGui
.QPushButton
.setText(self
, caption
)
51 self
.setToolTip(caption
)
53 def setText(self
, caption
):
54 self
.setToolTip(caption
)
58 def changeIcon(self
, iconPath
):
60 icon
.addFile(iconPath
, QtCore
.QSize(self
.iconSize
, self
.iconSize
))
63 def expand_tags(str, expanders
):
64 #ensure that str is QString
65 str = QtCore
.QString(str)
66 for expander
in expanders
:
67 str = expander
.expand_tags(str)
69 #remove unexpanded tags
70 return str.replace(QtCore
.QRegExp('\\$\\w+'), '')
72 def generate_metadata_path(song
, dir_tag
, file_tag
):
73 """Generate dirname and (db files only) full file path for reading/writing metadata files
74 (cover, lyrics) from $tags in dir/filename."""
75 if QtCore
.QDir
.isAbsolutePath(song
.filepath()):
76 dirname
= os
.path
.dirname(song
.filepath())
78 elif '://' in song
.filepath(): # we are streaming
82 dirname
= expand_tags(dir_tag
, (QtGui
.QApplication
.instance(), song
))
83 filepath
= '%s/%s'%(dirname
, expand_tags(file_tag
, (QtGui
.QApplication
.instance(), song
)).replace('/', '_'))
85 return dirname
, filepath