manatee-curl 0.0.6 → 0.0.7
raw patch · 10 files changed
+213/−56 lines, 10 filesdep ~manatee-coresetup-changed
Dependency ranges changed: manatee-core
Files
- Config/Curl.hs +39/−0
- Config/Default.hs +39/−0
- Config/Import.hs +21/−0
- Config/User.hs +19/−0
- Main.hs +6/−2
- Manatee/Extension/Curl/CurlBuffer.hs +42/−36
- Manatee/Extension/Curl/CurlView.hs +5/−14
- Manatee/Extension/Curl/Types.hs +20/−0
- Setup.hs +8/−1
- manatee-curl.cabal +14/−3
+ Config/Curl.hs view
@@ -0,0 +1,39 @@+-- Author: Andy Stewart <lazycat.manatee@gmail.com>+-- Maintainer: Andy Stewart <lazycat.manatee@gmail.com>+-- +-- Copyright (C) 2010 Andy Stewart, all rights reserved.+-- +-- This program is free software: you can redistribute it and/or modify+-- it under the terms of the GNU General Public License as published by+-- the Free Software Foundation, either version 3 of the License, or+-- any later version.+-- +-- This program is distributed in the hope that it will be useful,+-- but WITHOUT ANY WARRANTY; without even the implied warranty of+-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+-- GNU General Public License for more details.+-- +-- You should have received a copy of the GNU General Public License+-- along with this program. If not, see <http://www.gnu.org/licenses/>.++module Config.User where++-- | Default download thread number.+defaultThreadNumber :: Int+defaultThreadNumber = 8++-- | Default cache size (bytes).+-- Default is 512K.+-- This cache value is for thread, +-- max memory is bigger if you use more threads.+-- Of course, memory will release after flush cache to disk.+-- NOTE, don't set value too little, +-- it will cause too many I/O operation if cache size is less than download speed.+defaultCacheSize :: Int+defaultCacheSize = + 512 * 2 ^ 10++-- | Whether automatic start download file when startup process?+-- Default is 'False'.+autoStart :: Bool+autoStart = False
+ Config/Default.hs view
@@ -0,0 +1,39 @@+-- Author: Andy Stewart <lazycat.manatee@gmail.com>+-- Maintainer: Andy Stewart <lazycat.manatee@gmail.com>+-- +-- Copyright (C) 2010 Andy Stewart, all rights reserved.+-- +-- This program is free software: you can redistribute it and/or modify+-- it under the terms of the GNU General Public License as published by+-- the Free Software Foundation, either version 3 of the License, or+-- any later version.+-- +-- This program is distributed in the hope that it will be useful,+-- but WITHOUT ANY WARRANTY; without even the implied warranty of+-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+-- GNU General Public License for more details.+-- +-- You should have received a copy of the GNU General Public License+-- along with this program. If not, see <http://www.gnu.org/licenses/>.++module Config.Default where++-- | Default download thread number.+defaultThreadNumber :: Int+defaultThreadNumber = 8++-- | Default cache size (bytes).+-- Default is 512K.+-- This cache value is for thread, +-- max memory is bigger if you use more threads.+-- Of course, memory will release after flush cache to disk.+-- NOTE, don't set value too little, +-- it will cause too many I/O operation if cache size is less than download speed.+defaultCacheSize :: Int+defaultCacheSize = + 512 * 2 ^ 10++-- | Whether automatic start download file when startup process?+-- Default is 'False'.+autoStart :: Bool+autoStart = False
+ Config/Import.hs view
@@ -0,0 +1,21 @@+-- Author: Andy Stewart <lazycat.manatee@gmail.com>+-- Maintainer: Andy Stewart <lazycat.manatee@gmail.com>+-- +-- Copyright (C) 2010 Andy Stewart, all rights reserved.+-- +-- This program is free software: you can redistribute it and/or modify+-- it under the terms of the GNU General Public License as published by+-- the Free Software Foundation, either version 3 of the License, or+-- any later version.+-- +-- This program is distributed in the hope that it will be useful,+-- but WITHOUT ANY WARRANTY; without even the implied warranty of+-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+-- GNU General Public License for more details.+-- +-- You should have received a copy of the GNU General Public License+-- along with this program. If not, see <http://www.gnu.org/licenses/>.++module Config.Import (defaultThreadNumber, defaultCacheSize, autoStart) where ++import Config.Default
+ Config/User.hs view
@@ -0,0 +1,19 @@+-- Author: Andy Stewart <lazycat.manatee@gmail.com>+-- Maintainer: Andy Stewart <lazycat.manatee@gmail.com>+-- +-- Copyright (C) 2010 Andy Stewart, all rights reserved.+-- +-- This program is free software: you can redistribute it and/or modify+-- it under the terms of the GNU General Public License as published by+-- the Free Software Foundation, either version 3 of the License, or+-- any later version.+-- +-- This program is distributed in the hope that it will be useful,+-- but WITHOUT ANY WARRANTY; without even the implied warranty of+-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+-- GNU General Public License for more details.+-- +-- You should have received a copy of the GNU General Public License+-- along with this program. If not, see <http://www.gnu.org/licenses/>.++module Config.User where
Main.hs view
@@ -21,12 +21,16 @@ module Main where import Control.Applicative hiding (empty)+import Manatee.Core.Dynload import Manatee.Core.Render import Manatee.Core.Types import Manatee.Extension.Curl+import Manatee.Extension.Curl.Types -- | Irc client render process. main :: IO () main = - startupRender (\ pagePath options client pageId -> - PageBufferWrap <$> curlBufferNew pagePath options client pageId)+ startupRender + (\ pagePath options client pageId customize -> + PageBufferWrap <$> curlBufferNew pagePath options client pageId customize)+ curlCustomizeNew
Manatee/Extension/Curl/CurlBuffer.hs view
@@ -20,6 +20,7 @@ {-# LANGUAGE ScopedTypeVariables, DeriveDataTypeable #-} module Manatee.Extension.Curl.CurlBuffer where +import Config.Import import Control.Applicative import Control.Concurrent import Control.Concurrent.STM @@ -36,6 +37,7 @@ import Graphics.UI.Gtk.ModelView.TreeSortable import Manatee.Core.Config import Manatee.Core.DBus+import Manatee.Core.Dynload import Manatee.Core.Types import Manatee.Extension.Curl.PageMode import Manatee.Extension.Curl.Types@@ -74,6 +76,7 @@ ,curlBufferDownloadStatusPixbuf :: DownloadStatusPixbuf ,curlBufferMode :: PageMode ,curlBufferBroadcastChannel :: TChan CurlTChanSignal+ ,curlBufferCustomize :: CurlCustomize } deriving Typeable @@ -85,7 +88,7 @@ class CurlFileInfoClass a where getColumnTitle :: a -> String -- get title for treeColumn getCellXAlign :: a -> Float -- get x align for cell- getCellMinWidth :: a -> Maybe Int -- get min width for cell+ getCellWidthChars :: a -> Int -- get min width for cell getCellMaxWidth :: a -> Maybe Int -- get max width for cell getCellText :: a -> DownloadFile -> IO String -- get text for cell compareRow :: a -> DownloadFile -> DownloadFile -> IO Ordering -- compare row for treeView@@ -109,14 +112,14 @@ getCellXAlign DFThread = 1.0 getCellXAlign DFURL = 0.0 - getCellMinWidth DFName = Nothing- getCellMinWidth DFSize = Just 70- getCellMinWidth DFDownloadSize = Just 70- getCellMinWidth DFRestSize = Just 70- getCellMinWidth DFSpeed = Just 80- getCellMinWidth DFRestTime = Nothing- getCellMinWidth DFThread = Nothing- getCellMinWidth DFURL = Nothing+ getCellWidthChars DFName = -1+ getCellWidthChars DFSize = length ("xxx.xx KB" :: String)+ getCellWidthChars DFDownloadSize = length ("xxx.xx KB" :: String)+ getCellWidthChars DFRestSize = length ("xxx.xx KB" :: String)+ getCellWidthChars DFSpeed = length ("xxx.xx Kb/s" :: String)+ getCellWidthChars DFRestTime = length ("xxxd xxh xxm xxs" :: String)+ getCellWidthChars DFThread = -1+ getCellWidthChars DFURL = -1 getCellMaxWidth DFName = Just 300 getCellMaxWidth DFSize = Nothing@@ -165,10 +168,6 @@ compareRow DFURL row1 row2 = liftA2 compare (downloadFileGetURL row1) (downloadFileGetURL row2) --- | Default download thread number.-defaultThreadNumber :: Int-defaultThreadNumber = 4- -- | Default download directory. defaultDownloadDir :: FilePath defaultDownloadDir = @@ -179,25 +178,12 @@ defaultCacheDir = "download/cache" --- | Default cache size (bytes).--- Default is 512K.--- This cache value is for thread, --- max memory is bigger if you use more threads.--- Of course, memory will release after flush cache to disk.--- NOTE, don't set value too little, --- it will cause too many I/O operation if cache size is less than download speed.-defaultCacheSize :: Int-defaultCacheSize = - 512 * 2 ^ 10---- | Whether automatic start download file when startup process?--- Default is 'False'.-autoStart :: Bool-autoStart = False- -- | New.-curlBufferNew :: FilePath -> [String] -> Client -> PageId -> IO CurlBuffer-curlBufferNew name urls client pageId = do+curlBufferNew :: FilePath -> [String] -> Client -> PageId -> CustomizeWrap -> IO CurlBuffer+curlBufferNew name urls client pageId c = do+ -- Get customize option.+ let customize = castCustomize c+ -- Create directory if missing. configDir <- getConfigDirectory createDirectoryIfMissing True (configDir </> defaultDownloadDir)@@ -219,6 +205,7 @@ <*> pixbufNewFromIcon "gtk-cancel" 16) <*> pure curlMode <*> (newTChanIO :: IO (TChan CurlTChanSignal)) + <*> pure customize -- Scan cache file to resume. curlBufferScanCacheFile buffer@@ -254,7 +241,11 @@ -- | Add download. curlBufferAddDownload :: CurlBuffer -> String -> IO ()-curlBufferAddDownload curlBuffer uri = +curlBufferAddDownload curlBuffer@(CurlBuffer + {curlBufferCustomize =+ CurlCustomize + {curlCustomizeDefaultThreadNumber = threadNumberTVar}}) + uri = case parseURI uri of Nothing -> putStrLn $ "Malformed URI : " ++ uri Just _ -> do@@ -292,6 +283,7 @@ writeTVarIO (dfSize downloadFile) size -- Update DownloadBuffer.+ defaultThreadNumber <- readTVarIO threadNumberTVar buffers <- initDownloadBuffers size defaultThreadNumber writeTVarIO (dfBuffers downloadFile) buffers @@ -342,7 +334,10 @@ -- | Scan cache file to resume. curlBufferScanCacheFile :: CurlBuffer -> IO ()-curlBufferScanCacheFile curlBuffer = +curlBufferScanCacheFile curlBuffer@(CurlBuffer + {curlBufferCustomize = + CurlCustomize + {curlCustomizeAutoStart = autoStartTVar}}) = forkIO_ $ do -- Get log pathes. logPathes <- getLogPathes@@ -350,6 +345,7 @@ -- Scan log patch to pick cache information. forM_ logPathes $ \ logPath -> forkIO_ $ do+ autoStart <- readTVarIO autoStartTVar -- Get DownloadLog. let emptyLog = DownloadLog "" "" 0 M.empty downloadLog@(DownloadLog {dlBuffers = logBufferMap}) <- readConfig logPath emptyLog@@ -489,6 +485,7 @@ writeTVarIO (dbThreadId downloadBuffer) (Just tId) let range = show start ++ "-" ++ show end lock = dfFinishLock downloadFile+ cacheSizeTVar = curlCustomizeDefaultCacheSize $ curlBufferCustomize curlBuffer -- Init curl. h <- initialize@@ -504,7 +501,7 @@ setopt h (CurlRange range) setopt h (CurlNoProgress False) -- setopt h (CurlVerbose True) -- debug- setopt h (CurlWriteFunction (gather ref downloadFile downloadBuffer))+ setopt h (CurlWriteFunction (gather ref cacheSizeTVar downloadFile downloadBuffer)) setopt h (CurlProgressData nullPtr) setopt h (CurlProgressFunction (\ _ _ download _ _ -> do@@ -584,8 +581,8 @@ tryPutMVar lock DownloadFinish >> return () -- | Gather network data.-gather :: TVar BufferCache -> DownloadFile -> DownloadBuffer -> WriteFunction-gather tvar downloadFile downloadBuffer = +gather :: TVar BufferCache -> TVar Int -> DownloadFile -> DownloadBuffer -> WriteFunction+gather tvar cacheSizeTVar downloadFile downloadBuffer = writer $ \(srcPtr, bytes) -> do -- Copy memory chunks of data into bytestring. BufferCache destPtr offset <- readTVarIO tvar@@ -593,6 +590,7 @@ newDestPtr <- reallocBytes destPtr newOffset S.memcpy (newDestPtr `plusPtr` offset) srcPtr (fromIntegral bytes) + defaultCacheSize <- readTVarIO cacheSizeTVar if newOffset >= defaultCacheSize -- Flush cache to disk if data reach cache size. then do@@ -830,3 +828,11 @@ <*> newTVarIO cacheSize <*> newTVarIO isFinish) +-- | Curl customize new.+curlCustomizeNew :: IO CustomizeWrap+curlCustomizeNew =+ fmap CustomizeWrap $+ CurlCustomize <$> newTVarIO defaultThreadNumber+ <*> newTVarIO defaultCacheSize+ <*> newTVarIO autoStart+
Manatee/Extension/Curl/CurlView.hs view
@@ -45,6 +45,7 @@ import Manatee.Toolkit.Gtk.Gtk import Manatee.Toolkit.Gtk.ModelView import Manatee.Toolkit.Gtk.ScrolledWindow+import Paths_manatee_curl import System.Directory import System.FilePath import System.GIO@@ -69,6 +70,7 @@ pageBufferClient = curlBufferClient pageBufferCreateView a pId = PageViewWrap <$> curlViewNew a pId pageBufferMode = curlBufferMode+ pageBufferPackageName _ = fmap takeFileName getDataDir instance PageView CurlView where pageViewBuffer = PageBufferWrap . curlViewBuffer@@ -254,12 +256,13 @@ let name = getColumnTitle info tvc <- treeViewAddColumnWithTitle treeView name sortId- getCellMinWidth info - ?>= \width -> set tvc [treeViewColumnMinWidth := width]+ -- Set max width. getCellMaxWidth info ?>= \width -> set tvc [treeViewColumnMaxWidth := width] cell <- cellRendererTextNew+ -- Set min width request. + set cell [cellTextWidthChars := getCellWidthChars info] treeViewColumnPackStart tvc cell True curlViewSetCellText tvc cell model sortModel info@@ -539,16 +542,4 @@ ,("7", curlViewSortByRestTime) ,("8", curlViewSortByThread) ,("9", curlViewSortByUrl)- ,("t", curlViewTest) ]--curlViewTest :: CurlView -> IO ()-curlViewTest view@(CurlView {curlViewBuffer = buffer}) = do- let urls = ["http://3c.media.v4.skyrock.net/music/3c2/316/3c2316b00657d412725ce07c1c7a3900.mp3"]- forM_ urls $ \ url -> do- files <- readTVarIO $ curlBufferFileInfos buffer- if url `elem` map dfURL files- then pageViewUpdateOutputStatus view ("Has exist " ++ url) Nothing- else curlBufferAddDownload buffer url--
Manatee/Extension/Curl/Types.hs view
@@ -30,6 +30,26 @@ import Data.Typeable import Foreign import Graphics.UI.Gtk.Gdk.Pixbuf+import Manatee.Core.Types+import Manatee.Toolkit.General.STM+import Unsafe.Coerce++data CurlCustomize =+ CurlCustomize {curlCustomizeDefaultThreadNumber :: TVar Int+ ,curlCustomizeDefaultCacheSize :: TVar Int+ ,curlCustomizeAutoStart :: TVar Bool+ }+ deriving Typeable++instance Customize CurlCustomize where+ customizeConfigFile _ = "Curl.hs"+ customizeLoad a =+ [("defaultThreadNumber"+ ,\v -> writeTVarIO (curlCustomizeDefaultThreadNumber a) (unsafeCoerce v :: Int))+ ,("defaultCacheSize"+ ,\v -> writeTVarIO (curlCustomizeDefaultCacheSize a) (unsafeCoerce v :: Int))+ ,("autoStart"+ ,\v -> writeTVarIO (curlCustomizeAutoStart a) (unsafeCoerce v :: Bool))] data DownloadFile = DownloadFile {dfURL :: String
Setup.hs view
@@ -16,8 +16,10 @@ -- You should have received a copy of the GNU General Public License -- along with this program. If not, see <http://www.gnu.org/licenses/>. +import Distribution.PackageDescription import Distribution.Simple import Manatee.Core.Config+import Manatee.Core.Dynload import Manatee.Core.Types import Manatee.Toolkit.General.List import Manatee.Toolkit.General.Map@@ -27,8 +29,13 @@ main = defaultMainWithHooks simpleUserHooks {+ -- Generate User.hs and Import.hs before configure.+ preConf = \ _ _ -> do+ generateConfig "Curl.hs"+ ["defaultThreadNumber", "defaultCacheSize", "autoStart"]+ return emptyHookedBuildInfo -- Update Rule after install successful.- postInst = \ _ _ _ _ -> do+ ,postInst = \ _ _ _ _ -> do -- Update PageTypeRule. (PageTypeRule typeRule) <- readConfig pageTypeRulePath (PageTypeRule M.empty) writeConfig pageTypeRulePath (PageTypeRule (M.insert "PageCurl" "manatee-curl" typeRule))
manatee-curl.cabal view
@@ -1,5 +1,5 @@ name: manatee-curl-version: 0.0.6+version: 0.0.7 Cabal-Version: >= 1.6 license: GPL-3 license-file: LICENSE@@ -7,8 +7,12 @@ synopsis: Download Manager extension for Manatee. description: manatee-curl is multithreads download manager extension for Manatee (Haskell/Gtk+ Integrated Live Environment) .- Video at (Select 720p HD) at : <http://www.youtube.com/watch?v=weS6zys3U8k> <http://v.youku.com/v_show/id_XMjI2MDMzODI4.html>+ Default configuration template at Config\/Curl.hs, copy to directory `HOME/.manatee/config/`. .+ Note, you need re-install package to start the configuration file take effect the next time,+ .+ Video at (Select 720p HD) at : <http://www.youtube.com/watch?v=weS6zys3U8k> <http://www.youtube.com/watch?v=A3DgKDVkyeM> <http://v.youku.com/v_show/id_XMjI2MDMzODI4.html>+ . Screenshots at : <http://goo.gl/MkVw> . Manual at : <http://haskell.org/haskellwiki/Manatee>@@ -25,12 +29,15 @@ tested-with: GHC==6.12.3 build-type: Custom +data-dir: ""+data-files: Config/Curl.hs + Source-Repository head type: darcs location: http://patch-tag.com/r/AndyStewart/manatee-curl Library- build-depends: base >= 4 && < 5, manatee-core >= 0.0.6, dbus-client >= 0.3 && < 0.4, stm >= 2.1.2.0,+ build-depends: base >= 4 && < 5, manatee-core >= 0.0.7, dbus-client >= 0.3 && < 0.4, stm >= 2.1.2.0, containers >= 0.3.0.0, gtk-serialized-event >= 0.12.0, gtk >= 0.12.0, text >= 0.7.1.0, mtl >= 1.1.0.2, old-time, old-locale, glib >= 0.12.0, gio >= 0.12.0, filepath >= 1.1.0.3, utf8-string >= 0.3.4, bytestring, network, curl >= 1.3.5, directory,@@ -42,6 +49,10 @@ Manatee.Extension.Curl.CurlView Manatee.Extension.Curl.Types other-modules: + Paths_manatee_curl+ Config.Default + Config.User + Config.Import extensions: ghc-options: -fwarn-unused-matches -fwarn-unused-binds -fwarn-unused-imports -fwarn-overlapping-patterns -fwarn-duplicate-exports -fwarn-unrecognised-pragmas -fwarn-hi-shadowing