winix/templatesnotify/templatesnotify.cpp

136 lines
2.4 KiB
C++
Executable File

/*
* 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/locale.h"
#include "../core/data.h"
#include "../core/log.h"
namespace TemplatesNotifyFunctions
{
Patterns patterns;
Ezc::Functions functions;
Locale locale;
LocaleFilter locale_filter;
// you can use this pointer in template functions (will be always valid)
NotifyMsg * notify_msg;
} // namespace TemplatesNotifyFunctions
void TemplatesNotify::CreateFunctions()
{
using namespace TemplatesNotifyFunctions;
functions.Clear();
functions.Insert("notify_item_added", notify_item_added);
functions.Insert("notify_item_edited", notify_item_edited);
functions.Insert("notify_item_deleted", notify_item_deleted);
functions.Insert("notify_dir_added", notify_dir_added);
functions.Insert("notify_to", notify_to);
functions.Insert("notify_mount_type_is_thread", notify_mount_type_is_thread);
functions.Insert("notify_mount_type_is_cms", notify_mount_type_is_cms);
functions.Insert("notify_doc_base_url", notify_doc_base_url);
functions.Insert("notify_item_dir", notify_item_dir);
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(data.locale_str);
if( lang != Locale::lang_unknown )
locale.SetLang(lang);
else
locale.SetLang(Locale::lang_en);
ClearPatterns();
locale.Read(data.locale_dir, data.locale_dir_default);
TemplatesFunctions::Read(patterns, pat_email_notify, locale, locale_filter, "notify_email.txt", true);
notify_msg = 0;
}
void TemplatesNotify::Generate(Locale::Lang lang)
{
using namespace TemplatesNotifyFunctions;
notify_str.str("");
if( !notify_msg )
return;
if( static_cast<size_t>(lang) >= patterns.size() )
{
// ops, something wrong
return;
}
Ezc::Generator generator(notify_str, patterns[lang][pat_email_notify], functions);
generator.Generate();
}
TemplatesNotify::TemplatesNotify()
{
ClearPatterns();
}