app-manager/applications.c
author J. Ali Harlow <ali@juiblex.co.uk>
Sat Jul 16 11:07:18 2016 +0100 (2016-07-16)
changeset 61 31fb35727621
parent 10 8b50be3e2998
child 99 0121592e2512
permissions -rw-r--r--
Support parallel installations. The idea is that for CAD screener, we want
to be able to install this on the same machine as a standard AVOT setup
(most notably for John's laptop). To allow for the possibility of a second
application that might have the same requirements, we add the concept of
vendor-specific distributions. Thus we can have one distribution for CAD
screener and one for The Next Big Thing. It doesn't seem trivial to have
both CAD screener and AVOT under the same vendor tag so we'll have to have
AVOT under "City Occupational" and CAD screener under "City Occupational Ltd"
or some such kludge.

Most of this is done although we are very short of test cases (in particular
we don't test that it's actually possible to install CAD screener in parallel
with AVOT or to update either of them once installed, which is fundamental).

We also have a lot of baggage left over, including an intercept of razor_set.
The problem that this was introduced to debug has been fixed but it looks
like there are a number of memory leaks which it might be useful to help
track down so it has been left in place for now.

There is still a lot of confusion in plover between path-based and URI-based
API. We should review the API, decide what we want and have a general clear up.

There is also confusion as to the purpose of RAZOR_ROOT (and meaning; path or
URI). This is not used at all in librazor (although it is used in razor.exe).
Ideally we shouldn't use it in plover or plover-gtk either although again, we
might want to support it or an equivalent in (some of) the various executables.

Work that would still to nice to do for CAD screener:

- uninstall (ideally as an installed program that hooks into Add/Remove programs
but even re-running the installer would be acceptable).
- xz support (smaller packages).
- repomd.xml and xml:base (would be needed for an Internet installer).
- graphical installer.
     1 /*
     2  * Copyright (C) 2010  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 #ifdef WIN32
    23 #include <windows.h>
    24 #endif
    25 #include <glib.h>
    26 #include <gtk/gtk.h>
    27 #include <plover-gtk/packagestore.h>
    28 #include <plover-gtk/packagefilestore.h>
    29 #include "app-manager.h"
    30 
    31 #ifdef WIN32
    32 static BOOL CALLBACK plover_applications_visible_callback(HMODULE module,
    33   const char *type,char *name,long *param)
    34 {
    35     gboolean *visible=(void *)param;
    36     if (!IS_INTRESOURCE(name) && !strcmp(name,"MAINICON"))
    37 	*visible=TRUE;
    38     return !*visible;
    39 }
    40 #endif
    41 
    42 static gboolean plover_applications_visible_func(GtkTreeModel *model,
    43   GtkTreeIter *iter,gpointer data)
    44 {
    45     /* Visible if row is non-empty and package contains a .desktop file
    46      * in /usr/share/applications (UNIX) or package contains a .exe file
    47      * which has a default application icon (MS-Windows).
    48      */
    49     PloverPackage *package;
    50     GtkTreeModel *file_store;
    51     GtkTreeIter fi;
    52     gchar *name;
    53 #ifdef WIN32
    54     HMODULE module;
    55     DWORD flags=
    56 #ifdef LOAD_LIBRARY_AS_IMAGE_RESOURCE
    57       LOAD_LIBRARY_AS_IMAGE_RESOURCE|
    58 #endif
    59       LOAD_LIBRARY_AS_DATAFILE;
    60 #else
    61     gchar *dir;
    62 #endif
    63     gboolean visible=FALSE;
    64     gtk_tree_model_get(model,iter,PLOVER_PACKAGE_STORE_OBJ_COLUMN,&package,-1);
    65     if (package)
    66     {
    67 	file_store=
    68 	  GTK_TREE_MODEL(plover_package_file_store_new_from_package(package));
    69 	if (gtk_tree_model_get_iter_first(file_store,&fi))
    70 	{
    71 	    do
    72 	    {
    73 		gtk_tree_model_get(file_store,&fi,
    74 		  PLOVER_PACKAGE_FILE_STORE_NAME_COLUMN,&name,-1);
    75 #ifdef WIN32
    76 		if (g_str_has_suffix(name,".exe"))
    77 		{
    78 		    module=LoadLibraryExA(name,NULL,flags);
    79 		    if (module)
    80 		    {
    81 			(void)EnumResourceNamesA(module,RT_ICON,
    82 			  plover_applications_visible_callback,&visible);
    83 			if (!visible)
    84 			    (void)EnumResourceNamesA(module,RT_GROUP_ICON,
    85 			      plover_applications_visible_callback,&visible);
    86 			FreeLibrary(module);
    87 		    }
    88 		}
    89 #else
    90 		dir=g_path_get_dirname(name);
    91 		if (!strcmp(dir,"/usr/share/applications") &&
    92 		  g_str_has_suffix(name,".desktop"))
    93 		    visible=TRUE;
    94 		g_free(dir);
    95 #endif
    96 		g_free(name);
    97 	    } while(!visible && gtk_tree_model_iter_next(file_store,&fi));
    98 	}
    99 	g_object_unref(file_store);
   100     }
   101     g_object_unref(package);
   102     return visible;
   103 }
   104 
   105 GtkTreeModel *plover_applications_model_new(GtkTreeModel *installed)
   106 {
   107     GtkTreeModel *model;
   108     model=gtk_tree_model_filter_new(installed,NULL);
   109     gtk_tree_model_filter_set_visible_func(GTK_TREE_MODEL_FILTER(model),
   110       plover_applications_visible_func,NULL,NULL);
   111     return model;
   112 }