source tree cleanup

The lib/ directory was getting a bit out of hand, so this tries
to organize things a bit so it is easier going forward to locate
the code people want to patch.
This commit is contained in:
Christian Hergert
2017-09-28 16:17:56 -07:00
parent a71f05b885
commit c47822b26e
103 changed files with 304 additions and 328 deletions

View File

@ -0,0 +1,135 @@
/* sp-cell-renderer-percent.c
*
* Copyright (C) 2016 Christian Hergert <christian@hergert.me>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <glib/gi18n.h>
#include "widgets/sp-cell-renderer-percent.h"
typedef struct
{
gdouble percent;
} SpCellRendererPercentPrivate;
enum {
PROP_0,
PROP_PERCENT,
N_PROPS
};
G_DEFINE_TYPE_WITH_PRIVATE (SpCellRendererPercent, sp_cell_renderer_percent, GTK_TYPE_CELL_RENDERER_TEXT)
static GParamSpec *properties [N_PROPS];
static void
sp_cell_renderer_percent_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
SpCellRendererPercent *self = SP_CELL_RENDERER_PERCENT (object);
switch (prop_id)
{
case PROP_PERCENT:
g_value_set_double (value, sp_cell_renderer_percent_get_percent (self));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
}
static void
sp_cell_renderer_percent_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
SpCellRendererPercent *self = SP_CELL_RENDERER_PERCENT (object);
switch (prop_id)
{
case PROP_PERCENT:
sp_cell_renderer_percent_set_percent (self, g_value_get_double (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
}
static void
sp_cell_renderer_percent_class_init (SpCellRendererPercentClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->get_property = sp_cell_renderer_percent_get_property;
object_class->set_property = sp_cell_renderer_percent_set_property;
properties [PROP_PERCENT] =
g_param_spec_double ("percent",
"Percent",
"Percent",
0.0,
100.0,
0.0,
(G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS));
g_object_class_install_properties (object_class, N_PROPS, properties);
}
static void
sp_cell_renderer_percent_init (SpCellRendererPercent *self)
{
g_object_set (self, "xalign", 1.0f, NULL);
}
gdouble
sp_cell_renderer_percent_get_percent (SpCellRendererPercent *self)
{
SpCellRendererPercentPrivate *priv = sp_cell_renderer_percent_get_instance_private (self);
g_return_val_if_fail (SP_IS_CELL_RENDERER_PERCENT (self), 0.0);
return priv->percent;
}
void
sp_cell_renderer_percent_set_percent (SpCellRendererPercent *self,
gdouble percent)
{
SpCellRendererPercentPrivate *priv = sp_cell_renderer_percent_get_instance_private (self);
g_return_if_fail (SP_IS_CELL_RENDERER_PERCENT (self));
g_return_if_fail (percent >= 0.0);
g_return_if_fail (percent <= 100.0);
if (percent != priv->percent)
{
gchar text[128];
priv->percent = percent;
g_snprintf (text, sizeof text, "%.2lf<span size='smaller'><span size='smaller'> </span>%%</span>", percent);
text [sizeof text - 1] = '\0';
g_object_set (self, "markup", text, NULL);
g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_PERCENT]);
}
}

View File

@ -0,0 +1,57 @@
/* sp-cell-renderer-percent.h
*
* Copyright (C) 2016 Christian Hergert <christian@hergert.me>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef SP_CELL_RENDERER_PERCENT_H
#define SP_CELL_RENDERER_PERCENT_H
#include <gtk/gtk.h>
G_BEGIN_DECLS
#define SP_TYPE_CELL_RENDERER_PERCENT (sp_cell_renderer_percent_get_type())
#define SP_CELL_RENDERER_PERCENT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SP_TYPE_CELL_RENDERER_PERCENT, SpCellRendererPercent))
#define SP_CELL_RENDERER_PERCENT_CONST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SP_TYPE_CELL_RENDERER_PERCENT, SpCellRendererPercent const))
#define SP_CELL_RENDERER_PERCENT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), SP_TYPE_CELL_RENDERER_PERCENT, SpCellRendererPercentClass))
#define SP_IS_CELL_RENDERER_PERCENT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SP_TYPE_CELL_RENDERER_PERCENT))
#define SP_IS_CELL_RENDERER_PERCENT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), SP_TYPE_CELL_RENDERER_PERCENT))
#define SP_CELL_RENDERER_PERCENT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), SP_TYPE_CELL_RENDERER_PERCENT, SpCellRendererPercentClass))
typedef struct _SpCellRendererPercent SpCellRendererPercent;
typedef struct _SpCellRendererPercentClass SpCellRendererPercentClass;
struct _SpCellRendererPercent
{
GtkCellRendererText parent;
};
struct _SpCellRendererPercentClass
{
GtkCellRendererTextClass parent_class;
gpointer padding[4];
};
GType sp_cell_renderer_percent_get_type (void);
GtkCellRenderer *sp_cell_renderer_percent_new (void);
gdouble sp_cell_renderer_percent_get_percent (SpCellRendererPercent *self);
void sp_cell_renderer_percent_set_percent (SpCellRendererPercent *self,
gdouble percent);
G_END_DECLS
#endif /* SP_CELL_RENDERER_PERCENT_H */

View File

