aboutsummaryrefslogtreecommitdiff
path: root/src/chatlogpiece.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/chatlogpiece.cpp')
-rw-r--r--src/chatlogpiece.cpp68
1 files changed, 22 insertions, 46 deletions
diff --git a/src/chatlogpiece.cpp b/src/chatlogpiece.cpp
index 64ffefe8..d8ef2949 100644
--- a/src/chatlogpiece.cpp
+++ b/src/chatlogpiece.cpp
@@ -1,57 +1,33 @@
#include "chatlogpiece.h"
-chatlogpiece::chatlogpiece()
-{
- name = tr("UNKNOWN");
- showname = tr("UNKNOWN");
- message = tr("UNKNOWN");
- color = 0;
- action = "";
- datetime = QDateTime::currentDateTimeUtc();
-}
+#include <QStringBuilder>
-chatlogpiece::chatlogpiece(QString p_name, QString p_showname,
- QString p_message, QString p_action, int p_color, bool p_selfname)
+QString ChatLogPiece::toString()
{
- name = p_name;
- showname = p_showname;
- message = p_message;
- action = p_action;
- color = p_color;
- selfname = p_selfname;
- datetime = QDateTime::currentDateTimeUtc();
-}
+ auto maybe_unknown = [](QString str) -> QString {
+ if (str.isEmpty())
+ {
+ return tr("UNKNOWN");
+ }
+ else
+ {
+ return str;
+ }
+ };
-chatlogpiece::chatlogpiece(QString p_name, QString p_showname,
- QString p_message, QString p_action, int p_color, bool p_selfname,
- QDateTime p_datetime)
-{
- name = p_name;
- showname = p_showname;
- message = p_message;
- action = p_action;
- color = p_color;
- selfname = p_selfname;
- datetime = p_datetime.toUTC();
-}
+ QString details = QString("[%1] %2").arg(timestamp.toString(), maybe_unknown(character_name));
-QString chatlogpiece::get_full()
-{
- QString full = "[";
+ if (character_name != character)
+ {
+ details += " (" % maybe_unknown(character) % ")";
+ }
- full.append(get_datetime_as_string());
- full.append("] ");
- full.append(get_showname());
- if (get_showname() != get_name())
+ if (!action.isEmpty())
{
- full.append(" (");
- full.append(get_name());
- full.append(")");
+ details += " " % action;
}
- if (!get_action().isEmpty())
- full.append(" " + get_action());
- full.append(": ");
- full.append(get_message());
- return full;
+ details += ": " % maybe_unknown(message);
+
+ return details;
}