From 38bf070a4a3f866b604b07744760e94aaab03320 Mon Sep 17 00:00:00 2001 From: Simon Rozman Date: Fri, 29 Apr 2016 09:51:40 +0200 Subject: [PATCH] Auto-start on logon feature added (closes #8) --- ZRCola/ZRCola.fbp | 19 ++++++++++ ZRCola/locale/sl_SI.po | 82 ++++++++++++++++++++++++------------------ ZRCola/stdafx.h | 2 ++ ZRCola/zrcolafrm.cpp | 82 +++++++++++++++++++++++++++++++++--------- ZRCola/zrcolafrm.h | 4 ++- ZRCola/zrcolagui.cpp | 6 ++++ ZRCola/zrcolagui.h | 3 +- 7 files changed, 144 insertions(+), 54 deletions(-) diff --git a/ZRCola/ZRCola.fbp b/ZRCola/ZRCola.fbp index e714be4..48bf40e 100644 --- a/ZRCola/ZRCola.fbp +++ b/ZRCola/ZRCola.fbp @@ -137,6 +137,25 @@ &Program m_menuProgram protected + + + 0 + 1 + Start this program automatically on logon + wxID_AUTOSTART + wxITEM_CHECK + &Start on Logon + m_menuItemAutoStart + none + + + + + + + m_separatorProgram1 + none + 0 diff --git a/ZRCola/locale/sl_SI.po b/ZRCola/locale/sl_SI.po index f626042..cf37e1b 100644 --- a/ZRCola/locale/sl_SI.po +++ b/ZRCola/locale/sl_SI.po @@ -1,8 +1,8 @@ msgid "" msgstr "" "Project-Id-Version: ZRCola\n" -"POT-Creation-Date: 2016-04-23 22:20+0200\n" -"PO-Revision-Date: 2016-04-23 22:22+0200\n" +"POT-Creation-Date: 2016-04-29 09:43+0200\n" +"PO-Revision-Date: 2016-04-29 09:44+0200\n" "Last-Translator: Simon Rozman \n" "Language-Team: Amebis, d. o. o., Kamnik \n" "Language: sl_SI\n" @@ -17,12 +17,12 @@ msgstr "" "X-Poedit-KeywordsList: _\n" "X-Poedit-SearchPath-0: .\n" -#: zrcolafrm.cpp:70 +#: zrcolafrm.cpp:73 #, c-format msgid "Select %s language for decomposition" msgstr "Izberi jezik %s za razstavljanje" -#: zrcolafrm.cpp:81 +#: zrcolafrm.cpp:84 msgid "" "ZRCola keyboard shortcut Win+F5 could not be registered. Some functionality " "will not be available." @@ -30,11 +30,11 @@ msgstr "" "ZRColine bližnjice na tipkovnici Win+F5 ni mogoče registrirati. Nekaj " "funkcionalnosti ne bo na voljo." -#: zrcolafrm.cpp:81 zrcolafrm.cpp:83 +#: zrcolafrm.cpp:84 zrcolafrm.cpp:86 msgid "Warning" msgstr "Opozorilo" -#: zrcolafrm.cpp:83 +#: zrcolafrm.cpp:86 msgid "" "ZRCola keyboard shortcut Win+F6 could not be registered. Some functionality " "will not be available." @@ -42,7 +42,11 @@ msgstr "" "ZRColine bližnjice na tipkovnici Win+F6 ni mogoče registrirati. Nekaj " "funkcionalnosti ne bo na voljo." -#: zrcolafrm.cpp:205 +#: zrcolafrm.cpp:123 +msgid "Start ZRCola automatically on logon" +msgstr "Samodejno zaženi ZRColo ob prijavi" + +#: zrcolafrm.cpp:253 #, c-format msgid "" "ZRCola v%s\n" @@ -51,119 +55,127 @@ msgstr "" "ZRCola v%s\n" "Vse pravice pridržane 2015-%s Amebis" -#: zrcolafrm.cpp:205 +#: zrcolafrm.cpp:253 msgid "About ZRCola" msgstr "O ZRColi" #: zrcolagui.cpp:32 +msgid "&Start on Logon" +msgstr "Z&aženi ob prijavi" + +#: zrcolagui.cpp:32 +msgid "Start this program automatically on logon" +msgstr "Samodejno zaženi ta program ob prijavi" + +#: zrcolagui.cpp:38 msgid "E&xit" msgstr "I&zhod" -#: zrcolagui.cpp:32 +#: zrcolagui.cpp:38 msgid "Quit this program" msgstr "Zapri ta program" -#: zrcolagui.cpp:35 +#: zrcolagui.cpp:41 msgid "&Program" msgstr "&Program" -#: zrcolagui.cpp:68 +#: zrcolagui.cpp:74 msgid "Select &All" msgstr "Izberi &vse" -#: zrcolagui.cpp:68 +#: zrcolagui.cpp:74 msgid "Select all text" msgstr "Izberi celotno besedilo" -#: zrcolagui.cpp:74 +#: zrcolagui.cpp:80 msgid "&Send Composed" msgstr "Pošlji &sestavljeno" -#: zrcolagui.cpp:74 zrcolagui.cpp:125 +#: zrcolagui.cpp:80 zrcolagui.cpp:131 msgid "Send composed text to source window" msgstr "Pošlji sestavljeno besedilo izvornemu oknu" -#: zrcolagui.cpp:83 +#: zrcolagui.cpp:89 msgid "Send &Decomposed" msgstr "Pošlji &razstavljeno" -#: zrcolagui.cpp:83 zrcolagui.cpp:127 +#: zrcolagui.cpp:89 zrcolagui.cpp:133 msgid "Send decomposed text to source window" msgstr "Pošlji razstavljeno besedilo izvornemu oknu" -#: zrcolagui.cpp:92 +#: zrcolagui.cpp:98 msgid "Abort (De)composition" msgstr "Prekini raz/sestavljanje" -#: zrcolagui.cpp:92 +#: zrcolagui.cpp:98 msgid "Abort composition and return focus to source window" msgstr "Prekini sestavljanje in vrni fokus nazaj izvornemu oknu" -#: zrcolagui.cpp:101 +#: zrcolagui.cpp:107 msgid "&Language" msgstr "&Jezik" -#: zrcolagui.cpp:104 +#: zrcolagui.cpp:110 msgid "&Edit" msgstr "Ur&edi" -#: zrcolagui.cpp:111 +#: zrcolagui.cpp:117 msgid "&Help" msgstr "&Pomoč" -#: zrcolagui.cpp:117 +#: zrcolagui.cpp:123 msgid "Cut" msgstr "Izreži" -#: zrcolagui.cpp:117 +#: zrcolagui.cpp:123 msgid "Cut selection" msgstr "Izreži izbor" -#: zrcolagui.cpp:119 +#: zrcolagui.cpp:125 msgid "Copy" msgstr "Kopiraj" -#: zrcolagui.cpp:119 +#: zrcolagui.cpp:125 msgid "Copy selection" msgstr "Kopiraj izbor" -#: zrcolagui.cpp:121 +#: zrcolagui.cpp:127 msgid "Paste" msgstr "Prilepi" -#: zrcolagui.cpp:121 +#: zrcolagui.cpp:127 msgid "Paste selection" msgstr "Prilepi izbor" -#: zrcolagui.cpp:125 +#: zrcolagui.cpp:131 msgid "Send Composed" msgstr "Pošlji sestavljeno" -#: zrcolagui.cpp:127 +#: zrcolagui.cpp:133 msgid "Send Decomposed" msgstr "Pošlji razstavljeno" -#: zrcolagui.cpp:129 +#: zrcolagui.cpp:135 msgid "Language:" msgstr "Jezik:" -#: zrcolagui.cpp:178 +#: zrcolagui.cpp:184 msgid "Decomposed Text" msgstr "Razstavljeno besedilo" -#: zrcolagui.cpp:198 +#: zrcolagui.cpp:204 msgid "Decomposed Unicode Dump" msgstr "Unicode razstavljenega" -#: zrcolagui.cpp:225 +#: zrcolagui.cpp:231 msgid "Composed Text" msgstr "Sestavljeno besedilo" -#: zrcolagui.cpp:245 +#: zrcolagui.cpp:251 msgid "Composed Unicode Dump" msgstr "Unicode sestavljenega" -#: zrcolagui.h:75 MSIBuild/En.Win32.Release.Feature-2.idtx:4 +#: zrcolagui.h:76 MSIBuild/En.Win32.Release.Feature-2.idtx:4 #: MSIBuild/En.Win32.Release.Shortcut-2.idtx:4 #: MSIBuild/En.x64.Release.Feature-2.idtx:4 #: MSIBuild/En.x64.Release.Shortcut-2.idtx:4 diff --git a/ZRCola/stdafx.h b/ZRCola/stdafx.h index 6f92d90..0aadbd9 100644 --- a/ZRCola/stdafx.h +++ b/ZRCola/stdafx.h @@ -39,4 +39,6 @@ #if defined(__WXMSW__) #include +#include +#include #endif diff --git a/ZRCola/zrcolafrm.cpp b/ZRCola/zrcolafrm.cpp index d689b0a..1768625 100644 --- a/ZRCola/zrcolafrm.cpp +++ b/ZRCola/zrcolafrm.cpp @@ -25,21 +25,24 @@ ////////////////////////////////////////////////////////////////////////// wxBEGIN_EVENT_TABLE(wxZRColaFrame, wxZRColaFrameBase) - EVT_UPDATE_UI_RANGE(wxID_CUT, wxID_CLEAR, wxZRColaFrame::OnForwardEventUpdate) - EVT_MENU_RANGE(wxID_CUT, wxID_CLEAR, wxZRColaFrame::OnForwardEvent) - EVT_UPDATE_UI(wxID_SELECTALL, wxZRColaFrame::OnForwardEventUpdate) - EVT_MENU(wxID_SELECTALL, wxZRColaFrame::OnForwardEvent) + EVT_UPDATE_UI (wxID_AUTOSTART , wxZRColaFrame::OnAutostartUpdate ) + EVT_MENU (wxID_AUTOSTART , wxZRColaFrame::OnAutostart ) + EVT_MENU (wxID_EXIT , wxZRColaFrame::OnExit ) - EVT_UPDATE_UI_RANGE(wxID_SEND_COMPOSED, wxID_SEND_ABORT, wxZRColaFrame::OnSendUpdate) - EVT_MENU(wxID_SEND_COMPOSED , wxZRColaFrame::OnSendComposed ) - EVT_MENU(wxID_SEND_DECOMPOSED, wxZRColaFrame::OnSendDecomposed ) - EVT_MENU(wxID_SEND_ABORT , wxZRColaFrame::OnSendAbort ) + EVT_UPDATE_UI_RANGE(wxID_CUT, wxID_CLEAR , wxZRColaFrame::OnForwardEventUpdate ) + EVT_MENU_RANGE (wxID_CUT, wxID_CLEAR , wxZRColaFrame::OnForwardEvent ) + EVT_UPDATE_UI (wxID_SELECTALL , wxZRColaFrame::OnForwardEventUpdate ) + EVT_MENU (wxID_SELECTALL , wxZRColaFrame::OnForwardEvent ) + + EVT_UPDATE_UI_RANGE(wxID_SEND_COMPOSED, wxID_SEND_ABORT , wxZRColaFrame::OnSendUpdate ) + EVT_MENU (wxID_SEND_COMPOSED , wxZRColaFrame::OnSendComposed ) + EVT_MENU (wxID_SEND_DECOMPOSED , wxZRColaFrame::OnSendDecomposed ) + EVT_MENU (wxID_SEND_ABORT , wxZRColaFrame::OnSendAbort ) EVT_UPDATE_UI_RANGE(wxID_DECOMP_LANGUAGE_START, wxID_DECOMP_LANGUAGE_END, wxZRColaFrame::OnDecomposedLanguageUpdate) - EVT_MENU_RANGE(wxID_DECOMP_LANGUAGE_START, wxID_DECOMP_LANGUAGE_END, wxZRColaFrame::OnDecomposedLanguage) + EVT_MENU_RANGE (wxID_DECOMP_LANGUAGE_START, wxID_DECOMP_LANGUAGE_END, wxZRColaFrame::OnDecomposedLanguage ) - EVT_MENU(wxID_EXIT , wxZRColaFrame::OnExit ) - EVT_MENU(wxID_ABOUT, wxZRColaFrame::OnAbout) + EVT_MENU (wxID_ABOUT , wxZRColaFrame::OnAbout ) wxEND_EVENT_TABLE() @@ -92,6 +95,57 @@ wxZRColaFrame::~wxZRColaFrame() } +void wxZRColaFrame::OnAutostartUpdate(wxUpdateUIEvent& event) +{ +#if defined(__WXMSW__) + wxString linkName(wxExpandEnvVars("%APPDATA%\\Microsoft\\Windows\\Start Menu\\Programs\\Startup\\ZRCola.lnk")); + event.Check(wxFileExists(linkName)); +#else + event.Enable(false); +#endif +} + + +void wxZRColaFrame::OnAutostart(wxCommandEvent& event) +{ +#if defined(__WXMSW__) + wxString linkName(wxExpandEnvVars("%APPDATA%\\Microsoft\\Windows\\Start Menu\\Programs\\Startup\\ZRCola.lnk")); + if (wxFileExists(linkName)) { + // The shortcut already exists. Remove it. + wxRemoveFile(linkName); + } else { + // Create the shortcut. + IShellLink *sl; + HRESULT hr = ::CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (LPVOID*)&sl); + if (SUCCEEDED(hr)) { + // Setup ZRCola shortcut. + sl->SetPath(wxTheApp->argv[0]); + sl->SetDescription(_("Start ZRCola automatically on logon")); + sl->SetShowCmd(SW_SHOWMINNOACTIVE); + + // Query IShellLink for the IPersistFile interface, used for saving the + // shortcut in persistent storage. + IPersistFile *pf; + hr = sl->QueryInterface(IID_IPersistFile, (LPVOID*)&pf); + if (SUCCEEDED(hr)) { + // Save the link by calling IPersistFile::Save. + hr = pf->Save(linkName, TRUE); + pf->Release(); + } + + sl->Release(); + } + } +#endif +} + + +void wxZRColaFrame::OnExit(wxCommandEvent& event) +{ + Close(); +} + + void wxZRColaFrame::OnForwardEventUpdate(wxUpdateUIEvent& event) { wxControl *focusWnd = wxDynamicCast(FindFocus(), wxControl); @@ -194,12 +248,6 @@ void wxZRColaFrame::OnDecompLanguageChoice(wxCommandEvent& event) } -void wxZRColaFrame::OnExit(wxCommandEvent& event) -{ - Close(); -} - - void wxZRColaFrame::OnAbout(wxCommandEvent& event) { wxMessageBox(wxString::Format(_("ZRCola v%s\nCopyright 2015-%s Amebis"), wxT(ZRCOLA_VERSION_STR), wxT(ZRCOLA_BUILD_YEAR_STR)), _("About ZRCola"), wxOK | wxICON_INFORMATION); diff --git a/ZRCola/zrcolafrm.h b/ZRCola/zrcolafrm.h index b960062..cc3af2c 100644 --- a/ZRCola/zrcolafrm.h +++ b/ZRCola/zrcolafrm.h @@ -54,6 +54,9 @@ public: virtual ~wxZRColaFrame(); protected: + void OnAutostartUpdate(wxUpdateUIEvent& event); + void OnAutostart(wxCommandEvent& event); + void OnExit(wxCommandEvent& event); void OnForwardEventUpdate(wxUpdateUIEvent& event); void OnForwardEvent(wxCommandEvent& event); void OnSendUpdate(wxUpdateUIEvent& event); @@ -63,7 +66,6 @@ protected: void OnDecomposedLanguageUpdate(wxUpdateUIEvent& event); void OnDecomposedLanguage(wxCommandEvent& event); virtual void OnDecompLanguageChoice(wxCommandEvent& event); - void OnExit(wxCommandEvent& event); void OnAbout(wxCommandEvent& event); wxDECLARE_EVENT_TABLE(); diff --git a/ZRCola/zrcolagui.cpp b/ZRCola/zrcolagui.cpp index af7196e..dbfcada 100644 --- a/ZRCola/zrcolagui.cpp +++ b/ZRCola/zrcolagui.cpp @@ -28,6 +28,12 @@ wxZRColaFrameBase::wxZRColaFrameBase( wxWindow* parent, wxWindowID id, const wxS m_menubar = new wxMenuBar( 0 ); m_menuProgram = new wxMenu(); + wxMenuItem* m_menuItemAutoStart; + m_menuItemAutoStart = new wxMenuItem( m_menuProgram, wxID_AUTOSTART, wxString( _("&Start on Logon") ) , _("Start this program automatically on logon"), wxITEM_CHECK ); + m_menuProgram->Append( m_menuItemAutoStart ); + + m_menuProgram->AppendSeparator(); + wxMenuItem* m_menuItemExit; m_menuItemExit = new wxMenuItem( m_menuProgram, wxID_EXIT, wxString( _("E&xit") ) + wxT('\t') + wxT("Alt+F4"), _("Quit this program"), wxITEM_NORMAL ); m_menuProgram->Append( m_menuItemExit ); diff --git a/ZRCola/zrcolagui.h b/ZRCola/zrcolagui.h index 7f583e3..e592c58 100644 --- a/ZRCola/zrcolagui.h +++ b/ZRCola/zrcolagui.h @@ -45,7 +45,8 @@ class wxZRColaFrameBase : public wxFrame protected: enum { - wxID_SEND_COMPOSED = 1000, + wxID_AUTOSTART = 1000, + wxID_SEND_COMPOSED, wxID_SEND_DECOMPOSED, wxID_SEND_ABORT };