@ -0,0 +1,205 @@
/* sp-empty-state-view.c
*
* Copyright (C) 2016 Christian Hergert <chergert@redhat.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#define G_LOG_DOMAIN "sp-empty-state-view"
#include <string.h>
#include "widgets/sp-empty-state-view.h"
typedef struct
{
GtkLabel *title;
GtkLabel *subtitle;
} SpEmptyStateViewPrivate;
G_DEFINE_TYPE_WITH_PRIVATE (SpEmptyStateView, sp_empty_state_view, GTK_TYPE_BIN)
enum {
PROP_0,
PROP_TITLE,
PROP_SUBTITLE,
N_PROPS
};
static GParamSpec *properties [N_PROPS];
GtkWidget *
sp_empty_state_view_new (void)
{
return g_object_new (SP_TYPE_EMPTY_STATE_VIEW, NULL);
}
static gboolean
sp_empty_state_view_action (GtkWidget *widget,
const gchar *prefix,
const gchar *action_name,
GVariant *parameter)
{
GtkWidget *toplevel;
GApplication *app;
GActionGroup *group = NULL;
g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
g_return_val_if_fail (prefix, FALSE);
g_return_val_if_fail (action_name, FALSE);
app = g_application_get_default ();
toplevel = gtk_widget_get_toplevel (widget);
while ((group == NULL) && (widget != NULL))
{
group = gtk_widget_get_action_group (widget, prefix);
widget = gtk_widget_get_parent (widget);
}
if (!group && g_str_equal (prefix, "win") && G_IS_ACTION_GROUP (toplevel))
group = G_ACTION_GROUP (toplevel);
if (!group && g_str_equal (prefix, "app") && G_IS_ACTION_GROUP (app))
group = G_ACTION_GROUP (app);
if (group && g_action_group_has_action (group, action_name))
{
g_action_group_activate_action (group, action_name, parameter);
return TRUE;
}
if (parameter && g_variant_is_floating (parameter))
{
parameter = g_variant_ref_sink (parameter);
g_variant_unref (parameter);
}
g_warning ("Failed to locate action %s.%s", prefix, action_name);
return FALSE;
}
static gboolean
sp_empty_state_view_activate_link (SpEmptyStateView *self,
const gchar *uri,
GtkLabel *label)
{
g_assert (SP_IS_EMPTY_STATE_VIEW (self));
g_assert (uri != NULL);
g_assert (GTK_IS_LABEL (label));
if (g_str_has_prefix (uri, "action://"))
{
g_autofree gchar *full_name = NULL;
g_autofree gchar *action_name = NULL;
g_autofree gchar *group_name = NULL;
g_autoptr(GVariant) param = NULL;
g_autoptr(GError) error = NULL;
uri += strlen ("action://");
if (g_action_parse_detailed_name (uri, &full_name, &param, &error))
{
const gchar *dot = strchr (full_name, '.');
if (param != NULL && g_variant_is_floating (param))
param = g_variant_ref_sink (param);
if (dot == NULL)
return FALSE;
group_name = g_strndup (full_name, dot - full_name);
action_name = g_strdup (++dot);
sp_empty_state_view_action (GTK_WIDGET (self),
group_name,
action_name,
param);
return TRUE;
}
else
g_warning ("%s", error->message);
}
return FALSE;
}
static void
sp_empty_state_view_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
SpEmptyStateView *self = SP_EMPTY_STATE_VIEW (object);
SpEmptyStateViewPrivate *priv = sp_empty_state_view_get_instance_private (self);
switch (prop_id)
{
case PROP_TITLE:
gtk_label_set_label (priv->title, g_value_get_string (value));
break;
case PROP_SUBTITLE:
gtk_label_set_label (priv->subtitle, g_value_get_string (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
}
static void
sp_empty_state_view_class_init (SpEmptyStateViewClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
object_class->set_property = sp_empty_state_view_set_property;
properties [PROP_TITLE] =
g_param_spec_string ("title",
NULL,
NULL,
NULL,
(G_PARAM_WRITABLE | G_PARAM_STATIC_STRINGS));
properties [PROP_SUBTITLE] =
g_param_spec_string ("subtitle",
NULL,
NULL,
NULL,
(G_PARAM_WRITABLE | G_PARAM_STATIC_STRINGS));
g_object_class_install_properties (object_class, N_PROPS, properties);
gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/sysprof/ui/sp-empty-state-view.ui");
gtk_widget_class_bind_template_child_private (widget_class, SpEmptyStateView, subtitle);
gtk_widget_class_bind_template_child_private (widget_class, SpEmptyStateView, title);
}
static void
sp_empty_state_view_init (SpEmptyStateView *self)
{
SpEmptyStateViewPrivate *priv = sp_empty_state_view_get_instance_private (self);
gtk_widget_init_template (GTK_WIDGET (self));
g_signal_connect_object (priv->subtitle,
"activate-link",
G_CALLBACK (sp_empty_state_view_activate_link),
self,
G_CONNECT_SWAPPED);
}

View File

@ -0,0 +1,42 @@
/* sp-empty-state-view.h
*
* Copyright (C) 2016 Christian Hergert <chergert@redhat.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef SP_EMPTY_STATE_VIEW_H
#define SP_EMPTY_STATE_VIEW_H
#include <gtk/gtk.h>
G_BEGIN_DECLS
#define SP_TYPE_EMPTY_STATE_VIEW (sp_empty_state_view_get_type())
G_DECLARE_DERIVABLE_TYPE (SpEmptyStateView, sp_empty_state_view, SP, EMPTY_STATE_VIEW, GtkBin)
struct _SpEmptyStateViewClass
{
GtkBinClass parent;
gpointer padding[4];
};
GtkWidget *sp_empty_state_view_new (void);
G_END_DECLS
#endif /* SP_EMPTY_STATE_VIEW_H */

View File

@ -0,0 +1,42 @@
/* sp-failed-state-view.c
*
* Copyright (C) 2016 Christian Hergert <chergert@redhat.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "widgets/sp-failed-state-view.h"
G_DEFINE_TYPE (SpFailedStateView, sp_failed_state_view, GTK_TYPE_BIN)
GtkWidget *
sp_failed_state_view_new (void)
{
return g_object_new (SP_TYPE_FAILED_STATE_VIEW, NULL);
}
static void
sp_failed_state_view_class_init (SpFailedStateViewClass *klass)
{
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
gtk_widget_class_set_template_from_resource (widget_class,
"/org/gnome/sysprof/ui/sp-failed-state-view.ui");
}
static void
sp_failed_state_view_init (SpFailedStateView *self)
{
gtk_widget_init_template (GTK_WIDGET (self));
}

View File

@ -0,0 +1,45 @@
/* sp-failed-state-view.h
*
* Copyright (C) 2016 Christian Hergert <chergert@redhat.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef SP_FAILED_STATE_VIEW_H
#define SP_FAILED_STATE_VIEW_H
#include <gtk/gtk.h>
#include "profiler/sp-profiler.h"
G_BEGIN_DECLS
#define SP_TYPE_FAILED_STATE_VIEW (sp_failed_state_view_get_type())
G_DECLARE_DERIVABLE_TYPE (SpFailedStateView, sp_failed_state_view, SP, FAILED_STATE_VIEW, GtkBin)
struct _SpFailedStateViewClass
{
GtkBinClass parent;
gpointer padding[4];
};
GtkWidget *sp_failed_state_view_new (void);
void sp_failed_state_view_set_profiler (SpFailedStateView *self,
SpProfiler *profiler);
G_END_DECLS
#endif /* SP_FAILED_STATE_VIEW_H */

1913
lib/widgets/sp-multi-paned.c Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,55 @@
/* sp-multi-paned.h
*
* Copyright (C) 2016 Christian Hergert <chergert@redhat.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* This program 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 Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef SP_MULTI_PANED_H
#define SP_MULTI_PANED_H
#include <gtk/gtk.h>
G_BEGIN_DECLS
#define SP_TYPE_MULTI_PANED (sp_multi_paned_get_type())
G_DECLARE_DERIVABLE_TYPE (SpMultiPaned, sp_multi_paned, SP, MULTI_PANED, GtkContainer)
struct _SpMultiPanedClass
{
GtkContainerClass parent;
void (*resize_drag_begin) (SpMultiPaned *self,
GtkWidget *child);
void (*resize_drag_end) (SpMultiPaned *self,
GtkWidget *child);
gpointer _reserved1;
gpointer _reserved2;
gpointer _reserved3;
gpointer _reserved4;
gpointer _reserved5;
gpointer _reserved6;
gpointer _reserved7;
gpointer _reserved8;
};
GtkWidget *sp_multi_paned_new (void);
guint sp_multi_paned_get_n_children (SpMultiPaned *self);
G_END_DECLS
#endif /* SP_MULTI_PANED_H */

