~ubuntu-branches/ubuntu/utopic/almanah/utopic

« back to all changes in this revision

Viewing changes to src/definitions/note.c

  • Committer: Package Import Robot
  • Author(s): Angel Abad
  • Date: 2012-10-29 10:14:18 UTC
  • mfrom: (1.4.1) (10.1.7 sid)
  • Revision ID: package-import@ubuntu.com-20121029101418-k2c27xb0aku22zeg
Tags: 0.10.0-1~exp1
* Imported Upstream version 0.10.0
* debian/control:
  - Bump evolution Build-Depends ( >=3.6.0)
  - debian/control: Depends on evolution-common (>= 3.6.0)
* Bump Standards-Version to 3.9.4 (no changes)

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-2009 <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 "note.h"
24
 
#include "../definition.h"
25
 
#include "../interface.h"
26
 
#include "../main.h"
27
 
 
28
 
static gboolean note_view (AlmanahDefinition *definition);
29
 
static void note_build_dialog (AlmanahDefinition *definition, GtkVBox *parent_vbox);
30
 
static void note_close_dialog (AlmanahDefinition *definition, GtkVBox *parent_vbox);
31
 
static void note_parse_text (AlmanahDefinition *definition, const gchar *text);
32
 
static gchar *note_get_blurb (AlmanahDefinition *definition);
33
 
 
34
 
struct _AlmanahNoteDefinitionPrivate {
35
 
        GtkWidget *text_view;
36
 
};
37
 
 
38
 
G_DEFINE_TYPE (AlmanahNoteDefinition, almanah_note_definition, ALMANAH_TYPE_DEFINITION)
39
 
#define ALMANAH_NOTE_DEFINITION_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), ALMANAH_TYPE_NOTE_DEFINITION, AlmanahNoteDefinitionPrivate))
40
 
 
41
 
static void
42
 
almanah_note_definition_class_init (AlmanahNoteDefinitionClass *klass)
43
 
{
44
 
        AlmanahDefinitionClass *definition_class = ALMANAH_DEFINITION_CLASS (klass);
45
 
 
46
 
        g_type_class_add_private (klass, sizeof (AlmanahNoteDefinitionPrivate));
47
 
 
48
 
        definition_class->type_id = ALMANAH_DEFINITION_NOTE;
49
 
        definition_class->name = _("Note");
50
 
        definition_class->description = _("A note about an important event.");
51
 
        definition_class->icon_name = "emblem-important";
52
 
 
53
 
        definition_class->view = note_view;
54
 
        definition_class->build_dialog = note_build_dialog;
55
 
        definition_class->close_dialog = note_close_dialog;
56
 
        definition_class->parse_text = note_parse_text;
57
 
        definition_class->get_blurb = note_get_blurb;
58
 
}
59
 
 
60
 
static void
61
 
almanah_note_definition_init (AlmanahNoteDefinition *self)
62
 
{
63
 
        self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, ALMANAH_TYPE_NOTE_DEFINITION, AlmanahNoteDefinitionPrivate);
64
 
}
65
 
 
66
 
static gboolean
67
 
note_view (AlmanahDefinition *definition)
68
 
{
69
 
        const gchar *value = almanah_definition_get_value (definition);
70
 
 
71
 
        GtkWidget *dialog = gtk_message_dialog_new (NULL,
72
 
                                GTK_DIALOG_DESTROY_WITH_PARENT,
73
 
                                GTK_MESSAGE_INFO,
74
 
                                GTK_BUTTONS_CLOSE,
75
 
                                "%s", value);
76
 
        gtk_dialog_run (GTK_DIALOG (dialog));
77
 
        gtk_widget_destroy (dialog);
78
 
 
79
 
        return TRUE;
80
 
}
81
 
 
82
 
static void
83
 
note_build_dialog (AlmanahDefinition *definition, GtkVBox *parent_vbox)
84
 
{
85
 
        GtkWidget *scrolled_window;
86
 
        AlmanahNoteDefinitionPrivate *priv = ALMANAH_NOTE_DEFINITION (definition)->priv;
87
 
        const gchar *value = almanah_definition_get_value (definition);
88
 
 
89
 
        scrolled_window = gtk_scrolled_window_new (NULL, NULL);
90
 
        gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
91
 
                                        GTK_POLICY_AUTOMATIC,
92
 
                                        GTK_POLICY_AUTOMATIC);
93
 
        gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled_window),
94
 
                                             GTK_SHADOW_IN);
95
 
        priv->text_view = gtk_text_view_new ();
96
 
        gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (priv->text_view), GTK_WRAP_WORD_CHAR);
97
 
        gtk_widget_set_size_request (priv->text_view, 300, 300);
98
 
        gtk_container_add (GTK_CONTAINER (scrolled_window), priv->text_view);
99
 
 
100
 
        /* Initialise the dialogue with the definition's current values */
101
 
        if (value != NULL) {
102
 
                GtkTextBuffer *buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (priv->text_view));
103
 
                gtk_text_buffer_set_text (buffer, value, -1);
104
 
        }
105
 
 
106
 
        gtk_box_pack_start (GTK_BOX (parent_vbox), scrolled_window, TRUE, TRUE, 0);
107
 
        gtk_widget_show_all (GTK_WIDGET (parent_vbox));
108
 
}
109
 
 
110
 
static void
111
 
note_close_dialog (AlmanahDefinition *definition, GtkVBox *parent_vbox)
112
 
{
113
 
        AlmanahNoteDefinitionPrivate *priv = ALMANAH_NOTE_DEFINITION (definition)->priv;
114
 
        gchar *value;
115
 
        GtkTextBuffer *buffer;
116
 
        GtkTextIter start_iter, end_iter;
117
 
 
118
 
        buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (priv->text_view));
119
 
        gtk_text_buffer_get_bounds (buffer, &start_iter, &end_iter);
120
 
 
121
 
        value = gtk_text_buffer_get_text (buffer, &start_iter, &end_iter, FALSE);
122
 
        almanah_definition_set_value (definition, value);
123
 
        g_free (value);
124
 
 
125
 
        almanah_definition_set_value2 (definition, NULL);
126
 
}
127
 
 
128
 
static void
129
 
note_parse_text (AlmanahDefinition *definition, const gchar *text)
130
 
{
131
 
        /* TODO */
132
 
}
133
 
 
134
 
static gchar *
135
 
note_get_blurb (AlmanahDefinition *definition)
136
 
{
137
 
        return g_strdup (almanah_definition_get_value (definition));
138
 
}