ali@25: /* ali@25: * Copyright (C) 2014 J. Ali Harlow ali@25: * ali@25: * This program is free software; you can redistribute it and/or modify ali@25: * it under the terms of the GNU General Public License as published by ali@25: * the Free Software Foundation; either version 2 of the License, or ali@25: * (at your option) any later version. ali@25: * ali@25: * This program is distributed in the hope that it will be useful, ali@25: * but WITHOUT ANY WARRANTY; without even the implied warranty of ali@25: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ali@25: * GNU General Public License for more details. ali@25: * ali@25: * You should have received a copy of the GNU General Public License along ali@25: * with this program; if not, write to the Free Software Foundation, Inc., ali@25: * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ali@25: */ ali@25: ali@25: #include "config.h" ali@25: #include ali@25: #include ali@25: #ifdef WIN32 ali@25: #include ali@25: #endif /* WIN32 */ ali@25: #include ali@25: #include ali@25: #include ali@25: #include ali@25: #include ali@25: #include ali@25: #include ali@25: #include ali@25: #include ali@25: #include ali@25: ali@25: LUALIB_API int luaopen_posix(lua_State *L); ali@25: ali@25: #define LOGO_NAME "application-x-redhat-package-manager" ali@25: ali@25: gboolean install(PloverPackageSet *installed,const char *path) ali@25: { ali@25: gchar *s; ali@30: const char *prefix,*unsatisfied; ali@25: const char *filenames[2]; ali@25: GError *error=NULL; ali@25: GSList *packages,*lnk; ali@25: struct plover_vector *selected_packages; ali@25: PloverPackage *package; ali@25: PloverPackageSet *set; ali@25: PloverRepository *upstream; ali@25: PloverTransactionHelper *helper; ali@25: helper=plover_transaction_helper_new(NULL); ali@25: g_signal_connect(helper,"close",G_CALLBACK(gtk_main_quit),NULL); ali@25: plover_transaction_helper_set_installed(helper,installed); ali@25: if (plover_transaction_helper_get_error(helper,NULL)) ali@25: { ali@25: plover_transaction_helper_present(helper); ali@25: return TRUE; ali@25: } ali@25: filenames[0]=path; ali@25: filenames[1]=NULL; ali@25: upstream=plover_repository_new_from_files(filenames,&error); ali@25: if (upstream) ali@25: plover_transaction_helper_set_upstream(helper,upstream); ali@25: else ali@25: { ali@25: plover_transaction_helper_set_error(helper,error, ali@25: "Software installation failed"); ali@25: g_clear_error(&error); ali@25: plover_transaction_helper_present(helper); ali@25: return TRUE; ali@25: } ali@25: prefix=plover_transaction_helper_get_prefix(helper,&error); ali@25: if (error) ali@25: g_clear_error(&error); ali@25: else ali@25: { ali@25: s=g_strconcat(prefix?prefix:"","/var/log/open",NULL); ali@25: plover_log_open(s); ali@25: g_free(s); ali@25: } ali@25: set=plover_repository_get_package_set(upstream); ali@25: packages=plover_package_set_get_packages(set); ali@25: selected_packages=plover_vector_new(); ali@25: for(lnk=packages;lnk;lnk=lnk->next) ali@25: { ali@25: package=PLOVER_PACKAGE(lnk->data); ali@25: plover_vector_append(selected_packages, ali@25: plover_package_get_name(package)); ali@25: } ali@25: if (!plover_transaction_helper_install_packages(helper,selected_packages, ali@25: &error)) ali@25: { ali@25: if (g_error_matches(error,PLOVER_GENERAL_ERROR, ali@25: PLOVER_GENERAL_ERROR_NO_WORK)) ali@25: { ali@25: g_error_free(error); ali@25: error=g_error_new_literal(PLOVER_GENERAL_ERROR, ali@25: PLOVER_GENERAL_ERROR_NO_WORK, ali@25: "All packages already installed"); ali@25: plover_transaction_helper_set_error(helper,error, ali@25: "Software installation"); ali@25: } ali@25: else if (g_error_matches(error,PLOVER_GENERAL_ERROR, ali@25: PLOVER_GENERAL_ERROR_REQUIREMENTS_NOT_MET)) ali@25: { ali@25: g_error_free(error); ali@25: unsatisfied=plover_transaction_helper_get_unsatisfied(helper); ali@25: error=g_error_new(PLOVER_GENERAL_ERROR, ali@25: PLOVER_GENERAL_ERROR_REQUIREMENTS_NOT_MET, ali@25: "Software cannot be installed because the following requirements " ali@25: "were not met:\n\n%s",unsatisfied); ali@25: plover_transaction_helper_set_error(helper,error, ali@25: "Software installation failed"); ali@25: } ali@25: else ali@25: plover_transaction_helper_set_error(helper,error, ali@25: "Software installation failed"); ali@25: g_error_free(error); ali@25: } ali@25: plover_vector_free(selected_packages); ali@25: g_object_unref(upstream); ali@25: plover_transaction_helper_present(helper); ali@25: return TRUE; ali@25: } ali@25: ali@25: static void install_icons(void) ali@25: { ali@25: GtkIconSet *icon_set; ali@25: plover_icons_add_to_stock("mimetypes",LOGO_NAME); ali@25: icon_set=gtk_icon_factory_lookup_default(LOGO_NAME); ali@25: gtk_window_set_default_icon_name(LOGO_NAME); ali@25: } ali@25: ali@25: int main(int argc,char **argv) ali@25: { ali@25: GError *err=0; ali@25: gchar *install_path=NULL; ali@25: PloverPackageSet *set; ali@25: #if 0 ali@30: gsize len; ali@30: gchar *s,*t,*contents; ali@25: GSList *objects,*lnk; ali@25: #endif ali@25: GOptionEntry options[]={ ali@25: {"install",0,0,G_OPTION_ARG_FILENAME,&install_path, ali@25: "Install an RPM","path"}, ali@25: {NULL} ali@25: }; ali@25: #ifdef WIN32 ali@25: /* ali@25: * plover-open is normally a GUI application, but rpm scripts may well ali@25: * call console applications and it looks ugly if console windows keep ali@25: * popping up. Avoid this by allocating our own console and hiding it. ali@25: * Note: ali@25: * - If plover-open is a console application (typically for debugging), ali@25: * then skip this step. ali@25: * - Call ShowWindow twice to negate special handling on first call. ali@25: */ ali@25: if (!GetConsoleWindow()) ali@25: { ali@25: AllocConsole(); ali@25: ShowWindow(GetConsoleWindow(),SW_HIDE); ali@25: ShowWindow(GetConsoleWindow(),SW_HIDE); ali@25: } ali@25: #endif ali@31: plover_exception_handler_init(); ali@38: razor_set_lua_loader("posix",(void (*)())luaopen_posix); ali@38: razor_set_lua_loader("whelk",(void (*)())luaopen_whelk); ali@25: if (!gtk_init_with_args(&argc,&argv,NULL,options,NULL,&err)) ali@25: { ali@25: g_printerr("%s\n",err->message); ali@25: exit(1); ali@25: } ali@25: install_icons(); ali@25: #if 0 ali@25: ui=gtk_builder_new(); ali@25: if (!g_file_get_contents("plover-open.ui",&contents,&len,&err) && ali@25: g_error_matches(err,G_FILE_ERROR,G_FILE_ERROR_NOENT)) ali@25: { ali@25: #ifdef WIN32 ali@25: t=g_win32_get_package_installation_directory_of_module(NULL); ali@25: s=g_build_filename(t,"share","plover","plover-open.ui",NULL); ali@25: g_free(t); ali@25: #else ali@25: s=g_build_filename(PLOVER_DATADIR,"plover-open.ui",NULL); ali@25: #endif ali@25: g_clear_error(&err); ali@25: (void)g_file_get_contents(s,&contents,&len,&err); ali@25: g_free(s); ali@25: } ali@25: if (!err) ali@25: { ali@25: (void)gtk_builder_add_from_string(ui,contents,len,&err); ali@25: g_free(contents); ali@25: } ali@25: if (err) ali@25: { ali@25: g_error("%s",err->message); ali@25: exit(0); ali@25: } ali@25: gtk_builder_connect_signals(ui,NULL); ali@25: #endif ali@25: set=plover_package_set_new(); ali@25: (void)plover_package_set_open(set,"",TRUE,NULL); ali@25: if (install_path) ali@25: if (install(set,install_path)) ali@25: gtk_main(); ali@25: g_clear_object(&set); ali@25: #if 0 ali@25: objects=gtk_builder_get_objects(ui); ali@25: for(lnk=objects;lnk;lnk=lnk->next) ali@25: if (GTK_IS_WIDGET(lnk->data) && ali@25: gtk_widget_is_toplevel(GTK_WIDGET(lnk->data))) ali@25: gtk_widget_destroy(GTK_WIDGET(lnk->data)); ali@25: g_slist_free(objects); ali@25: g_clear_object(&ui); ali@25: #endif ali@25: g_free(install_path); ali@25: exit(0); ali@25: }