-bool wxMimeTypesManagerImpl::CheckGnomeDirsExist ()
- {
- wxString gnomedir;
- wxGetHomeDir( &gnomedir );
- wxString sTmp = gnomedir;
- sTmp = sTmp + "/.gnome" ;
- if (! wxDir::Exists ( sTmp ) )
- {
- if (!wxMkdir ( sTmp ))
- {
- wxFAIL_MSG (wxString ("Failed to create directory\n.gnome in \nCheckGnomeDirsExist") + sTmp );
- return FALSE;
- }
- }
- sTmp = sTmp + "/mime-info";
- if (! wxDir::Exists ( sTmp ) )
- {
- if (!wxMkdir ( sTmp ))
- {
- wxFAIL_MSG (wxString ("Failed to create directory\nmime-info in \nCheckGnomeDirsExist") + sTmp );
- return FALSE;
- }
- }
- return TRUE;
-
-}
-
-
-
-bool wxMimeTypesManagerImpl::WriteGnomeKeyFile(int index, bool delete_index)
- {
- wxString gnomedir;
- wxGetHomeDir( &gnomedir );
-
- wxMimeTextFile outfile ( gnomedir + "/.gnome/mime-info/user.keys");
- // if this fails probably Gnome is not installed ??
- // create it anyway as a private mime store
-
- if (! outfile.Open () )
- {
- if (delete_index) return FALSE;
- if (!CheckGnomeDirsExist() ) return FALSE;
- outfile.Create ();
- }
-
- wxString sTmp, strType = m_aTypes[index];
- int nIndex = outfile.pIndexOf(strType);
- if ( nIndex == wxNOT_FOUND )
- {
- outfile.AddLine ( strType + wxT(':') );
- // see file:/usr/doc/gnome-libs-devel-1.0.40/devel-docs/mime-type-handling.txt
- // as this does not deal with internationalisation
- // wxT( "\t[en_US]") + verb + wxT ('=') + cmd + wxT(" %f");
- wxMimeArrayString * entries = m_aEntries[index];
- size_t i;
- for (i=0; i < entries->GetCount(); i++)
- {
- sTmp = entries->Item(i);
- sTmp.Replace( wxT("%s"), wxT("%f") );
- sTmp = wxT ( "\t") + sTmp;
- outfile.AddLine ( sTmp );
- }
- //for international use do something like this
- //outfile.AddLine ( wxString( "\t[en_US]icon-filename=") + cmd );
- outfile.AddLine ( wxT( "\ticon-filename=") + m_aIcons[index] );
- }
- else
- {
- if (delete_index) outfile.CommentLine(nIndex);
- wxMimeArrayString sOld;
- size_t nOld = nIndex + 1;
- bool oldEntryEnd = FALSE;
- while ( (nOld < outfile.GetLineCount() )&& (oldEntryEnd == FALSE ))
- {
- sTmp = outfile.GetLine(nOld);
- if ( (sTmp[0u] == wxT('\t')) || (sTmp[0u] == wxT('#')) )
- {
- // we have another line to deal with
- outfile.CommentLine(nOld);
- nOld ++;
- // add the line to our store
- if ((!delete_index) && (sTmp[0u] == wxT('\t'))) sOld.Add(sTmp);
- }
- // next mimetpye ??or blank line
- else oldEntryEnd = TRUE;
- }
- // list of entries in our data; these should all be in sOld,
- // though sOld may also contain other entries , eg flags
- if (!delete_index)
- {
- wxMimeArrayString * entries = m_aEntries[index];
- size_t i;
- for (i=0; i < entries->GetCount(); i++)
- {
- // replace any entries in sold that match verbs we know
- sOld.ReplaceOrAddLineCmd ( entries->GetVerb(i), entries->GetCmd (i) );
- }
- //sOld should also contain the icon
- if ( !m_aIcons[index].IsEmpty() )
- sOld.ReplaceOrAddLineCmd ( wxT( "icon-filename"), m_aIcons[index] );
-
- for (i=0; i < sOld.GetCount(); i++)
- {
- sTmp = sOld.Item(i);
- sTmp.Replace( wxT("%s"), wxT("%f") );
- sTmp = wxT ( "\t") + sTmp;
- nIndex ++;
- outfile.InsertLine ( sTmp, nIndex );
- }
- }
- }
- bool bTmp = outfile.Write ();
- return bTmp;
- }
-
-
-bool wxMimeTypesManagerImpl::WriteGnomeMimeFile(int index, bool delete_index)
- {
- wxString gnomedir;
- wxGetHomeDir( &gnomedir );
-
- wxMimeTextFile outfile ( gnomedir + "/.gnome/mime-info/user.mime");
- // if this fails probably Gnome is not installed ??
- // create it anyway as a private mime store
- if (! outfile.Open () )
- {
- if (delete_index) return FALSE;
- if (!CheckGnomeDirsExist() ) return FALSE;
- outfile.Create ();
- }
- wxString strType = m_aTypes[index];
- int nIndex = outfile.pIndexOf(strType);
- if ( nIndex == wxNOT_FOUND )
- {
- outfile.AddLine ( strType );
- outfile.AddLine ( wxT( "\text:") + m_aExtensions.Item(index) );
- }
- else
- {
- if (delete_index)
- {
- outfile.CommentLine(nIndex);
- outfile.CommentLine(nIndex+1);
- }
- else
- {// check for next line being the right one to replace ??
- wxString sOld = outfile.GetLine(nIndex+1);
- if (sOld.Contains(wxT("\text: ")))
- {
- outfile.GetLine(nIndex+1) = wxT( "\text: ") + m_aExtensions.Item(index);
- }
- else
- {
- outfile.InsertLine(wxT( "\text: ") + m_aExtensions.Item(index), nIndex + 1 );
- }
- }
- }
- bool bTmp = outfile.Write ();
- return bTmp;
-}
-
-
-void wxMimeTypesManagerImpl::LoadGnomeDataFromKeyFile(const wxString& filename)