-bool wxMimeTypesManagerImpl::CheckGnomeDirsExist ()
-{
- wxString gnomedir;
- wxGetHomeDir( &gnomedir );
- wxString sTmp = gnomedir;
- sTmp = sTmp + wxT("/.gnome");
- if (! wxDir::Exists ( sTmp ) )
- {
- if (!wxMkdir ( sTmp ))
- {
- wxLogError(wxT("Failed to create directory %s/.gnome."), sTmp.c_str());
- return false;
- }
- }
- sTmp = sTmp + wxT("/mime-info");
- if (! wxDir::Exists ( sTmp ) )
- {
- if (!wxMkdir ( sTmp ))
- {
- wxLogError(wxT("Failed to create directory %s/mime-info."), sTmp.c_str());
- return false;
- }
- }
-
- return true;
-}
-
-bool wxMimeTypesManagerImpl::WriteGnomeKeyFile(int index, bool delete_index)
-{
- wxString gnomedir;
- wxGetHomeDir( &gnomedir );
-
- wxMimeTextFile outfile( gnomedir + wxT("/.gnome/mime-info/user.keys"));
- // if this fails probably Gnome is not installed ??
- // create it anyway as a private mime store
-
-#if defined(__WXGTK20__) && wxUSE_UNICODE
- if (! outfile.Open ( wxConvUTF8) )
-#else
- if (! outfile.Open () )
-#endif
- {
- 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");
- wxMimeTypeCommands * entries = m_aEntries[index];
- size_t count = entries->GetCount();
- for ( size_t i = 0; i < count; i++ )
- {
- sTmp = entries->GetVerbCmd(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);
-
- wxMimeTypeCommands sOld;
- size_t nOld = nIndex + 1;
- bool oldEntryEnd = false;
- while ( (nOld < outfile.GetLineCount() )&& (!oldEntryEnd))
- {
- 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)
- {
- wxMimeTypeCommands * 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.AddOrReplaceVerb( entries->GetVerb(i), entries->GetCmd(i) );
- }
-
- //sOld should also contain the icon
- if ( !m_aIcons[index].empty() )
- sOld.AddOrReplaceVerb( wxT("icon-filename"), m_aIcons[index] );
-
- for (i=0; i < sOld.GetCount(); i++)
- {
- sTmp = sOld.GetVerbCmd(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 + wxT("/.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;
-}
-