summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWill Thompson <will@willthompson.co.uk>2018-12-06 23:14:58 +0000
committerWill Thompson <will@willthompson.co.uk>2018-12-07 07:21:46 +0000
commit0edb16dceac37411233187288f45845c61cbfd41 (patch)
tree38bb9c7a65002c296c96818edc0ecec14397cdd2
parentc73a89d76cadbbf104ba7e5cdf005459bdf5e9eb (diff)
Show error name in details
For some reason I've never noticed this was missing before!
-rw-r--r--Bustle/UI/DetailsView.hs46
-rw-r--r--data/bustle.ui36
2 files changed, 68 insertions, 14 deletions
diff --git a/Bustle/UI/DetailsView.hs b/Bustle/UI/DetailsView.hs
index 25159e2..5f9cc11 100644
--- a/Bustle/UI/DetailsView.hs
+++ b/Bustle/UI/DetailsView.hs
@@ -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_)
diff --git a/data/bustle.ui b/data/bustle.ui
index 79785fd..d76aa01 100644
--- a/data/bustle.ui
+++ b/data/bustle.ui
@@ -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>