Permalink
Browse files

sort && filter

  • Loading branch information...
iptton committed Apr 18, 2012
1 parent b859931 commit 4a59d51cd8d0343cefd3562e54783f6d2d4622f7
View
@@ -16,7 +16,6 @@ SOURCES += main.cpp\
rytablemodel.cpp \
qnetworkproxyfactoryexendforpac.cpp \
composer.cpp \
- rypipetableview.cpp\
waterfallwindow.cpp \
rule/ryruleproject.cpp \
rule/ryrule.cpp \
@@ -36,15 +35,16 @@ SOURCES += main.cpp\
quazip/quacrc32.cpp \
quazip/quaadler32.cpp \
quazip/qioapi.cpp \
- quazip/JlCompress.cpp
+ quazip/JlCompress.cpp \
+ savesessionsdialog.cpp \
+ rytablesortfilterproxymodel.cpp
mac:SOURCES -= qiwinhttp.cpp
HEADERS += mainwindow.h \
rytablemodel.h \
qnetworkproxyfactoryexendforpac.h \
composer.h \
- rypipetableview.h \
waterfallwindow.h \
rule/ryruleproject.h \
rule/ryrule.h \
@@ -69,7 +69,9 @@ HEADERS += mainwindow.h \
quazip/JlCompress.h \
quazip/ioapi.h \
quazip/crypt.h \
- rymimedata.h
+ rymimedata.h \
+ savesessionsdialog.h \
+ rytablesortfilterproxymodel.h
win32:HEADERS += zlib/zutil.h \
zlib/zlib.h \
zlib/zconf.h \
@@ -88,7 +90,8 @@ mac:SOURCES -= proxy/rywinhttp.cpp
FORMS += mainwindow.ui \
composer.ui \
- waterfallwindow.ui
+ waterfallwindow.ui \
+ savesessionsdialog.ui
mac:CONFIG += app_bundle
View
@@ -181,7 +181,7 @@ void Composer::setupProxy(QString host,qint16 port){
void Composer::dragEnterEvent(QDragEnterEvent *event){
- qDebug()<<"drag enter";
+ //qDebug()<<"drag enter";
if (event->mimeData()->hasText()) {
if (event->source() == this) {
event->setDropAction(Qt::MoveAction);
@@ -196,15 +196,15 @@ void Composer::dragEnterEvent(QDragEnterEvent *event){
}
void Composer::dropEvent(QDropEvent *event){
- qDebug()<<"drop";
+ //qDebug()<<"drop";
const RyMimeData* mime = dynamic_cast<const RyMimeData*>(event->mimeData());
if (mime) {
RyPipeData_ptr d = mime->pipeData();
this->ui->server->setText(d->host);
this->ui->port->setText(QString::number(d->port));
this->ui->request->setPlainText(QString(d->requestHeaderRawData()).append("\r\n\r\n").append(d->requestBodyRawData()));
- qDebug()<<"drop text="<<mime->text();
+ //qDebug()<<"drop text="<<mime->text();
event->acceptProposedAction();
} else {
event->ignore();
View
@@ -40,6 +40,7 @@
#include <quazip/quazip.h>
#include <quazip/quazipfile.h>
+#include "rytablesortfilterproxymodel.h"
QByteArray gzipDecompress(QByteArray data){
if (data.size() <= 4) {
@@ -165,16 +166,22 @@ QString RyJsBridge::getConfigs(){
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
- pipeTableModel(new RyTableModel()),
ui(new Ui::MainWindow),
- isUsingCapture(false)
+ _isUsingCapture(false)
#ifdef Q_OS_WIN
,proxySetting("\\HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\",QSettings::NativeFormat)
#endif
{
ui->setupUi(this);
- ui->tableView->setModel(&pipeTableModel);
+
+ pipeTableModel = new RyTableModel(this);
+ sortFilterProxyModel = new RyTableSortFilterProxyModel(this);
+
+ ui->tableView->setSortingEnabled(true);
+ ui->tableView->setModel(sortFilterProxyModel);
+ sortFilterProxyModel->setDynamicSortFilter(true);
+ sortFilterProxyModel->setSourceModel(pipeTableModel);
ui->tableView->setSelectionBehavior(QAbstractItemView::SelectRows);
ui->tableView->setColumnWidth(0,30);
ui->tableView->setColumnWidth(1,30);
@@ -183,9 +190,9 @@ MainWindow::MainWindow(QWidget *parent) :
ui->tableView->setColumnWidth(7,50);
ui->tableView->verticalHeader()->setDefaultSectionSize(20);
ui->tableView->verticalHeader()->hide();
- //ui->tableView->setSortingEnabled(true);
- jsBridge = new RyJsBridge();
+
+ _jsBridge = new RyJsBridge();
QWebSettings::globalSettings()->setAttribute(QWebSettings::DeveloperExtrasEnabled, true);
addJsObject();
connect(ui->webView->page()->mainFrame(),SIGNAL(javaScriptWindowObjectCleared()),SLOT(addJsObject()));
@@ -198,31 +205,38 @@ MainWindow::MainWindow(QWidget *parent) :
8889);
- itemSelectModel = ui->tableView->selectionModel();
+ _itemSelectModel = ui->tableView->selectionModel();
connect(ui->tableView,SIGNAL(doubleClicked(QModelIndex)),SLOT(onItemDoubleClicked(QModelIndex)));
- connect(itemSelectModel,SIGNAL(currentChanged(QModelIndex,QModelIndex)),SLOT(onSelectionChange(QModelIndex)));
+ connect(_itemSelectModel,SIGNAL(currentChanged(QModelIndex,QModelIndex)),SLOT(onSelectionChange(QModelIndex)));
//ui->tableView->setItemDelegate();
createMenus();
//toggleCapture();
connect(ui->ActionCapture,SIGNAL(triggered()),SLOT(toggleCapture()));
- connect(ui->actionRemoveAll,SIGNAL(triggered()),&pipeTableModel,SLOT(removeAllItem()));
+ connect(ui->actionRemoveAll,SIGNAL(triggered()),this,SLOT(onActionRemoveAll()));
connect(ui->actionWaterfall, SIGNAL(triggered()), this, SLOT(onWaterfallActionTriggered()));
}
MainWindow::~MainWindow()
{
RyProxyServer* server = RyProxyServer::instance();
server->close();
- delete jsBridge;
+ delete _jsBridge;
delete ui;
}
void MainWindow::createMenus(){
- fileMenu = menuBar()->addMenu(tr("&File"));
- QAction *importSessions = fileMenu->addAction(tr("&import session..."));
- connect(importSessions,SIGNAL(triggered()),SLOT(importSessions()));
+ _fileMenu = menuBar()->addMenu(tr("&File"));
+ _importSessions = _fileMenu->addAction(tr("&import session..."));
+ _filterNoImagesAct = _fileMenu->addAction(tr("hide image requests"));
+ _filterNoImagesAct->setCheckable(true);
+ _filterNo304sAct = _fileMenu->addAction(tr("hide 304s"));
+ _filterNo304sAct->setCheckable(true);
+ _filterShowMatchOnly = _fileMenu->addAction(tr("show matching sessions only"));
+ _filterShowMatchOnly->setCheckable(true);
+
+ connect(_fileMenu,SIGNAL(triggered(QAction*)),SLOT(onAction(QAction*)));
}
void MainWindow::importSessions(){
@@ -285,12 +299,12 @@ void MainWindow::importSessions(){
void MainWindow::onPipeUpdate(RyPipeData_ptr pipeData){
//qDebug()<<"connected";
- pipeTableModel.updateItem(pipeData);
+ pipeTableModel->updateItem(pipeData);
}
void MainWindow::onNewPipe(RyPipeData_ptr pipeData){
//pipeTableModel
- pipeTableModel.addItem(pipeData);
+ pipeTableModel->addItem(pipeData);
}
void MainWindow::onSelectionChange(QModelIndex index){
@@ -301,8 +315,11 @@ void MainWindow::onSelectionChange(QModelIndex index){
void MainWindow::onItemDoubleClicked(QModelIndex topLeft){
//qDebug()<<"onSelectionChange";
- int row = topLeft.row();
- RyPipeData_ptr data = pipeTableModel.getItem(row);
+ RyPipeData_ptr data = sortFilterProxyModel->getItem(topLeft);
+ if(data.isNull()){
+ qDebug()<<QString("isNull %1").arg(topLeft.row());
+ return;
+ }
ui->tollTabs->setCurrentWidget(ui->inspectorTab);
ui->requestInspectorTabs->setCurrentWidget(ui->requestInspectorTextview);
@@ -327,7 +344,7 @@ void MainWindow::onItemDoubleClicked(QModelIndex topLeft){
QByteArray decrypedData =
(data->isResponseChunked()?
data->responseBodyRawDataUnChunked()
- :data->responseBodyRawData());;
+ :data->responseBodyRawData());
if(isEncrypted){
decrypedData = gzipDecompress(decrypedData);
}
@@ -338,7 +355,6 @@ void MainWindow::onItemDoubleClicked(QModelIndex topLeft){
// delete movie;
//}
if(data->getResponseHeader("Content-Type").toLower().indexOf("image")!=-1){
- ui->responseInspectorTabs->setCurrentWidget(ui->responseInspectorImageView);
if(!decrypedData.isEmpty()){
if(data->getResponseHeader("Content-Type").toLower().indexOf("gif")!=-1){
//QBuffer *data = new QBuffer(&decrypedData);
@@ -350,12 +366,17 @@ void MainWindow::onItemDoubleClicked(QModelIndex topLeft){
pixmap.loadFromData(decrypedData);
ui->label->setPixmap(pixmap);
}
+ ui->responseInspectorTabs->setCurrentWidget(ui->responseInspectorImageView);
+ }else{
+ ui->responseInspectorTabs->setCurrentWidget(ui->responseInspectorTextView);
+ ui->label->clear();
}
}else{
ui->label->clear();
ui->responseInspectorTabs->setCurrentWidget(ui->responseInspectorTextView);
}
+
// show in textview
QTextCodec* oldCodec = QTextCodec::codecForCStrings();
QTextCodec::setCodecForCStrings(QTextCodec::codecForName(encoding));
@@ -379,7 +400,7 @@ void MainWindow::onWaterfallActionTriggered(){
QListIterator<QModelIndex> it(list);
while(it.hasNext()){
QModelIndex i = it.next();
- RyPipeData_ptr data = pipeTableModel.getItem(i.row());
+ RyPipeData_ptr data = sortFilterProxyModel->getItem(i);
pipes.append(data);
}
@@ -398,14 +419,14 @@ void MainWindow::onWaterfallActionTriggered(){
void MainWindow::toggleProxy(){
- if(isUsingCapture){
- isUsingCapture = false;
- proxySetting.setValue("ProxyEnable",previousProxyInfo.enable);
- if(previousProxyInfo.enable != 0){
- proxySetting.setValue("ProxyServer",previousProxyInfo.proxyString);
+ if(_isUsingCapture){
+ _isUsingCapture = false;
+ proxySetting.setValue("ProxyEnable",_previousProxyInfo.enable);
+ if(_previousProxyInfo.enable != 0){
+ proxySetting.setValue("ProxyServer",_previousProxyInfo.proxyString);
}
- if( previousProxyInfo.isUsingPac != "0"){
- proxySetting.setValue("AutoConfigURL",previousProxyInfo.isUsingPac);
+ if( _previousProxyInfo.isUsingPac != "0"){
+ proxySetting.setValue("AutoConfigURL",_previousProxyInfo.isUsingPac);
}
/*
@@ -417,21 +438,21 @@ void MainWindow::toggleProxy(){
//}
*/
}else{
- isUsingCapture = true;
- previousProxyInfo.isUsingPac = proxySetting.value("AutoConfigURL","0").toString();
- previousProxyInfo.enable = proxySetting.value("ProxyEnable").toInt();
- previousProxyInfo.proxyString =proxySetting.value("ProxyServer").toString();
+ _isUsingCapture = true;
+ _previousProxyInfo.isUsingPac = proxySetting.value("AutoConfigURL","0").toString();
+ _previousProxyInfo.enable = proxySetting.value("ProxyEnable").toInt();
+ _previousProxyInfo.proxyString =proxySetting.value("ProxyServer").toString();
//qDebug()<<previousProxyInfo.proxyString;
///qDebug()<<previousProxyInfo.isUsingPac;
//http=127.0.0.1:8081;https=127.0.0.1:8081;ftp=127.0.0.1:8081
//initPac(previousProxyInfo.isUsingPac,previousProxyInfo.enable?previousProxyInfo.proxyString:"");
QString proxyServer="127.0.0.1:8889";
- if(previousProxyInfo.enable){
- if(previousProxyInfo.proxyString.indexOf(";")!=-1){
+ if(_previousProxyInfo.enable){
+ if(_previousProxyInfo.proxyString.indexOf(";")!=-1){
proxyServer = QString("http=")+proxyServer;
- QStringList proxies = previousProxyInfo.proxyString.split(";");
+ QStringList proxies = _previousProxyInfo.proxyString.split(";");
for(int i=0;i<proxies.length();++i){
QStringList tmp = proxies[i].split("=");
if(tmp.at(0).toLower()=="http"){
@@ -441,7 +462,7 @@ void MainWindow::toggleProxy(){
}
proxyServer = proxies.join(";");
}else{
- proxyServer = QString("http=%1;ftp=%2;https=%2").arg(proxyServer).arg(previousProxyInfo.proxyString);
+ proxyServer = QString("http=%1;ftp=%2;https=%2").arg(proxyServer).arg(_previousProxyInfo.proxyString);
}
}else{
proxyServer = "http="+proxyServer;
@@ -521,7 +542,7 @@ void MainWindow::toggleCapture(){
void MainWindow::closeEvent(QCloseEvent *event){
- if(isUsingCapture){
+ if(_isUsingCapture){
toggleCapture();
}
QMainWindow::closeEvent(event);
@@ -534,10 +555,38 @@ void MainWindow::contextMenuEvent(QContextMenuEvent *event){
}
void MainWindow::addJsObject(){
- ui->webView->page()->mainFrame()->addToJavaScriptWindowObject(QString("App"),jsBridge);
+ ui->webView->page()->mainFrame()->addToJavaScriptWindowObject(QString("App"),_jsBridge);
}
+void MainWindow::onAction(QAction *action){
+ if(action == _filterNoImagesAct){
+ if(action->isChecked()){
+ sortFilterProxyModel->setFilter(sortFilterProxyModel->filter() | RyTableSortFilterProxyModel::NoImageFilter);
+ }else{
+ sortFilterProxyModel->setFilter(sortFilterProxyModel->filter() & (~RyTableSortFilterProxyModel::NoImageFilter));
+ }
+ }else if(action == _filterNo304sAct){
+ if(action->isChecked()){
+ sortFilterProxyModel->setFilter(sortFilterProxyModel->filter() | RyTableSortFilterProxyModel::No304Filter);
+ }else{
+ sortFilterProxyModel->setFilter(sortFilterProxyModel->filter() & (~RyTableSortFilterProxyModel::No304Filter));
+ }
+ }else if(action == _importSessions){
+ importSessions();
+ }else if(action == _filterShowMatchOnly){
+ if(action->isChecked()){
+ sortFilterProxyModel->setFilter(sortFilterProxyModel->filter() | RyTableSortFilterProxyModel::OnlyMatchingFilter);
+ }else{
+ sortFilterProxyModel->setFilter(sortFilterProxyModel->filter() & (~RyTableSortFilterProxyModel::OnlyMatchingFilter));
+ }
+ }
+}
void MainWindow::on_actionLongCache_triggered(){
RyRuleManager::instance()->toggleLongCache();
}
+
+void MainWindow::onActionRemoveAll(){
+ pipeTableModel->removeAllItem();
+ sortFilterProxyModel->removeAllItem();
+}
Oops, something went wrong.

0 comments on commit 4a59d51

Please sign in to comment.