summaryrefslogtreecommitdiff
path: root/lib/ephy-file-dialog-utils.c
blob: 96b64a59416f36026280c9739b904baf1f813b34 (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
/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
 *  Copyright © 2003 Marco Pesenti Gritti
 *  Copyright © 2003, 2004 Christian Persch
 *  Copyright © 2017 Igalia S.L.
 *
 *  This file is part of Epiphany.
 *
 *  Epiphany 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 3 of the License, or
 *  (at your option) any later version.
 *
 *  Epiphany 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 Epiphany.  If not, see <http://www.gnu.org/licenses/>.
 */

#include "config.h"

#include "ephy-file-dialog-utils.h"
#include "ephy-file-helpers.h"
#include "ephy-gui.h"
#include "ephy-debug.h"

#include <gtk/gtk.h>
#include <glib/gi18n.h>

static const char *webpage_types[] = {
  "text/html",
  "application/xhtml+xml",
  "text/xml",
  "message/rfc822",                                     /* MHTML */
  "multipart/related",                                  /* MHTML */
  "application/x-mimearchive",                          /* MHTML */
  NULL
};

static const char *image_types[] = {
  "image/png",
  "image/jpeg",
  "image/gif",
  "image/webp",
  NULL
};

void
ephy_file_dialog_add_shortcuts (GtkFileDialog *dialog)
{
  g_autofree char *downloads_dir_path = NULL;
  g_autoptr (GFile) downloads_dir = NULL;
  g_autoptr (GListStore) shortcuts = NULL;

  g_assert (GTK_IS_FILE_DIALOG (dialog));

  downloads_dir_path = ephy_file_get_downloads_dir ();
  downloads_dir = g_file_new_for_path (downloads_dir_path);

  shortcuts = g_list_store_new (G_TYPE_FILE);
  g_list_store_append (shortcuts, downloads_dir);

  gtk_file_dialog_set_shortcut_folders (dialog, G_LIST_MODEL (shortcuts));
}

void
ephy_file_dialog_add_filters (GtkFileDialog *dialog)
{
  g_autoptr (GListStore) filters = NULL;
  g_autoptr (GtkFileFilter) supported_filter = NULL;
  g_autoptr (GtkFileFilter) webpages_filter = NULL;
  g_autoptr (GtkFileFilter) images_filter = NULL;
  g_autoptr (GtkFileFilter) all_filter = NULL;
  int i;

  g_assert (GTK_IS_FILE_DIALOG (dialog));

  filters = g_list_store_new (GTK_TYPE_FILE_FILTER);

  supported_filter = gtk_file_filter_new ();
  gtk_file_filter_set_name (supported_filter, _("All supported types"));
  g_list_store_append (filters, supported_filter);

  webpages_filter = gtk_file_filter_new ();
  gtk_file_filter_set_name (webpages_filter, _("Web pages"));
  g_list_store_append (filters, webpages_filter);

  images_filter = gtk_file_filter_new ();
  gtk_file_filter_set_name (images_filter, _("Images"));
  g_list_store_append (filters, images_filter);

  all_filter = gtk_file_filter_new ();
  gtk_file_filter_set_name (all_filter, _("All files"));
  gtk_file_filter_add_pattern (all_filter, "*");
  g_list_store_append (filters, all_filter);

  for (i = 0; webpage_types[i]; i++) {
    gtk_file_filter_add_mime_type (supported_filter, webpage_types[i]);
    gtk_file_filter_add_mime_type (webpages_filter, webpage_types[i]);
  }

  for (i = 0; image_types[i]; i++) {
    gtk_file_filter_add_mime_type (supported_filter, image_types[i]);
    gtk_file_filter_add_mime_type (images_filter, image_types[i]);
  }

  gtk_file_dialog_set_filters (dialog, G_LIST_MODEL (filters));
  gtk_file_dialog_set_current_filter (dialog, supported_filter);
}