Skip to content

Commit

Permalink
all: unify dialog handling
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
vaxerski committed Dec 11, 2024
1 parent 9694274 commit 282c2ba
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 7 deletions.
2 changes: 1 addition & 1 deletion utils/dialog/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ int main(int argc, char* argv[]) {
qputenv("QT_LOGGING_RULES", QByteArray("*.debug=false;qml=false"));

QString appTitle;
auto dialog = new CDialog();
auto dialog = new CDialog();

for (int i = 1; i < argc; ++i) {
std::string_view arg = argv[i];
Expand Down
1 change: 1 addition & 0 deletions utils/dialog/main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ ApplicationWindow {
text: dialog.dialogButtons[index]
onClicked: (e) => {
dialog.onButtonPress(dialog.dialogButtons[index])
window.close()
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion utils/update-screen/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 3 additions & 4 deletions utils/update-screen/UpdateScreen.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "UpdateScreen.hpp"

#include <print>

#include <hyprutils/string/String.hpp>
#include <hyprutils/os/Process.hpp>
using namespace Hyprutils::String;
Expand All @@ -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);
}
9 changes: 9 additions & 0 deletions utils/update-screen/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <qquickstyle.h>
#include <qtenvironmentvariables.h>
#include <QQmlContext>
#include "Dialog.hpp"

using namespace Hyprutils::String;

Expand Down Expand Up @@ -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();
Expand Down
5 changes: 4 additions & 1 deletion utils/update-screen/main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ pragma ComponentBehavior: Bound
import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
import './'

ApplicationWindow {
id: window
Expand Down Expand Up @@ -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()
}
}

Expand Down

0 comments on commit 282c2ba

Please sign in to comment.