Index: mythsettings/mythsettings.pro
===================================================================
--- mythsettings/mythsettings.pro	(revision 0)
+++ mythsettings/mythsettings.pro	(revision 0)
@@ -0,0 +1,19 @@
+include ( ../../config.mak )
+include ( ../../settings.pro )
+include ( ../programs-libs.pro )
+
+QT += network xml sql qt3support
+
+TEMPLATE = app
+CONFIG += thread
+CONFIG -= moc
+TARGET = mythsettings
+target.path = $${PREFIX}/bin
+INSTALLS = target
+
+QMAKE_CLEAN += $(TARGET)
+
+# Input
+
+HEADERS += settemplate.h
+SOURCES += main.cpp settemplate.cpp
Index: mythsettings/main.cpp
===================================================================
--- mythsettings/main.cpp	(revision 0)
+++ mythsettings/main.cpp	(revision 0)
@@ -0,0 +1,160 @@
+// C headers
+#include <unistd.h>
+
+// C++ headers
+#include <iostream>
+using namespace std;
+
+// Qt headers
+#include <QApplication>
+
+// libmyth headers
+#include "exitcodes.h"
+#include "mythcontext.h"
+#include "mythdb.h"
+#include "mythverbose.h"
+#include "mythversion.h"
+#include "settemplate.h"
+
+
+
+int main(int argc, char *argv[])
+{
+    QApplication a(argc, argv, false);
+    QString templateop="";
+    QString templatename="";
+    QString templatehostname="";
+    QStringList template_c_line;
+    int argpos = 1;
+    if ( a.argc() <=1 )
+    {
+    cerr << "Missing argument, run -h to see the help \n";
+    return 3;
+    };
+
+
+    while (argpos < a.argc())
+    {
+    if (!strcmp(a.argv()[argpos],"-t"))
+        {
+            if (a.argc()-1 > argpos)
+            {
+                QString tmpArg = a.argv()[argpos+1];
+                if (tmpArg.startsWith("-"))
+                {
+                    cerr << "Invalid or missing argument to -t \n";
+                    return 3;
+                }
+                else
+                {
+                    templatename=tmpArg;
+                    //++argpos;
+                }
+                ++argpos;
+                }
+        }
+        else if (!strcmp(a.argv()[argpos], "-o"))
+        {
+            if (a.argc()-1 > argpos)
+            {
+                QString tmpArg = a.argv()[argpos+1];
+                if (tmpArg.startsWith("-"))
+                {
+                    cerr << "Invalid or missing argument to -o \n";
+                    return 3;
+                }
+                else
+                {
+                    templateop=tmpArg;
+                }
+                ++argpos;
+                }
+
+        }
+        else if (!strcmp(a.argv()[argpos], "-n"))
+        {
+            if (a.argc()-1 > argpos)
+            {
+                QString tmpArg = a.argv()[argpos+1];
+                if (tmpArg.startsWith("-"))
+                {
+                    cerr << "Invalid or missing argument to -n \n";
+                    return 3;
+                }
+                else
+                {
+                    templatehostname=tmpArg;
+                }
+                ++argpos;
+                }
+        }
+
+        else if (!strcmp(a.argv()[argpos], "-h") ||
+                !strcmp(a.argv()[argpos], "--help"))
+        {
+            VERBOSE(VB_IMPORTANT, "-o [save|restore|copy_from|delete]");
+            VERBOSE(VB_IMPORTANT, "-t [Default|Default_1|user1|user2]");
+            VERBOSE(VB_IMPORTANT, "-n  hostname to copy_from (optional)");
+            return 3;
+        }
+        else
+        {
+            fprintf(stderr, "illegal option: '%s' (use --help)\n",
+                    a.argv()[argpos]);
+            return 3;
+        }
+
+        ++argpos;
+    }
+    VERBOSE(VB_IMPORTANT, "Using template:" +  templatename);
+    VERBOSE(VB_IMPORTANT, "Using Operation:" +  templateop);
+    if  ( templateop == "copy_from" )
+        VERBOSE(VB_IMPORTANT, "Copy from host:" +  templatehostname);
+
+    gContext = NULL;
+    gContext = new MythContext(MYTH_BINARY_VERSION);
+    if (!gContext->Init(false))
+    {
+        VERBOSE(VB_IMPORTANT, "Failed to init MythContext, exiting.");
+        delete gContext;
+        return FILLDB_EXIT_NO_MYTHCONTEXT;
+    }
+
+    if (!MSqlQuery::testDBConnection())
+    {
+        VERBOSE(VB_IMPORTANT, "Could not open the database. "
+                        "Exiting.");
+        return -1;
+    }
+
+    if ( templateop == "save" )
+    {
+        savesettings(templatehostname,templatename);
+    }
+
+    if ( templateop == "restore" )
+    {
+        if ( templatename == "Default" )
+            c_from("Default" , templatename);
+        else if ( templatename == "Default_1")
+            c_from ("Default_1" , templatename );
+        else
+            restoresettings(templatehostname,templatename);
+    }
+
+    if ( templateop == "delete" )
+        deletesettings(templatehostname,templatename);
+
+    if ( templateop == "copy_from" )
+    {
+        if ( templatename=="")
+            templatename="current";
+        c_from(templatehostname,templatename);
+    }
+
+    delete gContext;
+    VERBOSE(VB_IMPORTANT, "settings op " + templateop + " " + templatename + " run complete.");
+    return 0;
+}
+
+/* vim: set expandtab tabstop=4 shiftwidth=4: */
Index: mythsettings/settemplate.cpp
===================================================================
--- mythsettings/settemplate.cpp	(revision 0)
+++ mythsettings/settemplate.cpp	(revision 0)
@@ -0,0 +1,304 @@
+#include "exitcodes.h"
+#include "mythcontext.h"
+#include "mythdb.h"
+#include "mythverbose.h"
+#include "mythversion.h"
+#include "settemplate.h"
+
+void create_temp_table (QString create_table_name,QString like_name)
+{
+MSqlQuery query(MSqlQuery::InitCon());
+query.prepare("create table " +  create_table_name + " like  " +   like_name + ";" );
+    query.exec();
+    if ( like_name == "settings")
+    {
+        query.prepare("Alter table  " + create_table_name +  " add unique ( value ) ; " );
+        query.exec();
+    }
+    query.prepare(" truncate " + create_table_name + ";" );
+    query.exec();
+};
+
+void create_new_table (QString create_table_name,QString like_name)
+{
+    //should check for table before blindly creating it.
+MSqlQuery query(MSqlQuery::InitCon());
+query.prepare("create table " +  create_table_name + " like  " +   like_name + ";" );
+query.exec();
+};
+
+
+void drop_temp_table (QString tname)
+{
+    MSqlQuery query(MSqlQuery::InitCon());
+    query.prepare("drop table " +  tname + ";" );
+    query.exec();
+}
+
+
+
+
+void savesettings (QString hname ,QString templatenumber )
+{
+    QString thname;
+    if (hname=="")
+        thname=gContext->GetHostName();
+    else
+        thname=hname;
+    VERBOSE(VB_IMPORTANT, "Saving..." + templatenumber);
+    QString templatename = "settings_" + templatenumber ;
+    create_new_table(templatename,"settings");
+    VERBOSE(VB_IMPORTANT, thname );
+    // Remove old saved values
+    MSqlQuery query(MSqlQuery::InitCon());
+    query.prepare( "delete from "  + templatename +  " where hostname=:HOSTNAME   ;"  );
+    query.bindValue( ":HOSTNAME" ,   thname  );
+    query.exec();
+    //insert all new settings
+    query.prepare( "replace into "  + templatename +  " (select * from settings where hostname=:HOSTNAME  ) ;"  ) ;
+    query.bindValue( ":HOSTNAME" ,   thname );
+    query.exec();
+
+    // repeat for keybindings
+    templatename = "keybindings_" + templatenumber ;
+    create_new_table(templatename,"keybindings");
+    query.prepare( "delete from "  + templatename +  " where hostname=:HOSTNAME   ;"  );
+    query.bindValue( ":HOSTNAME" ,   thname  );
+    query.exec();
+
+    query.prepare( "replace into "  + templatename +  " (select * from keybindings  where hostname=:HOSTNAME  ) ;"  );
+    query.bindValue( ":HOSTNAME" ,   thname  );
+    query.exec();
+}
+
+void restoresettings (QString hname, QString templatenumber )
+{
+    QString thname;
+    if ( hname=="")
+        thname=gContext->GetHostName();
+    else
+        thname=hname;
+
+    VERBOSE(VB_IMPORTANT, "Restore..." + templatenumber + " " + thname);
+    if ( settings_check ( templatenumber , thname ) )
+    {
+    // DEFAULT settings are handled by the copy from routine
+        MSqlQuery query(MSqlQuery::InitCon());
+        QStringList tablelist ;
+        QStringList::Iterator it;
+        QString current_table;
+        tablelist.append ("settings");
+        tablelist.append ("keybindings");
+        QString templatename;
+        for ( it = tablelist.begin(); it != tablelist.end(); ++it )
+        {
+            current_table = *it ;
+            //find template table to use
+            QString templatename =  current_table + "_" + templatenumber ;
+            QString temptable="temp_table_" + current_table + "_" +   thname ;
+
+            // create temp table for merging settings,  The merge is needed to accoutn for any new settings.
+            create_temp_table(temptable, current_table );
+
+            // copy in current settings
+            query.prepare( "replace into  " + temptable + "  (select * from  " + current_table + "  where hostname=:HOSTNAME ) ; "  );
+            query.bindValue( ":HOSTNAME" ,  thname  );
+            query.exec();
+
+            // copy in stored settings
+            query.prepare( "replace into  " + temptable + "  (select * from  " + templatename + "  where hostname=:HOSTNAME ) ; "  );
+            query.bindValue( ":HOSTNAME" ,   thname  );
+            query.exec();
+
+            // remove current settings.  Need to remove because the old table allows for duplicates and replace into doesn' seem to "replace"
+            query.prepare( "delete from " + current_table + "  where hostname=:HOSTNAME ;"  );
+            query.bindValue( ":HOSTNAME" ,   thname  );
+            query.exec();
+
+            // copy new settings from temp to current
+            query.prepare( "replace into " + current_table  + "   (select * from  " + temptable + "  );"  );
+            query.exec();
+
+            // drop temptable
+            drop_temp_table(temptable);
+
+        }
+    }
+};
+
+void deletesettings(QString deletehost , QString templatenumber)
+{
+    int tempItem;
+    QString dhostname;
+    if ( deletehost == "" )
+        dhostname =  (gContext->GetHostName());
+    else
+        dhostname = deletehost;
+
+    VERBOSE(VB_IMPORTANT, "Deleteing..." + templatenumber);
+    QString templatename = "settings_" + templatenumber ;
+    // Remove old saved values
+    MSqlQuery query(MSqlQuery::InitCon());
+    query.prepare( "delete from "  + templatename +  " where hostname=:HOSTNAME   ;"  );
+    query.bindValue( ":HOSTNAME" ,   dhostname  );
+    query.exec();
+    //check if ok to delete table
+    query.prepare( "select count(*) from "  + templatename + ";"  );
+    if (query.exec() && query.isActive() && query.size() > 0)
+    {
+        query.next();
+        tempItem = query.value(0).toInt();
+        if (  tempItem == 0 )
+            drop_temp_table(templatename);
+    }
+
+    // repeat for keybindings
+    templatename = "keybindings_" + templatenumber ;
+    query.prepare( "delete from "  + templatename +  " where hostname=:HOSTNAME   ;"  );
+    query.bindValue( ":HOSTNAME" ,   dhostname  );
+    query.exec();
+    //check if ok to delete table
+    query.prepare( "select count(*) from "  + templatename + ";"  );
+    if (query.exec() && query.isActive() && query.size() > 0)
+    {
+        query.next();
+        tempItem = query.value(0).toInt();
+        if (  tempItem == 0 )
+            drop_temp_table(templatename);
+    }
+}
+
+
+
+void c_from(QString copyhost, QString templatenumber)
+{
+    VERBOSE(VB_IMPORTANT, "Copy " + copyhost + " " + templatenumber );
+
+    if ( settings_check ( templatenumber , copyhost ) || templatenumber == "Current" || templatenumber == "Default" || templatenumber == "Default_1"  )
+    {
+        MSqlQuery query(MSqlQuery::InitCon());
+        //Create temp table, copy in settings from host_template, update hostname for new host,copy temp_table to settings.
+        QStringList tablelist ;
+        QStringList::Iterator it;
+        QString current_table ;
+        tablelist.append ("settings");
+        tablelist.append ("keybindings");
+        QString templatename;
+        QString temptable;
+        QString sub_sql;
+        for ( it = tablelist.begin(); it != tablelist.end(); ++it )
+        {
+            current_table = *it ;
+            VERBOSE(VB_IMPORTANT, current_table );
+            //find template table to use
+            if  ( templatenumber == "Current" )
+                templatename =  current_table ;
+            else if ( templatenumber == "Default_1")
+                templatename = current_table + "_" + "Default" ;
+            else
+                templatename =  current_table + "_" + templatenumber ;
+
+            temptable="temp_table_" + current_table + "_" +   gContext->GetHostName() ;
+            // create temp table for merging settings
+            create_temp_table(temptable, current_table );
+            VERBOSE(VB_IMPORTANT, temptable + " " + current_table);
+            //copy current settings from  this host  into temptable minus all Mythvantage settings
+            if ( current_table == "settings")
+            {
+                query.prepare( "replace into  " + temptable + "    (select * from  " + current_table + "  where                       hostname=:HOSTNAME and value not like 'HOST%'  ) ; "  );
+                query.bindValue( ":HOSTNAME" ,   gContext->GetHostName()  );
+            }
+            else
+            {
+                query.prepare( "replace into  " + temptable + "    (select * from  " + current_table + " where        hostname=:HOSTNAME ) ; "  );
+                query.bindValue( ":HOSTNAME" ,   gContext->GetHostName()  );
+            }
+            query.exec();
+
+    // update hostname to match whatever the hostname of the template is
+            query.prepare ("update " + temptable + "  set hostname=:HOSTNAME ; " );
+            query.bindValue( ":HOSTNAME" ,  copyhost  );
+            query.exec();
+
+        // copy current settings from copy host  into temptable minus all Mythvantage settings
+            if ( current_table == "settings")
+                query.prepare( "replace into  " + temptable + "    (select * from  " + templatename  + "  where hostname=:HOSTNAME and value not like 'HOST%'  ) ; "  );
+            else
+                query.prepare( "replace into  " + temptable + "    (select * from  " + templatename  + "  where hostname=:HOSTNAME  ) ; "  );
+            query.bindValue( ":HOSTNAME" ,  copyhost  );
+            query.exec();
+
+        //update hostname to match current
+            query.prepare ("update " + temptable + "  set hostname=:HOSTNAME ; " );
+            query.bindValue( ":HOSTNAME" ,   gContext->GetHostName()  );
+            query.exec();
+
+        // delete old settings from settings table
+            if ( current_table == "settings")
+            {
+                query.prepare( "delete from " + current_table + "   where hostname=:HOSTNAME and value not like 'HOST%' ;"  );
+                query.bindValue( ":HOSTNAME" ,   gContext->GetHostName()  );
+            }
+            else
+            {
+                query.prepare( "delete from " + current_table + "   where hostname=:HOSTNAME ;"  );
+                query.bindValue( ":HOSTNAME" ,   gContext->GetHostName()  );
+            }
+            query.exec();
+
+            // copy settings from temptable to settings
+            if ( current_table == "settings")
+                query.prepare( "replace into " + current_table + "   (select * from  " + temptable + " where value not like 'HOST% ' ) ;"  );
+            else
+                query.prepare( "replace into " + current_table + "   (select * from  " + temptable + " );"  );
+
+            query.exec();
+        drop_temp_table(temptable);
+        };
+    };
+};
+
+bool settings_check (QString tname , QString hname)
+{
+    int tempItem;
+    bool returncode = FALSE ;
+    QString real_tname;
+    if ( tname != "settings" )
+        real_tname="settings_"+tname;
+
+    QString thname;
+    if ( hname == "" )
+        thname= gContext->GetHostName();
+    else
+        thname = hname;
+
+    QString sub_sql;
+    MSqlQuery query(MSqlQuery::InitCon());
+    sub_sql="SELECT count(data) from ";
+    sub_sql+=real_tname;
+    sub_sql+=" where hostname=:HOSTNAME ;";
+    query.prepare(sub_sql);
+    query.bindValue( ":HOSTNAME" , thname );
+
+
+    if (query.exec() && query.isActive() && query.size() > 0)
+    {
+        while (query.next())
+        {
+            tempItem = query.value(0).toInt();
+            if (  tempItem >= 5 )
+                returncode = TRUE;
+            else
+                VERBOSE(VB_IMPORTANT,tname + " Group does not contain valid settings for " + thname);
+
+
+        }
+    }
+    else
+        VERBOSE(VB_IMPORTANT,"Couldn't find " + real_tname );
+    return returncode;
+
+}
+
+
+
Index: mythsettings/settemplate.h
===================================================================
--- mythsettings/settemplate.h	(revision 0)
+++ mythsettings/settemplate.h	(revision 0)
@@ -0,0 +1,5 @@
+void savesettings(QString,QString);
+void restoresettings(QString,QString);
+void deletesettings(QString,QString);
+void c_from(QString,QString="Current" );
+bool settings_check (QString,QString);
\ No newline at end of file
Index: mythfrontend/util_menu.xml
===================================================================
--- mythfrontend/util_menu.xml	(revision 19405)
+++ mythfrontend/util_menu.xml	(working copy)
@@ -23,7 +23,7 @@
       <text lang="PL">Narzędzia muzyczne</text>
       <text lang="HE">כלי מוסיקה</text>
       <action>PLUGIN mythmusic</action>
