void log_window::log_str(LOGT logflags, const std::string &str) { if (isshown) { txtct->AppendText(wxstrstd(str)); } else { pending.push(str); } }
LOGT StrToLogFlags(const std::string &str) { LOGT out = LOGT::ZERO; wxString wstr = wxstrstd(str); wxStringTokenizer tkz(wstr, wxT(",\t\r\n "), wxTOKEN_STRTOK); while (tkz.HasMoreTokens()) { wxString token = tkz.GetNextToken(); if (token == wxT("all")) { out |= LOGT::GROUP_ALL; } else if (token == wxT("error")) { out |= LOGT::GROUP_ERR; } else if (token == wxT("err")) { out |= LOGT::GROUP_ERR; } else if (token == wxT("def")) { out |= LOGT::GROUP_LOGWINDEF; } else if (token == wxT("default")) { out |= LOGT::GROUP_LOGWINDEF; } else { std::string stdtoken = stdstrwx(token); for (unsigned int i = 0; i < sizeof(logflagsstrings) / sizeof(logflagsstrings[0]); i++) { if (stdtoken == logflagsstrings[i]) { out |= flag_wrap<LOGT>(1 << i); break; } } } } return out; }
bool retcon::OnInit() { raii_set rs; //wxApp::OnInit(); //don't call this, it just calls the default command line processor SetAppName(appname); InitWxLogger(); rs.add([&]() { DeInitWxLogger(); }); ::wxInitAllImageHandlers(); srand((unsigned int) time(nullptr)); datadir = stdstrwx(wxStandardPaths::Get().GetUserDataDir()); cmdlineproc(argv, argc); if(terms_requested) return false; if(!globallogwindow) new log_window(nullptr, LOGT::GROUP_LOGWINDEF, false); if(!datadir.empty() && datadir.back() == '/') datadir.pop_back(); wxString wxdatadir = wxstrstd(datadir); if(!::wxDirExists(wxdatadir)) { ::wxMkdir(wxdatadir, 0700); } InitCFGDefaults(); SetTermSigHandler(); sm.InitMultiIOHandler(); rs.add([&]() { sm.DeInitMultiIOHandler(); }); bool res = DBC_Init(datadir + "/retcondb.sqlite3"); if(!res) return false; rs.add([&]() { DBC_DeInit(); }); if(terms_requested) return false; pool.reset(new ThreadPool::Pool(gc.threadpoollimit)); InitGlobalFilters(); RestoreWindowLayout(); if(mainframelist.empty()) { mainframe *mf = new mainframe( appversionname, wxPoint(50, 50), wxSize(450, 340)); if(alist.empty() && ad.tpanels.empty()) { //everything is empty, maybe new user //make 3 basic auto tpanels to make things more obvious auto flags = TPF::AUTO_ALLACCS | TPF::DELETEONWINCLOSE; auto tpt = tpanel::MkTPanel("", "", flags | TPF::AUTO_TW, 0); tpt->MkTPanelWin(mf, true); auto tpm = tpanel::MkTPanel("", "", flags | TPF::AUTO_MN, 0); tpm->MkTPanelWin(mf, false); auto tpd = tpanel::MkTPanel("", "", flags | TPF::AUTO_DM, 0); tpd->MkTPanelWin(mf, false); } } if(terms_requested) return false; mainframelist[0]->Show(true); for(auto it=alist.begin(); it!=alist.end(); ++it) { (*it)->Setup(); (*it)->CalcEnabled(); (*it)->Exec(); } if(terms_requested) return false; rs.cancel(); return true; }
void SetCacerts(CURL *handle) { static std::string cacertpath; if (cacertpath.empty()) { cacertpath = "./cacert.pem"; if (wxFile::Exists(wxstrstd(cacertpath))) { LogMsgFormat(LOGT::SOCKTRACE, "SetCacerts: found existing ./cacert.pem"); // There is an existing cacert.pem we can use, no need to create one } else { cacertpath = wxGetApp().datadir + "/cacert.pem"; LogMsgFormat(LOGT::SOCKTRACE, "SetCacerts: Writing out cacert.pem to: %s", cstr(cacertpath)); wxFFileOutputStream output(wxstrstd(cacertpath)); wxMemoryInputStream input(cacert_start, cacert_end - cacert_start); wxZlibInputStream zliber(input, wxZLIB_ZLIB); output.Write(zliber); LogMsgFormat(LOGT::SOCKTRACE, "SetCacerts: Writing out cacert.pem complete"); } } curl_easy_setopt(handle, CURLOPT_CAINFO, cacertpath.c_str()); }
void tpanelnotebook::tabrightclickhandler(wxAuiNotebookEvent& event) { tpanelparentwin *tppw = static_cast<tpanelparentwin *>(GetPage(event.GetSelection())); if (tppw) { wxMenu menu; menu.SetTitle(wxstrstd(tppw->pimpl()->tp->dispname)); menu.Append(TPPWID_SPLIT, wxT("Split")); menu.Append(TPPWID_DETACH, wxT("Detach")); menu.Append(TPPWID_DUP, wxT("Duplicate")); menu.Append(TPPWID_DETACHDUP, wxT("Detached Duplicate")); menu.Append(TPPWID_CLOSE, wxT("Close")); GenericPopupWrapper(tppw, &menu); } }
void log_window::LWShow(bool shown) { isshown = shown; if (shown) { while (!pending.empty()) { txtct->AppendText(wxstrstd(pending.front())); pending.pop(); } } Show(shown); if (shown) { Raise(); } }
int retcon::OnExit() { LogMsg(LOGT::OTHERTRACE, "retcon::OnExit"); sm.DeInitMultiIOHandler(); pool.reset(); DBC_DeInit(); for (const observer_ptr<temp_file_holder> &it : temp_file_set) { LogMsgFormat(LOGT::FILEIOTRACE, "retcon::OnExit, resetting: %s", cstr(it->GetFilename())); it->Reset(); } if (!::wxRmdir(wxstrstd(tmpdir))) { LogMsgFormat(LOGT::FILEIOERR, "retcon::OnExit, could not remove temp dir: %s", cstr(tmpdir)); } DebugFinalChecks(); DeInitWxLogger(); std::exit(0); }
void main_gui::trainwin::Redraw() { Freeze(); grid->BeginBatch(); if (grid->GetNumberRows()) { grid->DeleteRows(0, grid->GetNumberRows()); } w->EnumerateTrains([&](const train &t) { grid->AppendRows(1); int rowid = grid->GetNumberRows() - 1; grid->SetRowLabelValue(rowid, wxT("")); int colid = 0; for (auto &it : columns->columns) { grid->SetCellValue(rowid, colid++, wxstrstd(it.func(t))); } }); grid->EndBatch(); Thaw(); }
main_gui::trainwin::trainwin(std::shared_ptr<const world> w_, std::shared_ptr<gr_view_winlist> winlist_, std::unique_ptr<trainwin_columnset> columns_) : wxFrame(nullptr, wxID_ANY, wxT("Train list")), w(std::move(w_)), winlist(std::move(winlist_)), columns(std::move(columns_)) { winlist->trainwins.emplace_back(this); grid = new wxGrid(this, wxID_ANY, columns->columns.size(), 5, 5); grid->CreateGrid(0, 0); grid->EnableGridLines(true); grid->EnableEditing(false); grid->AppendCols(columns->columns.size()); int colid = 0; for (auto &it : columns->columns) { grid->SetColLabelValue(colid++, wxstrstd(it.name)); } Redraw(); timer = statictimer.lock(); if (!timer) { timer = std::make_shared<twtimer>(winlist); statictimer = timer; } }
log_window::log_window(wxWindow *parent, LOGT flagmask, bool show) : log_object(flagmask), wxFrame(parent, wxID_ANY, wxT("Log Window")) { globallogwindow = this; txtct = new wxTextCtrl(this, wxID_ANY, wxT(""), wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE | wxTE_READONLY | wxTE_NOHIDESEL | wxHSCROLL); wxBoxSizer *bs = new wxBoxSizer(wxVERTICAL); bs->Add(txtct, 1, wxALL | wxEXPAND, 3); wxGridSizer *hs = new wxGridSizer(5, 1, 4); log_window_AddChkBox(this, LOGT::GROUP_ALL, wxT("ALL"), hs); log_window_AddChkBox(this, LOGT::GROUP_ERR, wxT("ERRORS"), hs); log_window_AddChkBox(this, LOGT::GROUP_LOGWINDEF, wxT("DEFAULTS"), hs); for (size_t i = hs->GetChildren().GetCount(); (i % hs->GetCols()) != 0; i++) { hs->AddStretchSpacer(); } for (unsigned int i = 0; i < (sizeof(LOGT) * 8); i++) { if (flag_wrap<LOGT>(1 << i) & LOGT::GROUP_STR) { log_window_AddChkBox(this, flag_wrap<LOGT>(1 << i), wxstrstd(logflagsstrings[i]), hs); } } bs->Add(hs, 0, wxALL, 2); SetSizer(bs); wxMenu *menuF = new wxMenu; menuF->Append(wxID_SAVE, wxT("&Save Log")); menuF->Append(wxID_CLEAR, wxT("Clear Log")); menuF->Append(wxID_CLOSE, wxT("&Close")); debug_menu = new wxMenu; wxMenuBar *menuBar = new wxMenuBar; menuBar->Append(menuF, wxT("&File")); menuBar->Append(debug_menu, wxT("&Debug")); SetMenuBar(menuBar); InitDialog(); LWShow(show); }
std::string tpanelload_pending_op::dump() { std::shared_ptr<tpanel> tp=pushtpanel.lock(); tpanelparentwin_nt *window=win.get(); return string_format("Push tweet to tpanel: %s, window: %p, pushflags: 0x%X", (tp) ? cstr(wxstrstd(tp->dispname)) : "N/A", window, pushflags); }
void ThreadAlwaysLogMsg(LOGT logflags, const std::string &str) { wxCommandEvent evt(wxextLOGEVT, wxextLOGEVT_ID_THREADLOGMSG); evt.SetString(wxstrstd(str)); //prevent any COW semantics evt.SetExtraLong(flag_unwrap<LOGT>(logflags)); the_logevt_handler.AddPendingEvent(evt); }
filter_dlg::filter_dlg(wxWindow *parent, wxWindowID id, std::function<const tweetidset *()> getidset_, std::string srcname_, const wxPoint &pos, const wxSize &size) : wxDialog(parent, id, wxT("Apply Filter"), pos, size, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER), getidset(getidset_), srcname(std::move(srcname_)) { fdg.reset(new filter_dlg_gui); fdg->shared_state = std::make_shared<filter_dlg_shared_state>(); fdg->shared_state->srcname = srcname; fdg->hbox = new wxBoxSizer(wxHORIZONTAL); fdg->vbox = new wxBoxSizer(wxVERTICAL); fdg->hbox->Add(fdg->vbox, 1, wxALL | wxEXPAND, 0); if (!srcname.empty()) { wxStaticText *srcname_label = new wxStaticText(this, wxID_ANY, wxstrstd(srcname)); wxBoxSizer *hs = new wxBoxSizer(wxHORIZONTAL); hs->AddStretchSpacer(); hs->Add(srcname_label, 0, wxEXPAND | wxALIGN_CENTRE_VERTICAL | wxALIGN_CENTRE, 0); hs->AddStretchSpacer(); fdg->vbox->Add(hs, 0, wxEXPAND | wxALIGN_CENTRE_VERTICAL | wxALL, 4); } auto addblock = [&](wxString name) -> wxFlexGridSizer * { wxStaticBoxSizer *hbox1 = new wxStaticBoxSizer(wxVERTICAL, this, name); wxFlexGridSizer *fgsr = new wxFlexGridSizer(2, 2, 5); fgsr->SetFlexibleDirection(wxBOTH); fgsr->AddGrowableCol(2, 1); fdg->vbox->Add(hbox1, 0, wxALL | wxEXPAND | wxALIGN_TOP, 4); hbox1->Add(fgsr, 0, wxALL | wxEXPAND | wxALIGN_TOP, 4); return fgsr; }; wxFlexGridSizer *cb = addblock(wxT("Select items to filter")); int nextcheckboxid = ID_CHECKBOX_START; auto addcheckbox = [&](wxFlexGridSizer *fgs, const wxString &name, std::function<void(const tweetidset &, selection_category &)> func) -> wxCheckBox * { wxCheckBox *chk = new wxCheckBox(this, nextcheckboxid, name); fgs->Add(chk, 0, wxALIGN_LEFT | wxALIGN_CENTRE_VERTICAL, 4); wxSize chksz = chk->GetSize(); fgs->SetItemMinSize(chk, std::max(200, chksz.GetWidth()), chksz.GetHeight()); wxStaticText *stattxt = new wxStaticText(this, wxID_ANY, wxT("0")); fgs->Add(stattxt, 0, wxEXPAND | wxALIGN_LEFT | wxALIGN_CENTRE_VERTICAL, 4); selection_category &sc = checkboxmap[nextcheckboxid]; sc.func = std::move(func); sc.stattext = stattxt; sc.chk = chk; nextcheckboxid++; return chk; }; auto addcheckbox_intersection = [&](wxFlexGridSizer *fgs, const wxString &name, const tweetidset &intersect_with) -> wxCheckBox * { return addcheckbox(fgs, name, [this, &intersect_with](const tweetidset &in, selection_category &sc) { std::set_intersection(in.begin(), in.end(), intersect_with.begin(), intersect_with.end(), std::inserter(sc.output, sc.output.end()), in.key_comp()); }); }; addcheckbox(cb, wxT("All"), [this](const tweetidset &in, selection_category &sc) { sc.output_other = ∈ }); addcheckbox_intersection(cb, wxT("Unread"), ad.cids.unreadids); addcheckbox_intersection(cb, wxT("Highlighted"), ad.cids.highlightids); wxStaticText *total_label = new wxStaticText(this, wxID_ANY, wxT("Total")); cb->Add(total_label, 0, wxEXPAND | wxALIGN_LEFT | wxALIGN_CENTRE_VERTICAL, 4); fdg->total = new wxStaticText(this, wxID_ANY, wxT("Total selected")); cb->Add(fdg->total, 0, wxEXPAND | wxALIGN_LEFT | wxALIGN_CENTRE_VERTICAL, 4); { wxFlexGridSizer *lfgs = addblock(wxT("Limit")); fdg->limit_count_chk = new wxCheckBox(this, nextcheckboxid, wxT("First N")); lfgs->Add(fdg->limit_count_chk, 0, wxALIGN_LEFT | wxALIGN_CENTRE_VERTICAL, 4); wxSize chksz = fdg->limit_count_chk->GetSize(); lfgs->SetItemMinSize(fdg->limit_count_chk, std::max(200, chksz.GetWidth()), chksz.GetHeight()); fdg->limit_count_txt = new wxTextCtrl(this, ID_LIMIT_TXT, wxT("0"), wxDefaultPosition, wxDefaultSize, 0, wxTextValidator(wxFILTER_NUMERIC)); lfgs->Add(fdg->limit_count_txt, 0, wxEXPAND | wxALIGN_LEFT | wxALIGN_CENTRE_VERTICAL, 4); } wxStaticBoxSizer *filtersb = new wxStaticBoxSizer(wxVERTICAL, this, wxT("Filter")); fdg->vbox->Add(filtersb, 0, wxALL | wxEXPAND | wxALIGN_TOP, 4); FilterTextValidator filterval(fdg->shared_state->apply_filter, &fdg->apply_filter_txt); wxTextCtrl *filtertc = new wxTextCtrl(this, wxID_ANY, wxT(""), wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE, filterval); filtersb->Add(filtertc, 0, wxEXPAND | wxALIGN_LEFT | wxALIGN_CENTRE_VERTICAL, 4); wxBoxSizer *hboxfooter = new wxBoxSizer(wxHORIZONTAL); fdg->vbox->Add(hboxfooter, 0, wxALL | wxALIGN_RIGHT | wxALIGN_BOTTOM, 4); fdg->filterbtn = new wxButton(this, wxID_OK, wxT("")); wxButton *cancelbtn = new wxButton(this, wxID_CANCEL, wxT("Cancel")); hboxfooter->Add(fdg->filterbtn, 0, wxALL | wxALIGN_BOTTOM | wxALIGN_RIGHT, 2); hboxfooter->Add(cancelbtn, 0, wxALL | wxALIGN_BOTTOM | wxALIGN_RIGHT, 2); ReCalculateCategories(); SetSizer(fdg->hbox); fdg->hbox->Fit(this); wxSize initsize = GetSize(); SetSizeHints(initsize.GetWidth(), initsize.GetHeight(), 9000, initsize.GetHeight()); }