# Copyright 2010-2021, Google Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
#     * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#     * Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following disclaimer
# in the documentation and/or other materials provided with the
# distribution.
#     * Neither the name of Google Inc. nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

load(
    "//:build_defs.bzl",
    "mozc_infoplist_strings",
    "mozc_select",
)
load(
    "//bazel:qt.bzl",
    "mozc_cc_qt_binary",
    "mozc_cc_qt_library",
    "mozc_macos_qt_application",
    "mozc_qt_moc",
    "mozc_qt_rcc",
    "mozc_qt_uic",
)

package(default_visibility = ["//gui:__subpackages__"])

mozc_qt_moc(
    name = "moc_character_form_editor",
    srcs = [
        "character_form_editor.h",
    ],
    outs = ["moc_character_form_editor.cc"],
)

mozc_qt_moc(
    name = "moc_combobox_delegate",
    srcs = [
        "combobox_delegate.h",
    ],
    outs = ["moc_combobox_delegate.cc"],
)

mozc_qt_moc(
    name = "moc_config_dialog",
    srcs = [
        "config_dialog.h",
    ],
    outs = ["moc_config_dialog.cc"],
)

mozc_qt_moc(
    name = "moc_generic_table_editor",
    srcs = [
        "generic_table_editor.h",
    ],
    outs = ["moc_generic_table_editor.cc"],
)

mozc_qt_moc(
    name = "moc_keybinding_editor",
    srcs = [
        "keybinding_editor.h",
    ],
    outs = ["moc_keybinding_editor.cc"],
)

mozc_qt_moc(
    name = "moc_keybinding_editor_delegate",
    srcs = [
        "keybinding_editor_delegate.h",
    ],
    outs = ["moc_keybinding_editor_delegate.cc"],
)

mozc_qt_moc(
    name = "moc_keymap_editor",
    srcs = [
        "keymap_editor.h",
    ],
    outs = ["moc_keymap_editor.cc"],
)

mozc_qt_moc(
    name = "moc_roman_table_editor",
    srcs = [
        "roman_table_editor.h",
    ],
    outs = ["moc_roman_table_editor.cc"],
)

mozc_qt_uic(
    name = "uic_config_dialog",
    srcs = [
        "config_dialog.ui",
    ],
    outs = ["ui_config_dialog.h"],
)

mozc_qt_uic(
    name = "uic_generic_table_editor",
    srcs = [
        "generic_table_editor.ui",
    ],
    outs = ["ui_generic_table_editor.h"],
)

mozc_qt_uic(
    name = "uic_keybinding_editor",
    srcs = [
        "keybinding_editor.ui",
    ],
    outs = ["ui_keybinding_editor.h"],
)

mozc_qt_rcc(
    name = "qrc_config_dialog",
    srcs = [
        "config_dialog_en.qm",
        "config_dialog_ja.qm",
        "keymap_en.qm",
        "keymap_ja.qm",
        "//gui/base:tr_en.qm",
        "//gui/base:tr_ja.qm",
    ],
    outs = ["qrc_config_dialog.cc"],
    qrc_file = "config_dialog.qrc",
    qrc_name = "qrc_config_dialog",
)

mozc_cc_qt_library(
    name = "combobox_delegate",
    srcs = [
        "combobox_delegate.cc",
        ":moc_combobox_delegate",
    ],
    hdrs = [
        "combobox_delegate.h",
    ],
)

mozc_cc_qt_library(
    name = "config_dialog",
    srcs = [
        "character_form_editor.cc",
        "config_dialog.cc",
        "config_dialog_libmain.cc",
        "generic_table_editor.cc",
        "keybinding_editor.cc",
        "keybinding_editor_delegate.cc",
        "keymap_editor.cc",
        "roman_table_editor.cc",
        ":moc_character_form_editor",
        ":moc_config_dialog",
        ":moc_generic_table_editor",
        ":moc_keybinding_editor",
        ":moc_keybinding_editor_delegate",
        ":moc_keymap_editor",
        ":moc_roman_table_editor",
        ":qrc_config_dialog",
    ],
    hdrs = [
        "character_form_editor.h",
        "config_dialog.h",
        "generic_table_editor.h",
        "keybinding_editor.h",
        "keybinding_editor_delegate.h",
        "keymap_editor.h",
        "roman_table_editor.h",
        ":uic_config_dialog",
        ":uic_generic_table_editor",
        ":uic_keybinding_editor",
    ],
    deps = [
        ":combobox_delegate",
        "//base:config_file_stream",
        "//base:file_stream",
        "//base:file_util",
        "//base:port",
        "//base:process",
        "//base:run_level",
        "//base:singleton",
        "//base:system_util",
        "//base:util",
        "//base:version",
        "//base:vlog",
        "//base/container:flat_map",
        "//client",
        "//client:client_interface",
        "//composer:key_parser",
        "//config:config_handler",
        "//config:stats_config_util",
        "//gui/base:gui_base",
        "//gui/base:singleton_window_helper",
        "//protocol:commands_cc_proto",
        "//protocol:config_cc_proto",
        "//session:keymap",
        "@com_google_absl//absl/container:btree",
        "@com_google_absl//absl/container:fixed_array",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/container:flat_hash_set",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/log:check",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/types:span",
    ] + mozc_select(
        macos = [
            "//base/mac:mac_util",
        ],
        windows = [
            "//gui/base:win_util",
        ],
    ),
)

mozc_cc_qt_library(
    name = "config_dialog_main_lib",
    srcs = ["config_dialog_main.cc"],
    deps = [
        ":config_dialog",
        "//base:init_mozc",
        "//gui/base:gui_base",
    ],
)

mozc_cc_qt_binary(
    name = "config_dialog_main",
    deps = [":config_dialog_main_lib"],
)

mozc_infoplist_strings(
    name = "infolist_strings_en",
    srcs = [
        "//data/mac:ConfigDialog/English.lproj/InfoPlist.strings",
    ],
    outs = ["English.lproj/InfoPlist.strings"],
)

mozc_infoplist_strings(
    name = "infolist_strings_ja",
    srcs = [
        "//data/mac:ConfigDialog/Japanese.lproj/InfoPlist.strings",
    ],
    outs = ["Japanese.lproj/InfoPlist.strings"],
)

mozc_macos_qt_application(
    name = "config_dialog_macos",
    bundle_name = "ConfigDialog",
    strings = [
        ":infolist_strings_en",
        ":infolist_strings_ja",
    ],
    deps = [":config_dialog_main_lib"],
)
