diff --git a/bazaar/SysExecGui/SysExecGui.cpp b/bazaar/SysExecGui/SysExecGui.cpp index b65be511e..0855643da 100644 --- a/bazaar/SysExecGui/SysExecGui.cpp +++ b/bazaar/SysExecGui/SysExecGui.cpp @@ -1,161 +1,166 @@ -#include "SysExecGui.h" - -#include - -NAMESPACE_UPP - -#ifdef PLATFORM_POSIX - -#define IMAGECLASS SysExecGuiImg -#define IMAGEFILE -#include - -#define LAYOUTFILE -#include - -/////////////////////////////////////////////////////////////////////////////////////// -// password dialog -class PasswordDlg : public WithPasswordDlgLayout -{ - private: - String user; - - protected: - - public: - - typedef PasswordDlg CLASSNAME; - - // constructor - PasswordDlg(); - - String GetPassword(void) { return pwd; } - - // starts dialog, return true on success - bool Run(String const &u = "root"); - -}; - -PasswordDlg::PasswordDlg() -{ - CtrlLayout(*this, GetExeTitle()); - pwd.Password(); - title.SetLabel(t_("Please enter password for ") + GetUserName() + " :"); - okBtn.Ok() <<= Acceptor(IDOK); - cancelBtn.Cancel() <<= Rejector(IDCANCEL); - VCenterPos().HCenterPos(); -} - -bool PasswordDlg::Run(String const &u) -{ - // ask for password - user = u; - while(true) - { - pwd.Clear(); - PopUp(NULL, false, true, true); - CenterScreen(); - switch(Execute()) - { - case IDOK: - // check the password running pwd - if(SysExecUser(user, pwd, "/bin/pwd", "")) - return true; - PromptOK(DeQtf(t_("Wrong password -- Try again"))); - break; - case IDCANCEL: - return false; - default: - NEVER(); - } - } - return true; -} - -static PasswordDlg &pDlg() -{ - static PasswordDlg p; - return p; -} - -/////////////////////////////////////////////////////////////////////////////////////////////// -// executes an external command as Admin user, passing a command line to it without waiting for its termination -// it WILL prompt for user intervention on windows secure systems (Vista+ OSes), on which the password is useless -// on linux, will return an error if password is wrong -// return true on success, false otherwise -bool SysStartAdmin(String const &command, String const &args, const VectorMap &Environ) -{ - if(!pDlg().Run()) - return false; - return SysStartAdmin(pDlg().GetPassword(), command, args, Environ); -} - -bool SysStartAdmin(String const &command, String const &args) -{ - if(!pDlg().Run()) - return false; - return SysStartAdmin(pDlg().GetPassword(), command, args); -} - -/////////////////////////////////////////////////////////////////////////////////////////////// -// executes an external command as required user, passing a command line to it without waiting for its termination -// on linux, will return an error if password is required AND wrong -// on windows, by now... it just spawn the process without changing security level -// I still shall find a way to go back to user mode on windows -// return true on success, false otherwise -bool SysStartUser(String const &user, String const &command, String const &args, const VectorMap &Environ) -{ - if(!pDlg().Run(user)) - return false; - return SysStartUser(user, pDlg().GetPassword(), command, args, Environ); -} - -bool SysStartUser(String const &user, String const &command, String const &args) -{ - if(!pDlg().Run(user)) - return false; - return SysStartUser(user, pDlg().GetPassword(), command, args); -} - -/////////////////////////////////////////////////////////////////////////////////////////////// -// executes an external command as Admin user, passing a command line to it waiting for its termination -// it WILL prompt for user intervention on windows secure systems (Vista+ OSes), on which the password is useless -// on linux, will return an error if password is wrong -// return true on success, false otherwise -bool SysExecAdmin(String const &command, String const &args, const VectorMap &Environ) -{ - if(!pDlg().Run()) - return false; - return SysExecAdmin(pDlg().GetPassword(), command, args, Environ); -} - -bool SysExecAdmin(String const &command, String const &args) -{ - if(!pDlg().Run()) - return false; - return SysExecAdmin(pDlg().GetPassword(), command, args); -} - -/////////////////////////////////////////////////////////////////////////////////////////////// -// executes an external command as required user, passing a command line to it waiting for its termination -// on linux, will return an error if password is required AND wrong -// on windows, by now... it just spawn the process without changing security level -// I still shall find a way to go back to user mode on windows -// return true on success, false otherwise -bool SysExecUser(String const &user, String const &command, String const &args, const VectorMap &Environ) -{ - if(!pDlg().Run(user)) - return false; - return SysExecUser(user, pDlg().GetPassword(), command, args, Environ); -} - -bool SysExecUser(String const &user, String const &command, String const &args) -{ - if(!pDlg().Run(user)) - return false; - return SysExecUser(user, pDlg().GetPassword(), command, args); -} - -#endif - -END_UPP_NAMESPACE +#include "SysExecGui.h" + +#include + +NAMESPACE_UPP + +#ifdef PLATFORM_POSIX + +#define IMAGECLASS SysExecGuiImg +#define IMAGEFILE +#include + +#define LAYOUTFILE +#include + +/////////////////////////////////////////////////////////////////////////////////////// +// password dialog +class PasswordDlg : public WithPasswordDlgLayout +{ + private: + String user; + StaticRect r; + + protected: + + public: + + typedef PasswordDlg CLASSNAME; + + // constructor + PasswordDlg(); + + String GetPassword(void) { return pwd; } + + // starts dialog, return true on success + bool Run(String const &u = "root"); + +}; + +PasswordDlg::PasswordDlg() +{ + Add(r.SizePos()); + r.Color(LtCyan); + CtrlLayout(*this, GetExeTitle()); + pwd.Password(); + lock.SetImage(SysExecGuiImg::lock()); + title1 <<= t_("Please enter password to execute administrative tasks"); + title2 <<= Format(t_("[1 '%s' application can change important parts of your system]"), GetExeTitle()); + okBtn.Ok() <<= Acceptor(IDOK); + cancelBtn.Cancel() <<= Rejector(IDCANCEL); + VCenterPos().HCenterPos(); +} + +bool PasswordDlg::Run(String const &u) +{ + // ask for password + user = u; + while(true) + { + pwd.Clear(); + PopUp(NULL, false, true, true); + CenterScreen(); + switch(Execute()) + { + case IDOK: + // check the password running pwd + if(SysExecUser(user, pwd, "/bin/pwd", "")) + return true; + PromptOK(DeQtf(t_("Wrong password -- Try again"))); + break; + case IDCANCEL: + return false; + default: + NEVER(); + } + } + return true; +} + +static PasswordDlg &pDlg() +{ + static PasswordDlg p; + return p; +} + +/////////////////////////////////////////////////////////////////////////////////////////////// +// executes an external command as Admin user, passing a command line to it without waiting for its termination +// it WILL prompt for user intervention on windows secure systems (Vista+ OSes), on which the password is useless +// on linux, will return an error if password is wrong +// return true on success, false otherwise +bool SysStartAdmin(String const &command, String const &args, const VectorMap &Environ) +{ + if(!pDlg().Run()) + return false; + return SysStartAdmin(pDlg().GetPassword(), command, args, Environ); +} + +bool SysStartAdmin(String const &command, String const &args) +{ + if(!pDlg().Run()) + return false; + return SysStartAdmin(pDlg().GetPassword(), command, args); +} + +/////////////////////////////////////////////////////////////////////////////////////////////// +// executes an external command as required user, passing a command line to it without waiting for its termination +// on linux, will return an error if password is required AND wrong +// on windows, by now... it just spawn the process without changing security level +// I still shall find a way to go back to user mode on windows +// return true on success, false otherwise +bool SysStartUser(String const &user, String const &command, String const &args, const VectorMap &Environ) +{ + if(!pDlg().Run(user)) + return false; + return SysStartUser(user, pDlg().GetPassword(), command, args, Environ); +} + +bool SysStartUser(String const &user, String const &command, String const &args) +{ + if(!pDlg().Run(user)) + return false; + return SysStartUser(user, pDlg().GetPassword(), command, args); +} + +/////////////////////////////////////////////////////////////////////////////////////////////// +// executes an external command as Admin user, passing a command line to it waiting for its termination +// it WILL prompt for user intervention on windows secure systems (Vista+ OSes), on which the password is useless +// on linux, will return an error if password is wrong +// return true on success, false otherwise +bool SysExecAdmin(String const &command, String const &args, const VectorMap &Environ) +{ + if(!pDlg().Run()) + return false; + return SysExecAdmin(pDlg().GetPassword(), command, args, Environ); +} + +bool SysExecAdmin(String const &command, String const &args) +{ + if(!pDlg().Run()) + return false; + return SysExecAdmin(pDlg().GetPassword(), command, args); +} + +/////////////////////////////////////////////////////////////////////////////////////////////// +// executes an external command as required user, passing a command line to it waiting for its termination +// on linux, will return an error if password is required AND wrong +// on windows, by now... it just spawn the process without changing security level +// I still shall find a way to go back to user mode on windows +// return true on success, false otherwise +bool SysExecUser(String const &user, String const &command, String const &args, const VectorMap &Environ) +{ + if(!pDlg().Run(user)) + return false; + return SysExecUser(user, pDlg().GetPassword(), command, args, Environ); +} + +bool SysExecUser(String const &user, String const &command, String const &args) +{ + if(!pDlg().Run(user)) + return false; + return SysExecUser(user, pDlg().GetPassword(), command, args); +} + +#endif + +END_UPP_NAMESPACE diff --git a/bazaar/SysExecGui/SysExecGui.iml b/bazaar/SysExecGui/SysExecGui.iml index bc925359c..d3b8241e9 100644 --- a/bazaar/SysExecGui/SysExecGui.iml +++ b/bazaar/SysExecGui/SysExecGui.iml @@ -1,5 +1,5 @@ PREMULTIPLIED -IMAGE_ID(lock_secure) +IMAGE_ID(lock) IMAGE_BEGIN_DATA IMAGE_DATA(120,156,189,151,123,76,91,85,24,192,251,0,202,163,5,218,82,161,208,23,143,210,7,143,74,11,148,118,148,148,18,30) diff --git a/bazaar/SysExecGui/SysExecGui.lay b/bazaar/SysExecGui/SysExecGui.lay index 32b00008f..89a462a71 100644 --- a/bazaar/SysExecGui/SysExecGui.lay +++ b/bazaar/SysExecGui/SysExecGui.lay @@ -1,8 +1,10 @@ LAYOUT(PasswordDlgLayout, 356, 200) - ITEM(Label, title, SetLabel(t_("Please enter password for")).LeftPosZ(56, 284).TopPosZ(4, 72)) - ITEM(EditString, pwd, LeftPosZ(132, 208).TopPosZ(92, 20)) - ITEM(Label, dv___2, SetLabel(t_("Password :")).LeftPosZ(56, 72).VSizePosZ(92, 85)) + ITEM(RichTextCtrl, title2, NoSb(true).LeftPosZ(56, 284).TopPosZ(56, 44)) + ITEM(EditString, pwd, LeftPosZ(132, 208).TopPosZ(112, 20)) + ITEM(Label, dv___2, SetLabel(t_("Password :")).LeftPosZ(56, 72).VSizePosZ(112, 65)) ITEM(Button, cancelBtn, SetLabel(t_("Cancel")).LeftPosZ(200, 68).TopPosZ(168, 20)) ITEM(Button, okBtn, SetLabel(t_("Ok")).LeftPosZ(276, 68).TopPosZ(168, 20)) + ITEM(RichTextCtrl, title1, NoSb(true).LeftPosZ(56, 284).TopPosZ(4, 44)) + ITEM(ImageCtrl, lock, LeftPosZ(4, 48).TopPosZ(4, 48)) END_LAYOUT