From 32194bff16c520ed79d1a39531680abcacf313aa Mon Sep 17 00:00:00 2001 From: Perry Werneck Date: Sat, 12 Sep 2020 09:46:35 -0300 Subject: [PATCH] Implementing creation of windows shortcut. --- src/objects/application/actions/about.c | 8 +++++++- src/objects/linux/savedesktopicon.c | 14 ++++++++++---- src/objects/windows/savedesktopicon.c | 129 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------- 3 files changed, 130 insertions(+), 21 deletions(-) diff --git a/src/objects/application/actions/about.c b/src/objects/application/actions/about.c index 0930910..1cddd7e 100644 --- a/src/objects/application/actions/about.c +++ b/src/objects/application/actions/about.c @@ -135,7 +135,9 @@ gtk_about_dialog_set_copyright(dialog, "Copyright © 2008 Banco do Brasil S.A." ); - lib3270_autoptr(char) license = lib3270_build_data_filename(NC_("LicenseFileName","LICENSE"),NULL); +#ifdef _WIN32 + + lib3270_autoptr(char) license = lib3270_build_data_filename(_("LICENSE"),NULL); if(g_file_test(license, G_FILE_TEST_IS_REGULAR)) { @@ -146,9 +148,13 @@ gtk_about_dialog_set_wrap_license(dialog,TRUE); } + } else { + gtk_about_dialog_set_license_type(dialog,GTK_LICENSE_GPL_3_0); } +#else gtk_about_dialog_set_license_type(dialog,GTK_LICENSE_GPL_3_0); +#endif // _WIN32 // gtk_about_dialog_set_website(dialog,NC_("ProjectURL","https://portal.softwarepublico.gov.br/social/pw3270/")); // gtk_about_dialog_set_website_label(dialog,NC_("ProjectURLLabel","Brazilian Public Software Portal" )); diff --git a/src/objects/linux/savedesktopicon.c b/src/objects/linux/savedesktopicon.c index 5fc54ae..162755f 100644 --- a/src/objects/linux/savedesktopicon.c +++ b/src/objects/linux/savedesktopicon.c @@ -63,6 +63,7 @@ X-Desktop-File-Install-Version=0.23 const gchar * key; const gchar * label; const gchar * tooltip; + const gchar * default_value; gint width; // gint n_chars; @@ -71,28 +72,27 @@ X-Desktop-File-Install-Version=0.23 { .label = N_("File name"), .width = 40, -// .n_chars = 40 }, { .key = "Name", .label = N_("Launcher name"), + .default_value = G_STRINGIFY(PRODUCT_NAME), .width = 20, -// .n_chars = 128 }, { .key = "GenericName", .label = N_("Generic name"), + .default_value = G_STRINGIFY(PRODUCT_NAME), .width = 20, -// .n_chars = 128 }, { .key = "Comment", .label = N_("Comment"), + .default_value = N_("IBM 3270 Terminal emulator"), .width = 30, -// .n_chars = 128 } }; @@ -162,6 +162,10 @@ X-Desktop-File-Install-Version=0.23 inputs[ix] = gtk_entry_new(); debug("inputs[%u]=%p",(unsigned int) ix, inputs[ix]); + if(entries[ix].default_value) { + gtk_entry_set_text(GTK_ENTRY(inputs[ix]),gettext(entries[ix].default_value)); + } + gtk_entry_set_width_chars(GTK_ENTRY(inputs[ix]),entries[ix].width); // gtk_entry_set_max_width_chars(GTK_ENTRY(inputs[ix]),entries[ix].n_chars); gtk_widget_set_hexpand(inputs[ix],FALSE); @@ -175,11 +179,13 @@ X-Desktop-File-Install-Version=0.23 gtk_entry_set_text(GTK_ENTRY(inputs[0]),filename); + /* gtk_entry_set_placeholder_text(GTK_ENTRY(inputs[1]),G_STRINGIFY(PRODUCT_NAME)); gtk_entry_set_text(GTK_ENTRY(inputs[1]),G_STRINGIFY(PRODUCT_NAME)); gtk_entry_set_placeholder_text(GTK_ENTRY(inputs[2]),G_STRINGIFY(PRODUCT_NAME)); gtk_entry_set_text(GTK_ENTRY(inputs[2]),G_STRINGIFY(PRODUCT_NAME)); + */ gtk_entry_set_placeholder_text(GTK_ENTRY(inputs[3]),v3270_get_url(terminal)); gtk_entry_set_text(GTK_ENTRY(inputs[3]),v3270_get_url(terminal)); diff --git a/src/objects/windows/savedesktopicon.c b/src/objects/windows/savedesktopicon.c index a8df662..260d4b2 100644 --- a/src/objects/windows/savedesktopicon.c +++ b/src/objects/windows/savedesktopicon.c @@ -37,8 +37,14 @@ * */ +// #include #include #include + #include + #include + #include + #include + #include #include #include @@ -59,12 +65,12 @@ } entries[] = { { - .label = N_("File name"), + .label = N_("Launcher name"), .width = 40, }, { - .label = N_("Launcher name"), + .label = N_("Description"), .width = 20, } @@ -122,9 +128,6 @@ gtk_grid_set_row_spacing(GTK_GRID(grid),6); gtk_grid_set_column_spacing(GTK_GRID(grid),12); - // https://developer.gnome.org/hig/stable/visual-layout.html.en - // gtk_box_set_spacing(GTK_BOX(content_area),18); - for(ix = 0; ix < G_N_ELEMENTS(entries); ix++) { GtkWidget * label = gtk_label_new(gettext(entries[ix].label)); @@ -135,7 +138,6 @@ debug("inputs[%u]=%p",(unsigned int) ix, inputs[ix]); gtk_entry_set_width_chars(GTK_ENTRY(inputs[ix]),entries[ix].width); -// gtk_entry_set_max_width_chars(GTK_ENTRY(inputs[ix]),entries[ix].n_chars); gtk_widget_set_hexpand(inputs[ix],FALSE); gtk_widget_set_vexpand(inputs[ix],FALSE); @@ -143,32 +145,127 @@ } - /* + { + gchar * filename = g_strdup_printf( + "%s\\" G_STRINGIFY(PRODUCT_NAME) ".lnk", + g_get_user_special_dir(G_USER_DIRECTORY_DESKTOP) + ); - gtk_entry_set_text(GTK_ENTRY(inputs[0]),filename); + size_t ix = 0; - gtk_entry_set_placeholder_text(GTK_ENTRY(inputs[1]),G_STRINGIFY(PRODUCT_NAME)); - gtk_entry_set_text(GTK_ENTRY(inputs[1]),G_STRINGIFY(PRODUCT_NAME)); + while(g_file_test(filename,G_FILE_TEST_EXISTS)) { - gtk_entry_set_placeholder_text(GTK_ENTRY(inputs[2]),G_STRINGIFY(PRODUCT_NAME)); - gtk_entry_set_text(GTK_ENTRY(inputs[2]),G_STRINGIFY(PRODUCT_NAME)); + g_free(filename); + filename = g_strdup_printf( + "%s\\" G_STRINGIFY(PRODUCT_NAME) "%u.lnk", + g_get_user_special_dir(G_USER_DIRECTORY_DESKTOP), + (unsigned int) ++ix + ); - gtk_entry_set_placeholder_text(GTK_ENTRY(inputs[3]),v3270_get_url(terminal)); - gtk_entry_set_text(GTK_ENTRY(inputs[3]),v3270_get_url(terminal)); - gtk_entry_set_input_hints(GTK_ENTRY(inputs[3]),GTK_INPUT_HINT_SPELLCHECK); + } - */ + gtk_entry_set_text(GTK_ENTRY(inputs[0]),filename); + g_free(filename); + } gtk_widget_show_all(GTK_WIDGET(grid)); return dialog; } + static HRESULT CreateShortCut(LPSTR pszTargetfile, LPSTR pszTargetargs, LPSTR pszLinkfile, LPSTR pszDescription, int iShowmode, LPSTR pszCurdir, LPSTR pszIconfile, int iIconindex) { + + // https://www.codeproject.com/Articles/11467/How-to-create-short-cuts-link-files + IShellLink* pShellLink; // IShellLink object pointer + IPersistFile* pPersistFile; // IPersistFile object pointer + WORD wszLinkfile[MAX_PATH]; // pszLinkfile as Unicode string + int iWideCharsWritten; // Number of wide characters written + + HRESULT hRes = + CoCreateInstance( + &CLSID_ShellLink, // predefined CLSID of the IShellLink object + NULL, // pointer to parent interface if part of aggregate + CLSCTX_INPROC_SERVER, // caller and called code are in same process + &IID_IShellLink, // predefined interface of the IShellLink object + (void **) &pShellLink); // Returns a pointer to the IShellLink object + + if(!SUCCEEDED(hRes)) { + return hRes; + } + + if(pszTargetfile && strlen(pszTargetfile)) { + hRes = pShellLink->lpVtbl->SetPath(pShellLink,pszTargetfile); + } else { + char filename[MAX_PATH+1]; + memset(filename,0,MAX_PATH+1); + GetModuleFileName(NULL,filename,MAX_PATH); + hRes = pShellLink->lpVtbl->SetPath(pShellLink,filename); + } + + if(pszTargetargs) { + hRes = pShellLink->lpVtbl->SetArguments(pShellLink,pszTargetargs); + } else { + hRes = pShellLink->lpVtbl->SetArguments(pShellLink,""); + } + + if(pszDescription && strlen(pszDescription) > 0) { + hRes = pShellLink->lpVtbl->SetDescription(pShellLink,pszDescription); + } else { + hRes = pShellLink->lpVtbl->SetDescription(pShellLink,_("IBM 3270 Terminal emulator")); + } + + if(iShowmode > 0) { + hRes = pShellLink->lpVtbl->SetShowCmd(pShellLink,iShowmode); + } + + if(pszCurdir && strlen(pszCurdir) > 0) { + hRes = pShellLink->lpVtbl->SetWorkingDirectory(pShellLink,pszCurdir); + } else { + g_autofree gchar * appdir = g_win32_get_package_installation_directory_of_module(NULL); + hRes = pShellLink->lpVtbl->SetWorkingDirectory(pShellLink,appdir); + } + + if(pszIconfile && strlen(pszIconfile) > 0 && iIconindex >= 0) { + hRes = pShellLink->lpVtbl->SetIconLocation(pShellLink, pszIconfile, iIconindex); + } + + // Use the IPersistFile object to save the shell link + hRes = pShellLink->lpVtbl->QueryInterface( + pShellLink, // existing IShellLink object + &IID_IPersistFile, // pre-defined interface of the IPersistFile object + (void **) &pPersistFile); // returns a pointer to the IPersistFile object + + + if(SUCCEEDED(hRes)){ + iWideCharsWritten = MultiByteToWideChar(CP_ACP, 0, pszLinkfile, -1, wszLinkfile, MAX_PATH); + hRes = pPersistFile->lpVtbl->Save(pPersistFile,wszLinkfile, TRUE); + pPersistFile->lpVtbl->Release(pPersistFile); + } + + pShellLink->lpVtbl->Release(pShellLink); + + return hRes; + } + void response(GtkWidget *dialog, gint response_id, GtkWidget *terminal) { debug("%s(%d)",__FUNCTION__,response_id); if(response_id == GTK_RESPONSE_APPLY) { + // Save desktop icon + GtkWidget ** inputs = g_object_get_data(G_OBJECT(dialog),"inputs"); + + HRESULT hRes = CreateShortCut( + NULL, // LPSTR pszTargetfile, + v3270_get_session_filename(terminal), // LPSTR pszTargetargs, + gtk_entry_get_text(GTK_ENTRY(inputs[0])), // LPSTR pszLinkfile, + gtk_entry_get_text(GTK_ENTRY(inputs[1])), //LPSTR pszDescription, + 0, + NULL, + NULL, + 0 + ); + } gtk_widget_destroy(dialog); -- libgit2 0.21.2