1 /*
2 * %kadu copyright begin%
3 * Copyright 2013, 2014 Bartosz Brachaczek (b.brachaczek@gmail.com)
4 * Copyright 2011, 2012, 2013, 2014 Rafał Przemysław Malinowski (rafal.przemyslaw.malinowski@gmail.com)
5 * %kadu copyright end%
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; either version 2 of
10 * the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21 #include "QtGui/QTextFrame"
22 #include "QtWidgets/QTextEdit"
23 #include "QtWidgets/QVBoxLayout"
24
25 #include "services/jabber-stream-debug-service.h"
26 #include "jabber-protocol.h"
27
28 #include "xml-console.h"
29
XmlConsole(Account account)30 XmlConsole::XmlConsole(Account account) :
31 // using C++ initializers breaks Qt's lupdate
32 WatchedAccount(account),
33 Viewer()
34 {
35 setAttribute(Qt::WA_DeleteOnClose);
36 setWindowTitle(tr("XML Console - %1").arg(WatchedAccount.id()));
37 setWindowRole("kadu-xml-console");
38
39 JabberProtocol *protocol = qobject_cast<JabberProtocol *>(account.protocolHandler());
40 if (protocol)
41 {
42 createGui();
43
44 connect(protocol->streamDebugService(), SIGNAL(incomingStream(QString)), this, SLOT(xmlIncomingSlot(QString)));
45 connect(protocol->streamDebugService(), SIGNAL(outgoingStream(QString)), this, SLOT(xmlOutgoingSlot(QString)));
46 }
47 else
48 deleteLater();
49 }
50
createGui()51 void XmlConsole::createGui()
52 {
53 QVBoxLayout *mainLayout = new QVBoxLayout(this);
54 Viewer = new QTextEdit(this);
55 Viewer->setUndoRedoEnabled(false);
56 Viewer->setReadOnly(true);
57 Viewer->setAcceptRichText(false);
58 Viewer->viewport()->setObjectName("XmlViewport");
59 // context menu shouldn't inherit it
60 Viewer->viewport()->setStyleSheet("#XmlViewport { background-color: black; }");
61
62 mainLayout->addWidget(Viewer);
63
64 resize(560, 400);
65 }
66
xmlIncomingSlot(const QString & str)67 void XmlConsole::xmlIncomingSlot(const QString &str)
68 {
69 Viewer->setTextColor(Qt::yellow);
70 Viewer->append(str + '\n');
71 }
72
xmlOutgoingSlot(const QString & str)73 void XmlConsole::xmlOutgoingSlot(const QString &str)
74 {
75 Viewer->setTextColor(Qt::red);
76 Viewer->append(str + '\n');
77 }
78
79 #include "moc_xml-console.cpp"
80