Revision
16132
Author
jmesquita
Date
2010-01-03 22:31:29 -0600 (Sun, 03 Jan 2010)

Log Message

mod_qsettings working retrieving settings from QSettings and expanding templates. Lets go draw the preferences window now.

Modified Paths

Added Paths

Diff

Added: freeswitch/trunk/contrib/jmesquita/FSPhone/conf/event_socket.conf.xml (0 => 16132)


--- freeswitch/trunk/contrib/jmesquita/FSPhone/conf/event_socket.conf.xml	                        (rev 0)
+++ freeswitch/trunk/contrib/jmesquita/FSPhone/conf/event_socket.conf.xml	2010-01-04 04:31:29 UTC (rev 16132)
@@ -0,0 +1,8 @@
+<configuration name="event_socket.conf" description="Socket Client">
+	  <settings>
+		<param name="nat-map" value="false"/>
+		<param name="listen-ip" value="127.0.0.1"/>
+		<param name="listen-port" value="8021"/>
+		<param name="password" value="ClueCon"/>
+	  </settings>
+</configuration>

Modified: freeswitch/trunk/contrib/jmesquita/FSPhone/fshost.cpp (16131 => 16132)


--- freeswitch/trunk/contrib/jmesquita/FSPhone/fshost.cpp	2010-01-03 23:36:24 UTC (rev 16131)
+++ freeswitch/trunk/contrib/jmesquita/FSPhone/fshost.cpp	2010-01-04 04:31:29 UTC (rev 16132)
@@ -59,6 +59,7 @@
     if (!conf_dir.exists(".fsphone"))
     {
         conf_dir.mkpath(".fsphone/conf/accounts");
+        conf_dir.mkpath(".fsphone/templates");
         QFile rootXML(":/confs/freeswitch.xml");
         QString dest = QString("%1/.fsphone/conf/freeswitch.xml").arg(conf_dir.absolutePath());
         rootXML.copy(dest);
@@ -120,14 +121,15 @@
 
     if (switch_event_bind("FSHost", SWITCH_EVENT_ALL, SWITCH_EVENT_SUBCLASS_ANY, eventHandlerCallback, NULL) != SWITCH_STATUS_SUCCESS) {
             switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't bind!\n");
-            printf("Something went really wrong while binding to events...");
     }
 
     /* Load our QSettings module */
     if (switch_loadable_module_build_dynamic("mod_qsettings",mod_qsettings_load,NULL,mod_qsettings_shutdown,SWITCH_FALSE) != SWITCH_STATUS_SUCCESS)
     {
-        printf("Something went wrong when loading our QSettings module\n");
+        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't load mod_qsettings\n");
     }
+    QString res;
+    sendCmd("load", "mod_event_socket", &res);
     emit ready();
     /* Go into the runtime loop. If the argument is true, this basically sets runtime.running = 1 and loops while that is set
      * If its false, it initializes the libedit for the console, then does the same thing

Modified: freeswitch/trunk/contrib/jmesquita/FSPhone/mod_qsettings/mod_qsettings.cpp (16131 => 16132)


--- freeswitch/trunk/contrib/jmesquita/FSPhone/mod_qsettings/mod_qsettings.cpp	2010-01-03 23:36:24 UTC (rev 16131)
+++ freeswitch/trunk/contrib/jmesquita/FSPhone/mod_qsettings/mod_qsettings.cpp	2010-01-04 04:31:29 UTC (rev 16132)
@@ -31,93 +31,119 @@
  *
  */
 #include <QString>
+#include <QtGui>
+#include <QDir>
 #include "mod_qsettings/mod_qsettings.h"
 
-struct xml_binding {
-        QString *bindings;
-};
-typedef struct xml_binding xml_binding_t;
-
-
 static struct {
     switch_memory_pool_t* pool;
 } globals;
 
+switch_xml_t XMLBinding::getConfigXML(QString tmpl)
+{
+    switch_event_t *e;
+    switch_event_create_plain(&e, SWITCH_EVENT_REQUEST_PARAMS);
+    switch_assert(e);
 
+    QFile tmplFile(QString("%1/templates/%2.xml").arg(QApplication::applicationDirPath(),tmpl));
 
+    if (!tmplFile.exists()) {
+        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO,
+                          "Template %s.xml, doesn't exist on directory, falling back to embedded template.\n",
+                          tmpl.toAscii().constData());
+        tmplFile.setFileName(QString(":/confs/%1.xml").arg(tmpl));
+        return NULL;
+    }
+
+    if (tmplFile.open(QIODevice::ReadOnly | QIODevice::Text))
+    {
+        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Template %s could not be read.!\n", tmpl.toAscii().constData());
+        return NULL;
+    }
+
+    /* Open template file and expand all strings based on QSettings */
+    QString tmplContents(tmplFile.readAll());
+    tmplFile.close();
+    _settings->beginGroup("FreeSIWTCH/conf");
+    _settings->beginGroup(tmpl);
+    foreach(QString k, _settings->childKeys())
+    {
+        switch_event_add_header_string(e, SWITCH_STACK_BOTTOM, k.toAscii().constData(), _settings->value(k).toByteArray().constData());
+    }
+
+    char *res = switch_event_expand_headers(e, tmplContents.toAscii().constData());
+    switch_safe_free(e);
+    return switch_xml_parse_str(res, strlen(res));
+}
+
 static switch_xml_t xml_url_fetch(const char *section, const char *tag_name, const char *key_name, const char *key_value, switch_event_t *params,
-								  void *user_data)
+                                  void *user_data)
 {
-	xml_binding_t *binding = (xml_binding_t *) user_data;
+    XMLBinding *binding = (XMLBinding *) user_data;
 
-	if (!binding) {
-		return NULL;
-	}
-	/* All we have to do here is check the section requested and maybe use a
-	   templating system to provide the corresponding xml */
+    if (!binding) {
+        return NULL;
+    }
 
-	return NULL;
+    return binding->getConfigXML(key_value);
 }
 
 static switch_status_t do_config(void)
 {
-        char *cf = "qsettings.conf";
-        switch_xml_t cfg, xml, bindings_tag;
-	xml_binding_t *binding = NULL;
+    char *cf = "qsettings.conf";
+    switch_xml_t cfg, xml, bindings_tag;
+    XMLBinding *binding = NULL;
 
-	if (!(xml = switch_xml_open_cfg(cf, &cfg, NULL))) {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "open of %s failed\n", cf);
-		return SWITCH_STATUS_TERM;
-	}
+    if (!(xml = switch_xml_open_cfg(cf, &cfg, NULL))) {
+        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "open of %s failed\n", cf);
+        return SWITCH_STATUS_TERM;
+    }
 
