Synchronet now requires the libarchive development package (e.g. libarchive-dev on Debian-based Linux distros, libarchive.org for more info) to build successfully.

ServicesCfgDlgUnit.cpp 7.17 KB
Newer Older
rswindell's avatar
rswindell committed
1 2 3 4 5
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

6
#include "MainFormUnit.h"
rswindell's avatar
rswindell committed
7 8
#include "TextFileEditUnit.h"
#include "ServicesCfgDlgUnit.h"
9
#include "CodeInputFormUnit.h"
10
#include "SoundCfgDlgUnit.h"
rswindell's avatar
rswindell committed
11 12 13 14 15 16 17 18 19
#include <stdio.h>			// sprintf()
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TServicesCfgDlg *ServicesCfgDlg;
//---------------------------------------------------------------------------
__fastcall TServicesCfgDlg::TServicesCfgDlg(TComponent* Owner)
    : TForm(Owner)
{
20
    ini = NULL;
rswindell's avatar
rswindell committed
21 22 23 24
}
//---------------------------------------------------------------------------
void __fastcall TServicesCfgDlg::FormShow(TObject *Sender)
{
25 26 27
    char str[256];

    if(MainForm->services_startup.interfaces==NULL)
rswindell's avatar
rswindell committed
28 29
        NetworkInterfaceEdit->Text="<ANY>";
    else {
30
        strListCombine(MainForm->services_startup.interfaces, str, sizeof(str)-1, ",");
rswindell's avatar
rswindell committed
31 32 33 34 35 36 37
        NetworkInterfaceEdit->Text=AnsiString(str);
    }
    AutoStartCheckBox->Checked=MainForm->ServicesAutoStart;

    HostnameCheckBox->Checked
        =!(MainForm->services_startup.options&BBS_OPT_NO_HOST_LOOKUP);

38 39 40 41 42 43 44 45 46 47 48 49 50 51
    iniFileName(iniFilename,sizeof(iniFilename),MainForm->cfg.ctrl_dir,"services.ini");
    /* Populate the Enables tab */
    CheckListBox->Clear();
    FILE* fp;
    if((fp=iniOpenFile(iniFilename, /* Create: */false)) != NULL) {
        ini=iniReadFile(fp);
        iniCloseFile(fp);
    }
    str_list_t services = iniGetSectionList(ini, NULL);
    CheckListBox->Items->BeginUpdate();
    for(unsigned u=0; services!=NULL && services[u]!=NULL; u++) {
        CheckListBox->Items->Append(services[u]);
    }
    CheckListBox->Items->EndUpdate();
rswindell's avatar
rswindell committed
52

53 54 55 56 57 58
    for(unsigned u=0; u<CheckListBox->Items->Count; u++) {
        str_list_t section = iniGetSection(ini, CheckListBox->Items->Strings[u].c_str());
        CheckListBox->Checked[u]=iniGetBool(section, NULL, "Enabled", TRUE);
        iniFreeStringList(section);
    }
    iniFreeStringList(services);
59
    if(CheckListBox->Items->Count) {
60
        CheckListBox->ItemIndex=0;
61 62 63 64 65 66 67
        CheckListBoxClick(Sender);
    }

    str_list_t keys = iniGetKeyList(ini, ROOT_SECTION);
    for(unsigned u=0; keys!=NULL && keys[u]!=NULL; u++) {
        if(keys[u][0])
            GlobalValueListEditor->InsertRow(AnsiString(keys[u])
68
                ,AnsiString(iniGetString(ini,ROOT_SECTION,keys[u],"",NULL))
69 70 71
                ,/* append: */true);
    }
    iniFreeStringList(keys);
72 73

    PageControl->ActivePage=GeneralTabSheet;
rswindell's avatar
rswindell committed
74 75 76 77
}
//---------------------------------------------------------------------------
void __fastcall TServicesCfgDlg::OKButtonClick(TObject *Sender)
{
78 79
    iniFreeStringList(MainForm->services_startup.interfaces);
    MainForm->services_startup.interfaces = strListSplitCopy(NULL, NetworkInterfaceEdit->Text.c_str(), ",");
rswindell's avatar
rswindell committed
80 81 82 83 84 85 86 87

    MainForm->ServicesAutoStart=AutoStartCheckBox->Checked;

	if(HostnameCheckBox->Checked==false)
    	MainForm->services_startup.options|=BBS_OPT_NO_HOST_LOOKUP;
    else
	    MainForm->services_startup.options&=~BBS_OPT_NO_HOST_LOOKUP;

88 89 90 91 92 93
    FILE* fp;
    if((fp=iniOpenFile(iniFilename, /* Create: */true)) != NULL) {
        iniWriteFile(fp, ini);
        iniCloseFile(fp);
    }

rswindell's avatar
rswindell committed
94 95 96 97 98
    MainForm->SaveSettings(Sender);

}

