Kaydet (Commit) a13362ef authored tarafından Caolán McNamara's avatar Caolán McNamara

Resolves: fdo#43049 basic PPD custom options support

because this is another way seen in the wild to transmit a fax number through
cups as an alternative to using fax4CUPS

Change-Id: I32db38aa05213e469442136eb46d0028098a8b7e
üst dcc8c917
...@@ -42,9 +42,14 @@ enum PPDValueType { eInvocation, eQuoted, eSymbol, eString, eNo }; ...@@ -42,9 +42,14 @@ enum PPDValueType { eInvocation, eQuoted, eSymbol, eString, eNo };
struct VCL_DLLPUBLIC PPDValue struct VCL_DLLPUBLIC PPDValue
{ {
PPDValueType m_eType; PPDValueType m_eType;
OUString m_aOption; //CustomOption stuff for fdo#43049
OUString m_aValue; //see http://www.cups.org/documentation.php/spec-ppd.html#OPTIONS
//for full specs, only the basics are implemented here
bool m_bCustomOption;
mutable OUString m_aCustomOption;
OUString m_aOption;
OUString m_aValue;
}; };
...@@ -82,7 +87,7 @@ public: ...@@ -82,7 +87,7 @@ public:
PPDKey( const OUString& rKey ); PPDKey( const OUString& rKey );
~PPDKey(); ~PPDKey();
PPDValue* insertValue( const OUString& rOption, PPDValueType eType ); PPDValue* insertValue(const OUString& rOption, PPDValueType eType, bool bCustomOption = false);
int countValues() const int countValues() const
{ return m_aValues.size(); } { return m_aValues.size(); }
// neither getValue will return the query option // neither getValue will return the query option
......
...@@ -39,6 +39,8 @@ void RTSDialog::insertAllPPDValues( ListBox& rBox, const PPDParser* pParser, con ...@@ -39,6 +39,8 @@ void RTSDialog::insertAllPPDValues( ListBox& rBox, const PPDParser* pParser, con
for( int i = 0; i < pKey->countValues(); i++ ) for( int i = 0; i < pKey->countValues(); i++ )
{ {
pValue = pKey->getValue( i ); pValue = pKey->getValue( i );
if (pValue->m_bCustomOption)
continue;
aOptionText = pParser->translateOption( pKey->getKey(), pValue->m_aOption) ; aOptionText = pParser->translateOption( pKey->getKey(), pValue->m_aOption) ;
if( m_aJobData.m_aContext.checkConstraints( pKey, pValue ) ) if( m_aJobData.m_aContext.checkConstraints( pKey, pValue ) )
...@@ -56,7 +58,7 @@ void RTSDialog::insertAllPPDValues( ListBox& rBox, const PPDParser* pParser, con ...@@ -56,7 +58,7 @@ void RTSDialog::insertAllPPDValues( ListBox& rBox, const PPDParser* pParser, con
} }
} }
pValue = m_aJobData.m_aContext.getValue( pKey ); pValue = m_aJobData.m_aContext.getValue( pKey );
if( pValue ) if (pValue && !pValue->m_bCustomOption)
{ {
if( ( nPos = rBox.GetEntryPos( (void*)pValue ) ) != LISTBOX_ENTRY_NOTFOUND ) if( ( nPos = rBox.GetEntryPos( (void*)pValue ) ) != LISTBOX_ENTRY_NOTFOUND )
rBox.SelectEntryPos( nPos ); rBox.SelectEntryPos( nPos );
...@@ -286,8 +288,9 @@ IMPL_LINK( RTSPaperPage, SelectHdl, ListBox*, pBox ) ...@@ -286,8 +288,9 @@ IMPL_LINK( RTSPaperPage, SelectHdl, ListBox*, pBox )
*/ */
RTSDevicePage::RTSDevicePage( RTSDialog* pParent ) RTSDevicePage::RTSDevicePage( RTSDialog* pParent )
: TabPage(pParent->m_pTabControl, "PrinterDevicePage", "vcl/ui/printerdevicepage.ui" ) : TabPage(pParent->m_pTabControl, "PrinterDevicePage", "vcl/ui/printerdevicepage.ui")
, m_pParent( pParent ) , m_pParent(pParent)
, m_pCustomValue(NULL)
{ {
get(m_pPPDKeyBox, "options"); get(m_pPPDKeyBox, "options");
get(m_pPPDValueBox, "values"); get(m_pPPDValueBox, "values");
...@@ -295,6 +298,9 @@ RTSDevicePage::RTSDevicePage( RTSDialog* pParent ) ...@@ -295,6 +298,9 @@ RTSDevicePage::RTSDevicePage( RTSDialog* pParent )
m_pPPDKeyBox->SetDropDownLineCount(12); m_pPPDKeyBox->SetDropDownLineCount(12);
m_pPPDValueBox->SetDropDownLineCount(12); m_pPPDValueBox->SetDropDownLineCount(12);
get(m_pCustomEdit, "custom");
m_pCustomEdit->SetModifyHdl(LINK(this, RTSDevicePage, ModifyHdl));
get(m_pLevelBox, "level"); get(m_pLevelBox, "level");
get(m_pSpaceBox, "colorspace"); get(m_pSpaceBox, "colorspace");
get(m_pDepthBox, "colordepth"); get(m_pDepthBox, "colordepth");
...@@ -423,7 +429,14 @@ sal_uLong RTSDevicePage::getPDFDevice() ...@@ -423,7 +429,14 @@ sal_uLong RTSDevicePage::getPDFDevice()
return -1; //explicitly PS return -1; //explicitly PS
} }
IMPL_LINK( RTSDevicePage, ModifyHdl, Edit*, pEdit )
{
if (m_pCustomValue)
{
m_pCustomValue->m_aCustomOption = m_pCustomEdit->GetText();
}
return 0;
}
IMPL_LINK( RTSDevicePage, SelectHdl, ListBox*, pBox ) IMPL_LINK( RTSDevicePage, SelectHdl, ListBox*, pBox )
{ {
...@@ -436,7 +449,7 @@ IMPL_LINK( RTSDevicePage, SelectHdl, ListBox*, pBox ) ...@@ -436,7 +449,7 @@ IMPL_LINK( RTSDevicePage, SelectHdl, ListBox*, pBox )
{ {
const PPDKey* pKey = (PPDKey*)m_pPPDKeyBox->GetEntryData( m_pPPDKeyBox->GetSelectEntryPos() ); const PPDKey* pKey = (PPDKey*)m_pPPDKeyBox->GetEntryData( m_pPPDKeyBox->GetSelectEntryPos() );
const PPDValue* pValue = (PPDValue*)m_pPPDValueBox->GetEntryData( m_pPPDValueBox->GetSelectEntryPos() ); const PPDValue* pValue = (PPDValue*)m_pPPDValueBox->GetEntryData( m_pPPDValueBox->GetSelectEntryPos() );
if( pKey && pValue ) if (pKey && pValue)
{ {
m_pParent->m_aJobData.m_aContext.setValue( pKey, pValue ); m_pParent->m_aJobData.m_aContext.setValue( pKey, pValue );
FillValueBox( pKey ); FillValueBox( pKey );
...@@ -445,11 +458,10 @@ IMPL_LINK( RTSDevicePage, SelectHdl, ListBox*, pBox ) ...@@ -445,11 +458,10 @@ IMPL_LINK( RTSDevicePage, SelectHdl, ListBox*, pBox )
return 0; return 0;
} }
void RTSDevicePage::FillValueBox( const PPDKey* pKey ) void RTSDevicePage::FillValueBox( const PPDKey* pKey )
{ {
m_pPPDValueBox->Clear(); m_pPPDValueBox->Clear();
m_pCustomEdit->Hide();
if( ! pKey ) if( ! pKey )
return; return;
...@@ -461,13 +473,24 @@ void RTSDevicePage::FillValueBox( const PPDKey* pKey ) ...@@ -461,13 +473,24 @@ void RTSDevicePage::FillValueBox( const PPDKey* pKey )
if( m_pParent->m_aJobData.m_aContext.checkConstraints( pKey, pValue ) && if( m_pParent->m_aJobData.m_aContext.checkConstraints( pKey, pValue ) &&
m_pParent->m_aJobData.m_pParser ) m_pParent->m_aJobData.m_pParser )
{ {
OUString aEntry( m_pParent->m_aJobData.m_pParser->translateOption( pKey->getKey(), pValue->m_aOption ) ); OUString aEntry;
if (pValue->m_bCustomOption)
aEntry = VclResId(SV_PRINT_CUSTOM_TXT);
else
aEntry = OUString(m_pParent->m_aJobData.m_pParser->translateOption( pKey->getKey(), pValue->m_aOption));
sal_uInt16 nPos = m_pPPDValueBox->InsertEntry( aEntry ); sal_uInt16 nPos = m_pPPDValueBox->InsertEntry( aEntry );
m_pPPDValueBox->SetEntryData( nPos, (void*)pValue ); m_pPPDValueBox->SetEntryData( nPos, (void*)pValue );
} }
} }
pValue = m_pParent->m_aJobData.m_aContext.getValue( pKey ); pValue = m_pParent->m_aJobData.m_aContext.getValue( pKey );
m_pPPDValueBox->SelectEntryPos( m_pPPDValueBox->GetEntryPos( (void*)pValue ) ); m_pPPDValueBox->SelectEntryPos( m_pPPDValueBox->GetEntryPos( (void*)pValue ) );
if (pValue->m_bCustomOption)
{
m_pCustomValue = pValue;
m_pParent->m_aJobData.m_aContext.setValue(pKey, pValue);
m_pCustomEdit->SetText(m_pCustomValue->m_aCustomOption);
m_pCustomEdit->Show();
}
} }
int SetupPrinterDriver(::psp::PrinterInfo& rJobData) int SetupPrinterDriver(::psp::PrinterInfo& rJobData)
......
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include "vcl/tabpage.hxx" #include "vcl/tabpage.hxx"
#include "vcl/tabctrl.hxx" #include "vcl/tabctrl.hxx"
#include "vcl/button.hxx" #include "vcl/button.hxx"
#include "vcl/edit.hxx"
#include "vcl/fixed.hxx" #include "vcl/fixed.hxx"
#include "vcl/lstbox.hxx" #include "vcl/lstbox.hxx"
#include "vcl/field.hxx" #include "vcl/field.hxx"
...@@ -102,6 +103,8 @@ class RTSDevicePage : public TabPage ...@@ -102,6 +103,8 @@ class RTSDevicePage : public TabPage
ListBox* m_pPPDKeyBox; ListBox* m_pPPDKeyBox;
ListBox* m_pPPDValueBox; ListBox* m_pPPDValueBox;
const psp::PPDValue* m_pCustomValue;
Edit* m_pCustomEdit;
ListBox* m_pLevelBox; ListBox* m_pLevelBox;
ListBox* m_pSpaceBox; ListBox* m_pSpaceBox;
...@@ -110,6 +113,7 @@ class RTSDevicePage : public TabPage ...@@ -110,6 +113,7 @@ class RTSDevicePage : public TabPage
void FillValueBox( const ::psp::PPDKey* ); void FillValueBox( const ::psp::PPDKey* );
DECL_LINK( SelectHdl, ListBox* ); DECL_LINK( SelectHdl, ListBox* );
DECL_LINK( ModifyHdl, Edit* );
public: public:
RTSDevicePage( RTSDialog* ); RTSDevicePage( RTSDialog* );
~RTSDevicePage(); ~RTSDevicePage();
......
...@@ -214,6 +214,7 @@ ...@@ -214,6 +214,7 @@
#define SV_PRINT_NOCOLLATE_IMG 10614 #define SV_PRINT_NOCOLLATE_IMG 10614
#define SV_PRINT_QUERYFAXNUMBER_TXT 10615 #define SV_PRINT_QUERYFAXNUMBER_TXT 10615
#define SV_PRINT_INVALID_TXT 10616 #define SV_PRINT_INVALID_TXT 10616
#define SV_PRINT_CUSTOM_TXT 10617
#define SV_EDIT_WARNING_BOX 10650 #define SV_EDIT_WARNING_BOX 10650
......
...@@ -115,4 +115,9 @@ String SV_PRINT_INVALID_TXT ...@@ -115,4 +115,9 @@ String SV_PRINT_INVALID_TXT
Text [ en-US ] = "<ignore>"; Text [ en-US ] = "<ignore>";
}; };
String SV_PRINT_CUSTOM_TXT
{
Text [ en-US ] = "Custom";
};
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
...@@ -71,7 +71,7 @@ ...@@ -71,7 +71,7 @@
<property name="xalign">0</property> <property name="xalign">0</property>
<property name="label" translatable="yes">Current _value</property> <property name="label" translatable="yes">Current _value</property>
<property name="use_underline">True</property> <property name="use_underline">True</property>
<property name="mnemonic_widget">values:border</property> <property name="mnemonic_widget">valuegrid</property>
<attributes> <attributes>
<attribute name="weight" value="bold"/> <attribute name="weight" value="bold"/>
</attributes> </attributes>
...@@ -195,13 +195,40 @@ ...@@ -195,13 +195,40 @@
</packing> </packing>
</child> </child>
<child> <child>
<object class="GtkTreeView" id="values:border"> <object class="GtkGrid" id="valuegrid">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">True</property> <property name="can_focus">False</property>
<property name="hexpand">True</property> <property name="hexpand">True</property>
<property name="vexpand">True</property> <property name="vexpand">True</property>
<child internal-child="selection"> <property name="row_spacing">6</property>
<object class="GtkTreeSelection" id="treeview-selection2"/> <child>
<object class="GtkEntry" id="custom">
<property name="can_focus">True</property>
<property name="no_show_all">True</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">0</property>
<property name="width">1</property>
<property name="height">1</property>
</packing>
</child>
<child>
<object class="GtkTreeView" id="values:border">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="hexpand">True</property>
<property name="vexpand">True</property>
<child internal-child="selection">
<object class="GtkTreeSelection" id="treeview-selection"/>
</child>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">1</property>
<property name="width">1</property>
<property name="height">1</property>
</packing>
</child> </child>
</object> </object>
<packing> <packing>
......
...@@ -591,10 +591,16 @@ void CUPSManager::getOptionsFromDocumentSetup( const JobData& rJob, bool bBanner ...@@ -591,10 +591,16 @@ void CUPSManager::getOptionsFromDocumentSetup( const JobData& rJob, bool bBanner
{ {
const PPDKey* pKey = aKeys[i]; const PPDKey* pKey = aKeys[i];
const PPDValue* pValue = rJob.m_aContext.getValue( pKey ); const PPDValue* pValue = rJob.m_aContext.getValue( pKey );
if(pValue && pValue->m_eType == eInvocation && !pValue->m_aOption.isEmpty() ) OUString sPayLoad;
if (pValue && pValue->m_eType == eInvocation)
{
sPayLoad = pValue->m_bCustomOption ? pValue->m_aCustomOption : pValue->m_aOption;
}
if (!sPayLoad.isEmpty())
{ {
OString aKey = OUStringToOString( pKey->getKey(), RTL_TEXTENCODING_ASCII_US ); OString aKey = OUStringToOString( pKey->getKey(), RTL_TEXTENCODING_ASCII_US );
OString aValue = OUStringToOString( pValue->m_aOption, RTL_TEXTENCODING_ASCII_US ); OString aValue = OUStringToOString( sPayLoad, RTL_TEXTENCODING_ASCII_US );
rNumOptions = cupsAddOption( aKey.getStr(), aValue.getStr(), rNumOptions, (cups_option_t**)rOptions ); rNumOptions = cupsAddOption( aKey.getStr(), aValue.getStr(), rNumOptions, (cups_option_t**)rOptions );
} }
} }
......
...@@ -933,6 +933,18 @@ void PPDParser::parse( ::std::list< OString >& rLines ) ...@@ -933,6 +933,18 @@ void PPDParser::parse( ::std::list< OString >& rLines )
} }
else if( aKey == "CustomPageSize" ) // currently not handled else if( aKey == "CustomPageSize" ) // currently not handled
continue; continue;
else if (aKey.startsWith("Custom", &aKey) )
{
//fdo#43049 very basic support for Custom entries, we ignore the
//validation params and types
PPDKey* pKey = NULL;
OUString aUniKey(OStringToOUString(aKey, RTL_TEXTENCODING_MS_1252));
keyit = m_aKeys.find( aUniKey );
if(keyit != m_aKeys.end())
pKey = keyit->second;
pKey->insertValue("Custom", eInvocation, true);
continue;
}
// default values are parsed in pass 2 // default values are parsed in pass 2
if (aKey.startsWith("Default")) if (aKey.startsWith("Default"))
...@@ -1525,15 +1537,14 @@ void PPDKey::eraseValue( const OUString& rOption ) ...@@ -1525,15 +1537,14 @@ void PPDKey::eraseValue( const OUString& rOption )
m_aValues.erase( it ); m_aValues.erase( it );
} }
PPDValue* PPDKey::insertValue(const OUString& rOption, PPDValueType eType, bool bCustomOption)
PPDValue* PPDKey::insertValue( const OUString& rOption, PPDValueType eType )
{ {
if( m_aValues.find( rOption ) != m_aValues.end() ) if( m_aValues.find( rOption ) != m_aValues.end() )
return NULL; return NULL;
PPDValue aValue; PPDValue aValue;
aValue.m_aOption = rOption; aValue.m_aOption = rOption;
aValue.m_bCustomOption = bCustomOption;
aValue.m_eType = eType; aValue.m_eType = eType;
m_aValues[ rOption ] = aValue; m_aValues[ rOption ] = aValue;
PPDValue* pValue = &m_aValues[rOption]; PPDValue* pValue = &m_aValues[rOption];
...@@ -1541,8 +1552,6 @@ PPDValue* PPDKey::insertValue( const OUString& rOption, PPDValueType eType ) ...@@ -1541,8 +1552,6 @@ PPDValue* PPDKey::insertValue( const OUString& rOption, PPDValueType eType )
return pValue; return pValue;
} }
/* /*
* PPDContext * PPDContext
*/ */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment