m = Map("qbittorrent", translate("qBittorrent"), translate("qBittorrent is a cross-platform free and open-source BitTorrent client.").."<br/>"..translate("Default login username: admin, password: adminadmin."))

m:section(SimpleSection).template="qbittorrent/qbittorrent_status"

s = m:section(TypedSection, "qbittorrent")
s.anonymous=true

enable = s:option(Flag, "enable", translate("Enable"))
enable.rmempty = false
enable.write = enable.write

port = s:option(Value,"port",translate("Port"),translate("WebUI listening port"))
port.default = "8080"
port.placeholder = "8080"
port.rmempty = false

profile_dir = s:option(Value,"profile_dir",translate("Profile Dir"),translate("Store configuration files in the Path"))
profile_dir.default = "/etc"
profile_dir.placeholder = "/etc"
profile_dir.rmempty = false

download_dir = s:option(Value,"download_dir",translate("Download Dir"),translate("Store download files in the Path"))
download_dir.default = "/mnt/download"
download_dir.placeholder = "/mnt/download"
download_dir.rmempty = false

download_dir = s:option(Value,"socks5_server",translate("Socks5 Server"),translate("Set your sock5 proxy server"))
download_dir.default = "proxy.torguard.org"
download_dir.placeholder = "proxy.torguard.org"
download_dir.rmempty = false

download_dir = s:option(Value,"socks5_port",translate("Socks5 Port"),translate("Set your sock5 port number"))
download_dir.default = "1085"
download_dir.placeholder = "1085"
download_dir.rmempty = false

download_dir = s:option(Value,"socks5_user",translate("Socks5 Username"),translate("Set your sock5 username"))
download_dir.default = "username"
download_dir.placeholder = "username"
download_dir.rmempty = false

download_dir = s:option(Value,"socks5_pass",translate("Socks5 Password"),translate("Set your sock5 password"))
download_dir.default = "password"
download_dir.placeholder = "password"
download_dir.rmempty = false

function enable.write(self, section, value)
    Flag.write(self, section, value)
    if value == "1" then
        luci.sys.call("/etc/init.d/qbittorrent start >/dev/null 2>&1")
    else
        luci.sys.call("/etc/init.d/qbittorrent stop >/dev/null 2>&1")
    end
end

return m