//---------------------------------------------------------------------------
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
void __fastcall TServicesCfgDlg::FormClose(TObject *Sender,
      TCloseAction &Action)
{
    iniFreeStringList(ini);
}
//---------------------------------------------------------------------------


void __fastcall TServicesCfgDlg::CheckListBoxClick(TObject *Sender)
{
    ValueListEditor->Strings->Clear();
    ValueListEditor->Visible=true;
    if(CheckListBox->ItemIndex < 0) {
        ValueListEditor->Visible=false;
        return;
    }
    if(iniGetBool(ini,CheckListBox->Items->Strings[CheckListBox->ItemIndex].c_str()
        ,"Enabled", true) != CheckListBox->Checked[CheckListBox->ItemIndex])
        iniSetBool(&ini
            ,CheckListBox->Items->Strings[CheckListBox->ItemIndex].c_str()
            ,"Enabled", CheckListBox->Checked[CheckListBox->ItemIndex]
            ,/* style: */NULL);

    char* service = strdup(CheckListBox->Items->Strings[CheckListBox->ItemIndex].c_str());
    str_list_t section = iniGetSection(ini, service);
    str_list_t keys = iniGetKeyList(section, NULL);
    for(unsigned u=0; keys!=NULL && keys[u]!=NULL; u++) {
        if(keys[u][0])
            ValueListEditor->InsertRow(AnsiString(keys[u]),
128
                AnsiString(iniGetString(section,NULL,keys[u],"",NULL)), /* append: */true);
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
    }
    iniFreeStringList(keys);
    iniFreeStringList(section);
    free(service);
}
//---------------------------------------------------------------------------


void __fastcall TServicesCfgDlg::ValueListEditorValidate(TObject *Sender,
      int ACol, int ARow, const AnsiString KeyName,
      const AnsiString KeyValue)
{
    if(CheckListBox->ItemIndex >= 0)
        iniSetString(&ini
            ,CheckListBox->Items->Strings[CheckListBox->ItemIndex].c_str()
            ,KeyName.c_str(), KeyValue.c_str(), /* style: */NULL);
}
//---------------------------------------------------------------------------

148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193
void __fastcall TServicesCfgDlg::ServiceAddClick(TObject *Sender)
{
	Application->CreateForm(__classid(TCodeInputForm), &CodeInputForm);
	CodeInputForm->Label->Caption="New Service Name";
   	CodeInputForm->Edit->Visible=true;
    if(CodeInputForm->ShowModal()==mrOk
       	&& CodeInputForm->Edit->Text.Length()
        && !iniSectionExists(ini,CodeInputForm->Edit->Text.c_str())
        && iniAppendSection(&ini,CodeInputForm->Edit->Text.c_str(),/* style: */NULL)) {
        CheckListBox->Items->Append(CodeInputForm->Edit->Text);
        CheckListBox->ItemIndex = CheckListBox->Items->Count-1;
        CheckListBoxClick(Sender);
    }
    delete CodeInputForm;
}
//---------------------------------------------------------------------------

void __fastcall TServicesCfgDlg::ServiceRemoveClick(TObject *Sender)
{
    if(CheckListBox->ItemIndex >= 0
        && iniRemoveSection(&ini,CheckListBox->Items->Strings[CheckListBox->ItemIndex].c_str())) {
        CheckListBox->DeleteSelected();
        CheckListBoxClick(Sender);
    }        
}
//---------------------------------------------------------------------------

void __fastcall TServicesCfgDlg::CheckListBoxKeyDown(TObject *Sender,
      WORD &Key, TShiftState Shift)
{
    if(Key==VK_INSERT)
        ServiceAddClick(Sender);
    else if(Key==VK_DELETE)
        ServiceRemoveClick(Sender);
}
//---------------------------------------------------------------------------

void __fastcall TServicesCfgDlg::GlobalValueListEditorValidate(
      TObject *Sender, int ACol, int ARow, const AnsiString KeyName,
      const AnsiString KeyValue)
{
    iniSetString(&ini
        ,ROOT_SECTION
        ,KeyName.c_str(), KeyValue.c_str(), /* style: */NULL);
}
//---------------------------------------------------------------------------
194 195 196 197 198 199 200
void __fastcall TServicesCfgDlg::ConfigureSoundButtonClick(TObject *Sender)
{
    SoundCfgDlg->sound = &MainForm->services_startup.sound;
    SoundCfgDlg->Caption = "Services Sound Configuration";
    SoundCfgDlg->ShowModal();
}
//---------------------------------------------------------------------------
201