1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
/*
* Diary
* Copyright (C) Philip Withnall 2008 <philip@tecnocode.co.uk>
*
* Diary is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Diary is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Diary. If not, see <http://www.gnu.org/licenses/>.
*/
#include <gtk/gtk.h>
#include <glib/gi18n.h>
#include "config.h"
#include "main.h"
#include "main-window.h"
#include "add-link-dialog.h"
#include "interface.h"
GtkWidget *
diary_create_interface (void)
{
GError *error = NULL;
GtkBuilder *builder;
builder = gtk_builder_new ();
if (gtk_builder_add_from_file (builder, PACKAGE_DATA_DIR"/diary/diary.ui", &error) == FALSE &&
gtk_builder_add_from_file (builder, "./data/diary.ui", NULL) == FALSE) {
/* Show an error */
GtkWidget *dialog = gtk_message_dialog_new (NULL,
GTK_DIALOG_MODAL,
GTK_MESSAGE_ERROR,
GTK_BUTTONS_OK,
_("UI file \"%s/diary/diary.ui\" could not be loaded. Error: %s"), PACKAGE_DATA_DIR, error->message);
gtk_dialog_run (GTK_DIALOG (dialog));
gtk_widget_destroy (dialog);
g_error_free (error);
g_object_unref (builder);
diary_quit ();
return NULL;
}
gtk_builder_set_translation_domain (builder, GETTEXT_PACKAGE);
gtk_builder_connect_signals (builder, NULL);
/* Set up the main window */
/* TODO: This is horrible */
diary->main_window = GTK_WIDGET (gtk_builder_get_object (builder, "dry_main_window"));
diary->entry_view = GTK_TEXT_VIEW (gtk_builder_get_object (builder, "dry_mw_entry_view"));
diary->entry_buffer = gtk_text_view_get_buffer (diary->entry_view);
diary->calendar = GTK_CALENDAR (gtk_builder_get_object (builder, "dry_mw_calendar"));
diary->date_label = GTK_LABEL (gtk_builder_get_object (builder, "dry_mw_date_label"));
diary->add_button = GTK_BUTTON (gtk_builder_get_object (builder, "dry_mw_add_button"));
diary->remove_button = GTK_BUTTON (gtk_builder_get_object (builder, "dry_mw_remove_button"));
diary->view_button = GTK_BUTTON (gtk_builder_get_object (builder, "dry_mw_view_button"));
diary->add_action = GTK_ACTION (gtk_builder_get_object (builder, "dry_ui_add_link"));
diary->remove_action = GTK_ACTION (gtk_builder_get_object (builder, "dry_ui_remove_link"));
diary->links_store = GTK_LIST_STORE (gtk_builder_get_object (builder, "dry_mw_links_store"));
diary->links_selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (gtk_builder_get_object (builder, "dry_mw_links_tree_view")));
diary->link_value_column = GTK_TREE_VIEW_COLUMN (gtk_builder_get_object (builder, "dry_mw_link_value_column"));
diary->link_value_renderer = GTK_CELL_RENDERER_TEXT (gtk_builder_get_object (builder, "dry_mw_link_value_renderer"));
diary_main_window_setup (builder);
/* Set up the add link dialogue */
diary->add_link_dialog = GTK_WIDGET (gtk_builder_get_object (builder, "dry_add_link_dialog"));
diary->ald_type_combo_box = GTK_COMBO_BOX (gtk_builder_get_object (builder, "dry_ald_type_combo_box"));
diary->ald_table = GTK_TABLE (gtk_builder_get_object (builder, "dry_ald_table"));
diary->ald_type_store = GTK_LIST_STORE (gtk_builder_get_object (builder, "dry_ald_type_store"));
diary_add_link_dialog_setup (builder);
g_object_unref (builder);
return diary->main_window;
}
/**
* diary_interface_error:
* @message: Error message
* @parent_window: The error dialog's parent window
*
* Display an error message and print the message to
* the console.
**/
void
diary_interface_error (const gchar *message, GtkWidget *parent_window)
{
GtkWidget *dialog;
g_warning (message);
dialog = gtk_message_dialog_new (GTK_WINDOW (parent_window),
GTK_DIALOG_MODAL,
GTK_MESSAGE_ERROR,
GTK_BUTTONS_OK,
message);
gtk_dialog_run (GTK_DIALOG (dialog));
gtk_widget_destroy (dialog);
}
|