#!/usr/bin/python
# -*- coding: utf-8 -*-
#
#       main.py
#       
#       Copyright © 2011, 2014 Brandon Invergo <brandon@invergo.net>
#       Copyright © 2009, 2010 Per Liedman <per@liedman.net>
#       
#       This file is part of Grotesque.
#
#       Grotesque 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 3 of the License, or
#       (at your option) any later version.
#
#       Grotesque 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 Grotesque.  If not, see <http://www.gnu.org/licenses/>.


import os
import errno

try:
    import gi
    gi.require_version('Gtk', '3.0')
except:
    import sys
    d = Gtk.MessageDialog(self, Gtk.DialogFlags.MODAL,
                          Gtk.MessageType.ERROR,
                          Gtk.ButtonsType.CLOSE)
    d.set_markup('Grotesque requires GTK+ version 3.0 or higher and '
                 'python-gobject.')
    restore_response = d.run()
    d.destroy()
    sys.exit()    
from grotesque.gui.gtk3 import Gui
from grotesque.settings import Settings


def main():
    # If this is the first time running the program, the settings file won't
    # exist, so run the settings assistant.
    gui = Gui()
    settings = Settings()
    if not settings.load():
        gui.setup_assistant(settings)
        if not os.path.exists(settings.configdir):
            os.makedirs(settings.configdir)
        if not os.path.exists(settings.coverart_dir):
            os.makedirs(settings.coverart_dir)
        settings.save()
    library_filename = settings.get_library_filename()
    gui.main_window(library_filename, settings)


if __name__ == "__main__":
    main()
