summaryrefslogtreecommitdiffstats
path: root/tqt3integration/libqtkde/qtkde.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tqt3integration/libqtkde/qtkde.cpp')
-rw-r--r--tqt3integration/libqtkde/qtkde.cpp147
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"