Ticket #6064: mythsettings.patch

File mythsettings.patch, 36.1 KB (added by anonymous, 15 years ago)
Line 
1Index: mythsettings/mythsettings.pro
2===================================================================
3--- mythsettings/mythsettings.pro       (revision 0)
4+++ mythsettings/mythsettings.pro       (revision 0)
5@@ -0,0 +1,19 @@
6+include ( ../../config.mak )
7+include ( ../../settings.pro )
8+include ( ../programs-libs.pro )
9+
10+QT += network xml sql qt3support
11+
12+TEMPLATE = app
13+CONFIG += thread
14+CONFIG -= moc
15+TARGET = mythsettings
16+target.path = $${PREFIX}/bin
17+INSTALLS = target
18+
19+QMAKE_CLEAN += $(TARGET)
20+
21+# Input
22+
23+HEADERS += settemplate.h
24+SOURCES += main.cpp settemplate.cpp
25Index: mythsettings/main.cpp
26===================================================================
27--- mythsettings/main.cpp       (revision 0)
28+++ mythsettings/main.cpp       (revision 0)
29@@ -0,0 +1,160 @@
30+// C headers
31+#include <unistd.h>
32+
33+// C++ headers
34+#include <iostream>
35+using namespace std;
36+
37+// Qt headers
38+#include <QApplication>
39+
40+// libmyth headers
41+#include "exitcodes.h"
42+#include "mythcontext.h"
43+#include "mythdb.h"
44+#include "mythverbose.h"
45+#include "mythversion.h"
46+#include "settemplate.h"
47+
48+
49+
50+int main(int argc, char *argv[])
51+{
52+    QApplication a(argc, argv, false);
53+    QString templateop="";
54+    QString templatename="";
55+    QString templatehostname="";
56+    QStringList template_c_line;
57+    int argpos = 1;
58+    if ( a.argc() <=1 )
59+    {
60+    cerr << "Missing argument, run -h to see the help \n";
61+    return 3;
62+    };
63+
64+
65+    while (argpos < a.argc())
66+    {
67+    if (!strcmp(a.argv()[argpos],"-t"))
68+        {
69+            if (a.argc()-1 > argpos)
70+            {
71+                QString tmpArg = a.argv()[argpos+1];
72+                if (tmpArg.startsWith("-"))
73+                {
74+                    cerr << "Invalid or missing argument to -t \n";
75+                    return 3;
76+                }
77+                else
78+                {
79+                    templatename=tmpArg;
80+                    //++argpos;
81+                }
82+                ++argpos;
83+                }
84+        }
85+        else if (!strcmp(a.argv()[argpos], "-o"))
86+        {
87+            if (a.argc()-1 > argpos)
88+            {
89+                QString tmpArg = a.argv()[argpos+1];
90+                if (tmpArg.startsWith("-"))
91+                {
92+                    cerr << "Invalid or missing argument to -o \n";
93+                    return 3;
94+                }
95+                else
96+                {
97+                    templateop=tmpArg;
98+                }
99+                ++argpos;
100+                }
101+
102+        }
103+        else if (!strcmp(a.argv()[argpos], "-n"))
104+        {
105+            if (a.argc()-1 > argpos)
106+            {
107+                QString tmpArg = a.argv()[argpos+1];
108+                if (tmpArg.startsWith("-"))
109+                {
110+                    cerr << "Invalid or missing argument to -n \n";
111+                    return 3;
112+                }
113+                else
114+                {
115+                    templatehostname=tmpArg;
116+                }
117+                ++argpos;
118+                }
119+        }
120+
121+        else if (!strcmp(a.argv()[argpos], "-h") ||
122+                !strcmp(a.argv()[argpos], "--help"))
123+        {
124+            VERBOSE(VB_IMPORTANT, "-o [save|restore|copy_from|delete]");
125+            VERBOSE(VB_IMPORTANT, "-t [Default|Default_1|user1|user2]");
126+            VERBOSE(VB_IMPORTANT, "-n  hostname to copy_from (optional)");
127+            return 3;
128+        }
129+        else
130+        {
131+            fprintf(stderr, "illegal option: '%s' (use --help)\n",
132+                    a.argv()[argpos]);
133+            return 3;
134+        }
135+
136+        ++argpos;
137+    }
138+    VERBOSE(VB_IMPORTANT, "Using template:" +  templatename);
139+    VERBOSE(VB_IMPORTANT, "Using Operation:" +  templateop);
140+    if  ( templateop == "copy_from" )
141+        VERBOSE(VB_IMPORTANT, "Copy from host:" +  templatehostname);
142+
143+    gContext = NULL;
144+    gContext = new MythContext(MYTH_BINARY_VERSION);
145+    if (!gContext->Init(false))
146+    {
147+        VERBOSE(VB_IMPORTANT, "Failed to init MythContext, exiting.");
148+        delete gContext;
149+        return FILLDB_EXIT_NO_MYTHCONTEXT;
150+    }
151+
152+    if (!MSqlQuery::testDBConnection())
153+    {
154+        VERBOSE(VB_IMPORTANT, "Could not open the database. "
155+                        "Exiting.");
156+        return -1;
157+    }
158+
159+    if ( templateop == "save" )
160+    {
161+        savesettings(templatehostname,templatename);
162+    }
163+
164+    if ( templateop == "restore" )
165+    {
166+        if ( templatename == "Default" )
167+            c_from("Default" , templatename);
168+        else if ( templatename == "Default_1")
169+            c_from ("Default_1" , templatename );
170+        else
171+            restoresettings(templatehostname,templatename);
172+    }
173+
174+    if ( templateop == "delete" )
175+        deletesettings(templatehostname,templatename);
176+
177+    if ( templateop == "copy_from" )
178+    {
179+        if ( templatename=="")
180+            templatename="current";
181+        c_from(templatehostname,templatename);
182+    }
183+
184+    delete gContext;
185+    VERBOSE(VB_IMPORTANT, "settings op " + templateop + " " + templatename + " run complete.");
186+    return 0;
187+}
188+
189+/* vim: set expandtab tabstop=4 shiftwidth=4: */
190Index: mythsettings/settemplate.cpp
191===================================================================
192--- mythsettings/settemplate.cpp        (revision 0)
193+++ mythsettings/settemplate.cpp        (revision 0)
194@@ -0,0 +1,304 @@
195+#include "exitcodes.h"
196+#include "mythcontext.h"
197+#include "mythdb.h"
198+#include "mythverbose.h"
199+#include "mythversion.h"
200+#include "settemplate.h"
201+
202+void create_temp_table (QString create_table_name,QString like_name)
203+{
204+MSqlQuery query(MSqlQuery::InitCon());
205+query.prepare("create table " +  create_table_name + " like  " +   like_name + ";" );
206+    query.exec();
207+    if ( like_name == "settings")
208+    {
209+        query.prepare("Alter table  " + create_table_name +  " add unique ( value ) ; " );
210+        query.exec();
211+    }
212+    query.prepare(" truncate " + create_table_name + ";" );
213+    query.exec();
214+};
215+
216+void create_new_table (QString create_table_name,QString like_name)
217+{
218+    //should check for table before blindly creating it.
219+MSqlQuery query(MSqlQuery::InitCon());
220+query.prepare("create table " +  create_table_name + " like  " +   like_name + ";" );
221+query.exec();
222+};
223+
224+
225+void drop_temp_table (QString tname)
226+{
227+    MSqlQuery query(MSqlQuery::InitCon());
228+    query.prepare("drop table " +  tname + ";" );
229+    query.exec();
230+}
231+
232+
233+
234+
235+void savesettings (QString hname ,QString templatenumber )
236+{
237+    QString thname;
238+    if (hname=="")
239+        thname=gContext->GetHostName();
240+    else
241+        thname=hname;
242+    VERBOSE(VB_IMPORTANT, "Saving..." + templatenumber);
243+    QString templatename = "settings_" + templatenumber ;
244+    create_new_table(templatename,"settings");
245+    VERBOSE(VB_IMPORTANT, thname );
246+    // Remove old saved values
247+    MSqlQuery query(MSqlQuery::InitCon());
248+    query.prepare( "delete from "  + templatename +  " where hostname=:HOSTNAME   ;"  );
249+    query.bindValue( ":HOSTNAME" ,   thname  );
250+    query.exec();
251+    //insert all new settings
252+    query.prepare( "replace into "  + templatename +  " (select * from settings where hostname=:HOSTNAME  ) ;"  ) ;
253+    query.bindValue( ":HOSTNAME" ,   thname );
254+    query.exec();
255+
256+    // repeat for keybindings
257+    templatename = "keybindings_" + templatenumber ;
258+    create_new_table(templatename,"keybindings");
259+    query.prepare( "delete from "  + templatename +  " where hostname=:HOSTNAME   ;"  );
260+    query.bindValue( ":HOSTNAME" ,   thname  );
261+    query.exec();
262+
263+    query.prepare( "replace into "  + templatename +  " (select * from keybindings  where hostname=:HOSTNAME  ) ;"  );
264+    query.bindValue( ":HOSTNAME" ,   thname  );
265+    query.exec();
266+}
267+
268+void restoresettings (QString hname, QString templatenumber )
269+{
270+    QString thname;
271+    if ( hname=="")
272+        thname=gContext->GetHostName();
273+    else
274+        thname=hname;
275+
276+    VERBOSE(VB_IMPORTANT, "Restore..." + templatenumber + " " + thname);
277+    if ( settings_check ( templatenumber , thname ) )
278+    {
279+    // DEFAULT settings are handled by the copy from routine
280+        MSqlQuery query(MSqlQuery::InitCon());
281+        QStringList tablelist ;
282+        QStringList::Iterator it;
283+        QString current_table;
284+        tablelist.append ("settings");
285+        tablelist.append ("keybindings");
286+        QString templatename;
287+        for ( it = tablelist.begin(); it != tablelist.end(); ++it )
288+        {
289+            current_table = *it ;
290+            //find template table to use
291+            QString templatename =  current_table + "_" + templatenumber ;
292+            QString temptable="temp_table_" + current_table + "_" +   thname ;
293+
294+            // create temp table for merging settings,  The merge is needed to accoutn for any new settings.
295+            create_temp_table(temptable, current_table );
296+
297+            // copy in current settings
298+            query.prepare( "replace into  " + temptable + "  (select * from  " + current_table + "  where hostname=:HOSTNAME ) ; "  );
299+            query.bindValue( ":HOSTNAME" ,  thname  );
300+            query.exec();
301+
302+            // copy in stored settings
303+            query.prepare( "replace into  " + temptable + "  (select * from  " + templatename + "  where hostname=:HOSTNAME ) ; "  );
304+            query.bindValue( ":HOSTNAME" ,   thname  );
305+            query.exec();
306+
307+            // remove current settings.  Need to remove because the old table allows for duplicates and replace into doesn' seem to "replace"
308+            query.prepare( "delete from " + current_table + "  where hostname=:HOSTNAME ;"  );
309+            query.bindValue( ":HOSTNAME" ,   thname  );
310+            query.exec();
311+
312+            // copy new settings from temp to current
313+            query.prepare( "replace into " + current_table  + "   (select * from  " + temptable + "  );"  );
314+            query.exec();
315+
316+            // drop temptable
317+            drop_temp_table(temptable);
318+
319+        }
320+    }
321+};
322+
323+void deletesettings(QString deletehost , QString templatenumber)
324+{
325+    int tempItem;
326+    QString dhostname;
327+    if ( deletehost == "" )
328+        dhostname =  (gContext->GetHostName());
329+    else
330+        dhostname = deletehost;
331+
332+    VERBOSE(VB_IMPORTANT, "Deleteing..." + templatenumber);
333+    QString templatename = "settings_" + templatenumber ;
334+    // Remove old saved values
335+    MSqlQuery query(MSqlQuery::InitCon());
336+    query.prepare( "delete from "  + templatename +  " where hostname=:HOSTNAME   ;"  );
337+    query.bindValue( ":HOSTNAME" ,   dhostname  );
338+    query.exec();
339+    //check if ok to delete table
340+    query.prepare( "select count(*) from "  + templatename + ";"  );
341+    if (query.exec() && query.isActive() && query.size() > 0)
342+    {
343+        query.next();
344+        tempItem = query.value(0).toInt();
345+        if (  tempItem == 0 )
346+            drop_temp_table(templatename);
347+    }
348+
349+    // repeat for keybindings
350+    templatename = "keybindings_" + templatenumber ;
351+    query.prepare( "delete from "  + templatename +  " where hostname=:HOSTNAME   ;"  );
352+    query.bindValue( ":HOSTNAME" ,   dhostname  );
353+    query.exec();
354+    //check if ok to delete table
355+    query.prepare( "select count(*) from "  + templatename + ";"  );
356+    if (query.exec() && query.isActive() && query.size() > 0)
357+    {
358+        query.next();
359+        tempItem = query.value(0).toInt();
360+        if (  tempItem == 0 )
361+            drop_temp_table(templatename);
362+    }
363+}
364+
365+
366+
367+void c_from(QString copyhost, QString templatenumber)
368+{
369+    VERBOSE(VB_IMPORTANT, "Copy " + copyhost + " " + templatenumber );
370+
371+    if ( settings_check ( templatenumber , copyhost ) || templatenumber == "Current" || templatenumber == "Default" || templatenumber == "Default_1"  )
372+    {
373+        MSqlQuery query(MSqlQuery::InitCon());
374+        //Create temp table, copy in settings from host_template, update hostname for new host,copy temp_table to settings.
375+        QStringList tablelist ;
376+        QStringList::Iterator it;
377+        QString current_table ;
378+        tablelist.append ("settings");
379+        tablelist.append ("keybindings");
380+        QString templatename;
381+        QString temptable;
382+        QString sub_sql;
383+        for ( it = tablelist.begin(); it != tablelist.end(); ++it )
384+        {
385+            current_table = *it ;
386+            VERBOSE(VB_IMPORTANT, current_table );
387+            //find template table to use
388+            if  ( templatenumber == "Current" )
389+                templatename =  current_table ;
390+            else if ( templatenumber == "Default_1")
391+                templatename = current_table + "_" + "Default" ;
392+            else
393+                templatename =  current_table + "_" + templatenumber ;
394+
395+            temptable="temp_table_" + current_table + "_" +   gContext->GetHostName() ;
396+            // create temp table for merging settings
397+            create_temp_table(temptable, current_table );
398+            VERBOSE(VB_IMPORTANT, temptable + " " + current_table);
399+            //copy current settings from  this host  into temptable minus all Mythvantage settings
400+            if ( current_table == "settings")
401+            {
402+                query.prepare( "replace into  " + temptable + "    (select * from  " + current_table + "  where                       hostname=:HOSTNAME and value not like 'HOST%'  ) ; "  );
403+                query.bindValue( ":HOSTNAME" ,   gContext->GetHostName()  );
404+            }
405+            else
406+            {
407+                query.prepare( "replace into  " + temptable + "    (select * from  " + current_table + " where        hostname=:HOSTNAME ) ; "  );
408+                query.bindValue( ":HOSTNAME" ,   gContext->GetHostName()  );
409+            }
410+            query.exec();
411+
412+    // update hostname to match whatever the hostname of the template is
413+            query.prepare ("update " + temptable + "  set hostname=:HOSTNAME ; " );
414+            query.bindValue( ":HOSTNAME" ,  copyhost  );
415+            query.exec();
416+
417+        // copy current settings from copy host  into temptable minus all Mythvantage settings
418+            if ( current_table == "settings")
419+                query.prepare( "replace into  " + temptable + "    (select * from  " + templatename  + "  where hostname=:HOSTNAME and value not like 'HOST%'  ) ; "  );
420+            else
421+                query.prepare( "replace into  " + temptable + "    (select * from  " + templatename  + "  where hostname=:HOSTNAME  ) ; "  );
422+            query.bindValue( ":HOSTNAME" ,  copyhost  );
423+            query.exec();
424+
425+        //update hostname to match current
426+            query.prepare ("update " + temptable + "  set hostname=:HOSTNAME ; " );
427+            query.bindValue( ":HOSTNAME" ,   gContext->GetHostName()  );
428+            query.exec();
429+
430+        // delete old settings from settings table
431+            if ( current_table == "settings")
432+            {
433+                query.prepare( "delete from " + current_table + "   where hostname=:HOSTNAME and value not like 'HOST%' ;"  );
434+                query.bindValue( ":HOSTNAME" ,   gContext->GetHostName()  );
435+            }
436+            else
437+            {
438+                query.prepare( "delete from " + current_table + "   where hostname=:HOSTNAME ;"  );
439+                query.bindValue( ":HOSTNAME" ,   gContext->GetHostName()  );
440+            }
441+            query.exec();
442+
443+            // copy settings from temptable to settings
444+            if ( current_table == "settings")
445+                query.prepare( "replace into " + current_table + "   (select * from  " + temptable + " where value not like 'HOST% ' ) ;"  );
446+            else
447+                query.prepare( "replace into " + current_table + "   (select * from  " + temptable + " );"  );
448+
449+            query.exec();
450+        drop_temp_table(temptable);
451+        };
452+    };
453+};
454+
455+bool settings_check (QString tname , QString hname)
456+{
457+    int tempItem;
458+    bool returncode = FALSE ;
459+    QString real_tname;
460+    if ( tname != "settings" )
461+        real_tname="settings_"+tname;
462+
463+    QString thname;
464+    if ( hname == "" )
465+        thname= gContext->GetHostName();
466+    else
467+        thname = hname;
468+
469+    QString sub_sql;
470+    MSqlQuery query(MSqlQuery::InitCon());
471+    sub_sql="SELECT count(data) from ";
472+    sub_sql+=real_tname;
473+    sub_sql+=" where hostname=:HOSTNAME ;";
474+    query.prepare(sub_sql);
475+    query.bindValue( ":HOSTNAME" , thname );
476+
477+
478+    if (query.exec() && query.isActive() && query.size() > 0)
479+    {
480+        while (query.next())
481+        {
482+            tempItem = query.value(0).toInt();
483+            if (  tempItem >= 5 )
484+                returncode = TRUE;
485+            else
486+                VERBOSE(VB_IMPORTANT,tname + " Group does not contain valid settings for " + thname);
487+
488+
489+        }
490+    }
491+    else
492+        VERBOSE(VB_IMPORTANT,"Couldn't find " + real_tname );
493+    return returncode;
494+
495+}
496+
497+
498+
499Index: mythsettings/settemplate.h
500===================================================================
501--- mythsettings/settemplate.h  (revision 0)
502+++ mythsettings/settemplate.h  (revision 0)
503@@ -0,0 +1,5 @@
504+void savesettings(QString,QString);
505+void restoresettings(QString,QString);
506+void deletesettings(QString,QString);
507+void c_from(QString,QString="Current" );
508+bool settings_check (QString,QString);
509\ No newline at end of file
510Index: mythfrontend/util_menu.xml
511===================================================================
512--- mythfrontend/util_menu.xml  (revision 19405)
513+++ mythfrontend/util_menu.xml  (working copy)
514@@ -23,7 +23,7 @@
515       <text lang="PL">Narzędzia muzyczne</text>
516       <text lang="HE">כלי מוסיקה</text>
517       <action>PLUGIN mythmusic</action>
518-      <depends>mythmusic</depends>     
519+      <depends>mythmusic</depends>
520    </button>
521 
522    <button>
523@@ -52,7 +52,7 @@
524       <action>JUMP Video Manager</action>
525       <depends>mythvideo</depends>
526    </button>
527-   
528+
529    <button>
530       <type>SETUP_KEYS</type>
531       <text>Edit Keys</text>
532@@ -74,9 +74,9 @@
533       <text lang="PL">Edytuj klawisze</text>
534       <text lang="HE">עךיכת מקשים</text>
535       <action>PLUGIN mythcontrols</action>
536-      <depends>mythcontrols</depends> 
537+      <depends>mythcontrols</depends>
538    </button>
539-     
540+
541    <button>
542       <type>SETUP_MENU</type>
543       <text>Setup</text>
544@@ -103,4 +103,9 @@
545       <action>MENU main_settings.xml</action>
546    </button>
547 
548+   <button>
549+       <type>MENU_UTILITIES_SETUP</type>
550+       <text>Save or Restore settings</text>
551+       <action>settings_profile</action>
552+   </button>
553 </mythmenu>
554Index: mythfrontend/main.cpp
555===================================================================
556--- mythfrontend/main.cpp       (revision 19405)
557+++ mythfrontend/main.cpp       (working copy)
558@@ -60,6 +60,7 @@
559 #include "mythappearance.h"
560 #include "mythuihelper.h"
561 #include "mythdirs.h"
562+#include "settings_template.h"
563 
564 static ExitPrompter   *exitPopup = NULL;
565 static MythThemedMenu *menu;
566@@ -466,7 +467,26 @@
567         showStatus();
568     else if (sel == "exiting_app")
569         handleExit();
570+    else if (sel == "settings_profile")
571+    {
572+        gContext->ActivateSettingsCache(false);
573+        MythCtemplate *setting =  new MythCtemplate();
574+        DialogCode res = setting->exec();
575+        delete setting;
576 
577+        if (kDialogCodeRejected != res)
578+        {
579+            if ( gContext->GetSetting("HOSTrestartfe") == "1" )
580+            {
581+                qApp->processEvents();
582+                GetMythMainWindow()->JumpTo("Reload Theme");
583+                RemoteSendMessage("CLEAR_SETTINGS_CACHE");
584+                gContext->SaveSetting("HOSTrestartfe","0" );
585+            }
586+        }
587+        gContext->ActivateSettingsCache(true);
588+    }
589+
590     if (sel.left(9) == "settings ")
591     {
592         gContext->removeCurrentLocation();
593Index: mythfrontend/mainmenu.xml
594===================================================================
595--- mythfrontend/mainmenu.xml   (revision 19405)
596+++ mythfrontend/mainmenu.xml   (working copy)
597@@ -34,7 +34,7 @@
598      <text lang="DE">Mediathek</text>
599      <text lang="FR">MédiathÚque</text>
600      <text lang="IS">Margmiðlunarsafn</text>
601-     <text lang="NL">Mediatheek</text>     
602+     <text lang="NL">Mediatheek</text>
603      <text lang="SV">Mediabibliotek</text>
604      <text lang="JA">メディアラむブラリ</text>
605      <text lang="FI">Mediakirjasto</text>
606@@ -57,7 +57,7 @@
607      <alttext lang="AR">المكتؚة</alttext>
608      <action>MENU library.xml</action>
609    </button>
610-   
611+
612     <button>
613       <type>MENU_MANAGE_RECORDINGS</type>
614       <text>Manage Recordings</text>
615Index: mythfrontend/mythfrontend.pro
616===================================================================
617--- mythfrontend/mythfrontend.pro       (revision 19405)
618+++ mythfrontend/mythfrontend.pro       (working copy)
619@@ -11,6 +11,8 @@
620 target.path = $${PREFIX}/bin
621 INSTALLS = target
622 
623+INCLUDEPATH += ../
624+
625 setting.path = $${PREFIX}/share/mythtv/
626 setting.files += theme.txt mysql.txt
627 setting.files += info_menu.xml mainmenu.xml media_settings.xml tv_schedule.xml
628@@ -30,14 +32,17 @@
629 HEADERS += statusbox.h networkcontrol.h custompriority.h
630 HEADERS += mediarenderer.h mythfexml.h
631 HEADERS += mythappearance.h exitprompt.h
632+HEADERS += settings_template.h ../mythsettings/settemplate.h
633 
634 SOURCES += main.cpp playbackbox.cpp viewscheduled.cpp
635-SOURCES += globalsettings.cpp manualschedule.cpp programrecpriority.cpp
636+SOURCES += globalsettings.cpp manualschedule.cpp programrecpriority.cpp
637 SOURCES += channelrecpriority.cpp statusbox.cpp networkcontrol.cpp
638 SOURCES += mediarenderer.cpp mythfexml.cpp
639 SOURCES += custompriority.cpp
640 SOURCES += mythappearance.cpp exitprompt.cpp
641+SOURCES += settings_template.cpp ../mythsettings/settemplate.cpp
642 
643+
644 macx {
645     mac_bundle {
646         CONFIG -= console  # Force behaviour of producing .app bundle
647Index: mythfrontend/settings_template.h
648===================================================================
649--- mythfrontend/settings_template.h    (revision 0)
650+++ mythfrontend/settings_template.h    (revision 0)
651@@ -0,0 +1,46 @@
652+#include <settings.h>
653+#include "mythdialogs.h"
654+
655+
656+
657+class TemplateSettings: public TriggeredConfigurationGroup {
658+Q_OBJECT
659+public:
660+    TemplateSettings();
661+    HostComboBox *HOSTtemplatetype;
662+    HostComboBox *HostTemplateSave;
663+    HostComboBox *HostTemplateRestore;
664+    HostComboBox *HostSelectcopy_from;
665+    HostComboBox *HostTemplateCopy_restore;
666+    HostComboBox *HostTemplateDelete;
667+    void fillHOSTtemplatetype();
668+    void fillHostTemplateSave();
669+    void fillHostTemplateRestore();
670+    void fillHostSelectcopy_from();
671+    void fillHostTemplateCopy_restore();
672+    void fillHostTemplateDelete();
673+    void remove_deleted_item(QString);
674+
675+public slots:
676+    void choosetemplate();
677+    QString gather_setting(QString);
678+};
679+
680+
681+class ProfileSettings_MainFrame: public VerticalConfigurationGroup {
682+Q_OBJECT
683+public:
684+         ProfileSettings_MainFrame();
685+         TransButtonSetting *userapplyButton;
686+};
687+
688+
689+
690+
691+class MythCtemplate: public ConfigurationWizard {
692+public:
693+    MythCtemplate();
694+   // TransButtonSetting *userapplyButton;
695+};
696+
697+
698
699Property changes on: mythfrontend/settings_template.h
700___________________________________________________________________
701Name: svn:executable
702   + *
703
704Index: mythfrontend/settings_template.cpp
705===================================================================
706--- mythfrontend/settings_template.cpp  (revision 0)
707+++ mythfrontend/settings_template.cpp  (revision 0)
708@@ -0,0 +1,368 @@
709+#include <mythcontext.h>
710+#include <unistd.h>
711+#include <iostream>
712+#include <fstream>
713+#include <stdio.h>
714+#include "settings.h"
715+#include <qsqldatabase.h>
716+#include <qsqlquery.h>
717+#include <stdlib.h>
718+#include <cstdlib>
719+#include <mythtv/mythdbcon.h>
720+
721+#include "settings_template.h"
722+#include <mythsettings/settemplate.h>
723+
724+
725+QString TemplateSettings::gather_setting(QString QUERY)
726+{
727+    QString returnvalue = "" ;
728+    if ( QUERY == "HOSTtemplatetype" )
729+        returnvalue=HOSTtemplatetype->getValue();
730+    else if ( QUERY == "HostTemplateSave")
731+        returnvalue=HostTemplateSave->getValue();
732+    else if ( QUERY == "HostTemplateRestore")
733+        returnvalue=HostTemplateRestore->getValue();
734+    else if ( QUERY == "HostSelectcopy_from")
735+        returnvalue=HostSelectcopy_from->getValue();
736+    else if ( QUERY == "HostTemplateCopy_restore")
737+        returnvalue=HostTemplateCopy_restore->getValue();
738+    else if ( QUERY == "HostTemplateDelete")
739+        returnvalue=HostTemplateDelete->getValue();
740+    return returnvalue;
741+}
742+
743+void TemplateSettings::fillHOSTtemplatetype()
744+{
745+    HOSTtemplatetype->setLabel(QObject::tr("Settings options"));
746+    HOSTtemplatetype->addSelection("Restore");
747+    HOSTtemplatetype->addSelection("Save") ;
748+    HOSTtemplatetype->addSelection("Copy From");
749+    HOSTtemplatetype->addSelection("Delete");
750+    HOSTtemplatetype->setHelpText(QObject::tr("Select the command to run."));
751+}
752+
753+void TemplateSettings::fillHostTemplateSave()
754+{
755+    HostTemplateSave->setLabel(QObject::tr("Save Template"));
756+    HostTemplateSave->addSelection("user1") ;
757+    HostTemplateSave->addSelection("user2") ;
758+    HostTemplateSave->setHelpText(QObject::tr("Save settings under this name"));
759+    MSqlQuery query(MSqlQuery::InitCon());
760+    QString tempItem;
761+    query.prepare( "show tables like \"settings_%\" " );
762+    if (query.exec() && query.isActive() && query.size() > 0)
763+    {
764+        while (query.next())
765+        {
766+            tempItem = query.value(0).toString();
767+            tempItem=tempItem.remove(QRegExp("settings_"));
768+            HostTemplateSave->addSelection(tempItem);
769+            VERBOSE(VB_IMPORTANT, "Adding " + tempItem + "to save list");
770+        }
771+    }
772+}
773+
774+void TemplateSettings::fillHostTemplateRestore()
775+{
776+    HostTemplateRestore->setLabel(QObject::tr("Restore"));
777+    QString tempItem;
778+    QString current_hostname =  gContext->GetHostName();
779+    QString sub_sql;
780+    QString returnvalue;
781+    MSqlQuery query(MSqlQuery::InitCon());
782+    MSqlQuery sub_query(MSqlQuery::InitCon());
783+    query.prepare( "show tables like \"settings_%\" " );
784+    if (query.exec() && query.isActive() && query.size() > 0)
785+    {
786+        while (query.next())
787+        {
788+            tempItem = query.value(0).toString();
789+            //if found tables has settings for this hostname add the table
790+            sub_sql="SELECT value from ";
791+            sub_sql+=tempItem;
792+            sub_sql+=" where hostname=:HOSTNAME ;";
793+            sub_query.prepare(sub_sql);
794+            sub_query.bindValue( ":HOSTNAME" , current_hostname );
795+            if (sub_query.exec() && sub_query.isActive() && sub_query.size() > 0)
796+            {
797+                tempItem=tempItem.remove(QRegExp("settings_"));
798+                HostTemplateRestore->addSelection(tempItem);
799+                VERBOSE(VB_IMPORTANT, "Adding " + tempItem + "to restore list");
800+            }
801+            else
802+                VERBOSE(VB_IMPORTANT, "Couldn't find settings for " + current_hostname + " in " + tempItem);
803+        }
804+    }
805+    // check to see if default is present before adding them
806+    query.prepare ("SELECT count(data) FROM settings_Default WHERE value = 'Theme' AND hostname = 'Default'");
807+    if (query.exec() && query.isActive() && query.size() > 0)
808+    {
809+    query.next();
810+    tempItem = query.value(0).toString();
811+    if ( tempItem == "1" )
812+        HostTemplateRestore->addSelection("Default");
813+    }
814+
815+    query.prepare ("SELECT count(data) FROM settings_Default WHERE value = 'Theme' AND hostname = 'Default_1'");
816+    if (query.exec() && query.isActive() && query.size() > 0)
817+    {
818+    query.next();
819+    tempItem = query.value(0).toString();
820+    if ( tempItem == "1" )
821+        HostTemplateRestore->addSelection("Default_1");
822+    }
823+
824+    HostTemplateRestore->setHelpText(QObject::tr("Saved settings to be restored."));
825+}
826+
827+void TemplateSettings:: fillHostSelectcopy_from()
828+{
829+
830+    HostSelectcopy_from->setLabel(QObject::tr("Host"));
831+    QString tempItem;
832+    MSqlQuery query(MSqlQuery::InitCon());
833+    query.prepare( "SELECT DISTINCT hostname from settings where hostname is not null;");
834+    if (query.exec() && query.isActive() && query.size() > 0)
835+    {
836+        while (query.next())
837+        {
838+            tempItem = query.value(0).toString();
839+            tempItem=tempItem.remove(QRegExp("settings_"));
840+            HostSelectcopy_from->addSelection(tempItem);
841+        }
842+    }
843+    HostSelectcopy_from->setHelpText(QObject::tr("Select the host to copy settings from."));
844+}
845+
846+
847+void TemplateSettings::fillHostTemplateCopy_restore()
848+{
849+    QString tempItem;
850+    HostTemplateCopy_restore->addSelection("Current");
851+    HostTemplateCopy_restore->setLabel(QObject::tr("Restore"));
852+    QString current_hostname = gContext->GetHostName();
853+    MSqlQuery query(MSqlQuery::InitCon());
854+    query.prepare( "show tables like \"settings_%\" " );
855+    if (query.exec() && query.isActive() && query.size() > 0)
856+    {
857+        while (query.next())
858+        {
859+            tempItem = query.value(0).toString();
860+            tempItem=tempItem.remove(QRegExp("settings_"));
861+            if ( tempItem != "Default" )
862+            {
863+                HostTemplateCopy_restore->addSelection(tempItem);
864+                VERBOSE(VB_IMPORTANT, "Adding " + tempItem + " to copy from  list");
865+            }
866+        }
867+    }
868+    else
869+        VERBOSE(VB_IMPORTANT, "Didn't find any profiles for copy from  list");
870+
871+    HostTemplateCopy_restore->setHelpText(QObject::tr("Select the settings group to restore."));
872+
873+};
874+
875+void TemplateSettings::fillHostTemplateDelete()
876+{
877+    HostTemplateDelete->setLabel(QObject::tr("Delete Template"));
878+    HostTemplateDelete->setHelpText(QObject::tr("Delete settings under this name"));
879+    MSqlQuery query(MSqlQuery::InitCon());
880+    QString tempItem;
881+    query.prepare( "show tables like \"settings_%\" " );
882+    if (query.exec() && query.isActive() && query.size() > 0)
883+    {
884+        while (query.next())
885+        {
886+            tempItem = query.value(0).toString();
887+            tempItem=tempItem.remove(QRegExp("settings_"));
888+            if ( tempItem != "Default" )
889+            {
890+                HostTemplateDelete->addSelection(tempItem);
891+                VERBOSE(VB_IMPORTANT, "Adding " + tempItem + "to Delete list");
892+            }
893+        }
894+    }
895+}
896+
897+void TemplateSettings::remove_deleted_item(QString ditem)
898+{
899+
900+        HostTemplateDelete->setValue(0);
901+        HostTemplateDelete->removeSelection(ditem);
902+        HostTemplateRestore->removeSelection(ditem);
903+}
904+
905+
906+TemplateSettings::TemplateSettings(): TriggeredConfigurationGroup(true)
907+{
908+    setLabel(QObject::tr("Manage Settings"));
909+    HOSTtemplatetype= new HostComboBox("HOSTtemplatetype");
910+    HostTemplateSave= new HostComboBox("HostTemplateSave",true);
911+    HostTemplateRestore = new HostComboBox("HostTemplateRestore");
912+    HostSelectcopy_from = new HostComboBox("HostSelectcopy_from");
913+    HostTemplateCopy_restore = new HostComboBox("HostTemplateCopy_restore");
914+    HostTemplateDelete = new HostComboBox("HostTemplateDelete");
915+
916+    fillHOSTtemplatetype();
917+    fillHostTemplateSave();
918+    fillHostTemplateRestore();
919+    fillHostSelectcopy_from();
920+    fillHostTemplateCopy_restore();
921+    fillHostTemplateDelete();
922+
923+    Setting* Mtemplate = HOSTtemplatetype;
924+    addChild(Mtemplate);
925+    setTrigger(Mtemplate);
926+
927+    ConfigurationGroup* trestore = new VerticalConfigurationGroup(false);
928+        trestore->addChild(HostTemplateRestore);
929+
930+
931+    ConfigurationGroup* tsave = new VerticalConfigurationGroup(false);
932+        tsave->addChild(HostTemplateSave);
933+
934+    ConfigurationGroup* tcopy = new VerticalConfigurationGroup(false);
935+        tcopy->addChild(HostSelectcopy_from);
936+        tcopy->addChild(HostTemplateCopy_restore);
937+
938+    ConfigurationGroup* tdelete = new VerticalConfigurationGroup(false);
939+        tdelete->addChild(HostTemplateDelete);
940+
941+//    addTarget("Do Nothing", new VerticalConfigurationGroup(true));
942+    addTarget("Restore", trestore);
943+    addTarget("Save", tsave);
944+    addTarget("Copy From", tcopy);
945+    addTarget("Delete", tdelete);
946+
947+};
948+
949+void popup_error(){
950+
951+    QString errorText="Could not find any settings to restore.";
952+    MythPopupBox::showOkPopup(gContext->GetMainWindow(),
953+                "Open Failed",
954+                    errorText);
955+
956+}
957+
958+void TemplateSettings::choosetemplate ()
959+{
960+    QString templateop;
961+    QString templatename;
962+    QString templatehostname="";
963+    templateop=gather_setting("HOSTtemplatetype");
964+    VERBOSE(VB_IMPORTANT, "Button was pressed... " + templateop);
965+    VERBOSE(VB_IMPORTANT, "####################################");
966+    templatename = "none";
967+
968+    if ( templateop == "Save" )
969+    {
970+        templatename=gather_setting("HostTemplateSave");
971+        templatehostname=gContext->GetHostName();
972+        VERBOSE(VB_IMPORTANT, "FE----RUNNING... ...." + templateop + "  " + templatename );
973+        savesettings(templatehostname,templatename);
974+    }
975+    else if ( templateop == "Restore" )
976+    {
977+        //Run Check to see if settings are present
978+        templatename=gather_setting("HostTemplateRestore");
979+
980+        VERBOSE(VB_IMPORTANT, "FE----RUNNING... " + templateop + "  " + templatename );
981+        if ( templatename == "Default")
982+        {
983+            if ( settings_check(templatename,"Default") )
984+            {
985+                VERBOSE(VB_IMPORTANT, "FE----RUNNING... c_from  " + templateop + "  " + templatename );
986+                c_from("Default" , "Default");
987+                gContext->SaveSetting("HOSTrestartfe","1" );
988+            }
989+            else
990+            {
991+                popup_error();
992+            }
993+        }
994+        else if ( templatename == "Default_1")
995+        {
996+            if ( settings_check("Default" ,"Default_1") )
997+            {
998+                VERBOSE(VB_IMPORTANT, "FE----RUNNING... c_from  " + templateop + "  " + templatename );
999+                c_from("Default_1" , "Default" );
1000+                gContext->SaveSetting("HOSTrestartfe","1" );
1001+            }
1002+            else
1003+            {
1004+                popup_error();
1005+            }
1006+
1007+        }
1008+        else
1009+        {
1010+            if ( settings_check(templatename,templatehostname) )
1011+            {
1012+                restoresettings(templatehostname,templatename);
1013+                gContext->SaveSetting("HOSTrestartfe","1" );
1014+            }
1015+            else
1016+            {
1017+                popup_error();
1018+            }
1019+        }
1020+    }
1021+    else if ( templateop == "Copy From" )
1022+    {
1023+        templatehostname=gather_setting("HostSelectcopy_from");
1024+        templatename=gather_setting("HostTemplateCopy_restore");
1025+
1026+        if ( settings_check(templatename,templatehostname) )
1027+        {
1028+            gContext->SaveSetting("HOSTrestartfe","1" );
1029+            VERBOSE(VB_IMPORTANT, "FE----RUNNING... ...." + templateop + "  " + templatename + " " + templatehostname );
1030+            c_from(templatehostname,templatename);
1031+        }
1032+        else
1033+        {
1034+            popup_error();
1035+        }
1036+    }
1037+    else if ( templateop == "Delete" )
1038+    {
1039+        templatehostname=gContext->GetHostName();
1040+        templatename=gather_setting("HostTemplateDelete");
1041+        deletesettings(templatehostname,templatename);
1042+        remove_deleted_item(templatename);
1043+    }
1044+    VERBOSE(VB_IMPORTANT, "####################################");
1045+
1046+};
1047+
1048+
1049+
1050+
1051+ProfileSettings_MainFrame::ProfileSettings_MainFrame():
1052+VerticalConfigurationGroup(false,false,false,false)
1053+{
1054+    setLabel(QObject::tr("Save/Backup settings"));
1055+    TemplateSettings *templatesettings = new TemplateSettings();
1056+
1057+    userapplyButton = new TransButtonSetting;
1058+    userapplyButton->setLabel("Run");
1059+
1060+    VerticalConfigurationGroup* frame_profile = new VerticalConfigurationGroup(false, true,false,false);
1061+    frame_profile->addChild(templatesettings);
1062+    frame_profile->addChild(userapplyButton);
1063+
1064+    addChild(frame_profile);
1065+    connect(userapplyButton, SIGNAL(pressed()),templatesettings,SLOT(choosetemplate()));
1066+};
1067+
1068+
1069+MythCtemplate::MythCtemplate()
1070+{
1071+    ProfileSettings_MainFrame *profilesettings_mainframe = new ProfileSettings_MainFrame();
1072+    addChild(profilesettings_mainframe);
1073+};
1074+
1075+
1076+
1077
1078Property changes on: mythfrontend/settings_template.cpp
1079___________________________________________________________________
1080Name: svn:executable
1081   + *
1082
1083Index: programs.pro
1084===================================================================
1085--- programs.pro        (revision 19405)
1086+++ programs.pro        (working copy)
1087@@ -8,6 +8,7 @@
1088     SUBDIRS += mythtv mythfrontend mythcommflag
1089     SUBDIRS += mythtvosd mythjobqueue mythlcdserver
1090     SUBDIRS += mythwelcome mythshutdown mythtranscode/replex
1091+    SUBDIRS += mythsettings
1092 }
1093 
1094 using_backend {