Exemplo n.º 1
0
static void
refresh_and_emit_app_selected (GtkAppChooserWidget *self,
                               GtkTreeSelection    *selection)
{
  GtkTreeModel *model;
  GtkTreeIter iter;
  GAppInfo *info = NULL;
  gboolean should_emit = FALSE;

  if (gtk_tree_selection_get_selected (selection, &model, &iter))
    gtk_tree_model_get (model, &iter, COLUMN_APP_INFO, &info, -1);

  if (info == NULL)
    return;

  if (self->priv->selected_app_info)
    {
      if (!g_app_info_equal (self->priv->selected_app_info, info))
        {
          should_emit = TRUE;
          g_set_object (&self->priv->selected_app_info, info);
        }
    }
  else
    {
      should_emit = TRUE;
      g_set_object (&self->priv->selected_app_info, info);
    }

  g_object_unref (info);

  if (should_emit)
    g_signal_emit (self, signals[SIGNAL_APPLICATION_SELECTED], 0,
                   self->priv->selected_app_info);
}
static void
custom_entry_changed_cb (GtkEditable *entry, gpointer user_data)
{
    NemoMimeApplicationChooser *chooser = user_data;

    const gchar *entry_text = gtk_entry_get_text (GTK_ENTRY (entry));

    if (g_strcmp0 (entry_text, "") != 0) {
        GAppInfo *default_app;
        gchar *cl = g_strdup_printf ("%s", entry_text);
        GAppInfo *info = g_app_info_create_from_commandline (cl, NULL, G_APP_INFO_CREATE_NONE, NULL);

        default_app = g_app_info_get_default_for_type (chooser->details->content_type, FALSE);
        gtk_widget_set_sensitive (chooser->details->set_as_default_button,
                                  !g_app_info_equal (info, default_app));

        gtk_widget_set_sensitive (chooser->details->add_button,
                                  app_info_can_add (info, chooser->details->content_type));

        g_object_unref (default_app);
        if (chooser->details->custom_info != NULL) {
            g_object_unref (chooser->details->custom_info);
            chooser->details->custom_info = NULL;
        }
        chooser->details->custom_info = info;

    } else {
        if (chooser->details->custom_info != NULL) {
            g_object_unref (chooser->details->custom_info);
            chooser->details->custom_info = NULL;
        }
        gtk_widget_set_sensitive (chooser->details->set_as_default_button, FALSE);
        gtk_widget_set_sensitive (chooser->details->add_button, FALSE);
    }
}
Exemplo n.º 3
0
static gboolean
select_application_func_cb (GtkTreeModel *model,
                            GtkTreePath *path,
                            GtkTreeIter *iter,
                            gpointer user_data)
{
  SelectAppData *data = user_data;
  GAppInfo *app_to_match = data->info, *app = NULL;
  gboolean custom;

  gtk_tree_model_get (model, iter,
                      COLUMN_APP_INFO, &app,
                      COLUMN_CUSTOM, &custom,
                      -1);

  /* cutsom items are always after GAppInfos, so iterating further here
   * is just useless.
   */
  if (custom)
    return TRUE;

  if (g_app_info_equal (app, app_to_match))
    {
      gtk_combo_box_set_active_iter (GTK_COMBO_BOX (data->self), iter);
      return TRUE;
    }

  return FALSE;
}
static void
application_selected_cb (GtkAppChooserWidget *widget,
                         GAppInfo *info,
                         gpointer user_data)
{
    NemoMimeApplicationChooser *chooser = user_data;
    GAppInfo *default_app;

    default_app = g_app_info_get_default_for_type (chooser->details->content_type, FALSE);
    gtk_widget_set_sensitive (chooser->details->set_as_default_button,
                              !g_app_info_equal (info, default_app));

    gtk_widget_set_sensitive (chooser->details->add_button,
                              app_info_can_add (info, chooser->details->content_type));

    g_object_unref (default_app);
}
static void
application_selected_cb (GtkAppChooserWidget *widget,
			 GAppInfo *info,
			 gpointer user_data)
{
	NemoMimeApplicationChooser *chooser = user_data;
	GAppInfo *default_app;

	default_app = g_app_info_get_default_for_type (chooser->details->content_type, FALSE);
	gtk_widget_set_sensitive (chooser->details->set_as_default_button,
				  !g_app_info_equal (info, default_app));

	gtk_widget_set_sensitive (chooser->details->add_button,
				  app_info_can_add (info, chooser->details->content_type));

    gtk_entry_set_text (GTK_ENTRY (chooser->details->custom_entry), "");
    gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (chooser->details->file_button), "");

	g_object_unref (default_app);
}
static void
response_cb (CajaOpenWithDialog *dialog,
             int response_id,
             gpointer data)
{
    GAppInfo *application;

    switch (response_id)
    {
    case RESPONSE_OPEN:
        if (check_application (dialog))
        {
            application = add_or_find_application (dialog);

            if (application)
            {
                emit_application_selected (dialog, application);
                g_object_unref (application);

                gtk_widget_destroy (GTK_WIDGET (dialog));
            }
        }

        break;
    case RESPONSE_REMOVE:
        if (dialog->details->selected_app_info != NULL)
        {
            if (g_app_info_delete (dialog->details->selected_app_info))
            {
                GtkTreeModel *model;
                GtkTreeIter iter;
                GAppInfo *info, *selected;

                selected = dialog->details->selected_app_info;
                dialog->details->selected_app_info = NULL;

                model = GTK_TREE_MODEL (dialog->details->program_list_store);
                if (gtk_tree_model_get_iter_first (model, &iter))
                {
                    do
                    {
                        gtk_tree_model_get (model, &iter,
                                            COLUMN_APP_INFO, &info,
                                            -1);
                        if (g_app_info_equal (selected, info))
                        {
                            gtk_list_store_remove (dialog->details->program_list_store, &iter);
                            break;
                        }
                    }
                    while (gtk_tree_model_iter_next (model, &iter));
                }

                g_object_unref (selected);
            }
        }
        break;
    case GTK_RESPONSE_NONE:
    case GTK_RESPONSE_DELETE_EVENT:
    case GTK_RESPONSE_CANCEL:
        gtk_widget_destroy (GTK_WIDGET (dialog));
        break;
    default :
        g_assert_not_reached ();
    }

}
static gint
app_compare (gconstpointer a,
             gconstpointer b)
{
    return !g_app_info_equal (G_APP_INFO (a), G_APP_INFO (b));
}
Exemplo n.º 8
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);
    }
}
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++;
    }
}
Exemplo n.º 10
0
static VALUE
appinfo_equal(VALUE self, VALUE other)
{
        return CBOOL2RVAL(g_app_info_equal(_SELF(self), _SELF(other)));
}
Exemplo n.º 11
0
/* Get desktop ID from window names.
 * Callee is responsible to free result with g_object_unref().
 */
