static void on_view_as_activate (GtkMenuItem *item, ViewAsData *d) { GtkWidget *w, *c, *s; Bonobo_Control control; CORBA_Environment ev; CameraFile *f; int result; Bonobo_PersistStream pstream; BonoboObject *stream; const char *data = NULL; unsigned long int size; const char *type; g_return_if_fail (d->iid != NULL); CORBA_exception_init (&ev); control = bonobo_get_object (d->iid, "IDL:Bonobo/Control:1.0", &ev); if (BONOBO_EX (&ev) || (control == CORBA_OBJECT_NIL)) { CORBA_exception_free (&ev); g_warning ("Could not get control from '%s'.", d->iid); return; } w = bonobo_window_new (d->file, d->file); c = bonobo_widget_new_control_from_objref (control, CORBA_OBJECT_NIL); gtk_widget_show (c); bonobo_window_set_contents (BONOBO_WINDOW (w), c); gtk_widget_show (w); s = gtkam_status_new (_("Downloading '%s' from '%s'..."), d->file, d->folder); g_signal_emit (G_OBJECT (d->list), signals[NEW_STATUS], 0, s); gp_file_new (&f); result = gp_camera_file_get (d->camera->camera, d->folder, d->file, GP_FILE_TYPE_NORMAL, f, GTKAM_STATUS (s)->context->context); if (d->camera->multi) gp_camera_exit (d->camera->camera, NULL); if (result >= 0) { CORBA_exception_init (&ev); pstream = Bonobo_Unknown_queryInterface (control, "IDL:Bonobo/PersistStream:1.0", &ev); if (!BONOBO_EX (&ev) && (pstream != CORBA_OBJECT_NIL)) { gp_file_get_data_and_size (f, &data, &size); gp_file_get_mime_type (f, &type); stream = bonobo_stream_mem_create (data, size, TRUE, FALSE); Bonobo_PersistStream_load (pstream, bonobo_object_corba_objref (stream), type, &ev); g_object_unref (G_OBJECT (stream)); bonobo_object_release_unref (pstream, NULL); } CORBA_exception_free (&ev); } gp_file_unref (f); gtk_object_destroy (GTK_OBJECT (s)); }
static void on_detect_clicked (GtkButton *button, GtkamChooser *chooser) { GtkWidget *d, *status; CameraList *list; int result; const char *name; status = gtkam_status_new (_("Detecting cameras...")); gtkam_dialog_add_status (GTKAM_DIALOG (chooser), status); gp_list_new (&list); result = gp_abilities_list_detect (chooser->priv->al, chooser->priv->il, list, GTKAM_STATUS (status)->context->context); switch (result) { case GP_OK: if (!gp_list_count (list)) { d = gtkam_close_new (_("No cameras detected.")); gtk_window_set_transient_for (GTK_WINDOW (d), GTK_WINDOW (chooser)); gtk_widget_show (d); } else { /* FIXME: Let user choose from the list */ gp_list_get_name (list, 0, &name); gtk_entry_set_text (chooser->priv->entry_model, name); gtk_entry_set_text (chooser->priv->entry_port, "Universal Serial Bus (usb:)"); } break; case GP_ERROR_CANCEL: break; default: d = gtkam_error_new (result, GTKAM_STATUS (status)->context, GTK_WIDGET (chooser), _("Could not detect any cameras.")); gtk_widget_show (d); break; } gp_list_unref (list); gtk_object_destroy (GTK_OBJECT (status)); }
static gboolean get_thumbnail_idle (gpointer data) { GtkamList *list = GTKAM_LIST (data); GetThumbnailData *d; CameraFile *file; GtkWidget *s; GdkPixbuf *pixbuf; GdkPixbufLoader *loader; int result; const char *fd; unsigned long fs; gfloat factor; d = list->priv->head; if (d == NULL) return (FALSE); s = gtkam_status_new (_("Downloading thumbnail of '%s' from " "folder '%s'..."), d->name, d->folder); g_signal_emit (G_OBJECT (list), signals[NEW_STATUS], 0, s); gp_file_new (&file); result = gp_camera_file_get (d->camera->camera, d->folder, d->name, GP_FILE_TYPE_PREVIEW, file, GTKAM_STATUS (s)->context->context); if (d->camera->multi) gp_camera_exit (d->camera->camera, NULL); if (result >= 0) { gp_file_get_data_and_size (file, &fd, &fs); loader = gdk_pixbuf_loader_new (); gdk_pixbuf_loader_write (loader, fd, fs, NULL); gdk_pixbuf_loader_close (loader, NULL); pixbuf = gdk_pixbuf_loader_get_pixbuf (loader); gtk_list_store_set (list->priv->store, d->iter, PREVIEW_ORIG_COLUMN, pixbuf, -1); factor = gtkam_list_get_zoom_factor (list); pixbuf = gdk_pixbuf_scale_simple (pixbuf, gdk_pixbuf_get_width (pixbuf) * factor, gdk_pixbuf_get_height (pixbuf) * factor, GDK_INTERP_BILINEAR); g_object_unref (G_OBJECT (loader)); gtk_list_store_set (list->priv->store, d->iter, PREVIEW_COLUMN, pixbuf, -1); g_object_unref (G_OBJECT (pixbuf)); } gp_file_unref (file); gtk_object_destroy (GTK_OBJECT (s)); if (result == GP_ERROR_CAMERA_BUSY) return (TRUE); g_object_unref (G_OBJECT (d->camera)); g_free (d->name); g_free (d->folder); gtk_tree_iter_free (d->iter); list->priv->head = d->next; g_free (d); if (!list->priv->head) list->priv->tail = NULL; gtk_widget_destroy (s); if (list->priv->head == NULL) return (FALSE); else return (TRUE); }
static GtkamCamera * gtkam_chooser_get_camera (GtkamChooser *chooser) { GtkWidget *dialog, *status; GPPortInfo info; Camera *camera; CameraAbilities abilities; const gchar *model, *port, *speed; gchar *port_path, *right, *tmp; int m, p, r; gboolean multi; GtkamCamera *c; model = gtk_entry_get_text (chooser->priv->entry_model); port = gtk_entry_get_text (chooser->priv->entry_port); speed = gtk_entry_get_text (chooser->priv->entry_speed); multi = GTK_TOGGLE_BUTTON (chooser->priv->check_multi)->active; if (!port || !*port) port_path = g_strdup (_("None")); else { port_path = g_strdup (port); right = strrchr (port_path, ')'); *right = '\0'; tmp = g_strdup (strrchr (port_path, '(') + 1); g_free (port_path); port_path = tmp; } gp_camera_new (&camera); #ifdef HAVE_GP_CAMERA_SET_TIMEOUT_FUNCS gp_camera_set_timeout_funcs (camera, start_timeout_func, stop_timeout_func, NULL); #endif /* Model? */ m = gp_abilities_list_lookup_model (chooser->priv->al, model); gp_abilities_list_get_abilities (chooser->priv->al, m, &abilities); gp_camera_set_abilities (camera, abilities); /* Port? */ if (strcmp (port_path, _("None"))) { p = gp_port_info_list_lookup_path (chooser->priv->il, port_path); gp_port_info_list_get_info (chooser->priv->il, p, &info); gp_camera_set_port_info (camera, info); } /* Speed? */ if (strcmp (speed, _("Best"))) gp_camera_set_port_speed (camera, atoi (speed)); /* * Initialize the camera to check if it is really there. Exit * afterwards because other applications could need the camera, too. */ status = gtkam_status_new (_("Initializing camera...")); gtkam_dialog_add_status (GTKAM_DIALOG (chooser), status); r = gp_camera_init (camera, GTKAM_STATUS (status)->context->context); if (multi) gp_camera_exit (camera, NULL); switch (r) { case GP_OK: break; case GP_ERROR_CANCEL: g_free (port_path); break; default: g_free (port_path); dialog = gtkam_error_new (r, GTKAM_STATUS (status)->context, NULL, _("Could not initialize camera.")); gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (chooser)); gtk_widget_show (dialog); gp_camera_unref (camera); camera = NULL; } gtk_object_destroy (GTK_OBJECT (status)); c = gtkam_camera_new (camera, multi); gp_camera_unref (camera); return (c); }