コード例 #1
0
/**
 * gpk_log_add_item
 **/
static void
gpk_log_add_item (PkTransactionPast *item)
{
	GtkTreeIter iter;
	gchar *details;
	gchar *date;
	gchar **date_part;
	const gchar *icon_name;
	const gchar *role_text;
	const gchar *username = NULL;
	const gchar *tool;
	static guint count;
	struct passwd *pw;
	gchar *tid;
	gchar *timespec;
	gboolean succeeded;
	guint duration;
	gchar *cmdline;
	guint uid;
	gchar *data;
	PkRoleEnum role;
	GtkTreeView *treeview = GTK_TREE_VIEW (gtk_builder_get_object (builder, "treeview_simple"));
	GtkTreeModel *model = gtk_tree_view_get_model (treeview);

	/* get data */
	g_object_get (item,
		      "role", &role,
		      "tid", &tid,
		      "timespec", &timespec,
		      "succeeded", &succeeded,
		      "duration", &duration,
		      "cmdline", &cmdline,
		      "uid", &uid,
		      "data", &data,
		      NULL);

	/* put formatted text into treeview */
	details = gpk_log_get_details_localised (timespec, data);
	date = gpk_log_get_localised_date (timespec);
	date_part = g_strsplit (date, ", ", 2);

	icon_name = gpk_role_enum_to_icon_name (role);
	role_text = gpk_role_enum_to_localised_past (role);

	/* query real name */
	pw = getpwuid(uid);
	if (pw != NULL) {
		if (pw->pw_gecos != NULL)
			username = pw->pw_gecos;
		else if (pw->pw_name != NULL)
			username = pw->pw_name;
	}

	/* get nice name for tool name */
	if (g_strcmp0 (cmdline, "pkcon") == 0)
		/* TRANSLATORS: short name for pkcon */
		tool = _("Command line client");
	else if (g_strcmp0 (cmdline, "gpk-application") == 0)
		/* TRANSLATORS: short name for gpk-update-viewer */
		tool = _("Add/Remove Software");
	else if (g_strcmp0 (cmdline, "gpk-update-viewer") == 0)
		/* TRANSLATORS: short name for gpk-update-viewer */
		tool = _("Update System");
	else if (g_strcmp0 (cmdline, "gpk-update-icon") == 0)
		/* TRANSLATORS: short name for gpk-update-icon */
		tool = _("Update Icon");
	else
		tool = cmdline;

	gpk_log_model_get_iter (model, &iter, tid);
	gtk_list_store_set (list_store, &iter,
			    GPK_LOG_COLUMN_ICON, icon_name,
			    GPK_LOG_COLUMN_TIMESPEC, timespec,
			    GPK_LOG_COLUMN_DATE_TEXT, date_part[1],
			    GPK_LOG_COLUMN_DATE, timespec,
			    GPK_LOG_COLUMN_ROLE, role_text,
			    GPK_LOG_COLUMN_DETAILS, details,
			    GPK_LOG_COLUMN_ID, tid,
			    GPK_LOG_COLUMN_USER, username,
			    GPK_LOG_COLUMN_TOOL, tool,
			    GPK_LOG_COLUMN_ACTIVE, TRUE, -1);

	/* spin the gui */
	if (count++ % 10 == 0)
		while (gtk_events_pending ())
			gtk_main_iteration ();

	g_strfreev (date_part);
	g_free (tid);
	g_free (timespec);
	g_free (cmdline);
	g_free (data);
	g_free (details);
	g_free (date);
}
コード例 #2
0
ファイル: gpk-log.c プロジェクト: nekohayo/gnome-packagekit
static void
gpk_log_add_item (PkTransactionPast *item)
{
	GtkTreeIter iter;
	g_autofree gchar *details = NULL;
	g_autofree gchar *date = NULL;
	const gchar *icon_name;
	const gchar *role_text;
	const gchar *username = NULL;
	const gchar *tool;
	static guint count;
	struct passwd *pw;
	g_autofree gchar *tid = NULL;
	g_autofree gchar *timespec = NULL;
	gboolean succeeded;
	guint duration;
	g_autofree gchar *cmdline = NULL;
	guint uid;
	g_autofree gchar *data = NULL;
	PkRoleEnum role;
	GtkTreeView *treeview = GTK_TREE_VIEW (gtk_builder_get_object (builder, "treeview_simple"));
	GtkTreeModel *model = gtk_tree_view_get_model (treeview);

	/* get data */
	g_object_get (item,
		      "role", &role,
		      "tid", &tid,
		      "timespec", &timespec,
		      "succeeded", &succeeded,
		      "duration", &duration,
		      "cmdline", &cmdline,
		      "uid", &uid,
		      "data", &data,
		      NULL);

	/* put formatted text into treeview */
	details = gpk_log_get_details_localised (timespec, data);
	date = gpk_log_get_localised_date (timespec);

	icon_name = gpk_role_enum_to_icon_name (role);
	role_text = gpk_role_enum_to_localised_past (role);

	/* query real name */
	pw = getpwuid(uid);
	if (pw != NULL) {
		if (pw->pw_gecos != NULL)
			username = pw->pw_gecos;
		else if (pw->pw_name != NULL)
			username = pw->pw_name;
	}

	/* get nice name for tool name */
	if (strstr (cmdline, "pkcon") != NULL)
		/* TRANSLATORS: user-friendly name for pkcon */
		tool = _("Command line client");
	else if (strstr (cmdline, "gpk-application") != NULL)
		/* TRANSLATORS: user-friendly name for gpk-update-viewer */
		tool = _("GNOME Packages");
	else if (strstr (cmdline, "gpk-update-viewer") != NULL)
		/* TRANSLATORS: user-friendly name for gpk-update-viewer */
		tool = _("GNOME Package Updater");
	else if (strstr (cmdline, "gpk-update-icon") != NULL)
		/* TRANSLATORS: user-friendly name for gpk-update-icon, which used to exist */
		tool = _("Update Icon");
	else if (strstr (cmdline, "pk-command-not-found") != NULL)
		/* TRANSLATORS: user-friendly name for the command not found plugin */
		tool = _("Bash – Command Not Found");
	else if (strstr (cmdline, "gnome-settings-daemon") != NULL)
		/* TRANSLATORS: user-friendly name for gnome-settings-daemon, which used to handle updates */
		tool = _("GNOME Session");
	else if (strstr (cmdline, "gnome-software") != NULL)
		/* TRANSLATORS: user-friendly name for gnome-software */
		tool = _("GNOME Software");
	else
		tool = cmdline;

	gpk_log_model_get_iter (model, &iter, tid);
	gtk_list_store_set (list_store, &iter,
			    GPK_LOG_COLUMN_ICON, icon_name,
			    GPK_LOG_COLUMN_TIMESPEC, timespec,
			    GPK_LOG_COLUMN_DATE_TEXT, date,
			    GPK_LOG_COLUMN_DATE, timespec,
			    GPK_LOG_COLUMN_ROLE, role_text,
			    GPK_LOG_COLUMN_DETAILS, details,
			    GPK_LOG_COLUMN_ID, tid,
			    GPK_LOG_COLUMN_USER, username,
			    GPK_LOG_COLUMN_TOOL, tool,
			    GPK_LOG_COLUMN_ACTIVE, TRUE, -1);

	/* spin the gui */
	if (count++ % 10 == 0)
		while (gtk_events_pending ())
			gtk_main_iteration ();
}