libpurple/purpleconversationmanager.c

Fri, 11 Jul 2025 02:46:28 -0500

author
Gary Kramlich <grim@reaperworld.com>
date
Fri, 11 Jul 2025 02:46:28 -0500
changeset 43284
50c1bcc45576
parent 43283
01eb1bbf4186
child 43287
1de854696dfc
permissions
-rw-r--r--

Load conversations back in from the database

This just handles the conversations and most of their properties including
their tags.

Testing Done:
Verified that conversations were created by starting pidgin 3 with `-n` and that their properties were correct. Then started pidgin 3 normally and verified that all the conversations were brought back online and worked properly.

Also called in the turtles.

Bugs closed: PIDGIN-17989

Reviewed at https://reviews.imfreedom.org/r/4051/

40948
2c312f084d84 Create a manager for conversations.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
1 /*
2c312f084d84 Create a manager for conversations.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
2 * Purple - Internet Messaging Library
2c312f084d84 Create a manager for conversations.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
3 * Copyright (C) Pidgin Developers <devel@pidgin.im>
2c312f084d84 Create a manager for conversations.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
4 *
42594
eddde70cedd8 Create a test for verifying license headers and correct the ones that were wrong
Gary Kramlich <grim@reaperworld.com>
parents: 42576
diff changeset
5 * Purple is the legal property of its developers, whose names are too numerous
eddde70cedd8 Create a test for verifying license headers and correct the ones that were wrong
Gary Kramlich <grim@reaperworld.com>
parents: 42576
diff changeset
6 * to list here. Please refer to the COPYRIGHT file distributed with this
eddde70cedd8 Create a test for verifying license headers and correct the ones that were wrong
Gary Kramlich <grim@reaperworld.com>
parents: 42576
diff changeset
7 * source distribution.
40948
2c312f084d84 Create a manager for conversations.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
8 *
42594
eddde70cedd8 Create a test for verifying license headers and correct the ones that were wrong
Gary Kramlich <grim@reaperworld.com>
parents: 42576
diff changeset
9 * This library is free software; you can redistribute it and/or modify it
eddde70cedd8 Create a test for verifying license headers and correct the ones that were wrong
Gary Kramlich <grim@reaperworld.com>
parents: 42576
diff changeset
10 * under the terms of the GNU General Public License as published by the Free
eddde70cedd8 Create a test for verifying license headers and correct the ones that were wrong
Gary Kramlich <grim@reaperworld.com>
parents: 42576
diff changeset
11 * Software Foundation; either version 2 of the License, or (at your option)
eddde70cedd8 Create a test for verifying license headers and correct the ones that were wrong
Gary Kramlich <grim@reaperworld.com>
parents: 42576
diff changeset
12 * any later version.
40948
2c312f084d84 Create a manager for conversations.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
13 *
42594
eddde70cedd8 Create a test for verifying license headers and correct the ones that were wrong
Gary Kramlich <grim@reaperworld.com>
parents: 42576
diff changeset
14 * This library is distributed in the hope that it will be useful, but WITHOUT
eddde70cedd8 Create a test for verifying license headers and correct the ones that were wrong
Gary Kramlich <grim@reaperworld.com>
parents: 42576
diff changeset
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
eddde70cedd8 Create a test for verifying license headers and correct the ones that were wrong
Gary Kramlich <grim@reaperworld.com>
parents: 42576
diff changeset
16 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
eddde70cedd8 Create a test for verifying license headers and correct the ones that were wrong
Gary Kramlich <grim@reaperworld.com>
parents: 42576
diff changeset
17 * more details.
eddde70cedd8 Create a test for verifying license headers and correct the ones that were wrong
Gary Kramlich <grim@reaperworld.com>
parents: 42576
diff changeset
18 *
eddde70cedd8 Create a test for verifying license headers and correct the ones that were wrong
Gary Kramlich <grim@reaperworld.com>
parents: 42576
diff changeset
19 * You should have received a copy of the GNU General Public License along with
eddde70cedd8 Create a test for verifying license headers and correct the ones that were wrong
Gary Kramlich <grim@reaperworld.com>
parents: 42576
diff changeset
20 * this library; if not, see <https://www.gnu.org/licenses/>.
40948
2c312f084d84 Create a manager for conversations.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
21 */
2c312f084d84 Create a manager for conversations.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
22
43283
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
23 #include <seagull.h>
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
24
42672
5b864b9b22aa Create purple_conversation_manager_find_dm
Gary Kramlich <grim@reaperworld.com>
parents: 42654
diff changeset
25 #include "purpleconversationmanager.h"
42997
368deff13c21 Split purpleprivate.h up into individual files
Gary Kramlich <grim@reaperworld.com>
parents: 42891
diff changeset
26 #include "purpleconversationmanagerprivate.h"
42672
5b864b9b22aa Create purple_conversation_manager_find_dm
Gary Kramlich <grim@reaperworld.com>
parents: 42654
diff changeset
27
42777
8b4f02641aa9 The first steps of making the conversation manager persistent
Gary Kramlich <grim@reaperworld.com>
parents: 42736
diff changeset
28 #include "core.h"
43284
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
29 #include "purpleaccount.h"
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
30 #include "purpleaccountmanager.h"
42672
5b864b9b22aa Create purple_conversation_manager_find_dm
Gary Kramlich <grim@reaperworld.com>
parents: 42654
diff changeset
31 #include "purplecontact.h"
42777
8b4f02641aa9 The first steps of making the conversation manager persistent
Gary Kramlich <grim@reaperworld.com>
parents: 42736
diff changeset
32 #include "purpleui.h"
42725
ceb13f1de2d2 Remove PurpleBuddy
Gary Kramlich <grim@reaperworld.com>
parents: 42715
diff changeset
33 #include "util.h"
40948
2c312f084d84 Create a manager for conversations.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
34
43284
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
35 #ifdef G_LOG_DOMAIN
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
36 #undef G_LOG_DOMAIN
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
37 #endif /* G_LOG_DOMAIN */
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
38 #define G_LOG_DOMAIN "PurpleConversationManager"
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
39
41226
a51ff7ecf053 Add registered and unregistered signals to PurpleConversationManager
Gary Kramlich <grim@reaperworld.com>
parents: 40986
diff changeset
40 enum {
42777
8b4f02641aa9 The first steps of making the conversation manager persistent
Gary Kramlich <grim@reaperworld.com>
parents: 42736
diff changeset
41 PROP_0,
8b4f02641aa9 The first steps of making the conversation manager persistent
Gary Kramlich <grim@reaperworld.com>
parents: 42736
diff changeset
42 PROP_FILENAME,
43044
b6cb116ce063 Change the internal data structure of Purple.ConversationManager to GPtrArray
Gary Kramlich <grim@reaperworld.com>
parents: 43040
diff changeset
43 PROP_ITEM_TYPE,
b6cb116ce063 Change the internal data structure of Purple.ConversationManager to GPtrArray
Gary Kramlich <grim@reaperworld.com>
parents: 43040
diff changeset
44 PROP_N_ITEMS,
42777
8b4f02641aa9 The first steps of making the conversation manager persistent
Gary Kramlich <grim@reaperworld.com>
parents: 42736
diff changeset
45 N_PROPERTIES,
8b4f02641aa9 The first steps of making the conversation manager persistent
Gary Kramlich <grim@reaperworld.com>
parents: 42736
diff changeset
46 };
8b4f02641aa9 The first steps of making the conversation manager persistent
Gary Kramlich <grim@reaperworld.com>
parents: 42736
diff changeset
47 static GParamSpec *properties[N_PROPERTIES] = {NULL, };
8b4f02641aa9 The first steps of making the conversation manager persistent
Gary Kramlich <grim@reaperworld.com>
parents: 42736
diff changeset
48
8b4f02641aa9 The first steps of making the conversation manager persistent
Gary Kramlich <grim@reaperworld.com>
parents: 42736
diff changeset
49 enum {
43029
b95b2d2b8200 Rename Purple.ConversationManager.register/unregister to add/remove
Gary Kramlich <grim@reaperworld.com>
parents: 42997
diff changeset
50 SIG_ADDED,
b95b2d2b8200 Rename Purple.ConversationManager.register/unregister to add/remove
Gary Kramlich <grim@reaperworld.com>
parents: 42997
diff changeset
51 SIG_REMOVED,
42286
3fe515350d59 Add a conversation-changed signal to PurpleConversationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42272
diff changeset
52 SIG_CONVERSATION_CHANGED,
42736
630084f39cc5 Add a present signal to PurpleConversation and propagate it from PurpleConversationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42725
diff changeset
53 SIG_PRESENT_CONVERSATION,
41226
a51ff7ecf053 Add registered and unregistered signals to PurpleConversationManager
Gary Kramlich <grim@reaperworld.com>
parents: 40986
diff changeset
54 N_SIGNALS,
a51ff7ecf053 Add registered and unregistered signals to PurpleConversationManager
Gary Kramlich <grim@reaperworld.com>
parents: 40986
diff changeset
55 };
a51ff7ecf053 Add registered and unregistered signals to PurpleConversationManager
Gary Kramlich <grim@reaperworld.com>
parents: 40986
diff changeset
56 static guint signals[N_SIGNALS] = {0, };
a51ff7ecf053 Add registered and unregistered signals to PurpleConversationManager
Gary Kramlich <grim@reaperworld.com>
parents: 40986
diff changeset
57
40948
2c312f084d84 Create a manager for conversations.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
58 struct _PurpleConversationManager {
2c312f084d84 Create a manager for conversations.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
59 GObject parent;
2c312f084d84 Create a manager for conversations.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
60
42777
8b4f02641aa9 The first steps of making the conversation manager persistent
Gary Kramlich <grim@reaperworld.com>
parents: 42736
diff changeset
61 char *filename;
43283
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
62 SeagullSqlite3 *db;
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
63 gboolean database_initialized;
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
64
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
65 SeagullStatement *delete_tags;
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
66 SeagullStatement *insert_properties;
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
67 SeagullStatement *insert_tags;
43284
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
68 SeagullStatement *query_properties;
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
69 SeagullStatement *query_tags;
42777
8b4f02641aa9 The first steps of making the conversation manager persistent
Gary Kramlich <grim@reaperworld.com>
parents: 42736
diff changeset
70
43044
b6cb116ce063 Change the internal data structure of Purple.ConversationManager to GPtrArray
Gary Kramlich <grim@reaperworld.com>
parents: 43040
diff changeset
71 GPtrArray *conversations;
40948
2c312f084d84 Create a manager for conversations.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
72 };
2c312f084d84 Create a manager for conversations.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
73
2c312f084d84 Create a manager for conversations.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
74 static PurpleConversationManager *default_manager = NULL;
2c312f084d84 Create a manager for conversations.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
75
2c312f084d84 Create a manager for conversations.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
76 typedef gboolean (*PurpleConversationManagerCompareFunc)(PurpleConversation *conversation, gpointer userdata);
2c312f084d84 Create a manager for conversations.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
77
43283
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
78 #define RESOURCE_PATH "/im/pidgin/libpurple/conversationmanager"
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
79
40948
2c312f084d84 Create a manager for conversations.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
80 /******************************************************************************
2c312f084d84 Create a manager for conversations.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
81 * Helpers
2c312f084d84 Create a manager for conversations.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
82 *****************************************************************************/
42777
8b4f02641aa9 The first steps of making the conversation manager persistent
Gary Kramlich <grim@reaperworld.com>
parents: 42736
diff changeset
83 static void
43283
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
84 purple_conversation_manager_initialize_database(PurpleConversationManager *manager)
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
85 {
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
86 SeagullStatement *stmt = NULL;
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
87 GError *error = NULL;
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
88 gboolean result = FALSE;
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
89 const char *migrations[] = {
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
90 "01-initial.sql",
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
91 NULL
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
92 };
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
93
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
94
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
95 if(!purple_strempty(manager->filename)) {
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
96 manager->db = seagull_db_new_from_file(manager->filename, &error);
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
97 } else {
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
98 manager->db = seagull_db_new_in_memory(&error);
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
99 }
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
100
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
101 if(error != NULL) {
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
102 g_warning("failed to create database: %s", error->message);
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
103 g_clear_error(&error);
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
104
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
105 return;
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
106 }
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
107
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
108 /* Run the migrations. */
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
109 result = seagull_migrations_run_from_resources(manager->db,
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
110 RESOURCE_PATH "/migrations",
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
111 migrations,
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
112 &error);
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
113
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
114 if(!result) {
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
115 g_warning("failed to run migrations: %s", error->message);
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
116 g_clear_error(&error);
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
117
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
118 return;
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
119 }
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
120
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
121 stmt = seagull_statement_new_from_resource(manager->db,
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
122 RESOURCE_PATH "/statements/delete-tags.sql",
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
123 &error);
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
124 if(error != NULL) {
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
125 g_warning("failed to loaded delete-tags statement: %s",
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
126 error->message);
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
127 g_clear_error(&error);
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
128
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
129 return;
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
130 }
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
131 manager->delete_tags = stmt;
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
132
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
133 stmt = seagull_statement_new_from_resource(manager->db,
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
134 RESOURCE_PATH "/statements/insert-properties.sql",
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
135 &error);
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
136 if(error != NULL) {
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
137 g_warning("failed to loaded insert-properties statement: %s",
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
138 error->message);
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
139 g_clear_error(&error);
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
140
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
141 return;
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
142 }
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
143 manager->insert_properties = stmt;
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
144
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
145 stmt = seagull_statement_new_from_resource(manager->db,
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
146 RESOURCE_PATH "/statements/insert-tags.sql",
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
147 &error);
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
148 if(error != NULL) {
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
149 g_warning("failed to loaded insert-tags statement: %s",
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
150 error->message);
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
151 g_clear_error(&error);
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
152
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
153 return;
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
154 }
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
155 manager->insert_tags = stmt;
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
156
43284
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
157 stmt = seagull_statement_new_from_resource(manager->db,
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
158 RESOURCE_PATH "/statements/query-properties.sql",
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
159 &error);
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
160 if(error != NULL) {
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
161 g_warning("failed to loaded query-properties statement: %s",
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
162 error->message);
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
163 g_clear_error(&error);
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
164
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
165 return;
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
166 }
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
167 manager->query_properties = stmt;
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
168
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
169 stmt = seagull_statement_new_from_resource(manager->db,
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
170 RESOURCE_PATH "/statements/query-tags.sql",
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
171 &error);
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
172 if(error != NULL) {
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
173 g_warning("failed to loaded query-tags statement: %s",
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
174 error->message);
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
175 g_clear_error(&error);
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
176
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
177 return;
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
178 }
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
179 manager->query_tags = stmt;
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
180
43283
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
181 manager->database_initialized = TRUE;
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
182 }
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
183
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
184 static void
42777
8b4f02641aa9 The first steps of making the conversation manager persistent
Gary Kramlich <grim@reaperworld.com>
parents: 42736
diff changeset
185 purple_conversation_manager_set_filename(PurpleConversationManager *manager,
8b4f02641aa9 The first steps of making the conversation manager persistent
Gary Kramlich <grim@reaperworld.com>
parents: 42736
diff changeset
186 const char *filename)
8b4f02641aa9 The first steps of making the conversation manager persistent
Gary Kramlich <grim@reaperworld.com>
parents: 42736
diff changeset
187 {
8b4f02641aa9 The first steps of making the conversation manager persistent
Gary Kramlich <grim@reaperworld.com>
parents: 42736
diff changeset
188 g_return_if_fail(PURPLE_IS_CONVERSATION_MANAGER(manager));
8b4f02641aa9 The first steps of making the conversation manager persistent
Gary Kramlich <grim@reaperworld.com>
parents: 42736
diff changeset
189
8b4f02641aa9 The first steps of making the conversation manager persistent
Gary Kramlich <grim@reaperworld.com>
parents: 42736
diff changeset
190 if(g_set_str(&manager->filename, filename)) {
8b4f02641aa9 The first steps of making the conversation manager persistent
Gary Kramlich <grim@reaperworld.com>
parents: 42736
diff changeset
191 g_object_notify_by_pspec(G_OBJECT(manager), properties[PROP_FILENAME]);
8b4f02641aa9 The first steps of making the conversation manager persistent
Gary Kramlich <grim@reaperworld.com>
parents: 42736
diff changeset
192 }
43284
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
193
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
194 /* The filename property is construct-only and nullable, so if it is set as
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
195 * null, the g_set_str above won't return TRUE, but and we have to
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
196 * initialize the database in any case so we just do it separately.
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
197 *
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
198 * Also, GObject will emit a Critical message if a construct only property
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
199 * is set more than once and not call it again, so we don't need to
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
200 * protect against that either.
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
201 */
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
202 purple_conversation_manager_initialize_database(manager);
42777
8b4f02641aa9 The first steps of making the conversation manager persistent
Gary Kramlich <grim@reaperworld.com>
parents: 42736
diff changeset
203 }
8b4f02641aa9 The first steps of making the conversation manager persistent
Gary Kramlich <grim@reaperworld.com>
parents: 42736
diff changeset
204
43283
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
205 static gboolean
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
206 purple_conversation_manager_save_conversation_properties(PurpleConversationManager *manager,
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
207 PurpleConversation *conversation)
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
208 {
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
209 PurpleAccount *account = NULL;
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
210 PurpleContactInfo *contact = NULL;
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
211 GError *error = NULL;
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
212 gboolean success = FALSE;
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
213
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
214 /* Bind the properties for the conversation. */
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
215 success = seagull_statement_bind_object(manager->insert_properties,
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
216 "conv_", G_OBJECT(conversation),
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
217 &error);
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
218 if(!success) {
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
219 g_warning("failed to bind conversation to insert properties: %s",
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
220 error->message);
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
221 g_clear_error(&error);
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
222
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
223 return FALSE;
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
224 }
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
225
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
226 /* Bind the account */
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
227 account = purple_conversation_get_account(conversation);
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
228 success = seagull_statement_bind_text(manager->insert_properties,
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
229 ":account_id",
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
230 purple_account_get_id(account),
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
231 -1,
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
232 NULL,
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
233 &error);
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
234 if(!success) {
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
235 g_warning("failed to bind account_id to insert properties: %s",
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
236 error->message);
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
237 g_clear_error(&error);
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
238
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
239 return FALSE;
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
240 }
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
241
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
242 /* If we have a creator, bind it. */
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
243 contact = purple_conversation_get_creator(conversation);
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
244 if(PURPLE_IS_CONTACT_INFO(contact)) {
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
245 success = seagull_statement_bind_text(manager->insert_properties,
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
246 ":creator_id",
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
247 purple_contact_info_get_id(contact),
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
248 -1,
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
249 NULL,
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
250 &error);
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
251 } else {
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
252 success = seagull_statement_bind_null(manager->insert_properties,
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
253 ":creator_id",
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
254 &error);
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
255 }
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
256
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
257 if(!success) {
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
258 g_warning("failed to bind creator_id to insert properties: %s",
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
259 error->message);
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
260 g_clear_error(&error);
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
261
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
262 return FALSE;
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
263 }
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
264
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
265 /* If we have a topic author, bind it. */
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
266 contact = purple_conversation_get_topic_author(conversation);
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
267 if(PURPLE_IS_CONTACT_INFO(contact)) {
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
268 success = seagull_statement_bind_text(manager->insert_properties,
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
269 ":topic_author_id",
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
270 purple_contact_info_get_id(contact),
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
271 -1,
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
272 NULL,
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
273 &error);
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
274 } else {
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
275 success = seagull_statement_bind_null(manager->insert_properties,
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
276 ":topic_author_id",
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
277 &error);
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
278 }
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
279
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
280 if(!success) {
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
281 g_warning("failed to bind creator_id to insert properties: %s",
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
282 error->message);
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
283 g_clear_error(&error);
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
284
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
285 return FALSE;
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
286 }
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
287
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
288 /* The return value of step is whether or not there is data to read. Since
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
289 * this is an insert statement, we can ignore it.
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
290 */
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
291 seagull_statement_step(manager->insert_properties, &error);
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
292 if(error != NULL) {
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
293 g_warning("failed to step insert statement: %s", error->message);
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
294 g_clear_error(&error);
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
295
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
296 return FALSE;
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
297 }
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
298
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
299 return TRUE;
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
300 }
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
301
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
302 static gboolean
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
303 purple_conversation_manager_save_conversation_tags(PurpleConversationManager *manager,
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
304 PurpleConversation *conversation)
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
305 {
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
306 PurpleAccount *account = NULL;
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
307 PurpleTags *tags = NULL;
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
308 GError *error = NULL;
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
309 const char *conversation_id = NULL;
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
310 const char *account_id = NULL;
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
311 gboolean success = FALSE;
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
312
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
313 /* Grab the conversation and account ids as we need them for everything. */
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
314 conversation_id = purple_conversation_get_id(conversation);
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
315 account = purple_conversation_get_account(conversation);
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
316 account_id = purple_account_get_id(account);
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
317
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
318 /* Bind the conversation id to the delete statement. */
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
319 success = seagull_statement_bind_text(manager->delete_tags,
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
320 ":conversation_id",
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
321 conversation_id,
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
322 -1,
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
323 NULL,
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
324 &error);
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
325 if(!success) {
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
326 g_warning("failed to bind conversation_id to delete tags: %s",
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
327 error->message);
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
328 g_clear_error(&error);
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
329
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
330 return FALSE;
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
331 }
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
332
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
333 /* Bind the account id to the delete statement. */
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
334 success = seagull_statement_bind_text(manager->delete_tags,
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
335 ":account_id",
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
336 account_id,
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
337 -1,
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
338 NULL,
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
339 &error);
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
340 if(!success) {
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
341 g_warning("failed to bind account_id to delete tags: %s",
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
342 error->message);
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
343 g_clear_error(&error);
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
344
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
345 return FALSE;
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
346 }
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
347
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
348 /* Delete the existing tags, since we just replace everything. */
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
349 seagull_statement_step(manager->delete_tags, &error);
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
350 if(error != NULL) {
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
351 g_warning("failed to delete tags: %s", error->message);
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
352 g_clear_error(&error);
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
353
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
354 return FALSE;
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
355 }
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
356
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
357 /* Bind the conversation id to the insert statement. */
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
358 success = seagull_statement_bind_text(manager->insert_tags,
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
359 ":conversation_id",
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
360 conversation_id,
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
361 -1,
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
362 NULL,
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
363 &error);
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
364 if(!success) {
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
365 g_warning("failed to bind conversation_id to insert tags: %s",
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
366 error->message);
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
367 g_clear_error(&error);
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
368
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
369 return FALSE;
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
370 }
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
371
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
372 /* Bind the account id to the insert statement. */
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
373 success = seagull_statement_bind_text(manager->insert_tags,
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
374 ":account_id",
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
375 account_id,
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
376 -1,
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
377 NULL,
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
378 &error);
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
379 if(!success) {
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
380 g_warning("failed to bind account_id to insert tags: %s",
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
381 error->message);
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
382 g_clear_error(&error);
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
383
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
384 return FALSE;
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
385 }
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
386
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
387 /* Now run through tags and insert them. */
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
388 tags = purple_conversation_get_tags(conversation);
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
389 for(GList *l = purple_tags_get_all(tags); l != NULL; l = l->next) {
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
390 const char *tag = l->data;
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
391
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
392 success = seagull_statement_bind_text(manager->insert_tags,
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
393 ":tag",
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
394 tag,
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
395 -1,
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
396 NULL,
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
397 &error);
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
398
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
399 if(!success) {
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
400 g_warning("failed to bind tag to insert tags: %s",
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
401 error->message);
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
402 g_clear_error(&error);
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
403
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
404 return FALSE;
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
405 }
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
406
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
407 /* Step the statement. */
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
408 seagull_statement_step(manager->insert_tags, &error);
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
409 if(error != NULL) {
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
410 g_warning("sql: %s", seagull_statement_get_expanded_sql(manager->insert_tags));
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
411 g_warning("failed to insert tag: %s", error->message);
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
412 g_clear_error(&error);
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
413
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
414 return FALSE;
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
415 }
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
416
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
417 if(!seagull_statement_reset(manager->insert_tags, &error)) {
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
418 g_warning("sql: %s", seagull_statement_get_expanded_sql(manager->insert_tags));
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
419 g_warning("failed to reset the insert tags statement: %s",
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
420 error->message);
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
421 g_clear_error(&error);
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
422
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
423 return FALSE;
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
424 }
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
425 }
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
426
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
427 return TRUE;
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
428 }
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
429
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
430 static void
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
431 purple_conversation_manager_save_conversation(PurpleConversationManager *manager,
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
432 PurpleConversation *conversation)
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
433 {
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
434 GError *error = NULL;
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
435 gboolean success = FALSE;
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
436
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
437 if(!manager->database_initialized) {
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
438 return;
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
439 }
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
440
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
441 /* Start a transaction so that everything is atomic. */
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
442 if(!seagull_transaction_begin(manager->db, &error)) {
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
443 g_warning("failed to begin transaction to save conversation: %s",
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
444 error->message);
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
445 g_clear_error(&error);
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
446
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
447 return;
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
448 }
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
449
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
450 /* Save the conversation properties. */
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
451 success = purple_conversation_manager_save_conversation_properties(manager,
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
452 conversation);
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
453 if(!seagull_statement_clear_bindings(manager->insert_properties,
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
454 &error))
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
455 {
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
456 g_warning("failed to clear bindings on the insert properties "
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
457 "statement: %s",
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
458 error->message);
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
459 g_clear_error(&error);
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
460 }
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
461
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
462 if(!seagull_statement_reset(manager->insert_properties, &error)) {
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
463 g_warning("failed to reset the insert properties statement: %s",
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
464 error->message);
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
465 g_clear_error(&error);
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
466 }
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
467 if(!success) {
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
468 if(!seagull_transaction_rollback(manager->db, &error)) {
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
469 g_warning("failed to rollback transaction: %s", error->message);
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
470 g_clear_error(&error);
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
471 }
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
472
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
473 return;
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
474 }
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
475
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
476 /* Save the conversation tags. */
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
477 success = purple_conversation_manager_save_conversation_tags(manager,
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
478 conversation);
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
479 if(!seagull_statement_clear_bindings(manager->delete_tags,
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
480 &error))
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
481 {
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
482 g_warning("failed to clear bindings on the delete tags statement: "
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
483 "%s",
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
484 error->message);
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
485 g_clear_error(&error);
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
486 }
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
487
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
488 if(!seagull_statement_reset(manager->delete_tags, &error)) {
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
489 g_warning("failed to reset the delete tags statement: %s",
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
490 error->message);
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
491 g_clear_error(&error);
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
492 }
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
493
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
494 if(!seagull_statement_clear_bindings(manager->insert_tags,
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
495 &error))
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
496 {
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
497 g_warning("failed to clear bindings on the insert tags statement: "
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
498 "%s",
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
499 error->message);
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
500 g_clear_error(&error);
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
501 }
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
502
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
503 if(!seagull_statement_reset(manager->insert_tags, &error)) {
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
504 g_warning("failed to reset the insert tags statement: %s",
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
505 error->message);
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
506 g_clear_error(&error);
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
507 }
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
508
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
509 if(!success) {
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
510 if(!seagull_transaction_rollback(manager->db, &error)) {
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
511 g_warning("failed to rollback transaction: %s", error->message);
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
512 g_clear_error(&error);
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
513 }
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
514
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
515 return;
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
516 }
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
517
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
518 /* Commit the transaction. */
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
519 if(!seagull_transaction_commit(manager->db, &error)) {
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
520 g_warning("failed to commit transaction to save conversation: %s",
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
521 error->message);
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
522 g_clear_error(&error);
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
523 }
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
524 }
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
525
43284
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
526 static void
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
527 purple_conversation_manager_load_conversation_tags(PurpleConversationManager *manager,
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
528 PurpleConversation *conversation,
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
529 const char *account_id,
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
530 const char *conversation_id,
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
531 GError **error)
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
532 {
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
533 PurpleTags *tags = NULL;
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
534 GError *local_error = NULL;
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
535
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
536 tags = purple_conversation_get_tags(conversation);
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
537
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
538 /* Conversations have some default tags when created, but we need to
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
539 * replace everything so we clear those.
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
540 */
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
541 purple_tags_remove_all(tags);
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
542
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
543 /* Reset the statement. */
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
544 seagull_statement_reset(manager->query_tags, &local_error);
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
545 if(local_error != NULL) {
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
546 g_propagate_error(error, local_error);
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
547
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
548 return;
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
549 }
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
550
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
551 /* Bind the account id. */
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
552 seagull_statement_bind_text(manager->query_tags, ":account_id", account_id,
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
553 -1, NULL, &local_error);
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
554 if(local_error != NULL) {
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
555 g_propagate_error(error, local_error);
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
556
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
557 return;
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
558 }
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
559
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
560 /* Bind the conversation id. */
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
561 seagull_statement_bind_text(manager->query_tags, ":conversation_id",
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
562 conversation_id, -1, NULL, &local_error);
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
563 if(local_error != NULL) {
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
564 g_propagate_error(error, local_error);
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
565
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
566 return;
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
567 }
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
568
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
569 while(seagull_statement_step(manager->query_tags, &local_error)) {
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
570 const char *tag = NULL;
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
571
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
572 tag = seagull_statement_column_text(manager->query_tags, "tag",
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
573 &local_error);
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
574
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
575 if(local_error != NULL) {
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
576 g_propagate_error(error, local_error);
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
577
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
578 return;
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
579 }
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
580
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
581 purple_tags_add(tags, tag);
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
582 }
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
583
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
584 if(local_error != NULL) {
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
585 g_propagate_error(error, local_error);
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
586 }
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
587 }
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
588
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
589 static void
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
590 purple_conversation_manager_load_conversations(PurpleConversationManager *manager)
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
591 {
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
592 PurpleAccountManager *account_manager = NULL;
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
593 GError *error = NULL;
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
594
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
595 seagull_statement_reset(manager->query_properties, &error);
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
596 if(error != NULL) {
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
597 g_warning("failed to request query properties statement: %s",
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
598 error->message);
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
599 g_clear_error(&error);
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
600
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
601 return;
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
602 }
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
603
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
604 account_manager = purple_account_manager_get_default();
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
605
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
606 while(seagull_statement_step(manager->query_properties, &error)) {
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
607 PurpleAccount *account = NULL;
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
608 PurpleConversation *conversation = NULL;
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
609 const char *account_id = NULL;
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
610 const char *conversation_id = NULL;
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
611 gint type = PURPLE_CONVERSATION_TYPE_UNSET;
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
612 gboolean federated = FALSE;
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
613
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
614 /* Grab the account id and attempt to find the account. */
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
615 account_id = seagull_statement_column_text(manager->query_properties,
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
616 "account_id", &error);
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
617 if(error != NULL) {
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
618 g_warning("failed to read account id: %s", error->message);
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
619 g_clear_error(&error);
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
620
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
621 continue;
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
622 }
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
623
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
624 account = purple_account_manager_find_by_id(account_manager,
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
625 account_id);
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
626 if(!PURPLE_IS_ACCOUNT(account)) {
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
627 g_warning("failed to find account for id %s", account_id);
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
628
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
629 continue;
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
630 }
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
631
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
632 conversation_id = seagull_statement_column_text(manager->query_properties,
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
633 "conversation_id",
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
634 &error);
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
635 if(error != NULL) {
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
636 g_warning("failed to read conversation id: %s", error->message);
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
637 g_clear_error(&error);
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
638
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
639 continue;
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
640 }
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
641
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
642 type = seagull_statement_column_enum(manager->query_properties, "type",
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
643 &error);
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
644 if(error != NULL) {
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
645 g_warning("failed to read type: %s", error->message);
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
646 g_clear_error(&error);
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
647
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
648 continue;
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
649 }
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
650
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
651 federated = seagull_statement_column_int(manager->query_properties,
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
652 "federated", &error);
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
653 if(error != NULL) {
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
654 g_warning("failed to read federated: %s", error->message);
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
655 g_clear_error(&error);
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
656
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
657 continue;
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
658 }
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
659
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
660 /* We have all the construct only properties, so let's create the
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
661 * instance.
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
662 */
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
663 conversation = g_object_new(
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
664 PURPLE_TYPE_CONVERSATION,
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
665 "account", account,
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
666 "federated", federated,
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
667 "id", conversation_id,
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
668 "type", type,
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
669 NULL);
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
670
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
671 /* Now set the rest of the properties. */
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
672 seagull_statement_column_object(manager->query_properties, "conv_",
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
673 G_OBJECT(conversation), &error);
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
674
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
675 if(error != NULL) {
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
676 g_warning("failed to read object properties: %s", error->message);
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
677 g_clear_error(&error);
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
678
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
679 g_clear_object(&conversation);
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
680
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
681 continue;
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
682 }
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
683
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
684 purple_conversation_manager_load_conversation_tags(manager,
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
685 conversation,
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
686 account_id,
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
687 conversation_id,
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
688 &error);
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
689 if(error != NULL) {
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
690 g_warning("failed to load tags for conversation %s: %s",
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
691 conversation_id, error->message);
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
692
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
693 g_clear_error(&error);
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
694 g_clear_object(&conversation);
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
695
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
696 continue;
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
697 }
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
698
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
699 /* Finally, add the conversation to the manager. */
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
700 if(!purple_conversation_manager_add(manager, conversation)) {
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
701 g_warning("failed to add conversation: %p", conversation);
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
702 }
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
703
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
704 g_clear_object(&conversation);
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
705 }
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
706
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
707 if(error != NULL) {
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
708 g_warning("failed querying properties: %s", error->message);
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
709 g_clear_error(&error);
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
710 }
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
711 }
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
712
40948
2c312f084d84 Create a manager for conversations.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
713 /******************************************************************************
42286
3fe515350d59 Add a conversation-changed signal to PurpleConversationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42272
diff changeset
714 * Callbacks
3fe515350d59 Add a conversation-changed signal to PurpleConversationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42272
diff changeset
715 *****************************************************************************/
3fe515350d59 Add a conversation-changed signal to PurpleConversationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42272
diff changeset
716 static void
3fe515350d59 Add a conversation-changed signal to PurpleConversationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42272
diff changeset
717 purple_conversation_manager_conversation_changed_cb(GObject *source,
3fe515350d59 Add a conversation-changed signal to PurpleConversationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42272
diff changeset
718 GParamSpec *pspec,
3fe515350d59 Add a conversation-changed signal to PurpleConversationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42272
diff changeset
719 gpointer data)
3fe515350d59 Add a conversation-changed signal to PurpleConversationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42272
diff changeset
720 {
43283
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
721 purple_conversation_manager_save_conversation(data,
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
722 PURPLE_CONVERSATION(source));
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
723
42286
3fe515350d59 Add a conversation-changed signal to PurpleConversationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42272
diff changeset
724 g_signal_emit(data, signals[SIG_CONVERSATION_CHANGED],
3fe515350d59 Add a conversation-changed signal to PurpleConversationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42272
diff changeset
725 g_param_spec_get_name_quark(pspec),
3fe515350d59 Add a conversation-changed signal to PurpleConversationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42272
diff changeset
726 source, pspec);
3fe515350d59 Add a conversation-changed signal to PurpleConversationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42272
diff changeset
727 }
3fe515350d59 Add a conversation-changed signal to PurpleConversationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42272
diff changeset
728
42736
630084f39cc5 Add a present signal to PurpleConversation and propagate it from PurpleConversationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42725
diff changeset
729 static void
630084f39cc5 Add a present signal to PurpleConversation and propagate it from PurpleConversationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42725
diff changeset
730 purple_conversation_manager_present_conversation_cb(PurpleConversation *conversation,
630084f39cc5 Add a present signal to PurpleConversation and propagate it from PurpleConversationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42725
diff changeset
731 gpointer data)
630084f39cc5 Add a present signal to PurpleConversation and propagate it from PurpleConversationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42725
diff changeset
732 {
630084f39cc5 Add a present signal to PurpleConversation and propagate it from PurpleConversationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42725
diff changeset
733 g_signal_emit(data, signals[SIG_PRESENT_CONVERSATION], 0, conversation);
630084f39cc5 Add a present signal to PurpleConversation and propagate it from PurpleConversationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42725
diff changeset
734 }
630084f39cc5 Add a present signal to PurpleConversation and propagate it from PurpleConversationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42725
diff changeset
735
42286
3fe515350d59 Add a conversation-changed signal to PurpleConversationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42272
diff changeset
736 /******************************************************************************
43044
b6cb116ce063 Change the internal data structure of Purple.ConversationManager to GPtrArray
Gary Kramlich <grim@reaperworld.com>
parents: 43040
diff changeset
737 * GListModel Implementation
b6cb116ce063 Change the internal data structure of Purple.ConversationManager to GPtrArray
Gary Kramlich <grim@reaperworld.com>
parents: 43040
diff changeset
738 *****************************************************************************/
b6cb116ce063 Change the internal data structure of Purple.ConversationManager to GPtrArray
Gary Kramlich <grim@reaperworld.com>
parents: 43040
diff changeset
739 static GType
b6cb116ce063 Change the internal data structure of Purple.ConversationManager to GPtrArray
Gary Kramlich <grim@reaperworld.com>
parents: 43040
diff changeset
740 purple_conversation_manager_get_item_type(G_GNUC_UNUSED GListModel *list) {
b6cb116ce063 Change the internal data structure of Purple.ConversationManager to GPtrArray
Gary Kramlich <grim@reaperworld.com>
parents: 43040
diff changeset
741 return PURPLE_TYPE_CONVERSATION;
b6cb116ce063 Change the internal data structure of Purple.ConversationManager to GPtrArray
Gary Kramlich <grim@reaperworld.com>
parents: 43040
diff changeset
742 }
b6cb116ce063 Change the internal data structure of Purple.ConversationManager to GPtrArray
Gary Kramlich <grim@reaperworld.com>
parents: 43040
diff changeset
743
b6cb116ce063 Change the internal data structure of Purple.ConversationManager to GPtrArray
Gary Kramlich <grim@reaperworld.com>
parents: 43040
diff changeset
744 static guint
b6cb116ce063 Change the internal data structure of Purple.ConversationManager to GPtrArray
Gary Kramlich <grim@reaperworld.com>
parents: 43040
diff changeset
745 purple_conversation_manager_get_n_items(GListModel *list) {
b6cb116ce063 Change the internal data structure of Purple.ConversationManager to GPtrArray
Gary Kramlich <grim@reaperworld.com>
parents: 43040
diff changeset
746 PurpleConversationManager *manager = PURPLE_CONVERSATION_MANAGER(list);
b6cb116ce063 Change the internal data structure of Purple.ConversationManager to GPtrArray
Gary Kramlich <grim@reaperworld.com>
parents: 43040
diff changeset
747
b6cb116ce063 Change the internal data structure of Purple.ConversationManager to GPtrArray
Gary Kramlich <grim@reaperworld.com>
parents: 43040
diff changeset
748 return manager->conversations->len;
b6cb116ce063 Change the internal data structure of Purple.ConversationManager to GPtrArray
Gary Kramlich <grim@reaperworld.com>
parents: 43040
diff changeset
749 }
b6cb116ce063 Change the internal data structure of Purple.ConversationManager to GPtrArray
Gary Kramlich <grim@reaperworld.com>
parents: 43040
diff changeset
750
b6cb116ce063 Change the internal data structure of Purple.ConversationManager to GPtrArray
Gary Kramlich <grim@reaperworld.com>
parents: 43040
diff changeset
751 static gpointer
b6cb116ce063 Change the internal data structure of Purple.ConversationManager to GPtrArray
Gary Kramlich <grim@reaperworld.com>
parents: 43040
diff changeset
752 purple_conversation_manager_get_item(GListModel *list, guint position) {
b6cb116ce063 Change the internal data structure of Purple.ConversationManager to GPtrArray
Gary Kramlich <grim@reaperworld.com>
parents: 43040
diff changeset
753 PurpleConversationManager *manager = PURPLE_CONVERSATION_MANAGER(list);
b6cb116ce063 Change the internal data structure of Purple.ConversationManager to GPtrArray
Gary Kramlich <grim@reaperworld.com>
parents: 43040
diff changeset
754 PurpleConversation *conversation = NULL;
b6cb116ce063 Change the internal data structure of Purple.ConversationManager to GPtrArray
Gary Kramlich <grim@reaperworld.com>
parents: 43040
diff changeset
755
b6cb116ce063 Change the internal data structure of Purple.ConversationManager to GPtrArray
Gary Kramlich <grim@reaperworld.com>
parents: 43040
diff changeset
756 if(position < manager->conversations->len) {
b6cb116ce063 Change the internal data structure of Purple.ConversationManager to GPtrArray
Gary Kramlich <grim@reaperworld.com>
parents: 43040
diff changeset
757 conversation = g_object_ref(g_ptr_array_index(manager->conversations,
b6cb116ce063 Change the internal data structure of Purple.ConversationManager to GPtrArray
Gary Kramlich <grim@reaperworld.com>
parents: 43040
diff changeset
758 position));
b6cb116ce063 Change the internal data structure of Purple.ConversationManager to GPtrArray
Gary Kramlich <grim@reaperworld.com>
parents: 43040
diff changeset
759 }
b6cb116ce063 Change the internal data structure of Purple.ConversationManager to GPtrArray
Gary Kramlich <grim@reaperworld.com>
parents: 43040
diff changeset
760
b6cb116ce063 Change the internal data structure of Purple.ConversationManager to GPtrArray
Gary Kramlich <grim@reaperworld.com>
parents: 43040
diff changeset
761 return conversation;
b6cb116ce063 Change the internal data structure of Purple.ConversationManager to GPtrArray
Gary Kramlich <grim@reaperworld.com>
parents: 43040
diff changeset
762 }
b6cb116ce063 Change the internal data structure of Purple.ConversationManager to GPtrArray
Gary Kramlich <grim@reaperworld.com>
parents: 43040
diff changeset
763
b6cb116ce063 Change the internal data structure of Purple.ConversationManager to GPtrArray
Gary Kramlich <grim@reaperworld.com>
parents: 43040
diff changeset
764 static void
b6cb116ce063 Change the internal data structure of Purple.ConversationManager to GPtrArray
Gary Kramlich <grim@reaperworld.com>
parents: 43040
diff changeset
765 pidgin_conversation_manager_list_model_iface_init(GListModelInterface *iface) {
b6cb116ce063 Change the internal data structure of Purple.ConversationManager to GPtrArray
Gary Kramlich <grim@reaperworld.com>
parents: 43040
diff changeset
766 iface->get_item_type = purple_conversation_manager_get_item_type;
b6cb116ce063 Change the internal data structure of Purple.ConversationManager to GPtrArray
Gary Kramlich <grim@reaperworld.com>
parents: 43040
diff changeset
767 iface->get_n_items = purple_conversation_manager_get_n_items;
b6cb116ce063 Change the internal data structure of Purple.ConversationManager to GPtrArray
Gary Kramlich <grim@reaperworld.com>
parents: 43040
diff changeset
768 iface->get_item = purple_conversation_manager_get_item;
b6cb116ce063 Change the internal data structure of Purple.ConversationManager to GPtrArray
Gary Kramlich <grim@reaperworld.com>
parents: 43040
diff changeset
769 }
b6cb116ce063 Change the internal data structure of Purple.ConversationManager to GPtrArray
Gary Kramlich <grim@reaperworld.com>
parents: 43040
diff changeset
770
b6cb116ce063 Change the internal data structure of Purple.ConversationManager to GPtrArray
Gary Kramlich <grim@reaperworld.com>
parents: 43040
diff changeset
771 /******************************************************************************
b6cb116ce063 Change the internal data structure of Purple.ConversationManager to GPtrArray
Gary Kramlich <grim@reaperworld.com>
parents: 43040
diff changeset
772 * GObject Implementation
b6cb116ce063 Change the internal data structure of Purple.ConversationManager to GPtrArray
Gary Kramlich <grim@reaperworld.com>
parents: 43040
diff changeset
773 *****************************************************************************/
b6cb116ce063 Change the internal data structure of Purple.ConversationManager to GPtrArray
Gary Kramlich <grim@reaperworld.com>
parents: 43040
diff changeset
774 G_DEFINE_FINAL_TYPE_WITH_CODE(PurpleConversationManager,
b6cb116ce063 Change the internal data structure of Purple.ConversationManager to GPtrArray
Gary Kramlich <grim@reaperworld.com>
parents: 43040
diff changeset
775 purple_conversation_manager,
b6cb116ce063 Change the internal data structure of Purple.ConversationManager to GPtrArray
Gary Kramlich <grim@reaperworld.com>
parents: 43040
diff changeset
776 G_TYPE_OBJECT,
b6cb116ce063 Change the internal data structure of Purple.ConversationManager to GPtrArray
Gary Kramlich <grim@reaperworld.com>
parents: 43040
diff changeset
777 G_IMPLEMENT_INTERFACE(G_TYPE_LIST_MODEL,
b6cb116ce063 Change the internal data structure of Purple.ConversationManager to GPtrArray
Gary Kramlich <grim@reaperworld.com>
parents: 43040
diff changeset
778 pidgin_conversation_manager_list_model_iface_init))
b6cb116ce063 Change the internal data structure of Purple.ConversationManager to GPtrArray
Gary Kramlich <grim@reaperworld.com>
parents: 43040
diff changeset
779
40948
2c312f084d84 Create a manager for conversations.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
780 static void
2c312f084d84 Create a manager for conversations.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
781 purple_conversation_manager_finalize(GObject *obj) {
2c312f084d84 Create a manager for conversations.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
782 PurpleConversationManager *manager = PURPLE_CONVERSATION_MANAGER(obj);
2c312f084d84 Create a manager for conversations.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
783
43044
b6cb116ce063 Change the internal data structure of Purple.ConversationManager to GPtrArray
Gary Kramlich <grim@reaperworld.com>
parents: 43040
diff changeset
784 g_clear_pointer(&manager->conversations, g_ptr_array_unref);
42777
8b4f02641aa9 The first steps of making the conversation manager persistent
Gary Kramlich <grim@reaperworld.com>
parents: 42736
diff changeset
785 g_clear_pointer(&manager->filename, g_free);
40948
2c312f084d84 Create a manager for conversations.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
786
43283
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
787 g_clear_object(&manager->insert_properties);
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
788 g_clear_object(&manager->insert_tags);
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
789 g_clear_object(&manager->delete_tags);
43284
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
790 g_clear_object(&manager->query_properties);
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
791 g_clear_object(&manager->query_tags);
43283
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
792
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
793 if(manager->db != NULL) {
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
794 GError *error = NULL;
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
795
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
796 seagull_db_close(manager->db, &error);
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
797 if(error != NULL) {
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
798 g_warning("failed to close database: %s", error->message);
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
799 g_clear_error(&error);
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
800 }
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
801 }
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
802
40948
2c312f084d84 Create a manager for conversations.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
803 G_OBJECT_CLASS(purple_conversation_manager_parent_class)->finalize(obj);
2c312f084d84 Create a manager for conversations.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
804 }
2c312f084d84 Create a manager for conversations.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
805
2c312f084d84 Create a manager for conversations.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
806 static void
42777
8b4f02641aa9 The first steps of making the conversation manager persistent
Gary Kramlich <grim@reaperworld.com>
parents: 42736
diff changeset
807 purple_conversation_manager_get_property(GObject *obj, guint param_id,
8b4f02641aa9 The first steps of making the conversation manager persistent
Gary Kramlich <grim@reaperworld.com>
parents: 42736
diff changeset
808 GValue *value, GParamSpec *pspec)
8b4f02641aa9 The first steps of making the conversation manager persistent
Gary Kramlich <grim@reaperworld.com>
parents: 42736
diff changeset
809 {
8b4f02641aa9 The first steps of making the conversation manager persistent
Gary Kramlich <grim@reaperworld.com>
parents: 42736
diff changeset
810 PurpleConversationManager *manager = PURPLE_CONVERSATION_MANAGER(obj);
8b4f02641aa9 The first steps of making the conversation manager persistent
Gary Kramlich <grim@reaperworld.com>
parents: 42736
diff changeset
811
8b4f02641aa9 The first steps of making the conversation manager persistent
Gary Kramlich <grim@reaperworld.com>
parents: 42736
diff changeset
812 switch(param_id) {
8b4f02641aa9 The first steps of making the conversation manager persistent
Gary Kramlich <grim@reaperworld.com>
parents: 42736
diff changeset
813 case PROP_FILENAME:
8b4f02641aa9 The first steps of making the conversation manager persistent
Gary Kramlich <grim@reaperworld.com>
parents: 42736
diff changeset
814 g_value_set_string(value,
8b4f02641aa9 The first steps of making the conversation manager persistent
Gary Kramlich <grim@reaperworld.com>
parents: 42736
diff changeset
815 purple_conversation_manager_get_filename(manager));
8b4f02641aa9 The first steps of making the conversation manager persistent
Gary Kramlich <grim@reaperworld.com>
parents: 42736
diff changeset
816 break;
43044
b6cb116ce063 Change the internal data structure of Purple.ConversationManager to GPtrArray
Gary Kramlich <grim@reaperworld.com>
parents: 43040
diff changeset
817 case PROP_ITEM_TYPE:
b6cb116ce063 Change the internal data structure of Purple.ConversationManager to GPtrArray
Gary Kramlich <grim@reaperworld.com>
parents: 43040
diff changeset
818 g_value_set_gtype(value,
b6cb116ce063 Change the internal data structure of Purple.ConversationManager to GPtrArray
Gary Kramlich <grim@reaperworld.com>
parents: 43040
diff changeset
819 purple_conversation_manager_get_item_type(G_LIST_MODEL(manager)));
b6cb116ce063 Change the internal data structure of Purple.ConversationManager to GPtrArray
Gary Kramlich <grim@reaperworld.com>
parents: 43040
diff changeset
820 break;
b6cb116ce063 Change the internal data structure of Purple.ConversationManager to GPtrArray
Gary Kramlich <grim@reaperworld.com>
parents: 43040
diff changeset
821 case PROP_N_ITEMS:
b6cb116ce063 Change the internal data structure of Purple.ConversationManager to GPtrArray
Gary Kramlich <grim@reaperworld.com>
parents: 43040
diff changeset
822 g_value_set_uint(value,
b6cb116ce063 Change the internal data structure of Purple.ConversationManager to GPtrArray
Gary Kramlich <grim@reaperworld.com>
parents: 43040
diff changeset
823 purple_conversation_manager_get_n_items(G_LIST_MODEL(manager)));
b6cb116ce063 Change the internal data structure of Purple.ConversationManager to GPtrArray
Gary Kramlich <grim@reaperworld.com>
parents: 43040
diff changeset
824 break;
42777
8b4f02641aa9 The first steps of making the conversation manager persistent
Gary Kramlich <grim@reaperworld.com>
parents: 42736
diff changeset
825 default:
8b4f02641aa9 The first steps of making the conversation manager persistent
Gary Kramlich <grim@reaperworld.com>
parents: 42736
diff changeset
826 G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, pspec);
8b4f02641aa9 The first steps of making the conversation manager persistent
Gary Kramlich <grim@reaperworld.com>
parents: 42736
diff changeset
827 break;
8b4f02641aa9 The first steps of making the conversation manager persistent
Gary Kramlich <grim@reaperworld.com>
parents: 42736
diff changeset
828 }
8b4f02641aa9 The first steps of making the conversation manager persistent
Gary Kramlich <grim@reaperworld.com>
parents: 42736
diff changeset
829 }
8b4f02641aa9 The first steps of making the conversation manager persistent
Gary Kramlich <grim@reaperworld.com>
parents: 42736
diff changeset
830
8b4f02641aa9 The first steps of making the conversation manager persistent
Gary Kramlich <grim@reaperworld.com>
parents: 42736
diff changeset
831 static void
8b4f02641aa9 The first steps of making the conversation manager persistent
Gary Kramlich <grim@reaperworld.com>
parents: 42736
diff changeset
832 purple_conversation_manager_set_property(GObject *obj, guint param_id,
8b4f02641aa9 The first steps of making the conversation manager persistent
Gary Kramlich <grim@reaperworld.com>
parents: 42736
diff changeset
833 const GValue *value,
8b4f02641aa9 The first steps of making the conversation manager persistent
Gary Kramlich <grim@reaperworld.com>
parents: 42736
diff changeset
834 GParamSpec *pspec)
8b4f02641aa9 The first steps of making the conversation manager persistent
Gary Kramlich <grim@reaperworld.com>
parents: 42736
diff changeset
835 {
8b4f02641aa9 The first steps of making the conversation manager persistent
Gary Kramlich <grim@reaperworld.com>
parents: 42736
diff changeset
836 PurpleConversationManager *manager = PURPLE_CONVERSATION_MANAGER(obj);
8b4f02641aa9 The first steps of making the conversation manager persistent
Gary Kramlich <grim@reaperworld.com>
parents: 42736
diff changeset
837
8b4f02641aa9 The first steps of making the conversation manager persistent
Gary Kramlich <grim@reaperworld.com>
parents: 42736
diff changeset
838 switch(param_id) {
8b4f02641aa9 The first steps of making the conversation manager persistent
Gary Kramlich <grim@reaperworld.com>
parents: 42736
diff changeset
839 case PROP_FILENAME:
8b4f02641aa9 The first steps of making the conversation manager persistent
Gary Kramlich <grim@reaperworld.com>
parents: 42736
diff changeset
840 purple_conversation_manager_set_filename(manager,
8b4f02641aa9 The first steps of making the conversation manager persistent
Gary Kramlich <grim@reaperworld.com>
parents: 42736
diff changeset
841 g_value_get_string(value));
8b4f02641aa9 The first steps of making the conversation manager persistent
Gary Kramlich <grim@reaperworld.com>
parents: 42736
diff changeset
842 break;
8b4f02641aa9 The first steps of making the conversation manager persistent
Gary Kramlich <grim@reaperworld.com>
parents: 42736
diff changeset
843 default:
8b4f02641aa9 The first steps of making the conversation manager persistent
Gary Kramlich <grim@reaperworld.com>
parents: 42736
diff changeset
844 G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, pspec);
8b4f02641aa9 The first steps of making the conversation manager persistent
Gary Kramlich <grim@reaperworld.com>
parents: 42736
diff changeset
845 break;
8b4f02641aa9 The first steps of making the conversation manager persistent
Gary Kramlich <grim@reaperworld.com>
parents: 42736
diff changeset
846 }
8b4f02641aa9 The first steps of making the conversation manager persistent
Gary Kramlich <grim@reaperworld.com>
parents: 42736
diff changeset
847 }
8b4f02641aa9 The first steps of making the conversation manager persistent
Gary Kramlich <grim@reaperworld.com>
parents: 42736
diff changeset
848
8b4f02641aa9 The first steps of making the conversation manager persistent
Gary Kramlich <grim@reaperworld.com>
parents: 42736
diff changeset
849 static void
43283
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
850 purple_conversation_manager_init(PurpleConversationManager *manager) {
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
851 manager->conversations = g_ptr_array_new_full(10, g_object_unref);
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
852 manager->database_initialized = FALSE;
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
853 }
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
854
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
855 static void
40948
2c312f084d84 Create a manager for conversations.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
856 purple_conversation_manager_class_init(PurpleConversationManagerClass *klass) {
2c312f084d84 Create a manager for conversations.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
857 GObjectClass *obj_class = G_OBJECT_CLASS(klass);
2c312f084d84 Create a manager for conversations.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
858
2c312f084d84 Create a manager for conversations.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
859 obj_class->finalize = purple_conversation_manager_finalize;
42777
8b4f02641aa9 The first steps of making the conversation manager persistent
Gary Kramlich <grim@reaperworld.com>
parents: 42736
diff changeset
860 obj_class->get_property = purple_conversation_manager_get_property;
8b4f02641aa9 The first steps of making the conversation manager persistent
Gary Kramlich <grim@reaperworld.com>
parents: 42736
diff changeset
861 obj_class->set_property = purple_conversation_manager_set_property;
8b4f02641aa9 The first steps of making the conversation manager persistent
Gary Kramlich <grim@reaperworld.com>
parents: 42736
diff changeset
862
8b4f02641aa9 The first steps of making the conversation manager persistent
Gary Kramlich <grim@reaperworld.com>
parents: 42736
diff changeset
863 /**
8b4f02641aa9 The first steps of making the conversation manager persistent
Gary Kramlich <grim@reaperworld.com>
parents: 42736
diff changeset
864 * PurpleConversationManager:filename:
8b4f02641aa9 The first steps of making the conversation manager persistent
Gary Kramlich <grim@reaperworld.com>
parents: 42736
diff changeset
865 *
8b4f02641aa9 The first steps of making the conversation manager persistent
Gary Kramlich <grim@reaperworld.com>
parents: 42736
diff changeset
866 * The filename that the manager should save its contents to.
8b4f02641aa9 The first steps of making the conversation manager persistent
Gary Kramlich <grim@reaperworld.com>
parents: 42736
diff changeset
867 *
8b4f02641aa9 The first steps of making the conversation manager persistent
Gary Kramlich <grim@reaperworld.com>
parents: 42736
diff changeset
868 * If this is %NULL, no serialization will be performed.
8b4f02641aa9 The first steps of making the conversation manager persistent
Gary Kramlich <grim@reaperworld.com>
parents: 42736
diff changeset
869 *
8b4f02641aa9 The first steps of making the conversation manager persistent
Gary Kramlich <grim@reaperworld.com>
parents: 42736
diff changeset
870 * Since: 3.0
8b4f02641aa9 The first steps of making the conversation manager persistent
Gary Kramlich <grim@reaperworld.com>
parents: 42736
diff changeset
871 */
8b4f02641aa9 The first steps of making the conversation manager persistent
Gary Kramlich <grim@reaperworld.com>
parents: 42736
diff changeset
872 properties[PROP_FILENAME] = g_param_spec_string(
8b4f02641aa9 The first steps of making the conversation manager persistent
Gary Kramlich <grim@reaperworld.com>
parents: 42736
diff changeset
873 "filename", NULL, NULL,
8b4f02641aa9 The first steps of making the conversation manager persistent
Gary Kramlich <grim@reaperworld.com>
parents: 42736
diff changeset
874 NULL,
8b4f02641aa9 The first steps of making the conversation manager persistent
Gary Kramlich <grim@reaperworld.com>
parents: 42736
diff changeset
875 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
8b4f02641aa9 The first steps of making the conversation manager persistent
Gary Kramlich <grim@reaperworld.com>
parents: 42736
diff changeset
876
43044
b6cb116ce063 Change the internal data structure of Purple.ConversationManager to GPtrArray
Gary Kramlich <grim@reaperworld.com>
parents: 43040
diff changeset
877 /**
b6cb116ce063 Change the internal data structure of Purple.ConversationManager to GPtrArray
Gary Kramlich <grim@reaperworld.com>
parents: 43040
diff changeset
878 * PurpleConversationManager:item-type:
b6cb116ce063 Change the internal data structure of Purple.ConversationManager to GPtrArray
Gary Kramlich <grim@reaperworld.com>
parents: 43040
diff changeset
879 *
b6cb116ce063 Change the internal data structure of Purple.ConversationManager to GPtrArray
Gary Kramlich <grim@reaperworld.com>
parents: 43040
diff changeset
880 * The type of items. See [vfunc@Gio.ListModel.get_item_type].
b6cb116ce063 Change the internal data structure of Purple.ConversationManager to GPtrArray
Gary Kramlich <grim@reaperworld.com>
parents: 43040
diff changeset
881 *
b6cb116ce063 Change the internal data structure of Purple.ConversationManager to GPtrArray
Gary Kramlich <grim@reaperworld.com>
parents: 43040
diff changeset
882 * Since: 3.0
b6cb116ce063 Change the internal data structure of Purple.ConversationManager to GPtrArray
Gary Kramlich <grim@reaperworld.com>
parents: 43040
diff changeset
883 */
b6cb116ce063 Change the internal data structure of Purple.ConversationManager to GPtrArray
Gary Kramlich <grim@reaperworld.com>
parents: 43040
diff changeset
884 properties[PROP_ITEM_TYPE] = g_param_spec_gtype(
43071
071588186662 Remove nick and blurb from libpurple properties
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 43046
diff changeset
885 "item-type", NULL, NULL,
43044
b6cb116ce063 Change the internal data structure of Purple.ConversationManager to GPtrArray
Gary Kramlich <grim@reaperworld.com>
parents: 43040
diff changeset
886 G_TYPE_OBJECT,
b6cb116ce063 Change the internal data structure of Purple.ConversationManager to GPtrArray
Gary Kramlich <grim@reaperworld.com>
parents: 43040
diff changeset
887 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
b6cb116ce063 Change the internal data structure of Purple.ConversationManager to GPtrArray
Gary Kramlich <grim@reaperworld.com>
parents: 43040
diff changeset
888
b6cb116ce063 Change the internal data structure of Purple.ConversationManager to GPtrArray
Gary Kramlich <grim@reaperworld.com>
parents: 43040
diff changeset
889 /**
b6cb116ce063 Change the internal data structure of Purple.ConversationManager to GPtrArray
Gary Kramlich <grim@reaperworld.com>
parents: 43040
diff changeset
890 * PurpleConversationManager:n-items:
b6cb116ce063 Change the internal data structure of Purple.ConversationManager to GPtrArray
Gary Kramlich <grim@reaperworld.com>
parents: 43040
diff changeset
891 *
b6cb116ce063 Change the internal data structure of Purple.ConversationManager to GPtrArray
Gary Kramlich <grim@reaperworld.com>
parents: 43040
diff changeset
892 * The number of items. See [vfunc@Gio.ListModel.get_n_items].
b6cb116ce063 Change the internal data structure of Purple.ConversationManager to GPtrArray
Gary Kramlich <grim@reaperworld.com>
parents: 43040
diff changeset
893 *
b6cb116ce063 Change the internal data structure of Purple.ConversationManager to GPtrArray
Gary Kramlich <grim@reaperworld.com>
parents: 43040
diff changeset
894 * Since: 3.0
b6cb116ce063 Change the internal data structure of Purple.ConversationManager to GPtrArray
Gary Kramlich <grim@reaperworld.com>
parents: 43040
diff changeset
895 */
b6cb116ce063 Change the internal data structure of Purple.ConversationManager to GPtrArray
Gary Kramlich <grim@reaperworld.com>
parents: 43040
diff changeset
896 properties[PROP_N_ITEMS] = g_param_spec_uint(
43071
071588186662 Remove nick and blurb from libpurple properties
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 43046
diff changeset
897 "n-items", NULL, NULL,
43044
b6cb116ce063 Change the internal data structure of Purple.ConversationManager to GPtrArray
Gary Kramlich <grim@reaperworld.com>
parents: 43040
diff changeset
898 0, G_MAXUINT, 0,
b6cb116ce063 Change the internal data structure of Purple.ConversationManager to GPtrArray
Gary Kramlich <grim@reaperworld.com>
parents: 43040
diff changeset
899 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
b6cb116ce063 Change the internal data structure of Purple.ConversationManager to GPtrArray
Gary Kramlich <grim@reaperworld.com>
parents: 43040
diff changeset
900
42777
8b4f02641aa9 The first steps of making the conversation manager persistent
Gary Kramlich <grim@reaperworld.com>
parents: 42736
diff changeset
901 g_object_class_install_properties(obj_class, N_PROPERTIES, properties);
41226
a51ff7ecf053 Add registered and unregistered signals to PurpleConversationManager
Gary Kramlich <grim@reaperworld.com>
parents: 40986
diff changeset
902
a51ff7ecf053 Add registered and unregistered signals to PurpleConversationManager
Gary Kramlich <grim@reaperworld.com>
parents: 40986
diff changeset
903 /**
43029
b95b2d2b8200 Rename Purple.ConversationManager.register/unregister to add/remove
Gary Kramlich <grim@reaperworld.com>
parents: 42997
diff changeset
904 * PurpleConversationManager::added:
b95b2d2b8200 Rename Purple.ConversationManager.register/unregister to add/remove
Gary Kramlich <grim@reaperworld.com>
parents: 42997
diff changeset
905 * @manager: The manager.
b95b2d2b8200 Rename Purple.ConversationManager.register/unregister to add/remove
Gary Kramlich <grim@reaperworld.com>
parents: 42997
diff changeset
906 * @conversation: The conversation that was added.
b95b2d2b8200 Rename Purple.ConversationManager.register/unregister to add/remove
Gary Kramlich <grim@reaperworld.com>
parents: 42997
diff changeset
907 *
b95b2d2b8200 Rename Purple.ConversationManager.register/unregister to add/remove
Gary Kramlich <grim@reaperworld.com>
parents: 42997
diff changeset
908 * Emitted after @conversation has been added to @manager.
b95b2d2b8200 Rename Purple.ConversationManager.register/unregister to add/remove
Gary Kramlich <grim@reaperworld.com>
parents: 42997
diff changeset
909 *
b95b2d2b8200 Rename Purple.ConversationManager.register/unregister to add/remove
Gary Kramlich <grim@reaperworld.com>
parents: 42997
diff changeset
910 * Since: 3.0
b95b2d2b8200 Rename Purple.ConversationManager.register/unregister to add/remove
Gary Kramlich <grim@reaperworld.com>
parents: 42997
diff changeset
911 */
b95b2d2b8200 Rename Purple.ConversationManager.register/unregister to add/remove
Gary Kramlich <grim@reaperworld.com>
parents: 42997
diff changeset
912 signals[SIG_ADDED] = g_signal_new_class_handler(
b95b2d2b8200 Rename Purple.ConversationManager.register/unregister to add/remove
Gary Kramlich <grim@reaperworld.com>
parents: 42997
diff changeset
913 "added",
b95b2d2b8200 Rename Purple.ConversationManager.register/unregister to add/remove
Gary Kramlich <grim@reaperworld.com>
parents: 42997
diff changeset
914 G_OBJECT_CLASS_TYPE(klass),
b95b2d2b8200 Rename Purple.ConversationManager.register/unregister to add/remove
Gary Kramlich <grim@reaperworld.com>
parents: 42997
diff changeset
915 G_SIGNAL_RUN_LAST,
b95b2d2b8200 Rename Purple.ConversationManager.register/unregister to add/remove
Gary Kramlich <grim@reaperworld.com>
parents: 42997
diff changeset
916 NULL,
b95b2d2b8200 Rename Purple.ConversationManager.register/unregister to add/remove
Gary Kramlich <grim@reaperworld.com>
parents: 42997
diff changeset
917 NULL,
b95b2d2b8200 Rename Purple.ConversationManager.register/unregister to add/remove
Gary Kramlich <grim@reaperworld.com>
parents: 42997
diff changeset
918 NULL,
b95b2d2b8200 Rename Purple.ConversationManager.register/unregister to add/remove
Gary Kramlich <grim@reaperworld.com>
parents: 42997
diff changeset
919 NULL,
b95b2d2b8200 Rename Purple.ConversationManager.register/unregister to add/remove
Gary Kramlich <grim@reaperworld.com>
parents: 42997
diff changeset
920 G_TYPE_NONE,
b95b2d2b8200 Rename Purple.ConversationManager.register/unregister to add/remove
Gary Kramlich <grim@reaperworld.com>
parents: 42997
diff changeset
921 1,
b95b2d2b8200 Rename Purple.ConversationManager.register/unregister to add/remove
Gary Kramlich <grim@reaperworld.com>
parents: 42997
diff changeset
922 PURPLE_TYPE_CONVERSATION);
b95b2d2b8200 Rename Purple.ConversationManager.register/unregister to add/remove
Gary Kramlich <grim@reaperworld.com>
parents: 42997
diff changeset
923
b95b2d2b8200 Rename Purple.ConversationManager.register/unregister to add/remove
Gary Kramlich <grim@reaperworld.com>
parents: 42997
diff changeset
924 /**
b95b2d2b8200 Rename Purple.ConversationManager.register/unregister to add/remove
Gary Kramlich <grim@reaperworld.com>
parents: 42997
diff changeset
925 * PurpleConversationManager::removed:
b95b2d2b8200 Rename Purple.ConversationManager.register/unregister to add/remove
Gary Kramlich <grim@reaperworld.com>
parents: 42997
diff changeset
926 * @manager: The manager.
b95b2d2b8200 Rename Purple.ConversationManager.register/unregister to add/remove
Gary Kramlich <grim@reaperworld.com>
parents: 42997
diff changeset
927 * @conversation: The conversation that was removed.
b95b2d2b8200 Rename Purple.ConversationManager.register/unregister to add/remove
Gary Kramlich <grim@reaperworld.com>
parents: 42997
diff changeset
928 *
b95b2d2b8200 Rename Purple.ConversationManager.register/unregister to add/remove
Gary Kramlich <grim@reaperworld.com>
parents: 42997
diff changeset
929 * Emitted after @conversation has been removed from @manager.
b95b2d2b8200 Rename Purple.ConversationManager.register/unregister to add/remove
Gary Kramlich <grim@reaperworld.com>
parents: 42997
diff changeset
930 *
b95b2d2b8200 Rename Purple.ConversationManager.register/unregister to add/remove
Gary Kramlich <grim@reaperworld.com>
parents: 42997
diff changeset
931 * Since: 3.0
b95b2d2b8200 Rename Purple.ConversationManager.register/unregister to add/remove
Gary Kramlich <grim@reaperworld.com>
parents: 42997
diff changeset
932 */
b95b2d2b8200 Rename Purple.ConversationManager.register/unregister to add/remove
Gary Kramlich <grim@reaperworld.com>
parents: 42997
diff changeset
933 signals[SIG_REMOVED] = g_signal_new_class_handler(
b95b2d2b8200 Rename Purple.ConversationManager.register/unregister to add/remove
Gary Kramlich <grim@reaperworld.com>
parents: 42997
diff changeset
934 "removed",
b95b2d2b8200 Rename Purple.ConversationManager.register/unregister to add/remove
Gary Kramlich <grim@reaperworld.com>
parents: 42997
diff changeset
935 G_OBJECT_CLASS_TYPE(klass),
b95b2d2b8200 Rename Purple.ConversationManager.register/unregister to add/remove
Gary Kramlich <grim@reaperworld.com>
parents: 42997
diff changeset
936 G_SIGNAL_RUN_LAST,
b95b2d2b8200 Rename Purple.ConversationManager.register/unregister to add/remove
Gary Kramlich <grim@reaperworld.com>
parents: 42997
diff changeset
937 NULL,
b95b2d2b8200 Rename Purple.ConversationManager.register/unregister to add/remove
Gary Kramlich <grim@reaperworld.com>
parents: 42997
diff changeset
938 NULL,
b95b2d2b8200 Rename Purple.ConversationManager.register/unregister to add/remove
Gary Kramlich <grim@reaperworld.com>
parents: 42997
diff changeset
939 NULL,
b95b2d2b8200 Rename Purple.ConversationManager.register/unregister to add/remove
Gary Kramlich <grim@reaperworld.com>
parents: 42997
diff changeset
940 NULL,
b95b2d2b8200 Rename Purple.ConversationManager.register/unregister to add/remove
Gary Kramlich <grim@reaperworld.com>
parents: 42997
diff changeset
941 G_TYPE_NONE,
b95b2d2b8200 Rename Purple.ConversationManager.register/unregister to add/remove
Gary Kramlich <grim@reaperworld.com>
parents: 42997
diff changeset
942 1,
b95b2d2b8200 Rename Purple.ConversationManager.register/unregister to add/remove
Gary Kramlich <grim@reaperworld.com>
parents: 42997
diff changeset
943 PURPLE_TYPE_CONVERSATION);
b95b2d2b8200 Rename Purple.ConversationManager.register/unregister to add/remove
Gary Kramlich <grim@reaperworld.com>
parents: 42997
diff changeset
944
b95b2d2b8200 Rename Purple.ConversationManager.register/unregister to add/remove
Gary Kramlich <grim@reaperworld.com>
parents: 42997
diff changeset
945 /**
42286
3fe515350d59 Add a conversation-changed signal to PurpleConversationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42272
diff changeset
946 * PurpleConversationManager::conversation-changed:
3fe515350d59 Add a conversation-changed signal to PurpleConversationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42272
diff changeset
947 * @manager: The account manager instance.
3fe515350d59 Add a conversation-changed signal to PurpleConversationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42272
diff changeset
948 * @conversation: The conversation that was changed.
3fe515350d59 Add a conversation-changed signal to PurpleConversationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42272
diff changeset
949 * @pspec: The [class@GObject.ParamSpec] for the property that changed.
3fe515350d59 Add a conversation-changed signal to PurpleConversationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42272
diff changeset
950 *
3fe515350d59 Add a conversation-changed signal to PurpleConversationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42272
diff changeset
951 * This is a propagation of the notify signal from @conversation. This
3fe515350d59 Add a conversation-changed signal to PurpleConversationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42272
diff changeset
952 * means that your callback will be called for any conversation that
3fe515350d59 Add a conversation-changed signal to PurpleConversationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42272
diff changeset
953 * @manager knows about.
3fe515350d59 Add a conversation-changed signal to PurpleConversationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42272
diff changeset
954 *
3fe515350d59 Add a conversation-changed signal to PurpleConversationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42272
diff changeset
955 * This also supports details, so you can specify the signal name as
3fe515350d59 Add a conversation-changed signal to PurpleConversationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42272
diff changeset
956 * something like `conversation-changed::title` and your callback will only
3fe515350d59 Add a conversation-changed signal to PurpleConversationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42272
diff changeset
957 * be called when [property@Conversation:title] has been changed.
3fe515350d59 Add a conversation-changed signal to PurpleConversationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42272
diff changeset
958 *
42613
780d7efe37c2 Remove the micro version from since tags for libpurple part 2
Gary Kramlich <grim@reaperworld.com>
parents: 42594
diff changeset
959 * Since: 3.0
42286
3fe515350d59 Add a conversation-changed signal to PurpleConversationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42272
diff changeset
960 */
3fe515350d59 Add a conversation-changed signal to PurpleConversationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42272
diff changeset
961 signals[SIG_CONVERSATION_CHANGED] = g_signal_new_class_handler(
3fe515350d59 Add a conversation-changed signal to PurpleConversationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42272
diff changeset
962 "conversation-changed",
3fe515350d59 Add a conversation-changed signal to PurpleConversationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42272
diff changeset
963 G_OBJECT_CLASS_TYPE(klass),
3fe515350d59 Add a conversation-changed signal to PurpleConversationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42272
diff changeset
964 G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
3fe515350d59 Add a conversation-changed signal to PurpleConversationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42272
diff changeset
965 NULL,
3fe515350d59 Add a conversation-changed signal to PurpleConversationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42272
diff changeset
966 NULL,
3fe515350d59 Add a conversation-changed signal to PurpleConversationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42272
diff changeset
967 NULL,
3fe515350d59 Add a conversation-changed signal to PurpleConversationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42272
diff changeset
968 NULL,
3fe515350d59 Add a conversation-changed signal to PurpleConversationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42272
diff changeset
969 G_TYPE_NONE,
3fe515350d59 Add a conversation-changed signal to PurpleConversationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42272
diff changeset
970 2,
3fe515350d59 Add a conversation-changed signal to PurpleConversationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42272
diff changeset
971 PURPLE_TYPE_CONVERSATION,
3fe515350d59 Add a conversation-changed signal to PurpleConversationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42272
diff changeset
972 G_TYPE_PARAM);
42736
630084f39cc5 Add a present signal to PurpleConversation and propagate it from PurpleConversationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42725
diff changeset
973
630084f39cc5 Add a present signal to PurpleConversation and propagate it from PurpleConversationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42725
diff changeset
974 /**
630084f39cc5 Add a present signal to PurpleConversation and propagate it from PurpleConversationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42725
diff changeset
975 * PurpleConversationManager::present-conversation:
630084f39cc5 Add a present signal to PurpleConversation and propagate it from PurpleConversationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42725
diff changeset
976 * @manager: The instance.
630084f39cc5 Add a present signal to PurpleConversation and propagate it from PurpleConversationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42725
diff changeset
977 * @conversation: The conversation that should be presented.
630084f39cc5 Add a present signal to PurpleConversation and propagate it from PurpleConversationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42725
diff changeset
978 *
630084f39cc5 Add a present signal to PurpleConversation and propagate it from PurpleConversationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42725
diff changeset
979 * This is a propagation of [signal@Conversation::present]. This means that
630084f39cc5 Add a present signal to PurpleConversation and propagate it from PurpleConversationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42725
diff changeset
980 * your callback will be called for any conversation that @manager knows
630084f39cc5 Add a present signal to PurpleConversation and propagate it from PurpleConversationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42725
diff changeset
981 * about.
630084f39cc5 Add a present signal to PurpleConversation and propagate it from PurpleConversationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42725
diff changeset
982 *
630084f39cc5 Add a present signal to PurpleConversation and propagate it from PurpleConversationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42725
diff changeset
983 * Since: 3.0
630084f39cc5 Add a present signal to PurpleConversation and propagate it from PurpleConversationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42725
diff changeset
984 */
630084f39cc5 Add a present signal to PurpleConversation and propagate it from PurpleConversationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42725
diff changeset
985 signals[SIG_PRESENT_CONVERSATION] = g_signal_new_class_handler(
630084f39cc5 Add a present signal to PurpleConversation and propagate it from PurpleConversationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42725
diff changeset
986 "present-conversation",
630084f39cc5 Add a present signal to PurpleConversation and propagate it from PurpleConversationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42725
diff changeset
987 G_OBJECT_CLASS_TYPE(klass),
630084f39cc5 Add a present signal to PurpleConversation and propagate it from PurpleConversationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42725
diff changeset
988 G_SIGNAL_RUN_LAST,
630084f39cc5 Add a present signal to PurpleConversation and propagate it from PurpleConversationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42725
diff changeset
989 NULL,
630084f39cc5 Add a present signal to PurpleConversation and propagate it from PurpleConversationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42725
diff changeset
990 NULL,
630084f39cc5 Add a present signal to PurpleConversation and propagate it from PurpleConversationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42725
diff changeset
991 NULL,
630084f39cc5 Add a present signal to PurpleConversation and propagate it from PurpleConversationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42725
diff changeset
992 NULL,
630084f39cc5 Add a present signal to PurpleConversation and propagate it from PurpleConversationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42725
diff changeset
993 G_TYPE_NONE,
630084f39cc5 Add a present signal to PurpleConversation and propagate it from PurpleConversationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42725
diff changeset
994 1,
630084f39cc5 Add a present signal to PurpleConversation and propagate it from PurpleConversationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42725
diff changeset
995 PURPLE_TYPE_CONVERSATION);
40948
2c312f084d84 Create a manager for conversations.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
996 }
2c312f084d84 Create a manager for conversations.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
997
2c312f084d84 Create a manager for conversations.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
998 /******************************************************************************
2c312f084d84 Create a manager for conversations.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
999 * Private API
2c312f084d84 Create a manager for conversations.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
1000 *****************************************************************************/
2c312f084d84 Create a manager for conversations.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
1001 void
2c312f084d84 Create a manager for conversations.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
1002 purple_conversation_manager_startup(void) {
2c312f084d84 Create a manager for conversations.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
1003 if(default_manager == NULL) {
42777
8b4f02641aa9 The first steps of making the conversation manager persistent
Gary Kramlich <grim@reaperworld.com>
parents: 42736
diff changeset
1004 PurpleUi *ui = purple_core_get_ui();
8b4f02641aa9 The first steps of making the conversation manager persistent
Gary Kramlich <grim@reaperworld.com>
parents: 42736
diff changeset
1005
8b4f02641aa9 The first steps of making the conversation manager persistent
Gary Kramlich <grim@reaperworld.com>
parents: 42736
diff changeset
1006 default_manager = purple_ui_get_conversation_manager(ui);
8b4f02641aa9 The first steps of making the conversation manager persistent
Gary Kramlich <grim@reaperworld.com>
parents: 42736
diff changeset
1007 if(PURPLE_IS_CONVERSATION_MANAGER(default_manager)) {
8b4f02641aa9 The first steps of making the conversation manager persistent
Gary Kramlich <grim@reaperworld.com>
parents: 42736
diff changeset
1008 g_object_add_weak_pointer(G_OBJECT(default_manager),
8b4f02641aa9 The first steps of making the conversation manager persistent
Gary Kramlich <grim@reaperworld.com>
parents: 42736
diff changeset
1009 (gpointer *)&default_manager);
8b4f02641aa9 The first steps of making the conversation manager persistent
Gary Kramlich <grim@reaperworld.com>
parents: 42736
diff changeset
1010 }
40948
2c312f084d84 Create a manager for conversations.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
1011 }
43284
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
1012
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
1013 /* Load conversations. */
50c1bcc45576 Load conversations back in from the database
Gary Kramlich <grim@reaperworld.com>
parents: 43283
diff changeset
1014 purple_conversation_manager_load_conversations(default_manager);
40948
2c312f084d84 Create a manager for conversations.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
1015 }
2c312f084d84 Create a manager for conversations.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
1016
2c312f084d84 Create a manager for conversations.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
1017 void
2c312f084d84 Create a manager for conversations.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
1018 purple_conversation_manager_shutdown(void) {
2c312f084d84 Create a manager for conversations.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
1019 g_clear_object(&default_manager);
2c312f084d84 Create a manager for conversations.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
1020 }
2c312f084d84 Create a manager for conversations.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
1021
2c312f084d84 Create a manager for conversations.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
1022 /******************************************************************************
2c312f084d84 Create a manager for conversations.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
1023 * Public API
2c312f084d84 Create a manager for conversations.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
1024 *****************************************************************************/
43029
b95b2d2b8200 Rename Purple.ConversationManager.register/unregister to add/remove
Gary Kramlich <grim@reaperworld.com>
parents: 42997
diff changeset
1025 gboolean
b95b2d2b8200 Rename Purple.ConversationManager.register/unregister to add/remove
Gary Kramlich <grim@reaperworld.com>
parents: 42997
diff changeset
1026 purple_conversation_manager_add(PurpleConversationManager *manager,
b95b2d2b8200 Rename Purple.ConversationManager.register/unregister to add/remove
Gary Kramlich <grim@reaperworld.com>
parents: 42997
diff changeset
1027 PurpleConversation *conversation)
b95b2d2b8200 Rename Purple.ConversationManager.register/unregister to add/remove
Gary Kramlich <grim@reaperworld.com>
parents: 42997
diff changeset
1028 {
43046
eeab15f4576e Call g_list_model_items_changed as necessary in Purple.ConversationManager
Gary Kramlich <grim@reaperworld.com>
parents: 43044
diff changeset
1029 guint position = 0;
eeab15f4576e Call g_list_model_items_changed as necessary in Purple.ConversationManager
Gary Kramlich <grim@reaperworld.com>
parents: 43044
diff changeset
1030
43029
b95b2d2b8200 Rename Purple.ConversationManager.register/unregister to add/remove
Gary Kramlich <grim@reaperworld.com>
parents: 42997
diff changeset
1031 g_return_val_if_fail(PURPLE_IS_CONVERSATION_MANAGER(manager), FALSE);
b95b2d2b8200 Rename Purple.ConversationManager.register/unregister to add/remove
Gary Kramlich <grim@reaperworld.com>
parents: 42997
diff changeset
1032 g_return_val_if_fail(PURPLE_IS_CONVERSATION(conversation), FALSE);
b95b2d2b8200 Rename Purple.ConversationManager.register/unregister to add/remove
Gary Kramlich <grim@reaperworld.com>
parents: 42997
diff changeset
1033
43044
b6cb116ce063 Change the internal data structure of Purple.ConversationManager to GPtrArray
Gary Kramlich <grim@reaperworld.com>
parents: 43040
diff changeset
1034 if(g_ptr_array_find(manager->conversations, conversation, NULL)) {
b6cb116ce063 Change the internal data structure of Purple.ConversationManager to GPtrArray
Gary Kramlich <grim@reaperworld.com>
parents: 43040
diff changeset
1035 return FALSE;
43029
b95b2d2b8200 Rename Purple.ConversationManager.register/unregister to add/remove
Gary Kramlich <grim@reaperworld.com>
parents: 42997
diff changeset
1036 }
b95b2d2b8200 Rename Purple.ConversationManager.register/unregister to add/remove
Gary Kramlich <grim@reaperworld.com>
parents: 42997
diff changeset
1037
43046
eeab15f4576e Call g_list_model_items_changed as necessary in Purple.ConversationManager
Gary Kramlich <grim@reaperworld.com>
parents: 43044
diff changeset
1038 position = manager->conversations->len;
43044
b6cb116ce063 Change the internal data structure of Purple.ConversationManager to GPtrArray
Gary Kramlich <grim@reaperworld.com>
parents: 43040
diff changeset
1039 g_ptr_array_add(manager->conversations, g_object_ref(conversation));
b6cb116ce063 Change the internal data structure of Purple.ConversationManager to GPtrArray
Gary Kramlich <grim@reaperworld.com>
parents: 43040
diff changeset
1040
b6cb116ce063 Change the internal data structure of Purple.ConversationManager to GPtrArray
Gary Kramlich <grim@reaperworld.com>
parents: 43040
diff changeset
1041 /* Register our signals that need to be propagated. */
b6cb116ce063 Change the internal data structure of Purple.ConversationManager to GPtrArray
Gary Kramlich <grim@reaperworld.com>
parents: 43040
diff changeset
1042 g_signal_connect_object(conversation, "notify",
b6cb116ce063 Change the internal data structure of Purple.ConversationManager to GPtrArray
Gary Kramlich <grim@reaperworld.com>
parents: 43040
diff changeset
1043 G_CALLBACK(purple_conversation_manager_conversation_changed_cb),
b6cb116ce063 Change the internal data structure of Purple.ConversationManager to GPtrArray
Gary Kramlich <grim@reaperworld.com>
parents: 43040
diff changeset
1044 manager, 0);
b6cb116ce063 Change the internal data structure of Purple.ConversationManager to GPtrArray
Gary Kramlich <grim@reaperworld.com>
parents: 43040
diff changeset
1045 g_signal_connect_object(conversation, "present",
b6cb116ce063 Change the internal data structure of Purple.ConversationManager to GPtrArray
Gary Kramlich <grim@reaperworld.com>
parents: 43040
diff changeset
1046 G_CALLBACK(purple_conversation_manager_present_conversation_cb),
b6cb116ce063 Change the internal data structure of Purple.ConversationManager to GPtrArray
Gary Kramlich <grim@reaperworld.com>
parents: 43040
diff changeset
1047 manager, 0);
b6cb116ce063 Change the internal data structure of Purple.ConversationManager to GPtrArray
Gary Kramlich <grim@reaperworld.com>
parents: 43040
diff changeset
1048
b6cb116ce063 Change the internal data structure of Purple.ConversationManager to GPtrArray
Gary Kramlich <grim@reaperworld.com>
parents: 43040
diff changeset
1049 /* Tell everyone about the new conversation. */
b6cb116ce063 Change the internal data structure of Purple.ConversationManager to GPtrArray
Gary Kramlich <grim@reaperworld.com>
parents: 43040
diff changeset
1050 g_signal_emit(manager, signals[SIG_ADDED], 0, conversation);
43046
eeab15f4576e Call g_list_model_items_changed as necessary in Purple.ConversationManager
Gary Kramlich <grim@reaperworld.com>
parents: 43044
diff changeset
1051 g_list_model_items_changed(G_LIST_MODEL(manager), position, 0, 1);
43128
1ce3ad90614c Make sure we notify on the n-items property for all objects that have it
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
1052 g_object_notify_by_pspec(G_OBJECT(manager), properties[PROP_N_ITEMS]);
43044
b6cb116ce063 Change the internal data structure of Purple.ConversationManager to GPtrArray
Gary Kramlich <grim@reaperworld.com>
parents: 43040
diff changeset
1053
43283
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
1054 purple_conversation_manager_save_conversation(manager, conversation);
01eb1bbf4186 Serialize conversations and their tags
Gary Kramlich <grim@reaperworld.com>
parents: 43132
diff changeset
1055
43044
b6cb116ce063 Change the internal data structure of Purple.ConversationManager to GPtrArray
Gary Kramlich <grim@reaperworld.com>
parents: 43040
diff changeset
1056 return TRUE;
43029
b95b2d2b8200 Rename Purple.ConversationManager.register/unregister to add/remove
Gary Kramlich <grim@reaperworld.com>
parents: 42997
diff changeset
1057 }
b95b2d2b8200 Rename Purple.ConversationManager.register/unregister to add/remove
Gary Kramlich <grim@reaperworld.com>
parents: 42997
diff changeset
1058
40948
2c312f084d84 Create a manager for conversations.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
1059 PurpleConversationManager *
42777
8b4f02641aa9 The first steps of making the conversation manager persistent
Gary Kramlich <grim@reaperworld.com>
parents: 42736
diff changeset
1060 purple_conversation_manager_new(const char *filename) {
8b4f02641aa9 The first steps of making the conversation manager persistent
Gary Kramlich <grim@reaperworld.com>
parents: 42736
diff changeset
1061 return g_object_new(
8b4f02641aa9 The first steps of making the conversation manager persistent
Gary Kramlich <grim@reaperworld.com>
parents: 42736
diff changeset
1062 PURPLE_TYPE_CONVERSATION_MANAGER,
8b4f02641aa9 The first steps of making the conversation manager persistent
Gary Kramlich <grim@reaperworld.com>
parents: 42736
diff changeset
1063 "filename", filename,
8b4f02641aa9 The first steps of making the conversation manager persistent
Gary Kramlich <grim@reaperworld.com>
parents: 42736
diff changeset
1064 NULL);
8b4f02641aa9 The first steps of making the conversation manager persistent
Gary Kramlich <grim@reaperworld.com>
parents: 42736
diff changeset
1065 }
8b4f02641aa9 The first steps of making the conversation manager persistent
Gary Kramlich <grim@reaperworld.com>
parents: 42736
diff changeset
1066
8b4f02641aa9 The first steps of making the conversation manager persistent
Gary Kramlich <grim@reaperworld.com>
parents: 42736
diff changeset
1067 PurpleConversationManager *
40948
2c312f084d84 Create a manager for conversations.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
1068 purple_conversation_manager_get_default(void) {
2c312f084d84 Create a manager for conversations.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
1069 return default_manager;
2c312f084d84 Create a manager for conversations.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
1070 }
2c312f084d84 Create a manager for conversations.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
1071
43044
b6cb116ce063 Change the internal data structure of Purple.ConversationManager to GPtrArray
Gary Kramlich <grim@reaperworld.com>
parents: 43040
diff changeset
1072 GListModel *
b6cb116ce063 Change the internal data structure of Purple.ConversationManager to GPtrArray
Gary Kramlich <grim@reaperworld.com>
parents: 43040
diff changeset
1073 purple_conversation_manager_get_default_as_model(void) {
b6cb116ce063 Change the internal data structure of Purple.ConversationManager to GPtrArray
Gary Kramlich <grim@reaperworld.com>
parents: 43040
diff changeset
1074 if(PURPLE_IS_CONVERSATION_MANAGER(default_manager)) {
b6cb116ce063 Change the internal data structure of Purple.ConversationManager to GPtrArray
Gary Kramlich <grim@reaperworld.com>
parents: 43040
diff changeset
1075 return G_LIST_MODEL(default_manager);
b6cb116ce063 Change the internal data structure of Purple.ConversationManager to GPtrArray
Gary Kramlich <grim@reaperworld.com>
parents: 43040
diff changeset
1076 }
b6cb116ce063 Change the internal data structure of Purple.ConversationManager to GPtrArray
Gary Kramlich <grim@reaperworld.com>
parents: 43040
diff changeset
1077
b6cb116ce063 Change the internal data structure of Purple.ConversationManager to GPtrArray
Gary Kramlich <grim@reaperworld.com>
parents: 43040
diff changeset
1078 return NULL;
b6cb116ce063 Change the internal data structure of Purple.ConversationManager to GPtrArray
Gary Kramlich <grim@reaperworld.com>
parents: 43040
diff changeset
1079 }
b6cb116ce063 Change the internal data structure of Purple.ConversationManager to GPtrArray
Gary Kramlich <grim@reaperworld.com>
parents: 43040
diff changeset
1080
42777
8b4f02641aa9 The first steps of making the conversation manager persistent
Gary Kramlich <grim@reaperworld.com>
parents: 42736
diff changeset
1081 const char *
8b4f02641aa9 The first steps of making the conversation manager persistent
Gary Kramlich <grim@reaperworld.com>
parents: 42736
diff changeset
1082 purple_conversation_manager_get_filename(PurpleConversationManager *manager) {
8b4f02641aa9 The first steps of making the conversation manager persistent
Gary Kramlich <grim@reaperworld.com>
parents: 42736
diff changeset
1083 g_return_val_if_fail(PURPLE_IS_CONVERSATION_MANAGER(manager), NULL);
8b4f02641aa9 The first steps of making the conversation manager persistent
Gary Kramlich <grim@reaperworld.com>
parents: 42736
diff changeset
1084
8b4f02641aa9 The first steps of making the conversation manager persistent
Gary Kramlich <grim@reaperworld.com>
parents: 42736
diff changeset
1085 return manager->filename;
8b4f02641aa9 The first steps of making the conversation manager persistent
Gary Kramlich <grim@reaperworld.com>
parents: 42736
diff changeset
1086 }
8b4f02641aa9 The first steps of making the conversation manager persistent
Gary Kramlich <grim@reaperworld.com>
parents: 42736
diff changeset
1087
40948
2c312f084d84 Create a manager for conversations.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
1088 GList *
2c312f084d84 Create a manager for conversations.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
1089 purple_conversation_manager_get_all(PurpleConversationManager *manager) {
43044
b6cb116ce063 Change the internal data structure of Purple.ConversationManager to GPtrArray
Gary Kramlich <grim@reaperworld.com>
parents: 43040
diff changeset
1090 GList *result = NULL;
40948
2c312f084d84 Create a manager for conversations.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
1091 g_return_val_if_fail(PURPLE_IS_CONVERSATION_MANAGER(manager), NULL);
2c312f084d84 Create a manager for conversations.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
1092
43044
b6cb116ce063 Change the internal data structure of Purple.ConversationManager to GPtrArray
Gary Kramlich <grim@reaperworld.com>
parents: 43040
diff changeset
1093 for(guint i = 0; i < manager->conversations->len; i++) {
b6cb116ce063 Change the internal data structure of Purple.ConversationManager to GPtrArray
Gary Kramlich <grim@reaperworld.com>
parents: 43040
diff changeset
1094 PurpleConversation *conversation = NULL;
b6cb116ce063 Change the internal data structure of Purple.ConversationManager to GPtrArray
Gary Kramlich <grim@reaperworld.com>
parents: 43040
diff changeset
1095
b6cb116ce063 Change the internal data structure of Purple.ConversationManager to GPtrArray
Gary Kramlich <grim@reaperworld.com>
parents: 43040
diff changeset
1096 conversation = g_ptr_array_index(manager->conversations, i);
b6cb116ce063 Change the internal data structure of Purple.ConversationManager to GPtrArray
Gary Kramlich <grim@reaperworld.com>
parents: 43040
diff changeset
1097 result = g_list_append(result, conversation);
b6cb116ce063 Change the internal data structure of Purple.ConversationManager to GPtrArray
Gary Kramlich <grim@reaperworld.com>
parents: 43040
diff changeset
1098 }
b6cb116ce063 Change the internal data structure of Purple.ConversationManager to GPtrArray
Gary Kramlich <grim@reaperworld.com>
parents: 43040
diff changeset
1099
b6cb116ce063 Change the internal data structure of Purple.ConversationManager to GPtrArray
Gary Kramlich <grim@reaperworld.com>
parents: 43040
diff changeset
1100 return result;
40948
2c312f084d84 Create a manager for conversations.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
1101 }
2c312f084d84 Create a manager for conversations.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
1102
2c312f084d84 Create a manager for conversations.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
1103 PurpleConversation *
42672
5b864b9b22aa Create purple_conversation_manager_find_dm
Gary Kramlich <grim@reaperworld.com>
parents: 42654
diff changeset
1104 purple_conversation_manager_find_dm(PurpleConversationManager *manager,
5b864b9b22aa Create purple_conversation_manager_find_dm
Gary Kramlich <grim@reaperworld.com>
parents: 42654
diff changeset
1105 PurpleContact *contact)
5b864b9b22aa Create purple_conversation_manager_find_dm
Gary Kramlich <grim@reaperworld.com>
parents: 42654
diff changeset
1106 {
5b864b9b22aa Create purple_conversation_manager_find_dm
Gary Kramlich <grim@reaperworld.com>
parents: 42654
diff changeset
1107 PurpleAccount *contact_account = NULL;
5b864b9b22aa Create purple_conversation_manager_find_dm
Gary Kramlich <grim@reaperworld.com>
parents: 42654
diff changeset
1108 PurpleContactInfo *info = NULL;
5b864b9b22aa Create purple_conversation_manager_find_dm
Gary Kramlich <grim@reaperworld.com>
parents: 42654
diff changeset
1109
5b864b9b22aa Create purple_conversation_manager_find_dm
Gary Kramlich <grim@reaperworld.com>
parents: 42654
diff changeset
1110 g_return_val_if_fail(PURPLE_IS_CONVERSATION_MANAGER(manager), NULL);
5b864b9b22aa Create purple_conversation_manager_find_dm
Gary Kramlich <grim@reaperworld.com>
parents: 42654
diff changeset
1111 g_return_val_if_fail(PURPLE_IS_CONTACT(contact), NULL);
5b864b9b22aa Create purple_conversation_manager_find_dm
Gary Kramlich <grim@reaperworld.com>
parents: 42654
diff changeset
1112
5b864b9b22aa Create purple_conversation_manager_find_dm
Gary Kramlich <grim@reaperworld.com>
parents: 42654
diff changeset
1113 info = PURPLE_CONTACT_INFO(contact);
5b864b9b22aa Create purple_conversation_manager_find_dm
Gary Kramlich <grim@reaperworld.com>
parents: 42654
diff changeset
1114 contact_account = purple_contact_get_account(contact);
5b864b9b22aa Create purple_conversation_manager_find_dm
Gary Kramlich <grim@reaperworld.com>
parents: 42654
diff changeset
1115
43044
b6cb116ce063 Change the internal data structure of Purple.ConversationManager to GPtrArray
Gary Kramlich <grim@reaperworld.com>
parents: 43040
diff changeset
1116 for(guint i = 0; i < manager->conversations->len; i++) {
42672
5b864b9b22aa Create purple_conversation_manager_find_dm
Gary Kramlich <grim@reaperworld.com>
parents: 42654
diff changeset
1117 PurpleAccount *conversation_account = NULL;
43044
b6cb116ce063 Change the internal data structure of Purple.ConversationManager to GPtrArray
Gary Kramlich <grim@reaperworld.com>
parents: 43040
diff changeset
1118 PurpleConversation *conversation = NULL;
42891
7f8daf96e7d3 Move Purple.Conversation:members to Purple.ConversationMembers
Gary Kramlich <grim@reaperworld.com>
parents: 42777
diff changeset
1119 PurpleConversationMembers *members = NULL;
42672
5b864b9b22aa Create purple_conversation_manager_find_dm
Gary Kramlich <grim@reaperworld.com>
parents: 42654
diff changeset
1120
43044
b6cb116ce063 Change the internal data structure of Purple.ConversationManager to GPtrArray
Gary Kramlich <grim@reaperworld.com>
parents: 43040
diff changeset
1121 conversation = g_ptr_array_index(manager->conversations, i);
42672
5b864b9b22aa Create purple_conversation_manager_find_dm
Gary Kramlich <grim@reaperworld.com>
parents: 42654
diff changeset
1122 conversation_account = purple_conversation_get_account(conversation);
5b864b9b22aa Create purple_conversation_manager_find_dm
Gary Kramlich <grim@reaperworld.com>
parents: 42654
diff changeset
1123 if(conversation_account != contact_account) {
5b864b9b22aa Create purple_conversation_manager_find_dm
Gary Kramlich <grim@reaperworld.com>
parents: 42654
diff changeset
1124 continue;
5b864b9b22aa Create purple_conversation_manager_find_dm
Gary Kramlich <grim@reaperworld.com>
parents: 42654
diff changeset
1125 }
5b864b9b22aa Create purple_conversation_manager_find_dm
Gary Kramlich <grim@reaperworld.com>
parents: 42654
diff changeset
1126
5b864b9b22aa Create purple_conversation_manager_find_dm
Gary Kramlich <grim@reaperworld.com>
parents: 42654
diff changeset
1127 if(!purple_conversation_is_dm(conversation)) {
5b864b9b22aa Create purple_conversation_manager_find_dm
Gary Kramlich <grim@reaperworld.com>
parents: 42654
diff changeset
1128 continue;
5b864b9b22aa Create purple_conversation_manager_find_dm
Gary Kramlich <grim@reaperworld.com>
parents: 42654
diff changeset
1129 }
5b864b9b22aa Create purple_conversation_manager_find_dm
Gary Kramlich <grim@reaperworld.com>
parents: 42654
diff changeset
1130
42891
7f8daf96e7d3 Move Purple.Conversation:members to Purple.ConversationMembers
Gary Kramlich <grim@reaperworld.com>
parents: 42777
diff changeset
1131 members = purple_conversation_get_members(conversation);
7f8daf96e7d3 Move Purple.Conversation:members to Purple.ConversationMembers
Gary Kramlich <grim@reaperworld.com>
parents: 42777
diff changeset
1132 if(purple_conversation_members_has_member(members, info, NULL)) {
42672
5b864b9b22aa Create purple_conversation_manager_find_dm
Gary Kramlich <grim@reaperworld.com>
parents: 42654
diff changeset
1133 return conversation;
5b864b9b22aa Create purple_conversation_manager_find_dm
Gary Kramlich <grim@reaperworld.com>
parents: 42654
diff changeset
1134 }
5b864b9b22aa Create purple_conversation_manager_find_dm
Gary Kramlich <grim@reaperworld.com>
parents: 42654
diff changeset
1135 }
5b864b9b22aa Create purple_conversation_manager_find_dm
Gary Kramlich <grim@reaperworld.com>
parents: 42654
diff changeset
1136
5b864b9b22aa Create purple_conversation_manager_find_dm
Gary Kramlich <grim@reaperworld.com>
parents: 42654
diff changeset
1137 return NULL;
5b864b9b22aa Create purple_conversation_manager_find_dm
Gary Kramlich <grim@reaperworld.com>
parents: 42654
diff changeset
1138 }
5b864b9b22aa Create purple_conversation_manager_find_dm
Gary Kramlich <grim@reaperworld.com>
parents: 42654
diff changeset
1139
5b864b9b22aa Create purple_conversation_manager_find_dm
Gary Kramlich <grim@reaperworld.com>
parents: 42654
diff changeset
1140 PurpleConversation *
42272
015257326ad4 Add an id property to PurpleConversation
Gary Kramlich <grim@reaperworld.com>
parents: 42005
diff changeset
1141 purple_conversation_manager_find_with_id(PurpleConversationManager *manager,
015257326ad4 Add an id property to PurpleConversation
Gary Kramlich <grim@reaperworld.com>
parents: 42005
diff changeset
1142 PurpleAccount *account,
015257326ad4 Add an id property to PurpleConversation
Gary Kramlich <grim@reaperworld.com>
parents: 42005
diff changeset
1143 const char *id)
015257326ad4 Add an id property to PurpleConversation
Gary Kramlich <grim@reaperworld.com>
parents: 42005
diff changeset
1144 {
015257326ad4 Add an id property to PurpleConversation
Gary Kramlich <grim@reaperworld.com>
parents: 42005
diff changeset
1145 g_return_val_if_fail(PURPLE_IS_CONVERSATION_MANAGER(manager), NULL);
015257326ad4 Add an id property to PurpleConversation
Gary Kramlich <grim@reaperworld.com>
parents: 42005
diff changeset
1146 g_return_val_if_fail(PURPLE_IS_ACCOUNT(account), NULL);
015257326ad4 Add an id property to PurpleConversation
Gary Kramlich <grim@reaperworld.com>
parents: 42005
diff changeset
1147
43132
b8a7d50eb1ae Simplify purple_conversation_manager_find_with_id
Gary Kramlich <grim@reaperworld.com>
parents: 43128
diff changeset
1148 for(guint i = 0; i < manager->conversations->len; i++) {
b8a7d50eb1ae Simplify purple_conversation_manager_find_with_id
Gary Kramlich <grim@reaperworld.com>
parents: 43128
diff changeset
1149 PurpleConversation *conversation = NULL;
b8a7d50eb1ae Simplify purple_conversation_manager_find_with_id
Gary Kramlich <grim@reaperworld.com>
parents: 43128
diff changeset
1150
b8a7d50eb1ae Simplify purple_conversation_manager_find_with_id
Gary Kramlich <grim@reaperworld.com>
parents: 43128
diff changeset
1151 conversation = g_ptr_array_index(manager->conversations, i);
b8a7d50eb1ae Simplify purple_conversation_manager_find_with_id
Gary Kramlich <grim@reaperworld.com>
parents: 43128
diff changeset
1152 if(purple_conversation_get_account(conversation) != account) {
b8a7d50eb1ae Simplify purple_conversation_manager_find_with_id
Gary Kramlich <grim@reaperworld.com>
parents: 43128
diff changeset
1153 continue;
b8a7d50eb1ae Simplify purple_conversation_manager_find_with_id
Gary Kramlich <grim@reaperworld.com>
parents: 43128
diff changeset
1154 }
b8a7d50eb1ae Simplify purple_conversation_manager_find_with_id
Gary Kramlich <grim@reaperworld.com>
parents: 43128
diff changeset
1155
b8a7d50eb1ae Simplify purple_conversation_manager_find_with_id
Gary Kramlich <grim@reaperworld.com>
parents: 43128
diff changeset
1156 if(purple_strequal(purple_conversation_get_id(conversation), id)) {
b8a7d50eb1ae Simplify purple_conversation_manager_find_with_id
Gary Kramlich <grim@reaperworld.com>
parents: 43128
diff changeset
1157 return conversation;
b8a7d50eb1ae Simplify purple_conversation_manager_find_with_id
Gary Kramlich <grim@reaperworld.com>
parents: 43128
diff changeset
1158 }
b8a7d50eb1ae Simplify purple_conversation_manager_find_with_id
Gary Kramlich <grim@reaperworld.com>
parents: 43128
diff changeset
1159 }
b8a7d50eb1ae Simplify purple_conversation_manager_find_with_id
Gary Kramlich <grim@reaperworld.com>
parents: 43128
diff changeset
1160
b8a7d50eb1ae Simplify purple_conversation_manager_find_with_id
Gary Kramlich <grim@reaperworld.com>
parents: 43128
diff changeset
1161 return NULL;
42272
015257326ad4 Add an id property to PurpleConversation
Gary Kramlich <grim@reaperworld.com>
parents: 42005
diff changeset
1162 }
43029
b95b2d2b8200 Rename Purple.ConversationManager.register/unregister to add/remove
Gary Kramlich <grim@reaperworld.com>
parents: 42997
diff changeset
1163
b95b2d2b8200 Rename Purple.ConversationManager.register/unregister to add/remove
Gary Kramlich <grim@reaperworld.com>
parents: 42997
diff changeset
1164 gboolean
b95b2d2b8200 Rename Purple.ConversationManager.register/unregister to add/remove
Gary Kramlich <grim@reaperworld.com>
parents: 42997
diff changeset
1165 purple_conversation_manager_remove(PurpleConversationManager *manager,
b95b2d2b8200 Rename Purple.ConversationManager.register/unregister to add/remove
Gary Kramlich <grim@reaperworld.com>
parents: 42997
diff changeset
1166 PurpleConversation *conversation)
b95b2d2b8200 Rename Purple.ConversationManager.register/unregister to add/remove
Gary Kramlich <grim@reaperworld.com>
parents: 42997
diff changeset
1167 {
43044
b6cb116ce063 Change the internal data structure of Purple.ConversationManager to GPtrArray
Gary Kramlich <grim@reaperworld.com>
parents: 43040
diff changeset
1168 guint position = 0;
43029
b95b2d2b8200 Rename Purple.ConversationManager.register/unregister to add/remove
Gary Kramlich <grim@reaperworld.com>
parents: 42997
diff changeset
1169
b95b2d2b8200 Rename Purple.ConversationManager.register/unregister to add/remove
Gary Kramlich <grim@reaperworld.com>
parents: 42997
diff changeset
1170 g_return_val_if_fail(PURPLE_IS_CONVERSATION_MANAGER(manager), FALSE);
b95b2d2b8200 Rename Purple.ConversationManager.register/unregister to add/remove
Gary Kramlich <grim@reaperworld.com>
parents: 42997
diff changeset
1171 g_return_val_if_fail(PURPLE_IS_CONVERSATION(conversation), FALSE);
b95b2d2b8200 Rename Purple.ConversationManager.register/unregister to add/remove
Gary Kramlich <grim@reaperworld.com>
parents: 42997
diff changeset
1172
43044
b6cb116ce063 Change the internal data structure of Purple.ConversationManager to GPtrArray
Gary Kramlich <grim@reaperworld.com>
parents: 43040
diff changeset
1173 if(!g_ptr_array_find(manager->conversations, conversation, &position)) {
b6cb116ce063 Change the internal data structure of Purple.ConversationManager to GPtrArray
Gary Kramlich <grim@reaperworld.com>
parents: 43040
diff changeset
1174 return FALSE;
b6cb116ce063 Change the internal data structure of Purple.ConversationManager to GPtrArray
Gary Kramlich <grim@reaperworld.com>
parents: 43040
diff changeset
1175 }
b6cb116ce063 Change the internal data structure of Purple.ConversationManager to GPtrArray
Gary Kramlich <grim@reaperworld.com>
parents: 43040
diff changeset
1176
43029
b95b2d2b8200 Rename Purple.ConversationManager.register/unregister to add/remove
Gary Kramlich <grim@reaperworld.com>
parents: 42997
diff changeset
1177 /* Make sure we have a reference in case we need to emit signals. */
b95b2d2b8200 Rename Purple.ConversationManager.register/unregister to add/remove
Gary Kramlich <grim@reaperworld.com>
parents: 42997
diff changeset
1178 g_object_ref(conversation);
b95b2d2b8200 Rename Purple.ConversationManager.register/unregister to add/remove
Gary Kramlich <grim@reaperworld.com>
parents: 42997
diff changeset
1179
43044
b6cb116ce063 Change the internal data structure of Purple.ConversationManager to GPtrArray
Gary Kramlich <grim@reaperworld.com>
parents: 43040
diff changeset
1180 g_ptr_array_remove_index(manager->conversations, position);
43029
b95b2d2b8200 Rename Purple.ConversationManager.register/unregister to add/remove
Gary Kramlich <grim@reaperworld.com>
parents: 42997
diff changeset
1181
43044
b6cb116ce063 Change the internal data structure of Purple.ConversationManager to GPtrArray
Gary Kramlich <grim@reaperworld.com>
parents: 43040
diff changeset
1182 /* Disconnect all the signals we added for propagation. */
b6cb116ce063 Change the internal data structure of Purple.ConversationManager to GPtrArray
Gary Kramlich <grim@reaperworld.com>
parents: 43040
diff changeset
1183 g_signal_handlers_disconnect_by_func(conversation,
b6cb116ce063 Change the internal data structure of Purple.ConversationManager to GPtrArray
Gary Kramlich <grim@reaperworld.com>
parents: 43040
diff changeset
1184 purple_conversation_manager_conversation_changed_cb,
b6cb116ce063 Change the internal data structure of Purple.ConversationManager to GPtrArray
Gary Kramlich <grim@reaperworld.com>
parents: 43040
diff changeset
1185 manager);
b6cb116ce063 Change the internal data structure of Purple.ConversationManager to GPtrArray
Gary Kramlich <grim@reaperworld.com>
parents: 43040
diff changeset
1186 g_signal_handlers_disconnect_by_func(conversation,
b6cb116ce063 Change the internal data structure of Purple.ConversationManager to GPtrArray
Gary Kramlich <grim@reaperworld.com>
parents: 43040
diff changeset
1187 purple_conversation_manager_present_conversation_cb,
b6cb116ce063 Change the internal data structure of Purple.ConversationManager to GPtrArray
Gary Kramlich <grim@reaperworld.com>
parents: 43040
diff changeset
1188 manager);
b6cb116ce063 Change the internal data structure of Purple.ConversationManager to GPtrArray
Gary Kramlich <grim@reaperworld.com>
parents: 43040
diff changeset
1189
b6cb116ce063 Change the internal data structure of Purple.ConversationManager to GPtrArray
Gary Kramlich <grim@reaperworld.com>
parents: 43040
diff changeset
1190 /* Tell everyone about the removed conversation. */
b6cb116ce063 Change the internal data structure of Purple.ConversationManager to GPtrArray
Gary Kramlich <grim@reaperworld.com>
parents: 43040
diff changeset
1191 g_signal_emit(manager, signals[SIG_REMOVED], 0, conversation);
43046
eeab15f4576e Call g_list_model_items_changed as necessary in Purple.ConversationManager
Gary Kramlich <grim@reaperworld.com>
parents: 43044
diff changeset
1192 g_list_model_items_changed(G_LIST_MODEL(manager), position, 1, 0);
43128
1ce3ad90614c Make sure we notify on the n-items property for all objects that have it
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
1193 g_object_notify_by_pspec(G_OBJECT(manager), properties[PROP_N_ITEMS]);
43029
b95b2d2b8200 Rename Purple.ConversationManager.register/unregister to add/remove
Gary Kramlich <grim@reaperworld.com>
parents: 42997
diff changeset
1194
b95b2d2b8200 Rename Purple.ConversationManager.register/unregister to add/remove
Gary Kramlich <grim@reaperworld.com>
parents: 42997
diff changeset
1195 g_object_unref(conversation);
b95b2d2b8200 Rename Purple.ConversationManager.register/unregister to add/remove
Gary Kramlich <grim@reaperworld.com>
parents: 42997
diff changeset
1196
43044
b6cb116ce063 Change the internal data structure of Purple.ConversationManager to GPtrArray
Gary Kramlich <grim@reaperworld.com>
parents: 43040
diff changeset
1197 return TRUE;
43029
b95b2d2b8200 Rename Purple.ConversationManager.register/unregister to add/remove
Gary Kramlich <grim@reaperworld.com>
parents: 42997
diff changeset
1198 }

mercurial