2009-10-01 00:31:20 +02:00
|
|
|
/*
|
2010-02-28 01:08:10 +01:00
|
|
|
* This file is a part of Winix
|
2009-10-01 00:31:20 +02:00
|
|
|
* and is not publicly distributed
|
|
|
|
*
|
2010-02-28 22:33:06 +01:00
|
|
|
* Copyright (c) 2008-2010, Tomasz Sowa
|
2009-10-01 00:31:20 +02:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "templatesnotify.h"
|
2010-08-10 18:12:50 +02:00
|
|
|
#include "core/misc.h"
|
|
|
|
#include "core/log.h"
|
2010-11-21 01:19:17 +01:00
|
|
|
#include "core/textstream.h"
|
|
|
|
#include "templates/locale.h"
|
2009-10-01 00:31:20 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
2010-09-13 01:33:27 +02:00
|
|
|
|
2009-10-01 00:31:20 +02:00
|
|
|
namespace TemplatesNotifyFunctions
|
|
|
|
{
|
2010-01-28 16:39:01 +01:00
|
|
|
|
2010-09-13 01:33:27 +02:00
|
|
|
// id of mount points types
|
|
|
|
int mount_type_cms;
|
|
|
|
int mount_type_thread;
|
|
|
|
int mount_type_ticket;
|
|
|
|
|
|
|
|
|
2010-07-04 22:27:14 +02:00
|
|
|
Patterns patterns;
|
2010-11-21 01:19:17 +01:00
|
|
|
Ezc::Functions<TextStream<std::wstring> > ezc_functions;
|
2010-02-15 01:31:14 +01:00
|
|
|
Locale locale;
|
2010-01-28 16:39:01 +01:00
|
|
|
LocaleFilter locale_filter;
|
|
|
|
|
2010-08-10 18:12:50 +02:00
|
|
|
Config * config;
|
2009-10-01 00:31:20 +02:00
|
|
|
|
|
|
|
|
|
|
|
// you can use this pointer in template functions (will be always valid)
|
|
|
|
NotifyMsg * notify_msg;
|
|
|
|
|
|
|
|
|
2010-01-28 16:39:01 +01:00
|
|
|
} // namespace TemplatesNotifyFunctions
|
2009-10-01 00:31:20 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-08-10 18:12:50 +02:00
|
|
|
void TemplatesNotify::SetConfig(Config * pconfig)
|
|
|
|
{
|
|
|
|
TemplatesNotifyFunctions::config = pconfig;
|
|
|
|
}
|
|
|
|
|
2010-09-13 01:33:27 +02:00
|
|
|
void TemplatesNotify::SetMountTypes(int mcms, int mthread, int mticket)
|
|
|
|
{
|
|
|
|
using namespace TemplatesNotifyFunctions;
|
|
|
|
|
|
|
|
mount_type_cms = mcms;
|
|
|
|
mount_type_thread = mthread;
|
|
|
|
mount_type_ticket = mticket;
|
|
|
|
}
|
2010-08-10 18:12:50 +02:00
|
|
|
|
2009-10-01 00:31:20 +02:00
|
|
|
|
|
|
|
|
|
|
|
void TemplatesNotify::CreateFunctions()
|
|
|
|
{
|
|
|
|
using namespace TemplatesNotifyFunctions;
|
2010-09-13 01:33:27 +02:00
|
|
|
|
2010-08-10 18:12:50 +02:00
|
|
|
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);
|
2010-09-08 01:54:01 +02:00
|
|
|
ezc_functions.Insert("notify_mount_type_is_ticket", notify_mount_type_is_ticket);
|
2010-08-10 18:12:50 +02:00
|
|
|
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);
|
2009-10-01 00:31:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-01-28 16:39:01 +01:00
|
|
|
void TemplatesNotify::ClearPatterns()
|
|
|
|
{
|
|
|
|
using namespace TemplatesNotifyFunctions;
|
2009-10-01 00:31:20 +02:00
|
|
|
|
2010-01-28 16:39:01 +01:00
|
|
|
|
2010-07-04 22:27:14 +02:00
|
|
|
TemplatesFunctions::ClearPatterns(patterns, pat_last);
|
2010-01-28 16:39:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// templates are read in the main thread
|
|
|
|
// (before creating the second thread)
|
|
|
|
void TemplatesNotify::Read()
|
2009-10-01 00:31:20 +02:00
|
|
|
{
|
|
|
|
using namespace TemplatesNotifyFunctions;
|
|
|
|
|
2010-08-10 18:12:50 +02:00
|
|
|
Locale::Lang lang = Locale::StrToLang(config->locale_str);
|
2009-10-01 00:31:20 +02:00
|
|
|
|
2010-02-15 01:31:14 +01:00
|
|
|
if( lang != Locale::lang_unknown )
|
|
|
|
locale.SetLang(lang);
|
|
|
|
else
|
|
|
|
locale.SetLang(Locale::lang_en);
|
2010-01-28 16:39:01 +01:00
|
|
|
|
2010-02-15 01:31:14 +01:00
|
|
|
ClearPatterns();
|
2010-11-21 01:19:17 +01:00
|
|
|
locale.UTF8(config->utf8);
|
2010-08-10 18:12:50 +02:00
|
|
|
locale.Read(config->locale_dir, config->locale_dir_default);
|
2010-11-25 23:42:24 +01:00
|
|
|
|
|
|
|
// !! 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);
|
2010-01-28 16:39:01 +01:00
|
|
|
|
2009-10-01 00:31:20 +02:00
|
|
|
notify_msg = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-01-28 16:39:01 +01:00
|
|
|
void TemplatesNotify::Generate(Locale::Lang lang)
|
2009-10-01 00:31:20 +02:00
|
|
|
{
|
|
|
|
using namespace TemplatesNotifyFunctions;
|
|
|
|
|
2010-11-21 01:19:17 +01:00
|
|
|
notify_str.Clear();
|
2009-10-01 00:31:20 +02:00
|
|
|
|
|
|
|
if( !notify_msg )
|
|
|
|
return;
|
|
|
|
|
2010-01-28 16:39:01 +01:00
|
|
|
if( static_cast<size_t>(lang) >= patterns.size() )
|
|
|
|
{
|
|
|
|
// ops, something wrong
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-11-25 23:42:24 +01:00
|
|
|
Ezc::Generator<TextStream<std::wstring> > generator;
|
2010-09-08 01:54:01 +02:00
|
|
|
generator.RecognizeSpecialChars(true);
|
|
|
|
generator.TrimWhite(true);
|
|
|
|
generator.SkipNewLine(true);
|
2010-11-25 23:42:24 +01:00
|
|
|
generator.Generate(notify_str, patterns[lang][pat_email_notify]);
|
2009-10-01 00:31:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-28 16:39:01 +01:00
|
|
|
TemplatesNotify::TemplatesNotify()
|
|
|
|
{
|
|
|
|
ClearPatterns();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|