/soc/2015/igor.gajowiak/chatlog: ebba8c7398f0: Hooked showing a ...

Igor Gajowiak igor.gajowiak at gmail.com
Sun Aug 16 08:41:13 EDT 2015


Changeset: ebba8c7398f040868f485d4908bc5332ba611e4a
Author:	 Igor Gajowiak <igor.gajowiak at gmail.com>
Date:	 2015-08-16 14:41 +0200
Branch:	 default
URL: https://hg.pidgin.im/soc/2015/igor.gajowiak/chatlog/rev/ebba8c7398f0

Description:

Hooked showing a generic log in proper places. Added automatic showing the last day's messages.

diffstat:

 pidgin/gtkblist.c      |   3 +
 pidgin/gtkconv.c       |   4 ++
 pidgin/gtkdialogs.c    |   4 ++
 pidgin/gtkgenericlog.c |  98 ++++++++++++++++++++++++++++++++++++++++++++++++++
 pidgin/gtkgenericlog.h |   8 ++++
 pidgin/gtklog.c        |   3 -
 6 files changed, 117 insertions(+), 3 deletions(-)

diffs (243 lines):

diff --git a/pidgin/gtkblist.c b/pidgin/gtkblist.c
--- a/pidgin/gtkblist.c
+++ b/pidgin/gtkblist.c
@@ -45,6 +45,7 @@
 #include "gtkdebug.h"
 #include "gtkdialogs.h"
 #include "gtkxfer.h"
+#include "gtkgenericlog.h"
 #include "gtklog.h"
 #include "gtkmenutray.h"
 #include "gtkpounce.h"
