manatee-curl 0.0.5 → 0.0.6
raw patch · 3 files changed
+57/−13 lines, 3 filesdep +dbus-coredep ~manatee-core
Dependencies added: dbus-core
Dependency ranges changed: manatee-core
Files
- Manatee/Extension/Curl/CurlBuffer.hs +35/−6
- Manatee/Extension/Curl/CurlView.hs +17/−4
- manatee-curl.cabal +5/−3
Manatee/Extension/Curl/CurlBuffer.hs view
@@ -16,6 +16,7 @@ -- You should have received a copy of the GNU General Public License -- along with this program. If not, see <http://www.gnu.org/licenses/>. +{-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE ScopedTypeVariables, DeriveDataTypeable #-} module Manatee.Extension.Curl.CurlBuffer where @@ -34,11 +35,13 @@ import Graphics.UI.Gtk.General.General import Graphics.UI.Gtk.ModelView.TreeSortable import Manatee.Core.Config+import Manatee.Core.DBus import Manatee.Core.Types import Manatee.Extension.Curl.PageMode import Manatee.Extension.Curl.Types import Manatee.Toolkit.General.Basic import Manatee.Toolkit.General.Concurrent+import Manatee.Toolkit.General.DBus import Manatee.Toolkit.General.List import Manatee.Toolkit.General.Maybe import Manatee.Toolkit.General.Misc@@ -83,6 +86,7 @@ getColumnTitle :: a -> String -- get title for treeColumn getCellXAlign :: a -> Float -- get x align for cell getCellMinWidth :: a -> Maybe 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 @@ -114,6 +118,15 @@ getCellMinWidth DFThread = Nothing getCellMinWidth DFURL = Nothing + getCellMaxWidth DFName = Just 300+ getCellMaxWidth DFSize = Nothing+ getCellMaxWidth DFDownloadSize = Nothing+ getCellMaxWidth DFRestSize = Nothing+ getCellMaxWidth DFSpeed = Nothing+ getCellMaxWidth DFRestTime = Nothing+ getCellMaxWidth DFThread = Nothing+ getCellMaxWidth DFURL = Nothing+ getCellText DFName file = downloadFileGetFileName file getCellText DFSize file = fmap formatSize $ downloadFileGetSize file getCellText DFDownloadSize file = fmap formatSize $ downloadFileGetDownloadSize file@@ -221,8 +234,24 @@ when (url `notElem` logUrls) $ curlBufferAddDownload buffer url + -- Listen DBus signal.+ daemonClient <- mkSessionClientWithName (packGenericBusName "curl")+ mkGenericDaemonMatchRule + daemonClient "curl"+ (Generic, \ (GenericArgs command options) -> + curlBufferListenDBus buffer command options)+ return buffer +-- | Listen DBus signal.+curlBufferListenDBus :: CurlBuffer -> String -> [String] -> IO ()+curlBufferListenDBus curlBuffer command options = + case command of+ -- Add download. + "Download" -> forM_ options (curlBufferAddDownload curlBuffer)+ -- Print error information if mismatch command.+ _ -> putStrLn $ "Invalid curl command : " ++ command+ -- | Add download. curlBufferAddDownload :: CurlBuffer -> String -> IO () curlBufferAddDownload curlBuffer uri = @@ -256,7 +285,7 @@ if size == 0 -- Stop download when file size is zero.- then putStrLn "Size is zero, stop download."+ then putStrLn $ "Size is zero, stop download " ++ uri -- Otherwise start download. else do -- Update size.@@ -352,7 +381,7 @@ -- | Wait download result. curlBufferWaitResult :: DownloadFile -> IO ()-curlBufferWaitResult downloadFile = do+curlBufferWaitResult downloadFile@(DownloadFile {dfURL = url}) = do e <- takeMVar (dfFinishLock downloadFile) case e of -- Kill thread if DownloadError.@@ -361,9 +390,9 @@ forM_ buffers (\ buffer -> readTVarIO (dbThreadId buffer) >?>= \ i -> killThread i)- putStrLn $ "Failed to connect: " ++ err- DownloadPause -> putStrLn "Fetch pause."- DownloadFinish -> putStrLn "Fetch complete."+ putStrLn $ "Failed to connect: " ++ url ++ " with reason (" ++ err ++ ")"+ DownloadPause -> putStrLn $ "Fetch pause : " ++ url+ DownloadFinish -> putStrLn $ "Fetch complete : " ++ url -- | Pause. curlBufferPause :: DownloadFile -> IO ()@@ -413,7 +442,7 @@ getLogPathes = do cacheDir <- fmap (</> defaultCacheDir) getConfigDirectory files <- getDirectoryContents cacheDir- return $ map (\x -> cacheDir </> x) (filter (=~ "^*_log$") files)+ return $ map (\x -> cacheDir </> x) (filter (\x -> x =~ ("^*_log$" :: String)) files) -- | Get download range with thread number. getDownloadRange :: Int -> Int -> [(Int, Int)]
Manatee/Extension/Curl/CurlView.hs view
@@ -38,7 +38,6 @@ import Manatee.Extension.Curl.Types import Manatee.Toolkit.General.Basic import Manatee.Toolkit.General.Functor-import Manatee.Toolkit.General.Map import Manatee.Toolkit.General.Maybe import Manatee.Toolkit.General.STM import Manatee.Toolkit.Gio.Gio@@ -114,6 +113,9 @@ -- Draw view. curlViewDraw curlView + -- Display file name when cursor change.+ treeView `on` cursorChanged $ curlViewDisplayFilenameStatus curlView+ return curlView -- | Listen broadcast channel for draw view synchronous.@@ -214,9 +216,8 @@ (_, fMime) <- contentTypeGuess name "" 0 modifyTVarIOM databaseTVar (updateFileIconPixbufDatabaseWithFilePath name) database <- readTVarIO databaseTVar- let (_, pixbuf) = maybeError (findMinMatch database (\ mime _ -> mime == fMime))- ("curlViewAddTypeIconColumn: can't find pixbuf match in database : " ++ show fMime)- return pixbuf]+ return $ maybeError (findIconPixbuf database fMime)+ ("curlViewAddTypeIconColumn: can't find pixbuf match in database : " ++ show fMime)] -- | Add progress. curlViewAddProgressColumn :: TreeViewClass tv => tv -> ListStore DownloadFile -> IO ()@@ -255,6 +256,8 @@ tvc <- treeViewAddColumnWithTitle treeView name sortId getCellMinWidth info ?>= \width -> set tvc [treeViewColumnMinWidth := width]+ getCellMaxWidth info + ?>= \width -> set tvc [treeViewColumnMaxWidth := width] cell <- cellRendererTextNew treeViewColumnPackStart tvc cell True@@ -341,6 +344,16 @@ -- | Previous node. curlViewPrevNode :: CurlView -> IO () curlViewPrevNode = treeViewFocusPrevToplevelNode . curlViewTreeView++-- | Display file name status.+curlViewDisplayFilenameStatus :: CurlView -> IO ()+curlViewDisplayFilenameStatus view = + treeViewGetSelectedValue (curlViewTreeView view)+ (curlViewSortModel view)+ (curlViewListStore view)+ >?>= \ downloadFile -> do+ name <- readTVarIO (dfName downloadFile)+ pageViewUpdateInfoStatus view "Filename" ("Filename : " ++ name) -- | Sort column. curlViewSort :: CurlView -> DownloadFileOption -> IO ()
manatee-curl.cabal view
@@ -1,5 +1,5 @@ name: manatee-curl-version: 0.0.5+version: 0.0.6 Cabal-Version: >= 1.6 license: GPL-3 license-file: LICENSE@@ -7,6 +7,8 @@ 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>+ . Screenshots at : <http://goo.gl/MkVw> . Manual at : <http://haskell.org/haskellwiki/Manatee>@@ -28,11 +30,11 @@ location: http://patch-tag.com/r/AndyStewart/manatee-curl Library- build-depends: base >= 4 && < 5, manatee-core >= 0.0.5, dbus-client >= 0.3 && < 0.4, stm >= 2.1.2.0,+ build-depends: base >= 4 && < 5, manatee-core >= 0.0.6, 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,- template-haskell, derive, binary, regex-tdfa+ template-haskell, derive, binary, regex-tdfa, dbus-core exposed-modules: Manatee.Extension.Curl Manatee.Extension.Curl.PageMode