~ubuntu-branches/ubuntu/maverick/almanah/maverick

« back to all changes in this revision

Viewing changes to src/definitions/file.c

  • Committer: Bazaar Package Importer
  • Author(s): Stefan Ebner
  • Date: 2009-05-16 15:49:21 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20090516154921-2uhvlj8btb4qygmd
Tags: 0.6.1-0ubuntu1
* New upstream release (LP: #368078)
* debian/control:
  - Bump Standards-Version to 3.8.1
  - Add intltool, libedataserver1.2-dev, libedataserverui1.2-dev, 
    libecal1.2-dev, libcryptui-dev as build dependency
  - Remove build dependency on autotools-dev and chrpath
* debian/{control/compat/rules}: Move to mimalistic dh7 style
* Update debian/watch
* Update copyright information

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
 
2
/*
 
3
 * Almanah
 
4
 * Copyright (C) Philip Withnall 2008 <philip@tecnocode.co.uk>
 
5
 * 
 
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.
 
10
 *
 
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.
 
15
 *
 
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/>.
 
18
 */
 
19
 
 
20
#include <glib.h>
 
21
#include <glib/gi18n.h>
 
22
 
 
23
#include "file.h"
 
24
#include "../definition.h"
 
25
#include "../main.h"
 
26
 
 
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);
 
33
 
 
34
struct _AlmanahFileDefinitionPrivate {
 
35
        GtkWidget *chooser;
 
36
};
 
37
 
 
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))
 
40
 
 
41
static void
 
42
almanah_file_definition_class_init (AlmanahFileDefinitionClass *klass)
 
43
{
 
44
        AlmanahDefinitionClass *definition_class = ALMANAH_DEFINITION_CLASS (klass);
 
45
 
 
46
        g_type_class_add_private (klass, sizeof (AlmanahFileDefinitionPrivate));
 
47
 
 
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";
 
52
 
 
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;
 
58
}
 
59
 
 
60
static void
 
61
almanah_file_definition_init (AlmanahFileDefinition *self)
 
62
{
 
63
        self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, ALMANAH_TYPE_FILE_DEFINITION, AlmanahFileDefinitionPrivate);
 
64
}
 
65
 
 
66
static gboolean
 
67
file_view (AlmanahDefinition *definition)
 
68
{
 
69
        GError *error = NULL;
 
70
        const gchar *value = almanah_definition_get_value (definition);
 
71
 
 
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);
 
79
 
 
80
                g_error_free (error);
 
81
 
 
82
                return FALSE;
 
83
        }
 
84
 
 
85
        return TRUE;
 
86
}
 
87
 
 
88
static void
 
89
file_build_dialog (AlmanahDefinition *definition, GtkVBox *parent_vbox)
 
90
{
 
91
        AlmanahFileDefinitionPrivate *priv = ALMANAH_FILE_DEFINITION (definition)->priv;
 
92
        const gchar *value = almanah_definition_get_value (definition);
 
93
 
 
94
        priv->chooser = gtk_file_chooser_button_new (_("Select File"), GTK_FILE_CHOOSER_ACTION_OPEN);
 
95
 
 
96
        /* Initialise the dialogue with the definition's current values */
 
97
        if (value != NULL)
 
98
                gtk_file_chooser_set_uri (GTK_FILE_CHOOSER (priv->chooser), value);
 
99
 
 
100
        gtk_box_pack_start (GTK_BOX (parent_vbox), priv->chooser, TRUE, TRUE, 0);
 
101
        gtk_widget_show_all (GTK_WIDGET (parent_vbox));
 
102
}
 
103
 
 
104
static void
 
105
file_close_dialog (AlmanahDefinition *definition, GtkVBox *parent_vbox)
 
106
{
 
107
        AlmanahFileDefinitionPrivate *priv = ALMANAH_FILE_DEFINITION (definition)->priv;
 
108
        gchar *value = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (priv->chooser));
 
109
 
 
110
        almanah_definition_set_value (definition, value);
 
111
        g_free (value);
 
112
 
 
113
        almanah_definition_set_value2 (definition, NULL);
 
114
}
 
115
 
 
116
static void
 
117
file_parse_text (AlmanahDefinition *definition, const gchar *text)
 
118
{
 
119
        /* TODO */
 
120
}
 
121
 
 
122
static gchar *
 
123
file_get_blurb (AlmanahDefinition *definition)
 
124
{
 
125
        return g_strdup (almanah_definition_get_value (definition));
 
126
}