# K-Meleon Macros (http://kmeleon.sourceforge.net/wiki/index.php?id=MacroLanguage)

# ---------- Custom Proxies ----------------------------------------------------------------------------------------
#
# Dependencies	: main.kmm ($macroPrefBranch)
# Resources	: -
# Preferences	: kmeleon.plugins.macros.proxy[1-3].name
#		  kmeleon.plugins.macros.proxy[1-3].http
#		  kmeleon.plugins.macros.proxy[1-3].http_port
#
# ------------------------------------------------------------------------------------------------------------------

Proxy_None{
menuchecked=(getpref(INT,$_Proxy_Active."type")==0);
setpref(INT,$_Proxy_Active."type",0); &_Proxy_Status;
}
Proxy_Auto{
menuchecked=(getpref(INT,$_Proxy_Active."type")==4);
setpref(INT,$_Proxy_Active."type",4); &_Proxy_Status;
}
Proxy_File{
menuchecked=(getpref(INT,$_Proxy_Active."type")==2);
getpref(STRING,$_Proxy_PACURL)==""?0:setpref(INT,$_Proxy_Active."type",2); &_Proxy_Status;
}
Proxy_Custom{
menuchecked=((getpref(INT,$_Proxy_Active."type")==1)*(getpref(STRING,$_Proxy_Custom.$ARG.".http")==getpref(STRING,$_Proxy_Active."http")));
$__srvr=getpref(STRING,$_Proxy_Custom.$ARG.".http");
$__port=getpref(INT,$_Proxy_Custom.$ARG.".http_port");
# When no server url is set, do not change anything!
$__srvr==""?0:setpref(STRING,$_Proxy_Active."http",$__srvr);
$__srvr==""?0:setpref(INT,$_Proxy_Active."http_port",$__port);
$__srvr==""?0:setpref(INT,$_Proxy_Active."type",1); &_Proxy_Status;
}
Proxy_Configuration{
$_tit=_("HTTP Proxy Configuration"); $_i=4;
$__url=getpref(STRING,$_Proxy_PACURL);
$__msg=sub("%n",$_i,_("Current settings for automatic proxy configuration:"))."\n\n".sub("%s",$__url==""?_("(not set)"):$__url,_("URL: %s"))."\n\n"._("Do you want to change these settings?");
$__key=confirm($__msg,$_tit,YESNOCANCEL,QUESTION); $__key==YES?&_Proxy_ConfigurationFile:($__key==NO?$_i=1:0);
while($_i!=4) &_Proxy_ConfigurationLoop;
}

# ----- PRIVATE

$_Proxy_Active="network.proxy.";
$_Proxy_PACURL=$_Proxy_Active."autoconfig_url";
$_Proxy_Custom=$macroPrefBranch."proxy";

_Proxy_Status{
$__data=getpref(INT,$_Proxy_Active."type");
$__data==0?statusbar(_("Connecting directly")):0;
$__data==1?statusbar(sub("%url",getpref(STRING,$_Proxy_Active."http"),sub("%port",getpref(INT,$_Proxy_Active."http_port"),_("Connecting over proxy %url:%port")))):0;
$__data==2?statusbar(sub("%s",getpref(STRING,$_Proxy_PACURL),_("Connecting according to %s"))):0;
$__data==4?statusbar(_("Connecting over any detected proxy")):0;
}

_Proxy_ConfigurationFile{
$__data=prompt(_("Automatic proxy configuration URL:"),$_tit,getpref(STRING,$_Proxy_PACURL));
$__data==""?0:setpref(STRING,$_Proxy_PACURL,$__data);
&Proxy_Configuration;
}
_Proxy_ConfigurationLoop{
$_name=getpref(STRING,$_Proxy_Custom.$_i.".name");
$_srvr=getpref(STRING,$_Proxy_Custom.$_i.".http");
$_port=getpref(INT,$_Proxy_Custom.$_i.".http_port");
$__msg=sub("%n",$_i,_("Current settings for proxy %n:"))."\n\n".sub("%s",$_name,_("Server name:\t%s"))."\n".sub("%s",$_srvr==""?_("(not set)"):$_srvr,_("Server URL:\t%s"))."\n".sub("%s",$_port==0?_("(not set)"):$_port,_("Server port:\t%s"))."\n\n"._("Do you want to change these settings?");
$__key=confirm($__msg,$_tit,YESNOCANCEL,QUESTION); $__key==YES?&_Proxy_ConfigurationChange:($__key==NO?$_i=$_i+1:$_i=4);
}
_Proxy_ConfigurationChange{
$_name=prompt(_("Server name:"),$_tit,$_name);
$_name==""?0:setpref(STRING,$_Proxy_Custom.$_i.".name",$_name);
$_name==""?$_srvr="":$_srvr=prompt(_("Server URL:"),$_tit,$_srvr);
$_srvr==""?0:setpref(STRING,$_Proxy_Custom.$_i.".http",$_srvr);
$_srvr==""?$_port="":$_port=prompt(_("Server port:"),$_tit,$_port);
$_port==""?0:setpref(INT,$_Proxy_Custom.$_i.".http_port",$_port);
&_Proxy_BuildMenu;
}

_Proxy_BuildMenu{
# tools menu
$_p="Pro&xy";
setmenu(PrivacySecurity,popup,$_p);
setmenu($_p,macro,"&Direct Connection",Proxy_None);
setmenu($_p,macro,"&Auto Detect",Proxy_Auto);
setmenu($_p,macro,"Auto &Configure",Proxy_File);
$_j=1; while($_j!=4) &_Proxy_BuildMenuLoop;
setmenu($_p,macro,"Con&figure...",Proxy_Configuration);
setmenu($_p,separator,"Con&figure...");
rebuildmenu($_p);
}
_Proxy_BuildMenuLoop{
setmenu($_p,macro,getpref(STRING,$_Proxy_Custom.$_j.".name"),"Proxy_Custom(".$_j.")"); $_j=$_j+1;
}
$OnInit=$OnInit."_Proxy_BuildMenu;";

# ------------------------------------------------------------------------------------------------------------------
$macroModules=$macroModules."Proxy;";