Esempio n. 1
0
void MFolderFromProfile::Delete()
{
   CHECK_RET( !m_folderName.empty(), _T("can't delete the root pseudo-folder") );

   // delete this folder from the parent profile
   String parentName = m_folderName.BeforeLast('/');
   Profile_obj profile(parentName);
   CHECK_RET( profile, _T("panic in MFolder: no profile") );

   profile->DeleteGroup(GetName());

   // let the parent now that its number of children changed
   MFolderFromProfile *parent = (MFolderFromProfile *)Get(parentName);
   if ( parent )
   {
      parent->OnSubfolderDelete();

      parent->DecRef();
   }
   else
   {
      // either we have managed to delete the root folder (bad) or something is
      // seriously wrong (even worse)
      FAIL_MSG( _T("no parent for deleted folder?") );
   }

   // notify everybody about the disappearance of the folder
   MEventManager::Send(
      new MEventFolderTreeChangeData (GetFullName(),
                                      MEventFolderTreeChangeData::Delete)
      );
}
Esempio n. 2
0
bool MFolderFromProfile::Rename(const String& newName)
{
   CHECK( !m_folderName.empty(), false, _T("can't rename the root pseudo-folder") );

   String path = m_folderName.BeforeLast(_T('/')),
          name = m_folderName.AfterLast(_T('/'));

   String newFullName = path;
   if ( !path.empty() )
      newFullName += _T('/');
   newFullName += newName;

   // we can't use Exists() here as it tries to read a value from the config
   // group newFullName and, as a side effect of this, creates this group, so
   // Profile::Rename() below will then fail!
#if 0
   if ( Exists(newFullName) )
   {
      wxLogError(_("Cannot rename folder '%s' to '%s': the folder with "
                   "the new name already exists."),
                   m_folderName.c_str(), newName.c_str());

      return false;
   }
#endif // 0

   Profile_obj profile(path);
   CHECK( profile, false, _T("panic in MFolder: no profile") );
   if ( !profile->Rename(name, newName) )
   {
      wxLogError(_("Cannot rename folder '%s' to '%s': the folder with "
                   "the new name already exists."),
                   m_folderName.c_str(), newName.c_str());

      return false;
   }

   String oldName = m_folderName;
   m_folderName = newFullName;

   // TODO: MFolderCache should just subscribe to "Rename" events...
   MFolderCache::RenameAll(oldName, newFullName);

   // notify everybody about the change of the folder name
   MEventManager::Send(
     new MEventFolderTreeChangeData(oldName,
                                    MEventFolderTreeChangeData::Rename,
                                    newFullName)
     );

   return true;
}
Esempio n. 3
0
wxIcon
wxIconManager::GetIconFromMimeType(const String& type, const String& ext)
{
   wxIcon icon;

   // use the system icons by default
   wxMimeTypesManager& mimeManager = mApplication->GetMimeManager();
   wxFileType *fileType = mimeManager.GetFileTypeFromMimeType(type);
   if ( !fileType && !ext.empty() )
   {
      fileType = mimeManager.GetFileTypeFromExtension(ext);
   }

   if ( fileType )
   {
#ifdef wxHAS_ICON_LOCATION
      wxIconLocation iconLoc;
      if ( fileType->GetIcon(&iconLoc) )
      {
         wxLogNull noLog;

         icon = wxIcon(iconLoc);
      }
#else // wx 2.4.x or very early 2.5.0
      (void)fileType->GetIcon(&icon);
#endif

      delete fileType;
   }

   if ( icon.Ok() )
      return icon;


   // now try to find it by name
   icon = GetIcon(type);

   if ( icon.IsSameAs(m_unknownIcon) )
   {
      // the generic icon for this class of things
      String primType = type.BeforeLast(_T('/'));
      if ( !primType.empty() )
         icon = GetIcon(primType);
   }

   return icon;
}
Esempio n. 4
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;
}
Esempio n. 5
0
MFolder *MFolderFromProfile::GetParent() const
{
   String path = m_folderName.BeforeLast(_T('/'));
   return Get(path);
}