From 18f4f0763dc134a05ac4e2e36a1590ce6917ff33 Mon Sep 17 00:00:00 2001 From: Alexey Berezhok Date: Tue, 2 May 2023 15:51:50 +0300 Subject: [PATCH] Added yandex provider (prebuild version) --- config.h.in | 13 + configure.ac | 27 ++ data/icons/scalable/Makefile.am | 1 + data/icons/scalable/Makefile.in | 1 + data/icons/scalable/goa-account-yandex.svg | 45 +++ data/icons/symbolic/Makefile.am | 1 + data/icons/symbolic/Makefile.in | 1 + .../symbolic/goa-account-yandex-symbolic.svg | 45 +++ src/goabackend/Makefile.am | 1 + src/goabackend/Makefile.in | 14 + src/goabackend/goaprovider.c | 4 + src/goabackend/goayandexprovider.c | 369 ++++++++++++++++++ src/goabackend/goayandexprovider.h | 37 ++ 13 files changed, 559 insertions(+) create mode 100644 data/icons/scalable/goa-account-yandex.svg create mode 100644 data/icons/symbolic/goa-account-yandex-symbolic.svg create mode 100644 src/goabackend/goayandexprovider.c create mode 100644 src/goabackend/goayandexprovider.h diff --git a/config.h.in b/config.h.in index f0b0354..40ca01d 100644 --- a/config.h.in +++ b/config.h.in @@ -70,6 +70,19 @@ /* ProviderType and extension point name */ #undef GOA_GOOGLE_NAME +/* Yandex OAuth 2.0 client id */ +#undef GOA_YANDEX_CLIENT_ID + +/* Yandex OAuth 2.0 client secret */ +#undef GOA_YANDEX_CLIENT_SECRET + +/* Enable Yandex data provider */ +#undef GOA_YANDEX_ENABLED + +/* ProviderType and extension point name */ +#undef GOA_YANDEX_NAME + + /* Enable IMAP/SMTP data provider */ #undef GOA_IMAP_SMTP_ENABLED diff --git a/configure.ac b/configure.ac index 332a0bf..538636a 100644 --- a/configure.ac +++ b/configure.ac @@ -277,6 +277,32 @@ if test "$enable_google" != "no"; then AC_DEFINE(GOA_GOOGLE_ENABLED, 1, [Enable Google data provider]) fi +# Yandex +AC_DEFINE(GOA_YANDEX_NAME, ["yandex"], [ProviderType and extension point name]) +AC_ARG_ENABLE([yandex], + [AS_HELP_STRING([--enable-yandex], [Enable Yandex provider])], + [], + [enable_yandex=yes]) +AC_ARG_WITH(yandex-client-id, + [AS_HELP_STRING([--with-yandex-client-id], [Yandex OAuth 2.0 client id])], + [], + []) +AC_ARG_WITH(yandex-client-secret, + [AS_HELP_STRING([--with-yandex-client-secret], [Yandex OAuth 2.0 client secret])], + [], + []) +if test "$with_yandex_client_id" = ""; then + with_yandex_client_id=8ef866ab7a1f4d3b8fcb58510d422fbc +fi +if test "$with_yandex_client_secret" = ""; then + with_yandex_client_secret=aa8be6b692dc4465b1fa40ae6ec7a377 +fi +AC_DEFINE_UNQUOTED(GOA_YANDEX_CLIENT_ID, ["$with_yandex_client_id"], [Yandex OAuth 2.0 client id]) +AC_DEFINE_UNQUOTED(GOA_YANDEX_CLIENT_SECRET, ["$with_yandex_client_secret"], [Yandex OAuth 2.0 client secret]) +if test "$enable_yadnex" != "no"; then + AC_DEFINE(GOA_YANDEX_ENABLED, 1, [Enable Yandex data provider]) +fi + # IMAP/SMTP AC_DEFINE(GOA_IMAP_SMTP_NAME, ["imap_smtp"], [ProviderType and extension point name]) AC_ARG_ENABLE([imap-smtp], @@ -569,6 +595,7 @@ echo " Flickr provider: ${enable_flickr} (OAuth 1.0, key:${with_flickr_consumer_key} secret:${with_flickr_consumer_secret}) Foursquare provider: ${enable_foursquare} (id:${with_foursquare_client_id}) Google provider: ${enable_google} (OAuth 2.0, id:${with_google_client_id} secret:${with_google_client_secret}) + Yandex provider: ${enable_yandex} (OAuth 2.0, id:${with_yandex_client_id} secret:${with_yandex_client_secret}) IMAP/SMTP provider: ${enable_imap_smtp} Media Server provider: ${enable_media_server} Microsoft Exchange provider: ${enable_exchange} diff --git a/data/icons/scalable/Makefile.am b/data/icons/scalable/Makefile.am index 5721dd5..0a8b5f7 100644 --- a/data/icons/scalable/Makefile.am +++ b/data/icons/scalable/Makefile.am @@ -12,6 +12,7 @@ icon_DATA = \ goa-account-msn.svg \ goa-account-owncloud.svg \ goa-account-foursquare.svg \ + goa-account-yandex.svg \ $(NULL) EXTRA_DIST = \ diff --git a/data/icons/scalable/Makefile.in b/data/icons/scalable/Makefile.in index 9e2632e..f2a5368 100644 --- a/data/icons/scalable/Makefile.in +++ b/data/icons/scalable/Makefile.in @@ -375,6 +375,7 @@ icon_DATA = \ goa-account-msn.svg \ goa-account-owncloud.svg \ goa-account-foursquare.svg \ + goa-account-yandex.svg \ $(NULL) EXTRA_DIST = \ diff --git a/data/icons/scalable/goa-account-yandex.svg b/data/icons/scalable/goa-account-yandex.svg new file mode 100644 index 0000000..dd7624f --- /dev/null +++ b/data/icons/scalable/goa-account-yandex.svg @@ -0,0 +1,45 @@ + + + + + + + diff --git a/data/icons/symbolic/Makefile.am b/data/icons/symbolic/Makefile.am index 1ba8100..5f555b7 100644 --- a/data/icons/symbolic/Makefile.am +++ b/data/icons/symbolic/Makefile.am @@ -11,6 +11,7 @@ icon_DATA = \ goa-account-msn-symbolic.svg \ goa-account-owncloud-symbolic.svg \ goa-account-foursquare-symbolic.svg \ + goa-account-yandex-symbolic.svg \ $(NULL) EXTRA_DIST = \ diff --git a/data/icons/symbolic/Makefile.in b/data/icons/symbolic/Makefile.in index b1d4415..35ffa14 100644 --- a/data/icons/symbolic/Makefile.in +++ b/data/icons/symbolic/Makefile.in @@ -374,6 +374,7 @@ icon_DATA = \ goa-account-msn-symbolic.svg \ goa-account-owncloud-symbolic.svg \ goa-account-foursquare-symbolic.svg \ + goa-account-yandex.svg \ $(NULL) EXTRA_DIST = \ diff --git a/data/icons/symbolic/goa-account-yandex-symbolic.svg b/data/icons/symbolic/goa-account-yandex-symbolic.svg new file mode 100644 index 0000000..528713f --- /dev/null +++ b/data/icons/symbolic/goa-account-yandex-symbolic.svg @@ -0,0 +1,45 @@ + + + + + + + diff --git a/src/goabackend/Makefile.am b/src/goabackend/Makefile.am index 8385237..ddf5030 100644 --- a/src/goabackend/Makefile.am +++ b/src/goabackend/Makefile.am @@ -97,6 +97,7 @@ libgoa_backend_1_0_la_SOURCES = \ goautils.h goautils.c \ goawebview.h goawebview.c \ nautilus-floating-bar.h nautilus-floating-bar.c \ + goayandexprovider.h goayandexprovider.c \ $(top_builddir)/src/goaidentity/org.gnome.Identity.c \ $(top_srcdir)/src/goaidentity/goaidentitymanagererror.c \ $(NULL) diff --git a/src/goabackend/Makefile.in b/src/goabackend/Makefile.in index 608b214..4444c0b 100644 --- a/src/goabackend/Makefile.in +++ b/src/goabackend/Makefile.in @@ -181,6 +181,7 @@ am__libgoa_backend_1_0_la_SOURCES_DIST = goabackend.h \ goaoauth2provider-priv.h goaoauth2provider-web-extension.h \ goaoauth2provider-web-view.h goaoauth2provider.c \ goagoogleprovider.h goagoogleprovider.c goafacebookprovider.h \ + goayandexprovider.h goayandexprovider.c \ goafacebookprovider.c goaimapsmtpprovider.h \ goaimapsmtpprovider.c goamediaserverprovider.h \ goamediaserverprovider.c goaowncloudprovider.h \ @@ -216,6 +217,7 @@ am_libgoa_backend_1_0_la_OBJECTS = \ libgoa_backend_1_0_la-goaoauthprovider.lo \ libgoa_backend_1_0_la-goaoauth2provider.lo \ libgoa_backend_1_0_la-goagoogleprovider.lo \ + libgoa_backend_1_0_la-goayandexprovider.lo \ libgoa_backend_1_0_la-goafacebookprovider.lo \ libgoa_backend_1_0_la-goaimapsmtpprovider.lo \ libgoa_backend_1_0_la-goamediaserverprovider.lo \ @@ -285,6 +287,7 @@ am__depfiles_remade = \ ./$(DEPDIR)/libgoa_backend_1_0_la-goaflickrprovider.Plo \ ./$(DEPDIR)/libgoa_backend_1_0_la-goafoursquareprovider.Plo \ ./$(DEPDIR)/libgoa_backend_1_0_la-goagoogleprovider.Plo \ + ./$(DEPDIR)/libgoa_backend_1_0_la-goayandexprovider.Plo \ ./$(DEPDIR)/libgoa_backend_1_0_la-goahttpclient.Plo \ ./$(DEPDIR)/libgoa_backend_1_0_la-goaidentitymanagererror.Plo \ ./$(DEPDIR)/libgoa_backend_1_0_la-goaimapauthlogin.Plo \ @@ -618,6 +621,7 @@ libgoa_backend_1_0_la_SOURCES = goabackend.h goabackendenums-priv.h \ goaoauth2provider-priv.h goaoauth2provider-web-extension.h \ goaoauth2provider-web-view.h goaoauth2provider.c \ goagoogleprovider.h goagoogleprovider.c goafacebookprovider.h \ + goayandexprovider.h goayandexprovider.c \ goafacebookprovider.c goaimapsmtpprovider.h \ goaimapsmtpprovider.c goamediaserverprovider.h \ goamediaserverprovider.c goaowncloudprovider.h \ @@ -839,6 +843,7 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libgoa_backend_1_0_la-goaflickrprovider.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libgoa_backend_1_0_la-goafoursquareprovider.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libgoa_backend_1_0_la-goagoogleprovider.Plo@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libgoa_backend_1_0_la-goayandexprovider.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libgoa_backend_1_0_la-goahttpclient.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libgoa_backend_1_0_la-goaidentitymanagererror.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libgoa_backend_1_0_la-goaimapauthlogin.Plo@am__quote@ # am--include-marker @@ -1003,6 +1008,13 @@ libgoa_backend_1_0_la-goagoogleprovider.lo: goagoogleprovider.c @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libgoa_backend_1_0_la_CFLAGS) $(CFLAGS) -c -o libgoa_backend_1_0_la-goagoogleprovider.lo `test -f 'goagoogleprovider.c' || echo '$(srcdir)/'`goagoogleprovider.c +libgoa_backend_1_0_la-goayandexprovider.lo: goayandexprovider.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libgoa_backend_1_0_la_CFLAGS) $(CFLAGS) -MT libgoa_backend_1_0_la-goayandexprovider.lo -MD -MP -MF $(DEPDIR)/libgoa_backend_1_0_la-goayandexprovider.Tpo -c -o libgoa_backend_1_0_la-goayandexprovider.lo `test -f 'goayandexprovider.c' || echo '$(srcdir)/'`goayandexprovider.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libgoa_backend_1_0_la-goayandexprovider.Tpo $(DEPDIR)/libgoa_backend_1_0_la-goayandexprovider.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='goayandexprovider.c' object='libgoa_backend_1_0_la-goayandexprovider.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libgoa_backend_1_0_la_CFLAGS) $(CFLAGS) -c -o libgoa_backend_1_0_la-goayandexprovider.lo `test -f 'goayandexprovider.c' || echo '$(srcdir)/'`goayandexprovider.c + libgoa_backend_1_0_la-goafacebookprovider.lo: goafacebookprovider.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libgoa_backend_1_0_la_CFLAGS) $(CFLAGS) -MT libgoa_backend_1_0_la-goafacebookprovider.lo -MD -MP -MF $(DEPDIR)/libgoa_backend_1_0_la-goafacebookprovider.Tpo -c -o libgoa_backend_1_0_la-goafacebookprovider.lo `test -f 'goafacebookprovider.c' || echo '$(srcdir)/'`goafacebookprovider.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libgoa_backend_1_0_la-goafacebookprovider.Tpo $(DEPDIR)/libgoa_backend_1_0_la-goafacebookprovider.Plo @@ -1335,6 +1347,7 @@ distclean: distclean-am -rm -f ./$(DEPDIR)/libgoa_backend_1_0_la-goaflickrprovider.Plo -rm -f ./$(DEPDIR)/libgoa_backend_1_0_la-goafoursquareprovider.Plo -rm -f ./$(DEPDIR)/libgoa_backend_1_0_la-goagoogleprovider.Plo + -rm -f ./$(DEPDIR)/libgoa_backend_1_0_la-goayandexprovider.Plo -rm -f ./$(DEPDIR)/libgoa_backend_1_0_la-goahttpclient.Plo -rm -f ./$(DEPDIR)/libgoa_backend_1_0_la-goaidentitymanagererror.Plo -rm -f ./$(DEPDIR)/libgoa_backend_1_0_la-goaimapauthlogin.Plo @@ -1417,6 +1430,7 @@ maintainer-clean: maintainer-clean-am -rm -f ./$(DEPDIR)/libgoa_backend_1_0_la-goaflickrprovider.Plo -rm -f ./$(DEPDIR)/libgoa_backend_1_0_la-goafoursquareprovider.Plo -rm -f ./$(DEPDIR)/libgoa_backend_1_0_la-goagoogleprovider.Plo + -rm -f ./$(DEPDIR)/libgoa_backend_1_0_la-goayandexprovider.Plo -rm -f ./$(DEPDIR)/libgoa_backend_1_0_la-goahttpclient.Plo -rm -f ./$(DEPDIR)/libgoa_backend_1_0_la-goaidentitymanagererror.Plo -rm -f ./$(DEPDIR)/libgoa_backend_1_0_la-goaimapauthlogin.Plo diff --git a/src/goabackend/goaprovider.c b/src/goabackend/goaprovider.c index 9e5bd45..c4858b7 100644 --- a/src/goabackend/goaprovider.c +++ b/src/goabackend/goaprovider.c @@ -32,6 +32,7 @@ #include "goawindowsliveprovider.h" #include "goamediaserverprovider.h" #include "goalastfmprovider.h" +#include "goayandexprovider.h" #ifdef GOA_FEDORA_ENABLED #include "goafedoraprovider.h" @@ -935,6 +936,9 @@ static struct * important because it affects the order in which they are * returned by goa_provider_get_all. */ +#ifdef GOA_YANDEX_ENABLED + { GOA_YANDEX_NAME, goa_yandex_provider_get_type }, +#endif #ifdef GOA_GOOGLE_ENABLED { GOA_GOOGLE_NAME, goa_google_provider_get_type }, #endif diff --git a/src/goabackend/goayandexprovider.c b/src/goabackend/goayandexprovider.c new file mode 100644 index 0000000..ab74283 --- /dev/null +++ b/src/goabackend/goayandexprovider.c @@ -0,0 +1,369 @@ +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ +/* + * Copyright © 2011 – 2017 Red Hat, Inc. + * + * 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 . + */ + +#include "config.h" +#include + +#include +#include + +#include "goaprovider.h" +#include "goaprovider-priv.h" +#include "goaoauth2provider.h" +#include "goayandexprovider.h" +#include "goaobjectskeletonutils.h" +#include "goarestproxy.h" + +struct _GoaYandexProvider +{ + GoaOAuth2Provider parent_instance; +}; + +G_DEFINE_TYPE_WITH_CODE (GoaYandexProvider, goa_yandex_provider, GOA_TYPE_OAUTH2_PROVIDER, + goa_provider_ensure_extension_points_registered (); + g_io_extension_point_implement (GOA_PROVIDER_EXTENSION_POINT_NAME, + g_define_type_id, + GOA_YANDEX_NAME, + 0)); + +/* ---------------------------------------------------------------------------------------------------- */ + +static const gchar * +get_provider_type (GoaProvider *provider) +{ + return GOA_YANDEX_NAME; +} + +static gchar * +get_provider_name (GoaProvider *provider, + GoaObject *object) +{ + return g_strdup (_("Yandex")); +} + +static GoaProviderGroup +get_provider_group (GoaProvider *provider) +{ + return GOA_PROVIDER_GROUP_BRANDED; +} + +static GoaProviderFeatures +get_provider_features (GoaProvider *provider) +{ + return GOA_PROVIDER_FEATURE_BRANDED | + GOA_PROVIDER_FEATURE_MAIL | + GOA_PROVIDER_FEATURE_CALENDAR | +// GOA_PROVIDER_FEATURE_CONTACTS | + GOA_PROVIDER_FEATURE_FILES; +} + +static const gchar * +get_authorization_uri (GoaOAuth2Provider *oauth2_provider) +{ + return "https://oauth.yandex.ru/authorize"; +} + +static const gchar * +get_token_uri (GoaOAuth2Provider *oauth2_provider) +{ + return "https://oauth.yandex.ru/token"; +} + +static const gchar * +get_redirect_uri (GoaOAuth2Provider *oauth2_provider) +{ + return "http://localhost"; +} + +static const gchar * +get_scope (GoaOAuth2Provider *oauth2_provider) +{ + return "login:email login:info mail:imap_full mail:imap_ro mail:smtp calendar:all yadisk:disk cloud_api:disk.read cloud_api:disk.write"; +} + +static guint +get_credentials_generation (GoaProvider *provider) +{ + return 24; +} + +static const gchar * +get_client_id (GoaOAuth2Provider *oauth2_provider) +{ + return GOA_YANDEX_CLIENT_ID; +} + +static const gchar * +get_client_secret (GoaOAuth2Provider *oauth2_provider) +{ + return GOA_YANDEX_CLIENT_SECRET; +} + +/* ---------------------------------------------------------------------------------------------------- */ + +static gchar * +get_identity_sync (GoaOAuth2Provider *oauth2_provider, + const gchar *access_token, + gchar **out_presentation_identity, + GCancellable *cancellable, + GError **error) +{ + GError *identity_error = NULL; + RestProxy *proxy = NULL; + RestProxyCall *call = NULL; + JsonParser *parser = NULL; + JsonObject *json_object; + gchar *ret = NULL; + gchar *id = NULL; + + /* TODO: cancellable */ + + proxy = goa_rest_proxy_new ("https://login.yandex.ru/info", FALSE); + call = rest_proxy_new_call (proxy); + rest_proxy_call_set_method (call, "GET"); + rest_proxy_call_add_param (call, "oauth_token", access_token); + + if (!rest_proxy_call_sync (call, error)) + goto out; + if (rest_proxy_call_get_status_code (call) != 200) + { + g_set_error (error, + GOA_ERROR, + GOA_ERROR_FAILED, + _("Expected status 200 when requesting your identity, instead got status %d (%s)"), + rest_proxy_call_get_status_code (call), + rest_proxy_call_get_status_message (call)); + goto out; + } + + parser = json_parser_new (); + if (!json_parser_load_from_data (parser, + rest_proxy_call_get_payload (call), + rest_proxy_call_get_payload_length (call), + &identity_error)) + { + g_warning ("json_parser_load_from_data() failed: %s (%s, %d)", + identity_error->message, + g_quark_to_string (identity_error->domain), + identity_error->code); + g_set_error (error, + GOA_ERROR, + GOA_ERROR_FAILED, + _("Could not parse response")); + goto out; + } + + json_object = json_node_get_object (json_parser_get_root (parser)); + if (!json_object_has_member (json_object, "default_email")) + { + g_warning ("Did not find emails in JSON data"); + g_set_error (error, + GOA_ERROR, + GOA_ERROR_FAILED, + _("Could not parse response")); + goto out; + } + + id = g_strdup (json_object_get_string_member (json_object, "default_email")); + + ret = id; + id = NULL; + if (out_presentation_identity != NULL) + *out_presentation_identity = g_strdup(ret); + + out: + g_clear_object (&parser); + g_clear_error (&identity_error); + g_clear_object (&call); + g_clear_object (&proxy); + g_free (id); + return ret; +} + +/* ---------------------------------------------------------------------------------------------------- */ + +static gboolean +is_identity_node (GoaOAuth2Provider *oauth2_provider, WebKitDOMHTMLInputElement *element) +{ + return FALSE; +} + +/* ---------------------------------------------------------------------------------------------------- */ + +static gboolean +build_object (GoaProvider *provider, + GoaObjectSkeleton *object, + GKeyFile *key_file, + const gchar *group, + GDBusConnection *connection, + gboolean just_added, + GError **error) +{ + GoaAccount *account = NULL; + GoaMail *mail = NULL; + gchar *uri_drive; + gchar *uri_caldav; + gchar *uri_carddav; + gboolean ret = FALSE; + gboolean mail_enabled; + gboolean files_enabled; + gboolean calendar_enabled; + gboolean contacts_enabled; + const gchar *email_address; + + /* Chain up */ + if (!GOA_PROVIDER_CLASS (goa_yandex_provider_parent_class)->build_object (provider, + object, + key_file, + group, + connection, + just_added, + error)) + goto out; + + account = goa_object_get_account (GOA_OBJECT (object)); + email_address = goa_account_get_identity (account); + + /* Email */ + mail = goa_object_get_mail (GOA_OBJECT (object)); + mail_enabled = g_key_file_get_boolean (key_file, group, "MailEnabled", NULL); + if (mail_enabled) + { + if (mail == NULL) + { + mail = goa_mail_skeleton_new (); + g_object_set (G_OBJECT (mail), + "email-address", email_address, + "imap-supported", TRUE, + "imap-host", "imap.yandex.ru", + "imap-user-name", email_address, + "imap-use-ssl", TRUE, + "smtp-supported", TRUE, + "smtp-host", "smtp.yandex.ru", + "smtp-user-name", email_address, + "smtp-use-auth", TRUE, + "smtp-auth-xoauth2", TRUE, + "smtp-use-ssl", TRUE, + "smtp-use-tls", TRUE, + NULL); + goa_object_skeleton_set_mail (object, mail); + } + } + else + { + if (mail != NULL) + goa_object_skeleton_set_mail (object, NULL); + } + + /* Calendar */ + calendar_enabled = g_key_file_get_boolean (key_file, group, "CalendarEnabled", NULL); + uri_caldav = g_strconcat ("https://caldav.yandex.ru/", NULL); + goa_object_skeleton_attach_calendar (object, uri_caldav, calendar_enabled, FALSE); + g_free (uri_caldav); + + /* Contacts */ + // contacts_enabled = g_key_file_get_boolean (key_file, group, "ContactsEnabled", NULL); + // uri_carddav = g_strconcat ("https://carddav.yandex.ru/", NULL); + // goa_object_skeleton_attach_contacts (object, uri_carddav, contacts_enabled, FALSE); + // g_free (uri_carddav); + + /* Files */ + files_enabled = g_key_file_get_boolean (key_file, group, "FilesEnabled", NULL); + uri_drive = g_strconcat ("https://cloud-api.yandex.net/v1/disk", NULL); + goa_object_skeleton_attach_files (object, uri_drive, files_enabled, FALSE); + g_free (uri_drive); + + + if (just_added) + { + goa_account_set_mail_disabled (account, !mail_enabled); + goa_account_set_calendar_disabled (account, !calendar_enabled); + goa_account_set_contacts_disabled (account, !contacts_enabled); + goa_account_set_files_disabled (account, !files_enabled); + + g_signal_connect (account, + "notify::mail-disabled", + G_CALLBACK (goa_util_account_notify_property_cb), + (gpointer) "MailEnabled"); + g_signal_connect (account, + "notify::calendar-disabled", + G_CALLBACK (goa_util_account_notify_property_cb), + (gpointer) "CalendarEnabled"); + // g_signal_connect (account, + // "notify::contacts-disabled", + // G_CALLBACK (goa_util_account_notify_property_cb), + // (gpointer) "ContactsEnabled"); + g_signal_connect (account, + "notify::files-disabled", + G_CALLBACK (goa_util_account_notify_property_cb), + (gpointer) "FilesEnabled"); + } + + ret = TRUE; + + out: + g_clear_object (&mail); + g_clear_object (&account); + return ret; +} + +/* ---------------------------------------------------------------------------------------------------- */ + +static void +add_account_key_values (GoaOAuth2Provider *oauth2_provider, + GVariantBuilder *builder) +{ + g_variant_builder_add (builder, "{ss}", "MailEnabled", "true"); + g_variant_builder_add (builder, "{ss}", "CalendarEnabled", "true"); + // g_variant_builder_add (builder, "{ss}", "ContactsEnabled", "true"); + g_variant_builder_add (builder, "{ss}", "FilesEnabled", "true"); +} + +/* ---------------------------------------------------------------------------------------------------- */ + +static void +goa_yandex_provider_init (GoaYandexProvider *self) +{ + +} + +static void +goa_yandex_provider_class_init (GoaYandexProviderClass *klass) +{ + GoaProviderClass *provider_class; + GoaOAuth2ProviderClass *oauth2_class; + + provider_class = GOA_PROVIDER_CLASS (klass); + provider_class->get_provider_type = get_provider_type; + provider_class->get_provider_name = get_provider_name; + provider_class->get_provider_group = get_provider_group; + provider_class->get_provider_features = get_provider_features; + provider_class->build_object = build_object; + provider_class->get_credentials_generation = get_credentials_generation; + + oauth2_class = GOA_OAUTH2_PROVIDER_CLASS (klass); + oauth2_class->get_authorization_uri = get_authorization_uri; + oauth2_class->get_client_id = get_client_id; + oauth2_class->get_client_secret = get_client_secret; + oauth2_class->get_identity_sync = get_identity_sync; + oauth2_class->get_redirect_uri = get_redirect_uri; + oauth2_class->get_scope = get_scope; + oauth2_class->is_identity_node = is_identity_node; + oauth2_class->get_token_uri = get_token_uri; + oauth2_class->add_account_key_values = add_account_key_values; +} diff --git a/src/goabackend/goayandexprovider.h b/src/goabackend/goayandexprovider.h new file mode 100644 index 0000000..bd4315f --- /dev/null +++ b/src/goabackend/goayandexprovider.h @@ -0,0 +1,37 @@ +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ +/* + * Copyright © 2011 – 2017 Red Hat, Inc. + * + * 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 . + */ + +#if !defined (__GOA_BACKEND_INSIDE_GOA_BACKEND_H__) && !defined (GOA_BACKEND_COMPILATION) +#error "Only can be included directly." +#endif + +#ifndef __GOA_YANDEX_PROVIDER_H__ +#define __GOA_YANDEX_PROVIDER_H__ + +#include + +#include "goaoauth2provider-priv.h" + +G_BEGIN_DECLS + +#define GOA_TYPE_YANDEX_PROVIDER (goa_yandex_provider_get_type ()) +G_DECLARE_FINAL_TYPE (GoaYandexProvider, goa_yandex_provider, GOA, YANDEX_PROVIDER, GoaOAuth2Provider); + +G_END_DECLS + +#endif /* __GOA_YANDEX_PROVIDER_H__ */ -- 2.39.1