Ejemplo n.º 1
0
QString
Application::icon() const
{
    if (!m_overrideIconPath.isEmpty()) {
        return m_overrideIconPath;
    }

    if (sticky() && (m_appInfo != NULL)) {
        GCharPointer ptr(g_icon_to_string(g_app_info_get_icon(m_appInfo.data())));
        return QString::fromUtf8(ptr.data());
    }

    if (m_application != NULL) {
        return m_application->icon();
    }

    if (m_appInfo != NULL) {
        GCharPointer ptr(g_icon_to_string(g_app_info_get_icon(m_appInfo.data())));
        return QString::fromUtf8(ptr.data());
    }

    if (m_snStartupSequence != NULL) {
        return QString::fromUtf8(sn_startup_sequence_get_icon_name(m_snStartupSequence.data()));
    }

    return QString();
}
Ejemplo n.º 2
0
static void
_update_icon_from_icon_theme (PengeAppTile *tile)
{
  PengeAppTilePrivate *priv = GET_PRIVATE (tile);
  gchar *icon_path;
  GError *error = NULL;
  GIcon *icon;

  icon = g_app_info_get_icon (priv->app_info);

  if (G_IS_FILE_ICON (icon))
  {
    icon_path = g_icon_to_string (icon);
  }
  
  if (!clutter_texture_set_from_file (CLUTTER_TEXTURE (priv->tex),
                                      icon_path,
                                      &error))
  {
    g_warning (G_STRLOC ": Error loading texture from file: %s",
                error->message);
    g_clear_error (&error);
  }

  g_free (icon_path);
}
Ejemplo n.º 3
0
/**
 * cinnamon_app_create_icon_texture:
 *
 * Look up the icon for this application, and create a #ClutterTexture
 * for it at the given size.
 *
 * Return value: (transfer none): A floating #ClutterActor
 */
