# Tanım: Uyap Belge Düzenleyici
# URL: uyap.gov.tr
# Paketçi: Cihan_Alkan
# Gerekler: openjdk akiskart opensc innoextract

isim=uyap
surum=4.1.10
devir=1
kaynak=(http://www.uyap.gov.tr/destek/uyap.zip::${isim}-${surum}.zip
        uyap-editor.png
        product_logo_32.xpm)

derle() {

innoextract $SRC/UKI_V4.1.10/UKI_V4.1.10.exe

    mkdir -p $PKG/opt/uki
    cp -r app/*.jar /$PKG/opt/uki/

# Başlatıcı 
mkdir -pv $PKG/usr/share/applications &&
cat > $PKG/usr/share/applications/$isim.desktop << "EOF" &&
[Desktop Entry]
Version=1.0
Type=Application
Name=Uyap Document Editor
Name[tr]=Uyap Belge Düzenleyici
Comment=Uyap Document Editor
Comment[tr]=Uyap Belge Düzenleyici
GenericName=Metin Düzenleyici
TryExec=uyap
Exec=uyap %U
Terminal=false
Icon=uyap-editor
Categories=TextEditor;Office;
StartupNotify=true
Actions=Window;Document;
MimeType=application/udf;
EOF

# Bin Dosyası 
mkdir -pv $PKG/usr/bin &&
cat > $PKG/usr/bin/$isim << "EOF" &&
java -Xmx512m -Duser.language=tr -Duser.region=TR -cp .:/opt/uki/editor_lib2.jar:/opt/uki/editor_lib.jar:/opt/uki/editor_laf.jar:/opt/uki/jai_hvl.jar:/opt/uki/editor_utility.jar:/opt/uki/jdom.jar:/opt/uki/updater.jar tr.com.havelsan.uyap.system.editor.common.WPAppManager "getNewWPInstance" "EDITOR_TYPE_DOCUMENT" "$1" "$2"
EOF

# Uyap Menü 
mkdir -pv $PKG/usr/share/menu &&
cat > $PKG/usr/share/menu/$isim.menu << "EOF" &&
?package(uyap):needs="x11" \
  section="Office" \
  hints="Metin Düzenleyici" \
  title="Uyap Belge Düzenleyici" \
  icon="/opt/uki/product_logo_32.xpm" \
  command="/usr/bin/uyap"
EOF

# Uyap Mime 
mkdir -pv $PKG/usr/share/mime/packages &&
cat > $PKG/usr/share/mime/packages/udf.xml << "EOF" &&
<?xml version="1.0" encoding="UTF-8"?>
<mime-info xmlns='http://www.freedesktop.org/standards/shared-mime-info'>
	<mime-type type="application/udf">
		<comment>Uyap Document File</comment>
  		<comment xml:lang="tr">Uyap Belge Dosyası</comment>
  		<acronym>UDF</acronym>
  		<expanded-acronym>Uyap Document File</expanded-acronym>
  		<generic-icon name="uyap-editor"/>
  		<glob pattern="*.udf"/>
	</mime-type>

	<mime-type type="application/usf">
		<comment>Uyap Template File</comment>
  		<comment xml:lang="tr">Uyap Şablon Dosyası</comment>
  		<acronym>USF</acronym>
  		<expanded-acronym>Uyap Template File</expanded-acronym>
  		<generic-icon name="uyap-editor"/>
  		<glob pattern="*.usf"/>
	</mime-type>
</mime-info>
EOF

	# Icon Stuff
	SRC_LOC="$SRC/"
	DEST_LOC="$PKG/usr/share/icons/hicolor"
	for i in 16 32 48 128 256
	do
		install -Dm644 "$SRC_LOC"/uyap-editor.png "$DEST_LOC/${i}x${i}/apps/uyap-editor.png"
	done
	install -m644 "$SRC/product_logo_32.xpm" "$PKG/opt/uki/product_logo_32.xpm"
    chmod +x $PKG/usr/bin/uyap
}
