2018-11-13 14:01:21 +00:00
|
|
|
/* gtkappchooserbutton.c: an app-chooser button
|
2010-11-24 17:45:42 +00:00
|
|
|
*
|
|
|
|
* Copyright (C) 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-24 17:45:42 +00:00
|
|
|
*
|
|
|
|
* Authors: Cosimo Cecchi <ccecchi@redhat.com>
|
|
|
|
*/
|
|
|
|
|
2011-01-06 07:07:35 +00:00
|
|
|
/**
|
2021-02-22 00:41:33 +00:00
|
|
|
* GtkAppChooserButton:
|
2011-01-06 07:07:35 +00:00
|
|
|
*
|
2021-02-22 00:41:33 +00:00
|
|
|
* The `GtkAppChooserButton` lets the user select an application.
|
2011-09-10 05:40:05 +00:00
|
|
|
*
|
2021-02-22 00:41:33 +00:00
|
|
|
* ![An example GtkAppChooserButton](appchooserbutton.png)
|
|
|
|
*
|
|
|
|
* Initially, a `GtkAppChooserButton` selects the first application
|
2011-09-10 05:40:05 +00:00
|
|
|
* in its list, which will either be the most-recently used application
|
2021-02-22 00:41:33 +00:00
|
|
|
* or, if [property@Gtk.AppChooserButton:show-default-item] is %TRUE, the
|
2011-09-10 05:40:05 +00:00
|
|
|
* default application.
|
|
|
|
*
|
2021-02-22 00:41:33 +00:00
|
|
|
* The list of applications shown in a `GtkAppChooserButton` includes
|
2011-09-10 05:40:05 +00:00
|
|
|
* the recommended applications for the given content type. When
|
2021-02-22 00:41:33 +00:00
|
|
|
* [property@Gtk.AppChooserButton:show-default-item] is set, the default
|
|
|
|
* application is also included. To let the user chooser other applications,
|
|
|
|
* you can set the [property@Gtk.AppChooserButton:show-dialog-item] property,
|
|
|
|
* which allows to open a full [class@Gtk.AppChooserDialog].
|
2011-09-10 05:40:05 +00:00
|
|
|
*
|
|
|
|
* It is possible to add custom items to the list, using
|
2021-02-22 00:41:33 +00:00
|
|
|
* [method@Gtk.AppChooserButton.append_custom_item]. These items cause
|
|
|
|
* the [signal@Gtk.AppChooserButton::custom-item-activated] signal to be
|
2011-09-10 05:40:05 +00:00
|
|
|
* emitted when they are selected.
|
|
|
|
*
|
|
|
|
* To track changes in the selected application, use the
|
2021-02-22 00:41:33 +00:00
|
|
|
* [signal@Gtk.AppChooserButton::changed] signal.
|
2020-08-02 09:26:40 +00:00
|
|
|
*
|
|
|
|
* # CSS nodes
|
|
|
|
*
|
2021-02-22 00:41:33 +00:00
|
|
|
* `GtkAppChooserButton` has a single CSS node with the name “appchooserbutton”.
|
2011-01-06 07:07:35 +00:00
|
|
|
*/
|
2010-11-24 23:32:05 +00:00
|
|
|
#include "config.h"
|
2010-11-24 17:45:42 +00:00
|
|
|
|
2010-11-29 11:19:18 +00:00
|
|
|
#include "gtkappchooserbutton.h"
|
2010-11-24 17:45:42 +00:00
|
|
|
|
|
|
|
#include "gtkappchooser.h"
|
2010-11-25 16:17:45 +00:00
|
|
|
#include "gtkappchooserdialog.h"
|
2010-11-24 17:45:42 +00:00
|
|
|
#include "gtkappchooserprivate.h"
|
|
|
|
#include "gtkcelllayout.h"
|
|
|
|
#include "gtkcellrendererpixbuf.h"
|
|
|
|
#include "gtkcellrenderertext.h"
|
|
|
|
#include "gtkcombobox.h"
|
2020-04-08 11:43:28 +00:00
|
|
|
#include "gtkwidgetprivate.h"
|
2010-11-25 16:17:45 +00:00
|
|
|
#include "gtkdialog.h"
|
|
|
|
#include "gtkintl.h"
|
2010-11-29 15:04:59 +00:00
|
|
|
#include "gtkmarshalers.h"
|
2020-06-21 22:03:39 +00:00
|
|
|
#include "gtkliststore.h"
|
2010-11-24 17:45:42 +00:00
|
|
|
|
|
|
|
enum {
|
2015-09-07 19:55:34 +00:00
|
|
|
PROP_SHOW_DIALOG_ITEM = 1,
|
2011-09-10 05:40:05 +00:00
|
|
|
PROP_SHOW_DEFAULT_ITEM,
|
2015-09-07 19:55:34 +00:00
|
|
|
PROP_HEADING,
|
2020-04-13 04:43:19 +00:00
|
|
|
PROP_MODAL,
|
2015-09-07 19:55:34 +00:00
|
|
|
NUM_PROPERTIES,
|
|
|
|
|
|
|
|
PROP_CONTENT_TYPE = NUM_PROPERTIES
|
2010-11-24 17:45:42 +00:00
|
|
|
};
|
|
|
|
|
2010-11-29 15:04:59 +00:00
|
|
|
enum {
|
2018-11-13 14:01:21 +00:00
|
|
|
SIGNAL_CHANGED,
|
2010-11-29 15:04:59 +00:00
|
|
|
SIGNAL_CUSTOM_ITEM_ACTIVATED,
|
2021-07-05 14:10:44 +00:00
|
|
|
ACTIVATE,
|
2010-11-29 15:04:59 +00:00
|
|
|
NUM_SIGNALS
|
|
|
|
};
|
|
|
|
|
2010-11-24 17:45:42 +00:00
|
|
|
enum {
|
|
|
|
COLUMN_APP_INFO,
|
|
|
|
COLUMN_NAME,
|
2010-11-29 15:04:59 +00:00
|
|
|
COLUMN_LABEL,
|
2010-11-24 17:45:42 +00:00
|
|
|
COLUMN_ICON,
|
|
|
|
COLUMN_CUSTOM,
|
|
|
|
COLUMN_SEPARATOR,
|
|
|
|
NUM_COLUMNS,
|
|
|
|
};
|
|
|
|
|
2010-11-29 15:04:59 +00:00
|
|
|
#define CUSTOM_ITEM_OTHER_APP "gtk-internal-item-other-app"
|
2010-11-24 17:45:42 +00:00
|
|
|
|
2014-12-23 23:37:28 +00:00
|
|
|
static void app_chooser_iface_init (GtkAppChooserIface *iface);
|
2010-11-24 17:45:42 +00:00
|
|
|
|
2010-11-29 11:19:18 +00:00
|
|
|
static void real_insert_custom_item (GtkAppChooserButton *self,
|
2020-07-24 18:40:36 +00:00
|
|
|
const char *name,
|
|
|
|
const char *label,
|
2014-12-23 23:37:28 +00:00
|
|
|
GIcon *icon,
|
|
|
|
gboolean custom,
|
|
|
|
GtkTreeIter *iter);
|
2010-11-25 16:17:45 +00:00
|
|
|
|
2014-12-23 23:37:28 +00:00
|
|
|
static void real_insert_separator (GtkAppChooserButton *self,
|
|
|
|
gboolean custom,
|
|
|
|
GtkTreeIter *iter);
|
2010-11-25 16:17:45 +00:00
|
|
|
|
2010-11-29 15:04:59 +00:00
|
|
|
static guint signals[NUM_SIGNALS] = { 0, };
|
2015-09-07 19:55:34 +00:00
|
|
|
static GParamSpec *properties[NUM_PROPERTIES];
|
2010-11-29 15:04:59 +00:00
|
|
|
|
2019-05-28 00:30:35 +00:00
|
|
|
typedef struct _GtkAppChooserButtonClass GtkAppChooserButtonClass;
|
|
|
|
|
|
|
|
struct _GtkAppChooserButton {
|
|
|
|
GtkWidget parent_instance;
|
|
|
|
|
2018-11-13 14:01:21 +00:00
|
|
|
GtkWidget *combobox;
|
2010-11-24 17:45:42 +00:00
|
|
|
GtkListStore *store;
|
2010-11-25 16:17:45 +00:00
|
|
|
|
2020-07-24 18:40:36 +00:00
|
|
|
char *content_type;
|
|
|
|
char *heading;
|
2020-07-24 13:54:49 +00:00
|
|
|
int last_active;
|
2011-04-12 16:24:05 +00:00
|
|
|
gboolean show_dialog_item;
|
2011-09-10 05:40:05 +00:00
|
|
|
gboolean show_default_item;
|
2020-04-13 04:43:19 +00:00
|
|
|
gboolean modal;
|
2010-11-29 15:04:59 +00:00
|
|
|
|
|
|
|
GHashTable *custom_item_names;
|
2020-04-13 04:46:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct _GtkAppChooserButtonClass {
|
|
|
|
GtkWidgetClass parent_class;
|
|
|
|
|
|
|
|
void (* changed) (GtkAppChooserButton *self);
|
|
|
|
void (* custom_item_activated) (GtkAppChooserButton *self,
|
2020-07-24 18:40:36 +00:00
|
|
|
const char *item_name);
|
2021-07-05 14:10:44 +00:00
|
|
|
void (* activate) (GtkAppChooserButton *self);
|
2020-04-13 04:46:00 +00:00
|
|
|
};
|
2010-11-24 17:45:42 +00:00
|
|
|
|
2018-11-13 14:01:21 +00:00
|
|
|
G_DEFINE_TYPE_WITH_CODE (GtkAppChooserButton, gtk_app_chooser_button, GTK_TYPE_WIDGET,
|
2013-06-27 19:02:52 +00:00
|
|
|
G_IMPLEMENT_INTERFACE (GTK_TYPE_APP_CHOOSER,
|
|
|
|
app_chooser_iface_init));
|
|
|
|
|
2010-11-24 17:45:42 +00:00
|
|
|
static gboolean
|
|
|
|
row_separator_func (GtkTreeModel *model,
|
2010-11-24 23:32:05 +00:00
|
|
|
GtkTreeIter *iter,
|
|
|
|
gpointer user_data)
|
2010-11-24 17:45:42 +00:00
|
|
|
{
|
|
|
|
gboolean separator;
|
|
|
|
|
|
|
|
gtk_tree_model_get (model, iter,
|
2010-11-24 23:32:05 +00:00
|
|
|
COLUMN_SEPARATOR, &separator,
|
|
|
|
-1);
|
2010-11-24 17:45:42 +00:00
|
|
|
|
|
|
|
return separator;
|
|
|
|
}
|
|
|
|
|
2010-11-24 18:08:17 +00:00
|
|
|
static void
|
|
|
|
get_first_iter (GtkListStore *store,
|
2010-11-24 23:32:05 +00:00
|
|
|
GtkTreeIter *iter)
|
2010-11-24 18:08:17 +00:00
|
|
|
{
|
|
|
|
GtkTreeIter iter2;
|
|
|
|
|
|
|
|
if (!gtk_tree_model_get_iter_first (GTK_TREE_MODEL (store), iter))
|
|
|
|
{
|
|
|
|
/* the model is empty, append */
|
|
|
|
gtk_list_store_append (store, iter);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gtk_list_store_insert_before (store, &iter2, iter);
|
|
|
|
*iter = iter2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-25 16:17:45 +00:00
|
|
|
typedef struct {
|
2010-11-29 11:19:18 +00:00
|
|
|
GtkAppChooserButton *self;
|
2010-11-25 16:17:45 +00:00
|
|
|
GAppInfo *info;
|
2020-07-24 13:54:49 +00:00
|
|
|
int active_index;
|
2010-11-25 16:17:45 +00:00
|
|
|
} SelectAppData;
|
|
|
|
|
|
|
|
static void
|
|
|
|
select_app_data_free (SelectAppData *data)
|
|
|
|
{
|
|
|
|
g_clear_object (&data->self);
|
|
|
|
g_clear_object (&data->info);
|
|
|
|
|
|
|
|
g_slice_free (SelectAppData, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
select_application_func_cb (GtkTreeModel *model,
|
2014-12-23 23:37:28 +00:00
|
|
|
GtkTreePath *path,
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
gpointer user_data)
|
2010-11-25 16:17:45 +00:00
|
|
|
{
|
|
|
|
SelectAppData *data = user_data;
|
2018-11-13 14:14:10 +00:00
|
|
|
GtkAppChooserButton *self = data->self;
|
2014-12-23 23:37:28 +00:00
|
|
|
GAppInfo *app_to_match = data->info;
|
|
|
|
GAppInfo *app = NULL;
|
2010-11-25 16:17:45 +00:00
|
|
|
gboolean custom;
|
2011-04-02 03:52:46 +00:00
|
|
|
gboolean result;
|
2010-11-25 16:17:45 +00:00
|
|
|
|
|
|
|
gtk_tree_model_get (model, iter,
|
2010-11-29 15:10:58 +00:00
|
|
|
COLUMN_APP_INFO, &app,
|
|
|
|
COLUMN_CUSTOM, &custom,
|
|
|
|
-1);
|
2010-11-25 16:17:45 +00:00
|
|
|
|
2011-04-02 03:52:46 +00:00
|
|
|
/* custom items are always after GAppInfos, so iterating further here
|
2010-11-25 16:17:45 +00:00
|
|
|
* is just useless.
|
|
|
|
*/
|
|
|
|
if (custom)
|
2011-04-02 03:52:46 +00:00
|
|
|
result = TRUE;
|
|
|
|
else if (g_app_info_equal (app, app_to_match))
|
2010-11-25 16:17:45 +00:00
|
|
|
{
|
2020-04-13 04:46:00 +00:00
|
|
|
gtk_combo_box_set_active_iter (GTK_COMBO_BOX (self->combobox), iter);
|
2011-04-02 03:52:46 +00:00
|
|
|
result = TRUE;
|
2010-11-25 16:17:45 +00:00
|
|
|
}
|
2011-04-02 03:52:46 +00:00
|
|
|
else
|
|
|
|
result = FALSE;
|
|
|
|
|
|
|
|
g_object_unref (app);
|
2010-11-25 16:17:45 +00:00
|
|
|
|
2011-04-02 03:52:46 +00:00
|
|
|
return result;
|
2010-11-25 16:17:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-11-29 11:19:18 +00:00
|
|
|
gtk_app_chooser_button_select_application (GtkAppChooserButton *self,
|
2014-12-23 23:37:28 +00:00
|
|
|
GAppInfo *info)
|
2010-11-25 16:17:45 +00:00
|
|
|
{
|
|
|
|
SelectAppData *data;
|
|
|
|
|
|
|
|
data = g_slice_new0 (SelectAppData);
|
|
|
|
data->self = g_object_ref (self);
|
|
|
|
data->info = g_object_ref (info);
|
|
|
|
|
2020-04-13 04:46:00 +00:00
|
|
|
gtk_tree_model_foreach (GTK_TREE_MODEL (self->store),
|
2010-11-29 15:10:58 +00:00
|
|
|
select_application_func_cb, data);
|
2010-11-25 16:17:45 +00:00
|
|
|
|
|
|
|
select_app_data_free (data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
other_application_dialog_response_cb (GtkDialog *dialog,
|
2020-07-24 13:54:49 +00:00
|
|
|
int response_id,
|
2014-12-23 23:37:28 +00:00
|
|
|
gpointer user_data)
|
2010-11-25 16:17:45 +00:00
|
|
|
{
|
2010-11-29 11:19:18 +00:00
|
|
|
GtkAppChooserButton *self = user_data;
|
2010-11-25 16:17:45 +00:00
|
|
|
GAppInfo *info;
|
|
|
|
|
|
|
|
if (response_id != GTK_RESPONSE_OK)
|
|
|
|
{
|
|
|
|
/* reset the active item, otherwise we are stuck on
|
2012-11-26 08:59:27 +00:00
|
|
|
* 'Other application…'
|
2010-11-25 16:17:45 +00:00
|
|
|
*/
|
2020-04-13 04:46:00 +00:00
|
|
|
gtk_combo_box_set_active (GTK_COMBO_BOX (self->combobox), self->last_active);
|
2020-05-09 14:26:22 +00:00
|
|
|
gtk_window_destroy (GTK_WINDOW (dialog));
|
2010-11-25 16:17:45 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
info = gtk_app_chooser_get_app_info (GTK_APP_CHOOSER (dialog));
|
|
|
|
|
2020-05-09 14:26:22 +00:00
|
|
|
gtk_window_destroy (GTK_WINDOW (dialog));
|
2011-08-24 04:10:34 +00:00
|
|
|
|
2010-11-25 16:17:45 +00:00
|
|
|
/* refresh the combobox to get the new application */
|
|
|
|
gtk_app_chooser_refresh (GTK_APP_CHOOSER (self));
|
2010-11-29 11:19:18 +00:00
|
|
|
gtk_app_chooser_button_select_application (self, info);
|
2010-11-25 16:17:45 +00:00
|
|
|
|
|
|
|
g_object_unref (info);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-11-29 15:04:59 +00:00
|
|
|
other_application_item_activated_cb (GtkAppChooserButton *self)
|
2010-11-25 16:17:45 +00:00
|
|
|
{
|
|
|
|
GtkWidget *dialog, *widget;
|
2019-03-17 23:41:26 +00:00
|
|
|
GtkRoot *root;
|
2010-11-25 16:17:45 +00:00
|
|
|
|
2019-03-17 23:41:26 +00:00
|
|
|
root = gtk_widget_get_root (GTK_WIDGET (self));
|
|
|
|
dialog = gtk_app_chooser_dialog_new_for_content_type (GTK_WINDOW (root),
|
2014-12-23 23:37:28 +00:00
|
|
|
GTK_DIALOG_DESTROY_WITH_PARENT,
|
2020-04-13 04:46:00 +00:00
|
|
|
self->content_type);
|
|
|
|
gtk_window_set_modal (GTK_WINDOW (dialog), self->modal | gtk_window_get_modal (GTK_WINDOW (root)));
|
|
|
|
gtk_app_chooser_dialog_set_heading (GTK_APP_CHOOSER_DIALOG (dialog), self->heading);
|
2011-01-21 02:21:42 +00:00
|
|
|
|
2010-11-25 16:17:45 +00:00
|
|
|
widget = gtk_app_chooser_dialog_get_widget (GTK_APP_CHOOSER_DIALOG (dialog));
|
|
|
|
g_object_set (widget,
|
2010-11-29 15:10:58 +00:00
|
|
|
"show-fallback", TRUE,
|
|
|
|
"show-other", TRUE,
|
|
|
|
NULL);
|
2010-11-25 16:17:45 +00:00
|
|
|
gtk_widget_show (dialog);
|
|
|
|
|
|
|
|
g_signal_connect (dialog, "response",
|
2010-11-29 15:10:58 +00:00
|
|
|
G_CALLBACK (other_application_dialog_response_cb), self);
|
2010-11-25 16:17:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-11-29 11:19:18 +00:00
|
|
|
gtk_app_chooser_button_ensure_dialog_item (GtkAppChooserButton *self,
|
2014-12-23 23:37:28 +00:00
|
|
|
GtkTreeIter *prev_iter)
|
2010-11-25 16:17:45 +00:00
|
|
|
{
|
2010-12-01 19:18:12 +00:00
|
|
|
GtkTreeIter iter, iter2;
|
2010-11-25 16:17:45 +00:00
|
|
|
|
2020-04-13 04:46:00 +00:00
|
|
|
if (!self->show_dialog_item || !self->content_type)
|
2010-11-25 16:17:45 +00:00
|
|
|
return;
|
|
|
|
|
2010-12-01 19:18:12 +00:00
|
|
|
if (prev_iter == NULL)
|
2020-04-13 04:46:00 +00:00
|
|
|
gtk_list_store_append (self->store, &iter);
|
2010-12-01 19:18:12 +00:00
|
|
|
else
|
2020-04-13 04:46:00 +00:00
|
|
|
gtk_list_store_insert_after (self->store, &iter, prev_iter);
|
2010-12-01 19:18:12 +00:00
|
|
|
|
2010-11-25 16:17:45 +00:00
|
|
|
real_insert_separator (self, FALSE, &iter);
|
2010-12-01 19:18:12 +00:00
|
|
|
iter2 = iter;
|
2010-11-25 16:17:45 +00:00
|
|
|
|
2020-04-13 04:46:00 +00:00
|
|
|
gtk_list_store_insert_after (self->store, &iter, &iter2);
|
2010-11-29 15:04:59 +00:00
|
|
|
real_insert_custom_item (self, CUSTOM_ITEM_OTHER_APP,
|
2012-11-26 08:59:27 +00:00
|
|
|
_("Other application…"), NULL,
|
2010-11-29 15:04:59 +00:00
|
|
|
FALSE, &iter);
|
2010-11-25 16:17:45 +00:00
|
|
|
}
|
|
|
|
|
2011-09-10 05:40:05 +00:00
|
|
|
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);
|
|
|
|
|
2020-04-13 04:46:00 +00:00
|
|
|
gtk_list_store_set (self->store, iter,
|
2011-09-10 05:40:05 +00:00
|
|
|
COLUMN_APP_INFO, app,
|
|
|
|
COLUMN_LABEL, g_app_info_get_name (app),
|
|
|
|
COLUMN_ICON, icon,
|
|
|
|
COLUMN_CUSTOM, FALSE,
|
|
|
|
-1);
|
|
|
|
|
|
|
|
g_object_unref (icon);
|
|
|
|
}
|
|
|
|
|
2010-11-24 17:45:42 +00:00
|
|
|
static void
|
2010-11-29 11:19:18 +00:00
|
|
|
gtk_app_chooser_button_populate (GtkAppChooserButton *self)
|
2010-11-24 17:45:42 +00:00
|
|
|
{
|
|
|
|
GList *recommended_apps = NULL, *l;
|
2011-09-10 05:40:05 +00:00
|
|
|
GAppInfo *app, *default_app = NULL;
|
2010-11-24 18:08:17 +00:00
|
|
|
GtkTreeIter iter, iter2;
|
2010-12-01 19:18:12 +00:00
|
|
|
gboolean cycled_recommended;
|
2010-11-24 17:45:42 +00:00
|
|
|
|
2011-01-11 15:13:34 +00:00
|
|
|
#ifndef G_OS_WIN32
|
2020-04-13 04:46:00 +00:00
|
|
|
if (self->content_type)
|
|
|
|
recommended_apps = g_app_info_get_recommended_for_type (self->content_type);
|
2011-01-11 15:13:34 +00:00
|
|
|
#endif
|
2010-12-01 19:18:12 +00:00
|
|
|
cycled_recommended = FALSE;
|
2010-12-01 15:29:57 +00:00
|
|
|
|
2020-04-13 04:46:00 +00:00
|
|
|
if (self->show_default_item)
|
2011-09-10 05:40:05 +00:00
|
|
|
{
|
2020-04-13 04:46:00 +00:00
|
|
|
if (self->content_type)
|
|
|
|
default_app = g_app_info_get_default_for_type (self->content_type, FALSE);
|
2011-09-10 05:40:05 +00:00
|
|
|
|
|
|
|
if (default_app != NULL)
|
|
|
|
{
|
2020-04-13 04:46:00 +00:00
|
|
|
get_first_iter (self->store, &iter);
|
2011-09-10 05:40:05 +00:00
|
|
|
cycled_recommended = TRUE;
|
|
|
|
|
|
|
|
insert_one_application (self, default_app, &iter);
|
|
|
|
|
|
|
|
g_object_unref (default_app);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-24 17:45:42 +00:00
|
|
|
for (l = recommended_apps; l != NULL; l = l->next)
|
|
|
|
{
|
|
|
|
app = l->data;
|
|
|
|
|
2011-09-10 05:40:05 +00:00
|
|
|
if (default_app != NULL && g_app_info_equal (app, default_app))
|
|
|
|
continue;
|
2010-11-24 17:45:42 +00:00
|
|
|
|
2010-12-01 19:18:12 +00:00
|
|
|
if (cycled_recommended)
|
2010-11-24 23:32:05 +00:00
|
|
|
{
|
2020-04-13 04:46:00 +00:00
|
|
|
gtk_list_store_insert_after (self->store, &iter2, &iter);
|
2010-12-01 19:18:12 +00:00
|
|
|
iter = iter2;
|
2010-11-24 23:32:05 +00:00
|
|
|
}
|
2010-11-24 18:08:17 +00:00
|
|
|
else
|
2010-11-24 23:32:05 +00:00
|
|
|
{
|
2020-04-13 04:46:00 +00:00
|
|
|
get_first_iter (self->store, &iter);
|
2010-12-01 19:18:12 +00:00
|
|
|
cycled_recommended = TRUE;
|
2010-11-24 23:32:05 +00:00
|
|
|
}
|
2010-11-24 18:08:17 +00:00
|
|
|
|
2011-09-10 05:40:05 +00:00
|
|
|
insert_one_application (self, app, &iter);
|
2010-11-24 17:45:42 +00:00
|
|
|
}
|
|
|
|
|
2011-09-10 05:40:05 +00:00
|
|
|
if (recommended_apps != NULL)
|
|
|
|
g_list_free_full (recommended_apps, g_object_unref);
|
|
|
|
|
2010-12-01 19:18:12 +00:00
|
|
|
if (!cycled_recommended)
|
|
|
|
gtk_app_chooser_button_ensure_dialog_item (self, NULL);
|
|
|
|
else
|
|
|
|
gtk_app_chooser_button_ensure_dialog_item (self, &iter);
|
|
|
|
|
2020-04-13 04:46:00 +00:00
|
|
|
gtk_combo_box_set_active (GTK_COMBO_BOX (self->combobox), 0);
|
2010-11-24 17:45:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-11-29 11:19:18 +00:00
|
|
|
gtk_app_chooser_button_build_ui (GtkAppChooserButton *self)
|
2010-11-24 17:45:42 +00:00
|
|
|
{
|
|
|
|
GtkCellRenderer *cell;
|
2011-01-20 20:48:00 +00:00
|
|
|
GtkCellArea *area;
|
2010-11-24 17:45:42 +00:00
|
|
|
|
2020-04-13 04:46:00 +00:00
|
|
|
gtk_combo_box_set_model (GTK_COMBO_BOX (self->combobox),
|
|
|
|
GTK_TREE_MODEL (self->store));
|
2010-11-24 17:45:42 +00:00
|
|
|
|
2020-04-13 04:46:00 +00:00
|
|
|
area = gtk_cell_layout_get_area (GTK_CELL_LAYOUT (self->combobox));
|
2011-01-20 20:48:00 +00:00
|
|
|
|
2020-04-13 04:46:00 +00:00
|
|
|
gtk_combo_box_set_row_separator_func (GTK_COMBO_BOX (self->combobox),
|
2010-11-24 23:32:05 +00:00
|
|
|
row_separator_func, NULL, NULL);
|
2010-11-24 17:45:42 +00:00
|
|
|
|
|
|
|
cell = gtk_cell_renderer_pixbuf_new ();
|
2011-01-20 20:48:00 +00:00
|
|
|
gtk_cell_area_add_with_properties (area, cell,
|
|
|
|
"align", FALSE,
|
|
|
|
"expand", FALSE,
|
|
|
|
"fixed-size", FALSE,
|
|
|
|
NULL);
|
2020-04-13 04:46:00 +00:00
|
|
|
gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (self->combobox), cell,
|
2010-11-24 23:32:05 +00:00
|
|
|
"gicon", COLUMN_ICON,
|
|
|
|
NULL);
|
2010-11-24 17:45:42 +00:00
|
|
|
|
|
|
|
cell = gtk_cell_renderer_text_new ();
|
2011-01-20 20:48:00 +00:00
|
|
|
gtk_cell_area_add_with_properties (area, cell,
|
|
|
|
"align", FALSE,
|
|
|
|
"expand", TRUE,
|
|
|
|
NULL);
|
2020-04-13 04:46:00 +00:00
|
|
|
gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (self->combobox), cell,
|
2010-11-29 15:04:59 +00:00
|
|
|
"text", COLUMN_LABEL,
|
2010-11-24 23:32:05 +00:00
|
|
|
NULL);
|
2010-11-24 17:45:42 +00:00
|
|
|
|
2010-11-29 11:19:18 +00:00
|
|
|
gtk_app_chooser_button_populate (self);
|
2010-11-24 17:45:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-11-29 11:19:18 +00:00
|
|
|
gtk_app_chooser_button_remove_non_custom (GtkAppChooserButton *self)
|
2010-11-24 17:45:42 +00:00
|
|
|
{
|
|
|
|
GtkTreeModel *model;
|
|
|
|
GtkTreeIter iter;
|
|
|
|
gboolean custom, res;
|
|
|
|
|
2020-04-13 04:46:00 +00:00
|
|
|
model = GTK_TREE_MODEL (self->store);
|
2010-11-24 17:45:42 +00:00
|
|
|
|
|
|
|
if (!gtk_tree_model_get_iter_first (model, &iter))
|
|
|
|
return;
|
|
|
|
|
|
|
|
do {
|
|
|
|
gtk_tree_model_get (model, &iter,
|
2010-11-24 23:32:05 +00:00
|
|
|
COLUMN_CUSTOM, &custom,
|
|
|
|
-1);
|
2010-11-24 17:45:42 +00:00
|
|
|
if (custom)
|
|
|
|
res = gtk_tree_model_iter_next (model, &iter);
|
2010-11-24 18:08:17 +00:00
|
|
|
else
|
|
|
|
res = gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
|
2010-11-24 17:45:42 +00:00
|
|
|
} while (res);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2018-11-13 14:01:21 +00:00
|
|
|
gtk_app_chooser_button_changed (GtkComboBox *object,
|
|
|
|
gpointer user_data)
|
2010-11-24 17:45:42 +00:00
|
|
|
{
|
2018-11-13 14:01:21 +00:00
|
|
|
GtkAppChooserButton *self = user_data;
|
2010-11-24 17:45:42 +00:00
|
|
|
GtkTreeIter iter;
|
2020-07-24 18:40:36 +00:00
|
|
|
char *name = NULL;
|
2010-11-29 15:04:59 +00:00
|
|
|
gboolean custom;
|
|
|
|
GQuark name_quark;
|
2010-11-24 17:45:42 +00:00
|
|
|
|
2010-11-24 18:08:17 +00:00
|
|
|
if (!gtk_combo_box_get_active_iter (object, &iter))
|
|
|
|
return;
|
2010-11-24 17:45:42 +00:00
|
|
|
|
2020-04-13 04:46:00 +00:00
|
|
|
gtk_tree_model_get (GTK_TREE_MODEL (self->store), &iter,
|
2010-11-29 15:04:59 +00:00
|
|
|
COLUMN_NAME, &name,
|
|
|
|
COLUMN_CUSTOM, &custom,
|
2010-11-24 23:32:05 +00:00
|
|
|
-1);
|
2010-11-24 17:45:42 +00:00
|
|
|
|
2010-11-29 15:04:59 +00:00
|
|
|
if (name != NULL)
|
|
|
|
{
|
|
|
|
if (custom)
|
|
|
|
{
|
|
|
|
name_quark = g_quark_from_string (name);
|
|
|
|
g_signal_emit (self, signals[SIGNAL_CUSTOM_ITEM_ACTIVATED], name_quark, name);
|
2020-04-13 04:46:00 +00:00
|
|
|
self->last_active = gtk_combo_box_get_active (object);
|
2010-11-29 15:04:59 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* trigger the dialog internally */
|
|
|
|
other_application_item_activated_cb (self);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free (name);
|
|
|
|
}
|
2011-01-20 21:58:19 +00:00
|
|
|
else
|
2020-04-13 04:46:00 +00:00
|
|
|
self->last_active = gtk_combo_box_get_active (object);
|
2018-11-13 14:01:21 +00:00
|
|
|
|
|
|
|
g_signal_emit (self, signals[SIGNAL_CHANGED], 0);
|
2010-11-24 17:45:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-11-29 11:19:18 +00:00
|
|
|
gtk_app_chooser_button_refresh (GtkAppChooser *object)
|
2010-11-24 17:45:42 +00:00
|
|
|
{
|
2010-11-29 11:19:18 +00:00
|
|
|
GtkAppChooserButton *self = GTK_APP_CHOOSER_BUTTON (object);
|
2010-11-24 17:45:42 +00:00
|
|
|
|
2010-11-29 11:19:18 +00:00
|
|
|
gtk_app_chooser_button_remove_non_custom (self);
|
|
|
|
gtk_app_chooser_button_populate (self);
|
2010-11-24 17:45:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static GAppInfo *
|
2010-11-29 11:19:18 +00:00
|
|
|
gtk_app_chooser_button_get_app_info (GtkAppChooser *object)
|
2010-11-24 17:45:42 +00:00
|
|
|
{
|
2010-11-29 11:19:18 +00:00
|
|
|
GtkAppChooserButton *self = GTK_APP_CHOOSER_BUTTON (object);
|
2010-11-24 17:45:42 +00:00
|
|
|
GtkTreeIter iter;
|
|
|
|
GAppInfo *info;
|
|
|
|
|
2020-04-13 04:46:00 +00:00
|
|
|
if (!gtk_combo_box_get_active_iter (GTK_COMBO_BOX (self->combobox), &iter))
|
2010-11-24 17:45:42 +00:00
|
|
|
return NULL;
|
|
|
|
|
2020-04-13 04:46:00 +00:00
|
|
|
gtk_tree_model_get (GTK_TREE_MODEL (self->store), &iter,
|
2010-11-24 23:32:05 +00:00
|
|
|
COLUMN_APP_INFO, &info,
|
|
|
|
-1);
|
2010-11-24 17:45:42 +00:00
|
|
|
|
|
|
|
return info;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-11-29 11:19:18 +00:00
|
|
|
gtk_app_chooser_button_constructed (GObject *obj)
|
2010-11-24 17:45:42 +00:00
|
|
|
{
|
2010-11-29 11:19:18 +00:00
|
|
|
GtkAppChooserButton *self = GTK_APP_CHOOSER_BUTTON (obj);
|
2010-11-24 17:45:42 +00:00
|
|
|
|
2010-11-29 11:19:18 +00:00
|
|
|
if (G_OBJECT_CLASS (gtk_app_chooser_button_parent_class)->constructed != NULL)
|
|
|
|
G_OBJECT_CLASS (gtk_app_chooser_button_parent_class)->constructed (obj);
|
2010-11-24 17:45:42 +00:00
|
|
|
|
2010-11-29 11:19:18 +00:00
|
|
|
gtk_app_chooser_button_build_ui (self);
|
2010-11-24 17:45:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-11-29 11:19:18 +00:00
|
|
|
gtk_app_chooser_button_set_property (GObject *obj,
|
|
|
|
guint property_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
2010-11-24 17:45:42 +00:00
|
|
|
{
|
2010-11-29 11:19:18 +00:00
|
|
|
GtkAppChooserButton *self = GTK_APP_CHOOSER_BUTTON (obj);
|
2010-11-24 17:45:42 +00:00
|
|
|
|
|
|
|
switch (property_id)
|
|
|
|
{
|
|
|
|
case PROP_CONTENT_TYPE:
|
2020-04-13 04:46:00 +00:00
|
|
|
self->content_type = g_value_dup_string (value);
|
2010-11-24 17:45:42 +00:00
|
|
|
break;
|
2010-11-25 16:17:45 +00:00
|
|
|
case PROP_SHOW_DIALOG_ITEM:
|
2010-11-29 11:19:18 +00:00
|
|
|
gtk_app_chooser_button_set_show_dialog_item (self, g_value_get_boolean (value));
|
2010-11-25 16:17:45 +00:00
|
|
|
break;
|
2011-09-10 05:40:05 +00:00
|
|
|
case PROP_SHOW_DEFAULT_ITEM:
|
|
|
|
gtk_app_chooser_button_set_show_default_item (self, g_value_get_boolean (value));
|
|
|
|
break;
|
2011-01-25 00:25:08 +00:00
|
|
|
case PROP_HEADING:
|
|
|
|
gtk_app_chooser_button_set_heading (self, g_value_get_string (value));
|
|
|
|
break;
|
2020-04-13 04:43:19 +00:00
|
|
|
case PROP_MODAL:
|
|
|
|
gtk_app_chooser_button_set_modal (self, g_value_get_boolean (value));
|
|
|
|
break;
|
2010-11-24 17:45:42 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, property_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-11-29 11:19:18 +00:00
|
|
|
gtk_app_chooser_button_get_property (GObject *obj,
|
|
|
|
guint property_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
2010-11-24 17:45:42 +00:00
|
|
|
{
|
2010-11-29 11:19:18 +00:00
|
|
|
GtkAppChooserButton *self = GTK_APP_CHOOSER_BUTTON (obj);
|
2010-11-24 17:45:42 +00:00
|
|
|
|
|
|
|
switch (property_id)
|
|
|
|
{
|
|
|
|
case PROP_CONTENT_TYPE:
|
2020-04-13 04:46:00 +00:00
|
|
|
g_value_set_string (value, self->content_type);
|
2010-11-24 17:45:42 +00:00
|
|
|
break;
|
2010-11-25 16:17:45 +00:00
|
|
|
case PROP_SHOW_DIALOG_ITEM:
|
2020-04-13 04:46:00 +00:00
|
|
|
g_value_set_boolean (value, self->show_dialog_item);
|
2010-11-25 16:17:45 +00:00
|
|
|
break;
|
2011-09-10 05:40:05 +00:00
|
|
|
case PROP_SHOW_DEFAULT_ITEM:
|
2020-04-13 04:46:00 +00:00
|
|
|
g_value_set_boolean (value, self->show_default_item);
|
2011-09-10 05:40:05 +00:00
|
|
|
break;
|
2011-01-25 00:25:08 +00:00
|
|
|
case PROP_HEADING:
|
2020-04-13 04:46:00 +00:00
|
|
|
g_value_set_string (value, self->heading);
|
2011-01-25 00:25:08 +00:00
|
|
|
break;
|
2020-04-13 04:43:19 +00:00
|
|
|
case PROP_MODAL:
|
2020-04-13 04:46:00 +00:00
|
|
|
g_value_set_boolean (value, self->modal);
|
2020-04-13 04:43:19 +00:00
|
|
|
break;
|
2010-11-24 17:45:42 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, property_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-11-29 11:19:18 +00:00
|
|
|
gtk_app_chooser_button_finalize (GObject *obj)
|
2010-11-24 17:45:42 +00:00
|
|
|
{
|
2010-11-29 11:19:18 +00:00
|
|
|
GtkAppChooserButton *self = GTK_APP_CHOOSER_BUTTON (obj);
|
2010-11-24 17:45:42 +00:00
|
|
|
|
2020-04-13 04:46:00 +00:00
|
|
|
g_hash_table_destroy (self->custom_item_names);
|
|
|
|
g_free (self->content_type);
|
|
|
|
g_free (self->heading);
|
|
|
|
g_object_unref (self->store);
|
|
|
|
gtk_widget_unparent (self->combobox);
|
2011-03-01 10:41:15 +00:00
|
|
|
|
2010-11-29 11:19:18 +00:00
|
|
|
G_OBJECT_CLASS (gtk_app_chooser_button_parent_class)->finalize (obj);
|
2010-11-24 17:45:42 +00:00
|
|
|
}
|
|
|
|
|
2018-11-13 14:01:21 +00:00
|
|
|
static void
|
|
|
|
gtk_app_chooser_button_measure (GtkWidget *widget,
|
|
|
|
GtkOrientation orientation,
|
|
|
|
int for_size,
|
|
|
|
int *minimum,
|
|
|
|
int *natural,
|
|
|
|
int *minimum_baseline,
|
|
|
|
int *natural_baseline)
|
|
|
|
{
|
2020-04-13 04:46:00 +00:00
|
|
|
GtkAppChooserButton *self = GTK_APP_CHOOSER_BUTTON (widget);
|
2018-11-13 14:01:21 +00:00
|
|
|
|
2020-04-13 04:46:00 +00:00
|
|
|
gtk_widget_measure (self->combobox, orientation, for_size,
|
2018-11-13 14:01:21 +00:00
|
|
|
minimum, natural,
|
|
|
|
minimum_baseline, natural_baseline);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2018-08-16 04:53:03 +00:00
|
|
|
gtk_app_chooser_button_size_allocate (GtkWidget *widget,
|
|
|
|
int width,
|
|
|
|
int height,
|
|
|
|
int baseline)
|
2018-11-13 14:01:21 +00:00
|
|
|
{
|
2020-04-13 04:46:00 +00:00
|
|
|
GtkAppChooserButton *self = GTK_APP_CHOOSER_BUTTON (widget);
|
2018-11-13 14:01:21 +00:00
|
|
|
|
2020-04-13 04:46:00 +00:00
|
|
|
gtk_widget_size_allocate (self->combobox, &(GtkAllocation){0, 0, width, height}, baseline);
|
2018-11-13 14:01:21 +00:00
|
|
|
}
|
|
|
|
|
2010-11-24 17:45:42 +00:00
|
|
|
static void
|
|
|
|
app_chooser_iface_init (GtkAppChooserIface *iface)
|
|
|
|
{
|
2010-11-29 11:19:18 +00:00
|
|
|
iface->get_app_info = gtk_app_chooser_button_get_app_info;
|
|
|
|
iface->refresh = gtk_app_chooser_button_refresh;
|
2010-11-24 17:45:42 +00:00
|
|
|
}
|
|
|
|
|
2021-07-05 14:10:44 +00:00
|
|
|
static void
|
|
|
|
gtk_app_chooser_button_activate (GtkAppChooserButton *self)
|
|
|
|
{
|
|
|
|
gtk_widget_activate (self->combobox);
|
|
|
|
}
|
|
|
|
|
2010-11-24 17:45:42 +00:00
|
|
|
static void
|
2010-11-29 11:19:18 +00:00
|
|
|
gtk_app_chooser_button_class_init (GtkAppChooserButtonClass *klass)
|
2010-11-24 17:45:42 +00:00
|
|
|
{
|
|
|
|
GObjectClass *oclass = G_OBJECT_CLASS (klass);
|
2018-11-13 14:01:21 +00:00
|
|
|
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
|
2010-11-24 17:45:42 +00:00
|
|
|
|
2010-11-29 11:19:18 +00:00
|
|
|
oclass->set_property = gtk_app_chooser_button_set_property;
|
|
|
|
oclass->get_property = gtk_app_chooser_button_get_property;
|
|
|
|
oclass->finalize = gtk_app_chooser_button_finalize;
|
|
|
|
oclass->constructed = gtk_app_chooser_button_constructed;
|
2010-11-24 17:45:42 +00:00
|
|
|
|
2018-11-13 14:01:21 +00:00
|
|
|
widget_class->measure = gtk_app_chooser_button_measure;
|
|
|
|
widget_class->size_allocate = gtk_app_chooser_button_size_allocate;
|
2020-04-08 11:43:28 +00:00
|
|
|
widget_class->grab_focus = gtk_widget_grab_focus_child;
|
|
|
|
widget_class->focus = gtk_widget_focus_child;
|
2010-11-24 17:45:42 +00:00
|
|
|
|
2021-07-05 14:10:44 +00:00
|
|
|
klass->activate = gtk_app_chooser_button_activate;
|
|
|
|
|
2010-11-24 17:45:42 +00:00
|
|
|
g_object_class_override_property (oclass, PROP_CONTENT_TYPE, "content-type");
|
|
|
|
|
2010-11-29 11:25:52 +00:00
|
|
|
/**
|
2021-02-25 23:22:25 +00:00
|
|
|
* GtkAppChooserButton:show-dialog-item: (attributes org.gtk.Property.get=gtk_app_chooser_button_get_show_dialog_item org.gtk.Property.set=gtk_app_chooser_button_set_show_dialog_item)
|
2010-11-29 11:25:52 +00:00
|
|
|
*
|
2021-02-22 00:41:33 +00:00
|
|
|
* Determines whether the dropdown menu shows an item to open
|
|
|
|
* a `GtkAppChooserDialog`.
|
2010-11-29 11:25:52 +00:00
|
|
|
*/
|
2015-09-07 19:55:34 +00:00
|
|
|
properties[PROP_SHOW_DIALOG_ITEM] =
|
2010-11-29 15:10:58 +00:00
|
|
|
g_param_spec_boolean ("show-dialog-item",
|
2016-10-03 16:20:03 +00:00
|
|
|
P_("Include an “Other…” item"),
|
2010-11-29 15:10:58 +00:00
|
|
|
P_("Whether the combobox should include an item that triggers a GtkAppChooserDialog"),
|
|
|
|
FALSE,
|
2014-06-07 20:38:34 +00:00
|
|
|
G_PARAM_READWRITE|G_PARAM_CONSTRUCT|G_PARAM_STATIC_STRINGS|G_PARAM_EXPLICIT_NOTIFY);
|
2010-11-25 16:17:45 +00:00
|
|
|
|
2011-09-10 05:40:05 +00:00
|
|
|
/**
|
2021-02-25 23:22:25 +00:00
|
|
|
* GtkAppChooserButton:show-default-item: (attributes org.gtk.Property.get=gtk_app_chooser_button_get_show_default_item org.gtk.Property.set=gtk_app_chooser_button_set_show_default_item)
|
2011-09-10 05:40:05 +00:00
|
|
|
*
|
2021-02-22 00:41:33 +00:00
|
|
|
* Determines whether the dropdown menu shows the default application
|
2011-09-10 05:40:05 +00:00
|
|
|
* on top for the provided content type.
|
|
|
|
*/
|
2015-09-07 19:55:34 +00:00
|
|
|
properties[PROP_SHOW_DEFAULT_ITEM] =
|
2011-09-10 05:40:05 +00:00
|
|
|
g_param_spec_boolean ("show-default-item",
|
|
|
|
P_("Show default item"),
|
|
|
|
P_("Whether the combobox should show the default application on top"),
|
|
|
|
FALSE,
|
2014-06-07 20:38:34 +00:00
|
|
|
G_PARAM_READWRITE|G_PARAM_CONSTRUCT|G_PARAM_STATIC_STRINGS|G_PARAM_EXPLICIT_NOTIFY);
|
2011-09-10 05:40:05 +00:00
|
|
|
|
2011-01-25 00:25:08 +00:00
|
|
|
/**
|
2021-02-25 23:22:25 +00:00
|
|
|
* GtkAppChooserButton:heading: (attributes org.gtk.Property.get=gtk_app_chooser_button_get_heading org.gtk.Property.set=gtk_app_chooser_button_set_heading)
|
2011-01-25 00:25:08 +00:00
|
|
|
*
|
|
|
|
* The text to show at the top of the dialog that can be
|
2021-02-22 00:41:33 +00:00
|
|
|
* opened from the button.
|
|
|
|
*
|
|
|
|
* The string may contain Pango markup.
|
2011-01-25 00:25:08 +00:00
|
|
|
*/
|
2015-09-07 19:55:34 +00:00
|
|
|
properties[PROP_HEADING] =
|
|
|
|
g_param_spec_string ("heading",
|
|
|
|
P_("Heading"),
|
|
|
|
P_("The text to show at the top of the dialog"),
|
|
|
|
NULL,
|
|
|
|
G_PARAM_READWRITE|G_PARAM_STATIC_STRINGS|G_PARAM_EXPLICIT_NOTIFY);
|
|
|
|
|
2021-02-22 00:41:33 +00:00
|
|
|
/**
|
2021-02-25 23:22:25 +00:00
|
|
|
* GtkAppChooserButton:modal: (attributes org.gtk.Property.get=gtk_app_chooser_button_get_modal org.gtk.Property.set=gtk_app_chooser_button_set_modal)
|
2021-02-22 00:41:33 +00:00
|
|
|
*
|
|
|
|
* Whether the app chooser dialog should be modal.
|
|
|
|
*/
|
2020-04-13 04:43:19 +00:00
|
|
|
properties[PROP_MODAL] =
|
|
|
|
g_param_spec_boolean ("modal",
|
|
|
|
P_("Modal"),
|
|
|
|
P_("Whether the dialog should be modal"),
|
|
|
|
TRUE,
|
|
|
|
G_PARAM_READWRITE|G_PARAM_CONSTRUCT|G_PARAM_STATIC_STRINGS|G_PARAM_EXPLICIT_NOTIFY);
|
2015-09-07 19:55:34 +00:00
|
|
|
g_object_class_install_properties (oclass, NUM_PROPERTIES, properties);
|
2011-01-25 00:25:08 +00:00
|
|
|
|
2020-12-01 17:16:05 +00:00
|
|
|
/**
|
|
|
|
* GtkAppChooserButton::changed:
|
|
|
|
* @self: the object which received the signal
|
|
|
|
*
|
2021-02-22 00:41:33 +00:00
|
|
|
* Emitted when the active application changes.
|
2020-12-01 17:16:05 +00:00
|
|
|
*/
|
2018-11-13 14:01:21 +00:00
|
|
|
signals[SIGNAL_CHANGED] =
|
|
|
|
g_signal_new (I_("changed"),
|
|
|
|
G_OBJECT_CLASS_TYPE (klass),
|
|
|
|
G_SIGNAL_RUN_LAST,
|
|
|
|
G_STRUCT_OFFSET (GtkAppChooserButtonClass, changed),
|
|
|
|
NULL, NULL,
|
2019-05-29 20:05:19 +00:00
|
|
|
NULL,
|
2018-11-13 14:01:21 +00:00
|
|
|
G_TYPE_NONE, 0);
|
|
|
|
|
|
|
|
|
2010-11-30 14:03:33 +00:00
|
|
|
/**
|
|
|
|
* GtkAppChooserButton::custom-item-activated:
|
|
|
|
* @self: the object which received the signal
|
|
|
|
* @item_name: the name of the activated item
|
|
|
|
*
|
2021-02-22 00:41:33 +00:00
|
|
|
* Emitted when a custom item is activated.
|
|
|
|
*
|
|
|
|
* Use [method@Gtk.AppChooserButton.append_custom_item],
|
|
|
|
* to add custom items.
|
2010-11-30 14:03:33 +00:00
|
|
|
*/
|
2010-11-29 15:04:59 +00:00
|
|
|
signals[SIGNAL_CUSTOM_ITEM_ACTIVATED] =
|
2015-09-12 13:13:00 +00:00
|
|
|
g_signal_new (I_("custom-item-activated"),
|
2010-11-29 15:04:59 +00:00
|
|
|
GTK_TYPE_APP_CHOOSER_BUTTON,
|
|
|
|
G_SIGNAL_RUN_FIRST | G_SIGNAL_DETAILED,
|
|
|
|
G_STRUCT_OFFSET (GtkAppChooserButtonClass, custom_item_activated),
|
|
|
|
NULL, NULL,
|
2016-08-29 14:00:17 +00:00
|
|
|
NULL,
|
2010-11-29 15:04:59 +00:00
|
|
|
G_TYPE_NONE,
|
|
|
|
1, G_TYPE_STRING);
|
2018-11-13 14:01:21 +00:00
|
|
|
|
2021-07-05 14:10:44 +00:00
|
|
|
/**
|
|
|
|
* GtkAppChooserButton::activate:
|
|
|
|
* @widget: the object which received the signal.
|
|
|
|
*
|
|
|
|
* Emitted to when the button is activated.
|
|
|
|
*
|
|
|
|
* The `::activate` signal on `GtkAppChooserButton` is an action signal and
|
|
|
|
* emitting it causes the button to pop up its dialog.
|
|
|
|
*
|
|
|
|
* Since: 4.4
|
|
|
|
*/
|
|
|
|
signals[ACTIVATE] =
|
|
|
|
g_signal_new (I_ ("activate"),
|
|
|
|
G_OBJECT_CLASS_TYPE (oclass),
|
|
|
|
G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
|
|
|
|
G_STRUCT_OFFSET (GtkAppChooserButtonClass, activate),
|
|
|
|
NULL, NULL,
|
|
|
|
NULL,
|
|
|
|
G_TYPE_NONE, 0);
|
|
|
|
|
|
|
|
gtk_widget_class_set_activate_signal (widget_class, signals[ACTIVATE]);
|
|
|
|
|
2018-11-13 14:01:21 +00:00
|
|
|
|
2020-08-02 09:26:40 +00:00
|
|
|
gtk_widget_class_set_css_name (widget_class, I_("appchooserbutton"));
|
2010-11-24 17:45:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-11-29 11:19:18 +00:00
|
|
|
gtk_app_chooser_button_init (GtkAppChooserButton *self)
|
2010-11-24 17:45:42 +00:00
|
|
|
{
|
2020-04-13 04:46:00 +00:00
|
|
|
self->modal = TRUE;
|
2020-04-13 04:43:19 +00:00
|
|
|
|
2020-04-13 04:46:00 +00:00
|
|
|
self->custom_item_names = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
|
|
|
|
self->store = gtk_list_store_new (NUM_COLUMNS,
|
2018-11-13 14:14:10 +00:00
|
|
|
G_TYPE_APP_INFO,
|
|
|
|
G_TYPE_STRING, /* name */
|
|
|
|
G_TYPE_STRING, /* label */
|
|
|
|
G_TYPE_ICON,
|
|
|
|
G_TYPE_BOOLEAN, /* separator */
|
|
|
|
G_TYPE_BOOLEAN); /* custom */
|
2020-04-13 04:46:00 +00:00
|
|
|
self->combobox = gtk_combo_box_new_with_model (GTK_TREE_MODEL (self->store));
|
|
|
|
gtk_widget_set_parent (self->combobox, GTK_WIDGET (self));
|
2018-11-13 14:14:10 +00:00
|
|
|
|
2020-04-13 04:46:00 +00:00
|
|
|
g_signal_connect (self->combobox, "changed",
|
2018-11-13 14:01:21 +00:00
|
|
|
G_CALLBACK (gtk_app_chooser_button_changed), self);
|
2010-11-24 17:45:42 +00:00
|
|
|
}
|
|
|
|
|
2010-12-01 11:12:03 +00:00
|
|
|
static gboolean
|
|
|
|
app_chooser_button_iter_from_custom_name (GtkAppChooserButton *self,
|
2020-07-24 18:40:36 +00:00
|
|
|
const char *name,
|
2011-09-10 05:40:05 +00:00
|
|
|
GtkTreeIter *set_me)
|
2010-12-01 11:12:03 +00:00
|
|
|
{
|
|
|
|
GtkTreeIter iter;
|
2020-07-24 18:40:36 +00:00
|
|
|
char *custom_name = NULL;
|
2010-12-01 11:12:03 +00:00
|
|
|
|
2020-04-13 04:46:00 +00:00
|
|
|
if (!gtk_tree_model_get_iter_first (GTK_TREE_MODEL (self->store), &iter))
|
2010-12-01 11:12:03 +00:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
do {
|
2020-04-13 04:46:00 +00:00
|
|
|
gtk_tree_model_get (GTK_TREE_MODEL (self->store), &iter,
|
2010-12-01 11:12:03 +00:00
|
|
|
COLUMN_NAME, &custom_name,
|
|
|
|
-1);
|
|
|
|
|
|
|
|
if (g_strcmp0 (custom_name, name) == 0)
|
|
|
|
{
|
|
|
|
g_free (custom_name);
|
|
|
|
*set_me = iter;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free (custom_name);
|
2020-04-13 04:46:00 +00:00
|
|
|
} while (gtk_tree_model_iter_next (GTK_TREE_MODEL (self->store), &iter));
|
2010-12-01 11:12:03 +00:00
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2010-11-25 16:17:45 +00:00
|
|
|
static void
|
2010-11-29 11:19:18 +00:00
|
|
|
real_insert_custom_item (GtkAppChooserButton *self,
|
2020-07-24 18:40:36 +00:00
|
|
|
const char *name,
|
|
|
|
const char *label,
|
2014-12-23 23:37:28 +00:00
|
|
|
GIcon *icon,
|
|
|
|
gboolean custom,
|
|
|
|
GtkTreeIter *iter)
|
2010-11-25 16:17:45 +00:00
|
|
|
{
|
2010-11-29 15:04:59 +00:00
|
|
|
if (custom)
|
|
|
|
{
|
2020-04-13 04:46:00 +00:00
|
|
|
if (g_hash_table_lookup (self->custom_item_names, name) != NULL)
|
2010-11-29 15:04:59 +00:00
|
|
|
{
|
|
|
|
g_warning ("Attempting to add custom item %s to GtkAppChooserButton, "
|
|
|
|
"when there's already an item with the same name", name);
|
|
|
|
return;
|
|
|
|
}
|
2010-11-25 16:17:45 +00:00
|
|
|
|
2020-04-13 04:46:00 +00:00
|
|
|
g_hash_table_insert (self->custom_item_names,
|
2010-11-29 15:04:59 +00:00
|
|
|
g_strdup (name), GINT_TO_POINTER (1));
|
|
|
|
}
|
2010-11-25 16:17:45 +00:00
|
|
|
|
2020-04-13 04:46:00 +00:00
|
|
|
gtk_list_store_set (self->store, iter,
|
2010-11-29 15:10:58 +00:00
|
|
|
COLUMN_NAME, name,
|
2010-11-29 15:04:59 +00:00
|
|
|
COLUMN_LABEL, label,
|
2010-11-29 15:10:58 +00:00
|
|
|
COLUMN_ICON, icon,
|
|
|
|
COLUMN_CUSTOM, custom,
|
|
|
|
COLUMN_SEPARATOR, FALSE,
|
|
|
|
-1);
|
2010-11-25 16:17:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-11-29 11:19:18 +00:00
|
|
|
real_insert_separator (GtkAppChooserButton *self,
|
2014-12-23 23:37:28 +00:00
|
|
|
gboolean custom,
|
|
|
|
GtkTreeIter *iter)
|
2010-11-25 16:17:45 +00:00
|
|
|
{
|
2020-04-13 04:46:00 +00:00
|
|
|
gtk_list_store_set (self->store, iter,
|
2014-12-23 23:37:28 +00:00
|
|
|
COLUMN_CUSTOM, custom,
|
|
|
|
COLUMN_SEPARATOR, TRUE,
|
|
|
|
-1);
|
2010-11-25 16:17:45 +00:00
|
|
|
}
|
|
|
|
|
2010-11-24 23:32:05 +00:00
|
|
|
/**
|
2010-11-29 11:19:18 +00:00
|
|
|
* gtk_app_chooser_button_new:
|
2010-11-24 23:32:05 +00:00
|
|
|
* @content_type: the content type to show applications for
|
|
|
|
*
|
2021-02-22 00:41:33 +00:00
|
|
|
* Creates a new `GtkAppChooserButton` for applications
|
2010-11-24 23:32:05 +00:00
|
|
|
* that can handle content of the given type.
|
|
|
|
*
|
2021-02-22 00:41:33 +00:00
|
|
|
* Returns: a newly created `GtkAppChooserButton`
|
2010-11-24 23:32:05 +00:00
|
|
|
*/
|
2010-11-24 17:45:42 +00:00
|
|
|
GtkWidget *
|
2020-07-24 18:40:36 +00:00
|
|
|
gtk_app_chooser_button_new (const char *content_type)
|
2010-11-24 17:45:42 +00:00
|
|
|
{
|
|
|
|
g_return_val_if_fail (content_type != NULL, NULL);
|
|
|
|
|
2010-11-29 11:19:18 +00:00
|
|
|
return g_object_new (GTK_TYPE_APP_CHOOSER_BUTTON,
|
2010-11-24 23:32:05 +00:00
|
|
|
"content-type", content_type,
|
|
|
|
NULL);
|
2010-11-24 17:45:42 +00:00
|
|
|
}
|
|
|
|
|
2010-11-24 23:32:05 +00:00
|
|
|
/**
|
2010-11-29 11:19:18 +00:00
|
|
|
* gtk_app_chooser_button_append_separator:
|
2021-02-22 00:41:33 +00:00
|
|
|
* @self: a `GtkAppChooserButton`
|
2010-11-24 23:32:05 +00:00
|
|
|
*
|
|
|
|
* Appends a separator to the list of applications that is shown
|
|
|
|
* in the popup.
|
|
|
|
*/
|
2010-11-24 17:45:42 +00:00
|
|
|
void
|
2010-11-29 11:19:18 +00:00
|
|
|
gtk_app_chooser_button_append_separator (GtkAppChooserButton *self)
|
2010-11-24 17:45:42 +00:00
|
|
|
{
|
|
|
|
GtkTreeIter iter;
|
|
|
|
|
2010-11-29 11:19:18 +00:00
|
|
|
g_return_if_fail (GTK_IS_APP_CHOOSER_BUTTON (self));
|
2010-11-24 17:45:42 +00:00
|
|
|
|
2020-04-13 04:46:00 +00:00
|
|
|
gtk_list_store_append (self->store, &iter);
|
2010-11-25 16:17:45 +00:00
|
|
|
real_insert_separator (self, TRUE, &iter);
|
2010-11-24 17:45:42 +00:00
|
|
|
}
|
|
|
|
|
2010-11-24 23:32:05 +00:00
|
|
|
/**
|
2010-11-29 11:19:18 +00:00
|
|
|
* gtk_app_chooser_button_append_custom_item:
|
2021-02-22 00:41:33 +00:00
|
|
|
* @self: a `GtkAppChooserButton`
|
2010-11-29 15:04:59 +00:00
|
|
|
* @name: the name of the custom item
|
2010-11-24 23:32:05 +00:00
|
|
|
* @label: the label for the custom item
|
|
|
|
* @icon: the icon for the custom item
|
|
|
|
*
|
|
|
|
* Appends a custom item to the list of applications that is shown
|
2021-02-22 00:41:33 +00:00
|
|
|
* in the popup.
|
|
|
|
*
|
|
|
|
* The item name must be unique per-widget. Clients can use the
|
|
|
|
* provided name as a detail for the
|
2021-02-25 23:22:25 +00:00
|
|
|
* [signal@Gtk.AppChooserButton::custom-item-activated] signal, to add a
|
2011-09-10 05:40:05 +00:00
|
|
|
* callback for the activation of a particular custom item in the list.
|
2021-02-22 00:41:33 +00:00
|
|
|
*
|
|
|
|
* See also [method@Gtk.AppChooserButton.append_separator].
|
2010-11-24 23:32:05 +00:00
|
|
|
*/
|
2010-11-24 17:45:42 +00:00
|
|
|
void
|
2010-11-29 15:04:59 +00:00
|
|
|
gtk_app_chooser_button_append_custom_item (GtkAppChooserButton *self,
|
2020-07-24 18:40:36 +00:00
|
|
|
const char *name,
|
|
|
|
const char *label,
|
2010-11-29 15:04:59 +00:00
|
|
|
GIcon *icon)
|
2010-11-24 17:45:42 +00:00
|
|
|
{
|
|
|
|
GtkTreeIter iter;
|
|
|
|
|
2010-11-29 11:19:18 +00:00
|
|
|
g_return_if_fail (GTK_IS_APP_CHOOSER_BUTTON (self));
|
2010-11-29 15:04:59 +00:00
|
|
|
g_return_if_fail (name != NULL);
|
2010-11-24 17:45:42 +00:00
|
|
|
|
2020-04-13 04:46:00 +00:00
|
|
|
gtk_list_store_append (self->store, &iter);
|
2010-11-29 15:04:59 +00:00
|
|
|
real_insert_custom_item (self, name, label, icon, TRUE, &iter);
|
2010-11-25 16:17:45 +00:00
|
|
|
}
|
|
|
|
|
2010-12-01 11:12:03 +00:00
|
|
|
/**
|
2011-02-09 04:14:46 +00:00
|
|
|
* gtk_app_chooser_button_set_active_custom_item:
|
2021-02-22 00:41:33 +00:00
|
|
|
* @self: a `GtkAppChooserButton`
|
2010-12-01 11:12:03 +00:00
|
|
|
* @name: the name of the custom item
|
|
|
|
*
|
2021-02-22 00:41:33 +00:00
|
|
|
* Selects a custom item.
|
2011-02-09 04:14:46 +00:00
|
|
|
*
|
2021-02-22 00:41:33 +00:00
|
|
|
* See [method@Gtk.AppChooserButton.append_custom_item].
|
|
|
|
*
|
|
|
|
* Use [method@Gtk.AppChooser.refresh] to bring the selection
|
2011-02-09 04:14:46 +00:00
|
|
|
* to its initial state.
|
2010-12-01 11:12:03 +00:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
gtk_app_chooser_button_set_active_custom_item (GtkAppChooserButton *self,
|
2020-07-24 18:40:36 +00:00
|
|
|
const char *name)
|
2010-12-01 11:12:03 +00:00
|
|
|
{
|
|
|
|
GtkTreeIter iter;
|
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_APP_CHOOSER_BUTTON (self));
|
|
|
|
g_return_if_fail (name != NULL);
|
|
|
|
|
2020-04-13 04:46:00 +00:00
|
|
|
if (!g_hash_table_contains (self->custom_item_names, name) ||
|
2010-12-01 11:12:03 +00:00
|
|
|
!app_chooser_button_iter_from_custom_name (self, name, &iter))
|
|
|
|
{
|
2014-12-23 23:37:28 +00:00
|
|
|
g_warning ("Can't find the item named %s in the app chooser.", name);
|
2010-12-01 11:12:03 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-04-13 04:46:00 +00:00
|
|
|
gtk_combo_box_set_active_iter (GTK_COMBO_BOX (self->combobox), &iter);
|
2010-12-01 11:12:03 +00:00
|
|
|
}
|
|
|
|
|
2010-11-29 11:25:52 +00:00
|
|
|
/**
|
2021-02-25 23:22:25 +00:00
|
|
|
* gtk_app_chooser_button_get_show_dialog_item: (attributes org.gtk.Method.get_property=show-dialog-item)
|
2021-02-22 00:41:33 +00:00
|
|
|
* @self: a `GtkAppChooserButton`
|
2010-11-29 11:25:52 +00:00
|
|
|
*
|
2021-02-22 00:41:33 +00:00
|
|
|
* Returns whether the dropdown menu shows an item
|
|
|
|
* for a `GtkAppChooserDialog`.
|
2010-11-29 11:25:52 +00:00
|
|
|
*
|
2021-02-22 00:41:33 +00:00
|
|
|
* Returns: the value of [property@Gtk.AppChooserButton:show-dialog-item]
|
2010-11-29 11:25:52 +00:00
|
|
|
*/
|
2010-11-25 16:17:45 +00:00
|
|
|
gboolean
|
2010-11-29 11:19:18 +00:00
|
|
|
gtk_app_chooser_button_get_show_dialog_item (GtkAppChooserButton *self)
|
2010-11-25 16:17:45 +00:00
|
|
|
{
|
2010-11-29 11:19:18 +00:00
|
|
|
g_return_val_if_fail (GTK_IS_APP_CHOOSER_BUTTON (self), FALSE);
|
2010-11-25 16:17:45 +00:00
|
|
|
|
2020-04-13 04:46:00 +00:00
|
|
|
return self->show_dialog_item;
|
2010-11-25 16:17:45 +00:00
|
|
|
}
|
|
|
|
|
2010-11-29 11:25:52 +00:00
|
|
|
/**
|
2021-02-25 23:22:25 +00:00
|
|
|
* gtk_app_chooser_button_set_show_dialog_item: (attributes org.gtk.Method.set_property=show-dialog-item)
|
2021-02-22 00:41:33 +00:00
|
|
|
* @self: a `GtkAppChooserButton`
|
|
|
|
* @setting: the new value for [property@Gtk.AppChooserButton:show-dialog-item]
|
2010-11-29 11:25:52 +00:00
|
|
|
*
|
|
|
|
* Sets whether the dropdown menu of this button should show an
|
2021-02-22 00:41:33 +00:00
|
|
|
* entry to trigger a `GtkAppChooserDialog`.
|
2010-11-29 11:25:52 +00:00
|
|
|
*/
|
2010-11-25 16:17:45 +00:00
|
|
|
void
|
2010-11-29 11:19:18 +00:00
|
|
|
gtk_app_chooser_button_set_show_dialog_item (GtkAppChooserButton *self,
|
2011-09-10 05:40:05 +00:00
|
|
|
gboolean setting)
|
2010-11-25 16:17:45 +00:00
|
|
|
{
|
2020-04-13 04:46:00 +00:00
|
|
|
if (self->show_dialog_item != setting)
|
2010-11-25 16:17:45 +00:00
|
|
|
{
|
2020-04-13 04:46:00 +00:00
|
|
|
self->show_dialog_item = setting;
|
2010-11-25 16:17:45 +00:00
|
|
|
|
2015-09-07 19:55:34 +00:00
|
|
|
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_SHOW_DIALOG_ITEM]);
|
2010-11-25 16:17:45 +00:00
|
|
|
|
|
|
|
gtk_app_chooser_refresh (GTK_APP_CHOOSER (self));
|
|
|
|
}
|
2010-11-24 17:45:42 +00:00
|
|
|
}
|
2011-01-25 00:25:08 +00:00
|
|
|
|
2011-09-10 05:40:05 +00:00
|
|
|
/**
|
2021-02-25 23:22:25 +00:00
|
|
|
* gtk_app_chooser_button_get_show_default_item: (attributes org.gtk.Method.get_property=show-default-item)
|
2021-02-22 00:41:33 +00:00
|
|
|
* @self: a `GtkAppChooserButton`
|
2011-09-10 05:40:05 +00:00
|
|
|
*
|
2021-02-22 00:41:33 +00:00
|
|
|
* Returns whether the dropdown menu should show the default
|
|
|
|
* application at the top.
|
2011-09-10 05:40:05 +00:00
|
|
|
*
|
2021-02-22 00:41:33 +00:00
|
|
|
* Returns: the value of [property@Gtk.AppChooserButton:show-default-item]
|
2011-09-10 05:40:05 +00:00
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gtk_app_chooser_button_get_show_default_item (GtkAppChooserButton *self)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GTK_IS_APP_CHOOSER_BUTTON (self), FALSE);
|
|
|
|
|
2020-04-13 04:46:00 +00:00
|
|
|
return self->show_default_item;
|
2011-09-10 05:40:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-02-25 23:22:25 +00:00
|
|
|
* gtk_app_chooser_button_set_show_default_item: (attributes org.gtk.Method.set_property=show-default-item)
|
2021-02-22 00:41:33 +00:00
|
|
|
* @self: a `GtkAppChooserButton`
|
|
|
|
* @setting: the new value for [property@Gtk.AppChooserButton:show-default-item]
|
2011-09-10 05:40:05 +00:00
|
|
|
*
|
|
|
|
* Sets whether the dropdown menu of this button should show the
|
|
|
|
* default application for the given content type at top.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gtk_app_chooser_button_set_show_default_item (GtkAppChooserButton *self,
|
|
|
|
gboolean setting)
|
|
|
|
{
|
2018-11-13 14:14:10 +00:00
|
|
|
g_return_if_fail (GTK_IS_APP_CHOOSER_BUTTON (self));
|
|
|
|
|
2020-04-13 04:46:00 +00:00
|
|
|
if (self->show_default_item != setting)
|
2011-09-10 05:40:05 +00:00
|
|
|
{
|
2020-04-13 04:46:00 +00:00
|
|
|
self->show_default_item = setting;
|
2011-09-10 05:40:05 +00:00
|
|
|
|
2015-09-07 19:55:34 +00:00
|
|
|
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_SHOW_DEFAULT_ITEM]);
|
2011-09-10 05:40:05 +00:00
|
|
|
|
|
|
|
gtk_app_chooser_refresh (GTK_APP_CHOOSER (self));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-25 00:25:08 +00:00
|
|
|
/**
|
2021-02-25 23:22:25 +00:00
|
|
|
* gtk_app_chooser_button_set_heading: (attributes org.gtk.Method.set_property=heading)
|
2021-02-22 00:41:33 +00:00
|
|
|
* @self: a `GtkAppChooserButton`
|
2011-01-25 00:25:08 +00:00
|
|
|
* @heading: a string containing Pango markup
|
|
|
|
*
|
|
|
|
* Sets the text to display at the top of the dialog.
|
2021-02-22 00:41:33 +00:00
|
|
|
*
|
2011-01-25 00:25:08 +00:00
|
|
|
* If the heading is not set, the dialog displays a default text.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gtk_app_chooser_button_set_heading (GtkAppChooserButton *self,
|
2020-07-24 18:40:36 +00:00
|
|
|
const char *heading)
|
2011-01-25 00:25:08 +00:00
|
|
|
{
|
|
|
|
g_return_if_fail (GTK_IS_APP_CHOOSER_BUTTON (self));
|
|
|
|
|
2020-04-13 04:46:00 +00:00
|
|
|
g_free (self->heading);
|
|
|
|
self->heading = g_strdup (heading);
|
2011-01-25 00:25:08 +00:00
|
|
|
|
2015-09-07 19:55:34 +00:00
|
|
|
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_HEADING]);
|
2011-01-25 00:25:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-02-25 23:22:25 +00:00
|
|
|
* gtk_app_chooser_button_get_heading: (attributes org.gtk.Method.get_property=heading)
|
2021-02-22 00:41:33 +00:00
|
|
|
* @self: a `GtkAppChooserButton`
|
2011-01-25 00:25:08 +00:00
|
|
|
*
|
|
|
|
* Returns the text to display at the top of the dialog.
|
|
|
|
*
|
2015-12-28 20:14:08 +00:00
|
|
|
* Returns: (nullable): the text to display at the top of the dialog,
|
2021-05-18 21:05:26 +00:00
|
|
|
* or %NULL, in which case a default text is displayed
|
2011-01-25 00:25:08 +00:00
|
|
|
*/
|
2020-07-24 18:40:36 +00:00
|
|
|
const char *
|
2011-01-25 00:25:08 +00:00
|
|
|
gtk_app_chooser_button_get_heading (GtkAppChooserButton *self)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GTK_IS_APP_CHOOSER_BUTTON (self), NULL);
|
|
|
|
|
2020-04-13 04:46:00 +00:00
|
|
|
return self->heading;
|
2011-01-25 00:25:08 +00:00
|
|
|
}
|
2020-04-13 04:43:19 +00:00
|
|
|
|
|
|
|
/**
|
2021-02-25 23:22:25 +00:00
|
|
|
* gtk_app_chooser_button_set_modal: (attributes org.gtk.Method.set_property=modal)
|
2021-02-22 00:41:33 +00:00
|
|
|
* @self: a `GtkAppChooserButton`
|
2020-04-13 04:43:19 +00:00
|
|
|
* @modal: %TRUE to make the dialog modal
|
|
|
|
*
|
|
|
|
* Sets whether the dialog should be modal.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gtk_app_chooser_button_set_modal (GtkAppChooserButton *self,
|
|
|
|
gboolean modal)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GTK_IS_APP_CHOOSER_BUTTON (self));
|
|
|
|
|
2020-04-13 04:46:00 +00:00
|
|
|
if (self->modal == modal)
|
2020-04-13 04:43:19 +00:00
|
|
|
return;
|
|
|
|
|
2020-04-13 04:46:00 +00:00
|
|
|
self->modal = modal;
|
2020-04-13 04:43:19 +00:00
|
|
|
|
|
|
|
g_object_notify (G_OBJECT (self), "modal");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-02-25 23:22:25 +00:00
|
|
|
* gtk_app_chooser_button_get_modal: (attributes org.gtk.Method.get_property=modal)
|
2021-02-22 00:41:33 +00:00
|
|
|
* @self: a `GtkAppChooserButton`
|
2020-04-13 04:43:19 +00:00
|
|
|
*
|
|
|
|
* Gets whether the dialog is modal.
|
|
|
|
*
|
|
|
|
* Returns: %TRUE if the dialog is modal
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gtk_app_chooser_button_get_modal (GtkAppChooserButton *self)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GTK_IS_APP_CHOOSER_BUTTON (self), FALSE);
|
|
|
|
|
2020-04-13 04:46:00 +00:00
|
|
|
return self->modal;
|
2020-04-13 04:43:19 +00:00
|
|
|
}
|
|
|
|
|