Ticket #6064: programs.patch

File programs.patch, 23.4 KB (added by anonymous, 3 years ago)

patch for programs directory.

  • programs/mythfrontend/util_menu.xml

     
    101101      <text lang="HE">הגד׹ה</text> 
    102102      <action>MENU main_settings.xml</action> 
    103103   </button> 
     104   <button> 
     105       <type>MENU_UTILITIES_SETUP</type> 
     106       <text>Save or Restore settings</text> 
     107       <description>Save or restore settings settings for MythTV</description> 
     108       <action>settings_profile</action> 
     109   </button> 
    104110 
    105111</mythmenu> 
  • programs/mythfrontend/main.cpp

     
    6161#include "mythcontrols.h" 
    6262#include "mythuihelper.h" 
    6363#include "mythdirs.h" 
     64#include "settings_template.h" 
    6465 
    6566static ExitPrompter   *exitPopup = NULL; 
    6667static MythThemedMenu *menu; 
     
    524525        showStatus(); 
    525526    else if (sel == "exiting_app") 
    526527        handleExit(); 
     528    else if (sel == "settings_profile") 
     529    { 
     530        gContext->ActivateSettingsCache(false); 
     531        MythCtemplate *setting =  new MythCtemplate(); 
     532        DialogCode res = setting->exec(); 
     533        delete setting; 
     534 
     535        if (kDialogCodeRejected != res) 
     536        { 
     537            if ( gContext->GetSetting("HOSTrestartfe") == "1" ) 
     538            { 
     539                qApp->processEvents(); 
     540                GetMythMainWindow()->JumpTo("Reload Theme"); 
     541                RemoteSendMessage("CLEAR_SETTINGS_CACHE"); 
     542                gContext->SaveSetting("HOSTrestartfe","0" ); 
     543            } 
     544        } 
     545        gContext->ActivateSettingsCache(true); 
     546    } 
    527547 
    528548    if (sel.left(9) == "settings ") 
    529549    { 
  • programs/mythfrontend/mythfrontend.pro

     
    1111target.path = $${PREFIX}/bin 
    1212INSTALLS = target 
    1313 
     14 
    1415setting.path = $${PREFIX}/share/mythtv/ 
    1516setting.files += theme.txt mysql.txt 
    1617setting.files += info_menu.xml mainmenu.xml media_settings.xml tv_schedule.xml 
     
    3132HEADERS += mediarenderer.h mythfexml.h playbackboxlistitem.h 
    3233HEADERS += mythappearance.h exitprompt.h proglist.h 
    3334HEADERS += action.h mythcontrols.h keybindings.h keygrabber.h 
     35HEADERS += settings_template.h 
    3436 
    3537SOURCES += main.cpp playbackbox.cpp viewscheduled.cpp 
    3638SOURCES += globalsettings.cpp manualschedule.cpp programrecpriority.cpp 
     
    3941SOURCES += custompriority.cpp mythappearance.cpp exitprompt.cpp proglist.cpp 
    4042SOURCES += action.cpp actionset.cpp  mythcontrols.cpp keybindings.cpp 
    4143SOURCES += keygrabber.cpp 
     44SOURCES += settings_template.cpp 
     45 
    4246 
    4347macx { 
    4448    mac_bundle { 
  • programs/mythfrontend/settings_template.h

     
     1#include <settings.h> 
     2#include "mythdialogs.h" 
     3 
     4class TemplateSettings: public TriggeredConfigurationGroup { 
     5Q_OBJECT 
     6public: 
     7    TemplateSettings(); 
     8    HostComboBox *HOSTtemplatetype; 
     9    HostComboBox *HostTemplateSave; 
     10    HostComboBox *HostTemplateRestore; 
     11    HostComboBox *HostSelectcopy_from; 
     12    HostComboBox *HostTemplateCopy_restore; 
     13    HostComboBox *HostTemplateDelete; 
     14    void fillHOSTtemplatetype(); 
     15    void fillHostTemplateSave(); 
     16    void fillHostTemplateRestore(); 
     17    void fillHostSelectcopy_from(); 
     18    void fillHostTemplateCopy_restore(); 
     19    void fillHostTemplateDelete(); 
     20    void remove_deleted_item(QString); 
     21 
     22public slots: 
     23    void choosetemplate(); 
     24    QString gather_setting(QString); 
     25}; 
     26 
     27class ProfileSettings_MainFrame: public VerticalConfigurationGroup { 
     28Q_OBJECT 
     29public: 
     30         ProfileSettings_MainFrame(); 
     31         TransButtonSetting *userapplyButton; 
     32}; 
     33 
     34class MythCtemplate: public ConfigurationWizard { 
     35public: 
     36    MythCtemplate(); 
     37}; 
     38 
     39 
  • programs/mythfrontend/settings_template.cpp

    Property changes on: programs/mythfrontend/settings_template.h
    ___________________________________________________________________
    Added: svn:executable
       + *
    
     
     1#include <mythcontext.h> 
     2#include <unistd.h> 
     3#include <iostream> 
     4#include <fstream> 
     5#include <stdio.h> 
     6#include "settings.h" 
     7#include <qsqldatabase.h> 
     8#include <qsqlquery.h> 
     9#include <stdlib.h> 
     10#include <cstdlib> 
     11#include <mythtv/mythdbcon.h> 
     12#include <mythtv/mythdb.h> 
     13 
     14#include "settings_template.h" 
     15 
     16QString TemplateSettings::gather_setting(QString QUERY) 
     17{ 
     18    QString returnvalue = "" ; 
     19    if ( QUERY == "HOSTtemplatetype" ) 
     20        returnvalue=HOSTtemplatetype->getValue(); 
     21    else if ( QUERY == "HostTemplateSave") 
     22        returnvalue=HostTemplateSave->getValue(); 
     23    else if ( QUERY == "HostTemplateRestore") 
     24        returnvalue=HostTemplateRestore->getValue(); 
     25    else if ( QUERY == "HostSelectcopy_from") 
     26        returnvalue=HostSelectcopy_from->getValue(); 
     27    else if ( QUERY == "HostTemplateCopy_restore") 
     28        returnvalue=HostTemplateCopy_restore->getValue(); 
     29    else if ( QUERY == "HostTemplateDelete") 
     30        returnvalue=HostTemplateDelete->getValue(); 
     31    return returnvalue; 
     32} 
     33 
     34void TemplateSettings::fillHOSTtemplatetype() 
     35{ 
     36    HOSTtemplatetype->setLabel(QObject::tr("Settings options")); 
     37    HOSTtemplatetype->addSelection("Restore"); 
     38    HOSTtemplatetype->addSelection("Save") ; 
     39    HOSTtemplatetype->addSelection("Copy From"); 
     40    HOSTtemplatetype->addSelection("Delete"); 
     41    HOSTtemplatetype->setHelpText(QObject::tr("Select the command to run.")); 
     42} 
     43 
     44void TemplateSettings::fillHostTemplateSave() 
     45{ 
     46    HostTemplateSave->setLabel(QObject::tr("Save Template")); 
     47    HostTemplateSave->addSelection("user1") ; 
     48    HostTemplateSave->addSelection("user2") ; 
     49    HostTemplateSave->setHelpText(QObject::tr("Save settings under this name")); 
     50    MSqlQuery query(MSqlQuery::InitCon()); 
     51    QString tempItem; 
     52    query.prepare( "show tables like \"settings_%\" " ); 
     53    if (query.exec() && query.isActive() && query.size() > 0) 
     54    { 
     55        while (query.next()) 
     56        { 
     57            tempItem = query.value(0).toString(); 
     58            tempItem=tempItem.remove(QRegExp("settings_")); 
     59            HostTemplateSave->addSelection(tempItem); 
     60            VERBOSE(VB_IMPORTANT, "Adding " + tempItem + "to save list"); 
     61        } 
     62    } 
     63} 
     64 
     65void TemplateSettings::fillHostTemplateRestore() 
     66{ 
     67    HostTemplateRestore->setLabel(QObject::tr("Restore")); 
     68    QString tempItem; 
     69    QString current_hostname =  gContext->GetHostName(); 
     70    QString sub_sql; 
     71    QString returnvalue; 
     72    MSqlQuery query(MSqlQuery::InitCon()); 
     73    MSqlQuery sub_query(MSqlQuery::InitCon()); 
     74    query.prepare( "show tables like \"settings_%\" " ); 
     75    if (query.exec() && query.isActive() && query.size() > 0) 
     76    { 
     77        while (query.next()) 
     78        { 
     79            tempItem = query.value(0).toString(); 
     80            //if found tables has settings for this hostname add the table 
     81            sub_sql="SELECT value from "; 
     82            sub_sql+=tempItem; 
     83            sub_sql+=" where hostname=:HOSTNAME ;"; 
     84            sub_query.prepare(sub_sql); 
     85            sub_query.bindValue( ":HOSTNAME" , current_hostname ); 
     86            if (sub_query.exec() && sub_query.isActive() && sub_query.size() > 0) 
     87            { 
     88                tempItem=tempItem.remove(QRegExp("settings_")); 
     89                HostTemplateRestore->addSelection(tempItem); 
     90                VERBOSE(VB_IMPORTANT, "Adding " + tempItem + "to restore list"); 
     91            } 
     92            else 
     93                VERBOSE(VB_IMPORTANT, "Couldn't find settings for " + 
     94                        current_hostname + " in " + tempItem); 
     95        } 
     96    } 
     97    // check to see if default is present before adding them 
     98    query.prepare ("SELECT count(data) FROM settings_Default WHERE value = 'Theme' AND hostname = 'Default'"); 
     99    if (query.exec() && query.isActive() && query.size() > 0) 
     100    { 
     101    query.next(); 
     102    tempItem = query.value(0).toString(); 
     103    if ( tempItem == "1" ) 
     104        HostTemplateRestore->addSelection("Default"); 
     105    } 
     106 
     107    query.prepare ("SELECT count(data) FROM settings_Default WHERE value = 'Theme' AND hostname = 'Default_1'"); 
     108    if (query.exec() && query.isActive() && query.size() > 0) 
     109    { 
     110        query.next(); 
     111        tempItem = query.value(0).toString(); 
     112        if ( tempItem == "1" ) 
     113            HostTemplateRestore->addSelection("Default_1"); 
     114    } 
     115    HostTemplateRestore->setHelpText(QObject::tr("Saved settings to be restored.")); 
     116} 
     117 
     118void TemplateSettings:: fillHostSelectcopy_from() 
     119{ 
     120 
     121    HostSelectcopy_from->setLabel(QObject::tr("Host")); 
     122    QString tempItem; 
     123    MSqlQuery query(MSqlQuery::InitCon()); 
     124    query.prepare( "SELECT DISTINCT hostname from settings where hostname is not null;"); 
     125    if (query.exec() && query.isActive() && query.size() > 0) 
     126    { 
     127        while (query.next()) 
     128        { 
     129            tempItem = query.value(0).toString(); 
     130            tempItem=tempItem.remove(QRegExp("settings_")); 
     131            HostSelectcopy_from->addSelection(tempItem); 
     132        } 
     133    } 
     134    HostSelectcopy_from->setHelpText(QObject::tr("Select the host to copy settings from.")); 
     135} 
     136 
     137 
     138void TemplateSettings::fillHostTemplateCopy_restore() 
     139{ 
     140    QString tempItem; 
     141    HostTemplateCopy_restore->addSelection("Current"); 
     142    HostTemplateCopy_restore->setLabel(QObject::tr("Restore")); 
     143    QString current_hostname = gContext->GetHostName(); 
     144    MSqlQuery query(MSqlQuery::InitCon()); 
     145    query.prepare( "show tables like \"settings_%\" " ); 
     146    if (query.exec() && query.isActive() && query.size() > 0) 
     147    { 
     148        while (query.next()) 
     149        { 
     150            tempItem = query.value(0).toString(); 
     151            tempItem=tempItem.remove(QRegExp("settings_")); 
     152            if ( tempItem != "Default" ) 
     153            { 
     154                HostTemplateCopy_restore->addSelection(tempItem); 
     155                VERBOSE(VB_IMPORTANT, "Adding " + tempItem + " to copy from  list"); 
     156            } 
     157        } 
     158    } 
     159    else 
     160        VERBOSE(VB_IMPORTANT, "Didn't find any profiles for copy from  list"); 
     161    HostTemplateCopy_restore->setHelpText(QObject::tr("Select the settings group to restore.")); 
     162 
     163}; 
     164 
     165void TemplateSettings::fillHostTemplateDelete() 
     166{ 
     167    HostTemplateDelete->setLabel(QObject::tr("Delete Template")); 
     168    HostTemplateDelete->setHelpText(QObject::tr("Delete settings under this name")); 
     169    MSqlQuery query(MSqlQuery::InitCon()); 
     170    QString tempItem; 
     171    query.prepare( "show tables like \"settings_%\" " ); 
     172    if (query.exec() && query.isActive() && query.size() > 0) 
     173    { 
     174        while (query.next()) 
     175        { 
     176            tempItem = query.value(0).toString(); 
     177            tempItem=tempItem.remove(QRegExp("settings_")); 
     178            if ( tempItem != "Default" ) 
     179            { 
     180                HostTemplateDelete->addSelection(tempItem); 
     181                VERBOSE(VB_IMPORTANT, "Adding " + tempItem + "to Delete list"); 
     182            } 
     183        } 
     184    } 
     185} 
     186 
     187void TemplateSettings::remove_deleted_item(QString ditem) 
     188{ 
     189 
     190        HostTemplateDelete->setValue(0); 
     191        HostTemplateDelete->removeSelection(ditem); 
     192        HostTemplateRestore->removeSelection(ditem); 
     193} 
     194 
     195 
     196TemplateSettings::TemplateSettings(): TriggeredConfigurationGroup(true) 
     197{ 
     198    setLabel(QObject::tr("Manage Settings")); 
     199    HOSTtemplatetype= new HostComboBox("HOSTtemplatetype"); 
     200    HostTemplateSave= new HostComboBox("HostTemplateSave",true); 
     201    HostTemplateRestore = new HostComboBox("HostTemplateRestore"); 
     202    HostSelectcopy_from = new HostComboBox("HostSelectcopy_from"); 
     203    HostTemplateCopy_restore = new HostComboBox("HostTemplateCopy_restore"); 
     204    HostTemplateDelete = new HostComboBox("HostTemplateDelete"); 
     205 
     206    fillHOSTtemplatetype(); 
     207    fillHostTemplateSave(); 
     208    fillHostTemplateRestore(); 
     209    fillHostSelectcopy_from(); 
     210    fillHostTemplateCopy_restore(); 
     211    fillHostTemplateDelete(); 
     212 
     213    Setting* Mtemplate = HOSTtemplatetype; 
     214    addChild(Mtemplate); 
     215    setTrigger(Mtemplate); 
     216 
     217    ConfigurationGroup* trestore = new VerticalConfigurationGroup(false); 
     218        trestore->addChild(HostTemplateRestore); 
     219 
     220    ConfigurationGroup* tsave = new VerticalConfigurationGroup(false); 
     221        tsave->addChild(HostTemplateSave); 
     222 
     223    ConfigurationGroup* tcopy = new VerticalConfigurationGroup(false); 
     224        tcopy->addChild(HostSelectcopy_from); 
     225        tcopy->addChild(HostTemplateCopy_restore); 
     226 
     227    ConfigurationGroup* tdelete = new VerticalConfigurationGroup(false); 
     228        tdelete->addChild(HostTemplateDelete); 
     229 
     230    addTarget("Restore", trestore); 
     231    addTarget("Save", tsave); 
     232    addTarget("Copy From", tcopy); 
     233    addTarget("Delete", tdelete); 
     234 
     235}; 
     236 
     237void popup_error(){ 
     238    QString errorText="Could not find any settings to restore."; 
     239    MythPopupBox::showOkPopup(gContext->GetMainWindow(), 
     240                "Open Failed", 
     241                    errorText); 
     242} 
     243 
     244void TemplateSettings::choosetemplate () 
     245{ 
     246    QString templateop; 
     247    QString templatename; 
     248    QString templatehostname=""; 
     249    templateop=gather_setting("HOSTtemplatetype"); 
     250    VERBOSE(VB_IMPORTANT, "Button was pressed... " + templateop); 
     251    VERBOSE(VB_IMPORTANT, "####################################"); 
     252    templatename = "none"; 
     253    if ( templateop == "Save" ) 
     254    { 
     255        templatename=gather_setting("HostTemplateSave"); 
     256        templatehostname=gContext->GetHostName(); 
     257        VERBOSE(VB_IMPORTANT, "FE----RUNNING... ...." + templateop + "  " + templatename ); 
     258        savesettings(templatehostname,templatename); 
     259    } 
     260    else if ( templateop == "Restore" ) 
     261    { 
     262        //Run Check to see if settings are present 
     263        templatename=gather_setting("HostTemplateRestore"); 
     264        templatehostname=gContext->GetHostName(); 
     265        VERBOSE(VB_IMPORTANT, "FE----RUNNING... " + templateop + "  " + templatename ); 
     266        if ( templatename == "Default") 
     267        { 
     268            if ( settings_check(templatename,"Default") ) 
     269            { 
     270                VERBOSE(VB_IMPORTANT, "FE----RUNNING... c_from  " + templateop + "  " + templatename ); 
     271                c_from("Default" , "Default",gContext->GetHostName()); 
     272                gContext->SaveSetting("HOSTrestartfe","1" ); 
     273            } 
     274            else 
     275            { 
     276                popup_error(); 
     277            } 
     278        } 
     279        else if ( templatename == "Default_1") 
     280        { 
     281            if ( settings_check("Default" ,"Default_1") ) 
     282            { 
     283                VERBOSE(VB_IMPORTANT, "FE----RUNNING... c_from  " + templateop + "  " + templatename ); 
     284                c_from("Default_1" , "Default",gContext->GetHostName() ); 
     285                gContext->SaveSetting("HOSTrestartfe","1" ); 
     286            } 
     287            else 
     288            { 
     289                popup_error(); 
     290            } 
     291        } 
     292        else 
     293        { 
     294            if ( settings_check(templatename,templatehostname) ) 
     295            { 
     296                restoresettings(templatehostname,templatename); 
     297                gContext->SaveSetting("HOSTrestartfe","1" ); 
     298            } 
     299            else 
     300            { 
     301                popup_error(); 
     302            } 
     303        } 
     304    } 
     305    else if ( templateop == "Copy From" ) 
     306    { 
     307        templatehostname=gather_setting("HostSelectcopy_from"); 
     308        templatename=gather_setting("HostTemplateCopy_restore"); 
     309 
     310        if ( settings_check(templatename,templatehostname) ) 
     311        { 
     312            gContext->SaveSetting("HOSTrestartfe","1" ); 
     313            VERBOSE(VB_IMPORTANT, "FE----RUNNING... ...." + templateop + "  " + templatename + " " + templatehostname ); 
     314            c_from(templatehostname,templatename,gContext->GetHostName()); 
     315        } 
     316        else 
     317        { 
     318            popup_error(); 
     319        } 
     320    } 
     321    else if ( templateop == "Delete" ) 
     322    { 
     323        templatehostname=gContext->GetHostName(); 
     324        templatename=gather_setting("HostTemplateDelete"); 
     325        deletesettings(templatehostname,templatename); 
     326        remove_deleted_item(templatename); 
     327    } 
     328    VERBOSE(VB_IMPORTANT, "####################################"); 
     329 
     330}; 
     331 
     332ProfileSettings_MainFrame::ProfileSettings_MainFrame(): 
     333VerticalConfigurationGroup(false,false,false,false) 
     334{ 
     335    setLabel(QObject::tr("Save/Backup settings")); 
     336    TemplateSettings *templatesettings = new TemplateSettings(); 
     337 
     338    userapplyButton = new TransButtonSetting; 
     339    userapplyButton->setLabel("Run"); 
     340 
     341    VerticalConfigurationGroup* frame_profile = 
     342            new VerticalConfigurationGroup(false, true,false,false); 
     343    frame_profile->addChild(templatesettings); 
     344    frame_profile->addChild(userapplyButton); 
     345 
     346    addChild(frame_profile); 
     347    connect(userapplyButton, SIGNAL(pressed()), 
     348            templatesettings,SLOT(choosetemplate())); 
     349}; 
     350 
     351MythCtemplate::MythCtemplate() 
     352{ 
     353    ProfileSettings_MainFrame *profilesettings_mainframe = new ProfileSettings_MainFrame(); 
     354    addChild(profilesettings_mainframe); 
     355}; 
  • programs/programs.pro

    Property changes on: programs/mythfrontend/settings_template.cpp
    ___________________________________________________________________
    Added: svn:executable
       + *
    
     
    88    SUBDIRS += mythtv mythfrontend mythcommflag 
    99    SUBDIRS += mythtvosd mythjobqueue mythlcdserver 
    1010    SUBDIRS += mythwelcome mythshutdown mythtranscode/replex 
     11    SUBDIRS += mythsettings 
    1112} 
    1213 
    1314using_backend { 
  • programs/mythsettings/mythsettings.pro

     
     1include ( ../../config.mak ) 
     2include ( ../../settings.pro ) 
     3include ( ../programs-libs.pro ) 
     4 
     5QT += network xml sql qt3support 
     6 
     7TEMPLATE = app 
     8CONFIG += thread 
     9CONFIG -= moc 
     10TARGET = mythsettings 
     11target.path = $${PREFIX}/bin 
     12INSTALLS = target 
     13 
     14QMAKE_CLEAN += $(TARGET) 
     15 
     16# Input 
     17 
     18SOURCES += main.cpp 
  • programs/mythsettings/main.cpp

     
     1// C headers 
     2#include <unistd.h> 
     3 
     4// C++ headers 
     5#include <iostream> 
     6using namespace std; 
     7 
     8// Qt headers 
     9#include <QApplication> 
     10 
     11// libmyth headers 
     12#include "exitcodes.h" 
     13#include "mythcontext.h" 
     14#include "mythdb.h" 
     15#include "mythverbose.h" 
     16#include "mythversion.h" 
     17//#include "settemplate.h" 
     18 
     19 
     20 
     21int main(int argc, char *argv[]) 
     22{ 
     23    QApplication a(argc, argv, false); 
     24    QString templateop=""; 
     25    QString templatename=""; 
     26    QString templatehostname=""; 
     27    QStringList template_c_line; 
     28    int argpos = 1; 
     29    cout << a.argc() << endl; 
     30    if ( a.argc() <=1 ) 
     31    { 
     32    cerr << "Missing argument, run -h to see the help \n"; 
     33    return 3; 
     34    }; 
     35 
     36    while (argpos < a.argc()) 
     37    { 
     38    if (!strcmp(a.argv()[argpos],"-t")) 
     39        { 
     40            if (a.argc()-1 > argpos) 
     41            { 
     42                QString tmpArg = a.argv()[argpos+1]; 
     43                if (tmpArg.startsWith("-")) 
     44                { 
     45                    cerr << "Invalid or missing argument to -t \n"; 
     46                    return 3; 
     47                } 
     48                else 
     49                { 
     50                    templatename=tmpArg; 
     51                } 
     52                ++argpos; 
     53            } 
     54        } 
     55        else if (!strcmp(a.argv()[argpos], "-o")) 
     56        { 
     57            if (a.argc()-1 > argpos) 
     58            { 
     59                QString tmpArg = a.argv()[argpos+1]; 
     60                if (tmpArg.startsWith("-") || tmpArg == "" ) 
     61                { 
     62                    cerr << "Missing argument to -o \n"; 
     63                    return 3; 
     64                } 
     65                else if ( tmpArg != "save" && 
     66                          tmpArg != "restore" && 
     67                          tmpArg != "copy_from" && 
     68                          tmpArg != "delete" ) 
     69                { 
     70                    cerr << "Invalid argument to -o \n"; 
     71                    return 3; 
     72                } 
     73                else 
     74                { 
     75                    templateop=tmpArg; 
     76                } 
     77                ++argpos; 
     78            } 
     79 
     80        } 
     81        else if (!strcmp(a.argv()[argpos], "-n")) 
     82        { 
     83            if (a.argc()-1 > argpos) 
     84            { 
     85                QString tmpArg = a.argv()[argpos+1]; 
     86                if (tmpArg.startsWith("-")) 
     87                { 
     88                    cerr << "Invalid or missing argument to -n \n"; 
     89                    return 3; 
     90                } 
     91                else 
     92                { 
     93                    templatehostname=tmpArg; 
     94                } 
     95                ++argpos; 
     96            } 
     97        } 
     98        else if (!strcmp(a.argv()[argpos], "-h") || 
     99                !strcmp(a.argv()[argpos], "--help")) 
     100        { 
     101            VERBOSE(VB_IMPORTANT, "-o [save|restore|copy_from|delete]"); 
     102            VERBOSE(VB_IMPORTANT, "-t template_name "); 
     103            VERBOSE(VB_IMPORTANT, "-n  hostname"); 
     104            return 3; 
     105        } 
     106        else 
     107        { 
     108            fprintf(stderr, "illegal option: '%s' (use --help)\n", 
     109                    a.argv()[argpos]); 
     110            return 3; 
     111        } 
     112        ++argpos; 
     113    } 
     114    if ( templatename == "" ) 
     115    { 
     116        VERBOSE(VB_IMPORTANT, "Missing template name"); 
     117        return 2; 
     118    } 
     119    if ( templateop == "" ) 
     120    { 
     121        VERBOSE(VB_IMPORTANT, "Missing operation"); 
     122        return 2; 
     123    } 
     124    if ( templatehostname == "" ) 
     125    { 
     126        VERBOSE(VB_IMPORTANT, "Missing hostname"); 
     127        return 2; 
     128    } 
     129    VERBOSE(VB_IMPORTANT, "Using template:" +  templatename); 
     130    VERBOSE(VB_IMPORTANT, "Using Operation:" +  templateop); 
     131    if  ( templateop == "copy_from" ) 
     132        VERBOSE(VB_IMPORTANT, "Copy from host:" +  templatehostname); 
     133 
     134    gContext = NULL; 
     135    gContext = new MythContext(MYTH_BINARY_VERSION); 
     136    if (!gContext->Init(false)) 
     137    { 
     138        VERBOSE(VB_IMPORTANT, "Failed to init MythContext, exiting."); 
     139        delete gContext; 
     140        return FILLDB_EXIT_NO_MYTHCONTEXT; 
     141    } 
     142 
     143    if (!MSqlQuery::testDBConnection()) 
     144    { 
     145        VERBOSE(VB_IMPORTANT, "Could not open the database. " 
     146                        "Exiting."); 
     147        return -1; 
     148    } 
     149 
     150    if ( templateop == "save" ) 
     151    { 
     152        savesettings(templatehostname,templatename); 
     153    } 
     154 
     155    if ( templateop == "restore" ) 
     156    { 
     157        if ( templatename == "Default" ) 
     158            c_from("Default" , templatename); 
     159        else if ( templatename == "Default_1") 
     160            c_from ("Default_1" , templatename ); 
     161        else if ( settings_check(templatename,templatehostname) ) 
     162        { 
     163                cout << "--------------------------" << endl; 
     164                restoresettings(templatehostname,templatename); 
     165        } 
     166    } 
     167 
     168    if ( templateop == "delete" ) 
     169        deletesettings(templatehostname,templatename); 
     170 
     171    if ( templateop == "copy_from" ) 
     172    { 
     173        if ( templatename=="") 
     174            templatename="current"; 
     175        c_from(templatehostname,templatename); 
     176    } 
     177 
     178    delete gContext; 
     179    VERBOSE(VB_IMPORTANT, "settings op " + templateop + " " + templatename + " run complete."); 
     180    return 0; 
     181} 
     182 
     183/* vim: set expandtab tabstop=4 shiftwidth=4: */