# HG changeset patch
# Node ID f602a7ef712d
# Parent  be1e91019453
diff --git a/libpurple/protocols/demo/meson.build b/libpurple/protocols/demo/meson.build
--- a/libpurple/protocols/demo/meson.build
+++ b/libpurple/protocols/demo/meson.build
@@ -1,4 +1,6 @@
 DEMO_SOURCES = [
+	'purpledemoconnection.c',
+	'purpledemoconnection.h',
 	'purpledemocontacts.c',
 	'purpledemocontacts.h',
 	'purpledemoplugin.c',
diff --git a/libpurple/protocols/demo/purpledemoconnection.h b/libpurple/protocols/demo/purpledemoconnection.h
new file mode 100644
--- /dev/null
+++ b/libpurple/protocols/demo/purpledemoconnection.h
@@ -0,0 +1,36 @@
+/*
+ * Purple - Internet Messaging Library
+ * Copyright (C) Pidgin Developers <devel@pidgin.im>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see <https://www.gnu.org/licenses/>.
+ */
+
+#ifndef PURPLE_DEMO_CONNECTION_H
+#define PURPLE_DEMO_CONNECTION_H
+
+#include <glib.h>
+
+#include <purple.h>
+
+G_BEGIN_DECLS
+
+#define PURPLE_DEMO_TYPE_CONNECTION (purple_demo_connection_get_type())
+G_DECLARE_FINAL_TYPE(PurpleDemoConnection, purple_demo_connection, PURPLE_DEMO,
+                     CONNECTION, PurpleConnection)
+
+G_GNUC_INTERNAL void purple_demo_connection_register(GPluginNativePlugin *plugin);
+
+G_BEGIN_DECLS
+
+#endif /* PURPLE_DEMO_CONNECTION_H */
diff --git a/libpurple/protocols/demo/purpledemoconnection.c b/libpurple/protocols/demo/purpledemoconnection.c
new file mode 100644
--- /dev/null
+++ b/libpurple/protocols/demo/purpledemoconnection.c
@@ -0,0 +1,80 @@
+/*
+ * Purple - Internet Messaging Library
+ * Copyright (C) Pidgin Developers <devel@pidgin.im>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see <https://www.gnu.org/licenses/>.
+ */
+
+#include <glib/gi18n-lib.h>
+
+#include "purpledemoconnection.h"
+
+#include "purpledemocontacts.h"
+
+struct _PurpleDemoConnection {
+	PurpleConnection parent;
+};
+
+G_DEFINE_DYNAMIC_TYPE(PurpleDemoConnection, purple_demo_connection,
+                      PURPLE_TYPE_CONNECTION)
+
+/******************************************************************************
+ * PurpleConnection Implementation
+ *****************************************************************************/
+static gboolean
+purple_demo_connection_connect(PurpleConnection *connection,
+                               G_GNUC_UNUSED GError **error)
+{
+	PurpleAccount *account = purple_connection_get_account(connection);
+
+	purple_connection_set_state(connection, PURPLE_CONNECTION_STATE_CONNECTED);
+
+	purple_demo_contacts_load(account);
+
+	return TRUE;
+}
+
+static gboolean
+purple_demo_connection_disconnect(G_GNUC_UNUSED PurpleConnection *connection,
+                                  G_GNUC_UNUSED GError **error)
+{
+	return TRUE;
+}
+
+/******************************************************************************
+ * GObject Implementation
+ *****************************************************************************/
+static void
+purple_demo_connection_init(G_GNUC_UNUSED PurpleDemoConnection *connection) {
+}
+
+static void
+purple_demo_connection_class_finalize(G_GNUC_UNUSED PurpleDemoConnectionClass *klass) {
+}
+
+static void
+purple_demo_connection_class_init(PurpleDemoConnectionClass *klass) {
+	PurpleConnectionClass *connection_class = PURPLE_CONNECTION_CLASS(klass);
+
+	connection_class->connect = purple_demo_connection_connect;
+	connection_class->disconnect = purple_demo_connection_disconnect;
+}
+
+/******************************************************************************
+ * Internal API
+ *****************************************************************************/
+void
+purple_demo_connection_register(GPluginNativePlugin *plugin) {
+	purple_demo_connection_register_type(G_TYPE_MODULE(plugin));
+}
diff --git a/libpurple/protocols/demo/purpledemoplugin.c b/libpurple/protocols/demo/purpledemoplugin.c
--- a/libpurple/protocols/demo/purpledemoplugin.c
+++ b/libpurple/protocols/demo/purpledemoplugin.c
@@ -25,6 +25,8 @@
 #include <purple.h>
 
 #include "purpledemoplugin.h"
+
+#include "purpledemoconnection.h"
 #include "purpledemoprotocol.h"
 
 /******************************************************************************
@@ -70,6 +72,7 @@
 		return FALSE;
 	}
 
+	purple_demo_connection_register(GPLUGIN_NATIVE_PLUGIN(plugin));
 	purple_demo_protocol_register(GPLUGIN_NATIVE_PLUGIN(plugin));
 
 	manager = purple_protocol_manager_get_default();
diff --git a/libpurple/protocols/demo/purpledemoprotocol.c b/libpurple/protocols/demo/purpledemoprotocol.c
--- a/libpurple/protocols/demo/purpledemoprotocol.c
+++ b/libpurple/protocols/demo/purpledemoprotocol.c
@@ -21,13 +21,13 @@
 #include <glib/gi18n-lib.h>
 
 #include "purpledemoprotocol.h"
+
+#include "purpledemoconnection.h"
 #include "purpledemoprotocolactions.h"
 #include "purpledemoprotocolclient.h"
 #include "purpledemoprotocolim.h"
 #include "purpledemoprotocolmedia.h"
 
-#include "purpledemocontacts.h"
-
 struct _PurpleDemoProtocol {
 	PurpleProtocol parent;
 };
@@ -35,16 +35,22 @@
 /******************************************************************************
  * PurpleProtocol Implementation
  *****************************************************************************/
-static void
-purple_demo_protocol_login(G_GNUC_UNUSED PurpleProtocol *protocol,
-                           PurpleAccount *account)
+static PurpleConnection *
+purple_demo_protocol_create_connection(PurpleProtocol *protocol,
+                                       PurpleAccount *account,
+                                       const char *password,
+                                       GError **error)
 {
-	PurpleConnection *connection = NULL;
+	g_return_val_if_fail(PURPLE_IS_PROTOCOL(protocol), NULL);
+	g_return_val_if_fail(PURPLE_IS_ACCOUNT(account), NULL);
 
-	connection = purple_account_get_connection(account);
-	purple_connection_set_state(connection, PURPLE_CONNECTION_STATE_CONNECTED);
+	return g_object_new(
+		PURPLE_DEMO_TYPE_CONNECTION,
+		"protocol", protocol,
+		"account", account,
+		"password", password,
+		NULL);
 
-	purple_demo_contacts_load(account);
 }
 
 static GList *
@@ -112,8 +118,8 @@
 purple_demo_protocol_class_init(PurpleDemoProtocolClass *klass) {
 	PurpleProtocolClass *protocol_class = PURPLE_PROTOCOL_CLASS(klass);
 
-	protocol_class->login = purple_demo_protocol_login;
 	protocol_class->status_types = purple_demo_protocol_status_types;
+	protocol_class->create_connection = purple_demo_protocol_create_connection;
 }
 
 /******************************************************************************
