aboutsummaryrefslogtreecommitdiffhomepage
path: root/Types
diff options
context:
space:
mode:
authorSean Whitton <spwhitton@spwhitton.name>2017-02-26 19:59:17 -0700
committerSean Whitton <spwhitton@spwhitton.name>2017-02-26 19:59:17 -0700
commit5bb55ee72688f46ca7b92a8f59d121e2ec1622ba (patch)
tree2a857b7f32d5afe5b72285d9404422459ed504fe /Types
parent4f6d803ad866dd2d201ac7098aa7cd51ad66c981 (diff)
downloadsscan-5bb55ee72688f46ca7b92a8f59d121e2ec1622ba.tar.gz
add ScanSess type & refactor
Diffstat (limited to 'Types')
-rw-r--r--Types/State.hs37
1 files changed, 21 insertions, 16 deletions
diff --git a/Types/State.hs b/Types/State.hs
index e37d7a8..68ef188 100644
--- a/Types/State.hs
+++ b/Types/State.hs
@@ -33,26 +33,31 @@ type DPI = Int
data OutputFormat = PDF | PNG
deriving (Eq, Show)
+-- | An active multi-page scanning session
+data ScanSess = ScanSess
+ FilePath -- ^ session's tmpdir
+ Int -- ^ total pages scanner thus far
+
-- | Application state
data St =
- St { _stScanningSession :: Maybe FilePath -- ^ if a session is in
- -- progress, accmulate
- -- scans in this dir
- , _stPageCount :: Maybe Int -- ^ if a session is in
- -- progress, the number of
- -- pages scanned thus far
- , _stOCR :: Bool -- ^ whether to use OCRmyPDF
- , _stColour :: Colour
- , _stPaper :: Paper -- ^ currently selected paper size
- , _stDefaultPaper :: Paper -- ^ locale's default paper size
- , _stDPI :: DPI
- , _stOutFormat :: OutputFormat
- , _stOutdir :: FilePath -- ^ where to save final PDFs
+ St { _stScanSess :: Maybe ScanSess
+ , _stOCR :: Bool -- ^ whether to use OCRmyPDF
+ , _stColour :: Colour
+ , _stPaper :: Paper -- ^ currently selected paper size
+ , _stDefaultPaper :: Paper -- ^ locale's default paper size
+ , _stDPI :: DPI
+ , _stOutFormat :: OutputFormat
+ , _stOutdir :: FilePath -- ^ where to save final PDFs
}
-
--- other device-specific scanimage options we could support: --swdespeck; --color-filter; --depth
+-- other device-specific scanimage options the old script supported: --swdespeck; --color-filter; --depth
makeLenses ''St
ifScanSess :: St -> a -> a -> a
-ifScanSess st a b = if isJust $ st^.stScanningSession then a else b
+ifScanSess st a b = if isJust $ st^.stScanSess then a else b
+
+-- | Update a state when there is no scanning session in progress (the
+-- state should not be changed when some pages have already been
+-- scanned)
+updateSt :: St -> (St -> St) -> St
+updateSt st f = ifScanSess st st (f st)