/* Notification callback for our label widgets that
 * monitor the current value of a mateconf key. i.e.
 * we are conceptually "configuring" the label widgets
 */
static void
configurable_widget_config_notify (MateConfClient *client,
                                   guint        cnxn_id,
                                   MateConfEntry  *entry,
                                   gpointer     user_data)
{
  GtkWidget *label = user_data;

  g_return_if_fail (GTK_IS_LABEL (label));

  /* Note that value can be NULL (unset) or it can have
   * the wrong type! Need to check that to survive
   * mateconftool --break-key
   */
  
  if (mateconf_entry_get_value (entry) == NULL)
    {
      gtk_label_set_text (GTK_LABEL (label), "");
    }
  else if (mateconf_entry_get_value (entry)->type == MATECONF_VALUE_STRING)
    {
      gtk_label_set_text (GTK_LABEL (label),
                          mateconf_value_get_string (mateconf_entry_get_value (entry)));
    }
  else
    {
      /* A real app would probably fall back to a reasonable default
       * in this case, instead of putting funky stuff in the GUI.
       */
      gtk_label_set_text (GTK_LABEL (label), "!type error!");
    }
}
static void
model_key_changed (MateConfClient * client,
		   guint cnxn_id, MateConfEntry * entry, GtkBuilder * dialog)
{
	set_model_text (WID ("xkb_model_pick"),
			mateconf_entry_get_value (entry));

	enable_disable_restoring (dialog);
}
static void
timeout_changed_cb (MateConfClient * client, guint id, MateConfEntry * entry, gpointer user_data)
{
    HardDriveStatusTile *tile = HARD_DRIVE_STATUS_TILE (user_data);
    HardDriveStatusTilePrivate *priv = HARD_DRIVE_STATUS_TILE_GET_PRIVATE (tile);

    int timeout;

    if (priv->update_timeout)
        g_source_remove (priv->update_timeout);

    timeout = mateconf_value_get_int (mateconf_entry_get_value (entry));
    timeout = MAX (timeout, 1000);

    priv->update_timeout = g_timeout_add (timeout, timeout_cb, tile);
}
static void
hash_lookup_defaults_func(gpointer key, gpointer value, gpointer user_data)
{
  MateConfEntry *entry = value;
  struct DefaultsLookupData* dld = user_data;
  MateConfSources *sources = dld->sources;
  const gchar** locales = dld->locales;
  
  if (mateconf_entry_get_value(entry) == NULL)
    {
      if (mateconf_entry_get_schema_name(entry) != NULL)
        {
          MateConfValue *val;


          val = mateconf_sources_query_value(sources,
                                          mateconf_entry_get_schema_name(entry),
                                          locales,
                                          TRUE,
                                          NULL,
                                          NULL,
                                          NULL,
                                          NULL);

          if (val != NULL &&
              val->type == MATECONF_VALUE_SCHEMA)
            {
              MateConfValue* defval;

              defval = mateconf_schema_steal_default_value (mateconf_value_get_schema(val));

              mateconf_entry_set_value_nocopy (entry, defval);
              mateconf_entry_set_is_default (entry, TRUE);
            }

          if (val)
            mateconf_value_free(val);
        }
    }
}
Example #5
0
static void
mate_panel_applet_locked_change_notify (MateConfClient *client,
				   guint        cnxn_id,
				   MateConfEntry  *entry,
				   GtkWidget   *applet)
{
	MateConfValue  *value;
	gboolean     locked;
	gboolean     applet_locked;
	AppletInfo  *info;
	PanelWidget *panel_widget;

	g_assert (applet != NULL);

	info = (AppletInfo  *) g_object_get_data (G_OBJECT (applet),
						  "applet_info");
	if (info == NULL)
		return;

	value = mateconf_entry_get_value (entry);
	if (value == NULL || value->type != MATECONF_VALUE_BOOL)
		return;

	locked = mateconf_value_get_bool (value);

	panel_widget = mate_panel_applet_get_panel_widget (info);
	applet_locked = panel_widget_get_applet_locked (panel_widget,
							info->widget);

	if ((locked && applet_locked) || !(locked || applet_locked))
		return;

	mate_panel_applet_toggle_locked (info);

	if (info->type == PANEL_OBJECT_APPLET)
		mate_panel_applet_frame_sync_menu_state (MATE_PANEL_APPLET_FRAME (info->widget));
	else
		mate_panel_applet_recreate_menu (info);
}
Example #6
0
static void
panel_addto_name_notify (MateConfClient      *client,
			 guint             cnxn_id,
			 MateConfEntry       *entry,
			 PanelAddtoDialog *dialog)
{
	MateConfValue *value;
	const char *key;
	const char *text = NULL;

	key = panel_mateconf_basename (mateconf_entry_get_key (entry));

	if (strcmp (key, "name"))
		return;

	value = mateconf_entry_get_value (entry);

	if (value && value->type == MATECONF_VALUE_STRING)
		text = mateconf_value_get_string (value);

	if (text)
		panel_addto_name_change (dialog, text);
}
static
gboolean
mateconf_tree_model_search_iter_foreach (GtkTreeModel *model, GtkTreePath *path,
				      GtkTreeIter *iter, gpointer data)
{
	Node    *node;
	SearchIter *st;
	gchar *found;
	GSList *values, *list;

	st = (SearchIter *) data;

	if (st->searching == NULL) {
		return TRUE;
	}

	if (st->res >= 1) {
		gtk_widget_show (GTK_WIDGET (st->output_window));
	}
	while (gtk_events_pending ())
		gtk_main_iteration ();

	node = iter->user_data;
	found = g_strrstr ((char*) node->path, (char*) st->pattern);

	if (found != NULL) {
		/* We found the pattern in the tree */
		gchar *key = mateconf_tree_model_get_mateconf_path (MATECONF_TREE_MODEL (model), iter);
		gedit_output_window_append_line (st->output_window, key, FALSE);
		g_free (key);
		st->res++;
		return FALSE;
	}

	if (!st->search_keys && !st->search_values) {
		return FALSE;
	}
	values = mateconf_client_all_entries (MATECONF_TREE_MODEL (model)->client, (const char*) node->path , NULL);
	for (list = values; list; list = list->next) {
		const gchar *key;
		MateConfEntry *entry = list->data;
		key = mateconf_entry_get_key (entry);
		/* Search in the key names */
		if (st->search_keys) {
			found = g_strrstr (key, (char*) st->pattern);
			if (found != NULL) {
				/* We found the pattern in the final key name */
				gedit_output_window_append_line (st->output_window, key, FALSE);
				st->res++;
				mateconf_entry_unref (entry);
				/* After finding an entry continue the list to find other matches */
				continue;
			}
		}

		/* Search in the values */
		if (st->search_values) {
			const char *mateconf_string;
			MateConfValue *mateconf_value = mateconf_entry_get_value (entry);

			/* FIXME: We are only looking into strings... should we do in
			 * int's? */
			if (mateconf_value != NULL && mateconf_value->type == MATECONF_VALUE_STRING)
				mateconf_string = mateconf_value_get_string (mateconf_value);
			else {
				mateconf_entry_unref (entry);
				continue;
			}

                	found = g_strrstr (mateconf_string, (char*) st->pattern);
			if (found != NULL) {
				/* We found the pattern in the key value */
				gedit_output_window_append_line (st->output_window, key, FALSE);
				st->res++;
				mateconf_entry_unref (entry);
				continue;
			}
		}
		mateconf_entry_unref (entry);
	}

	return FALSE;
}
GSList*       
mateconf_sources_all_entries   (MateConfSources* sources,
                             const gchar* dir,
                             const gchar** locales,
                             GError** err)
{
  GList* tmp;
  GHashTable* hash;
  GSList* flattened;
  gboolean first_pass = TRUE; /* as an optimization, don't bother
                                 doing hash lookups on first source
                              */
  struct DefaultsLookupData dld = { NULL, NULL };
  
  dld.sources = sources;
  dld.locales = locales;

  /* Empty MateConfSources, skip it */
  if (sources->sources == NULL)
    return NULL;

  hash = g_hash_table_new(g_str_hash, g_str_equal);

  tmp = sources->sources;

  while (tmp != NULL)
    {
      MateConfSource* src;
      GSList* pairs;
      GSList* iter;
      GError* error = NULL;
      
      src   = tmp->data;
      pairs = mateconf_source_all_entries(src, dir, locales, &error);
      iter  = pairs;
      
      /* On error, set error and bail */
      if (error != NULL)
        {
          g_hash_table_foreach(hash, hash_destroy_entries_func, NULL);
          
          g_hash_table_destroy(hash);
          
          if (err)
            {
              g_return_val_if_fail(*err == NULL, NULL);
              *err = error;
              return NULL;
            }
          else
            {
              g_error_free(error);
              return NULL;
            }
        }

      /* Iterate over the list of entries, stuffing them in the hash
         and setting their writability flag if they're new
      */
      
      while (iter != NULL)
        {
          MateConfEntry* pair = iter->data;
          MateConfEntry* previous;
          gchar *full;
          
          if (first_pass)
            previous = NULL; /* Can't possibly be there. */
          else
            previous = g_hash_table_lookup(hash, pair->key);
          
          if (previous != NULL)
            {
              if (mateconf_entry_get_value (previous) != NULL)
                /* Discard this latest one */
                ;
              else
                {
                  /* Save the new value, previously we had an entry but no value */
                  mateconf_entry_set_value_nocopy (previous,
                                                mateconf_entry_steal_value(pair));

                  /* As an efficiency hack, remember that
                   * entry->key is relative not absolute on the
                   * mateconfd side
                   */
                  full = mateconf_concat_dir_and_key (dir, previous->key);

                  mateconf_entry_set_is_writable (previous,
                                               key_is_writable (sources,
                                                                src,
                                                                full,
                                                                NULL));

                  g_free (full);
                }
              
              if (mateconf_entry_get_schema_name (previous) != NULL)
                /* Discard this latest one */
                ;
              else
                {
                  /* Save the new schema name, previously we had an entry but no schema name*/
                  if (mateconf_entry_get_schema_name (pair) != NULL)
                    {
                      mateconf_entry_set_schema_name (previous,
                                                   mateconf_entry_get_schema_name (pair));
                    }
                }

              mateconf_entry_free(pair);
            }
          else
            {
              /* Save */
              g_hash_table_insert(hash, pair->key, pair);
              
              /* As an efficiency hack, remember that
               * entry->key is relative not absolute on the
               * mateconfd side
               */
              full = mateconf_concat_dir_and_key (dir, pair->key);

              mateconf_entry_set_is_writable (pair,
                                           key_is_writable (sources,
                                                            src,
                                                            full,
                                                            NULL));
              
              g_free (full);
            }

          iter = g_slist_next(iter);
        }
      
      /* All pairs are either stored or destroyed. */
      g_slist_free(pairs);

      first_pass = FALSE;

      tmp = g_list_next(tmp);
    }

  flattened = NULL;

  g_hash_table_foreach(hash, hash_lookup_defaults_func, &dld);
  
  g_hash_table_foreach(hash, hash_listify_func, &flattened);

  g_hash_table_destroy(hash);
  
  return flattened;
}