2007-08-23 14:54:35 -07:00
|
|
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
|
|
|
|
*
|
|
|
|
* Copyright (C) 2007 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <glib/gi18n.h>
|
|
|
|
|
|
|
|
#include "pk-debug.h"
|
2007-09-07 09:06:05 -07:00
|
|
|
#include "pk-enum.h"
|
2007-08-23 14:54:35 -07:00
|
|
|
|
2007-08-24 09:28:03 -07:00
|
|
|
typedef struct {
|
|
|
|
guint value;
|
|
|
|
const gchar *string;
|
|
|
|
} PkTaskEnumMatch;
|
|
|
|
|
|
|
|
static PkTaskEnumMatch task_exit[] = {
|
2007-09-07 08:12:14 -07:00
|
|
|
{PK_EXIT_ENUM_UNKNOWN, "unknown"}, /* fall though value */
|
|
|
|
{PK_EXIT_ENUM_SUCCESS, "success"},
|
|
|
|
{PK_EXIT_ENUM_FAILED, "failed"},
|
|
|
|
{PK_EXIT_ENUM_CANCELED, "canceled"},
|
2007-08-24 09:28:03 -07:00
|
|
|
{0, NULL},
|
|
|
|
};
|
|
|
|
|
|
|
|
static PkTaskEnumMatch task_status[] = {
|
2007-09-07 08:12:14 -07:00
|
|
|
{PK_STATUS_ENUM_UNKNOWN, "unknown"}, /* fall though value */
|
|
|
|
{PK_STATUS_ENUM_SETUP, "setup"},
|
|
|
|
{PK_STATUS_ENUM_QUERY, "query"},
|
|
|
|
{PK_STATUS_ENUM_REFRESH_CACHE, "refresh-cache"},
|
|
|
|
{PK_STATUS_ENUM_REMOVE, "remove"},
|
|
|
|
{PK_STATUS_ENUM_DOWNLOAD, "download"},
|
|
|
|
{PK_STATUS_ENUM_INSTALL, "install"},
|
|
|
|
{PK_STATUS_ENUM_UPDATE, "update"},
|
2007-08-24 09:28:03 -07:00
|
|
|
{0, NULL},
|
|
|
|
};
|
|
|
|
|
2007-08-31 06:40:18 -07:00
|
|
|
static PkTaskEnumMatch task_role[] = {
|
2007-09-07 08:12:14 -07:00
|
|
|
{PK_ROLE_ENUM_UNKNOWN, "unknown"}, /* fall though value */
|
|
|
|
{PK_ROLE_ENUM_QUERY, "query"},
|
|
|
|
{PK_ROLE_ENUM_REFRESH_CACHE, "refresh-cache"},
|
|
|
|
{PK_ROLE_ENUM_PACKAGE_REMOVE, "package-remove"},
|
|
|
|
{PK_ROLE_ENUM_PACKAGE_INSTALL, "package-install"},
|
|
|
|
{PK_ROLE_ENUM_PACKAGE_UPDATE, "package-update"},
|
|
|
|
{PK_ROLE_ENUM_SYSTEM_UPDATE, "system-update"},
|
2007-08-31 06:40:18 -07:00
|
|
|
{0, NULL},
|
|
|
|
};
|
|
|
|
|
2007-08-24 09:28:03 -07:00
|
|
|
static PkTaskEnumMatch task_error[] = {
|
2007-09-07 10:09:40 -07:00
|
|
|
{PK_ERROR_ENUM_UNKNOWN, "unknown"}, /* fall though value */
|
|
|
|
{PK_ERROR_ENUM_OOM, "out-of-memory"},
|
2007-09-07 08:12:14 -07:00
|
|
|
{PK_ERROR_ENUM_NO_NETWORK, "no-network"},
|
2007-09-07 10:09:40 -07:00
|
|
|
{PK_ERROR_ENUM_NOT_SUPPORTED, "not-supported"},
|
|
|
|
{PK_ERROR_ENUM_INTERNAL_ERROR, "internal-error"},
|
|
|
|
{PK_ERROR_ENUM_GPG_FAILURE, "gpg-failure"},
|
|
|
|
{PK_ERROR_ENUM_FILTER_INVALID, "filter-invalid"},
|
2007-09-07 08:12:14 -07:00
|
|
|
{PK_ERROR_ENUM_PACKAGE_ID_INVALID, "package-id-invalid"},
|
|
|
|
{PK_ERROR_ENUM_TRANSACTION_ERROR, "transaction-error"},
|
|
|
|
{PK_ERROR_ENUM_PACKAGE_NOT_INSTALLED, "package-not-installed"},
|
|
|
|
{PK_ERROR_ENUM_PACKAGE_ALREADY_INSTALLED, "package-already-installed"},
|
|
|
|
{PK_ERROR_ENUM_PACKAGE_DOWNLOAD_FAILED, "package-download-failed"},
|
|
|
|
{PK_ERROR_ENUM_DEP_RESOLUTION_FAILED, "dep-resolution-failed"},
|
|
|
|
{PK_ERROR_ENUM_CREATE_THREAD_FAILED, "create-thread-failed"},
|
2007-08-24 09:28:03 -07:00
|
|
|
{0, NULL},
|
|
|
|
};
|
|
|
|
|
|
|
|
static PkTaskEnumMatch task_restart[] = {
|
2007-09-07 08:12:14 -07:00
|
|
|
{PK_RESTART_ENUM_NONE, "none"},
|
|
|
|
{PK_RESTART_ENUM_SYSTEM, "system"},
|
|
|
|
{PK_RESTART_ENUM_SESSION, "session"},
|
|
|
|
{PK_RESTART_ENUM_APPLICATION, "application"},
|
2007-08-24 09:28:03 -07:00
|
|
|
{0, NULL},
|
|
|
|
};
|
|
|
|
|
2007-08-27 09:43:53 -07:00
|
|
|
static PkTaskEnumMatch task_group[] = {
|
2007-09-07 08:12:14 -07:00
|
|
|
{PK_GROUP_ENUM_ACCESSIBILITY, "accessibility"},
|
|
|
|
{PK_GROUP_ENUM_ACCESSORIES, "accessories"},
|
|
|
|
{PK_GROUP_ENUM_EDUCATION, "education"},
|
|
|
|
{PK_GROUP_ENUM_GAMES, "games"},
|
|
|
|
{PK_GROUP_ENUM_GRAPHICS, "graphics"},
|
|
|
|
{PK_GROUP_ENUM_INTERNET, "internet"},
|
|
|
|
{PK_GROUP_ENUM_OFFICE, "office"},
|
|
|
|
{PK_GROUP_ENUM_OTHER, "other"},
|
|
|
|
{PK_GROUP_ENUM_PROGRAMMING, "programming"},
|
|
|
|
{PK_GROUP_ENUM_MULTIMEDIA, "multimedia"},
|
|
|
|
{PK_GROUP_ENUM_SYSTEM, "system"},
|
2007-08-27 09:43:53 -07:00
|
|
|
{0, NULL},
|
|
|
|
};
|
|
|
|
|
2007-08-28 11:27:56 -07:00
|
|
|
static PkTaskEnumMatch task_action[] = {
|
2007-09-07 08:12:14 -07:00
|
|
|
{PK_ACTION_ENUM_INSTALL, "install"},
|
|
|
|
{PK_ACTION_ENUM_REMOVE, "remove"},
|
|
|
|
{PK_ACTION_ENUM_UPDATE, "update"},
|
|
|
|
{PK_ACTION_ENUM_GET_UPDATES, "get-updates"},
|
|
|
|
{PK_ACTION_ENUM_REFRESH_CACHE, "refresh-cache"},
|
|
|
|
{PK_ACTION_ENUM_UPDATE_SYSTEM, "update-system"},
|
|
|
|
{PK_ACTION_ENUM_SEARCH_NAME, "search-name"},
|
|
|
|
{PK_ACTION_ENUM_SEARCH_DETAILS, "search-details"},
|
|
|
|
{PK_ACTION_ENUM_SEARCH_GROUP, "search-group"},
|
|
|
|
{PK_ACTION_ENUM_SEARCH_FILE, "search-file"},
|
|
|
|
{PK_ACTION_ENUM_GET_DEPENDS, "get-depends"},
|
|
|
|
{PK_ACTION_ENUM_GET_REQUIRES, "get-requires"},
|
|
|
|
{PK_ACTION_ENUM_GET_DESCRIPTION, "get-description"},
|
2007-08-28 11:27:56 -07:00
|
|
|
{0, NULL},
|
|
|
|
};
|
|
|
|
|
2007-08-23 14:54:35 -07:00
|
|
|
/**
|
2007-08-24 09:28:03 -07:00
|
|
|
* pk_task_enum_find_value:
|
2007-08-23 14:54:35 -07:00
|
|
|
*/
|
2007-08-24 09:28:03 -07:00
|
|
|
static guint
|
|
|
|
pk_task_enum_find_value (PkTaskEnumMatch *table, const gchar *string)
|
2007-08-23 14:54:35 -07:00
|
|
|
{
|
2007-08-24 09:28:03 -07:00
|
|
|
guint i;
|
|
|
|
const gchar *string_tmp;
|
|
|
|
|
|
|
|
/* return the first entry on non-found or error */
|
|
|
|
if (string == NULL) {
|
|
|
|
return table[0].value;
|
2007-08-23 14:54:35 -07:00
|
|
|
}
|
2007-08-24 09:28:03 -07:00
|
|
|
for (i=0;;i++) {
|
|
|
|
string_tmp = table[i].string;
|
|
|
|
if (string_tmp == NULL) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (strcmp (string, string_tmp) == 0) {
|
|
|
|
return table[i].value;
|
|
|
|
}
|
2007-08-23 14:54:35 -07:00
|
|
|
}
|
2007-08-24 09:28:03 -07:00
|
|
|
return table[0].value;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* pk_task_enum_find_string:
|
|
|
|
*/
|
|
|
|
static const gchar *
|
|
|
|
pk_task_enum_find_string (PkTaskEnumMatch *table, guint value)
|
|
|
|
{
|
|
|
|
guint i;
|
|
|
|
guint tmp;
|
|
|
|
const gchar *string_tmp;
|
|
|
|
|
|
|
|
for (i=0;;i++) {
|
|
|
|
string_tmp = table[i].string;
|
|
|
|
if (string_tmp == NULL) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
tmp = table[i].value;
|
|
|
|
if (tmp == value) {
|
|
|
|
return table[i].string;
|
|
|
|
}
|
2007-08-23 14:54:35 -07:00
|
|
|
}
|
2007-08-24 09:28:03 -07:00
|
|
|
return table[0].string;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2007-09-07 08:16:09 -07:00
|
|
|
* pk_exit_enum_from_text:
|
2007-08-24 09:28:03 -07:00
|
|
|
*/
|
|
|
|
PkTaskExit
|
2007-09-07 08:16:09 -07:00
|
|
|
pk_exit_enum_from_text (const gchar *exit)
|
2007-08-24 09:28:03 -07:00
|
|
|
{
|
|
|
|
return pk_task_enum_find_value (task_exit, exit);
|
2007-08-23 14:54:35 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2007-09-07 08:16:09 -07:00
|
|
|
* pk_exit_enum_to_text:
|
2007-08-23 14:54:35 -07:00
|
|
|
**/
|
|
|
|
const gchar *
|
2007-09-07 08:16:09 -07:00
|
|
|
pk_exit_enum_to_text (PkTaskExit exit)
|
2007-08-23 14:54:35 -07:00
|
|
|
{
|
2007-08-24 09:28:03 -07:00
|
|
|
return pk_task_enum_find_string (task_exit, exit);
|
2007-08-23 14:54:35 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2007-09-07 08:16:09 -07:00
|
|
|
* pk_status_enum_from_text:
|
2007-08-23 14:54:35 -07:00
|
|
|
**/
|
|
|
|
PkTaskStatus
|
2007-09-07 08:16:09 -07:00
|
|
|
pk_status_enum_from_text (const gchar *status)
|
2007-08-23 14:54:35 -07:00
|
|
|
{
|
2007-08-24 09:28:03 -07:00
|
|
|
return pk_task_enum_find_value (task_status, status);
|
2007-08-23 14:54:35 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2007-09-07 08:16:09 -07:00
|
|
|
* pk_status_enum_to_text:
|
2007-08-23 14:54:35 -07:00
|
|
|
**/
|
|
|
|
const gchar *
|
2007-09-07 08:16:09 -07:00
|
|
|
pk_status_enum_to_text (PkTaskStatus status)
|
2007-08-23 14:54:35 -07:00
|
|
|
{
|
2007-08-24 09:28:03 -07:00
|
|
|
return pk_task_enum_find_string (task_status, status);
|
2007-08-23 14:54:35 -07:00
|
|
|
}
|
|
|
|
|
2007-08-31 06:40:18 -07:00
|
|
|
/**
|
2007-09-07 08:16:09 -07:00
|
|
|
* pk_role_enum_from_text:
|
2007-08-31 06:40:18 -07:00
|
|
|
**/
|
|
|
|
PkTaskRole
|
2007-09-07 08:16:09 -07:00
|
|
|
pk_role_enum_from_text (const gchar *role)
|
2007-08-31 06:40:18 -07:00
|
|
|
{
|
|
|
|
return pk_task_enum_find_value (task_role, role);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2007-09-07 08:16:09 -07:00
|
|
|
* pk_role_enum_to_text:
|
2007-08-31 06:40:18 -07:00
|
|
|
**/
|
|
|
|
const gchar *
|
2007-09-07 08:16:09 -07:00
|
|
|
pk_role_enum_to_text (PkTaskRole role)
|
2007-08-31 06:40:18 -07:00
|
|
|
{
|
|
|
|
return pk_task_enum_find_string (task_role, role);
|
|
|
|
}
|
|
|
|
|
2007-08-23 14:54:35 -07:00
|
|
|
/**
|
2007-09-07 08:16:09 -07:00
|
|
|
* pk_error_enum_from_text:
|
2007-08-23 14:54:35 -07:00
|
|
|
**/
|
|
|
|
PkTaskErrorCode
|
2007-09-07 08:16:09 -07:00
|
|
|
pk_error_enum_from_text (const gchar *code)
|
2007-08-23 14:54:35 -07:00
|
|
|
{
|
2007-08-24 09:28:03 -07:00
|
|
|
return pk_task_enum_find_value (task_error, code);
|
2007-08-23 14:54:35 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2007-09-07 08:16:09 -07:00
|
|
|
* pk_error_enum_to_text:
|
2007-08-23 14:54:35 -07:00
|
|
|
**/
|
|
|
|
const gchar *
|
2007-09-07 08:16:09 -07:00
|
|
|
pk_error_enum_to_text (PkTaskErrorCode code)
|
2007-08-23 14:54:35 -07:00
|
|
|
{
|
2007-08-24 09:28:03 -07:00
|
|
|
return pk_task_enum_find_string (task_error, code);
|
2007-08-23 14:54:35 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2007-09-07 08:16:09 -07:00
|
|
|
* pk_restart_enum_from_text:
|
2007-08-23 14:54:35 -07:00
|
|
|
**/
|
|
|
|
PkTaskRestart
|
2007-09-07 08:16:09 -07:00
|
|
|
pk_restart_enum_from_text (const gchar *restart)
|
2007-08-23 14:54:35 -07:00
|
|
|
{
|
2007-08-24 09:28:03 -07:00
|
|
|
return pk_task_enum_find_value (task_restart, restart);
|
2007-08-23 14:54:35 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2007-09-07 08:16:09 -07:00
|
|
|
* pk_restart_enum_to_text:
|
2007-08-23 14:54:35 -07:00
|
|
|
**/
|
|
|
|
const gchar *
|
2007-09-07 08:16:09 -07:00
|
|
|
pk_restart_enum_to_text (PkTaskRestart restart)
|
2007-08-23 14:54:35 -07:00
|
|
|
{
|
2007-08-24 09:28:03 -07:00
|
|
|
return pk_task_enum_find_string (task_restart, restart);
|
2007-08-23 14:54:35 -07:00
|
|
|
}
|
|
|
|
|
2007-08-27 09:43:53 -07:00
|
|
|
/**
|
2007-09-07 08:16:09 -07:00
|
|
|
* pk_group_enum_from_text:
|
2007-08-27 09:43:53 -07:00
|
|
|
**/
|
|
|
|
PkTaskGroup
|
2007-09-07 08:16:09 -07:00
|
|
|
pk_group_enum_from_text (const gchar *group)
|
2007-08-27 09:43:53 -07:00
|
|
|
{
|
|
|
|
return pk_task_enum_find_value (task_group, group);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2007-09-07 08:16:09 -07:00
|
|
|
* pk_group_enum_to_text:
|
2007-08-27 09:43:53 -07:00
|
|
|
**/
|
|
|
|
const gchar *
|
2007-09-07 08:16:09 -07:00
|
|
|
pk_group_enum_to_text (PkTaskGroup group)
|
2007-08-27 09:43:53 -07:00
|
|
|
{
|
|
|
|
return pk_task_enum_find_string (task_group, group);
|
|
|
|
}
|
|
|
|
|
2007-08-28 11:27:56 -07:00
|
|
|
/**
|
2007-09-07 08:16:09 -07:00
|
|
|
* pk_action_enum_from_text:
|
2007-08-28 11:27:56 -07:00
|
|
|
**/
|
|
|
|
PkTaskAction
|
2007-09-07 08:16:09 -07:00
|
|
|
pk_action_enum_from_text (const gchar *action)
|
2007-08-28 11:27:56 -07:00
|
|
|
{
|
|
|
|
return pk_task_enum_find_value (task_action, action);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2007-09-07 08:16:09 -07:00
|
|
|
* pk_action_enum_to_text:
|
2007-08-28 11:27:56 -07:00
|
|
|
**/
|
|
|
|
const gchar *
|
2007-09-07 08:16:09 -07:00
|
|
|
pk_action_enum_to_text (PkTaskAction action)
|
2007-08-28 11:27:56 -07:00
|
|
|
{
|
|
|
|
return pk_task_enum_find_string (task_action, action);
|
|
|
|
}
|
|
|
|
|
2007-08-30 16:20:13 -07:00
|
|
|
/***************************************************************************
|
|
|
|
*** MAKE CHECK TESTS ***
|
|
|
|
***************************************************************************/
|
|
|
|
#ifdef PK_BUILD_TESTS
|
|
|
|
#include <libselftest.h>
|
|
|
|
|
|
|
|
void
|
2007-09-09 08:47:12 -07:00
|
|
|
libst_enum (LibSelfTest *test)
|
2007-08-30 16:20:13 -07:00
|
|
|
{
|
2007-09-09 08:47:12 -07:00
|
|
|
if (libst_start (test, "PkEnum", CLASS_AUTO) == FALSE) {
|
2007-08-30 16:20:13 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-08-30 16:26:31 -07:00
|
|
|
libst_end (test);
|
2007-08-30 16:20:13 -07:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|