Ejemplo n.º 1
0
String
strutil_encrypt(const String &original)
{
   if(original.Length() == 0)
      return wxEmptyString;

   if(! strutil_encrypt_initialised)
      strutil_encrypt_initialise();

   if ( READ_APPCONFIG(MP_CRYPTALGO) )
      return strutil_encrypt_tf(original);


   String
      tmpstr,
      newstr;
   const wxChar
      *cptr = original.c_str();

   unsigned char pair[2];
   while(*cptr)
   {
      pair[0] = (unsigned char) *cptr;
      pair[1] = (unsigned char) *(cptr+1);
      strutil_encrypt_pair(pair);
      // now we have the encrypted pair, which could be binary data,
      // so we write hex values instead:
      tmpstr.Printf(_T("%02x%02x"), (int)pair[0], (int)pair[1]);
      newstr << tmpstr;
      cptr ++;
      if(*cptr) cptr++;
   }
   return newstr;
}
Ejemplo n.º 2
0
/* static */
wxImage
XFace::GetXFaceImg(const String& filename,
                   bool *hasimg,
                   wxWindow * /* parent */)
{
#if !defined(__CYGWIN__) && !defined(__MINGW32__) // FIXME undefined reference to wxIconManager::LoadImage() when linking
   bool success = false;
   wxImage img;
   if(filename.Length())
   {
      img = wxIconManager::LoadImage(filename, &success);
      if(! success)
      {
         String msg;
         msg.Printf(_("Could not load XFace file '%s'."),
                    filename.c_str());
      }
   }
   if(success)
   {
      if(img.GetWidth() != 48 || img.GetHeight() != 48)
         img = img.Scale(48,48);
      // Now, check if we have some non-B&W colours:
      int intensity;
      for(int y = 0; y < 48; y++)
         for(int x = 0; x < 48; x++)
         {
            intensity = img.GetRed(x,y) + img.GetGreen(x,y) +
               img.GetBlue(x,y);
            if(intensity >= (3*255)/2)
               img.SetRGB(x,y,255,255,255);
            if(intensity <= (3*255)/2)
               img.SetRGB(x,y,0,0,0);
         }
      if(hasimg) *hasimg = true;
   }
   else
   {
      PathFinder pf(READ_APPCONFIG(MP_ICONPATH), true);
      pf.AddPaths(mApplication->GetLocalDir() + DIR_SEPARATOR + _T("icons"), true);
      pf.AddPaths(mApplication->GetDataDir() + DIR_SEPARATOR + _T("icons"), true);
      String name = pf.FindFile(_T("xface.xpm"), &success);
      if(success)
         img = wxIconManager::LoadImage(name, &success);
      if(hasimg) *hasimg = success;
   }
   return img;
#else // CYGWIN
   return NULL;
#endif
}
Ejemplo n.º 3
0
bool
strutil_checkpasswd(const String& passwd)
{
   wxString testdata = READ_APPCONFIG(MP_CRYPT_TESTDATA);

   CHECK( !testdata.empty(), true, _T("shouldn't be called if no old password") );

   String oldPassword = gs_GlobalPassword;
   gs_GlobalPassword = passwd;
   bool ok = strutil_decrypt(testdata) == _T("TESTDATA");
   gs_GlobalPassword = oldPassword;

   return ok;
}
Ejemplo n.º 4
0
/// A small helper function to expand mailfolder names:
String
strutil_expandfoldername(const String &name, MFolderType folderType)
{
   if( folderType != MF_FILE && folderType != MF_MH)
       return name;

   if ( strutil_isabsolutepath(name) )
      return strutil_expandpath(name);

   if ( folderType == MF_FILE )
   {
      String mboxpath = READ_APPCONFIG(MP_MBOXDIR);
      if ( mboxpath.empty() || !strutil_isabsolutepath(mboxpath) )
         mboxpath = mApplication->GetLocalDir() + DIR_SEPARATOR + mboxpath;

      if ( !mboxpath.empty() )
         mboxpath += DIR_SEPARATOR;

      mboxpath += name;

      return strutil_expandpath(mboxpath);
   }
   else // if ( folderType == MF_MH )
   {
      // the name is a misnomer, it is used here just to get MHPATH value
      String mhpath = MailFolder::InitializeMH();
      if ( !mhpath )
      {
         // oops - failed to init MH
         FAIL_MSG(_T("can't construct MH folder full name"));
      }
      else
      {
         mhpath += name;
      }

      return mhpath; // no need to expand, MHPATH should be already expanded
   }
}
Ejemplo n.º 5
0
void
wxMFrame::OnMenuCommand(int id)
{
   // is it a module generated entry?
   if(id >= WXMENU_MODULES_BEGIN && id < WXMENU_MODULES_END)
   {
      ProcessModulesMenu(id);
      return;
   }

   switch(id)
   {
      case WXMENU_FILE_CLOSE:
         Close();
         break;

      case WXMENU_FILE_COMPOSE_WITH_TEMPLATE:
      case WXMENU_FILE_COMPOSE:
         {
            wxString templ;
            if ( id == WXMENU_FILE_COMPOSE_WITH_TEMPLATE )
            {
               templ = ChooseTemplateFor(MessageTemplate_NewMessage, this);
               if ( templ.empty() )
               {
                  // cancelled by user
                  break;
               }
            }

            Profile_obj profile(GetFolderProfile());
            Composer *composeView = Composer::CreateNewMessage(templ, profile);

            composeView->InitText();
         }
         break;

      case WXMENU_FILE_SEND_OUTBOX:
         mApplication->SendOutbox();
         break;

      case WXMENU_FILE_POST:
         {
            Profile_obj profile(GetFolderProfile());
            Composer *composeView = Composer::CreateNewArticle(profile);

            composeView->InitText();
         }

      case WXMENU_FILE_COLLECT:
         {
            FolderMonitor *mailCollector = mApplication->GetFolderMonitor();
            if ( mailCollector )
            {
               // when the user explicitly checks for the new mail, also update
               // the currently opened folder(s) and give the verbose messages
               mailCollector->CheckNewMail(FolderMonitor::Interactive |
                                           FolderMonitor::Opened);
            }
         }
         break;

#ifdef USE_PYTHON
      case WXMENU_FILE_RUN_PYSCRIPT:
         {
            wxString path = mApplication->GetDataDir();
            if ( !path.empty() )
               path += DIR_SEPARATOR;
            path += _T("scripts");

            wxString filename = MDialog_FileRequester
                                (
                                 _("Please select a Python script to run."),
                                 this,
                                 path, "",
                                 "py", "*.py",
                                 false,
                                 NULL /* profile */
                                );
            if ( !filename.empty() )
            {
               PythonRunScript(filename);
            }
            //else: cancelled by user
         }
         break;
#endif   // USE_PYTHON

      case WXMENU_FILE_AWAY_MODE:
         mApplication->SetAwayMode(GetMenuBar()->IsChecked(id));
         break;

      case WXMENU_FILE_EXIT:
         // flush MEvent queues for safety
         MEventManager::DispatchPending();

         if ( CanClose() )
         {
            // this frame has been already asked whether it wants to exit, so
            // don't ask it again
            mApplication->AddToFramesOkToClose(this);

            // exit the application if other frames don't object
            mApplication->Exit();
         }
         break;

      case WXMENU_FILE_IMPORT:
         ShowImportDialog(this);
         break;

      case WXMENU_EDIT_ADB:
         ShowAdbFrame(this);
         break;

      case WXMENU_EDIT_PREF:
         ShowOptionsDialog(this);
         break;

      case WXMENU_EDIT_FILTERS:
         (void) ConfigureAllFilters(this);
         break;

      case WXMENU_EDIT_MODULES:
         ShowModulesDialog(this);
         break;

      case WXMENU_EDIT_TEMPLATES:
         EditTemplates(this);
         break;

      case WXMENU_EDIT_RESTORE_PREF:
         (void)ShowRestoreDefaultsDialog(mApplication->GetProfile(), this);
         break;

      case WXMENU_EDIT_SAVE_PREF:
         if ( Profile::FlushAll() )
         {
            wxLogStatus(this, _("Program preferences successfully saved."));
         }
         else
         {
            ERRORMESSAGE((_("Couldn't save preferences.")));
         }
         break;

      case WXMENU_EDIT_CONFIG_SOURCES:
         ShowConfigSourcesDialog(this);
         break;

      case WXMENU_EDIT_EXPORT_PREF:
      case WXMENU_EDIT_IMPORT_PREF:
         {
            const bool doExport = id == WXMENU_EDIT_EXPORT_PREF;

            String path = MDialog_FileRequester
                          (
                              doExport ? _("Choose file to export settings to")
                                       : _("Choose file to import settings from"),
                              this,
                              wxEmptyString, wxEmptyString, wxEmptyString, wxEmptyString,
                              doExport    // true => save, false => load
                          );
            if ( path.empty() )
               break;

            ConfigSource_obj
               configSrc(ConfigSourceLocal::CreateDefault()),
               configDst(ConfigSourceLocal::CreateFile(path));
            if ( !doExport )
            {
               configSrc.Swap(configDst);
            }

            bool ok = ConfigSource::Copy(*configDst, *configSrc);

            if ( doExport )
            {
               if ( ok )
               {
                  wxLogStatus(this,
                              _("Settings successfully exported to file \"%s\""),
                              path.c_str());
               }
               else
               {
                  wxLogError(_("Failed to export settings to the file \"%s\"."),
                             path.c_str());
               }
            }
            else // import
            {
               if ( ok )
               {
                  wxLogStatus(this,
                              _("Settings successfully imported from \"%s\""),
                              path.c_str());
               }
               else
               {
                  wxLogError(_("Failed to import settings from the file \"%s\"."),
                             path.c_str());
               }
            }
         }
         break;


      case WXMENU_HELP_ABOUT:
         MDialog_AboutDialog(this, false /* don't timeout */);
         break;

      case WXMENU_HELP_TIP:
         MDialog_ShowTip(this);
         break;

      case WXMENU_HELP_CONTEXT:
         MDialog_Message(_("Help not implemented for current context, yet."),this,_("Sorry"));
         break;

      case WXMENU_HELP_CONTENTS:
         mApplication->Help(MH_CONTENTS,this);
         break;

      case WXMENU_HELP_RELEASE_NOTES:
         mApplication->Help(MH_RELEASE_NOTES,this);
         break;

      case WXMENU_HELP_FAQ:
         mApplication->Help(MH_FAQ,this);
         break;

      case WXMENU_HELP_SEARCH:
         mApplication->Help(MH_SEARCH,this);
         break;

      case WXMENU_HELP_COPYRIGHT:
         mApplication->Help(MH_COPYRIGHT,this);
         break;

         // printing:
      case WXMENU_FILE_PRINT_SETUP:
         OnPrintSetup();
         break;
      case WXMENU_FILE_PAGE_SETUP:
         OnPageSetup();
         break;

#ifdef USE_PS_PRINTING
      case WXMENU_FILE_PRINT_SETUP_PS:
         OnPrintSetup();
         break;

      case WXMENU_FILE_PAGE_SETUP_PS:
         OnPageSetup();
         break;
#endif // USE_PS_PRINTING

#ifdef USE_DIALUP
      case WXMENU_FILE_NET_ON:
         mApplication->GoOnline();
         break;

      case WXMENU_FILE_NET_OFF:
         if(mApplication->CheckOutbox())
         {
            if ( MDialog_YesNoDialog
                 (
                  _("You have outgoing messages queued.\n"
                    "Do you want to send them before going offline?"),
                  this,
                  MDIALOG_YESNOTITLE,
                  M_DLG_YES_DEFAULT,
                  M_MSGBOX_GO_OFFLINE_SEND_FIRST
                 ) )
            {
               mApplication->SendOutbox();
            }
         }
         mApplication->GoOffline();
         break;
#endif // USE_DIALUP

         // create a new identity and edit it
      case WXMENU_FILE_IDENT_ADD:
         {
            wxString ident;
            if ( MInputBox(&ident,
                           _("Mahogany: Create new identity"),
                           _("Enter the identity name:"),
                           this,
                           "NewIdentity") )
            {
               ShowIdentityDialog(ident, this);

               // update the identity combo in the toolbar of the main frame if
               // any (note that this will update all the other existing
               // identity combo boxes as they keep themselves in sync
               // internally)
               //
               // TODO: we really should have a virtual wxMFrame::GetIdentCombo
               //       as we might not always create the main frame in the
               //       future but other frames (e.g. composer) may have the
               //       ident combo as well
               wxMFrame *frameTop = mApplication->TopLevelFrame();
               if ( frameTop )
               {
                  wxToolBar *tbar = frameTop->GetToolBar();
                  if ( tbar )
                  {
                     wxWindow *win = tbar->FindWindow(IDC_IDENT_COMBO);
                     if ( win )
                     {
                        wxChoice *combo = wxDynamicCast(win, wxChoice);
                        combo->Append(ident);
                     }
                  }
                  else
                  {
                     FAIL_MSG(_T("where is the main frames toolbar?"));
                  }
               }

               wxLogStatus(this, _("Created new identity '%s'."), ident.c_str());
            }
         }
         break;

         // change the current identity
      case WXMENU_FILE_IDENT_CHANGE:
         {
            wxArrayString identities = Profile::GetAllIdentities();
            if ( identities.IsEmpty() )
            {
               wxLogError(_("There are no existing identities to choose from.\n"
                            "Please create an identity first."));
            }
            else
            {
               identities.Insert(_("Default"), 0);
               int rc = MDialog_GetSelection
                        (
                         _("Select the new identity"),
                         MDIALOG_YESNOTITLE,
                         identities,
                         this
                        );

               if ( rc != -1 )
               {
                  Profile *profile = mApplication->GetProfile();
                  if ( rc == 0 )
                  {
                     // restore the default identity
                     profile->DeleteEntry(GetOptionName(MP_CURRENT_IDENTITY));
                  }
                  else
                  {
                     wxString ident = identities[(size_t)rc];
                     profile->writeEntry(MP_CURRENT_IDENTITY, ident);
                  }

                  // update the identity combo in the toolbar if any
                  wxWindow *win = GetToolBar()->FindWindow(IDC_IDENT_COMBO);
                  if ( win )
                  {
                     wxChoice *combo = wxDynamicCast(win, wxChoice);
                     combo->SetSelection(rc);
                  }

                  // TODO: should update everything (all options might have
                  //       changed)
               }
               //else: dialog cancelled, nothing to do
            }
         }
         break;

         // edit an identity's parameters
      case WXMENU_FILE_IDENT_EDIT:
         {
            String ident;
            wxArrayString identities = Profile::GetAllIdentities();
            if ( identities.IsEmpty() )
            {
               wxLogError(_("There are no existing identities to edit.\n"
                            "Please create an identity first."));
            }
            else
            {
               if ( identities.GetCount() > 1 )             
               {
                  int rc = MDialog_GetSelection
                           (
                            _("Which identity would you like to edit?"),
                            MDIALOG_YESNOTITLE,
                            identities,
                            this
                           );

                  if ( rc != -1 )
                  {
                     ident = identities[(size_t)rc];
                  }
                  //else: dialog was cancelled
               }
               else // only one identity
               {
                  // use the current one
                  ident = READ_APPCONFIG_TEXT(MP_CURRENT_IDENTITY);
               }
            }

            if ( !ident.empty() )
            {
               ShowIdentityDialog(ident, this);
            }
         }
         break;

      case WXMENU_FILE_IDENT_DELETE:
         {
            String ident;
            wxArrayString identities = Profile::GetAllIdentities();
            if ( identities.IsEmpty() )
            {
               wxLogError(_("There are no existing identities to delete."));
            }
            else
            {
               int rc = MDialog_GetSelection
                        (
                         _("Which identity would you like to delete?"),
                         MDIALOG_YESNOTITLE,
                         identities,
                         this
                        );
               if ( rc != -1 )
               {
                  ident = identities[(size_t)rc];
               }
               //else: cancelled
            }

            if ( !ident.empty() )
            {
               Profile *profile = mApplication->GetProfile();

               if ( ident == READ_APPCONFIG(MP_CURRENT_IDENTITY) )
               {
                  // can't keep this one
                  profile->writeEntry(MP_CURRENT_IDENTITY, wxEmptyString);
               }

               // FIXME: will this really work? if there are objects which
               //        use this identity the section will be recreated...
               String identSection;
               identSection << Profile::GetIdentityPath() << '/' << ident;
               profile->DeleteGroup(identSection);

               // update the identity combo in the toolbar if any
               wxWindow *win = GetToolBar()->FindWindow(IDC_IDENT_COMBO);
               if ( win )
               {
                  wxChoice *combo = wxDynamicCast(win, wxChoice);
                  combo->Delete(combo->FindString(ident));
               }

               wxLogStatus(this, _("Identity '%s' deleted."), ident.c_str());
            }
         }
         break;

      case WXMENU_LANG_SET_DEFAULT:
         {
            static const wxFontEncoding encodingsSupported[] =
            {
               wxFONTENCODING_ISO8859_1,       // West European (Latin1)
               wxFONTENCODING_ISO8859_2,       // Central and East European (Latin2)
               wxFONTENCODING_ISO8859_3,       // Esperanto (Latin3)
               wxFONTENCODING_ISO8859_4,       // Baltic (old) (Latin4)
               wxFONTENCODING_ISO8859_5,       // Cyrillic
               wxFONTENCODING_ISO8859_6,       // Arabic
               wxFONTENCODING_ISO8859_7,       // Greek
               wxFONTENCODING_ISO8859_8,       // Hebrew
               wxFONTENCODING_ISO8859_9,       // Turkish (Latin5)
               wxFONTENCODING_ISO8859_10,      // Variation of Latin4 (Latin6)
               wxFONTENCODING_ISO8859_11,      // Thai
               wxFONTENCODING_ISO8859_12,      // doesn't exist currently, but put it
                                               // here anyhow to make all ISO8859
                                               // consecutive numbers
               wxFONTENCODING_ISO8859_13,      // Baltic (Latin7)
               wxFONTENCODING_ISO8859_14,      // Latin8
               wxFONTENCODING_ISO8859_15,      // Latin9 (a.k.a. Latin0, includes euro)

               wxFONTENCODING_CP1250,          // WinLatin2
               wxFONTENCODING_CP1251,          // WinCyrillic
               wxFONTENCODING_CP1252,          // WinLatin1
               wxFONTENCODING_CP1253,          // WinGreek (8859-7)
               wxFONTENCODING_CP1254,          // WinTurkish
               wxFONTENCODING_CP1255,          // WinHebrew
               wxFONTENCODING_CP1256,          // WinArabic
               wxFONTENCODING_CP1257,          // WinBaltic (almost the same as Latin 7)

               wxFONTENCODING_KOI8,            // == KOI8-R
               wxFONTENCODING_UTF7,            // == UTF-7
               wxFONTENCODING_UTF8,            // == UTF-8
            };

            wxArrayString encDescs;
            encDescs.Add(_("Default 7 bit (US ASCII)"));
            for ( size_t n = 0; n < WXSIZEOF(encodingsSupported); n++ )
            {
               encDescs.Add(
                     wxFontMapper::GetEncodingDescription(
                        encodingsSupported[n]
                     )
               );
            }

            int choice = MDialog_GetSelection
                         (
                           _("Please choose the default encoding:\n"
                             "it will be used by default in both\n"
                             "message viewer and composer."),
                           _("Choose default encoding"),
                           encDescs,
                           this
                         );

            wxFontEncoding enc;
            if ( choice == -1 )
            {
               // cancelled, do nothing
               break;
            }
            else if ( choice == 0 )
            {
               enc = wxFONTENCODING_DEFAULT;
            }
            else
            {
               enc = encodingsSupported[choice - 1];
            }

            // remember the encoding as default
            mApplication->GetProfile()->writeEntry(MP_MSGVIEW_DEFAULT_ENCODING,
                                                   enc);
         }
         break;

      case WXMENU_VIEW_TOOLBAR:
         if ( GetMenuBar()->IsChecked(id) )
         {
            DoCreateToolBar();
         }
         else // hide the toolbar
         {
            delete GetToolBar();
            SetToolBar(NULL);
         }
         break;

      case WXMENU_VIEW_STATUSBAR:
         if ( GetMenuBar()->IsChecked(id) )
         {
            DoCreateStatusBar();
         }
         else // hide the status bar
         {
            delete GetStatusBar();
            SetStatusBar(NULL);
         }
         break;

      case WXMENU_VIEW_FULLSCREEN:
         ShowFullScreen(GetMenuBar()->IsChecked(id));
         break;
   }
}
Ejemplo n.º 6
0
static void
strutil_encrypt_initialise(void)
{
   /* initialise built-in weak encryption table: */
   for(int c = 0; c < 256; c++)
      strutil_encrypt_table[c] = (unsigned char )c;

   unsigned char
      tmp;
   int
      a = 0,
      b = STRUTIL_ENCRYPT_DELTA % 256;
   for(int i = 0 ; i < STRUTIL_ENCRYPT_MIX ; i++)
   {
      tmp = strutil_encrypt_table[a];
      strutil_encrypt_table[a] = strutil_encrypt_table[b];
      strutil_encrypt_table[b] = tmp;
      a += STRUTIL_ENCRYPT_DELTA;
      b += STRUTIL_ENCRYPT_DELTA;
      a %= 256;
      b %= 256;
   }

   // Now test if twofish works alright on this system
   int status = READ_APPCONFIG(MP_CRYPT_TWOFISH_OK);
   if ( status == -1 )
   {
      String oldPassword = gs_GlobalPassword;
      gs_GlobalPassword = _T("testPassword");
      String test = _T("This is a test, in cleartext.");
      String cipher = strutil_encrypt_tf(test);
      strutil_has_twofish = TRUE; // assume or it will fail
      String clearagain = strutil_decrypt_tf(cipher);
      if(clearagain != test)
      {
         MDialog_Message(
            _("The secure encryption algorithm included in Mahogany\n"
              "does not work on your system and will be replaced with\n"
              "insecure weak encryption.\n"
              "Please report this as a bug to the Mahogany developers,\n"
              "so that we can fix it."),
            NULL,
            _("Missing feature"),
            "EncryptionAlgoBroken");
         strutil_has_twofish = FALSE;
      }
      else
      {
         strutil_has_twofish = TRUE;
      }

      gs_GlobalPassword = oldPassword;

      mApplication->GetProfile()->
         writeEntry(MP_CRYPT_TWOFISH_OK, (long)strutil_has_twofish);
   }
   else
   {
      strutil_has_twofish = status != 0;
   }

   strutil_encrypt_initialised = true;
}
Ejemplo n.º 7
0
// return true if ok, false if no password
static bool
setup_twofish(void)
{
   if ( !gs_GlobalPassword.empty() )
   {
      // already have it
      return true;
   }

   MDialog_Message(
      _("Mahogany uses a global password to protect sensitive\n"
        "information in your configuration files.\n\n"
        "The next dialog will ask you for your global password.\n"
        "If you have not previously chosen one, please do it\n"
        "now, otherwise enter the one you chose previously.\n\n"
        "If you do not want to use a global password, just cancel\n"
        "the next dialog.\n\n"
        "(Tick the box below to never see this message again.)"),
      NULL,
      _("Global Password"),
      GetPersMsgBoxName(M_MSGBOX_EXPLAIN_GLOBALPASSWD));

   bool retry;
   do
   {
      MInputBox(&gs_GlobalPassword,
                _("Global Password:"******"Please enter the global password:"******"",
                true /* password */);

      if ( gs_GlobalPassword.empty() )
      {
         // cancelled, don't insist
         return false;
      }

      // TODO: ask to confirm it?

      wxString testdata = READ_APPCONFIG(MP_CRYPT_TESTDATA);
      if ( testdata.empty() )
      {
         // we hadn't used the global password before
         mApplication->GetProfile()->writeEntry(MP_CRYPT_TESTDATA,
               strutil_encrypt_tf(_T("TESTDATA")));

         return true;
      }

      if ( strutil_decrypt(testdata) == _T("TESTDATA") )
      {
         // correct password
         return true;
      }

      retry = MDialog_YesNoDialog
              (
               _("The password is wrong.\nDo you want to try again?"),
               NULL,
               MDIALOG_YESNOTITLE,
               M_DLG_YES_DEFAULT
              );

   } while( retry );

   return false;
}
Ejemplo n.º 8
0
wxIcon
wxIconManager::GetIcon(const String &iconNameOrig)
{
   String iconName = iconNameOrig;

   strutil_tolower(iconName);
   wxLogTrace(wxTraceIconLoading, _T("wxIconManager::GetIcon(%s) called..."),
              iconNameOrig.c_str());

   wxIcon icon;

   // first always look in the cache
   if ( FindInCache(iconName, &icon) )
      return icon;

   // next step: try to load the icon files .png,.xpm,.gif:
   if(m_GlobalDir.Length())
   {
      PathFinder pf(READ_APPCONFIG(MP_ICONPATH));

#ifdef M_TOP_SOURCEDIR
      // look in the source directory to make it possible to use the program
      // without installing it
      pf.AddPaths(String(M_TOP_SOURCEDIR) + _T("/src/icons"));
      pf.AddPaths(String(M_TOP_SOURCEDIR) + _T("/res"));
#endif // M_TOP_SOURCEDIR

      pf.AddPaths(m_GlobalDir, false);
      if(ms_IconPath.Length() > 0)
         pf.AddPaths(ms_IconPath,false, true /*prepend */);
      pf.AddPaths(m_LocalDir, false);
      if(m_SubDir.Length() > 1)  // 1 == "/" == empty
      {
         pf.AddPaths(m_GlobalDir+m_SubDir, false, true);
         pf.AddPaths(m_LocalDir+m_SubDir, false, true);
      }

      String name;
      for ( int ext = 0; wxIconManagerFileExtensions[ext]; ext++ )
      {
         // use iconNameOrig here to preserve the original case
         name = pf.FindFile(iconNameOrig + wxIconManagerFileExtensions[ext]);

         // but if it's not found, also fall back to the usual lower case
         if ( name.empty() )
         {
            name = pf.FindFile(iconName + wxIconManagerFileExtensions[ext]);
         }

         if ( !name.empty() )
         {
            ms_IconPath = name.BeforeLast('/');

            if ( !icon.LoadFile(name, wxBITMAP_TYPE_ANY) )
            {
               // try to load it via conversion to XPM
               char **ptr = LoadImageXpm(name);
               if(ptr)
               {
                  icon = wxIcon(ptr);
                  FreeImage(ptr);
               }
            }

            if ( icon.Ok() )
            {
               IconData  id;
               id.iconRef = icon;
               id.iconName = iconName;
               wxLogTrace(wxTraceIconLoading, _T("... icon found in '%s'"),
                          name.c_str());
               m_iconList.push_front(id);
               return icon;
            }
         }
     } // for all extensions
   } // if globaldir is not empty

#ifdef OS_WIN
   // last, look in the resources
   {
      icon = wxIcon(iconNameOrig);
      if ( icon.Ok() ) {
         wxLogTrace(wxTraceIconLoading, _T("... icon found in the ressources."));
         return icon;
      }

      // ok, it failed - now do all the usual stuff
   }
#endif  //Windows

   wxLogTrace(wxTraceIconLoading, _T("... icon not found."));

   return m_unknownIcon;
}
Ejemplo n.º 9
0
/* static */
wxImage &
wxIconManager::LoadImage(String filename, bool *success, bool showDlg)
{
   bool loaded = false;
   wxImage *img = new wxImage();

   // If we haven't been called yet, find out which image handlers
   // are supported:
   if(! m_knowHandlers) // first time initialisation
   {
      ms_NumOfHandlers = 0;
      for ( int i = 0; m_wxBitmapHandlers[i] != wxBITMAP_TYPE_MAX; i++ )
      {
         if ( !wxImage::FindHandler(m_wxBitmapHandlers[i]) )
            m_wxBitmapHandlers[i] = wxBITMAP_TYPE_INVALID; // not available
         else
            ms_NumOfHandlers ++;
      }

      m_knowHandlers = true;
   }

   // suppress any error logging from image handlers, some of them
   // will fail.
   {
      wxLogNull logNo;

      for ( int i = 0; m_wxBitmapHandlers[i] != wxBITMAP_TYPE_MAX; i++ )
      {
         if ( m_wxBitmapHandlers[i] != wxBITMAP_TYPE_INVALID )
         {
            if ( img->LoadFile(filename, m_wxBitmapHandlers[i]) )
               break;
         }
      }
   } // normal logging again

#ifdef OS_UNIX
   if(! loaded) // try to use imageMagick to convert image to another format:
   {
      String oldfilename = filename;
      String tempfile = filename;
      int format = READ_APPCONFIG(MP_TMPGFXFORMAT);
      if((format < 0 || format > NUMBER_OF_FORMATS)
         || (format != 0 &&
             m_wxBitmapHandlers[format] == wxBITMAP_TYPE_XPM)) //xpm we do ourselves
      {
         wxLogInfo(_("Unsupported intermediary image format '%s' specified,\n"
                     "reset to '%s'."),
                   ((format < 0 || format >NUMBER_OF_FORMATS) ?
                    _T("unknown") : HandlerNames[format]),
                   HandlerNames[0]);
         format = 0;
         mApplication->GetProfile()->writeEntry(MP_TMPGFXFORMAT,format);
      }
      tempfile += wxIconManagerFileExtensions[format];
      // strip leading path
      int i = tempfile.Length();
      while(i && tempfile.c_str()[i] != '/')
         i--;
      tempfile.assign(tempfile,i+1,tempfile.length()-1-i);
      tempfile = String(
         (wxGetenv(_T("TMP")) && wxStrlen(wxGetenv(_T("TMP"))))
         ? wxGetenv(_T("TMP")) : _T("/tmp")
         ) + _T('/') + tempfile;
      if(wxFile::Exists(filename))
      {
         String strConvertProgram = READ_APPCONFIG(MP_CONVERTPROGRAM);
         String strFormatSpec = strutil_extract_formatspec(strConvertProgram);
         if ( strFormatSpec != _T("ss") )
         {
            wxLogError(_("The setting for image conversion program should include "
                         "exactly two '%%s' format specificators.\n"
                         "The current setting '%s' is incorrect and "
                         "the default value will be used instead."),
                       strConvertProgram.c_str());
            strConvertProgram = GetStringDefault(MP_CONVERTPROGRAM);
         }
         String command;
         command.Printf(strConvertProgram, filename.c_str(), tempfile.c_str());
         wxLogTrace(wxTraceIconLoading,
                    _T("wxIconManager::LoadImage() calling '%s'..."),
                    command.c_str());
         if(wxSystem(command) == 0)
         {
            wxLogNull lo; // suppress error messages
            if(format != 0) // not xpm which we handle internally
            {
               switch(format)
               {
               case 1: // PNG!
                  loaded = img->LoadFile(tempfile, wxBITMAP_TYPE_PNG);
                  break;
               case 2: // 2 BMP
                  loaded = img->LoadFile(tempfile, wxBITMAP_TYPE_BMP);
                  break;
               case 3: // 3 JPG
                  loaded = img->LoadFile(tempfile, wxBITMAP_TYPE_JPEG);
                  break;
               }
            }
         } // system()
         if(tempfile.length()) // using a temporary file
            wxRemoveFile(tempfile);
      }// if(wxFile::Exists())
   }//! loaded
#endif // OS_UNIX

   // if everything else failed, try xpm loading:
   if( !loaded ) // try our own XPM loading code
   {
      char ** cpptr = LoadImageXpm(filename);
      if(cpptr)
      {
         *img = wxBitmap(cpptr).ConvertToImage();
         wxIconManager::FreeImage(cpptr);
         loaded = true;
      }
   }
   if(success)
      *success = loaded;
   return *img;
}
Ejemplo n.º 10
0
bool InitSSL(void) /* FIXME: MT */
{
   static bool s_errMsgGiven = false;

   if(gs_SSL_loaded)
      return gs_SSL_available;

   String ssl_dll = READ_APPCONFIG(MP_SSL_DLL_SSL);
   String crypto_dll = READ_APPCONFIG(MP_SSL_DLL_CRYPTO);

   // it doesn't take long so nobody sees this message anyhow
#if 0
   STATUSMESSAGE((_("Trying to load SSL libraries '%s' and '%s'..."),
                  crypto_dll.c_str(),
                  ssl_dll.c_str()));
#endif // 0

   if ( !gs_dllCrypto.Load(crypto_dll) )
      goto error;

   if ( !gs_dllSll.Load(ssl_dll) )
      goto error;

   SSL_LOOKUP(SSL_new);
   SSL_LOOKUP(SSL_free);
   SSL_LOOKUP(SSL_set_rfd);
   SSL_LOOKUP(SSL_set_wfd);
   SSL_LOOKUP(SSL_set_read_ahead);
   SSL_LOOKUP(SSL_connect);
   SSL_LOOKUP(SSL_read);
   SSL_LOOKUP(SSL_write);
   SSL_LOOKUP(SSL_pending);
   SSL_LOOKUP(SSL_library_init);
   SSL_LOOKUP(SSL_load_error_strings);
   SSL_LOOKUP(SSL_CTX_new);
   SSL_LOOKUP(SSL_CTX_use_certificate);
   SSL_LOOKUP(SSL_CTX_use_PrivateKey);
   SSL_LOOKUP(SSL_CIPHER_get_name);
   SSL_LOOKUP(SSL_CIPHER_get_bits);
   SSL_LOOKUP(SSL_get_current_cipher);
   SSL_LOOKUP(SSL_get_fd);
   SSL_LOOKUP(SSL_set_fd);
   SSL_LOOKUP(SSL_get_error);
   SSL_LOOKUP(SSL_get_peer_certificate);
   SSL_LOOKUP(sk_num);
   SSL_LOOKUP(sk_value);
   SSL_LOOKUP(RAND_seed);
   SSL_LOOKUP(BIO_new_socket);
   SSL_LOOKUP(BIO_new_mem_buf);
   SSL_LOOKUP(BIO_free);
   SSL_LOOKUP(SSL_CTX_ctrl);
   SSL_LOOKUP(SSL_CTX_set_verify);
   SSL_LOOKUP(SSL_CTX_load_verify_locations);
   SSL_LOOKUP(SSL_CTX_set_default_verify_paths);
   SSL_LOOKUP(SSL_set_bio);
   SSL_LOOKUP(SSL_set_connect_state);
   SSL_LOOKUP(SSL_state);
   SSL_LOOKUP(SSL_ctrl);
   SSL_LOOKUP(ERR_load_crypto_strings);
   SSL_LOOKUP(TLSv1_server_method);
   SSL_LOOKUP(SSLv23_server_method);
   SSL_LOOKUP(SSL_CTX_set_cipher_list);
   SSL_LOOKUP(SSL_CTX_use_certificate_chain_file);
   SSL_LOOKUP(SSL_CTX_use_RSAPrivateKey_file);
   SSL_LOOKUP(SSL_CTX_set_tmp_rsa_callback);
   SSL_LOOKUP(SSL_accept);
   SSL_LOOKUP(X509_STORE_CTX_get_error);
   SSL_LOOKUP(X509_verify_cert_error_string);
   SSL_LOOKUP(X509_STORE_CTX_get_current_cert);
   SSL_LOOKUP(X509_get_subject_name);
   SSL_LOOKUP(X509_NAME_oneline);
   SSL_LOOKUP(X509_get_ext_d2i);
   SSL_LOOKUP(X509_free);
   SSL_LOOKUP(SSL_shutdown);
   SSL_LOOKUP(SSL_CTX_free);
   SSL_LOOKUP(RSA_generate_key);
   SSL_LOOKUP(TLSv1_client_method);
   SSL_LOOKUP(SSLv23_client_method);
   SSL_LOOKUP(EVP_PKEY_free);
   SSL_LOOKUP(PEM_read_bio_X509);
   SSL_LOOKUP(PEM_read_bio_PrivateKey);

   CRYPTO_LOOKUP(ERR_get_error);
   CRYPTO_LOOKUP(ERR_error_string);

   gs_SSL_available =
   gs_SSL_loaded = true;

   STATUSMESSAGE((_("Successfully loaded '%s' and '%s' - "
                    "SSL authentication is now available."),
                  crypto_dll.c_str(),
                  ssl_dll.c_str()));

   ssl_onceonlyinit();

   return true;

error:
   if ( !s_errMsgGiven )
   {
      ERRORMESSAGE((_("SSL authentication is not available.")));

      s_errMsgGiven = true;

      // show the log dialog first
      wxLog::FlushActive();

      MDialog_Message
      (
         _("You can change the locations of the SSL and crypto "
           "libraries in the Helpers page of the preferences dialog\n"
           "if you have these libraries in non default location"
           " or if they have some other names on your system."),
         NULL,
         "SSL tip",
         "SSLLibTip"
      );
   }

   return false;
}