#!/usr/bin/env python
# -*- coding: utf-8 -*-
#puddletag.py

#Copyright (C) 2008-2009 concentricpuddle

#This file is part of puddletag, a semi-good music tag editor.

#This program is free software; you can redistribute it and/or modify
#it under the terms of the GNU General Public License as published by
#the Free Software Foundation; either version 2 of the License, or
#(at your option) any later version.

#This program is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#GNU General Public License for more details.

#You should have received a copy of the GNU General Public License
#along with this program; if not, write to the Free Software
#Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

#import psyco
#psyco.full()
import sys, os
_libs = [('mutagen', '(usually python-mutagen or just mutagen)', 
                    'http://code.google.com/p/quodlibet/wiki/Mutagen'),
         ('configobj', '(usually python-configobj)', 
            'http://code.google.com/p/configobj/'),
         ('pyparsing', '(python-pyparsing or python-parsing in most distros)',
            'http://pyparsing.wikispaces.com/'),
         ('musicbrainz2', '(python-musicbrainz2 in most distros)', 
            'http://musicbrainz2.org/doc/PythonMusicBrainz2'),
         ('PyQt4', '(python-qt4 in most)', 
            'http://www.riverbankcomputing.co.uk/software/pyqt/intro')]

def check_libs():
    found = True
    msg = "Error: %s module wasn't found, please check that it's installed " \
            "properly. You can download it from you distro's repository" \
            " %s or from the website %s"
    for lib in _libs:
        try:
            __import__(lib[0])
        except ImportError:
            print msg % lib
            found = False
    if not found:
       sys.exit(0)

if __name__ == '__main__':
    check_libs()


from PyQt4.QtGui import QApplication, QFont, QPixmap, QSplashScreen, QIcon
from PyQt4.QtCore import pyqtRemoveInputHook
import pdb
from puddlestuff.puddletag import MainWin
pyqtRemoveInputHook()
__version__ = "0.8.8"
import logging

try:
  if sys.argv[1] == '--debug':
    logging.basicConfig(stream=sys.stderr,
                        level=logging.DEBUG)
    del(sys.argv[1])
except IndexError:
  pass

size = None

for i, arg in enumerate(sys.argv):
    if arg.startswith('--fontsize'):
        try:
            size = int(sys.argv[i + 1])
        except IndexError:
            print 'No fontsize specified.'
        except ValueError:
            print 'Invalid fontsize specified.'

if len(sys.argv) > 1:
    filename = sys.argv[-1]
else:
    filename = None

if __name__ == '__main__':
    check_libs()
    app = QApplication(sys.argv)
    app.setWindowIcon(QIcon(":/appicon.png"))
    pixmap = QPixmap(':/puddlelogo.png')
    splash = QSplashScreen(pixmap)
    splash.show()
    app.processEvents()

    if size is not None:
        font = app.font()
        font.setPointSize(size)
        app.setFont(font)
    app.setOrganizationName("Puddle Inc.")
    app.setApplicationName("puddletag")
    win = MainWin()
    splash.close()
    win.setVisible(True)
    app.processEvents()
    if filename and os.path.exists(filename):
        win.openDir(filename)
    app.exec_()