summaryrefslogtreecommitdiff
path: root/src/analyzer/networkanalyzer.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/analyzer/networkanalyzer.cpp')
-rw-r--r--src/analyzer/networkanalyzer.cpp102
1 files changed, 52 insertions, 50 deletions
diff --git a/src/analyzer/networkanalyzer.cpp b/src/analyzer/networkanalyzer.cpp
index 752543d9..a3675dfa 100644
--- a/src/analyzer/networkanalyzer.cpp
+++ b/src/analyzer/networkanalyzer.cpp
@@ -46,29 +46,29 @@
#include <QClipboard>
NetworkAnalyzer::NetworkAnalyzer(QWidget *parent)
- : QWidget(parent)
- , _mapper(new QSignalMapper(this))
- , _requestList(new QTreeWidget(this))
+ : QWidget(parent)
+ , _mapper(new QSignalMapper(this))
+ , _requestList(new QTreeWidget(this))
{
QStringList headers;
headers << i18n("Method") << i18n("URL") << i18n("Response") << i18n("Length") << i18n("Content Type") << i18n("Info");
- _requestList->setHeaderLabels( headers );
-
+ _requestList->setHeaderLabels(headers);
+
_requestList->header()->setResizeMode(0, QHeaderView::Interactive);
_requestList->header()->setResizeMode(1, QHeaderView::Interactive);
_requestList->header()->setResizeMode(2, QHeaderView::Interactive);
_requestList->header()->setResizeMode(3, QHeaderView::Interactive);
_requestList->header()->setResizeMode(4, QHeaderView::Interactive);
-
+
_requestList->setAlternatingRowColors(true);
-
+
QVBoxLayout *lay = new QVBoxLayout(this);
- lay->addWidget( _requestList );
+ lay->addWidget(_requestList);
_requestList->setContextMenuPolicy(Qt::CustomContextMenu);
- connect( _mapper, SIGNAL(mapped(QObject *)), this, SLOT(requestFinished(QObject *)) );
- connect( _requestList, SIGNAL(itemDoubleClicked( QTreeWidgetItem*, int ) ), this, SLOT( showItemDetails( QTreeWidgetItem *) ) );
- connect( _requestList, SIGNAL(customContextMenuRequested(QPoint) ), this, SLOT( popupContextMenu(QPoint)));
+ connect(_mapper, SIGNAL(mapped(QObject *)), this, SLOT(requestFinished(QObject *)));
+ connect(_requestList, SIGNAL(itemDoubleClicked(QTreeWidgetItem*, int)), this, SLOT(showItemDetails(QTreeWidgetItem *)));
+ connect(_requestList, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(popupContextMenu(QPoint)));
}
@@ -78,12 +78,12 @@ NetworkAnalyzer::~NetworkAnalyzer()
void NetworkAnalyzer::popupContextMenu(const QPoint& pos)
{
- if(_requestList->topLevelItemCount() >= 1)
+ if (_requestList->topLevelItemCount() >= 1)
{
KMenu menu(_requestList);
KAction *copy;
- copy = new KAction(KIcon("edit-copy"),i18n("Copy URL"), this);
- connect(copy,SIGNAL(triggered(bool)),this,SLOT(copyURL()));
+ copy = new KAction(KIcon("edit-copy"), i18n("Copy URL"), this);
+ connect(copy, SIGNAL(triggered(bool)), this, SLOT(copyURL()));
menu.addAction(copy);
menu.exec(mapToGlobal(pos));
}
@@ -95,11 +95,11 @@ void NetworkAnalyzer::copyURL()
clipboard->setText(_requestList->currentItem()->text(1));
}
-void NetworkAnalyzer::addRequest( QNetworkAccessManager::Operation op, const QNetworkRequest &req, QNetworkReply *reply )
+void NetworkAnalyzer::addRequest(QNetworkAccessManager::Operation op, const QNetworkRequest &req, QNetworkReply *reply)
{
// Add to list of requests
QStringList cols;
- switch( op )
+ switch (op)
{
case QNetworkAccessManager::HeadOperation:
cols << QL1S("HEAD");
@@ -126,16 +126,16 @@ void NetworkAnalyzer::addRequest( QNetworkAccessManager::Operation op, const QNe
cols << req.url().toString();
cols << i18n("Pending");
- QTreeWidgetItem *item = new QTreeWidgetItem( cols );
- _requestList->addTopLevelItem( item );
+ QTreeWidgetItem *item = new QTreeWidgetItem(cols);
+ _requestList->addTopLevelItem(item);
// Add to maps
- _requestMap.insert( reply, req );
- _itemMap.insert( reply, item );
- _itemRequestMap.insert( item, req );
+ _requestMap.insert(reply, req);
+ _itemMap.insert(reply, item);
+ _itemRequestMap.insert(item, req);
- _mapper->setMapping( reply, reply );
- connect( reply, SIGNAL( finished() ), _mapper, SLOT( map() ) );
+ _mapper->setMapping(reply, reply);
+ connect(reply, SIGNAL(finished()), _mapper, SLOT(map()));
_requestList->header()->resizeSections(QHeaderView::ResizeToContents);
}
@@ -151,10 +151,11 @@ void NetworkAnalyzer::clear()
}
-void NetworkAnalyzer::requestFinished( QObject *replyObject )
+void NetworkAnalyzer::requestFinished(QObject *replyObject)
{
- QNetworkReply *reply = qobject_cast<QNetworkReply *>( replyObject );
- if ( !reply ) {
+ QNetworkReply *reply = qobject_cast<QNetworkReply *>(replyObject);
+ if (!reply)
+ {
kDebug() << "Failed to downcast reply";
return;
}
@@ -163,68 +164,69 @@ void NetworkAnalyzer::requestFinished( QObject *replyObject )
// Record the reply headers
QList<QByteArray> headerValues;
- foreach(const QByteArray &header, reply->rawHeaderList() )
+ foreach(const QByteArray &header, reply->rawHeaderList())
{
- headerValues += reply->rawHeader( header );
+ headerValues += reply->rawHeader(header);
}
-
+
QPair< QList<QByteArray>, QList<QByteArray> > replyHeaders;
replyHeaders.first = reply->rawHeaderList();
replyHeaders.second = headerValues;
_itemReplyMap[item] = replyHeaders;
// Display the request
- int status = reply->attribute( QNetworkRequest::HttpStatusCodeAttribute ).toInt();
- QString reason = reply->attribute( QNetworkRequest::HttpReasonPhraseAttribute ).toString();
- item->setText( 2, i18n("%1 %2", status, reason) );
+ int status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
+ QString reason = reply->attribute(QNetworkRequest::HttpReasonPhraseAttribute).toString();
+ item->setText(2, i18n("%1 %2", status, reason));
- QString length = reply->header( QNetworkRequest::ContentLengthHeader ).toString();
- item->setText( 3, length );
+ QString length = reply->header(QNetworkRequest::ContentLengthHeader).toString();
+ item->setText(3, length);
- QString contentType = reply->header( QNetworkRequest::ContentTypeHeader ).toString();
- item->setText( 4, contentType );
+ QString contentType = reply->header(QNetworkRequest::ContentTypeHeader).toString();
+ item->setText(4, contentType);
- if ( status == 302 ) {
- QUrl target = reply->attribute( QNetworkRequest::RedirectionTargetAttribute ).toUrl();
- item->setText( 5, i18n("Redirect: %1", target.toString() ) );
+ if (status == 302)
+ {
+ QUrl target = reply->attribute(QNetworkRequest::RedirectionTargetAttribute).toUrl();
+ item->setText(5, i18n("Redirect: %1", target.toString()));
}
}
-void NetworkAnalyzer::showItemDetails( QTreeWidgetItem *item )
+void NetworkAnalyzer::showItemDetails(QTreeWidgetItem *item)
{
// Show request details
QString details;
-
+
QNetworkRequest req = _itemRequestMap[item];
details += i18n("<h3>Request Details</h3>");
details += QL1S("<ul>");
- foreach(const QByteArray &header, req.rawHeaderList() )
+ foreach(const QByteArray &header, req.rawHeaderList())
{
details += QL1S("<li>");
- details += QL1S( header );
+ details += QL1S(header);
details += QL1S(": ");
- details += QL1S( req.rawHeader( header ) );
+ details += QL1S(req.rawHeader(header));
details += QL1S("</li>");
}
details += QL1S("</ul>");
-
+
QPair< QList<QByteArray>, QList<QByteArray> > replyHeaders = _itemReplyMap[item];
details += i18n("<h3>Response Details</h3>");
details += QL1S("<ul>");
- for ( int i = 0; i < replyHeaders.first.count(); i++ )
+ for (int i = 0; i < replyHeaders.first.count(); i++)
{
details += QL1S("<li>");
- details += QL1S( replyHeaders.first[i] );
+ details += QL1S(replyHeaders.first[i]);
details += QL1S(": ");
- details += QL1S( replyHeaders.second[i] );
+ details += QL1S(replyHeaders.second[i]);
details += QL1S("</li>");
}
details += QL1S("</ul>");
-
+
// QLabel *label = new QLabel(details, this);
// KPassivePopup *popup = new KPassivePopup(this);
// popup->setView(label);
// popup->show(_requestList->mapToGlobal(_requestList->pos()));
- KPassivePopup::message(details,this);
+ KPassivePopup::message(details, this);
}