-      <depends>mythmusic</depends>	
+      <depends>mythmusic</depends>
    </button>
 
    <button>
@@ -52,7 +52,7 @@
       <action>JUMP Video Manager</action>
       <depends>mythvideo</depends>
    </button>
-    
+
    <button>
       <type>SETUP_KEYS</type>
       <text>Edit Keys</text>
@@ -74,9 +74,9 @@
       <text lang="PL">Edytuj klawisze</text>
       <text lang="HE">עריכת מקשים</text>
       <action>PLUGIN mythcontrols</action>
-      <depends>mythcontrols</depends>	
+      <depends>mythcontrols</depends>
    </button>
-      
+
    <button>
       <type>SETUP_MENU</type>
       <text>Setup</text>
@@ -103,4 +103,9 @@
       <action>MENU main_settings.xml</action>
    </button>
 
+   <button>
+       <type>MENU_UTILITIES_SETUP</type>
+       <text>Save or Restore settings</text>
+       <action>settings_profile</action>
+   </button>
 </mythmenu>
Index: mythfrontend/main.cpp
===================================================================
--- mythfrontend/main.cpp	(revision 19405)
+++ mythfrontend/main.cpp	(working copy)
@@ -60,6 +60,7 @@
 #include "mythappearance.h"
 #include "mythuihelper.h"
 #include "mythdirs.h"
