Skip to content

Commit b5b415a

Browse files
committedDec 11, 2024·
all: unify dialog handling
this sucks, but I don't know how to do this better tbh. Will definitely not work if we want to have multiple dialogs at once.
1 parent 9694274 commit b5b415a

File tree

9 files changed

+32
-7
lines changed

9 files changed

+32
-7
lines changed
 

‎utils/dialog/main.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ int main(int argc, char* argv[]) {
1414
qputenv("QT_LOGGING_RULES", QByteArray("*.debug=false;qml=false"));
1515

1616
QString appTitle;
17-
auto dialog = new CDialog();
17+
auto dialog = new CDialog();
1818

1919
for (int i = 1; i < argc; ++i) {
2020
std::string_view arg = argv[i];

‎utils/dialog/main.qml

+1
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ ApplicationWindow {
8383
text: dialog.dialogButtons[index]
8484
onClicked: (e) => {
8585
dialog.onButtonPress(dialog.dialogButtons[index])
86+
window.close()
8687
}
8788
}
8889
}

‎utils/update-screen/CMakeLists.txt

+3-1
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,15 @@ qt_standard_project_setup(REQUIRES 6.5)
1414

1515
qt_add_executable(hyprland-update-screen
1616
main.cpp
17+
Dialog.cpp
18+
Dialog.hpp
1719
UpdateScreen.cpp
1820
)
1921

2022
qt_add_qml_module(hyprland-update-screen
2123
URI org.hyprland.update-screen
2224
VERSION 1.0
23-
QML_FILES main.qml
25+
QML_FILES main.qml dialogMain.qml
2426
)
2527

2628
target_link_libraries(hyprland-update-screen PRIVATE

‎utils/update-screen/Dialog.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#include "Dialog.hpp"
2+
3+
CDialog::CDialog(QObject* parent) : QObject(parent) {
4+
;
5+
}
6+
7+
void CDialog::onButtonPress(QString buttonName) {
8+
;
9+
}

‎utils/update-screen/Dialog.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../dialog/Dialog.hpp

‎utils/update-screen/UpdateScreen.cpp

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#include "UpdateScreen.hpp"
2+
23
#include <print>
4+
35
#include <hyprutils/string/String.hpp>
46
#include <hyprutils/os/Process.hpp>
57
using namespace Hyprutils::String;
@@ -9,9 +11,6 @@ CUpdateScreen::CUpdateScreen(QObject* parent) : QObject(parent) {
911
}
1012

1113
void CUpdateScreen::onButtonPress(QString buttonName) {
12-
if (buttonName == "dontshow") {
13-
Hyprutils::OS::CProcess proc("hyprland-dialog", {"--title", "Information", "--text", "If you wish to disable this dialog, set ecosystem:no_update_news to true in your Hyprland config.", "--buttons", "ok"});
14-
proc.runAsync();
15-
} else if (buttonName == "quit")
14+
if (buttonName == "quit")
1615
exit(0);
1716
}

‎utils/update-screen/dialogMain.qml

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../dialog/main.qml

‎utils/update-screen/main.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <qquickstyle.h>
77
#include <qtenvironmentvariables.h>
88
#include <QQmlContext>
9+
#include "Dialog.hpp"
910

1011
using namespace Hyprutils::String;
1112

@@ -46,8 +47,16 @@ int main(int argc, char* argv[]) {
4647
if (qEnvironmentVariableIsEmpty("QT_QUICK_CONTROLS_STYLE"))
4748
QQuickStyle::setStyle("org.kde.desktop");
4849

50+
// This entire mechanism fucking sucks,
51+
// but I also suck at qml and I want to avoid spawning a new process as it takes a while.
52+
auto popup = new CDialog();
53+
popup->title = "Information";
54+
popup->text = "If you wish to disable this dialog, set ecosystem:no_update_news to true in your Hyprland config.";
55+
popup->buttons = {"ok"};
56+
4957
QQmlApplicationEngine engine;
5058
engine.rootContext()->setContextProperty("updateScreen", dialog);
59+
engine.rootContext()->setContextProperty("dialog", popup);
5160
engine.load("qrc:/qt/qml/org/hyprland/update-screen/main.qml");
5261

5362
return app.exec();

‎utils/update-screen/main.qml

+4-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ pragma ComponentBehavior: Bound
33
import QtQuick
44
import QtQuick.Controls
55
import QtQuick.Layouts
6+
import './'
67

78
ApplicationWindow {
89
id: window
@@ -81,7 +82,9 @@ ApplicationWindow {
8182
Button {
8283
text: "Don't show this when I update"
8384
onClicked: (e) => {
84-
updateScreen.onButtonPress("dontshow");
85+
var component = Qt.createComponent("dialogMain.qml")
86+
var newWindow = component.createObject(window)
87+
newWindow.show()
8588
}
8689
}
8790

0 commit comments

Comments
 (0)
Please sign in to comment.