summaryrefslogtreecommitdiffstats
path: root/kparts/tests
diff options
context:
space:
mode:
Diffstat (limited to 'kparts/tests')
-rw-r--r--kparts/tests/Makefile.am46
-rw-r--r--kparts/tests/README5
-rw-r--r--kparts/tests/example.cpp135
-rw-r--r--kparts/tests/example.h39
-rw-r--r--kparts/tests/ghostview.cpp119
-rw-r--r--kparts/tests/ghostview.h22
-rw-r--r--kparts/tests/ghostviewtest_shell.rc15
-rw-r--r--kparts/tests/kpartstest_part1.rc18
-rw-r--r--kparts/tests/kpartstest_shell.rc28
-rw-r--r--kparts/tests/normalktm.cpp122
-rw-r--r--kparts/tests/normalktm.h38
-rw-r--r--kparts/tests/notepad.cpp101
-rw-r--r--kparts/tests/notepad.desktop86
-rw-r--r--kparts/tests/notepad.h42
-rw-r--r--kparts/tests/notepadpart.cpp5
-rw-r--r--kparts/tests/notepadpart.rc14
-rw-r--r--kparts/tests/parts.cpp90
-rw-r--r--kparts/tests/parts.h43
-rw-r--r--kparts/tests/plugin_foobar.rc12
-rw-r--r--kparts/tests/plugin_spellcheck.cpp39
-rw-r--r--kparts/tests/plugin_spellcheck.h18
-rw-r--r--kparts/tests/plugin_spellcheck.rc15
22 files changed, 1052 insertions, 0 deletions
diff --git a/kparts/tests/Makefile.am b/kparts/tests/Makefile.am
new file mode 100644
index 000000000..8474e1132
--- /dev/null
+++ b/kparts/tests/Makefile.am
@@ -0,0 +1,46 @@
+
+INCLUDES= -I$(top_srcdir) -I$(top_srcdir)/libltdl -I$(top_srcdir)/kfile -I$(top_srcdir)/kio $(all_includes)
+AM_LDFLAGS = $(all_libraries)
+LDADD = $(LIB_KPARTS)
+
+check_PROGRAMS = kpartstest normalktmtest ghostviewtest
+
+kpartstest_SOURCES = example.cpp parts.cpp
+kpartstest_LDADD = libnotepad.la $(LIB_KPARTS)
+normalktmtest_SOURCES = normalktm.cpp parts.cpp
+normalktmtest_LDADD = libnotepad.la $(LIB_KPARTS)
+ghostviewtest_SOURCES = ghostview.cpp
+ghostviewtest_LDADD = $(LIB_KPARTS)
+
+# These are not really libraries, but modules dynamically opened.
+# So they should be installed in kde_module_dir, which is usually $prefix/lib/kde3
+kde_module_LTLIBRARIES = libspellcheckplugin.la libnotepadpart.la
+
+libspellcheckplugin_la_SOURCES = plugin_spellcheck.cpp
+libspellcheckplugin_la_LIBADD = $(LIB_KPARTS)
+libspellcheckplugin_la_LDFLAGS = -module $(KDE_PLUGIN)
+
+libnotepadpart_la_SOURCES = notepadpart.cpp
+libnotepadpart_la_LIBADD = libnotepad.la $(LIB_KPARTS)
+libnotepadpart_la_LDFLAGS = -module $(KDE_PLUGIN)
+
+noinst_LTLIBRARIES = libnotepad.la
+libnotepad_la_SOURCES = notepad.cpp
+
+rcdir = $(kde_datadir)/kpartstest
+rc_DATA = kpartstest_shell.rc
+
+testpartdir = $(kde_datadir)/kpartstestpart
+testpart_DATA = kpartstest_part1.rc
+
+notepaddir = $(kde_datadir)/notepadpart
+notepad_DATA = notepadpart.rc
+
+ghostviewtestdir = $(kde_datadir)/ghostviewtest
+ghostviewtest_DATA = ghostviewtest_shell.rc
+
+pluginsdir = $(kde_datadir)/notepadpart/kpartplugins
+plugins_DATA = plugin_foobar.rc plugin_spellcheck.rc
+
+METASOURCES = AUTO
+
diff --git a/kparts/tests/README b/kparts/tests/README
new file mode 100644
index 000000000..38e43eaee
--- /dev/null
+++ b/kparts/tests/README
@@ -0,0 +1,5 @@
+In order to test embedding the notepad part in konqueror, you need
+to "make install", to install the libs, and to copy notepad.desktop
+into $KDEDIR/share/services/, and remove kwrite.desktop from
+$KDEDIR/share/applnk/... (at least the ServiceTypes line of it)
+
diff --git a/kparts/tests/example.cpp b/kparts/tests/example.cpp
new file mode 100644
index 000000000..51f493686
--- /dev/null
+++ b/kparts/tests/example.cpp
@@ -0,0 +1,135 @@
+
+#include "example.h"
+#include "parts.h"
+#include "notepad.h"
+
+#include <qsplitter.h>
+#include <qcheckbox.h>
+#include <qdir.h>
+
+#include <kiconloader.h>
+#include <kstandarddirs.h>
+#include <kapplication.h>
+#include <kmessagebox.h>
+#include <kaction.h>
+#include <klocale.h>
+
+Shell::Shell()
+{
+ setXMLFile( "kpartstest_shell.rc" );
+
+ m_manager = new KParts::PartManager( this );
+
+ // When the manager says the active part changes, the builder updates (recreates) the GUI
+ connect( m_manager, SIGNAL( activePartChanged( KParts::Part * ) ),
+ this, SLOT( createGUI( KParts::Part * ) ) );
+
+ // We can do this "switch active part" because we have a splitter with
+ // two items in it.
+ // I wonder what kdevelop uses/will use to embed kedit, BTW.
+ m_splitter = new QSplitter( this );
+
+ m_part1 = new Part1(this, m_splitter);
+ m_part2 = new Part2(this, m_splitter);
+
+ KActionCollection *coll = actionCollection();
+
+ (void)new KAction( "&View local file", 0, this, SLOT( slotFileOpen() ), coll, "open_local_file" );
+ (void)new KAction( "&View remote file", 0, this, SLOT( slotFileOpenRemote() ), coll, "open_remote_file" );
+
+ m_paEditFile = new KAction( "&Edit file", 0, this, SLOT( slotFileEdit() ), coll, "edit_file" );
+ m_paCloseEditor = new KAction( "&Close file editor", 0, this, SLOT( slotFileCloseEditor() ), coll, "close_editor" );
+ m_paCloseEditor->setEnabled(false);
+ KAction * paQuit = new KAction( "&Quit", 0, this, SLOT( close() ), coll, "shell_quit" );
+ paQuit->setIconSet(QIconSet(BarIcon("exit")));
+
+ (void)new KAction( "Yet another menu item", 0, coll, "shell_yami" );
+ (void)new KAction( "Yet another submenu item", 0, coll, "shell_yasmi" );
+
+ setCentralWidget( m_splitter );
+ m_splitter->setMinimumSize( 400, 300 );
+
+ m_splitter->show();
+
+ m_manager->addPart( m_part1, true ); // sets part 1 as the active part
+ m_manager->addPart( m_part2, false );
+ m_editorpart = 0;
+}
+
+Shell::~Shell()
+{
+ disconnect( m_manager, 0, this, 0 );
+}
+
+void Shell::slotFileOpen()
+{
+ if ( ! m_part1->openURL( locate("data", KGlobal::instance()->instanceName()+"/kpartstest_shell.rc" ) ) )
+ KMessageBox::error(this,"Couldn't open file !");
+}
+
+void Shell::slotFileOpenRemote()
+{
+ KURL u ( "http://www.kde.org/index.html" );
+ if ( ! m_part1->openURL( u ) )
+ KMessageBox::error(this,"Couldn't open file !");
+}
+
+void Shell::embedEditor()
+{
+ if ( m_manager->activePart() == m_part2 )
+ createGUI( 0L );
+
+ // replace part2 with the editor part
+ delete m_part2;
+ m_part2 = 0L;
+ m_editorpart = new NotepadPart( m_splitter, "editor",
+ this, "NotepadPart" );
+ m_editorpart->setReadWrite(); // read-write mode
+ m_manager->addPart( m_editorpart );
+ m_paEditFile->setEnabled(false);
+ m_paCloseEditor->setEnabled(true);
+}
+
+void Shell::slotFileCloseEditor()
+{
+ // It is very important to close the url of a read-write part
+ // before destroying it. This allows to save the document (if modified)
+ // and also to cancel.
+ if ( ! m_editorpart->closeURL() )
+ return;
+
+ // Is this necessary ? (David)
+ if ( m_manager->activePart() == m_editorpart )
+ createGUI( 0L );
+
+ delete m_editorpart;
+ m_editorpart = 0L;
+ m_part2 = new Part2(this, m_splitter);
+ m_manager->addPart( m_part2 );
+ m_paEditFile->setEnabled(true);
+ m_paCloseEditor->setEnabled(false);
+}
+
+void Shell::slotFileEdit()
+{
+ if ( !m_editorpart )
+ embedEditor();
+ // TODO use KFileDialog to allow testing remote files
+ if ( ! m_editorpart->openURL( QDir::current().absPath()+"/kpartstest_shell.rc" ) )
+ KMessageBox::error(this,"Couldn't open file !");
+}
+
+int main( int argc, char **argv )
+{
+ KApplication app( argc, argv, "kpartstest" );
+
+ Shell *shell = new Shell;
+
+ shell->show();
+
+ app.exec();
+
+ return 0;
+}
+
+#include "example.moc"
diff --git a/kparts/tests/example.h b/kparts/tests/example.h
new file mode 100644
index 000000000..ec3d67540
--- /dev/null
+++ b/kparts/tests/example.h
@@ -0,0 +1,39 @@
+
+#ifndef __example_h__
+#define __example_h__
+
+#include <kparts/partmanager.h>
+#include <kparts/mainwindow.h>
+
+class KAction;
+class QWidget;
+
+class Shell : public KParts::MainWindow
+{
+ Q_OBJECT
+public:
+ Shell();
+ virtual ~Shell();
+
+protected slots:
+ void slotFileOpen();
+ void slotFileOpenRemote();
+ void slotFileEdit();
+ void slotFileCloseEditor();
+
+protected:
+ void embedEditor();
+
+private:
+
+ KAction * m_paEditFile;
+ KAction * m_paCloseEditor;
+
+ KParts::ReadOnlyPart *m_part1;
+ KParts::Part *m_part2;
+ KParts::ReadWritePart *m_editorpart;
+ KParts::PartManager *m_manager;
+ QWidget *m_splitter;
+};
+
+#endif
diff --git a/kparts/tests/ghostview.cpp b/kparts/tests/ghostview.cpp
new file mode 100644
index 000000000..49736abfc
--- /dev/null
+++ b/kparts/tests/ghostview.cpp
@@ -0,0 +1,119 @@
+#include <kiconloader.h>
+#include <kstandarddirs.h>
+#include <kapplication.h>
+#include <kaction.h>
+#include <klocale.h>
+#include <kfiledialog.h>
+#include <kmessagebox.h>
+#include <kcmdlineargs.h>
+#include <klibloader.h>
+
+#include <qwidget.h>
+#include <qdir.h>
+#include <qfile.h>
+
+#include <ktrader.h>
+
+#include "ghostview.h"
+
+Shell::Shell()
+{
+ setXMLFile( "ghostviewtest_shell.rc" );
+
+ KAction * paOpen = new KAction( "&Open file" , "fileopen", 0, this,
+ SLOT( slotFileOpen() ), actionCollection(), "file_open" );
+
+ KAction * paQuit = new KAction( "&Quit" , "exit", 0, this, SLOT( close() ), actionCollection(), "file_quit" );
+
+ // Try to find a postscript component first
+ KTrader::OfferList offers = KTrader::self()->query("application/postscript", "('KParts/ReadOnlyPart' in ServiceTypes) or ('Browser/View' in ServiceTypes)");
+
+ KLibFactory *factory = 0;
+ m_gvpart = 0;
+ KTrader::OfferList::Iterator it(offers.begin());
+ for( ; it != offers.end(); ++it)
+ {
+ KService::Ptr ptr = (*it);
+
+ factory = KLibLoader::self()->factory( QFile::encodeName(ptr->library()) );
+ if (factory)
+ {
+ m_gvpart = static_cast<KParts::ReadOnlyPart *>(factory->create(this, ptr->name().latin1(), "KParts::ReadOnlyPart"));
+ setCentralWidget( m_gvpart->widget() );
+ // Integrate its GUI
+ createGUI( m_gvpart );
+
+ break;
+ }
+ }
+
+ // if we couldn't find a component with the trader, try the
+ // kghostview library directly. if this ever happens, then something
+ // is seriously screwed up, though -- the kghostview component
+ // should be picked up by the trader
+ if (!m_gvpart)
+ {
+ factory = KLibLoader::self()->factory( "libkghostview" );
+ if (factory)
+ {
+ // Create the part
+ m_gvpart = (KParts::ReadOnlyPart *)factory->create( this, "kgvpart",
+ "KParts::ReadOnlyPart" );
+ // Set the main widget
+ setCentralWidget( m_gvpart->widget() );
+ // Integrate its GUI
+ createGUI( m_gvpart );
+ }
+ else
+ {
+ KMessageBox::error(this, "No libkghostview found !");
+ }
+ }
+ // Set a reasonable size
+ resize( 600, 350 );
+}
+
+Shell::~Shell()
+{
+ delete m_gvpart;
+}
+
+void Shell::openURL( const KURL & url )
+{
+ m_gvpart->openURL( url );
+}
+
+void Shell::slotFileOpen()
+{
+ KURL url = KFileDialog::getOpenURL( QString::null, "*.ps|Postscript files (*.ps)", 0L, "file dialog" );
+
+ if( !url.isEmpty() )
+ openURL( url );
+}
+
+static KCmdLineOptions options[] =
+{
+ { "+file(s)", "Files to load", 0 },
+ KCmdLineLastOption
+};
+static const char version[] = "v0.0.1 2000 (c) David Faure";
+static const char description[] = "This is a test shell for the kghostview part.";
+
+int main( int argc, char **argv )
+{
+ KCmdLineArgs::init(argc, argv, "ghostviewtest", description, version);
+ KCmdLineArgs::addCmdLineOptions( options ); // Add my own options.
+ KApplication app;
+ KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
+ Shell *shell = new Shell;
+ if ( args->count() == 1 )
+ {
+ // Allow full paths, but also simple filenames from current dir
+ KURL url( QDir::currentDirPath()+"/", args->arg(0) );
+ shell->openURL( url );
+ }
+ shell->show();
+ return app.exec();
+}
+
+#include "ghostview.moc"
diff --git a/kparts/tests/ghostview.h b/kparts/tests/ghostview.h
new file mode 100644
index 000000000..5d99d4f0e
--- /dev/null
+++ b/kparts/tests/ghostview.h
@@ -0,0 +1,22 @@
+#ifndef __example_h__
+#define __example_h__
+
+#include <kparts/mainwindow.h>
+
+class Shell : public KParts::MainWindow
+{
+ Q_OBJECT
+public:
+ Shell();
+ virtual ~Shell();
+
+ void openURL( const KURL & url );
+
+protected slots:
+ void slotFileOpen();
+
+private:
+ KParts::ReadOnlyPart *m_gvpart;
+};
+
+#endif
diff --git a/kparts/tests/ghostviewtest_shell.rc b/kparts/tests/ghostviewtest_shell.rc
new file mode 100644
index 000000000..0bae67c82
--- /dev/null
+++ b/kparts/tests/ghostviewtest_shell.rc
@@ -0,0 +1,15 @@
+<!DOCTYPE kpartgui>
+<kpartgui name="KGVShell">
+<MenuBar>
+ <Menu name="file"><Text>&amp;File</Text>
+ <Action name="file_open"/>
+ <Action name="file_quit"/>
+ </Menu>
+</MenuBar>
+<ToolBar name="KGV-ToolBar">
+ <Action name="file_open"/>
+ <Action name="file_quit"/>
+</ToolBar>
+<StatusBar/>
+</kpartgui>
+
diff --git a/kparts/tests/kpartstest_part1.rc b/kparts/tests/kpartstest_part1.rc
new file mode 100644
index 000000000..9f4a75687
--- /dev/null
+++ b/kparts/tests/kpartstest_part1.rc
@@ -0,0 +1,18 @@
+<!DOCTYPE kpartgui>
+<kpartgui name="Part">
+<MenuBar>
+ <Menu name="file"><Text>&amp;File</Text>
+ <Action name="p1_blah"/>
+ </Menu>
+ <Menu name="Part1Menu"><text>Part1's Menu</text>
+ <Action name="p1_blah"/>
+ <Menu name="Part1Sub"><text>Stupid Submenu</text>
+ <Action name="p1_blah"/>
+ </Menu>
+ </Menu>
+</MenuBar>
+<ToolBar name="Part1-ToolBar">
+ <Action name="p1_blah"/>
+</ToolBar>
+<StatusBar/>
+</kpartgui>
diff --git a/kparts/tests/kpartstest_shell.rc b/kparts/tests/kpartstest_shell.rc
new file mode 100644
index 000000000..52790f9b6
--- /dev/null
+++ b/kparts/tests/kpartstest_shell.rc
@@ -0,0 +1,28 @@
+<!DOCTYPE kpartgui>
+<kpartgui name="Shell">
+<MenuBar>
+ <Menu name="file"><Text>&amp;File</Text>
+ <Action name="open_local_file"/>
+ <Action name="open_remote_file"/>
+ <Separator/>
+ <Action name="edit_file"/>
+ <Action name="close_editor"/>
+ <Merge name="NotepadPart"/>
+ <Separator/>
+ <Merge/>
+ <Separator/>
+ <Action name="shell_quit"/>
+ </Menu>
+ <Merge/>
+ <Menu name="blah"><Text>BlahFoo</Text>
+ <Action name="shell_yami"/>
+ <Menu name="nonsense"><Text>Dummdidumm</Text>
+ <Action name="shell_yasmi"/>
+ </Menu>
+ </Menu>
+</MenuBar>
+<ToolBar name="mainToolBar">
+ <Action name="shell_quit"/>
+</ToolBar>
+<StatusBar/>
+</kpartgui>
diff --git a/kparts/tests/normalktm.cpp b/kparts/tests/normalktm.cpp
new file mode 100644
index 000000000..f8884ae74
--- /dev/null
+++ b/kparts/tests/normalktm.cpp
@@ -0,0 +1,122 @@
+
+#include "normalktm.h"
+#include "parts.h"
+#include "notepad.h"
+
+#include <qsplitter.h>
+#include <qcheckbox.h>
+#include <qdir.h>
+
+#include <kiconloader.h>
+#include <kstandarddirs.h>
+#include <kapplication.h>
+#include <kmessagebox.h>
+#include <kaction.h>
+#include <klocale.h>
+
+#include <kmenubar.h>
+
+Shell::Shell()
+{
+ // We can do this "switch active part" because we have a splitter with
+ // two items in it.
+ // I wonder what kdevelop uses/will use to embed kedit, BTW.
+ m_splitter = new QSplitter( this );
+
+ m_part1 = new Part1(this, m_splitter);
+ m_part2 = new Part2(this, m_splitter);
+
+ QPopupMenu * pFile = new QPopupMenu( this );
+ menuBar()->insertItem( "File", pFile );
+ QObject * coll = this;
+ KAction * paLocal = new KAction( "&View local file", 0, this, SLOT( slotFileOpen() ), coll, "open_local_file" );
+ // No XML : we need to plug our actions ourselves
+ paLocal->plug( pFile );
+
+ KAction * paRemote = new KAction( "&View remote file", 0, this, SLOT( slotFileOpenRemote() ), coll, "open_remote_file" );
+ paRemote->plug( pFile );
+
+ m_paEditFile = new KAction( "&Edit file", 0, this, SLOT( slotFileEdit() ), coll, "edit_file" );
+ m_paEditFile->plug( pFile );
+
+ m_paCloseEditor = new KAction( "&Close file editor", 0, this, SLOT( slotFileCloseEditor() ), coll, "close_editor" );
+ m_paCloseEditor->setEnabled(false);
+ m_paCloseEditor->plug( pFile );
+
+ KAction * paQuit = new KAction( "&Quit", 0, this, SLOT( close() ), coll, "shell_quit" );
+ paQuit->setIconSet(QIconSet(BarIcon("exit")));
+ paQuit->plug( pFile );
+
+ setCentralWidget( m_splitter );
+ m_splitter->setMinimumSize( 400, 300 );
+
+ m_splitter->show();
+
+ m_editorpart = 0;
+}
+
+Shell::~Shell()
+{
+}
+
+void Shell::slotFileOpen()
+{
+ if ( ! m_part1->openURL( locate("data", KGlobal::instance()->instanceName()+"/kpartstest_shell.rc" ) ) )
+ KMessageBox::error(this,"Couldn't open file !");
+}
+
+void Shell::slotFileOpenRemote()
+{
+ KURL u ( "http://www.kde.org/index.html" );
+ if ( ! m_part1->openURL( u ) )
+ KMessageBox::error(this,"Couldn't open file !");
+}
+
+void Shell::embedEditor()
+{
+ // replace part2 with the editor part
+ delete m_part2;
+ m_part2 = 0L;
+ m_editorpart = new NotepadPart( m_splitter, "editor",
+ this, "NotepadPart" );
+ m_editorpart->setReadWrite(); // read-write mode
+ ////// m_manager->addPart( m_editorpart );
+ m_editorpart->widget()->show(); //// we need to do this in a normal KTM....
+ m_paEditFile->setEnabled(false);
+ m_paCloseEditor->setEnabled(true);
+}
+
+void Shell::slotFileCloseEditor()
+{
+ delete m_editorpart;
+ m_editorpart = 0L;
+ m_part2 = new Part2(this, m_splitter);
+ ////// m_manager->addPart( m_part2 );
+ m_part2->widget()->show(); //// we need to do this in a normal KTM....
+ m_paEditFile->setEnabled(true);
+ m_paCloseEditor->setEnabled(false);
+}
+
+void Shell::slotFileEdit()
+{
+ if ( !m_editorpart )
+ embedEditor();
+ // TODO use KFileDialog to allow testing remote files
+ if ( ! m_editorpart->openURL( QDir::current().absPath()+"/kpartstest_shell.rc" ) )
+ KMessageBox::error(this,"Couldn't open file !");
+}
+
+int main( int argc, char **argv )
+{
+ KApplication app( argc, argv, "kpartstest" ); // we cheat and call ourselves kpartstest for Shell::slotFileOpen()
+
+ Shell *shell = new Shell;
+
+ shell->show();
+
+ app.exec();
+
+ return 0;
+}
+
+#include "normalktm.moc"
diff --git a/kparts/tests/normalktm.h b/kparts/tests/normalktm.h
new file mode 100644
index 000000000..bcf7b89bc
--- /dev/null
+++ b/kparts/tests/normalktm.h
@@ -0,0 +1,38 @@
+
+#ifndef __normalktm_h__
+#define __normalktm_h__
+
+#include <kparts/part.h>
+#include <kmainwindow.h>
+
+class KAction;
+class QWidget;
+
+class Shell : public KMainWindow
+{
+ Q_OBJECT
+public:
+ Shell();
+ virtual ~Shell();
+
+protected slots:
+ void slotFileOpen();
+ void slotFileOpenRemote();
+ void slotFileEdit();
+ void slotFileCloseEditor();
+
+protected:
+ void embedEditor();
+
+private:
+
+ KAction * m_paEditFile;
+ KAction * m_paCloseEditor;
+
+ KParts::ReadOnlyPart *m_part1;
+ KParts::Part *m_part2;
+ KParts::ReadWritePart *m_editorpart;
+ QWidget *m_splitter;
+};
+
+#endif
diff --git a/kparts/tests/notepad.cpp b/kparts/tests/notepad.cpp
new file mode 100644
index 000000000..8e6f5462c
--- /dev/null
+++ b/kparts/tests/notepad.cpp
@@ -0,0 +1,101 @@
+
+#include "notepad.h"
+#include <kparts/partmanager.h>
+#include <kparts/mainwindow.h>
+
+#include <qsplitter.h>
+#include <qfile.h>
+#include <qtextstream.h>
+#include <qmultilineedit.h>
+
+#include <kaboutdata.h>
+#include <kapplication.h>
+#include <kdebug.h>
+#include <kaction.h>
+#include <klocale.h>
+#include <kstatusbar.h>
+#include <kstandarddirs.h>
+
+NotepadPart::NotepadPart( QWidget* parentWidget, const char*,
+ QObject* parent, const char* name,
+ const QStringList& )
+ : KParts::ReadWritePart( parent, name )
+{
+ setInstance( NotepadFactory::instance() );
+
+ m_edit = new QMultiLineEdit( parentWidget, "NotepadPart's multiline edit" );
+ setWidget( m_edit );
+
+ (void)new KAction( "Search and replace", 0, this, SLOT( slotSearchReplace() ), actionCollection(), "searchreplace" );
+ setXMLFile( "notepadpart.rc" );
+ setReadWrite( true );
+}
+
+NotepadPart::~NotepadPart()
+{
+}
+
+void NotepadPart::setReadWrite( bool rw )
+{
+ m_edit->setReadOnly( !rw );
+ if (rw)
+ connect( m_edit, SIGNAL( textChanged() ), this, SLOT( setModified() ) );
+ else
+ disconnect( m_edit, SIGNAL( textChanged() ), this, SLOT( setModified() ) );
+
+ ReadWritePart::setReadWrite( rw );
+}
+
+KAboutData* NotepadPart::createAboutData()
+{
+ return new KAboutData( "notepadpart", I18N_NOOP( "Notepad" ), "2.0" );
+}
+
+bool NotepadPart::openFile()
+{
+ kdDebug() << "NotepadPart: opening " << m_file << endl;
+ // Hehe this is from a tutorial I did some time ago :)
+ QFile f(m_file);
+ QString s;
+ if ( f.open(IO_ReadOnly) ) {
+ QTextStream t( &f );
+ while ( !t.eof() ) {
+ s += t.readLine() + "\n";
+ }
+ f.close();
+ }
+ m_edit->setText(s);
+
+ emit setStatusBarText( m_url.prettyURL() );
+
+ return true;
+}
+
+bool NotepadPart::saveFile()
+{
+ if ( !isReadWrite() )
+ return false;
+ QFile f(m_file);
+ QString s;
+ if ( f.open(IO_WriteOnly) ) {
+ QTextStream t( &f );
+ t << m_edit->text();
+ f.close();
+ return true;
+ } else
+ return false;
+}
+
+void NotepadPart::slotSearchReplace()
+{
+ // What's this ? (David)
+/*
+ QValueList<KParts::XMLGUIServant *> plugins = KParts::Plugin::pluginServants( this );
+ QValueList<KParts::XMLGUIServant *>::ConstIterator it = plugins.begin();
+ QValueList<KParts::XMLGUIServant *>::ConstIterator end = plugins.end();
+ for (; it != end; ++it )
+ factory()->removeServant( *it );
+*/
+}
+
+#include "notepad.moc"
diff --git a/kparts/tests/notepad.desktop b/kparts/tests/notepad.desktop
new file mode 100644
index 000000000..e7f1bb432
--- /dev/null
+++ b/kparts/tests/notepad.desktop
@@ -0,0 +1,86 @@
+[Desktop Entry]
+Name=Notepad (example)
+Name[af]=Notablok (voorbeeld)
+Name[ar]=مفكرة (مثال)
+Name[az]=Qeyd dəftəri (misal)
+Name[be]=Нататнік (узор)
+Name[bn]=নোটপ্যাড (উদাহরণ)
+Name[br]=Skrabvloc'h (skouer)
+Name[bs]=Notepad (primjer)
+Name[ca]=Bloc de notes (exemple)
+Name[cs]=Poznámkový blok (příklad)
+Name[csb]=Notownik (przëmiôr)
+Name[cy]=Pad ysgrifennu (enghraifft)
+Name[da]=Notepad (eksempel)
+Name[de]=Notizblock-Beispiel
+Name[el]=Σημειωματάριο (παράδειγμα)
+Name[eo]=Notlibro (ekzemplo)
+Name[es]=Bloc de notas (ejemplo)
+Name[et]=Notepad (näidis)
+Name[eu]=Notepad (adibidea)
+Name[fa]=دفترچه یادداشت)مثال(
+Name[fi]=Muistio (esimerkki)
+Name[fr]=Bloc-notes (exemple)
+Name[fy]=Skriuwboekje (foarbyld)
+Name[ga]=Notepad (sampla)
+Name[gl]=Caderno de Notas (exemplo)
+Name[he]=פנקס רשימות (דוגמה)
+Name[hi]=नोटपैड (उदाहरण)
+Name[hr]=Notepad (primjer)
+Name[hu]=Jegyzettömb (példa)
+Name[id]=Notepad (contoh)
+Name[is]=Notepad (sýnishorn)
+Name[it]=Blocco note (esempio)
+Name[ja]=ノートパッド (例)
+Name[ka]=ბლიკნოტი (მაგალითი)
+Name[kk]=Блокнот (мысал)
+Name[km]=Notepad (ឧទាហរណ៍)
+Name[ko]=쪽지장 (보기)
+Name[lb]=Notizblock (Beispill)
+Name[lt]=Notepad (pavyzdys)
+Name[lv]=Notepads (piemērs)
+Name[mk]=Тетратка (пример)
+Name[mn]=Тэмдэглэлийн блок (Жишээ)
+Name[ms]=Notepad (contoh)
+Name[mt]=Notepad (eżempju)
+Name[nb]=Notisblokk (eksempel)
+Name[nds]=Notizzeddel (Bispeel)
+Name[ne]=नोटप्याड (उदाहरण)
+Name[nl]=Kladblok (voorbeeld)
+Name[nn]=Notisblokk (døme)
+Name[nso]=Notepad (mohlala)
+Name[oc]=Bloc de notes (exemple)
+Name[pa]=ਨੋਟਪੈਡ (ਉਦਾਹਰਨ)
+Name[pl]=Notatnik (przykład)
+Name[pt]=Bloco de Notas (exemplo)
+Name[pt_BR]=Bloco de notas (exemplo)
+Name[ro]=Notepad (exemplu)
+Name[ru]=Блокнот (пример)
+Name[rw]=Notepad (urugero)
+Name[se]=Čállingirjjáš (ovdamearka)
+Name[sk]=Poznámkový blok (Príklad)
+Name[sl]=Beležnica (zgled)
+Name[sq]=Notepad (shembull)
+Name[sr]=Бележница (пример)
+Name[sr@Latn]=Beležnica (primer)
+Name[sv]=Notepad (exempel)
+Name[ta]=நோட்பாட் (உதாரணம்)
+Name[te]=నోట్ పేడ్ (ఉదాహరణ)
+Name[tg]=Дафтари ёддошт (мисол)
+Name[th]=โน้ตแพด (ตัวอย่าง)
+Name[tr]=Not defteri (örnek)
+Name[tt]=Däftär (ürnäk)
+Name[uk]=Записна книжка (приклад)
+Name[uz]=Yon daftarcha (misol)
+Name[uz@cyrillic]=Ён дафтарча (мисол)
+Name[ven]=Hau nwalela notsi (Tsumbo)
+Name[vi]=Tập giấy (thí dụ)
+Name[xh]=Iphetshan lokubhala (umzekelo)
+Name[zh_CN]=记事本(例子)
+Name[zh_HK]=記事本(範例)
+Name[zh_TW]=記事本(範例)
+Name[zu]=Incwadi yokubhala (umfanekiso)
+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++;
+ServiceTypes=KParts/ReadOnlyPart
+X-KDE-Library=libnotepadpart
+Type=Service
diff --git a/kparts/tests/notepad.h b/kparts/tests/notepad.h
new file mode 100644
index 000000000..bd499d651
--- /dev/null
+++ b/kparts/tests/notepad.h
@@ -0,0 +1,42 @@
+
+#ifndef __notepad_h__
+#define __notepad_h__
+
+#include <kparts/genericfactory.h>
+#include <kparts/part.h>
+
+class KAboutData;
+class QMultiLineEdit;
+
+/**
+ * Who said writing a part should be complex ? :-)
+ * Here is a very simple kedit-like part
+ * @internal
+ */
+class NotepadPart : public KParts::ReadWritePart
+{
+ Q_OBJECT
+public:
+ NotepadPart( QWidget*, const char* widgetName,
+ QObject* parent, const char* name,
+ const QStringList& args = QStringList() );
+ virtual ~NotepadPart();
+
+ virtual void setReadWrite( bool rw );
+
+ static KAboutData* createAboutData();
+
+protected:
+ virtual bool openFile();
+ virtual bool saveFile();
+
+protected slots:
+ void slotSearchReplace();
+
+protected:
+ QMultiLineEdit * m_edit;
+};
+
+typedef KParts::GenericFactory<NotepadPart> NotepadFactory;
+
+#endif
diff --git a/kparts/tests/notepadpart.cpp b/kparts/tests/notepadpart.cpp
new file mode 100644
index 000000000..072503fd1
--- /dev/null
+++ b/kparts/tests/notepadpart.cpp
@@ -0,0 +1,5 @@
+#include "notepad.h"
+
+// The entry point for the part.
+K_EXPORT_COMPONENT_FACTORY( libnotepadpart, NotepadFactory )
+
diff --git a/kparts/tests/notepadpart.rc b/kparts/tests/notepadpart.rc
new file mode 100644
index 000000000..ba30eb322
--- /dev/null
+++ b/kparts/tests/notepadpart.rc
@@ -0,0 +1,14 @@
+<!DOCTYPE kpartgui>
+<kpartgui name="NotepadPart" version="2">
+<MenuBar>
+ <Menu name="file"><Text>&amp;File</Text>
+ <Menu name="NotepadSubMenu"><text>Notepad Stuff</text>
+ <Action name="searchreplace"/>
+ </Menu>
+ </Menu>
+ <Menu name="edit"><Text>&amp;Edit</Text>
+ <Action name="searchreplace"/>
+ </Menu>
+</MenuBar>
+<StatusBar/>
+</kpartgui>
diff --git a/kparts/tests/parts.cpp b/kparts/tests/parts.cpp
new file mode 100644
index 000000000..27513185c
--- /dev/null
+++ b/kparts/tests/parts.cpp
@@ -0,0 +1,90 @@
+
+#include <kparts/event.h>
+
+#include "parts.h"
+
+#include <qcheckbox.h>
+#include <qfile.h>
+#include <qdir.h>
+#include <qtextstream.h>
+#include <qmultilineedit.h>
+#include <qlineedit.h>
+#include <qvbox.h>
+
+#include <kiconloader.h>
+#include <kapplication.h>
+#include <kdebug.h>
+#include <kmessagebox.h>
+#include <kaction.h>
+#include <klocale.h>
+
+Part1::Part1( QObject *parent, QWidget * parentWidget )
+ : KParts::ReadOnlyPart( parent, "Part1" )
+{
+ m_instance = new KInstance( "kpartstestpart" );
+ setInstance( m_instance );
+ m_edit = new QMultiLineEdit( parentWidget );
+ setWidget( m_edit );
+ setXMLFile( "kpartstest_part1.rc" );
+
+ /*KAction * paBlah = */ new KAction( "Blah", "filemail", 0, actionCollection(), "p1_blah" );
+}
+
+Part1::~Part1()
+{
+ delete m_instance;
+}
+
+bool Part1::openFile()
+{
+ kdDebug() << "Part1: opening " << QFile::encodeName(m_file) << endl;
+ // Hehe this is from a tutorial I did some time ago :)
+ QFile f(m_file);
+ QString s;
+ if ( f.open(IO_ReadOnly) ) {
+ QTextStream t( &f );
+ while ( !t.eof() ) {
+ s += t.readLine() + "\n";
+ }
+ f.close();
+ } else
+ return false;
+ m_edit->setText(s);
+
+ emit setStatusBarText( m_url.prettyURL() );
+
+ return true;
+}
+
+Part2::Part2( QObject *parent, QWidget * parentWidget )
+ : KParts::Part( parent, "Part2" )
+{
+ m_instance = new KInstance( "part2" );
+ setInstance( m_instance );
+ QWidget * w = new QWidget( parentWidget, "Part2Widget" );
+ setWidget( w );
+
+ QCheckBox * cb = new QCheckBox( "something", w );
+
+ QLineEdit * l = new QLineEdit( "something", widget() );
+ l->move(0,50);
+ // Since the main widget is a dummy one, we HAVE to set
+ // strong focus for it, otherwise we get the
+ // the famous activating-file-menu-switches-part bug.
+ w->setFocusPolicy( QWidget::ClickFocus );
+
+ // setXMLFile( ... ); // no actions currently
+}
+
+Part2::~Part2()
+{
+ delete m_instance;
+}
+
+void Part2::guiActivateEvent( KParts::GUIActivateEvent * event )
+{
+ if (event->activated())
+ emit setWindowCaption("[part2 activated]");
+}
+
+#include "parts.moc"
diff --git a/kparts/tests/parts.h b/kparts/tests/parts.h
new file mode 100644
index 000000000..27ec5fa1a
--- /dev/null
+++ b/kparts/tests/parts.h
@@ -0,0 +1,43 @@
+
+#ifndef __parts_h__
+#define __parts_h__
+
+#include <kparts/part.h>
+
+class QMultiLineEdit;
+namespace KParts {
+class GUIActivateEvent;
+};
+
+class Part1 : public KParts::ReadOnlyPart
+{
+ Q_OBJECT
+public:
+ Part1( QObject *parent, QWidget * parentWidget );
+ virtual ~Part1();
+
+protected:
+ virtual bool openFile();
+
+protected:
+ QMultiLineEdit * m_edit;
+ KInstance *m_instance;
+};
+
+class Part2 : public KParts::Part
+{
+ Q_OBJECT
+public:
+ Part2( QObject *parent, QWidget * parentWidget );
+ virtual ~Part2();
+
+protected:
+ // This is not mandatory - only if you care about setting the
+ // part caption when the part is used in a multi-part environment
+ // (i.e. in a part manager)
+ // There is a default impl for ReadOnlyPart...
+ virtual void guiActivateEvent( KParts::GUIActivateEvent * );
+ KInstance *m_instance;
+};
+
+#endif
diff --git a/kparts/tests/plugin_foobar.rc b/kparts/tests/plugin_foobar.rc
new file mode 100644
index 000000000..e614e505f
--- /dev/null
+++ b/kparts/tests/plugin_foobar.rc
@@ -0,0 +1,12 @@
+<!DOCTYPE kpartplugin>
+<kpartplugin library="libfoobar">
+<MenuBar>
+ <Menu name="file"><Text>&amp;File</Text>
+ <Action name="searchreplace"/>
+ </Menu>
+ <Menu name="woohoo"><Text>fun</Text>
+ <Action name="searchreplace"/>
+ </Menu>
+</MenuBar>
+<ToolBar name="gah"/>
+</kpartplugin>
diff --git a/kparts/tests/plugin_spellcheck.cpp b/kparts/tests/plugin_spellcheck.cpp
new file mode 100644
index 000000000..156552e1b
--- /dev/null
+++ b/kparts/tests/plugin_spellcheck.cpp
@@ -0,0 +1,39 @@
+#include "notepad.h" // this plugin applies to a notepad part
+#include <qmultilineedit.h>
+#include "plugin_spellcheck.h"
+#include <kaction.h>
+#include <kgenericfactory.h>
+#include <kmessagebox.h>
+#include <klocale.h>
+#include <kdebug.h>
+
+PluginSpellCheck::PluginSpellCheck( QObject* parent, const char* name,
+ const QStringList& )
+ : Plugin( parent, name )
+{
+ (void) new KAction( "&Select current line (plugin)", 0, this, SLOT(slotSpellCheck()),
+ actionCollection(), "spellcheck" );
+}
+
+PluginSpellCheck::~PluginSpellCheck()
+{
+}
+
+void PluginSpellCheck::slotSpellCheck()
+{
+ kdDebug() << "Plugin parent : " << parent()->name() << " (" << parent()->className() << ")" << endl;
+ // The parent is assumed to be a NotepadPart
+ if ( !parent()->inherits("NotepadPart") )
+ KMessageBox::error(0L,"You just called the spell-check action on a wrong part (not NotepadPart)");
+ else
+ {
+ NotepadPart * part = (NotepadPart *) parent();
+ QMultiLineEdit * widget = (QMultiLineEdit *) part->widget();
+ widget->selectAll(); //selects current line !
+ }
+}
+
+K_EXPORT_COMPONENT_FACTORY( libspellcheckplugin,
+ KGenericFactory<PluginSpellCheck> );
+
+#include <plugin_spellcheck.moc>
diff --git a/kparts/tests/plugin_spellcheck.h b/kparts/tests/plugin_spellcheck.h
new file mode 100644
index 000000000..31d6b5380
--- /dev/null
+++ b/kparts/tests/plugin_spellcheck.h
@@ -0,0 +1,18 @@
+#ifndef __plugin_spellcheck_h
+#define __plugin_spellcheck_h
+
+#include <kparts/plugin.h>
+
+class PluginSpellCheck : public KParts::Plugin
+{
+ Q_OBJECT
+public:
+ PluginSpellCheck( QObject* parent = 0, const char* name = 0,
+ const QStringList& = QStringList() );
+ virtual ~PluginSpellCheck();
+
+public slots:
+ void slotSpellCheck();
+};
+
+#endif
diff --git a/kparts/tests/plugin_spellcheck.rc b/kparts/tests/plugin_spellcheck.rc
new file mode 100644
index 000000000..1980186cf
--- /dev/null
+++ b/kparts/tests/plugin_spellcheck.rc
@@ -0,0 +1,15 @@
+<!DOCTYPE kpartplugin>
+<kpartplugin library="libspellcheckplugin">
+<MenuBar>
+ <Menu name="edit"><Text>&amp;Edit</Text>
+ <Action name="spellcheck"/>
+ </Menu>
+ <Menu name="SomePluginMenu"><text>Some Cool Plugin Menu</text>
+ <Action name="spellcheck"/>
+ <Action name="searchreplace"/>
+ <Menu name="WhatASubMenu"><text>Yep</text>
+ <Action name="searchreplace"/>
+ </Menu>
+ </Menu>
+</MenuBar>
+</kpartplugin>