|
| 1 | +import QtQuick |
| 2 | +import QtQuick.Controls |
| 3 | +import QtQuick.Layouts |
| 4 | +import Quickshell |
| 5 | +import Quickshell.Io |
| 6 | +import qs.Commons |
| 7 | +import qs.Modules.DesktopWidgets |
| 8 | +import qs.Widgets |
| 9 | + |
| 10 | +DraggableDesktopWidget { |
| 11 | + id: root |
| 12 | + property var pluginApi: null |
| 13 | + |
| 14 | + // Updated dimensions |
| 15 | + readonly property real _width: Math.round(320 * widgetScale) |
| 16 | + readonly property real _height: Math.round(200 * widgetScale) |
| 17 | + |
| 18 | + implicitWidth: _width |
| 19 | + implicitHeight: _height |
| 20 | + |
| 21 | + property string calendarVal: "" |
| 22 | + |
| 23 | + // Main data process |
| 24 | + Process { |
| 25 | + id: calProc |
| 26 | + command: ["sh", "-c", "khal list today 7d --format '{start-end-time-style} {title}' --day-format '{name}, {date}'"] |
| 27 | + running: root.pluginApi !== null |
| 28 | + stdout: StdioCollector { |
| 29 | + onTextChanged: root.calendarVal = text.trim().replace(/\n\s*\n/g, '\n') |
| 30 | + } |
| 31 | + } |
| 32 | + |
| 33 | + // Universal terminal launcher (Handles -e and -- syntax) but has the class for kitty alone |
| 34 | + Process { |
| 35 | + id: openIkhal |
| 36 | + command: [ |
| 37 | + "sh", "-c", |
| 38 | + "for term in xdg-terminal-exec kitty alacritty foot gnome-terminal konsole st xterm; do " + |
| 39 | + "if command -v $term >/dev/null 2>&1; then " + |
| 40 | + "if [ \"$term\" = \"kitty\" ]; then " + |
| 41 | + "exec kitty --class khal -e ikhal; " + |
| 42 | + "else " + |
| 43 | + "exec $term -e ikhal 2>/dev/null || exec $term -- ikhal; " + |
| 44 | + "fi; break; fi; done" |
| 45 | + ] |
| 46 | + } |
| 47 | + |
| 48 | + // Refresh every minute |
| 49 | + Timer { |
| 50 | + interval: 60000 |
| 51 | + running: root.pluginApi !== null |
| 52 | + repeat: true |
| 53 | + onTriggered: { |
| 54 | + calProc.running = false |
| 55 | + calProc.running = true |
| 56 | + } |
| 57 | + } |
| 58 | + |
| 59 | + Rectangle { |
| 60 | + anchors.fill: parent |
| 61 | + color: Color.mSurface |
| 62 | + opacity: 0.85 |
| 63 | + radius: Style.radiusM |
| 64 | + |
| 65 | + ColumnLayout { |
| 66 | + anchors.fill: parent |
| 67 | + anchors.margins: Style.marginL |
| 68 | + |
| 69 | + // Render only when API is ready to ensure translations work correctly |
| 70 | + visible: root.pluginApi !== null |
| 71 | + |
| 72 | + RowLayout { |
| 73 | + Layout.fillWidth: true |
| 74 | + |
| 75 | + NText { |
| 76 | + text: root.pluginApi.tr("widget.heading") |
| 77 | + color: Color.mOnSurfaceVariant |
| 78 | + font.pointSize: Style.fontSizeL * widgetScale |
| 79 | + Layout.fillWidth: true |
| 80 | + } |
| 81 | + |
| 82 | + NIconButton { |
| 83 | + // Strict translation: no fallback string used here |
| 84 | + icon: root.pluginApi.tr("widget.button") |
| 85 | + |
| 86 | + Layout.preferredWidth: 32 * widgetScale |
| 87 | + Layout.preferredHeight: 32 * widgetScale |
| 88 | + |
| 89 | + onClicked: { |
| 90 | + openIkhal.running = false |
| 91 | + openIkhal.running = true |
| 92 | + } |
| 93 | + } |
| 94 | + } |
| 95 | + |
| 96 | + NScrollView { |
| 97 | + Layout.fillWidth: true |
| 98 | + Layout.fillHeight: true |
| 99 | + clip: true |
| 100 | + |
| 101 | + // Force horizontal scrollbar off |
| 102 | + ScrollBar.horizontal.policy: ScrollBar.AlwaysOff |
| 103 | + |
| 104 | + NText { |
| 105 | + // Force the text width to match the ScrollView's width |
| 106 | + width: parent.width |
| 107 | + text: root.calendarVal !== "" ? root.calendarVal : root.pluginApi.tr("widget.loading") |
| 108 | + |
| 109 | + color: Color.mOnSurface |
| 110 | + font.pointSize: Style.fontSizeL * widgetScale |
| 111 | + wrapMode: Text.NoWrap |
| 112 | + elide: Text.ElideRight |
| 113 | + font.family: "Monospace" |
| 114 | + } |
| 115 | + } |
| 116 | + } |
| 117 | + } |
| 118 | +} |
0 commit comments