Browse Source

Add Session Dialog

Aqua-sama 2 weeks ago
parent
commit
09c4508aee
Signed by: Aqua-sama <aqua@iserlohn-fortress.net> GPG Key ID: 5378B8349C1D5ADA

+ 9
- 0
doc/Development.asciidoc View File

@@ -15,6 +15,15 @@ extensions. Source code should be kept as platform-agnostic as possible.
15 15
   syntax (SIGNAL/SLOT). This enables compile-time connect checks.
16 16
 * Prefer QVector over QList: http://lists.qt-project.org/pipermail/development/2017-March/029040.html
17 17
 
18
+=== Setting linker
19
+Meson has no environment variable to set the linker (link:https://github.com/mesonbuild/meson/issues/3597[issue]).
20
+
21
+Instead, this can be done using the cpp_link_args:
22
+[source, sh]
23
+----
24
+build% meson configure -Dcpp_link_args='-fuse-ld=gold'
25
+----
26
+
18 27
 === clazy
19 28
 You can use https://github.com/KDE/clazy[clazy] to check Qt semantics.
20 29
 

+ 49
- 0
doc/Development/Fuzzing.asciidoc View File

@@ -0,0 +1,49 @@
1
+=== Setup
2
+Required packages: afl
3
+
4
+==== Compiling Qt
5
+This will build an instrumented Qt:
6
+
7
+[source, sh]
8
+----
9
+export CC=$(which afl-gcc)
10
+export CXX=$(which afl-g++)
11
+./configure ...
12
+make
13
+----
14
+
15
+=== Running the fuzzer
16
+[source, sh]
17
+----
18
+cd /sys/devices/system/cpu
19
+su
20
+echo performance | tee cpu*/cpufreq/scaling_governor
21
+exit
22
+
23
+cd $testdir
24
+afl-fuzz -m 512 -t 40 -i $input -o $output -- $testexe @@
25
+
26
+# see for available scaling_governor values:
27
+cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors
28
+
29
+cd /sys/devices/system/cpu
30
+su
31
+echo powersave | tee cpu*/cpufreq/scaling_governor
32
+exit
33
+----
34
+
35
+The $input directory contains your reference input files, while the findings of the fuzzers will be written in $output.
36
+
37
+@@ gets replaced by the name of a file generated by AFL, containing the mutated input.
38
+
39
+=== Using ramdisk for tests
40
+[source, sh]
41
+----
42
+$ mkdir afl
43
+# mount -t tmpfs -o size=1024M tmpfs afl/
44
+$ cd afl/
45
+$ afl-fuzz -i inputs -o findings ...
46
+----
47
+
48
+=== Sources
49
+1. https://www.kdab.com/fuzzing-qt-fun-profit/

+ 2
- 0
lib/configuration/configuration.cpp View File

@@ -55,6 +55,8 @@ Configuration::Configuration(QObject *parent)
55 55
         ("browser.locale", po::value<std::string>(), "Set Qt localization.")
56 56
         ("browser.translation", po::value<std::string>(), "Set application localization.")
57 57
 
58
+        ("browser.session.path", po::value<std::string>()->default_value("~/.config/smolbote/session.d"))
59
+
58 60
 #ifdef CONFIG_USEBREAKPAD
59 61
         ("browser.crash.path", po::value<std::string>()->default_value(CONFIG_PATH_CRASHDUMP))
60 62
         ("browser.crash.handler", po::value<std::string>()->default_value(CONFIG_PATH_CRASHHANDLER))

+ 1
- 1
meson.build View File

@@ -26,7 +26,7 @@ dep_plasma = declare_dependency(
26 26
 )
27 27
 
28 28
 # add -DQT_NO_DEBUG to non-debug builds
29
-if not get_option('buildtype').startswith('debug')
29
+if not get_option('debug')
30 30
     add_global_arguments('-DQT_NO_DEBUG', language: 'cpp')
31 31
 endif
32 32
 

+ 3
- 8
src/mainwindow/mainwindow.cpp View File

@@ -13,6 +13,7 @@
13 13
 #include "configuration.h"
14 14
 #include "profilemanager.h"
15 15
 #include "session.h"
16
+#include "session/sessiondialog.h"
16 17
 #include "subwindow/subwindow.h"
17 18
 #include "ui_mainwindow.h"
18 19
 #include "webengine/webview.h"
@@ -126,14 +127,8 @@ MainWindow::MainWindow(const std::unique_ptr<Configuration> &config, QWidget *pa
126 127
             }
127 128
         });
128 129
         connect(ui->actionLoadSession, &QAction::triggered, this, [this]() {
129
-            const QString filename = QFileDialog::getOpenFileName(this, tr("Load Session"), QDir::homePath(), tr("JSON (*.json)"));
130
-            QFile json(filename);
131
-            if(json.open(QIODevice::ReadOnly | QIODevice::Text)) {
132
-                auto *browser = qobject_cast<Browser *>(qApp);
133
-                auto doc = QJsonDocument::fromJson(json.readAll());
134
-                browser->createSession(doc.object());
135
-                json.close();
136
-            }
130
+            auto *sessionDialog = new SessionDialog(this);
131
+            sessionDialog->exec();
137 132
         });
138 133
     }
139 134
 

+ 8
- 4
src/meson.build View File

@@ -1,10 +1,11 @@
1 1
 # poi
2 2
 poi_moc = qt5.preprocess(
3 3
     moc_headers: ['browser.h',
4
-        'mainwindow/mainwindow.h', 'mainwindow/widgets/dockwidget.h', 'mainwindow/widgets/navigationbar.h', 'mainwindow/widgets/searchform.h', 
5
-        'subwindow/subwindow.h', 'subwindow/tabwidget.h', 
4
+        'mainwindow/mainwindow.h', 'mainwindow/widgets/dockwidget.h', 'mainwindow/widgets/navigationbar.h', 'mainwindow/widgets/searchform.h',
5
+        'session/sessiondialog.h', 'session/sessionform.h',
6
+        'subwindow/subwindow.h', 'subwindow/tabwidget.h',
6 7
         'webengine/filter.h', 'webengine/urlinterceptor.h', 'webengine/webpage.h', 'webengine/webview.h'],
7
-    ui_files: ['mainwindow/mainwindow.ui', 'mainwindow/widgets/searchform.ui'],
8
+    ui_files: ['mainwindow/mainwindow.ui', 'mainwindow/widgets/searchform.ui', 'session/sessiondialog.ui', 'session/sessionform.ui'],
8 9
     qresources: '../data/resources.qrc',
9 10
     rcc_extra_arguments: ['--format-version=1'],
10 11
     dependencies: dep_qt5
@@ -32,7 +33,10 @@ poi = executable(get_option('poiName'), install: true,
32 33
     'mainwindow/mainwindow.cpp', 
33 34
     'mainwindow/widgets/dockwidget.cpp', 
34 35
     'mainwindow/widgets/navigationbar.cpp', 
35
-    'mainwindow/widgets/searchform.cpp', 
36
+    'mainwindow/widgets/searchform.cpp',
37
+
38
+    'session/sessiondialog.cpp',
39
+    'session/sessionform.cpp',
36 40
 
37 41
     'subwindow/subwindow.cpp', 
38 42
     'subwindow/tabwidget.cpp', 

+ 87
- 0
src/session/sessiondialog.cpp View File

@@ -0,0 +1,87 @@
1
+/*
2
+ * This file is part of smolbote. It's copyrighted by the contributors recorded
3
+ * in the version control history of the file, available from its original
4
+ * location: https://neueland.iserlohn-fortress.net/gitea/aqua/smolbote
5
+ *
6
+ * SPDX-License-Identifier: GPL-3.0
7
+ */
8
+
9
+#include "sessiondialog.h"
10
+#include "../browser.h"
11
+#include "../util.h"
12
+#include "sessionform.h"
13
+#include "ui_sessiondialog.h"
14
+#include "ui_sessionform.h"
15
+#include <QFile>
16
+#include <QFileDialog>
17
+#include <QToolButton>
18
+#include <QStyle>
19
+
20
+SessionDialog::SessionDialog(QWidget *parent)
21
+    : QDialog(parent)
22
+    , ui(new Ui::SessionDialog)
23
+{
24
+    ui->setupUi(this);
25
+    ui->open->setIcon(style()->standardIcon(QStyle::SP_DirOpenIcon));
26
+
27
+    auto *browser = qobject_cast<Browser *>(qApp);
28
+    Q_CHECK_PTR(browser);
29
+
30
+    for(const QString &path : Util::files(browser->configuration("browser.session.path"), { "*.json" })) {
31
+        auto *item = new QListWidgetItem(ui->listWidget);
32
+        auto *widget = new SessionForm(path, this);
33
+        connect(widget->ui->delete_toolButton, &QToolButton::clicked, this, [item, widget]() {
34
+            delete item;
35
+            delete widget;
36
+        });
37
+        ui->listWidget->setItemWidget(item, widget);
38
+    }
39
+
40
+#ifdef QT_DEBUG
41
+    ui->listWidget->addItem(tr("Start new session"));
42
+#endif
43
+
44
+    connect(ui->listWidget, &QListWidget::currentItemChanged, this, [this](QListWidgetItem *currentItem, QListWidgetItem *previousItem) {
45
+        auto *currentWidget = qobject_cast<SessionForm *>(ui->listWidget->itemWidget(currentItem));
46
+        if(currentWidget)
47
+            currentWidget->ui->delete_toolButton->show();
48
+
49
+        auto *previousWidget = qobject_cast<SessionForm *>(ui->listWidget->itemWidget(previousItem));
50
+        if(previousWidget)
51
+            previousWidget->ui->delete_toolButton->hide();
52
+    });
53
+
54
+    connect(ui->open, &QPushButton::clicked, this, [this]() {
55
+        const QString filename = QFileDialog::getOpenFileName(this, tr("Select Session file"), QDir::homePath(), tr("JSON (*.json)"));
56
+        if(!filename.isEmpty()) {
57
+            this->openSession(filename);
58
+            // close the dialog window; reject so it doesn't open another session
59
+            this->reject();
60
+        }
61
+    });
62
+
63
+    connect(this, &SessionDialog::accepted, this, [this]() {
64
+        auto *currentWidget = qobject_cast<SessionForm *>(ui->listWidget->itemWidget(ui->listWidget->currentItem()));
65
+        if(currentWidget)
66
+            this->openSession(currentWidget->ui->label->text());
67
+    });
68
+}
69
+
70
+SessionDialog::~SessionDialog()
71
+{
72
+    delete ui;
73
+}
74
+
75
+void SessionDialog::openSession(const QString &filename)
76
+{
77
+    auto *browser = qobject_cast<Browser *>(qApp);
78
+    Q_CHECK_PTR(browser);
79
+
80
+    QFile json(filename);
81
+    if(json.open(QIODevice::ReadOnly | QIODevice::Text)) {
82
+        auto *browser = qobject_cast<Browser *>(qApp);
83
+        auto doc = QJsonDocument::fromJson(json.readAll());
84
+        browser->createSession(doc.object());
85
+        json.close();
86
+    }
87
+}

+ 34
- 0
src/session/sessiondialog.h View File

@@ -0,0 +1,34 @@
1
+/*
2
+ * This file is part of smolbote. It's copyrighted by the contributors recorded
3
+ * in the version control history of the file, available from its original
4
+ * location: https://neueland.iserlohn-fortress.net/gitea/aqua/smolbote
5
+ *
6
+ * SPDX-License-Identifier: GPL-3.0
7
+ */
8
+
9
+#ifndef SMOLBOTE_SESSIONDIALOG_H
10
+#define SMOLBOTE_SESSIONDIALOG_H
11
+
12
+#include <QDialog>
13
+
14
+namespace Ui
15
+{
16
+class SessionDialog;
17
+}
18
+
19
+class SessionDialog : public QDialog
20
+{
21
+    Q_OBJECT
22
+
23
+public:
24
+    explicit SessionDialog(QWidget *parent = nullptr);
25
+    ~SessionDialog() override;
26
+
27
+private:
28
+    void openSession(const QString &filename);
29
+
30
+private:
31
+    Ui::SessionDialog *ui;
32
+};
33
+
34
+#endif // SMOLBOTE_SESSIONDIALOG_H

+ 96
- 0
src/session/sessiondialog.ui View File

@@ -0,0 +1,96 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<ui version="4.0">
3
+ <class>SessionDialog</class>
4
+ <widget class="QDialog" name="SessionDialog">
5
+  <property name="geometry">
6
+   <rect>
7
+    <x>0</x>
8
+    <y>0</y>
9
+    <width>1000</width>
10
+    <height>600</height>
11
+   </rect>
12
+  </property>
13
+  <property name="windowTitle">
14
+   <string>Select Session</string>
15
+  </property>
16
+  <layout class="QVBoxLayout" name="verticalLayout">
17
+   <item>
18
+    <layout class="QHBoxLayout" name="horizontalLayout">
19
+     <item>
20
+      <widget class="QLabel" name="label">
21
+       <property name="text">
22
+        <string>Filter</string>
23
+       </property>
24
+      </widget>
25
+     </item>
26
+     <item>
27
+      <widget class="QLineEdit" name="lineEdit">
28
+       <property name="placeholderText">
29
+        <string>Search</string>
30
+       </property>
31
+      </widget>
32
+     </item>
33
+    </layout>
34
+   </item>
35
+   <item>
36
+    <widget class="QListWidget" name="listWidget"/>
37
+   </item>
38
+   <item>
39
+    <layout class="QHBoxLayout" name="horizontalLayout_2">
40
+     <item>
41
+      <widget class="QPushButton" name="open">
42
+       <property name="text">
43
+        <string>Open from File</string>
44
+       </property>
45
+      </widget>
46
+     </item>
47
+     <item>
48
+      <widget class="QDialogButtonBox" name="buttonBox">
49
+       <property name="orientation">
50
+        <enum>Qt::Horizontal</enum>
51
+       </property>
52
+       <property name="standardButtons">
53
+        <set>QDialogButtonBox::Close|QDialogButtonBox::Open</set>
54
+       </property>
55
+      </widget>
56
+     </item>
57
+    </layout>
58
+   </item>
59
+  </layout>
60
+ </widget>
61
+ <resources/>
62
+ <connections>
63
+  <connection>
64
+   <sender>buttonBox</sender>
65
+   <signal>accepted()</signal>
66
+   <receiver>SessionDialog</receiver>
67
+   <slot>accept()</slot>
68
+   <hints>
69
+    <hint type="sourcelabel">
70
+     <x>248</x>
71
+     <y>254</y>
72
+    </hint>
73
+    <hint type="destinationlabel">
74
+     <x>157</x>
75
+     <y>274</y>
76
+    </hint>
77
+   </hints>
78
+  </connection>
79
+  <connection>
80
+   <sender>buttonBox</sender>
81
+   <signal>rejected()</signal>
82
+   <receiver>SessionDialog</receiver>
83
+   <slot>reject()</slot>
84
+   <hints>
85
+    <hint type="sourcelabel">
86
+     <x>316</x>
87
+     <y>260</y>
88
+    </hint>
89
+    <hint type="destinationlabel">
90
+     <x>286</x>
91
+     <y>274</y>
92
+    </hint>
93
+   </hints>
94
+  </connection>
95
+ </connections>
96
+</ui>

+ 36
- 0
src/session/sessionform.cpp View File

@@ -0,0 +1,36 @@
1
+/*
2
+ * This file is part of smolbote. It's copyrighted by the contributors recorded
3
+ * in the version control history of the file, available from its original
4
+ * location: https://neueland.iserlohn-fortress.net/gitea/aqua/smolbote
5
+ *
6
+ * SPDX-License-Identifier: GPL-3.0
7
+ */
8
+
9
+#include "sessionform.h"
10
+#include "ui_sessionform.h"
11
+#include <QStyle>
12
+
13
+SessionForm::SessionForm(const QString &path, QWidget *parent)
14
+    : QWidget(parent)
15
+    , ui(new Ui::SessionForm)
16
+{
17
+    ui->setupUi(this);
18
+    ui->label->setText(path);
19
+    ui->delete_toolButton->setIcon(style()->standardIcon(QStyle::SP_TrashIcon));
20
+    ui->delete_toolButton->hide();
21
+}
22
+
23
+SessionForm::~SessionForm()
24
+{
25
+    delete ui;
26
+}
27
+
28
+void SessionForm::showDetails()
29
+{
30
+    ui->delete_toolButton->show();
31
+}
32
+
33
+void SessionForm::hideDetails()
34
+{
35
+    ui->delete_toolButton->hide();
36
+}

+ 37
- 0
src/session/sessionform.h View File

@@ -0,0 +1,37 @@
1
+/*
2
+ * This file is part of smolbote. It's copyrighted by the contributors recorded
3
+ * in the version control history of the file, available from its original
4
+ * location: https://neueland.iserlohn-fortress.net/gitea/aqua/smolbote
5
+ *
6
+ * SPDX-License-Identifier: GPL-3.0
7
+ */
8
+
9
+#ifndef SMOLBOTE_SESSIONFORM_H
10
+#define SMOLBOTE_SESSIONFORM_H
11
+
12
+#include <QWidget>
13
+
14
+namespace Ui
15
+{
16
+class SessionForm;
17
+}
18
+
19
+class SessionForm : public QWidget
20
+{
21
+    Q_OBJECT
22
+
23
+    friend class SessionDialog;
24
+
25
+public:
26
+    explicit SessionForm(const QString &path, QWidget *parent = nullptr);
27
+    ~SessionForm() override;
28
+
29
+public slots:
30
+    void showDetails();
31
+    void hideDetails();
32
+
33
+private:
34
+    Ui::SessionForm *ui;
35
+};
36
+
37
+#endif // SMOLBOTE_SESSIONFORM_H

+ 41
- 0
src/session/sessionform.ui View File

@@ -0,0 +1,41 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<ui version="4.0">
3
+ <class>SessionForm</class>
4
+ <widget class="QWidget" name="SessionForm">
5
+  <property name="geometry">
6
+   <rect>
7
+    <x>0</x>
8
+    <y>0</y>
9
+    <width>711</width>
10
+    <height>34</height>
11
+   </rect>
12
+  </property>
13
+  <property name="windowTitle">
14
+   <string>Form</string>
15
+  </property>
16
+  <layout class="QHBoxLayout" name="horizontalLayout">
17
+   <property name="topMargin">
18
+    <number>0</number>
19
+   </property>
20
+   <property name="bottomMargin">
21
+    <number>0</number>
22
+   </property>
23
+   <item>
24
+    <widget class="QLabel" name="label">
25
+     <property name="text">
26
+      <string>TextLabel</string>
27
+     </property>
28
+    </widget>
29
+   </item>
30
+   <item>
31
+    <widget class="QToolButton" name="delete_toolButton">
32
+     <property name="text">
33
+      <string>...</string>
34
+     </property>
35
+    </widget>
36
+   </item>
37
+  </layout>
38
+ </widget>
39
+ <resources/>
40
+ <connections/>
41
+</ui>

+ 4
- 0
tools/format-code.sh View File

@@ -0,0 +1,4 @@
1
+#!/bin/bash
2
+
3
+# get names of staged files | filter out the header and cpp files | clang-format them
4
+git diff --staged --name-only | grep --regex="\.h\|\.cpp" | xargs clang-format -i

Loading…
Cancel
Save