ClutterActor *
cinnamon_app_create_icon_texture (CinnamonApp   *app,
                               int         size)
{
  GIcon *icon;
  ClutterActor *ret;

  ret = NULL;

  if (app->entry == NULL)
    return window_backed_app_get_icon (app, size);

  icon = g_app_info_get_icon (G_APP_INFO (gmenu_tree_entry_get_app_info (app->entry)));
  if (icon != NULL)
    ret = st_texture_cache_load_gicon (st_texture_cache_get_default (), NULL, icon, size);

  if (ret == NULL)
    {
      icon = g_themed_icon_new ("application-x-executable");
      ret = st_texture_cache_load_gicon (st_texture_cache_get_default (), NULL, icon, size);
      g_object_unref (icon);
    }

  return ret;
}
Ejemplo n.º 4
0
static MxAction *
_action_new_from_desktop_file (const gchar *desktop_file_id)
{
  GDesktopAppInfo *dai;

  dai = g_desktop_app_info_new (desktop_file_id);

  if (dai)
    {
      MxAction *action;
      GAppInfo *ai;
      GIcon *icon;

      ai = G_APP_INFO (dai);

      action = mx_action_new_full (g_app_info_get_name (ai),
                                   g_app_info_get_display_name (ai),
                                   G_CALLBACK (_app_launcher_cb),
                                   (gpointer)g_app_info_get_commandline (ai));

     icon = g_app_info_get_icon (ai);
     if (icon)
       {
         gchar *icon_name;
         icon_name =  g_icon_to_string (icon);

         mx_action_set_icon (action, icon_name);

         g_free (icon_name);
       }

      return action;
    }
  return NULL;
}
void
cc_shell_model_add_item (CcShellModel    *model,
                         CcPanelCategory  category,
                         GAppInfo        *appinfo,
                         const char      *id)
{
  GIcon       *icon = g_app_info_get_icon (appinfo);
  const gchar *name = g_app_info_get_name (appinfo);
  const gchar *comment = g_app_info_get_description (appinfo);
  char **keywords;
  char *casefolded_name, *casefolded_description;

  casefolded_name = cc_util_normalize_casefold_and_unaccent (name);
  casefolded_description = cc_util_normalize_casefold_and_unaccent (comment);
  keywords = get_casefolded_keywords (appinfo);

  gtk_list_store_insert_with_values (GTK_LIST_STORE (model), NULL, 0,
                                     COL_NAME, name,
                                     COL_CASEFOLDED_NAME, casefolded_name,
                                     COL_APP, appinfo,
                                     COL_ID, id,
                                     COL_CATEGORY, category,
                                     COL_DESCRIPTION, comment,
                                     COL_CASEFOLDED_DESCRIPTION, casefolded_description,
                                     COL_GICON, icon,
                                     COL_KEYWORDS, keywords,
                                     -1);

  g_free (casefolded_name);
  g_free (casefolded_description);
  g_strfreev (keywords);
}
Ejemplo n.º 6
0
static void on_content_type_finished(GObject* src_obj, GAsyncResult* res, gpointer user_data)
{
    AutoRun* data = (AutoRun*)user_data;
    GMount* mount = G_MOUNT(src_obj);
    char** types;
    char* desc = NULL;

    types = g_mount_guess_content_type_finish(mount, res, NULL);
    if(types)
    {
        GtkTreeIter it;
        GList* apps = NULL, *l;
        char** type;
        if(types[0])
        {
            for(type=types;*type;++type)
            {
                l = g_app_info_get_all_for_type(*type);
                if(l)
                    apps = g_list_concat(apps, l);
            }
            desc = g_content_type_get_description(types[0]);
        }
        g_strfreev(types);

        if(apps)
        {
            int pos = 0;
            GtkTreePath* tp;
            for(l = apps; l; l=l->next, ++pos)
            {
                GAppInfo* app = G_APP_INFO(l->data);
                gtk_list_store_insert_with_values(data->store, &it, pos,
                                   0, g_app_info_get_icon(app),
                                   1, g_app_info_get_name(app),
                                   2, app, -1);
                g_object_unref(app);
            }
            g_list_free(apps);

            gtk_tree_model_get_iter_first(GTK_TREE_MODEL(data->store), &it);
            gtk_tree_selection_select_iter(gtk_tree_view_get_selection(data->view), &it);
            tp = gtk_tree_path_new_first();
            gtk_tree_view_set_cursor(data->view, tp, NULL, FALSE);
            gtk_tree_path_free(tp);
        }
    }

    if(desc)
    {
        gtk_label_set_text(data->type, desc);
        g_free(desc);
    }
    else
        gtk_label_set_text(data->type, _("Removable Disk"));

}
Ejemplo n.º 7
0
GIcon *
desktop_entry_get_icon (DesktopEntry *entry)
{
  if (entry->type == DESKTOP_ENTRY_DESKTOP)
    {
      g_return_val_if_fail (G_IS_DESKTOP_APP_INFO (((DesktopEntryDesktop*)entry)->appinfo), NULL);
      return g_app_info_get_icon (G_APP_INFO (((DesktopEntryDesktop*)entry)->appinfo));
    }

  return ((DesktopEntryDirectory*)entry)->icon;
}
Ejemplo n.º 8
0
static void
gtk_app_chooser_button_populate (GtkAppChooserButton *self)
{
  GList *recommended_apps = NULL, *l;
  GAppInfo *app;
  GtkTreeIter iter, iter2;
  GIcon *icon;
  gboolean cycled_recommended;

#ifndef G_OS_WIN32
  if (self->priv->content_type)
    recommended_apps = g_app_info_get_recommended_for_type (self->priv->content_type);
#endif
  cycled_recommended = FALSE;

  for (l = recommended_apps; l != NULL; l = l->next)
    {
      app = l->data;

      icon = g_app_info_get_icon (app);

      if (icon == NULL)
        icon = g_themed_icon_new ("application-x-executable");
      else
        g_object_ref (icon);

      if (cycled_recommended)
        {
          gtk_list_store_insert_after (self->priv->store, &iter2, &iter);
          iter = iter2;
        }
      else
        {
          get_first_iter (self->priv->store, &iter);
          cycled_recommended = TRUE;
        }

      gtk_list_store_set (self->priv->store, &iter,
                          COLUMN_APP_INFO, app,
                          COLUMN_LABEL, g_app_info_get_name (app),
                          COLUMN_ICON, icon,
                          COLUMN_CUSTOM, FALSE,
                          -1);

      g_object_unref (icon);
    }

  if (!cycled_recommended)
    gtk_app_chooser_button_ensure_dialog_item (self, NULL);
  else
    gtk_app_chooser_button_ensure_dialog_item (self, &iter);

  gtk_combo_box_set_active (GTK_COMBO_BOX (self), 0);
}
Ejemplo n.º 9
0
/* Now we implement a set of iterator functions that will handle item lookup hell for us. */
void menu_iterate_begin(pqi inst, menu_iter *it, int showfirst)
{
	it->reverse = FALSE;
	it->showfirst = showfirst;
	it->si = (inst->items->next? showfirst? inst->items : inst->items->next : inst->items);
	it->valid = (it->si != NULL);
	
	if (it->valid)
		it->text = g_app_info_get_display_name(G_APP_INFO(it->si->dfile)),
		it->icon = g_app_info_get_icon(G_APP_INFO(it->si->dfile));
}
Ejemplo n.º 10
0
void menu_iterate_rbegin(pqi inst, menu_iter *it, int showfirst)
{
	it->reverse = TRUE;
	it->showfirst = showfirst;
	it->si = inst->lastitem;
	it->valid = (it->si != NULL); /* Wehther or not we show the first item, whether or not this is the first item, if it exists, we return it. */
	
	if (it->valid)
		it->text = g_app_info_get_display_name(G_APP_INFO(it->si->dfile)),
		it->icon = g_app_info_get_icon(G_APP_INFO(it->si->dfile));
}
Ejemplo n.º 11
0
void menu_iter_next(menu_iter* it)
{
	if (it->reverse)
		it->si = it->si->prev,
		it->valid = (it->si != NULL && (it->showfirst || it->si->prev));
	else
		it->si = it->si->next,
		it->valid = (it->si != NULL);
	
	if (it->valid)
		it->text = g_app_info_get_display_name(G_APP_INFO(it->si->dfile)),
		it->icon = g_app_info_get_icon(G_APP_INFO(it->si->dfile));
}
Ejemplo n.º 12
0
static void
gtk_app_chooser_add_default (GtkAppChooserWidget *self,
                             GAppInfo            *app)
{
  GtkTreeIter iter;
  GIcon *icon;
  gchar *string;
  gboolean unref_icon;

  unref_icon = FALSE;
  string = g_strdup_printf ("<b>%s</b>", _("Default Application"));

  gtk_list_store_append (self->priv->program_list_store, &iter);
  gtk_list_store_set (self->priv->program_list_store, &iter,
                      COLUMN_HEADING_TEXT, string,
                      COLUMN_HEADING, TRUE,
                      COLUMN_DEFAULT, TRUE,
                      -1);

  g_free (string);

  string = g_markup_printf_escaped ("%s",
                                    g_app_info_get_name (app) != NULL ?
                                    g_app_info_get_name (app) : "");

  icon = g_app_info_get_icon (app);
  if (icon == NULL)
    {
      icon = g_themed_icon_new ("application-x-executable");
      unref_icon = TRUE;
    }

  gtk_list_store_append (self->priv->program_list_store, &iter);
  gtk_list_store_set (self->priv->program_list_store, &iter,
                      COLUMN_APP_INFO, app,
                      COLUMN_GICON, icon,
                      COLUMN_NAME, g_app_info_get_name (app),
                      COLUMN_DESC, string,
                      COLUMN_EXEC, g_app_info_get_executable (app),
                      COLUMN_HEADING, FALSE,
                      COLUMN_DEFAULT, TRUE,
                      -1);

  g_free (string);

  if (unref_icon)
    g_object_unref (icon);
}
Ejemplo n.º 13
0
static void
combo_changed_cb (GtkAppChooserButton *button,
                  gpointer             user_data)
{
  GAppInfo *app_info;

  app_info = gtk_app_chooser_get_app_info (GTK_APP_CHOOSER (button));

  if (app_info == NULL)
    return;

  gtk_image_set_from_gicon (GTK_IMAGE (sel_image), g_app_info_get_icon (app_info));
  gtk_label_set_text (GTK_LABEL (sel_name), g_app_info_get_display_name (app_info));

  g_object_unref (app_info);
}
Ejemplo n.º 14
0
static void
combo_changed_cb (GtkComboBox *cb,
                  gpointer     user_data)
{
  GAppInfo *app_info;

  app_info = gtk_app_chooser_get_app_info (GTK_APP_CHOOSER (cb));

  if (app_info == NULL)
    return;

  gtk_image_set_from_gicon (GTK_IMAGE (sel_image), g_app_info_get_icon (app_info),
                            GTK_ICON_SIZE_DIALOG);
  gtk_label_set_text (GTK_LABEL (sel_name), g_app_info_get_display_name (app_info));

  g_object_unref (app_info);
}
static void
add_application (CcNotificationsPanel *panel,
                 Application          *app)
{
  GtkWidget *box, *w;
  GIcon *icon;

  icon = g_app_info_get_icon (app->app_info);
  if (icon == NULL)
    icon = g_themed_icon_new ("application-x-executable");
  else
    g_object_ref (icon);

  box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
  g_object_set_qdata_full (G_OBJECT (box), application_quark (),
                           app, (GDestroyNotify) application_free);

  gtk_container_add (GTK_CONTAINER (panel->list_box), box);

  w = gtk_image_new_from_gicon (icon, GTK_ICON_SIZE_DIALOG);
  gtk_widget_set_margin_left (w, 12);
  gtk_container_add (GTK_CONTAINER (box), w);
  g_object_unref (icon);

  w = gtk_label_new (g_app_info_get_name (app->app_info));
  gtk_container_add (GTK_CONTAINER (box), w);

  w = gtk_label_new ("");
  g_settings_bind_with_mapping (app->settings, "enable",
                                w, "label",
                                G_SETTINGS_BIND_GET |
                                G_SETTINGS_BIND_NO_SENSITIVITY,
                                on_off_label_mapping_get,
                                NULL,
                                NULL,
                                NULL);
  gtk_widget_set_margin_right (w, 12);
  gtk_widget_set_valign (w, GTK_ALIGN_CENTER);
  gtk_box_pack_end (GTK_BOX (box), w, FALSE, FALSE, 0);

  gtk_widget_show_all (box);

  g_hash_table_add (panel->known_applications, g_strdup (app->canonical_app_id));
}
Ejemplo n.º 16
0
static GList *
xde_action(MenuContext *ctx, GMenuTreeEntry *ent, GDesktopAppInfo *info, const char *action)
{
	GList *text = NULL;
	const char *name, *path;
	char *esc1, *esc2, *cmd, *p;
	char *s, *icon = NULL;
	GIcon *gicon = NULL;
	char *appid;

	name = g_desktop_app_info_get_action_name(info, action);
	esc1 = xde_character_escape(name, ')');

	if ((appid = strdup(gmenu_tree_entry_get_desktop_file_id(ent)))
			&& (p = strstr(appid, ".desktop")))
		*p = '\0';
	if (ctx->stack)
		gicon = gmenu_tree_directory_get_icon(ctx->stack->data);
	if ((path = gmenu_tree_entry_get_desktop_file_path(ent))) {
		GKeyFile *file = g_key_file_new();

		g_key_file_load_from_file(file, path, G_KEY_FILE_NONE, NULL);
		icon = xde_get_action_icon(ctx, file, action, gicon, "exec", "unknown",
				GET_ENTRY_ICON_FLAG_XPM | GET_ENTRY_ICON_FLAG_PNG |
				GET_ENTRY_ICON_FLAG_JPG | GET_ENTRY_ICON_FLAG_SVG);
		g_key_file_unref(file);
	} else
		icon = xde_get_icon2(ctx, "exec", "unknown");
	gicon = g_app_info_get_icon(G_APP_INFO(info));
	if (options.launch)
		cmd = g_strdup_printf("xdg-launch --pointer --action='%s' %s", action, appid);
	else
		cmd = xde_get_action(info, appid, icon, action);
	esc2 = xde_character_escape(cmd, '}');
	icon = ctx->wmm.wrap(ctx, icon);
	s = g_strdup_printf("%s[exec] (%s) {%s}%s\n", ctx->indent, esc1, esc2, icon);
	text = g_list_append(text, s);
	free(icon);
	free(appid);
	free(esc1);
	free(esc2);
	free(cmd);
	return (text);
}
Ejemplo n.º 17
0
static void
activate_open_with_application_item (GtkMenuItem *menuitem,
				     gpointer     data)
{
	GthBrowser          *browser = data;
	GList               *items;
	GList               *file_list;
	GList               *uris;
	GList               *scan;
	GAppInfo            *appinfo;
	GdkAppLaunchContext *context;
	GError              *error = NULL;

	items = gth_file_selection_get_selected (GTH_FILE_SELECTION (gth_browser_get_file_list_view (browser)));
	file_list = gth_file_list_get_files (GTH_FILE_LIST (gth_browser_get_file_list (browser)), items);

	uris = NULL;
	for (scan = file_list; scan; scan = scan->next) {
		GthFileData *file_data = scan->data;
		uris = g_list_prepend (uris, g_file_get_uri (file_data->file));
	}
	uris = g_list_reverse (uris);

	appinfo = g_object_get_data (G_OBJECT (menuitem), "appinfo");
	g_return_if_fail (G_IS_APP_INFO (appinfo));

	context = gdk_display_get_app_launch_context (gtk_widget_get_display (GTK_WIDGET (browser)));
	gdk_app_launch_context_set_timestamp (context, 0);
	gdk_app_launch_context_set_icon (context, g_app_info_get_icon (appinfo));
	if (! g_app_info_launch_uris (appinfo, uris, G_APP_LAUNCH_CONTEXT (context), &error)) {
		_gtk_error_dialog_from_gerror_show (GTK_WINDOW (browser),
						    _("Could not perform the operation"),
						    error);
		g_clear_error (&error);
	}

	g_object_unref (context);
	g_list_free (uris);
	_g_object_list_unref (file_list);
	_gtk_tree_path_list_free (items);
}
Ejemplo n.º 18
0
static void
insert_one_application (GtkAppChooserButton *self,
                        GAppInfo            *app,
                        GtkTreeIter         *iter)
{
  GIcon *icon;

  icon = g_app_info_get_icon (app);

  if (icon == NULL)
    icon = g_themed_icon_new ("application-x-executable");
  else
    g_object_ref (icon);

  gtk_list_store_set (self->priv->store, iter,
                      COLUMN_APP_INFO, app,
                      COLUMN_LABEL, g_app_info_get_name (app),
                      COLUMN_ICON, icon,
                      COLUMN_CUSTOM, FALSE,
                      -1);

  g_object_unref (icon);
}
Ejemplo n.º 19
0
void
ephy_web_application_setup_from_desktop_file (GDesktopAppInfo *desktop_info)
{
  GAppInfo *app_info;
  const char *wm_class;
  GIcon *icon;

  g_assert (G_IS_DESKTOP_APP_INFO (desktop_info));

  app_info = G_APP_INFO (desktop_info);
  g_set_prgname (g_app_info_get_name (app_info));
  g_set_application_name (g_app_info_get_display_name (app_info));

  icon = g_app_info_get_icon (app_info);
  if (G_IS_FILE_ICON (icon)) {
    GFile *file = g_file_icon_get_file (G_FILE_ICON (icon));
    char *path = file ? g_file_get_path (file) : NULL;

    if (path) {
      gtk_window_set_default_icon_from_file (path, NULL);
      g_free (path);
    }
    g_clear_object (&file);
  } else if (G_IS_THEMED_ICON (icon)) {
    const char * const *names = g_themed_icon_get_names (G_THEMED_ICON (icon));
    if (names)
      gtk_window_set_default_icon_name (names[0]);
  }
  g_clear_object (&icon);

  /* We need to re-set this because we have already parsed the
   * options, which inits GTK+ and sets this as a side effect.
   */
  wm_class = g_desktop_app_info_get_startup_wm_class (desktop_info);
  if (wm_class)
    gdk_set_program_class (wm_class);
}
Ejemplo n.º 20
0
static void
_launch_app (OlPlayerChooser *window,
             GAppInfo *app_info)
{
  GError *err = NULL;
  if (!g_app_info_launch (app_info, NULL, NULL, &err))
  {
    ol_errorf ("Cannot launch %s: %s",
               g_app_info_get_commandline (app_info),
               err->message);
    gchar *title = g_strdup_printf (_("Failed to launch %s"),
                                    g_app_info_get_name (app_info));
    ol_player_chooser_set_info (window, title, err->message);
    ol_player_chooser_set_image_by_name (window, GTK_STOCK_DIALOG_ERROR);
    g_free (title);
    g_error_free (err);
  }
  else
  {
    _set_launch_app (window, app_info);
    gchar *title = g_strdup_printf (_("Launching %s"),
                                    g_app_info_get_name (app_info));
    gchar *desc = g_strdup_printf (_("OSD Lyrics is trying to launch and connect to %s. Please wait for a second."),
                                   g_app_info_get_name (app_info));
    ol_player_chooser_set_info (window, title, desc);
    g_free (title);
    g_free (desc);
    ol_player_chooser_set_image_by_gicon (window, g_app_info_get_icon (app_info));
    _set_sensitive (window, FALSE);
    if (OL_IS_PLAYER_CHOOSER (window))
    {
      _remember_cmd_if_needed (window, g_app_info_get_commandline (app_info));
      gtk_dialog_response (GTK_DIALOG (window), OL_PLAYER_CHOOSER_RESPONSE_LAUNCH);
    }
  }
}
Ejemplo n.º 21
0
void
caja_autorun_prepare_combo_box (GtkWidget *combo_box,
                                const char *x_content_type,
                                gboolean include_ask,
                                gboolean include_open_with_other_app,
                                gboolean update_settings,
                                CajaAutorunComboBoxChanged changed_cb,
                                gpointer user_data)
{
    GList *l;
    GList *app_info_list;
    GAppInfo *default_app_info;
    GtkListStore *list_store;
    GtkTreeIter iter;
    GdkPixbuf *pixbuf;
    int icon_size;
    int set_active;
    int n;
    int num_apps;
    gboolean pref_ask;
    gboolean pref_start_app;
    gboolean pref_ignore;
    gboolean pref_open_folder;
    CajaAutorunComboBoxData *data;
    GtkCellRenderer *renderer;
    gboolean new_data;

    caja_autorun_get_preferences (x_content_type, &pref_start_app, &pref_ignore, &pref_open_folder);
    pref_ask = !pref_start_app && !pref_ignore && !pref_open_folder;

    icon_size = caja_get_icon_size_for_stock_size (GTK_ICON_SIZE_MENU);

    set_active = -1;
    data = NULL;
    new_data = TRUE;

    app_info_list = g_app_info_get_all_for_type (x_content_type);
    default_app_info = g_app_info_get_default_for_type (x_content_type, FALSE);
    num_apps = g_list_length (app_info_list);

    list_store = gtk_list_store_new (5,
                                     GDK_TYPE_PIXBUF,
                                     G_TYPE_STRING,
                                     G_TYPE_APP_INFO,
                                     G_TYPE_STRING,
                                     G_TYPE_INT);

    /* no apps installed */
    if (num_apps == 0)
    {
        gtk_list_store_append (list_store, &iter);
        pixbuf = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (),
                                           GTK_STOCK_DIALOG_ERROR,
                                           icon_size,
                                           0,
                                           NULL);

        /* TODO: integrate with PackageKit-mate to find applications */

        gtk_list_store_set (list_store, &iter,
                            COLUMN_AUTORUN_PIXBUF, pixbuf,
                            COLUMN_AUTORUN_NAME, _("No applications found"),
                            COLUMN_AUTORUN_APP_INFO, NULL,
                            COLUMN_AUTORUN_X_CONTENT_TYPE, x_content_type,
                            COLUMN_AUTORUN_ITEM_TYPE, AUTORUN_ASK,
                            -1);
        g_object_unref (pixbuf);
    }
    else
    {
        if (include_ask)
        {
            gtk_list_store_append (list_store, &iter);
            pixbuf = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (),
                                               GTK_STOCK_DIALOG_QUESTION,
                                               icon_size,
                                               0,
                                               NULL);
            gtk_list_store_set (list_store, &iter,
                                COLUMN_AUTORUN_PIXBUF, pixbuf,
                                COLUMN_AUTORUN_NAME, _("Ask what to do"),
                                COLUMN_AUTORUN_APP_INFO, NULL,
                                COLUMN_AUTORUN_X_CONTENT_TYPE, x_content_type,
                                COLUMN_AUTORUN_ITEM_TYPE, AUTORUN_ASK,
                                -1);
            g_object_unref (pixbuf);
        }

        gtk_list_store_append (list_store, &iter);
        pixbuf = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (),
                                           GTK_STOCK_CLOSE,
                                           icon_size,
                                           0,
                                           NULL);
        gtk_list_store_set (list_store, &iter,
                            COLUMN_AUTORUN_PIXBUF, pixbuf,
                            COLUMN_AUTORUN_NAME, _("Do Nothing"),
                            COLUMN_AUTORUN_APP_INFO, NULL,
                            COLUMN_AUTORUN_X_CONTENT_TYPE, x_content_type,
                            COLUMN_AUTORUN_ITEM_TYPE, AUTORUN_IGNORE,
                            -1);
        g_object_unref (pixbuf);

        gtk_list_store_append (list_store, &iter);
        pixbuf = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (),
                                           "folder-open",
                                           icon_size,
                                           0,
                                           NULL);
        gtk_list_store_set (list_store, &iter,
                            COLUMN_AUTORUN_PIXBUF, pixbuf,
                            COLUMN_AUTORUN_NAME, _("Open Folder"),
                            COLUMN_AUTORUN_APP_INFO, NULL,
                            COLUMN_AUTORUN_X_CONTENT_TYPE, x_content_type,
                            COLUMN_AUTORUN_ITEM_TYPE, AUTORUN_OPEN_FOLDER,
                            -1);
        g_object_unref (pixbuf);

        gtk_list_store_append (list_store, &iter);
        gtk_list_store_set (list_store, &iter,
                            COLUMN_AUTORUN_PIXBUF, NULL,
                            COLUMN_AUTORUN_NAME, NULL,
                            COLUMN_AUTORUN_APP_INFO, NULL,
                            COLUMN_AUTORUN_X_CONTENT_TYPE, NULL,
                            COLUMN_AUTORUN_ITEM_TYPE, AUTORUN_SEP,
                            -1);

        for (l = app_info_list, n = include_ask ? 4 : 3; l != NULL; l = l->next, n++)
        {
            GIcon *icon;
            CajaIconInfo *icon_info;
            char *open_string;
            GAppInfo *app_info = l->data;

            /* we deliberately ignore should_show because some apps might want
             * to install special handlers that should be hidden in the regular
             * application launcher menus
             */

            icon = g_app_info_get_icon (app_info);
            icon_info = caja_icon_info_lookup (icon, icon_size);
            pixbuf = caja_icon_info_get_pixbuf_at_size (icon_info, icon_size);
            g_object_unref (icon_info);

            open_string = g_strdup_printf (_("Open %s"), g_app_info_get_display_name (app_info));

            gtk_list_store_append (list_store, &iter);
            gtk_list_store_set (list_store, &iter,
                                COLUMN_AUTORUN_PIXBUF, pixbuf,
                                COLUMN_AUTORUN_NAME, open_string,
                                COLUMN_AUTORUN_APP_INFO, app_info,
                                COLUMN_AUTORUN_X_CONTENT_TYPE, x_content_type,
                                COLUMN_AUTORUN_ITEM_TYPE, AUTORUN_APP,
                                -1);
            if (pixbuf != NULL)
            {
                g_object_unref (pixbuf);
            }
            g_free (open_string);

            if (g_app_info_equal (app_info, default_app_info))
            {
                set_active = n;
            }
        }
    }

    if (include_open_with_other_app)
    {
        gtk_list_store_append (list_store, &iter);
        gtk_list_store_set (list_store, &iter,
                            COLUMN_AUTORUN_PIXBUF, NULL,
                            COLUMN_AUTORUN_NAME, NULL,
                            COLUMN_AUTORUN_APP_INFO, NULL,
                            COLUMN_AUTORUN_X_CONTENT_TYPE, NULL,
                            COLUMN_AUTORUN_ITEM_TYPE, AUTORUN_SEP,
                            -1);

        gtk_list_store_append (list_store, &iter);
        pixbuf = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (),
                                           "application-x-executable",
                                           icon_size,
                                           0,
                                           NULL);
        gtk_list_store_set (list_store, &iter,
                            COLUMN_AUTORUN_PIXBUF, pixbuf,
                            COLUMN_AUTORUN_NAME, _("Open with other Application..."),
                            COLUMN_AUTORUN_APP_INFO, NULL,
                            COLUMN_AUTORUN_X_CONTENT_TYPE, x_content_type,
                            COLUMN_AUTORUN_ITEM_TYPE, AUTORUN_OTHER_APP,
                            -1);
        g_object_unref (pixbuf);
    }

    if (default_app_info != NULL)
    {
        g_object_unref (default_app_info);
    }
    g_list_foreach (app_info_list, (GFunc) g_object_unref, NULL);
    g_list_free(app_info_list);

    gtk_combo_box_set_model (GTK_COMBO_BOX (combo_box), GTK_TREE_MODEL (list_store));
    g_object_unref (G_OBJECT (list_store));

    gtk_cell_layout_clear (GTK_CELL_LAYOUT (combo_box));

    renderer = gtk_cell_renderer_pixbuf_new ();
    gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo_box), renderer, FALSE);
    gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combo_box), renderer,
                                    "pixbuf", COLUMN_AUTORUN_PIXBUF,
                                    NULL);
    renderer = gtk_cell_renderer_text_new ();
    gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo_box), renderer, TRUE);
    gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combo_box), renderer,
                                    "text", COLUMN_AUTORUN_NAME,
                                    NULL);
    gtk_combo_box_set_row_separator_func (GTK_COMBO_BOX (combo_box), combo_box_separator_func, NULL, NULL);

    if (num_apps == 0)
    {
        gtk_combo_box_set_active (GTK_COMBO_BOX (combo_box), 0);
        gtk_widget_set_sensitive (combo_box, FALSE);
    }
    else
    {
        gtk_widget_set_sensitive (combo_box, TRUE);
        if (pref_ask && include_ask)
        {
            gtk_combo_box_set_active (GTK_COMBO_BOX (combo_box), 0);
        }
        else if (pref_ignore)
        {
            gtk_combo_box_set_active (GTK_COMBO_BOX (combo_box), include_ask ? 1 : 0);
        }
        else if (pref_open_folder)
        {
            gtk_combo_box_set_active (GTK_COMBO_BOX (combo_box), include_ask ? 2 : 1);
        }
        else if (set_active != -1)
        {
            gtk_combo_box_set_active (GTK_COMBO_BOX (combo_box), set_active);
        }
        else
        {
            gtk_combo_box_set_active (GTK_COMBO_BOX (combo_box), include_ask ? 1 : 0);
        }

        /* See if we have an old data around */
        data = g_object_get_data (G_OBJECT (combo_box), "caja_autorun_combobox_data");
        if (data)
        {
            new_data = FALSE;
            g_free (data->x_content_type);
        }
        else
        {
            data = g_new0 (CajaAutorunComboBoxData, 1);
        }

        data->x_content_type = g_strdup (x_content_type);
        data->include_ask = include_ask;
        data->include_open_with_other_app = include_open_with_other_app;
        data->update_settings = update_settings;
        data->changed_cb = changed_cb;
        data->user_data = user_data;
        data->combo_box = combo_box;
        if (data->changed_signal_id == 0)
        {
            data->changed_signal_id = g_signal_connect (G_OBJECT (combo_box),
                                      "changed",
                                      G_CALLBACK (combo_box_changed),
                                      data);
        }
    }

    if (new_data)
    {
        g_object_set_data_full (G_OBJECT (combo_box),
                                "caja_autorun_combobox_data",
                                data,
                                (GDestroyNotify) caja_autorun_combobox_data_destroy);
    }
}
Ejemplo n.º 22
0
char *
mpl_gdk_windowing_get_startup_notify_id (GAppLaunchContext *context,
                                         GAppInfo          *info, 
                                         GList             *files)
{
  static int sequence = 0;
#if 0
  GdkAppLaunchContextPrivate *priv;
#endif
  GdkDisplay *display;
  GdkScreen *screen;
  int files_count;
  char *description;
  char *icon_name;
  const char *binary_name;
  const char *application_id;
  char *screen_str;
  char *workspace_str;
#if 0
  GIcon *icon;
#endif
  guint32 timestamp;
  char *startup_id;

#if 0
  priv = GDK_APP_LAUNCH_CONTEXT (context)->priv;

  if (priv->screen)
    {
      screen = priv->screen;
      display = gdk_screen_get_display (priv->screen);
    }
  else if (priv->display)
    {
      display = priv->display;
      screen = gdk_display_get_default_screen (display);
    }
  else
    {
      display = gdk_display_get_default ();
      screen = gdk_display_get_default_screen (display);
    }
#else
      display = gdk_display_get_default ();
      screen = gdk_display_get_default_screen (display);
#endif

  files_count = g_list_length (files);
  if (files_count == 0)
    description = g_strdup_printf (_("Starting %s"), g_app_info_get_name (info));
  else if (files_count == 1)
    description = g_strdup_printf (_("Opening %s"), get_display_name (files->data));
  else
    description = g_strdup_printf (g_dngettext (GETTEXT_PACKAGE,
						"Opening %d Item",
						"Opening %d Items",
						files_count), files_count);

  icon_name = NULL;
#if 0
  if (priv->icon_name)
    icon_name = g_strdup (priv->icon_name);
  else
    {
      icon = NULL;

      if (priv->icon != NULL)
	icon = g_object_ref (priv->icon);
      else if (files_count == 1)
	icon = get_icon (files->data);

      if (icon == NULL)
	{
	  icon = g_app_info_get_icon (info);
	  g_object_ref (icon);
	}

      if (icon)
	icon_name = gicon_to_string (icon);

      g_object_unref (icon);
    }
#endif

  binary_name = g_app_info_get_executable (info);

#if 0
  timestamp = priv->timestamp;
  if (timestamp == GDK_CURRENT_TIME)
#endif
    timestamp = gdk_x11_display_get_user_time (display);

  screen_str = g_strdup_printf ("%d", gdk_screen_get_number (screen));
#if 0
  if (priv->workspace > -1) 
    workspace_str = g_strdup_printf ("%d", priv->workspace);
  else
#endif
    workspace_str = NULL;

  if (G_IS_DESKTOP_APP_INFO (info))
    application_id = g_desktop_app_info_get_filename (G_DESKTOP_APP_INFO (info));
  else
    application_id = NULL;

  startup_id = g_strdup_printf ("%s-%lu-%s-%s-%d_TIME%lu",
				g_get_prgname (),
				(unsigned long)getpid (),
				g_get_host_name (),
				binary_name,
				sequence++,
				(unsigned long)timestamp);

  
  gdk_x11_display_broadcast_startup_message (display, "new",
					     "ID", startup_id,
					     "NAME", g_app_info_get_name (info),
					     "SCREEN", screen_str,
					     "BIN", binary_name,
					     "ICON", icon_name,
					     "DESKTOP", workspace_str,
					     "DESCRIPTION", description,
					     "WMCLASS", NULL, /* FIXME */
					     "APPLICATION_ID", application_id,
					     NULL);

  g_free (description);
  g_free (screen_str);
  g_free (workspace_str);
  g_free (icon_name);

  add_startup_timeout (screen, startup_id);

  return startup_id;
}
Ejemplo n.º 23
0
/* create the "open with" dialog. */
void
dlg_open_with (FrWindow *window,
	       GList    *file_list)
{
	DialogData *data;
	GAppInfo *app;
	GList *scan, *app_names = NULL;
	char **editors;
	int i;
	GtkWidget *cancel_button;
	GtkTreeIter iter;
	GtkCellRenderer *renderer;
	GtkTreeViewColumn *column;
	GtkIconTheme *theme;
	int icon_size;

	if (file_list == NULL)
		return;

	data = g_new0 (DialogData, 1);
	data->settings = g_settings_new (EXRED_SCHEMA_GENERAL);
	data->builder = _gtk_builder_new_from_file ("open-with.ui");
	if (data->builder == NULL) {
		g_free (data);
		return;
	}

	data->file_list = path_list_dup (file_list);
	data->window = window;

	/* Get the widgets. */

	data->dialog = _gtk_builder_get_widget (data->builder, "open_with_dialog");
	data->o_app_tree_view = _gtk_builder_get_widget (data->builder, "o_app_list_tree_view");
	data->o_recent_tree_view = _gtk_builder_get_widget (data->builder, "o_recent_tree_view");
	data->o_app_entry = _gtk_builder_get_widget (data->builder, "o_app_entry");
	data->o_del_button = _gtk_builder_get_widget (data->builder, "o_del_button");
	data->ok_button = _gtk_builder_get_widget (data->builder, "o_ok_button");
	cancel_button = _gtk_builder_get_widget (data->builder, "o_cancel_button");

	gtk_widget_set_sensitive (data->ok_button, FALSE);

	/* Set the signals handlers. */

	g_signal_connect (G_OBJECT (data->dialog),
			  "destroy",
			  G_CALLBACK (open_with__destroy_cb),
			  data);

	g_signal_connect (G_OBJECT (data->o_app_entry),
			  "changed",
			  G_CALLBACK (app_entry__changed_cb),
			  data);

	g_signal_connect (G_OBJECT (gtk_tree_view_get_selection (GTK_TREE_VIEW (data->o_app_tree_view))),
			  "changed",
			  G_CALLBACK (app_list_selection_changed_cb),
			  data);
	g_signal_connect (G_OBJECT (data->o_app_tree_view),
			  "row_activated",
			  G_CALLBACK (app_activated_cb),
			  data);

	g_signal_connect (G_OBJECT (gtk_tree_view_get_selection (GTK_TREE_VIEW (data->o_recent_tree_view))),
			  "changed",
			  G_CALLBACK (recent_list_selection_changed_cb),
			  data);
	g_signal_connect (G_OBJECT (data->o_recent_tree_view),
			  "row_activated",
			  G_CALLBACK (recent_activated_cb),
			  data);

	g_signal_connect (G_OBJECT (data->ok_button),
			  "clicked",
			  G_CALLBACK (open_cb),
			  data);
	g_signal_connect_swapped (G_OBJECT (cancel_button),
				  "clicked",
				  G_CALLBACK (gtk_widget_destroy),
				  G_OBJECT (data->dialog));
	g_signal_connect (G_OBJECT (data->o_del_button),
			  "clicked",
			  G_CALLBACK (delete_recent_cb),
			  data);

	/* Set data. */

	/* * registered applications list. */

	data->app_list = NULL;
	for (scan = data->file_list; scan; scan = scan->next) {
		const char *mime_type;
		const char *name = scan->data;

		mime_type = get_file_mime_type_for_path (name, FALSE);
		if ((mime_type != NULL) && ! g_content_type_is_unknown (mime_type))
			data->app_list = g_list_concat (data->app_list, g_app_info_get_all_for_type (mime_type));
	}

	data->app_model = GTK_TREE_MODEL (gtk_list_store_new (N_COLUMNS,
							      GDK_TYPE_PIXBUF,
							      G_TYPE_STRING,
							      G_TYPE_POINTER));

	gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (data->app_model),
					      TEXT_COLUMN,
					      GTK_SORT_ASCENDING);

	gtk_tree_view_set_model (GTK_TREE_VIEW (data->o_app_tree_view),
				 data->app_model);
	g_object_unref (G_OBJECT (data->app_model));

	theme = gtk_icon_theme_get_default ();
	icon_size = get_folder_pixbuf_size_for_list (GTK_WIDGET (data->dialog));

	for (scan = data->app_list; scan; scan = scan->next) {
		gboolean   found;
		char      *utf8_name;
		GdkPixbuf *icon_image = NULL;

		app = scan->data;

		found = FALSE;
		if (app_names != NULL) {
			GList *p;
			for (p = app_names; p && !found; p = p->next)
				if (g_strcmp0 ((char*)p->data, g_app_info_get_executable (app)) == 0)
					found = TRUE;
		}

		if (found)
			continue;

		app_names = g_list_prepend (app_names, (char*) g_app_info_get_executable (app));

		utf8_name = g_locale_to_utf8 (g_app_info_get_name (app), -1, NULL, NULL, NULL);	
		icon_image = get_icon_pixbuf (g_app_info_get_icon (app), icon_size, theme);
		
		gtk_list_store_append (GTK_LIST_STORE (data->app_model),
				       &iter);
		gtk_list_store_set (GTK_LIST_STORE (data->app_model),
				    &iter,
				    ICON_COLUMN, icon_image,
				    TEXT_COLUMN, utf8_name,
				    DATA_COLUMN, app,
				    -1);

		g_free (utf8_name);
	}

	column = gtk_tree_view_column_new ();

	renderer = gtk_cell_renderer_pixbuf_new ();
	gtk_tree_view_column_pack_start (column, renderer, FALSE);
	gtk_tree_view_column_set_attributes (column, renderer,
					     "pixbuf", ICON_COLUMN,
					     NULL);

	renderer = gtk_cell_renderer_text_new ();
	gtk_tree_view_column_pack_start (column,
					 renderer,
					 TRUE);
	gtk_tree_view_column_set_attributes (column, renderer,
					     "text", TEXT_COLUMN,
					     NULL);

	gtk_tree_view_append_column (GTK_TREE_VIEW (data->o_app_tree_view),
				     column);

	if (app_names)
		g_list_free (app_names);

	/* * recent editors list. */

	data->recent_model = GTK_TREE_MODEL (gtk_list_store_new (1, G_TYPE_STRING));
	gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (data->recent_model), 0, GTK_SORT_ASCENDING);

	gtk_tree_view_set_model (GTK_TREE_VIEW (data->o_recent_tree_view),
				 data->recent_model);
	g_object_unref (G_OBJECT (data->recent_model));

	editors = g_settings_get_strv (data->settings, PREF_GENERAL_EDITORS);
	for (i = 0; editors[i] != NULL; i++) {
		gtk_list_store_append (GTK_LIST_STORE (data->recent_model), &iter);
		gtk_list_store_set (GTK_LIST_STORE (data->recent_model), &iter,
				    0, editors[i],
				    -1);
	}
	g_strfreev (editors);

	renderer = gtk_cell_renderer_text_new ();
	column = gtk_tree_view_column_new_with_attributes (NULL,
							   renderer,
							   "text", 0,
							   NULL);
	gtk_tree_view_column_set_sort_column_id (column, 0);
	gtk_tree_view_append_column (GTK_TREE_VIEW (data->o_recent_tree_view),
				     column);

	/* Run dialog. */
	gtk_window_set_transient_for (GTK_WINDOW (data->dialog),
				      GTK_WINDOW (window));
	gtk_window_set_modal (GTK_WINDOW (data->dialog), TRUE);
	gtk_widget_show_all (data->dialog);
}
Ejemplo n.º 24
0
static void
_gth_browser_update_open_menu (GthBrowser *browser,
			       const char *path)
{
	GtkWidget    *openwith_item;
	GtkWidget    *menu;
	GList        *items;
	GList        *file_list;
	GList        *scan;
	GList        *appinfo_list;
	GHashTable   *used_mime_types;
	GthIconCache *icon_cache;
	GHashTable   *used_apps;

	openwith_item = gtk_ui_manager_get_widget (gth_browser_get_ui_manager (browser), path);
	menu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (openwith_item));
	_gtk_container_remove_children (GTK_CONTAINER (menu), NULL, NULL);

	items = gth_file_selection_get_selected (GTH_FILE_SELECTION (gth_browser_get_file_list_view (browser)));
	file_list = gth_file_list_get_files (GTH_FILE_LIST (gth_browser_get_file_list (browser)), items);

	appinfo_list = NULL;
	used_mime_types = g_hash_table_new (g_str_hash, g_str_equal);
	for (scan = file_list; scan; scan = scan->next) {
		GthFileData *file_data = scan->data;
		const char  *mime_type;

		mime_type = gth_file_data_get_mime_type (file_data);
		if ((mime_type == NULL) || g_content_type_is_unknown (mime_type))
			continue;
		if (g_hash_table_lookup (used_mime_types, mime_type) != NULL)
			continue;

		appinfo_list = g_list_concat (appinfo_list, g_app_info_get_all_for_type (mime_type));

		g_hash_table_insert (used_mime_types, (gpointer) mime_type, GINT_TO_POINTER (1));
	}
	g_hash_table_destroy (used_mime_types);

	icon_cache = gth_browser_get_menu_icon_cache (browser);
	used_apps = g_hash_table_new (g_str_hash, g_str_equal);
	for (scan = appinfo_list; scan; scan = scan->next) {
		GAppInfo  *appinfo = scan->data;
		char      *label;
		GtkWidget *menu_item;
		GIcon     *icon;

		if (strcmp (g_app_info_get_executable (appinfo), "pix") == 0)
			continue;
		if (g_hash_table_lookup (used_apps, g_app_info_get_id (appinfo)) != NULL)
			continue;
		g_hash_table_insert (used_apps, (gpointer) g_app_info_get_id (appinfo), GINT_TO_POINTER (1));

		label = g_strdup_printf ("%s", g_app_info_get_name (appinfo));
		menu_item = gtk_image_menu_item_new_with_label (label);

		icon = g_app_info_get_icon (appinfo);
		if (icon != NULL) {
			GdkPixbuf *pixbuf;

			pixbuf = gth_icon_cache_get_pixbuf (icon_cache, icon);
			gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menu_item), gtk_image_new_from_pixbuf (pixbuf));
			gtk_image_menu_item_set_always_show_image (GTK_IMAGE_MENU_ITEM (menu_item), TRUE);

			g_object_unref (pixbuf);
		}

		gtk_widget_show (menu_item);
		gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item);

		g_object_set_data_full (G_OBJECT (menu_item),
					"appinfo",
					g_object_ref (appinfo),
					g_object_unref);
		g_signal_connect (menu_item,
				  "activate",
				  G_CALLBACK (activate_open_with_application_item),
			  	  browser);

		g_free (label);
	}

	/*
	if (appinfo_list == NULL) {
		GtkWidget *menu_item;

		menu_item = gtk_image_menu_item_new_with_label (_("No application available"));
		gtk_widget_set_sensitive (menu_item, FALSE);
		gtk_widget_show (menu_item);
		gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item);
	}*/

	gtk_widget_set_sensitive (openwith_item, appinfo_list != NULL);
	gtk_widget_show (openwith_item);

	g_hash_table_destroy (used_apps);
	_g_object_list_unref (appinfo_list);
	_g_object_list_unref (file_list);
	_gtk_tree_path_list_free (items);
}
Ejemplo n.º 25
0
static void
fill_open_with_menu (GtkTreeView *view, GtkBuilder *builder, GtkTreePath *path)
{
    GtkTreeModel *model = gtk_tree_view_get_model (view);
    if (!model) {
        return;
    }
    GtkTreeIter iter;
    if (!gtk_tree_model_get_iter(model, &iter, path)) {
        return;
    }
    DatabaseSearchEntry *entry = (DatabaseSearchEntry *)iter.user_data;
    if (!entry) {
        return;
    }

    BTreeNode * node = db_search_entry_get_node (entry);

    GList *app_list = NULL;
    char *content_type = NULL;

    if (node->is_dir) {
        content_type = g_content_type_from_mime_type ("inode/directory");
    }
    else {
        content_type = g_content_type_guess (node->name, NULL, 0, NULL);
    }

    if (!content_type) {
        goto clean_up;
    }

    app_list = g_app_info_get_all_for_type (content_type);
    if (!app_list) {
        goto clean_up;
    }

    GMenu *menu_mime = G_MENU (gtk_builder_get_object (builder,
                                                       "fsearch_listview_menu_open_with_mime_section"));

    for (GList *list_iter = app_list; list_iter; list_iter = list_iter->next) {
        GAppInfo *app_info = list_iter->data;
        const char *display_name = g_app_info_get_display_name (app_info);
        const char *app_id = g_app_info_get_id (app_info);

        char detailed_action[1024] = "";
        snprintf (detailed_action, sizeof (detailed_action), "win.open_with('%s')", app_id);

        GMenuItem *menu_item = g_menu_item_new (display_name, detailed_action);
        g_menu_item_set_icon (menu_item, g_app_info_get_icon (app_info));
        g_menu_append_item (menu_mime, menu_item);
        g_object_unref (menu_item);
    }

clean_up:
    if (content_type) {
        g_free (content_type);
        content_type = NULL;
    }
    if (app_list) {
        g_list_free_full (app_list, g_object_unref);
        app_list = NULL;
    }
}
Ejemplo n.º 26
0
static CoglHandle
cinnamon_app_create_faded_icon_cpu (StTextureCache *cache,
                                 const char     *key,
                                 void           *datap,
                                 GError        **error)
{
  CreateFadedIconData *data = datap;
  CinnamonApp *app;
  GdkPixbuf *pixbuf;
  int size;
  int scale;
  CoglHandle texture;
  gint width, height, rowstride;
  guint8 n_channels;
  gboolean have_alpha;
  gint fade_start;
  gint fade_range;
  guint i, j;
  guint pixbuf_byte_size;
  guint8 *orig_pixels;
  guint8 *pixels;
  GIcon *icon;
  GtkIconInfo *info;

  app = data->app;
  size = data->size;
  scale = data->scale;

  info = NULL;

  icon = g_app_info_get_icon (G_APP_INFO (gmenu_tree_entry_get_app_info (app->entry)));
  if (icon != NULL)
    {
      info = gtk_icon_theme_lookup_by_gicon_for_scale (gtk_icon_theme_get_default (),
                                                       icon, size, scale,
                                                       GTK_ICON_LOOKUP_FORCE_SIZE);
    }

  if (info == NULL)
    {
      icon = g_themed_icon_new ("application-x-executable");
      info = gtk_icon_theme_lookup_by_gicon_for_scale (gtk_icon_theme_get_default (),
                                                       icon, size, scale,
                                                       GTK_ICON_LOOKUP_FORCE_SIZE);
      g_object_unref (icon);
    }

  if (info == NULL)
    return COGL_INVALID_HANDLE;

  pixbuf = gtk_icon_info_load_icon (info, NULL);
  g_object_unref (info);

  if (pixbuf == NULL)
    return COGL_INVALID_HANDLE;

  width = gdk_pixbuf_get_width (pixbuf);
  height = gdk_pixbuf_get_height (pixbuf);
  rowstride = gdk_pixbuf_get_rowstride (pixbuf);
  n_channels = gdk_pixbuf_get_n_channels (pixbuf);
  orig_pixels = gdk_pixbuf_get_pixels (pixbuf);
  have_alpha = gdk_pixbuf_get_has_alpha (pixbuf);

  pixbuf_byte_size = (height - 1) * rowstride +
    + width * ((n_channels * gdk_pixbuf_get_bits_per_sample (pixbuf) + 7) / 8);

  pixels = g_malloc0 (rowstride * height);
  memcpy (pixels, orig_pixels, pixbuf_byte_size);

  fade_start = width / 2;
  fade_range = width - fade_start;
  for (i = fade_start; i < width; i++)
    {
      for (j = 0; j < height; j++)
        {
          guchar *pixel = &pixels[j * rowstride + i * n_channels];
          float fade = 1.0 - ((float) i - fade_start) / fade_range;
          pixel[0] = 0.5 + pixel[0] * fade;
          pixel[1] = 0.5 + pixel[1] * fade;
          pixel[2] = 0.5 + pixel[2] * fade;
          if (have_alpha)
            pixel[3] = 0.5 + pixel[3] * fade;
        }
    }

    texture = st_cogl_texture_new_from_data_wrapper (width, height,
                                                     COGL_TEXTURE_NONE,
                                                     have_alpha ? COGL_PIXEL_FORMAT_RGBA_8888 : COGL_PIXEL_FORMAT_RGB_888,
                                                     COGL_PIXEL_FORMAT_ANY,
                                                     rowstride, pixels);

  g_free (pixels);
  g_object_unref (pixbuf);

  return texture;
}
void
nautilus_x_content_bar_set_x_content_type (NautilusXContentBar *bar, const char *x_content_type)
{					  
	char *message;
	char *description;
	GAppInfo *default_app;

	g_free (bar->priv->x_content_type);
	bar->priv->x_content_type = g_strdup (x_content_type);

	description = g_content_type_get_description (x_content_type);

	/* Customize greeting for well-known x-content types */
	if (strcmp (x_content_type, "x-content/audio-cdda") == 0) {
		message = g_strdup (_("These files are on an Audio CD."));
	} else if (strcmp (x_content_type, "x-content/audio-dvd") == 0) {
		message = g_strdup (_("These files are on an Audio DVD."));
	} else if (strcmp (x_content_type, "x-content/video-dvd") == 0) {
		message = g_strdup (_("These files are on a Video DVD."));
	} else if (strcmp (x_content_type, "x-content/video-vcd") == 0) {
		message = g_strdup (_("These files are on a Video CD."));
	} else if (strcmp (x_content_type, "x-content/video-svcd") == 0) {
		message = g_strdup (_("These files are on a Super Video CD."));
	} else if (strcmp (x_content_type, "x-content/image-photocd") == 0) {
		message = g_strdup (_("These files are on a Photo CD."));
	} else if (strcmp (x_content_type, "x-content/image-picturecd") == 0) {
		message = g_strdup (_("These files are on a Picture CD."));
	} else if (strcmp (x_content_type, "x-content/image-dcf") == 0) {
		message = g_strdup (_("The media contains digital photos."));
	} else if (strcmp (x_content_type, "x-content/audio-player") == 0) {
		message = g_strdup (_("These files are on a digital audio player."));
	} else if (strcmp (x_content_type, "x-content/software") == 0) {
		message = g_strdup (_("The media contains software."));
	} else {
		/* fallback to generic greeting */
		message = g_strdup_printf (_("The media has been detected as \"%s\"."), description);
	}


	gtk_label_set_text (GTK_LABEL (bar->priv->label), message);
	gtk_widget_show (bar->priv->label);

	/* TODO: We really need a GtkBrowserBackButton-ish widget here.. until then, we only
	 *       show the default application. */

 	default_app = g_app_info_get_default_for_type (x_content_type, FALSE);
	if (default_app != NULL) {
		char *button_text;
		const char *name;
		GIcon *icon;
		GtkWidget *image;

		icon = g_app_info_get_icon (default_app);
		if (icon != NULL) {
			GdkPixbuf *pixbuf;
			int icon_size;
			NautilusIconInfo *icon_info;
			icon_size = nautilus_get_icon_size_for_stock_size (GTK_ICON_SIZE_BUTTON);
			icon_info = nautilus_icon_info_lookup (icon, icon_size);
			pixbuf = nautilus_icon_info_get_pixbuf_at_size (icon_info, icon_size);
			image = gtk_image_new_from_pixbuf (pixbuf);
			g_object_unref (pixbuf);
			g_object_unref (icon_info);
		} else {
			image = NULL;
		}

		name = g_app_info_get_name (default_app);
		button_text = g_strdup_printf (_("Open %s"), name);

		gtk_button_set_image (GTK_BUTTON (bar->priv->button), image);
		gtk_button_set_label (GTK_BUTTON (bar->priv->button), button_text);
		gtk_widget_show (bar->priv->button);
		g_free (button_text);
		g_object_unref (default_app);
	} else {
		gtk_widget_hide (bar->priv->button);
	}

	g_free (message);
	g_free (description);
}
static void
fill_combo_box(GtkIconTheme* theme, GtkComboBox* combo_box, GList* app_list, gchar* mime)
{
    guint index = 0;
    GList* entry;
    GtkTreeModel* model;
    GtkCellRenderer* renderer;
    GtkTreeIter iter;
    GdkPixbuf* pixbuf;
    GAppInfo* default_app;

    default_app = NULL;
    if (g_strcmp0(mime, "terminal") == 0)
    {
        GSettings *terminal_settings = g_settings_new (TERMINAL_SCHEMA);
        gchar *default_terminal = g_settings_get_string (terminal_settings, TERMINAL_KEY);
        for (entry = app_list; entry != NULL; entry = g_list_next(entry))
        {
            GAppInfo* item = (GAppInfo*) entry->data;
            if (g_strcmp0 (g_app_info_get_executable (item), default_terminal) == 0)
            {
                default_app = item;
            }
        }
        g_free (default_terminal);
        g_object_unref (terminal_settings);
    }
    else if (g_strcmp0(mime, "visual") == 0)
    {
        GSettings *visual_settings = g_settings_new (VISUAL_SCHEMA);
        gchar *default_visual = g_settings_get_string (visual_settings, VISUAL_KEY);
        for (entry = app_list; entry != NULL; entry = g_list_next(entry))
        {
            GAppInfo* item = (GAppInfo*) entry->data;
            if (g_strcmp0 (g_app_info_get_executable (item), default_visual) == 0)
            {
                default_app = item;
            }
        }
        g_free (default_visual);
        g_object_unref (visual_settings);
    }
    else if (g_strcmp0(mime, "mobility") == 0)
    {
        GSettings *mobility_settings = g_settings_new (MOBILITY_SCHEMA);
        gchar *default_mobility = g_settings_get_string (mobility_settings, MOBILITY_KEY);
        for (entry = app_list; entry != NULL; entry = g_list_next(entry))
        {
            GAppInfo* item = (GAppInfo*) entry->data;
            if (g_strcmp0 (g_app_info_get_executable (item), default_mobility) == 0)
            {
                default_app = item;
            }
        }
        g_free (default_mobility);
        g_object_unref (mobility_settings);
    }
    else
    {
        default_app = g_app_info_get_default_for_type (mime, FALSE);
    }

    if (theme == NULL)
    {
        theme = gtk_icon_theme_get_default();
    }

    model = GTK_TREE_MODEL(gtk_list_store_new(4, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING));
    gtk_combo_box_set_model(combo_box, model);

    renderer = gtk_cell_renderer_pixbuf_new();

    /* Not all cells have a pixbuf, this prevents the combo box to shrink */
    gtk_cell_renderer_set_fixed_size(renderer, -1, 22);
    gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combo_box), renderer, FALSE);
    gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(combo_box), renderer,
                                   "pixbuf", PIXBUF_COL,
                                   NULL);

    renderer = gtk_cell_renderer_text_new();

    gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combo_box), renderer, TRUE);
    gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(combo_box), renderer,
                                   "text", TEXT_COL,
                                   NULL);

    for (entry = app_list; entry != NULL; entry = g_list_next(entry))
    {
        GAppInfo* item = (GAppInfo*) entry->data;

        /* Icon */
        GIcon* icon = g_app_info_get_icon(item);
        gchar* icon_name = g_icon_to_string(icon);

        if (icon_name == NULL)
        {
            /* Default icon */
            icon_name = g_strdup("binary");
        }

        pixbuf = gtk_icon_theme_load_icon(theme, icon_name, 22, 0, NULL);

        gtk_list_store_append(GTK_LIST_STORE(model), &iter);
        gtk_list_store_set(GTK_LIST_STORE(model), &iter,
                           PIXBUF_COL, pixbuf,
                           TEXT_COL, g_app_info_get_display_name(item),
                           ID_COL, g_app_info_get_id(item),
                           ICONAME_COL, icon_name,
                           -1);

        if (pixbuf)
        {
            g_object_unref(pixbuf);
        }

        /* Set the index for the default app */
        if (default_app != NULL && g_app_info_equal(item, default_app))
        {
            gtk_combo_box_set_active(combo_box, index);
        }

        g_free(icon_name);

        index++;
    }
}
static void
search_panel_add_one_app_info (CcSearchPanel *self,
                               GAppInfo *app_info,
                               gboolean default_enabled)
{
  GtkWidget *row, *box, *w;
  GIcon *icon;

  /* gnome-control-center is special cased in the shell,
     and is not configurable */
  if (g_strcmp0 (g_app_info_get_id (app_info),
                 "gnome-control-center.desktop") == 0)
    return;

  /* reset valignment of the list box */
  gtk_widget_set_valign (self->priv->list_box, GTK_ALIGN_FILL);

  row = gtk_list_box_row_new ();
  box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
  gtk_container_add (GTK_CONTAINER (row), box);
  gtk_widget_set_hexpand (box, TRUE);
  gtk_container_set_border_width (GTK_CONTAINER (box), 6);
  g_object_set_data_full (G_OBJECT (row), "app-info",
                          g_object_ref (app_info), g_object_unref);
  g_object_set_data (G_OBJECT (row), "self", self);
  gtk_container_add (GTK_CONTAINER (self->priv->list_box), row);

  icon = g_app_info_get_icon (app_info);
  if (icon == NULL)
    icon = g_themed_icon_new ("application-x-executable");
  else
    g_object_ref (icon);

  w = gtk_image_new_from_gicon (icon, GTK_ICON_SIZE_DIALOG);
  gtk_container_add (GTK_CONTAINER (box), w);
  g_object_unref (icon);

  w = gtk_label_new (g_app_info_get_name (app_info));
  gtk_container_add (GTK_CONTAINER (box), w);

  w = gtk_switch_new ();
  gtk_widget_set_valign (w, GTK_ALIGN_CENTER);
  gtk_box_pack_end (GTK_BOX (box), w, FALSE, FALSE, 0);

  if (default_enabled)
    {
      g_settings_bind_with_mapping (self->priv->search_settings, "disabled",
                                    w, "active",
                                    G_SETTINGS_BIND_DEFAULT,
                                    switch_settings_mapping_get_default_enabled,
                                    switch_settings_mapping_set_default_enabled,
                                    row, NULL);
    }
  else
    {
      g_settings_bind_with_mapping (self->priv->search_settings, "enabled",
                                    w, "active",
                                    G_SETTINGS_BIND_DEFAULT,
                                    switch_settings_mapping_get_default_disabled,
                                    switch_settings_mapping_set_default_disabled,
                                    row, NULL);
    }

  gtk_widget_show_all (row);
}
Ejemplo n.º 30
0
void resolve_item_order(pqi inst)
{
	/* Remove the old icon images; we're about to replace them. */
	if (inst->pmainicon)
		g_object_unref(inst->pmainicon);
	if (inst->pmainicon_glow)
		g_object_unref(inst->pmainicon_glow);
	
	if (inst->items != NULL) /* We've got sorting to do */
	{ /* This uses a very simple, O(N**2) sorting method. I don't feel it calls for anything more complicated. */
		psi iter, back, move;
		switch (inst->mode) /* What are we sorting by? */
		{
			case mode_static:
					for (iter = inst->items; iter != NULL; iter = iter->next) /* For each list item */
					{
						move = NULL;
						for (back = iter->prev; back != NULL; back = back->prev) /* For each behind us */
							if (back->id > iter->id) /* If it has a higher ID, move before it so the lowest id is first */
								move = back;
							else break;
						if (move)
							listsort_move(inst,move,&iter);
					}
				break;
			case mode_recent:
					for (iter = inst->items; iter != NULL; iter = iter->next) /* For each list item */
					{
						move = NULL;
						for (back = iter->prev; back != NULL; back = back->prev) /* For each behind us */
							if (back->lastaccess < iter->lastaccess) /* If the previous one was used earlier, move before it so the most recent is first */
								move = back;
							else break;
						if (move)
							listsort_move(inst,move,&iter);
					}
				break;
			case mode_unrecent:
					for (iter = inst->items; iter != NULL; iter = iter->next) /* For each list item */
					{
						move = NULL;
						for (back = iter->prev; back != NULL; back = back->prev) /* For each behind us */
							if (back->lastaccess > iter->lastaccess) /* If the previous one was used later, move before it so the least recent is first */
								move = back;
							else break;
						if (move)
							listsort_move(inst,move,&iter);
					}
				break;
			case mode_infrequent:
					for (iter = inst->items; iter != NULL; iter = iter->next) /* For each list item */
					{
						move = NULL;
						for (back = iter->prev; back != NULL; back = back->prev) /* For each behind us */
							if (back->uses > iter->uses) /* If it was used more times, move before it so the least used comes first */
								move = back;
							else break;
						if (move)
							listsort_move(inst,move,&iter);
					}
				break;
			case mode_frequent:
					for (iter = inst->items; iter != NULL; iter = iter->next) /* For each list item */
					{
						move = NULL;
						for (back = iter->prev; back != NULL; back = back->prev) /* For each behind us */
							if (back->uses < iter->uses) /* If it was used less times, move before it so the most used comes first */
								move = back;
							else break;
						if (move)
							listsort_move(inst,move,&iter);
					}
				break;
		}
		
		/* Resolve the icon */
		if (inst->items->dfile)
		{
			GIcon *ico = g_app_info_get_icon(G_APP_INFO(inst->items->dfile));
			if (ico)
				icon_gicon(inst,ico,inst->size);
			else icon_default(inst,inst->size);
		} else icon_default(inst,inst->size);
	} else icon_default(inst,inst->size);
	gtk_widget_queue_draw(inst->box);
}