-	if (!(bindings_tag = switch_xml_child(cfg, "bindings"))) {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Missing <bindings> tag!\n");
-                switch_xml_free(xml);
-                return SWITCH_STATUS_FALSE;
-	}
+    if (!(bindings_tag = switch_xml_child(cfg, "bindings"))) {
+        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Missing <bindings> tag!\n");
+        switch_xml_free(xml);
+        return SWITCH_STATUS_FALSE;
+    }
 
-        QString *bind_mask = new QString(switch_xml_attr_soft(bindings_tag, "value"));
+    QString bind_mask = switch_xml_attr_soft(bindings_tag, "value");
+    if (!bind_mask.isEmpty())
+    {
+        binding = new XMLBinding(bind_mask);
+    }
 
-        binding = new xml_binding_t();
+    switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Binding XML Fetch Function [%s]\n",
+                      binding->getBinding().isEmpty() ? "all" : binding->getBinding().toAscii().constData());
+    switch_xml_bind_search_function(xml_url_fetch, switch_xml_parse_section_string(binding->getBinding().toAscii().constData()), binding);
+    binding = NULL;
 
-        if (!bind_mask->isEmpty()) {
-                binding->bindings = bind_mask;
-        }
-
-
-        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Binding XML Fetch Function [%s]\n",
-                          binding->bindings->isEmpty() ? "all" : binding->bindings->toAscii().constData());
-        switch_xml_bind_search_function(xml_url_fetch, switch_xml_parse_section_string(binding->bindings->toAscii().constData()), binding);
-        binding = NULL;
-
-        switch_xml_free(xml);
-        return SWITCH_STATUS_SUCCESS;
+    switch_xml_free(xml);
+    return SWITCH_STATUS_SUCCESS;
 }
 
 SWITCH_MODULE_LOAD_FUNCTION(mod_qsettings_load)
 {
-        /*switch_api_interface_t *qsettings_api_interface;*/
+    /*switch_api_interface_t *qsettings_api_interface;*/
 
-	/* connect my internal structure to the blank pointer passed to me */
-        *module_interface = switch_loadable_module_create_module_interface(pool, "mod_qsettings");
+    /* connect my internal structure to the blank pointer passed to me */
+    *module_interface = switch_loadable_module_create_module_interface(pool, "mod_qsettings");
 
-	memset(&globals,0,sizeof(globals));
-	globals.pool = pool;
+    memset(&globals,0,sizeof(globals));
+    globals.pool = pool;
 
-        if (do_config() == SWITCH_STATUS_SUCCESS) {
-                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Sucessfully configured.\n");
-	} else {
-		return SWITCH_STATUS_FALSE;
-	}
+    if (do_config() == SWITCH_STATUS_SUCCESS) {
+        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Sucessfully configured.\n");
+    } else {
+        return SWITCH_STATUS_FALSE;
+    }
 
 
-        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "We loaded mod_qsettings.\n");
-	/* indicate that the module should continue to be loaded */
-	return SWITCH_STATUS_SUCCESS;
+    switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "We loaded mod_qsettings.\n");
+    /* indicate that the module should continue to be loaded */
+    return SWITCH_STATUS_SUCCESS;
 }
 
 SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_qsettings_shutdown)
 {
-	switch_xml_unbind_search_function_ptr(xml_url_fetch);
-	return SWITCH_STATUS_SUCCESS;
+    switch_xml_unbind_search_function_ptr(xml_url_fetch);
+    return SWITCH_STATUS_SUCCESS;
 }

