1 /*
2  * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
3  * Copyright (C) 2014 Red Hat, Inc. (www.redhat.com)
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU Lesser General Public License as published by
7  * the Free Software Foundation.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
12  * for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public License
15  * along with this program; if not, see <http://www.gnu.org/licenses/>.
16  *
17  * Authors: Milan Crha <mcrha@redhat.com>
18  */
19 
20 #include "evolution-config.h"
21 
22 #include <string.h>
23 #include <glib/gi18n.h>
24 
25 #include <calendar/gui/e-cal-ops.h>
26 
27 #include "e-cal-base-shell-backend.h"
28 #include "e-cal-base-shell-sidebar.h"
29 #include "e-memo-shell-view.h"
30 #include "e-memo-shell-backend.h"
31 
32 #define E_MEMO_SHELL_BACKEND_GET_PRIVATE(obj) \
33 	(G_TYPE_INSTANCE_GET_PRIVATE \
34 	((obj), E_TYPE_MEMO_SHELL_BACKEND, EMemoShellBackendPrivate))
35 
36 struct _EMemoShellBackendPrivate {
37 	gint placeholder;
38 };
39 
G_DEFINE_DYNAMIC_TYPE(EMemoShellBackend,e_memo_shell_backend,E_TYPE_CAL_BASE_SHELL_BACKEND)40 G_DEFINE_DYNAMIC_TYPE (EMemoShellBackend, e_memo_shell_backend, E_TYPE_CAL_BASE_SHELL_BACKEND)
41 
42 static void
43 action_memo_new_cb (GtkAction *action,
44                     EShellWindow *shell_window)
45 {
46 	EShellView *shell_view;
47 	ESource *selected_source = NULL;
48 
49 	shell_view = e_shell_window_peek_shell_view (shell_window, "memos");
50 	if (shell_view != NULL) {
51 		EShellSidebar *shell_sidebar;
52 		ESourceSelector *selector;
53 
54 		shell_sidebar = e_shell_view_get_shell_sidebar (shell_view);
55 		selector = e_cal_base_shell_sidebar_get_selector (E_CAL_BASE_SHELL_SIDEBAR (shell_sidebar));
56 		selected_source = e_source_selector_ref_primary_selection (selector);
57 	}
58 
59 	e_cal_ops_new_component_editor (shell_window,
60 		E_CAL_CLIENT_SOURCE_TYPE_MEMOS, selected_source ? e_source_get_uid (selected_source) : NULL,
61 		g_strcmp0 (gtk_action_get_name (action), "memo-shared-new") == 0);
62 
63 	g_clear_object (&selected_source);
64 }
65 
66 static void
action_memo_list_new_cb(GtkAction * action,EShellWindow * shell_window)67 action_memo_list_new_cb (GtkAction *action,
68                          EShellWindow *shell_window)
69 {
70 	e_cal_base_shell_backend_util_new_source (shell_window, E_CAL_CLIENT_SOURCE_TYPE_MEMOS);
71 }
72 
73 static GtkActionEntry item_entries[] = {
74 
75 	{ "memo-new",
76 	  "stock_insert-note",
77 	  NC_("New", "Mem_o"),
78 	  "<Shift><Control>o",
79 	  N_("Create a new memo"),
80 	  G_CALLBACK (action_memo_new_cb) },
81 
82 	{ "memo-shared-new",
83 	  "stock_insert-note",
84 	  NC_("New", "_Shared Memo"),
85 	  "<Shift><Control>u",
86 	  N_("Create a new shared memo"),
87 	  G_CALLBACK (action_memo_new_cb) }
88 };
89 
90 static GtkActionEntry source_entries[] = {
91 
92 	{ "memo-list-new",
93 	  "stock_notes",
94 	  NC_("New", "Memo Li_st"),
95 	  NULL,
96 	  N_("Create a new memo list"),
97 	  G_CALLBACK (action_memo_list_new_cb) }
98 };
99 
100 static gboolean
e_memo_shell_backend_handle_uri(EShellBackend * shell_backend,const gchar * uri)101 e_memo_shell_backend_handle_uri (EShellBackend *shell_backend,
102 				 const gchar *uri)
103 {
104 	if (strncmp (uri, "memo:", 5) != 0)
105 		return FALSE;
106 
107 	return e_cal_base_shell_backend_util_handle_uri (shell_backend,
108 		E_CAL_CLIENT_SOURCE_TYPE_MEMOS, uri, NULL);
109 }
110 
111 static void
e_memo_shell_backend_class_init(EMemoShellBackendClass * class)112 e_memo_shell_backend_class_init (EMemoShellBackendClass *class)
113 {
114 	EShellBackendClass *shell_backend_class;
115 	ECalBaseShellBackendClass *cal_base_shell_backend_class;
116 
117 	g_type_class_add_private (class, sizeof (EMemoShellBackendPrivate));
118 
119 	shell_backend_class = E_SHELL_BACKEND_CLASS (class);
120 	shell_backend_class->shell_view_type = E_TYPE_MEMO_SHELL_VIEW;
121 	shell_backend_class->name = "memos";
122 	shell_backend_class->aliases = "";
123 	shell_backend_class->schemes = "memo";
124 	shell_backend_class->sort_order = 600;
125 	shell_backend_class->preferences_page = "calendar-and-tasks";
126 	shell_backend_class->start = NULL;
127 
128 	cal_base_shell_backend_class = E_CAL_BASE_SHELL_BACKEND_CLASS (class);
129 	cal_base_shell_backend_class->new_item_entries = item_entries;
130 	cal_base_shell_backend_class->new_item_n_entries = G_N_ELEMENTS (item_entries);
131 	cal_base_shell_backend_class->source_entries = source_entries;
132 	cal_base_shell_backend_class->source_n_entries = G_N_ELEMENTS (source_entries);
133 	cal_base_shell_backend_class->handle_uri = e_memo_shell_backend_handle_uri;
134 }
135 
136 static void
e_memo_shell_backend_init(EMemoShellBackend * memo_shell_backend)137 e_memo_shell_backend_init (EMemoShellBackend *memo_shell_backend)
138 {
139 	memo_shell_backend->priv = E_MEMO_SHELL_BACKEND_GET_PRIVATE (memo_shell_backend);
140 }
141 
142 static void
e_memo_shell_backend_class_finalize(EMemoShellBackendClass * class)143 e_memo_shell_backend_class_finalize (EMemoShellBackendClass *class)
144 {
145 }
146 
147 void
e_memo_shell_backend_type_register(GTypeModule * type_module)148 e_memo_shell_backend_type_register (GTypeModule *type_module)
149 {
150 	/* XXX G_DEFINE_DYNAMIC_TYPE declares a static type registration
151 	 *     function, so we have to wrap it with a public function in
152 	 *     order to register types from a separate compilation unit. */
153 	e_memo_shell_backend_register_type (type_module);
154 }
155