2 * This file is part of sharing-plugin-template
4 * Copyright (C) 2008-2009 Nokia Corporation. All rights reserved.
6 * This maemo code example is licensed under a MIT-style license,
7 * that can be found in the file called "COPYING" in the root
22 * @account: #SharingTransfer to be send
23 * @con: Connection used
24 * @dead_mans_switch: Turn to %FALSE at least every 30 seconds.
26 * Sends #SharingTransfer to service.
28 * Returns: #SharingPluginInterfaceSendResult
30 SharingPluginInterfaceSendResult share_item (SharingTransfer* transfer,
31 ConIcConnection* con, gboolean* dead_mans_switch)
33 SharingPluginInterfaceSendResult ret = SHARING_SEND_ERROR_UNKNOWN;
34 SharingEntry *entry = sharing_transfer_get_entry( transfer );
36 yandexPhotoAccessType access = YANDEX_PHOTO_ACCESS_PUBLIC;
37 const gchar* privacyOption = sharing_entry_get_option(entry,"privacy");
39 if (strcmp(privacyOption,"friends")==0) access = YANDEX_PHOTO_ACCESS_FRIENDS;
40 else if (strcmp(privacyOption,"private")==0) access = YANDEX_PHOTO_ACCESS_PRIVATE;
42 yandexPhotoPublishSettings publish = YANDEX_PHOTO_DONT_PUBLISH;
43 const gchar* publishOption = sharing_entry_get_option(entry,"publish");
45 if (strcmp(publishOption,"yes")==0) publish = YANDEX_PHOTO_PUBLISH;
47 const gchar* album = sharing_entry_get_option(entry,"album");
48 if (strcmp(album,"0")==0) album = NULL;
50 SharingAccount* account = sharing_entry_get_account(entry);
51 char* sessionKey = NULL;
52 char* sessionRequestId = NULL;
55 yandexGetAuthTokenResult token_res = YANDEX_GET_AUTH_TOKEN_FAILED;
56 *dead_mans_switch = FALSE;
57 if (yandexGetSessionKey(&sessionKey, &sessionRequestId) == YANDEX_GET_SESSION_KEY_SUCCESS) {
58 *dead_mans_switch = FALSE;
59 token_res = yandexGetAuthToken(sessionRequestId, sessionKey,
60 sharing_account_get_username(account), sharing_account_get_password(account),
63 *dead_mans_switch = FALSE;
65 if (YANDEX_GET_AUTH_TOKEN_SUCCESS == token_res && token != NULL) {
67 ret = SHARING_SEND_SUCCESS;
68 for (p = sharing_entry_get_media (entry); p != NULL; p = g_slist_next(p)) {
69 *dead_mans_switch = FALSE;
70 if (!sharing_transfer_continue(transfer)) break;
71 SharingEntryMedia* media = p->data;
72 if (!sharing_entry_media_get_sent (media)) {
73 yandexPhotoOptions options;
74 options.album = album;
75 options.access = access;
76 yandexSendPhotoResult send_res = yandexSendPhoto(token,media,transfer,options);
77 if (YANDEX_SEND_PHOTO_SUCCESS == send_res) sharing_entry_media_set_sent(media,TRUE);
78 else ret = SHARING_SEND_ERROR_AUTH;
81 if (!sharing_transfer_continue(transfer)) ret = SHARING_SEND_CANCELLED;
82 } else if (YANDEX_GET_AUTH_TOKEN_INVALID_USER == token_res) {
83 ret = SHARING_SEND_ERROR_AUTH;
86 if (token) free(token);
87 if (sessionKey) free(sessionKey);
88 if (sessionRequestId) free(sessionRequestId);