From 53c38347752b8c039f42861d85e8b3a34aa1701b Mon Sep 17 00:00:00 2001 From: Emmanuel Milou <emmanuel.milou@savoirfairelinux.com> Date: Wed, 18 Mar 2009 15:21:48 -0400 Subject: [PATCH] Add hooks squeleton on daemon side --- configure.ac | 3 +- sflphone-gtk/src/historyfilter.c | 89 ------------------- sflphone-gtk/src/main.c | 2 +- src/Makefile.am | 3 +- src/global.h | 2 +- src/hooks/Makefile.am | 6 ++ .../historyfilter.h => src/hooks/urlhook.cpp | 23 ++--- src/hooks/urlhook.h | 46 ++++++++++ test/hooksTest.h | 68 ++++++++++++++ 9 files changed, 134 insertions(+), 108 deletions(-) delete mode 100644 sflphone-gtk/src/historyfilter.c create mode 100644 src/hooks/Makefile.am rename sflphone-gtk/src/historyfilter.h => src/hooks/urlhook.cpp (52%) create mode 100644 src/hooks/urlhook.h create mode 100644 test/hooksTest.h diff --git a/configure.ac b/configure.ac index 988fc35e53..53260af39d 100644 --- a/configure.ac +++ b/configure.ac @@ -39,7 +39,8 @@ AC_CONFIG_FILES([src/Makefile \ src/dbus/Makefile \ src/plug-in/audiorecorder/Makefile \ src/plug-in/Makefile \ - src/plug-in/test/Makefile]) + src/plug-in/test/Makefile \ + src/hooks/Makefile]) dnl Unitary test section AC_CONFIG_FILES([test/Makefile]) diff --git a/sflphone-gtk/src/historyfilter.c b/sflphone-gtk/src/historyfilter.c deleted file mode 100644 index db1d405246..0000000000 --- a/sflphone-gtk/src/historyfilter.c +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright (C) 2008 Savoir-Faire Linux inc. - * Author: Antoine Reversat <antoine.reversat@savoirfairelinux.com> - * - * 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 3 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., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -#include <string.h> - -#include <historyfilter.h> -#include <calltree.h> - -GtkWidget * filter_entry; - -GtkTreeModel* -create_filter(GtkTreeModel* child) -{ - GtkTreeModel* ret = gtk_tree_model_filter_new(child, NULL); - gtk_tree_model_filter_set_visible_func(GTK_TREE_MODEL_FILTER(ret), is_visible, NULL, NULL); - return GTK_TREE_MODEL(ret); -} - -gboolean -is_visible(GtkTreeModel* model, GtkTreeIter* iter, gpointer data UNUSED) -{ - if( SHOW_SEARCHBAR ) - { - GValue val; - - gchar* text = NULL; - gchar* search = (gchar*)gtk_entry_get_text(GTK_ENTRY(filter_entry)); - memset (&val, 0, sizeof(val)); - gtk_tree_model_get_value(GTK_TREE_MODEL(model), iter, 1, &val); - if(G_VALUE_HOLDS_STRING(&val)){ - text = (gchar *)g_value_get_string(&val); - } - if(text != NULL && g_ascii_strncasecmp(search, _("Search"), 6) != 0){ - return g_regex_match_simple(search, text, G_REGEX_CASELESS, 0); - } - g_value_unset (&val); - return TRUE; - } - return TRUE; -} - -void -filter_entry_changed(GtkEntry* entry UNUSED, gchar* arg1 UNUSED, gpointer data UNUSED) -{ - gtk_toggle_tool_button_set_active(GTK_TOGGLE_TOOL_BUTTON(historyButton), TRUE); - gtk_tree_model_filter_refilter(GTK_TREE_MODEL_FILTER(histfilter)); -} - -void -clear_filter_entry_if_default(GtkWidget* widget UNUSED, gpointer user_data UNUSED) -{ - if(g_ascii_strncasecmp(gtk_entry_get_text(GTK_ENTRY(filter_entry)), _("Search"), 6) == 0) - gtk_entry_set_text(GTK_ENTRY(filter_entry), ""); -} - -GtkWidget* -create_filter_entry() -{ - GtkWidget* image; - GtkWidget* ret = gtk_hbox_new(FALSE, 0); - - filter_entry = sexy_icon_entry_new(); - //filter_entry = gtk_entry_new(); - image = gtk_image_new_from_stock( GTK_STOCK_FIND , GTK_ICON_SIZE_SMALL_TOOLBAR); - sexy_icon_entry_set_icon( SEXY_ICON_ENTRY(filter_entry), SEXY_ICON_ENTRY_PRIMARY , GTK_IMAGE(image) ); - sexy_icon_entry_add_clear_button( SEXY_ICON_ENTRY(filter_entry) ); - gtk_entry_set_text(GTK_ENTRY(filter_entry), _("Search")); - g_signal_connect(GTK_ENTRY(filter_entry), "changed", G_CALLBACK(filter_entry_changed), NULL); - g_signal_connect(GTK_ENTRY(filter_entry), "grab-focus", G_CALLBACK(clear_filter_entry_if_default), NULL); - - gtk_box_pack_start(GTK_BOX(ret), filter_entry, TRUE, TRUE, 0); - return ret; -} diff --git a/sflphone-gtk/src/main.c b/sflphone-gtk/src/main.c index 886f523186..b3c92c0731 100644 --- a/sflphone-gtk/src/main.c +++ b/sflphone-gtk/src/main.c @@ -33,7 +33,7 @@ main (int argc, char *argv[]) gtk_init (&argc, &argv); g_print("%s\n", PACKAGE_STRING); - g_print("Copyright (c) 2005 2006 2007 2008 Savoir-faire Linux Inc.\n"); + g_print("Copyright (c) 2005 2006 2007 2008 2009 Savoir-faire Linux Inc.\n"); g_print("This is free software. You may redistribute copies of it under the terms of\n\ the GNU General Public License Version 3 <http://www.gnu.org/licenses/gpl.html>.\n\ There is NO WARRANTY, to the extent permitted by law.\n\n"); diff --git a/src/Makefile.am b/src/Makefile.am index 62b1650881..1248568ec6 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -13,7 +13,7 @@ IAXSOURCES = IAXHEADERS = endif -SUBDIRS = audio config dbus plug-in +SUBDIRS = audio config dbus plug-in hooks # Add here the cpp files to be build with sflphone sflphoned_SOURCES = \ @@ -84,6 +84,7 @@ libsflphone_la_LIBADD = \ ./config/libconfig.la \ ./plug-in/libplugin.la \ ./plug-in/audiorecorder/libaudiorecorder.la \ + ./hooks/libhooks.la \ $(IAX_LIBS) libsflphone_la_SOURCES = diff --git a/src/global.h b/src/global.h index 719f7e4238..d6c763ac30 100644 --- a/src/global.h +++ b/src/global.h @@ -135,7 +135,7 @@ static const SOUND_FORMAT INT32 = 0x8; #define DEFAULT_SIP_PORT 5060 -#define HOOK_DEFAULT_SIP_FIELD "X-Call-url" +#define HOOK_DEFAULT_SIP_FIELD "X-Call-Url" #define HOOK_DEFAULT_URL_COMMAND "x-www-browser" diff --git a/src/hooks/Makefile.am b/src/hooks/Makefile.am new file mode 100644 index 0000000000..aa5797fe7a --- /dev/null +++ b/src/hooks/Makefile.am @@ -0,0 +1,6 @@ +SUBDIRS = + +noinst_LTLIBRARIES = libhooks.la + +libhooks_la_SOURCES = \ + urlhook.cpp urlhook.h diff --git a/sflphone-gtk/src/historyfilter.h b/src/hooks/urlhook.cpp similarity index 52% rename from sflphone-gtk/src/historyfilter.h rename to src/hooks/urlhook.cpp index 72d46b8ce7..b2f7d9e995 100644 --- a/sflphone-gtk/src/historyfilter.h +++ b/src/hooks/urlhook.cpp @@ -1,31 +1,24 @@ /* - * Copyright (C) 2007 Savoir-Faire Linux inc. - * Author: Antoine Reversat <antoine.reversat@savoirfairelinux.com> - * + * Copyright (C) 2009 Savoir-Faire Linux inc. + * Author: Emmanuel Milou <emmanuel.milou@savoirfairelinux.com> + * * 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 3 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., 675 Mass Ave, Cambridge, MA 02139, USA. */ - -#ifndef __HFILTER_H__ -#define __HFILTER_H__ -#include <calllist.h> -#include <gtk/gtk.h> -#include <libsexy/sexy-icon-entry.h> +#include "urlhook.h" -GtkTreeModel* create_filter(GtkTreeModel* child); +UrlHook::UrlHook () : _command (""), _field ("") { } -gboolean is_visible(GtkTreeModel* model, GtkTreeIter* iter, gpointer data); -GtkWidget* create_filter_entry(); -#endif +UrlHook::~UrlHook () { } diff --git a/src/hooks/urlhook.h b/src/hooks/urlhook.h new file mode 100644 index 0000000000..67f3fb352b --- /dev/null +++ b/src/hooks/urlhook.h @@ -0,0 +1,46 @@ +/* + * Copyright (C) 2009 Savoir-Faire Linux inc. + * Author: Emmanuel Milou <emmanuel.milou@savoirfairelinux.com> + * + * 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 3 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., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#ifndef URL_HOOK_H +#define URL_HOOK_H + +#include <string> + +class UrlHook { + + public: + /** + * Constructor + */ + UrlHook (); + + /** + * Destructor + */ + ~UrlHook (); + + private: + /* The command to execute when receiving the URL */ + std::string _command; + + /* The field to look for in the header */ + std::string _field; +}; + +#endif // URL_HOOK_H diff --git a/test/hooksTest.h b/test/hooksTest.h new file mode 100644 index 0000000000..a08e7e3ecd --- /dev/null +++ b/test/hooksTest.h @@ -0,0 +1,68 @@ +/* + * Copyright (C) 2009 Savoir-Faire Linux inc. + * Author: Emmanuel Milou <emmanuel.milou@savoirfairelinux.com> + * + * 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 3 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., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +// Cppunit import +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/TestCaller.h> +#include <cppunit/TestCase.h> +#include <cppunit/TestSuite.h> + +#include <assert.h> + +/* + * @file hooksTest.cpp + * @brief Regroups unitary tests related to the hooks. + */ + +#ifndef _HOOKS_TEST_ +#define _HOOKS_TEST_ + +class HooksTest : public CppUnit::TestCase { + + /** + * Use cppunit library macros to add unit test the factory + */ + CPPUNIT_TEST_SUITE (HooksTest); + CPPUNIT_TEST (); + CPPUNIT_TEST_SUITE_END(); + + public: + HooksTest() : CppUnit::TestCase("Hooks implementation Tests") {} + + /* + * Code factoring - Common resources can be initialized here. + * This method is called by unitcpp before each test + */ + void setUp(); + + /* + * Code factoring - Common resources can be released here. + * This method is called by unitcpp after each test + */ + inline void tearDown (); + + void testUnloadPlugins (); + + private: +}; + +/* Register our test module */ +CPPUNIT_TEST_SUITE_REGISTRATION (HooksTest); + +# -- GitLab