From db8311423edb6818027871a603700df8b478038c Mon Sep 17 00:00:00 2001 From: J. Ali Harlow Date: Sat, 15 Nov 2014 19:10:51 +0000 Subject: [PATCH] Add menu handler --- .gitignore | 7 + Makefile.am | 2 +- configure.ac | 3 + plover-open/Makefile.am | 67 ++++++++ plover-open/manifest.xml.in | 22 +++ plover-open/mimetypes-application-x-rpm.svg | 26 +++ plover-open/plover-open.c | 222 +++++++++++++++++++++++++++ plover-open/resources.rc.in | 37 +++++ 8 files changed, 385 insertions(+), 1 deletions(-) create mode 100644 plover-open/Makefile.am create mode 100644 plover-open/manifest.xml.in create mode 100644 plover-open/mimetypes-application-x-rpm.svg create mode 100644 plover-open/plover-open.c create mode 100644 plover-open/resources.rc.in diff --git a/.gitignore b/.gitignore index e1dbd73..331bf3b 100644 --- a/.gitignore +++ b/.gitignore @@ -36,3 +36,10 @@ app-manager/plover-applications*.pgm app-manager/plover-applications*.pnm app-manager/24x24 app-manager/48x48 +plover-open/resources.rc +plover-open/plover-open +plover-open/application-x-redhat-package-manager.svg +plover-open/mimetypes-application-x-rpm*.pgm +plover-open/mimetypes-application-x-rpm*.pnm +plover-open/24x24 +plover-open/48x48 diff --git a/Makefile.am b/Makefile.am index e82944d..677fb80 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1 +1 @@ -SUBDIRS=plover setup update pre-inst plover-gtk app-manager +SUBDIRS=plover setup update pre-inst plover-gtk app-manager plover-open diff --git a/configure.ac b/configure.ac index 71c61a8..e2d234b 100644 --- a/configure.ac +++ b/configure.ac @@ -19,11 +19,14 @@ pre-inst/Makefile pre-inst/resources.rc app-manager/Makefile app-manager/resources.rc +plover-open/Makefile +plover-open/resources.rc ]) PLOVER_MSWIN_MANIFEST([setup/setup.exe.manifest:setup/manifest.xml.in update/update.exe.manifest:update/manifest.xml.in pre-inst/pre-inst.exe.manifest:pre-inst/manifest.xml.in app-manager/app-manager.exe.manifest:app-manager/manifest.xml.in +plover-open/plover-open.exe.manifest:plover-open/manifest.xml.in ]) AM_INIT_AUTOMAKE(no-define) m4_ifdef([AM_SILENT_RULES],[AM_SILENT_RULES([yes])]) diff --git a/plover-open/Makefile.am b/plover-open/Makefile.am new file mode 100644 index 0000000..63152d3 --- /dev/null +++ b/plover-open/Makefile.am @@ -0,0 +1,67 @@ +AM_CFLAGS=$(GUI_CFLAGS) -g -DPLOVER_DATADIR=\""$(pkgdatadir)"\" -I$(top_srcdir) +LDADD=../plover/libplover.la ../plover-gtk/libplover-gtk.la $(GUI_LIBS) + +bin_PROGRAMS=plover-open +plover_open_SOURCES=plover-open.c +if HAVE_WINDRES +plover_open_SOURCES+=resources.rc plover-open.exe.manifest +endif +nodist_plover_open_SOURCES=icons.h +if PLOVER_MINGW +plover_open_LDFLAGS=-mwindows +endif +scaleabledir=$(datadir)/icons/hicolor/scalable/mimetypes +scaleable_DATA=application-x-redhat-package-manager.svg +smallicondir=$(datadir)/icons/hicolor/24x24/mimetypes +smallicon_DATA=24x24/application-x-redhat-package-manager.png +bigicondir=$(datadir)/icons/hicolor/48x48/mimetypes +bigicon_DATA=48x48/application-x-redhat-package-manager.png + +# PLOVER_V_SKIP: Don't echo anything for this command if V=0 +PLOVER_V_SKIP = $(PLOVER_V_SKIP_$(V)) +PLOVER_V_SKIP_ = $(PLOVER_V_SKIP_$(AM_DEFAULT_VERBOSITY)) +PLOVER_V_SKIP_0 = @ + +.rc.$(OBJEXT): + $(AM_V_GEN)$(WINDRES) $< $@ + +resources.$(OBJEXT): plover-open.exe.manifest plover-open.ico + +.png.pnm: + pngtopnm $< | pnmquant 256 > $@ + +mimetypes-application-x-rpm%.pnm: mimetypes-application-x-rpm.svg + $(PLOVER_V_SKIP)rsvg -w $* -h $* -f png $< temp.png + $(AM_V_GEN)pngtopnm temp.png | pnmquant -quiet 256 > $@ + $(PLOVER_V_SKIP)$(RM) temp.png + +mimetypes-application-x-rpm%.pgm: mimetypes-application-x-rpm.svg + $(PLOVER_V_SKIP)rsvg -w $* -h $* -f png $< temp.png + $(AM_V_GEN)pngtopnm -alpha temp.png > $@ + $(PLOVER_V_SKIP)$(RM) temp.png + +24x24/application-x-redhat-package-manager.png: mimetypes-application-x-rpm.svg + $(PLOVER_V_SKIP)mkdir -p 24x24 + $(AM_V_GEN)rsvg -w 24 -h 24 -f png $< $@ + +48x48/application-x-redhat-package-manager.png: mimetypes-application-x-rpm.svg + $(PLOVER_V_SKIP)mkdir -p 48x48 + $(AM_V_GEN)rsvg -w 48 -h 48 -f png $< $@ + +plover-open.ico: mimetypes-application-x-rpm16.pnm \ + mimetypes-application-x-rpm16.pgm \ + mimetypes-application-x-rpm22.pnm \ + mimetypes-application-x-rpm22.pgm \ + mimetypes-application-x-rpm32.pnm \ + mimetypes-application-x-rpm32.pgm \ + mimetypes-application-x-rpm46.pnm \ + mimetypes-application-x-rpm46.pgm + $(AM_V_GEN)ppmtowinicon -andpgms -output=$@ $^ + +clean-local: + -rm -rf 24x24 48x48 + +application-x-redhat-package-manager.svg: mimetypes-application-x-rpm.svg + $(AM_V_GEN)cp $< $@ + +EXTRA_DIST=mimetypes-application-x-rpm.svg diff --git a/plover-open/manifest.xml.in b/plover-open/manifest.xml.in new file mode 100644 index 0000000..35e881a --- /dev/null +++ b/plover-open/manifest.xml.in @@ -0,0 +1,22 @@ +changequote([,])dnl + + + + Package Handler + + + + + + + + + + + + + + diff --git a/plover-open/mimetypes-application-x-rpm.svg b/plover-open/mimetypes-application-x-rpm.svg new file mode 100644 index 0000000..6f40b44 --- /dev/null +++ b/plover-open/mimetypes-application-x-rpm.svg @@ -0,0 +1,26 @@ + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/plover-open/plover-open.c b/plover-open/plover-open.c new file mode 100644 index 0000000..707201f --- /dev/null +++ b/plover-open/plover-open.c @@ -0,0 +1,222 @@ +/* + * Copyright (C) 2014 J. Ali Harlow + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include "config.h" +#include +#include +#ifdef WIN32 +#include +#endif /* WIN32 */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +LUALIB_API int luaopen_posix(lua_State *L); + +#define LOGO_NAME "application-x-redhat-package-manager" + +gboolean install(PloverPackageSet *installed,const char *path) +{ + gchar *s; + const char *prefix,*name,*unsatisfied; + const char *filenames[2]; + GError *error=NULL; + GSList *packages,*lnk; + struct plover_vector *selected_packages; + PloverPackage *package; + PloverPackageSet *set; + PloverRepository *upstream; + PloverTransactionHelper *helper; + helper=plover_transaction_helper_new(NULL); + g_signal_connect(helper,"close",G_CALLBACK(gtk_main_quit),NULL); + plover_transaction_helper_set_installed(helper,installed); + if (plover_transaction_helper_get_error(helper,NULL)) + { + plover_transaction_helper_present(helper); + return TRUE; + } + filenames[0]=path; + filenames[1]=NULL; + upstream=plover_repository_new_from_files(filenames,&error); + if (upstream) + plover_transaction_helper_set_upstream(helper,upstream); + else + { + plover_transaction_helper_set_error(helper,error, + "Software installation failed"); + g_clear_error(&error); + plover_transaction_helper_present(helper); + return TRUE; + } + prefix=plover_transaction_helper_get_prefix(helper,&error); + if (error) + g_clear_error(&error); + else + { + s=g_strconcat(prefix?prefix:"","/var/log/open",NULL); + plover_log_open(s); + g_free(s); + } + set=plover_repository_get_package_set(upstream); + packages=plover_package_set_get_packages(set); + selected_packages=plover_vector_new(); + for(lnk=packages;lnk;lnk=lnk->next) + { + package=PLOVER_PACKAGE(lnk->data); + plover_vector_append(selected_packages, + plover_package_get_name(package)); + } + if (!plover_transaction_helper_install_packages(helper,selected_packages, + &error)) + { + if (g_error_matches(error,PLOVER_GENERAL_ERROR, + PLOVER_GENERAL_ERROR_NO_WORK)) + { + g_error_free(error); + error=g_error_new_literal(PLOVER_GENERAL_ERROR, + PLOVER_GENERAL_ERROR_NO_WORK, + "All packages already installed"); + plover_transaction_helper_set_error(helper,error, + "Software installation"); + } + else if (g_error_matches(error,PLOVER_GENERAL_ERROR, + PLOVER_GENERAL_ERROR_REQUIREMENTS_NOT_MET)) + { + g_error_free(error); + unsatisfied=plover_transaction_helper_get_unsatisfied(helper); + error=g_error_new(PLOVER_GENERAL_ERROR, + PLOVER_GENERAL_ERROR_REQUIREMENTS_NOT_MET, + "Software cannot be installed because the following requirements " + "were not met:\n\n%s",unsatisfied); + plover_transaction_helper_set_error(helper,error, + "Software installation failed"); + } + else + plover_transaction_helper_set_error(helper,error, + "Software installation failed"); + g_error_free(error); + } + plover_vector_free(selected_packages); + g_object_unref(upstream); + plover_transaction_helper_present(helper); + return TRUE; +} + +static void install_icons(void) +{ + GtkIconSet *icon_set; + plover_icons_add_to_stock("mimetypes",LOGO_NAME); + icon_set=gtk_icon_factory_lookup_default(LOGO_NAME); + gtk_window_set_default_icon_name(LOGO_NAME); +} + +int main(int argc,char **argv) +{ + GError *err=0; + GtkWidget *w; + gchar *s,*t,*contents; + gchar *install_path=NULL; + gsize len; + PloverPackageSet *set; +#if 0 + GSList *objects,*lnk; +#endif + gboolean started; + GOptionEntry options[]={ + {"install",0,0,G_OPTION_ARG_FILENAME,&install_path, + "Install an RPM","path"}, + {NULL} + }; +#ifdef WIN32 + /* + * plover-open is normally a GUI application, but rpm scripts may well + * call console applications and it looks ugly if console windows keep + * popping up. Avoid this by allocating our own console and hiding it. + * Note: + * - If plover-open is a console application (typically for debugging), + * then skip this step. + * - Call ShowWindow twice to negate special handling on first call. + */ + if (!GetConsoleWindow()) + { + AllocConsole(); + ShowWindow(GetConsoleWindow(),SW_HIDE); + ShowWindow(GetConsoleWindow(),SW_HIDE); + } +#endif + razor_set_lua_loader("posix",luaopen_posix); + razor_set_lua_loader("whelk",luaopen_whelk); + if (!gtk_init_with_args(&argc,&argv,NULL,options,NULL,&err)) + { + g_printerr("%s\n",err->message); + exit(1); + } + install_icons(); +#if 0 + ui=gtk_builder_new(); + if (!g_file_get_contents("plover-open.ui",&contents,&len,&err) && + g_error_matches(err,G_FILE_ERROR,G_FILE_ERROR_NOENT)) + { +#ifdef WIN32 + t=g_win32_get_package_installation_directory_of_module(NULL); + s=g_build_filename(t,"share","plover","plover-open.ui",NULL); + g_free(t); +#else + s=g_build_filename(PLOVER_DATADIR,"plover-open.ui",NULL); +#endif + g_clear_error(&err); + (void)g_file_get_contents(s,&contents,&len,&err); + g_free(s); + } + if (!err) + { + (void)gtk_builder_add_from_string(ui,contents,len,&err); + g_free(contents); + } + if (err) + { + g_error("%s",err->message); + exit(0); + } + gtk_builder_connect_signals(ui,NULL); +#endif + set=plover_package_set_new(); + (void)plover_package_set_open(set,"",TRUE,NULL); + if (install_path) + if (install(set,install_path)) + gtk_main(); + g_clear_object(&set); +#if 0 + objects=gtk_builder_get_objects(ui); + for(lnk=objects;lnk;lnk=lnk->next) + if (GTK_IS_WIDGET(lnk->data) && + gtk_widget_is_toplevel(GTK_WIDGET(lnk->data))) + gtk_widget_destroy(GTK_WIDGET(lnk->data)); + g_slist_free(objects); + g_clear_object(&ui); +#endif + g_free(install_path); + exit(0); +} diff --git a/plover-open/resources.rc.in b/plover-open/resources.rc.in new file mode 100644 index 0000000..b7e4c91 --- /dev/null +++ b/plover-open/resources.rc.in @@ -0,0 +1,37 @@ +#include +#include + +#pragma code_page(65001) + +MAINICON ICON "plover-open.ico" + +VS_VERSION_INFO VERSIONINFO + FILEVERSION @PLOVER_MAJOR_VERSION@,@PLOVER_MINOR_VERSION@, + @PLOVER_MICRO_VERSION@,0 + PRODUCTVERSION @PLOVER_MAJOR_VERSION@,@PLOVER_MINOR_VERSION@, + @PLOVER_MICRO_VERSION@,0 + FILEOS VOS__WINDOWS32 + FILETYPE VFT_APP + { + BLOCK "StringFileInfo" + { + BLOCK "080904B0" + { + VALUE "CompanyName","The plover development team" + VALUE "FileDescription","Plover Menu Handler" + VALUE "FileVersion","@PACKAGE_VERSION@" + VALUE "InternalName","plover-open" + VALUE "LegalCopyright", + "Copyright © 2014 J. Ali Harlow et al" + VALUE "OriginalFilename","plover-open.exe" + VALUE "ProductName","plover" + VALUE "ProductVersion","@PACKAGE_VERSION@" + } + } + BLOCK "VarFileInfo" + { + VALUE "Translation",0x809,0x4B0 + } + } + +CREATEPROCESS_MANIFEST_RESOURCE_ID RT_MANIFEST "plover-open.exe.manifest" -- 1.7.1