static GAppInfo* _xfdashboard_application_tracker_get_desktop_id_from_window_names(XfdashboardApplicationTracker *self,
																					XfdashboardWindowTrackerWindow *inWindow)
{
	XfdashboardApplicationTrackerPrivate	*priv;
	GAppInfo								*foundAppInfo;
	gchar									**names;
	gchar									**iter;

	g_return_val_if_fail(XFDASHBOARD_IS_APPLICATION_TRACKER(self), NULL);
	g_return_val_if_fail(XFDASHBOARD_IS_WINDOW_TRACKER_WINDOW(inWindow), NULL);

	priv=self->priv;
	foundAppInfo=NULL;

	/* Get window's names */
	names=xfdashboard_window_tracker_window_get_instance_names(inWindow);

	/* Iterate through window's names to try to find matching desktop file */
	iter=names;
	while(iter && *iter)
	{
		GAppInfo							*appInfo;

		/* Lookup application from unmodified name */
		if(g_str_has_suffix(*iter, ".desktop"))
		{
			appInfo=xfdashboard_application_database_lookup_desktop_id(priv->appDatabase, *iter);
		}
			else
			{
				gchar						*desktopID;

				desktopID=g_strconcat(*iter, ".desktop", NULL);
				appInfo=xfdashboard_application_database_lookup_desktop_id(priv->appDatabase, desktopID);
				g_free(desktopID);
			}

		/* Lookup application from to-lower-case converted name if previous
		 * lookup with unmodified name failed.
		 */
		if(!appInfo)
		{
			gchar							*lowerDesktopID;

			/* Convert name to lower case */
			lowerDesktopID=g_utf8_strdown(*iter, -1);

			/* Lookup application from lower-case name. No need to add '.desktop'
			 * as suffix as it was done before.
			 */
			if(g_str_has_suffix(lowerDesktopID, ".desktop"))
			{
				appInfo=xfdashboard_application_database_lookup_desktop_id(priv->appDatabase, lowerDesktopID);
			}
				else
				{
					gchar					*desktopID;

					desktopID=g_strconcat(lowerDesktopID, ".desktop", NULL);
					appInfo=xfdashboard_application_database_lookup_desktop_id(priv->appDatabase, desktopID);
					g_free(desktopID);
				}

			/* Free lower case of name */
			g_free(lowerDesktopID);

			/* If we still did not find an application continue with next
			 * name in list.
			 */
			if(!appInfo)
			{
				/* Continue with next name in list */
				iter++;
				continue;
			}
		}

		/* Check if found application info matches previous one. If it does not match
		 * the desktop IDs found previously are ambigous, so return NULL result.
		 */
		if(foundAppInfo &&
			!g_app_info_equal(foundAppInfo, appInfo))
		{
			g_debug("Resolved window names of '%s' are ambiguous - discarding desktop IDs '%s' and '%s'",
						xfdashboard_window_tracker_window_get_title(inWindow),
						g_app_info_get_id(foundAppInfo),
						g_app_info_get_id(appInfo));

			/* Release allocated resources */
			if(foundAppInfo) g_object_unref(foundAppInfo);
			if(appInfo) g_object_unref(appInfo);
			if(names) g_strfreev(names);

			return(NULL);
		}

		/* If it is the first application info found, remember it */
		if(!foundAppInfo) foundAppInfo=g_object_ref(appInfo);

		/* Release allocated resources */
		if(appInfo) g_object_unref(appInfo);

		/* Continue with next name in list */
		iter++;
	}

	/* Release allocated resources */
	if(names) g_strfreev(names);

	/* Return found application info */
	g_debug("Resolved window names of '%s' to desktop ID '%s'",
				xfdashboard_window_tracker_window_get_title(inWindow),
				foundAppInfo ? g_app_info_get_id(foundAppInfo) : "<nil>");

	return(foundAppInfo);
}
Exemplo n.º 12
0
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 = 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)
		{
			icon_name = g_strdup("binary"); // default icon
		}
		
		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 */
		if (default_app != NULL && g_app_info_equal(item, default_app))
		{
			gtk_combo_box_set_active(combo_box, index);
		}
		
		g_free(icon_name);
		
		index++;
	}
}
Exemplo n.º 13
0
static void on_app_selected(GtkComboBox* cb, FmAppChooserComboBoxData* data)
{
    GtkTreeIter it;
    GtkTreeModel* model;

    if( !gtk_combo_box_get_active_iter(cb, &it) )
        return;

    model = gtk_combo_box_get_model(cb);
    /* if the user chooses "Customize..." */
    if(it.user_data == data->other_apps_iter.user_data)
    {
        /* let the user choose an app or add custom actions here. */
        GtkWidget* parent = gtk_widget_get_toplevel(GTK_WIDGET(cb));
        GAppInfo* app = fm_choose_app_for_mime_type(GTK_WINDOW(parent), data->mime_type, FALSE);
        if(app)
        {
            gboolean found = FALSE;
            /* see if it's already in the list to prevent duplication */
            if(gtk_tree_model_get_iter_first(model, &it))
            {
                GAppInfo *_app;
                do
                {
                    gtk_tree_model_get(model, &it, 2, &_app, -1);
                    if(_app)
                    {
                        found = g_app_info_equal(app, _app);
                        g_object_unref(_app);
                    }
                    if(found)
                        break;
                }while(gtk_tree_model_iter_next(model, &it));
            }

            /* if it's already in the list, select it */
            if(found)
            {
                gtk_combo_box_set_active_iter(cb, &it);
            }
            else /* if it's not found, add it to the list */
            {
                gtk_list_store_insert_before(GTK_LIST_STORE(model), &it, &data->separator_iter);
                gtk_list_store_set(GTK_LIST_STORE(model), &it,
                                   0, g_app_info_get_icon(app),
                                   1, g_app_info_get_name(app),
                                   2, app, -1);
                data->prev_sel_iter = it;
                gtk_combo_box_set_active_iter(cb, &it);
                /* add to custom apps list */
                data->custom_apps = g_list_prepend(data->custom_apps, g_object_ref(app));
            }
            g_object_unref(app);
        }
        else
        {
            if(!data->prev_sel_iter.user_data)
                gtk_tree_model_get_iter_first(model, &data->prev_sel_iter);
            gtk_combo_box_set_active_iter(cb, &data->prev_sel_iter);
        }
    }
    else /* an application in the list is selected */
        data->prev_sel_iter = it;
}
Exemplo n.º 14
0
/**
 * fm_app_chooser_combo_box_setup
 * @combo: a #GtkComboBox
 * @mime_type: (allow-none): a #FmMimeType to select application
 * @apps: (allow-none) (element-type GAppInfo): custom list of applications
 * @sel: (allow-none): a selected application in @apps
 *
 * Setups a combobox for selecting default application either for
 * specified mime-type or from a list of pre-defined applications.
 * If @mime_type is %NULL, and @sel is provided and found in the @apps,
 * then it will be selected. If @mime_type is not %NULL then default
 * application for the @mime_type will be selected.
 * When set up, the combobox will contain a list of available applications.
 *
 * Since: 0.1.5
 */
void fm_app_chooser_combo_box_setup(GtkComboBox* combo, FmMimeType* mime_type, GList* apps, GAppInfo* sel)
{
    FmAppChooserComboBoxData* data = g_slice_new0(FmAppChooserComboBoxData);
    GtkListStore* store = gtk_list_store_new(3, G_TYPE_ICON, G_TYPE_STRING, G_TYPE_APP_INFO);
    GtkTreeIter it;
    GList* l;
    GtkCellRenderer* render;

    gtk_cell_layout_clear(GTK_CELL_LAYOUT(combo));

    render = gtk_cell_renderer_pixbuf_new();
    gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combo), render, FALSE);
    gtk_cell_layout_add_attribute(GTK_CELL_LAYOUT(combo), render, "gicon", 0);

    render = gtk_cell_renderer_text_new();
    gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combo), render, FALSE);
    gtk_cell_layout_add_attribute(GTK_CELL_LAYOUT(combo), render, "text", 1);

    if(mime_type)
    {
        data->mime_type = fm_mime_type_ref(mime_type);
        apps = g_app_info_get_all_for_type(fm_mime_type_get_type(data->mime_type));
        sel =  g_app_info_get_default_for_type(fm_mime_type_get_type(data->mime_type), FALSE);
    }

    for(l = apps; l; l = l->next)
    {
        GAppInfo* app = G_APP_INFO(l->data);
        gtk_list_store_insert_with_values(store, &it, -1,
                           0, g_app_info_get_icon(app),
                           1, g_app_info_get_name(app),
                           2, app, -1);
        if(sel && g_app_info_equal(app, sel))
        {
            /* this is the initially selected app */
            data->initial_sel_iter = it;
            data->initial_sel_app = (GAppInfo*)g_object_ref(app);
        }
    }

    if(mime_type) /* if this list is retrived with g_app_info_get_all_for_type() */
    {
        if(apps)
        {
            g_list_foreach(apps, (GFunc)g_object_unref, NULL);
            g_list_free(apps);
        }
        if(sel)
            g_object_unref(sel);
    }

    gtk_list_store_append(store, &it); /* separator */
    data->separator_iter = it;

    /* other applications */
    gtk_list_store_insert_with_values(store, &it, -1,
                       0, NULL,
                       1, _("Customize"), // FIXME: should be "Customize..."
                       2, NULL, -1);
    data->other_apps_iter = it;
    gtk_combo_box_set_model(combo, GTK_TREE_MODEL(store));

    if(data->initial_sel_iter.user_data) /* intital selection is set */
    {
        data->prev_sel_iter = data->initial_sel_iter;
        gtk_combo_box_set_active_iter(combo, &data->initial_sel_iter);
    }
    gtk_combo_box_set_row_separator_func(combo, is_row_separator, data, NULL);
    g_object_unref(store);

    g_signal_connect(combo, "changed", G_CALLBACK(on_app_selected), data);
    g_object_set_qdata_full(G_OBJECT(combo), fm_qdata_id, data, free_data);
}
Exemplo n.º 15
0
static void
gtk_app_chooser_button_populate (GtkAppChooserButton *self)
{
  GList *recommended_apps = NULL, *l;
  GAppInfo *app, *default_app = NULL;
  GtkTreeIter iter, iter2;
  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;

  if (self->priv->show_default_item)
    {
      if (self->priv->content_type)
        default_app = g_app_info_get_default_for_type (self->priv->content_type, FALSE);

      if (default_app != NULL)
        {
          get_first_iter (self->priv->store, &iter);
          cycled_recommended = TRUE;

          insert_one_application (self, default_app, &iter);

          g_object_unref (default_app);
        }
    }

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

      if (default_app != NULL && g_app_info_equal (app, default_app))
        continue;

      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;
        }

      insert_one_application (self, app, &iter);
    }

  if (recommended_apps != NULL)
    g_list_free_full (recommended_apps, g_object_unref);

  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);
}
/* Get desktop ID from window names.
 * Callee is responsible to free result with g_object_unref().
 */
static GAppInfo* _xfdashboard_application_tracker_get_desktop_id_from_window_names(XfdashboardApplicationTracker *self,
																					XfdashboardWindowTrackerWindow *inWindow)
{
	XfdashboardApplicationTrackerPrivate	*priv;
	GAppInfo								*foundAppInfo;
	gchar									**names;
	gchar									**iter;
	GList									*apps;

	g_return_val_if_fail(XFDASHBOARD_IS_APPLICATION_TRACKER(self), NULL);
	g_return_val_if_fail(XFDASHBOARD_IS_WINDOW_TRACKER_WINDOW(inWindow), NULL);

	priv=self->priv;
	foundAppInfo=NULL;

	/* Get list of applications */
	apps=xfdashboard_application_database_get_all_applications(priv->appDatabase);

	/* Get window's names */
	names=xfdashboard_window_tracker_window_get_instance_names(inWindow);

	/* Iterate through window's names to try to find matching desktop file */
	iter=names;
	while(iter && *iter)
	{
		GAppInfo							*appInfo;
		gchar								*iterName;
		gchar								*iterNameLowerCase;

		/* Build desktop ID from iterated name */
		if(!g_str_has_suffix(*iter, ".desktop")) iterName=g_strconcat(*iter, ".desktop", NULL);
			else iterName=g_strdup(*iter);

		iterNameLowerCase=g_utf8_strdown(iterName, -1);

		/* Lookup application from unmodified name */
		appInfo=xfdashboard_application_database_lookup_desktop_id(priv->appDatabase, iterName);

		/* Lookup application from to-lower-case converted name if previous
		 * lookup with unmodified name failed.
		 */
		if(!appInfo)
		{
			/* Lookup application from lower-case name */
			appInfo=xfdashboard_application_database_lookup_desktop_id(priv->appDatabase, iterNameLowerCase);
		}

		/* If no application was found for the name it may be an application
		 * located in a subdirectory. Then the desktop ID is prefixed with
		 * the subdirectory's name followed by a dash. So iterate through all
		 * applications and lookup with glob pattern '*-' followed by name
		 * and suffix '.desktop'.
		 */
		if(!appInfo)
		{
			GList							*iterApps;
			GList							*foundSubdirApps;
			gchar							*globName;
			GPatternSpec					*globPattern;
			GAppInfo						*globAppInfo;

			/* Build glob pattern */
			globAppInfo=NULL;
			globName=g_strconcat("*-", iterNameLowerCase, NULL);
			globPattern=g_pattern_spec_new(globName);

			/* Iterate through application and collect applications matching
			 * glob pattern.
			 */
			foundSubdirApps=NULL;
			for(iterApps=apps; iterApps; iterApps=g_list_next(iterApps))
			{
				if(!G_IS_APP_INFO(iterApps->data)) continue;
				globAppInfo=G_APP_INFO(iterApps->data);

				if(g_pattern_match_string(globPattern, g_app_info_get_id(globAppInfo)))
				{
					foundSubdirApps=g_list_prepend(foundSubdirApps, globAppInfo);
					g_debug("Found possible application '%s' for window '%s' using pattern '%s'",
							g_app_info_get_id(globAppInfo),
							xfdashboard_window_tracker_window_get_title(inWindow),
							globName);
				}
			}

			/* If exactly one application was collected because it matched
			 * the glob pattern then we found the application.
			 */
			if(g_list_length(foundSubdirApps)==1)
			{
				appInfo=G_APP_INFO(g_object_ref(G_OBJECT(foundSubdirApps->data)));

				g_debug("Found exactly one application named '%s' for window '%s' using pattern '%s'",
						g_app_info_get_id(appInfo),
						xfdashboard_window_tracker_window_get_title(inWindow),
						globName);
			}

			/* Release allocated resources */
			if(foundSubdirApps) g_list_free(foundSubdirApps);
			if(globPattern) g_pattern_spec_free(globPattern);
			if(globName) g_free(globName);
		}

		/* If we still did not find an application continue with next
		 * name in list.
		 */
		if(!appInfo)
		{
			/* Release allocated resources */
			if(iterName) g_free(iterName);
			if(iterNameLowerCase) g_free(iterNameLowerCase);

			/* Continue with next name in list */
			iter++;
			continue;
		}

		/* Check if found application info matches previous one. If it does not match
		 * the desktop IDs found previously are ambigous, so return NULL result.
		 */
		if(foundAppInfo &&
			!g_app_info_equal(foundAppInfo, appInfo))
		{
			g_debug("Resolved window names of '%s' are ambiguous - discarding desktop IDs '%s' and '%s'",
						xfdashboard_window_tracker_window_get_title(inWindow),
						g_app_info_get_id(foundAppInfo),
						g_app_info_get_id(appInfo));

			/* Release allocated resources */
			if(iterName) g_free(iterName);
			if(iterNameLowerCase) g_free(iterNameLowerCase);
			if(foundAppInfo) g_object_unref(foundAppInfo);
			if(appInfo) g_object_unref(appInfo);
			if(names) g_strfreev(names);
			if(apps) g_list_free_full(apps, g_object_unref);

			return(NULL);
		}

		/* If it is the first application info found, remember it */
		if(!foundAppInfo) foundAppInfo=g_object_ref(appInfo);

		/* Release allocated resources */
		if(iterName) g_free(iterName);
		if(iterNameLowerCase) g_free(iterNameLowerCase);
		if(appInfo) g_object_unref(appInfo);

		/* Continue with next name in list */
		iter++;
	}

	/* Release allocated resources */
	if(names) g_strfreev(names);
	if(apps) g_list_free_full(apps, g_object_unref);

	/* Return found application info */
	g_debug("Resolved window names of '%s' to desktop ID '%s'",
				xfdashboard_window_tracker_window_get_title(inWindow),
				foundAppInfo ? g_app_info_get_id(foundAppInfo) : "<nil>");

	return(foundAppInfo);
}