aboutsummaryrefslogtreecommitdiffstats
path: root/src/callbacks.c
diff options
context:
space:
mode:
authorMauro Carvalho Chehab <mchehab+samsung@kernel.org>2018-08-28 13:55:08 (GMT)
committerAlessio Treglia <quadrispro@ubuntu.com>2018-08-28 13:55:08 (GMT)
commitd07ed0da6c46ffaca7a88c7c7caecd696336d203 (patch)
treef2e9a1744213ee4bb40999c84a1d91d657eca6b4 /src/callbacks.c
parentd73d6c58d392dfbd11f5b384ab8c4ee948d2dfb7 (diff)
Improvements and fixes (#17)0.20
* Get rid of *~ backup files and autom4mate.cache/ It doesn't make sense to keep backup files stored on git. Update .gitignore accordingly and sort their entries. Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org> * Bug reports should be done at the github tree Not sure why it is listing gnome for bug report. I suspect it was because it was written originally to be part of Gnome. Update it to point to upstream's camorama repository at github, where bugs will likely be better handled. Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org> * Add a camorama.appdata.xml Use the file shipped with Fedora as basis, changing the screenshots (the link there is broken) and changing the email of the current maintainer. Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org> * v4l: fix a typo enqueu -> enqueue Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org> * Rename configure.in to configure.ac While here, update it according with: https://www.gnu.org/software/automake/manual/automake.html#Modernize-AM_005fINIT_005fAUTOMAKE-invocation Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org> * autogen.sh: use a more modern approach The procedure used there is deprecated. Change it to run with latest versions of Gtk 2. Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org> * Update build system Run the autogen.sh script to generate again the files that are created automatically. Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org> * Convert it to use the new gettext logic Since version 0.19.8, gettext doesn't need intltoolize anymore. Cleanup gettext logic, in order to auto-generate the po/* files. Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org> * Update auto-generated build files All those files can be generated by running the autogen.sh script. Yet, as camorama use to carry those for a while, let's auto-generate and keep them inside the tree, removing the obsolete ones and backup files. Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org> * POFILES.in: add missing sources Several sources are missing at the POFILES.in. Update. Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org> * callbacks: allow translating the fps streaming message Use gettext to allow translating this message: "%.2f fps - current %.2f fps - average" Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org> * Auto-translate camera.desktop Add the needed logic to auto-translate camera.desktop. Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org> * Auto-translate camorama.appdata.xml Add locale translations for camorama.appdata.xml too. Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org> * Fix depth on filters and fileio V4L2 uses depth as bits per pixel, while filters and file io uses it as bits per byte. Do the conversion. Fixes a regression on Camorama filters. Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org> * v4l: Better name V4L bits per pixel field At V4L, the depth for each video format is represented using bits per pixel. However, at Camorama, the filters use bytes per pixel instead. That caused a regression during the conversion to V4L2. In order to avoid further troubles, let's rename: cam->depth ===> cam->bpp Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org> * v4l: make print_cam() useful There is a debug logic at v4l.c that is not used anywhere. Also, its output is noisy, as it displays some things that shouldn't work if not explicitly set. Print data from it when -D is used, on a useful way, e. g. by default it will print something like: Camera Info ----------- device = /dev/video0, x = 960, y = 720 bits per pixel = 24, desk_depth = 24 capture directory = /home/user/Webcam_Pictures, capture file = Webcam Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org> * Include only gtk.h header Instead of including header files just for a few widgets used, include the main one. That's a rule with Gtk 3. That also allows building it with: make CFLAGS+="-DGTK_DISABLE_SINGLE_INCLUDES" Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org> * filter: get rid of a warning due to a missing prototype filter.c: In function ‘camorama_filters_init’: filter.c:574:2: warning: implicit declaration of function ‘camorama_filter_reichardt_get_type’; did you mean ‘camorama_filter_invert_get_type’? [-Wimplicit-function-declaration] camorama_filter_reichardt_get_type(); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ camorama_filter_invert_get_type Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org> * fileio: use g_thread_new() instead of g_thread_create() fileio.c:226:9: warning: ‘g_thread_create’ is deprecated: Use 'g_thread_new' instead [-Wdeprecated-declarations] g_thread_create ((GThreadFunc) save_thread, cam, FALSE, NULL); ^~~~~~~~~~~~~~~ In file included from /usr/include/glib-2.0/glib.h:108, from /usr/include/glib-2.0/gobject/gbinding.h:28, from /usr/include/glib-2.0/glib-object.h:23, from /usr/include/glib-2.0/gio/gioenums.h:28, from /usr/include/glib-2.0/gio/giotypes.h:28, from /usr/include/glib-2.0/gio/gio.h:26, from /usr/include/gtk-2.0/gdk/gdkapplaunchcontext.h:30, from /usr/include/gtk-2.0/gdk/gdk.h:32, from /usr/include/gtk-2.0/gtk/gtk.h:32, from v4l.h:14, from fileio.h:1, from fileio.c:1: /usr/include/glib-2.0/glib/deprecated/gthread.h:104:10: note: declared here GThread *g_thread_create (GThreadFunc func, ^~~~~~~~~~~~~~~ Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org> * stop using deprecated gdk_pixbuf_new_from_inline() Prevents this deprecated warning: camorama-stock-items.c:18:2: warning: ‘gdk_pixbuf_new_from_inline’ is deprecated [-Wdeprecated-declarations] GdkPixbuf* buf = gdk_pixbuf_new_from_inline(-1, inline_data, FALSE, NULL); ^~~~~~~~~ In file included from /usr/include/gdk-pixbuf-2.0/gdk-pixbuf/gdk-pixbuf.h:34, from /usr/include/gtk-2.0/gdk/gdkpixbuf.h:37, from /usr/include/gtk-2.0/gdk/gdkcairo.h:28, from /usr/include/gtk-2.0/gdk/gdk.h:33, from /usr/include/gtk-2.0/gtk/gtk.h:32, from camorama-stock-items.c:8: /usr/include/gdk-pixbuf-2.0/gdk-pixbuf/gdk-pixbuf-core.h:362:12: note: declared here GdkPixbuf* gdk_pixbuf_new_from_inline (gint data_length, ^~~~~~~~~~~~~~~~~~~~~~~~~~ Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org> * get rid of deprecated GTK_WIDGET_STATE() Use gtk_widget_get_state() instead. Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org> * Add labels for GNOMEUIINFO_MENU_* items glade-3 doesn't recognize GNOMEUIINFO_MENU_* stock_item anymore. So, we need labels. Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org> * camorama.glade: use glade-3 to generate it It is a way easier to use glade-3 to change the interface. Now that it doesn't use the obsoleted stock item anymore, convert it to the format that glade-3 uses. It will produce one warning, though: [main_window:bonobodock1:vbox36:hbox25:frame1:da] Object class 'Custom widget' from gtk 2.16 is deprecated It should be noticed that glade-3 will add a "swapped attribute to all signals. Those will cause harmless warnings when camorama runs. In order to avoid, we just need to patch the file, after using glade-3 with hunks like this: - <signal name="activate" handler="on_show_effects_activate" swapped="no"/> + <signal name="activate" handler="on_show_effects_activate"/> Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org> * Replace custom widget by GtkDrawingArea There's no need to use a custom widget here. Just use a GtkDrawingArea and simplify the code. With such change, glade-3 doesn't complain anymore about the usage of obsolete widgets. Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org> * camorama.glade: get rid of bonobo and GnomeApp Do some cleanup at camorama.glade in order to make it easier to convert later to Gtk 3 by removing bonobo-specific and GnomeApp widget dependencies. Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org> * Use GtkStatusbar instead of GnomeAppBar No need to use the gnome-specific widget. Just use the default Gtk one. That should make easier when converting this to Gtk 3. Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org> * Convert to Gtk Builder Instead of using libglade, use Gtk Builder. This removes one dependency from Camorama and makes easier to convert to Gtk 3. Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org> * Instead of gnome, use Gtk to display "about" information The gnome_about_new() function is deprecated. Convert it to use the Gtk about dialog instead, and add the license information to it. Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org> * remove uneded includes from camorama-window.c, v4l.c and fileio.c Those headers aren't needed there, so remove them. While here, reorder includes to put into alphabetic order. Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org> * camorama-stock-items: get rid of gnome-specific file location function The only reason why gnome.h is included here is due to a function to locate an icon file. On other parts of Camorama, PACKAGE_DATA_DIR is used, instead, in order o get a pixmap. So, standardize it, by doing the same way here. Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org> * support: get rid of create_pixbuf() This function is not used anymore. Get rid of it. Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org> * support: use Gtk dialog instead of the gnome one There's no good reason to use gnome-specific dialog message here. So, replace by the equivalent Gtk one. Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org> * 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> * fileio: fix a bug preventing timestamp to show on remote file When storing a remote file, the timestamp was not shown: Webcam-(null).jpeg That's because it was doing a sizeof(char *) instead of sizeof(char[str_len]). While here, get rid of the unused timenow var inside remote_save(). Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org> * Only validate remote host settings if capture is enabled It doesn't make any sense to try to map to a remote host if capture is disabled. Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org> * main: use gtk_init() instead of gnome_program_init() With that, camorama doesn't need to use libgnomeui-2.0 anymore. While here, update Gtk check logic to version 2.24, as it is needed in order to use the GtkComboBox. Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org> * Rename data/camorama.glade -> data/camorama.ui The default extension for Gtk Builder is .ui. Change it accordingly at the building system. Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org> * main: Wait for filled buffers in read mode When the driver is on read mode, the driver will return immediately from read() callback even when the buffer is not filled. That causes flicker while on read mode. Also, it displays a non-realistic frame rate. Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org> * Use cairo instead of using GdkPixmap This is another obsolete part of Gtk 2 API. Replace it in favor of using cairo instead. While here, remove code duplication, as image display logic was on 3 different places. Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org> * Replace GTK_WIDGET_VISIBLE() with gtk_widget_get_visible() Replace another Gtk 2 macro that was replaced on Gtk 3. Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org> * Replace gtk_object_get_data() with g_object_get_data() Another function that got replaced on Gtk 3. Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org> * Remove unused function/function prototype Neither lookup_widget nor io_func are used. As both use some Gtk 2 deprecated functions, get rid of them for good. Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org> * Use gtk_container_add() instead of gtk_menu_append() gtk_menu_append() is deprecated and not available anymore with Gtk 3. gtk_container_add() works with both versions, so use it instead. Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org> * Don't get window with widget->window directly Such kind of access is deprecated with Gtk 3. So, use, instead the function gtk_widget_get_window(), as it works with both Gtk 2 and Gtk 3. Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org> * Use g_foo() variants instead of gtk_foo() Several functions were deprecated, as GLib defines an equivalent one, and got removed on Gtk 3. So, use the GLib version. Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org> * Add an option to build with Gtk 3 instead of Gtk 2 By default, Camorama will be built against Gtk 2. However, as it now builds also against Gtk 3, add an option to use Gtk 3 instead. Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org> * Update translation files Now that the translation files are auto-generated, the makefile auto-updates them. That makes a way easier to fix, as editors like poedit will see the new strings that were added to camorama along the time. Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org> * pt_BR: Update Brazilian translation Several messages changed along time. Update their translations. Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org> * Bump version to 0.20 and update ChangeLog There were simply too many changes on Camorama. So, bump its version to 0.20 and reflect latest changes at the ChangeLog. Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
Diffstat (limited to 'src/callbacks.c')
-rw-r--r--src/callbacks.c401
1 files changed, 262 insertions, 139 deletions
diff --git a/src/callbacks.c b/src/callbacks.c
index 0b7aaa1..ccbb31a 100644
--- a/src/callbacks.c
+++ b/src/callbacks.c
@@ -1,13 +1,10 @@
#include <gtk/gtk.h>
+#include <glib/gi18n.h>
#include <config.h>
#include "callbacks.h"
#include "interface.h"
#include "support.h"
#include "filter.h"
-#include <gnome.h>
-#include <libgnomeui/gnome-about.h>
-#include <libgnomeui/gnome-propertybox.h>
-#include <libgnomeui/gnome-window-icon.h>
#include <pthread.h>
#include <libv4l2.h>
@@ -18,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
@@ -41,8 +38,8 @@ void customstring_func (GtkWidget * rb, cam * cam)
client = gconf_client_get_default ();
cam->usestring = gtk_toggle_button_get_active ((GtkToggleButton *) rb);
gconf_client_set_bool (cam->gc, KEY18, cam->usestring, NULL);
- gtk_widget_set_sensitive (glade_xml_get_widget
- (cam->xml, "string_entry"), cam->usestring);
+ gtk_widget_set_sensitive (GTK_WIDGET(gtk_builder_get_object
+ (cam->xml, "string_entry")), cam->usestring);
}
void drawdate_func (GtkWidget * rb, cam * cam)
@@ -104,28 +101,28 @@ void ppm_func (GtkWidget * rb, cam * cam)
void set_sensitive (cam * cam)
{
- gtk_widget_set_sensitive (glade_xml_get_widget (cam->xml, "table4"),
+ gtk_widget_set_sensitive (GTK_WIDGET(gtk_builder_get_object(cam->xml, "table4")),
cam->cap);
- gtk_widget_set_sensitive (glade_xml_get_widget
- (cam->xml, "appendbutton"), cam->cap);
- gtk_widget_set_sensitive (glade_xml_get_widget (cam->xml, "tsbutton"),
+ gtk_widget_set_sensitive (GTK_WIDGET(gtk_builder_get_object
+ (cam->xml, "appendbutton")), cam->cap);
+ gtk_widget_set_sensitive (GTK_WIDGET(gtk_builder_get_object(cam->xml, "tsbutton")),
cam->cap);
- gtk_widget_set_sensitive (glade_xml_get_widget (cam->xml, "jpgb"),
+ gtk_widget_set_sensitive (GTK_WIDGET(gtk_builder_get_object(cam->xml, "jpgb")),
cam->cap);
- gtk_widget_set_sensitive (glade_xml_get_widget (cam->xml, "pngb"),
+ gtk_widget_set_sensitive (GTK_WIDGET(gtk_builder_get_object(cam->xml, "pngb")),
cam->cap);
- gtk_widget_set_sensitive (glade_xml_get_widget (cam->xml, "table5"),
+ gtk_widget_set_sensitive (GTK_WIDGET(gtk_builder_get_object(cam->xml, "table5")),
cam->rcap);
- gtk_widget_set_sensitive (glade_xml_get_widget (cam->xml, "timecb"),
+ gtk_widget_set_sensitive (GTK_WIDGET(gtk_builder_get_object(cam->xml, "timecb")),
cam->rcap);
- gtk_widget_set_sensitive (glade_xml_get_widget
- (cam->xml, "tsbutton2"), cam->rcap);
- gtk_widget_set_sensitive (glade_xml_get_widget (cam->xml, "fjpgb"),
+ gtk_widget_set_sensitive (GTK_WIDGET(gtk_builder_get_object
+ (cam->xml, "tsbutton2")), cam->rcap);
+ gtk_widget_set_sensitive (GTK_WIDGET(gtk_builder_get_object(cam->xml, "fjpgb")),
cam->rcap);
- gtk_widget_set_sensitive (glade_xml_get_widget (cam->xml, "fpngb"),
+ gtk_widget_set_sensitive (GTK_WIDGET(gtk_builder_get_object(cam->xml, "fpngb")),
cam->rcap);
- gtk_widget_set_sensitive (glade_xml_get_widget (cam->xml, "hbox20"),
+ gtk_widget_set_sensitive (GTK_WIDGET(gtk_builder_get_object(cam->xml, "hbox20")),
cam->acap);
}
@@ -166,7 +163,7 @@ void acap_func (GtkWidget * rb, cam * cam)
if (cam->acap == TRUE) {
cam->timeout_id =
- gtk_timeout_add (cam->timeout_interval,
+ g_timeout_add (cam->timeout_interval,
(GSourceFunc) timeout_capture_func, cam);
if (cam->debug == TRUE) {
printf ("add autocap - %d - timeout_interval = \n",
@@ -177,7 +174,7 @@ void acap_func (GtkWidget * rb, cam * cam)
printf ("remove autocap - %d - timeout_interval = \n",
cam->timeout_id, cam->timeout_interval);
}
- gtk_timeout_remove (cam->timeout_id);
+ g_source_remove (cam->timeout_id);
}
update_tooltip (cam);
set_sensitive (cam);
@@ -197,9 +194,9 @@ void interval_change (GtkWidget * sb, cam * cam)
("interval_change; old timeout_id = %d old interval = %d\n",
cam->timeout_id, cam->timeout_interval);
}
- gtk_timeout_remove (cam->timeout_id);
+ g_source_remove (cam->timeout_id);
cam->timeout_id =
- gtk_timeout_add (cam->timeout_interval,
+ g_timeout_add (cam->timeout_interval,
(GSourceFunc) timeout_capture_func, cam);
if (cam->debug == TRUE) {
printf ("new timeout_id = %d, new interval = %d\n",
@@ -284,27 +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
+ * apply preferences
*/
void prefs_func (GtkWidget * okbutton, cam * cam)
{
GConfClient *client;
+ gchar *rdir;
client = gconf_client_get_default ();
- if (gnome_file_entry_get_full_path ((GnomeFileEntry *) dentry, TRUE)
- != NULL) {
- cam->pixdir = g_strdup ((gchar *)
- gnome_file_entry_get_full_path ((GnomeFileEntry *) dentry, FALSE));
+ 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
*/
@@ -314,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));
@@ -398,34 +437,32 @@ void on_change_size_activate (GtkWidget * widget, cam * cam)
if (cam->read == FALSE)
start_streaming(cam);
- cam->pixmap = gdk_pixmap_new (NULL, cam->width, cam->height, cam->desk_depth);
- gtk_widget_set_size_request (glade_xml_get_widget (cam->xml, "da"),
+ gtk_widget_set_size_request (GTK_WIDGET(gtk_builder_get_object(cam->xml, "da")),
cam->width, cam->height);
gtk_window_resize (GTK_WINDOW
- (glade_xml_get_widget (cam->xml, "main_window")), 320,
+ (GTK_WIDGET(gtk_builder_get_object(cam->xml, "main_window"))), 320,
240);
title = g_strdup_printf ("Camorama - %s - %dx%d", cam->name,
cam->width, cam->height);
gtk_window_set_title (GTK_WINDOW
- (glade_xml_get_widget (cam->xml, "main_window")),
+ (GTK_WIDGET(gtk_builder_get_object(cam->xml, "main_window"))),
title);
g_free (title);
}
-void on_show_adjustments_activate (GtkMenuItem * menuitem, cam * cam)
+void on_show_adjustments_activate (GtkToggleButton * button, cam * cam)
{
-
- if (GTK_WIDGET_VISIBLE (glade_xml_get_widget (cam->xml, "adjustments_table"))) {
- gtk_widget_hide (glade_xml_get_widget (cam->xml, "adjustments_table"));
+ if (gtk_widget_get_visible(GTK_WIDGET(gtk_builder_get_object(cam->xml, "adjustments_table")))) {
+ gtk_widget_hide (GTK_WIDGET(gtk_builder_get_object(cam->xml, "adjustments_table")));
gtk_window_resize (GTK_WINDOW
- (glade_xml_get_widget
- (cam->xml, "main_window")), 320, 240);
+ (GTK_WIDGET(gtk_builder_get_object
+ (cam->xml, "main_window"))), 320, 240);
cam->show_adjustments = FALSE;
} else {
- gtk_widget_show (glade_xml_get_widget (cam->xml, "adjustments_table"));
+ gtk_widget_show (GTK_WIDGET(gtk_builder_get_object(cam->xml, "adjustments_table")));
cam->show_adjustments = TRUE;
}
gconf_client_set_bool (cam->gc, KEY22, cam->show_adjustments, NULL);
@@ -433,12 +470,12 @@ void on_show_adjustments_activate (GtkMenuItem * menuitem, cam * cam)
void
on_show_effects_activate(GtkMenuItem* menuitem, cam* cam) {
- GtkWidget* effects = glade_xml_get_widget(cam->xml, "scrolledwindow_effects");
+ GtkWidget* effects = GTK_WIDGET(gtk_builder_get_object(cam->xml, "scrolledwindow_effects"));
cam->show_effects = gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(menuitem));
if(!cam->show_effects) {
gtk_widget_hide(effects);
- gtk_window_resize(GTK_WINDOW(glade_xml_get_widget(cam->xml, "main_window")), 320, 240);
+ gtk_window_resize(GTK_WINDOW(GTK_WIDGET(gtk_builder_get_object(cam->xml, "main_window"))), 320, 240);
} else {
gtk_widget_show(effects);
}
@@ -455,8 +492,8 @@ void on_about_activate (GtkMenuItem * menuitem, cam * cam)
NULL
};
const gchar *documenters[] = { NULL };
- GdkPixbuf *logo =
- (GdkPixbuf *) create_pixbuf (PACKAGE_DATA_DIR "/pixmaps/camorama.png");
+ GdkPixbuf *logo = gdk_pixbuf_new_from_file (PACKAGE_DATA_DIR
+ "/pixmaps/camorama.png", NULL);
char *translators = _("translator_credits");
if (!strcmp (translators, "translator_credits"))
@@ -466,17 +503,34 @@ void on_about_activate (GtkMenuItem * menuitem, cam * cam)
return;
}
- about = gnome_about_new (_("Camorama"), PACKAGE_VERSION,
- "Copyright \xc2\xa9 2002 Greg Jones",
- _("View, alter and save images from a webcam"),
- (const char **) authors,
- (const char **) documenters, translators, logo);
+ about = g_object_new (GTK_TYPE_ABOUT_DIALOG,
+ "name", "Camorama",
+ "version", PACKAGE_VERSION,
+ "copyright", "Copyright \xc2\xa9 2002 Greg Jones",
+ "comments", _("View, alter and save images from a webcam"),
+ "authors", authors,
+ "documenters", documenters,
+ "translator-credits", translators,
+ "logo", logo,
+ "license", "GPL version 2.\n\n"
+ "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 version 2 of the License.\n\n"
+ "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.",
+ "wrap-license", TRUE,
+ NULL);
gtk_window_set_transient_for (GTK_WINDOW (about),
- GTK_WINDOW (glade_xml_get_widget
- (cam->xml, "main_window")));
+ GTK_WINDOW (GTK_WIDGET(gtk_builder_get_object
+ (cam->xml, "main_window"))));
g_object_add_weak_pointer (G_OBJECT (about), (void **) &(about));
-
+ g_object_unref (logo);
+ g_signal_connect (about, "response",
+ G_CALLBACK (gtk_widget_destroy),
+ NULL);
gtk_widget_show (about);
}
@@ -487,8 +541,8 @@ static void
apply_filters(cam* cam) {
/* v4l has reverse rgb order from what camora expect so call the color
filter to fix things up before running the user selected filters */
- camorama_filter_color_filter(NULL, cam->pic_buf, cam->width, cam->height, cam->depth);
- camorama_filter_chain_apply(cam->filter_chain, cam->pic_buf, cam->width, cam->height, cam->depth);
+ camorama_filter_color_filter(NULL, cam->pic_buf, cam->width, cam->height, cam->bpp / 8);
+ camorama_filter_chain_apply(cam->filter_chain, cam->pic_buf, cam->width, cam->height, cam->bpp / 8);
#warning "FIXME: enable the threshold channel filter"
// if((effect_mask & CAMORAMA_FILTER_THRESHOLD_CHANNEL) != 0)
// threshold_channel (cam->pic_buf, cam->width, cam->height, cam->dither);
@@ -497,94 +551,163 @@ apply_filters(cam* cam) {
// threshold (cam->pic_buf, cam->width, cam->height, cam->dither);
}
+#define MULT(d,c,a,t) G_STMT_START { t = c * a + 0x7f; d = ((t >> 8) + t) >> 8; } G_STMT_END
+
/*
- * get image from cam - does all the work ;)
+ * As GTK+2 doesn't have gdk_cairo_surface_create_from_pixbuf, we
+ * Borrowed its implementation from
+ * https://github.com/bratsche/gtk-/blob/master/gdk/gdkcairo.c
+ * With a small backport.
*/
-gint
-read_timeout_func(cam* cam) {
- int i, count = 0;
- GdkGC *gc;
- unsigned char *pic_buf = cam->pic_buf;
-
- v4l2_read (cam->dev, cam->pic_buf, (cam->width * cam->height * cam->depth / 8));
- frames2++;
- /*
- * update_rec.x = 0;
- * update_rec.y = 0;
- * update_rec.width = cam->width;
- * update_rec.height = cam->height;
- */
- count++;
- /*
- * refer the frame
- */
+cairo_surface_t *create_from_pixbuf(const GdkPixbuf *pixbuf,
+ GdkWindow *for_window)
+{
+ gint width = gdk_pixbuf_get_width (pixbuf);
+ gint height = gdk_pixbuf_get_height (pixbuf);
+ guchar *gdk_pixels = gdk_pixbuf_get_pixels (pixbuf);
+ int gdk_rowstride = gdk_pixbuf_get_rowstride (pixbuf);
+ int n_channels = gdk_pixbuf_get_n_channels (pixbuf);
+ int cairo_stride;
+ guchar *cairo_pixels;
+ cairo_format_t format;
+ cairo_surface_t *surface;
+ int j;
+
+ format = CAIRO_FORMAT_RGB24;
+
+ surface = cairo_image_surface_create(CAIRO_FORMAT_RGB24,
+ width, height);
+ cairo_stride = cairo_image_surface_get_stride (surface);
+ cairo_pixels = cairo_image_surface_get_data (surface);
+
+ for (j = height; j; j--) {
+ guchar *p = gdk_pixels;
+ guchar *q = cairo_pixels;
+
+ if (n_channels == 3) {
+ guchar *end = p + 3 * width;
+
+ while (p < end) {
+#if G_BYTE_ORDER == G_LITTLE_ENDIAN
+ q[0] = p[2];
+ q[1] = p[1];
+ q[2] = p[0];
+#else
+ q[1] = p[0];
+ q[2] = p[1];
+ q[3] = p[2];
+#endif
+ p += 3;
+ q += 4;
+ }
+ } else {
+ guchar *end = p + 4 * width;
+ guint t1,t2,t3;
+
+ while (p < end) {
+#if G_BYTE_ORDER == G_LITTLE_ENDIAN
+ MULT(q[0], p[2], p[3], t1);
+ MULT(q[1], p[1], p[3], t2);
+ MULT(q[2], p[0], p[3], t3);
+ q[3] = p[3];
+#else
+ q[0] = p[3];
+ MULT(q[1], p[0], p[3], t1);
+ MULT(q[2], p[1], p[3], t2);
+ MULT(q[3], p[2], p[3], t3);
+#endif
+
+ p += 4;
+ q += 4;
+ }
+
+#undef MULT
+ }
- if (cam->pixformat == V4L2_PIX_FMT_YUV420) {
- yuv420p_to_rgb (cam->pic_buf, cam->tmp, cam->width, cam->height, cam->depth);
- pic_buf = cam->tmp;
+ gdk_pixels += gdk_rowstride;
+ cairo_pixels += cairo_stride;
}
- apply_filters(cam);
-
- gc = gdk_gc_new (cam->pixmap);
- gdk_draw_rgb_image (cam->pixmap,
- gc, 0, 0,
- cam->width, cam->height,
- GDK_RGB_DITHER_NORMAL, pic_buf,
- cam->width * cam->depth / 8);
-
- gtk_widget_queue_draw_area (glade_xml_get_widget (cam->xml, "da"), 0,
- 0, cam->width, cam->height);
- return 1;
-
+ cairo_surface_mark_dirty (surface);
+ return surface;
}
-gint timeout_func (cam * cam)
+static void show_buffer(cam* cam)
{
- int i, count = 0;
- GdkGC *gc;
+ int i;
+ GdkPixbuf *pb;
unsigned char *pic_buf = cam->pic_buf;
+ const GdkRectangle rect = {
+ .x = 0, .y = 0,
+ .width = cam->width, .height = cam->height
+ };
- capture_buffers(cam, cam->pic_buf, cam->width * cam->height * cam->bytesperline);
-
- count++;
/*
- * refer the frame
+ * refer the frame
*/
if (cam->pixformat == V4L2_PIX_FMT_YUV420) {
- yuv420p_to_rgb (cam->pic_buf, cam->tmp, cam->width, cam->height, cam->depth);
+ yuv420p_to_rgb (cam->pic_buf, cam->tmp, cam->width, cam->height, cam->bpp / 8);
pic_buf = cam->tmp;
}
- apply_filters(cam);
+ apply_filters(cam);
+
+ /* Use cairo to display the pixel buffer */
+ pb = gdk_pixbuf_new_from_data(pic_buf, GDK_COLORSPACE_RGB, FALSE, 8,
+ cam->width, cam->height,
+ (cam->width * cam->bpp / 8), NULL,
+ NULL);
- gc = gdk_gc_new (cam->pixmap);
+ GtkWidget *widget = GTK_WIDGET(gtk_builder_get_object(cam->xml, "da"));
+ GdkWindow *window = gtk_widget_get_window(widget);
- gdk_draw_rgb_image (cam->pixmap,
- gc, 0, 0,
- cam->width, cam->height,
- GDK_RGB_DITHER_NORMAL, pic_buf,
- cam->width * cam->depth / 8);
+ cairo_surface_t *surface = create_from_pixbuf(pb, window);
+ cairo_t *cr = gdk_cairo_create(window);
+ cairo_set_source_surface(cr, surface, 0, 0);
- gtk_widget_queue_draw_area (glade_xml_get_widget (cam->xml, "da"), 0,
- 0, cam->width, cam->height);
+ gdk_cairo_rectangle(cr, &rect);
+ cairo_fill(cr);
+ cairo_destroy(cr);
+
+ frames++;
frames2++;
- g_object_unref ((gpointer) gc);
- return 1;
+}
+
+/*
+ * get image from cam - does all the work ;)
+ */
+gint
+read_timeout_func(cam* cam) {
+ v4l2_read (cam->dev, cam->pic_buf,
+ (cam->width * cam->height * cam->bpp / 8));
+
+ show_buffer(cam);
+
+ return TRUE;
+}
+
+gint timeout_func (cam * cam)
+{
+ capture_buffers(cam, cam->pic_buf, cam->width * cam->height * cam->bytesperline);
+
+ show_buffer(cam);
+
+ return TRUE;
}
gint fps (GtkWidget * sb)
{
gchar *stat;
+ guint cont = gtk_statusbar_get_context_id (GTK_STATUSBAR(sb), "context");
seconds++;
- stat = g_strdup_printf ("%.2f fps - current %.2f fps - average",
+ stat = g_strdup_printf (_("%.2f fps - current %.2f fps - average"),
(float) frames / (float) (2),
(float) frames2 / (float) (seconds * 2));
frames = 0;
- gnome_appbar_push (GNOME_APPBAR (sb), stat);
+ gtk_statusbar_push (GTK_STATUSBAR(sb), cont, stat);
g_free (stat);
return 1;
}
@@ -599,10 +722,10 @@ void capture_func (GtkWidget * widget, cam * cam)
if (cam->debug == TRUE) {
printf
("capture_func\nx = %d, y = %d, depth = %d, realloc size = %d\n",
- cam->width, cam->height, cam->depth, (cam->width * cam->height * cam->depth / 8));
+ cam->width, cam->height, cam->bpp, (cam->width * cam->height * cam->bpp / 8));
}
- memcpy (cam->tmp, cam->pic_buf, cam->width * cam->height * cam->depth / 8);
+ memcpy (cam->tmp, cam->pic_buf, cam->width * cam->height * cam->bpp / 8);
if (cam->rcap == TRUE) {
remote_save (cam);
@@ -631,7 +754,7 @@ gint timeout_capture_func (cam * cam)
pt2Function (cam);
}
- memcpy (cam->tmp, cam->pic_buf, cam->width * cam->height * cam->depth / 8);
+ memcpy (cam->tmp, cam->pic_buf, cam->width * cam->height * cam->bpp / 8);
if (cam->cap == TRUE) {
local_save (cam);
@@ -711,6 +834,6 @@ void update_tooltip (cam * cam)
}
tooltip_text = g_strdup_printf (_("Automatic Capture Disabled"));
}
- gtk_status_icon_set_tooltip(cam->tray_icon, tooltip_text);
+ gtk_status_icon_set_tooltip_text(cam->tray_icon, tooltip_text);
g_free (tooltip_text);
}

Privacy Policy