# This file is part of the Zorin Appearance program.
#
# Copyright 2017-2024 Zorin OS Technologies Ltd.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms and conditions of the GNU General Public License,
# version 2, as published by the Free Software Foundation.
#
# This program is distributed in the hope 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.

import gi
import dbus
import zorin_appearance.Layouts.layout as layout
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk, Gio, GLib


class WindowsIconsXFCE(layout.Layout, Gtk.Box):

    __metaclass__ = layout.LayoutBox

    environment = 'XFCE'

    def __init__(self):
        Gtk.Box.__init__(self)

        self.settings = [
            ('xfce4-panel', '/configver', 2),
            ('xfce4-panel', '/panels', dbus.UInt32(1,
             variant_level=1)),
            ('xfce4-panel', '/panels/panel-0/autohide-behavior', 0),
            ('xfce4-panel', '/panels/panel-0/disable-struts', 0),
            ('xfce4-panel', '/panels/panel-0/icon-size', 16),
            ('xfce4-panel', '/panels/panel-0/length', 100),
            ('xfce4-panel', '/panels/panel-0/length-adjust', True),
            ('xfce4-panel', '/panels/panel-0/mode', 0),
            ('xfce4-panel', '/panels/panel-0/nrows', 1),
            ('xfce4-panel', '/panels/panel-0/plugin-ids', dbus.Array([
                dbus.Int32(1, variant_level=1),
                dbus.Int32(2, variant_level=1),
                dbus.Int32(3, variant_level=1),
                dbus.Int32(4, variant_level=1),
                dbus.Int32(5, variant_level=1),
                dbus.Int32(6, variant_level=1),
                dbus.Int32(7, variant_level=1),
                dbus.Int32(8, variant_level=1),
                dbus.Int32(9, variant_level=1),
                dbus.Int32(10, variant_level=1)
                ], signature=dbus.Signature('v'), variant_level=1)),
            ('xfce4-panel', '/panels/panel-0/position',
             'p=8;x=960;y=1176'),
            ('xfce4-panel', '/panels/panel-0/position-locked', True),
            ('xfce4-panel', '/panels/panel-0/size', 40),
            ('xfce4-panel', '/plugins/plugin-1', 'zorinmenulite'),
            ('xfce4-panel', '/plugins/plugin-2', 'separator'),
            ('xfce4-panel', '/plugins/plugin-2/style', 0),
            ('xfce4-panel', '/plugins/plugin-2/expand', False),
            ('xfce4-panel', '/plugins/plugin-3', 'docklike'),
            ('xfce4-panel', '/plugins/plugin-4', 'separator'),
            ('xfce4-panel', '/plugins/plugin-4/style', 0),
            ('xfce4-panel', '/plugins/plugin-4/expand', True),
            ('xfce4-panel', '/plugins/plugin-5', 'systray'),
            ('xfce4-panel', '/plugins/plugin-5/menu-is-primary', True),
            ('xfce4-panel', '/plugins/plugin-5/show-frame', False),
            ('xfce4-panel', '/plugins/plugin-5/single-row', True),
            ('xfce4-panel', '/plugins/plugin-5/square-icons', True),
            ('xfce4-panel', '/plugins/plugin-5/size-max', 22),
            ('xfce4-panel', '/plugins/plugin-5/symbolic-icons', True),
            ('xfce4-panel', '/plugins/plugin-5/icon-size', 16),
            ('xfce4-panel', '/plugins/plugin-6', 'notification-plugin'),
            ('xfce4-panel', '/plugins/plugin-7', 'indicator'),
            ('xfce4-panel', '/plugins/plugin-7/blacklist',
             dbus.Array([dbus.String(u'libappmenu.so',
             variant_level=1)], signature=dbus.Signature('v'),
             variant_level=1)),
            ('xfce4-panel', '/plugins/plugin-7/square-icons', True),
            ('xfce4-panel', '/plugins/plugin-8', 'pulseaudio'),
            ('xfce4-panel', '/plugins/plugin-8/enable-keyboard-shortcuts', True),
            ('xfce4-panel', '/plugins/plugin-8/enable-mpris', True),
            ('xfce4-panel', '/plugins/plugin-8/enable-wnck', True),
            ('xfce4-panel', '/plugins/plugin-8/known-players', 'parole;rhythmbox'),
            ('xfce4-panel', '/plugins/plugin-8/mixer-command', 'pavucontrol'),
            ('xfce4-panel', '/plugins/plugin-8/persistent-players', 'parole;rhythmbox'),
            ('xfce4-panel', '/plugins/plugin-8/show-notifications', True),
            ('xfce4-panel', '/plugins/plugin-9', 'power-manager-plugin'),
            ('xfce4-panel', '/plugins/plugin-10', 'clock'),
            ('xfce4-panel', '/plugins/plugin-10/digital-time-format', '    %_d %b %R     '),
            ('xfce4-panel', '/plugins/plugin-10/digital-time-font', 'Inter Bold 10'),
            ('xfce4-panel', '/plugins/plugin-10/digital-layout', 3),
            ('xfwm4', '/general/button_layout', 'O|HMC'),
            ('xfce4-keyboard-shortcuts', '/commands/custom/<Primary>Escape', 'xfce4-popup-zorinmenulite'),
            ('xsettings', '/Gtk/DecorationLayout', 'menu:minimize,maximize,close'),
            ('xsettings', '/Gtk/MenuImages', False),
            ]

        preview = Gtk.DrawingArea()
        preview.connect('draw', self.draw_layout_preview)
        preview.set_size_request(layout.LAYOUT_PREVIEW_WIDTH,
                                 layout.LAYOUT_PREVIEW_HEIGHT)

        self.pack_start(preview, True, False, 0)

    def draw_layout_preview(self, widget, cr):
        style_context = widget.get_style_context()
        color = style_context.get_color(Gtk.StateFlags.NORMAL)
        cr.set_source_rgba(*color)

        # Outline
        cr.set_line_width(2)
        cr.rectangle(1, 1, layout.LAYOUT_PREVIEW_WIDTH - 2,
                     layout.LAYOUT_PREVIEW_HEIGHT - 2)
        cr.stroke()

        # Panel
        cr.set_line_width(2)
        cr.move_to(2, layout.LAYOUT_PREVIEW_HEIGHT - 15)
        cr.line_to(layout.LAYOUT_PREVIEW_WIDTH - 2,
                   layout.LAYOUT_PREVIEW_HEIGHT - 15)
        cr.stroke()
        cr.move_to(0, 0)

        # Menu
        cr.set_line_width(2)
        cr.rectangle(5, layout.LAYOUT_PREVIEW_HEIGHT - 89, 60, 70)
        cr.stroke()

        # Menu icon 1
        cr.rectangle(8, layout.LAYOUT_PREVIEW_HEIGHT - 86, 4, 4)
        cr.fill()

        # Menu text 1
        cr.rectangle(14, layout.LAYOUT_PREVIEW_HEIGHT - 85, 15, 2)
        cr.fill()

        # Menu icon 2
        cr.rectangle(8, layout.LAYOUT_PREVIEW_HEIGHT - 78, 4, 4)
        cr.fill()

        # Menu text 2
        cr.rectangle(14, layout.LAYOUT_PREVIEW_HEIGHT - 77, 10, 2)
        cr.fill()

        # Menu icon 3
        cr.rectangle(8, layout.LAYOUT_PREVIEW_HEIGHT - 70, 4, 4)
        cr.fill()

        # Menu text 3
        cr.rectangle(14, layout.LAYOUT_PREVIEW_HEIGHT - 69, 12, 2)
        cr.fill()

        # Menu icon 4
        cr.rectangle(8, layout.LAYOUT_PREVIEW_HEIGHT - 62, 4, 4)
        cr.fill()

        # Menu text 4
        cr.rectangle(14, layout.LAYOUT_PREVIEW_HEIGHT - 61, 11, 2)
        cr.fill()

        # Menu icon 5
        cr.rectangle(8, layout.LAYOUT_PREVIEW_HEIGHT - 54, 4, 4)
        cr.fill()

        # Menu text 5
        cr.rectangle(14, layout.LAYOUT_PREVIEW_HEIGHT - 53, 9, 2)
        cr.fill()

        # Menu icon 6
        cr.rectangle(8, layout.LAYOUT_PREVIEW_HEIGHT - 46, 4, 4)
        cr.fill()

        # Menu text 6
        cr.rectangle(14, layout.LAYOUT_PREVIEW_HEIGHT - 45, 14, 2)
        cr.fill()

        # Menu icon 7
        cr.rectangle(8, layout.LAYOUT_PREVIEW_HEIGHT - 38, 4, 4)
        cr.fill()

        # Menu text 7
        cr.rectangle(14, layout.LAYOUT_PREVIEW_HEIGHT - 37, 8, 2)
        cr.fill()

        # Menu icon 8
        cr.rectangle(8, layout.LAYOUT_PREVIEW_HEIGHT - 30, 4, 4)
        cr.fill()

        # Menu text 8
        cr.rectangle(14, layout.LAYOUT_PREVIEW_HEIGHT - 29, 10, 2)
        cr.fill()

        # Menu right text 1
        cr.rectangle(44, layout.LAYOUT_PREVIEW_HEIGHT - 85, 10, 2)
        cr.fill()

        # Menu right text 2
        cr.rectangle(44, layout.LAYOUT_PREVIEW_HEIGHT - 77, 14, 2)
        cr.fill()

        # Menu right text 3
        cr.rectangle(44, layout.LAYOUT_PREVIEW_HEIGHT - 69, 8, 2)
        cr.fill()

        # Menu right text 4
        cr.rectangle(44, layout.LAYOUT_PREVIEW_HEIGHT - 61, 12, 2)
        cr.fill()

        # Menu right text 5
        cr.rectangle(44, layout.LAYOUT_PREVIEW_HEIGHT - 53, 15, 2)
        cr.fill()

        # Menu right text 6
        cr.rectangle(44, layout.LAYOUT_PREVIEW_HEIGHT - 45, 11, 2)
        cr.fill()

        # Menu right text 7
        cr.rectangle(44, layout.LAYOUT_PREVIEW_HEIGHT - 37, 12, 2)
        cr.fill()

        # Menu right text 8
        cr.rectangle(44, layout.LAYOUT_PREVIEW_HEIGHT - 29, 10, 2)
        cr.fill()

        # Panel menu icon
        cr.set_line_width(4)
        cr.rectangle(4, layout.LAYOUT_PREVIEW_HEIGHT - 12, 8, 8)
        cr.stroke()

        # Panel app icon 1
        cr.rectangle(18, layout.LAYOUT_PREVIEW_HEIGHT - 10, 4, 4)
        cr.fill()

        # Panel app icon 2
        cr.rectangle(26, layout.LAYOUT_PREVIEW_HEIGHT - 10, 4, 4)
        cr.fill()

        # Panel app icon 3
        cr.rectangle(34, layout.LAYOUT_PREVIEW_HEIGHT - 10, 4, 4)
        cr.fill()

        # Indicators
        cr.rectangle(layout.LAYOUT_PREVIEW_WIDTH - 34,
                     layout.LAYOUT_PREVIEW_HEIGHT - 9, 30, 2)
        cr.fill()