View File

@ -0,0 +1,251 @@
/* sp-process-model-row.c
*
* Copyright (C) 2016 Christian Hergert <christian@hergert.me>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "widgets/sp-process-model-row.h"
typedef struct
{
SpProcessModelItem *item;
GtkLabel *args_label;
GtkLabel *label;
GtkLabel *pid;
GtkImage *image;
GtkImage *check;
} SpProcessModelRowPrivate;
G_DEFINE_TYPE_WITH_PRIVATE (SpProcessModelRow, sp_process_model_row, GTK_TYPE_LIST_BOX_ROW)
enum {
PROP_0,
PROP_ITEM,
PROP_SELECTED,
N_PROPS
};
static GParamSpec *properties [N_PROPS];
GtkWidget *
sp_process_model_row_new (SpProcessModelItem *item)
{
return g_object_new (SP_TYPE_PROCESS_MODEL_ROW,
"item", item,
NULL);
}
SpProcessModelItem *
sp_process_model_row_get_item (SpProcessModelRow *self)
{
SpProcessModelRowPrivate *priv = sp_process_model_row_get_instance_private (self);
g_return_val_if_fail (SP_IS_PROCESS_MODEL_ROW (self), NULL);
return priv->item;
}
static void
sp_process_model_row_set_item (SpProcessModelRow *self,
SpProcessModelItem *item)
{
SpProcessModelRowPrivate *priv = sp_process_model_row_get_instance_private (self);
g_assert (SP_IS_PROCESS_MODEL_ROW (self));
g_assert (SP_IS_PROCESS_MODEL_ITEM (item));
if (g_set_object (&priv->item, item))
{
const gchar *command_line;
g_auto(GStrv) parts = NULL;
g_autofree gchar *pidstr = NULL;
const gchar * const *argv;
GPid pid;
command_line = sp_process_model_item_get_command_line (item);
parts = g_strsplit (command_line ?: "", "\n", 0);
gtk_label_set_label (priv->label, parts [0]);
if ((NULL != (argv = sp_process_model_item_get_argv (item))) && (argv[0] != NULL))
{
g_autofree gchar *argvstr = g_strjoinv (" ", (gchar **)&argv[1]);
gtk_label_set_label (priv->args_label, argvstr);
}
pid = sp_process_model_item_get_pid (item);
pidstr = g_strdup_printf ("<small>%u</small>", pid);
gtk_label_set_label (priv->pid, pidstr);
gtk_label_set_use_markup (priv->pid, TRUE);
}
}
gboolean
sp_process_model_row_get_selected (SpProcessModelRow *self)
{
SpProcessModelRowPrivate *priv = sp_process_model_row_get_instance_private (self);
g_return_val_if_fail (SP_IS_PROCESS_MODEL_ROW (self), FALSE);
return gtk_widget_get_visible (GTK_WIDGET (priv->check));
}
void
sp_process_model_row_set_selected (SpProcessModelRow *self,
gboolean selected)
{
SpProcessModelRowPrivate *priv = sp_process_model_row_get_instance_private (self);
g_return_if_fail (SP_IS_PROCESS_MODEL_ROW (self));
selected = !!selected;
if (selected != sp_process_model_row_get_selected (self))
{
gtk_widget_set_visible (GTK_WIDGET (priv->check), selected);
g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_SELECTED]);
}
}
static gboolean
sp_process_model_row_query_tooltip (GtkWidget *widget,
gint x,
gint y,
gboolean keyboard_mode,
GtkTooltip *tooltip)
{
SpProcessModelRow *self = (SpProcessModelRow *)widget;
SpProcessModelRowPrivate *priv = sp_process_model_row_get_instance_private (self);
g_assert (SP_IS_PROCESS_MODEL_ROW (self));
g_assert (GTK_IS_TOOLTIP (tooltip));
if (priv->item != NULL)
{
const gchar * const *argv = sp_process_model_item_get_argv (priv->item);
if (argv != NULL)
{
g_autofree gchar *str = g_strjoinv (" ", (gchar **)argv);
gtk_tooltip_set_text (tooltip, str);
return TRUE;
}
}
return FALSE;
}
static void
sp_process_model_row_finalize (GObject *object)
{
SpProcessModelRow *self = (SpProcessModelRow *)object;
SpProcessModelRowPrivate *priv = sp_process_model_row_get_instance_private (self);
g_clear_object (&priv->item);
G_OBJECT_CLASS (sp_process_model_row_parent_class)->finalize (object);
}
static void
sp_process_model_row_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
SpProcessModelRow *self = SP_PROCESS_MODEL_ROW (object);
switch (prop_id)
{
case PROP_ITEM:
g_value_set_object (value, sp_process_model_row_get_item (self));
break;
case PROP_SELECTED:
g_value_set_boolean (value, sp_process_model_row_get_selected (self));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
}
static void
sp_process_model_row_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
SpProcessModelRow *self = SP_PROCESS_MODEL_ROW (object);
switch (prop_id)
{
case PROP_ITEM:
sp_process_model_row_set_item (self, g_value_get_object (value));
break;
case PROP_SELECTED:
sp_process_model_row_set_selected (self, g_value_get_boolean (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
}
static void
sp_process_model_row_class_init (SpProcessModelRowClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
object_class->finalize = sp_process_model_row_finalize;
object_class->get_property = sp_process_model_row_get_property;
object_class->set_property = sp_process_model_row_set_property;
widget_class->query_tooltip = sp_process_model_row_query_tooltip;
properties [PROP_ITEM] =
g_param_spec_object ("item",
"Item",
"Item",
SP_TYPE_PROCESS_MODEL_ITEM,
(G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
properties [PROP_SELECTED] =
g_param_spec_boolean ("selected",
"Selected",
"Selected",
FALSE,
(G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS));
g_object_class_install_properties (object_class, N_PROPS, properties);
gtk_widget_class_set_template_from_resource (widget_class,
"/org/gnome/sysprof/ui/sp-process-model-row.ui");
gtk_widget_class_bind_template_child_private (widget_class, SpProcessModelRow, args_label);
gtk_widget_class_bind_template_child_private (widget_class, SpProcessModelRow, image);
gtk_widget_class_bind_template_child_private (widget_class, SpProcessModelRow, label);
gtk_widget_class_bind_template_child_private (widget_class, SpProcessModelRow, pid);
gtk_widget_class_bind_template_child_private (widget_class, SpProcessModelRow, check);
}
static void
sp_process_model_row_init (SpProcessModelRow *self)
{
gtk_widget_init_template (GTK_WIDGET (self));
gtk_widget_set_has_tooltip (GTK_WIDGET (self), TRUE);
}

View File

@ -0,0 +1,48 @@
/* sp-process-model-row.h
*
* Copyright (C) 2016 Christian Hergert <christian@hergert.me>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef SP_PROCESS_MODEL_ROW_H
#define SP_PROCESS_MODEL_ROW_H
#include <gtk/gtk.h>
#include "util/sp-process-model-item.h"
G_BEGIN_DECLS
#define SP_TYPE_PROCESS_MODEL_ROW (sp_process_model_row_get_type())
G_DECLARE_DERIVABLE_TYPE (SpProcessModelRow, sp_process_model_row, SP, PROCESS_MODEL_ROW, GtkListBoxRow)
struct _SpProcessModelRowClass
{
GtkListBoxRowClass parent;
gpointer padding[4];
};
GtkWidget *sp_process_model_row_new (SpProcessModelItem *item);
SpProcessModelItem *sp_process_model_row_get_item (SpProcessModelRow *self);
gboolean sp_process_model_row_get_selected (SpProcessModelRow *self);
void sp_process_model_row_set_selected (SpProcessModelRow *self,
gboolean selected);
G_END_DECLS
#endif /* SP_PROCESS_MODEL_ROW_H */

