1.1 --- a/plover-gtk/packageset.c Fri Mar 23 20:29:50 2012 +0000
1.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
1.3 @@ -1,259 +0,0 @@
1.4 -/*
1.5 - * Copyright (C) 2010-2012 J. Ali Harlow <ali@juiblex.co.uk>
1.6 - *
1.7 - * This program is free software; you can redistribute it and/or modify
1.8 - * it under the terms of the GNU General Public License as published by
1.9 - * the Free Software Foundation; either version 2 of the License, or
1.10 - * (at your option) any later version.
1.11 - *
1.12 - * This program is distributed in the hope that it will be useful,
1.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
1.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1.15 - * GNU General Public License for more details.
1.16 - *
1.17 - * You should have received a copy of the GNU General Public License along
1.18 - * with this program; if not, write to the Free Software Foundation, Inc.,
1.19 - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
1.20 - */
1.21 -
1.22 -#include "config.h"
1.23 -#include <stdlib.h>
1.24 -#include <string.h>
1.25 -#include <fcntl.h>
1.26 -#include <errno.h>
1.27 -#include <unistd.h>
1.28 -#include <glib-object.h>
1.29 -#include <razor.h>
1.30 -#include "plover/plover.h"
1.31 -#include "plover-gtk/error.h"
1.32 -#include "plover-gtk/packageset.h"
1.33 -#include "plover-gtk/package.h"
1.34 -
1.35 -G_DEFINE_TYPE(PloverPackageSet,plover_package_set,G_TYPE_OBJECT);
1.36 -
1.37 -typedef struct _PloverPackageSetPrivate {
1.38 - struct razor_root *root;
1.39 - struct razor_set *set;
1.40 - GSList *packages;
1.41 - int no_details;
1.42 -} PloverPackageSetPrivate;
1.43 -
1.44 -#define PLOVER_PACKAGE_SET_GET_PRIVATE(obj)\
1.45 - G_TYPE_INSTANCE_GET_PRIVATE(obj,\
1.46 - PLOVER_TYPE_PACKAGE_SET,\
1.47 - PloverPackageSetPrivate)
1.48 -
1.49 -enum {
1.50 - CHANGED=0,
1.51 - N_SIGNALS
1.52 -};
1.53 -
1.54 -static guint signals[N_SIGNALS];
1.55 -
1.56 -static void plover_package_set_finalize(GObject *obj)
1.57 -{
1.58 - PloverPackageSetPrivate *priv=PLOVER_PACKAGE_SET_GET_PRIVATE(obj);
1.59 - if (priv->root)
1.60 - razor_root_close(priv->root);
1.61 - if (G_OBJECT_CLASS(plover_package_set_parent_class)->finalize)
1.62 - G_OBJECT_CLASS(plover_package_set_parent_class)->finalize(obj);
1.63 -}
1.64 -
1.65 -static void plover_package_set_dispose(GObject *obj)
1.66 -{
1.67 - PloverPackageSetPrivate *priv=PLOVER_PACKAGE_SET_GET_PRIVATE(obj);
1.68 - if (priv->set)
1.69 - {
1.70 - razor_set_unref(priv->set);
1.71 - priv->set=NULL;
1.72 - }
1.73 - if (G_OBJECT_CLASS(plover_package_set_parent_class)->dispose)
1.74 - G_OBJECT_CLASS(plover_package_set_parent_class)->dispose(obj);
1.75 -}
1.76 -
1.77 -static void plover_package_set_class_init(PloverPackageSetClass *klass)
1.78 -{
1.79 - GObjectClass *oclass=G_OBJECT_CLASS(klass);
1.80 - oclass->finalize=plover_package_set_finalize;
1.81 - oclass->dispose=plover_package_set_dispose;
1.82 - g_type_class_add_private(klass,sizeof(PloverPackageSetPrivate));
1.83 - signals[CHANGED]=g_signal_newv("changed",
1.84 - G_TYPE_FROM_CLASS(klass),G_SIGNAL_RUN_LAST,NULL,NULL,NULL,
1.85 - g_cclosure_marshal_VOID__VOID,G_TYPE_NONE,0,NULL);
1.86 -}
1.87 -
1.88 -static void plover_package_set_init(PloverPackageSet *set)
1.89 -{
1.90 - PloverPackageSetPrivate *priv;
1.91 - priv=PLOVER_PACKAGE_SET_GET_PRIVATE(set);
1.92 - priv->no_details=-1;
1.93 -}
1.94 -
1.95 -PloverPackageSet *plover_package_set_new(void)
1.96 -{
1.97 - return g_object_new(PLOVER_TYPE_PACKAGE_SET,NULL);
1.98 -}
1.99 -
1.100 -PloverPackageSet *plover_package_set_new_from_installed(const char *root,
1.101 - GError **err)
1.102 -{
1.103 - PloverPackageSet *set;
1.104 - PloverPackageSetPrivate *priv;
1.105 - struct razor_error *error=NULL;
1.106 - set=plover_package_set_new();
1.107 - priv=PLOVER_PACKAGE_SET_GET_PRIVATE(set);
1.108 - priv->root=razor_root_open(root,&error);
1.109 - if (!priv->root)
1.110 - {
1.111 - g_set_error_literal(err,PLOVER_RAZOR_ERROR,PLOVER_RAZOR_ERROR_FAILED,
1.112 - razor_error_get_msg(error));
1.113 - razor_error_free(error);
1.114 - g_object_unref(set);
1.115 - return NULL;
1.116 - }
1.117 - priv->set=razor_set_ref(razor_root_get_system_set(priv->root));
1.118 - if (!priv->set)
1.119 - {
1.120 - g_set_error(err,PLOVER_RAZOR_ERROR,PLOVER_RAZOR_ERROR_FAILED,
1.121 - "Failed to get system set from %s",root);
1.122 - g_object_unref(set);
1.123 - return NULL;
1.124 - }
1.125 - return set;
1.126 -}
1.127 -
1.128 -PloverPackageSet *plover_package_set_new_from_repository(const char *base,
1.129 - struct razor_relocations *relocations,GError **err)
1.130 -{
1.131 -#if HAVE_FCHDIR
1.132 - int fd;
1.133 -#else
1.134 - size_t wd_len;
1.135 - char *wd;
1.136 -#endif
1.137 - gchar *s;
1.138 - struct razor_set *reloc;
1.139 - struct razor_error *error=NULL;
1.140 - PloverPackageSet *set;
1.141 - PloverPackageSetPrivate *priv;
1.142 - set=plover_package_set_new();
1.143 - priv=PLOVER_PACKAGE_SET_GET_PRIVATE(set);
1.144 -#if HAVE_FCHDIR
1.145 - fd=open(".",O_RDONLY);
1.146 -#else
1.147 - wd_len=32;
1.148 - wd=malloc(wd_len);
1.149 - while (!getcwd(wd,wd_len) && errno==ERANGE)
1.150 - {
1.151 - free(wd);
1.152 - wd_len*=2;
1.153 - wd=malloc(wd_len);
1.154 - }
1.155 -#endif
1.156 - s=g_build_filename(base,"repodata",NULL);
1.157 - if (chdir(s)<0)
1.158 - {
1.159 - g_set_error(err,G_FILE_ERROR,g_file_error_from_errno(errno),
1.160 - "%s: %s",s,g_strerror(errno));
1.161 - g_object_unref(set);
1.162 -#if HAVE_FCHDIR
1.163 - close(fd);
1.164 -#else
1.165 - free(wd);
1.166 -#endif
1.167 - return NULL;
1.168 - }
1.169 - g_free(s);
1.170 - priv->set=plover_razor_set_create_from_yum("..");
1.171 -#if HAVE_FCHDIR
1.172 - (void)fchdir(fd);
1.173 - close(fd);
1.174 -#else
1.175 - chdir(wd);
1.176 - free(wd);
1.177 -#endif
1.178 - if (priv->set && relocations)
1.179 - {
1.180 - reloc=plover_relocate_packages(priv->set,base,relocations,&error);
1.181 - if (!reloc)
1.182 - {
1.183 - g_set_error_literal(err,PLOVER_RAZOR_ERROR,
1.184 - PLOVER_RAZOR_ERROR_FAILED,razor_error_get_msg(error));
1.185 - razor_error_free(error);
1.186 - g_object_unref(set);
1.187 - return NULL;
1.188 - }
1.189 - razor_set_unref(priv->set);
1.190 - priv->set=reloc;
1.191 - }
1.192 - if (!priv->set)
1.193 - {
1.194 - g_set_error(err,PLOVER_RAZOR_ERROR,PLOVER_RAZOR_ERROR_FAILED,
1.195 - "Failed to create package set from repository %s",base);
1.196 - g_object_unref(set);
1.197 - return NULL;
1.198 - }
1.199 - return set;
1.200 -}
1.201 -
1.202 -GSList *plover_package_set_get_packages(PloverPackageSet *set)
1.203 -{
1.204 - struct razor_package_iterator *iter;
1.205 - struct razor_package *pkg;
1.206 - PloverPackageSetPrivate *priv;
1.207 - PloverPackage *package;
1.208 - g_return_val_if_fail(PLOVER_IS_PACKAGE_SET(set),NULL);
1.209 - priv=PLOVER_PACKAGE_SET_GET_PRIVATE(set);
1.210 - if (priv->set && !priv->packages)
1.211 - {
1.212 - iter=razor_package_iterator_create(priv->set);
1.213 - while(razor_package_iterator_next(iter,&pkg,RAZOR_DETAIL_LAST))
1.214 - {
1.215 - package=plover_package_new(priv->set,pkg);
1.216 - priv->packages=g_slist_prepend(priv->packages,package);
1.217 - }
1.218 - razor_package_iterator_destroy(iter);
1.219 - }
1.220 - return priv->packages;
1.221 -}
1.222 -
1.223 -/*
1.224 - * Some versions of razor have a bug which causes all detail strings
1.225 - * to be discarded. If such a version of razor is used to install or
1.226 - * update a package, then all the detail strings for the installed
1.227 - * set will be lost. This function tests for this condition and can
1.228 - * be used to present something more useful than blank details.
1.229 - */
1.230 -
1.231 -gboolean plover_package_set_get_no_details(PloverPackageSet *set)
1.232 -{
1.233 - PloverPackageSetPrivate *priv;
1.234 - PloverPackage *package;
1.235 - GSList *packages,*link;
1.236 - g_return_val_if_fail(PLOVER_IS_PACKAGE_SET(set),FALSE);
1.237 - priv=PLOVER_PACKAGE_SET_GET_PRIVATE(set);
1.238 - if (priv->no_details<0)
1.239 - {
1.240 - packages=plover_package_set_get_packages(set);
1.241 - if (packages)
1.242 - {
1.243 - priv->no_details=0;
1.244 - for(link=packages;link;link=link->next)
1.245 - {
1.246 - package=link->data;
1.247 - priv->no_details+=2;
1.248 - if (*plover_package_get_summary(package))
1.249 - priv->no_details--;
1.250 - if (*plover_package_get_license(package))
1.251 - priv->no_details--;
1.252 - if (*plover_package_get_description(package))
1.253 - priv->no_details--;
1.254 - if (*plover_package_get_URL(package))
1.255 - priv->no_details--;
1.256 - }
1.257 - if (priv->no_details<0) /* More than 50% of strings present */
1.258 - priv->no_details=0;
1.259 - }
1.260 - }
1.261 - return priv->no_details>0;
1.262 -}