# -*- coding: utf-8 -*-
#
# Picard, the next-generation MusicBrainz tagger
# Copyright (c) 2004 Robert Kaye
# Copyright (C) 2006 Lukáš Lalinský
#
# 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 Street, Fifth Floor, Boston, MA 02110-1301, USA.

import sys
from PyQt4 import QtGui
from picard.config import TextOption
from picard.ui.options import OptionsPage, register_options_page
from picard.util.cdrom import get_cdrom_drives, AUTO_DETECT_DRIVES

if AUTO_DETECT_DRIVES:
    from picard.ui.ui_options_cdlookup_select import Ui_CDLookupOptionsPage
else:
    from picard.ui.ui_options_cdlookup import Ui_CDLookupOptionsPage


class CDLookupOptionsPage(OptionsPage):

    NAME = "cdlookup"
    TITLE = N_("CD Lookup")
    PARENT = None
    SORT_ORDER = 50
    ACTIVE = True

    options = [
        TextOption("setting", "cd_lookup_device", ""),
    ]

    def __init__(self, parent=None):
        super(CDLookupOptionsPage, self).__init__(parent)
        self.ui = Ui_CDLookupOptionsPage()
        self.ui.setupUi(self)
        if AUTO_DETECT_DRIVES:
            self.drives = get_cdrom_drives()
            self.ui.cd_lookup_device.addItems(self.drives)

    def load(self):
        if AUTO_DETECT_DRIVES:
            try:
                self.ui.cd_lookup_device.setCurrentIndex(self.drives.index(self.config.setting["cd_lookup_device"]))
            except ValueError:
                pass
        else:
            self.ui.cd_lookup_device.setText(self.config.setting["cd_lookup_device"])

    def save(self):
        if AUTO_DETECT_DRIVES:
            self.config.setting["cd_lookup_device"] = unicode(self.ui.cd_lookup_device.currentText())
        else:
            self.config.setting["cd_lookup_device"] = unicode(self.ui.cd_lookup_device.text())


register_options_page(CDLookupOptionsPage)
