diff --git a/src/include/config.h.in b/src/include/config.h.in index 61b0a72..228c745 100644 --- a/src/include/config.h.in +++ b/src/include/config.h.in @@ -36,6 +36,9 @@ #undef PACKAGE_NAME #undef PACKAGE_VERSION #undef PACKAGE_RELEASE + #undef PRODUCT_NAME + #undef PACKAGE_DESCRIPTION + #undef DEFAULT_SESSION_NAME #undef APPLICATION_NAME diff --git a/src/include/pw3270.h b/src/include/pw3270.h index 0eb5858..e5c2679 100644 --- a/src/include/pw3270.h +++ b/src/include/pw3270.h @@ -62,7 +62,6 @@ LIB3270_EXPORT GtkWidget * pw3270_get_toplevel(void); - LIB3270_EXPORT gchar * pw3270_build_filename(GtkWidget *widget, const gchar *first_element, ...); LIB3270_EXPORT void pw3270_save_window_size(GtkWidget *widget, const gchar *name); LIB3270_EXPORT void pw3270_restore_window(GtkWidget *widget, const gchar *name); diff --git a/src/include/pw3270/plugin.h b/src/include/pw3270/plugin.h index abd072c..74412ae 100644 --- a/src/include/pw3270/plugin.h +++ b/src/include/pw3270/plugin.h @@ -47,7 +47,7 @@ LIB3270_EXPORT int pw3270_plugin_stop(GtkWidget *window, GtkWidget *terminal); // plugins - LIB3270_EXPORT void pw3270_load_plugins(const gchar *path); + LIB3270_EXPORT void pw3270_load_plugins(void); LIB3270_EXPORT void pw3270_unload_plugins(void); LIB3270_EXPORT void pw3270_start_plugins(GtkWidget *widget); diff --git a/src/pw3270/dialog.c b/src/pw3270/dialog.c index 7a67548..5e46fee 100644 --- a/src/pw3270/dialog.c +++ b/src/pw3270/dialog.c @@ -32,170 +32,11 @@ #include #include "private.h" #include + #include #include - /* - #ifdef _WIN32 - #include - - struct file { - OPENFILENAME ofn; - gboolean enabled; - char szName[260]; // buffer for file name - GtkFileChooserAction action; - BOOL ok; - }; - - - #endif // _WIN32 - */ - - /* - #if defined(HAVE_LIBSSL) - #include - #include - #endif - */ - -/*--[ Globals ]--------------------------------------------------------------------------------------*/ - -/* - static const struct _charset - { - const gchar *name; - const gchar *description; - } charset[] = - { - // http://en.wikipedia.org/wiki/Character_encoding - { "UTF-8", N_( "UTF-8" ) }, - { "ISO-8859-1", N_( "Western Europe (ISO 8859-1)" ) }, - { "CP1252", N_( "Windows Western languages (CP1252)" ) }, - - { NULL, NULL } - }; -*/ - /*--[ Implement ]------------------------------------------------------------------------------------*/ -/* - static void charset_changed(GtkComboBox *widget,gchar **encoding) - { - gchar *new_encoding = NULL; - -#if GTK_CHECK_VERSION(3,0,0) - - new_encoding = g_strdup(gtk_combo_box_get_active_id(GTK_COMBO_BOX(widget))); - -#else - - GValue value = { 0, }; - GtkTreeIter iter; - - if(!gtk_combo_box_get_active_iter(widget,&iter)) - return; - - gtk_tree_model_get_value(gtk_combo_box_get_model(widget),&iter,1,&value); - new_encoding = g_strdup(g_value_get_string(&value)); - -#endif - - if(!new_encoding) - return; - - trace("%s: %s->%s",__FUNCTION__,*encoding,new_encoding); - if(*encoding) - g_free(*encoding); - - *encoding = new_encoding; - } -*/ - - /* - static void add_option_menus(GtkWidget *widget, GtkAction *action, gchar **encoding) - { -#if GTK_CHECK_VERSION(3,0,0) - GtkWidget *box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL,6); -#else - GtkWidget *box = gtk_hbox_new(FALSE,6); -#endif // GTK(3,0,0) - - gchar *ptr = g_object_get_data(G_OBJECT(action),"charset"); - - if(ptr) - { - *encoding = g_strdup(ptr); - } - else - { - // Add charset options - GtkWidget * label = gtk_label_new_with_mnemonic (_("C_haracter Coding:")); - const gchar * scharset = NULL; -#if GTK_CHECK_VERSION(3,0,0) - GtkWidget * menu = gtk_combo_box_text_new(); -#else - GtkTreeModel * model = (GtkTreeModel *) gtk_list_store_new(2,G_TYPE_STRING,G_TYPE_STRING); - GtkWidget * menu = gtk_combo_box_new_with_model(model); - GtkCellRenderer * renderer = gtk_cell_renderer_text_new(); - GtkTreeIter iter; -#endif // GTK(3,0,0) - gchar * text; - int f; - int p = 0; - - g_get_charset(&scharset); - *encoding = g_strdup(scharset); - - text = g_strdup_printf(_("Current (%s)"),scharset); - -#if GTK_CHECK_VERSION(3,0,0) - - gtk_combo_box_text_insert(GTK_COMBO_BOX_TEXT(menu),p,scharset,text); - -#else - - gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(menu), renderer, TRUE); - gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(menu), renderer, "text", 0, NULL); - - gtk_list_store_append((GtkListStore *) model,&iter); - gtk_list_store_set((GtkListStore *) model, &iter, 0, text, 1, scharset, -1); - -#endif // GTK(3,0,0) - - g_free(text); - - gtk_combo_box_set_active(GTK_COMBO_BOX(menu),p++); - - for(f=0;charset[f].name;f++) - { - if(strcasecmp(scharset,charset[f].name)) - { -#if GTK_CHECK_VERSION(3,0,0) - gtk_combo_box_text_insert(GTK_COMBO_BOX_TEXT(menu),p++,charset[f].name,gettext(charset[f].description)); -#else - gtk_list_store_append((GtkListStore *) model,&iter); - gtk_list_store_set((GtkListStore *) model, &iter, 0, gettext(charset[f].description), 1, charset[f].name, -1); -#endif // GTK(3,0,0) - } - } - - - gtk_label_set_mnemonic_widget(GTK_LABEL(label), menu); - - gtk_box_pack_start(GTK_BOX(box),label,FALSE,FALSE,0); - - gtk_box_pack_start(GTK_BOX(box),menu,TRUE,TRUE,0); - - g_signal_connect(G_OBJECT(menu),"changed",G_CALLBACK(charset_changed),encoding); - - } - - - gtk_widget_show_all(box); - gtk_file_chooser_set_extra_widget(GTK_FILE_CHOOSER(widget),box); - - } - */ - void save_all_action(GtkAction *action, GtkWidget *widget) { v3270_save_all(widget,g_object_get_data(G_OBJECT(action),"filename"),NULL); @@ -211,43 +52,6 @@ v3270_save_copy(widget,g_object_get_data(G_OBJECT(action),"filename"),NULL); } - /* - static void paste_filename(GtkWidget *widget, const gchar *filename, const gchar *encoding) - { - GError *error = NULL; - gchar *text = NULL; - - if(!encoding) - g_get_charset(&encoding); - - trace("Loading \"%s\" encoding=%s",filename,encoding); - - if(!g_file_get_contents(filename,&text,NULL,&error)) - { - GtkWidget *popup = gtk_message_dialog_new_with_markup( - GTK_WINDOW(gtk_widget_get_toplevel(widget)), - GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_MESSAGE_ERROR,GTK_BUTTONS_CLOSE, - _( "Error loading %s" ),filename); - - gtk_window_set_title(GTK_WINDOW(popup),_("Can't load file")); - - gtk_message_dialog_format_secondary_markup(GTK_MESSAGE_DIALOG(popup),"%s",error->message); - g_error_free(error); - - gtk_dialog_run(GTK_DIALOG(popup)); - gtk_widget_destroy(popup); - - } - - if(text) - { - v3270_input_text(widget,text,encoding); - g_free(text); - } - - } - */ void paste_file_action(GtkAction *action, GtkWidget *widget) { const gchar * user_title = g_object_get_data(G_OBJECT(action),"title"); @@ -262,59 +66,6 @@ gtk_widget_destroy(dialog); - /* - const gchar * user_title = g_object_get_data(G_OBJECT(action),"title"); - const gchar * filename = g_object_get_data(G_OBJECT(action),"filename"); - gchar * encattr = NULL; - GtkWidget * dialog; - gchar * ptr; - const gchar * encoding = NULL; - - g_get_charset(&encoding); - - trace("Action %s activated on widget %p",gtk_action_get_name(action),widget); - - if(filename) - { - ptr = g_object_get_data(G_OBJECT(action),"charset"); - paste_filename(widget,filename,ptr); - return; - } - - dialog = gtk_file_chooser_dialog_new( gettext(user_title ? user_title : N_( "Paste text file contents" )), - GTK_WINDOW(gtk_widget_get_toplevel(widget)), - GTK_FILE_CHOOSER_ACTION_OPEN, - GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, - GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, - NULL ); - - add_option_menus(dialog, action, &encattr); - - ptr = get_string_from_config("load",gtk_action_get_name(action),""); - - if(*ptr) - gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(dialog),ptr); - else - gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog),g_get_user_special_dir(G_USER_DIRECTORY_DOCUMENTS)); - - g_free(ptr); - - if(gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) - { - ptr = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)); - - if(ptr) - { - set_string_to_config("load",gtk_action_get_name(action),"%s",ptr); - paste_filename(widget,ptr,encattr); - g_free(ptr); - } - } - gtk_widget_destroy(dialog); - - if(encattr) - g_free(encattr); - */ } G_GNUC_INTERNAL void about_dialog_action(GtkAction *action, GtkWidget *widget) @@ -342,10 +93,9 @@ "Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02111-1307 " "USA" ); - GtkAboutDialog * dialog = GTK_ABOUT_DIALOG(gtk_about_dialog_new()); - g_autofree gchar * text = g_strdup_printf("%s-logo.png",g_get_application_name()); - g_autofree gchar * filename = build_data_filename(text,NULL); - g_autofree gchar * info = g_strdup_printf(_( "3270 terminal emulator for GTK %d.%d" ),GTK_MAJOR_VERSION,GTK_MINOR_VERSION); + GtkAboutDialog * dialog = GTK_ABOUT_DIALOG(gtk_about_dialog_new()); + lib3270_autoptr(char) logo = lib3270_build_data_filename(G_STRINGIFY(PRODUCT_NAME) "-logo.png",NULL); + g_autofree gchar * info = g_strdup_printf(_( "3270 terminal emulator for GTK %d.%d" ),GTK_MAJOR_VERSION,GTK_MINOR_VERSION); g_autofree gchar * version = #ifdef PACKAGE_RELEASE @@ -359,10 +109,10 @@ gtk_window_set_transient_for(GTK_WINDOW(dialog),GTK_WINDOW(gtk_widget_get_toplevel(widget))); } - if(g_file_test(filename,G_FILE_TEST_EXISTS)) + if(g_file_test(logo,G_FILE_TEST_EXISTS)) { GError * error = NULL; - GdkPixbuf * pix = gdk_pixbuf_new_from_file(filename,&error); + GdkPixbuf * pix = gdk_pixbuf_new_from_file(logo,&error); gtk_about_dialog_set_logo(dialog,pix); @@ -372,13 +122,13 @@ } else { - g_warning("Can't load %s: %s",filename,error->message); + g_warning("Can't load %s: %s",logo,error->message); g_error_free(error); } } else { - g_message("Can't load %s: %s",filename,strerror(ENOENT)); + g_message("%s: %s",logo,strerror(ENOENT)); } diff --git a/src/pw3270/main.c b/src/pw3270/main.c index c992f49..26143c2 100644 --- a/src/pw3270/main.c +++ b/src/pw3270/main.c @@ -45,6 +45,7 @@ #endif // HAVE_GTKMAC #include +#include #include #include "v3270/accessible.h" #include @@ -104,7 +105,6 @@ static int initialize(void) static void toplevel_setup(GtkWindow *window) { - g_autofree gchar * name = g_strdup_printf("%s.png",g_get_application_name()); g_autofree gchar * role = g_strdup_printf("%s_top",g_get_application_name()); gtk_window_set_type_hint(window,GDK_WINDOW_TYPE_HINT_NORMAL); @@ -112,20 +112,65 @@ static void toplevel_setup(GtkWindow *window) gtk_window_set_role(window,role); #ifndef _WIN32 - // Set default icon - g_autofree gchar * filename = pw3270_build_filename(GTK_WIDGET(window),name,NULL); - if(g_file_test(filename,G_FILE_TEST_EXISTS)) + + size_t ix; + + static const gchar * icons[] = { - GError * error = NULL; + G_STRINGIFY(PRODUCT_NAME) ".svg", + G_STRINGIFY(PRODUCT_NAME) ".png", - trace("Loading default icon from %s",filename); + G_STRINGIFY(PACKAGE_NAME) ".svg", + G_STRINGIFY(PACKAGE_NAME) ".png" + }; + + for(ix = 0; ix < G_N_ELEMENTS(icons); ix++) + { + g_autofree gchar * filename = g_strconcat("/usr/share/pixmaps/",icons[ix],NULL); - if(!gtk_window_set_default_icon_from_file(filename,&error)) + if(g_file_test(filename,G_FILE_TEST_EXISTS)) { - g_warning("Error %s loading default icon from %s",error->message,filename); - g_error_free(error); + GError * error = NULL; + + trace("Loading default icon from %s",filename); + + if(!gtk_window_set_default_icon_from_file(filename,&error)) + { + g_warning("Error %s loading icon from %s",error->message,filename); + g_error_free(error); + } + + return; + } + } + + for(ix = 0; ix < G_N_ELEMENTS(icons); ix++) + { + lib3270_autoptr(char) filename = lib3270_build_data_filename(icons[ix], NULL); + + if(g_file_test(filename,G_FILE_TEST_EXISTS)) + { + GError * error = NULL; + + trace("Loading default icon from %s",filename); + + if(!gtk_window_set_default_icon_from_file(filename,&error)) + { + g_warning("Error %s loading icon from %s",error->message,filename); + g_error_free(error); + } + + return; + + } + + } + + // https://specifications.freedesktop.org/icon-naming-spec/icon-naming-spec-latest.html + gtk_window_set_default_icon_name("utilities-terminal"); + #endif // _WIN32 } @@ -171,7 +216,6 @@ static gboolean startup(GtkWidget *toplevel) int main(int argc, char *argv[]) { - const gchar * pluginpath = NULL; #ifdef APPLICATION_NAME const char * app_name = G_STRINGIFY(APPLICATION_NAME); #else @@ -219,12 +263,12 @@ int main(int argc, char *argv[]) #if defined(ENABLE_WINDOWS_REGISTRY) HKEY hMainKey; DWORD disp; - LSTATUS winRegError = RegCreateKeyEx(HKEY_CURRENT_USER,"SOFTWARE\\" PACKAGE_NAME,0,NULL,REG_OPTION_NON_VOLATILE,KEY_SET_VALUE,NULL,&hMainKey,&disp); + LSTATUS winRegError = RegCreateKeyEx(HKEY_CURRENT_USER,"SOFTWARE\\" G_STRINGIFY(PRODUCT_NAME),0,NULL,REG_OPTION_NON_VOLATILE,KEY_SET_VALUE,NULL,&hMainKey,&disp); if(winRegError == ERROR_SUCCESS) { HKEY hKey; - winRegError = RegCreateKeyEx(HKEY_CURRENT_USER,"SOFTWARE\\" PACKAGE_NAME "\\application",0,NULL,REG_OPTION_NON_VOLATILE,KEY_SET_VALUE,NULL,&hKey,&disp); + winRegError = RegCreateKeyEx(HKEY_CURRENT_USER,"SOFTWARE\\" G_STRINGIFY(PRODUCT_NAME) "\\application",0,NULL,REG_OPTION_NON_VOLATILE,KEY_SET_VALUE,NULL,&hKey,&disp); if(winRegError == ERROR_SUCCESS) { const struct _versions @@ -252,7 +296,7 @@ int main(int argc, char *argv[]) #ifdef DEBUG else { - g_error("Can't open HKCU\\SOFTWARE\\" PACKAGE_NAME ": %s", lib3270_win32_strerror(winRegError)); + g_error("Can't open HKCU\\SOFTWARE\\" G_STRINGIFY(PRODUCT_NAME) ": %s", lib3270_win32_strerror(winRegError)); } #endif RegCloseKey(hMainKey); @@ -260,7 +304,7 @@ int main(int argc, char *argv[]) #ifdef DEBUG else { - g_error("Can't open HKCU\\SOFTWARE\\" PACKAGE_NAME "\\application: %s",lib3270_win32_strerror(winRegError)); + g_error("Can't open HKCU\\SOFTWARE\\" G_STRINGIFY(PRODUCT_NAME) "\\application: %s",lib3270_win32_strerror(winRegError)); } #endif @@ -308,7 +352,6 @@ int main(int argc, char *argv[]) { "model", 'M', 0, G_OPTION_ARG_STRING, &model, N_( "The model of 3270 display to be emulated" ), NULL }, { "oversize", 'O', 0, G_OPTION_ARG_STRING, &oversize, N_( "Makes the screen larger than the default for the chosen model number." ), NULL }, { "autodisconnect", 'D', 0, G_OPTION_ARG_INT, &timer, N_( "Minutes for auto-disconnect" ), 0 }, - { "pluginpath", 'P', 0, G_OPTION_ARG_STRING, &pluginpath, N_( "Path for plugin files" ), NULL }, #ifdef APPLICATION_NAME { "application-name", 'A', 0, G_OPTION_ARG_STRING, &app_name, N_( "Application name" ), G_STRINGIFY(APPLICATION_NAME) }, @@ -453,7 +496,7 @@ int main(int argc, char *argv[]) pw3270_set_string(toplevel,"application","session",session_name); #endif // _WIN32 - pw3270_load_plugins(pluginpath); + pw3270_load_plugins(); if(toggleset) { diff --git a/src/pw3270/plugin.c b/src/pw3270/plugin.c index a0b6996..a28d833 100644 --- a/src/pw3270/plugin.c +++ b/src/pw3270/plugin.c @@ -39,21 +39,27 @@ /*--[ Implement ]------------------------------------------------------------------------------------*/ - static void load(const gchar *path) + LIB3270_EXPORT void pw3270_load_plugins(void) { - GDir * dir; - const gchar * name; - GError * err = NULL; - GList * lst = NULL; #ifdef _WIN32 UINT errorMode; + lib3270_autoptr(char) path = lib3270_build_data_filename("plugins") +#else + const gchar * path = LIBDIR G_DIR_SEPARATOR_S G_STRINGIFY(PRODUCT_NAME) "-plugins"; #endif // _WIN32 + GDir * dir; + const gchar * name; + GError * err = NULL; + GList * lst = NULL; trace("Loading plugins from %s",path); if(!g_file_test(path,G_FILE_TEST_IS_DIR)) + { + g_warning("Can't load plugins from %s",path); return; + } dir = g_dir_open(path,0,&err); if(!dir) @@ -159,6 +165,7 @@ } + /* LIB3270_EXPORT void pw3270_load_plugins(const gchar *p) { if(p) @@ -221,6 +228,7 @@ #endif } + */ LIB3270_EXPORT void pw3270_start_plugins(GtkWidget *widget) { -- libgit2 0.21.2