bool CAutoAsciiFiles::TransferRemoteAsAscii(wxString const& remote_file, ServerType server_type)
{
	int mode = COptions::Get()->GetOptionVal(OPTION_ASCIIBINARY);
	if (mode == 1)
		return true;
	else if (mode == 2)
		return false;

	if (server_type == VMS) {
		return TransferRemoteAsAscii(StripVMSRevision(remote_file.ToStdWstring()), DEFAULT);
	}

	if (!remote_file.empty() && remote_file[0] == '.')
		return COptions::Get()->GetOptionVal(OPTION_ASCIIDOTFILE) != 0;

	int pos = remote_file.Find('.', true);
	if (pos < 0 || static_cast<unsigned int>(pos) + 1 == remote_file.size()) {
		return COptions::Get()->GetOptionVal(OPTION_ASCIINOEXT) != 0;
	}
	wxString ext = remote_file.Mid(pos + 1);

	for (auto const& ascii_ext : m_ascii_extensions) {
		if (!ext.CmpNoCase(ascii_ext)) {
			return true;
		}
	}

	return false;
}
예제 #2
0
wxString Model_CustomField::getDefault(const wxString& Properties)
{
    json::Object jsonProperties;
    std::wstringstream jsonPropertiesStream;

    jsonPropertiesStream << Properties.ToStdWstring();
    json::Reader::Read(jsonProperties, jsonPropertiesStream);
    return wxString(json::String(jsonProperties[L"Default"]));
}
예제 #3
0
bool Model_CustomField::getAutocomplete(const wxString& Properties)
{
    json::Object jsonProperties;
    std::wstringstream jsonPropertiesStream;

    jsonPropertiesStream << Properties.ToStdWstring();
    json::Reader::Read(jsonProperties, jsonPropertiesStream);
    return json::Boolean(jsonProperties[L"Autocomplete"]);
}
예제 #4
0
wxString GetAsURL(wxString const& dir)
{
	// Cheap URL encode
	wxString encoded;
	std::string utf8 = fz::to_utf8(dir.ToStdWstring());

	char const* p = utf8.c_str();
	while (*p) {
		// List of characters that don't need to be escaped taken
		// from the BNF grammar in RFC 1738
		// Again attention seeking Windows wants special treatment...
		const unsigned char c = (unsigned char)*p++;
		if ((c >= 'a' && c <= 'z') ||
			(c >= 'A' && c <= 'Z') ||
			(c >= '0' && c <= '9') ||
			c == '$' ||
			c == '_' ||
			c == '-' ||
			c == '.' ||
			c == '+' ||
			c == '!' ||
			c == '*' ||
#ifndef __WXMSW__
			c == '\'' ||
#endif
			c == '(' ||
			c == ')' ||
			c == ',' ||
			c == '?' ||
			c == ':' ||
			c == '@' ||
			c == '&' ||
			c == '=' ||
			c == '/')
		{
			encoded += (wxChar)c;
		}
#ifdef __WXMSW__
		else if (c == '\\') {
			encoded += '/';
		}
#endif
		else
			encoded += wxString::Format(_T("%%%x"), (unsigned int)c);
	}
#ifdef __WXMSW__
	if (encoded.Left(2) == _T("//")) {
		// UNC path
		encoded = encoded.Mid(2);
	}
	else {
		encoded = _T("/") + encoded;
	}
#endif
	return _T("file://") + encoded;
}
예제 #5
0
const wxString mmHomePagePanel::displayGrandTotals(double& tBalance)
{
    json::Object o;
    std::wstringstream ss;

    const wxString tBalanceStr = Model_Currency::toCurrency(tBalance);

    o[L"NAME"] = json::String(_("Grand Total:").ToStdWstring());
    o[L"VALUE"] = json::String(tBalanceStr.ToStdWstring());

    json::Writer::Write(o, ss);
    return ss.str();
}
예제 #6
0
wxString Model_CustomField::formatProperties(const wxString& Tooltip, const wxString& RegEx, bool Autocomplete, const wxString& Default, const wxArrayString& Choices)
{
    json::Object jsonProperties;
    std::wstringstream jsonPropertiesStream;
    json::Array jsonChoices;
    wxString outputMessage;

    jsonProperties[L"Tooltip"] = json::String(Tooltip.ToStdWstring());
    jsonProperties[L"RegEx"] = json::String(RegEx.ToStdWstring());
    jsonProperties[L"Autocomplete"] = json::Boolean(Autocomplete);
    jsonProperties[L"Default"] = json::String(Default.ToStdWstring());

    for (const auto &choice : Choices)
    {
        json::Object o;
        o[L"Choice"] = json::String(choice.ToStdWstring());
        jsonChoices.Insert(o);
    }
    jsonProperties[L"Choices"] = json::Array(jsonChoices);

    json::Writer::Write(jsonProperties, jsonPropertiesStream);
    return jsonPropertiesStream.str();
}
예제 #7
0
wxArrayString Model_CustomField::getChoices(const wxString& Properties)
{
    json::Object jsonProperties;
    std::wstringstream jsonPropertiesStream;
    wxArrayString Choices;

    jsonPropertiesStream << Properties.ToStdWstring();
    json::Reader::Read(jsonProperties, jsonPropertiesStream);

    const json::Array& jsonChoices = jsonProperties[L"Choices"];
    for (json::Array::const_iterator it = jsonChoices.Begin(); it != jsonChoices.End(); ++it)
    {
        const json::Object& obj = *it;
        Choices.Add(wxString(json::String(obj[L"Choice"])));
    }

    return Choices;
}
예제 #8
0
void PropertiesDialog::OnLanguageValueChanged(const wxString& langstr)
{
    Language lang = Language::TryParse(langstr.ToStdWstring());
    wxString pluralForm = lang.DefaultPluralFormsExpr();
    if (pluralForm.empty())
    {
        m_pluralFormsDefault->Disable();
        m_pluralFormsCustom->SetValue(true);
    }
    else
    {
        m_pluralFormsDefault->Enable();
        if (m_pluralFormsExpr->GetValue().empty() ||
            m_pluralFormsExpr->GetValue() == pluralForm)
        {
            m_pluralFormsDefault->SetValue(true);
        }
    }
}
예제 #9
0
mm_html_template::mm_html_template(const wxString& arg_template): html_template(arg_template.ToStdWstring())
{
    this->load_context();
}
예제 #10
0
wxString Model_Report::get_html(const Data* r)
{
    mm_html_template report(r->TEMPLATECONTENT);
    r->to_template(report);

    loop_t contents;

    loop_t errors;
    row_t error;

    wxSQLite3ResultSet q;
    int columnCount = 0;
    wxString sql = r->SQLCONTENT;
    std::map <wxString, wxString> rep_params;
    try
    {
        PrepareSQL(sql, rep_params);

        wxSQLite3Statement stmt = this->db_->PrepareStatement(sql);
        if (!stmt.IsReadOnly())
        {
            return wxString::Format(_("The SQL script:\n%s \nwill modify database! aborted!"), r->SQLCONTENT);
        }
        else
        {
            q = stmt.ExecuteQuery();
            columnCount = q.GetColumnCount();
        }
    }
    catch (const wxSQLite3Exception& e)
    {
        return e.GetMessage();
    }

    std::map <std::wstring, int> colHeaders;

    loop_t columns;
    for (int i = 0; i < columnCount; ++i)
    {
        int col_type = q.GetColumnType(i);
        const std::wstring col_name = q.GetColumnName(i).ToStdWstring();
        colHeaders[col_name] = col_type;
        row_t row;
        row(L"COLUMN") = col_name;
        columns += row;
    }
    report(L"COLUMNS") = columns;

    LuaGlue state;
    state.
        Class<Record>("Record").
        ctor("new").
        method("get", &Record::get).
        method("set", &Record::set).
        end().open().glue();

    bool skip_lua = r->LUACONTENT.IsEmpty();
    bool lua_status = state.doString(std::string(r->LUACONTENT.ToUTF8()));
    if (!skip_lua && !lua_status)
    {
        error(L"ERROR") = wxString("failed to doString : ") + r->LUACONTENT + wxString(" err: ") + wxString(state.lastError());
        errors += error;
    }

    while (q.NextRow())
    {
        Record rec;
        for (int i = 0; i < columnCount; ++i)
        {
            const wxString column_name = q.GetColumnName(i);
            rec[column_name.ToStdWstring()] = q.GetAsString(i);
        }

        if (lua_status && !skip_lua)
        {
            try
            {
                state.invokeVoidFunction("handle_record", &rec);
            }
            catch (const std::runtime_error& e)
            {
                error(L"ERROR") = wxString("failed to call handle_record : ") + wxString(e.what());
                errors += error;
            }
            catch (const std::exception& e)
            {
                error(L"ERROR") = wxString("failed to call handle_record : ") + wxString(e.what());
                errors += error;
            }
            catch (...)
            {
                error(L"ERROR") = L"failed to call handle_record ";
                errors += error;
            }
        }
        row_t row;
        for (const auto& item : rec)
        {
            row(item.first) = item.second;
        }
        contents += row;

    }
    q.Finalize();

    Record result;
    if (lua_status && !skip_lua)
    {
        try
        {
            state.invokeVoidFunction("complete", &result);
        }
        catch (const std::runtime_error& e)
        {
            error(L"ERROR") = wxString("failed to call complete: ") + wxString(e.what());
            errors += error;
        }
        catch (const std::exception& e)
        {
            error(L"ERROR") = wxString("failed to call complete: ") + wxString(e.what());
            errors += error;
        }
        catch (...)
        {
            error(L"ERROR") = L"failed to call complete";
            errors += error;
        }
    }

    for (const auto& item : result)
        report(item.first) = item.second;

    report(L"CONTENTS") = contents;
    {
        for (const auto& item : rep_params)
        {
            report(item.first.Upper().ToStdWstring()) = item.second;
        }
        auto p = mmex::getPathAttachment(mmAttachmentManage::InfotablePathSetting());
        //javascript does not handle backslashs
        p.Replace("\\", "\\\\");
        report(L"ATTACHMENTSFOLDER") = p;
        auto s = wxString(wxFileName::GetPathSeparator());
        s.Replace("\\", "\\\\");
        report(L"FILESEPARATOR") = s;
        report(L"LANGUAGE") = Option::instance().LanguageISO6391();
        report(L"HTMLSCALE") = wxString::Format("%d", Option::instance().HtmlFontSize());
    }
    report(L"ERRORS") = errors;

    wxString out = wxEmptyString;
    try 
    {
        out = report.Process();
    }
    catch (const syntax_ex& e)
    {
        return e.what();
    }
    catch (...)
    {
        return _("Caught exception");
    }

    return out;
}
wxString mmFilterTransactionsDialog::to_json()
{
    json::Object o;
    o.Clear();
    const wxString label = m_settingLabel->GetValue().Trim();
    if (!label.empty()) o[L"LABEL"] = json::String(label.ToStdWstring());
    if (accountCheckBox_->IsChecked())
    {
        const wxString acc = accountDropDown_->GetStringSelection();
        if (!acc.empty()) o[L"ACCOUNT"] = json::String(acc.ToStdWstring());
    }
    if (dateRangeCheckBox_->IsChecked())
    {
        o[L"DATE1"] = json::String(fromDateCtrl_->GetValue().FormatISODate().ToStdWstring());
        o[L"DATE2"] = json::String(toDateControl_->GetValue().FormatISODate().ToStdWstring());
    }
    if (payeeCheckBox_->IsChecked())
    {
        wxString wxpayee = cbPayee_->GetValue();
        //TODO: Here is big problem for UTF8 usage!!! wxString::ToStdString() does not working
        //for some strings like Kubalíková
        //but cyrillic working Николай = Николай (Николай)
        //Kubalíková ----> KubalГ­kovГЎ
        wxCharBuffer buffer = wxpayee.ToUTF8();
        std::string str_std(buffer.data(), strlen(buffer.data()));
        std::wstring test = wxpayee.ToStdWstring();
        wxLogDebug("utf8: %s|to_chars %s|from_chars %s|std::string: %s"
            , wxpayee, str_std, wxString(str_std.c_str(), wxConvUTF8), test);

        if (!test.empty()) o[L"PAYEE"] = json::String(test);
    }
    if (categoryCheckBox_->IsChecked())
    {
        o[L"SIMILAR_YN"] = json::Boolean(bSimilarCategoryStatus_);
        o[L"CATEGORY"] = json::String(btnCategory_->GetLabel().ToStdWstring());
    }
    if (statusCheckBox_->IsChecked())
    {
        int item = choiceStatus_->GetSelection();
        wxString status;
        if (0 <= item && item < (int)Model_Checking::all_status().size())
            status = Model_Checking::all_status()[item];
        if (!status.empty()) o[L"STATUS"] = json::String(status.ToStdWstring());
    }
    if (typeCheckBox_->IsChecked())
    {
        wxString type = wxString()
            << (cbTypeWithdrawal_->GetValue() && typeCheckBox_->GetValue() ? "W" : "")
            << (cbTypeDeposit_->GetValue() && typeCheckBox_->GetValue() ? "D" : "")
            << (cbTypeTransferTo_->GetValue() && typeCheckBox_->GetValue() ? "T" : "")
            << (cbTypeTransferFrom_->GetValue() && typeCheckBox_->GetValue() ? "F" : "");
        if (!type.empty()) o[L"TYPE"] = json::String(type.ToStdWstring());
    }

    if (amountRangeCheckBox_->IsChecked())
    {
        if (!amountMinEdit_->GetValue().empty())
        {
            double amount_min;
            amountMinEdit_->GetDouble(amount_min);
            o[L"AMOUNT_MIN"] = json::Number(amount_min);
        }
        if (!amountMaxEdit_->GetValue().empty())
        {
            double amount_max;
            amountMaxEdit_->GetDouble(amount_max);
            o[L"AMOUNT_MAX"] = json::Number(amount_max);
        }
    }
    if (transNumberCheckBox_->IsChecked())
    {
        const wxString num = transNumberEdit_->GetValue();
        if (!num.empty()) o[L"NUMBER"] = json::String(num.ToStdWstring());
    }
    if (notesCheckBox_->IsChecked())
    {
        const wxString notes = notesEdit_->GetValue();
        if (!notes.empty()) o[L"NOTES"] = json::String(notes.ToStdWstring());
    }

    std::wstringstream ss;
    json::Writer::Write(o, ss);
    return ss.str();
}
예제 #12
0
void DatabaseCanvas::AddQuickQueryFields(const wxString &tbl, std::vector<Field *> &quickSelectFields, bool quickSelect)
{
    ShapeList shapes;
    m_pManager.GetShapes( CLASSINFO( FieldShape ), shapes );
    for( ShapeList::iterator it = shapes.begin (); it != shapes.end (); ++it )
    {
        auto fld = wxDynamicCast( (*it), FieldShape );
        auto fieldName = wxDynamicCast( (*it), FieldShape )->GetField()->GetFieldName();
        auto found = false;
        for( std::vector<Field *>::iterator it2 = quickSelectFields.begin(); it2 < quickSelectFields.end() && !false; ++it2 )
        {
            if( (*it2)->GetFieldName() == fieldName )
            {
                found = true;
                (*it)->Select( true );
                dynamic_cast<DrawingView *>( m_view )->AddFieldToQuery( *fld, fld->IsSelected(), tbl.ToStdWstring(), quickSelect );
            }
        }
    }
    Refresh();
}
예제 #13
0
wxString Model_Report::get_html(const Data* r)
{
    mm_html_template report(r->TEMPLATECONTENT);
    r->to_template(report);

    loop_t contents;
    json::Array jsoncontents;

    loop_t errors;
    row_t error;

    wxSQLite3ResultSet q;
    int columnCount = 0;
    try
    {
        wxString sql = r->SQLCONTENT;
        sql.Trim();
        if (!sql.empty() && sql.Last() != ';') sql += ';';
        wxSQLite3Statement stmt = this->db_->PrepareStatement(sql);
        if (!stmt.IsReadOnly())
        {
            return wxString::Format(_("The SQL script:\n%s \nwill modify database! aborted!"), r->SQLCONTENT);
        }
        else
        {
            q = stmt.ExecuteQuery();
            columnCount = q.GetColumnCount();
        }
    }
    catch (const wxSQLite3Exception& e)
    {
        return e.GetMessage();
    }

    std::map <std::wstring, int> colHeaders;

    loop_t columns;
    for (int i = 0; i < columnCount; ++i)
    {
        int col_type = q.GetColumnType(i);
        const std::wstring col_name = q.GetColumnName(i).ToStdWstring();
        colHeaders[col_name] = col_type;
        row_t row;
        row(L"COLUMN") = col_name;
        columns += row;
    }
    report(L"COLUMNS") = columns;

    LuaGlue state;
    state.
        Class<Record>("Record").
        ctor("new").
        method("get", &Record::get).
        method("set", &Record::set).
        end().open().glue();

    bool skip_lua = r->LUACONTENT.IsEmpty();
    bool lua_status = state.doString(std::string(r->LUACONTENT.ToUTF8()));
    if (!skip_lua && !lua_status)
    {
        error(L"ERROR") = wxString("failed to doString : ") + r->LUACONTENT + wxString(" err: ") + wxString(state.lastError());
        errors += error;
    }

    while (q.NextRow())
    {
        Record rec;
        for (int i = 0; i < columnCount; ++i)
        {
            const wxString column_name = q.GetColumnName(i);
            rec[column_name.ToStdWstring()] = q.GetAsString(i);
        }

        if (lua_status && !skip_lua)
        {
            try
            {
                state.invokeVoidFunction("handle_record", &rec);
            }
            catch (const std::runtime_error& e)
            {
                error(L"ERROR") = wxString("failed to call handle_record : ") + wxString(e.what());
                errors += error;
            }
            catch (const std::exception& e)
            {
                error(L"ERROR") = wxString("failed to call handle_record : ") + wxString(e.what());
                errors += error;
            }
            catch (...)
            {
                error(L"ERROR") = L"failed to call handle_record ";
                errors += error;
            }
        }
        row_t row;
        json::Object o;
        for (const auto& item : rec)
        {
            row(item.first) = item.second;

            double v;
            if ((colHeaders[item.first] == WXSQLITE_INTEGER || colHeaders[item.first] == WXSQLITE_FLOAT)
                && wxString(item.second).ToDouble(&v))
            {
                o[wxString(item.first).ToStdWstring()] = json::Number(v);
            }
            else
                o[wxString(item.first).ToStdWstring()] = json::String(wxString(item.second).ToStdWstring());
        }
        contents += row;
        jsoncontents.Insert(o);

    }
    q.Finalize();

    Record result;
    if (lua_status && !skip_lua)
    {
        try
        {
            state.invokeVoidFunction("complete", &result);
        }
        catch (const std::runtime_error& e)
        {
            error(L"ERROR") = wxString("failed to call complete: ") + wxString(e.what());
            errors += error;
        }
        catch (const std::exception& e)
        {
            error(L"ERROR") = wxString("failed to call complete: ") + wxString(e.what());
            errors += error;
        }
        catch (...)
        {
            error(L"ERROR") = L"failed to call complete";
            errors += error;
        }
    }

    for (const auto& item : result)
        report(item.first) = item.second;

    report(L"CONTENTS") = contents;
    {
        std::wstringstream ss;
        json::Writer::Write(jsoncontents, ss);
        report(L"JSONCONTENTS") = wxString(ss.str());
        auto p = mmex::getPathAttachment(mmAttachmentManage::InfotablePathSetting());
        //javascript does not handle backslashs
        p.Replace("\\", "\\\\");
        report(L"ATTACHMENTSFOLDER") = p;
        auto s = wxString(wxFileName::GetPathSeparator());
        s.Replace("\\", "\\\\");
        report(L"FILESEPARATOR") = s;
        report(L"LANGUAGE") = Model_Setting::instance().GetStringSetting(LANGUAGE_PARAMETER, "english");
        report(L"HTMLSCALE") = wxString::Format("%d", mmIniOptions::instance().html_font_size_);
    }
    report(L"ERRORS") = errors;

    wxString out = wxEmptyString;
    try 
    {
        out = report.Process();
    }
    catch (const syntax_ex& e)
    {
        out = e.what();
    }
    catch (...)
    {
        // TODO
    }

    outputReportFile(out);
    return out;
}
예제 #14
0
bool CWelcomeDialog::Run(wxWindow* parent, bool force /*=false*/, bool delay /*=false*/)
{
	const wxString ownVersion = CBuildInfo::GetVersion();
	wxString greetingVersion = COptions::Get()->GetOption(OPTION_GREETINGVERSION);

	wxString const resources = COptions::Get()->GetOption(OPTION_GREETINGRESOURCES);
	COptions::Get()->SetOption(OPTION_GREETINGRESOURCES, _T(""));

	if (!force) {
		if (COptions::Get()->GetOptionVal(OPTION_DEFAULT_KIOSKMODE) == 2) {
			if (delay)
				delete this;
			return true;
		}

		if (!greetingVersion.empty() &&
			CBuildInfo::ConvertToVersionNumber(ownVersion.c_str()) <= CBuildInfo::ConvertToVersionNumber(greetingVersion.c_str()))
		{
			// Been there done that
			if (delay)
				delete this;
			return true;
		}
		COptions::Get()->SetOption(OPTION_GREETINGVERSION, ownVersion.ToStdWstring());

		if (greetingVersion.empty() && !COptions::Get()->GetOptionVal(OPTION_DEFAULT_KIOSKMODE))
			COptions::Get()->SetOption(OPTION_PROMPTPASSWORDSAVE, 1);
	}

	if (!Load(parent, _T("ID_WELCOME"))) {
		if (delay) {
			delete this;
		}
		return false;
	}

	InitFooter(force ? wxString() : resources);

	xrc_call(*this, "ID_FZVERSION", &wxStaticText::SetLabel, _T("FileZilla ") + CBuildInfo::GetVersion());

	wxString const url = _T("https://welcome.filezilla-project.org/welcome?type=client&category=%s&version=") + ownVersion;

	if (!greetingVersion.empty()) {
		xrc_call(*this, "ID_LINK_NEWS", &wxHyperlinkCtrl::SetURL, wxString::Format(url, _T("news")) + _T("&oldversion=") + greetingVersion);
		xrc_call(*this, "ID_LINK_NEWS", &wxHyperlinkCtrl::SetLabel, wxString::Format(_("New features and improvements in %s"), CBuildInfo::GetVersion()));
	}
	else {
		xrc_call(*this, "ID_LINK_NEWS", &wxHyperlinkCtrl::Hide);
		xrc_call(*this, "ID_HEADING_NEWS", &wxStaticText::Hide);
	}

	xrc_call(*this, "ID_DOCUMENTATION_BASIC", &wxHyperlinkCtrl::SetURL, wxString::Format(url, _T("documentation_basic")));
	xrc_call(*this, "ID_DOCUMENTATION_NETWORK", &wxHyperlinkCtrl::SetURL, wxString::Format(url, _T("documentation_network")));
	xrc_call(*this, "ID_DOCUMENTATION_MORE", &wxHyperlinkCtrl::SetURL, wxString::Format(url, _T("documentation_more")));
	xrc_call(*this, "ID_SUPPORT_FORUM", &wxHyperlinkCtrl::SetURL, wxString::Format(url, _T("support_forum")));
	xrc_call(*this, "ID_SUPPORT_MORE", &wxHyperlinkCtrl::SetURL, wxString::Format(url, _T("support_more")));

#ifdef FZ_WINDOWS
	// Add phone support link in official Windows builds builds...
	if (CBuildInfo::GetBuildType() == _T("official")) {
		auto lang = wxGetLocale() ? wxGetLocale()->GetName() : wxString();
		// but only in English...
		if (lang.StartsWith(_T("en"))) {
			auto const now = fz::datetime::now();
			// while the build is fresh...
			if ((now - CBuildInfo::GetBuildDate()).get_days() < 60) {
				// and only for US and Canada, so limit by timezone
				auto ref = fz::datetime(now.format("%Y%m%d%H%M%S", fz::datetime::utc), fz::datetime::utc);
				auto offset = fz::datetime(ref.format("%Y%m%d%H%M%S", fz::datetime::utc), fz::datetime::local);
				auto diff = (ref - offset).get_hours();
				if (diff >= -9 && diff <= -3) {
					auto sizer = xrc_call(*this, "ID_SUPPORT_MORE", &wxWindow::GetContainingSizer);
					if (sizer) {
						auto link = new wxHyperlinkCtrl(sizer->GetContainingWindow(), wxID_ANY, _T("Phone support"), _T("https://filezilla-project.org/phone_support.php"));
						sizer->Insert(0, link);
					}
				}
			}
		}
	}
#endif

	Layout();

	GetSizer()->Fit(this);

	if (delay) {
		m_delayedShowTimer.SetOwner(this);
		m_delayedShowTimer.Start(10, true);
	}
	else
		ShowModal();

	return true;
}