diff options
author | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2011-10-19 18:56:47 +0000 |
---|---|---|
committer | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2011-10-19 18:56:47 +0000 |
commit | 337f18fe5d032a59084a5d6516bcb0ff070128b6 (patch) | |
tree | b8e5fa7014c3aa5672f15c86ddba5e53462d6f6f /tqt3integration/libqtkde/qtkde.cpp | |
parent | 1944004a4c57c4c87efc66084579b595da720af8 (diff) | |
download | tdebase-337f18fe5d032a59084a5d6516bcb0ff070128b6.tar.gz tdebase-337f18fe5d032a59084a5d6516bcb0ff070128b6.zip |
Add tqt3integration
These files were originally taken from the GPLed OpenSUSE kdebase builds
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdebase@1259731 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'tqt3integration/libqtkde/qtkde.cpp')
-rw-r--r-- | tqt3integration/libqtkde/qtkde.cpp | 147 |
1 files changed, 147 insertions, 0 deletions
diff --git a/tqt3integration/libqtkde/qtkde.cpp b/tqt3integration/libqtkde/qtkde.cpp new file mode 100644 index 000000000..4e737a9a2 --- /dev/null +++ b/tqt3integration/libqtkde/qtkde.cpp @@ -0,0 +1,147 @@ + /* + * This file is part of the Trinity Desktop Environment + * + * Original file taken from the OpenSUSE kdebase builds + * + * 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. + */ + +#include "qtkde.h" + +#include <assert.h> +#include <dcopclient.h> +#include <dcoptypes.h> +#include <qapplication.h> +#include <qregexp.h> +#include <qstringlist.h> +#include <qwidget.h> +#include <unistd.h> + +#include <X11/Xlib.h> + +extern Time qt_x_time; + +static QString convertFileFilter( const QString& filter ) + { + if( filter.isEmpty()) + return filter; + QString f2 = filter; + f2.replace( '\n', ";;" ); // Qt says separator is ";;", but it also silently accepts newline + f2.replace( '/', "\\/" ); // escape /'s for KFileDialog + QStringList items = QStringList::split( ";;", f2 ); + QRegExp reg( "\\((.*)\\)" ); + for( QStringList::Iterator it = items.begin(); + it != items.end(); + ++it ) + { + if( reg.search( *it )) + *it = reg.cap( 1 ) + '|' + *it; + } + return items.join( "\n" ); + } + +static QString convertBackFileFilter( const QString& filter ) + { + if( filter.isEmpty()) + return filter; + QStringList items = QStringList::split( "\n", filter ); + for( QStringList::Iterator it = items.begin(); + 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 ) + { + assert( qApp != NULL ); // TODO + prepared = true; + dcop->bindToApp(); + if( !qApp->inherits( "KApplication" )) // KApp takes care of input blocking + { + static qtkde_EventLoop* loop = new qtkde_EventLoop; + QObject::connect( dcop, SIGNAL( blockUserInput( bool )), loop, SLOT( block( bool ))); + } + } + return dcop; + } + +// defined in qapplication_x11.cpp +typedef int (*QX11EventFilter) (XEvent*); +extern QX11EventFilter qt_set_x11_event_filter (QX11EventFilter filter); + +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; + } + +void qtkde_EventLoop::block( bool b ) + { + if( b ) + old_filter = qt_set_x11_event_filter( input_filter ); + else + qt_set_x11_event_filter( old_filter ); + } + +// duped in kded module +static QString getHostname() + { + char hostname[ 256 ]; + if( gethostname( hostname, 255 ) == 0 ) + { + hostname[ 255 ] = '\0'; + return hostname; + } + return ""; + } + +#include "qtkde_functions.cpp" + +#include "qtkde.moc" |