Nicolas Jager | 0efc843 | 2017-03-22 16:22:00 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 Savoir-faire Linux Inc. |
| 3 | * Author: Nicolas Jäger <nicolas.jager@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 | |
| 20 | // Client |
| 21 | #include "pendingcontactrequests.h" |
| 22 | #include "models/gtkqtreemodel.h" |
| 23 | #include "native/pixbufmanipulator.h" |
| 24 | |
| 25 | // LRC |
| 26 | #include <recentmodel.h> |
| 27 | #include <accountmodel.h> |
| 28 | #include <pendingcontactrequestmodel.h> |
| 29 | #include <account.h> |
Nicolas Jager | 8a6e10a | 2017-04-18 09:13:57 -0400 | [diff] [blame] | 30 | #include <availableaccountmodel.h> |
Nicolas Jager | 0efc843 | 2017-03-22 16:22:00 -0400 | [diff] [blame] | 31 | |
| 32 | // System |
| 33 | #include <gtk/gtk.h> |
| 34 | #include <glib/gi18n.h> |
| 35 | |
| 36 | /** |
| 37 | * gtk structure |
| 38 | */ |
| 39 | struct _PendingContactRequestsView |
| 40 | { |
| 41 | GtkTreeView parent; |
| 42 | }; |
| 43 | |
| 44 | /** |
| 45 | * gtk class structure |
| 46 | */ |
| 47 | struct _PendingContactRequestsViewClass |
| 48 | { |
| 49 | GtkTreeViewClass parent_class; |
| 50 | }; |
| 51 | |
| 52 | typedef struct _PendingContactRequestsViewPrivate PendingContactRequestsViewPrivate; |
| 53 | |
| 54 | /** |
| 55 | * gtk private structure |
| 56 | */ |
| 57 | struct _PendingContactRequestsViewPrivate |
| 58 | { |
| 59 | GtkWidget *treeview_pending_contact_request_list; |
| 60 | QSortFilterProxyModel* myProxy; |
| 61 | }; |
| 62 | |
| 63 | G_DEFINE_TYPE_WITH_PRIVATE(PendingContactRequestsView, pending_contact_requests_view, GTK_TYPE_TREE_VIEW); |
| 64 | |
| 65 | #define PENDING_CONTACT_REQUESTS_VIEW_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), PENDING_CONTACT_REQUESTS_VIEW_TYPE, PendingContactRequestsViewPrivate)) |
| 66 | |
| 67 | /** |
| 68 | * gtk init function |
| 69 | */ |
| 70 | static void |
| 71 | pending_contact_requests_view_init(PendingContactRequestsView *self) |
| 72 | { |
| 73 | gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(self), FALSE); |
| 74 | gtk_tree_view_set_show_expanders(GTK_TREE_VIEW(self), FALSE); |
| 75 | gtk_tree_view_set_enable_search(GTK_TREE_VIEW(self), FALSE); |
| 76 | |
| 77 | // the next signal is used to set the model in function of the selection of the account |
Nicolas Jager | 8a6e10a | 2017-04-18 09:13:57 -0400 | [diff] [blame] | 78 | QObject::connect(AvailableAccountModel::instance().selectionModel(), &QItemSelectionModel::currentChanged, [self](const QModelIndex& idx){ |
Nicolas Jager | 0efc843 | 2017-03-22 16:22:00 -0400 | [diff] [blame] | 79 | auto account = idx.data(static_cast<int>(Account::Role::Object)).value<Account*>(); |
| 80 | GtkQTreeModel *pending_contact_requests_model; |
| 81 | pending_contact_requests_model = gtk_q_tree_model_new( |
| 82 | account->pendingContactRequestModel(), |
| 83 | 1/*nmbr. of cols.*/, |
| 84 | 0, |
| 85 | Qt::DisplayRole, |
| 86 | G_TYPE_STRING); |
| 87 | |
| 88 | gtk_tree_view_set_model(GTK_TREE_VIEW(self), GTK_TREE_MODEL(pending_contact_requests_model)); |
| 89 | }); |
| 90 | |
| 91 | GtkCellRenderer *renderer = gtk_cell_renderer_text_new(); |
| 92 | GtkTreeViewColumn *column = gtk_tree_view_column_new_with_attributes(C_("Account alias (name) column", "Alias"), renderer, "text", 0, NULL); |
| 93 | |
| 94 | /* layout */ |
| 95 | gtk_tree_view_append_column(GTK_TREE_VIEW(self), column); |
| 96 | gtk_tree_view_column_set_resizable(column, TRUE); |
| 97 | gtk_tree_view_column_set_expand(column, TRUE); |
| 98 | gtk_tree_view_expand_all(GTK_TREE_VIEW(self)); |
| 99 | |
| 100 | |
| 101 | gtk_widget_show_all(GTK_WIDGET(self)); |
| 102 | } |
| 103 | |
| 104 | /** |
| 105 | * gtk dispose function |
| 106 | */ |
| 107 | static void |
| 108 | pending_contact_requests_view_dispose(GObject *object) |
| 109 | { |
| 110 | G_OBJECT_CLASS(pending_contact_requests_view_parent_class)->dispose(object); |
| 111 | } |
| 112 | |
| 113 | /** |
| 114 | * gtk finalize function |
| 115 | */ |
| 116 | static void |
| 117 | pending_contact_requests_view_finalize(GObject *object) |
| 118 | { |
| 119 | G_OBJECT_CLASS(pending_contact_requests_view_parent_class)->finalize(object); |
| 120 | } |
| 121 | |
| 122 | /** |
| 123 | * gtk class init function |
| 124 | */ |
| 125 | static void |
| 126 | pending_contact_requests_view_class_init(PendingContactRequestsViewClass *klass) |
| 127 | { |
| 128 | G_OBJECT_CLASS(klass)->finalize = pending_contact_requests_view_finalize; |
| 129 | G_OBJECT_CLASS(klass)->dispose = pending_contact_requests_view_dispose; |
| 130 | } |
| 131 | |
| 132 | /** |
| 133 | * gtk new function |
| 134 | */ |
| 135 | GtkWidget * |
| 136 | pending_contact_requests_view_new() |
| 137 | { |
| 138 | gpointer self = g_object_new(PENDING_CONTACT_REQUESTS_VIEW_TYPE, NULL); |
| 139 | |
| 140 | return (GtkWidget *)self; |
| 141 | } |