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> |
| 34 | #include "../createcontactdialog.h" |
| 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 |
| 48 | create_new_contact(GtkWidget *item, ContactMethod *contactmethod) |
| 49 | { |
| 50 | // we get the parent widget which should be stored in the item object |
| 51 | GtkWidget *parent = GTK_WIDGET(g_object_get_data(G_OBJECT(item), "parent-widget")); |
| 52 | auto dialog = create_contact_dialog_new(contactmethod, parent); |
| 53 | gtk_dialog_run(GTK_DIALOG(dialog)); |
| 54 | gtk_widget_destroy(dialog); |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * creates a menu item with 2 options: |
| 59 | * - create a new contact with the given contact method |
| 60 | * TODO: - add given contact method to existing contact |
| 61 | */ |
| 62 | GtkWidget * menu_item_contact_add_to(ContactMethod *cm, GtkWidget *parent) |
| 63 | { |
| 64 | g_return_val_if_fail(cm, NULL); |
| 65 | |
| 66 | auto add_to = gtk_menu_item_new_with_mnemonic("_Add to"); |
| 67 | |
| 68 | auto add_to_menu = gtk_menu_new(); |
| 69 | gtk_menu_item_set_submenu(GTK_MENU_ITEM(add_to), add_to_menu); |
| 70 | |
| 71 | /* TODO: uncomment when feature added */ |
| 72 | // auto existing = gtk_menu_item_new_with_mnemonic("_Existing contact"); |
| 73 | // gtk_menu_shell_append(GTK_MENU_SHELL(add_to_menu), existing); |
| 74 | |
| 75 | auto new_contact = gtk_menu_item_new_with_mnemonic("_New contact"); |
| 76 | gtk_menu_shell_append(GTK_MENU_SHELL(add_to_menu), new_contact); |
| 77 | |
| 78 | /* save the parent widget in the item object, so we can retrieve |
| 79 | * it in the callback */ |
| 80 | g_object_set_data(G_OBJECT(new_contact), "parent-widget", parent); |
| 81 | |
| 82 | g_signal_connect(new_contact, "activate", G_CALLBACK(create_new_contact), cm); |
| 83 | |
| 84 | return add_to; |
| 85 | } |