From e2bc6f4153813cc570ae814c8ddb74628009b488 Mon Sep 17 00:00:00 2001 From: Michal Kubecek Date: Mon, 13 Apr 2015 09:21:39 +0200 Subject: initial checkin Check in contents of upstream 1.4.2 tarball, exclude generated files. --- src/utils/mime_database.h | 90 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 src/utils/mime_database.h (limited to 'src/utils/mime_database.h') diff --git a/src/utils/mime_database.h b/src/utils/mime_database.h new file mode 100644 index 0000000..fcf6444 --- /dev/null +++ b/src/utils/mime_database.h @@ -0,0 +1,90 @@ +/* + Copyright (C) 2005-2009 Michel de Boer + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +/** + * @file + * Mime database + * Conversion between mime types, file content and file extensions. + */ + +#ifndef _MIME_DATABASE_H +#define _MIME_DATABASE_H + +#include +#include +#include + +#include "record_file.h" + +using namespace std; + +namespace utils { + +/** Record from the mime database. */ +class t_mime_db_record : public utils::t_record { +public: + string mimetype; /**< Mimetype, e.g. text/plain */ + string file_glob; /**< File glob expression */ + + virtual bool create_file_record(vector &v) const; + virtual bool populate_from_file_record(const vector &v); +}; + +/** + * The mime database. + * The default location for the mime database is /usr/share/mime/globs + */ +class t_mime_database : public utils::t_record_file { +private: + /** Mapping between mimetypes and file globs. */ + map map_mime2glob_; + + /** Handle on the magic number database. */ + magic_t mime_magic_; + +protected: + virtual void add_record(const t_mime_db_record &record); + +public: + /** Constructor */ + t_mime_database(); + + /** Destructor */ + ~t_mime_database(); + + /** + * Get a glob expression for a mimetype. + * @param mimetype [in] The mimetype. + * @return Glob expression associated with the mimetype. Empty string + * if no glob expression can be found. + */ + string get_glob(const string &mimetype) const; + + /** + * Get the mimetype of a file. + * @param filename [in] Name of the file. + * @return The mimetype or empty string if no mimetype can be determined. + */ + string get_mimetype(const string &filename) const; +}; + +}; // namespace + +extern utils::t_mime_database *mime_database; + +#endif -- cgit v1.2.3