Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

sort && filter

  • Loading branch information...
commit 4a59d51cd8d0343cefd3562e54783f6d2d4622f7 1 parent b859931
@iptton iptton authored
View
13 Rythem.pro
@@ -16,7 +16,6 @@ SOURCES += main.cpp\
rytablemodel.cpp \
qnetworkproxyfactoryexendforpac.cpp \
composer.cpp \
- rypipetableview.cpp\
waterfallwindow.cpp \
rule/ryruleproject.cpp \
rule/ryrule.cpp \
@@ -36,7 +35,9 @@ 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
@@ -44,7 +45,6 @@ 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
6 composer.cpp
@@ -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,7 +196,7 @@ 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) {
@@ -204,7 +204,7 @@ void Composer::dropEvent(QDropEvent *event){
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
121 mainwindow.cpp
@@ -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,17 +205,17 @@ 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()));
}
@@ -216,13 +223,20 @@ 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,10 +438,10 @@ 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
@@ -428,10 +449,10 @@ void MainWindow::toggleProxy(){
//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();
+}
View
34 mainwindow.h
@@ -15,6 +15,7 @@
#include "rule/ryrulemanager.h"
#include "proxy/ryproxyserver.h"
+
#include <QScriptEngine>
using namespace rule;
@@ -23,6 +24,7 @@ namespace Ui {
class MainWindow;
}
class RyPipeData;
+class RyTableSortFilterProxyModel;
class QItemSelectionModel;
class RyJsBridge:public QObject{
Q_OBJECT
@@ -44,9 +46,6 @@ class MainWindow : public QMainWindow
Q_OBJECT
-private slots:
- void toggleCapture();
- void importSessions();
public:
explicit MainWindow(QWidget *parent=0);
~MainWindow();
@@ -68,21 +67,26 @@ public slots:
QString pacUrl;
QString isUsingPac;
}ProxyInfo;
- RyTableModel pipeTableModel;
+ RyTableModel *pipeTableModel;
+ RyTableSortFilterProxyModel *sortFilterProxyModel;
private:
Ui::MainWindow *ui;
- RyJsBridge *jsBridge;
+ RyJsBridge *_jsBridge;
void createMenus();
- RyProxyServer *server;
-
- bool isUsingCapture;
- ProxyInfo previousProxyInfo;
- QMenu *fileMenu;
- QMenu *toolMenu;
- QAction *captureAct;
- QItemSelectionModel *itemSelectModel;
+ RyProxyServer *_server;
+
+ bool _isUsingCapture;
+ ProxyInfo _previousProxyInfo;
+ QMenu *_fileMenu;
+ QMenu *_filterMenu;
+ QAction *_importSessions;
+ QAction *_filterNoImagesAct;
+ QAction *_filterNo304sAct;
+ QAction *_filterShowMatchOnly;
+ QAction *_captureAct;
+ QItemSelectionModel *_itemSelectModel;
protected:
void closeEvent(QCloseEvent *event);
void contextMenuEvent(QContextMenuEvent *event);
@@ -90,7 +94,11 @@ public slots:
private slots:
void addJsObject();
+ void onAction(QAction*);
void on_actionLongCache_triggered();
+ void toggleCapture();
+ void importSessions();
+ void onActionRemoveAll();
};
#endif // MAINWINDOW_H
View
2  proxy/rypipedata.cpp
@@ -475,7 +475,7 @@ QString& RyPipeData::httpVersion()const{
*/
QString RyPipeData::getRequestHeader(const QString &name) const{
- return _requestHeaders.value(name,"undefined");
+ return _requestHeaders.value(name,"");
}
QString RyPipeData::getResponseHeader(const QString &name) const{
return _responseHeaders.value(name,"");
View
2  proxy/rypipedata.h
@@ -4,7 +4,7 @@
#include <QObject>
#include <QSharedPointer>
#include <QVariant>
-
+#include <QDebug>
class RyPipeData : public QObject
View
18 ryconnectiontableview.cpp
@@ -2,9 +2,10 @@
#include <QTemporaryFile>
#include "quazip/quazip.h"
#include "quazip/quazipfile.h"
-#include "rytablemodel.h"
+#include "rytablesortfilterproxymodel.h"
#include "rymimedata.h"
+#include "savesessionsdialog.h"
extern QString appPath;
extern QByteArray gzipDecompress(QByteArray data);
@@ -13,6 +14,7 @@ RyConnectionTableView::RyConnectionTableView(QWidget *parent) :
QTableView(parent){
_isMouseDown = false;
this->setDragEnabled(true);
+ this->setAlternatingRowColors(true);
createMenu();
}
@@ -73,8 +75,11 @@ void RyConnectionTableView::mouseMoveEvent(QMouseEvent *event){
return;
}
QPoint hotSpot = event->pos() - this->pos();
- RyTableModel* model = qobject_cast<RyTableModel*>(this->model());
- RyPipeData_ptr data = model->getItem(index.row());
+ RyTableSortFilterProxyModel* model = qobject_cast<RyTableSortFilterProxyModel*>(this->model());
+ RyPipeData_ptr data = model->getItem(index);
+ if(data.isNull()){
+ return;
+ }
RyMimeData *mimeData = new RyMimeData(data);
mimeData->setText(data->getRequestHeader("Host"));
QDrag *drag = new QDrag(this);
@@ -97,9 +102,11 @@ void RyConnectionTableView::onAction(QAction *action){
QuaZip zip(saveFileName);
zip.open(QuaZip::mdCreate);
- RyTableModel *model = qobject_cast<RyTableModel*>(this->model());
+ RyTableSortFilterProxyModel *model = qobject_cast<RyTableSortFilterProxyModel*>(this->model());
QItemSelection selection = this->selectionModel()->selection();
+
+
int index=0;
for(int j=0;j<selection.length();++j){
QItemSelectionRange r = selection.at(j);
@@ -139,6 +146,7 @@ void RyConnectionTableView::onAction(QAction *action){
zip.close();
}else if(action == _saveSessionRespnoseBodyAct){
+
QFileDialog dialog;
QString saveDir = dialog.getExistingDirectory(this,tr("save session response body to..."));
if(saveDir.isEmpty()){
@@ -146,7 +154,7 @@ void RyConnectionTableView::onAction(QAction *action){
}
QDir dir(saveDir);
- RyTableModel *model = qobject_cast<RyTableModel*>(this->model());
+ RyTableSortFilterProxyModel *model = qobject_cast<RyTableSortFilterProxyModel*>(this->model());
QItemSelection selection = this->selectionModel()->selection();
int index=0;
for(int j=0;j<selection.length();++j){
View
9 rypipetableview.cpp
@@ -1,9 +0,0 @@
-#include "rypipetableview.h"
-#include <QDebug>
-
-RyPipeTableView::RyPipeTableView(QWidget *parent) :
- QTableView(parent){
-}
-void RyPipeTableView::mousePressEvent(QMouseEvent *){
- qDebug()<<"mouse press";
-}
View
19 rypipetableview.h
@@ -1,19 +0,0 @@
-#ifndef RYPIPETABLEVIEW_H
-#define RYPIPETABLEVIEW_H
-
-#include <QTableView>
-
-class RyPipeTableView : public QTableView
-{
- Q_OBJECT
- public:
- explicit RyPipeTableView(QWidget *parent = 0);
- protected:
- void mousePressEvent(QMouseEvent *event);
- signals:
-
- public slots:
-
-};
-
-#endif // RYPIPETABLEVIEW_H
View
69 rytablemodel.cpp
@@ -85,7 +85,19 @@ QVariant RyTableModel::data(const QModelIndex &index, int role) const{
}else if(role == Qt::BackgroundColorRole){
if(pipesVector.count()>index.row()){
- return (pipesVector.at(index.row())->isMatchingRule ? Qt::cyan : QVariant());
+
+ RyPipeData_ptr d = pipesVector.at(index.row());
+ if(d->isMatchingRule){
+ return Qt::cyan;
+ }else if(d->responseStatus.startsWith('4') || d->responseStatus.startsWith('5')){
+ return Qt::darkCyan;
+ }
+ }else{
+ return QVariant();
+ }
+ }else if(role == RyTableModel::RowDataRole){
+ if(pipesVector.count()>index.row()){
+ return QVariant(pipesVector.at(index.row()));
}else{
return QVariant();
}
@@ -118,40 +130,49 @@ Qt::ItemFlags RyTableModel::flags(const QModelIndex &index) const{
return QAbstractTableModel::flags(index);
}
-bool RyTableModel::itemLessThan(RyPipeData_ptr a,RyPipeData_ptr b){
- return rypipeDataGetDataByColumn(a,1) <
- rypipeDataGetDataByColumn(b,1);
+bool RyTableModel::itemLessThan(RyPipeData_ptr left,int leftColumn,RyPipeData_ptr right,int rightColumn){
+ if(left.isNull() || right.isNull()){
+ return false;
+ }
+ QString leftData = rypipeDataGetDataByColumn(left,leftColumn) ;
+ QString rightData = rypipeDataGetDataByColumn(right,rightColumn);
+ bool isNumber=false;
+ long long leftNumber = leftData.toLongLong(&isNumber);
+ long long rightNumber;
+ if(isNumber){
+ rightNumber = rightData.toLongLong(&isNumber);
+ if(isNumber){
+ return leftNumber<rightNumber;
+ }
+ }
+ return leftData < rightData;
}
-
-void RyTableModel::sort(int column, Qt::SortOrder/* = Qt::AscendingOrder*/){
- //qDebug()<<"sort called..";
- _sortingColumn = column;
- //rypipeDataGetDataByColumn(a,_sortingColumn),
- //rypipeDataGetDataByColumn(b,_sortingColumn)
- //qSort(pipesVector.begin(),pipesVector.end(),itemLessThan);
+bool RyTableModel::itemLessThan(const QModelIndex &left, const QModelIndex &right){
+ return itemLessThan(getItem(left.row()),left.column(),getItem(right.row()),right.column());
}
+
RyPipeData_ptr RyTableModel::getItem(int row){
//qDebug()<<pipesVector.size()<<row;
- //if(pipesVector.size() >= row){
+ if(pipesVector.size() >= row){
return pipesVector.at(row);
- //}
- //qDebug()<<row<<" ---";
- //return RyPipeData_ptr(new RyPipeData());
+ }
+ qDebug()<<QString("getItem invalid row:%1").arg(row);
+ return RyPipeData_ptr();
}
void RyTableModel::updateItem(RyPipeData_ptr p){
int i = pipesMap.keys().indexOf(p->id);
if(i!=-1){
- /*
+
RyPipeData_ptr ori = pipesMap[p->id];
pipesMap[p->id] = p;
int j = pipesVector.indexOf(ori);
if(j!=-1){
pipesVector.replace(j,p);
}
- */
- emit dataChanged(index(i,0),index(i,8));//TODO.. magic number 7
+
+ emit dataChanged(index(i,0),index(i,columnCount()));
emit connectionUpdated(p);
}
}
@@ -160,9 +181,12 @@ void RyTableModel::addItem(RyPipeData_ptr p){
//qDebug()<<"addItem...."<<p->getRequestHeader(QByteArray("Host"))<<pipesVector.count();
RyPipeData_ptr p1 = p;
++_pipeNumber;
+ int l = pipesVector.size();
+ if(l==0){
+ _pipeNumber = 1;
+ }
p1->number=_pipeNumber;
-
- this->beginInsertRows(index(_pipeNumber-1, 0),_pipeNumber-1,_pipeNumber-1);
+ this->beginInsertRows(index(l, 0),l,l);
//TODO thread safe?
pipesMap[p1->id] = p1;
@@ -177,12 +201,11 @@ void RyTableModel::addItem(RyPipeData_ptr p){
}
void RyTableModel::removeAllItem(){
- //int l = pipesVector.size();
+ beginResetModel();
pipesMap.clear();
pipesVector.clear();
//qDebug()<<"length="<<pipesVector.count();
- //emit dataChanged(index(0,0),index(l-1,7));
- emit reset();
+ endResetModel();
}
void RyTableModel::removeItems(){
View
13 rytablemodel.h
@@ -12,19 +12,24 @@ class RyTableModel : public QAbstractTableModel
{
Q_OBJECT
public:
+
+ enum Role{
+ RowDataRole = Qt::UserRole + 1
+ };
+
explicit RyTableModel(QObject *parent = 0);
~RyTableModel();
QMap<int,RyPipeData_ptr > pipesMap;
QVector<RyPipeData_ptr > pipesVector;
int rowCount( const QModelIndex & parent ) const;
- int columnCount(const QModelIndex &parent) const;
- QVariant data(const QModelIndex &index, int role) const;
+ int columnCount(const QModelIndex &parent = QModelIndex()) const;
+ QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const;
QVariant headerData(int section, Qt::Orientation orientation, int role) const;
Qt::ItemFlags flags(const QModelIndex &index) const;
- void sort(int column, Qt::SortOrder order = Qt::AscendingOrder);
- static bool itemLessThan(RyPipeData_ptr a,RyPipeData_ptr b);
+ bool itemLessThan(RyPipeData_ptr left,int leftColumn,RyPipeData_ptr right,int rightColumn);
+ bool itemLessThan(const QModelIndex& left,const QModelIndex& right);
public slots:
void addItem(RyPipeData_ptr p);
void removeItems();
View
66 rytablesortfilterproxymodel.cpp
@@ -0,0 +1,66 @@
+#include "rytablesortfilterproxymodel.h"
+
+RyTableSortFilterProxyModel::RyTableSortFilterProxyModel(QObject *parent) :
+ QSortFilterProxyModel(parent){
+ _filterFlags = NoFilter;
+}
+
+void RyTableSortFilterProxyModel::setSourceModel(RyTableModel *sourceModel){
+ QSortFilterProxyModel::setSourceModel(sourceModel);
+ _sourceModel = sourceModel;
+}
+
+bool RyTableSortFilterProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &) const{
+ RyPipeData_ptr p = _sourceModel->getItem(sourceRow);
+ if(p.isNull()){
+ return true;
+ }
+
+ if(_filterFlags & NoImageFilter){
+ if(p->getResponseHeader("Content-Type").toLower().indexOf("image")!=-1){
+ //if(!noImageFilterAccepted(p)){
+ return false;
+ }
+ }
+ if(_filterFlags & No304Filter){
+ if(p->responseStatus == "304"){
+ return false;
+ }
+ }
+ if(_filterFlags & OnlyMatchingFilter){
+ if(!p->isMatchingRule){
+ return false;
+ }
+ }
+ if(_filterFlags & CustomFilter){
+ //if(!_filterCallback(p)){
+ // return false;
+ //}
+ }
+ return true;
+}
+bool RyTableSortFilterProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const{
+ //qDebug()<<QString("row:%1,col:%2").arg(left.row()).arg(left.column());
+ //qDebug()<<QString("row:%1,col:%2").arg(right.row()).arg(right.column());
+ //QModelIndex leftSource = mapToSource(left);
+ //QModelIndex rightSource = mapToSource(right);
+ return _sourceModel->itemLessThan(left,right);
+}
+RyPipeData_ptr RyTableSortFilterProxyModel::getItem(int sourceRow){
+ return _sourceModel->getItem(sourceRow);
+}
+RyPipeData_ptr RyTableSortFilterProxyModel::getItem(const QModelIndex& proxyIndex){
+ return getItem(mapToSource(proxyIndex).row());
+}
+
+void RyTableSortFilterProxyModel::setFilter(int flag){
+ _filterFlags = flag;
+ emit invalidateFilter();
+}
+
+int RyTableSortFilterProxyModel::filter()const{
+ return _filterFlags;
+}
+void RyTableSortFilterProxyModel::setCustomeFilter(FilterCallBack filtercb){
+ _filterCallback = filtercb;
+}
View
48 rytablesortfilterproxymodel.h
@@ -0,0 +1,48 @@
+#ifndef RYTABLESORTFILTERPROXYMODEL_H
+#define RYTABLESORTFILTERPROXYMODEL_H
+
+#include <QSortFilterProxyModel>
+#include <rytablemodel.h>
+
+class RyTableSortFilterProxyModel : public QSortFilterProxyModel
+{
+ Q_OBJECT
+public:
+
+ typedef bool (*FilterCallBack)(RyPipeData_ptr);
+ enum Filter{
+ NoFilter = 0,
+ NoImageFilter = 0x01,
+ No304Filter = 0x02,
+ CustomFilter = 0x04,
+ OnlyMatchingFilter = 0x08
+ };
+
+ explicit RyTableSortFilterProxyModel(QObject *parent = 0);
+ void setSourceModel(RyTableModel *sourceModel);
+ RyPipeData_ptr getItem(int sourceRow);
+ RyPipeData_ptr getItem(const QModelIndex& proxyIndex);
+
+ void setFilter(int filter);
+ int filter()const;
+ void setCustomeFilter(FilterCallBack);
+
+ void removeAllItem(){
+ reset();
+ }
+
+protected:
+ bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const;
+ bool lessThan(const QModelIndex &left, const QModelIndex &right) const;
+
+signals:
+
+public slots:
+
+private:
+ RyTableModel *_sourceModel;
+ int _filterFlags;
+ FilterCallBack _filterCallback;
+};
+
+#endif // RYTABLESORTFILTERPROXYMODEL_H
View
23 savesessionsdialog.cpp
@@ -0,0 +1,23 @@
+#include "savesessionsdialog.h"
+#include "ui_savesessionsdialog.h"
+
+SaveSessionsDialog::SaveSessionsDialog(int totalFiles,QWidget *parent) :
+ QDialog(parent),
+ ui(new Ui::SaveSessionsDialog)
+{
+ ui->setupUi(this);
+ _saved = 0;
+ _totalFiles = totalFiles;
+ ui->progressBar->setMaximum(_totalFiles);
+ ui->progressBar->setTextVisible(true);
+}
+
+SaveSessionsDialog::~SaveSessionsDialog()
+{
+ delete ui;
+}
+
+void SaveSessionsDialog::updateProgress(const QString &savingFileName){
+ ui->progressBar->setValue(_saved);
+ ui->savingFileNameLabel->setText(savingFileName);
+}
View
28 savesessionsdialog.h
@@ -0,0 +1,28 @@
+#ifndef SAVESESSIONSDIALOG_H
+#define SAVESESSIONSDIALOG_H
+
+#include <QDialog>
+
+namespace Ui {
+class SaveSessionsDialog;
+}
+
+class SaveSessionsDialog : public QDialog
+{
+ Q_OBJECT
+
+public:
+ explicit SaveSessionsDialog(int total,QWidget *parent = 0);
+ ~SaveSessionsDialog();
+public slots:
+ void updateProgress(const QString& savingFileName);
+
+
+private:
+ Ui::SaveSessionsDialog *ui;
+
+ int _totalFiles;
+ int _saved;
+};
+
+#endif // SAVESESSIONSDIALOG_H
View
135 savesessionsdialog.ui
@@ -0,0 +1,135 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>SaveSessionsDialog</class>
+ <widget class="QDialog" name="SaveSessionsDialog">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>373</width>
+ <height>184</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>Dialog</string>
+ </property>
+ <widget class="QDialogButtonBox" name="buttonBox">
+ <property name="geometry">
+ <rect>
+ <x>30</x>
+ <y>140</y>
+ <width>341</width>
+ <height>32</height>
+ </rect>
+ </property>
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="standardButtons">
+ <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
+ </property>
+ </widget>
+ <widget class="QLabel" name="label">
+ <property name="geometry">
+ <rect>
+ <x>30</x>
+ <y>80</y>
+ <width>61</width>
+ <height>16</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string>saving</string>
+ </property>
+ </widget>
+ <widget class="QLabel" name="savingFileNameLabel">
+ <property name="geometry">
+ <rect>
+ <x>20</x>
+ <y>100</y>
+ <width>331</width>
+ <height>20</height>
+ </rect>
+ </property>
+ <property name="layoutDirection">
+ <enum>Qt::LeftToRight</enum>
+ </property>
+ <property name="text">
+ <string>/path/to/svae/file/name.html</string>
+ </property>
+ <property name="textFormat">
+ <enum>Qt::PlainText</enum>
+ </property>
+ <property name="scaledContents">
+ <bool>false</bool>
+ </property>
+ <property name="alignment">
+ <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
+ </property>
+ <property name="wordWrap">
+ <bool>false</bool>
+ </property>
+ </widget>
+ <widget class="QProgressBar" name="progressBar">
+ <property name="geometry">
+ <rect>
+ <x>30</x>
+ <y>50</y>
+ <width>118</width>
+ <height>23</height>
+ </rect>
+ </property>
+ <property name="value">
+ <number>24</number>
+ </property>
+ </widget>
+ <widget class="QLabel" name="label_3">
+ <property name="geometry">
+ <rect>
+ <x>30</x>
+ <y>20</y>
+ <width>61</width>
+ <height>16</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string>1/10</string>
+ </property>
+ </widget>
+ </widget>
+ <resources/>
+ <connections>
+ <connection>
+ <sender>buttonBox</sender>
+ <signal>accepted()</signal>
+ <receiver>SaveSessionsDialog</receiver>
+ <slot>accept()</slot>
+ <hints>
+ <hint type="sourcelabel">
+ <x>248</x>
+ <y>254</y>
+ </hint>
+ <hint type="destinationlabel">
+ <x>157</x>
+ <y>274</y>
+ </hint>
+ </hints>
+ </connection>
+ <connection>
+ <sender>buttonBox</sender>
+ <signal>rejected()</signal>
+ <receiver>SaveSessionsDialog</receiver>
+ <slot>reject()</slot>
+ <hints>
+ <hint type="sourcelabel">
+ <x>316</x>
+ <y>260</y>
+ </hint>
+ <hint type="destinationlabel">
+ <x>286</x>
+ <y>274</y>
+ </hint>
+ </hints>
+ </connection>
+ </connections>
+</ui>
Please sign in to comment.
Something went wrong with that request. Please try again.