1 /* coded by Ketmar // Vampire Avalon (psyc://ketmar.no-ip.org/~Ketmar)
2 * Understanding is not required. Only obedience.
4 * This program is free software. It comes without any warranty, to
5 * the extent permitted by applicable law. You can redistribute it
6 * and/or modify it under the terms of the Do What The Fuck You Want
7 * To Public License, Version 2, as published by Sam Hocevar. See
8 * http://sam.zoy.org/wtfpl/COPYING for more details.
15 #include <QTextStream>
17 #include "k8strutils.h"
19 #include "psycproto.h"
25 ConsoleForm::ConsoleForm (QWidget
*parent
) : QDialog(parent
) {
27 setAttribute(Qt::WA_QuitOnClose
, false);
28 setAttribute(Qt::WA_DeleteOnClose
, false);
30 //logStr("=========================================\n", "");
34 ConsoleForm::~ConsoleForm () {
38 void ConsoleForm::on_btClear_clicked (void) {
43 void ConsoleForm::logStr (const QString
&pfx
, const QString
&str
) {
44 QString spathStr
= QCoreApplication::applicationDirPath();
45 if (spathStr
.isEmpty()) spathStr
+= "./";
46 else if (spathStr
[spathStr
.length()-1] != '/' && spathStr
[spathStr
.length()-1] != '\\') spathStr
+= "/";
48 QFile
fl(spathStr
+"packets.log");
49 if (!fl
.open(QIODevice::Append
)) return;
52 if (!pfx
.isEmpty()) st
<< pfx
;
53 if (!str
.isEmpty()) st
<< str
;
57 void ConsoleForm::addPacket (const PsycPacket
&pkt
, bool isOutgoing
) {
58 if (!cbActive
->isChecked()) return;
60 QString
str(pkt
.toString(true)); // raw dump
63 if (isOutgoing
) pfx
= "<<< OUTGOING >>>\n"; else pfx
= ">>> INCOMING <<<\n";
66 QTextCursor
cr(tbLog
->textCursor());
67 cr
.movePosition(QTextCursor::End
, QTextCursor::MoveAnchor
);
69 //tbLog->moveCursor(QTextCursor::End);
70 QString
s(K8Str::escapeStr(str
, true));
71 s
.replace("\n", "<br />\n");
72 //quint64 cursorPosition = tbLog->textCursor().position();
73 if (!isOutgoing
) cr
.insertHtml("<font color='#00ff00'>"+s
+"</font>");
74 else cr
.insertHtml(s
);
75 cr
.insertHtml("\n<hr>\n");
77 //tbLog->moveCursor(QTextCursor::End);
78 tbLog
->verticalScrollBar()->setValue(tbLog
->verticalScrollBar()->maximum());
79 //tbLog->verticalScrollBar()->setEnabled(true);