Added /reloadui reminder feature. Fixed broken keybindings with french client. Renamed time format and alert style settings.

Jayden Platell [05-05-14 - 11:17]
Added /reloadui reminder feature.  Fixed broken keybindings with french client.  Renamed time format and alert style settings.
Filename
Bindings.xml
Librarian.lua
LibrarianSettings.lua
diff --git a/Bindings.xml b/Bindings.xml
index 06d75f2..2d0e25d 100644
--- a/Bindings.xml
+++ b/Bindings.xml
@@ -1,10 +1,10 @@
 <Bindings>
-  <Layer name="General">
+  <Layer name="SI_KEYBINDINGS_LAYER_GENERAL">
     <Category name="Librarian">
       <Action name="TOGGLE_LIBRARIAN">
         <Down>Librarian:Toggle()</Down>
       </Action>
-	<Action name="RELOAD_UI">
+	     <Action name="RELOAD_UI">
         <Down>SLASH_COMMANDS["/reloadui"]()</Down>
       </Action>
     </Category>
diff --git a/Librarian.lua b/Librarian.lua
index 1f23c5e..71c94ed 100644
--- a/Librarian.lua
+++ b/Librarian.lua
@@ -10,7 +10,7 @@ ZO_CreateStringId("SI_LIBRARIAN_SORT_TYPE_TITLE", "Title")
 ZO_CreateStringId("SI_LIBRARIAN_SORT_TYPE_WORD_COUNT", "Words")
 ZO_CreateStringId("SI_LIBRARIAN_MARK_UNREAD", "Mark as Unread")
 ZO_CreateStringId("SI_LIBRARIAN_MARK_READ", "Mark as Read")
-ZO_CreateStringId("SI_LIBRARIAN_CREDIT", "by Flamage")
+ZO_CreateStringId("SI_LIBRARIAN_CREDIT", "Librarian 1.0.16 by Flamage")
 ZO_CreateStringId("SI_LIBRARIAN_BOOK_COUNT", "%d Books")
 ZO_CreateStringId("SI_LIBRARIAN_UNREAD_COUNT", "%s (%d Unread)")
 ZO_CreateStringId("SI_LIBRARIAN_SHOW_ALL_BOOKS", "Show books for all characters")
@@ -18,6 +18,7 @@ ZO_CreateStringId("SI_LIBRARIAN_NEW_BOOK_FOUND", "Book added to librarian")
 ZO_CreateStringId("SI_LIBRARIAN_NEW_BOOK_FOUND_WITH_TITLE", "Book added to librarian: %s")
 ZO_CreateStringId("SI_LIBRARIAN_FULLTEXT_SEARCH", "Full-text Search:")
 ZO_CreateStringId("SI_LIBRARIAN_SEARCH_HINT", "Enter text to search for.")
+ZO_CreateStringId("SI_LIBRARIAN_RELOAD_REMINDER", "ReloadUI suggested to update Librarian database.")

 local SORT_ARROW_UP = "EsoUI/Art/Miscellaneous/list_sortUp.dds"
 local SORT_ARROW_DOWN = "EsoUI/Art/Miscellaneous/list_sortDown.dds"
@@ -40,6 +41,7 @@ end

 function Librarian:Initialise()
  	self.masterList = {}
+ 	self.newBookCount = 0
     self.sortHeaderGroup:SelectHeaderByKey("timeStamp")

  	ZO_ScrollList_AddDataType(self.list, LIBRARIAN_DATA, "LibrarianBookRow", 30, function(control, data) self:SetupBookRow(control, data) end)
@@ -150,6 +152,17 @@ function Librarian:UpdateSavedVariables()
 		self.localSavedVars.books = nil
 		self:RefreshData()
 	end
+
+	-- Version 1.0.16 - Fixed a couple of settings names.
+	if self.globalSavedVars.settings.alert_style then
+		self.globalSavedVars.settings.alertStyle = self.globalSavedVars.settings.alert_style
+		self.globalSavedVars.settings.alert_style = nil
+	end
+
+	if self.globalSavedVars.settings.time_format then
+		self.globalSavedVars.settings.timeFormat = self.globalSavedVars.settings.time_format
+		self.globalSavedVars.settings.time_format = nil
+	end
 end

 function Librarian:InitializeKeybindStripDescriptors()
