<?php

// YubaPrefs 0.1.0
// 

// Includes

require (__DIR__."/functions.php");
require (__DIR__."/functions.pashua.php");

// Read Prefs

$prefs_file = "/Users/".get_current_user()."/Library/Preferences/yuba_prefs.php";
$p = unserialize(file_get_contents($prefs_file));
if(!$p['bdest']) {
	$p['bdest'] = "/Users/".get_current_user()."/Documents/Yuba/";
	if (!is_dir($p['bdest'])) { if (!mkdir($p['bdest'])) { echo "Error creating destination directory"; } }
	}

// Load strings

$strings[] = array("Do nothing","Reveal result in Finder","Upload result with rsync");
$strings[] = array("Bypass","Generate","Rebuild");
$strings[] = array("external","ql-thumbnail","qltool","qlmanage");

$result = Pashua::showDialog(makeWindowString($p, $strings));

// User cancelled

if (@$result['cb']) {
	echo "0";
	die;
	}

// Fix strings

$result['postflight'] = array_search($result['postflight'],$strings[0]);
$result['thumbs'] = array_search($result['thumbs'],$strings[1]);
$result['thumb_priority'] = array_search($result['thumb_priority'],$strings[2]);

// If the user didn't specify a destpath, set to default

if(!$p['bdest']) {
	$p['bdest'] = "/Users/".get_current_user()."/Documents/Yuba/";
	}

// Fix a Pashua bug

$result['destpath'] = str_replace("Desktop/Desktop","Desktop",$result['destpath']);

// Write Prefs

file_put_contents($prefs_file,serialize($result));
echo "1";

?>