Skip to content

Commit df79e95

Browse files
committed
ff-qtah: Add postpone action
1 parent e7d91cb commit df79e95

File tree

3 files changed

+46
-14
lines changed

3 files changed

+46
-14
lines changed

ff-qtah/FF/Qt/DateComponent.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
module FF.Qt.DateComponent (DateComponent (..), new, setDate) where
66

77
import Data.Time (Day, toGregorian)
8+
import Foreign.Hoppy.Runtime (toGc)
89
import Graphics.UI.Qtah.Core.QDate qualified as QDate
910
import Graphics.UI.Qtah.Widgets.QAbstractSpinBox qualified as QAbstractSpinBox
1011
import Graphics.UI.Qtah.Widgets.QBoxLayout qualified as QBoxLayout
@@ -56,7 +57,7 @@ setDate this day =
5657
QWidget.show this.date
5758
QWidget.hide this.add
5859
QWidget.show this.remove
59-
qdate <- QDate.newWithYmd (fromInteger y) m d
60+
qdate <- toGc =<< QDate.newWithYmd (fromInteger y) m d
6061
QDateTimeEdit.setDate this.date qdate
6162
Nothing -> do
6263
-- TODO replace with button "add date"

ff-qtah/FF/Qt/MainWindow.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ setTaskView taskWidget item = do
160160
hPutStrLn stderr $ "internal error" ++ prettyCallStack callStack
161161
Task -> do
162162
noteId <- DocId @Note <$> TaskListWidget.getId item
163-
TaskWidget.update taskWidget noteId
163+
TaskWidget.reload taskWidget noteId
164164
QWidget.show taskWidget.parent
165165

166166
showAboutProgram :: (QWidgetPtr mainWindow) => mainWindow -> String -> IO ()

ff-qtah/FF/Qt/TaskWidget.hs

Lines changed: 43 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
1+
{-# LANGUAGE BlockArguments #-}
12
{-# LANGUAGE NamedFieldPuns #-}
23
{-# LANGUAGE OverloadedRecordDot #-}
34

45
module FF.Qt.TaskWidget (
56
TaskWidget (parent),
67
new,
7-
update,
8+
reload,
89
) where
910

10-
-- global
11+
import Data.IORef (IORef, atomicWriteIORef, newIORef, readIORef)
1112
import Foreign.Hoppy.Runtime (toGc)
1213
import Graphics.UI.Qtah.Core.Types (QtAlignmentFlag (AlignTop))
14+
import Graphics.UI.Qtah.Signal (connect_)
15+
import Graphics.UI.Qtah.Widgets.QAbstractButton qualified as QAbstractButton
1316
import Graphics.UI.Qtah.Widgets.QBoxLayout qualified as QBoxLayout
1417
import Graphics.UI.Qtah.Widgets.QFormLayout qualified as QFormLayout
1518
import Graphics.UI.Qtah.Widgets.QFrame (QFrame)
@@ -18,25 +21,24 @@ import Graphics.UI.Qtah.Widgets.QHBoxLayout qualified as QHBoxLayout
1821
import Graphics.UI.Qtah.Widgets.QLabel (QLabel)
1922
import Graphics.UI.Qtah.Widgets.QLabel qualified as QLabel
2023
import Graphics.UI.Qtah.Widgets.QPushButton qualified as QPushButton
21-
import Graphics.UI.Qtah.Widgets.QScrollArea (QScrollArea)
24+
import Graphics.UI.Qtah.Widgets.QScrollArea (QScrollArea, setWidget)
2225
import Graphics.UI.Qtah.Widgets.QScrollArea qualified as QScrollArea
2326
import Graphics.UI.Qtah.Widgets.QSizePolicy (QSizePolicy, QSizePolicyPolicy)
2427
import Graphics.UI.Qtah.Widgets.QSizePolicy qualified as QSizePolicy
2528
import Graphics.UI.Qtah.Widgets.QWidget qualified as QWidget
2629
import RON.Storage.FS (runStorage)
2730
import RON.Storage.FS qualified as Storage
2831

29-
-- project
30-
import FF (fromRgaM, viewNote)
32+
import FF (cmdPostpone, fromRgaM, viewNote)
3133
import FF.Types (
3234
Entity (..),
35+
EntityDoc,
3336
Note (..),
3437
NoteId,
3538
View (NoteView, note),
3639
loadNote,
3740
)
3841

39-
-- package
4042
import FF.Qt.DateComponent (DateComponent)
4143
import FF.Qt.DateComponent qualified as DateComponent
4244

@@ -48,14 +50,15 @@ data TaskWidget = TaskWidget
4850
, storage :: Storage.Handle
4951
, start :: DateComponent
5052
, end :: DateComponent
53+
, noteId :: IORef (Maybe NoteId)
5154
}
5255

5356
new :: Storage.Handle -> IO TaskWidget
5457
new storage = do
5558
parent <- QScrollArea.new
5659

5760
innerWidget <- QFrame.new
58-
QScrollArea.setWidget parent innerWidget
61+
setWidget parent innerWidget
5962

6063
textContent <- QLabel.new
6164
QWidget.setSizePolicy textContent
@@ -83,11 +86,39 @@ new storage = do
8386
QBoxLayout.addStretch actions
8487
QFormLayout.addRowLayout form actions
8588

86-
pure TaskWidget{parent, innerWidget, textContent, storage, start, end}
87-
88-
update :: TaskWidget -> NoteId -> IO ()
89-
update this noteId = do
90-
Entity{entityVal} <- runStorage this.storage $ loadNote noteId >>= viewNote
89+
noteId <- newIORef Nothing
90+
91+
let this =
92+
TaskWidget
93+
{ parent
94+
, innerWidget
95+
, textContent
96+
, storage
97+
, start
98+
, end
99+
, noteId
100+
}
101+
102+
connect_ postpone QAbstractButton.clickedSignal $ postponeSlot this
103+
104+
pure this
105+
106+
postponeSlot :: TaskWidget -> Bool -> IO ()
107+
postponeSlot this _checked = do
108+
mNoteId <- readIORef this.noteId
109+
case mNoteId of
110+
Just noteId ->
111+
runStorage this.storage (cmdPostpone noteId) >>= update this
112+
Nothing -> pure ()
113+
114+
reload :: TaskWidget -> NoteId -> IO ()
115+
reload this noteId = do
116+
atomicWriteIORef this.noteId $ Just noteId
117+
runStorage this.storage (loadNote noteId) >>= update this
118+
119+
update :: TaskWidget -> EntityDoc Note -> IO ()
120+
update this noteDoc = do
121+
Entity{entityVal} <- runStorage this.storage $ viewNote noteDoc
91122
let NoteView{note} = entityVal
92123
let Note{note_text, note_start, note_end} = note
93124
QLabel.setText this.textContent $ fromRgaM note_text

0 commit comments

Comments
 (0)