Ejemplo n.º 1
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;
}
Ejemplo n.º 2
0
String MFolderFromProfile::GetName() const
{
   return m_folderName.AfterLast(_T('/'));
}
Ejemplo n.º 3
0
bool MFolderFromProfile::Move(MFolder *newParent)
{
   CHECK( newParent, false, _T("no new parent in MFolder::Move()") );

   // This does not really 'move' the folder, but it creates a new one with the
   // correct parent and name, and copies all the profile information from the
   // old one to the new one. It then calls Delete on itself, so that the old
   // folder is removed from the tree. Last thing is to notify everyone that a
   // new folder has been created.

   // There are things that do not make sense at all
   CHECK( GetFolderType(GetType()) != MF_ILLEGAL, false,
            _T("How did you manage to try to move an MF_ILLEGAL folder ?") );
   CHECK( GetFolderType(GetType()) != MF_NEWS, false,
            _T("can't move News folders") );
   CHECK( GetFolderType(GetType()) != MF_INBOX, false,
            _T("can't move system Inbox") );
   CHECK( GetFolderType(GetType()) != MF_ROOT, false,
            _T("can't move the root pseudo-folder") );

   // And there are things we can't do yet.
   CHECK( GetSubfolderCount() == 0, false, _T("can't move a folder with sub-folders (yet)") );
   CHECK( GetFolderType(GetType()) != MF_IMAP, false, _T("can't move IMAP folders (yet)") );

   if ( GetFolderType(GetType()) == MF_IMAP )
   {
      // IMAP folders have one more check: we must make sure that they stay on
      // the same server, so that we can simply send it a RENAME command.
      CHECK( false, false, _T("Same server check not yet implemented") );
   }
   
   // Compute the name of the folder to create
   String path = newParent->GetFullName();
   String name = m_folderName.AfterLast('/');
   String newFullName = path;
   if ( !path.empty() )
      newFullName += _T('/');
   newFullName += name;

   // Create a new folder
   MFolder_obj newSubfolder(newParent->CreateSubfolder(name, MF_ILLEGAL));
   if ( !newSubfolder )
   {
      wxLogError(_("Could not create subfolder '%s' in '%s'."),
                   name.c_str(), path.c_str());
      return false;
   }

   wxString oldProfilePath, newProfilePath;
   oldProfilePath << Profile::GetProfilePath() << '/' << m_folderName;
   newProfilePath << Profile::GetProfilePath() << '/' << newFullName;
   if ( CopyEntries(mApplication->GetProfile()->GetConfig(), oldProfilePath, newProfilePath, false) == -1 )
   {
      wxLogError(_("Could not copy profile."));
      return false;
   }

   if ( GetFolderType(GetType()) == MF_IMAP )
   {
      // IMAP folders need one last specific thing: send a RENAME
      // command to the server, unless we are moving the root folder
      // for this server (in this case, nothing changes on the server
      // and no RENAME command should be issued).
      CHECK( false, false, _T("RENAME command to server not yet implemented") );
   }

   // We should update the cache, but I (XNO) did not find a way to do it correctly.
   //MFolderCache::Remove(this);
   //MFolderCache::Add(newSubfolder);
   
   // Iterate over all the filters to change the name of the folder where
   // it appears.
   wxArrayString allFilterNames = MFilter::GetAllFilters();
   for ( size_t i = 0; i < allFilterNames.GetCount(); ++i )
   {
      wxString filterName = allFilterNames[i];
      MFilter *filter = MFilter::CreateFromProfile(filterName);
      MFilterDesc filterDesc = filter->GetDesc();
      if ( filterDesc.IsSimple() )
      {
         MFDialogSettings *dialogSettings = filterDesc.GetSettings();
         wxString argument = dialogSettings->GetActionArgument();
         size_t nbReplacements = argument.Replace(m_folderName, newFullName);
         if ( nbReplacements > 0 )
         {
            dialogSettings->SetAction(dialogSettings->GetAction(), argument);
            filterDesc.Set(dialogSettings);
            filter->Set(filterDesc);
            wxLogStatus(_("Filter '%s' has been updated."), filterName.c_str());
         }
         else
         {
            dialogSettings->DecRef();
         }
      }
      else
      {
         // XNOTODO: Find out how to update this filter anyway
         wxLogError(_("Filter '%s' is not \"simple\" and has not been updated."), filterName.c_str());
      }
      filter->DecRef();
   }

   /*
   // notify everybody about the disappearance of the old folder
   MEventManager::Send(
      new MEventFolderTreeChangeData (m_folderName,
                                      MEventFolderTreeChangeData::Delete)
      );
      */
   // notify everybody about the creation of the new folder
   MEventManager::Send(
      new MEventFolderTreeChangeData(newFullName,
                                     MEventFolderTreeChangeData::Create)
      );

   // Now, we can delete the old folder from the hierarchy
   Delete();

   struct MailFolderStatus status;
   MfStatusCache* cache = MfStatusCache::Get();
   if ( cache->GetStatus(m_folderName, &status) )
      cache->UpdateStatus(newFullName, status);

   return true;
}