1
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
4
* Copyright (C) Philip Withnall 2008-2009 <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"
25
#include "../interface.h"
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);
34
struct _AlmanahNoteDefinitionPrivate {
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))
42
almanah_note_definition_class_init (AlmanahNoteDefinitionClass *klass)
44
AlmanahDefinitionClass *definition_class = ALMANAH_DEFINITION_CLASS (klass);
46
g_type_class_add_private (klass, sizeof (AlmanahNoteDefinitionPrivate));
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";
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;
61
almanah_note_definition_init (AlmanahNoteDefinition *self)
63
self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, ALMANAH_TYPE_NOTE_DEFINITION, AlmanahNoteDefinitionPrivate);
67
note_view (AlmanahDefinition *definition)
69
const gchar *value = almanah_definition_get_value (definition);
71
GtkWidget *dialog = gtk_message_dialog_new (NULL,
72
GTK_DIALOG_DESTROY_WITH_PARENT,
76
gtk_dialog_run (GTK_DIALOG (dialog));
77
gtk_widget_destroy (dialog);
83
note_build_dialog (AlmanahDefinition *definition, GtkVBox *parent_vbox)
85
GtkWidget *scrolled_window;
86
AlmanahNoteDefinitionPrivate *priv = ALMANAH_NOTE_DEFINITION (definition)->priv;
87
const gchar *value = almanah_definition_get_value (definition);
89
scrolled_window = gtk_scrolled_window_new (NULL, NULL);
90
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
92
GTK_POLICY_AUTOMATIC);
93
gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled_window),
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);
100
/* Initialise the dialogue with the definition's current values */
102
GtkTextBuffer *buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (priv->text_view));
103
gtk_text_buffer_set_text (buffer, value, -1);
106
gtk_box_pack_start (GTK_BOX (parent_vbox), scrolled_window, TRUE, TRUE, 0);
107
gtk_widget_show_all (GTK_WIDGET (parent_vbox));
111
note_close_dialog (AlmanahDefinition *definition, GtkVBox *parent_vbox)
113
AlmanahNoteDefinitionPrivate *priv = ALMANAH_NOTE_DEFINITION (definition)->priv;
115
GtkTextBuffer *buffer;
116
GtkTextIter start_iter, end_iter;
118
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (priv->text_view));
119
gtk_text_buffer_get_bounds (buffer, &start_iter, &end_iter);
121
value = gtk_text_buffer_get_text (buffer, &start_iter, &end_iter, FALSE);
122
almanah_definition_set_value (definition, value);
125
almanah_definition_set_value2 (definition, NULL);
129
note_parse_text (AlmanahDefinition *definition, const gchar *text)
135
note_get_blurb (AlmanahDefinition *definition)
137
return g_strdup (almanah_definition_get_value (definition));