1
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
4
* Copyright (C) Philip Withnall 2008 <philip@tecnocode.co.uk>
6
* Almanah is free software: you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation, either version 3 of the License, or
9
* (at your option) any later version.
11
* Almanah is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with Almanah. If not, see <http://www.gnu.org/licenses/>.
21
#include <glib/gi18n.h>
24
#include "../definition.h"
27
static void almanah_file_definition_init (AlmanahFileDefinition *self);
28
static gboolean file_view (AlmanahDefinition *definition);
29
static void file_build_dialog (AlmanahDefinition *definition, GtkVBox *parent_vbox);
30
static void file_close_dialog (AlmanahDefinition *definition, GtkVBox *parent_vbox);
31
static void file_parse_text (AlmanahDefinition *definition, const gchar *text);
32
static gchar *file_get_blurb (AlmanahDefinition *definition);
34
struct _AlmanahFileDefinitionPrivate {
38
G_DEFINE_TYPE (AlmanahFileDefinition, almanah_file_definition, ALMANAH_TYPE_DEFINITION)
39
#define ALMANAH_FILE_DEFINITION_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), ALMANAH_TYPE_FILE_DEFINITION, AlmanahFileDefinitionPrivate))
42
almanah_file_definition_class_init (AlmanahFileDefinitionClass *klass)
44
AlmanahDefinitionClass *definition_class = ALMANAH_DEFINITION_CLASS (klass);
46
g_type_class_add_private (klass, sizeof (AlmanahFileDefinitionPrivate));
48
definition_class->type_id = ALMANAH_DEFINITION_FILE;
49
definition_class->name = _("File");
50
definition_class->description = _("An attached file.");
51
definition_class->icon_name = "system-file-manager";
53
definition_class->view = file_view;
54
definition_class->build_dialog = file_build_dialog;
55
definition_class->close_dialog = file_close_dialog;
56
definition_class->parse_text = file_parse_text;
57
definition_class->get_blurb = file_get_blurb;
61
almanah_file_definition_init (AlmanahFileDefinition *self)
63
self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, ALMANAH_TYPE_FILE_DEFINITION, AlmanahFileDefinitionPrivate);
67
file_view (AlmanahDefinition *definition)
70
const gchar *value = almanah_definition_get_value (definition);
72
if (gtk_show_uri (gtk_widget_get_screen (almanah->main_window), value, GDK_CURRENT_TIME, &error) == FALSE) {
73
GtkWidget *dialog = gtk_message_dialog_new (GTK_WINDOW (almanah->main_window),
74
GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK,
75
_("Error opening file"));
76
gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), "%s", error->message);
77
gtk_dialog_run (GTK_DIALOG (dialog));
78
gtk_widget_destroy (dialog);
89
file_build_dialog (AlmanahDefinition *definition, GtkVBox *parent_vbox)
91
AlmanahFileDefinitionPrivate *priv = ALMANAH_FILE_DEFINITION (definition)->priv;
92
const gchar *value = almanah_definition_get_value (definition);
94
priv->chooser = gtk_file_chooser_button_new (_("Select File"), GTK_FILE_CHOOSER_ACTION_OPEN);
96
/* Initialise the dialogue with the definition's current values */
98
gtk_file_chooser_set_uri (GTK_FILE_CHOOSER (priv->chooser), value);
100
gtk_box_pack_start (GTK_BOX (parent_vbox), priv->chooser, TRUE, TRUE, 0);
101
gtk_widget_show_all (GTK_WIDGET (parent_vbox));
105
file_close_dialog (AlmanahDefinition *definition, GtkVBox *parent_vbox)
107
AlmanahFileDefinitionPrivate *priv = ALMANAH_FILE_DEFINITION (definition)->priv;
108
gchar *value = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (priv->chooser));
110
almanah_definition_set_value (definition, value);
113
almanah_definition_set_value2 (definition, NULL);
117
file_parse_text (AlmanahDefinition *definition, const gchar *text)
123
file_get_blurb (AlmanahDefinition *definition)
125
return g_strdup (almanah_definition_get_value (definition));