1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
22 #include <kdecommandthread.hxx>
24 #include <config_vclplug.h>
27 #include <tqstringlist.h>
28 #include <tdeapplication.h>
30 #include <qstringlist.h>
31 #include <kapplication.h>
34 #if OSL_DEBUG_LEVEL > 1
38 //////////////////////////////////////////////////////////////////////////
40 //////////////////////////////////////////////////////////////////////////
42 KDECommandEvent::KDECommandEvent( const QString
&qCommand
, QStringList
*pStringList
)
43 : QCustomEvent( TypeId
, pStringList
),
48 CommandEventType eType
;
51 { "appendControl", AppendControl
},
52 { "enableControl", EnableControl
},
53 { "getValue", GetValue
},
54 { "setValue", SetValue
},
55 { "appendFilter", AppendFilter
},
56 { "appendFilterGroup", AppendFilterGroup
},
57 { "getCurrentFilter", GetCurrentFilter
},
58 { "setCurrentFilter", SetCurrentFilter
},
59 { "getDirectory", GetDirectory
},
60 { "setDirectory", SetDirectory
},
61 { "getFiles", GetFiles
},
62 { "setTitle", SetTitle
},
63 { "setType", SetType
},
64 { "setDefaultName", SetDefaultName
},
65 { "setMultiSelection", SetMultiSelection
},
70 for ( pIdx
= pMapping
; pIdx
->pName
&& qCommand
!= pIdx
->pName
; ++pIdx
)
73 m_eCommand
= pIdx
->eType
;
76 //////////////////////////////////////////////////////////////////////////
78 //////////////////////////////////////////////////////////////////////////
80 KDECommandThread::KDECommandThread( QWidget
*pObject
)
81 : m_pObject( pObject
)
85 KDECommandThread::~KDECommandThread()
89 void KDECommandThread::run()
91 QTextIStream
qStream( stdin
);
92 qStream
.setEncoding( QTextStream::UnicodeUTF8
);
96 while ( !bQuit
&& !qStream
.atEnd() )
98 qLine
= qStream
.readLine();
99 handleCommand( qLine
, bQuit
);
103 void KDECommandThread::handleCommand( const QString
&rString
, bool &bQuit
)
105 QMutexLocker
qMutexLocker( &m_aMutex
);
107 #if OSL_DEBUG_LEVEL > 1
108 ::std::cerr
<< "kdefilepicker received: " << rString
.latin1() << ::std::endl
;
112 QStringList
*pTokens
= tokenize( rString
);
116 if ( pTokens
->empty() )
118 delete pTokens
, pTokens
= NULL
;
122 QString qCommand
= pTokens
->front();
123 pTokens
->pop_front();
124 #if OSL_DEBUG_LEVEL > 1
125 ::std::cerr
<< "kdefilepicker first command: " << qCommand
.latin1() << ::std::endl
;
128 if ( qCommand
== "exit" )
132 kapp
->wakeUpGuiThread();
133 #if OSL_DEBUG_LEVEL > 1
134 ::std::cerr
<< "kdefilepicker: exiting" << ::std::endl
;
138 kapp
->postEvent( m_pObject
, new KDECommandEvent( qCommand
, pTokens
) );
141 QStringList
* KDECommandThread::tokenize( const QString
&rString
)
143 // Commands look like:
144 // command arg1 arg2 arg3 ...
145 // Args may be enclosed in '"', if they contain spaces.
147 QStringList
*pList
= new QStringList();
150 qBuffer
.reserve( 1024 );
152 const QChar
*pUnicode
= rString
.unicode();
153 const QChar
*pEnd
= pUnicode
+ rString
.length();
154 bool bQuoted
= false;
156 for ( ; pUnicode
!= pEnd
; ++pUnicode
)
158 if ( *pUnicode
== '\\' )
161 if ( pUnicode
!= pEnd
)
163 if ( *pUnicode
== 'n' )
164 qBuffer
.append( '\n' );
166 qBuffer
.append( *pUnicode
);
169 else if ( *pUnicode
== '"' )
171 else if ( *pUnicode
== ' ' && !bQuoted
)
173 pList
->push_back( qBuffer
);
174 qBuffer
.setLength( 0 );
177 qBuffer
.append( *pUnicode
);
179 pList
->push_back( qBuffer
);
184 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */