2010-11-16 12:47:51 +00:00
|
|
|
/*
|
2010-11-23 16:23:37 +00:00
|
|
|
* gtkappchooserdialog.c: an app-chooser dialog
|
2010-11-16 12:47:51 +00:00
|
|
|
*
|
|
|
|
* Copyright (C) 2004 Novell, Inc.
|
|
|
|
* Copyright (C) 2007, 2010 Red Hat, Inc.
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
2012-02-27 13:01:10 +00:00
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
2010-11-16 12:47:51 +00:00
|
|
|
*
|
|
|
|
* Authors: Dave Camp <dave@novell.com>
|
|
|
|
* Alexander Larsson <alexl@redhat.com>
|
|
|
|
* Cosimo Cecchi <ccecchi@redhat.com>
|
|
|
|
*/
|
|
|
|
|
2011-01-06 07:07:35 +00:00
|
|
|
/**
|
2021-02-27 04:14:34 +00:00
|
|
|
* GtkAppChooserDialog:
|
2011-01-06 07:07:35 +00:00
|
|
|
*
|
2021-02-27 04:14:34 +00:00
|
|
|
* `GtkAppChooserDialog` shows a `GtkAppChooserWidget` inside a `GtkDialog`.
|
2011-01-06 07:07:35 +00:00
|
|
|
*
|
2021-02-27 04:14:34 +00:00
|
|
|
* ![An example GtkAppChooserDialog](appchooserdialog.png)
|
2011-09-10 05:40:05 +00:00
|
|
|
*
|
2021-02-27 04:14:34 +00:00
|
|
|
* Note that `GtkAppChooserDialog` does not have any interesting methods
|
|
|
|
* of its own. Instead, you should get the embedded `GtkAppChooserWidget`
|
|
|
|
* using [method@Gtk.AppChooserDialog.get_widget] and call its methods if
|
|
|
|
* the generic [iface@Gtk.AppChooser] interface is not sufficient for
|
|
|
|
* your needs.
|
|
|
|
*
|
|
|
|
* To set the heading that is shown above the `GtkAppChooserWidget`,
|
|
|
|
* use [method@Gtk.AppChooserDialog.set_heading].
|
2011-01-06 07:07:35 +00:00
|
|
|
*/
|
2010-11-24 23:32:05 +00:00
|
|
|
#include "config.h"
|
2010-11-16 12:47:51 +00:00
|
|
|
|
2010-11-23 16:23:37 +00:00
|
|
|
#include "gtkappchooserdialog.h"
|
2010-11-16 12:47:51 +00:00
|
|
|
|
|
|
|
#include "gtkintl.h"
|
2010-11-23 16:23:37 +00:00
|
|
|
#include "gtkappchooser.h"
|
2010-11-24 23:32:05 +00:00
|
|
|
#include "gtkappchooserprivate.h"
|
|
|
|
|
|
|
|
#include "gtkmessagedialog.h"
|
2013-12-08 14:22:46 +00:00
|
|
|
#include "gtksettings.h"
|
2010-11-24 23:32:05 +00:00
|
|
|
#include "gtklabel.h"
|
2020-04-30 19:42:37 +00:00
|
|
|
#include "gtkbox.h"
|
2010-11-24 23:32:05 +00:00
|
|
|
#include "gtkbutton.h"
|
2014-02-14 12:02:32 +00:00
|
|
|
#include "gtkentry.h"
|
|
|
|
#include "gtktogglebutton.h"
|
2013-12-08 14:22:46 +00:00
|
|
|
#include "gtkheaderbar.h"
|
|
|
|
#include "gtkdialogprivate.h"
|
2014-02-14 12:02:32 +00:00
|
|
|
#include "gtksearchbar.h"
|
2015-02-27 01:55:54 +00:00
|
|
|
#include "gtksizegroup.h"
|
2010-11-16 12:47:51 +00:00
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include <glib/gi18n-lib.h>
|
|
|
|
#include <gio/gio.h>
|
|
|
|
|
2019-05-28 00:30:59 +00:00
|
|
|
typedef struct _GtkAppChooserDialogClass GtkAppChooserDialogClass;
|
|
|
|
|
|
|
|
struct _GtkAppChooserDialog {
|
|
|
|
GtkDialog parent;
|
|
|
|
|
2010-11-16 12:47:51 +00:00
|
|
|
char *content_type;
|
|
|
|
GFile *gfile;
|
2011-01-21 01:55:59 +00:00
|
|
|
char *heading;
|
2010-11-16 12:47:51 +00:00
|
|
|
|
|
|
|
GtkWidget *label;
|
2013-03-23 14:02:33 +00:00
|
|
|
GtkWidget *inner_box;
|
2010-11-16 12:47:51 +00:00
|
|
|
|
|
|
|
GtkWidget *open_label;
|
|
|
|
|
2014-02-14 12:02:32 +00:00
|
|
|
GtkWidget *search_bar;
|
|
|
|
GtkWidget *search_entry;
|
2010-11-23 16:23:37 +00:00
|
|
|
GtkWidget *app_chooser_widget;
|
2010-11-22 22:05:59 +00:00
|
|
|
GtkWidget *show_more_button;
|
2014-02-13 05:14:42 +00:00
|
|
|
GtkWidget *software_button;
|
2010-11-23 15:50:21 +00:00
|
|
|
|
2015-02-27 01:55:54 +00:00
|
|
|
GtkSizeGroup *buttons;
|
|
|
|
|
2010-11-23 15:50:21 +00:00
|
|
|
gboolean show_more_clicked;
|
2012-02-01 18:16:06 +00:00
|
|
|
gboolean dismissed;
|
2010-11-16 12:47:51 +00:00
|
|
|
};
|
|
|
|
|
2020-03-28 14:59:12 +00:00
|
|
|
struct _GtkAppChooserDialogClass {
|
|
|
|
GtkDialogClass parent_class;
|
|
|
|
};
|
|
|
|
|
2010-11-16 12:47:51 +00:00
|
|
|
enum {
|
|
|
|
PROP_GFILE = 1,
|
|
|
|
PROP_CONTENT_TYPE,
|
2011-01-25 00:25:08 +00:00
|
|
|
PROP_HEADING
|
2010-11-16 12:47:51 +00:00
|
|
|
};
|
|
|
|
|
2010-11-23 16:23:37 +00:00
|
|
|
static void gtk_app_chooser_dialog_iface_init (GtkAppChooserIface *iface);
|
|
|
|
G_DEFINE_TYPE_WITH_CODE (GtkAppChooserDialog, gtk_app_chooser_dialog, GTK_TYPE_DIALOG,
|
2010-11-24 23:32:05 +00:00
|
|
|
G_IMPLEMENT_INTERFACE (GTK_TYPE_APP_CHOOSER,
|
|
|
|
gtk_app_chooser_dialog_iface_init));
|
2010-11-16 12:47:51 +00:00
|
|
|
|
2010-11-29 17:10:06 +00:00
|
|
|
|
2010-11-24 14:49:47 +00:00
|
|
|
static void
|
|
|
|
add_or_find_application (GtkAppChooserDialog *self)
|
|
|
|
{
|
|
|
|
GAppInfo *app;
|
|
|
|
|
|
|
|
app = gtk_app_chooser_get_app_info (GTK_APP_CHOOSER (self));
|
|
|
|
|
2011-08-29 02:43:20 +00:00
|
|
|
if (app)
|
|
|
|
{
|
|
|
|
/* we don't care about reporting errors here */
|
2020-03-28 14:59:12 +00:00
|
|
|
if (self->content_type)
|
2011-08-29 02:43:20 +00:00
|
|
|
g_app_info_set_as_last_used_for_type (app,
|
2020-03-28 14:59:12 +00:00
|
|
|
self->content_type,
|
2011-08-29 02:43:20 +00:00
|
|
|
NULL);
|
|
|
|
g_object_unref (app);
|
|
|
|
}
|
2010-11-24 14:49:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_app_chooser_dialog_response (GtkDialog *dialog,
|
2020-07-24 13:54:49 +00:00
|
|
|
int response_id,
|
2010-11-24 23:32:05 +00:00
|
|
|
gpointer user_data)
|
2010-11-24 14:49:47 +00:00
|
|
|
{
|
|
|
|
GtkAppChooserDialog *self = GTK_APP_CHOOSER_DIALOG (dialog);
|
|
|
|
|
|
|
|
switch (response_id)
|
|
|
|
{
|
|
|
|
case GTK_RESPONSE_OK:
|
|
|
|
add_or_find_application (self);
|
|
|
|
break;
|
2012-02-01 18:16:06 +00:00
|
|
|
case GTK_RESPONSE_CANCEL:
|
|
|
|
case GTK_RESPONSE_DELETE_EVENT:
|
2020-03-28 14:59:12 +00:00
|
|
|
self->dismissed = TRUE;
|
2020-03-06 07:32:21 +00:00
|
|
|
break;
|
2013-12-08 14:22:46 +00:00
|
|
|
default:
|
2010-11-24 14:49:47 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-16 12:47:51 +00:00
|
|
|
static void
|
2010-11-23 16:23:37 +00:00
|
|
|
widget_application_selected_cb (GtkAppChooserWidget *widget,
|
2010-11-24 23:32:05 +00:00
|
|
|
GAppInfo *app_info,
|
|
|
|
gpointer user_data)
|
2010-11-16 12:47:51 +00:00
|
|
|
{
|
2020-03-28 14:59:12 +00:00
|
|
|
gtk_dialog_set_response_sensitive (GTK_DIALOG (user_data), GTK_RESPONSE_OK, TRUE);
|
2010-11-16 12:47:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-11-23 16:23:37 +00:00
|
|
|
widget_application_activated_cb (GtkAppChooserWidget *widget,
|
2010-11-24 23:32:05 +00:00
|
|
|
GAppInfo *app_info,
|
|
|
|
gpointer user_data)
|
2010-11-16 12:47:51 +00:00
|
|
|
{
|
2020-03-28 14:59:12 +00:00
|
|
|
gtk_dialog_response (GTK_DIALOG (user_data), GTK_RESPONSE_OK);
|
2010-11-16 12:47:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static char *
|
|
|
|
get_extension (const char *basename)
|
|
|
|
{
|
|
|
|
char *p;
|
|
|
|
|
|
|
|
p = strrchr (basename, '.');
|
|
|
|
|
|
|
|
if (p && *(p + 1) != '\0')
|
|
|
|
return g_strdup (p + 1);
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-11-23 16:23:37 +00:00
|
|
|
set_dialog_properties (GtkAppChooserDialog *self)
|
2010-11-16 12:47:51 +00:00
|
|
|
{
|
2020-07-24 18:40:36 +00:00
|
|
|
char *name;
|
|
|
|
char *extension;
|
|
|
|
char *description;
|
|
|
|
char *string;
|
2011-03-01 10:41:15 +00:00
|
|
|
gboolean unknown;
|
2020-07-24 18:40:36 +00:00
|
|
|
char *title;
|
|
|
|
char *subtitle;
|
2014-02-13 05:14:42 +00:00
|
|
|
gboolean use_header;
|
|
|
|
GtkWidget *header;
|
2010-11-16 12:47:51 +00:00
|
|
|
|
|
|
|
name = NULL;
|
|
|
|
extension = NULL;
|
|
|
|
description = NULL;
|
2011-03-01 10:41:15 +00:00
|
|
|
unknown = TRUE;
|
2010-11-16 12:47:51 +00:00
|
|
|
|
2020-03-28 14:59:12 +00:00
|
|
|
if (self->gfile != NULL)
|
2010-11-16 12:47:51 +00:00
|
|
|
{
|
2020-03-28 14:59:12 +00:00
|
|
|
name = g_file_get_basename (self->gfile);
|
2010-11-16 12:47:51 +00:00
|
|
|
extension = get_extension (name);
|
|
|
|
}
|
|
|
|
|
2020-03-28 14:59:12 +00:00
|
|
|
if (self->content_type)
|
2011-03-01 10:41:15 +00:00
|
|
|
{
|
2020-03-28 14:59:12 +00:00
|
|
|
description = g_content_type_get_description (self->content_type);
|
|
|
|
unknown = g_content_type_is_unknown (self->content_type);
|
2011-03-01 10:41:15 +00:00
|
|
|
}
|
|
|
|
|
2020-05-01 15:01:34 +00:00
|
|
|
title = g_strdup (_("Select Application"));
|
|
|
|
subtitle = NULL;
|
|
|
|
string = NULL;
|
|
|
|
|
2010-11-18 22:17:23 +00:00
|
|
|
if (name != NULL)
|
2010-11-16 12:47:51 +00:00
|
|
|
{
|
2010-11-17 20:37:09 +00:00
|
|
|
/* Translators: %s is a filename */
|
2014-02-13 05:14:42 +00:00
|
|
|
subtitle = g_strdup_printf (_("Opening “%s”."), name);
|
|
|
|
string = g_strdup_printf (_("No applications found for “%s”"), name);
|
2010-11-16 12:47:51 +00:00
|
|
|
}
|
2020-05-01 15:01:34 +00:00
|
|
|
else if (self->content_type)
|
2010-11-16 12:47:51 +00:00
|
|
|
{
|
2010-11-17 20:37:09 +00:00
|
|
|
/* Translators: %s is a file type description */
|
2014-02-13 05:14:42 +00:00
|
|
|
subtitle = g_strdup_printf (_("Opening “%s” files."),
|
2020-03-28 14:59:12 +00:00
|
|
|
unknown ? self->content_type : description);
|
2014-02-13 05:14:42 +00:00
|
|
|
string = g_strdup_printf (_("No applications found for “%s” files"),
|
2020-03-28 14:59:12 +00:00
|
|
|
unknown ? self->content_type : description);
|
2010-11-16 12:47:51 +00:00
|
|
|
}
|
|
|
|
|
2014-02-13 05:14:42 +00:00
|
|
|
g_object_get (self, "use-header-bar", &use_header, NULL);
|
|
|
|
if (use_header)
|
|
|
|
{
|
2020-04-30 19:42:37 +00:00
|
|
|
GtkWidget *box, *label;
|
|
|
|
|
2014-02-13 05:14:42 +00:00
|
|
|
header = gtk_dialog_get_header_bar (GTK_DIALOG (self));
|
2020-04-30 19:42:37 +00:00
|
|
|
|
|
|
|
box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
|
|
|
|
gtk_widget_set_valign (box, GTK_ALIGN_CENTER);
|
|
|
|
|
|
|
|
label = gtk_label_new (title);
|
|
|
|
gtk_widget_set_halign (label, GTK_ALIGN_CENTER);
|
|
|
|
gtk_label_set_single_line_mode (GTK_LABEL (label), TRUE);
|
|
|
|
gtk_label_set_ellipsize (GTK_LABEL (label), PANGO_ELLIPSIZE_END);
|
|
|
|
gtk_label_set_width_chars (GTK_LABEL (label), 5);
|
2020-08-13 23:49:02 +00:00
|
|
|
gtk_widget_add_css_class (label, "title");
|
2020-04-30 19:42:37 +00:00
|
|
|
gtk_widget_set_parent (label, box);
|
|
|
|
|
2020-05-02 18:34:58 +00:00
|
|
|
if (subtitle)
|
|
|
|
{
|
|
|
|
label = gtk_label_new (subtitle);
|
|
|
|
gtk_widget_set_halign (label, GTK_ALIGN_CENTER);
|
|
|
|
gtk_label_set_single_line_mode (GTK_LABEL (label), TRUE);
|
|
|
|
gtk_label_set_ellipsize (GTK_LABEL (label), PANGO_ELLIPSIZE_END);
|
2020-08-13 23:49:02 +00:00
|
|
|
gtk_widget_add_css_class (label, "subtitle");
|
2020-05-02 18:34:58 +00:00
|
|
|
gtk_widget_set_parent (label, box);
|
|
|
|
}
|
2020-04-30 19:42:37 +00:00
|
|
|
|
2020-04-30 23:17:27 +00:00
|
|
|
gtk_header_bar_set_title_widget (GTK_HEADER_BAR (header), box);
|
2014-02-13 05:14:42 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gtk_window_set_title (GTK_WINDOW (self), _("Select Application"));
|
|
|
|
}
|
2010-11-18 22:17:23 +00:00
|
|
|
|
2020-03-28 14:59:12 +00:00
|
|
|
if (self->heading != NULL)
|
2014-02-13 05:14:42 +00:00
|
|
|
{
|
2020-03-28 14:59:12 +00:00
|
|
|
gtk_label_set_markup (GTK_LABEL (self->label), self->heading);
|
|
|
|
gtk_widget_show (self->label);
|
2014-02-13 05:14:42 +00:00
|
|
|
}
|
2011-01-21 01:55:59 +00:00
|
|
|
else
|
2014-02-13 05:14:42 +00:00
|
|
|
{
|
2020-03-28 14:59:12 +00:00
|
|
|
gtk_widget_hide (self->label);
|
2014-02-13 05:14:42 +00:00
|
|
|
}
|
2010-11-23 11:47:16 +00:00
|
|
|
|
2020-03-28 14:59:12 +00:00
|
|
|
gtk_app_chooser_widget_set_default_text (GTK_APP_CHOOSER_WIDGET (self->app_chooser_widget),
|
2014-02-13 05:14:42 +00:00
|
|
|
string);
|
2010-11-23 11:47:16 +00:00
|
|
|
|
2014-02-13 05:14:42 +00:00
|
|
|
g_free (title);
|
|
|
|
g_free (subtitle);
|
2010-11-16 12:47:51 +00:00
|
|
|
g_free (name);
|
|
|
|
g_free (extension);
|
|
|
|
g_free (description);
|
2010-11-23 11:47:16 +00:00
|
|
|
g_free (string);
|
2010-11-16 12:47:51 +00:00
|
|
|
}
|
|
|
|
|
2010-11-22 22:05:59 +00:00
|
|
|
static void
|
|
|
|
show_more_button_clicked_cb (GtkButton *button,
|
2010-11-24 23:32:05 +00:00
|
|
|
gpointer user_data)
|
2010-11-22 22:05:59 +00:00
|
|
|
{
|
2010-11-23 16:23:37 +00:00
|
|
|
GtkAppChooserDialog *self = user_data;
|
2010-11-22 22:05:59 +00:00
|
|
|
|
2020-03-28 14:59:12 +00:00
|
|
|
g_object_set (self->app_chooser_widget,
|
2010-11-24 23:32:05 +00:00
|
|
|
"show-recommended", TRUE,
|
|
|
|
"show-fallback", TRUE,
|
|
|
|
"show-other", TRUE,
|
|
|
|
NULL);
|
2010-11-22 22:05:59 +00:00
|
|
|
|
2020-03-28 14:59:12 +00:00
|
|
|
gtk_widget_hide (self->show_more_button);
|
|
|
|
self->show_more_clicked = TRUE;
|
2010-11-23 15:50:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-11-24 23:32:05 +00:00
|
|
|
widget_notify_for_button_cb (GObject *source,
|
|
|
|
GParamSpec *pspec,
|
|
|
|
gpointer user_data)
|
2010-11-23 15:50:21 +00:00
|
|
|
{
|
2010-11-23 16:23:37 +00:00
|
|
|
GtkAppChooserDialog *self = user_data;
|
|
|
|
GtkAppChooserWidget *widget = GTK_APP_CHOOSER_WIDGET (source);
|
2010-11-23 15:50:21 +00:00
|
|
|
gboolean should_hide;
|
|
|
|
|
2011-01-20 21:22:51 +00:00
|
|
|
should_hide = gtk_app_chooser_widget_get_show_other (widget) ||
|
2020-03-28 14:59:12 +00:00
|
|
|
self->show_more_clicked;
|
2010-11-23 15:50:21 +00:00
|
|
|
|
|
|
|
if (should_hide)
|
2020-03-28 14:59:12 +00:00
|
|
|
gtk_widget_hide (self->show_more_button);
|
2010-11-22 22:05:59 +00:00
|
|
|
}
|
|
|
|
|
2010-11-17 18:28:48 +00:00
|
|
|
static void
|
2013-03-23 14:02:33 +00:00
|
|
|
construct_appchooser_widget (GtkAppChooserDialog *self)
|
2010-11-17 18:28:48 +00:00
|
|
|
{
|
2011-08-29 03:49:41 +00:00
|
|
|
GAppInfo *info;
|
2010-11-17 18:28:48 +00:00
|
|
|
|
2013-03-23 14:02:33 +00:00
|
|
|
/* Need to build the appchooser widget after, because of the content-type construct-only property */
|
2020-03-28 14:59:12 +00:00
|
|
|
self->app_chooser_widget = gtk_app_chooser_widget_new (self->content_type);
|
|
|
|
gtk_widget_set_vexpand (self->app_chooser_widget, TRUE);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (self->inner_box), self->app_chooser_widget);
|
2010-11-23 15:50:21 +00:00
|
|
|
|
2020-03-28 14:59:12 +00:00
|
|
|
g_signal_connect (self->app_chooser_widget, "application-selected",
|
2010-11-24 23:32:05 +00:00
|
|
|
G_CALLBACK (widget_application_selected_cb), self);
|
2020-03-28 14:59:12 +00:00
|
|
|
g_signal_connect (self->app_chooser_widget, "application-activated",
|
2010-11-24 23:32:05 +00:00
|
|
|
G_CALLBACK (widget_application_activated_cb), self);
|
2020-03-28 14:59:12 +00:00
|
|
|
g_signal_connect (self->app_chooser_widget, "notify::show-other",
|
2010-11-24 23:32:05 +00:00
|
|
|
G_CALLBACK (widget_notify_for_button_cb), self);
|
2010-11-17 18:28:48 +00:00
|
|
|
|
2013-03-23 14:02:33 +00:00
|
|
|
/* Add the custom button to the new appchooser */
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (self->inner_box),
|
2020-03-28 14:59:12 +00:00
|
|
|
self->show_more_button);
|
2014-02-13 05:14:42 +00:00
|
|
|
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (self->inner_box),
|
2020-03-28 14:59:12 +00:00
|
|
|
self->software_button);
|
2010-11-17 18:28:48 +00:00
|
|
|
|
2020-03-28 14:59:12 +00:00
|
|
|
info = gtk_app_chooser_get_app_info (GTK_APP_CHOOSER (self->app_chooser_widget));
|
2013-12-08 14:22:46 +00:00
|
|
|
gtk_dialog_set_response_sensitive (GTK_DIALOG (self), GTK_RESPONSE_OK, info != NULL);
|
2011-08-29 03:49:41 +00:00
|
|
|
if (info)
|
|
|
|
g_object_unref (info);
|
2014-02-14 12:02:32 +00:00
|
|
|
|
2020-03-28 14:59:12 +00:00
|
|
|
_gtk_app_chooser_widget_set_search_entry (GTK_APP_CHOOSER_WIDGET (self->app_chooser_widget),
|
|
|
|
GTK_EDITABLE (self->search_entry));
|
2018-03-11 12:55:45 +00:00
|
|
|
|
2020-03-28 14:59:12 +00:00
|
|
|
gtk_search_bar_set_key_capture_widget (GTK_SEARCH_BAR (self->search_bar),
|
2018-03-11 12:55:45 +00:00
|
|
|
GTK_WIDGET (self));
|
2010-11-17 18:28:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-11-23 16:23:37 +00:00
|
|
|
set_gfile_and_content_type (GtkAppChooserDialog *self,
|
2013-12-18 02:23:05 +00:00
|
|
|
GFile *file)
|
2010-11-17 18:28:48 +00:00
|
|
|
{
|
|
|
|
GFileInfo *info;
|
|
|
|
|
|
|
|
if (file == NULL)
|
|
|
|
return;
|
|
|
|
|
2020-03-28 14:59:12 +00:00
|
|
|
self->gfile = g_object_ref (file);
|
2010-11-17 18:28:48 +00:00
|
|
|
|
2020-03-28 14:59:12 +00:00
|
|
|
info = g_file_query_info (self->gfile,
|
2010-11-24 23:32:05 +00:00
|
|
|
G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE,
|
|
|
|
0, NULL, NULL);
|
2020-03-28 14:59:12 +00:00
|
|
|
self->content_type = g_strdup (g_file_info_get_content_type (info));
|
2010-11-17 18:28:48 +00:00
|
|
|
|
|
|
|
g_object_unref (info);
|
|
|
|
}
|
|
|
|
|
|
|
|
static GAppInfo *
|
2010-11-23 16:23:37 +00:00
|
|
|
gtk_app_chooser_dialog_get_app_info (GtkAppChooser *object)
|
2010-11-17 18:28:48 +00:00
|
|
|
{
|
2010-11-23 16:23:37 +00:00
|
|
|
GtkAppChooserDialog *self = GTK_APP_CHOOSER_DIALOG (object);
|
2019-05-28 00:51:46 +00:00
|
|
|
|
2020-03-28 14:59:12 +00:00
|
|
|
return gtk_app_chooser_get_app_info (GTK_APP_CHOOSER (self->app_chooser_widget));
|
2010-11-17 18:28:48 +00:00
|
|
|
}
|
|
|
|
|
2010-11-22 22:02:57 +00:00
|
|
|
static void
|
2010-11-23 16:23:37 +00:00
|
|
|
gtk_app_chooser_dialog_refresh (GtkAppChooser *object)
|
2010-11-22 22:02:57 +00:00
|
|
|
{
|
2010-11-23 16:23:37 +00:00
|
|
|
GtkAppChooserDialog *self = GTK_APP_CHOOSER_DIALOG (object);
|
2010-11-22 22:02:57 +00:00
|
|
|
|
2020-03-28 14:59:12 +00:00
|
|
|
gtk_app_chooser_refresh (GTK_APP_CHOOSER (self->app_chooser_widget));
|
2010-11-22 22:02:57 +00:00
|
|
|
}
|
|
|
|
|
2013-12-18 02:23:05 +00:00
|
|
|
static void
|
2020-07-24 18:40:36 +00:00
|
|
|
show_error_dialog (const char *primary,
|
|
|
|
const char *secondary,
|
2013-12-18 02:23:05 +00:00
|
|
|
GtkWindow *parent)
|
|
|
|
{
|
|
|
|
GtkWidget *message_dialog;
|
|
|
|
|
|
|
|
message_dialog = gtk_message_dialog_new (parent, 0,
|
|
|
|
GTK_MESSAGE_ERROR,
|
|
|
|
GTK_BUTTONS_OK,
|
|
|
|
NULL);
|
|
|
|
g_object_set (message_dialog,
|
|
|
|
"text", primary,
|
|
|
|
"secondary-text", secondary,
|
|
|
|
NULL);
|
|
|
|
gtk_dialog_set_default_response (GTK_DIALOG (message_dialog), GTK_RESPONSE_OK);
|
|
|
|
|
|
|
|
gtk_widget_show (message_dialog);
|
|
|
|
|
|
|
|
g_signal_connect (message_dialog, "response",
|
2020-05-09 14:26:22 +00:00
|
|
|
G_CALLBACK (gtk_window_destroy), NULL);
|
2013-12-18 02:23:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
software_button_clicked_cb (GtkButton *button,
|
|
|
|
GtkAppChooserDialog *self)
|
|
|
|
{
|
|
|
|
GSubprocess *process;
|
|
|
|
GError *error = NULL;
|
2020-07-24 18:40:36 +00:00
|
|
|
char *option;
|
2013-12-18 02:23:05 +00:00
|
|
|
|
2020-03-28 14:59:12 +00:00
|
|
|
if (self->content_type)
|
|
|
|
option = g_strconcat ("--search=", self->content_type, NULL);
|
2013-12-18 02:23:05 +00:00
|
|
|
else
|
|
|
|
option = g_strdup ("--mode=overview");
|
|
|
|
|
|
|
|
process = g_subprocess_new (0, &error, "gnome-software", option, NULL);
|
|
|
|
if (!process)
|
|
|
|
{
|
|
|
|
show_error_dialog (_("Failed to start GNOME Software"),
|
|
|
|
error->message, GTK_WINDOW (self));
|
|
|
|
g_error_free (error);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
g_object_unref (process);
|
|
|
|
|
|
|
|
g_free (option);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ensure_software_button (GtkAppChooserDialog *self)
|
|
|
|
{
|
2020-07-24 18:40:36 +00:00
|
|
|
char *path;
|
2015-02-18 10:38:29 +00:00
|
|
|
|
|
|
|
path = g_find_program_in_path ("gnome-software");
|
|
|
|
if (path != NULL)
|
2020-03-28 14:59:12 +00:00
|
|
|
gtk_widget_show (self->software_button);
|
2014-02-13 05:14:42 +00:00
|
|
|
else
|
2020-03-28 14:59:12 +00:00
|
|
|
gtk_widget_hide (self->software_button);
|
2015-02-18 10:38:29 +00:00
|
|
|
|
|
|
|
g_free (path);
|
2013-12-18 02:23:05 +00:00
|
|
|
}
|
|
|
|
|
2014-02-14 12:02:32 +00:00
|
|
|
static void
|
|
|
|
setup_search (GtkAppChooserDialog *self)
|
|
|
|
{
|
|
|
|
gboolean use_header;
|
|
|
|
|
|
|
|
g_object_get (self, "use-header-bar", &use_header, NULL);
|
|
|
|
if (use_header)
|
|
|
|
{
|
|
|
|
GtkWidget *button;
|
|
|
|
GtkWidget *image;
|
|
|
|
GtkWidget *header;
|
|
|
|
|
|
|
|
button = gtk_toggle_button_new ();
|
|
|
|
gtk_widget_set_valign (button, GTK_ALIGN_CENTER);
|
2017-11-15 00:43:13 +00:00
|
|
|
image = gtk_image_new_from_icon_name ("edit-find-symbolic");
|
2020-05-02 07:05:19 +00:00
|
|
|
gtk_button_set_child (GTK_BUTTON (button), image);
|
2020-02-06 16:32:26 +00:00
|
|
|
gtk_widget_add_css_class (button, "image-button");
|
|
|
|
gtk_widget_remove_css_class (button, "text-button");
|
2014-02-14 12:02:32 +00:00
|
|
|
|
|
|
|
header = gtk_dialog_get_header_bar (GTK_DIALOG (self));
|
|
|
|
gtk_header_bar_pack_end (GTK_HEADER_BAR (header), button);
|
2020-03-28 14:59:12 +00:00
|
|
|
gtk_size_group_add_widget (self->buttons, button);
|
2014-02-14 12:02:32 +00:00
|
|
|
|
|
|
|
g_object_bind_property (button, "active",
|
2020-03-28 14:59:12 +00:00
|
|
|
self->search_bar, "search-mode-enabled",
|
2014-02-14 12:02:32 +00:00
|
|
|
G_BINDING_BIDIRECTIONAL);
|
2020-03-28 14:59:12 +00:00
|
|
|
g_object_bind_property (self->search_entry, "sensitive",
|
2014-02-14 14:39:49 +00:00
|
|
|
button, "sensitive",
|
|
|
|
G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
|
2014-02-14 12:02:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-16 12:47:51 +00:00
|
|
|
static void
|
2010-11-23 16:23:37 +00:00
|
|
|
gtk_app_chooser_dialog_constructed (GObject *object)
|
2010-11-16 12:47:51 +00:00
|
|
|
{
|
2010-11-23 16:23:37 +00:00
|
|
|
GtkAppChooserDialog *self = GTK_APP_CHOOSER_DIALOG (object);
|
2010-11-16 12:47:51 +00:00
|
|
|
|
2010-11-23 16:23:37 +00:00
|
|
|
if (G_OBJECT_CLASS (gtk_app_chooser_dialog_parent_class)->constructed != NULL)
|
|
|
|
G_OBJECT_CLASS (gtk_app_chooser_dialog_parent_class)->constructed (object);
|
2010-11-16 12:47:51 +00:00
|
|
|
|
2013-03-23 14:02:33 +00:00
|
|
|
construct_appchooser_widget (self);
|
2010-11-16 12:47:51 +00:00
|
|
|
set_dialog_properties (self);
|
2013-12-18 02:23:05 +00:00
|
|
|
ensure_software_button (self);
|
2014-02-14 12:02:32 +00:00
|
|
|
setup_search (self);
|
|
|
|
}
|
|
|
|
|
2010-11-16 12:47:51 +00:00
|
|
|
static void
|
2010-11-29 17:10:06 +00:00
|
|
|
gtk_app_chooser_dialog_dispose (GObject *object)
|
2010-11-16 12:47:51 +00:00
|
|
|
{
|
2010-11-23 16:23:37 +00:00
|
|
|
GtkAppChooserDialog *self = GTK_APP_CHOOSER_DIALOG (object);
|
2010-11-29 17:10:06 +00:00
|
|
|
|
2020-03-28 14:59:12 +00:00
|
|
|
g_clear_object (&self->gfile);
|
2010-11-16 12:47:51 +00:00
|
|
|
|
2020-03-28 14:59:12 +00:00
|
|
|
self->dismissed = TRUE;
|
2013-05-03 00:00:49 +00:00
|
|
|
|
2010-11-29 17:10:06 +00:00
|
|
|
G_OBJECT_CLASS (gtk_app_chooser_dialog_parent_class)->dispose (object);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_app_chooser_dialog_finalize (GObject *object)
|
|
|
|
{
|
|
|
|
GtkAppChooserDialog *self = GTK_APP_CHOOSER_DIALOG (object);
|
2010-11-16 12:47:51 +00:00
|
|
|
|
2020-03-28 14:59:12 +00:00
|
|
|
g_free (self->content_type);
|
|
|
|
g_free (self->heading);
|
2010-11-16 12:47:51 +00:00
|
|
|
|
2010-11-23 16:23:37 +00:00
|
|
|
G_OBJECT_CLASS (gtk_app_chooser_dialog_parent_class)->finalize (object);
|
2010-11-16 12:47:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-11-24 23:32:05 +00:00
|
|
|
gtk_app_chooser_dialog_set_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
2010-11-16 12:47:51 +00:00
|
|
|
{
|
2010-11-23 16:23:37 +00:00
|
|
|
GtkAppChooserDialog *self = GTK_APP_CHOOSER_DIALOG (object);
|
2010-11-16 12:47:51 +00:00
|
|
|
|
|
|
|
switch (property_id)
|
|
|
|
{
|
|
|
|
case PROP_GFILE:
|
2010-11-17 18:28:48 +00:00
|
|
|
set_gfile_and_content_type (self, g_value_get_object (value));
|
2010-11-16 12:47:51 +00:00
|
|
|
break;
|
|
|
|
case PROP_CONTENT_TYPE:
|
2010-11-17 18:28:48 +00:00
|
|
|
/* don't try to override a value previously set with the GFile */
|
2020-03-28 14:59:12 +00:00
|
|
|
if (self->content_type == NULL)
|
|
|
|
self->content_type = g_value_dup_string (value);
|
2010-11-16 12:47:51 +00:00
|
|
|
break;
|
2011-01-21 01:55:59 +00:00
|
|
|
case PROP_HEADING:
|
|
|
|
gtk_app_chooser_dialog_set_heading (self, g_value_get_string (value));
|
|
|
|
break;
|
2010-11-16 12:47:51 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-11-24 23:32:05 +00:00
|
|
|
gtk_app_chooser_dialog_get_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
2010-11-16 12:47:51 +00:00
|
|
|
{
|
2010-11-23 16:23:37 +00:00
|
|
|
GtkAppChooserDialog *self = GTK_APP_CHOOSER_DIALOG (object);
|
2010-11-16 12:47:51 +00:00
|
|
|
|
|
|
|
switch (property_id)
|
|
|
|
{
|
|
|
|
case PROP_GFILE:
|
2020-03-28 14:59:12 +00:00
|
|
|
if (self->gfile != NULL)
|
|
|
|
g_value_set_object (value, self->gfile);
|
2010-11-16 12:47:51 +00:00
|
|
|
break;
|
|
|
|
case PROP_CONTENT_TYPE:
|
2020-03-28 14:59:12 +00:00
|
|
|
g_value_set_string (value, self->content_type);
|
2010-11-16 12:47:51 +00:00
|
|
|
break;
|
2011-01-21 01:55:59 +00:00
|
|
|
case PROP_HEADING:
|
2020-03-28 14:59:12 +00:00
|
|
|
g_value_set_string (value, self->heading);
|
2011-01-21 01:55:59 +00:00
|
|
|
break;
|
2010-11-16 12:47:51 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-17 18:28:48 +00:00
|
|
|
static void
|
2010-11-23 16:23:37 +00:00
|
|
|
gtk_app_chooser_dialog_iface_init (GtkAppChooserIface *iface)
|
2010-11-17 18:28:48 +00:00
|
|
|
{
|
2010-11-23 16:23:37 +00:00
|
|
|
iface->get_app_info = gtk_app_chooser_dialog_get_app_info;
|
|
|
|
iface->refresh = gtk_app_chooser_dialog_refresh;
|
2010-11-17 18:28:48 +00:00
|
|
|
}
|
|
|
|
|
2010-11-16 12:47:51 +00:00
|
|
|
static void
|
2010-11-23 16:23:37 +00:00
|
|
|
gtk_app_chooser_dialog_class_init (GtkAppChooserDialogClass *klass)
|
2010-11-16 12:47:51 +00:00
|
|
|
{
|
|
|
|
GObjectClass *gobject_class;
|
2016-10-09 00:32:00 +00:00
|
|
|
GtkWidgetClass *widget_class;
|
2010-11-17 18:28:48 +00:00
|
|
|
GParamSpec *pspec;
|
2010-11-16 12:47:51 +00:00
|
|
|
|
|
|
|
gobject_class = G_OBJECT_CLASS (klass);
|
2016-10-09 00:32:00 +00:00
|
|
|
widget_class = GTK_WIDGET_CLASS (klass);
|
|
|
|
|
2010-11-29 17:10:06 +00:00
|
|
|
gobject_class->dispose = gtk_app_chooser_dialog_dispose;
|
2010-11-23 16:23:37 +00:00
|
|
|
gobject_class->finalize = gtk_app_chooser_dialog_finalize;
|
|
|
|
gobject_class->set_property = gtk_app_chooser_dialog_set_property;
|
|
|
|
gobject_class->get_property = gtk_app_chooser_dialog_get_property;
|
|
|
|
gobject_class->constructed = gtk_app_chooser_dialog_constructed;
|
2010-11-16 12:47:51 +00:00
|
|
|
|
2010-11-17 18:28:48 +00:00
|
|
|
g_object_class_override_property (gobject_class, PROP_CONTENT_TYPE, "content-type");
|
|
|
|
|
2010-11-30 14:03:33 +00:00
|
|
|
/**
|
|
|
|
* GtkAppChooserDialog:gfile:
|
|
|
|
*
|
2021-02-27 04:14:34 +00:00
|
|
|
* The GFile used by the `GtkAppChooserDialog`.
|
|
|
|
*
|
|
|
|
* The dialog's `GtkAppChooserWidget` content type will
|
|
|
|
* be guessed from the file, if present.
|
2010-11-30 14:03:33 +00:00
|
|
|
*/
|
2010-11-17 18:28:48 +00:00
|
|
|
pspec = g_param_spec_object ("gfile",
|
2010-11-24 23:32:05 +00:00
|
|
|
P_("GFile"),
|
2010-11-30 14:03:33 +00:00
|
|
|
P_("The GFile used by the app chooser dialog"),
|
2010-11-24 23:32:05 +00:00
|
|
|
G_TYPE_FILE,
|
|
|
|
G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE |
|
|
|
|
G_PARAM_STATIC_STRINGS);
|
2010-11-17 18:28:48 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_GFILE, pspec);
|
2010-11-16 12:47:51 +00:00
|
|
|
|
2011-01-21 01:55:59 +00:00
|
|
|
/**
|
2021-02-27 04:14:34 +00:00
|
|
|
* GtkAppChooserDialog:heading: (attributes org.gtk.Property.get=gtk_app_chooser_dialog_get_heading org.gtk.Property.set=gtk_app_chooser_dialog_set_heading)
|
2011-01-21 01:55:59 +00:00
|
|
|
*
|
|
|
|
* The text to show at the top of the dialog.
|
2021-02-27 04:14:34 +00:00
|
|
|
*
|
2011-01-21 01:55:59 +00:00
|
|
|
* The string may contain Pango markup.
|
|
|
|
*/
|
|
|
|
pspec = g_param_spec_string ("heading",
|
|
|
|
P_("Heading"),
|
|
|
|
P_("The text to show at the top of the dialog"),
|
|
|
|
NULL,
|
2018-05-13 07:51:06 +00:00
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS |
|
|
|
|
G_PARAM_EXPLICIT_NOTIFY);
|
2011-01-21 01:55:59 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_HEADING, pspec);
|
|
|
|
|
2013-03-23 14:02:33 +00:00
|
|
|
/* Bind class to template
|
|
|
|
*/
|
|
|
|
gtk_widget_class_set_template_from_resource (widget_class,
|
2014-01-23 23:59:20 +00:00
|
|
|
"/org/gtk/libgtk/ui/gtkappchooserdialog.ui");
|
2020-03-28 14:59:12 +00:00
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkAppChooserDialog, label);
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkAppChooserDialog, show_more_button);
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkAppChooserDialog, software_button);
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkAppChooserDialog, inner_box);
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkAppChooserDialog, search_bar);
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkAppChooserDialog, search_entry);
|
|
|
|
gtk_widget_class_bind_template_child(widget_class, GtkAppChooserDialog, buttons);
|
2013-07-26 17:49:49 +00:00
|
|
|
gtk_widget_class_bind_template_callback (widget_class, show_more_button_clicked_cb);
|
2014-02-13 05:14:42 +00:00
|
|
|
gtk_widget_class_bind_template_callback (widget_class, software_button_clicked_cb);
|
2010-11-16 12:47:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-11-23 16:23:37 +00:00
|
|
|
gtk_app_chooser_dialog_init (GtkAppChooserDialog *self)
|
2010-11-16 12:47:51 +00:00
|
|
|
{
|
2013-03-23 14:02:33 +00:00
|
|
|
gtk_widget_init_template (GTK_WIDGET (self));
|
2013-12-08 14:22:46 +00:00
|
|
|
gtk_dialog_set_use_header_bar_from_setting (GTK_DIALOG (self));
|
|
|
|
|
2010-11-24 14:49:47 +00:00
|
|
|
/* we can't override the class signal handler here, as it's a RUN_LAST;
|
|
|
|
* we want our signal handler instead to be executed before any user code.
|
|
|
|
*/
|
|
|
|
g_signal_connect (self, "response",
|
2010-11-24 23:32:05 +00:00
|
|
|
G_CALLBACK (gtk_app_chooser_dialog_response), NULL);
|
2010-11-16 12:47:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-11-24 23:32:05 +00:00
|
|
|
set_parent_and_flags (GtkWidget *dialog,
|
|
|
|
GtkWindow *parent,
|
|
|
|
GtkDialogFlags flags)
|
2010-11-16 12:47:51 +00:00
|
|
|
{
|
|
|
|
if (parent != NULL)
|
2010-11-24 23:32:05 +00:00
|
|
|
gtk_window_set_transient_for (GTK_WINDOW (dialog), parent);
|
|
|
|
|
2010-11-16 12:47:51 +00:00
|
|
|
if (flags & GTK_DIALOG_MODAL)
|
|
|
|
gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
|
|
|
|
|
|
|
|
if (flags & GTK_DIALOG_DESTROY_WITH_PARENT)
|
|
|
|
gtk_window_set_destroy_with_parent (GTK_WINDOW (dialog), TRUE);
|
|
|
|
}
|
|
|
|
|
2010-11-16 18:24:00 +00:00
|
|
|
/**
|
2010-11-23 16:23:37 +00:00
|
|
|
* gtk_app_chooser_dialog_new:
|
2021-02-27 04:14:34 +00:00
|
|
|
* @parent: (allow-none): a `GtkWindow`, or %NULL
|
2010-11-16 18:24:00 +00:00
|
|
|
* @flags: flags for this dialog
|
2021-02-27 04:14:34 +00:00
|
|
|
* @file: a `GFile`
|
|
|
|
*
|
|
|
|
* Creates a new `GtkAppChooserDialog` for the provided `GFile`.
|
2010-11-16 18:24:00 +00:00
|
|
|
*
|
2021-02-27 04:14:34 +00:00
|
|
|
* The dialog will show applications that can open the file.
|
2010-11-16 18:24:00 +00:00
|
|
|
*
|
2021-02-27 04:14:34 +00:00
|
|
|
* Returns: a newly created `GtkAppChooserDialog`
|
|
|
|
*/
|
2010-11-16 12:47:51 +00:00
|
|
|
GtkWidget *
|
2010-11-24 23:32:05 +00:00
|
|
|
gtk_app_chooser_dialog_new (GtkWindow *parent,
|
|
|
|
GtkDialogFlags flags,
|
|
|
|
GFile *file)
|
2010-11-16 12:47:51 +00:00
|
|
|
{
|
|
|
|
GtkWidget *retval;
|
|
|
|
|
|
|
|
g_return_val_if_fail (G_IS_FILE (file), NULL);
|
|
|
|
|
2010-11-23 16:23:37 +00:00
|
|
|
retval = g_object_new (GTK_TYPE_APP_CHOOSER_DIALOG,
|
2010-11-24 23:32:05 +00:00
|
|
|
"gfile", file,
|
|
|
|
NULL);
|
2010-11-16 12:47:51 +00:00
|
|
|
|
|
|
|
set_parent_and_flags (retval, parent, flags);
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2010-11-16 18:24:00 +00:00
|
|
|
/**
|
2010-11-23 16:23:37 +00:00
|
|
|
* gtk_app_chooser_dialog_new_for_content_type:
|
2021-02-27 04:14:34 +00:00
|
|
|
* @parent: (allow-none): a `GtkWindow`, or %NULL
|
2010-11-16 18:24:00 +00:00
|
|
|
* @flags: flags for this dialog
|
|
|
|
* @content_type: a content type string
|
|
|
|
*
|
2021-02-27 04:14:34 +00:00
|
|
|
* Creates a new `GtkAppChooserDialog` for the provided content type.
|
|
|
|
*
|
|
|
|
* The dialog will show applications that can open the content type.
|
2010-11-16 18:24:00 +00:00
|
|
|
*
|
2021-02-27 04:14:34 +00:00
|
|
|
* Returns: a newly created `GtkAppChooserDialog`
|
|
|
|
*/
|
2010-11-16 12:47:51 +00:00
|
|
|
GtkWidget *
|
2010-11-24 23:32:05 +00:00
|
|
|
gtk_app_chooser_dialog_new_for_content_type (GtkWindow *parent,
|
|
|
|
GtkDialogFlags flags,
|
2020-07-24 18:40:36 +00:00
|
|
|
const char *content_type)
|
2010-11-16 12:47:51 +00:00
|
|
|
{
|
|
|
|
GtkWidget *retval;
|
|
|
|
|
|
|
|
g_return_val_if_fail (content_type != NULL, NULL);
|
|
|
|
|
2010-11-23 16:23:37 +00:00
|
|
|
retval = g_object_new (GTK_TYPE_APP_CHOOSER_DIALOG,
|
2010-11-24 23:32:05 +00:00
|
|
|
"content-type", content_type,
|
|
|
|
NULL);
|
2010-11-16 12:47:51 +00:00
|
|
|
|
|
|
|
set_parent_and_flags (retval, parent, flags);
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
2010-11-16 13:31:03 +00:00
|
|
|
|
2010-11-24 23:32:05 +00:00
|
|
|
/**
|
|
|
|
* gtk_app_chooser_dialog_get_widget:
|
2021-02-27 04:14:34 +00:00
|
|
|
* @self: a `GtkAppChooserDialog`
|
2010-11-24 23:32:05 +00:00
|
|
|
*
|
2021-02-27 04:14:34 +00:00
|
|
|
* Returns the `GtkAppChooserWidget` of this dialog.
|
2010-11-24 23:32:05 +00:00
|
|
|
*
|
2021-02-27 04:14:34 +00:00
|
|
|
* Returns: (transfer none): the `GtkAppChooserWidget` of @self
|
2010-11-24 23:32:05 +00:00
|
|
|
*/
|
2010-11-17 18:28:48 +00:00
|
|
|
GtkWidget *
|
2010-11-23 16:23:37 +00:00
|
|
|
gtk_app_chooser_dialog_get_widget (GtkAppChooserDialog *self)
|
2010-11-16 17:02:29 +00:00
|
|
|
{
|
2010-11-23 16:23:37 +00:00
|
|
|
g_return_val_if_fail (GTK_IS_APP_CHOOSER_DIALOG (self), NULL);
|
2010-11-16 17:02:29 +00:00
|
|
|
|
2020-03-28 14:59:12 +00:00
|
|
|
return self->app_chooser_widget;
|
2010-11-16 18:23:15 +00:00
|
|
|
}
|
2011-01-21 01:55:59 +00:00
|
|
|
|
|
|
|
/**
|
2021-02-27 04:14:34 +00:00
|
|
|
* gtk_app_chooser_dialog_set_heading: (attributes org.gtk.Method.set_property=heading)
|
|
|
|
* @self: a `GtkAppChooserDialog`
|
2011-01-21 01:55:59 +00:00
|
|
|
* @heading: a string containing Pango markup
|
|
|
|
*
|
|
|
|
* Sets the text to display at the top of the dialog.
|
2021-02-27 04:14:34 +00:00
|
|
|
*
|
2011-01-21 01:55:59 +00:00
|
|
|
* If the heading is not set, the dialog displays a default text.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gtk_app_chooser_dialog_set_heading (GtkAppChooserDialog *self,
|
2020-07-24 18:40:36 +00:00
|
|
|
const char *heading)
|
2011-01-21 01:55:59 +00:00
|
|
|
{
|
|
|
|
g_return_if_fail (GTK_IS_APP_CHOOSER_DIALOG (self));
|
|
|
|
|
2020-03-28 14:59:12 +00:00
|
|
|
g_free (self->heading);
|
|
|
|
self->heading = g_strdup (heading);
|
2011-01-21 01:55:59 +00:00
|
|
|
|
2020-03-28 14:59:12 +00:00
|
|
|
if (self->label)
|
2014-02-13 05:14:42 +00:00
|
|
|
{
|
2020-03-28 14:59:12 +00:00
|
|
|
if (self->heading)
|
2014-02-13 05:14:42 +00:00
|
|
|
{
|
2020-03-28 14:59:12 +00:00
|
|
|
gtk_label_set_markup (GTK_LABEL (self->label), self->heading);
|
|
|
|
gtk_widget_show (self->label);
|
2014-02-13 05:14:42 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-03-28 14:59:12 +00:00
|
|
|
gtk_widget_hide (self->label);
|
2014-02-13 05:14:42 +00:00
|
|
|
}
|
|
|
|
}
|
2011-01-21 01:55:59 +00:00
|
|
|
|
|
|
|
g_object_notify (G_OBJECT (self), "heading");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-02-27 04:14:34 +00:00
|
|
|
* gtk_app_chooser_dialog_get_heading: (attributes org.gtk.Method.get_property=heading)
|
|
|
|
* @self: a `GtkAppChooserDialog`
|
2011-01-21 01:55:59 +00:00
|
|
|
*
|
|
|
|
* Returns the text to display at the top of the dialog.
|
|
|
|
*
|
2021-02-27 04:14:34 +00:00
|
|
|
* Returns: (nullable): the text to display at the top of the dialog,
|
|
|
|
* or %NULL, in which case a default text is displayed
|
2011-01-21 01:55:59 +00:00
|
|
|
*/
|
2020-07-24 18:40:36 +00:00
|
|
|
const char *
|
2011-01-21 01:55:59 +00:00
|
|
|
gtk_app_chooser_dialog_get_heading (GtkAppChooserDialog *self)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GTK_IS_APP_CHOOSER_DIALOG (self), NULL);
|
|
|
|
|
2020-03-28 14:59:12 +00:00
|
|
|
return self->heading;
|
2011-01-21 01:55:59 +00:00
|
|
|
}
|