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.
This commit is contained in:
Vaxry 2024-12-11 17:21:40 +00:00
parent 9694274192
commit b5b415a168
9 changed files with 32 additions and 7 deletions

View file

@ -83,6 +83,7 @@ ApplicationWindow {
text: dialog.dialogButtons[index]
onClicked: (e) => {
dialog.onButtonPress(dialog.dialogButtons[index])
window.close()
}
}
}

View file

@ -14,13 +14,15 @@ qt_standard_project_setup(REQUIRES 6.5)
qt_add_executable(hyprland-update-screen
main.cpp
Dialog.cpp
Dialog.hpp
UpdateScreen.cpp
)
qt_add_qml_module(hyprland-update-screen
URI org.hyprland.update-screen
VERSION 1.0
QML_FILES main.qml
QML_FILES main.qml dialogMain.qml
)
target_link_libraries(hyprland-update-screen PRIVATE

View file

@ -0,0 +1,9 @@
#include "Dialog.hpp"
CDialog::CDialog(QObject* parent) : QObject(parent) {
;
}
void CDialog::onButtonPress(QString buttonName) {
;
}

View file

@ -0,0 +1 @@
../dialog/Dialog.hpp

View file

@ -1,5 +1,7 @@
#include "UpdateScreen.hpp"
#include <print>
#include <hyprutils/string/String.hpp>
#include <hyprutils/os/Process.hpp>
using namespace Hyprutils::String;
@ -9,9 +11,6 @@ CUpdateScreen::CUpdateScreen(QObject* parent) : QObject(parent) {
}
void CUpdateScreen::onButtonPress(QString buttonName) {
if (buttonName == "dontshow") {
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"});
proc.runAsync();
} else if (buttonName == "quit")
if (buttonName == "quit")
exit(0);
}

View file

@ -0,0 +1 @@
../dialog/main.qml

View file

@ -6,6 +6,7 @@
#include <qquickstyle.h>
#include <qtenvironmentvariables.h>
#include <QQmlContext>
#include "Dialog.hpp"
using namespace Hyprutils::String;
@ -46,8 +47,16 @@ int main(int argc, char* argv[]) {
if (qEnvironmentVariableIsEmpty("QT_QUICK_CONTROLS_STYLE"))
QQuickStyle::setStyle("org.kde.desktop");
// This entire mechanism fucking sucks,
// but I also suck at qml and I want to avoid spawning a new process as it takes a while.
auto popup = new CDialog();
popup->title = "Information";
popup->text = "If you wish to disable this dialog, set ecosystem:no_update_news to true in your Hyprland config.";
popup->buttons = {"ok"};
QQmlApplicationEngine engine;
engine.rootContext()->setContextProperty("updateScreen", dialog);
engine.rootContext()->setContextProperty("dialog", popup);
engine.load("qrc:/qt/qml/org/hyprland/update-screen/main.qml");
return app.exec();

View file

@ -3,6 +3,7 @@ pragma ComponentBehavior: Bound
import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
import './'
ApplicationWindow {
id: window
@ -81,7 +82,9 @@ ApplicationWindow {
Button {
text: "Don't show this when I update"
onClicked: (e) => {
updateScreen.onButtonPress("dontshow");
var component = Qt.createComponent("dialogMain.qml")
var newWindow = component.createObject(window)
newWindow.show()
}
}