aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMauro Carvalho Chehab <mchehab+samsung@kernel.org>2018-08-21 19:37:04 (GMT)
committerMauro Carvalho Chehab <mchehab+samsung@kernel.org>2018-08-28 11:20:36 (GMT)
commit08a0c60f1bff93a905fa4ca2b6fc0a2c7d2f68c1 (patch)
tree86c0fa5998c578f1f5f780a7c2a72d12a311fd0a
parent182906534797a0a75daa417258cb99678c79cc4a (diff)
fileio: use gio instead of gnomeVFS and support sftp and smb
The gnomeVFS is now obsolete. Replace it by gio. As a bonus, it now supports also sftp and smb protocols. While here, remove dead code inside fileio.c. Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
-rw-r--r--data/camorama.glade72
-rw-r--r--src/callbacks.c97
-rw-r--r--src/camorama-globals.h3
-rw-r--r--src/camorama-window.c39
-rw-r--r--src/fileio.c238
-rw-r--r--src/fileio.h4
-rw-r--r--src/interface.h4
-rw-r--r--src/main.c21
-rw-r--r--src/v4l.c6
-rw-r--r--src/v4l.h8
10 files changed, 254 insertions, 238 deletions
diff --git a/data/camorama.glade b/data/camorama.glade
index 06d6e15..9f99b38 100644
--- a/data/camorama.glade
+++ b/data/camorama.glade
@@ -684,7 +684,7 @@
<object class="GtkTable" id="table5">
<property name="visible">True</property>
<property name="can_focus">False</property>
- <property name="n_rows">5</property>
+ <property name="n_rows">4</property>
<property name="n_columns">2</property>
<property name="column_spacing">6</property>
<property name="row_spacing">6</property>
@@ -693,7 +693,7 @@
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xalign">0</property>
- <property name="label" translatable="yes">FTP server: </property>
+ <property name="label" translatable="yes">Server:</property>
</object>
<packing>
<property name="x_options">GTK_FILL</property>
@@ -701,39 +701,35 @@
</packing>
</child>
<child>
- <object class="GtkLabel" id="label45">
+ <object class="GtkLabel" id="proto_type">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xalign">0</property>
- <property name="label" translatable="yes">Username:</property>
+ <property name="label" translatable="yes">Type:</property>
</object>
<packing>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
- <property name="x_options">GTK_FILL</property>
- <property name="y_options"/>
</packing>
</child>
<child>
- <object class="GtkLabel" id="label46">
+ <object class="GtkLabel" id="rem_directory">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xalign">0</property>
- <property name="label" translatable="yes">Password:</property>
+ <property name="label" translatable="yes">Save directory:</property>
</object>
<packing>
<property name="top_attach">2</property>
<property name="bottom_attach">3</property>
- <property name="x_options">GTK_FILL</property>
- <property name="y_options"/>
</packing>
</child>
<child>
- <object class="GtkLabel" id="label47">
+ <object class="GtkLabel" id="label48">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xalign">0</property>
- <property name="label" translatable="yes">Save directory:</property>
+ <property name="label" translatable="yes">Filename:</property>
</object>
<packing>
<property name="top_attach">3</property>
@@ -743,20 +739,6 @@
</packing>
</child>
<child>
- <object class="GtkLabel" id="label48">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="xalign">0</property>
- <property name="label" translatable="yes">Filename</property>
- </object>
- <packing>
- <property name="top_attach">4</property>
- <property name="bottom_attach">5</property>
- <property name="x_options">GTK_FILL</property>
- <property name="y_options"/>
- </packing>
- </child>
- <child>
<object class="GtkEntry" id="host_entry">
<property name="visible">True</property>
<property name="can_focus">True</property>
@@ -773,29 +755,22 @@
</packing>
</child>
<child>
- <object class="GtkEntry" id="login_entry">
+ <object class="GtkComboBoxText" id="remote_protocol">
<property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="text" translatable="yes">your-username</property>
- <property name="primary_icon_activatable">False</property>
- <property name="secondary_icon_activatable">False</property>
- <property name="primary_icon_sensitive">True</property>
- <property name="secondary_icon_sensitive">True</property>
+ <property name="can_focus">False</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
- <property name="y_options"/>
</packing>
</child>
<child>
- <object class="GtkEntry" id="pw_entry">
+ <object class="GtkEntry" id="rdir_entry">
<property name="visible">True</property>
<property name="can_focus">True</property>
- <property name="visibility">False</property>
- <property name="text" translatable="yes">your-password</property>
+ <property name="invisible_char">‚óŹ</property>
<property name="primary_icon_activatable">False</property>
<property name="secondary_icon_activatable">False</property>
<property name="primary_icon_sensitive">True</property>
@@ -806,25 +781,6 @@
<property name="right_attach">2</property>
<property name="top_attach">2</property>
<property name="bottom_attach">3</property>
- <property name="y_options"/>
- </packing>
- </child>
- <child>
- <object class="GtkEntry" id="directory_entry">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="text" translatable="yes">path/to/save/to</property>
- <property name="primary_icon_activatable">False</property>
- <property name="secondary_icon_activatable">False</property>
- <property name="primary_icon_sensitive">True</property>
- <property name="secondary_icon_sensitive">True</property>
- </object>
- <packing>
- <property name="left_attach">1</property>
- <property name="right_attach">2</property>
- <property name="top_attach">3</property>
- <property name="bottom_attach">4</property>
- <property name="y_options"/>
</packing>
</child>
<child>
@@ -840,8 +796,8 @@
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
- <property name="top_attach">4</property>
- <property name="bottom_attach">5</property>
+ <property name="top_attach">3</property>
+ <property name="bottom_attach">4</property>
<property name="y_options"/>
</packing>
</child>
diff --git a/src/callbacks.c b/src/callbacks.c
index b2f117b..cf809cb 100644
--- a/src/callbacks.c
+++ b/src/callbacks.c
@@ -15,8 +15,8 @@ extern int frames;
extern int frames2;
extern int seconds;
extern GtkWidget *dentry, *entry2, *string_entry;
-extern GtkWidget *host_entry,
- *directory_entry, *filename_entry, *login_entry, *pw_entry;
+extern GtkWidget *host_entry, *protocol, *rdir_entry, *filename_entry;
+extern const gchar * const protos[];
/*
* pref callbacks
@@ -281,26 +281,92 @@ int delete_event (GtkWidget * widget, gpointer data)
return FALSE;
}
+static int apply_remote_pref(cam *cam)
+{
+ if (!strlen (gtk_entry_get_text ((GtkEntry *) host_entry)))
+ return 0;
+
+ int index = gtk_combo_box_get_active(GTK_COMBO_BOX(protocol));
+
+ gchar *host = g_strdup (gtk_entry_get_text ((GtkEntry *) host_entry));
+ gchar *rdir = g_strdup (gtk_entry_get_text ((GtkEntry *) rdir_entry));
+ gchar *proto = g_strdup (protos[index]);
+ gchar *rfile = g_strdup (gtk_entry_get_text ((GtkEntry *) filename_entry));
+
+ if (!host || !proto || !rdir || !rfile) {
+ if (host)
+ g_free(host);
+ if (proto)
+ g_free(proto);
+ if (rdir)
+ g_free(rdir);
+ if (rfile)
+ g_free(rfile);
+ return 0;
+ }
+
+ gchar *uri = volume_uri(host, proto, rdir);
+
+ if (cam->rdir_ok) {
+ /* unmount/mount can spend time. Do only if URI changed */
+ if (strcmp(uri, cam->uri)) {
+ umount_volume(cam);
+ } else {
+ g_free(host);
+ g_free(proto);
+ g_free(rdir);
+ g_free(rfile);
+ g_free(uri);
+
+ return 0;
+ }
+ }
+
+ if (cam->host)
+ g_free(cam->host);
+ if (cam->proto)
+ g_free(cam->proto);
+ if (cam->rdir)
+ g_free(cam->rdir);
+ if (cam->rcapturefile)
+ g_free(cam->rcapturefile);
+ if (cam->uri)
+ g_free(cam->uri);
+
+ cam->host = host;
+ cam->rdir = rdir;
+ cam->proto = proto;
+ cam->rcapturefile = rfile;
+ cam->uri = uri;
+
+ mount_volume(cam);
+
+ return 1;
+}
+
/*
* apply preferences
*/
void prefs_func (GtkWidget * okbutton, cam * cam)
{
GConfClient *client;
- gchar *dir;
+ gchar *rdir;
client = gconf_client_get_default ();
if (gtk_file_chooser_get_current_folder((GtkFileChooser *) dentry)) {
cam->pixdir = g_strdup (gtk_file_chooser_get_current_folder((GtkFileChooser *) dentry));
gconf_client_set_string (cam->gc, KEY1, cam->pixdir, NULL);
-
} else {
if (cam->debug == TRUE) {
fprintf (stderr, "null directory\ndirectory unchanged.");
}
}
+ if (!apply_remote_pref(cam) && cam->debug == TRUE) {
+ fprintf (stderr, "remote directory params wrong\ndirectory unchanged.");
+ }
+
/*
* this is stupid, even if the string is empty, it will not return NULL
*/
@@ -310,29 +376,6 @@ void prefs_func (GtkWidget * okbutton, cam * cam)
gconf_client_set_string (cam->gc, KEY2, cam->capturefile, NULL);
}
- if (strlen (gtk_entry_get_text ((GtkEntry *) host_entry)) > 0) {
- cam->rhost = g_strdup (gtk_entry_get_text ((GtkEntry *) host_entry));
- gconf_client_set_string (cam->gc, KEY5, cam->rhost, NULL);
- }
- if (strlen (gtk_entry_get_text ((GtkEntry *) login_entry)) > 0) {
- cam->rlogin =
- g_strdup (gtk_entry_get_text ((GtkEntry *) login_entry));
- gconf_client_set_string (cam->gc, KEY6, cam->rlogin, NULL);
- }
- if (strlen (gtk_entry_get_text ((GtkEntry *) pw_entry)) > 0) {
- cam->rpw = g_strdup (gtk_entry_get_text ((GtkEntry *) pw_entry));
- gconf_client_set_string (cam->gc, KEY7, cam->rpw, NULL);
- }
- if (strlen (gtk_entry_get_text ((GtkEntry *) directory_entry)) > 0) {
- cam->rpixdir =
- g_strdup (gtk_entry_get_text ((GtkEntry *) directory_entry));
- gconf_client_set_string (cam->gc, KEY8, cam->rpixdir, NULL);
- }
- if (strlen (gtk_entry_get_text ((GtkEntry *) filename_entry)) > 0) {
- cam->rcapturefile =
- g_strdup (gtk_entry_get_text ((GtkEntry *) filename_entry));
- gconf_client_set_string (cam->gc, KEY9, cam->rcapturefile, NULL);
- }
if (strlen (gtk_entry_get_text ((GtkEntry *) string_entry)) > 0) {
cam->ts_string =
g_strdup (gtk_entry_get_text ((GtkEntry *) string_entry));
diff --git a/src/camorama-globals.h b/src/camorama-globals.h
index 3fa35bc..4dd8386 100644
--- a/src/camorama-globals.h
+++ b/src/camorama-globals.h
@@ -32,8 +32,7 @@ G_BEGIN_DECLS
GtkWidget *main_window, *prefswindow;
int frames, frames2, seconds;
GtkWidget *dentry, *entry2, *string_entry, *format_selection;
-GtkWidget *host_entry, *directory_entry, *filename_entry, *login_entry,
- *pw_entry;
+GtkWidget *host_entry, *protocol, *rdir_entry, *filename_entry;
G_END_DECLS
diff --git a/src/camorama-window.c b/src/camorama-window.c
index 4d9bfcd..b65f4e1 100644
--- a/src/camorama-window.c
+++ b/src/camorama-window.c
@@ -39,6 +39,10 @@
static GQuark menu_item_filter_type = 0;
+/* Supported URI protocol schemas */
+const gchar * const protos[] = { "ftp", "sftp", "smb" };
+
+
static void
add_filter_clicked(GtkMenuItem* menuitem, CamoramaFilterChain* chain) {
GType filter_type = GPOINTER_TO_SIZE(g_object_get_qdata(G_OBJECT(menuitem), menu_item_filter_type));
@@ -187,9 +191,10 @@ static guint resolution_signals[8] = { 0 };
void
load_interface(cam* cam) {
+ int i;
gchar *title;
GdkPixbuf *logo = NULL;
- GtkCellRenderer* cell;
+ GtkCellRenderer* cell;
GtkWidget *small_res, *new_res;
GtkWidget *window = GTK_WIDGET(gtk_builder_get_object(cam->xml,
"main_window"));
@@ -275,8 +280,6 @@ load_interface(cam* cam) {
get_supported_resolutions(cam);
if (cam->n_res > 0) {
- int i;
-
for (i = 0; i < cam->n_res; i++) {
char name[32];
@@ -459,22 +462,36 @@ load_interface(cam* cam) {
cam->timestamp);
/* remote */
- login_entry = GTK_WIDGET(gtk_builder_get_object(cam->xml, "login_entry"));
host_entry = GTK_WIDGET(gtk_builder_get_object(cam->xml, "host_entry"));
- pw_entry = GTK_WIDGET(gtk_builder_get_object(cam->xml, "pw_entry"));
- directory_entry = GTK_WIDGET(gtk_builder_get_object(cam->xml, "directory_entry"));
+ protocol = GTK_WIDGET(gtk_builder_get_object(cam->xml, "remote_protocol"));
+ rdir_entry = GTK_WIDGET(gtk_builder_get_object(cam->xml, "rdir_entry"));
filename_entry = GTK_WIDGET(gtk_builder_get_object(cam->xml, "filename_entry"));
- gtk_entry_set_text (GTK_ENTRY (host_entry), cam->rhost);
- gtk_entry_set_text (GTK_ENTRY (login_entry), cam->rlogin);
- gtk_entry_set_text (GTK_ENTRY (pw_entry), cam->rpw);
- gtk_entry_set_text (GTK_ENTRY (directory_entry), cam->rpixdir);
+
+ gtk_entry_set_text (GTK_ENTRY (host_entry), cam->host);
+ gtk_entry_set_text (GTK_ENTRY (rdir_entry), cam->rdir);
gtk_entry_set_text (GTK_ENTRY (filename_entry), cam->rcapturefile);
+ if (!cam->proto)
+ cam->proto = g_strdup(protos[0]);
+
+ for (i = 0; i < G_N_ELEMENTS (protos); i++) {
+ gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT(protocol), protos[i]);
+ if (!strcmp(cam->proto, protos[i]))
+ gtk_combo_box_set_active(GTK_COMBO_BOX(protocol), i);
+ }
+
+ if (cam->host && cam->proto && cam->rdir) {
+ cam->uri = volume_uri(cam->host, cam->proto, cam->rdir);
+ mount_volume(cam);
+ } else {
+ cam->uri = NULL;
+ }
+
g_signal_connect (gtk_builder_get_object(cam->xml, "timecb"),
"toggled", G_CALLBACK (rappend_func), cam);
gtk_toggle_button_set_active ((GtkToggleButton *)
gtk_builder_get_object (cam->xml,
- "timecb"),
+ "timecb"),
cam->rtimefn);
g_signal_connect (gtk_builder_get_object(cam->xml, "fjpgb"),
diff --git a/src/fileio.c b/src/fileio.c
index 2a99197..e3a2d37 100644
--- a/src/fileio.c
+++ b/src/fileio.c
@@ -1,9 +1,11 @@
#include <errno.h>
#include <gtk/gtk.h>
+#include <gio/gio.h>
#include <glib/gi18n.h>
#include <time.h>
#include <stdio.h>
+#include "interface.h"
#include "support.h"
#include "fileio.h"
@@ -12,8 +14,6 @@
# define CHAR_START 4
# include "font_6x11.h"
-static int print_error (GnomeVFSResult result, const char *uri_string);
-
/* add timestamp/text to image - "borrowed" from gspy */
int
add_rgb_text (guchar *image, int width, int height, char *cstring, char *format,
@@ -83,12 +83,8 @@ add_rgb_text (guchar *image, int width, int height, char *cstring, char *format,
void remote_save (cam * cam)
{
GThread *remote_thread;
- GnomeVFSHandle **write_handle;
char *output_uri_string, *input_uri_string;
- GnomeVFSFileSize bytes_written;
- GnomeVFSURI *uri_1;
unsigned char *tmp;
- GnomeVFSResult result = 0;
gboolean test;
char *filename, *error_message;
FILE *fp;
@@ -110,7 +106,6 @@ void remote_save (cam * cam)
default:
ext = g_strdup ((gchar *) "jpeg");
}
- //cam->tmp = NULL;
if (cam->rtimestamp == TRUE) {
add_rgb_text (cam->tmp, cam->width, cam->height, cam->ts_string,
@@ -120,7 +115,6 @@ void remote_save (cam * cam)
if (chdir ("/tmp") != 0) {
error_dialog (_("Could save temporary image file in /tmp."));
g_free (ext);
- //g_thread_exit (NULL);
}
time (&t);
@@ -128,7 +122,6 @@ void remote_save (cam * cam)
strftime (timenow, sizeof (timenow) - 1, "%s", tm);
filename = g_strdup_printf ("camorama.%s", ext);
- //g_free(ext);
pb = gdk_pixbuf_new_from_data (cam->tmp, GDK_COLORSPACE_RGB, FALSE, 8,
cam->width, cam->height,
cam->width * cam->bpp / 8, NULL,
@@ -139,105 +132,104 @@ void remote_save (cam * cam)
g_strdup_printf (_("Unable to create image '%s'."), filename);
error_dialog (error_message);
g_free (error_message);
- //g_thread_exit (NULL);
}
- pbs = gdk_pixbuf_save (pb, filename, ext, NULL, NULL); //&error);//, NULL);
+ pbs = gdk_pixbuf_save (pb, filename, ext, NULL, NULL);
if (pbs == FALSE) {
error_message =
g_strdup_printf (_("Could not save image '%s/%s'."),
cam->pixdir, filename);
error_dialog (error_message);
g_free (filename);
- //g_free (error_message);
- //return -1;
}
- /*if (cam->debug == TRUE)
- * {
- * fprintf (stderr, "bytes to file %s: %d\n", filename, fc);
- * } */
-
g_free (filename);
- /* from here :) */
- /* open tmp file and read it */
- /*input_uri_string = g_strdup_printf ("camorama.%s", ext);
- *
- * if (!(fp = fopen (input_uri_string, "rb")))
- * {
- * error_message =
- * g_strdup_printf (_
- * ("Unable to open temporary image file '%s'."),
- * filename);
- * error_dialog (error_message);
- * g_free (input_uri_string);
- * g_free (error_message);
- * exit (0);
- * }
- *
- * tmp = malloc (sizeof (char) * cam->width * cam->height * cam->bpp * 2 / 8);
- * while (!feof (fp))
- * {
- * bytes += fread (tmp, 1, cam->width * cam->height * cam->bpp / 8, fp);
- * }
- * fclose (fp);
- *
- * time (&t);
- * tm = localtime (&t);
- * strftime (timenow, sizeof (timenow) - 1, "%s", tm);
- * if (cam->rtimefn == TRUE)
- * {
- * output_uri_string = g_strdup_printf ("ftp://%s/%s/%s-%s.%s",
- * cam->rhost, cam->rpixdir,
- * cam->rcapturefile,
- * timenow, ext);
- * }
- * else
- * {
- * output_uri_string =
- * g_strdup_printf ("ftp://%s/%s/%s.%s", cam->rhost,
- * cam->rpixdir, cam->rcapturefile,
- * ext);
- * }
- * uri_1 = gnome_vfs_uri_new (output_uri_string);
- *
- * test = gnome_vfs_uri_exists (uri_1);
- *
- * gnome_vfs_uri_set_user_name (uri_1, cam->rlogin);
- * gnome_vfs_uri_set_password (uri_1, cam->rpw);
- */
- /* start here? */
- /*result = gnome_vfs_open_uri((GnomeVFSHandle **) & write_handle, uri_1, GNOME_VFS_OPEN_WRITE);
- * if(result != GNOME_VFS_OK) {
- * error_message = g_strdup_printf(_("An error occurred opening %s."), output_uri_string);
- * error_dialog(error_message);
- * g_free(error_message);
- * g_thread_exit(NULL);
- * } */
-
- /* write the data */
- /*result = gnome_vfs_write((GnomeVFSHandle *) write_handle, tmp, bytes, &bytes_written);
- * if(result != GNOME_VFS_OK) {
- * error_message = g_strdup_printf(_("An error occurred writing to %s."), output_uri_string);
- * error_dialog(error_message);
- * g_free(error_message);
- * } */
remote_thread =
g_thread_new ("remote", (GThreadFunc) save_thread, cam);
g_free (ext);
- //free (tmp);
+}
+
+struct mount_params {
+ GFile *rdir_file;
+ GMountOperation *mop;
+ gchar *uri;
+};
+
+static void mount_cb (GObject * obj, GAsyncResult * res, gpointer user_data)
+{
+ cam *cam = user_data;
+ gboolean ret;
+ GError *err = NULL;
+
+ ret = g_file_mount_enclosing_volume_finish (G_FILE (obj), res, &err);
+
+ /* Ignore G_IO_ERROR_ALREADY_MOUNTED */
+ if (g_error_matches (err, G_IO_ERROR, G_IO_ERROR_ALREADY_MOUNTED))
+ ret = 1;
+
+ if (ret) {
+ cam->rdir_ok = TRUE;
+ gconf_client_set_string(cam->gc, KEY5, cam->host, NULL);
+ gconf_client_set_string(cam->gc, KEY6, cam->proto, NULL);
+ gconf_client_set_string(cam->gc, KEY8, cam->rdir, NULL);
+ gconf_client_set_string(cam->gc, KEY9, cam->rcapturefile, NULL);
+ } else {
+ gchar *error_message = g_strdup_printf (_("An error occurred mounting %s:%s."),
+ cam->uri, err->message);
+ error_dialog (error_message);
+ g_free (error_message);
+ }
+}
+
+gchar *volume_uri(gchar *host, gchar *proto, gchar *rdir)
+{
+ return g_strdup_printf ("%s://%s/%s", proto, host, rdir);
+}
+
+void umount_volume(cam *cam)
+{
+ struct mount_params mount;
+
+ /* Unmount previous volume */
+ if (!cam->rdir_ok)
+ return;
+ cam->rdir_ok = FALSE;
+ g_file_unmount_mountable_with_operation(cam->rdir_file,
+ G_MOUNT_UNMOUNT_NONE,
+ cam->rdir_mop, NULL,
+ NULL, cam);
+}
+
+void mount_volume(cam *cam)
+{
+ /* Prepare a mount operation */
+ cam->rdir_file = g_file_new_for_uri(cam->uri);
+ if (cam->rdir_file)
+ cam->rdir_mop = gtk_mount_operation_new(NULL);
+ else
+ cam->rdir_mop = NULL;
+
+ if (!cam->rdir_mop) {
+ gchar *error_message = g_strdup_printf (_("An error occurred accessing %s."),
+ cam->uri);
+ error_dialog (error_message);
+ g_free (error_message);
+
+ return;
+ }
+
+ g_file_mount_enclosing_volume(cam->rdir_file, G_MOUNT_MOUNT_NONE,
+ cam->rdir_mop, NULL, mount_cb, cam);
}
void save_thread (cam * cam)
{
- GnomeVFSHandle **write_handle;
char *output_uri_string, *input_uri_string;
- GnomeVFSFileSize bytes_written;
- GnomeVFSURI *uri_1;
+ GFile *uri_1;
+ GFileOutputStream *fout;
unsigned char *tmp;
- GnomeVFSResult result = 0;
gboolean test;
char *filename, *error_message;
FILE *fp;
@@ -247,9 +239,11 @@ void save_thread (cam * cam)
struct tm *tm;
gboolean pbs;
GdkPixbuf *pb;
- /*GnomeVFSResult result = 0;
- * GnomeVFSHandle **write_handle;
- * char *error_message; */
+ GError *error = NULL;
+
+ /* Check if it is ready to mount */
+ if (!cam->rdir_ok)
+ return;
switch (cam->rsavetype) {
case JPEG:
@@ -291,24 +285,16 @@ void save_thread (cam * cam)
tm = localtime (&t);
strftime (timenow, sizeof (timenow) - 1, "%s", tm);
if (cam->rtimefn == TRUE) {
- output_uri_string = g_strdup_printf ("ftp://%s/%s/%s-%s.%s",
- cam->rhost, cam->rpixdir,
- cam->rcapturefile, timenow, ext);
+ output_uri_string = g_strdup_printf ("%s/%s-%s.%s", cam->uri,
+ cam->capturefile,
+ timenow, ext);
} else {
- output_uri_string =
- g_strdup_printf ("ftp://%s/%s/%s.%s", cam->rhost,
- cam->rpixdir, cam->rcapturefile, ext);
+ output_uri_string = g_strdup_printf ("%s/%s.%s", cam->uri,
+ cam->capturefile, ext);
}
- uri_1 = gnome_vfs_uri_new (output_uri_string);
-
- //test = gnome_vfs_uri_exists (uri_1);
- gnome_vfs_uri_set_user_name (uri_1, cam->rlogin);
- gnome_vfs_uri_set_password (uri_1, cam->rpw);
-
- result = gnome_vfs_open_uri ((GnomeVFSHandle **) & write_handle,
- uri_1, GNOME_VFS_OPEN_WRITE);
- if (result != GNOME_VFS_OK) {
+ uri_1 = g_file_new_for_uri (output_uri_string);
+ if (!uri_1) {
error_message =
g_strdup_printf (_("An error occurred opening %s."),
output_uri_string);
@@ -317,32 +303,40 @@ void save_thread (cam * cam)
g_thread_exit (NULL);
}
+ fout = g_file_replace (uri_1, NULL, FALSE,
+ G_FILE_CREATE_REPLACE_DESTINATION, NULL, &error);
+ if (error) {
+ error_message =
+ g_strdup_printf (_("An error occurred opening %s for write: %s."),
+ output_uri_string, error->message);
+ error_dialog (error_message);
+ g_free (error_message);
+ g_thread_exit (NULL);
+ }
+
/* write the data */
- result = gnome_vfs_write ((GnomeVFSHandle *) write_handle, tmp, bytes,
- &bytes_written);
- if (result != GNOME_VFS_OK) {
+ g_output_stream_write(G_OUTPUT_STREAM(fout), tmp, bytes, NULL, &error);
+ if (error) {
error_message =
- g_strdup_printf (_("An error occurred writing to %s."),
- output_uri_string);
+ g_strdup_printf (_("An error occurred writing to %s: %s."),
+ output_uri_string, error->message);
+ error_dialog (error_message);
+ g_free (error_message);
+ }
+ g_output_stream_close(G_OUTPUT_STREAM(fout), NULL, &error);
+ if (error) {
+ error_message =
+ g_strdup_printf (_("An error occurred closing %s: %s."),
+ output_uri_string, error->message);
error_dialog (error_message);
g_free (error_message);
}
- gnome_vfs_close ((GnomeVFSHandle *) write_handle);
- gnome_vfs_shutdown ();
+
+ g_object_unref(uri_1);
free (tmp);
g_thread_exit (NULL);
}
-static int print_error (GnomeVFSResult result, const char *uri_string)
-{
- const char *error_string;
- /* get the string corresponding to this GnomeVFSResult value */
- error_string = gnome_vfs_result_to_string (result);
- printf ("Error %s occurred opening location %s\n", error_string,
- uri_string);
- return 1;
-}
-
int local_save (cam * cam)
{
int fc;
@@ -367,8 +361,6 @@ int local_save (cam * cam)
default:
ext = g_strdup ((gchar *) "jpeg");
}
- //cam->tmp = NULL;
- //memcpy (cam->tmp, cam->pic_buf, cam->width * cam->height * cam->bpp / 8);
if (cam->timestamp == TRUE) {
add_rgb_text (cam->tmp, cam->width, cam->height, cam->ts_string,
diff --git a/src/fileio.h b/src/fileio.h
index c74e2ca..9aa8688 100644
--- a/src/fileio.h
+++ b/src/fileio.h
@@ -1,7 +1,9 @@
#include "v4l.h"
-#include <libgnomevfs/gnome-vfs.h>
int add_rgb_text (guchar *, int, int, char *, char *, gboolean, gboolean);
void remote_save (cam *);
void save_thread (cam *);
int local_save (cam *);
+gchar *volume_uri(gchar *host, gchar *proto, gchar *rdir);
+void umount_volume(cam *);
+void mount_volume (cam *);
diff --git a/src/interface.h b/src/interface.h
index bd1dbfe..ed10f06 100644
--- a/src/interface.h
+++ b/src/interface.h
@@ -5,8 +5,8 @@
#define KEY3 "/apps/camorama/preferences/file_type"
#define KEY4 "/apps/camorama/preferences/timestamp"
#define KEY5 "/apps/camorama/preferences/hostname"
-#define KEY6 "/apps/camorama/preferences/login"
-#define KEY7 "/apps/camorama/preferences/password"
+#define KEY6 "/apps/camorama/preferences/remote_proto"
+/* KEY7 removed */
#define KEY8 "/apps/camorama/preferences/remote_save_dir"
#define KEY9 "/apps/camorama/preferences/remote_save_file"
#define KEY10 "/apps/camorama/preferences/remote_file_type"
diff --git a/src/main.c b/src/main.c
index a7e9bce..4b47605 100644
--- a/src/main.c
+++ b/src/main.c
@@ -91,6 +91,7 @@ main(int argc, char *argv[]) {
};
cam = &cam_object;
+
/* set some default values */
cam->frame_number = 0;
cam->pixmap = NULL;
@@ -145,8 +146,6 @@ main(int argc, char *argv[]) {
gconf_client_add_dir (cam->gc, PATH, GCONF_CLIENT_PRELOAD_NONE, NULL);
gconf_client_notify_add (cam->gc, KEY1, (void *) gconf_notify_func,
cam->pixdir, NULL, NULL);
- gconf_client_notify_add (cam->gc, KEY5, (void *) gconf_notify_func,
- cam->rhost, NULL, NULL);
gconf_client_notify_add (cam->gc, KEY2, (void *) gconf_notify_func,
cam->capturefile, NULL, NULL);
gconf_client_notify_add (cam->gc, KEY3,
@@ -155,6 +154,14 @@ main(int argc, char *argv[]) {
gconf_client_notify_add (cam->gc, KEY4,
(void *) gconf_notify_func_bool,
&cam->timestamp, NULL, NULL);
+ gconf_client_notify_add (cam->gc, KEY5, (void *) gconf_notify_func,
+ cam->host, NULL, NULL);
+ gconf_client_notify_add (cam->gc, KEY6, (void *) gconf_notify_func,
+ cam->proto, NULL, NULL);
+ gconf_client_notify_add (cam->gc, KEY8, (void *) gconf_notify_func,
+ cam->rdir, NULL, NULL);
+ gconf_client_notify_add (cam->gc, KEY9, (void *) gconf_notify_func,
+ cam->rcapturefile, NULL, NULL);
if (!poopoo) {
gchar const* gconf_device = gconf_client_get_string(cam->gc, KEY_DEVICE, NULL);
@@ -170,13 +177,11 @@ main(int argc, char *argv[]) {
cam->pixdir = g_strdup (gconf_client_get_string (cam->gc, KEY1, NULL));
cam->capturefile =
g_strdup (gconf_client_get_string (cam->gc, KEY2, NULL));
- cam->rhost = g_strdup (gconf_client_get_string (cam->gc, KEY5, NULL));
- cam->rlogin = g_strdup (gconf_client_get_string (cam->gc, KEY6, NULL));
- cam->rpw = g_strdup (gconf_client_get_string (cam->gc, KEY7, NULL));
- cam->rpixdir = g_strdup (gconf_client_get_string (cam->gc, KEY8, NULL));
- cam->rcapturefile =
- g_strdup (gconf_client_get_string (cam->gc, KEY9, NULL));
cam->savetype = gconf_client_get_int (cam->gc, KEY3, NULL);
+ cam->host = g_strdup (gconf_client_get_string (cam->gc, KEY5, NULL));
+ cam->proto = g_strdup (gconf_client_get_string (cam->gc, KEY6, NULL));
+ cam->rdir = g_strdup (gconf_client_get_string (cam->gc, KEY8, NULL));
+ cam->rcapturefile = g_strdup (gconf_client_get_string (cam->gc, KEY9, NULL));
cam->rsavetype = gconf_client_get_int (cam->gc, KEY10, NULL);
cam->ts_string =
g_strdup (gconf_client_get_string (cam->gc, KEY16, NULL));
diff --git a/src/v4l.c b/src/v4l.c
index 7a94b3e..24242f2 100644
--- a/src/v4l.c
+++ b/src/v4l.c
@@ -29,10 +29,7 @@ void print_cam(cam *cam){
}
}
printf("capture directory = %s, capture file = %s\n",cam->pixdir, cam->capturefile);
- if (strcmp(cam->rhost, "yourdomain.org")) {
- printf("remote host = %s, remote login = %s\n",cam->rhost,cam->rlogin);
- printf("remote capture directory = %s, remote capture file = %s\n",cam->rpixdir, cam->rcapturefile);
- }
+ printf("remote host = %s\n",cam->uri);
if (strcmp(cam->ts_string, "Camorama!"))
printf("timestamp = %s\n\n",cam->ts_string);
}
@@ -125,6 +122,7 @@ void camera_cap(cam * cam)
/* Query supported resolutions */
+ cam->rdir_ok = FALSE;
cam->min_width = -1;
cam->min_height = -1;
cam->max_width = 0;
diff --git a/src/v4l.h b/src/v4l.h
index ba860a8..45f25cf 100644
--- a/src/v4l.h
+++ b/src/v4l.h
@@ -6,6 +6,7 @@
#include <stdlib.h>
#include <string.h>
#include <getopt.h>
+#include <gio/gio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
@@ -62,9 +63,8 @@ typedef struct camera {
char *video_dev;
unsigned char *image;
gchar *capturefile, *rcapturefile;
- gchar *pixdir, *rpixdir;
+ gchar *pixdir, *host, *proto, *rdir, *uri;
int savetype, rsavetype;
- gchar *rhost, *rlogin, *rpw;
gchar *ts_string;
gchar *date_format;
gboolean debug, read, hidden;
@@ -82,6 +82,10 @@ typedef struct camera {
CamoramaFilterChain* filter_chain;
+ gboolean rdir_ok;
+ GFile *rdir_file;
+ GMountOperation *rdir_mop;
+
/* Buffer handling - should be used only inside v4l.c */
struct v4l2_requestbuffers req;
unsigned int n_buffers;

Privacy Policy