Import the initial Gallery 2 code
authorHeikki Kallasjoki <fis@zem.fi>
Tue, 10 Nov 2009 15:48:41 +0000 (17:48 +0200)
committerHeikki Kallasjoki <fis@zem.fi>
Tue, 10 Nov 2009 15:48:41 +0000 (17:48 +0200)
25 files changed:
Makefile.am
configure.ac
data/Makefile.am
data/gallery2-icon.png [new file with mode: 0644]
data/gallery2.service.xml.in [new file with mode: 0644]
data/template-post.png [deleted file]
data/template-setup.png [deleted file]
data/template.service.xml.in [deleted file]
debian/changelog
debian/control
debian/copyright
debian/sharing-plugin-gallery2.install [new file with mode: 0644]
debian/sharing-plugin-template.install [deleted file]
debian/sharing-service-gallery2.prerm [new file with mode: 0644]
debian/sharing-service-template.prerm [deleted file]
src/Makefile.am
src/common.c [deleted file]
src/common.h [deleted file]
src/gallery2.c [new file with mode: 0644]
src/gallery2.h [new file with mode: 0644]
src/plugin.c
src/send.c [deleted file]
src/send.h [deleted file]
src/validate.c [deleted file]
src/validate.h [deleted file]

index 55f2fa8..f7f66f9 100644 (file)
@@ -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
index 3bf0ed2..ac90448 100644 (file)
@@ -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
 ])
 
index 0ba93ba..342ae97 100644 (file)
@@ -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 (file)
index 0000000..94b7659
Binary files /dev/null and b/data/gallery2-icon.png differ
diff --git a/data/gallery2.service.xml.in b/data/gallery2.service.xml.in
new file mode 100644 (file)
index 0000000..34ee347
--- /dev/null
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="UTF-8"?> 
+<service plugin="libsharingplugingallery2.so" provider="Heikki Kallasjoki"> 
+
+       <accounts plugInSetup="1" plugInEdit="1">
+               <signup>http://gallery.menalto.com/</signup>
+               <password maxlen="32"/>
+       </accounts> 
+
+       <ui>
+               <name>Gallery 2</name>
+               <icon type="post">@servicesdir@/gallery2-icon.png</icon>
+               <icon type="setup">@servicesdir@/gallery2-icon.png</icon>
+               <options>
+                       <option id="privacy" type="enumeration" default="private">
+                               <caption domain="osso-sharing-ui" key="share_bd_options_privacy" />
+                               <value id="private" domain="osso-sharing-ui" key="share_fi_options_privacy_private" />
+                               <value id="public" domain="osso-sharing-ui" key="share_fi_options_privacy_public" />
+                       </option>
+               </options>
+       </ui> 
+</service>
diff --git a/data/template-post.png b/data/template-post.png
deleted file mode 100644 (file)
index cb76233..0000000
Binary files a/data/template-post.png and /dev/null differ
diff --git a/data/template-setup.png b/data/template-setup.png
deleted file mode 100644 (file)
index 408a18a..0000000
Binary files a/data/template-setup.png and /dev/null differ
diff --git a/data/template.service.xml.in b/data/template.service.xml.in
deleted file mode 100644 (file)
index faad554..0000000
+++ /dev/null
@@ -1,22 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?> 
-<service plugin="libsharingplugintemplate.so" provider="Me"> 
-    
-    <accounts plugInSetup="0" plugInEdit="0">
-      <signup>http://www.maemo.org</signup> 
-      <password maxlen="32"/> 
-    </accounts> 
-    
-    <ui>
-        <name>Template</name>
-        <icon type="post">@servicesdir@/template-post.png</icon>
-        <icon type="setup">@servicesdir@/template-setup.png</icon>
-        <options>
-            <option id="privacy" type="enumeration" default="private">
-                <caption domain="osso-sharing-ui" key="share_bd_options_privacy"/>
-                <value id="private" domain="osso-sharing-ui" key="share_fi_options_privacy_private"/>
-                <value id="public" domain="osso-sharing-ui" key="share_fi_options_privacy_public"/>
-            </option>
-        </options>
-    </ui> 
-</service>
-
index 28411f9..8825958 100644 (file)
@@ -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 <xxxx@maemo.org>  Wed, 18 Mar 2009 16:49:55 +0200
-
-sharing-plugin-template (0.1) unstable; urgency=low
-
-  * Update
-
- -- Maemo Team <xxxx@maemo.org>  Wed, 18 Mar 2009 16:49:55 +0200
+ -- Heikki Kallasjoki <fis@zem.fi>  Sun, 08 Nov 2009 00:53:51 +0200
 
index f2e80b1..355de1d 100644 (file)
@@ -1,15 +1,15 @@
-Source: sharing-plugin-template
+Source: sharing-plugin-gallery2
 Section: user/other
 Priority: optional
-Maintainer: Maemo Team <xxxx@maemo.org>
+Maintainer: Heikki Kallasjoki <fis@zem.fi>
 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
index fc44a81..8ad171d 100644 (file)
@@ -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 (file)
index 0000000..baac9bf
--- /dev/null
@@ -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 (file)
index baac9bf..0000000
+++ /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 (file)
index 0000000..a6a4528
--- /dev/null
@@ -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 (file)
index cffbdbd..0000000
+++ /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
index f79d74c..d9d5558 100644 (file)
@@ -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 (file)
index 2f47076..0000000
+++ /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 <stdio.h>
-#include <glib.h>
-#include <osso-log.h>
-#include <sharing-http.h>
-#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 (file)
index 3e9b700..0000000
+++ /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 <glib.h>
-#include <sharing-account.h>
-
-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 (file)
index 0000000..09caf67
--- /dev/null
@@ -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 <stdio.h>
+#include <string.h>
+#include <glib.h>
+#include <osso-log.h>
+#include <sharing-http.h>
+#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 (file)
index 0000000..195f203
--- /dev/null
@@ -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 <glib.h>
+#include <sharing-plugin-interface.h>
+#include <sharing-account.h>
+#include <sharing-transfer.h>
+#include <conicconnection.h>
+
+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_
index a4fac37..53cc78f 100644 (file)
@@ -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 <gtk/gtk.h>
 #include <glib.h>
+#include <string.h>
+#include <stdio.h>
 #include <sharing-plugin-interface.h>
 #include <sharing-transfer.h>
 #include <conicconnection.h>
 #include <osso-log.h>
+#include <hildon/hildon.h>
 
-#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 (file)
index addfc3b..0000000
+++ /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 <stdio.h>
-#include <glib.h>
-#include <osso-log.h>
-#include <sharing-http.h>
-#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 (file)
index e316919..0000000
+++ /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 <glib.h>
-#include <sharing-transfer.h>
-#include <sharing-entry.h>
-#include <conicconnection.h>
-#include <sharing-plugin-interface.h>
-
-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 (file)
index 83ceb2c..0000000
+++ /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 <stdio.h>
-#include <glib.h>
-#include <sharing-account.h>
-#include <sharing-http.h>
-#include <osso-log.h>
-#include <conicconnection.h>
-#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 (file)
index db74b13..0000000
+++ /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 <glib.h>
-#include <sharing-entry.h>
-#include <sharing-plugin-interface.h>
-#include <conicconnection.h>
-
-G_BEGIN_DECLS
-
-SharingPluginInterfaceAccountValidateResult validate (SharingAccount* account,
-    ConIcConnection* con, gboolean *cont, gboolean* dead_mans_switch);
-
-G_END_DECLS
-
-#endif // _VALIDATE_H_
-