You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
148 lines
4.0 KiB
148 lines
4.0 KiB
13 years ago
|
/*
|
||
|
* This file is part of the Trinity Desktop Environment
|
||
|
*
|
||
13 years ago
|
* Original file taken from the OpenSUSE tdebase builds
|
||
13 years ago
|
*
|
||
|
* This program is free software; you can redistribute it and/or modify
|
||
|
* it under the terms of the GNU General Public License as published by
|
||
|
* the Free Software Foundation; either version 2 of the License, or
|
||
|
* (at your option) any later version.
|
||
|
*
|
||
|
* This program is distributed in the hope that it will be useful,
|
||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
|
* GNU General Public License for more details.
|
||
|
*
|
||
|
* You should have received a copy of the GNU General Public License
|
||
|
* along with this program; if not, write to the Free Software
|
||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||
|
*/
|
||
|
|
||
6 years ago
|
#include "tqttde.h"
|
||
13 years ago
|
|
||
|
#include <assert.h>
|
||
|
#include <dcopclient.h>
|
||
|
#include <dcoptypes.h>
|
||
13 years ago
|
#include <tqapplication.h>
|
||
|
#include <tqregexp.h>
|
||
|
#include <tqstringlist.h>
|
||
|
#include <tqwidget.h>
|
||
13 years ago
|
#include <unistd.h>
|
||
|
|
||
|
#include <X11/Xlib.h>
|
||
|
|
||
13 years ago
|
extern Time tqt_x_time;
|
||
13 years ago
|
|
||
13 years ago
|
static TQString convertFileFilter( const TQString& filter )
|
||
13 years ago
|
{
|
||
|
if( filter.isEmpty())
|
||
|
return filter;
|
||
13 years ago
|
TQString f2 = filter;
|
||
|
f2.replace( '\n', ";;" ); // TQt says separator is ";;", but it also silently accepts newline
|
||
13 years ago
|
f2.replace( '/', "\\/" ); // escape /'s for KFileDialog
|
||
13 years ago
|
TQStringList items = TQStringList::split( ";;", f2 );
|
||
|
TQRegExp reg( "\\((.*)\\)" );
|
||
|
for( TQStringList::Iterator it = items.begin();
|
||
13 years ago
|
it != items.end();
|
||
|
++it )
|
||
|
{
|
||
|
if( reg.search( *it ))
|
||
|
*it = reg.cap( 1 ) + '|' + *it;
|
||
|
}
|
||
|
return items.join( "\n" );
|
||
|
}
|
||
|
|
||
13 years ago
|
static TQString convertBackFileFilter( const TQString& filter )
|
||
13 years ago
|
{
|
||
|
if( filter.isEmpty())
|
||
|
return filter;
|
||
13 years ago
|
TQStringList items = TQStringList::split( "\n", filter );
|
||
|
for( TQStringList::Iterator it = items.begin();
|
||
13 years ago
|
it != items.end();
|
||
|
++it )
|
||
|
{
|
||
|
int pos = (*it).find( '|' );
|
||
|
if( pos >= 0 )
|
||
|
(*it) = (*it).mid( pos + 1 );
|
||
|
}
|
||
|
return items.join( ";;" );
|
||
|
}
|
||
|
|
||
|
static DCOPClient* dcopClient()
|
||
|
{
|
||
|
DCOPClient* dcop = DCOPClient::mainClient();
|
||
|
if( dcop == NULL )
|
||
|
{
|
||
|
static DCOPClient* dcop_private;
|
||
|
if( dcop_private == NULL )
|
||
|
{
|
||
|
dcop_private = new DCOPClient;
|
||
|
dcop_private->attach();
|
||
|
}
|
||
|
dcop = dcop_private;
|
||
|
}
|
||
|
static bool prepared = false;
|
||
|
if( !prepared )
|
||
|
{
|
||
13 years ago
|
assert( tqApp != NULL ); // TODO
|
||
13 years ago
|
prepared = true;
|
||
|
dcop->bindToApp();
|
||
12 years ago
|
if( !tqApp->inherits( "TDEApplication" )) // KApp takes care of input blocking
|
||
13 years ago
|
{
|
||
6 years ago
|
static tqttde_EventLoop* loop = new tqttde_EventLoop;
|
||
13 years ago
|
TQObject::connect( dcop, TQT_SIGNAL( blockUserInput( bool )), loop, TQT_SLOT( block( bool )));
|
||
13 years ago
|
}
|
||
|
}
|
||
|
return dcop;
|
||
|
}
|
||
|
|
||
|
// defined in qapplication_x11.cpp
|
||
|
typedef int (*QX11EventFilter) (XEvent*);
|
||
13 years ago
|
extern QX11EventFilter tqt_set_x11_event_filter (QX11EventFilter filter);
|
||
13 years ago
|
|
||
|
static QX11EventFilter old_filter;
|
||
|
|
||
|
static int input_filter( XEvent* e )
|
||
|
{
|
||
|
switch( e->type )
|
||
|
{
|
||
|
case ButtonPress:
|
||
|
case ButtonRelease:
|
||
|
case KeyPress:
|
||
|
case KeyRelease:
|
||
|
case MotionNotify:
|
||
|
case EnterNotify:
|
||
|
case LeaveNotify:
|
||
|
return true;
|
||
|
default:
|
||
|
break;
|
||
|
}
|
||
|
if( old_filter != NULL )
|
||
|
return old_filter( e );
|
||
|
return false;
|
||
|
}
|
||
|
|
||
6 years ago
|
void tqttde_EventLoop::block( bool b )
|
||
13 years ago
|
{
|
||
|
if( b )
|
||
13 years ago
|
old_filter = tqt_set_x11_event_filter( input_filter );
|
||
13 years ago
|
else
|
||
13 years ago
|
tqt_set_x11_event_filter( old_filter );
|
||
13 years ago
|
}
|
||
|
|
||
|
// duped in kded module
|
||
13 years ago
|
static TQString getHostname()
|
||
13 years ago
|
{
|
||
|
char hostname[ 256 ];
|
||
|
if( gethostname( hostname, 255 ) == 0 )
|
||
|
{
|
||
|
hostname[ 255 ] = '\0';
|
||
|
return hostname;
|
||
|
}
|
||
|
return "";
|
||
|
}
|
||
|
|
||
6 years ago
|
#include "tqttde_functions.cpp"
|
||
13 years ago
|
|
||
6 years ago
|
#include "tqttde.moc"
|