Commit 0edb16dc authored by Will Thompson's avatar Will Thompson

Show error name in details

For some reason I've never noticed this was missing before!
parent c73a89d7
......@@ -28,19 +28,23 @@ import Data.List (intercalate)
import Graphics.UI.Gtk hiding (Signal)
import qualified DBus as D
import DBus.Internal.Message (MethodError(..))
import DBus.Internal.Types (ErrorName(..))
import Bustle.Types
import Bustle.Marquee
import Bustle.VariantFormatter
type OptionalRow = (Label, Label)
data DetailsView =
DetailsView { detailsGrid :: Grid
, detailsType :: Stack
, detailsSender :: Label
, detailsDestinationCaption :: Label
, detailsDestination :: Label
, detailsDestination :: OptionalRow
, detailsPath :: Label
, detailsMember :: Label
, detailsErrorName :: OptionalRow
, detailsBodyView :: TextView
}
......@@ -50,11 +54,16 @@ detailsViewNew builder = DetailsView
<$> builderGetObject builder castToGrid "detailsGrid"
<*> builderGetObject builder castToStack "detailsType"
<*> builderGetObject builder castToLabel "detailsSender"
<*> builderGetObject builder castToLabel "detailsDestinationCaption"
<*> builderGetObject builder castToLabel "detailsDestination"
<*> optionalRow "detailsDestination"
<*> builderGetObject builder castToLabel "detailsPath"
<*> builderGetObject builder castToLabel "detailsMember"
<*> optionalRow "detailsErrorName"
<*> builderGetObject builder castToTextView "detailsArguments"
where
optionalRow labelId = (,)
<$> builderGetObject builder castToLabel (labelId ++ "Caption")
<*> builderGetObject builder castToLabel labelId
pickType :: Detailed Message -> String
pickType (Detailed _ m _ _) = case m of
......@@ -82,15 +91,34 @@ getDestination (Detailed _ m _ _) = case m of
Signal { signalDestination = d } -> d
_ -> Just (destination m)
getErrorName :: Detailed a -> Maybe String
getErrorName (Detailed _ _ _ rm) = case rm of
(D.ReceivedMethodError _ (MethodError { methodErrorName = ErrorName en})) -> Just en
_ -> Nothing
formatMessage :: Detailed Message -> String
formatMessage (Detailed _ _ _ rm) =
formatArgs $ D.receivedMessageBody rm
where
formatArgs = intercalate "\n" . map (format_Variant VariantStyleSignature)
-- TODO: suppress escaping and type sig for errors, which are always (s)
detailsViewGetTop :: DetailsView -> Widget
detailsViewGetTop = toWidget . detailsGrid
setOptionalRow :: OptionalRow
-> Maybe String
-> IO ()
setOptionalRow (caption, label) s_ = do
case s_ of
Just s -> do
labelSetText label s
widgetShow label
widgetShow caption
Nothing -> do
widgetHide label
widgetHide caption
detailsViewUpdate :: DetailsView
-> Detailed Message
-> IO ()
......@@ -102,14 +130,8 @@ detailsViewUpdate d m = do
-- TODO: these would be a lot more useful if we could resolve unique names
-- to/from well-known names and show both
labelSetText (detailsSender d) (unBusName . sender . deEvent $ m)
case getDestination m of
Just n -> do
labelSetText (detailsDestination d) (unBusName n)
widgetShow (detailsDestination d)
widgetShow (detailsDestinationCaption d)
Nothing -> do
widgetHide (detailsDestination d)
widgetHide (detailsDestinationCaption d)
setOptionalRow (detailsDestination d) (unBusName <$> getDestination m)
setOptionalRow (detailsErrorName d) (getErrorName m)
labelSetText (detailsPath d) (maybe unknown (D.formatObjectPath . path) member_)
labelSetMarkup (detailsMember d) (maybe unknown getMemberMarkup member_)
......
......@@ -726,7 +726,7 @@
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">5</property>
<property name="top_attach">6</property>
</packing>
</child>
<child>
......@@ -747,7 +747,7 @@
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">5</property>
<property name="top_attach">6</property>
</packing>
</child>
<child>
......@@ -888,6 +888,38 @@
<property name="top_attach">2</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="detailsErrorNameCaption">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="hexpand">False</property>
<property name="label" translatable="yes">Error</property>
<property name="xalign">1</property>
<style>
<class name="dim-label"/>
</style>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">5</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="detailsErrorName">
<property name="name">detailsMember</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="hexpand">True</property>
<property name="label">com.example.Placeholder.Error.OhNo</property>
<property name="selectable">True</property>
<property name="ellipsize">start</property>
<property name="xalign">0</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">5</property>
</packing>
</child>
</object>
<packing>
<property name="resize">False</property>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment