/* * This file is a part of Winix * and is not publicly distributed * * Copyright (c) 2008-2010, Tomasz Sowa * All rights reserved. * */ #include "templatesnotify.h" #include "core/misc.h" #include "core/log.h" #include "core/textstream.h" #include "templates/locale.h" namespace TemplatesNotifyFunctions { // id of mount points types int mount_type_cms; int mount_type_thread; int mount_type_ticket; Patterns patterns; Ezc::Functions > ezc_functions; Locale locale; LocaleFilter locale_filter; Config * config; // you can use this pointer in template functions (will be always valid) NotifyMsg * notify_msg; } // namespace TemplatesNotifyFunctions void TemplatesNotify::SetConfig(Config * pconfig) { TemplatesNotifyFunctions::config = pconfig; } void TemplatesNotify::SetMountTypes(int mcms, int mthread, int mticket) { using namespace TemplatesNotifyFunctions; mount_type_cms = mcms; mount_type_thread = mthread; mount_type_ticket = mticket; } void TemplatesNotify::CreateFunctions() { using namespace TemplatesNotifyFunctions; ezc_functions.Clear(); ezc_functions.Insert("notify_item_added", notify_item_added); ezc_functions.Insert("notify_item_edited", notify_item_edited); ezc_functions.Insert("notify_item_deleted", notify_item_deleted); ezc_functions.Insert("notify_dir_added", notify_dir_added); ezc_functions.Insert("notify_to", notify_to); ezc_functions.Insert("notify_mount_type_is_thread", notify_mount_type_is_thread); ezc_functions.Insert("notify_mount_type_is_ticket", notify_mount_type_is_ticket); ezc_functions.Insert("notify_mount_type_is_cms", notify_mount_type_is_cms); ezc_functions.Insert("notify_doc_base_url", notify_doc_base_url); ezc_functions.Insert("notify_item_dir", notify_item_dir); ezc_functions.Insert("notify_item_link", notify_item_link); } void TemplatesNotify::ClearPatterns() { using namespace TemplatesNotifyFunctions; TemplatesFunctions::ClearPatterns(patterns, pat_last); } // templates are read in the main thread // (before creating the second thread) void TemplatesNotify::Read() { using namespace TemplatesNotifyFunctions; Locale::Lang lang = Locale::StrToLang(config->locale_str); if( lang != Locale::lang_unknown ) locale.SetLang(lang); else locale.SetLang(Locale::lang_en); ClearPatterns(); locale.UTF8(config->utf8); locale.Read(config->locale_dir, config->locale_dir_default); // !! nazwe pliku do konfiga TemplatesFunctions::Read(patterns, pat_email_notify, locale, locale_filter, ezc_functions, L"notify_email.txt", config->utf8, config->templates_dir, config->templates_dir_default, true); notify_msg = 0; } void TemplatesNotify::Generate(Locale::Lang lang) { using namespace TemplatesNotifyFunctions; notify_str.Clear(); if( !notify_msg ) return; if( static_cast(lang) >= patterns.size() ) { // ops, something wrong return; } Ezc::Generator > generator; generator.RecognizeSpecialChars(true); generator.TrimWhite(true); generator.SkipNewLine(true); generator.Generate(notify_str, patterns[lang][pat_email_notify]); } TemplatesNotify::TemplatesNotify() { ClearPatterns(); }