View File

@ -0,0 +1,871 @@
/* sp-profiler-menu-button.c
*
* Copyright (C) 2016 Christian Hergert <christian@hergert.me>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <glib/gi18n.h>
#include <string.h>
#include "util/sp-model-filter.h"
#include "util/sp-process-model.h"
#include "util/sp-process-model-item.h"
#include "widgets/sp-process-model-row.h"
#include "widgets/sp-profiler-menu-button.h"
typedef struct
{
SpProfiler *profiler;
SpModelFilter *process_filter;
/* Gtk template widgets */
GtkTreeModel *environment_model;
GtkLabel *label;
GtkPopover *popover;
GtkEntry *process_filter_entry;
GtkListBox *process_list_box;
SpProcessModel *process_model;
GtkBox *processes_box;
GtkEntry *spawn_entry;
GtkStack *stack;
GtkSwitch *whole_system_switch;
GtkTreeView *env_tree_view;
GtkTreeViewColumn *env_key_column;
GtkTreeViewColumn *env_value_column;
GtkCellRenderer *key_cell;
GtkCellRenderer *value_cell;
GtkCheckButton *inherit_environ;
/* Property Bindings */
GBinding *inherit_binding;
GBinding *list_sensitive_binding;
GBinding *mutable_binding;
GBinding *whole_system_binding;
/* Signal handlers */
gulong notify_whole_system_handler;
/* GSources */
guint save_env_source;
} SpProfilerMenuButtonPrivate;
G_DEFINE_TYPE_WITH_PRIVATE (SpProfilerMenuButton, sp_profiler_menu_button, GTK_TYPE_MENU_BUTTON)
enum {
PROP_0,
PROP_PROFILER,
N_PROPS
};
static void sp_profiler_menu_button_env_row_changed (SpProfilerMenuButton *self,
GtkTreePath *tree_path,
GtkTreeIter *tree_iter,
gpointer user_data);
static void sp_profiler_menu_button_validate_spawn (SpProfilerMenuButton *self,
GtkEntry *entry);
static gboolean save_environ_to_gsettings (gpointer data);
static GParamSpec *properties [N_PROPS];
GtkWidget *
sp_profiler_menu_button_new (void)
{
return g_object_new (SP_TYPE_PROFILER_MENU_BUTTON, NULL);
}
static void
sp_profiler_menu_button_update_label (SpProfilerMenuButton *self)
{
SpProfilerMenuButtonPrivate *priv = sp_profiler_menu_button_get_instance_private (self);
g_autofree gchar *str = NULL;
const gchar *visible_child;
const GPid *pids;
guint n_pids = 0;
g_assert (SP_IS_PROFILER_MENU_BUTTON (self));
if (priv->profiler == NULL)
{
gtk_label_set_label (priv->label, "");
return;
}
visible_child = gtk_stack_get_visible_child_name (priv->stack);
if (g_strcmp0 (visible_child, "spawn") == 0)
{
const gchar *text;
text = gtk_entry_get_text (priv->spawn_entry);
if (text && *text)
gtk_label_set_label (priv->label, text);
else if (sp_profiler_get_whole_system (priv->profiler))
gtk_label_set_label (priv->label, _("All Processes"));
else
gtk_label_set_label (priv->label, _("New Process"));
sp_profiler_set_spawn (priv->profiler, text && *text);
return;
}
sp_profiler_set_spawn (priv->profiler, FALSE);
pids = sp_profiler_get_pids (priv->profiler, &n_pids);
if (n_pids == 0 || sp_profiler_get_whole_system (priv->profiler))
{
gtk_label_set_label (priv->label, _("All Processes"));
return;
}
if (n_pids == 1)
{
str = g_strdup_printf (_("Process %d"), pids[0]);
gtk_label_set_label (priv->label, str);
return;
}
str = g_strdup_printf (ngettext("%u Process", "%u Processes", n_pids), n_pids);
gtk_label_set_label (priv->label, str);
}
static void
clear_selected_flags (GtkWidget *widget,
gpointer user_data)
{
sp_process_model_row_set_selected (SP_PROCESS_MODEL_ROW (widget), FALSE);
}
static void
add_binding (GBinding **binding,
gpointer src,
const gchar *src_property,
gpointer dst,
const gchar *dst_property,
GBindingFlags flags)
{
g_assert (binding != NULL);
g_assert (*binding == NULL);
g_assert (src != NULL);
g_assert (src_property != NULL);
g_assert (dst != NULL);
g_assert (dst_property != NULL);
*binding = g_object_bind_property (src, src_property,
dst, dst_property,
flags);
g_object_add_weak_pointer (G_OBJECT (*binding), (gpointer *)binding);
}
static void
clear_binding (GBinding **binding)
{
g_assert (binding != NULL);
g_assert (!*binding || G_IS_BINDING (*binding));
if (*binding != NULL)
{
g_object_remove_weak_pointer (G_OBJECT (*binding), (gpointer *)binding);
g_binding_unbind (*binding);
*binding = NULL;
}
}
static void
sp_profiler_menu_button_connect (SpProfilerMenuButton *self)
{
SpProfilerMenuButtonPrivate *priv = sp_profiler_menu_button_get_instance_private (self);
g_assert (SP_IS_PROFILER_MENU_BUTTON (self));
g_assert (SP_IS_PROFILER (priv->profiler));
add_binding (&priv->mutable_binding,
priv->profiler, "is-mutable",
self, "sensitive",
G_BINDING_SYNC_CREATE);
add_binding (&priv->whole_system_binding,
priv->profiler, "whole-system",
priv->whole_system_switch, "active",
G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL);
add_binding (&priv->list_sensitive_binding,
priv->profiler, "whole-system",
priv->processes_box, "visible",
G_BINDING_SYNC_CREATE | G_BINDING_INVERT_BOOLEAN);
add_binding (&priv->inherit_binding,
priv->inherit_environ, "active",
priv->profiler, "spawn-inherit-environ",
G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL);
priv->notify_whole_system_handler =
g_signal_connect_object (priv->profiler,
"notify::whole-system",
G_CALLBACK (sp_profiler_menu_button_update_label),
self,
G_CONNECT_SWAPPED);
sp_profiler_menu_button_update_label (self);
sp_profiler_menu_button_validate_spawn (self, priv->spawn_entry);
sp_profiler_menu_button_env_row_changed (self, NULL, NULL, NULL);
}
static void
sp_profiler_menu_button_disconnect (SpProfilerMenuButton *self)
{
SpProfilerMenuButtonPrivate *priv = sp_profiler_menu_button_get_instance_private (self);
g_assert (SP_IS_PROFILER_MENU_BUTTON (self));
g_assert (SP_IS_PROFILER (priv->profiler));
clear_binding (&priv->mutable_binding);
clear_binding (&priv->whole_system_binding);
clear_binding (&priv->list_sensitive_binding);
clear_binding (&priv->inherit_binding);
if (priv->save_env_source != 0)
save_environ_to_gsettings (self);
g_signal_handler_disconnect (priv->profiler, priv->notify_whole_system_handler);
priv->notify_whole_system_handler = 0;
gtk_widget_set_sensitive (GTK_WIDGET (self), FALSE);
g_clear_object (&priv->profiler);
gtk_container_foreach (GTK_CONTAINER (priv->process_list_box),
clear_selected_flags,
NULL);
sp_profiler_menu_button_update_label (self);
}
/**
* sp_profiler_menu_button_get_profiler:
* @self: An #SpProfilerMenuButton
*
* Gets the profiler instance that is being configured.
*
* Returns: (nullable) (transfer none): An #SpProfiler or %NULL.
*/
SpProfiler *
sp_profiler_menu_button_get_profiler (SpProfilerMenuButton *self)
{
SpProfilerMenuButtonPrivate *priv = sp_profiler_menu_button_get_instance_private (self);
g_return_val_if_fail (SP_IS_PROFILER_MENU_BUTTON (self), NULL);
return priv->profiler;
}
void
sp_profiler_menu_button_set_profiler (SpProfilerMenuButton *self,
SpProfiler *profiler)
{
SpProfilerMenuButtonPrivate *priv = sp_profiler_menu_button_get_instance_private (self);
g_return_if_fail (SP_IS_PROFILER_MENU_BUTTON (self));
g_return_if_fail (!profiler || SP_IS_PROFILER (profiler));
if (priv->profiler != profiler)
{
if (priv->profiler != NULL)
sp_profiler_menu_button_disconnect (self);
if (profiler != NULL)
{
priv->profiler = g_object_ref (profiler);
sp_profiler_menu_button_connect (self);
}
g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_PROFILER]);
}
}
static void
sp_profiler_menu_button_row_activated (SpProfilerMenuButton *self,
SpProcessModelRow *row,
GtkListBox *list_box)
{
SpProfilerMenuButtonPrivate *priv = sp_profiler_menu_button_get_instance_private (self);
gboolean selected;
g_assert (SP_IS_PROFILER_MENU_BUTTON (self));
g_assert (SP_IS_PROCESS_MODEL_ROW (row));
g_assert (GTK_IS_LIST_BOX (list_box));
selected = !sp_process_model_row_get_selected (row);
sp_process_model_row_set_selected (row, selected);
if (priv->profiler != NULL)
{
SpProcessModelItem *item = sp_process_model_row_get_item (row);
GPid pid = sp_process_model_item_get_pid (item);
if (selected)
sp_profiler_add_pid (priv->profiler, pid);
else
sp_profiler_remove_pid (priv->profiler, pid);
}
sp_profiler_menu_button_update_label (self);
}
static GtkWidget *
sp_profiler_menu_button_create_row (gpointer itemptr,
gpointer user_data)
{
SpProcessModelItem *item = itemptr;
SpProfilerMenuButton *self = user_data;
g_assert (SP_IS_PROCESS_MODEL_ITEM (item));
g_assert (SP_IS_PROFILER_MENU_BUTTON (self));
return g_object_new (SP_TYPE_PROCESS_MODEL_ROW,
"item", item,
"visible", TRUE,
NULL);
}
static void
sp_profiler_menu_button_clicked (GtkButton *button)
{
SpProfilerMenuButton *self = (SpProfilerMenuButton *)button;
SpProfilerMenuButtonPrivate *priv = sp_profiler_menu_button_get_instance_private (self);
g_assert (SP_IS_PROFILER_MENU_BUTTON (self));
sp_process_model_queue_reload (priv->process_model);
GTK_BUTTON_CLASS (sp_profiler_menu_button_parent_class)->clicked (button);
}
static void
sp_profiler_menu_button_filter_changed (SpProfilerMenuButton *self,
GtkEntry *entry)
{
SpProfilerMenuButtonPrivate *priv = sp_profiler_menu_button_get_instance_private (self);
g_assert (SP_IS_PROFILER_MENU_BUTTON (self));
g_assert (GTK_IS_ENTRY (entry));
sp_model_filter_invalidate (priv->process_filter);
}
static gboolean
sp_profiler_menu_button_filter_func (GObject *object,
gpointer user_data)
{
SpProfilerMenuButton *self = user_data;
SpProfilerMenuButtonPrivate *priv = sp_profiler_menu_button_get_instance_private (self);
const gchar *cmdline;
const gchar *text;
gboolean ret;
g_assert (SP_IS_PROFILER_MENU_BUTTON (self));
g_assert (SP_IS_PROCESS_MODEL_ITEM (object));
text = gtk_entry_get_text (priv->process_filter_entry);
if (!text || !*text)
return TRUE;
cmdline = sp_process_model_item_get_command_line (SP_PROCESS_MODEL_ITEM (object));
if (!cmdline)
return FALSE;
ret = (strstr (cmdline, text) != NULL);
return ret;
}
static void
sp_profiler_menu_button_constructed (GObject *object)
{
SpProfilerMenuButton *self = (SpProfilerMenuButton *)object;
SpProfilerMenuButtonPrivate *priv = sp_profiler_menu_button_get_instance_private (self);
g_assert (SP_IS_PROFILER_MENU_BUTTON (self));
priv->process_filter = sp_model_filter_new (G_LIST_MODEL (priv->process_model));
sp_model_filter_set_filter_func (priv->process_filter,
sp_profiler_menu_button_filter_func,
self, NULL);
gtk_list_box_bind_model (priv->process_list_box,
G_LIST_MODEL (priv->process_filter),
sp_profiler_menu_button_create_row,
self, NULL);
G_OBJECT_CLASS (sp_profiler_menu_button_parent_class)->constructed (object);
}
static void
sp_profiler_menu_button_realize (GtkWidget *widget)
{
SpProfilerMenuButton *self = (SpProfilerMenuButton *)widget;
SpProfilerMenuButtonPrivate *priv = sp_profiler_menu_button_get_instance_private (self);
g_autoptr(GSettings) settings = NULL;
g_auto(GStrv) env = NULL;
GTK_WIDGET_CLASS (sp_profiler_menu_button_parent_class)->realize (widget);
settings = g_settings_new ("org.gnome.sysprof2");
env = g_settings_get_strv (settings, "last-spawn-env");
g_settings_bind (settings, "last-spawn-argv",
priv->spawn_entry, "text",
G_SETTINGS_BIND_DEFAULT);
g_settings_bind (settings, "last-spawn-inherit-env",
priv->inherit_environ, "active",
G_SETTINGS_BIND_DEFAULT);
if (env)
{
GtkTreeModel *model;
GtkTreeIter iter;
guint i;
model = gtk_tree_view_get_model (priv->env_tree_view);
gtk_list_store_clear (GTK_LIST_STORE (model));
for (i = 0; env [i]; i++)
{
const gchar *key = env [i];
const gchar *value = NULL;
gchar *eq = strchr (env[i], '=');
if (eq)
{
*eq = '\0';
value = eq + 1;
}
gtk_list_store_append (GTK_LIST_STORE (model), &iter);
gtk_list_store_set (GTK_LIST_STORE (model), &iter,
0, key,
1, value,
-1);
}
gtk_list_store_append (GTK_LIST_STORE (model), &iter);
}
}
static gboolean
save_environ_to_gsettings (gpointer data)
{
SpProfilerMenuButton *self = data;
SpProfilerMenuButtonPrivate *priv = sp_profiler_menu_button_get_instance_private (self);
g_autoptr(GPtrArray) ar = NULL;
g_autoptr(GSettings) settings = NULL;
GtkTreeIter iter;
g_assert (SP_IS_PROFILER_MENU_BUTTON (self));
priv->save_env_source = 0;
settings = g_settings_new ("org.gnome.sysprof2");
ar = g_ptr_array_new_with_free_func (g_free);
if (gtk_tree_model_get_iter_first (priv->environment_model, &iter))
{
do
{
g_autofree gchar *key = NULL;
g_autofree gchar *value = NULL;
gtk_tree_model_get (priv->environment_model, &iter,
0, &key,
1, &value,
-1);
if (!key || !*key)
continue;
g_ptr_array_add (ar, g_strdup_printf ("%s=%s", key, value ? value : ""));
}
while (gtk_tree_model_iter_next (priv->environment_model, &iter));
}
g_ptr_array_add (ar, NULL);
g_settings_set_strv (settings, "last-spawn-env", (const gchar * const *)ar->pdata);
return G_SOURCE_REMOVE;
}
static void
sp_profiler_menu_button_destroy (GtkWidget *widget)
{
SpProfilerMenuButton *self = (SpProfilerMenuButton *)widget;
SpProfilerMenuButtonPrivate *priv = sp_profiler_menu_button_get_instance_private (self);
if (priv->profiler != NULL)
{
sp_profiler_menu_button_disconnect (self);
g_clear_object (&priv->profiler);
}
g_clear_object (&priv->process_filter);
GTK_WIDGET_CLASS (sp_profiler_menu_button_parent_class)->destroy (widget);
}
static void
sp_profiler_menu_button_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
SpProfilerMenuButton *self = SP_PROFILER_MENU_BUTTON (object);
switch (prop_id)
{
case PROP_PROFILER:
g_value_set_object (value, sp_profiler_menu_button_get_profiler (self));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
}
static void
sp_profiler_menu_button_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
SpProfilerMenuButton *self = SP_PROFILER_MENU_BUTTON (object);
switch (prop_id)
{
case PROP_PROFILER:
sp_profiler_menu_button_set_profiler (self, g_value_get_object (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
}
static void
sp_profiler_menu_button_class_init (SpProfilerMenuButtonClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
GtkButtonClass *button_class = GTK_BUTTON_CLASS (klass);
object_class->constructed = sp_profiler_menu_button_constructed;
object_class->get_property = sp_profiler_menu_button_get_property;
object_class->set_property = sp_profiler_menu_button_set_property;
widget_class->destroy = sp_profiler_menu_button_destroy;
widget_class->realize = sp_profiler_menu_button_realize;
button_class->clicked = sp_profiler_menu_button_clicked;
properties [PROP_PROFILER] =
g_param_spec_object ("profiler",
"Profiler",
"Profiler",
SP_TYPE_PROFILER,
(G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS));
g_object_class_install_properties (object_class, N_PROPS, properties);
gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/sysprof/ui/sp-profiler-menu-button.ui");
gtk_widget_class_bind_template_child_private (widget_class, SpProfilerMenuButton, env_key_column);
gtk_widget_class_bind_template_child_private (widget_class, SpProfilerMenuButton, env_tree_view);
gtk_widget_class_bind_template_child_private (widget_class, SpProfilerMenuButton, env_value_column);
gtk_widget_class_bind_template_child_private (widget_class, SpProfilerMenuButton, environment_model);
gtk_widget_class_bind_template_child_private (widget_class, SpProfilerMenuButton, inherit_environ);
gtk_widget_class_bind_template_child_private (widget_class, SpProfilerMenuButton, key_cell);
gtk_widget_class_bind_template_child_private (widget_class, SpProfilerMenuButton, label);
gtk_widget_class_bind_template_child_private (widget_class, SpProfilerMenuButton, popover);
gtk_widget_class_bind_template_child_private (widget_class, SpProfilerMenuButton, process_filter_entry);
gtk_widget_class_bind_template_child_private (widget_class, SpProfilerMenuButton, process_list_box);
gtk_widget_class_bind_template_child_private (widget_class, SpProfilerMenuButton, process_model);
gtk_widget_class_bind_template_child_private (widget_class, SpProfilerMenuButton, processes_box);
gtk_widget_class_bind_template_child_private (widget_class, SpProfilerMenuButton, spawn_entry);
gtk_widget_class_bind_template_child_private (widget_class, SpProfilerMenuButton, stack);
gtk_widget_class_bind_template_child_private (widget_class, SpProfilerMenuButton, value_cell);
gtk_widget_class_bind_template_child_private (widget_class, SpProfilerMenuButton, whole_system_switch);
}
static void
sp_profiler_menu_button_env_row_changed (SpProfilerMenuButton *self,
GtkTreePath *tree_path,
GtkTreeIter *tree_iter,
gpointer user_data)
{
SpProfilerMenuButtonPrivate *priv = sp_profiler_menu_button_get_instance_private (self);
g_autoptr(GPtrArray) env = NULL;
GtkTreeModel *model;
GtkTreeIter iter;
g_assert (SP_IS_PROFILER_MENU_BUTTON (self));
/* queue saving settings to gsettings */
if (priv->save_env_source)
g_source_remove (priv->save_env_source);
priv->save_env_source = g_timeout_add_seconds (1, save_environ_to_gsettings, self);
/* sync the environ to the profiler */
env = g_ptr_array_new_with_free_func (g_free);
model = gtk_tree_view_get_model (priv->env_tree_view);
if (gtk_tree_model_get_iter_first (model, &iter))
{
do
{
g_autofree gchar *key = NULL;
g_autofree gchar *value = NULL;
gtk_tree_model_get (model, &iter,
0, &key,
1, &value,
-1);
if (key && *key)
g_ptr_array_add (env, g_strdup_printf ("%s=%s", key, value));
}
while (gtk_tree_model_iter_next (model, &iter));
}
g_ptr_array_add (env, NULL);
sp_profiler_set_spawn_env (priv->profiler, (const gchar * const *)env->pdata);
}
static void
on_backspace (SpProfilerMenuButton *self,
GtkEntry *entry)
{
SpProfilerMenuButtonPrivate *priv = sp_profiler_menu_button_get_instance_private (self);
if (g_object_get_data (G_OBJECT (entry), "CELL_WAS_EMPTY"))
{
GtkTreeModel *model;
GtkTreeSelection *selection;
GtkTreeIter iter;
model = gtk_tree_view_get_model (priv->env_tree_view);
selection = gtk_tree_view_get_selection (priv->env_tree_view);
if (gtk_tree_selection_get_selected (selection, NULL, &iter))
{
gtk_cell_renderer_stop_editing (priv->key_cell, TRUE);
gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
}
}
else
g_object_set_data (G_OBJECT (entry), "CELL_WAS_EMPTY",
GINT_TO_POINTER (*gtk_entry_get_text (entry) == '\0'));
}
static void
sp_profiler_menu_button_env_key_editing_started (SpProfilerMenuButton *self,
GtkCellEditable *editable,
const gchar *path,
GtkCellRenderer *cell)
{
g_signal_connect_object (editable,
"backspace",
G_CALLBACK (on_backspace),
self,
G_CONNECT_AFTER | G_CONNECT_SWAPPED);
}
static void
sp_profiler_menu_button_env_key_edited (SpProfilerMenuButton *self,
const gchar *path,
const gchar *new_text,
GtkCellRendererText *cell)
{
SpProfilerMenuButtonPrivate *priv = sp_profiler_menu_button_get_instance_private (self);
GtkTreeModel *model;
GtkTreePath *tree_path;
GtkTreeIter iter;
g_assert (SP_IS_PROFILER_MENU_BUTTON (self));
g_assert (path != NULL);
g_assert (new_text != NULL);
g_assert (GTK_IS_CELL_RENDERER_TEXT (cell));
model = gtk_tree_view_get_model (priv->env_tree_view);
tree_path = gtk_tree_path_new_from_string (path);
if (gtk_tree_model_get_iter (model, &iter, tree_path))
{
gtk_list_store_set (GTK_LIST_STORE (model), &iter,
0, new_text,
-1);
if (!gtk_tree_model_iter_next (model, &iter))
gtk_list_store_append (GTK_LIST_STORE (model), &iter);
gtk_tree_view_set_cursor_on_cell (priv->env_tree_view,
tree_path,
priv->env_value_column,
priv->value_cell,
TRUE);
}
gtk_tree_path_free (tree_path);
}
static void
sp_profiler_menu_button_env_value_edited (SpProfilerMenuButton *self,
const gchar *path,
const gchar *new_text,
GtkCellRendererText *cell)
{
SpProfilerMenuButtonPrivate *priv = sp_profiler_menu_button_get_instance_private (self);
GtkTreeModel *model;
GtkTreePath *tree_path;
GtkTreeIter iter;
g_assert (SP_IS_PROFILER_MENU_BUTTON (self));
g_assert (path != NULL);
g_assert (new_text != NULL);
g_assert (GTK_IS_CELL_RENDERER_TEXT (cell));
model = gtk_tree_view_get_model (priv->env_tree_view);
tree_path = gtk_tree_path_new_from_string (path);
if (gtk_tree_model_get_iter (model, &iter, tree_path))
{
gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1, new_text,
-1);
if (!gtk_tree_model_iter_next (model, &iter))
gtk_list_store_append (GTK_LIST_STORE (model), &iter);
gtk_tree_path_next (tree_path);
gtk_tree_view_set_cursor_on_cell (priv->env_tree_view,
tree_path,
priv->env_key_column,
priv->key_cell,
TRUE);
}
gtk_tree_path_free (tree_path);
}
static void
sp_profiler_menu_button_validate_spawn (SpProfilerMenuButton *self,
GtkEntry *entry)
{
SpProfilerMenuButtonPrivate *priv = sp_profiler_menu_button_get_instance_private (self);
g_auto(GStrv) argv = NULL;
g_autoptr(GError) error = NULL;
const gchar *text;
gint argc;
g_assert (SP_IS_PROFILER_MENU_BUTTON (self));
g_assert (GTK_IS_ENTRY (entry));
text = gtk_entry_get_text (entry);
if (text && *text && !g_shell_parse_argv (text, &argc, &argv, &error))
{
sp_profiler_set_spawn_argv (priv->profiler, NULL);
g_object_set (entry,
"secondary-icon-name", "dialog-warning-symbolic",
"secondary-icon-tooltip-text", _("The command line arguments provided are invalid"),
NULL);
}
else
{
sp_profiler_set_spawn_argv (priv->profiler, (const gchar * const *)argv);
g_object_set (entry,
"secondary-icon-name", NULL,
"secondary-icon-tooltip-text", NULL,
NULL);
}
}
static void
sp_profiler_menu_button_init (SpProfilerMenuButton *self)
{
SpProfilerMenuButtonPrivate *priv = sp_profiler_menu_button_get_instance_private (self);
gtk_widget_init_template (GTK_WIDGET (self));
g_signal_connect_object (priv->process_filter_entry,
"changed",
G_CALLBACK (sp_profiler_menu_button_filter_changed),
self,
G_CONNECT_SWAPPED);
g_signal_connect_object (priv->spawn_entry,
"changed",
G_CALLBACK (sp_profiler_menu_button_update_label),
self,
G_CONNECT_SWAPPED);
g_signal_connect_object (priv->spawn_entry,
"changed",
G_CALLBACK (sp_profiler_menu_button_validate_spawn),
self,
G_CONNECT_SWAPPED);
g_signal_connect_object (priv->stack,
"notify::visible-child",
G_CALLBACK (sp_profiler_menu_button_update_label),
self,
G_CONNECT_SWAPPED);
g_signal_connect_object (priv->process_list_box,
"row-activated",
G_CALLBACK (sp_profiler_menu_button_row_activated),
self,
G_CONNECT_SWAPPED);
g_signal_connect_object (priv->key_cell,
"edited",
G_CALLBACK (sp_profiler_menu_button_env_key_edited),
self,
G_CONNECT_SWAPPED);
g_signal_connect_object (priv->value_cell,
"edited",
G_CALLBACK (sp_profiler_menu_button_env_value_edited),
self,
G_CONNECT_SWAPPED);
g_signal_connect_object (gtk_tree_view_get_model (priv->env_tree_view),
"row-changed",
G_CALLBACK (sp_profiler_menu_button_env_row_changed),
self,
G_CONNECT_SWAPPED);
g_signal_connect_object (priv->key_cell,
"editing-started",
G_CALLBACK (sp_profiler_menu_button_env_key_editing_started),
self,
G_CONNECT_SWAPPED);
gtk_widget_set_sensitive (GTK_WIDGET (self), FALSE);
}

View File

@ -0,0 +1,46 @@
/* sp-profiler-menu-button.h
*
* Copyright (C) 2016 Christian Hergert <christian@hergert.me>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef SP_PROFILER_MENU_BUTTON_H
#define SP_PROFILER_MENU_BUTTON_H
#include <gtk/gtk.h>
#include "profiler/sp-profiler.h"
G_BEGIN_DECLS
#define SP_TYPE_PROFILER_MENU_BUTTON (sp_profiler_menu_button_get_type())
G_DECLARE_DERIVABLE_TYPE (SpProfilerMenuButton, sp_profiler_menu_button, SP, PROFILER_MENU_BUTTON, GtkMenuButton)
struct _SpProfilerMenuButtonClass
{
GtkMenuButtonClass parent_class;
gpointer padding[8];
};
GtkWidget *sp_profiler_menu_button_new (void);
void sp_profiler_menu_button_set_profiler (SpProfilerMenuButton *self,
SpProfiler *profiler);
SpProfiler *sp_profiler_menu_button_get_profiler (SpProfilerMenuButton *self);
G_END_DECLS
#endif /* SP_PROFILER_MENU_BUTTON_H */

View File

@ -0,0 +1,193 @@
/* sp-recording-state-view.c
*
* Copyright (C) 2016 Christian Hergert <chergert@redhat.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "widgets/sp-recording-state-view.h"
typedef struct
{
SpProfiler *profiler;
gulong notify_elapsed_handler;
GtkLabel *elapsed;
} SpRecordingStateViewPrivate;
G_DEFINE_TYPE_WITH_PRIVATE (SpRecordingStateView, sp_recording_state_view, GTK_TYPE_BIN)
enum {
PROP_0,
PROP_PROFILER,
N_PROPS
};
static GParamSpec *properties [N_PROPS];
GtkWidget *
sp_recording_state_view_new (void)
{
return g_object_new (SP_TYPE_RECORDING_STATE_VIEW, NULL);
}
static void
sp_recording_state_view_notify_elapsed (SpRecordingStateView *self,
GParamSpec *pspec,
SpProfiler *profiler)
{
SpRecordingStateViewPrivate *priv = sp_recording_state_view_get_instance_private (self);
g_autofree gchar *str = NULL;
gint64 elapsed;
guint hours;
guint minutes;
guint seconds;
g_assert (SP_IS_RECORDING_STATE_VIEW (self));
g_assert (SP_IS_PROFILER (profiler));
elapsed = (gint64)sp_profiler_get_elapsed (profiler);
hours = elapsed / (60 * 60);
if (hours > 0)
minutes = (elapsed % (hours * 60 * 60)) / 60;
else
minutes = elapsed / 60;
seconds = elapsed % 60;
if (hours == 0)
str = g_strdup_printf ("%02u:%02u", minutes, seconds);
else
str = g_strdup_printf ("%02u:%02u:%02u", hours, minutes, seconds);
gtk_label_set_label (priv->elapsed, str);
}
static void
sp_recording_state_view_destroy (GtkWidget *widget)
{
SpRecordingStateView *self = (SpRecordingStateView *)widget;
SpRecordingStateViewPrivate *priv = sp_recording_state_view_get_instance_private (self);
if (priv->profiler != NULL)
{
g_signal_handler_disconnect (priv->profiler, priv->notify_elapsed_handler);
g_clear_object (&priv->profiler);
}
GTK_WIDGET_CLASS (sp_recording_state_view_parent_class)->destroy (widget);
}
static void
sp_recording_state_view_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
SpRecordingStateView *self = SP_RECORDING_STATE_VIEW (object);
SpRecordingStateViewPrivate *priv = sp_recording_state_view_get_instance_private (self);
switch (prop_id)
{
case PROP_PROFILER:
g_value_set_object (value, priv->profiler);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
}
static void
sp_recording_state_view_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
SpRecordingStateView *self = SP_RECORDING_STATE_VIEW (object);
switch (prop_id)
{
case PROP_PROFILER:
sp_recording_state_view_set_profiler (self, g_value_get_object (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
}
static void
sp_recording_state_view_class_init (SpRecordingStateViewClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
object_class->get_property = sp_recording_state_view_get_property;
object_class->set_property = sp_recording_state_view_set_property;
widget_class->destroy = sp_recording_state_view_destroy;
properties [PROP_PROFILER] =
g_param_spec_object ("profiler",
"Profiler",
"Profiler",
SP_TYPE_PROFILER,
(G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_install_properties (object_class, N_PROPS, properties);
gtk_widget_class_set_template_from_resource (widget_class,
"/org/gnome/sysprof/ui/sp-recording-state-view.ui");
gtk_widget_class_bind_template_child_private (widget_class, SpRecordingStateView, elapsed);
}
static void
sp_recording_state_view_init (SpRecordingStateView *self)
{
gtk_widget_init_template (GTK_WIDGET (self));
}
void
sp_recording_state_view_set_profiler (SpRecordingStateView *self,
SpProfiler *profiler)
{
SpRecordingStateViewPrivate *priv = sp_recording_state_view_get_instance_private (self);
g_assert (SP_IS_RECORDING_STATE_VIEW (self));
g_assert (!profiler || SP_IS_PROFILER (profiler));
gtk_label_set_label (priv->elapsed, "00:00");
if (profiler != priv->profiler)
{
if (priv->profiler != NULL)
{
g_signal_handler_disconnect (priv->profiler, priv->notify_elapsed_handler);
g_clear_object (&priv->profiler);
}
gtk_label_set_label (priv->elapsed, "00:00");
if (profiler != NULL)
{
priv->profiler = g_object_ref (profiler);
priv->notify_elapsed_handler =
g_signal_connect_object (profiler,
"notify::elapsed",
G_CALLBACK (sp_recording_state_view_notify_elapsed),
self,
G_CONNECT_SWAPPED);
}
}
}

View File

@ -0,0 +1,45 @@
/* sp-recording-state-view.h
*
* Copyright (C) 2016 Christian Hergert <chergert@redhat.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef SP_RECORDING_STATE_VIEW_H
#define SP_RECORDING_STATE_VIEW_H
#include <gtk/gtk.h>
#include "profiler/sp-profiler.h"
G_BEGIN_DECLS
#define SP_TYPE_RECORDING_STATE_VIEW (sp_recording_state_view_get_type())
G_DECLARE_DERIVABLE_TYPE (SpRecordingStateView, sp_recording_state_view, SP, RECORDING_STATE_VIEW, GtkBin)
struct _SpRecordingStateViewClass
{
GtkBinClass parent;
gpointer padding[4];
};
GtkWidget *sp_recording_state_view_new (void);
void sp_recording_state_view_set_profiler (SpRecordingStateView *self,
SpProfiler *profiler);
G_END_DECLS
#endif /* SP_RECORDING_STATE_VIEW_H */