Stepan Salenikovich | 9816a94 | 2015-04-22 17:49:16 -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 | 9816a94 | 2015-04-22 17:49:16 -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. |
Stepan Salenikovich | 9816a94 | 2015-04-22 17:49:16 -0400 | [diff] [blame] | 18 | */ |
| 19 | |
| 20 | #include "historyview.h" |
| 21 | |
| 22 | #include <gtk/gtk.h> |
Stepan Salenikovich | a1b8cb3 | 2015-09-11 14:58:35 -0400 | [diff] [blame] | 23 | #include <glib/gi18n.h> |
Stepan Salenikovich | f607822 | 2016-10-03 17:31:16 -0400 | [diff] [blame] | 24 | #include "models/gtkqtreemodel.h" |
Stepan Salenikovich | 9816a94 | 2015-04-22 17:49:16 -0400 | [diff] [blame] | 25 | #include <categorizedhistorymodel.h> |
| 26 | #include <QtCore/QSortFilterProxyModel> |
| 27 | #include <personmodel.h> |
| 28 | #include "utils/calling.h" |
| 29 | #include <memory> |
Stepan Salenikovich | bbd6c13 | 2015-08-20 15:21:48 -0400 | [diff] [blame] | 30 | #include <globalinstances.h> |
| 31 | #include "native/pixbufmanipulator.h" |
Stepan Salenikovich | 9816a94 | 2015-04-22 17:49:16 -0400 | [diff] [blame] | 32 | #include "defines.h" |
| 33 | #include "utils/models.h" |
| 34 | #include <contactmethod.h> |
Stepan Salenikovich | 82b1acf | 2015-05-12 12:33:51 -0400 | [diff] [blame] | 35 | #include <QtCore/QDateTime> // for date time formatting |
Stepan Salenikovich | 9d29449 | 2015-05-14 16:34:24 -0400 | [diff] [blame] | 36 | #include <QtCore/QItemSelectionModel> |
Stepan Salenikovich | f2d76c5 | 2015-07-17 17:54:56 -0400 | [diff] [blame] | 37 | #include "utils/menus.h" |
Stepan Salenikovich | 8eaa13e | 2016-08-26 16:51:48 -0400 | [diff] [blame] | 38 | #include "contactpopupmenu.h" |
Stepan Salenikovich | dcfb503 | 2016-10-26 18:57:56 -0400 | [diff] [blame] | 39 | #include "models/namenumberfilterproxymodel.h" |
Julien Baron | 865676b | 2016-03-04 20:38:59 +0100 | [diff] [blame] | 40 | |
Stepan Salenikovich | 9816a94 | 2015-04-22 17:49:16 -0400 | [diff] [blame] | 41 | struct _HistoryView |
| 42 | { |
Stepan Salenikovich | 4a5dd7f | 2015-10-29 16:35:02 -0400 | [diff] [blame] | 43 | GtkTreeView parent; |
Stepan Salenikovich | 9816a94 | 2015-04-22 17:49:16 -0400 | [diff] [blame] | 44 | }; |
| 45 | |
| 46 | struct _HistoryViewClass |
| 47 | { |
Stepan Salenikovich | 4a5dd7f | 2015-10-29 16:35:02 -0400 | [diff] [blame] | 48 | GtkTreeViewClass parent_class; |
Stepan Salenikovich | 9816a94 | 2015-04-22 17:49:16 -0400 | [diff] [blame] | 49 | }; |
| 50 | |
| 51 | typedef struct _HistoryViewPrivate HistoryViewPrivate; |
| 52 | |
| 53 | struct _HistoryViewPrivate |
| 54 | { |
Stepan Salenikovich | 8eaa13e | 2016-08-26 16:51:48 -0400 | [diff] [blame] | 55 | GtkWidget *popup_menu; |
| 56 | |
Stepan Salenikovich | dcfb503 | 2016-10-26 18:57:56 -0400 | [diff] [blame] | 57 | NameNumberFilterProxy *filterproxy; |
Stepan Salenikovich | 9d29449 | 2015-05-14 16:34:24 -0400 | [diff] [blame] | 58 | QMetaObject::Connection category_changed; |
Stepan Salenikovich | 9816a94 | 2015-04-22 17:49:16 -0400 | [diff] [blame] | 59 | }; |
| 60 | |
Stepan Salenikovich | 4a5dd7f | 2015-10-29 16:35:02 -0400 | [diff] [blame] | 61 | G_DEFINE_TYPE_WITH_PRIVATE(HistoryView, history_view, GTK_TYPE_TREE_VIEW); |
Stepan Salenikovich | 9816a94 | 2015-04-22 17:49:16 -0400 | [diff] [blame] | 62 | |
| 63 | #define HISTORY_VIEW_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), HISTORY_VIEW_TYPE, HistoryViewPrivate)) |
| 64 | |
| 65 | static void |
| 66 | render_call_direction(G_GNUC_UNUSED GtkTreeViewColumn *tree_column, |
| 67 | GtkCellRenderer *cell, |
| 68 | GtkTreeModel *tree_model, |
| 69 | GtkTreeIter *iter, |
| 70 | G_GNUC_UNUSED gpointer data) |
| 71 | { |
| 72 | /* check if this is a top level item (the fuzzy date item), |
| 73 | * in this case we don't want to show a call direction */ |
| 74 | gchar *render_direction = NULL; |
| 75 | GtkTreeIter parent; |
| 76 | if (gtk_tree_model_iter_parent(tree_model, &parent, iter)) { |
| 77 | /* get direction and missed values */ |
| 78 | GValue value = G_VALUE_INIT; |
| 79 | gtk_tree_model_get_value(tree_model, iter, 3, &value); |
| 80 | Call::Direction direction = (Call::Direction)g_value_get_int(&value); |
| 81 | g_value_unset(&value); |
| 82 | |
| 83 | gtk_tree_model_get_value(tree_model, iter, 4, &value); |
| 84 | gboolean missed = g_value_get_boolean(&value); |
| 85 | g_value_unset(&value); |
| 86 | |
| 87 | switch (direction) { |
| 88 | case Call::Direction::INCOMING: |
| 89 | if (missed) |
| 90 | render_direction = g_strdup_printf("<span fgcolor=\"red\" font=\"monospace\">↙</span>"); |
| 91 | else |
| 92 | render_direction = g_strdup_printf("<span fgcolor=\"green\" font=\"monospace\">↙</span>"); |
| 93 | break; |
| 94 | case Call::Direction::OUTGOING: |
| 95 | if (missed) |
| 96 | render_direction = g_strdup_printf("<span fgcolor=\"red\" font=\"monospace\">↗</span>"); |
| 97 | else |
| 98 | render_direction = g_strdup_printf("<span fgcolor=\"green\" font=\"monospace\">↗</span>"); |
| 99 | break; |
| 100 | } |
| 101 | } |
| 102 | g_object_set(G_OBJECT(cell), "markup", render_direction, NULL); |
| 103 | g_free(render_direction); |
| 104 | } |
| 105 | |
| 106 | static void |
| 107 | activate_history_item(GtkTreeView *tree_view, |
| 108 | GtkTreePath *path, |
| 109 | G_GNUC_UNUSED GtkTreeViewColumn *column, |
| 110 | G_GNUC_UNUSED gpointer user_data) |
| 111 | { |
| 112 | GtkTreeModel *model = gtk_tree_view_get_model(tree_view); |
| 113 | |
| 114 | /* expand / collapse row */ |
| 115 | if (gtk_tree_view_row_expanded(tree_view, path)) |
| 116 | gtk_tree_view_collapse_row(tree_view, path); |
| 117 | else |
| 118 | gtk_tree_view_expand_row(tree_view, path, FALSE); |
| 119 | |
| 120 | /* get iter */ |
| 121 | GtkTreeIter iter; |
| 122 | if (gtk_tree_model_get_iter(model, &iter, path)) { |
Stepan Salenikovich | f607822 | 2016-10-03 17:31:16 -0400 | [diff] [blame] | 123 | QModelIndex idx = gtk_q_tree_model_get_source_idx(GTK_Q_TREE_MODEL(model), &iter); |
Stepan Salenikovich | 9816a94 | 2015-04-22 17:49:16 -0400 | [diff] [blame] | 124 | |
| 125 | QVariant contact_method = idx.data(static_cast<int>(Call::Role::ContactMethod)); |
| 126 | /* create new call */ |
| 127 | if (contact_method.value<ContactMethod*>()) { |
| 128 | place_new_call(contact_method.value<ContactMethod*>()); |
| 129 | } |
| 130 | } |
| 131 | } |
| 132 | |
| 133 | static void |
Stepan Salenikovich | 82b1acf | 2015-05-12 12:33:51 -0400 | [diff] [blame] | 134 | render_call_photo(G_GNUC_UNUSED GtkTreeViewColumn *tree_column, |
| 135 | GtkCellRenderer *cell, |
| 136 | GtkTreeModel *tree_model, |
| 137 | GtkTreeIter *iter, |
| 138 | G_GNUC_UNUSED gpointer data) |
| 139 | { |
| 140 | /* check if this is a top level item (category), |
| 141 | * in this case we don't want to show a photo */ |
| 142 | GtkTreePath *path = gtk_tree_model_get_path(tree_model, iter); |
| 143 | int depth = gtk_tree_path_get_depth(path); |
| 144 | gtk_tree_path_free(path); |
| 145 | if (depth == 2) { |
| 146 | /* get person */ |
Stepan Salenikovich | f607822 | 2016-10-03 17:31:16 -0400 | [diff] [blame] | 147 | QModelIndex idx = gtk_q_tree_model_get_source_idx(GTK_Q_TREE_MODEL(tree_model), iter); |
Stepan Salenikovich | 82b1acf | 2015-05-12 12:33:51 -0400 | [diff] [blame] | 148 | if (idx.isValid()) { |
| 149 | QVariant var_c = idx.data(static_cast<int>(Call::Role::Object)); |
| 150 | Call *c = var_c.value<Call *>(); |
| 151 | /* get photo */ |
Stepan Salenikovich | bbd6c13 | 2015-08-20 15:21:48 -0400 | [diff] [blame] | 152 | QVariant var_p = GlobalInstances::pixmapManipulator().callPhoto(c, QSize(50, 50), false); |
Stepan Salenikovich | 82b1acf | 2015-05-12 12:33:51 -0400 | [diff] [blame] | 153 | std::shared_ptr<GdkPixbuf> photo = var_p.value<std::shared_ptr<GdkPixbuf>>(); |
| 154 | g_object_set(G_OBJECT(cell), "pixbuf", photo.get(), NULL); |
| 155 | return; |
| 156 | } |
| 157 | } |
| 158 | |
| 159 | /* otherwise, make sure its an empty pixbuf */ |
| 160 | g_object_set(G_OBJECT(cell), "pixbuf", NULL, NULL); |
| 161 | } |
| 162 | |
| 163 | static void |
| 164 | render_name_and_contact_method(G_GNUC_UNUSED GtkTreeViewColumn *tree_column, |
| 165 | GtkCellRenderer *cell, |
| 166 | GtkTreeModel *tree_model, |
| 167 | GtkTreeIter *iter, |
Stepan Salenikovich | e4981b2 | 2015-10-22 15:22:59 -0400 | [diff] [blame] | 168 | GtkTreeView *treeview) |
Stepan Salenikovich | 82b1acf | 2015-05-12 12:33:51 -0400 | [diff] [blame] | 169 | { |
Stepan Salenikovich | e4981b2 | 2015-10-22 15:22:59 -0400 | [diff] [blame] | 170 | // check if this iter is selected |
| 171 | gboolean is_selected = FALSE; |
| 172 | if (GTK_IS_TREE_VIEW(treeview)) { |
| 173 | auto selection = gtk_tree_view_get_selection(treeview); |
| 174 | is_selected = gtk_tree_selection_iter_is_selected(selection, iter); |
| 175 | } |
| 176 | |
Stepan Salenikovich | 82b1acf | 2015-05-12 12:33:51 -0400 | [diff] [blame] | 177 | /** |
| 178 | * If call, show the name and the contact method (number) underneath; |
| 179 | * otherwise just display the category. |
| 180 | */ |
| 181 | GtkTreePath *path = gtk_tree_model_get_path(tree_model, iter); |
| 182 | int depth = gtk_tree_path_get_depth(path); |
| 183 | gtk_tree_path_free(path); |
| 184 | |
| 185 | gchar *text = NULL; |
| 186 | |
Stepan Salenikovich | f607822 | 2016-10-03 17:31:16 -0400 | [diff] [blame] | 187 | QModelIndex idx = gtk_q_tree_model_get_source_idx(GTK_Q_TREE_MODEL(tree_model), iter); |
Stepan Salenikovich | 82b1acf | 2015-05-12 12:33:51 -0400 | [diff] [blame] | 188 | if (idx.isValid()) { |
| 189 | QVariant var = idx.data(Qt::DisplayRole); |
| 190 | if (depth == 1) { |
| 191 | /* category */ |
Stepan Salenikovich | 0731de0 | 2016-05-17 17:47:16 -0400 | [diff] [blame] | 192 | text = g_markup_printf_escaped("<b>%s</b>", var.value<QString>().toUtf8().constData()); |
Stepan Salenikovich | 82b1acf | 2015-05-12 12:33:51 -0400 | [diff] [blame] | 193 | } else if (depth == 2) { |
| 194 | /* call item */ |
| 195 | QVariant var_name = idx.data(static_cast<int>(Call::Role::Name)); |
| 196 | QVariant var_number = idx.data(static_cast<int>(Call::Role::Number)); |
Stepan Salenikovich | e4981b2 | 2015-10-22 15:22:59 -0400 | [diff] [blame] | 197 | |
| 198 | /* we want the color of the status text to be the default color if this iter is |
| 199 | * selected so that the treeview is able to invert it against the selection color */ |
| 200 | if (is_selected) { |
Stepan Salenikovich | 0731de0 | 2016-05-17 17:47:16 -0400 | [diff] [blame] | 201 | text = g_markup_printf_escaped("%s\n %s", |
| 202 | var_name.value<QString>().toUtf8().constData(), |
| 203 | var_number.value<QString>().toUtf8().constData()); |
Stepan Salenikovich | e4981b2 | 2015-10-22 15:22:59 -0400 | [diff] [blame] | 204 | } else { |
Stepan Salenikovich | 0731de0 | 2016-05-17 17:47:16 -0400 | [diff] [blame] | 205 | text = g_markup_printf_escaped("%s\n <span fgcolor=\"gray\">%s</span>", |
| 206 | var_name.value<QString>().toUtf8().constData(), |
| 207 | var_number.value<QString>().toUtf8().constData()); |
Stepan Salenikovich | e4981b2 | 2015-10-22 15:22:59 -0400 | [diff] [blame] | 208 | } |
Stepan Salenikovich | 82b1acf | 2015-05-12 12:33:51 -0400 | [diff] [blame] | 209 | } |
| 210 | } |
| 211 | |
| 212 | g_object_set(G_OBJECT(cell), "markup", text, NULL); |
| 213 | g_free(text); |
| 214 | } |
| 215 | |
| 216 | static void |
Stepan Salenikovich | 501a7f8 | 2015-12-23 11:06:47 -0500 | [diff] [blame] | 217 | render_date_time(G_GNUC_UNUSED GtkTreeViewColumn *tree_column, |
| 218 | GtkCellRenderer *cell, |
| 219 | GtkTreeModel *tree_model, |
| 220 | GtkTreeIter *iter, |
| 221 | GtkTreeView *treeview) |
Stepan Salenikovich | 82b1acf | 2015-05-12 12:33:51 -0400 | [diff] [blame] | 222 | { |
Stepan Salenikovich | 501a7f8 | 2015-12-23 11:06:47 -0500 | [diff] [blame] | 223 | // check if this iter is selected |
| 224 | gboolean is_selected = FALSE; |
| 225 | if (GTK_IS_TREE_VIEW(treeview)) { |
| 226 | auto selection = gtk_tree_view_get_selection(treeview); |
| 227 | is_selected = gtk_tree_selection_iter_is_selected(selection, iter); |
Stepan Salenikovich | 82b1acf | 2015-05-12 12:33:51 -0400 | [diff] [blame] | 228 | } |
| 229 | |
Stepan Salenikovich | 82b1acf | 2015-05-12 12:33:51 -0400 | [diff] [blame] | 230 | gchar *text = NULL; |
| 231 | |
Stepan Salenikovich | f607822 | 2016-10-03 17:31:16 -0400 | [diff] [blame] | 232 | QModelIndex idx = gtk_q_tree_model_get_source_idx(GTK_Q_TREE_MODEL(tree_model), iter); |
Stepan Salenikovich | 501a7f8 | 2015-12-23 11:06:47 -0500 | [diff] [blame] | 233 | QVariant var_d = idx.data(static_cast<int>(Call::Role::DateTime)); |
| 234 | if (idx.isValid() && var_d.isValid()) { |
Stepan Salenikovich | 803562b | 2015-12-23 10:51:01 -0500 | [diff] [blame] | 235 | QDateTime date_time = var_d.value<QDateTime>(); |
Stepan Salenikovich | 501a7f8 | 2015-12-23 11:06:47 -0500 | [diff] [blame] | 236 | |
| 237 | /* we want the color of the text to be the default color if this iter is |
| 238 | * selected so that the treeview is able to invert it against the selection color */ |
| 239 | if (is_selected) { |
Stepan Salenikovich | 0731de0 | 2016-05-17 17:47:16 -0400 | [diff] [blame] | 240 | text = g_markup_printf_escaped("%s\n%s", |
| 241 | date_time.time().toString().toUtf8().constData(), |
| 242 | date_time.date().toString().toUtf8().constData() |
Stepan Salenikovich | 501a7f8 | 2015-12-23 11:06:47 -0500 | [diff] [blame] | 243 | ); |
| 244 | } else { |
Stepan Salenikovich | 0731de0 | 2016-05-17 17:47:16 -0400 | [diff] [blame] | 245 | text = g_markup_printf_escaped("%s\n<span fgcolor=\"gray\">%s</span>", |
| 246 | date_time.time().toString().toUtf8().constData(), |
| 247 | date_time.date().toString().toUtf8().constData() |
Stepan Salenikovich | 501a7f8 | 2015-12-23 11:06:47 -0500 | [diff] [blame] | 248 | ); |
| 249 | } |
Stepan Salenikovich | 82b1acf | 2015-05-12 12:33:51 -0400 | [diff] [blame] | 250 | } |
| 251 | |
| 252 | g_object_set(G_OBJECT(cell), "markup", text, NULL); |
| 253 | g_free(text); |
| 254 | } |
| 255 | |
| 256 | static void |
Stepan Salenikovich | 9816a94 | 2015-04-22 17:49:16 -0400 | [diff] [blame] | 257 | history_view_init(HistoryView *self) |
| 258 | { |
| 259 | HistoryViewPrivate *priv = HISTORY_VIEW_GET_PRIVATE(self); |
| 260 | |
Stepan Salenikovich | 9816a94 | 2015-04-22 17:49:16 -0400 | [diff] [blame] | 261 | /* make headers visible to allow column resizing */ |
Stepan Salenikovich | 4a5dd7f | 2015-10-29 16:35:02 -0400 | [diff] [blame] | 262 | gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(self), TRUE); |
| 263 | /* disable default search, we will handle it ourselves; |
Stepan Salenikovich | b01d736 | 2015-04-27 23:02:00 -0400 | [diff] [blame] | 264 | * otherwise the search steals input focus on key presses */ |
Stepan Salenikovich | 4a5dd7f | 2015-10-29 16:35:02 -0400 | [diff] [blame] | 265 | gtk_tree_view_set_enable_search(GTK_TREE_VIEW(self), FALSE); |
Stepan Salenikovich | b01d736 | 2015-04-27 23:02:00 -0400 | [diff] [blame] | 266 | |
Stepan Salenikovich | 9d29449 | 2015-05-14 16:34:24 -0400 | [diff] [blame] | 267 | /* instantiate history proxy model */ |
Stepan Salenikovich | dcfb503 | 2016-10-26 18:57:56 -0400 | [diff] [blame] | 268 | auto q_sorted_proxy = &CategorizedHistoryModel::SortedProxy::instance(); |
Stepan Salenikovich | 9d29449 | 2015-05-14 16:34:24 -0400 | [diff] [blame] | 269 | |
Stepan Salenikovich | 9d29449 | 2015-05-14 16:34:24 -0400 | [diff] [blame] | 270 | /* select default category (the first one, which is by date) */ |
Stepan Salenikovich | dcfb503 | 2016-10-26 18:57:56 -0400 | [diff] [blame] | 271 | q_sorted_proxy->categorySelectionModel()->setCurrentIndex( |
| 272 | q_sorted_proxy->categoryModel()->index(0, 0), |
Stepan Salenikovich | 9d29449 | 2015-05-14 16:34:24 -0400 | [diff] [blame] | 273 | QItemSelectionModel::ClearAndSelect); |
Stepan Salenikovich | 803562b | 2015-12-23 10:51:01 -0500 | [diff] [blame] | 274 | /* make sure it is sorted so that newest calls are at the top */ |
Stepan Salenikovich | dcfb503 | 2016-10-26 18:57:56 -0400 | [diff] [blame] | 275 | q_sorted_proxy->model()->sort(0, Qt::AscendingOrder); |
| 276 | |
| 277 | /* filter for name and number */ |
| 278 | priv->filterproxy = new NameNumberFilterProxy(q_sorted_proxy->model()); |
Stepan Salenikovich | 9816a94 | 2015-04-22 17:49:16 -0400 | [diff] [blame] | 279 | |
Stepan Salenikovich | f607822 | 2016-10-03 17:31:16 -0400 | [diff] [blame] | 280 | GtkQTreeModel *history_model = gtk_q_tree_model_new( |
Stepan Salenikovich | dcfb503 | 2016-10-26 18:57:56 -0400 | [diff] [blame] | 281 | priv->filterproxy, |
Stepan Salenikovich | 9816a94 | 2015-04-22 17:49:16 -0400 | [diff] [blame] | 282 | 5, |
aviau | 271bcc2 | 2016-05-27 17:25:19 -0400 | [diff] [blame] | 283 | 0, Qt::DisplayRole, G_TYPE_STRING, |
| 284 | 0, Call::Role::Number, G_TYPE_STRING, |
| 285 | 0, Call::Role::FormattedDate, G_TYPE_STRING, |
| 286 | 0, Call::Role::Direction, G_TYPE_INT, |
| 287 | 0, Call::Role::Missed, G_TYPE_BOOLEAN); |
Stepan Salenikovich | 4a5dd7f | 2015-10-29 16:35:02 -0400 | [diff] [blame] | 288 | gtk_tree_view_set_model( GTK_TREE_VIEW(self), GTK_TREE_MODEL(history_model) ); |
Stepan Salenikovich | 9816a94 | 2015-04-22 17:49:16 -0400 | [diff] [blame] | 289 | |
Stepan Salenikovich | 82b1acf | 2015-05-12 12:33:51 -0400 | [diff] [blame] | 290 | /* call direction, photo, name/number column */ |
| 291 | GtkCellArea *area = gtk_cell_area_box_new(); |
| 292 | GtkTreeViewColumn *column = gtk_tree_view_column_new_with_area(area); |
Stepan Salenikovich | a1b8cb3 | 2015-09-11 14:58:35 -0400 | [diff] [blame] | 293 | gtk_tree_view_column_set_title(column, C_("Call history", "Call")); |
Stepan Salenikovich | 9816a94 | 2015-04-22 17:49:16 -0400 | [diff] [blame] | 294 | |
| 295 | /* call direction */ |
| 296 | GtkCellRenderer *renderer = gtk_cell_renderer_text_new(); |
Stepan Salenikovich | 82b1acf | 2015-05-12 12:33:51 -0400 | [diff] [blame] | 297 | gtk_cell_area_box_pack_start(GTK_CELL_AREA_BOX(area), renderer, FALSE, FALSE, FALSE); |
Stepan Salenikovich | 9816a94 | 2015-04-22 17:49:16 -0400 | [diff] [blame] | 298 | |
| 299 | /* display the call direction with arrows */ |
| 300 | gtk_tree_view_column_set_cell_data_func( |
| 301 | column, |
| 302 | renderer, |
| 303 | (GtkTreeCellDataFunc)render_call_direction, |
| 304 | NULL, |
| 305 | NULL); |
| 306 | |
Stepan Salenikovich | 82b1acf | 2015-05-12 12:33:51 -0400 | [diff] [blame] | 307 | /* photo renderer */ |
| 308 | renderer = gtk_cell_renderer_pixbuf_new(); |
| 309 | gtk_cell_area_box_pack_start(GTK_CELL_AREA_BOX(area), renderer, FALSE, FALSE, FALSE); |
Stepan Salenikovich | 9816a94 | 2015-04-22 17:49:16 -0400 | [diff] [blame] | 310 | |
Stepan Salenikovich | 82b1acf | 2015-05-12 12:33:51 -0400 | [diff] [blame] | 311 | /* get the photo */ |
| 312 | gtk_tree_view_column_set_cell_data_func( |
| 313 | column, |
| 314 | renderer, |
| 315 | (GtkTreeCellDataFunc)render_call_photo, |
| 316 | NULL, |
| 317 | NULL); |
| 318 | |
| 319 | /* name and contact method renderer */ |
Stepan Salenikovich | 9816a94 | 2015-04-22 17:49:16 -0400 | [diff] [blame] | 320 | renderer = gtk_cell_renderer_text_new(); |
| 321 | g_object_set(G_OBJECT(renderer), "ellipsize", PANGO_ELLIPSIZE_END, NULL); |
Stepan Salenikovich | 82b1acf | 2015-05-12 12:33:51 -0400 | [diff] [blame] | 322 | gtk_cell_area_box_pack_start(GTK_CELL_AREA_BOX(area), renderer, FALSE, FALSE, FALSE); |
| 323 | |
| 324 | gtk_tree_view_column_set_cell_data_func( |
| 325 | column, |
| 326 | renderer, |
| 327 | (GtkTreeCellDataFunc)render_name_and_contact_method, |
Stepan Salenikovich | 4a5dd7f | 2015-10-29 16:35:02 -0400 | [diff] [blame] | 328 | self, |
Stepan Salenikovich | 82b1acf | 2015-05-12 12:33:51 -0400 | [diff] [blame] | 329 | NULL); |
| 330 | |
Stepan Salenikovich | 4a5dd7f | 2015-10-29 16:35:02 -0400 | [diff] [blame] | 331 | gtk_tree_view_append_column(GTK_TREE_VIEW(self), column); |
Stepan Salenikovich | 9816a94 | 2015-04-22 17:49:16 -0400 | [diff] [blame] | 332 | gtk_tree_view_column_set_resizable(column, TRUE); |
Stepan Salenikovich | e7c4e28 | 2015-06-11 17:22:08 -0400 | [diff] [blame] | 333 | gtk_tree_view_column_set_expand(column, TRUE); |
Stepan Salenikovich | 9816a94 | 2015-04-22 17:49:16 -0400 | [diff] [blame] | 334 | |
Stepan Salenikovich | 501a7f8 | 2015-12-23 11:06:47 -0500 | [diff] [blame] | 335 | /* date time column */ |
Stepan Salenikovich | 82b1acf | 2015-05-12 12:33:51 -0400 | [diff] [blame] | 336 | area = gtk_cell_area_box_new(); |
| 337 | column = gtk_tree_view_column_new_with_area(area); |
Stepan Salenikovich | a1b8cb3 | 2015-09-11 14:58:35 -0400 | [diff] [blame] | 338 | gtk_tree_view_column_set_title(column, C_("Call history", "Date")); |
Stepan Salenikovich | 82b1acf | 2015-05-12 12:33:51 -0400 | [diff] [blame] | 339 | |
Stepan Salenikovich | 501a7f8 | 2015-12-23 11:06:47 -0500 | [diff] [blame] | 340 | /* date time renderer */ |
Stepan Salenikovich | 9816a94 | 2015-04-22 17:49:16 -0400 | [diff] [blame] | 341 | renderer = gtk_cell_renderer_text_new (); |
Stepan Salenikovich | 82b1acf | 2015-05-12 12:33:51 -0400 | [diff] [blame] | 342 | gtk_cell_area_box_pack_start(GTK_CELL_AREA_BOX(area), renderer, FALSE, FALSE, FALSE); |
| 343 | /* format the time*/ |
| 344 | gtk_tree_view_column_set_cell_data_func( |
| 345 | column, |
| 346 | renderer, |
Stepan Salenikovich | 501a7f8 | 2015-12-23 11:06:47 -0500 | [diff] [blame] | 347 | (GtkTreeCellDataFunc)render_date_time, |
| 348 | self, |
Stepan Salenikovich | 82b1acf | 2015-05-12 12:33:51 -0400 | [diff] [blame] | 349 | NULL); |
| 350 | |
Stepan Salenikovich | 4a5dd7f | 2015-10-29 16:35:02 -0400 | [diff] [blame] | 351 | gtk_tree_view_append_column(GTK_TREE_VIEW(self), column); |
Stepan Salenikovich | 9816a94 | 2015-04-22 17:49:16 -0400 | [diff] [blame] | 352 | gtk_tree_view_column_set_resizable(column, TRUE); |
Stepan Salenikovich | e7c4e28 | 2015-06-11 17:22:08 -0400 | [diff] [blame] | 353 | gtk_tree_view_column_set_expand(column, FALSE); |
Stepan Salenikovich | 9816a94 | 2015-04-22 17:49:16 -0400 | [diff] [blame] | 354 | |
Stepan Salenikovich | 4a5dd7f | 2015-10-29 16:35:02 -0400 | [diff] [blame] | 355 | g_signal_connect(self, "row-activated", G_CALLBACK(activate_history_item), NULL); |
Stepan Salenikovich | 8eaa13e | 2016-08-26 16:51:48 -0400 | [diff] [blame] | 356 | |
| 357 | /* init popup menu */ |
| 358 | priv->popup_menu = contact_popup_menu_new(GTK_TREE_VIEW(self)); |
| 359 | g_signal_connect_swapped(self, "button-press-event", G_CALLBACK(contact_popup_menu_show), priv->popup_menu); |
Stepan Salenikovich | 9816a94 | 2015-04-22 17:49:16 -0400 | [diff] [blame] | 360 | |
| 361 | gtk_widget_show_all(GTK_WIDGET(self)); |
| 362 | } |
| 363 | |
| 364 | static void |
| 365 | history_view_dispose(GObject *object) |
| 366 | { |
Stepan Salenikovich | 9d29449 | 2015-05-14 16:34:24 -0400 | [diff] [blame] | 367 | HistoryViewPrivate *priv = HISTORY_VIEW_GET_PRIVATE(object); |
| 368 | |
| 369 | QObject::disconnect(priv->category_changed); |
Stepan Salenikovich | 8eaa13e | 2016-08-26 16:51:48 -0400 | [diff] [blame] | 370 | gtk_widget_destroy(priv->popup_menu); |
Stepan Salenikovich | 9d29449 | 2015-05-14 16:34:24 -0400 | [diff] [blame] | 371 | |
Stepan Salenikovich | 9816a94 | 2015-04-22 17:49:16 -0400 | [diff] [blame] | 372 | G_OBJECT_CLASS(history_view_parent_class)->dispose(object); |
| 373 | } |
| 374 | |
| 375 | static void |
| 376 | history_view_finalize(GObject *object) |
| 377 | { |
Stepan Salenikovich | 9816a94 | 2015-04-22 17:49:16 -0400 | [diff] [blame] | 378 | G_OBJECT_CLASS(history_view_parent_class)->finalize(object); |
| 379 | } |
| 380 | |
| 381 | static void |
| 382 | history_view_class_init(HistoryViewClass *klass) |
| 383 | { |
| 384 | G_OBJECT_CLASS(klass)->finalize = history_view_finalize; |
| 385 | G_OBJECT_CLASS(klass)->dispose = history_view_dispose; |
| 386 | } |
| 387 | |
| 388 | GtkWidget * |
| 389 | history_view_new() |
| 390 | { |
| 391 | gpointer self = g_object_new(HISTORY_VIEW_TYPE, NULL); |
| 392 | |
| 393 | return (GtkWidget *)self; |
Stepan Salenikovich | 9d29449 | 2015-05-14 16:34:24 -0400 | [diff] [blame] | 394 | } |
Stepan Salenikovich | dcfb503 | 2016-10-26 18:57:56 -0400 | [diff] [blame] | 395 | |
| 396 | void |
| 397 | history_view_set_filter_string(HistoryView *self, const char *text) |
| 398 | { |
| 399 | auto priv = HISTORY_VIEW_GET_PRIVATE(self); |
| 400 | |
| 401 | priv->filterproxy->setFilterRegExp(QRegExp(text, Qt::CaseInsensitive, QRegExp::FixedString)); |
| 402 | |
| 403 | // if filtering, expand all categories so we can see the calls |
| 404 | // otherwise collapse all |
| 405 | if (text && strlen(text) > 0) |
| 406 | gtk_tree_view_expand_all(GTK_TREE_VIEW(self)); |
| 407 | else |
| 408 | gtk_tree_view_collapse_all(GTK_TREE_VIEW(self)); |
| 409 | } |