# MU-Wetter

License: GPLv2+

A lightweight, international weather monitor designed for Puppy Linux and Debian-based systems. The application leverages the Open-Meteo API for real-time hourly and daily forecasts, and OpenStreetMap (Nominatim) for automated location geocoding.

Built entirely in **Vala** and utilizing **GTK+ 3**, it ensures a native, resource-efficient user experience.

---

## 📂 Project Structure

The codebase is split into modular files to guarantee maintainability and eliminate LLM text-buffer truncations during development:

*   **`mu-wetter-gui.vala`**: Handles the GTK3 user interface, layout containers, widgets, and notebook tabs (`partial class`).
*   **`mu-wetter-logic.vala`**: Manages the asynchronous network queries for Nominatim and the Open-Meteo data callbacks (`partial class`).
*   **`wetter-api.vala`**: Orchestrates JSON parsing, API URL generation, and localization lookups.
*   **`wetter-config.vala`**: Persists user preferences (units, coordinates, language) inside `~/.mu-wetter/`.
*   **`wetter-main.vala`**: Application entry point. Decides between interactive GUI execution and silent background processing.
*   **`languages.rc`**: The translation database file containing localization keys.
*   **`Makefile`**: Automates compilation, installation routines, and cross-architecture packaging.

---

## ⚙️ Core Engines & Architecture

### 1. Command Line Interface (CLI) Engine
MU-Wetter features a built-in background processing engine. It can be triggered without an active X-Server (GUI) to fetch weather updates silently, which is ideal for automation scripts or cronjobs.

*   **GUI Mode (Default)**: Launched via `./mu-wetter`. Opens the interactive interface.
*   **Silent Mode (CLI)**: Launched via `./mu-wetter -s` or `./mu-wetter --silent`. 
    *   Bypasses GTK initialization completely.
    *   Spawns a headless `GLib.MainLoop` to handle asynchronous network requests.
    *   Triggers the API to fetch current weather data for the saved location.
    *   Processes the raw JSON payloads and writes a formatted plaintext report into `~/.mu-wetter/vorhersage.txt`.
    *   Exits cleanly with status code `0`.

### 2. Localization System (`languages.rc`)
Multi-language support is powered by a custom runtime localization parser. Instead of forcing heavy `gettext` dependencies, the program reads the `languages.rc` key-value store.

*   **Storage Location**: Looked up dynamically at `/etc/mu-wetter/languages.rc`. If not found (e.g., during development), it falls back to the current working directory.
*   **Format Constraints**: Lines must use the syntax `[language_code]:[KEY]=[Translation]`. Comments start with `#`.
    *   *Example*: `de:TAB_TODAY=Heute (Stündlich)`
    *   *Example*: `en:TAB_TODAY=Today (Hourly)`
*   **Runtime Logic**: The `WetterApi` class reads the file sequentially via a `DataInputStream` and maps keys into a `GLib.HashTable`. The custom lookup method `api._("KEY")` fetches translations on-the-fly. Hardcoded English fallbacks are compiled in to prevent critical UI breaks if the file is missing.

---

## 🛠️ Build Requirements

### 1. On BookwormPup (64-Bit Host)
Install native GTK3, Soup, and JSON developer headers:
```bash
apt-get update && apt-get install valac libgtk-3-dev libsoup-2.4-dev libjson-glib-dev
```

### 2. On Linux Mint 22.3 (32-Bit Cross-Compile Host)
Ensure the host dependencies and the multilib cross-compilation toolchains are present:
```bash
sudo apt update && sudo apt install valac libgtk-3-dev libsoup2.4-dev libjson-glib-dev gcc-multilib
```

---

## 🚀 Building & Installation

### Local Build & Run (64-Bit)
```bash
make clean && make
./mu-wetter
```

### System-Wide Installation
Compiles the application, installs the binary to `/usr/bin/`, copies the translation file to `/etc/mu-wetter/languages.rc`, and integrates a `.desktop` launcher into the system application menu:
```bash
make install
```

### System-Wide Removal
```bash
make uninstall
```

---

## 📦 Distribution Packages

### 1. Host Architecture (64-Bit Packages)
Generate packages locally on your 64-bit platform:
```bash
make deb64   # Generates an amd64 .deb archive
make pet64   # Generates a native x86_64 Puppy Linux .pet package
```

### 2. Target Architecture (32-Bit Cross-Compiled Packages)
Transfer the project directory to your **Linux Mint 22.3** multilib environment and run:
```bash
make deb32   # Generates an i386 .deb package using 'gcc -m32'
make pet32   # Generates an i386 Puppy Linux .pet package for vintage rigs
```

---

## 🪵 Tracing & Diagnostics
The binaries are equipped with deterministic console tracing. Launch the application inside a terminal shell to review real-time network states and JSON diagnostics:
```bash
./mu-wetter
```
Keep an eye out for `[DEBUG-SEARCH]` and `[DEBUG-WEATHER]` prefixes to trace Nominatim URL structures and data buffer updates instantly.
Verwende Code mit Vorsicht.
