# 070 — Search window

Status: approved 2026-09-30. Built in F3.

## 1. Flow

```
Home search button (801) / "Nové hledání" in the window
  → RunPlugin(plugin://plugin.video.milionar/?action=skin_search[&query=…])
      1. no query → xbmcgui.Dialog().input(<#Hledat>, type=INPUT_ALPHANUM)
         (Estuary's DialogKeyboard); empty/cancel → stop
      2. save to search history (search_history_universal.json, shared with
         tmdb_universal_search, max 15)
      3. fetch TMDb /search/multi (movies, tv, person; cs-CZ) and write
         skin_cache/search_<hash>.json  ← network happens here, with DialogBusy;
         build the two library paths (§2 rows 4–5)
      4. Window(Home).setProperty milionar.search.query = query,
         milionar.search.token = <epoch ms>,
         milionar.search.lib_movies / milionar.search.lib_tvshows = paths
      5. ActivateWindow(1120) (or refresh it if already open)
```

All TMDb calls happen once per search in step 3; the rows only read the
cache, so there are no calls per keystroke and no race between rows.

## 2. Window `Custom_1120_MilionarSearch.xml`

- `type="window"` (full screen, back returns to Home), Estuary look: the
  Home background, header like Estuary media windows ("Hledat: <query>"),
  top button row with `IconButton`s: Nové hledání, and Estuary-like layout of
  widget rows below (`WidgetGroupListCommon` grouplist).
- Rows, each hidden when empty (`Integer.IsGreater(Container(<id>).NumItems,0)`);
  plugin rows use `content_path =
  plugin://plugin.video.milionar/?action=widget_search&kind=<kind>&token=$INFO[Window(Home).Property(milionar.search.token)]`,
  library rows the native paths below:

| # | Row | `kind` | Include | Click |
|---|-----|--------|---------|-------|
| 1 | Filmy | `movie` | `WidgetListPoster` | `default_movie_action` (as addon listings) |
| 2 | Seriály | `tv` | `WidgetListPoster` | series detail as addon listings |
| 3 | Osoby | `person` | `WidgetListPoster` (profile image) | `display_actor_dialog` / director / creator by known_for_department |
| 4 | V mé knihovně: Filmy | — (native) | `WidgetListPoster` | Estuary default for library items |
| 5 | V mé knihovně: Seriály | — (native) | `WidgetListPoster` | Estuary default for library items |
| 6 | Historie hledání | `history` | `WidgetListCategories` | `skin_search&query=<q>` |

Rows 4–5 are **native library listings**, not plugin items (decided): the
addon builds `videodb://movies/titles/?xsp=<urlencoded JSON>` and
`videodb://tvshows/titles/?xsp=…` with
`{"type":"movies"|"tvshows","rules":{"and":[{"field":"title","operator":"contains","value":["<query>"]}]}}`
(URL-encoded with `urllib.parse.quote`, so quotes and diacritics are safe)
and puts them in `milionar.search.lib_movies` / `…lib_tvshows`; the rows use
`content_path = $INFO[Window(Home).Property(milionar.search.lib_movies)]`.
Items are real library items, so clicking, info and context menus behave
exactly as in Estuary.

- No results at all: Estuary `ImageWidget` text "Nic nenalezeno" + button
  Nové hledání.
- Focus: default on row 1 (or the first non-empty); up from the rows goes to
  the button row; back closes the window.
- Without the addon the Home search button keeps Estuary's 1107 menu, so the
  window is never reached.

## 3. Strings and settings

Header, button and row labels in cs/sk/en (#31900+ in the skin for skin-side
labels; addon strings for the keyboard heading). No new addon settings.

## 4. Result (F3, 2026-10-01)

- `skin_search` (`wcs/skin/search.py`): keyboard (or `query=`), history
  (`search_history.json` key `universal`, max 15, shared with
  `tmdb_universal_search`), one TMDb `/search/multi` call under a busy
  dialog, result written to `skin_cache/search_current.json` (a single "last
  search" file instead of one per hash), properties `milionar.search.*`, then
  `ActivateWindow(1120)`; an open window only reloads (token in the row
  paths). Without a TMDb key the library rows still work and a notification
  says so.
- `Custom_1120_MilionarSearch.xml` (root needs `id="1120"`): header
  "Hledat: <query>", button "Nové hledání", rows Filmy, Seriály, Osoby,
  V mé knihovně: Filmy / Seriály (native `videodb://...?xsp=` listings), Historie
  hledání; "Nic nenalezeno" + button when nothing was found.
- Click: TMDb movie / series -> addon details dialog (`show_wcs_details`),
  person -> actor / director / writer dialog by `known_for_department`,
  history -> new search with that text (all via `skin_run`).
- Verified live: "Harry Potter" (15 movies, 5 shows, library movies and
  shows, history), "Daniel Radcliffe" (person row), "zzqqxx" (empty state);
  rows load in 42-67 ms (the TMDb call happens once, in `skin_search`).
- Clicking a person / title was not exercised (opens addon dialogs).
