Thunarのコントロールバインド

7473 ワード

Thunarではexo_を使用していますmutual_binding_new_fullとexo_binding_newはコントロール属性のバインドを行い、プロトタイプは:
/*     , object1 object2      transform reverse_transform     */
ExoMutualBinding*   exo_mutual_binding_new_full         (GObject *object1,
                                                         const gchar *property1,
                                                         GObject *object2,
                                                         const gchar *property2, 
                                                         /* property1 src, property2 dest */
                                                         ExoBindingTransform transform,
                                                         /* property2 src, property1 dest  */
                                                         ExoBindingTransform reverse_transform,
                                                         GDestroyNotify destroy_notify,
                                                         gpointer user_data);

 
/*      , src_property      dst_property      */
ExoBinding*         exo_binding_new                     (GObject *src_object,
                                                         const gchar *src_property,
                                                         GObject *dst_object,
                                                         const gchar *dst_property);

 
 
まずexo_について見てみましょうmutual_binding_new_fullのコードクリップ:
./thunar-preferences-dialog.c
  GtkWidget      *combo;
  combo = gtk_combo_box_new_text ();
  gtk_combo_box_append_text (GTK_COMBO_BOX (combo), _("Icon View"));
  gtk_combo_box_append_text (GTK_COMBO_BOX (combo), _("Detailed List View"));
  gtk_combo_box_append_text (GTK_COMBO_BOX (combo), _("Compact List View"));
  gtk_combo_box_append_text (GTK_COMBO_BOX (combo), _("Last Active View"));
  //  dialog->preferences "default-view"    combo  "active"       
  exo_mutual_binding_new_full (G_OBJECT (dialog->preferences), "default-view", G_OBJECT (combo), "active",
                               transform_view_string_to_index, transform_view_index_to_string, NULL, NULL);

 
 
// dialog->preferences "default-view"      combo  "active"       
static gboolean
transform_view_string_to_index (const GValue *src_value,
                                GValue       *dst_value,
                                gpointer      user_data)
{
  GType type;

  type = g_type_from_name (g_value_get_string (src_value));
  if (type == THUNAR_TYPE_ICON_VIEW)
    g_value_set_int (dst_value, 0);
  else if (type == THUNAR_TYPE_DETAILS_VIEW)
    g_value_set_int (dst_value, 1);
  else if (type == THUNAR_TYPE_COMPACT_VIEW)
    g_value_set_int (dst_value, 2);
  else
    g_value_set_int (dst_value, 3);

  return TRUE;
}
 
// combo  "active"      dialog->preferences "default-view"        
static gboolean
transform_view_index_to_string (const GValue *src_value,
                                GValue       *dst_value,
                                gpointer      user_data)
{
  switch (g_value_get_int (src_value))
    {
    case 0:
      g_value_set_static_string (dst_value, g_type_name (THUNAR_TYPE_ICON_VIEW));
      break;

    case 1:
      g_value_set_static_string (dst_value, g_type_name (THUNAR_TYPE_DETAILS_VIEW));
      break;

    case 2:
      g_value_set_static_string (dst_value, g_type_name (THUNAR_TYPE_COMPACT_VIEW));
      break;

    default:
      g_value_set_static_string (dst_value, g_type_name (G_TYPE_NONE));
      break;
    }

  return TRUE;
}

 
./thunar-preferences.cでプロパティ「default-view」を定義します.
ここでは関数を使用します.プロトタイプは次のとおりです.
GParamSpec*         g_param_spec_string                 (const gchar *name,
                                                         const gchar *nick,
                                                         const gchar *blurb,
                                                         const gchar *default_value,
                                                         GParamFlags flags);
 
enum
{
  PROP_0,
  PROP_DEFAULT_VIEW,
  PROP_LAST_COMPACT_VIEW_ZOOM_LEVEL,
//...
}

static void
thunar_preferences_class_init (ThunarPreferencesClass *klass)
{
  GObjectClass *gobject_class;

  gobject_class = G_OBJECT_CLASS (klass);
  gobject_class->finalize = thunar_preferences_finalize;
  gobject_class->get_property = thunar_preferences_get_property;
  gobject_class->set_property = thunar_preferences_set_property;

  /**
   * ThunarPreferences:default-view:
   *
   * The name of the widget class, which should be used for the
   * view pane in new #ThunarWindow<!---->s or "void" to use the
   * last selected view from the "last-view" preference.
   **/
  g_object_class_install_property (gobject_class,
                                   PROP_DEFAULT_VIEW,//  ID,      ,     
                                   g_param_spec_string ("default-view",//   
                                                        "DefaultView",//    ,   
                                                        "default-view",//    ,   
                                                        "void",//     
                                                        EXO_PARAM_READWRITE));//         
  /**
   * ThunarPreferences:last-compact-view-zoom-level:
   *
   * The last selected #ThunarZoomLevel for the #ThunarCompactView.
   **/
  g_object_class_install_property (gobject_class,
                                   PROP_LAST_COMPACT_VIEW_ZOOM_LEVEL,
                                   g_param_spec_enum ("last-compact-view-zoom-level",
                                                      "LastCompactViewZoomLevel",
                                                      "last-compact-view-zoom-level",
                                                      THUNAR_TYPE_ZOOM_LEVEL,
                                                      THUNAR_ZOOM_LEVEL_SMALLEST,
                                                      EXO_PARAM_READWRITE));

}

 
では、「default-view」プロパティを取得する必要がある場合は、次の方法を参照してください.
./thunar-window.c
  gchar          *type_name;
  GType           type;
  /* determine the default view */
  g_object_get (G_OBJECT (window->preferences), "default-view", &type_name, NULL);
  type = g_type_from_name (type_name);
  g_free (type_name);

 
また、thunarの一般的な値は、ファイルdocs/README.thunarrcで見つけることができます.