From 53860f89ceac2ee7398f794af37752cac7bcfde4 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Wed, 1 Dec 2010 21:45:04 -0500 Subject: [PATCH] - Re-enable libmpd --- xmobar.libmpd-0.5.patch | 127 ++++++++++++++++++++++++++++++++++++++++ xmobar.spec | 11 +++- 2 files changed, 136 insertions(+), 2 deletions(-) create mode 100644 xmobar.libmpd-0.5.patch diff --git a/xmobar.libmpd-0.5.patch b/xmobar.libmpd-0.5.patch new file mode 100644 index 0000000..63e17ce --- /dev/null +++ b/xmobar.libmpd-0.5.patch @@ -0,0 +1,127 @@ +--- Plugins/Monitors/MPD.hs 2010-12-01 21:35:40.602992136 -0500 ++++ Plugins/Monitors/MPD.hs.libmpd-0.5 2010-11-18 17:24:03.000000000 -0500 +@@ -19,74 +19,97 @@ + import qualified Network.MPD as M + + mpdConfig :: IO MConfig + mpdConfig = mkMConfig "MPD: " + [ "bar", "state", "statei", "volume", "length" +- , "lapsed", "plength" ++ , "lapsed", "remaining", "plength", "ppos", "file" + , "name", "artist", "composer", "performer" +- , "album", "title", "track", "trackno", "file", "genre" ++ , "album", "title", "track", "genre" + ] + +-data MOpts = MOpts {mPlaying :: String, mStopped :: String, mPaused :: String} ++data MOpts = MOpts ++ { mPlaying :: String ++ , mStopped :: String ++ , mPaused :: String ++ , mHost :: String ++ , mPort :: Integer ++ , mPassword :: String ++ } + + defaultOpts :: MOpts +-defaultOpts = MOpts { mPlaying = ">>", mStopped = "><", mPaused = "||" } ++defaultOpts = MOpts ++ { mPlaying = ">>" ++ , mStopped = "><" ++ , mPaused = "||" ++ , mHost = "127.0.0.1" ++ , mPort = 6600 ++ , mPassword = "" ++ } + + options :: [OptDescr (MOpts -> MOpts)] + options = + [ Option "P" ["playing"] (ReqArg (\x o -> o { mPlaying = x }) "") "" + , Option "S" ["stopped"] (ReqArg (\x o -> o { mStopped = x }) "") "" + , Option "Z" ["paused"] (ReqArg (\x o -> o { mPaused = x }) "") "" ++ , Option "h" ["host"] (ReqArg (\x o -> o { mHost = x }) "") "" ++ , Option "p" ["port"] (ReqArg (\x o -> o { mPort = read x }) "") "" ++ , Option "x" ["password"] (ReqArg (\x o -> o { mPassword = x }) "") "" + ] + + runMPD :: [String] -> Monitor String + runMPD args = do +- status <- io $ M.withMPD M.status +- song <- io $ M.withMPD M.currentSong + opts <- io $ mopts args +- let (b, s) = parseMPD status song opts +- bs <- showPercentBar (100 * b) b +- parseTemplate (bs:s) ++ let mpd = M.withMPDEx (mHost opts) (mPort opts) (mPassword opts) ++ status <- io $ mpd M.status ++ song <- io $ mpd M.currentSong ++ s <- parseMPD status song opts ++ parseTemplate s + + mopts :: [String] -> IO MOpts + mopts argv = + case getOpt Permute options argv of + (o, _, []) -> return $ foldr id defaultOpts o + (_, _, errs) -> ioError . userError $ concat errs + + parseMPD :: M.Response M.Status -> M.Response (Maybe M.Song) -> MOpts +- -> (Float, [String]) +-parseMPD (Left e) _ _ = (0, show e:repeat "") +-parseMPD (Right st) song opts = (b, [ss, si, vol, len, lap, plen] ++ sf) ++ -> Monitor [String] ++parseMPD (Left e) _ _ = return $ show e:repeat "" ++parseMPD (Right st) song opts = do ++ songData <- parseSong song ++ bar <- showPercentBar (100 * b) b ++ return $ [bar, ss, si, vol, len, lap, remain, plen, ppos] ++ songData + where s = M.stState st + ss = show s + si = stateGlyph s opts +- vol = int2Str $ M.stVolume st +- (lap, len) = (showTime p, showTime t) ++ vol = int2str $ M.stVolume st + (p, t) = M.stTime st +- b = if t > 0 then fromIntegral p / fromIntegral t else 0 +- plen = int2Str $ M.stPlaylistLength st +- sf = parseSong song ++ [lap, len, remain] = map showTime [floor p, t, max 0 (t - floor p)] ++ b = if t > 0 then realToFrac $ p / fromIntegral t else 0 ++ plen = int2str $ M.stPlaylistLength st ++ ppos = maybe "" (int2str . (+1)) $ M.stSongPos st + + stateGlyph :: M.State -> MOpts -> String + stateGlyph s o = + case s of + M.Playing -> mPlaying o + M.Paused -> mPaused o + M.Stopped -> mStopped o + +-parseSong :: M.Response (Maybe M.Song) -> [String] +-parseSong (Left _) = repeat "" +-parseSong (Right Nothing) = repeat "" ++parseSong :: M.Response (Maybe M.Song) -> Monitor [String] ++parseSong (Left _) = return $ repeat "" ++parseSong (Right Nothing) = return $ repeat "" + parseSong (Right (Just s)) = +- [ M.sgName s, M.sgArtist s, M.sgComposer s, M.sgPerformer s +- , M.sgAlbum s, M.sgTitle s, track, trackno, M.sgFilePath s, M.sgGenre s] +- where (track, trackno) = (int2Str t, int2Str tn) +- (t, tn) = M.sgTrack s ++ let join [] = "" ++ join (x:xs) = foldl (\a o -> a ++ ", " ++ o) x xs ++ str sel = maybe "" join (M.sgGet sel s) ++ sels = [ M.Name, M.Artist, M.Composer, M.Performer ++ , M.Album, M.Title, M.Track, M.Genre ] ++ fields = M.sgFilePath s : map str sels ++ in mapM showWithPadding fields + + showTime :: Integer -> String +-showTime t = int2Str minutes ++ ":" ++ int2Str seconds ++showTime t = int2str minutes ++ ":" ++ int2str seconds + where minutes = t `div` 60 + seconds = t `mod` 60 + +-int2Str :: (Num a, Ord a) => a -> String +-int2Str x = if x < 10 then '0':sx else sx where sx = show x ++int2str :: (Num a, Ord a) => a -> String ++int2str x = if x < 10 then '0':sx else sx where sx = show x diff --git a/xmobar.spec b/xmobar.spec index 40eb937..07ae36e 100644 --- a/xmobar.spec +++ b/xmobar.spec @@ -1,7 +1,7 @@ # link with shared libs %bcond_without dynamic %bcond_without hinotify -%bcond_with libmpd +%bcond_without libmpd %bcond_with iwlib # ghc does not emit debug information @@ -9,7 +9,7 @@ Name: xmobar Version: 0.11.1 -Release: 6%{?dist} +Release: 7%{?dist} Summary: A minimalistic text-based status bar Group: User Interface/X @@ -17,6 +17,9 @@ License: BSD URL: http://hackage.haskell.org/package/%{name} Source0: http://hackage.haskell.org/packages/archive/%{name}/%{version}/%{name}-%{version}.tar.gz Source1: xmobar.desktop +# Made from diff in MPD.hs between upstream and +# http://code.google.com/p/xmobar/issues/detail?id=31 +Patch0: xmobar.libmpd-0.5.patch BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n) # fedora ghc archs: ExclusiveArch: %{ix86} x86_64 ppc alpha @@ -46,6 +49,7 @@ color management, output templates, and extensibility through plugins. %prep %setup -q +%patch0 -p0 -b .libmpd-0.5 %build @@ -85,6 +89,9 @@ rm -rf %{buildroot} %changelog +* Wed Dec 01 2010 Ben Boeckel - 0.11.1-7 +- Re-enable libmpd + * Mon Nov 29 2010 Ben Boeckel - 0.11.1-6 - Disable libmpd support since GHC7 broke things