+#include "settings_template.h"
 
 static ExitPrompter   *exitPopup = NULL;
 static MythThemedMenu *menu;
@@ -466,7 +467,26 @@
         showStatus();
     else if (sel == "exiting_app")
         handleExit();
+    else if (sel == "settings_profile")
+    {
+        gContext->ActivateSettingsCache(false);
+        MythCtemplate *setting =  new MythCtemplate();
+        DialogCode res = setting->exec();
+        delete setting;
 
+        if (kDialogCodeRejected != res)
+        {
+            if ( gContext->GetSetting("HOSTrestartfe") == "1" )
+            {
+                qApp->processEvents();
+                GetMythMainWindow()->JumpTo("Reload Theme");
+                RemoteSendMessage("CLEAR_SETTINGS_CACHE");
+                gContext->SaveSetting("HOSTrestartfe","0" );
+            }
+        }
+        gContext->ActivateSettingsCache(true);
+    }
+
     if (sel.left(9) == "settings ")
     {
         gContext->removeCurrentLocation();
Index: mythfrontend/mainmenu.xml
===================================================================
--- mythfrontend/mainmenu.xml	(revision 19405)
+++ mythfrontend/mainmenu.xml	(working copy)
@@ -34,7 +34,7 @@
      <text lang="DE">Mediathek</text>
      <text lang="FR">Médiathèque</text>
      <text lang="IS">Margmiðlunarsafn</text>
-     <text lang="NL">Mediatheek</text>     
+     <text lang="NL">Mediatheek</text>
      <text lang="SV">Mediabibliotek</text>
      <text lang="JA">メディアライブラリ</text>
      <text lang="FI">Mediakirjasto</text>
@@ -57,7 +57,7 @@
      <alttext lang="AR">المكتبة</alttext>
      <action>MENU library.xml</action>
    </button>
-   
+
     <button>
       <type>MENU_MANAGE_RECORDINGS</type>
       <text>Manage Recordings</text>
Index: mythfrontend/mythfrontend.pro
===================================================================
--- mythfrontend/mythfrontend.pro	(revision 19405)
+++ mythfrontend/mythfrontend.pro	(working copy)
@@ -11,6 +11,8 @@
 target.path = $${PREFIX}/bin
 INSTALLS = target
 
+INCLUDEPATH += ../
+
 setting.path = $${PREFIX}/share/mythtv/
 setting.files += theme.txt mysql.txt
 setting.files += info_menu.xml mainmenu.xml media_settings.xml tv_schedule.xml
@@ -30,14 +32,17 @@
 HEADERS += statusbox.h networkcontrol.h custompriority.h
 HEADERS += mediarenderer.h mythfexml.h
 HEADERS += mythappearance.h exitprompt.h
+HEADERS += settings_template.h ../mythsettings/settemplate.h
 
 SOURCES += main.cpp playbackbox.cpp viewscheduled.cpp
-SOURCES += globalsettings.cpp manualschedule.cpp programrecpriority.cpp 
+SOURCES += globalsettings.cpp manualschedule.cpp programrecpriority.cpp
 SOURCES += channelrecpriority.cpp statusbox.cpp networkcontrol.cpp
 SOURCES += mediarenderer.cpp mythfexml.cpp
 SOURCES += custompriority.cpp
 SOURCES += mythappearance.cpp exitprompt.cpp
+SOURCES += settings_template.cpp ../mythsettings/settemplate.cpp
 
+
 macx {
     mac_bundle {
         CONFIG -= console  # Force behaviour of producing .app bundle
Index: mythfrontend/settings_template.h
===================================================================
--- mythfrontend/settings_template.h	(revision 0)
+++ mythfrontend/settings_template.h	(revision 0)
@@ -0,0 +1,46 @@
+#include <settings.h>
+#include "mythdialogs.h"
+
+
+
+class TemplateSettings: public TriggeredConfigurationGroup {
+Q_OBJECT
+public:
+    TemplateSettings();
+    HostComboBox *HOSTtemplatetype;
+    HostComboBox *HostTemplateSave;
+    HostComboBox *HostTemplateRestore;
+    HostComboBox *HostSelectcopy_from;
+    HostComboBox *HostTemplateCopy_restore;
+    HostComboBox *HostTemplateDelete;
+    void fillHOSTtemplatetype();
+    void fillHostTemplateSave();
+    void fillHostTemplateRestore();
+    void fillHostSelectcopy_from();
+    void fillHostTemplateCopy_restore();
+    void fillHostTemplateDelete();
+    void remove_deleted_item(QString);
+
+public slots:
+    void choosetemplate();
+    QString gather_setting(QString);
+};
+
+
+class ProfileSettings_MainFrame: public VerticalConfigurationGroup {
+Q_OBJECT
+public:
+         ProfileSettings_MainFrame();
+         TransButtonSetting *userapplyButton;
+};
+
+
+
+
+class MythCtemplate: public ConfigurationWizard {
+public:
+    MythCtemplate();
+   // TransButtonSetting *userapplyButton;
+};
+
+

Property changes on: mythfrontend/settings_template.h
___________________________________________________________________
Name: svn:executable
   + *

Index: mythfrontend/settings_template.cpp
===================================================================
--- mythfrontend/settings_template.cpp	(revision 0)
+++ mythfrontend/settings_template.cpp	(revision 0)
@@ -0,0 +1,368 @@
+#include <mythcontext.h>
+#include <unistd.h>
+#include <iostream>
+#include <fstream>
+#include <stdio.h>
+#include "settings.h"
+#include <qsqldatabase.h>
+#include <qsqlquery.h>
+#include <stdlib.h>
+#include <cstdlib>
+#include <mythtv/mythdbcon.h>
+
+#include "settings_template.h"
+#include <mythsettings/settemplate.h>
+
+
+QString TemplateSettings::gather_setting(QString QUERY)
+{
+    QString returnvalue = "" ;
+    if ( QUERY == "HOSTtemplatetype" )
+        returnvalue=HOSTtemplatetype->getValue();
+    else if ( QUERY == "HostTemplateSave")
+        returnvalue=HostTemplateSave->getValue();
+    else if ( QUERY == "HostTemplateRestore")
+        returnvalue=HostTemplateRestore->getValue();
+    else if ( QUERY == "HostSelectcopy_from")
+        returnvalue=HostSelectcopy_from->getValue();
+    else if ( QUERY == "HostTemplateCopy_restore")
+        returnvalue=HostTemplateCopy_restore->getValue();
+    else if ( QUERY == "HostTemplateDelete")
+        returnvalue=HostTemplateDelete->getValue();
+    return returnvalue;
+}
+
+void TemplateSettings::fillHOSTtemplatetype()
+{
+    HOSTtemplatetype->setLabel(QObject::tr("Settings options"));
+    HOSTtemplatetype->addSelection("Restore");
+    HOSTtemplatetype->addSelection("Save") ;
+    HOSTtemplatetype->addSelection("Copy From");
+    HOSTtemplatetype->addSelection("Delete");
+    HOSTtemplatetype->setHelpText(QObject::tr("Select the command to run."));
+}
+
+void TemplateSettings::fillHostTemplateSave()
+{
+    HostTemplateSave->setLabel(QObject::tr("Save Template"));
+    HostTemplateSave->addSelection("user1") ;
+    HostTemplateSave->addSelection("user2") ;
+    HostTemplateSave->setHelpText(QObject::tr("Save settings under this name"));
+    MSqlQuery query(MSqlQuery::InitCon());
+    QString tempItem;
+    query.prepare( "show tables like \"settings_%\" " );
+    if (query.exec() && query.isActive() && query.size() > 0)
+    {
+        while (query.next())
+        {
+            tempItem = query.value(0).toString();
+            tempItem=tempItem.remove(QRegExp("settings_"));
+            HostTemplateSave->addSelection(tempItem);
+            VERBOSE(VB_IMPORTANT, "Adding " + tempItem + "to save list");
+        }
+    }
+}
+
+void TemplateSettings::fillHostTemplateRestore()
+{
+    HostTemplateRestore->setLabel(QObject::tr("Restore"));
+    QString tempItem;
+    QString current_hostname =  gContext->GetHostName();
+    QString sub_sql;
+    QString returnvalue;
+    MSqlQuery query(MSqlQuery::InitCon());
+    MSqlQuery sub_query(MSqlQuery::InitCon());
+    query.prepare( "show tables like \"settings_%\" " );
+    if (query.exec() && query.isActive() && query.size() > 0)
+    {
+        while (query.next())
+        {
+            tempItem = query.value(0).toString();
+            //if found tables has settings for this hostname add the table
+            sub_sql="SELECT value from ";
+            sub_sql+=tempItem;
+            sub_sql+=" where hostname=:HOSTNAME ;";
+            sub_query.prepare(sub_sql);
+            sub_query.bindValue( ":HOSTNAME" , current_hostname );
+            if (sub_query.exec() && sub_query.isActive() && sub_query.size() > 0)
+            {
+                tempItem=tempItem.remove(QRegExp("settings_"));
+                HostTemplateRestore->addSelection(tempItem);
+                VERBOSE(VB_IMPORTANT, "Adding " + tempItem + "to restore list");
+            }
+            else
+                VERBOSE(VB_IMPORTANT, "Couldn't find settings for " + current_hostname + " in " + tempItem);
+        }
+    }
+    // check to see if default is present before adding them
+    query.prepare ("SELECT count(data) FROM settings_Default WHERE value = 'Theme' AND hostname = 'Default'");
+    if (query.exec() && query.isActive() && query.size() > 0)
+    {
+    query.next();
+    tempItem = query.value(0).toString();
+    if ( tempItem == "1" )
+        HostTemplateRestore->addSelection("Default");
+    }
+
+    query.prepare ("SELECT count(data) FROM settings_Default WHERE value = 'Theme' AND hostname = 'Default_1'");
+    if (query.exec() && query.isActive() && query.size() > 0)
+    {
+    query.next();
+    tempItem = query.value(0).toString();
+    if ( tempItem == "1" )
+        HostTemplateRestore->addSelection("Default_1");
+    }
+
+    HostTemplateRestore->setHelpText(QObject::tr("Saved settings to be restored."));
+}
+
+void TemplateSettings:: fillHostSelectcopy_from()
+{
+
+    HostSelectcopy_from->setLabel(QObject::tr("Host"));
+    QString tempItem;
+    MSqlQuery query(MSqlQuery::InitCon());
+    query.prepare( "SELECT DISTINCT hostname from settings where hostname is not null;");
+    if (query.exec() && query.isActive() && query.size() > 0)
+    {
+        while (query.next())
+        {
+            tempItem = query.value(0).toString();
+            tempItem=tempItem.remove(QRegExp("settings_"));
+            HostSelectcopy_from->addSelection(tempItem);
+        }
+    }
+    HostSelectcopy_from->setHelpText(QObject::tr("Select the host to copy settings from."));
+}
+
+
+void TemplateSettings::fillHostTemplateCopy_restore()
+{
+    QString tempItem;
+    HostTemplateCopy_restore->addSelection("Current");
+    HostTemplateCopy_restore->setLabel(QObject::tr("Restore"));
+    QString current_hostname = gContext->GetHostName();
+    MSqlQuery query(MSqlQuery::InitCon());
+    query.prepare( "show tables like \"settings_%\" " );
+    if (query.exec() && query.isActive() && query.size() > 0)
+    {
+        while (query.next())
+        {
+            tempItem = query.value(0).toString();
+            tempItem=tempItem.remove(QRegExp("settings_"));
+            if ( tempItem != "Default" )
+            {
+                HostTemplateCopy_restore->addSelection(tempItem);
+                VERBOSE(VB_IMPORTANT, "Adding " + tempItem + " to copy from  list");
+            }
+        }
+    }
+    else
+        VERBOSE(VB_IMPORTANT, "Didn't find any profiles for copy from  list");
+
+    HostTemplateCopy_restore->setHelpText(QObject::tr("Select the settings group to restore."));
+
+};
+
+void TemplateSettings::fillHostTemplateDelete()
+{
+    HostTemplateDelete->setLabel(QObject::tr("Delete Template"));
+    HostTemplateDelete->setHelpText(QObject::tr("Delete settings under this name"));
+    MSqlQuery query(MSqlQuery::InitCon());
+    QString tempItem;
+    query.prepare( "show tables like \"settings_%\" " );
+    if (query.exec() && query.isActive() && query.size() > 0)
+    {
+        while (query.next())
+        {
+            tempItem = query.value(0).toString();
+            tempItem=tempItem.remove(QRegExp("settings_"));
+            if ( tempItem != "Default" )
+            {
+                HostTemplateDelete->addSelection(tempItem);
+                VERBOSE(VB_IMPORTANT, "Adding " + tempItem + "to Delete list");
+            }
+        }
+    }
+}
+
+void TemplateSettings::remove_deleted_item(QString ditem)
+{
+
+        HostTemplateDelete->setValue(0);
+        HostTemplateDelete->removeSelection(ditem);
+        HostTemplateRestore->removeSelection(ditem);
+}
+
+
+TemplateSettings::TemplateSettings(): TriggeredConfigurationGroup(true)
+{
+    setLabel(QObject::tr("Manage Settings"));
+    HOSTtemplatetype= new HostComboBox("HOSTtemplatetype");
+    HostTemplateSave= new HostComboBox("HostTemplateSave",true);
+    HostTemplateRestore = new HostComboBox("HostTemplateRestore");
+    HostSelectcopy_from = new HostComboBox("HostSelectcopy_from");
+    HostTemplateCopy_restore = new HostComboBox("HostTemplateCopy_restore");
+    HostTemplateDelete = new HostComboBox("HostTemplateDelete");
+
+    fillHOSTtemplatetype();
+    fillHostTemplateSave();
+    fillHostTemplateRestore();
+    fillHostSelectcopy_from();
+    fillHostTemplateCopy_restore();
+    fillHostTemplateDelete();
+
+    Setting* Mtemplate = HOSTtemplatetype;
+    addChild(Mtemplate);
+    setTrigger(Mtemplate);
+
+    ConfigurationGroup* trestore = new VerticalConfigurationGroup(false);
+        trestore->addChild(HostTemplateRestore);
+
+
+    ConfigurationGroup* tsave = new VerticalConfigurationGroup(false);
+        tsave->addChild(HostTemplateSave);
+
+    ConfigurationGroup* tcopy = new VerticalConfigurationGroup(false);
+        tcopy->addChild(HostSelectcopy_from);
+        tcopy->addChild(HostTemplateCopy_restore);
+
+    ConfigurationGroup* tdelete = new VerticalConfigurationGroup(false);
+        tdelete->addChild(HostTemplateDelete);
+
+//    addTarget("Do Nothing", new VerticalConfigurationGroup(true));
+    addTarget("Restore", trestore);
+    addTarget("Save", tsave);
+    addTarget("Copy From", tcopy);
+    addTarget("Delete", tdelete);
+
+};
+
+void popup_error(){
+
+    QString errorText="Could not find any settings to restore.";
+    MythPopupBox::showOkPopup(gContext->GetMainWindow(),
+                "Open Failed",
+                    errorText);
+
+}
+
+void TemplateSettings::choosetemplate ()
+{
+    QString templateop;
+    QString templatename;
+    QString templatehostname="";
+    templateop=gather_setting("HOSTtemplatetype");
+    VERBOSE(VB_IMPORTANT, "Button was pressed... " + templateop);
+    VERBOSE(VB_IMPORTANT, "####################################");
+    templatename = "none";
+
+    if ( templateop == "Save" )
+    {
+        templatename=gather_setting("HostTemplateSave");
+        templatehostname=gContext->GetHostName();
+        VERBOSE(VB_IMPORTANT, "FE----RUNNING... ...." + templateop + "  " + templatename );
+        savesettings(templatehostname,templatename);
+    }
+    else if ( templateop == "Restore" )
+    {
+        //Run Check to see if settings are present
+        templatename=gather_setting("HostTemplateRestore");
+
+        VERBOSE(VB_IMPORTANT, "FE----RUNNING... " + templateop + "  " + templatename );
+        if ( templatename == "Default")
+        {
+            if ( settings_check(templatename,"Default") )
+            {
+                VERBOSE(VB_IMPORTANT, "FE----RUNNING... c_from  " + templateop + "  " + templatename );
+                c_from("Default" , "Default");
+                gContext->SaveSetting("HOSTrestartfe","1" );
+            }
+            else
+            {
+                popup_error();
+            }
+        }
+        else if ( templatename == "Default_1")
+        {
+            if ( settings_check("Default" ,"Default_1") )
+            {
+                VERBOSE(VB_IMPORTANT, "FE----RUNNING... c_from  " + templateop + "  " + templatename );
+                c_from("Default_1" , "Default" );
+                gContext->SaveSetting("HOSTrestartfe","1" );
+            }
+            else
+            {
+                popup_error();
+            }
+
+        }
+        else
+        {
+            if ( settings_check(templatename,templatehostname) )
+            {
+                restoresettings(templatehostname,templatename);
+                gContext->SaveSetting("HOSTrestartfe","1" );
+            }
+            else
+            {
+                popup_error();
+            }
+        }
+    }
+    else if ( templateop == "Copy From" )
+    {
+        templatehostname=gather_setting("HostSelectcopy_from");
+        templatename=gather_setting("HostTemplateCopy_restore");
+
+        if ( settings_check(templatename,templatehostname) )
+        {
+            gContext->SaveSetting("HOSTrestartfe","1" );
+            VERBOSE(VB_IMPORTANT, "FE----RUNNING... ...." + templateop + "  " + templatename + " " + templatehostname );
+            c_from(templatehostname,templatename);
+        }
+        else
+        {
+            popup_error();
+        }
+    }
+    else if ( templateop == "Delete" )
+    {
+        templatehostname=gContext->GetHostName();
+        templatename=gather_setting("HostTemplateDelete");
+        deletesettings(templatehostname,templatename);
+        remove_deleted_item(templatename);
+    }
+    VERBOSE(VB_IMPORTANT, "####################################");
+
+};
+
+
+
+
+ProfileSettings_MainFrame::ProfileSettings_MainFrame():
+VerticalConfigurationGroup(false,false,false,false)
+{
+    setLabel(QObject::tr("Save/Backup settings"));
+    TemplateSettings *templatesettings = new TemplateSettings();
+
+    userapplyButton = new TransButtonSetting;
+    userapplyButton->setLabel("Run");
+
+    VerticalConfigurationGroup* frame_profile = new VerticalConfigurationGroup(false, true,false,false);
+    frame_profile->addChild(templatesettings);
+    frame_profile->addChild(userapplyButton);
+
+    addChild(frame_profile);
+    connect(userapplyButton, SIGNAL(pressed()),templatesettings,SLOT(choosetemplate()));
+};
+
+
+MythCtemplate::MythCtemplate()
+{
+    ProfileSettings_MainFrame *profilesettings_mainframe = new ProfileSettings_MainFrame();
+    addChild(profilesettings_mainframe);
+};
+
+
+

Property changes on: mythfrontend/settings_template.cpp
___________________________________________________________________
Name: svn:executable
   + *

Index: programs.pro
===================================================================
--- programs.pro	(revision 19405)
+++ programs.pro	(working copy)
@@ -8,6 +8,7 @@
     SUBDIRS += mythtv mythfrontend mythcommflag
     SUBDIRS += mythtvosd mythjobqueue mythlcdserver
     SUBDIRS += mythwelcome mythshutdown mythtranscode/replex
+    SUBDIRS += mythsettings
 }
 
 using_backend {