@@ -342,17 +355,7 @@ end

 function Librarian:AddBook(book)
 	if not self:FindCharacterBook(book.title) then
-		local characterBook = {title = book.title, timeStamp = GetTimeStamp()}
-		table.insert(self.characterBooks, characterBook)
-
-		local function IsBookInGlobalData(book)
-			for _,i in ipairs(self.books) do
-				if i.title == book.title then return true end
-			end
-			return false
-		end
-
-		if not IsBookInGlobalData(book) then
+		if not self:FindBook(book.title) then
 			book.timeStamp = GetTimeStamp()
 			book.unread = true
 			local wordCount = 0
@@ -360,6 +363,9 @@ function Librarian:AddBook(book)
 			book.wordCount = wordCount
 			table.insert(self.books, book)
 		end
+
+		local characterBook = { title = book.title, timeStamp = GetTimeStamp() }
+		table.insert(self.characterBooks, characterBook)

 		self:RefreshData()
 		if self.settings.alertEnabled then
@@ -368,6 +374,11 @@ function Librarian:AddBook(book)
 		if self.settings.chatEnabled then
 			d(string.format(GetString(SI_LIBRARIAN_NEW_BOOK_FOUND_WITH_TITLE), book.title))
 		end
+
+		self.newBookCount = self.newBookCount + 1
+		if self.settings.reloadReminderBookCount > 0 and self.settings.reloadReminderBookCount <= self.newBookCount then
+			d(GetString(SI_LIBRARIAN_RELOAD_REMINDER))
+		end
 	end
 end

@@ -396,7 +407,7 @@ function Librarian:FormatClockTime(time)
     end

     local dateString = GetDateStringFromTimestamp(time)
-    local timeString = ZO_FormatTime((time + offset) % 86400, TIME_FORMAT_STYLE_CLOCK_TIME, self.settings.time_format)
+    local timeString = ZO_FormatTime((time + offset) % 86400, TIME_FORMAT_STYLE_CLOCK_TIME, self.settings.timeFormat)
 	return string.format("%s %s", dateString, timeString)
 end

@@ -416,7 +427,7 @@ local function OnAddonLoaded(event, addon)
 end

 local function OnShowBook(eventCode, title, body, medium, showTitle)
-	local book = {title = title, body = body, medium = medium, showTitle = showTitle}
+	local book = { title = title, body = body, medium = medium, showTitle = showTitle }
 	LIBRARIAN:AddBook(book)
 end

diff --git a/LibrarianSettings.lua b/LibrarianSettings.lua
index f629875..985ccfc 100644
--- a/LibrarianSettings.lua
+++ b/LibrarianSettings.lua
@@ -1,15 +1,22 @@
 LibrarianSettings = ZO_Object:Subclass()

