Skip to content

Commit

Permalink
Added FPP Device Selection based on Subnet, Added Sequence Selection …
Browse files Browse the repository at this point in the history
…from Batch Render. Consolidate IDs of right click options
  • Loading branch information
computergeek1507 committed Jan 4, 2025
1 parent cec6785 commit 4ce7104
Show file tree
Hide file tree
Showing 2 changed files with 138 additions and 50 deletions.
157 changes: 123 additions & 34 deletions xLights/controllers/FPPConnectDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <wx/config.h>
#include <wx/dir.h>
#include <wx/hyperlink.h>
#include <wx/choicdlg.h>

#include "FPPConnectDialog.h"
#include "xLightsMain.h"
Expand Down Expand Up @@ -38,33 +39,29 @@
#include <algorithm>

//(*IdInit(FPPConnectDialog)
const long FPPConnectDialog::ID_SCROLLEDWINDOW1 = wxNewId();
const long FPPConnectDialog::ID_STATICTEXT1 = wxNewId();
const long FPPConnectDialog::ID_CHOICE_FILTER = wxNewId();
const long FPPConnectDialog::ID_STATICTEXT2 = wxNewId();
const long FPPConnectDialog::ID_CHOICE_FOLDER = wxNewId();
const long FPPConnectDialog::ID_STATICTEXT3 = wxNewId();
const long FPPConnectDialog::ID_PANEL2 = wxNewId();
const long FPPConnectDialog::ID_PANEL1 = wxNewId();
const long FPPConnectDialog::ID_SPLITTERWINDOW1 = wxNewId();
const long FPPConnectDialog::ID_BUTTON1 = wxNewId();
const long FPPConnectDialog::ID_BUTTON_Upload = wxNewId();
const wxWindowID FPPConnectDialog::ID_SCROLLEDWINDOW1 = wxNewId();
const wxWindowID FPPConnectDialog::ID_STATICTEXT1 = wxNewId();
const wxWindowID FPPConnectDialog::ID_CHOICE_FILTER = wxNewId();
const wxWindowID FPPConnectDialog::ID_STATICTEXT2 = wxNewId();
const wxWindowID FPPConnectDialog::ID_CHOICE_FOLDER = wxNewId();
const wxWindowID FPPConnectDialog::ID_STATICTEXT3 = wxNewId();
const wxWindowID FPPConnectDialog::ID_PANEL2 = wxNewId();
const wxWindowID FPPConnectDialog::ID_PANEL1 = wxNewId();
const wxWindowID FPPConnectDialog::ID_SPLITTERWINDOW1 = wxNewId();
const wxWindowID FPPConnectDialog::ID_BUTTON1 = wxNewId();
const wxWindowID FPPConnectDialog::ID_BUTTON_Upload = wxNewId();
//*)

const long FPPConnectDialog::ID_MNU_SELECTALL = wxNewId();
const long FPPConnectDialog::ID_MNU_SELECTNONE = wxNewId();
const long FPPConnectDialog::ID_MNU_SELECTHIGH = wxNewId();
const long FPPConnectDialog::ID_MNU_DESELECTHIGH = wxNewId();
const long FPPConnectDialog::ID_FPP_INSTANCE_LIST = wxNewId();

static const long ID_FPP_INSTANCE_LIST = wxNewId();

static const long ID_POPUP_MNU_SORT_NAME = wxNewId();
static const long ID_POPUP_MNU_SORT_IP = wxNewId();
static const long ID_POPUP_MNU_SELECT_ALL = wxNewId();
static const long ID_POPUP_MNU_DESELECT_ALL = wxNewId();
static const long ID_POPUP_MNU_CAPE_SELECT_ALL = wxNewId();
static const long ID_POPUP_MNU_CAPE_DESELECT_ALL = wxNewId();
static const long ID_POPUP_MNU_MEDIA_DESELECT_ALL = wxNewId();
static const long ID_POPUP_MNU_SELECT_HIGH = wxNewId();
static const long ID_POPUP_MNU_DESELECT_HIGH = wxNewId();
static const long ID_POPUP_MNU_SELECT_BATCH = wxNewId();
static const long ID_POPUP_MNU_SELECT_SUBNET = wxNewId();

