+ icn = wxIcon(sTmp, wxBITMAP_TYPE_ANY);
+
+ if ( icn.Ok() )
+ {
+ *icon = icn;
+ if (iconFile) *iconFile = sTmp;
+ if (iconIndex) *iconIndex = 0;
+ return TRUE;
+ }
+#endif // wxUSE_GUI
+
+ return FALSE;
+}
+
+
+bool
+wxFileTypeImpl::GetMimeTypes(wxArrayString& mimeTypes) const
+{
+ mimeTypes.Clear();
+ for (size_t i = 0; i < m_index.GetCount(); i++)
+ mimeTypes.Add(m_manager->m_aTypes[m_index[i]]);
+ return TRUE;
+}
+
+
+size_t wxFileTypeImpl::GetAllCommands(wxArrayString *verbs,
+ wxArrayString *commands,
+ const wxFileType::MessageParameters& params) const
+{
+
+ wxString vrb, cmd, sTmp;
+ size_t count = 0;
+ wxMimeArrayString * sPairs;
+
+ // verbs and commands have been cleared already in mimecmn.cpp...
+ // if we find no entries in the exact match, try the inexact match
+ for (size_t n = 0; ((count ==0) && (n < m_index.GetCount())); n++)
+ {
+ // list of verb = command pairs for this mimetype
+ sPairs = m_manager->m_aEntries [m_index[n]];
+ size_t i;
+ for ( i = 0; i < sPairs->GetCount () ; i++ )
+ {
+ vrb = sPairs->GetVerb(i);
+ // some gnome entries have . inside
+ vrb = vrb.AfterLast(wxT('.'));
+ cmd = sPairs->GetCmd (i);
+ if (! cmd.IsEmpty() )
+ {
+ cmd = wxFileType::ExpandCommand(cmd, params);
+ count ++;
+ if ( vrb.IsSameAs (wxT("open")))
+ {
+ verbs->Insert(vrb,0u);
+ commands ->Insert(cmd,0u);
+ }
+ else
+ {
+ verbs->Add (vrb);
+ commands->Add (cmd);
+ }
+ }
+
+ }
+
+ }
+ return count;
+
+}
+
+bool wxFileTypeImpl::GetExtensions(wxArrayString& extensions)
+{
+ wxString strExtensions = m_manager->GetExtension(m_index[0]);
+ extensions.Empty();
+
+ // one extension in the space or comma delimitid list
+ wxString strExt;
+ for ( const wxChar *p = strExtensions; ; p++ ) {
+ if ( *p == wxT(' ') || *p == wxT(',') || *p == wxT('\0') ) {
+ if ( !strExt.IsEmpty() ) {
+ extensions.Add(strExt);
+ strExt.Empty();
+ }
+ //else: repeated spaces (shouldn't happen, but it's not that
+ // important if it does happen)
+
+ if ( *p == wxT('\0') )
+ break;
+ }
+ else if ( *p == wxT('.') ) {
+ // remove the dot from extension (but only if it's the first char)
+ if ( !strExt.IsEmpty() ) {
+ strExt += wxT('.');
+ }
+ //else: no, don't append it
+ }
+ else {
+ strExt += *p;
+ }
+ }
+
+ return TRUE;
+}
+
+// set an arbitrary command,
+// could adjust the code to ask confirmation if it already exists and
+// overwriteprompt is TRUE, but this is currently ignored as *Associate* has
+// no overwrite prompt
+bool wxFileTypeImpl::SetCommand(const wxString& cmd, const wxString& verb, bool overwriteprompt /*= TRUE*/)
+ {
+ wxArrayString strExtensions;
+ wxString strDesc, strIcon ;
+
+ wxMimeArrayString *entry = new wxMimeArrayString ();
+ entry->Add(verb + wxT("=") + cmd + wxT(" %s "));
+
+ wxArrayString strTypes;
+ GetMimeTypes (strTypes);
+ if (strTypes.GetCount() < 1) return FALSE;
+
+ size_t i;
+ bool Ok = TRUE;
+ for (i = 0; i < strTypes.GetCount(); i++)
+ {
+ if (!m_manager->DoAssociation (strTypes[i], strIcon, entry, strExtensions, strDesc))
+ Ok = FALSE;
+ }
+
+ return Ok;
+ }
+
+// ignore index on the grouds that we only have one icon in a Unix file
+bool wxFileTypeImpl::SetDefaultIcon(const wxString& strIcon /*= wxEmptyString*/, int /*index = 0*/)
+ {
+ if (strIcon.IsEmpty()) return FALSE;
+ wxArrayString strExtensions;
+ wxString strDesc;
+
+ wxMimeArrayString *entry = new wxMimeArrayString ();
+
+ wxArrayString strTypes;
+ GetMimeTypes (strTypes);
+ if (strTypes.GetCount() < 1) return FALSE;
+
+ size_t i;
+ bool Ok = TRUE;
+ for (i = 0; i < strTypes.GetCount(); i++)
+ {
+ if (!m_manager->DoAssociation (strTypes[i], strIcon, entry, strExtensions, strDesc))
+ Ok = FALSE;
+ }
+
+ return Ok;
+ }
+// ----------------------------------------------------------------------------
+// wxMimeTypesManagerImpl (Unix)
+// ----------------------------------------------------------------------------
+
+
+wxMimeTypesManagerImpl::wxMimeTypesManagerImpl()
+{
+ m_initialized = FALSE;
+ m_mailcapStylesInited = 0;
+}
+
+// read system and user mailcaps and other files
+void wxMimeTypesManagerImpl::Initialize(int mailcapStyles,
+ const wxString& sExtraDir)
+{
+ // read mimecap amd mime.types
+ if ( (mailcapStyles & wxMAILCAP_NETSCAPE) ||
+ (mailcapStyles & wxMAILCAP_STANDARD) )
+ GetMimeInfo(sExtraDir);
+
+ // read GNOME tables
+ if ( mailcapStyles & wxMAILCAP_GNOME)
+ GetGnomeMimeInfo(sExtraDir);
+
+ // read KDE tables
+ if ( mailcapStyles & wxMAILCAP_KDE)
+ GetKDEMimeInfo(sExtraDir);
+
+ m_mailcapStylesInited |= mailcapStyles;
+}
+
+// clear data so you can read another group of WM files
+void wxMimeTypesManagerImpl::ClearData()
+{
+ m_aTypes.Clear ();
+ m_aIcons.Clear ();
+ m_aExtensions.Clear ();
+ m_aDescriptions.Clear ();
+
+ size_t cnt = m_aTypes.GetCount();
+ for (size_t i = 0; i < cnt; i++)
+ {
+ m_aEntries[i]->Clear ();
+ }
+ m_aEntries.Clear ();
+ m_mailcapStylesInited = 0;
+}
+
+wxMimeTypesManagerImpl::~wxMimeTypesManagerImpl()
+{
+ ClearData(); // do we need to delete the ArrayStrings too to avoid a leak
+
+// delete m_aEntries //fix a leak here ?;
+}
+
+
+void wxMimeTypesManagerImpl::GetMimeInfo (const wxString& sExtraDir)
+{
+ // read this for netscape or Metamail formats
+
+ // directories where we look for mailcap and mime.types by default
+ // used by netscape and pine and other mailers, using 2 different formats!
+
+ // (taken from metamail(1) sources)
+ //
+ // although RFC 1524 specifies the search path of
+ // /etc/:/usr/etc:/usr/local/etc only, it doesn't hurt to search in more
+ // places - OTOH, the RFC also says that this path can be changed with
+ // MAILCAPS environment variable (containing the colon separated full
+ // filenames to try) which is not done yet (TODO?)
+
+ wxString strHome = wxGetenv(wxT("HOME"));
+
+ wxArrayString dirs;
+ dirs.Add ( strHome + wxT("/.") );
+ dirs.Add ( wxT("/etc/") );
+ dirs.Add ( wxT("/usr/etc/") );
+ dirs.Add ( wxT("/usr/local/etc/") );
+ dirs.Add ( wxT("/etc/mail/") );
+ dirs.Add ( wxT("/usr/public/lib/") );
+ if (!sExtraDir.IsEmpty()) dirs.Add ( sExtraDir + wxT("/") );
+
+ size_t nDirs = dirs.GetCount();
+ for ( size_t nDir = 0; nDir < nDirs; nDir++ )
+ {
+ wxString file = dirs[nDir] + wxT("mailcap");
+ if ( wxFile::Exists(file) ) {
+ ReadMailcap(file);
+ }
+
+ file = dirs[nDir] + wxT("mime.types");
+ if ( wxFile::Exists(file) ) {
+ ReadMimeTypes(file);
+ }
+ }
+
+}
+
+bool wxMimeTypesManagerImpl::WriteToMimeTypes (int index, bool delete_index)
+{
+ // check we have the right manager
+ if (! ( m_mailcapStylesInited & wxMAILCAP_STANDARD) )
+ return FALSE;
+
+ bool bTemp;
+ wxString strHome = wxGetenv(wxT("HOME"));
+
+ // and now the users mailcap
+ wxString strUserMailcap = strHome + wxT("/.mime.types");
+
+ wxMimeTextFile file;
+ if ( wxFile::Exists(strUserMailcap) )
+ {
+ bTemp = file.Open(strUserMailcap);
+ }
+ else
+ {
+ if (delete_index) return FALSE;
+ bTemp = file.Create(strUserMailcap);
+ }
+ if (bTemp)
+ {
+ int nIndex;
+ // test for netscape's header and return FALSE if its found
+ nIndex = file.pIndexOf (wxT("#--Netscape"));
+ if (nIndex != wxNOT_FOUND)
+ {
+ wxASSERT_MSG(FALSE,wxT("Error in .mime.types \nTrying to mix Netscape and Metamail formats\nFile not modiifed"));
+ return FALSE;
+ }
+ // write it in alternative format
+ // get rid of unwanted entries
+ wxString strType = m_aTypes[index];
+ nIndex = file.pIndexOf (strType);
+ // get rid of all the unwanted entries...
+ if (nIndex != wxNOT_FOUND) file.CommentLine (nIndex);
+
+ if (!delete_index)
+ {
+ // add the new entries in
+ wxString sTmp = strType.Append (wxT(' '), 40-strType.Len() );
+ sTmp = sTmp + m_aExtensions[index];
+ file.AddLine (sTmp);
+ }
+
+
+ bTemp = file.Write ();
+ file.Close ();
+ }
+ return bTemp;
+}
+
+bool wxMimeTypesManagerImpl::WriteToNSMimeTypes (int index, bool delete_index)
+{
+ //check we have the right managers
+ if (! ( m_mailcapStylesInited & wxMAILCAP_NETSCAPE) )
+ return FALSE;
+
+ bool bTemp;
+ wxString strHome = wxGetenv(wxT("HOME"));
+
+ // and now the users mailcap
+ wxString strUserMailcap = strHome + wxT("/.mime.types");
+
+ wxMimeTextFile file;
+ if ( wxFile::Exists(strUserMailcap) )
+ {
+ bTemp = file.Open(strUserMailcap);
+ }
+ else
+ {
+ if (delete_index) return FALSE;
+ bTemp = file.Create(strUserMailcap);
+ }
+ if (bTemp)
+ {
+
+ // write it in the format that Netscape uses
+ int nIndex;
+ // test for netscape's header and insert if required...
+ // this is a comment so use TRUE
+ nIndex = file.pIndexOf (wxT("#--Netscape"), TRUE);
+ if (nIndex == wxNOT_FOUND)
+ {
+ // either empty file or metamail format
+ // at present we can't cope with mixed formats, so exit to preseve
+ // metamail entreies
+ if (file.GetLineCount () > 0)
+ {
+ wxASSERT_MSG(FALSE, wxT(".mime.types File not in Netscape format\nNo entries written to\n.mime.types or to .mailcap"));
+ return FALSE;
+ }
+ file.InsertLine (wxT( "#--Netscape Communications Corporation MIME Information" ), 0);
+ nIndex = 0;
+ }
+
+ wxString strType = wxT("type=") + m_aTypes[index];
+ nIndex = file.pIndexOf (strType);
+ // get rid of all the unwanted entries...
+ if (nIndex != wxNOT_FOUND)
+ {
+ wxString sOld = file[nIndex];
+ while ( (sOld.Contains(wxT("\\"))) && (nIndex < (int) file.GetLineCount()) )
+ {
+ file.CommentLine(nIndex);
+ sOld = file[nIndex];
+ wxLogTrace(TRACE_MIME, wxT("--- Deleting from mime.types line '%d %s' ---"), nIndex, sOld.c_str());
+ nIndex ++;
+ }
+ if (nIndex < (int) file.GetLineCount()) file.CommentLine (nIndex);
+ }
+ else nIndex = (int) file.GetLineCount();
+
+ wxString sTmp = strType + wxT(" \\");
+ if (!delete_index) file.InsertLine (sTmp, nIndex);
+ if ( ! m_aDescriptions.Item(index).IsEmpty() )
+ {
+ sTmp = wxT("desc=\"") + m_aDescriptions[index]+ wxT("\" \\") ; //.trim ??
+ if (!delete_index)
+ {
+ nIndex ++;
+ file.InsertLine (sTmp, nIndex);
+ }
+ }
+ wxString sExts = m_aExtensions.Item(index);
+ sTmp = wxT("exts=\"") + sExts.Trim(FALSE).Trim() + wxT("\"");
+ if (!delete_index)
+ {
+ nIndex ++;
+ file.InsertLine (sTmp, nIndex);
+ }
+
+ bTemp = file.Write ();
+ file.Close ();
+ }
+ return bTemp;
+}
+
+
+bool wxMimeTypesManagerImpl::WriteToMailCap (int index, bool delete_index)
+{
+ //check we have the right managers
+ if ( !( ( m_mailcapStylesInited & wxMAILCAP_NETSCAPE) ||
+ ( m_mailcapStylesInited & wxMAILCAP_STANDARD) ) )
+ return FALSE;
+
+ bool bTemp;
+ wxString strHome = wxGetenv(wxT("HOME"));
+
+ // and now the users mailcap
+ wxString strUserMailcap = strHome + wxT("/.mailcap");
+
+ wxMimeTextFile file;
+ if ( wxFile::Exists(strUserMailcap) )
+ {
+ bTemp = file.Open(strUserMailcap);
+ }
+ else
+ {
+ if (delete_index) return FALSE;
+ bTemp = file.Create(strUserMailcap);
+ }
+ if (bTemp)
+ {
+ // now got a file we can write to ....
+ wxMimeArrayString * entries = m_aEntries[index];
+ size_t iOpen = entries->pIndexOf(wxT("open"));
+ wxString sCmd = entries->GetCmd(iOpen);
+ wxString sTmp;
+
+ sTmp = m_aTypes[index];
+ wxString sOld;
+ int nIndex = file.pIndexOf(sTmp);
+ // get rid of all the unwanted entries...
+ if (nIndex == wxNOT_FOUND)
+ {
+ nIndex = (int) file.GetLineCount();
+ }
+ else
+ {
+ sOld = file[nIndex];
+ wxLogTrace(TRACE_MIME, wxT("--- Deleting from mailcap line '%d' ---"), nIndex);