app-manager/setup.c
author J. Ali Harlow <ali@juiblex.co.uk>
Mon Nov 02 19:01:50 2015 +0000 (2015-11-02)
changeset 30 3ee18a3a0f58
child 61 31fb35727621
permissions -rw-r--r--
Fix compiler warnings
     1 /*
     2  * Copyright (C) 2014  J. Ali Harlow <ali@juiblex.co.uk>
     3  *
     4  * This program is free software; you can redistribute it and/or modify
     5  * it under the terms of the GNU General Public License as published by
     6  * the Free Software Foundation; either version 2 of the License, or
     7  * (at your option) any later version.
     8  *
     9  * This program is distributed in the hope that it will be useful,
    10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    12  * GNU General Public License for more details.
    13  *
    14  * You should have received a copy of the GNU General Public License along
    15  * with this program; if not, write to the Free Software Foundation, Inc.,
    16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
    17  */
    18 
    19 #include "config.h"
    20 #include <stdlib.h>
    21 #include <string.h>
    22 #include <errno.h>
    23 #include <glib.h>
    24 #include <gio/gio.h>
    25 #include <gtk/gtk.h>
    26 #include <plover/plover.h>
    27 #include <plover/transaction.h>
    28 #include <plover/packageset.h>
    29 #include <plover-gtk/transactionhelper.h>
    30 #include "app-manager.h"
    31 
    32 gboolean setup(PloverPackageSet *installed,const char *base)
    33 {
    34     gchar *s;
    35     const char *prefix;
    36     GError *error=NULL;
    37     static PloverTransactionHelper *helper=NULL;
    38     if (!helper)
    39     {
    40 	helper=plover_transaction_helper_new(ui);
    41 	plover_transaction_helper_set_installed(helper,installed);
    42 	plover_transaction_helper_set_base(helper,base);
    43 	prefix=plover_transaction_helper_get_prefix(helper,&error);
    44 	if (error)
    45 	    g_clear_error(&error);
    46 	else
    47 	{
    48 	    s=g_strconcat(prefix?prefix:"","/var/log/setup",NULL);
    49 	    plover_log_open(s);
    50 	    g_free(s);
    51 	}
    52 	plover_transaction_helper_set_check_vendor(helper,TRUE);
    53 	g_signal_connect(helper,"close",G_CALLBACK(gtk_main_quit),NULL);
    54     }
    55     if (!plover_transaction_helper_get_visible(helper))
    56     {
    57 	if (!plover_transaction_helper_install_group(helper,"base",&error))
    58 	{
    59 	    if (g_error_matches(error,PLOVER_GENERAL_ERROR,
    60 	      PLOVER_GENERAL_ERROR_NO_WORK))
    61 	    {
    62 		g_error_free(error);
    63 		error=g_error_new_literal(PLOVER_GENERAL_ERROR,
    64 		  PLOVER_GENERAL_ERROR_NO_WORK,
    65 		  "All packages already installed");
    66 		plover_transaction_helper_set_error(helper,error,
    67 		  "Software installation");
    68 	    }
    69 	    else if (g_error_matches(error,PLOVER_GENERAL_ERROR,
    70 	      PLOVER_GENERAL_ERROR_REQUIREMENTS_NOT_MET))
    71 	    {
    72 		g_error_free(error);
    73 		error=g_error_new_literal(PLOVER_GENERAL_ERROR,
    74 		  PLOVER_GENERAL_ERROR_REQUIREMENTS_NOT_MET,
    75 		  "Software cannot be installed because of missing updates. "
    76 		  "Installing all updates first should resolve this problem");
    77 		plover_transaction_helper_set_error(helper,error,
    78 		  "Software installation failed");
    79 	    }
    80 	    else
    81 		plover_transaction_helper_set_error(helper,error,
    82 		  "Software installation failed");
    83 	    g_error_free(error);
    84 	}
    85     }
    86     plover_transaction_helper_present(helper);
    87     return TRUE;
    88 }