wxString locationSortCol = "ip";

Expand Down Expand Up @@ -377,8 +374,8 @@ void FPPConnectDialog::IPSortMenu(wxContextMenuEvent& event) {
void FPPConnectDialog::CapePopupMenu(wxContextMenuEvent& event)
{
wxMenu mnu;
mnu.Append(ID_POPUP_MNU_CAPE_SELECT_ALL, "Select All");
mnu.Append(ID_POPUP_MNU_CAPE_DESELECT_ALL, "Deselect All");
mnu.Append(ID_POPUP_MNU_SELECT_ALL, "Select All");
mnu.Append(ID_POPUP_MNU_DESELECT_ALL, "Deselect All");
mnu.Connect(wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(FPPConnectDialog::OnCapePopupClick), NULL, this);
PopupMenu(&mnu);
}
Expand All @@ -391,9 +388,9 @@ void FPPConnectDialog::OnCapePopupClick(wxCommandEvent& event)
if (inst->fppType == FPP_TYPE::FPP) {
if (inst->supportedForFPPConnect()) {
std::string rowStr = std::to_string(row);
if (event.GetId() == ID_POPUP_MNU_CAPE_SELECT_ALL) {
if (event.GetId() == ID_POPUP_MNU_SELECT_ALL) {
SetCheckValue(UPLOAD_CONTROLLER_COL + rowStr, true);
} else if (event.GetId() == ID_POPUP_MNU_CAPE_DESELECT_ALL) {
} else if (event.GetId() == ID_POPUP_MNU_DESELECT_ALL) {
SetCheckValue(UPLOAD_CONTROLLER_COL + rowStr, false);
}
}
Expand All @@ -406,11 +403,16 @@ void FPPConnectDialog::UploadPopupMenu(wxContextMenuEvent& event) {
wxMenu mnu;
mnu.Append(ID_POPUP_MNU_SELECT_ALL, "Select All");
mnu.Append(ID_POPUP_MNU_DESELECT_ALL, "Deselect All");
mnu.Append(ID_POPUP_MNU_SELECT_SUBNET, "Select Subnet");
mnu.Connect(wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(FPPConnectDialog::OnUploadPopupClick), NULL, this);
PopupMenu(&mnu);
}

void FPPConnectDialog::OnUploadPopupClick(wxCommandEvent& event) {
if (ID_POPUP_MNU_SELECT_SUBNET == event.GetId()) {
SelectIPsWithSubnet();
return;
}
int row = 0;
for (const auto& inst : instances) {
std::string l = inst->hostName + " - " + inst->ipAddress;
Expand All @@ -428,9 +430,43 @@ void FPPConnectDialog::OnUploadPopupClick(wxCommandEvent& event) {
}
}

void FPPConnectDialog::SelectIPsWithSubnet() {
wxArrayString subs;
for (const auto& inst : instances) {

wxString const& sub_net = BeforeLast(inst->ipAddress, '.') + ".0";
if (wxNOT_FOUND == subs.Index(sub_net)) {
subs.push_back(sub_net);
}
}
wxString const& message = "Select Subnet";
wxSingleChoiceDialog dlg(this, message, message, subs);

if (dlg.ShowModal() != wxID_OK) {
// return dlg.GetStringSelection();
return;
}

std::string const& subnet = dlg.GetStringSelection();
int row { 0 };
for (const auto& inst : instances) {
if (inst->fppType == FPP_TYPE::FPP) {
if (inst->supportedForFPPConnect()) {
std::string rowStr = std::to_string(row);
if (IsInSameSubnet(subnet, inst->ipAddress)) {
SetCheckValue(CHECK_COL + rowStr, true);
} else {
SetCheckValue(CHECK_COL + rowStr, false);
}
}
}
row++;
}
}

void FPPConnectDialog::MediaPopupMenu(wxContextMenuEvent& event) {
wxMenu mnu;
mnu.Append(ID_POPUP_MNU_MEDIA_DESELECT_ALL, "Deselect All");
mnu.Append(ID_POPUP_MNU_DESELECT_ALL, "Deselect All");
mnu.Connect(wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(FPPConnectDialog::OnMediaPopupClick), NULL, this);
PopupMenu(&mnu);
}
Expand All @@ -442,7 +478,7 @@ void FPPConnectDialog::OnMediaPopupClick(wxCommandEvent& event) {
if (inst->fppType == FPP_TYPE::FPP) {
if (inst->supportedForFPPConnect()) {
std::string rowStr = std::to_string(row);
if (event.GetId() == ID_POPUP_MNU_MEDIA_DESELECT_ALL) {
if (event.GetId() == ID_POPUP_MNU_DESELECT_ALL) {
SetCheckValue(MEDIA_COL + rowStr, false);
}
}
Expand Down Expand Up @@ -657,24 +693,76 @@ void FPPConnectDialog::AddInstanceRow(const FPP &inst) {
void FPPConnectDialog::OnPopup(wxCommandEvent &event)
{
int id = event.GetId();
if (ID_POPUP_MNU_SELECT_BATCH == id) {
SelectBatchRenderSeq();
return;
}
wxTreeListItem item = CheckListBox_Sequences->GetFirstItem();
while (item.IsOk()) {
bool isChecked = CheckListBox_Sequences->GetCheckedState(item) == wxCHK_CHECKED;
bool isSelected = CheckListBox_Sequences->IsSelected(item);
if (id == ID_MNU_SELECTALL && !isChecked) {
if (id == ID_POPUP_MNU_SELECT_ALL && !isChecked) {
CheckListBox_Sequences->CheckItem(item);
} else if (id == ID_MNU_SELECTNONE && isChecked) {
} else if (id == ID_POPUP_MNU_DESELECT_ALL && isChecked) {
CheckListBox_Sequences->UncheckItem(item);
} else if (id == ID_MNU_SELECTHIGH && isSelected) {
} else if (id == ID_POPUP_MNU_SELECT_HIGH && isSelected) {
CheckListBox_Sequences->CheckItem(item);
} else if (id == ID_MNU_DESELECTHIGH && isSelected) {
} else if (id == ID_POPUP_MNU_DESELECT_HIGH && isSelected) {
CheckListBox_Sequences->UncheckItem(item);
}
item = CheckListBox_Sequences->GetNextItem(item);
}
UpdateSeqCount();
}

void FPPConnectDialog::SelectBatchRenderSeq() {

wxConfigBase* config = wxConfigBase::Get();
if (nullptr == config) {
return;
}
wxString itcsv;
config->Read("BatchRendererItemList", &itcsv, "");

if (!itcsv.IsEmpty()) {
auto const& savedBatchItems = wxSplit(itcsv, ',');
xLightsFrame* frame = static_cast<xLightsFrame*>(GetParent());
wxString const& showDirectory = frame->GetShowDirectory();
wxString const& fseqDirectory = frame->GetFseqDirectory();

if (savedBatchItems.empty()) {
return;
}
auto uitem = CheckListBox_Sequences->GetFirstItem();
while (uitem.IsOk()) {
auto const& isChecked = CheckListBox_Sequences->GetCheckedState(uitem) == wxCHK_CHECKED;
if (isChecked) {
CheckListBox_Sequences->UncheckItem(uitem);
}
uitem = CheckListBox_Sequences->GetNextItem(uitem);
}
for (auto const& bat_seq : savedBatchItems) {
auto const& xsqName = showDirectory + wxFileName::GetPathSeparator() + bat_seq;
wxFileName fseqFile(xsqName);
fseqFile.SetExt("fseq");

if (fseqDirectory != showDirectory) {
fseqFile.SetPath(fseqDirectory);
}
auto const& fseqName = fseqFile.GetFullPath();
auto item = CheckListBox_Sequences->GetFirstItem();
while (item.IsOk()) {
if (CheckListBox_Sequences->GetItemText(item) == fseqName) {
CheckListBox_Sequences->CheckItem(item);
break;
}
item = CheckListBox_Sequences->GetNextItem(item);
}
}
UpdateSeqCount();
}
}

FPPConnectDialog::~FPPConnectDialog()
{
unsigned int sortCol = SORT_SEQ_NAME_COL;
Expand Down Expand Up @@ -1491,10 +1579,11 @@ void FPPConnectDialog::OnClose(wxCloseEvent& event)
void FPPConnectDialog::SequenceListPopup(wxTreeListEvent& event)
{
wxMenu mnu;
mnu.Append(ID_MNU_SELECTALL, "Select All");
mnu.Append(ID_MNU_SELECTNONE, "Clear Selections");
mnu.Append(ID_MNU_SELECTHIGH, "Select Highlighted");
mnu.Append(ID_MNU_DESELECTHIGH, "Deselect Highlighted");
mnu.Append(ID_POPUP_MNU_SELECT_ALL, "Select All");
mnu.Append(ID_POPUP_MNU_DESELECT_ALL, "Clear Selections");
mnu.Append(ID_POPUP_MNU_SELECT_HIGH, "Select Highlighted");
mnu.Append(ID_POPUP_MNU_DESELECT_HIGH, "Deselect Highlighted");
mnu.Append(ID_POPUP_MNU_SELECT_BATCH, "Select Batch Render");
mnu.Connect(wxEVT_MENU, (wxObjectEventFunction)&FPPConnectDialog::OnPopup, nullptr, this);
PopupMenu(&mnu);
}
Expand Down
31 changes: 15 additions & 16 deletions xLights/controllers/FPPConnectDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,24 +53,20 @@ class FPPConnectDialog: public wxDialog
protected:

//(*Identifiers(FPPConnectDialog)
static const long ID_SCROLLEDWINDOW1;
static const long ID_STATICTEXT1;
static const long ID_CHOICE_FILTER;
static const long ID_STATICTEXT2;
static const long ID_CHOICE_FOLDER;
static const long ID_STATICTEXT3;
static const long ID_PANEL2;
static const long ID_PANEL1;
static const long ID_SPLITTERWINDOW1;
static const long ID_BUTTON1;
static const long ID_BUTTON_Upload;
static const wxWindowID ID_SCROLLEDWINDOW1;
static const wxWindowID ID_STATICTEXT1;
static const wxWindowID ID_CHOICE_FILTER;
static const wxWindowID ID_STATICTEXT2;
static const wxWindowID ID_CHOICE_FOLDER;
static const wxWindowID ID_STATICTEXT3;
static const wxWindowID ID_PANEL2;
static const wxWindowID ID_PANEL1;
static const wxWindowID ID_SPLITTERWINDOW1;
static const wxWindowID ID_BUTTON1;
static const wxWindowID ID_BUTTON_Upload;
//*)

static const long ID_MNU_SELECTALL;
static const long ID_MNU_SELECTNONE;
static const long ID_MNU_SELECTHIGH;
static const long ID_MNU_DESELECTHIGH;
static const long ID_FPP_INSTANCE_LIST;



std::list<FPP*> instances;
Expand Down Expand Up @@ -123,6 +119,9 @@ class FPPConnectDialog: public wxDialog
void doUpload(FPPUploadProgressDialog *prgs, std::vector<bool> doUpload);
std::vector<int> SplitIP(const wxString& ip) const;

void SelectBatchRenderSeq();
void SelectIPsWithSubnet();

DECLARE_EVENT_TABLE()
};

Expand Down

0 comments on commit 4ce7104

Please sign in to comment.