---------------------------------------------------------------------------------
--
-- Prat - A framework for World of Warcraft chat mods
--
-- Copyright (C) 2006-2007  Prat Development Team
--
-- This program is free software; you can redistribute it and/or
-- modify it under the terms of the GNU General Public License
-- as published by the Free Software Foundation; either version 2
-- of the License, or (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program; if not, write to:
--
-- Free Software Foundation, Inc., 
-- 51 Franklin Street, Fifth Floor, 
-- Boston, MA  02110-1301, USA.
--
--
-------------------------------------------------------------------------------



--[[
Name: Prat_History
Revision: $Revision: 26318 $
Author(s): Krtek (krtek4@gmail.com)
Website: http://www.wowace.com/files/index.php?path=Prat/
Documentation: http://www.wowace.com/wiki/Prat/Integrated_Modules#History
SVN: http://svn.wowace.com/wowace/trunk/Prat/
Description: Module for Prat that adds chat history options.
Dependencies: Prat
]]

local L = AceLibrary("AceLocale-2.2"):new("PratHistory")

L:RegisterTranslations("enUS", function() return {
    ["History"] = true,
    ["Chat history options."] = true,
    ["Set Lines"] = true,
    ["Set number of History lines for each window."] = true,
    ["Chat%dHistory"] = true,
    ["Sets history for chat window %d."] = true,
} end)

L:RegisterTranslations("zhCN", function() return {
	["History"] = "历史",
	["Chat history options."] = "聊天历史选项。",
	["Set Lines"] = "设置",
	["Set number of History lines for each window."] = "为每一聊天窗口设置历史记录行数.",
    ["Chat%dHistory"] = "窗口%d历史",
    ["Sets history for chat window %d."] = "设置聊天窗口%d聊天历史记录",
} end)

L:RegisterTranslations("koKR", function() return {
    ["History"] = "이력",
    ["Chat history options."] = "대화 이력 설정입니다.",
    ["Set Lines"] = "라인수 설정",
    ["Set number of History lines for each window."] = "각각의 대화창에 대한 이력의 라인 수를 설정합니다.",
    ["Chat%dHistory"] = "대화창%d이력",
    ["Sets history for chat window %d."] = "대화창 %d에 대한 이력을 설정합니다.",
} end)

L:RegisterTranslations("zhTW", function() return {
    ["History"] = "記錄",
    ["Chat history options."] = "聊天記錄選項。",
    ["Set Lines"] = "設定",
    ["Set number of History lines for each window."] = "為每一聊天視窗設定記錄行數。",
    ["Chat%dHistory"] = "視窗%d記錄",
    ["Sets history for chat window %d."] = "設定聊天視窗 %d 聊天記錄。",
} end)

L:RegisterTranslations("esES", function() return {
    ["History"] = "Historial",
    ["Chat history options."] = "Opciones del historial de chat",
    ["Set Lines"] = "Establecer",
    ["Set number of History lines for each window."] = "Establece el n\195\186mero de l\195\173neas de historial para cada ventana",
    ["Chat%dHistory"] = "Historial del Chat %d",
    ["Sets history for chat window %d."] = "Establece el historial para la ventana de chat %d",
} end)

L:RegisterTranslations("deDE", function() return {
    ["History"] = "Verlauf",
    ["Chat history options."] = "Chat Verlauf Optionen.",
    ["Set Lines"] = "Setze",
    ["Set number of History lines for each window."] = "Setze die Anzahl der Verlauf Zeilen f\195\188r jedes Fenster.",
    ["Chat%dHistory"] = "Chat %d Verlauf",
    ["Sets history for chat window %d."] = "Setze Verlauf f\195\188r Chatfenster %d.",
} end)

L:RegisterTranslations("frFR", function() return {
    ["History"] = "Historique",
    ["Chat history options."] = "Options de l'historique des chats",
    ["Set Lines"] = "Nombre de lignes",
    ["Set number of History lines for each window."] = "R195\168gle le nombre de lignes d'historique à garder pour chaque fen\195\170tre.",
    ["Chat%dHistory"] = "Historique fen\195\170tre %d",
    ["Sets history for chat window %d."] = "R195\168gle l'historique pour la fen\195\170tre %d.",
} end)

Prat_History = Prat:NewModule(Prat:RequestModuleName("PratHistory"))

Prat_History.revision = tonumber(string.sub("$Revision: 26318 $", 12, -3))

-- Prat categories relevant to this module. list at: http://groups.google.com/group/wow-prat/web/prat-categories
local cat = Prat.Categories
Prat_History.Categories	= { cat.INFO, cat.FRAME, cat.BEHAVIOR }	-- eg { cat.TEXT, cat.INFO }

Prat_History.defaultDB = {
    on = true,
    chatlines = {128, 128, 128, 128, 128, 128, 128, 128},
}

Prat_History.moduleOptions = {}

function Prat_History:GetModuleOptions()
    self.moduleOptions = {
        name = L["History"],
        desc = L["Chat history options."],
        type = "group",
        args = {
            set = {
                name = L["Set Lines"],
                desc = L["Set number of History lines for each window."],
                type = "group",
                args = {
                    chat1 = {
                        name = string.format(L["Chat%dHistory"], 1),
                        desc = string.format(L["Sets history for chat window %d."], 1),
                        type = "range",
                        min = 50,
                        max = 500,
                        step = 1,
                        get = function() return self.db.profile.chatlines[1] end,
                        set = function(v) Prat_History:SetHistory(1, v) end,
                    },
                    chat2 = {
                        name = string.format(L["Chat%dHistory"], 2),
                        desc = string.format(L["Sets history for chat window %d."], 2),
                        type = "range",
                        min = 50,
                        max = 500,
                        step = 1,
                        get = function() return self.db.profile.chatlines[2] end,
                        set = function(v) Prat_History:SetHistory(2, v) end,
                    },
                    chat3 = {
                        name = string.format(L["Chat%dHistory"], 3),
                        desc = string.format(L["Sets history for chat window %d."], 3),
                        type = "range",
                        min = 50,
                        max = 500,
                        step = 1,
                        get = function() return self.db.profile.chatlines[3] end,
                        set = function(v) Prat_History:SetHistory(3, v) end,
                    },
                    chat4 = {
                        name = string.format(L["Chat%dHistory"], 4),
                        desc = string.format(L["Sets history for chat window %d."], 4),
                        type = "range",
                        min = 50,
                        max = 500,
                        step = 1,
                        get = function() return self.db.profile.chatlines[4] end,
                        set = function(v) Prat_History:SetHistory(4, v) end,
                    },
                    chat5 = {
                        name = string.format(L["Chat%dHistory"], 5),
                        desc = string.format(L["Sets history for chat window %d."], 5),
                        type = "range",
                        min = 50,
                        max = 500,
                        step = 1,
                        get = function() return self.db.profile.chatlines[5] end,
                        set = function(v) Prat_History:SetHistory(5, v) end,
                    },
                    chat6 = {
                        name = string.format(L["Chat%dHistory"], 6),
                        desc = string.format(L["Sets history for chat window %d."], 6),
                        type = "range",
                        min = 50,
                        max = 500,
                        step = 1,
                        get = function() return self.db.profile.chatlines[6] end,
                        set = function(v) Prat_History:SetHistory(6, v) end,
                    },
                    chat7 = {
                        name = string.format(L["Chat%dHistory"],7),
                        desc = string.format(L["Sets history for chat window %d."], 7),
                        type = "range",
                        min = 50,
                        max = 500,
                        step = 1,
                        get = function() return self.db.profile.chatlines[7] end,
                        set = function(v) Prat_History:SetHistory(7, v) end,
                    },
                }
            },
        }
    }
   	return self.moduleOptions
end

function Prat_History:OnModuleEnable()
    for i=1,NUM_CHAT_WINDOWS do
        self:SetHistory(i,self.db.profile.chatlines[i])
    end
end

function Prat_History:OnModuleDisable()
    for i=1,NUM_CHAT_WINDOWS do
        self:SetHistory(i,128)
    end
end

--[[------------------------------------------------
	Core Functions
------------------------------------------------]]--

function Prat_History:SetHistory(id, lines)
    if lines ~= self.db.profile.chatlines[id] then
    	getglobal("ChatFrame"..id):SetMaxLines(lines)
		self.db.profile.chatlines[id] = lines
	end
end