Compare commits
2 Commits
5a67a0998c
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6285840eb2 | ||
|
|
a840972375 |
@@ -10,7 +10,7 @@ TargetContext=true
|
|||||||
Enabled=true
|
Enabled=true
|
||||||
|
|
||||||
[X-Action-Profile profile-zero]
|
[X-Action-Profile profile-zero]
|
||||||
Exec=md_to_print_gui.sh --print %F
|
Exec=sh -c 'DISPLAY="${DISPLAY:-:0}" md_to_print_gui.sh --print %F'
|
||||||
MimeTypes=text/markdown;text/x-markdown;
|
MimeTypes=text/markdown;text/x-markdown;
|
||||||
MatchPattern=*.md;*.markdown;*.mkd;
|
MatchPattern=*.md;*.markdown;*.mkd;
|
||||||
Name=Default profile
|
Name=Default profile
|
||||||
|
|||||||
@@ -535,8 +535,11 @@ fi
|
|||||||
|
|
||||||
PANDOC_OPTS=(
|
PANDOC_OPTS=(
|
||||||
"$MD_FILE"
|
"$MD_FILE"
|
||||||
|
--from=markdown # Format d'entrée explicite (Markdown)
|
||||||
|
--to=pdf # Format de sortie explicite (PDF)
|
||||||
-o "$PDF_FILE"
|
-o "$PDF_FILE"
|
||||||
--pdf-engine="$PDF_ENGINE"
|
--pdf-engine="$PDF_ENGINE"
|
||||||
|
--standalone # Document complet avec métadonnées
|
||||||
-V geometry:margin=2cm
|
-V geometry:margin=2cm
|
||||||
-V fontsize=11pt
|
-V fontsize=11pt
|
||||||
-V documentclass=article
|
-V documentclass=article
|
||||||
@@ -551,9 +554,11 @@ if [ "$PDF_ENGINE" = "xelatex" ]; then
|
|||||||
)
|
)
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$ORIENTATION" = "landscape" ]; then
|
# Ne pas forcer l'orientation dans le PDF - laisser CUPS gérer l'orientation lors de l'impression
|
||||||
PANDOC_OPTS+=(-V geometry:landscape)
|
# Cela évite les conflits de mise en page
|
||||||
fi
|
# if [ "$ORIENTATION" = "landscape" ]; then
|
||||||
|
# PANDOC_OPTS+=(-V geometry:landscape)
|
||||||
|
# fi
|
||||||
|
|
||||||
log DEBUG "Exécution: pandoc ${PANDOC_OPTS[*]}"
|
log DEBUG "Exécution: pandoc ${PANDOC_OPTS[*]}"
|
||||||
|
|
||||||
@@ -600,12 +605,17 @@ if [ -n "$PAGES" ]; then
|
|||||||
LP_OPTS+=(-o page-ranges="$PAGES")
|
LP_OPTS+=(-o page-ranges="$PAGES")
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Appliquer l'orientation via CUPS (le PDF reste en portrait)
|
||||||
|
# Utiliser les valeurs standard IPP pour l'orientation
|
||||||
if [ "$ORIENTATION" = "landscape" ]; then
|
if [ "$ORIENTATION" = "landscape" ]; then
|
||||||
LP_OPTS+=(-o orientation-requested=4)
|
LP_OPTS+=(-o orientation-requested=4)
|
||||||
fi
|
fi
|
||||||
|
|
||||||
LP_OPTS+=(-o media="$SIZE")
|
LP_OPTS+=(-o media="$SIZE")
|
||||||
|
|
||||||
|
# Ne pas utiliser fit-to-page car cela peut causer des problèmes de mise en page
|
||||||
|
# Le PDF est déjà correctement dimensionné
|
||||||
|
|
||||||
case "$QUALITY" in
|
case "$QUALITY" in
|
||||||
draft)
|
draft)
|
||||||
LP_OPTS+=(-o print-quality=3)
|
LP_OPTS+=(-o print-quality=3)
|
||||||
|
|||||||
@@ -66,37 +66,60 @@ show_print_options() {
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Dialogue zenity avec formulaire
|
# Dialogue zenity avec formulaire (forcer DISPLAY et mode synchrone)
|
||||||
local result=$(zenity --forms --title "Options d'impression MD_to_Print" \
|
echo "DEBUG show_print_options: Tentative d'affichage avec DISPLAY=${DISPLAY}" >> /tmp/md_to_print_debug.log
|
||||||
|
|
||||||
|
local result
|
||||||
|
# Utiliser dbus-launch si nécessaire pour les applications GUI depuis un contexte non-GUI
|
||||||
|
if [ -z "${DBUS_SESSION_BUS_ADDRESS:-}" ] && command -v dbus-launch &> /dev/null; then
|
||||||
|
eval $(dbus-launch --sh-syntax)
|
||||||
|
fi
|
||||||
|
|
||||||
|
result=$(DISPLAY="${DISPLAY}" zenity --forms \
|
||||||
|
--title "Options d'impression MD_to_Print" \
|
||||||
--text "Configurez les options d'impression" \
|
--text "Configurez les options d'impression" \
|
||||||
--add-combo "Imprimante" \
|
--add-combo "Imprimante" \
|
||||||
--combo-values "$printers" \
|
--combo-values "$printers" \
|
||||||
--set-value "Par défaut" \
|
|
||||||
--add-combo "Recto-verso" \
|
--add-combo "Recto-verso" \
|
||||||
--combo-values "none|simplex|duplex" \
|
--combo-values "none|simplex|duplex" \
|
||||||
--set-value "none" \
|
|
||||||
--add-entry "Nombre de copies (1-10)" \
|
--add-entry "Nombre de copies (1-10)" \
|
||||||
--set-value "1" \
|
|
||||||
--add-combo "Couleur" \
|
--add-combo "Couleur" \
|
||||||
--combo-values "Non|Oui" \
|
--combo-values "Non|Oui" \
|
||||||
--set-value "Non" \
|
|
||||||
--add-combo "Qualité" \
|
--add-combo "Qualité" \
|
||||||
--combo-values "draft|normal|high" \
|
--combo-values "draft|normal|high" \
|
||||||
--set-value "normal" \
|
|
||||||
--add-combo "Orientation" \
|
--add-combo "Orientation" \
|
||||||
--combo-values "portrait|landscape" \
|
--combo-values "portrait|landscape" \
|
||||||
--set-value "portrait" \
|
2>&1)
|
||||||
2>/dev/null)
|
|
||||||
|
|
||||||
if [ $? -ne 0 ] || [ -z "$result" ]; then
|
local zenity_exit=$?
|
||||||
return 1 # Utilisateur a annulé
|
echo "DEBUG show_print_options: zenity_exit=$zenity_exit, result=$result" >> /tmp/md_to_print_debug.log
|
||||||
|
|
||||||
|
# Code 1 = utilisateur a annulé (normal)
|
||||||
|
# Code 0 = OK
|
||||||
|
# Autre = erreur
|
||||||
|
if [ $zenity_exit -eq 1 ]; then
|
||||||
|
# Utilisateur a annulé
|
||||||
|
echo "DEBUG: Utilisateur a annulé le dialogue" >> /tmp/md_to_print_debug.log
|
||||||
|
return 1
|
||||||
|
elif [ $zenity_exit -ne 0 ]; then
|
||||||
|
# Erreur d'exécution
|
||||||
|
echo "Erreur zenity (code $zenity_exit): $result" >> /tmp/md_to_print_zenity_error.log
|
||||||
|
echo "DEBUG: Erreur zenity (code $zenity_exit): $result" >> /tmp/md_to_print_debug.log
|
||||||
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [ -z "$result" ]; then
|
||||||
|
echo "DEBUG: Résultat vide" >> /tmp/md_to_print_debug.log
|
||||||
|
return 1 # Pas de résultat
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "DEBUG: Dialogue réussi, résultat: $result" >> /tmp/md_to_print_debug.log
|
||||||
|
|
||||||
# Parser les résultats (zenity forms retourne les valeurs séparées par |)
|
# Parser les résultats (zenity forms retourne les valeurs séparées par |)
|
||||||
IFS='|' read -r selected_printer duplex_mode copies color quality orientation <<< "$result"
|
IFS='|' read -r selected_printer duplex_mode copies color quality orientation <<< "$result"
|
||||||
|
|
||||||
# Valider et formater les options
|
# Valider et formater les options (déclarer comme globale)
|
||||||
PRINT_OPTS=()
|
declare -ga PRINT_OPTS=()
|
||||||
|
|
||||||
if [ -n "$selected_printer" ] && [ "$selected_printer" != "Par défaut" ] && [ "$selected_printer" != "" ]; then
|
if [ -n "$selected_printer" ] && [ "$selected_printer" != "Par défaut" ] && [ "$selected_printer" != "" ]; then
|
||||||
PRINT_OPTS+=(--printer "$selected_printer")
|
PRINT_OPTS+=(--printer "$selected_printer")
|
||||||
@@ -291,6 +314,45 @@ if [ ${#MD_FILES[@]} -gt 1 ]; then
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Afficher le dialogue d'options d'impression AVANT le traitement si action print et un seul fichier
|
||||||
|
# (doit être fait depuis l'hôte, pas dans Docker)
|
||||||
|
PRINT_OPTS=()
|
||||||
|
|
||||||
|
# S'assurer que DISPLAY est défini (nécessaire quand appelé depuis Caja Actions)
|
||||||
|
if [ -z "${DISPLAY:-}" ]; then
|
||||||
|
# Essayer de trouver DISPLAY depuis l'environnement utilisateur
|
||||||
|
if [ -f "$HOME/.Xauthority" ] && [ -S "/tmp/.X11-unix/X0" ]; then
|
||||||
|
export DISPLAY=":0"
|
||||||
|
elif [ -S "/tmp/.X11-unix/X0" ]; then
|
||||||
|
export DISPLAY=":0"
|
||||||
|
fi
|
||||||
|
# Dernière tentative : utiliser la valeur par défaut
|
||||||
|
if [ -z "${DISPLAY:-}" ]; then
|
||||||
|
export DISPLAY=":0"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Logs de débogage
|
||||||
|
echo "DEBUG: ACTION=$ACTION" >> /tmp/md_to_print_debug.log
|
||||||
|
echo "DEBUG: DISPLAY=${DISPLAY:-}" >> /tmp/md_to_print_debug.log
|
||||||
|
echo "DEBUG: zenity disponible: $(command -v zenity 2>&1)" >> /tmp/md_to_print_debug.log
|
||||||
|
echo "DEBUG: Nombre de fichiers: ${#MD_FILES[@]}" >> /tmp/md_to_print_debug.log
|
||||||
|
|
||||||
|
# Afficher le dialogue d'options pour print ET preview (si un seul fichier)
|
||||||
|
if [ \( "$ACTION" = "print" -o "$ACTION" = "preview" \) ] && command -v zenity &> /dev/null && [ ${#MD_FILES[@]} -eq 1 ]; then
|
||||||
|
echo "DEBUG: Conditions remplies, tentative d'affichage du dialogue" >> /tmp/md_to_print_debug.log
|
||||||
|
# Toujours essayer d'afficher le dialogue pour print et preview
|
||||||
|
if show_print_options; then
|
||||||
|
echo "DEBUG: Dialogue OK, options: ${PRINT_OPTS[*]}" >> /tmp/md_to_print_debug.log
|
||||||
|
notify info "Options sélectionnées: ${PRINT_OPTS[*]}"
|
||||||
|
else
|
||||||
|
echo "DEBUG: Dialogue échoué ou annulé" >> /tmp/md_to_print_debug.log
|
||||||
|
notify info "Utilisation des options par défaut"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo "DEBUG: Conditions non remplies - ACTION=$ACTION, zenity=$(command -v zenity), fichiers=${#MD_FILES[@]}" >> /tmp/md_to_print_debug.log
|
||||||
|
fi
|
||||||
|
|
||||||
# Notification de début
|
# Notification de début
|
||||||
notify info "Traitement de ${#MD_FILES[@]} fichier(s)..."
|
notify info "Traitement de ${#MD_FILES[@]} fichier(s)..."
|
||||||
|
|
||||||
@@ -315,18 +377,15 @@ for file in "${MD_FILES[@]}"; do
|
|||||||
if [ "$ACTION" = "convert" ]; then
|
if [ "$ACTION" = "convert" ]; then
|
||||||
docker_args+=(--convert-only)
|
docker_args+=(--convert-only)
|
||||||
elif [ "$ACTION" = "preview" ]; then
|
elif [ "$ACTION" = "preview" ]; then
|
||||||
|
# Pour "preview", utiliser les options déjà récupérées avant la boucle
|
||||||
|
if [ ${#PRINT_OPTS[@]} -gt 0 ]; then
|
||||||
|
docker_args+=("${PRINT_OPTS[@]}")
|
||||||
|
fi
|
||||||
docker_args+=(--preview --keep-pdf)
|
docker_args+=(--preview --keep-pdf)
|
||||||
else
|
else
|
||||||
# Pour "print", afficher le dialogue d'options si disponible
|
# Pour "print", utiliser les options déjà récupérées avant la boucle
|
||||||
if command -v zenity &> /dev/null && [ ${#MD_FILES[@]} -eq 1 ]; then
|
if [ ${#PRINT_OPTS[@]} -gt 0 ]; then
|
||||||
# Afficher le dialogue d'options pour un seul fichier
|
docker_args+=("${PRINT_OPTS[@]}")
|
||||||
if show_print_options; then
|
|
||||||
docker_args+=("${PRINT_OPTS[@]}")
|
|
||||||
notify info "Options: ${PRINT_OPTS[*]}"
|
|
||||||
else
|
|
||||||
# Utiliser les valeurs par défaut si l'utilisateur annule
|
|
||||||
notify info "Utilisation des options par défaut"
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
# On garde le PDF après impression
|
# On garde le PDF après impression
|
||||||
docker_args+=(--keep-pdf)
|
docker_args+=(--keep-pdf)
|
||||||
@@ -344,6 +403,21 @@ for file in "${MD_FILES[@]}"; do
|
|||||||
"${docker_args[@]}" \
|
"${docker_args[@]}" \
|
||||||
> /tmp/md_to_print_docker.log 2>&1; then
|
> /tmp/md_to_print_docker.log 2>&1; then
|
||||||
SUCCESS_COUNT=$((SUCCESS_COUNT + 1))
|
SUCCESS_COUNT=$((SUCCESS_COUNT + 1))
|
||||||
|
|
||||||
|
# Pour preview, ouvrir le PDF depuis l'hôte après conversion
|
||||||
|
if [ "$ACTION" = "preview" ]; then
|
||||||
|
pdf_file="$output_dir/${file_base%.*}.pdf"
|
||||||
|
if [ -f "$pdf_file" ]; then
|
||||||
|
if command -v evince &> /dev/null; then
|
||||||
|
evince "$pdf_file" 2>/dev/null &
|
||||||
|
elif command -v xdg-open &> /dev/null; then
|
||||||
|
xdg-open "$pdf_file" 2>/dev/null &
|
||||||
|
else
|
||||||
|
notify warn "Aucun visualiseur PDF trouvé pour prévisualisation"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
notify success "✓ $file_name traité"
|
notify success "✓ $file_name traité"
|
||||||
else
|
else
|
||||||
ERROR_COUNT=$((ERROR_COUNT + 1))
|
ERROR_COUNT=$((ERROR_COUNT + 1))
|
||||||
@@ -363,16 +437,9 @@ for file in "${MD_FILES[@]}"; do
|
|||||||
|
|
||||||
case "$ACTION" in
|
case "$ACTION" in
|
||||||
print)
|
print)
|
||||||
# Pour print, afficher le dialogue d'options si disponible
|
# Pour print, utiliser les options déjà récupérées avant la boucle
|
||||||
if command -v zenity &> /dev/null && [ ${#MD_FILES[@]} -eq 1 ]; then
|
if [ ${#PRINT_OPTS[@]} -gt 0 ]; then
|
||||||
# Afficher le dialogue d'options pour un seul fichier
|
cmd_args+=("${PRINT_OPTS[@]}")
|
||||||
if show_print_options; then
|
|
||||||
cmd_args+=("${PRINT_OPTS[@]}")
|
|
||||||
notify info "Options: ${PRINT_OPTS[*]}"
|
|
||||||
else
|
|
||||||
# Utiliser les valeurs par défaut si l'utilisateur annule
|
|
||||||
notify info "Utilisation des options par défaut"
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
# On garde le PDF après impression
|
# On garde le PDF après impression
|
||||||
cmd_args+=(--keep-pdf)
|
cmd_args+=(--keep-pdf)
|
||||||
@@ -382,12 +449,40 @@ for file in "${MD_FILES[@]}"; do
|
|||||||
cmd_args+=(--convert-only)
|
cmd_args+=(--convert-only)
|
||||||
;;
|
;;
|
||||||
preview)
|
preview)
|
||||||
|
# Pour preview, utiliser les options déjà récupérées avant la boucle
|
||||||
|
if [ ${#PRINT_OPTS[@]} -gt 0 ]; then
|
||||||
|
cmd_args+=("${PRINT_OPTS[@]}")
|
||||||
|
fi
|
||||||
cmd_args+=(--preview --keep-pdf)
|
cmd_args+=(--preview --keep-pdf)
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
if "$script_path" "${cmd_args[@]}" > /tmp/md_to_print.log 2>&1; then
|
if "$script_path" "${cmd_args[@]}" > /tmp/md_to_print.log 2>&1; then
|
||||||
SUCCESS_COUNT=$((SUCCESS_COUNT + 1))
|
SUCCESS_COUNT=$((SUCCESS_COUNT + 1))
|
||||||
|
|
||||||
|
# Pour preview, ouvrir le PDF depuis l'hôte après conversion
|
||||||
|
if [ "$ACTION" = "preview" ]; then
|
||||||
|
# Chercher le PDF dans le répertoire de sortie
|
||||||
|
pdf_file=""
|
||||||
|
if [ -f "${file%.*}.pdf" ]; then
|
||||||
|
pdf_file="${file%.*}.pdf"
|
||||||
|
elif [ -f "$HOME/MD_to_print_output/$(basename "${file%.*}.pdf")" ]; then
|
||||||
|
pdf_file="$HOME/MD_to_print_output/$(basename "${file%.*}.pdf")"
|
||||||
|
elif [ -f "./output/$(basename "${file%.*}.pdf")" ]; then
|
||||||
|
pdf_file="./output/$(basename "${file%.*}.pdf")"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -n "$pdf_file" ] && [ -f "$pdf_file" ]; then
|
||||||
|
if command -v evince &> /dev/null; then
|
||||||
|
evince "$pdf_file" 2>/dev/null &
|
||||||
|
elif command -v xdg-open &> /dev/null; then
|
||||||
|
xdg-open "$pdf_file" 2>/dev/null &
|
||||||
|
else
|
||||||
|
notify warn "Aucun visualiseur PDF trouvé pour prévisualisation"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
notify success "✓ $file_name traité"
|
notify success "✓ $file_name traité"
|
||||||
else
|
else
|
||||||
ERROR_COUNT=$((ERROR_COUNT + 1))
|
ERROR_COUNT=$((ERROR_COUNT + 1))
|
||||||
|
|||||||
46
scripts/md_to_print_notify.sh
Executable file
46
scripts/md_to_print_notify.sh
Executable file
@@ -0,0 +1,46 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Script utilitaire pour les notifications MD_to_Print
|
||||||
|
# Usage: md_to_print_notify.sh [level] [message]
|
||||||
|
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
LEVEL="${1:-info}"
|
||||||
|
MESSAGE="${2:-}"
|
||||||
|
ICON=""
|
||||||
|
URGENCY="normal"
|
||||||
|
|
||||||
|
case "$LEVEL" in
|
||||||
|
info|INFO)
|
||||||
|
ICON="dialog-information"
|
||||||
|
URGENCY="low"
|
||||||
|
;;
|
||||||
|
success|SUCCESS)
|
||||||
|
ICON="dialog-information"
|
||||||
|
URGENCY="normal"
|
||||||
|
;;
|
||||||
|
warning|WARN)
|
||||||
|
ICON="dialog-warning"
|
||||||
|
URGENCY="normal"
|
||||||
|
;;
|
||||||
|
error|ERROR)
|
||||||
|
ICON="dialog-error"
|
||||||
|
URGENCY="critical"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
ICON="dialog-information"
|
||||||
|
URGENCY="normal"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
if [ -z "$MESSAGE" ]; then
|
||||||
|
echo "Usage: $0 [level] [message]"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if command -v notify-send &> /dev/null; then
|
||||||
|
notify-send -u "$URGENCY" -i "$ICON" "MD_to_Print" "$MESSAGE" 2>/dev/null || true
|
||||||
|
else
|
||||||
|
echo "[$LEVEL] $MESSAGE" >&2
|
||||||
|
fi
|
||||||
|
|
||||||
Reference in New Issue
Block a user