Stepan Salenikovich | f2d76c5 | 2015-07-17 17:54:56 -0400 | [diff] [blame] | 1 | /* |
| 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 Salenikovich | 0cf247d | 2015-07-24 17:36:32 -0400 | [diff] [blame] | 34 | #include "../contactpopover.h" |
Stepan Salenikovich | f2d76c5 | 2015-07-17 17:54:56 -0400 | [diff] [blame] | 35 | |
| 36 | /** |
| 37 | * checks if the given contact method is already associated with a contact |
| 38 | */ |
| 39 | gboolean |
| 40 | contact_method_has_contact(ContactMethod *cm) |
| 41 | { |
| 42 | g_return_val_if_fail(cm, FALSE); |
| 43 | |
| 44 | return cm->contact() != NULL; |
| 45 | } |
| 46 | |
| 47 | static void |
Stepan Salenikovich | 0cf247d | 2015-07-24 17:36:32 -0400 | [diff] [blame] | 48 | choose_contact(GtkWidget *item, ContactMethod *contactmethod) |
Stepan Salenikovich | f2d76c5 | 2015-07-17 17:54:56 -0400 | [diff] [blame] | 49 | { |
| 50 | // we get the parent widget which should be stored in the item object |
Stepan Salenikovich | 0cf247d | 2015-07-24 17:36:32 -0400 | [diff] [blame] | 51 | 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 Salenikovich | f2d76c5 | 2015-07-17 17:54:56 -0400 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | /** |
Stepan Salenikovich | 0cf247d | 2015-07-24 17:36:32 -0400 | [diff] [blame] | 60 | * creates a menu item allowing the adition of a contact method to a contact |
Stepan Salenikovich | f2d76c5 | 2015-07-17 17:54:56 -0400 | [diff] [blame] | 61 | */ |
Stepan Salenikovich | 0cf247d | 2015-07-24 17:36:32 -0400 | [diff] [blame] | 62 | GtkWidget * menu_item_add_to_contact(ContactMethod *cm, GtkWidget *parent, const GdkRectangle *rect) |
Stepan Salenikovich | f2d76c5 | 2015-07-17 17:54:56 -0400 | [diff] [blame] | 63 | { |
| 64 | g_return_val_if_fail(cm, NULL); |
| 65 | |
Stepan Salenikovich | 0cf247d | 2015-07-24 17:36:32 -0400 | [diff] [blame] | 66 | auto add_to = gtk_menu_item_new_with_mnemonic("_Add to contact"); |
Stepan Salenikovich | f2d76c5 | 2015-07-17 17:54:56 -0400 | [diff] [blame] | 67 | |
| 68 | /* save the parent widget in the item object, so we can retrieve |
| 69 | * it in the callback */ |
Stepan Salenikovich | 0cf247d | 2015-07-24 17:36:32 -0400 | [diff] [blame] | 70 | g_object_set_data(G_OBJECT(add_to), "parent-widget", parent); |
Stepan Salenikovich | f2d76c5 | 2015-07-17 17:54:56 -0400 | [diff] [blame] | 71 | |
Stepan Salenikovich | 0cf247d | 2015-07-24 17:36:32 -0400 | [diff] [blame] | 72 | 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 Salenikovich | f2d76c5 | 2015-07-17 17:54:56 -0400 | [diff] [blame] | 80 | |
| 81 | return add_to; |
| 82 | } |