blob: b107e0229e6860e9440a59a43601befe8f88b48b [file] [log] [blame]
Stepan Salenikovich9816a942015-04-22 17:49:16 -04001/*
Stepan Salenikovichbbd6c132015-08-20 15:21:48 -04002 * Copyright (C) 2015 Savoir-faire Linux Inc.
Stepan Salenikovich9816a942015-04-22 17:49:16 -04003 * Author: Stepan Salenikovich <stepan.salenikovich@savoirfairelinux.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Additional permission under GNU GPL version 3 section 7:
20 *
21 * If you modify this program, or any covered work, by linking or
22 * combining it with the OpenSSL project's OpenSSL library (or a
23 * modified version of that library), containing parts covered by the
Stepan Salenikovichbbd6c132015-08-20 15:21:48 -040024 * terms of the OpenSSL or SSLeay licenses, Savoir-faire Linux Inc.
Stepan Salenikovich9816a942015-04-22 17:49:16 -040025 * grants you additional permission to convey the resulting work.
26 * Corresponding Source for a non-source form of such a combination
27 * shall include the source code for the parts of OpenSSL used as well
28 * as that of the covered work.
29 */
30
31#include "historyview.h"
32
33#include <gtk/gtk.h>
Stepan Salenikovicha1b8cb32015-09-11 14:58:35 -040034#include <glib/gi18n.h>
Stepan Salenikovich9816a942015-04-22 17:49:16 -040035#include "models/gtkqsortfiltertreemodel.h"
36#include <categorizedhistorymodel.h>
37#include <QtCore/QSortFilterProxyModel>
38#include <personmodel.h>
39#include "utils/calling.h"
40#include <memory>
Stepan Salenikovichbbd6c132015-08-20 15:21:48 -040041#include <globalinstances.h>
42#include "native/pixbufmanipulator.h"
Stepan Salenikovich9816a942015-04-22 17:49:16 -040043#include "defines.h"
44#include "utils/models.h"
45#include <contactmethod.h>
Stepan Salenikovich82b1acf2015-05-12 12:33:51 -040046#include <QtCore/QDateTime> // for date time formatting
Stepan Salenikovich9d294492015-05-14 16:34:24 -040047#include <QtCore/QItemSelectionModel>
Stepan Salenikovichf2d76c52015-07-17 17:54:56 -040048#include "utils/menus.h"
Stepan Salenikovich9816a942015-04-22 17:49:16 -040049
50struct _HistoryView
51{
Stepan Salenikovich7c71bfe2015-05-13 18:08:09 -040052 GtkBox parent;
Stepan Salenikovich9816a942015-04-22 17:49:16 -040053};
54
55struct _HistoryViewClass
56{
Stepan Salenikovich7c71bfe2015-05-13 18:08:09 -040057 GtkBoxClass parent_class;
Stepan Salenikovich9816a942015-04-22 17:49:16 -040058};
59
60typedef struct _HistoryViewPrivate HistoryViewPrivate;
61
62struct _HistoryViewPrivate
63{
Stepan Salenikovich9d294492015-05-14 16:34:24 -040064 CategorizedHistoryModel::SortedProxy *q_sorted_proxy;
65 QMetaObject::Connection category_changed;
Stepan Salenikovich9816a942015-04-22 17:49:16 -040066};
67
Stepan Salenikovich7c71bfe2015-05-13 18:08:09 -040068G_DEFINE_TYPE_WITH_PRIVATE(HistoryView, history_view, GTK_TYPE_BOX);
Stepan Salenikovich9816a942015-04-22 17:49:16 -040069
70#define HISTORY_VIEW_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), HISTORY_VIEW_TYPE, HistoryViewPrivate))
71
72static void
73render_call_direction(G_GNUC_UNUSED GtkTreeViewColumn *tree_column,
74 GtkCellRenderer *cell,
75 GtkTreeModel *tree_model,
76 GtkTreeIter *iter,
77 G_GNUC_UNUSED gpointer data)
78{
79 /* check if this is a top level item (the fuzzy date item),
80 * in this case we don't want to show a call direction */
81 gchar *render_direction = NULL;
82 GtkTreeIter parent;
83 if (gtk_tree_model_iter_parent(tree_model, &parent, iter)) {
84 /* get direction and missed values */
85 GValue value = G_VALUE_INIT;
86 gtk_tree_model_get_value(tree_model, iter, 3, &value);
87 Call::Direction direction = (Call::Direction)g_value_get_int(&value);
88 g_value_unset(&value);
89
90 gtk_tree_model_get_value(tree_model, iter, 4, &value);
91 gboolean missed = g_value_get_boolean(&value);
92 g_value_unset(&value);
93
94 switch (direction) {
95 case Call::Direction::INCOMING:
96 if (missed)
97 render_direction = g_strdup_printf("<span fgcolor=\"red\" font=\"monospace\">&#8601;</span>");
98 else
99 render_direction = g_strdup_printf("<span fgcolor=\"green\" font=\"monospace\">&#8601;</span>");
100 break;
101 case Call::Direction::OUTGOING:
102 if (missed)
103 render_direction = g_strdup_printf("<span fgcolor=\"red\" font=\"monospace\">&#8599;</span>");
104 else
105 render_direction = g_strdup_printf("<span fgcolor=\"green\" font=\"monospace\">&#8599;</span>");
106 break;
107 }
108 }
109 g_object_set(G_OBJECT(cell), "markup", render_direction, NULL);
110 g_free(render_direction);
111}
112
113static void
114activate_history_item(GtkTreeView *tree_view,
115 GtkTreePath *path,
116 G_GNUC_UNUSED GtkTreeViewColumn *column,
117 G_GNUC_UNUSED gpointer user_data)
118{
119 GtkTreeModel *model = gtk_tree_view_get_model(tree_view);
120
121 /* expand / collapse row */
122 if (gtk_tree_view_row_expanded(tree_view, path))
123 gtk_tree_view_collapse_row(tree_view, path);
124 else
125 gtk_tree_view_expand_row(tree_view, path, FALSE);
126
127 /* get iter */
128 GtkTreeIter iter;
129 if (gtk_tree_model_get_iter(model, &iter, path)) {
130 QModelIndex idx = gtk_q_sort_filter_tree_model_get_source_idx(GTK_Q_SORT_FILTER_TREE_MODEL(model), &iter);
131
132 QVariant contact_method = idx.data(static_cast<int>(Call::Role::ContactMethod));
133 /* create new call */
134 if (contact_method.value<ContactMethod*>()) {
135 place_new_call(contact_method.value<ContactMethod*>());
136 }
137 }
138}
139
140static void
141copy_history_item(G_GNUC_UNUSED GtkWidget *item, GtkTreeView *treeview)
142{
143 GtkTreeSelection *selection = gtk_tree_view_get_selection(treeview);
144 QModelIndex idx = get_index_from_selection(selection);
145
146 if (idx.isValid()) {
147 GtkClipboard* clip = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD);
148
149 const gchar* number = idx.data(static_cast<int>(Call::Role::Number)).toString().toUtf8().constData();
150 gtk_clipboard_set_text(clip, number, -1);
151 }
152}
153
154/* TODO: can't seem to delete just one item for now, add when supported in backend
155 * static void
156 * delete_history_item(G_GNUC_UNUSED GtkWidget *item, GtkTreeView *treeview)
157 * {
158 * GtkTreeSelection *selection = gtk_tree_view_get_selection(treeview);
159 * QModelIndex idx = get_index_from_selection(selection);
160 *
161 * if (idx.isValid()) {
162 * g_debug("deleting history item");
163 * CategorizedHistoryModel::instance()->removeRow(idx.row(), idx.parent());
164 * }
165 * }
166 */
167
168static gboolean
169history_popup_menu(G_GNUC_UNUSED GtkWidget *widget, GdkEventButton *event, GtkTreeView *treeview)
170{
171 /* build popup menu when right clicking on history item
172 * user should be able to copy the "number",
173 * delete history item or all of the history,
174 * and eventualy add the number to a contact
175 */
176
177 /* check for right click */
178 if (event->button != BUTTON_RIGHT_CLICK || event->type != GDK_BUTTON_PRESS)
179 return FALSE;
180
181 GtkWidget *menu = gtk_menu_new();
182
183 /* copy */
Stepan Salenikovicha1b8cb32015-09-11 14:58:35 -0400184 GtkWidget *item = gtk_menu_item_new_with_mnemonic(_("_Copy"));
Stepan Salenikovich9816a942015-04-22 17:49:16 -0400185 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
186 g_signal_connect(item, "activate", G_CALLBACK(copy_history_item), treeview);
187
188 /* TODO: delete history entry
189 * gtk_menu_shell_append(GTK_MENU_SHELL(menu), gtk_separator_menu_item_new());
190 * item = gtk_menu_item_new_with_mnemonic("_Delete entry");
191 * gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
192 * g_signal_connect(item, "activate", G_CALLBACK(delete_history_item), treeview);
193 */
194
Stepan Salenikovichf2d76c52015-07-17 17:54:56 -0400195 /* check if the selected item is a call, if so get the contact method and
196 * check if it is already linked to a person, if not, then offer to either
197 * add to a new or existing contact */
198 auto selection = gtk_tree_view_get_selection(treeview);
199 const auto& idx = get_index_from_selection(selection);
200 const auto& var_c = idx.data(static_cast<int>(Call::Role::Object));
201 if (idx.isValid() && var_c.isValid()) {
202 if (auto call = var_c.value<Call *>()) {
203 auto contactmethod = call->peerContactMethod();
204 if (!contact_method_has_contact(contactmethod)) {
Stepan Salenikovich0cf247d2015-07-24 17:36:32 -0400205 GtkTreeIter iter;
206 GtkTreeModel *model;
207 gtk_tree_selection_get_selected(selection, &model, &iter);
208 auto path = gtk_tree_model_get_path(model, &iter);
209 auto column = gtk_tree_view_get_column(treeview, 0);
210 GdkRectangle rect;
211 gtk_tree_view_get_cell_area(treeview, path, column, &rect);
212 gtk_tree_view_convert_bin_window_to_widget_coords(treeview, rect.x, rect.y, &rect.x, &rect.y);
213 gtk_tree_path_free(path);
214 auto add_to = menu_item_add_to_contact(contactmethod, GTK_WIDGET(treeview), &rect);
Stepan Salenikovichf2d76c52015-07-17 17:54:56 -0400215 gtk_menu_shell_append(GTK_MENU_SHELL(menu), add_to);
216 }
217 }
218 }
219
Stepan Salenikovich9816a942015-04-22 17:49:16 -0400220 /* show menu */
221 gtk_widget_show_all(menu);
222 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, event->button, event->time);
223
Stepan Salenikovichf2d76c52015-07-17 17:54:56 -0400224 return TRUE;
Stepan Salenikovich9816a942015-04-22 17:49:16 -0400225}
226
227static void
Stepan Salenikovich82b1acf2015-05-12 12:33:51 -0400228render_call_photo(G_GNUC_UNUSED GtkTreeViewColumn *tree_column,
229 GtkCellRenderer *cell,
230 GtkTreeModel *tree_model,
231 GtkTreeIter *iter,
232 G_GNUC_UNUSED gpointer data)
233{
234 /* check if this is a top level item (category),
235 * in this case we don't want to show a photo */
236 GtkTreePath *path = gtk_tree_model_get_path(tree_model, iter);
237 int depth = gtk_tree_path_get_depth(path);
238 gtk_tree_path_free(path);
239 if (depth == 2) {
240 /* get person */
241 QModelIndex idx = gtk_q_sort_filter_tree_model_get_source_idx(GTK_Q_SORT_FILTER_TREE_MODEL(tree_model), iter);
242 if (idx.isValid()) {
243 QVariant var_c = idx.data(static_cast<int>(Call::Role::Object));
244 Call *c = var_c.value<Call *>();
245 /* get photo */
Stepan Salenikovichbbd6c132015-08-20 15:21:48 -0400246 QVariant var_p = GlobalInstances::pixmapManipulator().callPhoto(c, QSize(50, 50), false);
Stepan Salenikovich82b1acf2015-05-12 12:33:51 -0400247 std::shared_ptr<GdkPixbuf> photo = var_p.value<std::shared_ptr<GdkPixbuf>>();
248 g_object_set(G_OBJECT(cell), "pixbuf", photo.get(), NULL);
249 return;
250 }
251 }
252
253 /* otherwise, make sure its an empty pixbuf */
254 g_object_set(G_OBJECT(cell), "pixbuf", NULL, NULL);
255}
256
257static void
258render_name_and_contact_method(G_GNUC_UNUSED GtkTreeViewColumn *tree_column,
259 GtkCellRenderer *cell,
260 GtkTreeModel *tree_model,
261 GtkTreeIter *iter,
262 G_GNUC_UNUSED gpointer data)
263{
264 /**
265 * If call, show the name and the contact method (number) underneath;
266 * otherwise just display the category.
267 */
268 GtkTreePath *path = gtk_tree_model_get_path(tree_model, iter);
269 int depth = gtk_tree_path_get_depth(path);
270 gtk_tree_path_free(path);
271
272 gchar *text = NULL;
273
274 QModelIndex idx = gtk_q_sort_filter_tree_model_get_source_idx(GTK_Q_SORT_FILTER_TREE_MODEL(tree_model), iter);
275 if (idx.isValid()) {
276 QVariant var = idx.data(Qt::DisplayRole);
277 if (depth == 1) {
278 /* category */
279 text = g_strdup_printf("<b>%s</b>", var.value<QString>().toUtf8().constData());
280 } else if (depth == 2) {
281 /* call item */
282 QVariant var_name = idx.data(static_cast<int>(Call::Role::Name));
283 QVariant var_number = idx.data(static_cast<int>(Call::Role::Number));
284 text = g_strdup_printf("%s\n <span fgcolor=\"gray\">%s</span>",
285 var_name.value<QString>().toUtf8().constData(),
286 var_number.value<QString>().toUtf8().constData());
287 }
288 }
289
290 g_object_set(G_OBJECT(cell), "markup", text, NULL);
291 g_free(text);
292}
293
294static void
295render_time(G_GNUC_UNUSED GtkTreeViewColumn *tree_column,
296 GtkCellRenderer *cell,
297 GtkTreeModel *tree_model,
298 GtkTreeIter *iter,
299 G_GNUC_UNUSED gpointer data)
300{
301 /**
302 * If call, show the the time;
303 * if category, don't show anything.
304 */
305 GtkTreePath *path = gtk_tree_model_get_path(tree_model, iter);
306 int depth = gtk_tree_path_get_depth(path);
307 gtk_tree_path_free(path);
308
309 gchar *text = NULL;
310
311 QModelIndex idx = gtk_q_sort_filter_tree_model_get_source_idx(GTK_Q_SORT_FILTER_TREE_MODEL(tree_model), iter);
312 if (idx.isValid() && depth == 2) {
313 QVariant var_d = idx.data(static_cast<int>(Call::Role::Date));
314 time_t time = var_d.value<time_t>();
315 QDateTime date_time = QDateTime::fromTime_t(time);
316 text = g_strdup_printf("%s", date_time.time().toString().toUtf8().constData());
317 }
318
319 g_object_set(G_OBJECT(cell), "markup", text, NULL);
320 g_free(text);
321}
322
323static void
324render_date(G_GNUC_UNUSED GtkTreeViewColumn *tree_column,
325 GtkCellRenderer *cell,
326 GtkTreeModel *tree_model,
327 GtkTreeIter *iter,
328 G_GNUC_UNUSED gpointer data)
329{
330 /**
331 * If call, show the date;
332 * if category, don't show anything.
333 */
334 GtkTreePath *path = gtk_tree_model_get_path(tree_model, iter);
335 int depth = gtk_tree_path_get_depth(path);
336 gtk_tree_path_free(path);
337
338 gchar *text = NULL;
339
340 QModelIndex idx = gtk_q_sort_filter_tree_model_get_source_idx(GTK_Q_SORT_FILTER_TREE_MODEL(tree_model), iter);
341 if (idx.isValid() && depth == 2) {
342 QVariant var_d = idx.data(static_cast<int>(Call::Role::Date));
343 time_t time = var_d.value<time_t>();
344 QDateTime date_time = QDateTime::fromTime_t(time);
345 text = g_strdup_printf("%s", date_time.date().toString().toUtf8().constData());
346 }
347
348 g_object_set(G_OBJECT(cell), "markup", text, NULL);
349 g_free(text);
350}
351
352static void
Stepan Salenikovich9816a942015-04-22 17:49:16 -0400353history_view_init(HistoryView *self)
354{
355 HistoryViewPrivate *priv = HISTORY_VIEW_GET_PRIVATE(self);
356
Stepan Salenikovich7c71bfe2015-05-13 18:08:09 -0400357 gtk_orientable_set_orientation(GTK_ORIENTABLE(self), GTK_ORIENTATION_VERTICAL);
358 /* need to be able to focus on widget so that we can auto-scroll to it */
359 gtk_widget_set_can_focus(GTK_WIDGET(self), TRUE);
Stepan Salenikovich7be4f622015-05-13 15:36:19 -0400360
Stepan Salenikovicha1b8cb32015-09-11 14:58:35 -0400361 GtkWidget *label_history = gtk_label_new(C_("Call history", "History"));
Stepan Salenikovich7c71bfe2015-05-13 18:08:09 -0400362 gtk_box_pack_start(GTK_BOX(self), label_history, FALSE, TRUE, 10);
363
Stepan Salenikovich9816a942015-04-22 17:49:16 -0400364 GtkWidget *treeview_history = gtk_tree_view_new();
Stepan Salenikovich7c71bfe2015-05-13 18:08:09 -0400365 /* set can-focus to false so that the scrollwindow doesn't jump to try to
366 * contain the top of the treeview */
367 gtk_widget_set_can_focus(treeview_history, FALSE);
Stepan Salenikovich9816a942015-04-22 17:49:16 -0400368 /* make headers visible to allow column resizing */
369 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(treeview_history), TRUE);
Stepan Salenikovich7c71bfe2015-05-13 18:08:09 -0400370 gtk_box_pack_start(GTK_BOX(self), treeview_history, TRUE, TRUE, 0);
Stepan Salenikovich9816a942015-04-22 17:49:16 -0400371
Stepan Salenikovichb01d7362015-04-27 23:02:00 -0400372 /* disable default search, we will handle it ourselves via LRC;
373 * otherwise the search steals input focus on key presses */
374 gtk_tree_view_set_enable_search(GTK_TREE_VIEW(treeview_history), FALSE);
375
Stepan Salenikovich9d294492015-05-14 16:34:24 -0400376 /* instantiate history proxy model */
377 priv->q_sorted_proxy = CategorizedHistoryModel::SortedProxy::instance();
378
379 /* for now there is no way in the UI to pick whether sorting is ascending
380 * or descending, so we do it in the code when the category changes */
381 priv->category_changed = QObject::connect(
382 priv->q_sorted_proxy->categorySelectionModel(),
383 &QItemSelectionModel::currentChanged,
384 [=] (const QModelIndex &current, G_GNUC_UNUSED const QModelIndex &previous)
385 {
386 if (current.isValid()) {
387 if (current.row() == 0) {
388 /* sort in descending order for the date */
389 priv->q_sorted_proxy->model()->sort(0, Qt::DescendingOrder);
390 } else {
391 /* ascending order for verything else */
392 priv->q_sorted_proxy->model()->sort(0);
393 }
394 }
395 }
396 );
397
398 /* select default category (the first one, which is by date) */
399 priv->q_sorted_proxy->categorySelectionModel()->setCurrentIndex(
400 priv->q_sorted_proxy->categoryModel()->index(0, 0),
401 QItemSelectionModel::ClearAndSelect);
Stepan Salenikovich9816a942015-04-22 17:49:16 -0400402
403 GtkQSortFilterTreeModel *history_model = gtk_q_sort_filter_tree_model_new(
Stepan Salenikovich9d294492015-05-14 16:34:24 -0400404 priv->q_sorted_proxy->model(),
Stepan Salenikovich9816a942015-04-22 17:49:16 -0400405 5,
406 Qt::DisplayRole, G_TYPE_STRING,
407 Call::Role::Number, G_TYPE_STRING,
408 Call::Role::FormattedDate, G_TYPE_STRING,
409 Call::Role::Direction, G_TYPE_INT,
410 Call::Role::Missed, G_TYPE_BOOLEAN);
411 gtk_tree_view_set_model( GTK_TREE_VIEW(treeview_history), GTK_TREE_MODEL(history_model) );
412
Stepan Salenikovich82b1acf2015-05-12 12:33:51 -0400413 /* call direction, photo, name/number column */
414 GtkCellArea *area = gtk_cell_area_box_new();
415 GtkTreeViewColumn *column = gtk_tree_view_column_new_with_area(area);
Stepan Salenikovicha1b8cb32015-09-11 14:58:35 -0400416 gtk_tree_view_column_set_title(column, C_("Call history", "Call"));
Stepan Salenikovich9816a942015-04-22 17:49:16 -0400417
418 /* call direction */
419 GtkCellRenderer *renderer = gtk_cell_renderer_text_new();
Stepan Salenikovich82b1acf2015-05-12 12:33:51 -0400420 gtk_cell_area_box_pack_start(GTK_CELL_AREA_BOX(area), renderer, FALSE, FALSE, FALSE);
Stepan Salenikovich9816a942015-04-22 17:49:16 -0400421
422 /* display the call direction with arrows */
423 gtk_tree_view_column_set_cell_data_func(
424 column,
425 renderer,
426 (GtkTreeCellDataFunc)render_call_direction,
427 NULL,
428 NULL);
429
Stepan Salenikovich82b1acf2015-05-12 12:33:51 -0400430 /* photo renderer */
431 renderer = gtk_cell_renderer_pixbuf_new();
432 gtk_cell_area_box_pack_start(GTK_CELL_AREA_BOX(area), renderer, FALSE, FALSE, FALSE);
Stepan Salenikovich9816a942015-04-22 17:49:16 -0400433
Stepan Salenikovich82b1acf2015-05-12 12:33:51 -0400434 /* get the photo */
435 gtk_tree_view_column_set_cell_data_func(
436 column,
437 renderer,
438 (GtkTreeCellDataFunc)render_call_photo,
439 NULL,
440 NULL);
441
442 /* name and contact method renderer */
Stepan Salenikovich9816a942015-04-22 17:49:16 -0400443 renderer = gtk_cell_renderer_text_new();
444 g_object_set(G_OBJECT(renderer), "ellipsize", PANGO_ELLIPSIZE_END, NULL);
Stepan Salenikovich82b1acf2015-05-12 12:33:51 -0400445 gtk_cell_area_box_pack_start(GTK_CELL_AREA_BOX(area), renderer, FALSE, FALSE, FALSE);
446
447 gtk_tree_view_column_set_cell_data_func(
448 column,
449 renderer,
450 (GtkTreeCellDataFunc)render_name_and_contact_method,
451 NULL,
452 NULL);
453
Stepan Salenikovich9816a942015-04-22 17:49:16 -0400454 gtk_tree_view_append_column(GTK_TREE_VIEW(treeview_history), column);
455 gtk_tree_view_column_set_resizable(column, TRUE);
Stepan Salenikoviche7c4e282015-06-11 17:22:08 -0400456 gtk_tree_view_column_set_expand(column, TRUE);
Stepan Salenikovich9816a942015-04-22 17:49:16 -0400457
458 /* date column */
Stepan Salenikovich82b1acf2015-05-12 12:33:51 -0400459 area = gtk_cell_area_box_new();
460 column = gtk_tree_view_column_new_with_area(area);
Stepan Salenikovicha1b8cb32015-09-11 14:58:35 -0400461 gtk_tree_view_column_set_title(column, C_("Call history", "Date"));
Stepan Salenikovich82b1acf2015-05-12 12:33:51 -0400462
463 /* time renderer */
Stepan Salenikovich9816a942015-04-22 17:49:16 -0400464 renderer = gtk_cell_renderer_text_new ();
Stepan Salenikovich82b1acf2015-05-12 12:33:51 -0400465 gtk_cell_area_box_pack_start(GTK_CELL_AREA_BOX(area), renderer, FALSE, FALSE, FALSE);
466 /* format the time*/
467 gtk_tree_view_column_set_cell_data_func(
468 column,
469 renderer,
470 (GtkTreeCellDataFunc)render_time,
471 NULL,
472 NULL);
473
474 /* date renderer */
475 renderer = gtk_cell_renderer_text_new ();
476 gtk_cell_area_box_pack_start(GTK_CELL_AREA_BOX(area), renderer, FALSE, FALSE, FALSE);
Stepan Salenikovich9816a942015-04-22 17:49:16 -0400477 g_object_set(G_OBJECT(renderer), "ellipsize", PANGO_ELLIPSIZE_END, NULL);
Stepan Salenikovich82b1acf2015-05-12 12:33:51 -0400478 /* format the date */
479 gtk_tree_view_column_set_cell_data_func(
480 column,
481 renderer,
482 (GtkTreeCellDataFunc)render_date,
483 NULL,
484 NULL);
485
Stepan Salenikovich9816a942015-04-22 17:49:16 -0400486 gtk_tree_view_append_column(GTK_TREE_VIEW(treeview_history), column);
487 gtk_tree_view_column_set_resizable(column, TRUE);
Stepan Salenikoviche7c4e282015-06-11 17:22:08 -0400488 gtk_tree_view_column_set_expand(column, FALSE);
Stepan Salenikovich9816a942015-04-22 17:49:16 -0400489
Stepan Salenikovich9816a942015-04-22 17:49:16 -0400490 g_signal_connect(treeview_history, "row-activated", G_CALLBACK(activate_history_item), NULL);
491 g_signal_connect(treeview_history, "button-press-event", G_CALLBACK(history_popup_menu), treeview_history);
Stepan Salenikovich9816a942015-04-22 17:49:16 -0400492
493 gtk_widget_show_all(GTK_WIDGET(self));
494}
495
496static void
497history_view_dispose(GObject *object)
498{
Stepan Salenikovich9d294492015-05-14 16:34:24 -0400499 HistoryViewPrivate *priv = HISTORY_VIEW_GET_PRIVATE(object);
500
501 QObject::disconnect(priv->category_changed);
502
Stepan Salenikovich9816a942015-04-22 17:49:16 -0400503 G_OBJECT_CLASS(history_view_parent_class)->dispose(object);
504}
505
506static void
507history_view_finalize(GObject *object)
508{
Stepan Salenikovich9816a942015-04-22 17:49:16 -0400509 G_OBJECT_CLASS(history_view_parent_class)->finalize(object);
510}
511
512static void
513history_view_class_init(HistoryViewClass *klass)
514{
515 G_OBJECT_CLASS(klass)->finalize = history_view_finalize;
516 G_OBJECT_CLASS(klass)->dispose = history_view_dispose;
517}
518
519GtkWidget *
520history_view_new()
521{
522 gpointer self = g_object_new(HISTORY_VIEW_TYPE, NULL);
523
524 return (GtkWidget *)self;
Stepan Salenikovich9d294492015-05-14 16:34:24 -0400525}