| 1 | /*
|
|---|
| 2 | * xmlconsole.cpp - dialog for interacting manually with Jabber
|
|---|
| 3 | * Copyright (C) 2001, 2002 Justin Karneges
|
|---|
| 4 | *
|
|---|
| 5 | * This program is free software; you can redistribute it and/or
|
|---|
| 6 | * modify it under the terms of the GNU General Public License
|
|---|
| 7 | * as published by the Free Software Foundation; either version 2
|
|---|
| 8 | * of the License, or (at your option) any later version.
|
|---|
| 9 | *
|
|---|
| 10 | * This program is distributed in the hope that it will be useful,
|
|---|
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|---|
| 13 | * GNU General Public License for more details.
|
|---|
| 14 | *
|
|---|
| 15 | * You should have received a copy of the GNU General Public License
|
|---|
| 16 | * along with this library; if not, write to the Free Software
|
|---|
| 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|---|
| 18 | *
|
|---|
| 19 | */
|
|---|
| 20 |
|
|---|
| 21 | #include"xmlconsole.h"
|
|---|
| 22 |
|
|---|
| 23 | #include<qlayout.h>
|
|---|
| 24 | #include<qpushbutton.h>
|
|---|
| 25 | #include<qcheckbox.h>
|
|---|
| 26 | #include<qtextedit.h>
|
|---|
| 27 | #include"common.h"
|
|---|
| 28 | #include"psiaccount.h"
|
|---|
| 29 | #include"im.h"
|
|---|
| 30 |
|
|---|
| 31 |
|
|---|
| 32 | //----------------------------------------------------------------------------
|
|---|
| 33 | // XmlConsole
|
|---|
| 34 | //----------------------------------------------------------------------------
|
|---|
| 35 | XmlConsole::XmlConsole(PsiAccount *_pa, QWidget *parent, const char *name)
|
|---|
| 36 | :QWidget(parent, name)
|
|---|
| 37 | {
|
|---|
| 38 | pa = _pa;
|
|---|
| 39 | pa->dialogRegister(this);
|
|---|
| 40 | connect(pa, SIGNAL(updatedAccount()), SLOT(updateCaption()));
|
|---|
| 41 | connect(pa->client(), SIGNAL(xmlIncoming(const QString &)), SLOT(client_xmlIncoming(const QString &)));
|
|---|
| 42 | connect(pa->client(), SIGNAL(xmlOutgoing(const QString &)), SLOT(client_xmlOutgoing(const QString &)));
|
|---|
| 43 | updateCaption();
|
|---|
| 44 |
|
|---|
| 45 | QVBoxLayout *vb1 = new QVBoxLayout(this, 8);
|
|---|
| 46 |
|
|---|
| 47 | prompt = 0;
|
|---|
| 48 |
|
|---|
| 49 | te = new QTextEdit(this);
|
|---|
| 50 | te->setUndoRedoEnabled(false);
|
|---|
| 51 | te->setReadOnly(true);
|
|---|
| 52 | te->setTextFormat(PlainText);
|
|---|
| 53 |
|
|---|
| 54 | te->setPaper(QBrush(Qt::black));
|
|---|
| 55 | vb1->addWidget(te);
|
|---|
| 56 |
|
|---|
| 57 | QHBoxLayout *hb1 = new QHBoxLayout(vb1);
|
|---|
| 58 | ck_enable = new QCheckBox(tr("Enable"), this);
|
|---|
| 59 | hb1->addWidget(ck_enable);
|
|---|
| 60 | hb1->addStretch(1);
|
|---|
| 61 |
|
|---|
| 62 | QPushButton *pb;
|
|---|
| 63 | pb = new QPushButton(tr("Clear"), this);
|
|---|
| 64 | pb->setMinimumWidth(80);
|
|---|
| 65 | connect(pb, SIGNAL(clicked()), te, SLOT(clear()));
|
|---|
| 66 | hb1->addWidget(pb);
|
|---|
| 67 |
|
|---|
| 68 | pb = new QPushButton(tr("&XML Input..."), this);
|
|---|
| 69 | pb->setMinimumWidth(80);
|
|---|
| 70 | connect(pb, SIGNAL(clicked()), SLOT(insertXml()));
|
|---|
| 71 | hb1->addWidget(pb);
|
|---|
| 72 |
|
|---|
| 73 | pb = new QPushButton(tr("&Close"), this);
|
|---|
| 74 | pb->setMinimumWidth(80);
|
|---|
| 75 | connect(pb, SIGNAL(clicked()), SLOT(close()));
|
|---|
| 76 | hb1->addWidget(pb);
|
|---|
| 77 |
|
|---|
| 78 | resize(560,400);
|
|---|
| 79 | }
|
|---|
| 80 |
|
|---|
| 81 | XmlConsole::~XmlConsole()
|
|---|
| 82 | {
|
|---|
| 83 | pa->dialogUnregister(this);
|
|---|
| 84 | }
|
|---|
| 85 |
|
|---|
| 86 | void XmlConsole::updateCaption()
|
|---|
| 87 | {
|
|---|
| 88 | setCaption(pa->name() + ": " + tr("XML Console"));
|
|---|
| 89 | }
|
|---|
| 90 |
|
|---|
| 91 | void XmlConsole::enable()
|
|---|
| 92 | {
|
|---|
| 93 | ck_enable->setChecked(true);
|
|---|
| 94 | }
|
|---|
| 95 |
|
|---|
| 96 | void XmlConsole::client_xmlIncoming(const QString &str)
|
|---|
| 97 | {
|
|---|
| 98 | if(ck_enable->isChecked()) {
|
|---|
| 99 | te->setColor(Qt::yellow);
|
|---|
| 100 | te->append(str + '\n');
|
|---|
| 101 | }
|
|---|
| 102 | }
|
|---|
| 103 |
|
|---|
| 104 | void XmlConsole::client_xmlOutgoing(const QString &str)
|
|---|
| 105 | {
|
|---|
| 106 | if(ck_enable->isChecked()) {
|
|---|
| 107 | te->setColor(Qt::red);
|
|---|
| 108 | te->append(str + '\n');
|
|---|
| 109 | }
|
|---|
| 110 | }
|
|---|
| 111 |
|
|---|
| 112 | void XmlConsole::insertXml()
|
|---|
| 113 | {
|
|---|
| 114 | if(prompt)
|
|---|
| 115 | bringToFront(prompt);
|
|---|
| 116 | else {
|
|---|
| 117 | prompt = new XmlPrompt(this);
|
|---|
| 118 | connect(prompt, SIGNAL(textReady(const QString &)), SLOT(xml_textReady(const QString &)));
|
|---|
| 119 | prompt->show();
|
|---|
| 120 | }
|
|---|
| 121 | }
|
|---|
| 122 |
|
|---|
| 123 | void XmlConsole::xml_textReady(const QString &str)
|
|---|
| 124 | {
|
|---|
| 125 | pa->client()->send(str);
|
|---|
| 126 | }
|
|---|
| 127 |
|
|---|
| 128 |
|
|---|
| 129 | //----------------------------------------------------------------------------
|
|---|
| 130 | // XmlPrompt
|
|---|
| 131 | //----------------------------------------------------------------------------
|
|---|
| 132 | XmlPrompt::XmlPrompt(QWidget *parent, const char *name)
|
|---|
| 133 | :QDialog(parent, name, false, WDestructiveClose)
|
|---|
| 134 | {
|
|---|
| 135 | setCaption(tr("XML Input"));
|
|---|
| 136 |
|
|---|
| 137 | QVBoxLayout *vb1 = new QVBoxLayout(this, 8);
|
|---|
| 138 |
|
|---|
| 139 | te = new QTextEdit(this);
|
|---|
| 140 | vb1->addWidget(te);
|
|---|
| 141 |
|
|---|
| 142 | QHBoxLayout *hb1 = new QHBoxLayout(vb1);
|
|---|
| 143 | QPushButton *pb;
|
|---|
| 144 |
|
|---|
| 145 | pb = new QPushButton(tr("&Transmit"), this);
|
|---|
| 146 | pb->setDefault(TRUE);
|
|---|
| 147 | connect(pb, SIGNAL(clicked()), SLOT(doTransmit()));
|
|---|
| 148 | hb1->addWidget(pb);
|
|---|
| 149 | hb1->addStretch(1);
|
|---|
| 150 |
|
|---|
| 151 | pb = new QPushButton(tr("&Close"), this);
|
|---|
| 152 | connect(pb, SIGNAL(clicked()), SLOT(close()));
|
|---|
| 153 | hb1->addWidget(pb);
|
|---|
| 154 |
|
|---|
| 155 | resize(320,240);
|
|---|
| 156 | }
|
|---|
| 157 |
|
|---|
| 158 | XmlPrompt::~XmlPrompt()
|
|---|
| 159 | {
|
|---|
| 160 | }
|
|---|
| 161 |
|
|---|
| 162 | void XmlPrompt::doTransmit()
|
|---|
| 163 | {
|
|---|
| 164 | QString str = te->text();
|
|---|
| 165 | textReady(str);
|
|---|
| 166 | close();
|
|---|
| 167 | }
|
|---|
| 168 |
|
|---|