mirror of
https://github.com/hyprwm/hyprland-qtutils.git
synced 2024-12-25 08:09:50 +01:00
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:
parent
9694274192
commit
b5b415a168
9 changed files with 32 additions and 7 deletions
|
@ -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];
|
||||
|
|
|
@ -83,6 +83,7 @@ ApplicationWindow {
|
|||
text: dialog.dialogButtons[index]
|
||||
onClicked: (e) => {
|
||||
dialog.onButtonPress(dialog.dialogButtons[index])
|
||||
window.close()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
9
utils/update-screen/Dialog.cpp
Normal file
9
utils/update-screen/Dialog.cpp
Normal file
|
@ -0,0 +1,9 @@
|
|||
#include "Dialog.hpp"
|
||||
|
||||
CDialog::CDialog(QObject* parent) : QObject(parent) {
|
||||
;
|
||||
}
|
||||
|
||||
void CDialog::onButtonPress(QString buttonName) {
|
||||
;
|
||||
}
|
1
utils/update-screen/Dialog.hpp
Symbolic link
1
utils/update-screen/Dialog.hpp
Symbolic link
|
@ -0,0 +1 @@
|
|||
../dialog/Dialog.hpp
|
|
@ -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);
|
||||
}
|
||||
|
|
1
utils/update-screen/dialogMain.qml
Symbolic link
1
utils/update-screen/dialogMain.qml
Symbolic link
|
@ -0,0 +1 @@
|
|||
../dialog/main.qml
|
|
@ -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();
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue