From 9a03f1d0a2f500998963c3f5f1d55a472eb19110 Mon Sep 17 00:00:00 2001 From: Heikki Kallasjoki Date: Tue, 10 Nov 2009 17:48:41 +0200 Subject: [PATCH] Import the initial Gallery 2 code --- Makefile.am | 8 +- configure.ac | 6 +- data/Makefile.am | 11 +- data/gallery2-icon.png | Bin 0 -> 4345 bytes data/gallery2.service.xml.in | 21 ++ data/template-post.png | Bin 950 -> 0 bytes data/template-setup.png | Bin 950 -> 0 bytes data/template.service.xml.in | 22 -- debian/changelog | 12 +- debian/control | 8 +- debian/copyright | 6 +- debian/sharing-plugin-gallery2.install | 3 + debian/sharing-plugin-template.install | 3 - debian/sharing-service-gallery2.prerm | 6 + debian/sharing-service-template.prerm | 6 - src/Makefile.am | 21 +- src/common.c | 31 -- src/common.h | 25 -- src/gallery2.c | 531 ++++++++++++++++++++++++++++++++ src/gallery2.h | 41 +++ src/plugin.c | 446 ++++++++++++++++++++++++--- src/send.c | 59 ---- src/send.h | 29 -- src/validate.c | 55 ---- src/validate.h | 28 -- 25 files changed, 1029 insertions(+), 349 deletions(-) create mode 100644 data/gallery2-icon.png create mode 100644 data/gallery2.service.xml.in delete mode 100644 data/template-post.png delete mode 100644 data/template-setup.png delete mode 100644 data/template.service.xml.in create mode 100644 debian/sharing-plugin-gallery2.install delete mode 100644 debian/sharing-plugin-template.install create mode 100644 debian/sharing-service-gallery2.prerm delete mode 100644 debian/sharing-service-template.prerm delete mode 100644 src/common.c delete mode 100644 src/common.h create mode 100644 src/gallery2.c create mode 100644 src/gallery2.h delete mode 100644 src/send.c delete mode 100644 src/send.h delete mode 100644 src/validate.c delete mode 100644 src/validate.h diff --git a/Makefile.am b/Makefile.am index 55f2fa8..f7f66f9 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,11 +1,11 @@ # -# This file is part of sharing-plugin-template +# This file is part of sharing-plugin-gallery2 # +# Copyright (C) 2009 Heikki Kallasjoki. All rights reserved. # Copyright (C) 2008-2009 Nokia Corporation. All rights reserved. # -# This maemo code example is licensed under a MIT-style license, -# that can be found in the file called "COPYING" in the root -# directory. +# This code is licensed under a MIT-style license, that can be +# found in the file called "COPYING" in the root directory. # SUBDIRS = src data diff --git a/configure.ac b/configure.ac index 3bf0ed2..ac90448 100644 --- a/configure.ac +++ b/configure.ac @@ -1,4 +1,4 @@ -AC_INIT([sharing-plugin-template], [0.1]) +AC_INIT([sharing-plugin-gallery2], [0.1]) AM_INIT_AUTOMAKE([foreign]) AM_MAINTAINER_MODE @@ -46,7 +46,7 @@ dnl ===== Checks for libraries dnl ======================================================= dnl PKG_CHECK_MODULES(PACKAGE, [glib-2.0 gtk+-2.0 libsharing conic libosso]) -PKG_CHECK_MODULES(PACKAGE, [glib-2.0 gtk+-2.0 libsharing conic]) +PKG_CHECK_MODULES(PACKAGE, [glib-2.0 gtk+-2.0 libsharing conic hildon-1]) AC_SUBST(PACKAGE_CFLAGS) AC_SUBST(PACKAGE_LIBS) @@ -101,7 +101,7 @@ dnl ======================================================= AC_OUTPUT([ Makefile data/Makefile - data/template.service.xml + data/gallery2.service.xml src/Makefile ]) diff --git a/data/Makefile.am b/data/Makefile.am index 0ba93ba..342ae97 100644 --- a/data/Makefile.am +++ b/data/Makefile.am @@ -1,16 +1,15 @@ # -# This file is part of sharing-plugin-template +# This file is part of sharing-plugin-gallery2 # +# Copyright (C) 2009 Heikki Kallasjoki. All rights reserved. # Copyright (C) 2008-2009 Nokia Corporation. All rights reserved. # -# This maemo code example is licensed under a MIT-style license, -# that can be found in the file called "COPYING" in the root -# directory. +# This code is licensed under a MIT-style license, that can be +# found in the file called "COPYING" in the root directory. # -services_DATA = template.service.xml template-post.png template-setup.png +services_DATA = gallery2.service.xml gallery2-icon.png EXTRA_DIST = $(services) MAINTAINERCLEANFILES = Makefile.in - diff --git a/data/gallery2-icon.png b/data/gallery2-icon.png new file mode 100644 index 0000000000000000000000000000000000000000..94b7659e74001dd0eabf6dc3c2ff729237378f01 GIT binary patch literal 4345 zcmVPx_vq?ljR9M5+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tTx{Ih)EBT-OVwWjR7fDTI_ea)`-j4XrgR6>&7`al6$t8=GBy zJDHi(<)OAo?_JLoXD(H0wR4qf_4QJ@db3ojw8Aiq4lEYU`)-ZTR{~yd^v5K`ZOaWK z*r{gMb+3)Giw7IM^+T=U=DgEsWLx z6&j8DY^T2Zz;N@z4EI-xh+1W+aTPi)v58a6>=-7YS+a(swDgBcX0{WjyhUMcE0Zm3 z74wzDn+Z$%Ld!zJrr=RV0yXE0< zP@9ZLl{kvhT5Fe?1rdxTNI9-O^gXwk3cTCdOt6*7WZSu1uAR#ldbwO-Tq}8r{XU*> z-Z#*@vD+9?G>K#!Ppsi^=#IzZR1{4zaU7+UHZB`uftdhe5@duFkz+eU*Y$dy=k + + + + http://gallery.menalto.com/ + + + + + Gallery 2 + @servicesdir@/gallery2-icon.png + @servicesdir@/gallery2-icon.png + + + + + diff --git a/data/template-post.png b/data/template-post.png deleted file mode 100644 index cb762336f46ae1c52cb63a70082ef54a225cd93a..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 950 zcmV;n14;aeP)Px#32;bRa{vGf6951U69E94oEQKA00(qQO+^RU0}~4o70$R#`~Uy|8FWQhbVF}# zZDnqB07G(RVRU6=Aa`kWXdp*PO;A^X4i^9b10zX9K~z}7<(N%KR8bVie|KhlqmxdV z7HOhUXciJ>9}r>GCP*kEuv!R$K~My3qfHXDsJ2B!5)@X8TC{0V^tCV|A^Je7l|@rx zRzix}jJzIPw|?m6dw?w3$XF@F|eUM=SH{~_cPzo%BkGB5MB7QM(Ysf|TkzAUyQpqdFY+%s$eG97&b~$)Npw(pnCO!5c!}ykcEKkA zWkH+$u9QJJ2%;Vb5eBtwM zhR@7=^@vwDk$Ygo6BXySWau=hBiWRAz^i-64w!QB+hZ8AuRps-a5?V#JU z1BAi&?fXTBFFQ-`4{|fA-=6JDbhfXmgr+`9nhJQYF4(gP;kWr!PBL)RECMtBJMw}H z*fqkgU8B8>+_S^WOEBi{w+cix+u%9llYyT?U2|d+DB!kP8|!2IbuL~#hj0E;?%j2j z>jUuXP9FZD%i`b*Q>e?Z-w*SG-{(Vgep7B8!9+iD+`uc;$58d=r7LG0&5#~2@M-wr zqB}JgVK7_ftAUr037&HNEJB9qf6TcTzIErfDDtQKS?R?f5nOk{f*)OI;5Df7t-D}U z!{T+O;EN_F*F!4bI*wQpt=5d+7Q}ClT~;gIf+#Xeuhm|C!6tdv;4f;;o%O^T#D?Ia z^FG}IqKJyNyh&Fejs@IYIPV6mR=2?DfQcL|dqecXmBqN9{R>jkX|i1y%>Ic!%IeifOn_tlasSv53fhSQfV4 z^6(-`{dG#WdN}2XRm7e`U8u<}2cl8m!{P&;&v>Gd_zNN}p>}y$)2dkeh>Al#Pq?Cr zlE=i)Lc*)i@>4FTJjl8?l(mGo-H@M|IK$*E^tAg)YPu~b+fGdv$sKcYxdL*K$s0`E zCH)rtZ^5Ho(F&4#sq7%pJcoBX=5Y*@ensXzQz`T@q(T%Etww90q#13cuiG;5U*GHf Y19p+;L;%~24FCWD07*qoM6N<$f>k-aUH||9 diff --git a/data/template-setup.png b/data/template-setup.png deleted file mode 100644 index 408a18a16a74f03eca603c06324ddfc8be5fb577..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 950 zcmV;n14;aeP)Px#32;bRa{vGf6951U69E94oEQKA00(qQO+^RU0}~4oB6bDn^8f$<8FWQhbVF}# zZDnqB07G(RVRU6=Aa`kWXdp*PO;A^X4i^9b10zX9K~z}7<(N%KR8bVie|KhlqmxdV z7HOhUXciJ>9}r>GCP*kEuv!R$K~My3qfHXDsJ2B!5)@X8TC{0V^tCV|A^Je7l|@rx zRzix}jJzIPw|?m6dw?w3$XF@F|eUM=SH{~_cPzo%BkGB5MB7QM(Ysf|TkzAUyQpqdFY+%s$eG97&b~$)Npw(pnCO!5c!}ykcEKkA zWkH+$u9QJJ2%;Vb5eBtwM zhR@7=^@vwDk$Ygo6BXySWau=hBiWRAz^i-64w!QB+hZ8AuRps-a5?V#JU z1BAi&?fXTBFFQ-`4{|fA-=6JDbhfXmgr+`9nhJQYF4(gP;kWr!PBL)RECMtBJMw}H z*fqkgU8B8>+_S^WOEBi{w+cix+u%9llYyT?U2|d+DB!kP8|!2IbuL~#hj0E;?%j2j z>jUuXP9FZD%i`b*Q>e?Z-w*SG-{(Vgep7B8!9+iD+`uc;$58d=r7LG0&5#~2@M-wr zqB}JgVK7_ftAUr037&HNEJB9qf6TcTzIErfDDtQKS?R?f5nOk{f*)OI;5Df7t-D}U z!{T+O;EN_F*F!4bI*wQpt=5d+7Q}ClT~;gIf+#Xeuhm|C!6tdv;4f;;o%O^T#D?Ia z^FG}IqKJyNyh&Fejs@IYIPV6mR=2?DfQcL|dqecXmBqN9{R>jkX|i1y%>Ic!%IeifOn_tlasSv53fhSQfV4 z^6(-`{dG#WdN}2XRm7e`U8u<}2cl8m!{P&;&v>Gd_zNN}p>}y$)2dkeh>Al#Pq?Cr zlE=i)Lc*)i@>4FTJjl8?l(mGo-H@M|IK$*E^tAg)YPu~b+fGdv$sKcYxdL*K$s0`E zCH)rtZ^5Ho(F&4#sq7%pJcoBX=5Y*@ensXzQz`T@q(T%Etww90q#13cuiG;5U*GHf Y19p+;L;%~24FCWD07*qoM6N<$g65FC@&Et; diff --git a/data/template.service.xml.in b/data/template.service.xml.in deleted file mode 100644 index faad554..0000000 --- a/data/template.service.xml.in +++ /dev/null @@ -1,22 +0,0 @@ - - - - - http://www.maemo.org - - - - - Template - @servicesdir@/template-post.png - @servicesdir@/template-setup.png - - - - - - diff --git a/debian/changelog b/debian/changelog index 28411f9..8825958 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,12 +1,6 @@ -sharing-plugin-template (0.2) unstable; urgency=low +sharing-plugin-gallery2 (0.1) unstable; urgency=low - * Update + * Initial released version - -- Maemo Team Wed, 18 Mar 2009 16:49:55 +0200 - -sharing-plugin-template (0.1) unstable; urgency=low - - * Update - - -- Maemo Team Wed, 18 Mar 2009 16:49:55 +0200 + -- Heikki Kallasjoki Sun, 08 Nov 2009 00:53:51 +0200 diff --git a/debian/control b/debian/control index f2e80b1..355de1d 100644 --- a/debian/control +++ b/debian/control @@ -1,15 +1,15 @@ -Source: sharing-plugin-template +Source: sharing-plugin-gallery2 Section: user/other Priority: optional -Maintainer: Maemo Team +Maintainer: Heikki Kallasjoki Build-Depends: debhelper (>= 5.0.0), libgtk2.0-dev, libglib2.0-dev, libconic0-dev, libosso-dev, libsharing-plugin-dev Standards-Version: 3.8.0 -Package: sharing-plugin-template +Package: sharing-plugin-gallery2 Section: user/other Architecture: any Depends: ${shlibs:Depends}, ${misc:Depends}, sharing-manager, libsharing0 -Description: Maemo Share Plugin template for an service +Description: Maemo Share Plugin for a Gallery 2 service diff --git a/debian/copyright b/debian/copyright index fc44a81..8ad171d 100644 --- a/debian/copyright +++ b/debian/copyright @@ -1,7 +1,9 @@ +Copyright: (c) 2009 Heikki Kallasjoki Copyright: (c) 2008-2009 Nokia Corporation -The code examples copyrighted by Nokia Corporation that are included to -this material are licensed to you under following MIT-style License: +This code is licensed under the following MIT-style License. +It is based on the sharing-plugin-template code example copyrighted +by Nokia Corporation, licensed under the same License. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the diff --git a/debian/sharing-plugin-gallery2.install b/debian/sharing-plugin-gallery2.install new file mode 100644 index 0000000..baac9bf --- /dev/null +++ b/debian/sharing-plugin-gallery2.install @@ -0,0 +1,3 @@ +usr/lib/sharing/plugins/*.so* +usr/share/sharing/services/* + diff --git a/debian/sharing-plugin-template.install b/debian/sharing-plugin-template.install deleted file mode 100644 index baac9bf..0000000 --- a/debian/sharing-plugin-template.install +++ /dev/null @@ -1,3 +0,0 @@ -usr/lib/sharing/plugins/*.so* -usr/share/sharing/services/* - diff --git a/debian/sharing-service-gallery2.prerm b/debian/sharing-service-gallery2.prerm new file mode 100644 index 0000000..a6a4528 --- /dev/null +++ b/debian/sharing-service-gallery2.prerm @@ -0,0 +1,6 @@ +#!/bin/sh +# You can use sharing-account-remover to remove the accounts at plugin +# uninstallation +if [ "$1" = "remove" ]; then + /usr/bin/sharing-account-remover sharingplugingallery2 +fi diff --git a/debian/sharing-service-template.prerm b/debian/sharing-service-template.prerm deleted file mode 100644 index cffbdbd..0000000 --- a/debian/sharing-service-template.prerm +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/sh -# You can use sharing-account-remover to remove the accounts at plugin -# uninstallation -if [ "$1" = "remove" ]; then - /usr/bin/sharing-account-remover sharingplugintemplate -fi diff --git a/src/Makefile.am b/src/Makefile.am index f79d74c..d9d5558 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,22 +1,19 @@ # -# This file is part of sharing-plugin-template +# This file is part of sharing-plugin-gallery2 # +# Copyright (C) 2009 Heikki Kallasjoki. All rights reserved. # Copyright (C) 2008-2009 Nokia Corporation. All rights reserved. # -# This maemo code example is licensed under a MIT-style license, -# that can be found in the file called "COPYING" in the root -# directory. +# This code is licensed under a MIT-style license, that can be +# found in the file called "COPYING" in the root directory. # -plugins_LTLIBRARIES = libtemplate.la +plugins_LTLIBRARIES = libsharingplugingallery2.la -libtemplate_la_SOURCES = plugin.c common.c send.c validate.c - -libtemplate_la_CFLAGS = $(PACKAGE_CFLAGS) $(DEBUG_CFLAGS) -libtemplate_la_LDFLAGS = -module -avoid-version -export-dynamic -libtemplate_la_LIBADD = $(PACKAGE_LIBS) +libsharingplugingallery2_la_SOURCES = plugin.c gallery2.c +libsharingplugingallery2_la_CFLAGS = $(PACKAGE_CFLAGS) $(DEBUG_CFLAGS) +libsharingplugingallery2_la_LDFLAGS = -module -avoid-version -export-dynamic +libsharingplugingallery2_la_LIBADD = $(PACKAGE_LIBS) MAINTAINERCLEANFILES = Makefile.in - - diff --git a/src/common.c b/src/common.c deleted file mode 100644 index 2f47076..0000000 --- a/src/common.c +++ /dev/null @@ -1,31 +0,0 @@ -/* - * This file is part of sharing-plugin-template - * - * Copyright (C) 2008-2009 Nokia Corporation. All rights reserved. - * - * This maemo code example is licensed under a MIT-style license, - * that can be found in the file called "COPYING" in the root - * directory. - * - */ - -#include -#include -#include -#include -#include "common.h" - -/** - * example_function: - * @username: Example parameter - * @password: Example parameter - * - * Example function - * - * Returns: Newly allocated string or %NULL - */ -gchar* example_function (const gchar* username, const gchar* password) -{ - return NULL; -} - diff --git a/src/common.h b/src/common.h deleted file mode 100644 index 3e9b700..0000000 --- a/src/common.h +++ /dev/null @@ -1,25 +0,0 @@ -/* - * This file is part of sharing-plugin-template - * - * Copyright (C) 2008-2009 Nokia Corporation. All rights reserved. - * - * This maemo code example is licensed under a MIT-style license, - * that can be found in the file called "COPYING" in the root - * directory. - * - */ - -#ifndef _COMMON_H_ -#define _COMMON_H_ - -#include -#include - -G_BEGIN_DECLS - -gchar* example_function (const gchar* username, const gchar* password); - -G_END_DECLS - -#endif // _COMMON_H_ - diff --git a/src/gallery2.c b/src/gallery2.c new file mode 100644 index 0000000..09caf67 --- /dev/null +++ b/src/gallery2.c @@ -0,0 +1,531 @@ +/* + * This file is part of sharing-plugin-gallery2 + * + * Copyright (C) 2009 Heikki Kallasjoki. All rights reserved. + * Copyright (C) 2008-2009 Nokia Corporation. All rights reserved. + * + * This code is licensed under a MIT-style license, that can be + * found in the file called "COPYING" in the root directory. + * + */ + +#include +#include +#include +#include +#include +#include "gallery2.h" + +/** + * gallery2_login: + * @con: Connection to use + * @urlbase: Base URL to the Gallery 2 site + * @username: User name + * @password: Password + * @cookies: Output parameter for any cookies set. + * @auth: Output paremeter for the authentication token. + * + * Logs in to the Gallery 2 service. + * + * Returns: Validation result. + */ +SharingPluginInterfaceAccountValidateResult +gallery2_login (ConIcConnection* con, + const gchar* urlbase, const gchar* username, const gchar* password, + GHashTable** cookies, gchar** auth) +{ + SharingPluginInterfaceAccountValidateResult ret = SHARING_ACCOUNT_VALIDATE_SUCCESS; + + SharingHTTP* http = sharing_http_new (); + + *cookies = 0; + *auth = 0; + + /* Do the login request */ + + gchar* url = g_strdup_printf("%s/main.php?g2_controller=remote:GalleryRemote&" + "g2_form[cmd]=login&g2_form[protocol_version]=2.0&" + "g2_form[uname]=%s&g2_form[password]=%s", + urlbase, username, password); + + sharing_http_set_connection (http, con); + SharingHTTPRunResponse res = sharing_http_run (http, url); + + g_free (url); + url = 0; + + /* Parse the response */ + + if (res == SHARING_HTTP_RUNRES_SUCCESS && sharing_http_get_res_code (http) == 200) + { + /* Split response into lines */ + + gchar** lines = 0; + + { + gsize content_len = 0; + const gchar* content = sharing_http_get_res_content (http, &content_len); + gchar* c = g_strndup (content, content_len); /* force \0 termination */ + lines = g_strsplit_set (c, "\r\n", 0); + g_free (c); + } + + /* Process the lines */ + + *cookies = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); + + gboolean in_body = FALSE; + + for (gchar** p = lines; *p; p++) + { + gchar* line = *p; + + if (!in_body) + { + if (g_ascii_strncasecmp (line, "Set-Cookie:", 11) == 0) + { + /* Extract the key=value part of the cookie */ + + gchar** data = 0; + + { + gchar* c = g_strchug (line+11); /* start of cookie data */ + + char* end = strchr (c, ';'); + if (end) *end = 0; + + data = g_strsplit (c, "=", 2); + } + + if (!data[0] || !data[1]) + { + /* Bad Set-Cookie: header, ignore */ + g_strfreev (data); + continue; + } + + /* Insert into our table */ + + g_hash_table_replace (*cookies, data[0], data[1]); + g_free (data); /* not g_strfreev! strings still used in "cookies" */ + + continue; + } + + if (g_str_has_prefix (line, "#__GR2PROTO__")) + { + in_body = TRUE; + continue; + } + } + else + { + /* Split key=value into fields */ + + gchar* value = strchr (line, '='); + if (!value) continue; + *value = 0; + value++; + + /* Process the necessary parts */ + + if (strcmp (line, "status") == 0 && strcmp (value, "0") != 0) + { + ULOG_ERR_L ("Gallery 2 login auth failed\n"); + ret = SHARING_ACCOUNT_VALIDATE_FAILED; + break; + } + + if (strcmp (line, "auth_token") == 0) + { + *auth = g_strdup (value); + continue; + } + } + } + + g_strfreev (lines); + } + else + { + ULOG_ERR_L ("Gallery 2 login connection failed\n"); + ret = SHARING_ACCOUNT_VALIDATE_ERROR_CONNECTION; + } + + if (ret != SHARING_ACCOUNT_VALIDATE_SUCCESS) + { + if (*cookies) g_hash_table_unref (*cookies); + if (*auth) g_free (auth); + *cookies = 0; + *auth = 0; + } + + sharing_http_unref (http); + return ret; +} + +/** + * gallery2_lookup_album: + * @con: Connection to use + * @urlbase: Base URL to the Gallery 2 site + * @albumpath: Slash-separated path to album + * @album: Output parameter to hold the album ID + * @cookies: Cookies from gallery2_login. + * @auth: Authentication token from gallery2_login. + * + * Retrieves the album id based on an album path. + */ +SharingPluginInterfaceAccountValidateResult +gallery2_lookup_album (ConIcConnection* con, + const gchar* urlbase, const gchar* albumpath, gchar** album, + GHashTable* cookies, gchar* auth) +{ + SharingPluginInterfaceAccountValidateResult ret = SHARING_ACCOUNT_VALIDATE_ERROR_UNKNOWN; + + SharingHTTP* http = sharing_http_new (); + + /* Prepare and send the request */ + + gchar* url = g_strdup_printf("%s/main.php?g2_controller=remote:GalleryRemote%s%s&" + "g2_form[cmd]=fetch-albums-prune&g2_form[protocol_version]=2.2&g2_form[no_perms]=yes", + urlbase, + auth ? "&g2_authToken=" : "", auth ? auth : ""); + + if (cookies) + { + GHashTableIter iter; + gpointer key, value; + g_hash_table_iter_init (&iter, cookies); + while (g_hash_table_iter_next (&iter, &key, &value)) + { + gchar* hdr = g_strdup_printf("Cookie: %s=%s", (gchar*)key, (gchar*)value); + sharing_http_add_req_header_line (http, hdr); + g_free (hdr); + } + } + + sharing_http_set_connection (http, con); + SharingHTTPRunResponse res = sharing_http_run (http, url); + + g_free (url); + url = 0; + + /* Parse the response into an album map. */ + + GHashTable* album_names = 0; /* map string (display-name) -> GSList [ string (url-name) ] */ + GHashTable* album_parent = 0; /* map string (url-name) -> string (url-name) */ + gchar* album_root = 0; /* root album url-name */ + gboolean valid = FALSE; /* true if the maps are usable */ + char** lines = 0; /* raw data (response lines) */ + + if (res == SHARING_HTTP_RUNRES_SUCCESS && sharing_http_get_res_code (http) == 200) + { + { + gsize content_len = 0; + const gchar* content = sharing_http_get_res_body (http, &content_len); + gchar* c = g_strndup (content, content_len); /* force \0 termination */ + lines = g_strsplit_set (c, "\r\n", 0); + g_free (c); + } + + gboolean in_body = FALSE; + gchar* current_ref_num = 0; + gchar* current_url_name = 0; + + for (gchar** p = lines; *p; p++) + { + gchar* line = *p; + + if (!in_body) + { + if (g_str_has_prefix (line, "#__GR2PROTO__")) + { + album_names = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, (GDestroyNotify)g_slist_free); + album_parent = g_hash_table_new (g_str_hash, g_str_equal); + in_body = TRUE; + } + continue; + } + + gchar* value = strchr (line, '='); + if (!value) continue; + *value = 0; + value++; + + if (strcmp (line, "status") == 0) + { + if (strcmp (value, "0") == 0) + valid = TRUE; + continue; + } + else if (g_str_has_prefix (line, "album.name.")) + { + current_ref_num = line + 11; + current_url_name = value; + } + else if (g_str_has_prefix (line, "album.title.")) + { + if (!current_ref_num || strcmp (current_ref_num, line + 12) != 0) + continue; + GSList* others = g_hash_table_lookup (album_names, value); + if (others) g_hash_table_steal (album_names, value); + g_hash_table_insert (album_names, value, g_slist_prepend (others, current_url_name)); + } + else if (g_str_has_prefix (line, "album.parent.")) + { + if (!current_ref_num || strcmp (current_ref_num, line + 13) != 0) + continue; + g_hash_table_insert (album_parent, current_url_name, value); + if (strcmp (value, "0") == 0) + album_root = current_url_name; + } + } + } + else + ret = SHARING_ACCOUNT_VALIDATE_ERROR_CONNECTION; + + sharing_http_unref (http); + + /* Find the album we are interested in. */ + + *album = 0; + + if (album_names && album_parent && album_root && valid) + { + gchar* current_album = album_root; + gboolean seen_parents = FALSE; /* for the root special case */ + gboolean found_final = FALSE; /* to make sure the last real component is found */ + + gchar** components = g_strsplit (albumpath, "/", 0); + + for (gchar** p = components; *p; p++) + { + if (!**p) continue; /* ignore empty path components */ + found_final = FALSE; /* this component needs to be found */ + GSList* candidates = g_hash_table_lookup (album_names, *p); + /* bad case: no candidates at all */ + if (!candidates) break; + /* special case 1: if only one candidate and no unseen parents, choose that */ + if (!seen_parents && !g_slist_next (candidates)) + { + found_final = TRUE; + current_album = candidates->data; + continue; + } + /* general case: find a candidate with an acceptable parent */ + while (candidates) + { + gchar* parent = g_hash_table_lookup (album_parent, candidates->data); + /* suitable parents: current_album, or (if no specified parents) null or 0 (explicit root case) */ + if ((parent && strcmp (parent, current_album) == 0) + || (!seen_parents && (!parent || strcmp (parent, "0") == 0))) + { + found_final = TRUE; + current_album = candidates->data; + break; + } + candidates = g_slist_next (candidates); /* try next */ + } + } + + g_strfreev (components); + + if (found_final) + { + *album = g_strdup(current_album); + ret = SHARING_ACCOUNT_VALIDATE_SUCCESS; + } + } + + if (album_names) g_hash_table_unref (album_names); + if (album_parent) g_hash_table_unref (album_parent); + g_strfreev (lines); + + return ret; +} + +/* gallery2_send callback helper declarations */ + +struct gallery2_send_record +{ + SharingTransfer* transfer; + gdouble progress_start; + gdouble progress_end; + guint64 media_bytes; + gboolean* dms; +}; + +gboolean gallery2_send_callback (SharingHTTP* http, guint64 bytes_sent, gpointer user_data); + +/** + * gallery2_send: + * @con: Connection to use + * @transfer: Sharing transfer object + * @progress_start: Initial state of progress meter + * @progress_end: Desired final state of progress meter + * @dms: Dead man's switch + * @media: Media item to send + * @urlbase: Base URL to the Gallery 2 site + * @album: Album ID from gallery2_lookup_album. + * @cookies: Cookies from gallery2_login. + * @auth: Authentication token from gallery2_login. + * + * Sends a media item to a Gallery 2 service. + * + * Returns: Send result. + */ +SharingPluginInterfaceSendResult +gallery2_send (ConIcConnection* con, + SharingTransfer* transfer, gdouble progress_start, gdouble progress_end, gboolean *dms, + SharingEntryMedia* media, + const gchar* urlbase, const gchar* album, GHashTable* cookies, gchar* auth) +{ + struct gallery2_send_record rec = { + .transfer = transfer, + .progress_start = progress_start, + .progress_end = progress_end, + .media_bytes = 0, + .dms = dms + }; + + SharingPluginInterfaceSendResult ret = SHARING_SEND_SUCCESS; + + SharingHTTP* http = sharing_http_new (); + + /* Prepare and send the request */ + + /* gchar* album = "1652"; */ /* TODO: get from UI/login */ + + gchar* media_title = sharing_entry_media_get_title (media); + gchar* media_mime = sharing_entry_media_get_mime (media); + gchar* media_filename = sharing_entry_media_get_filename (media); + + const gchar* desc = sharing_entry_media_get_desc (media); + + gchar* url = g_strdup_printf("%s/main.php?g2_controller=remote:GalleryRemote%s%s&" + "g2_form[cmd]=add-item&g2_form[protocol_version]=2.0&" + "g2_form[set_albumName]=%s&g2_form[caption]=%s" + "%s%s%s%s", + urlbase, + auth ? "&g2_authToken=" : "", auth ? auth : "", + album, media_title, + desc ? "&g2_form[extrafield.Summary]=" : "", desc ? desc : "", + desc ? "&g2_form[extrafield.Description]=" : "", desc ? desc : ""); + + if (cookies) + { + GHashTableIter iter; + gpointer key, value; + g_hash_table_iter_init (&iter, cookies); + while (g_hash_table_iter_next (&iter, &key, &value)) + { + gchar* hdr = g_strdup_printf("Cookie: %s=%s", (gchar*)key, (gchar*)value); + sharing_http_add_req_header_line (http, hdr); + g_free (hdr); + } + } + + sharing_http_add_req_multipart_file_with_filename (http, + "g2_userfile", + sharing_entry_media_get_localpath (media), + media_mime ? media_mime : "image/jpeg", + media_filename ? media_filename : "unknown.jpg"); + + g_free (media_title); + g_free (media_mime); + g_free (media_filename); + + media_title = media_mime = media_filename = 0; + + rec.media_bytes = sharing_entry_media_get_size (media); + sharing_http_set_progress_callback (http, gallery2_send_callback, &rec); + + *dms = FALSE; + sharing_http_set_connection (http, con); + SharingHTTPRunResponse res = sharing_http_run (http, url); + *dms = FALSE; + + g_free (url); + url = 0; + + /* Parse the response */ + + if (res == SHARING_HTTP_RUNRES_SUCCESS && sharing_http_get_res_code (http) == 200) + { + gchar** lines = 0; + + { + gsize content_len = 0; + const gchar* content = sharing_http_get_res_body (http, &content_len); + gchar* c = g_strndup (content, content_len); /* force \0 termination */ + lines = g_strsplit_set (c, "\r\n", 0); + g_free (c); + } + + gboolean in_body = FALSE; + ret = SHARING_SEND_ERROR_UNKNOWN; + + for (gchar** p = lines; *p; p++) + { + gchar* line = *p; + + if (!in_body) + { + if (g_str_has_prefix (line, "#__GR2PROTO__")) + in_body = TRUE; + continue; + } + + gchar* value = strchr (line, '='); + if (!value) continue; + *value = 0; + value++; + + if (strcmp (line, "status") == 0) + { + if (strcmp (value, "0") == 0) + ret = SHARING_SEND_SUCCESS; + break; + } + } + + g_strfreev (lines); + } + else if (res == SHARING_HTTP_RUNRES_CANCELLED) + ret = SHARING_SEND_CANCELLED; + else + ret = SHARING_SEND_ERROR_CONNECTION; + + sharing_http_unref (http); + + *dms = FALSE; + sharing_transfer_set_progress (transfer, progress_end); + + return ret; +} + +/* gallery2_send callback implementation */ + +gboolean gallery2_send_callback (SharingHTTP* http, guint64 bytes_sent, gpointer user_data) +{ + struct gallery2_send_record* rec = user_data; + + if (!sharing_transfer_continue (rec->transfer)) + return FALSE; + + *rec->dms = FALSE; + + gdouble progress = (rec->progress_start + rec->progress_end) / 2.0; + + if (rec->media_bytes) + { + if (bytes_sent >= rec->media_bytes) + progress = rec->progress_end; + else + progress = rec->progress_start + (bytes_sent / (gdouble)rec->media_bytes) * (rec->progress_end - rec->progress_start); + } + + sharing_transfer_set_progress (rec->transfer, progress); + + return TRUE; +} diff --git a/src/gallery2.h b/src/gallery2.h new file mode 100644 index 0000000..195f203 --- /dev/null +++ b/src/gallery2.h @@ -0,0 +1,41 @@ +/* + * This file is part of sharing-plugin-gallery2 + * + * Copyright (C) 2009 Heikki Kallasjoki. All rights reserved. + * Copyright (C) 2008-2009 Nokia Corporation. All rights reserved. + * + * This code is licensed under a MIT-style license, that can be + * found in the file called "COPYING" in the root directory. + * + */ + +#ifndef _GALLERY2_H_ +#define _GALLERY2_H_ + +#include +#include +#include +#include +#include + +G_BEGIN_DECLS + +SharingPluginInterfaceAccountValidateResult +gallery2_login (ConIcConnection* con, + const gchar* urlbase, const gchar* username, const gchar* password, + GHashTable** cookies, gchar** auth); + +SharingPluginInterfaceAccountValidateResult +gallery2_lookup_album (ConIcConnection* con, + const gchar* urlbase, const gchar* albumpath, gchar** album, + GHashTable* cookies, gchar* auth); + +SharingPluginInterfaceSendResult +gallery2_send (ConIcConnection* con, + SharingTransfer* transfer, gdouble progress_start, gdouble progress_end, gboolean *dms, + SharingEntryMedia* media, + const gchar* urlbase, const gchar* album, GHashTable* cookies, gchar* auth); + +G_END_DECLS + +#endif // _GALLERY2_H_ diff --git a/src/plugin.c b/src/plugin.c index a4fac37..53cc78f 100644 --- a/src/plugin.c +++ b/src/plugin.c @@ -1,23 +1,52 @@ /* - * This file is part of sharing-plugin-template + * This file is part of sharing-plugin-gallery2 * + * Copyright (C) 2009 Heikki Kallasjoki. All rights reserved. * Copyright (C) 2008-2009 Nokia Corporation. All rights reserved. * - * This maemo code example is licensed under a MIT-style license, - * that can be found in the file called "COPYING" in the root - * directory. + * This code is licensed under a MIT-style license, that can be + * found in the file called "COPYING" in the root directory. * */ #include #include +#include +#include #include #include #include #include +#include -#include "send.h" -#include "validate.h" +#include "gallery2.h" + +/* Plugin interface definition: */ + +guint sharing_plugin_interface_init (gboolean* dead_mans_switch); +guint sharing_plugin_interface_uninit (gboolean* dead_mans_switch); +SharingPluginInterfaceSendResult sharing_plugin_interface_send ( + SharingTransfer* transfer, ConIcConnection* con, + gboolean* dead_mans_switch); +SharingPluginInterfaceAccountSetupResult +sharing_plugin_interface_account_setup ( + GtkWindow* parent, + SharingService* service, SharingAccount** worked_on, + osso_context_t* osso); +SharingPluginInterfaceEditAccountResult +sharing_plugin_interface_edit_account ( + GtkWindow* parent, + SharingAccount* account, + ConIcConnection* con, + gboolean* dead_mans_switch); +SharingPluginInterfaceAccountValidateResult +sharing_plugin_interface_account_validate ( + SharingAccount* account, ConIcConnection* con, + gboolean *cont, gboolean* dead_mans_switch); + +/* UI flow helper definition: */ + +static SharingPluginInterfaceEditAccountResult edit_account (SharingAccount* account, GtkWindow* parent, gboolean setup); /** * sharing_plugin_interface_init: @@ -29,7 +58,8 @@ */ guint sharing_plugin_interface_init (gboolean* dead_mans_switch) { - ULOG_DEBUG_L("sharing_manager_plugin_interface_init"); + ULOG_DEBUG_L("sharing_plugin_interface_init, gallery2"); + *dead_mans_switch = FALSE; return 0; } @@ -43,7 +73,8 @@ guint sharing_plugin_interface_init (gboolean* dead_mans_switch) */ guint sharing_plugin_interface_uninit (gboolean* dead_mans_switch) { - ULOG_DEBUG_L("sharing_manager_plugin_interface_uninit"); + ULOG_DEBUG_L("sharing_plugin_interface_uninit, gallery2"); + *dead_mans_switch = FALSE; return 0; } @@ -57,72 +88,385 @@ guint sharing_plugin_interface_uninit (gboolean* dead_mans_switch) * * Returns: Result of send */ -SharingPluginInterfaceSendResult sharing_plugin_interface_send - (SharingTransfer* transfer, ConIcConnection* con, - gboolean* dead_mans_switch) +SharingPluginInterfaceSendResult sharing_plugin_interface_send ( + SharingTransfer* transfer, ConIcConnection* con, + gboolean* dead_mans_switch) { - ULOG_DEBUG_L ("sharing_plugin_interface_send"); - SharingPluginInterfaceSendResult ret_val = SHARING_SEND_ERROR_UNKNOWN; - ret_val = send (transfer, con, dead_mans_switch); - return ret_val; + ULOG_DEBUG_L ("sharing_plugin_interface_send, gallery2"); + + SharingPluginInterfaceSendResult ret = SHARING_SEND_SUCCESS; + + SharingEntry *entry = sharing_transfer_get_entry (transfer); + SharingAccount *account = sharing_entry_get_account (entry); + + gchar* urlbase = sharing_account_get_param (account, "urlbase"); + gchar* albumname = sharing_account_get_param (account, "albumname"); + + GHashTable* cookies = 0; + gchar* auth = 0; + + gchar* album = 0; + + /* Login to the target service */ + + sharing_transfer_set_progress (transfer, 0.0); + *dead_mans_switch = FALSE; + + SharingPluginInterfaceAccountValidateResult login_ret = SHARING_ACCOUNT_VALIDATE_FAILED; + + if (urlbase) + { + gchar* user = sharing_account_get_username (account); + gchar* pass = sharing_account_get_password (account); + if (user && pass) + login_ret = gallery2_login (con, + urlbase, user, pass, + &cookies, &auth); + g_free (user); + g_free (pass); + } + + if (login_ret != SHARING_ACCOUNT_VALIDATE_SUCCESS || !sharing_transfer_continue (transfer)) + { + if (cookies) g_hash_table_unref (cookies); + g_free (auth); + g_free (urlbase); + g_free (albumname); + if (!sharing_transfer_continue (transfer)) + return SHARING_SEND_CANCELLED; + else if (login_ret == SHARING_ACCOUNT_VALIDATE_ERROR_CONNECTION) + return SHARING_SEND_ERROR_CONNECTION; + else + return SHARING_SEND_ERROR_AUTH; + } + + /* Look up the album */ + + sharing_transfer_set_progress (transfer, 0.05); + *dead_mans_switch = FALSE; + + login_ret = gallery2_lookup_album (con, urlbase, albumname, &album, cookies, auth); + g_free (albumname); + albumname = 0; + + if (login_ret != SHARING_ACCOUNT_VALIDATE_SUCCESS || !album || !sharing_transfer_continue (transfer)) + { + if (cookies) g_hash_table_unref (cookies); + g_free (auth); + g_free (urlbase); + g_free (album); /* just in case... */ + if (!sharing_transfer_continue (transfer)) + return SHARING_SEND_CANCELLED; + else if (login_ret == SHARING_ACCOUNT_VALIDATE_ERROR_CONNECTION) + return SHARING_SEND_ERROR_CONNECTION; + else + return SHARING_SEND_ERROR_UNKNOWN; + } + + /* Start sending items */ + + sharing_transfer_set_progress (transfer, 0.1); + *dead_mans_switch = FALSE; + + guint64 total_bytes = 0; + + for (GSList* p = sharing_entry_get_media (entry); p; p = g_slist_next (p)) + { + SharingEntryMedia* media = p->data; + if (!sharing_entry_media_get_sent (media)) + total_bytes += sharing_entry_media_get_size (media); + } + + if (!total_bytes) total_bytes = 1; /* just in case... */ + + guint64 sent_bytes = 0; + + for (GSList* p = sharing_entry_get_media (entry); p; p = g_slist_next (p)) + { + SharingEntryMedia* media = p->data; + if (sharing_entry_media_get_sent (media)) + continue; + + if (!sharing_transfer_continue (transfer)) + { + ret = SHARING_SEND_CANCELLED; + break; + } + + guint64 media_size = sharing_entry_media_get_size (media); + + gdouble progress_start = 1.0 - 0.9*((total_bytes - sent_bytes) / (gdouble)total_bytes); + gdouble progress_end = 1.0 - 0.9*((total_bytes - (sent_bytes + media_size)) / (gdouble)total_bytes); + + sharing_transfer_set_progress (transfer, progress_start); + *dead_mans_switch = FALSE; + + SharingPluginInterfaceSendResult mret = gallery2_send (con, + transfer, progress_start, progress_end, dead_mans_switch, + media, + urlbase, album, cookies, auth); + + if (mret == SHARING_SEND_SUCCESS) + sharing_entry_media_set_sent (media, TRUE); + else + ret = mret; /* propagate last error */ + } + + sharing_transfer_set_progress (transfer, 1.0); + *dead_mans_switch = FALSE; + + if (cookies) g_hash_table_unref (cookies); + g_free (auth); + g_free (urlbase); + g_free (album); + + return ret; } /** * sharing_plugin_interface_account_setup: - * @transfer: #SharingTransfer send - * @service: #SharingService - * @worked_on: Connection used - * @osso_context_t: Osso context + * @parent: Parent window + * @service: Service information + * @worked_on: Who knows? + * @osso: osso_context_t for the dialog. * - * Send interface + * Custom account setup UI flow. * - * Returns: Result of account setup + * Returns: Something? */ -SharingPluginInterfaceAccountSetupResult sharing_plugin_interface_account_setup - (GtkWindow* parent, SharingService* service, SharingAccount** worked_on, - osso_context_t* osso) +SharingPluginInterfaceAccountSetupResult +sharing_plugin_interface_account_setup ( + GtkWindow* parent, + SharingService* service, SharingAccount** worked_on, + osso_context_t* osso) { - ULOG_DEBUG_L ("sharing_plugin_interface_account_setup"); - SharingPluginInterfaceAccountSetupResult ret = 0; - return ret; + if (!worked_on || !*worked_on) + return SHARING_ACCOUNT_SETUP_ERROR_UNKNOWN; + + SharingPluginInterfaceEditAccountResult res = edit_account (*worked_on, parent, TRUE); + if (res == SHARING_EDIT_ACCOUNT_SUCCESS) + return SHARING_ACCOUNT_SETUP_SUCCESS; + else + return SHARING_ACCOUNT_SETUP_ERROR_UNKNOWN; +} + +/** + * sharing_plugin_interface_edit_account: + * @parent: Parent window + * @account: Account to edit + * @con: Connection to use (for what?) + * @dead_mans_switch: Switch to flip (really?!) + */ +SharingPluginInterfaceEditAccountResult +sharing_plugin_interface_edit_account ( + GtkWindow* parent, + SharingAccount* account, + ConIcConnection* con, + gboolean* dead_mans_switch) +{ + if (!account) + return SHARING_EDIT_ACCOUNT_NOT_STARTED; + + return edit_account (account, parent, FALSE); } /** - * sharing_manager_plugin_interface_account_validate: + * sharing_plugin_interface_account_validate: * @account: Account tested * @con: Connection used to test account - * @dead_mans_switch: + * @cont: ... + * @dead_mans_switch: ... * * Validates account information. * * Returns: Result of account validation */ SharingPluginInterfaceAccountValidateResult -sharing_plugin_interface_account_validate (SharingAccount* account, - ConIcConnection* con, gboolean *cont, gboolean* dead_mans_switch) +sharing_plugin_interface_account_validate ( + SharingAccount* account, ConIcConnection* con, + gboolean *cont, gboolean* dead_mans_switch) +{ + ULOG_DEBUG_L ("sharing_plugin_interface_account_validate, gallery2"); + + gchar* user = sharing_account_get_username (account); + gchar* pass = sharing_account_get_password (account); + gchar* urlbase = sharing_account_get_param (account, "urlbase"); + gchar* albumname = sharing_account_get_param (account, "albumname"); + + SharingPluginInterfaceAccountValidateResult ret = SHARING_ACCOUNT_VALIDATE_FAILED; + + if (user && pass && urlbase && albumname) + { + GHashTable* cookies = 0; + gchar* auth = 0; + + /* URL sanity checks and fixups */ + + gboolean update_url = FALSE; + + if (!(g_str_has_prefix (urlbase, "http://") + || g_str_has_prefix (urlbase, "https://"))) + { + gchar* prev = urlbase; + urlbase = g_strdup_printf ("http://%s", prev); + update_url = TRUE; + g_free (prev); + } + + if (g_str_has_suffix (urlbase, "/main.php")) + { + gchar* prev = urlbase; + urlbase = g_strndup (prev, strlen (prev) - 9); + update_url = TRUE; + g_free (prev); + } + else if (g_str_has_suffix (urlbase, "/")) + { + gchar* prev = urlbase; + urlbase = g_strndup (prev, strlen (prev) - 1); + update_url = TRUE; + g_free (prev); + } + + if (update_url) + sharing_account_set_param (account, "urlbase", urlbase); + + /* Validate by trying to login */ + + ret = gallery2_login (con, + urlbase, user, pass, + &cookies, &auth); + *dead_mans_switch = FALSE; + + /* Also validate the album name here, if login ok */ + + if (ret == SHARING_ACCOUNT_VALIDATE_SUCCESS) + { + gchar* album = 0; + ret = gallery2_lookup_album (con, urlbase, albumname, &album, cookies, auth); + *dead_mans_switch = FALSE; + g_free (album); + } + + if (cookies) g_hash_table_unref (cookies); + if (auth) g_free (auth); + } + + g_free (user); + g_free (pass); + g_free (urlbase); + g_free (albumname); + + return ret; +} + +/* UI flow helper implementations. */ + +static void gui_add_item (GtkWidget* table, guint row, + gchar* id, const gchar* label, const gchar* placeholder, + gboolean invis, SharingAccount* a, GHashTable* h); +static gboolean gui_read_item (GHashTable* h, const gchar* id, SharingAccount* a); +static gboolean gui_read (GHashTable* h, SharingAccount* a); + +static void gui_add_item (GtkWidget* table, guint row, + gchar* id, const gchar* label, const gchar* placeholder, + gboolean invis, SharingAccount* a, GHashTable* h) { - ULOG_DEBUG_L ("sharing_plugin_interface_account_validate"); - SharingPluginInterfaceAccountValidateResult ret_val = 0; - ret_val = validate (account, con, cont, dead_mans_switch); - return ret_val; + GtkWidget* wlabel = gtk_label_new (label); + gtk_table_attach (GTK_TABLE (table), wlabel, 0, 1, row, row+1, GTK_FILL, GTK_FILL|GTK_EXPAND, HILDON_MARGIN_DOUBLE, 0); + + GtkWidget* wentry = hildon_entry_new (HILDON_SIZE_AUTO); + hildon_entry_set_placeholder (HILDON_ENTRY (wentry), placeholder); + if (invis) + hildon_gtk_entry_set_input_mode (GTK_ENTRY (wentry), HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_INVISIBLE); + gtk_table_attach_defaults (GTK_TABLE (table), wentry, 1, 2, row, row+1); + + g_hash_table_insert (h, id, wentry); + + gchar* old = sharing_account_get_param (a, id); + if (old) + { + gtk_entry_set_text (GTK_ENTRY (wentry), old); + g_free (old); + } } -/** - * sharing_plugin_interface_edit_account: - * @account: Account tested - * @con: Connection used to test account - * @dead_mans_switch: - * - * Edit account plugin implementation. - * - * Returns: Result of account edit - */ -SharingPluginInterfaceEditAccountResult - sharing_plugin_interface_edit_account (GtkWindow* parent, - SharingAccount* account, ConIcConnection* con, gboolean* dead_mans_switch) +static gboolean gui_read_item (GHashTable* h, const gchar* id, SharingAccount* a) +{ + GtkWidget* wentry = g_hash_table_lookup (h, id); + if (!wentry) return FALSE; + + gchar* old = sharing_account_get_param (a, id); + const gchar* new = gtk_entry_get_text (GTK_ENTRY (wentry)); + + gboolean changed = FALSE; + + if (!old || strcmp (old, new) != 0) + { + sharing_account_set_param (a, id, new); + changed = TRUE; + } + + g_free (old); + return changed; +} + +static gboolean gui_read (GHashTable* h, SharingAccount* a) { - SharingPluginInterfaceEditAccountResult ret = 0; - ULOG_DEBUG_L ("sharing_plugin_interface_edit_account"); - return ret; + gboolean changed = FALSE; + if (gui_read_item (h, "username", a)) changed = TRUE; + if (gui_read_item (h, "password", a)) changed = TRUE; + if (gui_read_item (h, "urlbase", a)) changed = TRUE; + if (gui_read_item (h, "albumname", a)) changed = TRUE; + return changed; } +static SharingPluginInterfaceEditAccountResult edit_account (SharingAccount* account, GtkWindow* parent, gboolean setup) +{ + GHashTable* h = g_hash_table_new (g_str_hash, g_str_equal); + + GtkWidget* dlg = 0; + + if (setup) + dlg = gtk_dialog_new_with_buttons ( + "Account setup - Gallery 2", parent, + GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_STOCK_OK, GTK_RESPONSE_YES, + NULL); + else + dlg = gtk_dialog_new_with_buttons ( + "Edit account - Gallery 2", parent, + GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_STOCK_SAVE, GTK_RESPONSE_YES, + GTK_STOCK_DELETE, GTK_RESPONSE_NO, + NULL); + + GtkWidget* dlg_content = gtk_dialog_get_content_area (GTK_DIALOG (dlg)); + + GtkWidget* table = gtk_table_new (4, 2, FALSE); + gtk_container_add (GTK_CONTAINER (dlg_content), table); + + gui_add_item (table, 0, "username", "User name", "Gallery 2 account name", FALSE, account, h); + gui_add_item (table, 1, "password", "Password", "Gallery 2 account password", TRUE, account, h); + gui_add_item (table, 2, "urlbase", "URL", "Gallery 2 site address", FALSE, account, h); + gui_add_item (table, 3, "albumname", "Album", "Album name to upload to", FALSE, account, h); + + gtk_widget_show_all (GTK_WIDGET (dlg)); + gint result = gtk_dialog_run (GTK_DIALOG (dlg)); + + gboolean changed = FALSE; + if (result == GTK_RESPONSE_YES) + changed = gui_read (h, account); + + gtk_widget_destroy (dlg); + g_hash_table_unref (h); + + if (result == GTK_RESPONSE_YES && (changed || setup)) + return SHARING_EDIT_ACCOUNT_SUCCESS; + else if (result == GTK_RESPONSE_YES) /* !changed in edit */ + return SHARING_EDIT_ACCOUNT_NOT_STARTED; + else if (result == GTK_RESPONSE_NO) + return SHARING_EDIT_ACCOUNT_DELETE; + else + return SHARING_EDIT_ACCOUNT_CANCELLED; +} diff --git a/src/send.c b/src/send.c deleted file mode 100644 index addfc3b..0000000 --- a/src/send.c +++ /dev/null @@ -1,59 +0,0 @@ -/* - * This file is part of sharing-plugin-template - * - * Copyright (C) 2008-2009 Nokia Corporation. All rights reserved. - * - * This maemo code example is licensed under a MIT-style license, - * that can be found in the file called "COPYING" in the root - * directory. - * - */ - -#include -#include -#include -#include -#include "send.h" -#include "common.h" - -/** - * send: - * @account: #SharingTransfer to be send - * @con: Connection used - * @dead_mans_switch: Turn to %FALSE at least every 30 seconds. - * - * Sends #SharingTransfer to service. - * - * Returns: #SharingPluginInterfaceSendResult - */ -SharingPluginInterfaceSendResult send (SharingTransfer* transfer, - ConIcConnection* con, gboolean* dead_mans_switch) -{ - SharingPluginInterfaceSendResult ret = SHARING_SEND_SUCCESS; - - SharingEntry *entry = sharing_transfer_get_entry( transfer ); - - gint result = 0; - - for (GSList* p = sharing_entry_get_media (entry); p != NULL; p = g_slist_next(p)) { - SharingEntryMedia* media = p->data; - /* Process media */ - if (!sharing_entry_media_get_sent (media)) { - /* Post media */ - //result = my_send_task_post_function (my_send_task, media); - /* Process post result */ - if (result == 0 /* EXAMPLE: MY_SEND_RESULT_SUCCESS */) { - /* If success mark media as sent */ - sharing_entry_media_set_sent (media, TRUE); - /* And mark process to your internal data structure */ - //my_send_task->upload_done += sharing_entry_media_get_size (media); - } else { - /* We have sent the file in last sharing-manager call */ - //my_send_task->upload_done += sharing_entry_media_get_size (media); - } - } - } - - return ret; -} - diff --git a/src/send.h b/src/send.h deleted file mode 100644 index e316919..0000000 --- a/src/send.h +++ /dev/null @@ -1,29 +0,0 @@ -/* - * This file is part of sharing-plugin-template - * - * Copyright (C) 2008-2009 Nokia Corporation. All rights reserved. - * - * This maemo code example is licensed under a MIT-style license, - * that can be found in the file called "COPYING" in the root - * directory. - * - */ - -#ifndef _SEND_H_ -#define _SEND_H_ - -#include -#include -#include -#include -#include - -G_BEGIN_DECLS - -SharingPluginInterfaceSendResult send (SharingTransfer* transfer, - ConIcConnection* con, gboolean* dead_mans_switch); - -G_END_DECLS - -#endif // _SEND_H_ - diff --git a/src/validate.c b/src/validate.c deleted file mode 100644 index 83ceb2c..0000000 --- a/src/validate.c +++ /dev/null @@ -1,55 +0,0 @@ -/* - * This file is part of sharing-plugin-template - * - * Copyright (C) 2008-2009 Nokia Corporation. All rights reserved. - * - * This maemo code example is licensed under a MIT-style license, - * that can be found in the file called "COPYING" in the root - * directory. - * - */ - -#include -#include -#include -#include -#include -#include -#include "validate.h" -#include "common.h" - -/** - * test: - * @account: #SharingAccount to be tested - * @con: Connection used - * @dead_mans_switch: Turn to %FALSE at least every 30 seconds. - * - * Test if #SharingAccount is valid. - * - * Returns: #SharingPluginInterfaceTestAccountResult - */ -SharingPluginInterfaceAccountValidateResult validate (SharingAccount* account, - ConIcConnection* con, gboolean *cont, gboolean* dead_mans_switch) -{ - SharingPluginInterfaceAccountValidateResult ret = - SHARING_ACCOUNT_VALIDATE_SUCCESS; - - SharingHTTP * http = sharing_http_new (); - - /* Correct fields must be added to http request before sending */ - - SharingHTTPRunResponse res; - res = sharing_http_run (http, "http://example.com/post"); - if (res == SHARING_HTTP_RUNRES_SUCCESS) { - ULOG_DEBUG_L ("Got response (%d): %s\n", sharing_http_get_res_code (http), - sharing_http_get_res_body (http, NULL)); - } else { - ULOG_ERR_L ("Couldn't get stuff from service\n"); - ret = SHARING_ACCOUNT_VALIDATE_FAILED; - } - sharing_http_unref (http); - - - return ret; -} - diff --git a/src/validate.h b/src/validate.h deleted file mode 100644 index db74b13..0000000 --- a/src/validate.h +++ /dev/null @@ -1,28 +0,0 @@ -/* - * This file is part of sharing-plugin-template - * - * Copyright (C) 2008-2009 Nokia Corporation. All rights reserved. - * - * This maemo code example is licensed under a MIT-style license, - * that can be found in the file called "COPYING" in the root - * directory. - * - */ - -#ifndef _VALIDATE_H_ -#define _VALIDATE_H_ - -#include -#include -#include -#include - -G_BEGIN_DECLS - -SharingPluginInterfaceAccountValidateResult validate (SharingAccount* account, - ConIcConnection* con, gboolean *cont, gboolean* dead_mans_switch); - -G_END_DECLS - -#endif // _VALIDATE_H_ - -- 1.7.9.5