blob: ffb1ccc8f8de7b08cdf80a66a9d6fdd315640008 [file] [log] [blame]
Stepan Salenikovichf2d76c52015-07-17 17:54:56 -04001/*
2 * Copyright (C) 2015 Savoir-faire Linux Inc.
3 * Author: Stepan Salenikovich <stepan.salenikovich@savoirfairelinux.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Additional permission under GNU GPL version 3 section 7:
20 *
21 * If you modify this program, or any covered work, by linking or
22 * combining it with the OpenSSL project's OpenSSL library (or a
23 * modified version of that library), containing parts covered by the
24 * terms of the OpenSSL or SSLeay licenses, Savoir-faire Linux Inc.
25 * grants you additional permission to convey the resulting work.
26 * Corresponding Source for a non-source form of such a combination
27 * shall include the source code for the parts of OpenSSL used as well
28 * as that of the covered work.
29 */
30
31#include "menus.h"
32
33#include <contactmethod.h>
Stepan Salenikovich0cf247d2015-07-24 17:36:32 -040034#include "../contactpopover.h"
Stepan Salenikovichf2d76c52015-07-17 17:54:56 -040035
36/**
37 * checks if the given contact method is already associated with a contact
38 */
39gboolean
40contact_method_has_contact(ContactMethod *cm)
41{
42 g_return_val_if_fail(cm, FALSE);
43
44 return cm->contact() != NULL;
45}
46
47static void
Stepan Salenikovich0cf247d2015-07-24 17:36:32 -040048choose_contact(GtkWidget *item, ContactMethod *contactmethod)
Stepan Salenikovichf2d76c52015-07-17 17:54:56 -040049{
50 // we get the parent widget which should be stored in the item object
Stepan Salenikovich0cf247d2015-07-24 17:36:32 -040051 auto parent = g_object_get_data(G_OBJECT(item), "parent-widget");
52 auto rect = g_object_get_data(G_OBJECT(item), "parent-rectangle");
53
54 auto popover = contact_popover_new(contactmethod, GTK_WIDGET(parent), (GdkRectangle *)rect);
55
56 gtk_widget_show(popover);
Stepan Salenikovichf2d76c52015-07-17 17:54:56 -040057}
58
59/**
Stepan Salenikovich0cf247d2015-07-24 17:36:32 -040060 * creates a menu item allowing the adition of a contact method to a contact
Stepan Salenikovichf2d76c52015-07-17 17:54:56 -040061 */
Stepan Salenikovich0cf247d2015-07-24 17:36:32 -040062GtkWidget * menu_item_add_to_contact(ContactMethod *cm, GtkWidget *parent, const GdkRectangle *rect)
Stepan Salenikovichf2d76c52015-07-17 17:54:56 -040063{
64 g_return_val_if_fail(cm, NULL);
65
Stepan Salenikovich0cf247d2015-07-24 17:36:32 -040066 auto add_to = gtk_menu_item_new_with_mnemonic("_Add to contact");
Stepan Salenikovichf2d76c52015-07-17 17:54:56 -040067
68 /* save the parent widget in the item object, so we can retrieve
69 * it in the callback */
Stepan Salenikovich0cf247d2015-07-24 17:36:32 -040070 g_object_set_data(G_OBJECT(add_to), "parent-widget", parent);
Stepan Salenikovichf2d76c52015-07-17 17:54:56 -040071
Stepan Salenikovich0cf247d2015-07-24 17:36:32 -040072 GdkRectangle *copy_rect = NULL;
73 if (rect) {
74 copy_rect = g_new0(GdkRectangle, 1);
75 memcpy(copy_rect, rect, sizeof(GdkRectangle));
76 }
77 g_object_set_data_full(G_OBJECT(add_to), "parent-rectangle", copy_rect, (GDestroyNotify)g_free);
78
79 g_signal_connect(add_to, "activate", G_CALLBACK(choose_contact), cm);
Stepan Salenikovichf2d76c52015-07-17 17:54:56 -040080
81 return add_to;
82}