Commit 32194bff16c520ed79d1a39531680abcacf313aa
1 parent
4ff79de5
Exists in
master
and in
3 other branches
Implementing creation of windows shortcut.
Showing
3 changed files
with
130 additions
and
21 deletions
Show diff stats
src/objects/application/actions/about.c
| ... | ... | @@ -135,7 +135,9 @@ |
| 135 | 135 | |
| 136 | 136 | gtk_about_dialog_set_copyright(dialog, "Copyright © 2008 Banco do Brasil S.A." ); |
| 137 | 137 | |
| 138 | - lib3270_autoptr(char) license = lib3270_build_data_filename(NC_("LicenseFileName","LICENSE"),NULL); | |
| 138 | +#ifdef _WIN32 | |
| 139 | + | |
| 140 | + lib3270_autoptr(char) license = lib3270_build_data_filename(_("LICENSE"),NULL); | |
| 139 | 141 | |
| 140 | 142 | if(g_file_test(license, G_FILE_TEST_IS_REGULAR)) { |
| 141 | 143 | |
| ... | ... | @@ -146,9 +148,13 @@ |
| 146 | 148 | gtk_about_dialog_set_wrap_license(dialog,TRUE); |
| 147 | 149 | } |
| 148 | 150 | |
| 151 | + } else { | |
| 152 | + gtk_about_dialog_set_license_type(dialog,GTK_LICENSE_GPL_3_0); | |
| 149 | 153 | } |
| 150 | 154 | |
| 155 | +#else | |
| 151 | 156 | gtk_about_dialog_set_license_type(dialog,GTK_LICENSE_GPL_3_0); |
| 157 | +#endif // _WIN32 | |
| 152 | 158 | |
| 153 | 159 | // gtk_about_dialog_set_website(dialog,NC_("ProjectURL","https://portal.softwarepublico.gov.br/social/pw3270/")); |
| 154 | 160 | // gtk_about_dialog_set_website_label(dialog,NC_("ProjectURLLabel","Brazilian Public Software Portal" )); | ... | ... |
src/objects/linux/savedesktopicon.c
| ... | ... | @@ -63,6 +63,7 @@ X-Desktop-File-Install-Version=0.23 |
| 63 | 63 | const gchar * key; |
| 64 | 64 | const gchar * label; |
| 65 | 65 | const gchar * tooltip; |
| 66 | + const gchar * default_value; | |
| 66 | 67 | gint width; |
| 67 | 68 | // gint n_chars; |
| 68 | 69 | |
| ... | ... | @@ -71,28 +72,27 @@ X-Desktop-File-Install-Version=0.23 |
| 71 | 72 | { |
| 72 | 73 | .label = N_("File name"), |
| 73 | 74 | .width = 40, |
| 74 | -// .n_chars = 40 | |
| 75 | 75 | }, |
| 76 | 76 | |
| 77 | 77 | { |
| 78 | 78 | .key = "Name", |
| 79 | 79 | .label = N_("Launcher name"), |
| 80 | + .default_value = G_STRINGIFY(PRODUCT_NAME), | |
| 80 | 81 | .width = 20, |
| 81 | -// .n_chars = 128 | |
| 82 | 82 | }, |
| 83 | 83 | |
| 84 | 84 | { |
| 85 | 85 | .key = "GenericName", |
| 86 | 86 | .label = N_("Generic name"), |
| 87 | + .default_value = G_STRINGIFY(PRODUCT_NAME), | |
| 87 | 88 | .width = 20, |
| 88 | -// .n_chars = 128 | |
| 89 | 89 | }, |
| 90 | 90 | |
| 91 | 91 | { |
| 92 | 92 | .key = "Comment", |
| 93 | 93 | .label = N_("Comment"), |
| 94 | + .default_value = N_("IBM 3270 Terminal emulator"), | |
| 94 | 95 | .width = 30, |
| 95 | -// .n_chars = 128 | |
| 96 | 96 | } |
| 97 | 97 | |
| 98 | 98 | }; |
| ... | ... | @@ -162,6 +162,10 @@ X-Desktop-File-Install-Version=0.23 |
| 162 | 162 | inputs[ix] = gtk_entry_new(); |
| 163 | 163 | debug("inputs[%u]=%p",(unsigned int) ix, inputs[ix]); |
| 164 | 164 | |
| 165 | + if(entries[ix].default_value) { | |
| 166 | + gtk_entry_set_text(GTK_ENTRY(inputs[ix]),gettext(entries[ix].default_value)); | |
| 167 | + } | |
| 168 | + | |
| 165 | 169 | gtk_entry_set_width_chars(GTK_ENTRY(inputs[ix]),entries[ix].width); |
| 166 | 170 | // gtk_entry_set_max_width_chars(GTK_ENTRY(inputs[ix]),entries[ix].n_chars); |
| 167 | 171 | gtk_widget_set_hexpand(inputs[ix],FALSE); |
| ... | ... | @@ -175,11 +179,13 @@ X-Desktop-File-Install-Version=0.23 |
| 175 | 179 | |
| 176 | 180 | gtk_entry_set_text(GTK_ENTRY(inputs[0]),filename); |
| 177 | 181 | |
| 182 | + /* | |
| 178 | 183 | gtk_entry_set_placeholder_text(GTK_ENTRY(inputs[1]),G_STRINGIFY(PRODUCT_NAME)); |
| 179 | 184 | gtk_entry_set_text(GTK_ENTRY(inputs[1]),G_STRINGIFY(PRODUCT_NAME)); |
| 180 | 185 | |
| 181 | 186 | gtk_entry_set_placeholder_text(GTK_ENTRY(inputs[2]),G_STRINGIFY(PRODUCT_NAME)); |
| 182 | 187 | gtk_entry_set_text(GTK_ENTRY(inputs[2]),G_STRINGIFY(PRODUCT_NAME)); |
| 188 | + */ | |
| 183 | 189 | |
| 184 | 190 | gtk_entry_set_placeholder_text(GTK_ENTRY(inputs[3]),v3270_get_url(terminal)); |
| 185 | 191 | gtk_entry_set_text(GTK_ENTRY(inputs[3]),v3270_get_url(terminal)); | ... | ... |
src/objects/windows/savedesktopicon.c
| ... | ... | @@ -37,8 +37,14 @@ |
| 37 | 37 | * |
| 38 | 38 | */ |
| 39 | 39 | |
| 40 | +// #include <stdafx.h> | |
| 40 | 41 | #include <winsock2.h> |
| 41 | 42 | #include <windows.h> |
| 43 | + #include <winnls.h> | |
| 44 | + #include <shobjidl.h> | |
| 45 | + #include <objbase.h> | |
| 46 | + #include <objidl.h> | |
| 47 | + #include <shlguid.h> | |
| 42 | 48 | |
| 43 | 49 | #include <v3270.h> |
| 44 | 50 | #include <pw3270.h> |
| ... | ... | @@ -59,12 +65,12 @@ |
| 59 | 65 | } entries[] = { |
| 60 | 66 | |
| 61 | 67 | { |
| 62 | - .label = N_("File name"), | |
| 68 | + .label = N_("Launcher name"), | |
| 63 | 69 | .width = 40, |
| 64 | 70 | }, |
| 65 | 71 | |
| 66 | 72 | { |
| 67 | - .label = N_("Launcher name"), | |
| 73 | + .label = N_("Description"), | |
| 68 | 74 | .width = 20, |
| 69 | 75 | } |
| 70 | 76 | |
| ... | ... | @@ -122,9 +128,6 @@ |
| 122 | 128 | gtk_grid_set_row_spacing(GTK_GRID(grid),6); |
| 123 | 129 | gtk_grid_set_column_spacing(GTK_GRID(grid),12); |
| 124 | 130 | |
| 125 | - // https://developer.gnome.org/hig/stable/visual-layout.html.en | |
| 126 | - // gtk_box_set_spacing(GTK_BOX(content_area),18); | |
| 127 | - | |
| 128 | 131 | for(ix = 0; ix < G_N_ELEMENTS(entries); ix++) { |
| 129 | 132 | |
| 130 | 133 | GtkWidget * label = gtk_label_new(gettext(entries[ix].label)); |
| ... | ... | @@ -135,7 +138,6 @@ |
| 135 | 138 | debug("inputs[%u]=%p",(unsigned int) ix, inputs[ix]); |
| 136 | 139 | |
| 137 | 140 | gtk_entry_set_width_chars(GTK_ENTRY(inputs[ix]),entries[ix].width); |
| 138 | -// gtk_entry_set_max_width_chars(GTK_ENTRY(inputs[ix]),entries[ix].n_chars); | |
| 139 | 141 | gtk_widget_set_hexpand(inputs[ix],FALSE); |
| 140 | 142 | gtk_widget_set_vexpand(inputs[ix],FALSE); |
| 141 | 143 | |
| ... | ... | @@ -143,32 +145,127 @@ |
| 143 | 145 | |
| 144 | 146 | } |
| 145 | 147 | |
| 146 | - /* | |
| 148 | + { | |
| 149 | + gchar * filename = g_strdup_printf( | |
| 150 | + "%s\\" G_STRINGIFY(PRODUCT_NAME) ".lnk", | |
| 151 | + g_get_user_special_dir(G_USER_DIRECTORY_DESKTOP) | |
| 152 | + ); | |
| 147 | 153 | |
| 148 | - gtk_entry_set_text(GTK_ENTRY(inputs[0]),filename); | |
| 154 | + size_t ix = 0; | |
| 149 | 155 | |
| 150 | - gtk_entry_set_placeholder_text(GTK_ENTRY(inputs[1]),G_STRINGIFY(PRODUCT_NAME)); | |
| 151 | - gtk_entry_set_text(GTK_ENTRY(inputs[1]),G_STRINGIFY(PRODUCT_NAME)); | |
| 156 | + while(g_file_test(filename,G_FILE_TEST_EXISTS)) { | |
| 152 | 157 | |
| 153 | - gtk_entry_set_placeholder_text(GTK_ENTRY(inputs[2]),G_STRINGIFY(PRODUCT_NAME)); | |
| 154 | - gtk_entry_set_text(GTK_ENTRY(inputs[2]),G_STRINGIFY(PRODUCT_NAME)); | |
| 158 | + g_free(filename); | |
| 159 | + filename = g_strdup_printf( | |
| 160 | + "%s\\" G_STRINGIFY(PRODUCT_NAME) "%u.lnk", | |
| 161 | + g_get_user_special_dir(G_USER_DIRECTORY_DESKTOP), | |
| 162 | + (unsigned int) ++ix | |
| 163 | + ); | |
| 155 | 164 | |
| 156 | - gtk_entry_set_placeholder_text(GTK_ENTRY(inputs[3]),v3270_get_url(terminal)); | |
| 157 | - gtk_entry_set_text(GTK_ENTRY(inputs[3]),v3270_get_url(terminal)); | |
| 158 | - gtk_entry_set_input_hints(GTK_ENTRY(inputs[3]),GTK_INPUT_HINT_SPELLCHECK); | |
| 165 | + } | |
| 159 | 166 | |
| 160 | - */ | |
| 167 | + gtk_entry_set_text(GTK_ENTRY(inputs[0]),filename); | |
| 168 | + g_free(filename); | |
| 169 | + } | |
| 161 | 170 | |
| 162 | 171 | gtk_widget_show_all(GTK_WIDGET(grid)); |
| 163 | 172 | return dialog; |
| 164 | 173 | } |
| 165 | 174 | |
| 175 | + static HRESULT CreateShortCut(LPSTR pszTargetfile, LPSTR pszTargetargs, LPSTR pszLinkfile, LPSTR pszDescription, int iShowmode, LPSTR pszCurdir, LPSTR pszIconfile, int iIconindex) { | |
| 176 | + | |
| 177 | + // https://www.codeproject.com/Articles/11467/How-to-create-short-cuts-link-files | |
| 178 | + IShellLink* pShellLink; // IShellLink object pointer | |
| 179 | + IPersistFile* pPersistFile; // IPersistFile object pointer | |
| 180 | + WORD wszLinkfile[MAX_PATH]; // pszLinkfile as Unicode string | |
| 181 | + int iWideCharsWritten; // Number of wide characters written | |
| 182 | + | |
| 183 | + HRESULT hRes = | |
| 184 | + CoCreateInstance( | |
| 185 | + &CLSID_ShellLink, // predefined CLSID of the IShellLink object | |
| 186 | + NULL, // pointer to parent interface if part of aggregate | |
| 187 | + CLSCTX_INPROC_SERVER, // caller and called code are in same process | |
| 188 | + &IID_IShellLink, // predefined interface of the IShellLink object | |
| 189 | + (void **) &pShellLink); // Returns a pointer to the IShellLink object | |
| 190 | + | |
| 191 | + if(!SUCCEEDED(hRes)) { | |
| 192 | + return hRes; | |
| 193 | + } | |
| 194 | + | |
| 195 | + if(pszTargetfile && strlen(pszTargetfile)) { | |
| 196 | + hRes = pShellLink->lpVtbl->SetPath(pShellLink,pszTargetfile); | |
| 197 | + } else { | |
| 198 | + char filename[MAX_PATH+1]; | |
| 199 | + memset(filename,0,MAX_PATH+1); | |
| 200 | + GetModuleFileName(NULL,filename,MAX_PATH); | |
| 201 | + hRes = pShellLink->lpVtbl->SetPath(pShellLink,filename); | |
| 202 | + } | |
| 203 | + | |
| 204 | + if(pszTargetargs) { | |
| 205 | + hRes = pShellLink->lpVtbl->SetArguments(pShellLink,pszTargetargs); | |
| 206 | + } else { | |
| 207 | + hRes = pShellLink->lpVtbl->SetArguments(pShellLink,""); | |
| 208 | + } | |
| 209 | + | |
| 210 | + if(pszDescription && strlen(pszDescription) > 0) { | |
| 211 | + hRes = pShellLink->lpVtbl->SetDescription(pShellLink,pszDescription); | |
| 212 | + } else { | |
| 213 | + hRes = pShellLink->lpVtbl->SetDescription(pShellLink,_("IBM 3270 Terminal emulator")); | |
| 214 | + } | |
| 215 | + | |
| 216 | + if(iShowmode > 0) { | |
| 217 | + hRes = pShellLink->lpVtbl->SetShowCmd(pShellLink,iShowmode); | |
| 218 | + } | |
| 219 | + | |
| 220 | + if(pszCurdir && strlen(pszCurdir) > 0) { | |
| 221 | + hRes = pShellLink->lpVtbl->SetWorkingDirectory(pShellLink,pszCurdir); | |
| 222 | + } else { | |
| 223 | + g_autofree gchar * appdir = g_win32_get_package_installation_directory_of_module(NULL); | |
| 224 | + hRes = pShellLink->lpVtbl->SetWorkingDirectory(pShellLink,appdir); | |
| 225 | + } | |
| 226 | + | |
| 227 | + if(pszIconfile && strlen(pszIconfile) > 0 && iIconindex >= 0) { | |
| 228 | + hRes = pShellLink->lpVtbl->SetIconLocation(pShellLink, pszIconfile, iIconindex); | |
| 229 | + } | |
| 230 | + | |
| 231 | + // Use the IPersistFile object to save the shell link | |
| 232 | + hRes = pShellLink->lpVtbl->QueryInterface( | |
| 233 | + pShellLink, // existing IShellLink object | |
| 234 | + &IID_IPersistFile, // pre-defined interface of the IPersistFile object | |
| 235 | + (void **) &pPersistFile); // returns a pointer to the IPersistFile object | |
| 236 | + | |
| 237 | + | |
| 238 | + if(SUCCEEDED(hRes)){ | |
| 239 | + iWideCharsWritten = MultiByteToWideChar(CP_ACP, 0, pszLinkfile, -1, wszLinkfile, MAX_PATH); | |
| 240 | + hRes = pPersistFile->lpVtbl->Save(pPersistFile,wszLinkfile, TRUE); | |
| 241 | + pPersistFile->lpVtbl->Release(pPersistFile); | |
| 242 | + } | |
| 243 | + | |
| 244 | + pShellLink->lpVtbl->Release(pShellLink); | |
| 245 | + | |
| 246 | + return hRes; | |
| 247 | + } | |
| 248 | + | |
| 166 | 249 | void response(GtkWidget *dialog, gint response_id, GtkWidget *terminal) { |
| 167 | 250 | |
| 168 | 251 | debug("%s(%d)",__FUNCTION__,response_id); |
| 169 | 252 | |
| 170 | 253 | if(response_id == GTK_RESPONSE_APPLY) { |
| 171 | 254 | |
| 255 | + // Save desktop icon | |
| 256 | + GtkWidget ** inputs = g_object_get_data(G_OBJECT(dialog),"inputs"); | |
| 257 | + | |
| 258 | + HRESULT hRes = CreateShortCut( | |
| 259 | + NULL, // LPSTR pszTargetfile, | |
| 260 | + v3270_get_session_filename(terminal), // LPSTR pszTargetargs, | |
| 261 | + gtk_entry_get_text(GTK_ENTRY(inputs[0])), // LPSTR pszLinkfile, | |
| 262 | + gtk_entry_get_text(GTK_ENTRY(inputs[1])), //LPSTR pszDescription, | |
| 263 | + 0, | |
| 264 | + NULL, | |
| 265 | + NULL, | |
| 266 | + 0 | |
| 267 | + ); | |
| 268 | + | |
| 172 | 269 | } |
| 173 | 270 | |
| 174 | 271 | gtk_widget_destroy(dialog); | ... | ... |