Modified: freeswitch/trunk/contrib/jmesquita/FSPhone/mod_qsettings/mod_qsettings.h (16131 => 16132)


--- freeswitch/trunk/contrib/jmesquita/FSPhone/mod_qsettings/mod_qsettings.h	2010-01-03 23:36:24 UTC (rev 16131)
+++ freeswitch/trunk/contrib/jmesquita/FSPhone/mod_qsettings/mod_qsettings.h	2010-01-04 04:31:29 UTC (rev 16132)
@@ -30,9 +30,22 @@
 #ifndef MOD_QSETTINGS_H
 #define MOD_QSETTINGS_H
 
+#include <QString>
+#include <QSettings>
 #include <switch.h>
 
 SWITCH_MODULE_LOAD_FUNCTION(mod_qsettings_load);
 SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_qsettings_shutdown);
 
+class XMLBinding
+{
+public:
+    XMLBinding(QString binding) : _binding(binding), _settings(new QSettings) {}
+    QString getBinding(void) { return _binding; }
+    switch_xml_t getConfigXML(QString);
+private:
+    QString _binding;
+    QSettings* _settings;
+};
+
 #endif // MOD_QSETTINGS_H

Modified: freeswitch/trunk/contrib/jmesquita/FSPhone/resources.qrc (16131 => 16132)


--- freeswitch/trunk/contrib/jmesquita/FSPhone/resources.qrc	2010-01-03 23:36:24 UTC (rev 16131)
+++ freeswitch/trunk/contrib/jmesquita/FSPhone/resources.qrc	2010-01-04 04:31:29 UTC (rev 16132)
@@ -5,5 +5,6 @@
     <qresource prefix="/confs">
         <file alias="freeswitch.xml">conf/freeswitch.xml</file>
         <file alias="example.xml">conf/accounts/example.xml</file>
+        <file alias="event_socket.conf.xml">conf/event_socket.conf.xml</file>
     </qresource>
 </RCC>