~ubuntu-branches/ubuntu/jaunty/psi/jaunty

« back to all changes in this revision

Viewing changes to src/logwindow.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jan Niehusmann
  • Date: 2002-04-19 02:28:44 UTC
  • Revision ID: james.westby@ubuntu.com-20020419022844-za7xgai5qyfd9xv6
Tags: upstream-0.8.5
ImportĀ upstreamĀ versionĀ 0.8.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
** logwindow.cpp - a debug window to log colored messages
 
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 program; 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"logwindow.h"
 
22
#include"common.h"
 
23
#include<qlayout.h>
 
24
#include<qpushbutton.h>
 
25
#include<qbuttongroup.h>
 
26
 
 
27
LogWindow::LogWindow(QWidget *parent, const char *name)
 
28
:QWidget(parent, name)
 
29
{
 
30
        setCaption(CAP("Log Window"));
 
31
 
 
32
        QVBoxLayout *vb1 = new QVBoxLayout(this, 8);
 
33
 
 
34
        te = new QTextEdit(this);
 
35
        te->setReadOnly(TRUE);
 
36
        te->setUndoRedoEnabled(FALSE);
 
37
        te->setTextFormat(RichText);
 
38
 
 
39
        te->setPaper(QBrush(Qt::black));
 
40
        vb1->addWidget(te);
 
41
 
 
42
        QHBoxLayout *hb1 = new QHBoxLayout(vb1);
 
43
        QButtonGroup *bg = new QButtonGroup(2, Vertical, "Log debug messages from:", this);
 
44
        db_check[0] = new QCheckBox("JabXml", bg);
 
45
        db_check[1] = new QCheckBox("Jabber", bg);
 
46
        db_check[2] = new QCheckBox("JabCon", bg);
 
47
        db_check[3] = new QCheckBox("MainWin", bg);
 
48
        db_check[4] = new QCheckBox("ContactView", bg);
 
49
        db_check[5] = new QCheckBox("HighLevel", bg);
 
50
        for(int n = 0; n < 6; ++n)
 
51
                db_check[n]->setChecked(FALSE);
 
52
        hb1->addWidget(bg);
 
53
 
 
54
        QVBoxLayout *vb2 = new QVBoxLayout(hb1);
 
55
 
 
56
        QPushButton *pb;
 
57
 
 
58
        pb = new QPushButton("&XML Input...", this);
 
59
        pb->setFixedWidth(100);
 
60
        connect(pb, SIGNAL(clicked()), SLOT(insertXml()));
 
61
        vb2->addWidget(pb);
 
62
 
 
63
        pb = new QPushButton("&Close", this);
 
64
        pb->setFixedWidth(100);
 
65
        connect(pb, SIGNAL(clicked()), SLOT(close()));
 
66
        vb2->addWidget(pb);
 
67
 
 
68
        resize(560,400);
 
69
}
 
70
 
 
71
LogWindow::~LogWindow()
 
72
{
 
73
}
 
74
 
 
75
void LogWindow::insertXml()
 
76
{
 
77
        bool ok;
 
78
 
 
79
        QString text = XmlPrompt::getText(&ok, this);
 
80
        if(ok) {
 
81
                if(debug_jabber)
 
82
                        debug_jabber->insertXml(text);
 
83
        }
 
84
}
 
85
 
 
86
void LogWindow::append(int depth, const QString &str)
 
87
{
 
88
        if(!db_check[depth]->isChecked())
 
89
                return;
 
90
 
 
91
        QColor depth2color[6] = { Qt::yellow, Qt::red, Qt::cyan, Qt::blue, Qt::green, Qt::white };
 
92
 
 
93
        //te->setColor(depth2color[depth]);
 
94
        //te->append(str);
 
95
        te->append(QString("<font color=\"%1\">").arg(depth2color[depth].name()) + plain2rich(str) + "</font>\n");
 
96
        te->scrollToBottom();
 
97
}
 
98
 
 
99
 
 
100
XmlPrompt::XmlPrompt(QWidget *parent, const char *name)
 
101
:QDialog(parent, name, TRUE)
 
102
{
 
103
        setCaption(CAP("Xml Input"));
 
104
 
 
105
        QVBoxLayout *vb1 = new QVBoxLayout(this, 8);
 
106
 
 
107
        te = new QTextEdit(this);
 
108
        vb1->addWidget(te);
 
109
 
 
110
        QHBoxLayout *hb1 = new QHBoxLayout(vb1);
 
111
        QPushButton *pb;
 
112
 
 
113
        pb = new QPushButton("&Transmit", this);
 
114
        pb->setDefault(TRUE);
 
115
        connect(pb, SIGNAL(clicked()), SLOT(accept()));
 
116
        hb1->addWidget(pb);
 
117
        hb1->addStretch(1);
 
118
 
 
119
        pb = new QPushButton("&Close", this);
 
120
        connect(pb, SIGNAL(clicked()), SLOT(close()));
 
121
        hb1->addWidget(pb);
 
122
 
 
123
        resize(320,240);
 
124
}
 
125
 
 
126
QString XmlPrompt::getText(bool *ok, QWidget *parent, const char *name)
 
127
{
 
128
        XmlPrompt *p = new XmlPrompt(parent, name);
 
129
        QString result;
 
130
 
 
131
        if(p->exec() == Accepted) {
 
132
                *ok = TRUE;
 
133
                result = p->te->text();
 
134
        }
 
135
        else
 
136
                *ok = FALSE;
 
137
 
 
138
        delete p;
 
139
        return result;
 
140
}