Author: akv Date: 2009-12-25 01:34:55 +0100 (Fri, 25 Dec 2009) New Revision: 2841
Added: trunk/plugins/output-facebook/Makefile.am trunk/plugins/output-facebook/output-facebook.c trunk/plugins/output-facebook/output-facebook.h Log: Added initial facebook plugin. Added: trunk/plugins/output-facebook/Makefile.am =================================================================== --- trunk/plugins/output-facebook/Makefile.am (rev 0) +++ trunk/plugins/output-facebook/Makefile.am 2009-12-25 00:34:55 UTC (rev 2841) @@ -0,0 +1,21 @@ +plugindir = $(libdir)/rawstudio/plugins + +AM_CFLAGS =\ + -Wall\ + -O4 + +AM_CXXFLAGS = $(AM_CFLAGS) + +INCLUDES = \ + -DPACKAGE_DATA_DIR=\""$(datadir)"\" \ + -DPACKAGE_LOCALE_DIR=\""$(prefix)/$(DATADIRNAME)/locale"\" \ + @PACKAGE_CFLAGS@ \ + -I../../librawstudio/ + +lib_LTLIBRARIES = output_facebook.la + +libdir = $(datadir)/rawstudio/plugins/ + +output_facebook_la_LIBADD = @PACKAGE_LIBS@ +output_facebook_la_LDFLAGS = -module -avoid-version -L/usr/lib -lflickcurl +output_facebook_la_SOURCES = output-facebook.c facebook.c Added: trunk/plugins/output-facebook/output-facebook.c =================================================================== --- trunk/plugins/output-facebook/output-facebook.c (rev 0) +++ trunk/plugins/output-facebook/output-facebook.c 2009-12-25 00:34:55 UTC (rev 2841) @@ -0,0 +1,246 @@ +/* + * Copyright (C) 2006-2009 Anders Brander <[email protected]> and + * Anders Kvist <[email protected]> + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +/* Output plugin tmpl version 1 */ + +/* + TODO: + - move rs_conf_* to librawstudio - this needs RS_FILETYPE from application.h. Should/can we move this to rs-filetypes.h? + - decide if rawstudio can be dependent on libflickcurl. Will this plugin be build on dependency satisfiction or --with-output-flickr option. +*/ + +#include <rawstudio.h> +#include <gettext.h> +#include "config.h" +#include "output-facebook.h" +#include <unistd.h> +#include <string.h> +#include "facebook.h" + +/* Ugly HACK - conf_interface.c|h needs to be ported to librawstudio */ +gchar *rs_conf_get_string (const gchar * name); +gboolean rs_conf_set_string (const gchar * name, const gchar * value); + +#define RS_TYPE_FACEBOOK (rs_facebook_type) +#define RS_FACEBOOK(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), RS_TYPE_FACEBOOK, RSFacebook)) +#define RS_FACEBOOK_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), RS_TYPE_FACEBOOK, RSFacebookClass)) +#define RS_IS_FACEBOOK(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), RS_TYPE_FACEBOOK)) + +typedef struct _RSFacebook RSFacebook; +typedef struct _RSFacebookClass RSFacebookClass; + +struct _RSFacebook +{ + RSOutput parent; + + gint quality; + gchar *filename; /* Required for a output plugin - not in use */ + gchar *caption; +}; + +struct _RSFacebookClass +{ + RSOutputClass parent_class; +}; + +RS_DEFINE_OUTPUT (rs_facebook, RSFacebook) +enum +{ + PROP_0, + PROP_JPEG_QUALITY, + PROP_FILENAME, /* Required for a output plugin - not in use */ + PROP_CAPTION +}; + +static void get_property (GObject * object, guint property_id, GValue * value, GParamSpec * pspec); +static void set_property (GObject * object, guint property_id, const GValue * value, GParamSpec * pspec); +static gboolean execute (RSOutput * output, RSFilter * filter); + +G_MODULE_EXPORT void rs_plugin_load (RSPlugin * plugin) +{ + rs_facebook_get_type (G_TYPE_MODULE (plugin)); +} + +static void +rs_facebook_class_init (RSFacebookClass * klass) +{ + RSOutputClass *output_class = RS_OUTPUT_CLASS (klass); + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + object_class->get_property = get_property; + object_class->set_property = set_property; + + g_object_class_install_property (object_class, + PROP_JPEG_QUALITY, + g_param_spec_int ("quality", + "JPEG Quality", + _("JPEG Quality"), 10, + 100, 90, + G_PARAM_READWRITE)); + + g_object_class_install_property (object_class, + PROP_CAPTION, g_param_spec_string ("caption", + "caption", + _("Caption"), + NULL, + G_PARAM_READWRITE)); + + g_object_class_install_property (object_class, /* Required for a output plugin - not in use */ + PROP_FILENAME, g_param_spec_string ("filename", + "filename", + "Filename", + NULL, + G_PARAM_READWRITE)); + + output_class->execute = execute; + output_class->display_name = _("Upload photo to Facebook"); +} + +static void +rs_facebook_init (RSFacebook * facebook) +{ + facebook->quality = 90; +} + +static void +get_property (GObject * object, guint property_id, GValue * value, GParamSpec * pspec) +{ + RSFacebook *facebook = RS_FACEBOOK (object); + + switch (property_id) + { + case PROP_JPEG_QUALITY: + g_value_set_int (value, facebook->quality); + break; + case PROP_FILENAME: /* Required for a output plugin - not in use */ + g_value_set_string (value, facebook->filename); + break; + case PROP_CAPTION: + g_value_set_string (value, facebook->caption); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + } +} + +static void +set_property (GObject * object, guint property_id, const GValue * value, GParamSpec * pspec) +{ + RSFacebook *facebook = RS_FACEBOOK (object); + + switch (property_id) + { + case PROP_JPEG_QUALITY: + facebook->quality = g_value_get_int (value); + break; + case PROP_FILENAME: /* Required for a output plugin - not in use */ + facebook->filename = g_value_dup_string (value); + break; + case PROP_CAPTION: + facebook->caption = g_value_dup_string (value); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + } +} + +GtkWidget * +gui_dialog_make_from_widget (const gchar * stock_id, gchar * primary_text, GtkWidget * widget) +{ + GtkWidget *dialog, *image, *hhbox, *vvbox; + GtkWidget *primary_label; + gchar *str; + + image = gtk_image_new_from_stock (stock_id, GTK_ICON_SIZE_DIALOG); + gtk_misc_set_alignment (GTK_MISC (image), 0.5, 0.0); + dialog = gtk_dialog_new (); + gtk_container_set_border_width (GTK_CONTAINER (dialog), 5); + gtk_box_set_spacing (GTK_BOX (GTK_DIALOG (dialog)->vbox), 14); + gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE); + gtk_dialog_set_has_separator (GTK_DIALOG (dialog), FALSE); + gtk_window_set_title (GTK_WINDOW (dialog), ""); + gtk_window_set_modal (GTK_WINDOW (dialog), TRUE); + gtk_window_set_destroy_with_parent (GTK_WINDOW (dialog), TRUE); + + primary_label = gtk_label_new (NULL); + gtk_label_set_line_wrap (GTK_LABEL (primary_label), TRUE); + gtk_label_set_use_markup (GTK_LABEL (primary_label), TRUE); + gtk_misc_set_alignment (GTK_MISC (primary_label), 0.0, 0.5); + gtk_label_set_selectable (GTK_LABEL (primary_label), TRUE); + str = g_strconcat ("<span weight=\"bold\" size=\"larger\">", primary_text, "</span>", NULL); + gtk_label_set_markup (GTK_LABEL (primary_label), str); + g_free (str); + + hhbox = gtk_hbox_new (FALSE, 12); + gtk_container_set_border_width (GTK_CONTAINER (hhbox), 5); + gtk_box_pack_start (GTK_BOX (hhbox), image, FALSE, FALSE, 0); + vvbox = gtk_vbox_new (FALSE, 12); + gtk_box_pack_start (GTK_BOX (hhbox), vvbox, FALSE, FALSE, 0); + gtk_box_pack_start (GTK_BOX (vvbox), primary_label, FALSE, FALSE, 0); + gtk_box_pack_start (GTK_BOX (vvbox), widget, FALSE, FALSE, 0); + gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), hhbox, FALSE, FALSE, 0); + + return (dialog); +} + +GtkWidget * +gui_dialog_make_from_text (const gchar * stock_id, gchar * primary_text, gchar * secondary_text) +{ + GtkWidget *secondary_label; + + secondary_label = gtk_label_new (NULL); + gtk_label_set_line_wrap (GTK_LABEL (secondary_label), TRUE); + gtk_label_set_use_markup (GTK_LABEL (secondary_label), TRUE); + gtk_misc_set_alignment (GTK_MISC (secondary_label), 0.0, 0.5); + gtk_label_set_selectable (GTK_LABEL (secondary_label), TRUE); + gtk_label_set_markup (GTK_LABEL (secondary_label), secondary_text); + + return (gui_dialog_make_from_widget(stock_id, primary_text, secondary_label)); +} + +static gboolean +execute (RSOutput * output, RSFilter * filter) +{ + RSFacebook *facebook = RS_FACEBOOK (output); + + if(facebook_init(FACEBOOK_API_KEY, FACEBOOK_SECRET_KEY, FACEBOOK_SERVER)) + if(facebook_get_token()) + { + gchar *url = facebook_get_auth_url(FACEBOOK_LOGIN); + g_debug("URL: %s\n", url); + sleep(5); + if (facebook_get_session()) + { + /* FIXME: save session to conf */ + RSOutput *jpegsave = rs_output_new ("RSJpegfile"); + gchar *temp_file = g_strdup_printf ("%s%s.rawstudio-tmp-%d.jpg", g_get_tmp_dir (), G_DIR_SEPARATOR_S, (gint) (g_random_double () * 10000.0)); + + g_object_set (jpegsave, "filename", temp_file, "quality", facebook->quality, NULL); + rs_output_execute (jpegsave, filter); + g_object_unref (jpegsave); + + facebook_upload_photo(temp_file ,"nothing yet"); + + unlink (temp_file); + g_free (temp_file); + facebook_close(); + } + } + return TRUE; +} Added: trunk/plugins/output-facebook/output-facebook.h =================================================================== --- trunk/plugins/output-facebook/output-facebook.h (rev 0) +++ trunk/plugins/output-facebook/output-facebook.h 2009-12-25 00:34:55 UTC (rev 2841) @@ -0,0 +1,23 @@ +/* + * Copyright (C) 2006-2009 Anders Brander <[email protected]> and + * Anders Kvist <[email protected]> + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#define FACEBOOK_API_KEY "4c86b468bbe77840771dda74c7fb1272" +#define FACEBOOK_SECRET_KEY "4945724ce9ef58ce5ed2360e020ec07d" +#define FACEBOOK_SERVER "api.facebook.com/restserver.php" +#define FACEBOOK_LOGIN "http://api.facebook.com/login.php" _______________________________________________ Rawstudio-commit mailing list [email protected] http://rawstudio.org/cgi-bin/mailman/listinfo/rawstudio-commit
