evolution-3.6.4/calendar/gui/dialogs/memo-editor.c

No issues found

  1 /*
  2  * This program is free software; you can redistribute it and/or
  3  * modify it under the terms of the GNU Lesser General Public
  4  * License as published by the Free Software Foundation; either
  5  * version 2 of the License, or (at your option) version 3.
  6  *
  7  * This program is distributed in the hope that it will be useful,
  8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 10  * Lesser General Public License for more details.
 11  *
 12  * You should have received a copy of the GNU Lesser General Public
 13  * License along with the program; if not, see <http://www.gnu.org/licenses/>
 14  *
 15  *
 16  * Authors:
 17  *		Miguel de Icaza <miguel@ximian.com>
 18  *      Federico Mena-Quintero <federico@ximian.com>
 19  *      Seth Alves <alves@hungry.com>
 20  *      JP Rosevear <jpr@ximian.com>
 21  *      Nathan Owens <pianocomp81@yahoo.com>
 22  *
 23  * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
 24  *
 25  */
 26 
 27 #ifdef HAVE_CONFIG_H
 28 #include <config.h>
 29 #endif
 30 
 31 #include <string.h>
 32 #include <glib/gi18n.h>
 33 
 34 #include <e-util/e-plugin-ui.h>
 35 #include <e-util/e-util-private.h>
 36 
 37 #include "memo-page.h"
 38 #include "cancel-comp.h"
 39 #include "memo-editor.h"
 40 
 41 #define MEMO_EDITOR_GET_PRIVATE(obj) \
 42 	(G_TYPE_INSTANCE_GET_PRIVATE \
 43 	((obj), TYPE_MEMO_EDITOR, MemoEditorPrivate))
 44 
 45 struct _MemoEditorPrivate {
 46 	MemoPage *memo_page;
 47 
 48 	gboolean updating;
 49 };
 50 
 51 /* Extends the UI definition in CompEditor */
 52 static const gchar *ui =
 53 "<ui>"
 54 "  <menubar action='main-menu'>"
 55 "    <menu action='view-menu'>"
 56 "      <menuitem action='view-categories'/>"
 57 "    </menu>"
 58 "    <menu action='options-menu'>"
 59 "      <menu action='classification-menu'>"
 60 "        <menuitem action='classify-public'/>"
 61 "        <menuitem action='classify-private'/>"
 62 "        <menuitem action='classify-confidential'/>"
 63 "      </menu>"
 64 "    </menu>"
 65 "  </menubar>"
 66 "</ui>";
 67 
 68 G_DEFINE_TYPE (MemoEditor, memo_editor, TYPE_COMP_EDITOR)
 69 
 70 static void
 71 memo_editor_show_categories (CompEditor *editor,
 72                              gboolean visible)
 73 {
 74 	MemoEditorPrivate *priv;
 75 
 76 	priv = MEMO_EDITOR_GET_PRIVATE (editor);
 77 
 78 	memo_page_set_show_categories (priv->memo_page, visible);
 79 }
 80 
 81 static void
 82 memo_editor_dispose (GObject *object)
 83 {
 84 	MemoEditorPrivate *priv;
 85 
 86 	priv = MEMO_EDITOR_GET_PRIVATE (object);
 87 
 88 	if (priv->memo_page) {
 89 		g_object_unref (priv->memo_page);
 90 		priv->memo_page = NULL;
 91 	}
 92 
 93 	/* Chain up to parent's dispose() method. */
 94 	G_OBJECT_CLASS (memo_editor_parent_class)->dispose (object);
 95 }
 96 
 97 static void
 98 memo_editor_constructed (GObject *object)
 99 {
100 	MemoEditorPrivate *priv;
101 	CompEditor *editor;
102 
103 	priv = MEMO_EDITOR_GET_PRIVATE (object);
104 	editor = COMP_EDITOR (object);
105 
106 	priv->memo_page = memo_page_new (editor);
107 	comp_editor_append_page (
108 		editor, COMP_EDITOR_PAGE (priv->memo_page),
109 		_("Memo"), TRUE);
110 
111 	/* Chain up to parent's constructed() method. */
112 	G_OBJECT_CLASS (memo_editor_parent_class)->constructed (object);
113 }
114 
115 static void
116 memo_editor_class_init (MemoEditorClass *class)
117 {
118 	GObjectClass *object_class;
119 	CompEditorClass *editor_class;
120 
121 	g_type_class_add_private (class, sizeof (MemoEditorPrivate));
122 
123 	object_class = G_OBJECT_CLASS (class);
124 	object_class->dispose = memo_editor_dispose;
125 	object_class->constructed = memo_editor_constructed;
126 
127 	/* TODO Add a help section for memos. */
128 	editor_class = COMP_EDITOR_CLASS (class);
129 	/*editor_class->help_section = "usage-calendar-memo";*/
130 	editor_class->show_categories = memo_editor_show_categories;
131 }
132 
133 /* Object initialization function for the memo editor */
134 static void
135 memo_editor_init (MemoEditor *me)
136 {
137 	CompEditor *editor = COMP_EDITOR (me);
138 	GtkUIManager *ui_manager;
139 	GtkAction *action;
140 	const gchar *id;
141 	GError *error = NULL;
142 
143 	me->priv = MEMO_EDITOR_GET_PRIVATE (me);
144 	me->priv->updating = FALSE;
145 
146 	ui_manager = comp_editor_get_ui_manager (editor);
147 	gtk_ui_manager_add_ui_from_string (ui_manager, ui, -1, &error);
148 
149 	id = "org.gnome.evolution.memo-editor";
150 	e_plugin_ui_register_manager (ui_manager, id, me);
151 	e_plugin_ui_enable_manager (ui_manager, id);
152 
153 	if (error != NULL) {
154 		g_critical ("%s: %s", G_STRFUNC, error->message);
155 		g_error_free (error);
156 	}
157 
158 	action = comp_editor_get_action (editor, "print");
159 	gtk_action_set_tooltip (action, _("Print this memo"));
160 }
161 
162 /**
163  * memo_editor_new:
164  * @client: an #ECalClient
165  *
166  * Creates a new event editor dialog.
167  *
168  * Return value: A newly-created event editor dialog, or NULL if the event
169  * editor could not be created.
170  **/
171 CompEditor *
172 memo_editor_new (ECalClient *client,
173                  EShell *shell,
174                  CompEditorFlags flags)
175 {
176 	g_return_val_if_fail (E_IS_CAL_CLIENT (client), NULL);
177 	g_return_val_if_fail (E_IS_SHELL (shell), NULL);
178 
179 	return g_object_new (
180 		TYPE_MEMO_EDITOR,
181 		"client", client, "flags", flags, "shell", shell, NULL);
182 }