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