From 3b01e357838eca9b640865fe913632e1410e3f31 Mon Sep 17 00:00:00 2001 From: Tim Blume Date: Sat, 29 Aug 2020 01:09:41 +0200 Subject: [PATCH] sta --- .cmake/api/v1/query/cache-v2 | 0 .cmake/api/v1/query/cmakeFiles-v1 | 0 .cmake/api/v1/query/codemodel-v2 | 0 historymodel.cpp | 45 +++++++++++++++++++++++++++++++ historymodel.h | 11 ++++++++ includes.h | 17 +++++++++--- mainwindow.cpp | 3 ++- mainwindow.h | 1 + session.cpp | 2 ++ test.sh | 4 +-- 10 files changed, 76 insertions(+), 7 deletions(-) create mode 100644 .cmake/api/v1/query/cache-v2 create mode 100644 .cmake/api/v1/query/cmakeFiles-v1 create mode 100644 .cmake/api/v1/query/codemodel-v2 diff --git a/.cmake/api/v1/query/cache-v2 b/.cmake/api/v1/query/cache-v2 new file mode 100644 index 0000000..e69de29 diff --git a/.cmake/api/v1/query/cmakeFiles-v1 b/.cmake/api/v1/query/cmakeFiles-v1 new file mode 100644 index 0000000..e69de29 diff --git a/.cmake/api/v1/query/codemodel-v2 b/.cmake/api/v1/query/codemodel-v2 new file mode 100644 index 0000000..e69de29 diff --git a/historymodel.cpp b/historymodel.cpp index c0daf61..be46fb7 100644 --- a/historymodel.cpp +++ b/historymodel.cpp @@ -63,16 +63,61 @@ QVariant HistoryModel::data(const QModelIndex &index, int role) const return QString::number(item.size); } } + throw std::out_of_range("history model col"); } catch (std::out_of_range const& exc) { qDebug() << "historymodel data " << exc.what(); } return QVariant(); } +QVariant HistoryModel::headerData(int section, Qt::Orientation orientation, int role) const +{ + if(role != Qt::DisplayRole) { + return QVariant(); + } + if(orientation == Qt::Horizontal) { + switch(section) { + case 0: { + return "id"; + } + case 1: { + return "time"; + } + case 2: { + return "url"; + } + case 3: { + return "code"; + } + case 4: { + return "reason"; + } + case 5: { + return "rtt"; + } + case 6: { + return "size"; + } + } + } + return QVariant(); +} + void HistoryModel::update(std::vector *items) { if(current_items) { delete current_items; } current_items = items; + emit layoutChanged(); +} + +bool HistoryProxyModel::lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const +{ + return QSortFilterProxyModel::lessThan(source_left, source_right); +} + +bool HistoryProxyModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const +{ + return true; } diff --git a/historymodel.h b/historymodel.h index 66e3b96..99c3705 100644 --- a/historymodel.h +++ b/historymodel.h @@ -2,6 +2,7 @@ #include #include +#include struct HistoryItem { int id = -1; @@ -27,5 +28,15 @@ public: int rowCount(const QModelIndex &parent = QModelIndex()) const override; int columnCount(const QModelIndex &parent = QModelIndex()) const override; QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; + QVariant headerData(int section, Qt::Orientation orientation, int role) const override; void update(std::vector* items); }; + +class HistoryProxyModel : public QSortFilterProxyModel +{ + Q_OBJECT +private: +public: + bool lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const override; + bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const override; +}; diff --git a/includes.h b/includes.h index b8ee75d..b43ce1a 100644 --- a/includes.h +++ b/includes.h @@ -18,16 +18,25 @@ bool json_get(json j, T& value, K key) noexcept { j[key].get_to(value); return true; } catch (nlohmann::detail::type_error& err) { - qDebug() << err.what(); + qDebug() << "key " << key << " error " << err.what(); } catch (nlohmann::detail::out_of_range& err) { - qDebug() << err.what(); + qDebug() << "key " << key << " error " << err.what(); } catch (nlohmann::detail::other_error& err) { - qDebug() << err.what(); + qDebug() << "key " << key << " error " << err.what(); } return false; } template bool json_get(json j, T& value, K key, Ks... keys) noexcept { - return json_get(j[key], value, keys...); + try { + return json_get(j[key], value, keys...); + } catch (nlohmann::detail::type_error& err) { + qDebug() << "key " << key << " error " << err.what(); + } catch (nlohmann::detail::out_of_range& err) { + qDebug() << "key " << key << " error " << err.what(); + } catch (nlohmann::detail::other_error& err) { + qDebug() << "key " << key << " error " << err.what(); + } + return false; } diff --git a/mainwindow.cpp b/mainwindow.cpp index 5c0df19..edbada0 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -22,11 +22,12 @@ MainWindow::MainWindow(QWidget *parent) thread->start(); history_model.update(current_session->getHistoryItems()); + history_proxy.setSourceModel(&history_model); ui->setupUi(this); ui->historyHTTPTable->setShowGrid(true); ui->historyHTTPTable->setEditTriggers(QAbstractItemView::NoEditTriggers); - ui->historyHTTPTable->setModel(&history_model); + ui->historyHTTPTable->setModel(&history_proxy); } MainWindow::~MainWindow() diff --git a/mainwindow.h b/mainwindow.h index ebfa2ba..d0f40b9 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -19,6 +19,7 @@ private: QThread* thread; Session* current_session; HistoryModel history_model; + HistoryProxyModel history_proxy; public: MainWindow(QWidget *parent = nullptr); ~MainWindow(); diff --git a/session.cpp b/session.cpp index 569e790..9ecd03e 100644 --- a/session.cpp +++ b/session.cpp @@ -134,6 +134,7 @@ std::optional Session::getSetting(std::string key) { } std::vector* Session::getHistoryItems() { + qDebug() << "history items generated"; // todo check reset return code sqlite3_reset(stmt_get_all_history); @@ -297,6 +298,7 @@ int Session::saveFlow(http::Flow flow) { return -1; } + qDebug() << "saved flow"; return sqlite3_last_insert_rowid(db); } diff --git a/test.sh b/test.sh index e555c56..bba25dc 100755 --- a/test.sh +++ b/test.sh @@ -5,9 +5,9 @@ export mitmpid=$! ./build/littlesnitch & sleep 5 -curl -x http://localhost:1878 -k https://yolo.jetzt +curl -s -x http://localhost:1878 -k https://yolo.jetzt > /dev/null sleep 2 -curl -x http://localhost:1878 -k https://get.yolo.jetzt +curl -s -x http://localhost:1878 -k https://blog.fefe.de > /dev/null sleep 2 kill -9 $mitmpid