-local time_formats = {
+local timeFormats = {
 	{ name = "12 hour", value = TIME_FORMAT_PRECISION_TWELVE_HOUR },
 	{ name = "24 hour", value = TIME_FORMAT_PRECISION_TWENTY_FOUR_HOUR }
 }

-local alert_styles = {
-	{ name = "None", value = 'None', chat = false, alert = false },
-	{ name = "Chat only", value = 'Chat', chat = true, alert = false },
-	{ name = "Alert only", value = 'Alert', chat = false, alert = true },
-	{ name = "Both", value = 'Both', chat = true, alert = true },
+local alertStyles = {
+	{ name = "None", value = "None", chat = false, alert = false },
+	{ name = "Chat only", value = "Chat", chat = true, alert = false },
+	{ name = "Alert only", value = "Alert", chat = false, alert = true },
+	{ name = "Both", value = "Both", chat = true, alert = true },
+}
+
+local reloadReminders = {
+	{ name = "Never", value = 0 },
+	{ name = "1 new book", value = 1 },
+	{ name = "5 new books", value = 5 },
+	{ name = "10 new books", value = 10 }
 }

 function LibrarianSettings:New( ... )
@@ -41,16 +48,16 @@ end
 function LibrarianSettings:Initialise(settings)
 	self.settings = settings

-	if self.settings.time_format == nil then
-		self.settings.time_format = (GetCVar("Language.2") == "en") and TIME_FORMAT_PRECISION_TWELVE_HOUR or TIME_FORMAT_PRECISION_TWENTY_FOUR_HOUR
+	if self.settings.timeFormat == nil then
+		self.settings.timeFormat = (GetCVar("Language.2") == "en") and TIME_FORMAT_PRECISION_TWELVE_HOUR or TIME_FORMAT_PRECISION_TWENTY_FOUR_HOUR
 	end

 	if self.settings.showAllBooks == nil then
 		self.settings.showAllBooks = true
 	end

-	if self.settings.alert_style == nil then
-		self.settings.alert_style = 'Both'
+	if self.settings.alertStyle == nil then
+		self.settings.alertStyle = 'Both'
 		self.settings.chatEnabled = true
 		self.settings.alertEnabled = true
 	end
@@ -59,33 +66,33 @@ function LibrarianSettings:Initialise(settings)
 		self.settings.showUnreadIndicatorInReader = true
 	end

+	if self.settings.reloadReminderBookCount == nil then
+		self.settings.reloadReminderBookCount = 5
+	end
+
 	local LAM = LibStub("LibAddonMenu-1.0")
 	local optionsPanel = LAM:CreateControlPanel("LibrarianOptions", "Librarian")

-	local time_formats_list = map(time_formats, function(item) return item.name end)
-
 	LAM:AddDropdown(optionsPanel,
 		"LibrarianOptionsTimeFormat",
 		"Time Format",
 		"Select a format to display times in.",
-		time_formats_list,
-		function() return getSettingByValue(time_formats, self.settings.time_format).name end,
-		function(format)
-			self.settings.time_format = getSettingByName(time_formats, format).value
+		map(timeFormats, function(item) return item.name end),
+		function() return getSettingByValue(timeFormats, self.settings.timeFormat).name end,
+		function(name)
+			self.settings.timeFormat = getSettingByName(timeFormats, name).value
 			LIBRARIAN:CommitScrollList()
 		end)

-	local alert_styles_list = map(alert_styles, function(item) return item.name end)
-
 	LAM:AddDropdown(optionsPanel,
 		"LibrarianOptionsAlertSetting",
 		"Alert Settings",
 		"Select a style of alert.",
-		alert_styles_list,
-		function() return getSettingByValue(alert_styles, self.settings.alert_style).name end,
-		function(format)
-			local setting = getSettingByName(alert_styles, format)
-			self.settings.alert_style = setting.value
+		map(alertStyles, function(item) return item.name end),
+		function() return getSettingByValue(alertStyles, self.settings.alertStyle).name end,
+		function(name)
+			local setting = getSettingByName(alertStyles, name)
+			self.settings.alertStyle = setting.value
 			self.settings.chatEnabled = setting.chat
 			self.settings.alertEnabled = setting.alert
 		end)
@@ -93,7 +100,18 @@ function LibrarianSettings:Initialise(settings)
 	LAM:AddCheckbox(optionsPanel,
 		"LibrarianOptionsUnreadIndicator",
 		"Unread Indicator",
-		"Show unread indicator in book reader",
+		"Show unread indicator in book reader.",
 		function() return self.settings.showUnreadIndicatorInReader end,
 		function(value) self.settings.showUnreadIndicatorInReader = value end)
+
+	LAM:AddDropdown(optionsPanel,
+		"LibrarianOptionsReloadReminder",
+		"ReloadUI reminder after",
+		"Reminder to /reloadui after this number of new books are discovered.",
+		map(reloadReminders, function(item) return item.name end),
+		function() return getSettingByValue(reloadReminders, self.settings.reloadReminderBookCount).name end,
+		function(name)
+			local setting = getSettingByName(reloadReminders, name)
+			self.settings.reloadReminderBookCount = setting.value
+		end)
 end
\ No newline at end of file