Skip to content

Commit 17b6ef7

Browse files
authored
XMPP Console (#902)
* xmlconsole.ui add tooltips * xmlconsole.ui rename title to XMPP Console * xmlconsole.ui disable ck_sm (asks) by default: it's too many of them * xmlconsole.ui remove black background * xmlconsole.ui use frame color to distinguish in/out messages * xmlconsole.ui: addRecord() use early return * xmlconsole.ui: addRecord() extract vars for readability
1 parent 55ffff5 commit 17b6ef7

File tree

5 files changed

+49
-29
lines changed

5 files changed

+49
-29
lines changed

src/contactlistaccountmenu.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ class ContactListAccountMenu::Private : public QObject {
122122
privacyListsAction_ = new IconAction(tr("Privacy Lists"), this, "psi/eye");
123123
connect(privacyListsAction_, SIGNAL(triggered()), SLOT(privacyLists()));
124124

125-
xmlConsoleAction_ = new IconAction(tr("&XML Console"), this, "psi/xml");
125+
xmlConsoleAction_ = new IconAction(tr("&XMPP Console"), this, "psi/xml");
126126
connect(xmlConsoleAction_, SIGNAL(triggered()), SLOT(xmlConsole()));
127127

128128
modifyAccountAction_ = new IconAction(tr("&Modify Account..."), this, "psi/account");

src/psiactionlist.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ void PsiActionList::Private::createMainWin()
244244
if (!PsiOptions::instance()->getOption("options.ui.contactlist.lockdown-roster").toBool())
245245
add_act = new MAction(IconsetFactory::icon("psi/addContact"), tr("&Add a Contact"), 0, psi, this);
246246

247-
IconAction *lw_act = new MAction(IconsetFactory::icon("psi/xml"), tr("&XML Console"), 2, psi, this);
247+
IconAction *lw_act = new MAction(IconsetFactory::icon("psi/xml"), tr("&XMPP Console"), 2, psi, this);
248248

249249
IconAction *actDisco = nullptr;
250250
if (!PsiOptions::instance()->getOption("options.ui.contactlist.disable-service-discovery").toBool())

src/psiiconset.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ struct ClientIconCheck {
5959
*
6060
* To discover the client do next:
6161
* 1. Find any alive contact using interested you client
62-
* 2. Open xml console, and insert the current JID together with current online resource into the filter line
62+
* 2. Open XMPP Console and insert the current JID together with its current online resource into the filter line
6363
* 3. Press Dump Ringbuf to see some stanzas.
6464
* 4. Find <presence....> stanza and remember "ver" attribute from <c> element
6565
* 5. Open caps.xml file (~/.cache/psi/caps.xml, "C:/Users/<USER>/AppData/Local/psi/cache") and search for

src/xmlconsole.cpp

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,6 @@ XmlConsole::XmlConsole(PsiAccount *_pa) : QWidget()
5757
ui_.te->setReadOnly(true);
5858
ui_.te->setAcceptRichText(false);
5959

60-
QTextFrameFormat f = ui_.te->document()->rootFrame()->frameFormat();
61-
f.setBackground(QBrush(Qt::black));
62-
ui_.te->document()->rootFrame()->setFrameFormat(f);
63-
6460
connect(ui_.pb_clear, SIGNAL(clicked()), SLOT(clear()));
6561
connect(ui_.pb_input, SIGNAL(clicked()), SLOT(insertXml()));
6662
connect(ui_.pb_close, SIGNAL(clicked()), SLOT(close()));
@@ -74,17 +70,14 @@ XmlConsole::~XmlConsole() { pa->dialogUnregister(this); }
7470
void XmlConsole::clear()
7571
{
7672
ui_.te->clear();
77-
QTextFrameFormat f = ui_.te->document()->rootFrame()->frameFormat();
78-
f.setBackground(QBrush(Qt::black));
79-
ui_.te->document()->rootFrame()->setFrameFormat(f);
8073
}
8174

8275
void XmlConsole::updateCaption()
8376
{
8477
if (pa->psi()->contactList()->enabledAccounts().count() > 1)
85-
setWindowTitle(pa->name() + ": " + tr("XML Console"));
78+
setWindowTitle(pa->name() + ": " + tr("XMPP Console"));
8679
else
87-
setWindowTitle(tr("XML Console"));
80+
setWindowTitle(tr("XMPP Console"));
8881
}
8982

9083
void XmlConsole::enable() { ui_.ck_enable->setChecked(true); }
@@ -135,23 +128,38 @@ void XmlConsole::dumpRingbuf()
135128
ui_.ck_enable->setChecked(enablesave);
136129
}
137130

131+
static const QTextFrameFormat frameFormatIncoming = [] {
132+
QTextFrameFormat f;
133+
f.setBackground(QColorConstants::Svg::lemonchiffon);
134+
return f;
135+
}();
136+
137+
static const QTextFrameFormat frameFormatOutcoming = [] {
138+
QTextFrameFormat f;
139+
f.setBackground(QColorConstants::Svg::lightpink);
140+
return f;
141+
}();
142+
143+
138144
void XmlConsole::addRecord(bool incoming, const QString &str)
139145
{
140-
if (!filtered(str)) {
141-
int prevSPos = ui_.te->verticalScrollBar()->value();
142-
bool atBottom = (prevSPos == ui_.te->verticalScrollBar()->maximum());
143-
QTextCursor prevCur = ui_.te->textCursor();
144-
145-
ui_.te->moveCursor(QTextCursor::End);
146-
ui_.te->setTextColor(incoming ? Qt::yellow : Qt::red);
147-
ui_.te->insertPlainText(str + '\n');
148-
149-
if (!atBottom) {
150-
ui_.te->setTextCursor(prevCur);
151-
ui_.te->verticalScrollBar()->setValue(prevSPos);
152-
} else {
153-
ui_.te->verticalScrollBar()->setValue(ui_.te->verticalScrollBar()->maximum());
154-
}
146+
if (filtered(str))
147+
return;
148+
auto *textEdit = ui_.te;
149+
auto *scrollBar = textEdit->verticalScrollBar();
150+
int prevSPos = scrollBar->value();
151+
bool wasAtBottom = (prevSPos == scrollBar->maximum());
152+
auto prevCur = textEdit->textCursor();
153+
154+
textEdit->moveCursor(QTextCursor::End);
155+
textEdit->textCursor().insertFrame(incoming ? frameFormatIncoming : frameFormatOutcoming);
156+
textEdit->insertPlainText(str);
157+
158+
if (!wasAtBottom) {
159+
textEdit->setTextCursor(prevCur);
160+
scrollBar->setValue(prevSPos);
161+
} else {
162+
scrollBar->setValue(scrollBar->maximum());
155163
}
156164
}
157165

src/xmlconsole.ui

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
</rect>
1212
</property>
1313
<property name="windowTitle">
14-
<string>XML Console</string>
14+
<string>XMPP Console</string>
1515
</property>
1616
<layout class="QVBoxLayout">
1717
<property name="margin" >
@@ -37,6 +37,9 @@
3737
</property>
3838
<item>
3939
<widget class="QCheckBox" name="ck_message">
40+
<property name="toolTip">
41+
<string>&lt;message&gt; stanza used to send information to other XMPP entities without requiring a response.</string>
42+
</property>
4043
<property name="text">
4144
<string>Message</string>
4245
</property>
@@ -47,6 +50,9 @@
4750
</item>
4851
<item>
4952
<widget class="QCheckBox" name="ck_presence">
53+
<property name="toolTip">
54+
<string>&lt;presence&gt; stanza used for status of other clients and components. It's a multi-cast so extensions use it to broadcast own things to contacts, such as capabilities, music choice, or location.</string>
55+
</property>
5056
<property name="text">
5157
<string>Presence</string>
5258
</property>
@@ -57,6 +63,9 @@
5763
</item>
5864
<item>
5965
<widget class="QCheckBox" name="ck_iq">
66+
<property name="toolTip">
67+
<string>&lt;iq&gt; (info/query) stanza used for requesting and modifying information.</string>
68+
</property>
6069
<property name="text">
6170
<string>IQ</string>
6271
</property>
@@ -67,11 +76,14 @@
6776
</item>
6877
<item>
6978
<widget class="QCheckBox" name="ck_sm">
79+
<property name="toolTip">
80+
<string>&lt;a&gt; (ack) and &lt;r&gt; (request ack) stanzas used to acknowledge successful receipt of a stanza.</string>
81+
</property>
7082
<property name="text">
7183
<string>SM</string>
7284
</property>
7385
<property name="checked">
74-
<bool>true</bool>
86+
<bool>false</bool>
7587
</property>
7688
</widget>
7789
</item>

0 commit comments

Comments
 (0)