mimetype.cpp/.h split into unix,mac,msw
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@5529 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
75
include/wx/mac/mimetype.h
Normal file
75
include/wx/mac/mimetype.h
Normal file
@@ -0,0 +1,75 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: wx/mac/mimetype.h
|
||||
// Purpose: classes and functions to manage MIME types
|
||||
// Author: Vadim Zeitlin
|
||||
// Modified by:
|
||||
// Created: 23.09.98
|
||||
// RCS-ID: $Id$
|
||||
// Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
|
||||
// Licence: wxWindows license (part of wxExtra library)
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef _MIMETYPE_IMPL_H
|
||||
#define _MIMETYPE_IMPL_H
|
||||
|
||||
|
||||
#include "wx/defs.h"
|
||||
#include "wx/mimetype.h"
|
||||
|
||||
|
||||
|
||||
class wxMimeTypesManagerImpl
|
||||
{
|
||||
public :
|
||||
wxMimeTypesManagerImpl() { }
|
||||
|
||||
// implement containing class functions
|
||||
wxFileType *GetFileTypeFromExtension(const wxString& ext);
|
||||
wxFileType *GetFileTypeFromMimeType(const wxString& mimeType);
|
||||
|
||||
size_t EnumAllFileTypes(wxArrayString& mimetypes);
|
||||
|
||||
// this are NOPs under MacOS
|
||||
bool ReadMailcap(const wxString& filename, bool fallback = TRUE) { return TRUE; }
|
||||
bool ReadMimeTypes(const wxString& filename) { return TRUE; }
|
||||
|
||||
void AddFallback(const wxFileTypeInfo& ft) { m_fallbacks.Add(ft); }
|
||||
|
||||
private:
|
||||
wxArrayFileTypeInfo m_fallbacks;
|
||||
};
|
||||
|
||||
class wxFileTypeImpl
|
||||
{
|
||||
public:
|
||||
// initialize us with our file type name
|
||||
void SetFileType(const wxString& strFileType)
|
||||
{ m_strFileType = strFileType; }
|
||||
void SetExt(const wxString& ext)
|
||||
{ m_ext = ext; }
|
||||
|
||||
// implement accessor functions
|
||||
bool GetExtensions(wxArrayString& extensions);
|
||||
bool GetMimeType(wxString *mimeType) const;
|
||||
bool GetIcon(wxIcon *icon) const;
|
||||
bool GetDescription(wxString *desc) const;
|
||||
bool GetOpenCommand(wxString *openCmd,
|
||||
const wxFileType::MessageParameters&) const
|
||||
{ return GetCommand(openCmd, "open"); }
|
||||
bool GetPrintCommand(wxString *printCmd,
|
||||
const wxFileType::MessageParameters&) const
|
||||
{ return GetCommand(printCmd, "print"); }
|
||||
|
||||
private:
|
||||
// helper function
|
||||
bool GetCommand(wxString *command, const char *verb) const;
|
||||
|
||||
wxString m_strFileType, m_ext;
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
//_MIMETYPE_H
|
||||
|
||||
/* vi: set cin tw=80 ts=4 sw=4: */
|
94
include/wx/msw/mimetype.h
Normal file
94
include/wx/msw/mimetype.h
Normal file
@@ -0,0 +1,94 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: wx/mimetype.h
|
||||
// Purpose: classes and functions to manage MIME types
|
||||
// Author: Vadim Zeitlin
|
||||
// Modified by:
|
||||
// Created: 23.09.98
|
||||
// RCS-ID: $Id$
|
||||
// Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
|
||||
// Licence: wxWindows license (part of wxExtra library)
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef _MIMETYPE_IMPL_H
|
||||
#define _MIMETYPE_IMPL_H
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma interface "mimetype.h"
|
||||
#endif
|
||||
|
||||
#include "wx/defs.h"
|
||||
|
||||
#include "wx/mimetype.h"
|
||||
|
||||
|
||||
class WXDLLEXPORT wxFileTypeImpl
|
||||
{
|
||||
public:
|
||||
// ctor
|
||||
wxFileTypeImpl() { m_info = NULL; }
|
||||
|
||||
// one of these Init() function must be called (ctor can't take any
|
||||
// arguments because it's common)
|
||||
|
||||
// initialize us with our file type name and extension - in this case
|
||||
// we will read all other data from the registry
|
||||
void Init(const wxString& strFileType, const wxString& ext)
|
||||
{ m_strFileType = strFileType; m_ext = ext; }
|
||||
|
||||
// initialize us with a wxFileTypeInfo object - it contains all the
|
||||
// data
|
||||
void Init(const wxFileTypeInfo& info)
|
||||
{ m_info = &info; }
|
||||
|
||||
// implement accessor functions
|
||||
bool GetExtensions(wxArrayString& extensions);
|
||||
bool GetMimeType(wxString *mimeType) const;
|
||||
bool GetIcon(wxIcon *icon) const;
|
||||
bool GetDescription(wxString *desc) const;
|
||||
bool GetOpenCommand(wxString *openCmd,
|
||||
const wxFileType::MessageParameters& params) const;
|
||||
bool GetPrintCommand(wxString *printCmd,
|
||||
const wxFileType::MessageParameters& params) const;
|
||||
|
||||
private:
|
||||
// helper function: reads the command corresponding to the specified verb
|
||||
// from the registry (returns an empty string if not found)
|
||||
wxString GetCommand(const wxChar *verb) const;
|
||||
|
||||
// we use either m_info or read the data from the registry if m_info == NULL
|
||||
const wxFileTypeInfo *m_info;
|
||||
wxString m_strFileType, // may be empty
|
||||
m_ext;
|
||||
};
|
||||
|
||||
|
||||
|
||||
class WXDLLEXPORT wxMimeTypesManagerImpl
|
||||
{
|
||||
public:
|
||||
// nothing to do here, we don't load any data but just go and fetch it from
|
||||
// the registry when asked for
|
||||
wxMimeTypesManagerImpl() { }
|
||||
|
||||
// implement containing class functions
|
||||
wxFileType *GetFileTypeFromExtension(const wxString& ext);
|
||||
wxFileType *GetFileTypeFromMimeType(const wxString& mimeType);
|
||||
|
||||
size_t EnumAllFileTypes(wxArrayString& mimetypes);
|
||||
|
||||
// this are NOPs under Windows
|
||||
bool ReadMailcap(const wxString& filename, bool fallback = TRUE)
|
||||
{ return TRUE; }
|
||||
bool ReadMimeTypes(const wxString& filename)
|
||||
{ return TRUE; }
|
||||
|
||||
void AddFallback(const wxFileTypeInfo& ft) { m_fallbacks.Add(ft); }
|
||||
|
||||
private:
|
||||
wxArrayFileTypeInfo m_fallbacks;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
//_MIMETYPE_IMPL_H
|
||||
|
126
include/wx/unix/mimetype.h
Normal file
126
include/wx/unix/mimetype.h
Normal file
@@ -0,0 +1,126 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: unix/mimetype.h
|
||||
// Purpose: classes and functions to manage MIME types
|
||||
// Author: Vadim Zeitlin
|
||||
// Modified by:
|
||||
// Created: 23.09.98
|
||||
// RCS-ID: $Id$
|
||||
// Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
|
||||
// Licence: wxWindows license (part of wxExtra library)
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef _MIMETYPE_IMPL_H
|
||||
#define _MIMETYPE_IMPL_H
|
||||
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma interface "mimetype.h"
|
||||
#endif
|
||||
|
||||
#include "wx/mimetype.h"
|
||||
|
||||
#if (wxUSE_FILE && wxUSE_TEXTFILE)
|
||||
|
||||
class MailCapEntry;
|
||||
class wxMimeTypeIconHandler;
|
||||
|
||||
WX_DEFINE_ARRAY(wxMimeTypeIconHandler *, ArrayIconHandlers);
|
||||
WX_DEFINE_ARRAY(MailCapEntry *, ArrayTypeEntries);
|
||||
|
||||
// this is the real wxMimeTypesManager for Unix
|
||||
class WXDLLEXPORT wxMimeTypesManagerImpl
|
||||
{
|
||||
friend class WXDLLEXPORT wxFileTypeImpl; // give it access to m_aXXX variables
|
||||
|
||||
public:
|
||||
// ctor loads all info into memory for quicker access later on
|
||||
// TODO it would be nice to load them all, but parse on demand only...
|
||||
wxMimeTypesManagerImpl();
|
||||
|
||||
// implement containing class functions
|
||||
wxFileType *GetFileTypeFromExtension(const wxString& ext);
|
||||
wxFileType *GetFileTypeFromMimeType(const wxString& mimeType);
|
||||
|
||||
size_t EnumAllFileTypes(wxArrayString& mimetypes);
|
||||
|
||||
bool ReadMailcap(const wxString& filename, bool fallback = FALSE);
|
||||
bool ReadMimeTypes(const wxString& filename);
|
||||
|
||||
void AddFallback(const wxFileTypeInfo& filetype);
|
||||
|
||||
// add information about the given mimetype
|
||||
void AddMimeTypeInfo(const wxString& mimetype,
|
||||
const wxString& extensions,
|
||||
const wxString& description);
|
||||
void AddMailcapInfo(const wxString& strType,
|
||||
const wxString& strOpenCmd,
|
||||
const wxString& strPrintCmd,
|
||||
const wxString& strTest,
|
||||
const wxString& strDesc);
|
||||
|
||||
// accessors
|
||||
// get the string containing space separated extensions for the given
|
||||
// file type
|
||||
wxString GetExtension(size_t index) { return m_aExtensions[index]; }
|
||||
|
||||
// get the array of icon handlers
|
||||
static ArrayIconHandlers& GetIconHandlers();
|
||||
|
||||
private:
|
||||
wxArrayString m_aTypes, // MIME types
|
||||
m_aDescriptions, // descriptions (just some text)
|
||||
m_aExtensions; // space separated list of extensions
|
||||
ArrayTypeEntries m_aEntries; // commands and tests for this file type
|
||||
|
||||
// head of the linked list of the icon handlers
|
||||
static ArrayIconHandlers ms_iconHandlers;
|
||||
};
|
||||
|
||||
class WXDLLEXPORT wxFileTypeImpl
|
||||
{
|
||||
public:
|
||||
// initialization functions
|
||||
void Init(wxMimeTypesManagerImpl *manager, size_t index)
|
||||
{ m_manager = manager; m_index = index; }
|
||||
|
||||
// accessors
|
||||
bool GetExtensions(wxArrayString& extensions);
|
||||
bool GetMimeType(wxString *mimeType) const
|
||||
{ *mimeType = m_manager->m_aTypes[m_index]; return TRUE; }
|
||||
bool GetIcon(wxIcon *icon) const;
|
||||
bool GetDescription(wxString *desc) const
|
||||
{ *desc = m_manager->m_aDescriptions[m_index]; return TRUE; }
|
||||
|
||||
bool GetOpenCommand(wxString *openCmd,
|
||||
const wxFileType::MessageParameters& params) const
|
||||
{
|
||||
return GetExpandedCommand(openCmd, params, TRUE);
|
||||
}
|
||||
|
||||
bool GetPrintCommand(wxString *printCmd,
|
||||
const wxFileType::MessageParameters& params) const
|
||||
{
|
||||
return GetExpandedCommand(printCmd, params, FALSE);
|
||||
}
|
||||
|
||||
private:
|
||||
// get the entry which passes the test (may return NULL)
|
||||
MailCapEntry *GetEntry(const wxFileType::MessageParameters& params) const;
|
||||
|
||||
// choose the correct entry to use and expand the command
|
||||
bool GetExpandedCommand(wxString *expandedCmd,
|
||||
const wxFileType::MessageParameters& params,
|
||||
bool open) const;
|
||||
|
||||
wxMimeTypesManagerImpl *m_manager;
|
||||
size_t m_index; // in the wxMimeTypesManagerImpl arrays
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
// wxUSE_FILE
|
||||
|
||||
#endif
|
||||
//_MIMETYPE_IMPL_H
|
||||
|
Reference in New Issue
Block a user