Console: Extend framework with intended recipient and content type metainformation
================================================================================== Limitations of the current framework: - Codes the translated state only for TranslatedNotification as part of the type. - Does not code the intended recipient (user, developer, ...) Problems: - Some errors are intended for developers, some errors may only be intended for users, if, for example, there is another developer error which already contains all the information. The current framework may lead to information duplication or to showing to the user developer information, which is perceived as annoying. - Logs shall be in English (report view), while every message to the user (UI) shall be translated. The current framework can only differentiate where to report based on subscription (legacy logs do not subscribe to notifications), and for notifications, whether it is translated or not depends on the type. It is not possible to code errors or warnings that are already translated. Solution: - To extend the ILogger interface with additional metainformation, indicating the intended recipient (User, Developer, All), and the content of the message (translated, untranslated, untranslatable). The latter is useful for dynamic strings that won't find a match in the translation framework. Bonus: - This extended version allows to do away with translatednotification, as now any message can be independently marked as translated or untranslated or untraslatable. - It is now possible to provide the right icon of severity (error, warning, info), even when it is only user intended and already translated.
This commit is contained in:
committed by
abdullahtahiriyo
parent
f3595bce0b
commit
9d9f928b2d
@@ -49,11 +49,14 @@ namespace Base {
|
||||
class ConsoleEvent : public QEvent {
|
||||
public:
|
||||
ConsoleSingleton::FreeCAD_ConsoleMsgType msgtype;
|
||||
IntendedRecipient recipient;
|
||||
ContentType content;
|
||||
std::string notifier;
|
||||
std::string msg;
|
||||
|
||||
ConsoleEvent(ConsoleSingleton::FreeCAD_ConsoleMsgType type, const std::string& notifier, const std::string& msg)
|
||||
: QEvent(QEvent::User), msgtype(type), notifier(notifier),msg(msg)
|
||||
ConsoleEvent(ConsoleSingleton::FreeCAD_ConsoleMsgType type, IntendedRecipient recipient,
|
||||
ContentType content, const std::string& notifier, const std::string& msg)
|
||||
: QEvent(QEvent::User), msgtype(type), recipient(recipient), content(content), notifier(notifier), msg(msg)
|
||||
{
|
||||
}
|
||||
~ConsoleEvent() override = default;
|
||||
@@ -77,25 +80,25 @@ public:
|
||||
ConsoleEvent* ce = static_cast<ConsoleEvent*>(ev);
|
||||
switch (ce->msgtype) {
|
||||
case ConsoleSingleton::MsgType_Txt:
|
||||
Console().Notify<LogStyle::Message>(ce->notifier, ce->msg);
|
||||
Console().notifyPrivate(LogStyle::Message, ce->recipient, ce->content, ce->notifier, ce->msg);
|
||||
break;
|
||||
case ConsoleSingleton::MsgType_Log:
|
||||
Console().Notify<LogStyle::Log>(ce->notifier, ce->msg);
|
||||
Console().notifyPrivate(LogStyle::Log, ce->recipient, ce->content, ce->notifier, ce->msg);
|
||||
break;
|
||||
case ConsoleSingleton::MsgType_Wrn:
|
||||
Console().Notify<LogStyle::Warning>(ce->notifier, ce->msg);
|
||||
Console().notifyPrivate(LogStyle::Warning, ce->recipient, ce->content, ce->notifier, ce->msg);
|
||||
break;
|
||||
case ConsoleSingleton::MsgType_Err:
|
||||
Console().Notify<LogStyle::Error>(ce->notifier, ce->msg);
|
||||
Console().notifyPrivate(LogStyle::Error, ce->recipient, ce->content, ce->notifier, ce->msg);
|
||||
break;
|
||||
case ConsoleSingleton::MsgType_Critical:
|
||||
Console().Notify<LogStyle::Critical>(ce->notifier, ce->msg);
|
||||
Console().notifyPrivate(LogStyle::Critical, ce->recipient, ce->content, ce->notifier, ce->msg);
|
||||
break;
|
||||
case ConsoleSingleton::MsgType_Notification:
|
||||
Console().Notify<LogStyle::Notification>(ce->notifier, ce->msg);
|
||||
Console().notifyPrivate(LogStyle::Notification, ce->recipient, ce->content, ce->notifier, ce->msg);
|
||||
break;
|
||||
case ConsoleSingleton::MsgType_TranslatedNotification:
|
||||
Console().Notify<LogStyle::TranslatedNotification>(ce->notifier, ce->msg);
|
||||
Console().notifyPrivate(LogStyle::TranslatedNotification, ce->recipient, ce->content, ce->notifier, ce->msg);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -286,18 +289,20 @@ void ConsoleSingleton::DetachObserver(ILogger *pcObserver)
|
||||
_aclObservers.erase(pcObserver);
|
||||
}
|
||||
|
||||
void Base::ConsoleSingleton::notifyPrivate(LogStyle category, const std::string& notifiername, const std::string& msg)
|
||||
void Base::ConsoleSingleton::notifyPrivate(LogStyle category, IntendedRecipient recipient,
|
||||
ContentType content, const std::string& notifiername, const std::string& msg)
|
||||
{
|
||||
for (std::set<ILogger * >::iterator Iter=_aclObservers.begin();Iter!=_aclObservers.end();++Iter) {
|
||||
if ((*Iter)->isActive(category)) {
|
||||
(*Iter)->SendLog(notifiername, msg, category); // send string to the listener
|
||||
(*Iter)->SendLog(notifiername, msg, category, recipient, content); // send string to the listener
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ConsoleSingleton::postEvent(ConsoleSingleton::FreeCAD_ConsoleMsgType type, const std::string& notifiername, const std::string& msg)
|
||||
void ConsoleSingleton::postEvent(ConsoleSingleton::FreeCAD_ConsoleMsgType type, IntendedRecipient recipient,
|
||||
ContentType content, const std::string& notifiername, const std::string& msg)
|
||||
{
|
||||
QCoreApplication::postEvent(ConsoleOutput::getInstance(), new ConsoleEvent(type, notifiername, msg));
|
||||
QCoreApplication::postEvent(ConsoleOutput::getInstance(), new ConsoleEvent(type, recipient, content, notifiername, msg));
|
||||
}
|
||||
|
||||
ILogger *ConsoleSingleton::Get(const char *Name) const
|
||||
|
||||
Reference in New Issue
Block a user