add a structure type PkDistroUpgradeObj so we can use it in the DistroUpgrade callback easily

This commit is contained in:
Richard Hughes 2008-08-20 12:11:46 +01:00
parent 9f86b37549
commit b510f03808
5 changed files with 215 additions and 10 deletions

View File

@ -39,6 +39,7 @@
#include <pk-common.h>
#include <pk-connection.h>
#include <pk-update-detail-obj.h>
#include <pk-distro-upgrade-obj.h>
#include "pk-tools-common.h"
@ -209,17 +210,14 @@ pk_console_transaction_cb (PkClient *client, const gchar *tid, const gchar *time
* pk_console_distro_upgrade_cb:
**/
static void
pk_console_distro_upgrade_cb (PkClient *client, PkUpdateStateEnum type, const gchar *name,
const gchar *summary, gpointer user_data)
pk_console_distro_upgrade_cb (PkClient *client, const PkDistroUpgradeObj *obj, gpointer user_data)
{
const gchar *type_text;
type_text = pk_update_state_enum_to_text (type);
if (awaiting_space) {
g_print ("\n");
}
g_print ("Distro : %s\n", name);
g_print (" type : %s\n", type_text);
g_print (" summary : %s\n", summary);
g_print ("Distro : %s\n", obj->name);
g_print (" type : %s\n", pk_update_state_enum_to_text (obj->state));
g_print (" summary : %s\n", obj->summary);
}
/**

View File

@ -33,6 +33,7 @@ libpackagekit_include_HEADERS = \
pk-package-list.h \
pk-update-detail-obj.h \
pk-update-detail-list.h \
pk-distro-upgrade-obj.h \
pk-details-obj.h \
pk-enum.h \
pk-bitfield.h \
@ -67,6 +68,8 @@ libpackagekit_la_SOURCES = \
pk-update-detail-obj.h \
pk-update-detail-list.c \
pk-update-detail-list.h \
pk-distro-upgrade-obj.c \
pk-distro-upgrade-obj.h \
pk-details-obj.c \
pk-details-obj.h \
pk-enum.c \

View File

@ -59,6 +59,7 @@
#include "pk-control.h"
#include "pk-update-detail-obj.h"
#include "pk-details-obj.h"
#include "pk-distro-upgrade-obj.h"
static void pk_client_class_init (PkClientClass *klass);
static void pk_client_init (PkClient *client);
@ -605,11 +606,14 @@ pk_client_distro_upgrade_cb (DBusGProxy *proxy, const gchar *type_text, const gc
const gchar *summary, PkClient *client)
{
PkUpdateStateEnum type;
PkDistroUpgradeObj *obj;
g_return_if_fail (PK_IS_CLIENT (client));
type = pk_update_state_enum_from_text (type_text);
obj = pk_distro_upgrade_obj_new_from_data (type, name, summary);
pk_debug ("emitting distro_upgrade %s, %s, %s", type_text, name, summary);
g_signal_emit (client, signals [PK_CLIENT_DISTRO_UPGRADE], 0, type, name, summary);
g_signal_emit (client, signals [PK_CLIENT_DISTRO_UPGRADE], 0, obj);
pk_distro_upgrade_obj_free (obj);
}
/**
@ -3520,8 +3524,8 @@ pk_client_class_init (PkClientClass *klass)
g_signal_new ("distro-upgrade",
G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (PkClientClass, distro_upgrade),
NULL, NULL, pk_marshal_VOID__UINT_STRING_STRING,
G_TYPE_NONE, 3, G_TYPE_UINT, G_TYPE_STRING, G_TYPE_STRING);
NULL, NULL, g_cclosure_marshal_VOID__POINTER,
G_TYPE_NONE, 1, G_TYPE_POINTER);
/**
* PkClient::update-detail:
* @client: the #PkClient instance that emitted the signal

View File

@ -0,0 +1,149 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
*
* Copyright (C) 2008 Richard Hughes <richard@hughsie.com>
*
* Licensed under the GNU General Public License Version 2
*
* 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 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/**
* SECTION:pk-update-detail-obj
* @short_description: Functionality to create an update detail struct
*/
#include "config.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <glib/gi18n.h>
#include <pk-enum.h>
#include "pk-debug.h"
#include "pk-common.h"
#include "pk-distro-upgrade-obj.h"
/**
* pk_distro_upgrade_obj_new:
*
* Creates a new #PkDistroUpgradeObj object with default values
*
* Return value: a new #PkDistroUpgradeObj object
**/
PkDistroUpgradeObj *
pk_distro_upgrade_obj_new (void)
{
PkDistroUpgradeObj *obj;
obj = g_new0 (PkDistroUpgradeObj, 1);
obj->name = NULL;
obj->summary = NULL;
obj->state = PK_DISTRO_UPGRADE_ENUM_UNKNOWN;
return obj;
}
/**
* pk_distro_upgrade_obj_new_from_data:
*
* Creates a new #PkDistroUpgradeObj object with values.
*
* Return value: a new #PkDistroUpgradeObj object
**/
PkDistroUpgradeObj *
pk_distro_upgrade_obj_new_from_data (PkUpdateStateEnum state, const gchar *name, const gchar *summary)
{
PkDistroUpgradeObj *obj = NULL;
/* create new object */
obj = pk_distro_upgrade_obj_new ();
obj->state = state;
obj->name = g_strdup (name);
obj->summary = g_strdup (summary);
return obj;
}
/**
* pk_distro_upgrade_obj_copy:
*
* Return value: a new #PkDistroUpgradeObj object
**/
PkDistroUpgradeObj *
pk_distro_upgrade_obj_copy (const PkDistroUpgradeObj *obj)
{
g_return_val_if_fail (obj != NULL, NULL);
return pk_distro_upgrade_obj_new_from_data (obj->state, obj->name, obj->summary);
}
/**
* pk_distro_upgrade_obj_free:
* @obj: the #PkDistroUpgradeObj object
*
* Return value: %TRUE if the #PkDistroUpgradeObj object was freed.
**/
gboolean
pk_distro_upgrade_obj_free (PkDistroUpgradeObj *obj)
{
if (obj == NULL) {
return FALSE;
}
g_free (obj->name);
g_free (obj->summary);
g_free (obj);
return TRUE;
}
/***************************************************************************
*** MAKE CHECK TESTS ***
***************************************************************************/
#ifdef PK_BUILD_TESTS
#include <libselftest.h>
void
libst_distro_upgrade (LibSelfTest *test)
{
gboolean ret;
PkDistroUpgradeObj *obj;
if (libst_start (test, "PkDistroUpgradeObj", CLASS_AUTO) == FALSE) {
return;
}
/************************************************************
**************** IDENT ******************
************************************************************/
/************************************************************/
libst_title (test, "get an upgrade object");
obj = pk_distro_upgrade_obj_new ();
if (obj != NULL) {
libst_success (test, NULL);
} else {
libst_failed (test, NULL);
}
/************************************************************/
libst_title (test, "test upgrade");
ret = pk_distro_upgrade_obj_free (obj);
if (ret) {
libst_success (test, NULL);
} else {
libst_failed (test, NULL);
}
libst_end (test);
}
#endif

View File

@ -0,0 +1,51 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
*
* Copyright (C) 2008 Richard Hughes <richard@hughsie.com>
*
* Licensed under the GNU General Public License Version 2
*
* 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 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef __PK_DISTRO_UPGRADE_H
#define __PK_DISTRO_UPGRADE_H
#include <glib-object.h>
#include <pk-enum.h>
G_BEGIN_DECLS
/**
* PkDistroUpgradeObj:
*
* Cached object to represent details about the update.
**/
typedef struct
{
PkUpdateStateEnum state;
gchar *name;
gchar *summary;
} PkDistroUpgradeObj;
PkDistroUpgradeObj *pk_distro_upgrade_obj_new (void);
PkDistroUpgradeObj *pk_distro_upgrade_obj_copy (const PkDistroUpgradeObj *obj);
PkDistroUpgradeObj *pk_distro_upgrade_obj_new_from_data (PkUpdateStateEnum state,
const gchar *name,
const gchar *summary);
gboolean pk_distro_upgrade_obj_free (PkDistroUpgradeObj *obj);
G_END_DECLS
#endif /* __PK_DISTRO_UPGRADE_H */