| 1 |
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- |
| 2 |
* |
| 3 |
* Copyright (C) 2009 Richard Hughes <[email protected]> |
| 4 |
* |
| 5 |
* Licensed under the GNU Lesser General Public License Version 2.1 |
| 6 |
* |
| 7 |
* This library is free software; you can redistribute it and/or |
| 8 |
* modify it under the terms of the GNU Lesser General Public |
| 9 |
* License as published by the Free Software Foundation; either |
| 10 |
* version 2.1 of the License, or (at your option) any later version. |
| 11 |
* |
| 12 |
* This library is distributed in the hope that it will be useful, |
| 13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 |
* Lesser General Public License for more details. |
| 16 |
* |
| 17 |
* You should have received a copy of the GNU Lesser General Public |
| 18 |
* License along with this library; if not, write to the Free Software |
| 19 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 20 |
*/ |
| 21 |
|
| 22 |
#include "config.h" |
| 23 |
|
| 24 |
#include <packagekit-glib2/pk-enum.h> |
| 25 |
#include <packagekit-glib2/pk-results.h> |
| 26 |
#include <packagekit-glib2/pk-package-id.h> |
| 27 |
|
| 28 |
#include "pk-task-wrapper.h" |
| 29 |
|
| 30 |
struct _PkTaskWrapper |
| 31 |
{ |
| 32 |
PkTask parent; |
| 33 |
}; |
| 34 |
|
| 35 |
G_DEFINE_TYPE (PkTaskWrapper, pk_task_wrapper, PK_TYPE_TASK) |
| 36 |
|
| 37 |
/* |
| 38 |
* pk_task_wrapper_untrusted_question: |
| 39 |
**/ |
| 40 |
static void |
| 41 |
pk_task_wrapper_untrusted_question (PkTask *task, guint request, PkResults *results) |
| 42 |
{ |
| 43 |
g_print ("UNTRUSTED\n"); |
| 44 |
|
| 45 |
/* just accept without asking */ |
| 46 |
pk_task_user_accepted (task, request); |
| 47 |
} |
| 48 |
|
| 49 |
/* |
| 50 |
* pk_task_wrapper_key_question: |
| 51 |
**/ |
| 52 |
static void |
| 53 |
pk_task_wrapper_key_question (PkTask *task, guint request, PkResults *results) |
| 54 |
{ |
| 55 |
/* just accept without asking */ |
| 56 |
pk_task_user_accepted (task, request); |
| 57 |
} |
| 58 |
|
| 59 |
/* |
| 60 |
* pk_task_wrapper_eula_question: |
| 61 |
**/ |
| 62 |
static void |
| 63 |
pk_task_wrapper_eula_question (PkTask *task, guint request, PkResults *results) |
| 64 |
{ |
| 65 |
/* just accept without asking */ |
| 66 |
pk_task_user_accepted (task, request); |
| 67 |
} |
| 68 |
|
| 69 |
/* |
| 70 |
* pk_task_wrapper_media_change_question: |
| 71 |
**/ |
| 72 |
static void |
| 73 |
pk_task_wrapper_media_change_question (PkTask *task, guint request, PkResults *results) |
| 74 |
{ |
| 75 |
/* just accept without asking */ |
| 76 |
pk_task_user_accepted (task, request); |
| 77 |
} |
| 78 |
|
| 79 |
/* |
| 80 |
* pk_task_wrapper_simulate_question: |
| 81 |
**/ |
| 82 |
static void |
| 83 |
pk_task_wrapper_simulate_question (PkTask *task, guint request, PkResults *results) |
| 84 |
{ |
| 85 |
guint i; |
| 86 |
const gchar *package_id; |
| 87 |
PkPackage *package; |
| 88 |
g_autoptr(PkPackageSack) sack = NULL; |
| 89 |
g_autoptr(GPtrArray) array = NULL; |
| 90 |
|
| 91 |
/* get data */ |
| 92 |
sack = pk_results_get_package_sack (results); |
| 93 |
|
| 94 |
/* print data */ |
| 95 |
array = pk_package_sack_get_array (sack); |
| 96 |
for (i = 0; i < array->len; i++) { |
| 97 |
g_autofree gchar *printable = NULL; |
| 98 |
package = g_ptr_array_index (array, i); |
| 99 |
package_id = pk_package_get_id (package); |
| 100 |
printable = pk_package_id_to_printable (package_id); |
| 101 |
g_print ("%s\t%s\t%s\n", pk_info_enum_to_string (pk_package_get_info (package)), |
| 102 |
printable, pk_package_get_summary (package)); |
| 103 |
} |
| 104 |
|
| 105 |
/* just accept without asking */ |
| 106 |
pk_task_user_accepted (task, request); |
| 107 |
} |
| 108 |
|
| 109 |
/* |
| 110 |
* pk_task_wrapper_class_init: |
| 111 |
**/ |
| 112 |
static void |
| 113 |
pk_task_wrapper_class_init (PkTaskWrapperClass *klass) |
| 114 |
{ |
| 115 |
PkTaskClass *task_class = PK_TASK_CLASS (klass); |
| 116 |
|
| 117 |
task_class->untrusted_question = pk_task_wrapper_untrusted_question; |
| 118 |
task_class->key_question = pk_task_wrapper_key_question; |
| 119 |
task_class->eula_question = pk_task_wrapper_eula_question; |
| 120 |
task_class->media_change_question = pk_task_wrapper_media_change_question; |
| 121 |
task_class->simulate_question = pk_task_wrapper_simulate_question; |
| 122 |
} |
| 123 |
|
| 124 |
/* |
| 125 |
* pk_task_wrapper_init: |
| 126 |
* @task_wrapper: This class instance |
| 127 |
**/ |
| 128 |
static void |
| 129 |
pk_task_wrapper_init (PkTaskWrapper *task) |
| 130 |
{ |
| 131 |
} |
| 132 |
|
| 133 |
/** |
| 134 |
* pk_task_wrapper_new: |
| 135 |
* |
| 136 |
* Return value: a new #PkTaskWrapper object. |
| 137 |
**/ |
| 138 |
PkTaskWrapper * |
| 139 |
pk_task_wrapper_new (void) |
| 140 |
{ |
| 141 |
PkTaskWrapper *task; |
| 142 |
task = g_object_new (PK_TYPE_TASK_WRAPPER, NULL); |
| 143 |
return PK_TASK_WRAPPER (task); |
| 144 |
} |