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
* Diary 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
* Diary 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 Diary. If not, see <http://www.gnu.org/licenses/>.
22
#include <glib/gi18n.h>
28
#define LINK_TYPE(T) gchar *link_##T##_format_value (const DiaryLink *link); \
29
gboolean link_##T##_view (const DiaryLink *link); \
30
void link_##T##_build_dialog (const gchar *type, GtkTable *dialog_table); \
31
void link_##T##_get_values (DiaryLink *link);
40
* Make sure this list is kept in alphabetical order by type.
42
* To add a link type, add an entry here then add a file in src/links
43
* named after the link type, containing the format, view, dialogue-building
44
* and value-getting functions referenced in this table.
45
* Don't forget to add the function prototypes at the top of *this* file.
47
static const DiaryLinkType link_types[] = {
48
/* Type, Name, Description, Icon, Columns, Format function, View function, Dialogue build function, Get values function */
49
/*{ "email", N_("E-mail"), N_("An e-mail you sent or received."), "mail-read", 2, &link_email_format_value, &link_email_view, &link_email_build_dialog, &link_email_get_values },*/
51
/* Translators: These are the names and descriptions of the different link types. */
52
{ "file", N_("File"), N_("An attached file."), "system-file-manager", 1, &link_file_format_value, &link_file_view, &link_file_build_dialog, &link_file_get_values },
53
{ "note", N_("Note"), N_("A note about an important event."), "emblem-important", 1, &link_note_format_value, &link_note_view, &link_note_build_dialog, &link_note_get_values },
54
{ "uri", N_("URI"), N_("A URI of a file or web page."), "applications-internet", 1, &link_uri_format_value, &link_uri_view, &link_uri_build_dialog, &link_uri_get_values }
58
diary_populate_link_model (GtkListStore *list_store, guint type_column, guint name_column, guint icon_name_column)
63
for (i = 0; i < G_N_ELEMENTS (link_types); i++) {
64
gtk_list_store_append (list_store, &iter);
65
gtk_list_store_set (list_store, &iter,
66
type_column, link_types[i].type,
67
name_column, _(link_types[i].name),
68
icon_name_column, link_types[i].icon_name,
74
diary_validate_link_type (const gchar *type)
76
return (diary_link_get_type (type) == NULL) ? FALSE : TRUE;
80
diary_link_get_type (const gchar *type)
82
guint lower_limit, upper_limit, temp;
85
/* Do a binary search */
87
upper_limit = G_N_ELEMENTS (link_types) - 1;
89
/* TODO: perhaps use GQuarks to make things less heavy on the strcmps */
91
temp = ceil ((lower_limit + upper_limit) / 2);
92
comparison = strcmp (type, link_types[temp].type);
95
if (lower_limit == upper_limit && comparison != 0)
99
upper_limit = temp - 1; /* It's in the lower half */
100
else if (comparison > 0)
101
lower_limit = temp + 1; /* It's in the upper half */
103
return &(link_types[temp]); /* Match! */
110
diary_link_format_value (const DiaryLink *link)
112
const DiaryLinkType *link_type = diary_link_get_type (link->type);
113
g_assert (link_type != NULL);
114
return link_type->format_value_func (link);
118
diary_link_view (const DiaryLink *link)
120
const DiaryLinkType *link_type = diary_link_get_type (link->type);
121
g_assert (link_type != NULL);
124
g_debug ("Viewing %s link ('%s', '%s')", link->type, link->value, link->value2);
126
return link_type->view_func (link);
130
diary_link_build_dialog (const DiaryLinkType *link_type)
132
g_assert (link_type != NULL);
133
link_type->build_dialog_func (link_type->type, diary->ald_table);
137
diary_link_get_values (DiaryLink *link)
139
const DiaryLinkType *link_type = diary_link_get_type (link->type);
140
g_assert (link_type != NULL);
141
link_type->get_values_func (link);