xref: /aoo41x/main/vcl/unx/generic/dtrans/config.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_vcl.hxx"
30 
31 #include <cstdio>
32 #include <unotools/configitem.hxx>
33 
34 #include "X11_selection.hxx"
35 
36 #define SETTINGS_CONFIGNODE "VCL/Settings/Transfer"
37 #define SELECTION_PROPERTY "SelectionTimeout"
38 
39 namespace x11
40 {
41 
42 class DtransX11ConfigItem : public ::utl::ConfigItem
43 {
44     sal_Int32           m_nSelectionTimeout;
45 
46     virtual void Notify( const ::com::sun::star::uno::Sequence< ::rtl::OUString >& rPropertyNames );
47     virtual void Commit();
48 public:
49     DtransX11ConfigItem();
50     virtual ~DtransX11ConfigItem();
51 
52     sal_Int32 getSelectionTimeout() const { return m_nSelectionTimeout; }
53 };
54 
55 }
56 
57 using namespace com::sun::star::lang;
58 using namespace com::sun::star::uno;
59 using namespace rtl;
60 using namespace x11;
61 
62 sal_Int32 SelectionManager::getSelectionTimeout()
63 {
64     if( m_nSelectionTimeout < 1 )
65     {
66         DtransX11ConfigItem aCfg;
67         m_nSelectionTimeout = aCfg.getSelectionTimeout();
68 #if OSL_DEBUG_LEVEL > 1
69         fprintf( stderr, "initialized selection timeout to %ld seconds\n", m_nSelectionTimeout );
70 #endif
71     }
72     return m_nSelectionTimeout;
73 }
74 
75 /*
76  *  DtransX11ConfigItem constructor
77  */
78 
79 DtransX11ConfigItem::DtransX11ConfigItem() :
80     ConfigItem( OUString( RTL_CONSTASCII_USTRINGPARAM( SETTINGS_CONFIGNODE ) ),
81                 CONFIG_MODE_DELAYED_UPDATE ),
82     m_nSelectionTimeout( 3 )
83 {
84     if( IsValidConfigMgr() )
85     {
86         Sequence< OUString > aKeys( 1 );
87         aKeys.getArray()[0] = OUString( RTL_CONSTASCII_USTRINGPARAM( SELECTION_PROPERTY ) );
88         Sequence< Any > aValues = GetProperties( aKeys );
89 #if OSL_DEBUG_LEVEL > 1
90         fprintf( stderr, "found %ld properties for %s\n", aValues.getLength(), SELECTION_PROPERTY );
91 #endif
92         Any* pValue = aValues.getArray();
93         for( int i = 0; i < aValues.getLength(); i++, pValue++ )
94         {
95             if( pValue->getValueTypeClass() == TypeClass_STRING )
96             {
97                 const OUString* pLine = (const OUString*)pValue->getValue();
98                 if( pLine->getLength() )
99                 {
100                     m_nSelectionTimeout = pLine->toInt32();
101                     if( m_nSelectionTimeout < 1 )
102                         m_nSelectionTimeout = 1;
103                 }
104 #if OSL_DEBUG_LEVEL > 1
105                 fprintf( stderr, "found SelectionTimeout \"%s\"\n",
106                 OUStringToOString( *pLine, osl_getThreadTextEncoding() ).getStr() );
107 #endif
108             }
109 #if OSL_DEBUG_LEVEL > 1
110             else
111                 fprintf( stderr, "found SelectionTimeout of type \"%s\"\n",
112                 OUStringToOString( pValue->getValueType().getTypeName(), osl_getThreadTextEncoding() ).getStr() );
113 #endif
114         }
115     }
116 #if OSL_DEBUG_LEVEL > 1
117     else
118         fprintf( stderr, "no valid configmanager, could not read timeout setting\n" );
119 #endif
120 }
121 
122 /*
123  *  DtransX11ConfigItem destructor
124  */
125 
126 DtransX11ConfigItem::~DtransX11ConfigItem()
127 {
128 }
129 
130 /*
131  *  DtransX11ConfigItem::Commit
132  */
133 
134 void DtransX11ConfigItem::Commit()
135 {
136     // for the clipboard service this is readonly, so
137     // there is nothing to commit
138 }
139 
140 /*
141  *  DtransX11ConfigItem::Notify
142  */
143 
144 void DtransX11ConfigItem::Notify( const Sequence< OUString >& /*rPropertyNames*/ )
145 {
146 }
147 
148 
149