Stepan Salenikovich | 2f8b449 | 2015-09-21 17:10:36 -0400 | [diff] [blame] | 1 | /* |
Stepan Salenikovich | be87d2c | 2016-01-25 14:14:34 -0500 | [diff] [blame] | 2 | * Copyright (C) 2015-2016 Savoir-faire Linux Inc. |
Stepan Salenikovich | 2f8b449 | 2015-09-21 17:10:36 -0400 | [diff] [blame] | 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 | |
| 20 | #include "recentcontactsview.h" |
| 21 | |
| 22 | #include <gtk/gtk.h> |
| 23 | #include <glib/gi18n.h> |
Stepan Salenikovich | f607822 | 2016-10-03 17:31:16 -0400 | [diff] [blame] | 24 | #include "models/gtkqtreemodel.h" |
Stepan Salenikovich | 2f8b449 | 2015-09-21 17:10:36 -0400 | [diff] [blame] | 25 | #include "utils/calling.h" |
| 26 | #include <memory> |
| 27 | #include <globalinstances.h> |
| 28 | #include "native/pixbufmanipulator.h" |
| 29 | #include <contactmethod.h> |
| 30 | #include "defines.h" |
| 31 | #include "utils/models.h" |
| 32 | #include <recentmodel.h> |
| 33 | #include <call.h> |
| 34 | #include "utils/menus.h" |
| 35 | #include <itemdataroles.h> |
| 36 | #include <callmodel.h> |
| 37 | #include <QtCore/QItemSelectionModel> |
| 38 | #include <historytimecategorymodel.h> |
| 39 | #include <QtCore/QDateTime> |
Stepan Salenikovich | 0c17cb6 | 2015-11-03 13:01:50 -0500 | [diff] [blame] | 40 | #include <QtCore/QMimeData> |
Stepan Salenikovich | d876507 | 2016-01-14 10:58:51 -0500 | [diff] [blame] | 41 | #include "utils/drawing.h" |
Stepan Salenikovich | 8eaa13e | 2016-08-26 16:51:48 -0400 | [diff] [blame] | 42 | #include <numbercategory.h> |
| 43 | #include "contactpopupmenu.h" |
Stepan Salenikovich | 2f8b449 | 2015-09-21 17:10:36 -0400 | [diff] [blame] | 44 | |
Stepan Salenikovich | 0c17cb6 | 2015-11-03 13:01:50 -0500 | [diff] [blame] | 45 | static constexpr const char* CALL_TARGET = "CALL_TARGET"; |
| 46 | static constexpr int CALL_TARGET_ID = 0; |
| 47 | |
Stepan Salenikovich | 2f8b449 | 2015-09-21 17:10:36 -0400 | [diff] [blame] | 48 | struct _RecentContactsView |
| 49 | { |
| 50 | GtkTreeView parent; |
| 51 | }; |
| 52 | |
| 53 | struct _RecentContactsViewClass |
| 54 | { |
| 55 | GtkTreeViewClass parent_class; |
| 56 | }; |
| 57 | |
| 58 | typedef struct _RecentContactsViewPrivate RecentContactsViewPrivate; |
| 59 | |
| 60 | struct _RecentContactsViewPrivate |
| 61 | { |
Stepan Salenikovich | 8eaa13e | 2016-08-26 16:51:48 -0400 | [diff] [blame] | 62 | GtkWidget *popup_menu; |
Stepan Salenikovich | e8fa681 | 2015-10-16 15:34:59 -0400 | [diff] [blame] | 63 | |
| 64 | QMetaObject::Connection selection_updated; |
Stepan Salenikovich | f53128f | 2016-10-07 10:32:16 -0400 | [diff] [blame] | 65 | QMetaObject::Connection layout_changed; |
Stepan Salenikovich | 2f8b449 | 2015-09-21 17:10:36 -0400 | [diff] [blame] | 66 | }; |
| 67 | |
| 68 | G_DEFINE_TYPE_WITH_PRIVATE(RecentContactsView, recent_contacts_view, GTK_TYPE_TREE_VIEW); |
| 69 | |
| 70 | #define RECENT_CONTACTS_VIEW_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), RECENT_CONTACTS_VIEW_TYPE, RecentContactsViewPrivate)) |
| 71 | |
| 72 | static void |
Stepan Salenikovich | c132342 | 2016-01-06 10:54:44 -0500 | [diff] [blame] | 73 | update_selection(GtkTreeSelection *selection, G_GNUC_UNUSED gpointer user_data) |
Stepan Salenikovich | 2f8b449 | 2015-09-21 17:10:36 -0400 | [diff] [blame] | 74 | { |
| 75 | auto current_proxy = get_index_from_selection(selection); |
Guillaume Roguez | 5d1514b | 2015-10-22 15:55:31 -0400 | [diff] [blame] | 76 | auto current = RecentModel::instance().peopleProxy()->mapToSource(current_proxy); |
Stepan Salenikovich | c132342 | 2016-01-06 10:54:44 -0500 | [diff] [blame] | 77 | |
| 78 | RecentModel::instance().selectionModel()->setCurrentIndex(current, QItemSelectionModel::ClearAndSelect); |
| 79 | |
| 80 | // update the CallModel selection since we rely on the UserActionModel |
Guillaume Roguez | 5d1514b | 2015-10-22 15:55:31 -0400 | [diff] [blame] | 81 | if (auto call_to_select = RecentModel::instance().getActiveCall(current)) { |
| 82 | CallModel::instance().selectCall(call_to_select); |
Stepan Salenikovich | 2f8b449 | 2015-09-21 17:10:36 -0400 | [diff] [blame] | 83 | } else { |
Guillaume Roguez | 5d1514b | 2015-10-22 15:55:31 -0400 | [diff] [blame] | 84 | CallModel::instance().selectionModel()->clearCurrentIndex(); |
Stepan Salenikovich | 2f8b449 | 2015-09-21 17:10:36 -0400 | [diff] [blame] | 85 | } |
| 86 | } |
| 87 | |
| 88 | static void |
Stepan Salenikovich | 2f8b449 | 2015-09-21 17:10:36 -0400 | [diff] [blame] | 89 | render_contact_photo(G_GNUC_UNUSED GtkTreeViewColumn *tree_column, |
| 90 | GtkCellRenderer *cell, |
| 91 | GtkTreeModel *model, |
| 92 | GtkTreeIter *iter, |
| 93 | G_GNUC_UNUSED gpointer data) |
| 94 | { |
Stepan Salenikovich | f607822 | 2016-10-03 17:31:16 -0400 | [diff] [blame] | 95 | QModelIndex idx = gtk_q_tree_model_get_source_idx(GTK_Q_TREE_MODEL(model), iter); |
Stepan Salenikovich | 2f8b449 | 2015-09-21 17:10:36 -0400 | [diff] [blame] | 96 | |
Stepan Salenikovich | d876507 | 2016-01-14 10:58:51 -0500 | [diff] [blame] | 97 | std::shared_ptr<GdkPixbuf> image; |
Stepan Salenikovich | 2f8b449 | 2015-09-21 17:10:36 -0400 | [diff] [blame] | 98 | /* we only want to render a photo for the top nodes: Person, ContactMethod (, later Conference) */ |
| 99 | QVariant object = idx.data(static_cast<int>(Ring::Role::Object)); |
| 100 | if (idx.isValid() && object.isValid()) { |
| 101 | QVariant var_photo; |
| 102 | if (auto person = object.value<Person *>()) { |
| 103 | var_photo = GlobalInstances::pixmapManipulator().contactPhoto(person, QSize(50, 50), false); |
| 104 | } else if (auto cm = object.value<ContactMethod *>()) { |
| 105 | /* get photo, note that this should in all cases be the fallback avatar, since there |
| 106 | * shouldn't be a person associated with this contact method */ |
| 107 | var_photo = GlobalInstances::pixmapManipulator().callPhoto(cm, QSize(50, 50), false); |
Stepan Salenikovich | 0c17cb6 | 2015-11-03 13:01:50 -0500 | [diff] [blame] | 108 | } else if (auto call = object.value<Call *>()) { |
| 109 | if (call->type() == Call::Type::CONFERENCE) { |
| 110 | var_photo = GlobalInstances::pixmapManipulator().callPhoto(call, QSize(50, 50), false); |
| 111 | } |
Stepan Salenikovich | 2f8b449 | 2015-09-21 17:10:36 -0400 | [diff] [blame] | 112 | } |
Stepan Salenikovich | d876507 | 2016-01-14 10:58:51 -0500 | [diff] [blame] | 113 | if (var_photo.isValid()) { |
| 114 | std::shared_ptr<GdkPixbuf> photo = var_photo.value<std::shared_ptr<GdkPixbuf>>(); |
| 115 | |
| 116 | auto unread = idx.data(static_cast<int>(Ring::Role::UnreadTextMessageCount)); |
| 117 | |
| 118 | image.reset(ring_draw_unread_messages(photo.get(), unread.toInt()), g_object_unref); |
| 119 | } else { |
Stepan Salenikovich | 2f8b449 | 2015-09-21 17:10:36 -0400 | [diff] [blame] | 120 | // set the width of the cell rendered to the with of the photo |
| 121 | // so that the other renderers are shifted to the right |
| 122 | g_object_set(G_OBJECT(cell), "width", 50, NULL); |
| 123 | } |
| 124 | } |
| 125 | |
Stepan Salenikovich | d876507 | 2016-01-14 10:58:51 -0500 | [diff] [blame] | 126 | g_object_set(G_OBJECT(cell), "pixbuf", image.get(), NULL); |
Stepan Salenikovich | 2f8b449 | 2015-09-21 17:10:36 -0400 | [diff] [blame] | 127 | } |
| 128 | |
| 129 | static void |
| 130 | render_name_and_info(G_GNUC_UNUSED GtkTreeViewColumn *tree_column, |
| 131 | GtkCellRenderer *cell, |
| 132 | GtkTreeModel *model, |
| 133 | GtkTreeIter *iter, |
Stepan Salenikovich | e4981b2 | 2015-10-22 15:22:59 -0400 | [diff] [blame] | 134 | GtkTreeView *treeview) |
Stepan Salenikovich | 2f8b449 | 2015-09-21 17:10:36 -0400 | [diff] [blame] | 135 | { |
| 136 | gchar *text = NULL; |
| 137 | |
Stepan Salenikovich | f607822 | 2016-10-03 17:31:16 -0400 | [diff] [blame] | 138 | QModelIndex idx = gtk_q_tree_model_get_source_idx(GTK_Q_TREE_MODEL(model), iter); |
Stepan Salenikovich | 2f8b449 | 2015-09-21 17:10:36 -0400 | [diff] [blame] | 139 | |
Stepan Salenikovich | e4981b2 | 2015-10-22 15:22:59 -0400 | [diff] [blame] | 140 | // check if this iter is selected |
| 141 | gboolean is_selected = FALSE; |
| 142 | if (GTK_IS_TREE_VIEW(treeview)) { |
| 143 | auto selection = gtk_tree_view_get_selection(treeview); |
| 144 | is_selected = gtk_tree_selection_iter_is_selected(selection, iter); |
| 145 | } |
| 146 | |
Stepan Salenikovich | 2f8b449 | 2015-09-21 17:10:36 -0400 | [diff] [blame] | 147 | auto type = idx.data(static_cast<int>(Ring::Role::ObjectType)); |
| 148 | if (idx.isValid() && type.isValid()) { |
| 149 | switch (type.value<Ring::ObjectType>()) { |
| 150 | case Ring::ObjectType::Person: |
| 151 | case Ring::ObjectType::ContactMethod: |
| 152 | { |
| 153 | auto var_name = idx.data(static_cast<int>(Ring::Role::Name)); |
| 154 | auto var_lastused = idx.data(static_cast<int>(Ring::Role::LastUsed)); |
| 155 | auto var_status = idx.data(static_cast<int>(Ring::Role::FormattedState)); |
| 156 | |
| 157 | QString name, status; |
| 158 | |
| 159 | if (var_name.isValid()) |
| 160 | name = var_name.value<QString>(); |
| 161 | |
| 162 | // show the status if there is a call, otherwise the last used date/time |
| 163 | if (var_status.isValid()) { |
| 164 | status += var_status.value<QString>(); |
| 165 | }else if (var_lastused.isValid()) { |
| 166 | auto date_time = var_lastused.value<QDateTime>(); |
| 167 | auto category = HistoryTimeCategoryModel::timeToHistoryConst(date_time.toTime_t()); |
| 168 | |
| 169 | // if it is 'today', then we only want to show the time |
| 170 | if (category != HistoryTimeCategoryModel::HistoryConst::Today) { |
| 171 | status += HistoryTimeCategoryModel::timeToHistoryCategory(date_time.toTime_t()); |
| 172 | } |
| 173 | // we only want to show the time if it is less than a week ago |
| 174 | if (category < HistoryTimeCategoryModel::HistoryConst::A_week_ago) { |
| 175 | if (!status.isEmpty()) |
| 176 | status += ", "; |
| 177 | status += QLocale::system().toString(date_time.time(), QLocale::ShortFormat); |
| 178 | } |
| 179 | } |
| 180 | |
Stepan Salenikovich | e4981b2 | 2015-10-22 15:22:59 -0400 | [diff] [blame] | 181 | /* we want the color of the status text to be the default color if this iter is |
| 182 | * selected so that the treeview is able to invert it against the selection color */ |
| 183 | if (is_selected) { |
Stepan Salenikovich | 0731de0 | 2016-05-17 17:47:16 -0400 | [diff] [blame] | 184 | text = g_markup_printf_escaped("%s\n<span size=\"smaller\">%s</span>", |
| 185 | name.toUtf8().constData(), |
| 186 | status.toUtf8().constData()); |
Stepan Salenikovich | e4981b2 | 2015-10-22 15:22:59 -0400 | [diff] [blame] | 187 | } else { |
Stepan Salenikovich | 0731de0 | 2016-05-17 17:47:16 -0400 | [diff] [blame] | 188 | text = g_markup_printf_escaped("%s\n<span size=\"smaller\" color=\"gray\">%s</span>", |
| 189 | name.toUtf8().constData(), |
| 190 | status.toUtf8().constData()); |
Stepan Salenikovich | e4981b2 | 2015-10-22 15:22:59 -0400 | [diff] [blame] | 191 | } |
Stepan Salenikovich | 2f8b449 | 2015-09-21 17:10:36 -0400 | [diff] [blame] | 192 | } |
| 193 | break; |
| 194 | case Ring::ObjectType::Call: |
| 195 | { |
Stepan Salenikovich | 0c17cb6 | 2015-11-03 13:01:50 -0500 | [diff] [blame] | 196 | // check if it is a conference |
| 197 | auto idx_source = RecentModel::instance().peopleProxy()->mapToSource(idx); |
| 198 | auto is_conference = RecentModel::instance().isConference(idx_source); |
Stepan Salenikovich | 2f8b449 | 2015-09-21 17:10:36 -0400 | [diff] [blame] | 199 | |
Stepan Salenikovich | 0c17cb6 | 2015-11-03 13:01:50 -0500 | [diff] [blame] | 200 | if (is_conference) { |
| 201 | auto var_name = idx.data(static_cast<int>(Ring::Role::Name)); |
Stepan Salenikovich | 0731de0 | 2016-05-17 17:47:16 -0400 | [diff] [blame] | 202 | text = g_markup_escape_text(var_name.value<QString>().toUtf8().constData(), -1); |
Stepan Salenikovich | 0c17cb6 | 2015-11-03 13:01:50 -0500 | [diff] [blame] | 203 | } else { |
| 204 | auto parent_source = RecentModel::instance().peopleProxy()->mapToSource(idx.parent()); |
| 205 | if (RecentModel::instance().isConference(parent_source)) { |
| 206 | // part of conference, simply display the name |
| 207 | auto var_name = idx.data(static_cast<int>(Ring::Role::Name)); |
Stepan Salenikovich | 2f8b449 | 2015-09-21 17:10:36 -0400 | [diff] [blame] | 208 | |
Stepan Salenikovich | 0c17cb6 | 2015-11-03 13:01:50 -0500 | [diff] [blame] | 209 | /* we want the color of the name text to be the default color if this iter is |
| 210 | * selected so that the treeview is able to invert it against the selection color */ |
Stepan Salenikovich | 0731de0 | 2016-05-17 17:47:16 -0400 | [diff] [blame] | 211 | if (is_selected) { |
| 212 | text = g_markup_printf_escaped("<span size=\"smaller\">%s</span>", |
| 213 | var_name.value<QString>().toUtf8().constData()); |
| 214 | } else { |
| 215 | text = g_markup_printf_escaped("<span size=\"smaller\" color=\"gray\">%s</span>", |
| 216 | var_name.value<QString>().toUtf8().constData()); |
| 217 | } |
Stepan Salenikovich | 0c17cb6 | 2015-11-03 13:01:50 -0500 | [diff] [blame] | 218 | } else { |
| 219 | // just a call, so display the state |
| 220 | auto var_status = idx.data(static_cast<int>(Ring::Role::FormattedState)); |
Stepan Salenikovich | 2f8b449 | 2015-09-21 17:10:36 -0400 | [diff] [blame] | 221 | |
Stepan Salenikovich | 0c17cb6 | 2015-11-03 13:01:50 -0500 | [diff] [blame] | 222 | QString status; |
| 223 | |
| 224 | if (var_status.isValid()) |
| 225 | status += var_status.value<QString>(); |
| 226 | |
| 227 | /* we want the color of the status text to be the default color if this iter is |
| 228 | * selected so that the treeview is able to invert it against the selection color */ |
Stepan Salenikovich | 0731de0 | 2016-05-17 17:47:16 -0400 | [diff] [blame] | 229 | if (is_selected) { |
| 230 | text = g_markup_printf_escaped("<span size=\"smaller\">%s</span>", |
| 231 | status.toUtf8().constData()); |
| 232 | } else { |
| 233 | text = g_markup_printf_escaped("<span size=\"smaller\" color=\"gray\">%s</span>", |
| 234 | status.toUtf8().constData()); |
| 235 | } |
Stepan Salenikovich | 0c17cb6 | 2015-11-03 13:01:50 -0500 | [diff] [blame] | 236 | } |
| 237 | } |
Stepan Salenikovich | 2f8b449 | 2015-09-21 17:10:36 -0400 | [diff] [blame] | 238 | } |
| 239 | break; |
| 240 | case Ring::ObjectType::Media: |
aviau | 9a27747 | 2016-12-13 14:54:58 -0500 | [diff] [blame^] | 241 | case Ring::ObjectType::Certificate: |
Stepan Salenikovich | 2f8b449 | 2015-09-21 17:10:36 -0400 | [diff] [blame] | 242 | // nothing to do for now |
Stepan Salenikovich | 4e7ea71 | 2015-12-24 14:04:37 -0500 | [diff] [blame] | 243 | case Ring::ObjectType::COUNT__: |
Stepan Salenikovich | 2f8b449 | 2015-09-21 17:10:36 -0400 | [diff] [blame] | 244 | break; |
| 245 | } |
| 246 | } |
| 247 | |
| 248 | g_object_set(G_OBJECT(cell), "markup", text, NULL); |
| 249 | g_free(text); |
| 250 | } |
| 251 | |
| 252 | static void |
| 253 | render_call_duration(G_GNUC_UNUSED GtkTreeViewColumn *tree_column, |
| 254 | GtkCellRenderer *cell, |
| 255 | GtkTreeModel *model, |
| 256 | GtkTreeIter *iter, |
| 257 | G_GNUC_UNUSED gpointer data) |
| 258 | { |
| 259 | gchar *text = NULL; |
| 260 | |
Stepan Salenikovich | f607822 | 2016-10-03 17:31:16 -0400 | [diff] [blame] | 261 | QModelIndex idx = gtk_q_tree_model_get_source_idx(GTK_Q_TREE_MODEL(model), iter); |
Stepan Salenikovich | 2f8b449 | 2015-09-21 17:10:36 -0400 | [diff] [blame] | 262 | |
| 263 | auto type = idx.data(static_cast<int>(Ring::Role::ObjectType)); |
| 264 | if (idx.isValid() && type.isValid()) { |
| 265 | switch (type.value<Ring::ObjectType>()) { |
| 266 | case Ring::ObjectType::Person: |
| 267 | case Ring::ObjectType::ContactMethod: |
| 268 | { |
| 269 | // check if there are any children (calls); we need to convert to source model in |
| 270 | // case there is only one |
Guillaume Roguez | 5d1514b | 2015-10-22 15:55:31 -0400 | [diff] [blame] | 271 | auto idx_source = RecentModel::instance().peopleProxy()->mapToSource(idx); |
Stepan Salenikovich | 2f8b449 | 2015-09-21 17:10:36 -0400 | [diff] [blame] | 272 | auto duration = idx.data(static_cast<int>(Ring::Role::Length)); |
| 273 | if (idx_source.isValid() |
| 274 | && (idx_source.model()->rowCount(idx_source) == 1) |
| 275 | && duration.isValid()) |
| 276 | { |
Stepan Salenikovich | 0731de0 | 2016-05-17 17:47:16 -0400 | [diff] [blame] | 277 | text = g_markup_escape_text(duration.value<QString>().toUtf8().constData(), -1); |
Stepan Salenikovich | 2f8b449 | 2015-09-21 17:10:36 -0400 | [diff] [blame] | 278 | } |
| 279 | } |
| 280 | break; |
| 281 | case Ring::ObjectType::Call: |
| 282 | { |
Stepan Salenikovich | 0c17cb6 | 2015-11-03 13:01:50 -0500 | [diff] [blame] | 283 | // do not display the duration if the call is part of a conference |
| 284 | auto parent_source = RecentModel::instance().peopleProxy()->mapToSource(idx.parent()); |
| 285 | auto in_conference = RecentModel::instance().isConference(parent_source); |
Stepan Salenikovich | 2f8b449 | 2015-09-21 17:10:36 -0400 | [diff] [blame] | 286 | |
Stepan Salenikovich | 0c17cb6 | 2015-11-03 13:01:50 -0500 | [diff] [blame] | 287 | if (!in_conference) { |
| 288 | auto duration = idx.data(static_cast<int>(Ring::Role::Length)); |
| 289 | |
| 290 | if (duration.isValid()) |
Stepan Salenikovich | 0731de0 | 2016-05-17 17:47:16 -0400 | [diff] [blame] | 291 | text = g_markup_escape_text(duration.value<QString>().toUtf8().constData(), -1); |
Stepan Salenikovich | 0c17cb6 | 2015-11-03 13:01:50 -0500 | [diff] [blame] | 292 | } |
Stepan Salenikovich | 2f8b449 | 2015-09-21 17:10:36 -0400 | [diff] [blame] | 293 | } |
| 294 | break; |
| 295 | case Ring::ObjectType::Media: |
aviau | 9a27747 | 2016-12-13 14:54:58 -0500 | [diff] [blame^] | 296 | case Ring::ObjectType::Certificate: |
Stepan Salenikovich | 2f8b449 | 2015-09-21 17:10:36 -0400 | [diff] [blame] | 297 | // nothing to do for now |
Stepan Salenikovich | 4e7ea71 | 2015-12-24 14:04:37 -0500 | [diff] [blame] | 298 | case Ring::ObjectType::COUNT__: |
Stepan Salenikovich | 2f8b449 | 2015-09-21 17:10:36 -0400 | [diff] [blame] | 299 | break; |
| 300 | } |
| 301 | } |
| 302 | |
| 303 | g_object_set(G_OBJECT(cell), "markup", text, NULL); |
| 304 | g_free(text); |
| 305 | } |
| 306 | |
| 307 | static void |
| 308 | activate_item(GtkTreeView *tree_view, |
| 309 | GtkTreePath *path, |
| 310 | G_GNUC_UNUSED GtkTreeViewColumn *column, |
| 311 | G_GNUC_UNUSED gpointer user_data) |
| 312 | { |
| 313 | auto model = gtk_tree_view_get_model(tree_view); |
| 314 | GtkTreeIter iter; |
| 315 | if (gtk_tree_model_get_iter(model, &iter, path)) { |
Stepan Salenikovich | f607822 | 2016-10-03 17:31:16 -0400 | [diff] [blame] | 316 | QModelIndex idx = gtk_q_tree_model_get_source_idx(GTK_Q_TREE_MODEL(model), &iter); |
Stepan Salenikovich | 2f8b449 | 2015-09-21 17:10:36 -0400 | [diff] [blame] | 317 | auto type = idx.data(static_cast<int>(Ring::Role::ObjectType)); |
| 318 | if (idx.isValid() && type.isValid()) { |
| 319 | switch (type.value<Ring::ObjectType>()) { |
| 320 | case Ring::ObjectType::Person: |
| 321 | { |
| 322 | // call the last used contact method |
| 323 | // TODO: if no contact methods have been used, offer a popup to Choose |
| 324 | auto p_var = idx.data(static_cast<int>(Ring::Role::Object)); |
| 325 | if (p_var.isValid()) { |
| 326 | auto person = p_var.value<Person *>(); |
| 327 | auto cms = person->phoneNumbers(); |
| 328 | |
| 329 | if (!cms.isEmpty()) { |
| 330 | auto last_used_cm = cms.at(0); |
| 331 | for (int i = 1; i < cms.size(); ++i) { |
| 332 | auto new_cm = cms.at(i); |
| 333 | if (difftime(new_cm->lastUsed(), last_used_cm->lastUsed()) > 0) |
| 334 | last_used_cm = new_cm; |
| 335 | } |
| 336 | |
| 337 | place_new_call(last_used_cm); |
| 338 | } |
| 339 | } |
| 340 | } |
| 341 | break; |
| 342 | case Ring::ObjectType::ContactMethod: |
| 343 | { |
| 344 | // call the contact method |
| 345 | auto cm = idx.data(static_cast<int>(Ring::Role::Object)); |
| 346 | if (cm.isValid()) |
| 347 | place_new_call(cm.value<ContactMethod *>()); |
| 348 | } |
| 349 | break; |
| 350 | case Ring::ObjectType::Call: |
| 351 | case Ring::ObjectType::Media: |
aviau | 9a27747 | 2016-12-13 14:54:58 -0500 | [diff] [blame^] | 352 | case Ring::ObjectType::Certificate: |
Stepan Salenikovich | 2f8b449 | 2015-09-21 17:10:36 -0400 | [diff] [blame] | 353 | // nothing to do for now |
Stepan Salenikovich | 4e7ea71 | 2015-12-24 14:04:37 -0500 | [diff] [blame] | 354 | case Ring::ObjectType::COUNT__: |
Stepan Salenikovich | 2f8b449 | 2015-09-21 17:10:36 -0400 | [diff] [blame] | 355 | break; |
| 356 | } |
| 357 | } |
| 358 | } |
| 359 | } |
| 360 | |
Stepan Salenikovich | 2f8b449 | 2015-09-21 17:10:36 -0400 | [diff] [blame] | 361 | static void |
| 362 | expand_if_child(G_GNUC_UNUSED GtkTreeModel *tree_model, |
| 363 | GtkTreePath *path, |
| 364 | G_GNUC_UNUSED GtkTreeIter *iter, |
| 365 | GtkTreeView *treeview) |
| 366 | { |
| 367 | if (gtk_tree_path_get_depth(path) > 1) |
| 368 | gtk_tree_view_expand_to_path(treeview, path); |
| 369 | } |
| 370 | |
| 371 | static void |
Stepan Salenikovich | ec0862f | 2015-10-16 15:49:42 -0400 | [diff] [blame] | 372 | scroll_to_selection(GtkTreeSelection *selection) |
| 373 | { |
| 374 | GtkTreeModel *model = nullptr; |
| 375 | GtkTreeIter iter; |
| 376 | if (gtk_tree_selection_get_selected(selection, &model, &iter)) { |
| 377 | auto path = gtk_tree_model_get_path(model, &iter); |
| 378 | auto treeview = gtk_tree_selection_get_tree_view(selection); |
| 379 | gtk_tree_view_scroll_to_cell(treeview, path, nullptr, FALSE, 0.0, 0.0); |
| 380 | } |
| 381 | } |
| 382 | |
| 383 | static void |
Stepan Salenikovich | 0c17cb6 | 2015-11-03 13:01:50 -0500 | [diff] [blame] | 384 | on_drag_data_get(GtkWidget *treeview, |
| 385 | G_GNUC_UNUSED GdkDragContext *context, |
| 386 | GtkSelectionData *data, |
| 387 | G_GNUC_UNUSED guint info, |
| 388 | G_GNUC_UNUSED guint time, |
| 389 | G_GNUC_UNUSED gpointer user_data) |
| 390 | { |
| 391 | g_return_if_fail(IS_RECENT_CONTACTS_VIEW(treeview)); |
| 392 | |
| 393 | /* we always drag the selected row */ |
| 394 | auto selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview)); |
| 395 | GtkTreeModel *model = NULL; |
| 396 | GtkTreeIter iter; |
| 397 | |
| 398 | if (gtk_tree_selection_get_selected(selection, &model, &iter)) { |
| 399 | auto path_str = gtk_tree_model_get_string_from_iter(model, &iter); |
| 400 | |
| 401 | gtk_selection_data_set(data, |
| 402 | gdk_atom_intern_static_string(CALL_TARGET), |
| 403 | 8, /* bytes */ |
| 404 | (guchar *)path_str, |
| 405 | strlen(path_str) + 1); |
| 406 | |
| 407 | g_free(path_str); |
| 408 | } else { |
| 409 | g_warning("drag selection not valid"); |
| 410 | } |
| 411 | } |
| 412 | |
| 413 | static gboolean |
| 414 | on_drag_drop(GtkWidget *treeview, |
| 415 | GdkDragContext *context, |
| 416 | gint x, |
| 417 | gint y, |
| 418 | guint time, |
| 419 | G_GNUC_UNUSED gpointer user_data) |
| 420 | { |
| 421 | g_return_val_if_fail(IS_RECENT_CONTACTS_VIEW(treeview), FALSE); |
| 422 | |
| 423 | GtkTreePath *path = NULL; |
| 424 | GtkTreeViewDropPosition drop_pos; |
| 425 | |
| 426 | if (gtk_tree_view_get_dest_row_at_pos(GTK_TREE_VIEW(treeview), |
| 427 | x, y, &path, &drop_pos)) { |
| 428 | |
| 429 | GdkAtom target_type = gtk_drag_dest_find_target(treeview, context, NULL); |
| 430 | |
| 431 | if (target_type != GDK_NONE) { |
| 432 | g_debug("can drop"); |
| 433 | gtk_drag_get_data(treeview, context, target_type, time); |
| 434 | return TRUE; |
| 435 | } |
| 436 | |
| 437 | gtk_tree_path_free(path); |
| 438 | } |
| 439 | |
| 440 | return FALSE; |
| 441 | } |
| 442 | |
| 443 | static gboolean |
| 444 | on_drag_motion(GtkWidget *treeview, |
| 445 | GdkDragContext *context, |
| 446 | gint x, |
| 447 | gint y, |
| 448 | guint time, |
| 449 | G_GNUC_UNUSED gpointer user_data) |
| 450 | { |
| 451 | g_return_val_if_fail(IS_RECENT_CONTACTS_VIEW(treeview), FALSE); |
| 452 | |
| 453 | GtkTreePath *path = NULL; |
| 454 | GtkTreeViewDropPosition drop_pos; |
| 455 | |
| 456 | if (gtk_tree_view_get_dest_row_at_pos(GTK_TREE_VIEW(treeview), |
| 457 | x, y, &path, &drop_pos)) { |
| 458 | // we only want to drop on a row, not before or after |
| 459 | if (drop_pos == GTK_TREE_VIEW_DROP_BEFORE) { |
| 460 | gtk_tree_view_set_drag_dest_row(GTK_TREE_VIEW(treeview), path, GTK_TREE_VIEW_DROP_INTO_OR_BEFORE); |
| 461 | } else if (drop_pos == GTK_TREE_VIEW_DROP_AFTER) { |
| 462 | gtk_tree_view_set_drag_dest_row(GTK_TREE_VIEW(treeview), path, GTK_TREE_VIEW_DROP_INTO_OR_AFTER); |
| 463 | } |
| 464 | gdk_drag_status(context, gdk_drag_context_get_suggested_action(context), time); |
| 465 | return TRUE; |
| 466 | } else { |
| 467 | // not a row in the treeview, so we cannot drop |
| 468 | return FALSE; |
| 469 | } |
| 470 | } |
| 471 | |
| 472 | static void |
| 473 | on_drag_data_received(GtkWidget *treeview, |
| 474 | GdkDragContext *context, |
| 475 | gint x, |
| 476 | gint y, |
| 477 | GtkSelectionData *data, |
| 478 | G_GNUC_UNUSED guint info, |
| 479 | guint time, |
| 480 | G_GNUC_UNUSED gpointer user_data) |
| 481 | { |
| 482 | g_return_if_fail(IS_RECENT_CONTACTS_VIEW(treeview)); |
| 483 | |
| 484 | gboolean success = FALSE; |
| 485 | |
| 486 | /* get the source and destination calls */ |
| 487 | auto path_str_source = (gchar *)gtk_selection_data_get_data(data); |
| 488 | auto type = gtk_selection_data_get_data_type(data); |
| 489 | g_debug("data type: %s", gdk_atom_name(type)); |
| 490 | if (path_str_source && strlen(path_str_source) > 0) { |
| 491 | g_debug("source path: %s", path_str_source); |
| 492 | |
| 493 | /* get the destination path */ |
| 494 | GtkTreePath *dest_path = NULL; |
| 495 | if (gtk_tree_view_get_dest_row_at_pos(GTK_TREE_VIEW(treeview), x, y, &dest_path, NULL)) { |
| 496 | auto model = gtk_tree_view_get_model(GTK_TREE_VIEW(treeview)); |
| 497 | |
| 498 | GtkTreeIter source; |
| 499 | gtk_tree_model_get_iter_from_string(model, &source, path_str_source); |
Stepan Salenikovich | f607822 | 2016-10-03 17:31:16 -0400 | [diff] [blame] | 500 | auto idx_source_proxy = gtk_q_tree_model_get_source_idx(GTK_Q_TREE_MODEL(model), &source); |
Stepan Salenikovich | 0c17cb6 | 2015-11-03 13:01:50 -0500 | [diff] [blame] | 501 | |
| 502 | GtkTreeIter dest; |
| 503 | gtk_tree_model_get_iter(model, &dest, dest_path); |
Stepan Salenikovich | f607822 | 2016-10-03 17:31:16 -0400 | [diff] [blame] | 504 | auto idx_dest_proxy = gtk_q_tree_model_get_source_idx(GTK_Q_TREE_MODEL(model), &dest); |
Stepan Salenikovich | 0c17cb6 | 2015-11-03 13:01:50 -0500 | [diff] [blame] | 505 | |
| 506 | // get call objects and indeces from RecentModel indeces being drag and dropped |
| 507 | auto idx_source = RecentModel::instance().peopleProxy()->mapToSource(idx_source_proxy); |
| 508 | auto idx_dest = RecentModel::instance().peopleProxy()->mapToSource(idx_dest_proxy); |
| 509 | auto call_source = RecentModel::instance().getActiveCall(idx_source); |
| 510 | auto call_dest = RecentModel::instance().getActiveCall(idx_dest); |
| 511 | auto idx_call_source = CallModel::instance().getIndex(call_source); |
| 512 | auto idx_call_dest = CallModel::instance().getIndex(call_dest); |
| 513 | |
| 514 | if (idx_call_source.isValid() && idx_call_dest.isValid()) { |
| 515 | QModelIndexList source_list; |
| 516 | source_list << idx_call_source; |
| 517 | auto mimeData = CallModel::instance().mimeData(source_list); |
| 518 | auto action = Call::DropAction::Conference; |
| 519 | mimeData->setProperty("dropAction", action); |
| 520 | |
| 521 | if (CallModel::instance().dropMimeData(mimeData, Qt::MoveAction, idx_call_dest.row(), idx_call_dest.column(), idx_call_dest.parent())) { |
| 522 | success = TRUE; |
| 523 | } else { |
| 524 | g_warning("could not drop mime data"); |
| 525 | } |
| 526 | } else { |
| 527 | g_warning("source or dest call not valid"); |
| 528 | } |
| 529 | |
| 530 | gtk_tree_path_free(dest_path); |
| 531 | } |
| 532 | } |
| 533 | |
| 534 | gtk_drag_finish(context, success, FALSE, time); |
| 535 | } |
| 536 | |
| 537 | static void |
Stepan Salenikovich | 2f8b449 | 2015-09-21 17:10:36 -0400 | [diff] [blame] | 538 | recent_contacts_view_init(RecentContactsView *self) |
| 539 | { |
Stepan Salenikovich | e8fa681 | 2015-10-16 15:34:59 -0400 | [diff] [blame] | 540 | RecentContactsViewPrivate *priv = RECENT_CONTACTS_VIEW_GET_PRIVATE(self); |
| 541 | |
Stepan Salenikovich | 2f8b449 | 2015-09-21 17:10:36 -0400 | [diff] [blame] | 542 | gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(self), FALSE); |
| 543 | /* no need to show the expander since it will always be expanded */ |
| 544 | gtk_tree_view_set_show_expanders(GTK_TREE_VIEW(self), FALSE); |
| 545 | /* disable default search, we will handle it ourselves via LRC; |
| 546 | * otherwise the search steals input focus on key presses */ |
| 547 | gtk_tree_view_set_enable_search(GTK_TREE_VIEW(self), FALSE); |
| 548 | |
Stepan Salenikovich | f607822 | 2016-10-03 17:31:16 -0400 | [diff] [blame] | 549 | GtkQTreeModel *recent_model = gtk_q_tree_model_new( |
Guillaume Roguez | 5d1514b | 2015-10-22 15:55:31 -0400 | [diff] [blame] | 550 | RecentModel::instance().peopleProxy(), |
Stepan Salenikovich | 2f8b449 | 2015-09-21 17:10:36 -0400 | [diff] [blame] | 551 | 1, |
aviau | 271bcc2 | 2016-05-27 17:25:19 -0400 | [diff] [blame] | 552 | 0, Qt::DisplayRole, G_TYPE_STRING); |
Stepan Salenikovich | 2f8b449 | 2015-09-21 17:10:36 -0400 | [diff] [blame] | 553 | |
| 554 | gtk_tree_view_set_model(GTK_TREE_VIEW(self), |
| 555 | GTK_TREE_MODEL(recent_model)); |
| 556 | |
| 557 | /* photo and name/contact method column */ |
| 558 | GtkCellArea *area = gtk_cell_area_box_new(); |
| 559 | GtkTreeViewColumn *column = gtk_tree_view_column_new_with_area(area); |
| 560 | |
| 561 | /* photo renderer */ |
| 562 | GtkCellRenderer *renderer = gtk_cell_renderer_pixbuf_new(); |
| 563 | gtk_cell_area_box_pack_start(GTK_CELL_AREA_BOX(area), renderer, FALSE, FALSE, FALSE); |
| 564 | |
| 565 | /* get the photo */ |
| 566 | gtk_tree_view_column_set_cell_data_func( |
| 567 | column, |
| 568 | renderer, |
| 569 | (GtkTreeCellDataFunc)render_contact_photo, |
| 570 | NULL, |
| 571 | NULL); |
| 572 | |
| 573 | /* name/cm and status renderer */ |
| 574 | renderer = gtk_cell_renderer_text_new(); |
| 575 | g_object_set(G_OBJECT(renderer), "ellipsize", PANGO_ELLIPSIZE_END, NULL); |
| 576 | gtk_cell_area_box_pack_start(GTK_CELL_AREA_BOX(area), renderer, FALSE, FALSE, FALSE); |
| 577 | |
| 578 | gtk_tree_view_column_set_cell_data_func( |
| 579 | column, |
| 580 | renderer, |
| 581 | (GtkTreeCellDataFunc)render_name_and_info, |
Stepan Salenikovich | e4981b2 | 2015-10-22 15:22:59 -0400 | [diff] [blame] | 582 | self, |
Stepan Salenikovich | 2f8b449 | 2015-09-21 17:10:36 -0400 | [diff] [blame] | 583 | NULL); |
| 584 | |
Stepan Salenikovich | e8ef935 | 2015-10-27 19:07:46 -0400 | [diff] [blame] | 585 | /* call duration */ |
Stepan Salenikovich | 2f8b449 | 2015-09-21 17:10:36 -0400 | [diff] [blame] | 586 | renderer = gtk_cell_renderer_text_new(); |
Stepan Salenikovich | e8ef935 | 2015-10-27 19:07:46 -0400 | [diff] [blame] | 587 | g_object_set(G_OBJECT(renderer), "xalign", 1.0, NULL); |
| 588 | gtk_cell_area_box_pack_end(GTK_CELL_AREA_BOX(area), renderer, FALSE, FALSE, FALSE); |
Stepan Salenikovich | 2f8b449 | 2015-09-21 17:10:36 -0400 | [diff] [blame] | 589 | gtk_tree_view_column_set_cell_data_func( |
| 590 | column, |
| 591 | renderer, |
| 592 | (GtkTreeCellDataFunc)render_call_duration, |
| 593 | NULL, |
| 594 | NULL); |
| 595 | |
Stepan Salenikovich | e8ef935 | 2015-10-27 19:07:46 -0400 | [diff] [blame] | 596 | gtk_tree_view_append_column(GTK_TREE_VIEW(self), column); |
| 597 | gtk_tree_view_column_set_resizable(column, TRUE); |
| 598 | gtk_tree_view_column_set_expand(column, TRUE); |
Stepan Salenikovich | 2f8b449 | 2015-09-21 17:10:36 -0400 | [diff] [blame] | 599 | gtk_tree_view_expand_all(GTK_TREE_VIEW(self)); |
| 600 | |
Stepan Salenikovich | 2f8b449 | 2015-09-21 17:10:36 -0400 | [diff] [blame] | 601 | g_signal_connect(self, "row-activated", G_CALLBACK(activate_item), NULL); |
| 602 | g_signal_connect(recent_model, "row-inserted", G_CALLBACK(expand_if_child), self); |
| 603 | |
| 604 | GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(self)); |
Stepan Salenikovich | c132342 | 2016-01-06 10:54:44 -0500 | [diff] [blame] | 605 | g_signal_connect(selection, "changed", G_CALLBACK(update_selection), NULL); |
Stepan Salenikovich | ec0862f | 2015-10-16 15:49:42 -0400 | [diff] [blame] | 606 | g_signal_connect(selection, "changed", G_CALLBACK(scroll_to_selection), NULL); |
| 607 | g_signal_connect_swapped(recent_model, "rows-reordered", G_CALLBACK(scroll_to_selection), selection); |
Stepan Salenikovich | 2f8b449 | 2015-09-21 17:10:36 -0400 | [diff] [blame] | 608 | |
Stepan Salenikovich | c132342 | 2016-01-06 10:54:44 -0500 | [diff] [blame] | 609 | /* update the selection based on the RecentModel */ |
Stepan Salenikovich | e8fa681 | 2015-10-16 15:34:59 -0400 | [diff] [blame] | 610 | priv->selection_updated = QObject::connect( |
Stepan Salenikovich | c132342 | 2016-01-06 10:54:44 -0500 | [diff] [blame] | 611 | RecentModel::instance().selectionModel(), |
Stepan Salenikovich | e8fa681 | 2015-10-16 15:34:59 -0400 | [diff] [blame] | 612 | &QItemSelectionModel::currentChanged, |
| 613 | [self, recent_model](const QModelIndex current, G_GNUC_UNUSED const QModelIndex & previous) { |
Stepan Salenikovich | c132342 | 2016-01-06 10:54:44 -0500 | [diff] [blame] | 614 | auto selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(self)); |
| 615 | |
| 616 | auto current_proxy = RecentModel::instance().peopleProxy()->mapFromSource(current); |
Stepan Salenikovich | e8fa681 | 2015-10-16 15:34:59 -0400 | [diff] [blame] | 617 | |
Stepan Salenikovich | 8043a56 | 2016-03-18 13:56:40 -0400 | [diff] [blame] | 618 | if (current.isValid()) { |
| 619 | /* select the current */ |
| 620 | GtkTreeIter new_iter; |
Stepan Salenikovich | f607822 | 2016-10-03 17:31:16 -0400 | [diff] [blame] | 621 | if (gtk_q_tree_model_source_index_to_iter(recent_model, current_proxy, &new_iter)) { |
Stepan Salenikovich | 8043a56 | 2016-03-18 13:56:40 -0400 | [diff] [blame] | 622 | gtk_tree_selection_select_iter(selection, &new_iter); |
| 623 | } |
| 624 | } else { |
| 625 | gtk_tree_selection_unselect_all(selection); |
Stepan Salenikovich | e8fa681 | 2015-10-16 15:34:59 -0400 | [diff] [blame] | 626 | } |
| 627 | } |
| 628 | ); |
| 629 | |
Stepan Salenikovich | f53128f | 2016-10-07 10:32:16 -0400 | [diff] [blame] | 630 | /* we may need to update the selection when the layout changes */ |
| 631 | priv->layout_changed = QObject::connect( |
| 632 | RecentModel::instance().peopleProxy(), |
| 633 | &QAbstractItemModel::layoutChanged, |
| 634 | [self, recent_model]() { |
| 635 | auto idx = RecentModel::instance().selectionModel()->currentIndex(); |
| 636 | auto selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(self)); |
| 637 | |
| 638 | auto idx_proxy = RecentModel::instance().peopleProxy()->mapFromSource(idx); |
| 639 | |
| 640 | if (idx_proxy.isValid()) { |
| 641 | /* select the current */ |
| 642 | GtkTreeIter iter; |
| 643 | if (gtk_q_tree_model_source_index_to_iter(recent_model, idx_proxy, &iter)) { |
| 644 | gtk_tree_selection_select_iter(selection, &iter); |
| 645 | } |
| 646 | } else { |
| 647 | gtk_tree_selection_unselect_all(selection); |
| 648 | } |
| 649 | } |
| 650 | ); |
| 651 | |
Stepan Salenikovich | 0c17cb6 | 2015-11-03 13:01:50 -0500 | [diff] [blame] | 652 | /* drag and drop */ |
| 653 | static GtkTargetEntry targetentries[] = { |
| 654 | { (gchar *)CALL_TARGET, GTK_TARGET_SAME_WIDGET, CALL_TARGET_ID }, |
| 655 | }; |
| 656 | |
| 657 | gtk_tree_view_enable_model_drag_source(GTK_TREE_VIEW(self), |
| 658 | GDK_BUTTON1_MASK, targetentries, 1, (GdkDragAction)(GDK_ACTION_DEFAULT | GDK_ACTION_MOVE)); |
| 659 | |
| 660 | gtk_tree_view_enable_model_drag_dest(GTK_TREE_VIEW(self), |
| 661 | targetentries, 1, GDK_ACTION_DEFAULT); |
| 662 | |
| 663 | g_signal_connect(self, "drag-data-get", G_CALLBACK(on_drag_data_get), nullptr); |
| 664 | g_signal_connect(self, "drag-drop", G_CALLBACK(on_drag_drop), nullptr); |
| 665 | g_signal_connect(self, "drag-motion", G_CALLBACK(on_drag_motion), nullptr); |
| 666 | g_signal_connect(self, "drag_data_received", G_CALLBACK(on_drag_data_received), nullptr); |
| 667 | |
Stepan Salenikovich | 8eaa13e | 2016-08-26 16:51:48 -0400 | [diff] [blame] | 668 | /* init popup menu */ |
| 669 | priv->popup_menu = contact_popup_menu_new(GTK_TREE_VIEW(self)); |
| 670 | g_signal_connect_swapped(self, "button-press-event", G_CALLBACK(contact_popup_menu_show), priv->popup_menu); |
| 671 | |
Stepan Salenikovich | 2f8b449 | 2015-09-21 17:10:36 -0400 | [diff] [blame] | 672 | gtk_widget_show_all(GTK_WIDGET(self)); |
| 673 | } |
| 674 | |
| 675 | static void |
| 676 | recent_contacts_view_dispose(GObject *object) |
| 677 | { |
Stepan Salenikovich | e8fa681 | 2015-10-16 15:34:59 -0400 | [diff] [blame] | 678 | RecentContactsView *self = RECENT_CONTACTS_VIEW(object); |
| 679 | RecentContactsViewPrivate *priv = RECENT_CONTACTS_VIEW_GET_PRIVATE(self); |
| 680 | |
| 681 | QObject::disconnect(priv->selection_updated); |
Stepan Salenikovich | f53128f | 2016-10-07 10:32:16 -0400 | [diff] [blame] | 682 | QObject::disconnect(priv->layout_changed); |
Stepan Salenikovich | 8eaa13e | 2016-08-26 16:51:48 -0400 | [diff] [blame] | 683 | gtk_widget_destroy(priv->popup_menu); |
Stepan Salenikovich | e8fa681 | 2015-10-16 15:34:59 -0400 | [diff] [blame] | 684 | |
Stepan Salenikovich | 2f8b449 | 2015-09-21 17:10:36 -0400 | [diff] [blame] | 685 | G_OBJECT_CLASS(recent_contacts_view_parent_class)->dispose(object); |
| 686 | } |
| 687 | |
| 688 | static void |
| 689 | recent_contacts_view_finalize(GObject *object) |
| 690 | { |
| 691 | G_OBJECT_CLASS(recent_contacts_view_parent_class)->finalize(object); |
| 692 | } |
| 693 | |
| 694 | static void |
| 695 | recent_contacts_view_class_init(RecentContactsViewClass *klass) |
| 696 | { |
| 697 | G_OBJECT_CLASS(klass)->finalize = recent_contacts_view_finalize; |
| 698 | G_OBJECT_CLASS(klass)->dispose = recent_contacts_view_dispose; |
| 699 | } |
| 700 | |
| 701 | GtkWidget * |
| 702 | recent_contacts_view_new() |
| 703 | { |
| 704 | gpointer self = g_object_new(RECENT_CONTACTS_VIEW_TYPE, NULL); |
| 705 | |
| 706 | return (GtkWidget *)self; |
| 707 | } |