Beispiel #1
0
static void
home_widget_set_module (MnbHomeWidget *self,
    const gchar *module)
{
  if (0 == g_strcmp0 (module, self->priv->module))
    return;

  DEBUG ("%s -> %s (%s)", self->priv->module, module,
      self->priv->settings_path);

  g_free (self->priv->module);
  self->priv->module = g_strdup (module);

  if (self->priv->app != NULL)
    dawati_home_plugins_app_deinit (self->priv->app);

  g_clear_object (&self->priv->app);

  if (STR_EMPTY (self->priv->module))
    {
      DEBUG ("no module, going into edit mode (%s)",
          self->priv->settings_path);
      mnb_home_widget_set_edit_mode (self, TRUE);
    }
  else
    {
      DEBUG ("module = '%s' (%s)", self->priv->module,
          self->priv->settings_path);

      if (self->priv->engine == NULL)
        self->priv->engine = mnb_home_plugins_engine_dup ();

      self->priv->app =
        mnb_home_plugins_engine_create_app (self->priv->engine,
            self->priv->module, self->priv->settings_path);
      if (self->priv->app != NULL)
        dawati_home_plugins_app_init (self->priv->app);
    }

  /* reload the widget */
  mnb_home_widget_set_edit_mode (self, self->priv->edit_mode);

  g_object_notify (G_OBJECT (self), "module");
}
static void
mnb_home_new_widget_dialog_init (MnbHomeNewWidgetDialog *self)
{
  ClutterActor *table, *itemview;
  MnbHomeNewWidgetDialogItemFactory *factory;
  MnbHomePluginsEngine *engine;
  const GList *l;

  self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
      MNB_TYPE_HOME_NEW_WIDGET_DIALOG, MnbHomeNewWidgetDialogPrivate);

  /* set up model and view */
  self->priv->items = clutter_list_model_new (ITEMS_N_COLUMNS,
      G_TYPE_STRING, "Module", /* ITEMS_MODULE */
      G_TYPE_STRING, "Name", /* ITEMS_NAME */
      G_TYPE_STRING, "Icon" /* ITEMS_ICON */);

  table = mx_table_new ();
  mx_bin_set_child (MX_BIN (self), table);

  factory = g_object_new (MNB_TYPE_HOME_NEW_WIDGET_DIALOG_ITEM_FACTORY, NULL);
  factory->dialog = self;

  itemview = mx_item_view_new ();
  mx_table_add_actor (MX_TABLE (table), itemview, 0, 1);
  mx_item_view_set_model (MX_ITEM_VIEW (itemview), self->priv->items);
  mx_item_view_set_factory (MX_ITEM_VIEW (itemview), MX_ITEM_FACTORY (factory));

  mx_item_view_add_attribute (MX_ITEM_VIEW (itemview), "module", ITEMS_MODULE);
  mx_item_view_add_attribute (MX_ITEM_VIEW (itemview), "label", ITEMS_NAME);
  mx_item_view_add_attribute (MX_ITEM_VIEW (itemview), "icon", ITEMS_ICON);

  clutter_actor_show_all (table);

  /* find plugins */
  /* FIXME: should we monitor for new plugins on the fly? */
  engine = mnb_home_plugins_engine_dup ();

  for (l = peas_engine_get_plugin_list (PEAS_ENGINE (engine));
       l != NULL;
       l = g_list_next (l))
    {
      PeasPluginInfo *info = l->data;
      char *icon;

      if (!peas_plugin_info_is_available (info, NULL))
        continue;

      icon = g_build_filename (
          peas_plugin_info_get_module_dir (info),
          peas_plugin_info_get_icon_name (info),
          NULL);

      clutter_model_append (self->priv->items,
          ITEMS_MODULE, peas_plugin_info_get_module_name (info),
          ITEMS_NAME, peas_plugin_info_get_name (info),
          ITEMS_ICON, icon,
          -1);

      g_free (icon);
    }

  /* add actions */
  mx_dialog_add_action (MX_DIALOG (self),
      mx_action_new_full ("cancel", _("Cancel"),
        G_CALLBACK (home_new_widget_dialog_cancel),
        self));

  g_object_unref (engine);
  g_object_unref (factory);
}