app-manager/update.c
changeset 59 296eac3183bc
child 61 31fb35727621
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/app-manager/update.c	Fri Jul 08 08:26:29 2016 +0100
     1.3 @@ -0,0 +1,89 @@
     1.4 +/*
     1.5 + * Copyright (C) 2014  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 <errno.h>
    1.26 +#include <glib.h>
    1.27 +#include <gio/gio.h>
    1.28 +#include <gtk/gtk.h>
    1.29 +#include <plover/plover.h>
    1.30 +#include <plover/transaction.h>
    1.31 +#include <plover/packageset.h>
    1.32 +#include <plover-gtk/transactionhelper.h>
    1.33 +#include "app-manager.h"
    1.34 +
    1.35 +gboolean update(PloverPackageSet *installed,const char *base)
    1.36 +{
    1.37 +    gchar *s;
    1.38 +    const char *prefix;
    1.39 +    GError *error=NULL;
    1.40 +    static PloverTransactionHelper *helper=NULL;
    1.41 +    if (!helper)
    1.42 +    {
    1.43 +	helper=plover_transaction_helper_new(ui);
    1.44 +	plover_transaction_helper_set_installed(helper,installed);
    1.45 +	plover_transaction_helper_set_base(helper,base);
    1.46 +	prefix=plover_transaction_helper_get_prefix(helper,&error);
    1.47 +	if (error)
    1.48 +	    g_clear_error(&error);
    1.49 +	else
    1.50 +	{
    1.51 +	    s=g_strconcat(prefix?prefix:"","/var/log/update",NULL);
    1.52 +	    plover_log_open(s);
    1.53 +	    g_free(s);
    1.54 +	}
    1.55 +	plover_transaction_helper_set_check_vendor(helper,TRUE);
    1.56 +	g_signal_connect(helper,"close",G_CALLBACK(gtk_main_quit),NULL);
    1.57 +    }
    1.58 +    if (!plover_transaction_helper_get_visible(helper))
    1.59 +    {
    1.60 +	if (!plover_transaction_helper_update(helper,&error))
    1.61 +	{
    1.62 +	    if (g_error_matches(error,PLOVER_GENERAL_ERROR,
    1.63 +	      PLOVER_GENERAL_ERROR_NO_WORK))
    1.64 +	    {
    1.65 +		g_error_free(error);
    1.66 +		error=g_error_new_literal(PLOVER_GENERAL_ERROR,
    1.67 +		  PLOVER_GENERAL_ERROR_NO_WORK,
    1.68 +		  "All relevant updates already applied");
    1.69 +		plover_transaction_helper_set_error(helper,error,
    1.70 +		  "Software update");
    1.71 +	    }
    1.72 +	    else if (g_error_matches(error,PLOVER_GENERAL_ERROR,
    1.73 +	      PLOVER_GENERAL_ERROR_REQUIREMENTS_NOT_MET))
    1.74 +	    {
    1.75 +		g_error_free(error);
    1.76 +		error=g_error_new_literal(PLOVER_GENERAL_ERROR,
    1.77 +		  PLOVER_GENERAL_ERROR_REQUIREMENTS_NOT_MET,
    1.78 +		  "Updates cannot be applied because some earlier updates are "
    1.79 +		  "missing. Installing updates in sequence should resolve this "
    1.80 +		  "problem");
    1.81 +		plover_transaction_helper_set_error(helper,error,
    1.82 +		  "Software update failed");
    1.83 +	    }
    1.84 +	    else
    1.85 +		plover_transaction_helper_set_error(helper,error,
    1.86 +		  "Software update failed");
    1.87 +	    g_error_free(error);
    1.88 +	}
    1.89 +    }
    1.90 +    plover_transaction_helper_present(helper);
    1.91 +    return TRUE;
    1.92 +}