xref: /aoo41x/main/vcl/unx/generic/dtrans/config.cxx (revision c82f2877)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_vcl.hxx"
26 
27 #include <cstdio>
28 #include <unotools/configitem.hxx>
29 
30 #include "X11_selection.hxx"
31 
32 #define SETTINGS_CONFIGNODE "VCL/Settings/Transfer"
33 #define SELECTION_PROPERTY "SelectionTimeout"
34 
35 namespace x11
36 {
37 
38 class DtransX11ConfigItem : public ::utl::ConfigItem
39 {
40     sal_Int32           m_nSelectionTimeout;
41 
42     virtual void Notify( const ::com::sun::star::uno::Sequence< ::rtl::OUString >& rPropertyNames );
43     virtual void Commit();
44 public:
45     DtransX11ConfigItem();
46     virtual ~DtransX11ConfigItem();
47 
getSelectionTimeout() const48     sal_Int32 getSelectionTimeout() const { return m_nSelectionTimeout; }
49 };
50 
51 }
52 
53 using namespace com::sun::star::lang;
54 using namespace com::sun::star::uno;
55 using namespace rtl;
56 using namespace x11;
57 
getSelectionTimeout()58 sal_Int32 SelectionManager::getSelectionTimeout()
59 {
60     if( m_nSelectionTimeout < 1 )
61     {
62         DtransX11ConfigItem aCfg;
63         m_nSelectionTimeout = aCfg.getSelectionTimeout();
64 #if OSL_DEBUG_LEVEL > 1
65         fprintf( stderr, "initialized selection timeout to %ld seconds\n", m_nSelectionTimeout );
66 #endif
67     }
68     return m_nSelectionTimeout;
69 }
70 
71 /*
72  *  DtransX11ConfigItem constructor
73  */
74 
DtransX11ConfigItem()75 DtransX11ConfigItem::DtransX11ConfigItem() :
76     ConfigItem( OUString( RTL_CONSTASCII_USTRINGPARAM( SETTINGS_CONFIGNODE ) ),
77                 CONFIG_MODE_DELAYED_UPDATE ),
78     m_nSelectionTimeout( 3 )
79 {
80     if( IsValidConfigMgr() )
81     {
82         Sequence< OUString > aKeys( 1 );
83         aKeys.getArray()[0] = OUString( RTL_CONSTASCII_USTRINGPARAM( SELECTION_PROPERTY ) );
84         Sequence< Any > aValues = GetProperties( aKeys );
85 #if OSL_DEBUG_LEVEL > 1
86         fprintf( stderr, "found %ld properties for %s\n", aValues.getLength(), SELECTION_PROPERTY );
87 #endif
88         Any* pValue = aValues.getArray();
89         for( int i = 0; i < aValues.getLength(); i++, pValue++ )
90         {
91             if( pValue->getValueTypeClass() == TypeClass_STRING )
92             {
93                 const OUString* pLine = (const OUString*)pValue->getValue();
94                 if( pLine->getLength() )
95                 {
96                     m_nSelectionTimeout = pLine->toInt32();
97                     if( m_nSelectionTimeout < 1 )
98                         m_nSelectionTimeout = 1;
99                 }
100 #if OSL_DEBUG_LEVEL > 1
101                 fprintf( stderr, "found SelectionTimeout \"%s\"\n",
102                 OUStringToOString( *pLine, osl_getThreadTextEncoding() ).getStr() );
103 #endif
104             }
105 #if OSL_DEBUG_LEVEL > 1
106             else
107                 fprintf( stderr, "found SelectionTimeout of type \"%s\"\n",
108                 OUStringToOString( pValue->getValueType().getTypeName(), osl_getThreadTextEncoding() ).getStr() );
109 #endif
110         }
111     }
112 #if OSL_DEBUG_LEVEL > 1
113     else
114         fprintf( stderr, "no valid configmanager, could not read timeout setting\n" );
115 #endif
116 }
117 
118 /*
119  *  DtransX11ConfigItem destructor
120  */
121 
~DtransX11ConfigItem()122 DtransX11ConfigItem::~DtransX11ConfigItem()
123 {
124 }
125 
126 /*
127  *  DtransX11ConfigItem::Commit
128  */
129 
Commit()130 void DtransX11ConfigItem::Commit()
131 {
132     // for the clipboard service this is readonly, so
133     // there is nothing to commit
134 }
135 
136 /*
137  *  DtransX11ConfigItem::Notify
138  */
139 
Notify(const Sequence<OUString> &)140 void DtransX11ConfigItem::Notify( const Sequence< OUString >& /*rPropertyNames*/ )
141 {
142 }
143 
144 
145