summaryrefslogtreecommitdiff
path: root/gio/giomm/contenttype.cc
blob: abe6733781f00ff18b61dc72d65e0b7acd6b88ed (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/* Copyright (C) 2008 The gtkmm Development Team
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
 */

#include <giomm/contenttype.h>
#include <glibmm/vectorutils.h>
#include <gio/gio.h>

namespace Gio
{

bool
content_type_equals(const Glib::ustring& type1, const Glib::ustring& type2)
{
  return g_content_type_equals(type1.c_str(), type2.c_str());
}

bool
content_type_is_a(const Glib::ustring& type, const Glib::ustring& supertype)
{
  return g_content_type_is_a(type.c_str(), supertype.c_str());
}

bool
content_type_is_unknown(const Glib::ustring& type)
{
  return g_content_type_is_unknown(type.c_str());
}

Glib::ustring
content_type_get_description(const Glib::ustring& type)
{
  return Glib::convert_return_gchar_ptr_to_ustring(g_content_type_get_description(type.c_str()));
}

Glib::ustring
content_type_get_mime_type(const Glib::ustring& type)
{
  return Glib::convert_return_gchar_ptr_to_ustring(g_content_type_get_mime_type(type.c_str()));
}

Glib::RefPtr<Gio::Icon>
content_type_get_icon(const Glib::ustring& type)
{
  auto retvalue = Glib::wrap(g_content_type_get_icon(type.c_str()));
  if (retvalue)
    retvalue->reference(); // The function does not do a ref for us.
  return retvalue;
}

#ifdef G_OS_UNIX
Glib::RefPtr<Gio::Icon>
content_type_get_symbolic_icon(const Glib::ustring& type)
{
  auto retvalue = Glib::wrap(g_content_type_get_symbolic_icon(type.c_str()));
  if (retvalue)
    retvalue->reference(); // The function does not do a ref for us.
  return retvalue;
}
#endif

bool
content_type_can_be_executable(const Glib::ustring& type)
{
  return g_content_type_can_be_executable(type.c_str());
}

Glib::ustring
content_type_from_mime_type(const Glib::ustring& mime_type)
{
  return Glib::convert_return_gchar_ptr_to_ustring(
    g_content_type_from_mime_type(mime_type.c_str()));
}

Glib::ustring
content_type_guess(
  const std::string& filename, const std::basic_string<guchar>& data, bool& result_uncertain)
{
  gboolean c_result_uncertain = FALSE;
  const gchar* c_filename = filename.empty() ? nullptr : filename.c_str();
  gchar* cresult = g_content_type_guess(c_filename, data.c_str(), data.size(), &c_result_uncertain);
  result_uncertain = c_result_uncertain;
  return Glib::convert_return_gchar_ptr_to_ustring(cresult);
}

Glib::ustring
content_type_guess(
  const std::string& filename, const guchar* data, gsize data_size, bool& result_uncertain)
{
  gboolean c_result_uncertain = FALSE;
  const gchar* c_filename = filename.empty() ? nullptr : filename.c_str();
  gchar* cresult = g_content_type_guess(c_filename, data, data_size, &c_result_uncertain);
  result_uncertain = c_result_uncertain;
  return Glib::convert_return_gchar_ptr_to_ustring(cresult);
}

Glib::ustring
content_type_guess(const std::string& filename, const std::string& data, bool& result_uncertain)
{
  gboolean c_result_uncertain = FALSE;
  const gchar* c_filename = filename.empty() ? nullptr : filename.c_str();
  gchar* cresult =
    g_content_type_guess(c_filename, (const guchar*)data.c_str(), data.size(), &c_result_uncertain);
  result_uncertain = c_result_uncertain;
  return Glib::convert_return_gchar_ptr_to_ustring(cresult);
}

std::vector<Glib::ustring>
content_type_guess_for_tree(const Glib::RefPtr<const File>& root)
{
  return Glib::ArrayHandler<Glib::ustring>::array_to_vector(
    g_content_type_guess_for_tree(const_cast<GFile*>(root->gobj())), Glib::OWNERSHIP_DEEP);
}

std::vector<Glib::ustring>
content_types_get_registered()
{
  return Glib::ListHandler<Glib::ustring>::list_to_vector(g_content_types_get_registered(), Glib::OWNERSHIP_DEEP);
}

} // namespace Gio