Commit 971a4c75 authored by Daniel G. Siegel's avatar Daniel G. Siegel

add the gedit warning box when no camera is found, fixes bug #511945, courtesy of sebastian keller

svn path=/trunk/; revision=624
parent 2bc15059
......@@ -2,13 +2,14 @@ written by daniel g. siegel <dgsiegel@gmail.com> and Jaap Haitsma <jaap@haitsma.
the following people contributed to cheese:
- Diego Escalante Urrelo <dieguito@gmail.com>
- Patryk Zawadzki <patrys@pld-linux.org>
- Tim Philipp Müller <tim@centricular.net>
- Mirco "MacSlow" Müller <macslow@bangang.de>
- Gintautas Miliauskas <gintas@akl.lt>
- Luca Ferretti <elle.uca@libero.it>
- Mirco "MacSlow" Müller <macslow@bangang.de>
- Patryk Zawadzki <patrys@pld-linux.org>
- Sebastian Keller <sebastian-keller@gmx.de>
- Steve Magoun <steve.magoun@canonical.com>
- Tim Philipp Müller <tim@centricular.net>
- Tommi Vainikainen <thv@iki.fi>
- Gintautas Miliauskas <gintas@akl.lt>
icon-work
- cheese icons by Andreas Nilsson <andreas@andreasn.se>
......
2008-04-02 daniel g. siegel <dgsiegel@gmail.com>
* AUTHORS,
data/cheese.glade,
data/cheese.ui,
src/cheese-no-camera.c,
src/cheese-no-camera.h,
src/cheese-window.c,
src/gedit-message-area.c,
src/gedit-message-area.h,
src/Makefile.am:
add the gedit warning box when no camera is found, fixes bug #511945, courtesy of sebastian keller
2008-03-20 daniel g. siegel <dgsiegel@gmail.com>
* data/cheese.schemas.in:
......
......@@ -26,18 +26,37 @@
<property name="show_tabs">False</property>
<property name="show_border">False</property>
<child>
<widget class="GtkAspectFrame" id="video_frame">
<widget class="GtkVBox" id="video_frame_vbox">
<property name="visible">True</property>
<property name="label_xalign">0</property>
<property name="shadow_type">GTK_SHADOW_NONE</property>
<property name="ratio">1.3300000429153442</property>
<property name="obey_child">False</property>
<child>
<widget class="GtkDrawingArea" id="video_screen">
<property name="width_request">320</property>
<property name="height_request">240</property>
<widget class="GtkAlignment" id="message_area_frame">
<property name="visible">True</property>
<child>
<placeholder/>
</child>
</widget>
<packing>
<property name="expand">False</property>
</packing>
</child>
<child>
<widget class="GtkAspectFrame" id="video_frame">
<property name="visible">True</property>
<property name="label_xalign">0</property>
<property name="shadow_type">GTK_SHADOW_NONE</property>
<property name="ratio">1.3300000429153442</property>
<property name="obey_child">False</property>
<child>
<widget class="GtkDrawingArea" id="video_screen">
<property name="width_request">320</property>
<property name="height_request">240</property>
<property name="visible">True</property>
</widget>
</child>
</widget>
<packing>
<property name="position">1</property>
</packing>
</child>
</widget>
<packing>
......@@ -66,6 +85,12 @@
<property name="position">1</property>
</packing>
</child>
<child>
<placeholder/>
<packing>
<property name="type">tab</property>
</packing>
</child>
<child>
<widget class="GtkAspectFrame" id="throbber_frame">
<property name="visible">True</property>
......@@ -82,6 +107,12 @@
<property name="position">2</property>
</packing>
</child>
<child>
<placeholder/>
<packing>
<property name="type">tab</property>
</packing>
</child>
</widget>
</child>
<child>
......
......@@ -25,18 +25,37 @@
<property name="show_tabs">False</property>
<property name="show_border">False</property>
<child>
<object class="GtkAspectFrame" id="video_frame">
<object class="GtkVBox" id="video_frame_vbox">
<property name="visible">True</property>
<property name="label_xalign">0</property>
<property name="shadow_type">GTK_SHADOW_NONE</property>
<property name="ratio">1.3300000429153442</property>
<property name="obey_child">False</property>
<child>
<object class="GtkDrawingArea" id="video_screen">
<property name="width_request">320</property>
<property name="height_request">240</property>
<object class="GtkAlignment" id="message_area_frame">
<property name="visible">True</property>
<child>
<placeholder/>
</child>
</object>
<packing>
<property name="expand">False</property>
</packing>
</child>
<child>
<object class="GtkAspectFrame" id="video_frame">
<property name="visible">True</property>
<property name="label_xalign">0</property>
<property name="shadow_type">GTK_SHADOW_NONE</property>
<property name="ratio">1.3300000429153442</property>
<property name="obey_child">False</property>
<child>
<object class="GtkDrawingArea" id="video_screen">
<property name="width_request">320</property>
<property name="height_request">240</property>
<property name="visible">True</property>
</object>
</child>
</object>
<packing>
<property name="position">1</property>
</packing>
</child>
</object>
</child>
......@@ -56,6 +75,9 @@
</child>
</object>
</child>
<child type="tab">
<placeholder/>
</child>
<child>
<object class="GtkAspectFrame" id="throbber_frame">
<property name="visible">True</property>
......@@ -69,6 +91,9 @@
</child>
</object>
</child>
<child type="tab">
<placeholder/>
</child>
</object>
</child>
<child>
......
......@@ -31,7 +31,11 @@ cheese_SOURCES = \
ephy-spinner.c \
ephy-spinner.h \
gst-audio-play.c \
gst-audio-play.h
gst-audio-play.h \
gedit-message-area.c \
gedit-message-area.h \
no-camera.c \
no-camera.h
cheese_LDADD = \
$(CHEESE_LIBS)
......
/*
* Copyright (C) 2005 Paolo Maggi
* Copyright (C) 2008 Sebastian Keller <sebastian-keller@gmx.de>
* Copyright (C) 2008 daniel g. siegel <dgsiegel@gmail.com>
*
* Licensed under the GNU General Public License Version 2
*
* 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, see <http://www.gnu.org/licenses/>.
*
*---------
*
* Based on gedit-io-error-message-area.c by Paolo Maggi
*/
#include <gtk/gtk.h>
#include <glib/gi18n.h>
#include "gedit-message-area.h"
#include "cheese-no-camera.h"
static void
cheese_no_camera_set_message_area_text_and_icon (GeditMessageArea *message_area,
const gchar *icon_stock_id,
const gchar *primary_text,
const gchar *secondary_text)
{
GtkWidget *hbox_content;
GtkWidget *image;
GtkWidget *vbox;
gchar *primary_markup;
gchar *secondary_markup;
GtkWidget *primary_label;
GtkWidget *secondary_label;
hbox_content = gtk_hbox_new (FALSE, 8);
gtk_widget_show (hbox_content);
image = gtk_image_new_from_stock (icon_stock_id, GTK_ICON_SIZE_DIALOG);
gtk_widget_show (image);
gtk_box_pack_start (GTK_BOX (hbox_content), image, FALSE, FALSE, 0);
gtk_misc_set_alignment (GTK_MISC (image), 0.5, 0);
vbox = gtk_vbox_new (FALSE, 6);
gtk_widget_show (vbox);
gtk_box_pack_start (GTK_BOX (hbox_content), vbox, TRUE, TRUE, 0);
primary_markup = g_strdup_printf ("<b>%s</b>", primary_text);
primary_label = gtk_label_new (primary_markup);
g_free (primary_markup);
gtk_widget_show (primary_label);
gtk_box_pack_start (GTK_BOX (vbox), primary_label, TRUE, TRUE, 0);
gtk_label_set_use_markup (GTK_LABEL (primary_label), TRUE);
gtk_label_set_line_wrap (GTK_LABEL (primary_label), TRUE);
gtk_misc_set_alignment (GTK_MISC (primary_label), 0, 0.5);
GTK_WIDGET_SET_FLAGS (primary_label, GTK_CAN_FOCUS);
gtk_label_set_selectable (GTK_LABEL (primary_label), TRUE);
if (secondary_text != NULL)
{
secondary_markup = g_strdup_printf ("<small>%s</small>",
secondary_text);
secondary_label = gtk_label_new (secondary_markup);
g_free (secondary_markup);
gtk_widget_show (secondary_label);
gtk_box_pack_start (GTK_BOX (vbox), secondary_label, TRUE, TRUE, 0);
GTK_WIDGET_SET_FLAGS (secondary_label, GTK_CAN_FOCUS);
gtk_label_set_use_markup (GTK_LABEL (secondary_label), TRUE);
gtk_label_set_line_wrap (GTK_LABEL (secondary_label), TRUE);
gtk_label_set_selectable (GTK_LABEL (secondary_label), TRUE);
gtk_misc_set_alignment (GTK_MISC (secondary_label), 0, 0.5);
}
gedit_message_area_set_contents (GEDIT_MESSAGE_AREA (message_area),
hbox_content);
}
GtkWidget *
cheese_no_camera_message_area ()
{
GtkWidget *message_area;
message_area = gedit_message_area_new ();
cheese_no_camera_set_message_area_text_and_icon (GEDIT_MESSAGE_AREA (message_area),
"gtk-dialog-error",
_("No camera found!"),
_("Please refer to the help for further information."));
gedit_message_area_add_stock_button_with_text (GEDIT_MESSAGE_AREA (message_area),
_("Help"),
GTK_STOCK_HELP, GTK_RESPONSE_HELP);
return message_area;
}
/*
* Copyright (C) 2008 Sebastian Keller <sebastian-keller@gmx.de>
* Copyright (C) 2008 daniel g. siegel <dgsiegel@gmail.com>
*
* Licensed under the GNU General Public License Version 2
*
* 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, see <http://www.gnu.org/licenses/>.
*/
#ifndef __CHEESE_NO_CAMERA_H__
#define __CHEESE_NO_CAMERA_H__
G_BEGIN_DECLS
GtkWidget* cheese_no_camera_message_area (void);
G_END_DECLS
#endif /* __CHEESE_NO_CAMERA_H__ */
......@@ -47,6 +47,8 @@
#include "cheese-window.h"
#include "ephy-spinner.h"
#include "gst-audio-play.h"
#include "gedit-message-area.h"
#include "cheese-no-camera.h"
#define SHUTTER_SOUNDS 5
......@@ -83,6 +85,8 @@ typedef struct
GtkWidget *throbber;
GtkWidget *countdown_frame;
GtkWidget *countdown;
GtkWidget *message_area_frame;
GtkWidget *message_area;
GtkWidget *button_effects;
GtkWidget *button_photo;
......@@ -820,6 +824,30 @@ cheese_window_countdown_picture_cb (gpointer data)
cheese_webcam_take_photo (cheese_window->webcam, cheese_window->photo_filename);
}
static void
cheese_window_no_camera_message_area_response (GtkWidget *widget, gint response_id, GtkWidget *cheese_window)
{
GError *error = NULL;
gboolean ret;
if (response_id == GTK_RESPONSE_HELP)
{
ret = g_app_info_launch_default_for_uri ("ghelp:cheese?faq", NULL, &error);
if (ret == FALSE)
{
GtkWidget *d;
d = gtk_message_dialog_new (GTK_WINDOW (cheese_window->window),
GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE,
_("Unable to open help file for Cheese"));
gtk_dialog_run(GTK_DIALOG(d));
gtk_widget_destroy(d);
g_error_free(error);
}
}
}
static void
cheese_window_stop_recording (CheeseWindow *cheese_window)
{
......@@ -1026,6 +1054,25 @@ cheese_window_radio_action_group_new (CheeseWindow *cheese_window, char *name,
return action_group;
}
static void
cheese_window_set_message_area (CheeseWindow *cheese_window,
GtkWidget *message_area)
{
if (cheese_window->message_area == message_area)
return;
if (cheese_window->message_area != NULL)
gtk_widget_destroy (cheese_window->message_area);
cheese_window->message_area = message_area;
if (message_area == NULL)
return;
gtk_container_add (GTK_CONTAINER (cheese_window->message_area_frame), cheese_window->message_area);
gtk_widget_show (GTK_WIDGET(cheese_window->message_area));
}
static void
cheese_window_create_window (CheeseWindow *cheese_window)
{
......@@ -1041,6 +1088,8 @@ cheese_window_create_window (CheeseWindow *cheese_window)
GtkWidget *menubar;
#endif
cheese_window->message_area = NULL;
builder = gtk_builder_new ();
gtk_builder_add_from_file (builder, PACKAGE_DATADIR"/cheese.ui", &error);
......@@ -1069,6 +1118,7 @@ cheese_window_create_window (CheeseWindow *cheese_window)
cheese_window->throbber_frame = GTK_WIDGET (gtk_builder_get_object (builder, "throbber_frame"));
cheese_window->countdown_frame = GTK_WIDGET (gtk_builder_get_object (builder, "countdown_frame"));
cheese_window->effect_frame = GTK_WIDGET (gtk_builder_get_object (builder, "effect_frame"));
cheese_window->message_area_frame = GTK_WIDGET (gtk_builder_get_object (builder, "message_area_frame"));
#ifdef HILDON
/* Reparent widgets in case we use hildon. This saves us maintaining two
......@@ -1252,6 +1302,7 @@ void
setup_camera (CheeseWindow *cheese_window)
{
char *webcam_device = NULL;
GtkWidget *message_area;
g_object_get (cheese_window->gconf, "gconf_prop_webcam", &webcam_device, NULL);
......@@ -1272,6 +1323,17 @@ setup_camera (CheeseWindow *cheese_window)
gdk_threads_enter ();
gtk_notebook_set_current_page (GTK_NOTEBOOK(cheese_window->notebook), 0);
ephy_spinner_stop (EPHY_SPINNER (cheese_window->throbber));
if (cheese_webcam_get_num_webcam_devices (cheese_window->webcam) == 0)
{
message_area = cheese_no_camera_message_area();
g_signal_connect (message_area,
"response",
G_CALLBACK (cheese_window_no_camera_message_area_response),
cheese_window);
cheese_window_set_message_area (cheese_window, message_area);
}
gdk_threads_leave ();
gtk_widget_set_sensitive (GTK_WIDGET (cheese_window->take_picture), TRUE);
}
......
/*
* gedit-message-area.c
* This file is part of gedit
*
* Copyright (C) 2005 - Paolo Maggi
*
* 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., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307, USA.
*/
/*
* Modified by the gedit Team, 2005. See the AUTHORS file for a
* list of people on the gedit Team.
* See the ChangeLog files for a list of changes.
*
* $Id: gedit-message-area.c 5887 2007-09-07 07:20:19Z pborelli $
*/
/* TODO: Style properties */
#include <glib/gi18n.h>
#include <gtk/gtk.h>
#include <gdk/gdk.h>
#include <gdk/gdkkeysyms.h>
#include "gedit-message-area.h"
#define GEDIT_MESSAGE_AREA_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), \
GEDIT_TYPE_MESSAGE_AREA, \
GeditMessageAreaPrivate))
struct _GeditMessageAreaPrivate
{
GtkWidget *main_hbox;
GtkWidget *contents;
GtkWidget *action_area;
gboolean changing_style;
};
typedef struct _ResponseData ResponseData;
struct _ResponseData
{
gint response_id;
};
enum {
RESPONSE,
CLOSE,
LAST_SIGNAL
};
static guint signals[LAST_SIGNAL];
G_DEFINE_TYPE(GeditMessageArea, gedit_message_area, GTK_TYPE_HBOX)
static void
gedit_message_area_finalize (GObject *object)
{
/*
GeditMessageArea *message_area = GEDIT_MESSAGE_AREA (object);
*/
G_OBJECT_CLASS (gedit_message_area_parent_class)->finalize (object);
}
static ResponseData *
get_response_data (GtkWidget *widget,
gboolean create)
{
ResponseData *ad = g_object_get_data (G_OBJECT (widget),
"gedit-message-area-response-data");
if (ad == NULL && create)
{
ad = g_new (ResponseData, 1);
g_object_set_data_full (G_OBJECT (widget),
"gedit-message-area-response-data",
ad,
g_free);
}
return ad;
}
static GtkWidget *
find_button (GeditMessageArea *message_area,
gint response_id)
{
GList *children, *tmp_list;
GtkWidget *child = NULL;
children = gtk_container_get_children (
GTK_CONTAINER (message_area->priv->action_area));
for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
{
ResponseData *rd = get_response_data (tmp_list->data, FALSE);
if (rd && rd->response_id == response_id)
{
child = tmp_list->data;
break;
}
}
g_list_free (children);
return child;
}
static void
gedit_message_area_close (GeditMessageArea *message_area)
{
if (!find_button (message_area, GTK_RESPONSE_CANCEL))
return;
/* emit response signal */
gedit_message_area_response (GEDIT_MESSAGE_AREA (message_area),
GTK_RESPONSE_CANCEL);
}
static gboolean
paint_message_area (GtkWidget *widget,
GdkEventExpose *event,
gpointer user_data)
{
gtk_paint_flat_box (widget->style,
widget->window,
GTK_STATE_NORMAL,
GTK_SHADOW_OUT,
NULL,
widget,
"tooltip",
widget->allocation.x + 1,
widget->allocation.y + 1,
widget->allocation.width - 2,
widget->allocation.height - 2);
return FALSE;
}
static void
gedit_message_area_class_init (GeditMessageAreaClass *klass)
{
GObjectClass *object_class;
GtkBindingSet *binding_set;
object_class = G_OBJECT_CLASS (klass);
object_class->finalize = gedit_message_area_finalize;
klass->close = gedit_message_area_close;
g_type_class_add_private (object_class, sizeof(GeditMessageAreaPrivate));
signals[RESPONSE] = g_signal_new ("response",
G_OBJECT_CLASS_TYPE (klass),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GeditMessageAreaClass, response),
NULL, NULL,
g_cclosure_marshal_VOID__INT,
G_TYPE_NONE, 1,
G_TYPE_INT);
signals[CLOSE] = g_signal_new ("close",
G_OBJECT_CLASS_TYPE (klass),
G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
G_STRUCT_OFFSET (GeditMessageAreaClass, close),
NULL, NULL,
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE, 0);
binding_set = gtk_binding_set_by_class (klass);
gtk_binding_entry_add_signal (binding_set, GDK_Escape, 0, "close", 0);
}
static void
style_set (GtkWidget *widget,
GtkStyle *prev_style,
GeditMessageArea *message_area)
{
GtkWidget *window;
GtkStyle *style;
if (message_area->priv->changing_style)
return;
/* This is a hack needed to use the tooltip background color */
window = gtk_window_new (GTK_WINDOW_POPUP);
gtk_widget_set_name (window, "gtk-tooltip");
gtk_widget_ensure_style (window);
style = gtk_widget_get_style (window);
message_area->priv->changing_style = TRUE;
gtk_widget_set_style (GTK_WIDGET (message_area), style);
message_area->priv->changing_style = FALSE;
gtk_widget_destroy (window);
gtk_widget_queue_draw (GTK_WIDGET (message_area));