@@ -732,6 +733,8 @@ static void gtk_blist_menu_bp_cb(GtkWidg
 
 static void gtk_blist_menu_showlog_cb(GtkWidget *w, PurpleBlistNode *node)
 {
+	pidgin_genericlog_show_contact_log(node);
+
 	PurpleLogType type;
 	PurpleAccount *account;
 	char *name = NULL;
diff --git a/pidgin/gtkconv.c b/pidgin/gtkconv.c
--- a/pidgin/gtkconv.c
+++ b/pidgin/gtkconv.c
@@ -56,6 +56,7 @@
 #include "gtkconv-theme.h"
 #include "gtkconv-theme-loader.h"
 #include "gtkdialogs.h"
+#include "gtkgenericlog.h"
 #include "gtklog.h"
 #include "gtkmenutray.h"
 #include "gtkpounce.h"
@@ -1212,6 +1213,8 @@ menu_view_log_cb(GtkAction *action, gpoi
 	for (cur = buddies; cur != NULL; cur = cur->next)
 	{
 		PurpleBlistNode *node = cur->data;
+		pidgin_genericlog_show_contact_log(node);
+
 		if ((node != NULL) && ((node->prev != NULL) || (node->next != NULL)))
 		{
 			pidgin_log_show_contact((PurpleContact *)node->parent);
@@ -1224,6 +1227,7 @@ menu_view_log_cb(GtkAction *action, gpoi
 	g_slist_free(buddies);
 
 	pidgin_log_show(type, name, account);
+	pidgin_genericlog_show();
 
 	pidgin_clear_cursor(gtkblist->window);
 	pidgin_clear_cursor(win->window);
diff --git a/pidgin/gtkdialogs.c b/pidgin/gtkdialogs.c
--- a/pidgin/gtkdialogs.c
+++ b/pidgin/gtkdialogs.c
@@ -34,6 +34,7 @@
 
 #include "gtkblist.h"
 #include "gtkdialogs.h"
+#include "gtkgenericlog.h"
 #include "gtklog.h"
 #include "gtkutils.h"
 #include "gtkwebview.h"
@@ -1162,6 +1163,8 @@ pidgin_dialogs_log_cb(gpointer data, Pur
 		for (cur = buddies; cur != NULL; cur = cur->next)
 		{
 			PurpleBlistNode *node = cur->data;
+			pidgin_genericlog_show_contact_log(node);
+
 			if ((node != NULL) && ((node->prev != NULL) || (node->next != NULL)))
 			{
 				pidgin_log_show_contact((PurpleContact *)node->parent);
@@ -1174,6 +1177,7 @@ pidgin_dialogs_log_cb(gpointer data, Pur
 		g_slist_free(buddies);
 
 		pidgin_log_show(PURPLE_LOG_IM, username, account);
+		pidgin_genericlog_show();
 
 		pidgin_clear_cursor(gtkblist->window);
 	}
diff --git a/pidgin/gtkgenericlog.c b/pidgin/gtkgenericlog.c
--- a/pidgin/gtkgenericlog.c
+++ b/pidgin/gtkgenericlog.c
@@ -645,6 +645,9 @@ static void
 populate_calendar_store(PurpleBlistNode *contact, GtkTreeStore *store);
 
 static void
+select_calendar_last_day(PidginGenericLogViewer *viewer);
+
+static void
 on_buddylist_row_changed(GtkTreeSelection *sel, gpointer data)
 {
 	g_assert(data);
@@ -677,6 +680,8 @@ on_buddylist_row_changed(GtkTreeSelectio
 
 	gtk_tree_view_set_model(GTK_TREE_VIEW(viewer->calendar_tree_view),
 		GTK_TREE_MODEL(viewer->calendar_tree_store));
+
+	select_calendar_last_day(viewer);
 }
 
 static void
@@ -777,6 +782,55 @@ populate_buddylist_store(GtkTreeStore *s
 	g_hash_table_destroy(branches);
 }
 
+typedef struct ContactSelectionData
+{
+	PidginGenericLogViewer *viewer;
+	PurpleBlistNode *contact;
+} ContactSelectionData;
+
+static gboolean
+select_contact_row_cb(GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter,
+	gpointer user_data)
+{
+	ContactSelectionData *data = (ContactSelectionData*) user_data;
+	PurpleBlistNode *contact;
+
+	gtk_tree_model_get(model, iter, BLIST_TREE_STORE_COL_CONTACT, &contact, -1);
+	g_object_unref(G_OBJECT(contact));
+
+	if (contact == data->contact) {
+		/* Make sure the path to the element is expanded */
+		GtkTreePath *path = gtk_tree_model_get_path(model, iter);
+		gtk_tree_view_expand_to_path(
+			GTK_TREE_VIEW(data->viewer->blist_tree_view), path);
+		gtk_tree_path_free(path);
+
+		GtkTreeSelection *selection = gtk_tree_view_get_selection(
+			GTK_TREE_VIEW(data->viewer->blist_tree_view));
+
+		gtk_tree_selection_select_iter(selection, iter);
+
+		return TRUE;
+	}
+
+	return FALSE;
+}
+
+static void
+select_blist_contact_row(PidginGenericLogViewer *viewer,
+	PurpleBlistNode *contact)
+{
+	g_assert(viewer);
+	g_assert(contact);
+
+	ContactSelectionData data;
+	data.viewer = viewer;
+	data.contact = contact;
+
+	gtk_tree_model_foreach(GTK_TREE_MODEL(viewer->blist_tree_store),
+		select_contact_row_cb, &data);
+}
+
 static GtkWidget *
 create_buddylist_view(GtkTreeStore *store, PidginGenericLogViewer *viewer)
 {
@@ -1015,6 +1069,39 @@ on_calendar_row_changed(GtkTreeSelection
 	g_list_free_full(messages, g_object_unref);
 }
 
+static void
+select_calendar_last_day(PidginGenericLogViewer *viewer)
+{
+	g_assert(viewer);
+
+	GtkTreeModel *model = GTK_TREE_MODEL(viewer->calendar_tree_store);
+
+	gint years_count = gtk_tree_model_iter_n_children(model, NULL);
+	if (years_count == 0)
+		return;
+
+	GtkTreeIter year_iter;
+	gtk_tree_model_iter_nth_child(model, &year_iter, NULL, years_count - 1);
+
+	gint days_count = gtk_tree_model_iter_n_children(model, &year_iter);
+	if (days_count == 0)
+		return;
+
+	GtkTreeIter day_iter;
+	gtk_tree_model_iter_nth_child(model, &day_iter, &year_iter, days_count - 1);
+
+	/* Make sure the path to the element is expanded */
+	GtkTreePath *path = gtk_tree_model_get_path(model, &day_iter);
+		gtk_tree_view_expand_to_path(
+			GTK_TREE_VIEW(viewer->calendar_tree_view), path);
+	gtk_tree_path_free(path);
+
+	GtkTreeSelection *selection = gtk_tree_view_get_selection(
+		GTK_TREE_VIEW(viewer->calendar_tree_view));
+
+	gtk_tree_selection_select_iter(selection, &day_iter);
+}
+
 static gboolean
 popup_calendar_button_pressed(GtkWidget *treeview, GdkEventButton *event,
 	gpointer data)
@@ -1494,6 +1581,17 @@ pidgin_genericlog_show(void)
 	gtk_widget_show_all(generic_log_viewer->window);
 }
 
+void
+pidgin_genericlog_show_contact_log(PurpleBlistNode *contact)
+{
+	g_return_if_fail(contact != NULL);
+	g_return_if_fail(PURPLE_IS_BUDDY(contact) || PURPLE_IS_CHAT(contact));
+
+	pidgin_genericlog_show();
+
+	select_blist_contact_row(generic_log_viewer, contact);
+}
+
 /******************************************************************************/
 /* GTK+ generic log subsystem                                                 */
 /******************************************************************************/
diff --git a/pidgin/gtkgenericlog.h b/pidgin/gtkgenericlog.h
--- a/pidgin/gtkgenericlog.h
+++ b/pidgin/gtkgenericlog.h
@@ -86,6 +86,14 @@ G_BEGIN_DECLS
  */
 void pidgin_genericlog_show(void);
 
+/**
+ * pidgin_genericlog_show_contact_log:
+ * @contact: The contact. Must be one of #PurpleBuddy, #PurpleChat.
+ *
+ * Shows the GTK+ generic log window and sets focus to the contact.
+ */
+void pidgin_genericlog_show_contact_log(PurpleBlistNode *contact);
+
 /******************************************************************************/
 /* GTK+ generic log subsystem                                                 */
 /******************************************************************************/
diff --git a/pidgin/gtklog.c b/pidgin/gtklog.c
--- a/pidgin/gtklog.c
+++ b/pidgin/gtklog.c
@@ -681,9 +681,6 @@ static PidginLogViewer *display_log_view
 }
 
 void pidgin_log_show(PurpleLogType type, const char *buddyname, PurpleAccount *account) {
-	// TODO: a temporary invocation for testing
-	pidgin_genericlog_show();
-
 	struct log_viewer_hash_t *ht;
 	PidginLogViewer *lv = NULL;
 	const char *name = buddyname;



More information about the Commits mailing list