summaryrefslogtreecommitdiffstats
path: root/xparts/xpart_notepad
diff options
context:
space:
mode:
authortoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
committertoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
commit90825e2392b2d70e43c7a25b8a3752299a933894 (patch)
treee33aa27f02b74604afbfd0ea4f1cfca8833d882a /xparts/xpart_notepad
downloadtdebindings-90825e2392b2d70e43c7a25b8a3752299a933894.tar.gz
tdebindings-90825e2392b2d70e43c7a25b8a3752299a933894.zip
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdebindings@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'xparts/xpart_notepad')
-rw-r--r--xparts/xpart_notepad/Makefile.am29
-rw-r--r--xparts/xpart_notepad/README3
-rw-r--r--xparts/xpart_notepad/shell_xparthost.cpp80
-rw-r--r--xparts/xpart_notepad/shell_xparthost.h29
-rw-r--r--xparts/xpart_notepad/shell_xparthost.rc11
-rw-r--r--xparts/xpart_notepad/xp_notepad.cpp114
-rw-r--r--xparts/xpart_notepad/xp_notepad.desktop9
-rw-r--r--xparts/xpart_notepad/xp_notepad.rc11
-rw-r--r--xparts/xpart_notepad/xp_notepad_factory.cpp72
-rw-r--r--xparts/xpart_notepad/xp_notepad_factory.h62
10 files changed, 420 insertions, 0 deletions
diff --git a/xparts/xpart_notepad/Makefile.am b/xparts/xpart_notepad/Makefile.am
new file mode 100644
index 00000000..cadb799e
--- /dev/null
+++ b/xparts/xpart_notepad/Makefile.am
@@ -0,0 +1,29 @@
+INCLUDES = -I$(srcdir)/../src/kde -I$(srcdir)/../src/interfaces -I$(prefix)/include -I$(top_srcdir) $(all_includes)
+
+#AM_CFLAGS += $(GLIB_CFLAGS) $(GTK_CFLAGS)
+
+bin_PROGRAMS = xp_notepad shell_xparthost
+
+xpart_DIR=$(srcdir)/../src/interfaces
+xparthost_DIR=$(srcdir)/../src/interfaces
+
+xp_notepad_SOURCES = xp_notepad.cpp xpart.skel xparthost.stub
+xp_notepad_LDADD = ../src/kde/libkdexparts.la
+#xp_notepad_LDFLAGS = -L$(prefix)/lib -lxpcom $(all_libraries)
+xp_notepad_LDFLAGS = -L$(prefix)/lib $(all_libraries)
+
+shell_xparthost_SOURCES = shell_xparthost.cpp
+shell_xparthost_LDADD = $(top_builddir)/xparts/src/kde/libkdexparts.la
+shell_xparthost_LDFLAGS = $(all_libraries)
+
+lib_LTLIBRARIES = libxp_notepadpart.la
+
+libxp_notepadpart_la_SOURCES = xp_notepad_factory.cpp
+libxp_notepadpart_la_LDFLAGS = -module $(all_libraries)
+libxp_notepadpart_la_LIBADD = ../src/kde/libkdexparts.la
+
+servicedir = $(kde_servicesdir)
+service_DATA = xp_notepad.desktop
+
+METASOURCES = AUTO
+
diff --git a/xparts/xpart_notepad/README b/xparts/xpart_notepad/README
new file mode 100644
index 00000000..0d1ba65e
--- /dev/null
+++ b/xparts/xpart_notepad/README
@@ -0,0 +1,3 @@
+
+xpart_notepad is a small XPart editor. Use it to understand how to use XPart
+technology.
diff --git a/xparts/xpart_notepad/shell_xparthost.cpp b/xparts/xpart_notepad/shell_xparthost.cpp
new file mode 100644
index 00000000..bd6a9418
--- /dev/null
+++ b/xparts/xpart_notepad/shell_xparthost.cpp
@@ -0,0 +1,80 @@
+
+#include "xparthost_kpart.h"
+#include "shell_xparthost.h"
+
+#include <dcopclient.h>
+#include <dcopobject.h>
+#include <kapplication.h>
+#include <kstdaction.h>
+#include <kaction.h>
+#include <kmainwindow.h>
+#include <kprocess.h>
+#include <kparts/mainwindow.h>
+#include <kdebug.h>
+
+ShellWindow::ShellWindow()
+ : KParts::MainWindow()
+{
+ m_host = new XPartHost_KPart( this, 0, this, "parthost" );
+
+ setCentralWidget( m_host->widget() );
+
+ connect(m_host, SIGNAL( actionsInitialized() ), this, SLOT( mergeGUI() ) );
+
+ // Launch our XPart child.
+ m_partProcess = new KProcess;
+ *m_partProcess << "./xp_notepad"
+ << kapp->dcopClient()->appId() << m_host->objId();
+ m_partProcess->start();
+
+ // Init our Gui
+ (void) new KAction( "Hop", 0, this, SLOT(hop()), actionCollection(), "hop" );
+ KStdAction::quit( this, SLOT( close() ), actionCollection() );
+ KSelectAction *s = new KSelectAction( "http://www.kde.org" , 0,
+ actionCollection(), "location" );
+ connect( s, SIGNAL(activated( const QString& ) ), this, SLOT( slotOpenUrl( const QString & ) ) );
+ s->setEditable(true);
+
+ kdDebug() << "KShell window created" << endl;
+}
+
+ShellWindow::~ShellWindow()
+{
+ delete m_partProcess;
+}
+
+void ShellWindow::hop()
+{
+ kdDebug() << "hop called!" << endl;
+}
+
+void ShellWindow::slotOpenUrl( const QString &url )
+{
+ kdDebug() << "this=" << this;
+ kdDebug() << "url=" << url << endl;
+ m_host->openURL(url.latin1());
+}
+
+void ShellWindow::mergeGUI()
+{
+ qDebug("initGUI");
+ setXMLFile("shell_xparthost.rc");
+ createGUI( m_host );
+ m_host->widget()->setFocus();
+ kdDebug() << "focus set to embedded widget" << endl;
+}
+
+int main( int argc, char **argv )
+{
+ KApplication app( argc, argv, "xparthost_shell" );
+
+ app.dcopClient()->registerAs("xparthost_shell");
+
+ ShellWindow *w = new ShellWindow;
+ w->resize(500, 500);
+ w->show();
+
+ return app.exec();
+}
+
+#include "shell_xparthost.moc"
diff --git a/xparts/xpart_notepad/shell_xparthost.h b/xparts/xpart_notepad/shell_xparthost.h
new file mode 100644
index 00000000..02982326
--- /dev/null
+++ b/xparts/xpart_notepad/shell_xparthost.h
@@ -0,0 +1,29 @@
+#ifndef shell_xparthost_h
+#define shell_xparthost_h
+
+#include <kmainwindow.h>
+#include <kparts/mainwindow.h>
+#include <kdebug.h>
+
+class KProcess;
+
+class ShellWindow : public KParts::MainWindow
+{
+ Q_OBJECT
+
+public:
+ ShellWindow();
+ virtual ~ShellWindow();
+
+public slots:
+ void hop();
+
+ void slotOpenUrl( const QString &url );
+ void mergeGUI();
+
+private:
+ XPartHost_KPart *m_host;
+ KProcess *m_partProcess;
+};
+
+#endif
diff --git a/xparts/xpart_notepad/shell_xparthost.rc b/xparts/xpart_notepad/shell_xparthost.rc
new file mode 100644
index 00000000..8164b5b4
--- /dev/null
+++ b/xparts/xpart_notepad/shell_xparthost.rc
@@ -0,0 +1,11 @@
+<!DOCTYPE kpartgui SYSTEM "kpartgui.dtd">
+<kpartgui name="xparthost_shell" version="1">
+
+<MenuBar>
+ <Menu name="File">
+ <Merge/>
+ </Menu>
+ <Merge/>
+</MenuBar>
+
+</kpartgui>
diff --git a/xparts/xpart_notepad/xp_notepad.cpp b/xparts/xpart_notepad/xp_notepad.cpp
new file mode 100644
index 00000000..57173bbb
--- /dev/null
+++ b/xparts/xpart_notepad/xp_notepad.cpp
@@ -0,0 +1,114 @@
+#include <dcopclient.h>
+#include <kapplication.h>
+#include <qmultilineedit.h>
+#include <qfile.h>
+#include <qtextstream.h>
+#include <stdio.h>
+#include <iostream.h>
+#include <xpart.h>
+#include <kdebug.h>
+
+#include "xparthost_stub.h"
+
+class XPartNotepad : public QMultiLineEdit, virtual public XPart
+{
+
+public:
+ XPartNotepad(char *)
+ {
+ setText("This is a xpart component editor");
+ setReadOnly( false );
+ resize( 200, 200 );
+ QMultiLineEdit::setFocus();
+ }
+
+ /** needed by XPartManager to embed the part */
+ Q_UINT32 windowId()
+ { return winId(); }
+
+ /** used by XPartManager to show the part */
+ void show()
+ { printf("show()\n"); QWidget::show(); }
+
+ /** sent by the XPartHost to query an url */
+ bool openURL( const QCString& url )
+ { printf("openURL %s\n", (const char *) url );
+ QFile f(url);
+ QString s;
+ if ( ! f.open(IO_ReadOnly) ) {
+ return false;
+ }
+ QTextStream t( &f );
+ while ( !t.eof() ) {
+ s += t.readLine() + "\n";
+ }
+ f.close();
+ setText(s);
+ return true;
+ }
+
+ /** sent by the XPartHost to close an url */
+ bool closeURL()
+ { printf("closeURL\n"); setText(""); return true; }
+
+ /** called when an action has been activated. name is
+ * the name of the
+ * * action, state is used with Toggle actions to
+ * precise the current state.
+ * */
+ void activateAction( const QString &name, int state )
+ { printf("activateAction: %s, %d\n", name.latin1(), state ); }
+
+ /** are extentions available -> browser extension
+ * / TextEditor ? */
+ DCOPRef queryExtension( const QCString& extension )
+ { printf("query Extension : %s\n", (const char * ) extension ); return DCOPRef(); }
+
+
+protected:
+ void focusInEvent( QFocusEvent * )
+ { kdDebug() << "Focus in" << endl; QMultiLineEdit::setFocus(); }
+ void focusOutEvent( QFocusEvent * )
+ { kdDebug() << "Focus Out" << endl;QMultiLineEdit::setFocus(); }
+};
+
+int main( int argc, char **argv )
+{
+ if (argc < 3) {
+ printf("application need arguments");
+ return 1;
+ }
+ printf("args: XPartHost appId = %s , XPartHost_KPart objId = %s\n", argv[1], argv[2] );
+
+ KApplication app( argc, argv, "xp_notepad" );
+ XPartNotepad * xpn = new XPartNotepad("xp_notepad");
+ app.setMainWidget( xpn );
+ app.dcopClient()->attach();
+ QCString appId = app.dcopClient()->registerAs("xp_notepad", true);
+
+ XPartHost_stub xph_stub( argv[1], argv[2] );
+ DCOPRef xpn_dcopref( xpn );
+
+ DCOPRef xph_dcopref = xph_stub.registerXPart(xpn_dcopref);
+ if ( xph_dcopref.isNull() ) {
+ printf("could not register\n");
+ return 2;
+ }
+ printf("XPart registered!\n");
+
+ // Initializing actions:
+ const char * actions =
+"<!DOCTYPE actionList SYSTEM \"actionlist.dtd\">\n"
+"<Actionlist>\n"
+" <Action name=\"open_url\" />\n"
+" <Action name=\"close_url\" />\n"
+" <Action name=\"nonexistant\" />\n"
+" <XMLFile location=\"./xp_notepad.rc\" />\n"
+"</Actionlist>\n";
+ xph_stub.createActions( actions );
+
+ return app.exec();
+}
+
+
+
diff --git a/xparts/xpart_notepad/xp_notepad.desktop b/xparts/xpart_notepad/xp_notepad.desktop
new file mode 100644
index 00000000..bda514ed
--- /dev/null
+++ b/xparts/xpart_notepad/xp_notepad.desktop
@@ -0,0 +1,9 @@
+[Desktop Entry]
+Type=Service
+Exec=foobar
+Comment=XPart Notepad Editor
+Icon=
+Name=XNotepad (XPart example)
+MimeType=text/english;text/plain;text/x-makefile;text/x-c++hdr;text/x-c++src;text/x-chdr;text/x-csrc;text/x-java;text/x-moc;text/x-pascal;text/x-tcl;text/x-tex;application/x-shellscript;text/x-c;text/x-c++;text/x-diff;
+ServiceTypes=KParts/ReadOnlyPart
+X-KDE-Library=libxp_notepadpart
diff --git a/xparts/xpart_notepad/xp_notepad.rc b/xparts/xpart_notepad/xp_notepad.rc
new file mode 100644
index 00000000..13428980
--- /dev/null
+++ b/xparts/xpart_notepad/xp_notepad.rc
@@ -0,0 +1,11 @@
+<!DOCTYPE kpartgui SYSTEM "kpartgui.dtd">
+<kpartgui name="notepad_xpart" version="1">
+<MenuBar>
+ <Menu name="File">
+ <Action name="open_url" />
+ <Action name="close_url" />
+ <Separator />
+ <Action name="nonexistant" />
+ </Menu>
+</MenuBar>
+</kpartgui>
diff --git a/xparts/xpart_notepad/xp_notepad_factory.cpp b/xparts/xpart_notepad/xp_notepad_factory.cpp
new file mode 100644
index 00000000..232e5756
--- /dev/null
+++ b/xparts/xpart_notepad/xp_notepad_factory.cpp
@@ -0,0 +1,72 @@
+/* This file is part of the KDE project
+ *
+ * Copyright (C) 2000 Simon Hausmann <hausmann@kde.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include <dcopclient.h>
+#include <dcopobject.h>
+#include <kapplication.h>
+#include <kstdaction.h>
+#include <kaction.h>
+#include <kmainwindow.h>
+#include <kprocess.h>
+#include <kparts/mainwindow.h>
+#include <kdebug.h>
+#include "xp_notepad_factory.h"
+
+extern "C"
+{
+ void *init_libxp_notepadpart()
+ {
+ return new XP_NotepadFactory( true );
+ }
+};
+
+
+KParts::Part *XP_NotepadFactory::createPartObject( QWidget *parentWidget, const char *widgetName, QObject *parent, const char *name, const char *className, const QStringList & )
+{
+ return new XP_NotepadPart( parentWidget, widgetName, parent, name );
+}
+
+XP_NotepadPart::XP_NotepadPart(QWidget *parentWidget, const char *widgetName,
+ QObject *parent, const char *name)
+ : XPartHost_KPart(parentWidget, widgetName, parent, name)
+{
+ m_partProcess = new KProcess;
+ *m_partProcess << "xnotepard"
+ << kapp->dcopClient()->appId() << objId();
+ m_partProcess->start();
+
+ qDebug("---->>>>>> enter loop");
+ kapp->enter_loop();
+ qDebug("----<<<<<< left loop");
+}
+
+XP_NotepadPart::~XP_NotepadPart()
+{
+ delete m_partProcess;
+}
+
+void XP_NotepadPart::createActions( const QCString &xmlActions )
+{
+ XPartHost_KPart::createActions( xmlActions );
+ qDebug("----<<<<<< exit loop");
+ kapp->exit_loop();
+}
+
+#include "xp_notepad_factory.moc"
diff --git a/xparts/xpart_notepad/xp_notepad_factory.h b/xparts/xpart_notepad/xp_notepad_factory.h
new file mode 100644
index 00000000..efc812fd
--- /dev/null
+++ b/xparts/xpart_notepad/xp_notepad_factory.h
@@ -0,0 +1,62 @@
+/* This file is part of the KDE project
+ *
+ * Copyright (C) 2000 Simon Hausmann <hausmann@kde.org>
+ * Copyright (C) 2001 Philippe Fremy <pfremy@chez.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+#ifndef __xp_notepad_factory_h__
+#define __xp_notepad_factory_h__
+
+#include <kparts/factory.h>
+#include <qptrlist.h>
+#include <kurl.h>
+#include "xparthost_kpart.h"
+
+class KInstance;
+class KAboutData;
+class KHTMLSettings;
+class KHTMLPart;
+class KProcess;
+
+class XP_NotepadFactory : public KParts::Factory
+{
+ Q_OBJECT
+public:
+ XP_NotepadFactory( bool clone = false ) {}
+ virtual ~XP_NotepadFactory() {}
+
+ virtual KParts::Part *createPartObject( QWidget *parentWidget, const char *widgetName, QObject *parent, const char *name, const char *className, const QStringList &args );
+
+};
+
+
+
+class XP_NotepadPart : public XPartHost_KPart
+{
+ Q_OBJECT
+
+public:
+ XP_NotepadPart(QWidget *parentWidget, const char *widgetName,
+ QObject *parent, const char *name);
+ virtual ~XP_NotepadPart();
+
+ virtual void createActions( const QCString &xmlActions );
+private:
+ KProcess *m_partProcess;
+};
+
+#endif