diff options
Diffstat (limited to 'libtdepim/komposer/core')
32 files changed, 2785 insertions, 0 deletions
diff --git a/libtdepim/komposer/core/Makefile.am b/libtdepim/komposer/core/Makefile.am new file mode 100644 index 000000000..b494e7151 --- /dev/null +++ b/libtdepim/komposer/core/Makefile.am @@ -0,0 +1,28 @@ +AM_CPPFLAGS = -I$(top_builddir)/libtdepim $(all_includes) +METASOURCES = AUTO + +lib_LTLIBRARIES = libkomposer.la + +libkomposer_la_SOURCES = plugin.cpp editor.cpp core.cpp attachment.cpp corewidget.cpp \ + settings.kcfgc pluginmanager.cpp komposerIface.skel +libkomposer_la_LDFLAGS = -no-undefined $(KDE_RPATH) -version-info 1:0:0 $(all_libraries) +libkomposer_la_LIBADD = $(LIB_KPARTS) $(top_builddir)/libtdepim/libtdepim.la -lkutils + +#kde_module_LTLIBRARIES = kcm_komposer.la + +#kcm_komposer_la_SOURCES = prefsmodule.cpp +#kcm_komposer_la_LDFLAGS = -module -avoid-version -no-undefined $(all_libraries) +#kcm_komposer_la_LIBADD = libkomposer.la $(top_builddir)/libtdepim/libtdepim.la $(LIB_KDECORE) + +kpincludedir = $(includedir)/komposer +kpinclude_HEADERS = plugin.h editor.h core.h + +rcdir = $(kde_datadir)/komposer +rc_DATA = komposerui.rc + +kde_kcfg_DATA = komposer.kcfg + +servicetypedir = $(kde_servicetypesdir) +servicetype_DATA = komposerplugin.desktop komposereditor.desktop + +kde_services_DATA = komposerconfig.desktop diff --git a/libtdepim/komposer/core/attachment.cpp b/libtdepim/komposer/core/attachment.cpp new file mode 100644 index 000000000..df803de60 --- /dev/null +++ b/libtdepim/komposer/core/attachment.cpp @@ -0,0 +1,112 @@ +// -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil; -*- +/** + * attachment.cpp + * + * Copyright (C) 2003 Zack Rusin <zack@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA + */ +#include "attachment.h" + +using namespace Komposer; + +class Attachment::Private +{ +public: + TQString name; + TQCString cte; + TQByteArray data; + TQCString type; + TQCString subType; + TQCString paramAttr; + TQString paramValue; + TQCString contDisp; +}; + +Attachment::Attachment( const TQString &name, + const TQCString &cte, + const TQByteArray &data, + const TQCString &type, + const TQCString &subType, + const TQCString ¶mAttr, + const TQString ¶mValue, + const TQCString &contDisp ) + : d( new Private ) +{ + d->name = name; + d->cte = cte; + d->data = data; + d->type = type; + d->subType = subType; + d->paramAttr = paramAttr; + d->paramValue = paramValue; + d->contDisp = contDisp; +} + +Attachment::~Attachment() +{ + delete d; d = 0; +} + +TQString +Attachment::name() const +{ + return d->name; +} + +TQCString +Attachment::cte() const +{ + return d->cte; +} + +TQByteArray +Attachment::data() const +{ + return d->data; +} + +TQCString +Attachment::type() const +{ + return d->type; +} + + +TQCString +Attachment::subType() const +{ + return d->subType; +} + +TQCString +Attachment::paramAttr() const +{ + return d->paramAttr; +} + +TQString +Attachment::paramValue() const +{ + return d->paramValue; +} + +TQCString +Attachment::contentDisposition() const +{ + return d->contDisp; +} + diff --git a/libtdepim/komposer/core/attachment.h b/libtdepim/komposer/core/attachment.h new file mode 100644 index 000000000..5c4e1ebf2 --- /dev/null +++ b/libtdepim/komposer/core/attachment.h @@ -0,0 +1,61 @@ +// -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil; -*- +/** + * attachment.h + * + * Copyright (C) 2003 Zack Rusin <zack@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA + */ +#ifndef KOMPOSER_ATTACHMENT_H +#define KOMPOSER_ATTACHMENT_H + +#include <tqstring.h> +#include <tqcstring.h> +#include <tqvaluelist.h> + +namespace Komposer +{ + + class Attachment + { + public: + Attachment( const TQString &name, + const TQCString &cte, + const TQByteArray &data, + const TQCString &type, + const TQCString &subType, + const TQCString ¶mAttr, + const TQString ¶mValue, + const TQCString &contDisp ); + ~Attachment(); + + TQString name() const; + TQCString cte() const; + TQByteArray data() const; + TQCString type() const; + TQCString subType() const; + TQCString paramAttr() const; + TQString paramValue() const; + TQCString contentDisposition() const; + + private: + class Private; + Private *d; + }; + typedef TQValueList<Attachment> AttachmentList; +} + +#endif diff --git a/libtdepim/komposer/core/core.cpp b/libtdepim/komposer/core/core.cpp new file mode 100644 index 000000000..f93e59cc9 --- /dev/null +++ b/libtdepim/komposer/core/core.cpp @@ -0,0 +1,357 @@ +// -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil; -*- +/** + * core.cpp + * + * Copyright (C) 2003 Zack Rusin <zack@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA + */ + +#include "core.h" + +#include "pluginmanager.h" +#include "editor.h" +#include "plugin.h" + +#include <ksettings/dialog.h> +#include <kplugininfo.h> +#include <kapplication.h> +#include <kconfig.h> +#include <ktrader.h> +#include <klibloader.h> +#include <kstdaction.h> +#include <klistbox.h> +#include <kiconloader.h> +#include <kstandarddirs.h> +#include <kshortcut.h> +#include <klocale.h> +#include <kstatusbar.h> +#include <kguiitem.h> +#include <kpopupmenu.h> +#include <kshortcut.h> +#include <kcmultidialog.h> +#include <kaction.h> +#include <kstdaccel.h> +#include <kdebug.h> + +#include <tqwidgetstack.h> +#include <tqhbox.h> +#include <tqwidget.h> + +using namespace Komposer; + +Core::Core( TQWidget *parent, const char *name ) + : KomposerIface( "KomposerIface" ), + KMainWindow( parent, name ), m_currentEditor( 0 ) +{ + initWidgets(); + initCore(); + initConnections(); + setInstance( new KInstance( "komposer" ) ); + + createActions(); + setXMLFile( "komposerui.rc" ); + + createGUI( 0 ); + + resize( 600, 400 ); // initial size + setAutoSaveSettings(); + + loadSettings(); +} + +Core::~Core() +{ + saveSettings(); + + //Prefs::self()->writeConfig(); +} + +void +Core::addEditor( Komposer::Editor *editor ) +{ + if ( editor->widget() ) { + m_stack->addWidget( editor->widget() ); + m_stack->raiseWidget( editor->widget() ); + editor->widget()->show(); + m_currentEditor = editor; + } + + // merge the editors GUI into the main window + //insertChildClient( editor ); + guiFactory()->addClient( editor ); +} + +void +Core::addPlugin( Komposer::Plugin *plugin ) +{ + //insertChildClient( plugin ); + guiFactory()->addClient( plugin ); +} + +void +Core::slotPluginLoaded( Plugin *plugin ) +{ + kdDebug() << "Plugin loaded "<<endl; + + Editor *editor = dynamic_cast<Editor*>( plugin ); + if ( editor ) { + addEditor( editor ); + } else { + addPlugin( plugin ); + } +} + +void +Core::slotAllPluginsLoaded() +{ + TQValueList<KPluginInfo*> plugins = m_pluginManager->availablePlugins(); + kdDebug()<<"Number of available plugins is "<< plugins.count() <<endl; + for ( TQValueList<KPluginInfo*>::iterator it = plugins.begin(); it != plugins.end(); ++it ) { + KPluginInfo *i = ( *it ); + kdDebug()<<"\tAvailable plugin "<< i->pluginName() + <<", comment = "<< i->comment() <<endl; + } + + if ( !m_stack->visibleWidget() ) { + m_pluginManager->loadPlugin( "komposer_defaulteditor", PluginManager::LoadAsync ); + } +} + +#if 0 +void +Core::slotActivePartChanged( KParts::Part *part ) +{ + if ( !part ) { + createGUI( 0 ); + return; + } + + kdDebug() << "Part activated: " << part << " with stack id. " + << m_stack->id( part->widget() )<< endl; + + createGUI( part ); +} + +void +Core::selectEditor( Komposer::Editor *editor ) +{ + if ( !editor ) + return; + + KParts::Part *part = editor->part(); + + editor->select(); + + TQPtrList<KParts::Part> *partList = const_cast<TQPtrList<KParts::Part>*>( + m_partManager->parts() ); + if ( partList->find( part ) == -1 ) + addPart( part ); + + m_partManager->setActivePart( part ); + TQWidget *view = part->widget(); + Q_ASSERT( view ); + + kdDebug()<<"Raising view "<<view<<endl; + if ( view ) + { + m_stack->raiseWidget( view ); + view->show(); + view->setFocus(); + m_currentEditor = editor; + } +} + +void +Core::selectEditor( const TQString &editorName ) +{ + +} +#endif + +void +Core::loadSettings() +{ + //kdDebug()<<"Trying to select "<< Prefs::self()->m_activeEditor <<endl; + //selectEditor( Prefs::self()->m_activeEditor ); + + //m_activeEditors = Prefs::self()->m_activeEditors; +} + +void +Core::saveSettings() +{ + //if ( m_currentEditor ) + //Prefs::self()->m_activeEditor = m_currentEditor->identifier(); +} + +void +Core::slotQuit() +{ + kdDebug()<<"exit"<<endl; + m_pluginManager->shutdown(); +} + +void +Core::slotPreferences() +{ + if ( m_dlg == 0 ) + m_dlg = new KSettings::Dialog( this ); + m_dlg->show(); +} + +void +Core::initWidgets() +{ + statusBar()->show(); + TQHBox *topWidget = new TQHBox( this ); + setCentralWidget( topWidget ); + m_stack = new TQWidgetStack( topWidget ); +} + +void +Core::initCore() +{ + m_pluginManager = new PluginManager( this ); + connect( m_pluginManager, TQT_SIGNAL(pluginLoaded(Plugin*)), + TQT_SLOT(slotPluginLoaded(Plugin*)) ); + connect( m_pluginManager, TQT_SIGNAL(allPluginsLoaded()), + TQT_SLOT(slotAllPluginsLoaded()) ); + + + m_pluginManager->loadAllPlugins(); + kdDebug()<<"Loading"<<endl; +} + +void +Core::initConnections() +{ + connect( kapp, TQT_SIGNAL(shutDown()), + TQT_SLOT(slotQuit()) ); +} + +void +Core::createActions() +{ + KStdAction::close( this, TQT_SLOT(slotClose()), actionCollection() ); + + (void) new KAction( i18n( "&Send" ), "mail_send", CTRL+Key_Return, + this, TQT_SLOT(slotSendNow()), actionCollection(), + "send_default" ); + + (void) new KAction( i18n( "&Queue" ), "queue", 0, + this, TQT_SLOT(slotSendLater()), + actionCollection(), "send_alternative" ); + + (void) new KAction( i18n( "Save in &Drafts Folder" ), "filesave", 0, + this, TQT_SLOT(slotSaveDraft()), + actionCollection(), "save_in_drafts" ); + (void) new KAction( i18n( "&Insert File..." ), "fileopen", 0, + this, TQT_SLOT(slotInsertFile()), + actionCollection(), "insert_file" ); + (void) new KAction( i18n( "&Address Book" ), "contents",0, + this, TQT_SLOT(slotAddrBook()), + actionCollection(), "addressbook" ); + (void) new KAction( i18n( "&New Composer" ), "mail_new", + KStdAccel::shortcut( KStdAccel::New ), + this, TQT_SLOT(slotNewComposer()), + actionCollection(), "new_composer" ); + + (void) new KAction( i18n( "&Attach File..." ), "attach", + 0, this, TQT_SLOT(slotAttachFile()), + actionCollection(), "attach_file" ); +} + +void +Core::slotClose() +{ + close( false ); +} + +void +Core::slotSendNow() +{ + +} + +void +Core::slotSendLater() +{ + +} + +void +Core::slotSaveDraft() +{ + +} + +void +Core::slotInsertFile() +{ + +} + +void +Core::slotAddrBook() +{ + +} + +void +Core::slotNewComposer() +{ + +} + +void +Core::slotAttachFile() +{ + +} + +void +Core::send( int how ) +{ + +} + +void +Core::addAttachment( const KURL &url, const TQString &comment ) +{ + +} + +void +Core::setBody( const TQString &body ) +{ + m_currentEditor->setText( body ); +} + +void +Core::addAttachment( const TQString &name, + const TQCString &cte, + const TQByteArray &data, + const TQCString &type, + const TQCString &subType, + const TQCString ¶mAttr, + const TQString ¶mValue, + const TQCString &contDisp ) +{ + +} + +#include "core.moc" diff --git a/libtdepim/komposer/core/core.h b/libtdepim/komposer/core/core.h new file mode 100644 index 000000000..91487572a --- /dev/null +++ b/libtdepim/komposer/core/core.h @@ -0,0 +1,108 @@ +// -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil; -*- +/** + * core.h + * + * Copyright (C) 2003 Zack Rusin <zack@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA + */ +#ifndef KOMPOSER_CORE_H +#define KOMPOSER_CORE_H + +#include "komposerIface.h" + +#include <kmainwindow.h> +#include <tqptrlist.h> + +namespace KSettings { + class Dialog; +} +class TQWidgetStack; + +namespace Komposer +{ + + class Editor; + class Plugin; + class PluginManager; + + /** + * This class provides the interface to the Komposer core for the editor. + */ + class Core : public KMainWindow, virtual public KomposerIface + { + Q_OBJECT + TQ_OBJECT + public: + Core( TQWidget *parentWidget = 0, const char *name = 0 ); + virtual ~Core(); + + public slots: + virtual void send( int how ); + virtual void addAttachment( const KURL &url, const TQString &comment ); + virtual void setBody( const TQString &body ); + virtual void addAttachment( const TQString &name, + const TQCString &cte, + const TQByteArray &data, + const TQCString &type, + const TQCString &subType, + const TQCString ¶mAttr, + const TQString ¶mValue, + const TQCString &contDisp ); + + + + protected slots: + //void slotActivePartChanged( KParts::Part *part ); + void slotPluginLoaded( Plugin* ); + void slotAllPluginsLoaded(); + void slotPreferences(); + void slotQuit(); + void slotClose(); + + void slotSendNow(); + void slotSendLater(); + void slotSaveDraft(); + void slotInsertFile(); + void slotAddrBook(); + void slotNewComposer(); + void slotAttachFile(); + + protected: + virtual void initWidgets(); + void initCore(); + void initConnections(); + void loadSettings(); + void saveSettings(); + void createActions(); + + void addEditor( Komposer::Editor *editor ); + void addPlugin( Komposer::Plugin *plugin ); + + private: + TQWidgetStack *m_stack; + Editor *m_currentEditor; + PluginManager *m_pluginManager; + + KSettings::Dialog *m_dlg; + + class Private; + Private *d; +}; + +} + +#endif diff --git a/libtdepim/komposer/core/corewidget.cpp b/libtdepim/komposer/core/corewidget.cpp new file mode 100644 index 000000000..c65893766 --- /dev/null +++ b/libtdepim/komposer/core/corewidget.cpp @@ -0,0 +1,32 @@ +// -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil; -*- +/** + * corewidget.cpp + * + * Copyright (C) 2003 Zack Rusin <zack@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA + */ + +#include "corewidget.h" + +using namespace Komposer; + +CoreWidget::CoreWidget( TQWidget *parent, const char *name ) + : TQWidget( parent, name ) +{ +} + +#include "corewidget.moc" diff --git a/libtdepim/komposer/core/corewidget.h b/libtdepim/komposer/core/corewidget.h new file mode 100644 index 000000000..7d2acc6db --- /dev/null +++ b/libtdepim/komposer/core/corewidget.h @@ -0,0 +1,49 @@ +// -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil; -*- +/** + * corewidget.h + * + * Copyright (C) 2003-2004 Zack Rusin <zack@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA + */ +#ifndef COREWIDGET_H +#define COREWIDGET_H + +#include "attachment.h" + +#include <tqwidget.h> + +namespace Komposer +{ + + class CoreWidget : public TQWidget + { + Q_OBJECT + TQ_OBJECT + public: + CoreWidget( TQWidget *parent, const char *name=0 ); + + virtual TQString subject() const =0; + virtual TQStringList to() const =0; + virtual TQStringList cc() const =0; + virtual TQStringList bcc() const =0; + virtual TQString from() const =0; + virtual TQString replyTo() const =0; + virtual AttachmentList attachments() const =0; + }; +} + +#endif diff --git a/libtdepim/komposer/core/editor.cpp b/libtdepim/komposer/core/editor.cpp new file mode 100644 index 000000000..5dada393f --- /dev/null +++ b/libtdepim/komposer/core/editor.cpp @@ -0,0 +1,51 @@ +// -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil; -*- +/** + * editor.cpp + * + * Copyright (C) 2003 Zack Rusin <zack@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA + */ + +#include "editor.h" +#include "core.h" + +namespace Komposer { + +class Editor::Private { +public: + TQString id; +}; + +Editor::Editor( TQObject *parent, const char *name, const TQStringList &args ) + : Plugin( parent, name, args ), d( new Private ) +{ +} + +Editor::~Editor() +{ + delete d; d = 0; +} + +void +Editor::select() +{ +} + + +} + +#include "editor.moc" diff --git a/libtdepim/komposer/core/editor.h b/libtdepim/komposer/core/editor.h new file mode 100644 index 000000000..cdc05710d --- /dev/null +++ b/libtdepim/komposer/core/editor.h @@ -0,0 +1,105 @@ +// -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil; -*- +/** + * editor.h + * + * Copyright (C) 2003-2004 Zack Rusin <zack@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA + */ + +#ifndef KOMPOSER_EDITOR_H +#define KOMPOSER_EDITOR_H + +#include "plugin.h" + +#include <tqstringlist.h> + +namespace KParts { + class Part; +} + +namespace Komposer { + + class Core; + + class Editor : public Plugin + { + Q_OBJECT + TQ_OBJECT + public: + enum TextType { + Plain = 1 << 0, + RichText = 1 << 1, + HTML = 1 << 2 + }; + virtual ~Editor(); + + /** + * This is the magic function that all derivatives have to reimplement. + * It returns the actual editor component. + */ + virtual TQWidget *widget() =0; + + int supportedTextFormats() const; + + /** + * Returns the full text inside the editor. + */ + virtual TQString text() const =0; + + /** + * This function is called when the plugin is selected by the user before the + * widget of the KPart belonging to the plugin is raised. + */ + virtual void select(); + + /** + * Reimplement this method and return a @ref TQStringList of all config + * modules your application part should offer via Komposer. Note that the + * part and the module will have to take care for config syncing themselves. + * Usually @p DCOP used for that purpose. + * + * @note Make sure you offer the modules in the form: + * <code>"pathrelativetosettings/mysettings.desktop"</code> + */ + virtual TQStringList configModules() const { return TQStringList(); } + + + public slots: + /** + * Sets the text of the opened editor. + * Most commonly used on replaying. + * If any text is present if will be deleted. + */ + virtual void setText( const TQString &txt ) =0; + + /** + * Changes currently used signature. If no signature is present + * a new one should be appened. + */ + virtual void changeSignature( const TQString &txt ) =0; + + protected: + Editor( TQObject *parent, const char *name, const TQStringList &args ); + + private: + class Private; + Private *d; + }; + +} + +#endif diff --git a/libtdepim/komposer/core/komposer.kcfg b/libtdepim/komposer/core/komposer.kcfg new file mode 100644 index 000000000..111584b88 --- /dev/null +++ b/libtdepim/komposer/core/komposer.kcfg @@ -0,0 +1,26 @@ +<?xml version="1.0" encoding="UTF-8"?> +<kcfg xmlns="http://www.kde.org/standards/kcfg/1.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://www.kde.org/standards/kcfg/1.0 + http://www.kde.org/standards/kcfg/1.0/kcfg.xsd" > + <kcfgfile name="komposerrc"/> + + <group name="Colors"> + + <entry type="Color" name="foregroundColor"> + </entry> + + <entry type="Color" name="backgroundColor"> + </entry> + + <entry type="Color" name="QuotedText$(Level)" key="quotedColor_$(Level)"> + <parameter name="Level" type="Int" max="3"/> + <default param="0">#ff0000</default> + <default param="1">#00ff00</default> + <default param="2">#0000ff</default> + <default param="3">#ffff00</default> + </entry> + + </group> + +</kcfg> diff --git a/libtdepim/komposer/core/komposerIface.h b/libtdepim/komposer/core/komposerIface.h new file mode 100644 index 000000000..eecab2f3a --- /dev/null +++ b/libtdepim/komposer/core/komposerIface.h @@ -0,0 +1,85 @@ +/* + * komposerIface.h + * + * Copyright (C) 2004 Zack Rusin <zack@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA + */ +#ifndef KOMPOSERIFACE_H +#define KOMPOSERIFACE_H + +#include <dcopobject.h> +#include <kurl.h> + +namespace Komposer +{ + +/** + DCOP interface for mail composer window. The address header fields are set, + when the composer is constructed. KMailIface::openComposer() returns a + reference to the DCOP interface of the new composer window, which provides the + functions defined in the MailComposerIface. +*/ +class KomposerIface : virtual public DCOPObject +{ + K_DCOP +k_dcop: + /** + Send message. + + @param how 0 for deafult method, 1 for sending now, 2 for sending later. + */ + virtual void send(int how) = 0; + + /** + Add url as attachment with a user-defined comment. + */ + virtual void addAttachment( const KURL &url, const TQString &comment) = 0; + + /** + Set message body. + */ + virtual void setBody( const TQString &body ) = 0; + + /** + Add attachment. + + @param name Name of Attachment + @param cte Content Transfer Encoding + @param data Data to be attached + @param type MIME content type + @param subType MIME content sub type + @param paramAttr Attribute name of parameter of content type + @param paramValue Value of parameter of content type + @param contDisp Content disposition + */ + virtual void addAttachment( const TQString &name, + const TQCString &cte, + const TQByteArray &data, + const TQCString &type, + const TQCString &subType, + const TQCString ¶mAttr, + const TQString ¶mValue, + const TQCString &contDisp ) = 0; +public: + KomposerIface( const char *name ) + : DCOPObject( name ) + {} +}; + +} + +#endif diff --git a/libtdepim/komposer/core/komposerconfig.desktop b/libtdepim/komposer/core/komposerconfig.desktop new file mode 100644 index 000000000..58c8bd765 --- /dev/null +++ b/libtdepim/komposer/core/komposerconfig.desktop @@ -0,0 +1,56 @@ +[Desktop Entry] +Exec=kcmshell komposerconfig +Icon=komposer +Type=Application +Terminal=false + +X-KDE-ModuleType=Library +X-KDE-Library=komposer +X-KDE-FactoryName=komposerconfig +X-KDE-HasReadOnlyMode=false + +Name=Komposer +Name[cy]=Kyfansoddydd +Name[da]=Brevskriver +Name[hi]=कमà¥à¤ªà¥‹à¤œà¤¼à¤° +Name[ms]=Penggubah +Name[ne]=कमà¥à¤ªà¥‹à¤œà¤° +Name[pt]=Kompositor +Name[ta]=கமà¯à®ªà¯‹à®šà®°à¯ +Comment=KDE Komposer +Comment[bg]=ПиÑане на форматиран текÑÑ‚ +Comment[br]=Komposer KDE +Comment[ca]=Compositor per a KDE +Comment[cy]=Cyfansoddydd KDE +Comment[da]=KDE Brevskriver +Comment[de]=KDE-Komposer +Comment[fr]=Komposer KDE +Comment[ga]=Komposer KDE +Comment[hi]=केडीई कमà¥à¤ªà¥‹à¤œà¤¼à¤° +Comment[ms]=Penggubah KDE +Comment[nds]=Nettbreef-Editor vun KDE +Comment[ne]=केडीई कमà¥à¤ªà¥‹à¤œà¤° +Comment[nn]=KDE, tekstredigerar for e-post +Comment[pl]=Komposer dla KDE +Comment[pt]=Kompositor do KDE +Comment[pt_BR]=Konposer do KDE +Comment[ru]=Композитор KDE +Comment[ta]=கேடிஇ கமà¯à®ªà¯‹à®šà®°à¯ +Comment[tg]=Композитори KDE +Keywords=komposer +Keywords[bg]=редактор, ÑÑŠÑтавител, форматиране, текÑÑ‚, komposer +Keywords[ca]=compositor +Keywords[cy]=komposer,kyfansoddydd +Keywords[da]=brevskriver +Keywords[de]=Komposer +Keywords[fy]=komposer,opstellen, opsteller +Keywords[hi]=कमà¥à¤ªà¥‹à¤œà¤¼à¤° +Keywords[nds]=Komposer +Keywords[ne]=कमà¥à¤ªà¥‹à¤œà¤° +Keywords[nl]=komposer,opstellen +Keywords[nn]=komposer,tekstredigerar,epost +Keywords[ru]=komposer,ноты +Keywords[sr]=komposer,ÑаÑтављач +Keywords[sr@Latn]=komposer,sastavljaÄ +Keywords[ta]=கமà¯à®ªà¯‹à®šà®°à¯ +Keywords[tg]=komposer,нотаҳо diff --git a/libtdepim/komposer/core/komposereditor.desktop b/libtdepim/komposer/core/komposereditor.desktop new file mode 100644 index 000000000..fd1c1341e --- /dev/null +++ b/libtdepim/komposer/core/komposereditor.desktop @@ -0,0 +1,56 @@ +[Desktop Entry] +Type=ServiceType +X-KDE-ServiceType=Komposer/Editor +X-KDE-Derived=Komposer/Plugin +Comment=Komposer Editor +Comment[af]=Komposer Redigeerder +Comment[bg]=ПиÑане на форматиран текÑÑ‚ +Comment[br]=Aozer Komposer +Comment[bs]=Komposer editor +Comment[ca]=Compositor per a KDE +Comment[cs]=Komposer editor +Comment[da]=Komposer editor +Comment[el]=ΕπεξεÏγαστής Komposer +Comment[eo]=Komposer-redaktilo +Comment[es]=Editor Komposer +Comment[et]=Komposeri redaktor +Comment[eu]=Komposer editorea +Comment[fa]=ویرایشگر Komposer +Comment[fi]=Komposer-muokkain +Comment[fr]=Éditeur Komposer +Comment[fy]=Komposer-bewurker +Comment[ga]=Eagarthóir Komposer +Comment[gl]=Editor Komposer +Comment[he]=עורך של Komposer +Comment[hu]=Komposer +Comment[is]=Komposer ritill +Comment[it]=Komposer editor +Comment[ja]=Komposer,エディタ +Comment[kk]=Komposer өңдегіші +Comment[km]=កម្មវិធី​និពន្ធ Komposer +Comment[ko]=Komposer 편집기 +Comment[lt]=Komposer redaktorius +Comment[ms]=Editor Komposer +Comment[nb]=Komposer redigerer +Comment[nds]=Komposer-Editor +Comment[ne]=कमà¥à¤ªà¥‹à¤œà¤° समà¥à¤ªà¤¾à¤¦à¤• +Comment[nl]=Komposer-editor +Comment[nn]=Komposer redigerar +Comment[pl]=Edytor Komposer +Comment[pt]=Editor Kompositor +Comment[pt_BR]=Editor de Mensagens +Comment[ru]=Редактор Komposer +Comment[sk]=Editor Komposer +Comment[sl]=Urejevalnik Komposer +Comment[sr]=Уређивач Komposer +Comment[sr@Latn]=UreÄ‘ivaÄ Komposer +Comment[sv]=Komposer editor +Comment[ta]=கமà¯à®ªà¯‹à®šà®°à¯ தொகà¯à®ªà¯à®ªà®¾à®©à¯ +Comment[tg]=Муҳаррири Komposer +Comment[tr]=Komposer Düzenleyicisi +Comment[uk]=Редактор Komposer +Comment[zh_CN]=Komposer 编辑器 +Comment[zh_TW]=Komposer 編輯器 + +[PropertyDef::X-Komposer-Weight] +Type=int diff --git a/libtdepim/komposer/core/komposerplugin.desktop b/libtdepim/komposer/core/komposerplugin.desktop new file mode 100644 index 000000000..b398e1c67 --- /dev/null +++ b/libtdepim/komposer/core/komposerplugin.desktop @@ -0,0 +1,59 @@ +[Desktop Entry] +Type=ServiceType +X-KDE-ServiceType=Komposer/Plugin +X-KDE-Derived=KPluginInfo +Name=Komposer Plugin +Name[af]=Komposer inprop module +Name[bg]=ПриÑтавка за Komposer +Name[br]=Lugent Komposer +Name[bs]=Komposer dodatak +Name[ca]=Endollable Komposer +Name[cs]=Komposer modul +Name[cy]=Ategyn Kyfansoddydd +Name[da]=Brevskriver-plugin +Name[de]=Komposer-Modul +Name[el]=Î Ïόσθετο του Komposer +Name[eo]=Komposer-kromaĵo +Name[es]=Accesorio Komposer +Name[et]=Komposeri plugin +Name[eu]=Komposer plugin-a +Name[fa]=وصلۀ Komposer +Name[fi]=Komposer-liitännäinen +Name[fr]=Module de Komposer +Name[fy]=Komposer-plugin +Name[ga]=Breiseán Komposer +Name[gl]=Extensión Komposer +Name[he]=תןסף Kompoer +Name[hi]=कमà¥à¤ªà¥‹à¤œà¤¼à¤° पà¥à¤²à¤—इन +Name[hu]=Komposer bÅ‘vÃtÅ‘modul +Name[is]=Komposer Ãforrit +Name[it]=Plugin Komposer +Name[ja]=Komposer プラグイン +Name[kk]=Komposer плагин модулі +Name[km]=កម្មវិធី​ជំនួយ Komposer +Name[ko]=Komposer í”ŒëŸ¬ê·¸ì¸ +Name[lt]=Komposer priedas +Name[ms]=Plugin Komposer +Name[nb]=Komposer-programtillegg +Name[nds]=Komposer-Moduul +Name[ne]=कमà¥à¤ªà¥‹à¤œà¤° पà¥à¤²à¤—इन +Name[nn]=Komposer-programtillegg +Name[pl]=Wtyczka Komposer +Name[pt]='Plugin' do Kompositor +Name[pt_BR]=Plug-in do Komposer +Name[ro]=Modul Komposer +Name[ru]=Модуль Komposer +Name[sk]=Modul Komposer +Name[sl]=Vstavek za Komposer +Name[sr]=Прикључак Komposer-а +Name[sr@Latn]=PrikljuÄak Komposer-a +Name[sv]=Komposer-insticksprogram +Name[ta]=கமà¯à®ªà¯‹à®šà®°à¯ சொரà¯à®•à¯à®ªà¯à®ªà¯Šà®°à¯à®³à¯ +Name[tg]=Модули Komposer +Name[tr]=Komposer Eklentisi +Name[uk]=Втулок Komposer +Name[zh_CN]=Komposer æ’件 +Name[zh_TW]=Komposer å¤–æŽ›ç¨‹å¼ + +[PropertyDef::X-Komposer-Version] +Type=int diff --git a/libtdepim/komposer/core/komposerui.rc b/libtdepim/komposer/core/komposerui.rc new file mode 100644 index 000000000..83ec4d299 --- /dev/null +++ b/libtdepim/komposer/core/komposerui.rc @@ -0,0 +1,51 @@ +<!DOCTYPE kpartgui > +<kpartgui version="2" name="komposer" > +<MenuBar> + <Menu name="file" noMerge="1"> + <text>&Message</text> + <Action name="new_composer" /> + <Action name="open_mailreader" /> + <Separator/> + <Action name="send_default" /> + <Action name="send_alternative" /> + <Action name="save_in_drafts" /> + <Separator/> + <Action name="insert_file" /> + <Action name="file_print" /> + <Separator/> + <Merge/> + <Separator/> + <Action name="file_close" /> + </Menu> + <Merge /> + <Menu noMerge="1" name="attach"> + <text>&Attach</text> + <Merge/> + <Separator/> + <Action name="attach_file"/> + <Action name="remove_attachment"/> + <Action name="attachment_properties"/> + </Menu> + <Menu noMerge="1" name="Tools"> + <text>&Tools</text> + <Merge/> + <Action name="addressbook"/> + </Menu> + <Menu noMerge="1" name="settings"> + <text>&Settings</text> + <Merge/> + <Separator/> + <Action name="settings_configure_komposer"/> + </Menu> +</MenuBar> +<ToolBar position="Top" iconText="IconOnly" noMerge="1" name="mainToolBar"><text>Main Toolbar</text> + <Action name="send_default" /> + <Action name="send_alternative" /> + <Separator/> + <Action name="attach_file"/> + <Separator/> + <Merge/> + <Separator/> + <Action name="help_whats_this"/> +</ToolBar> +</kpartgui> diff --git a/libtdepim/komposer/core/plugin.cpp b/libtdepim/komposer/core/plugin.cpp new file mode 100644 index 000000000..41af47cd9 --- /dev/null +++ b/libtdepim/komposer/core/plugin.cpp @@ -0,0 +1,80 @@ +// -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil; -*- +/** + * plugin.cpp + * + * Copyright (C) 2003 Zack Rusin <zack@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA + */ +#include "plugin.h" + +#include "core.h" + +#include <kdebug.h> +#include <tqstring.h> + +namespace Komposer +{ + +class Plugin::Private +{ +public: + //Core* core; +}; + +Plugin::Plugin( TQObject *parent, const char *name, const TQStringList & ) + : TQObject( parent, name ), d( new Private ) +{ + //d->core = core; +} + +Plugin::~Plugin() +{ + delete d; d = 0; +} + +void +Plugin::startedComposing() +{ +} + +void +Plugin::sendClicked() +{ +} + +void +Plugin::quitClicked() +{ +} + +void +Plugin::aboutToUnload() +{ + kdDebug()<<"plugin unloading"<<endl; + emit readyForUnload(); +} + +Core* +Plugin::core() const +{ + return 0; + //return d->core; +} + +}//end namespace Komposer + +#include "plugin.moc" diff --git a/libtdepim/komposer/core/plugin.h b/libtdepim/komposer/core/plugin.h new file mode 100644 index 000000000..7acd7f70f --- /dev/null +++ b/libtdepim/komposer/core/plugin.h @@ -0,0 +1,76 @@ +// -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil; -*- +/** + * plugin.h + * + * Copyright (C) 2003 Zack Rusin <zack@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA + */ +#ifndef KOMPOSER_PLUGIN_H +#define KOMPOSER_PLUGIN_H + +#include <tqobject.h> +#include <kxmlguiclient.h> + +namespace Komposer +{ + class Core; + + class Plugin : public TQObject, + virtual public KXMLGUIClient + { + Q_OBJECT + TQ_OBJECT + public: + virtual ~Plugin(); + + signals: + void statusMessage( const TQString & ); + void readyForUnload(); + + protected slots: + /** + * Called when a new message is created. + */ + virtual void startedComposing(); + + /** + * Called after the send button has been pressed + * and before the message has been sent. + */ + virtual void sendClicked(); + + /** + * Called after the quit button has been pressed + */ + virtual void quitClicked(); + + virtual void aboutToUnload(); + + protected: + Core *core() const; + protected: + friend class PluginManager; + Plugin( TQObject *parent, const char *name, const TQStringList& args = TQStringList() ); + + private: + class Private; + Private *d; + }; + +} + +#endif diff --git a/libtdepim/komposer/core/pluginmanager.cpp b/libtdepim/komposer/core/pluginmanager.cpp new file mode 100644 index 000000000..dcfea6f4b --- /dev/null +++ b/libtdepim/komposer/core/pluginmanager.cpp @@ -0,0 +1,489 @@ +// -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 2; -*- +/** + * pluginmanager.cpp + * Most of this code has been lifted from Martijn's KopetePluginManager class + * + * Copyright (C) 2004 Zack Rusin <zack@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA + */ +#include "pluginmanager.h" + +#include "plugin.h" + +#include <tqapplication.h> +#include <tqfile.h> +#include <tqregexp.h> +#include <tqtimer.h> +#include <tqvaluestack.h> + +#include <kapplication.h> +#include <kdebug.h> +#include <kparts/componentfactory.h> +#include <kplugininfo.h> +#include <ksettings/dispatcher.h> +#include <ksimpleconfig.h> +#include <kstandarddirs.h> +#include <kstaticdeleter.h> +#include <kurl.h> + + +namespace Komposer +{ + +class PluginManager::Private +{ +public: + // All available plugins, regardless of category, and loaded or not + TQValueList<KPluginInfo*> plugins; + + // Dict of all currently loaded plugins, mapping the KPluginInfo to + // a plugin + TQMap<KPluginInfo*, Plugin*> loadedPlugins; + + // The plugin manager's mode. The mode is StartingUp until loadAllPlugins() + // has finished loading the plugins, after which it is set to Running. + // ShuttingDown and DoneShutdown are used during Komposer shutdown by the + // async unloading of plugins. + enum ShutdownMode { StartingUp, Running, ShuttingDown, DoneShutdown }; + ShutdownMode shutdownMode; + + KSharedConfig::Ptr config; + // Plugins pending for loading + TQValueStack<TQString> pluginsToLoad; +}; + +PluginManager::PluginManager( TQObject *parent ) + : TQObject( parent ) +{ + d = new Private; + + // We want to add a reference to the application's event loop so we + // can remain in control when all windows are removed. + // This way we can unload plugins asynchronously, which is more + // robust if they are still doing processing. + kapp->ref(); + d->shutdownMode = Private::StartingUp; + + KSettings::Dispatcher::self()->registerInstance( KGlobal::instance(), + this, TQT_SLOT( loadAllPlugins() ) ); + + d->plugins = KPluginInfo::fromServices( + KTrader::self()->query( TQString::tqfromLatin1( "Komposer/Plugin" ), + TQString::tqfromLatin1( "[X-Komposer-Version] == 1" ) ) ); +} + +PluginManager::~PluginManager() +{ + if ( d->shutdownMode != Private::DoneShutdown ) { + slotShutdownTimeout(); +#if 0 + kdWarning() << k_funcinfo + << "Destructing plugin manager without going through " + << "the shutdown process!" + << endl + << kdBacktrace(10) << endl; +#endif + } + + // Quick cleanup of the remaining plugins, hope it helps + TQMap<KPluginInfo*, Plugin*>::ConstIterator it; + for ( it = d->loadedPlugins.begin(); it != d->loadedPlugins.end(); /* EMPTY */ ) + { + // Remove causes the iterator to become invalid, so pre-increment first + TQMap<KPluginInfo*, Plugin*>::ConstIterator nextIt( it ); + ++nextIt; + kdWarning() << k_funcinfo << "Deleting stale plugin '" + << it.data()->name() << "'" << endl; + delete it.data(); + it = nextIt; + } + + delete d; +} + +TQValueList<KPluginInfo*> +PluginManager::availablePlugins( const TQString &category ) const +{ + if ( category.isEmpty() ) + return d->plugins; + + TQValueList<KPluginInfo*> result; + TQValueList<KPluginInfo*>::ConstIterator it; + for ( it = d->plugins.begin(); it != d->plugins.end(); ++it ) + { + if ( ( *it )->category() == category ) + result.append( *it ); + } + + return result; +} + +TQMap<KPluginInfo*, Plugin*> +PluginManager::loadedPlugins( const TQString &category ) const +{ + TQMap<KPluginInfo*, Plugin*> result; + TQMap<KPluginInfo*, Plugin*>::ConstIterator it; + for ( it = d->loadedPlugins.begin(); it != d->loadedPlugins.end(); ++it ) + { + if ( category.isEmpty() || it.key()->category() == category ) + result.insert( it.key(), it.data() ); + } + + return result; +} + +void +PluginManager::shutdown() +{ + d->shutdownMode = Private::ShuttingDown; + + // Remove any pending plugins to load, we're shutting down now :) + d->pluginsToLoad.clear(); + + // Ask all plugins to unload + if ( d->loadedPlugins.empty() ) { + d->shutdownMode = Private::DoneShutdown; + } else { + TQMap<KPluginInfo*, Plugin*>::ConstIterator it; + for ( it = d->loadedPlugins.begin(); it != d->loadedPlugins.end(); /* EMPTY */ ) + { + // Remove causes the iterator to become invalid, so pre-increment first + TQMap<KPluginInfo*, Plugin*>::ConstIterator nextIt( it ); + ++nextIt; + it.data()->aboutToUnload(); + it = nextIt; + } + } + + TQTimer::singleShot( 3000, this, TQT_SLOT(slotShutdownTimeout()) ); +} + +void +PluginManager::slotPluginReadyForUnload() +{ + // Using TQObject::sender() is on purpose here, because otherwise all + // plugins would have to pass 'this' as parameter, which makes the API + // less clean for plugin authors + Plugin* plugin = dynamic_cast<Plugin*>( const_cast<TQObject*>( sender() ) ); + if ( !plugin ) + { + kdWarning() << k_funcinfo << "Calling object is not a plugin!" << endl; + return; + + } + kdDebug()<<"manager unloading"<<endl; + plugin->deleteLater(); +} + +void +PluginManager::slotShutdownTimeout() +{ + // When we were already done the timer might still fire. + // Do nothing in that case. + if ( d->shutdownMode == Private::DoneShutdown ) + return; + +#ifndef NDEBUG + TQStringList remaining; + for ( TQMap<KPluginInfo*, Plugin*>::ConstIterator it = d->loadedPlugins.begin(); + it != d->loadedPlugins.end(); ++it ) + remaining.append( it.key()->pluginName() ); + + kdWarning() << k_funcinfo << "Some plugins didn't shutdown in time!" << endl + << "Remaining plugins: " + << remaining.join( TQString::tqfromLatin1( ", " ) ) << endl + << "Forcing Komposer shutdown now." << endl; +#endif + + slotShutdownDone(); +} + +void +PluginManager::slotShutdownDone() +{ + d->shutdownMode = Private::DoneShutdown; + + kapp->deref(); +} + +void +PluginManager::loadAllPlugins() +{ + // FIXME: We need session management here - Martijn + + if ( !d->config ) + d->config = KSharedConfig::openConfig( "komposerrc" ); + + TQMap<TQString, TQString> entries = d->config->entryMap( + TQString::tqfromLatin1( "Plugins" ) ); + + TQMap<TQString, TQString>::Iterator it; + for ( it = entries.begin(); it != entries.end(); ++it ) + { + TQString key = it.key(); + if ( key.endsWith( TQString::tqfromLatin1( "Enabled" ) ) ) + { + key.setLength( key.length() - 7 ); + //kdDebug() << k_funcinfo << "Set " << key << " to " << it.data() << endl; + + if ( it.data() == TQString::tqfromLatin1( "true" ) ) + { + if ( !plugin( key ) ) + d->pluginsToLoad.push( key ); + } + else + { + // FIXME: Does this ever happen? As loadAllPlugins is only called on startup + // I'd say 'no'. If it does, it should be made async + // though. - Martijn + if ( plugin( key ) ) + unloadPlugin( key ); + } + } + } + + // Schedule the plugins to load + TQTimer::singleShot( 0, this, TQT_SLOT( slotLoadNextPlugin() ) ); +} + +void PluginManager::slotLoadNextPlugin() +{ + if ( d->pluginsToLoad.isEmpty() ) + { + if ( d->shutdownMode == Private::StartingUp ) + { + d->shutdownMode = Private::Running; + emit allPluginsLoaded(); + } + return; + } + + TQString key = d->pluginsToLoad.pop(); + loadPluginInternal( key ); + + // Schedule the next run unconditionally to avoid code duplication on the + // allPluginsLoaded() signal's handling. This has the added benefit that + // the signal is delayed one event loop, so the accounts are more likely + // to be instantiated. + TQTimer::singleShot( 0, this, TQT_SLOT( slotLoadNextPlugin() ) ); +} + +Plugin* +PluginManager::loadPlugin( const TQString &pluginId, + PluginLoadMode mode /* = LoadSync */ ) +{ + if ( mode == LoadSync ) { + return loadPluginInternal( pluginId ); + } else { + d->pluginsToLoad.push( pluginId ); + TQTimer::singleShot( 0, this, TQT_SLOT( slotLoadNextPlugin() ) ); + return 0; + } +} + +Plugin* +PluginManager::loadPluginInternal( const TQString &pluginId ) +{ + KPluginInfo* info = infoForPluginId( pluginId ); + if ( !info ) { + kdWarning() << k_funcinfo << "Unable to find a plugin named '" + << pluginId << "'!" << endl; + return 0; + } + + if ( d->loadedPlugins.contains( info ) ) + return d->loadedPlugins[ info ]; + + int error = 0; + Plugin *plugin = KParts::ComponentFactory::createInstanceFromQuery<Komposer::Plugin>( + TQString::tqfromLatin1( "Komposer/Plugin" ), + TQString::tqfromLatin1( "[X-KDE-PluginInfo-Name]=='%1'" ).tqarg( pluginId ), + this, 0, TQStringList(), &error ); + + if ( plugin ) { + d->loadedPlugins.insert( info, plugin ); + info->setPluginEnabled( true ); + + connect( plugin, TQT_SIGNAL(destroyed(TQObject*)), + this, TQT_SLOT(slotPluginDestroyed(TQObject*)) ); + connect( plugin, TQT_SIGNAL(readyForUnload()), + this, TQT_SLOT(slotPluginReadyForUnload()) ); + + kdDebug() << k_funcinfo << "Successfully loaded plugin '" + << pluginId << "'" << endl; + + emit pluginLoaded( plugin ); + } else { + switch ( error ) { + case KParts::ComponentFactory::ErrNoServiceFound: + kdDebug() << k_funcinfo << "No service implementing the given mimetype " + << "and fullfilling the given constraint expression can be found." + << endl; + break; + + case KParts::ComponentFactory::ErrServiceProvidesNoLibrary: + kdDebug() << "the specified service provides no shared library." << endl; + break; + + case KParts::ComponentFactory::ErrNoLibrary: + kdDebug() << "the specified library could not be loaded." << endl; + break; + + case KParts::ComponentFactory::ErrNoFactory: + kdDebug() << "the library does not export a factory for creating components." + << endl; + break; + + case KParts::ComponentFactory::ErrNoComponent: + kdDebug() << "the factory does not support creating components " + << "of the specified type." + << endl; + break; + } + + kdDebug() << k_funcinfo << "Loading plugin '" << pluginId + << "' failed, KLibLoader reported error: '" + << KLibLoader::self()->lastErrorMessage() + << "'" << endl; + } + + return plugin; +} + +bool +PluginManager::unloadPlugin( const TQString &spec ) +{ + TQMap<KPluginInfo*, Plugin*>::ConstIterator it; + for ( it = d->loadedPlugins.begin(); it != d->loadedPlugins.end(); ++it ) + { + if ( it.key()->pluginName() == spec ) + { + it.data()->aboutToUnload(); + return true; + } + } + + return false; +} + +void +PluginManager::slotPluginDestroyed( TQObject *plugin ) +{ + TQMap<KPluginInfo*, Plugin*>::Iterator it; + for ( it = d->loadedPlugins.begin(); it != d->loadedPlugins.end(); ++it ) + { + if ( it.data() == plugin ) + { + d->loadedPlugins.erase( it ); + break; + } + } + + if ( d->shutdownMode == Private::ShuttingDown && d->loadedPlugins.isEmpty() ) + { + // Use a timer to make sure any pending deleteLater() calls have + // been handled first + TQTimer::singleShot( 0, this, TQT_SLOT(slotShutdownDone()) ); + } +} + +Plugin* +PluginManager::plugin( const TQString &pluginId ) const +{ + KPluginInfo *info = infoForPluginId( pluginId ); + if ( !info ) + return 0; + + if ( d->loadedPlugins.contains( info ) ) + return d->loadedPlugins[ info ]; + else + return 0; +} + +TQString +PluginManager::pluginName( const Plugin *plugin ) const +{ + TQMap<KPluginInfo*, Plugin*>::ConstIterator it; + for ( it = d->loadedPlugins.begin(); it != d->loadedPlugins.end(); ++it ) + { + if ( it.data() == plugin ) + return it.key()->name(); + } + + return TQString::tqfromLatin1( "Unknown" ); +} + +TQString +PluginManager::pluginId( const Plugin *plugin ) const +{ + TQMap<KPluginInfo*, Plugin*>::ConstIterator it; + for ( it = d->loadedPlugins.begin(); it != d->loadedPlugins.end(); ++it ) + { + if ( it.data() == plugin ) + return it.key()->pluginName(); + } + + return TQString::tqfromLatin1( "unknown" ); +} + +TQString +PluginManager::pluginIcon( const Plugin *plugin ) const +{ + TQMap<KPluginInfo*, Plugin*>::ConstIterator it; + for ( it = d->loadedPlugins.begin(); it != d->loadedPlugins.end(); ++it ) + { + if ( it.data() == plugin ) + return it.key()->icon(); + } + + return TQString::tqfromLatin1( "Unknown" ); +} + +KPluginInfo* +PluginManager::infoForPluginId( const TQString &pluginId ) const +{ + TQValueList<KPluginInfo*>::ConstIterator it; + for ( it = d->plugins.begin(); it != d->plugins.end(); ++it ) + { + if ( ( *it )->pluginName() == pluginId ) + return *it; + } + + return 0; +} + +bool +PluginManager::setPluginEnabled( const TQString &pluginId, bool enabled /* = true */ ) +{ + if ( !d->config ) + d->config = KSharedConfig::openConfig( "komposerrc" ); + + d->config->setGroup( "Plugins" ); + + + if ( !infoForPluginId( pluginId ) ) + return false; + + d->config->writeEntry( pluginId + TQString::tqfromLatin1( "Enabled" ), enabled ); + d->config->sync(); + + return true; +} + +} + +#include "pluginmanager.moc" diff --git a/libtdepim/komposer/core/pluginmanager.h b/libtdepim/komposer/core/pluginmanager.h new file mode 100644 index 000000000..34cc6b9c5 --- /dev/null +++ b/libtdepim/komposer/core/pluginmanager.h @@ -0,0 +1,252 @@ +// -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil; -*- +/** + * pluginmanager.h + * + * Copyright (C) 2004 Zack Rusin <zack@kde.org> + * Copyright (C) 2003 Martijn Klingens <klingens@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA + */ + +#ifndef KOMPOSER_PLUGINMANAGER_H +#define KOMPOSER_PLUGINMANAGER_H + +#include <tqmap.h> +#include <tqobject.h> +#include <tqstring.h> +#include <tqstringlist.h> +#include <tqvaluelist.h> + +class KPluginInfo; + +namespace Komposer +{ + + class Plugin; + + class PluginManager : public TQObject + { + Q_OBJECT + TQ_OBJECT + + public: + PluginManager( TQObject * ); + + ~PluginManager(); + + /** + * Returns a list of all available plugins for the given category. + * Currently there are two categories, "Plugins" and "Editors", but + * you can add your own categories if you want. + * + * If you pass an empty string you get the complete list of ALL plugins. + * + * You can query all information on the plugins through the @ref KPluginInfo + * interface. + */ + TQValueList<KPluginInfo*> availablePlugins( const TQString &category + = TQString() ) const; + + /** + * Returns a list of all plugins that are actually loaded. + * If you omit the category you get all, otherwise it's a filtered list. + * See also @ref availablePlugins(). + */ + TQMap<KPluginInfo*, Plugin*> loadedPlugins( const TQString &category + = TQString() ) const; + + /** + * @brief Search by plugin name. This is the key used as X-KDE-PluginInfo-Name + * in the .desktop file, e.g. "komposer_attachment" + * + * @return The @ref Plugin object found by the search, or a null + * pointer if the plugin is not loaded. + * + * If you want to also load the plugin you can better use @ref loadPlugin, + * which returns + * the pointer to the plugin if it's already loaded. + */ + Plugin* plugin( const TQString &pluginName ) const; + + /** + * @brief Return the short user-visible name of the plugin. + * + * If you want to have the internal name, use @ref pluginId() instead. + * + * @return The name of the protocol, in the user's locale. + */ + TQString pluginName( const Plugin *plugin ) const; + + /** + * @brief Return the internal name of the plugin. + * + * You cannot display this name on the screen, it's used internally for + * passing around IDs. Use @ref pluginName() for a string ready for display. + * + * @return The name of the protocol, in the user's locale. + */ + TQString pluginId( const Plugin *plugin ) const; + + /** + * @brief Unload the plugin specified by @p pluginName + */ + bool unloadPlugin( const TQString &pluginName ); + + /** + * @brief Retrieve the name of the icon for a @ref Plugin. + * + * @return An empty string if the given plugin is not loaded + * or the filename of the icon to use. + */ + TQString pluginIcon( const Plugin *plugin ) const; + + /** + * Shuts down the plugin manager on Komposer shutdown, but first + * unloads all plugins asynchronously. + * + * After 3 seconds all plugins should be removed; what's still left + * by then is unloaded through a hard delete instead. + * + * Note that this call also derefs the plugin manager from the event + * loop, so do NOT call this method when not terminating Komposer! + */ + void shutdown(); + + /** + * Enable a plugin. + * + * This marks a plugin as enabled in the config file, so loadAll() + * can pick it up later. + * + * This method does not actually load a plugin, it only edits the + * config file. + * + * @param name is the name of the plugin as it is listed in the .desktop + * file in the X-KDE-Library field. + * + * Returns false when no appropriate plugin can be found. + */ + bool setPluginEnabled( const TQString &name, bool enabled = true ); + + /** + * Plugin loading mode. Used by @loadPlugin. Code that doesn't want to block + * the GUI and/or lot a lot of plugins at once should use Async loading. + * The default is sync loading. + */ + enum PluginLoadMode { LoadSync, LoadAsync }; + + public slots: + /** + * @brief Load a single plugin by plugin name. Returns an existing plugin + * if one is already loaded in memory. + * + * If mode is set to Async, the plugin will be queued and loaded in + * the background. This method will return a null pointer. To get + * the loaded plugin you can track the @ref pluginLoaded() signal. + * + * See also @ref plugin(). + */ + Plugin* loadPlugin( const TQString &pluginId, PluginLoadMode mode = LoadSync ); + + /** + * @brief Loads all the enabled plugins. Also used to reread the + * config file when the configuration has changed. + */ + void loadAllPlugins(); + + signals: + /** + * @brief Signals a new plugin has just been loaded. + */ + void pluginLoaded( Plugin *plugin ); + + /** + * @brief All plugins have been loaded by the plugin manager. + * + * This signal is emitted exactly ONCE, when the plugin manager has emptied + * its plugin queue for the first time. This means that if you call an async + * loadPlugin() before loadAllPlugins() this signal is probably emitted after + * the initial call completes, unless you are quick enough to fill the queue + * before it completes, which is a dangerous race you shouldn't count upon :) + * + * The signal is delayed one event loop iteration through a singleShot timer, + * but that is not guaranteed to be enough for account instantiation. You may + * need an additional timer for it in the code if you want to programmatically + * act on it. + * + * If you use the signal for enabling/disabling GUI objects there is little + * chance a user is able to activate them in the short while that's remaining, + * the slow part of the code is over now and the remaining processing time + * is neglectable for the user. + */ + void allPluginsLoaded(); + + private slots: + /** + * @brief Cleans up some references if the plugin is destroyed + */ + void slotPluginDestroyed( TQObject *plugin ); + + /** + * shutdown() starts a timer, when it fires we force all plugins + * to be unloaded here by deref()-ing the event loop to trigger the plugin + * manager's destruction + */ + void slotShutdownTimeout(); + + /** + * Common entry point to deref() the KApplication. Used both by the clean + * shutdown and the timeout condition of slotShutdownTimeout() + */ + void slotShutdownDone(); + + /** + * Emitted by a Plugin when it's ready for unload + */ + void slotPluginReadyForUnload(); + + /** + * Load a plugin from our queue. Does nothing if the queue is empty. + * Schedules itself again if more plugins are pending. + */ + void slotLoadNextPlugin(); + + private: + /** + * @internal + * + * The internal method for loading plugins. + * Called by @ref loadPlugin directly or through the queue for async plugin + * loading. + */ + Plugin *loadPluginInternal( const TQString &pluginId ); + + /** + * @internal + * + * Find the KPluginInfo structure by key. Reduces some code duplication. + * + * Returns a null pointer when no plugin info is found. + */ + KPluginInfo *infoForPluginId( const TQString &pluginId ) const; + private: + class Private; + Private *d; + }; + +} + +#endif // KOMPOSER_PLUGINMANAGER_H diff --git a/libtdepim/komposer/core/prefsmodule.cpp b/libtdepim/komposer/core/prefsmodule.cpp new file mode 100644 index 000000000..77e1c264b --- /dev/null +++ b/libtdepim/komposer/core/prefsmodule.cpp @@ -0,0 +1,142 @@ +/** + * prefsmodule.cpp + * + * Copyright (C) 2003-2004 Zack Rusin <zack@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA + */ + +#include "prefsmodule.h" + +#include <kaboutdata.h> +#include <kdebug.h> +#include <kcombobox.h> +#include <klocale.h> +#include <ktrader.h> + +#include <tqlayout.h> +#include <tqlabel.h> +#include <tqbuttongroup.h> + +#include <tdepimmacros.h> + +extern "C" +{ + KDE_EXPORT KCModule *create_komposerconfig( TQWidget *parent, const char * ) { + return new Komposer::PrefsModule( parent, "komposerprefs" ); + } +} +using namespace Komposer; + +PrefsModule::PrefsModule( TQWidget *parent, const char *name ) + : KPrefsModule( Komposer::Prefs::self(), parent, name ) +{ + TQVBoxLayout *topLayout = new TQVBoxLayout( this ); + + EditorSelection *editors = new EditorSelection( i18n( "Editors" ), + Komposer::Prefs::self()->m_activeEditor, + this ); + topLayout->addWidget( editors->groupBox() ); + + addWid( editors ); + + load(); +} + +const KAboutData* +PrefsModule::aboutData() const +{ + KAboutData *about = new KAboutData( I18N_NOOP( "komposerconfig" ), + I18N_NOOP( "KDE Komposer" ), + 0, 0, KAboutData::License_LGPL, + I18N_NOOP( "(c), 2003-2004 Zack Rusin" ) ); + + about->addAuthor( "Zack Rusin", 0, "zack@kde.org" );; + + return about; +} + + +EditorSelection::EditorSelection( const TQString &text, TQString &reference, + TQWidget *parent ) + : m_reference( reference ) +{ + m_box = new TQGroupBox( 0, TQt::Vertical, text, parent ); + TQVBoxLayout *boxLayout = new TQVBoxLayout( m_box->tqlayout() ); + boxLayout->tqsetAlignment( TQt::AlignTop ); + + m_editorsCombo = new KComboBox( m_box ); + boxLayout->addWidget( m_editorsCombo ); + + connect( m_editorsCombo, TQT_SIGNAL(activated(const TQString&)), + TQT_SLOT(slotActivated(const TQString&)) ); +} + +EditorSelection::~EditorSelection() +{ +} + +TQGroupBox* +EditorSelection::groupBox() const +{ + return m_box; +} + +void +EditorSelection::readConfig() +{ + m_editorsCombo->clear(); + + KTrader::OfferList editors = KTrader::self()->query( + TQString::tqfromLatin1( "Komposer/Editor" ) ); + KTrader::OfferList::ConstIterator it; + int i = 0; + for ( it = editors.begin(); it != editors.end(); ++it, ++i ) { + if ( !(*it)->hasServiceType( TQString::tqfromLatin1( "Komposer/Editor" ) ) ) + continue; + + TQString name = (*it)->property( "X-KDE-KomposerIdentifier" ).toString(); + m_editorsCombo->insertItem( name ); + if ( m_reference.contains( name ) ) + m_editorsCombo->setCurrentItem( i ); + } +} + +void EditorSelection::writeConfig() +{ + m_reference = m_services[ m_editorsCombo->currentText()]-> + property( "X-KDE-KomposerIdentifier" ).toString(); +} + +void +EditorSelection::slotActivated( const TQString &editor ) +{ + if ( !editor.isEmpty() ) + emit changed(); +} + +void +EditorSelection::setItem( const TQString &str ) +{ + for ( int i = 0; i < m_editorsCombo->count(); ++i ) { + if ( m_editorsCombo->text( i ) == str ) { + m_editorsCombo->setCurrentItem( i ); + break; + } + } +} + +#include "prefsmodule.moc" diff --git a/libtdepim/komposer/core/prefsmodule.h b/libtdepim/komposer/core/prefsmodule.h new file mode 100644 index 000000000..aba969f16 --- /dev/null +++ b/libtdepim/komposer/core/prefsmodule.h @@ -0,0 +1,72 @@ +/* + * prefsmodule.h + * + * Copyright (C) 2003 Zack Rusin <zack@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA + */ +#ifndef KOMPOSER_PREFSMODULE_H +#define KOMPOSER_PREFSMODULE_H + +#include <kprefsdialog.h> +#include <kservice.h> +#include <tqmap.h> +class TQGroupBox; +class TQListViewItem; + +class KAboutData; +class KComboBox; + +namespace Komposer { + + class PrefsModule : public KPrefsModule + { + Q_OBJECT + TQ_OBJECT + public: + PrefsModule( TQWidget *parent=0, const char *name=0 ); + virtual const KAboutData *aboutData() const; + }; + + class EditorSelection : public KPrefsWid + { + Q_OBJECT + TQ_OBJECT + + public: + EditorSelection( const TQString &text, TQString &reference, TQWidget *parent ); + ~EditorSelection(); + + void readConfig(); + void writeConfig(); + + TQGroupBox *groupBox() const; + + private slots: + void slotActivated( const TQString & ); + + private: + void setItem( const TQString & ); + private: + TQString &m_reference; + + TQGroupBox *m_box; + KComboBox *m_editorsCombo; + TQMap<TQString, KService::Ptr> m_services; + }; +} + +#endif diff --git a/libtdepim/komposer/core/settings.kcfgc b/libtdepim/komposer/core/settings.kcfgc new file mode 100644 index 000000000..fc98478a9 --- /dev/null +++ b/libtdepim/komposer/core/settings.kcfgc @@ -0,0 +1,9 @@ +# Code generation options for kconfig_compiler +File=komposer.kcfg +NameSpace=Komposer +ClassName=Config +Singleton=true +Mutators=true +#MemberVariables=public +GlobalEnums=true +#SetUserTexts=true diff --git a/libtdepim/komposer/core/tests/Makefile.am b/libtdepim/komposer/core/tests/Makefile.am new file mode 100644 index 000000000..fbf127956 --- /dev/null +++ b/libtdepim/komposer/core/tests/Makefile.am @@ -0,0 +1,20 @@ +INCLUDES = -I$(top_builddir)/libtdepim/komposer/core $(all_includes) + +check_PROGRAMS = testfactory testmanager testkomposer + +METASOURCES = AUTO + +testfactory_SOURCES = main.cpp managertest.cpp +testfactory_LDFLAGS = $(all_libraries) $(KDE_RPATH) $(LIB_QT) -lDCOP $(LIB_KDECORE) $(LIB_KDEUI) -ltdefx $(LIB_KIO) -lktexteditor +testfactory_LDADD = ../libkomposer.la + +testmanager_SOURCES = testmanager.cpp +testmanager_LDFLAGS = $(all_libraries) $(KDE_RPATH) $(LIB_QT) -lDCOP $(LIB_KDECORE) $(LIB_KDEUI) -ltdefx $(LIB_KIO) -lktexteditor +testmanager_LDADD = ../libkomposer.la + +testkomposer_SOURCES = testkomposer.cpp +testkomposer_LDFLAGS = $(all_libraries) $(KDE_RPATH) $(LIB_QT) -lDCOP $(LIB_KDECORE) $(LIB_KDEUI) -ltdefx $(LIB_KIO) -lktexteditor +testkomposer_LDADD = ../libkomposer.la + +check: testfactory + @./testfactory 2>&1 | grep "tests:" diff --git a/libtdepim/komposer/core/tests/main.cpp b/libtdepim/komposer/core/tests/main.cpp new file mode 100644 index 000000000..4a33a2f13 --- /dev/null +++ b/libtdepim/komposer/core/tests/main.cpp @@ -0,0 +1,52 @@ +/** + * main.cpp + * + * Copyright (C) 2004 Zack Rusin <zack@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA + */ +#include "testfactory.h" +#include <kaboutdata.h> +#include <kapplication.h> +#include <kdebug.h> +#include <klocale.h> +#include <kcmdlineargs.h> + +#include <unistd.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> + + +static const KCmdLineOptions options[] = +{ + {"verbose", "Verbose output", 0}, + KCmdLineLastOption +}; +int main( int argc, char** argv ) +{ + KAboutData aboutData( "tests","Test","0.1" ); + KCmdLineArgs::init( argc, argv, &aboutData ); + KCmdLineArgs::addCmdLineOptions( options ); + + KApplication app; + + KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); + Q_UNUSED( args ); + + TestFactory t; + return t.runTests(); +} diff --git a/libtdepim/komposer/core/tests/managertest.cpp b/libtdepim/komposer/core/tests/managertest.cpp new file mode 100644 index 000000000..487a84c59 --- /dev/null +++ b/libtdepim/komposer/core/tests/managertest.cpp @@ -0,0 +1,43 @@ +/** + * managertest.cpp + * + * Copyright (C) 2004 Zack Rusin <zack@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA + */ +#include "managertest.h" + +#include "pluginmanager.h" +using namespace Komposer; + +ManagerTest::ManagerTest( TQObject* parent ) + : TQObject( parent ) +{ + m_manager = new PluginManager( this ); +} + + +void ManagerTest::allTests() +{ + CHECK( m_manager->availablePlugins().isEmpty(), true ); + CHECK( m_manager->loadedPlugins().empty(), true ); + CHECK( m_manager->plugin( "non-existing" ), ( Plugin* )0 ); + m_manager->loadAllPlugins(); + CHECK( m_manager->loadedPlugins().empty(), true ); + m_manager->shutdown(); +} + +#include "managertest.moc" diff --git a/libtdepim/komposer/core/tests/managertest.h b/libtdepim/komposer/core/tests/managertest.h new file mode 100644 index 000000000..f02510e67 --- /dev/null +++ b/libtdepim/komposer/core/tests/managertest.h @@ -0,0 +1,45 @@ +/* + * managertest.h + * + * Copyright (C) 2004 Zack Rusin <zack@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA + */ +#ifndef MANAGERTEST_H +#define MANAGERTEST_H + +#include <tqobject.h> +#include "tester.h" + +namespace Komposer { + class PluginManager; +} + +class ManagerTest : public TQObject, + public Tester +{ + Q_OBJECT + TQ_OBJECT +public: + ManagerTest( TQObject* parent = 0 ); + +public slots: + void allTests(); +private: + Komposer::PluginManager* m_manager; +}; + +#endif diff --git a/libtdepim/komposer/core/tests/tester.cpp b/libtdepim/komposer/core/tests/tester.cpp new file mode 100644 index 000000000..b32c89644 --- /dev/null +++ b/libtdepim/komposer/core/tests/tester.cpp @@ -0,0 +1,30 @@ +/** + * tester.cpp + * + * Copyright (C) 2004 Zack Rusin <zack@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA + */ +#include "tester.h" + + +Tester::Tester( TQObject* parent ) + : TQObject( parent ) +{ +} + + +#include "tester.moc" diff --git a/libtdepim/komposer/core/tests/tester.h b/libtdepim/komposer/core/tests/tester.h new file mode 100644 index 000000000..5981d681d --- /dev/null +++ b/libtdepim/komposer/core/tests/tester.h @@ -0,0 +1,71 @@ +/* + * tester.h + * + * Copyright (C) 2004 Zack Rusin <zack@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA + */ +#ifndef TESTER_H +#define TESTER_H + +#include <kdebug.h> +#include <tqstringlist.h> + +#define CHECK( x, y ) check( __FILE__, __LINE__, #x, x, y ) + +class Tester +{ +public: + Tester() : m_tests( 0 ) {} + virtual ~Tester() {} + +public: + virtual void allTests() = 0; + +public: + int testsFinished() const { + return m_tests; + } + int testsFailed() const { + return m_errorList.count(); + } + TQStringList errorList() const { + return m_errorList; + } + +protected: + template<typename T> + void check( const char* file, int line, const char* str, + const T& result, const T& expectedResult ) + { + if ( result != expectedResult ) { + TQString error; + TQTextStream ts( &error, IO_WriteOnly ); + ts << file << "["<< line <<"]:" + <<" failed on \""<< str <<"\"" + << "\ntests:\t\t result = " + << result + << ", expected = "<< expectedResult; + m_errorList.append( error ); + } + ++m_tests; + } +private: + TQStringList m_errorList; + int m_tests; +}; + +#endif diff --git a/libtdepim/komposer/core/tests/testfactory.h b/libtdepim/komposer/core/tests/testfactory.h new file mode 100644 index 000000000..9354e52ad --- /dev/null +++ b/libtdepim/komposer/core/tests/testfactory.h @@ -0,0 +1,71 @@ +/* + * testfactory.h + * + * Copyright (C) 2004 Zack Rusin <zack@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA + */ +#ifndef TESTFACTORY_H +#define TESTFACTORY_H + +#include "managertest.h" + +#include <tqasciidict.h> + +#define ADD_TEST(x) addTest( #x, new x ) + +class TestFactory +{ +public: + TestFactory() + { + ADD_TEST( ManagerTest ); + m_tests.setAutoDelete( true ); + } + + int runTests() + { + int result = 0; + kdDebug()<<"Running tests..."<<endl; + TQAsciiDictIterator<Tester> it( m_tests ); + for( ; it.current(); ++it ) { + Tester* test = it.current(); + test->allTests(); + TQStringList errorList = test->errorList(); + if ( !errorList.empty() ) { + ++result; + kdDebug()<< it.currentKey() <<" errors:" << endl; + for ( TQStringList::Iterator itr = errorList.begin(); + itr != errorList.end(); ++itr ) { + kdDebug()<< "\t" << (*itr).latin1() <<endl;; + } + } else { + kdDebug()<< it.currentKey()<< " OK "<<endl; + } + } + kdDebug()<< "Done" <<endl; + return result; + } +public: + void addTest( const char* name, Tester* test ) + { + m_tests.insert( name, test ); + } +private: + TQAsciiDict<Tester> m_tests; +}; + +#endif diff --git a/libtdepim/komposer/core/tests/testkomposer.cpp b/libtdepim/komposer/core/tests/testkomposer.cpp new file mode 100644 index 000000000..b7997e8c3 --- /dev/null +++ b/libtdepim/komposer/core/tests/testkomposer.cpp @@ -0,0 +1,18 @@ +#include "core.h" + +#include <kplugininfo.h> +#include <kcmdlineargs.h> +#include <kapplication.h> +#include <kdebug.h> + +int main( int argc, char **argv ) +{ + KCmdLineArgs::init( argc, argv, "test", "test", "test", "0.1" ); + KApplication app; + + Komposer::Core *core = new Komposer::Core(); + app.setMainWidget( core ); + core->show(); + + return app.exec(); +} diff --git a/libtdepim/komposer/core/tests/testmanager.cpp b/libtdepim/komposer/core/tests/testmanager.cpp new file mode 100644 index 000000000..0fcba16b9 --- /dev/null +++ b/libtdepim/komposer/core/tests/testmanager.cpp @@ -0,0 +1,53 @@ +#include "testmanager.h" +#include "testmanager.moc" + +#include "pluginmanager.h" +#include "plugin.h" + +#include <kplugininfo.h> +#include <kcmdlineargs.h> +#include <kapplication.h> +#include <kdebug.h> + +using namespace Komposer; + +TestManager::TestManager( TQObject *parent ) + : TQObject( parent ) +{ + m_manager = new PluginManager( this ); + connect( m_manager, TQT_SIGNAL(pluginLoaded(Plugin*)), + TQT_SLOT(slotPluginLoaded(Plugin*)) ); + connect( m_manager, TQT_SIGNAL(allPluginsLoaded()), + TQT_SLOT(slotAllPluginsLoaded()) ); + m_manager->loadAllPlugins(); + + TQValueList<KPluginInfo*> plugins = m_manager->availablePlugins(); + kdDebug()<<"Number of available plugins is "<< plugins.count() <<endl; + for ( TQValueList<KPluginInfo*>::iterator it = plugins.begin(); it != plugins.end(); ++it ) { + KPluginInfo *i = ( *it ); + kdDebug()<<"\tAvailable plugin "<< i->name() + <<", comment = "<< i->comment() <<endl; + } +} + +void TestManager::slotAllPluginsLoaded() +{ + kdDebug()<<"Done"<<endl; + m_manager->shutdown(); + tqApp->exit(); +} + +void TestManager::slotPluginLoaded( Plugin *plugin ) +{ + kdDebug()<<"A plugin "<< m_manager->pluginName( plugin ) << " has been loaded"<<endl; +} + +int main( int argc, char **argv ) +{ + KCmdLineArgs::init( argc, argv, "test", "test", "test", "0.1" ); + KApplication app; + + TestManager manager( &app ); + + return app.exec(); +} diff --git a/libtdepim/komposer/core/tests/testmanager.h b/libtdepim/komposer/core/tests/testmanager.h new file mode 100644 index 000000000..5dfaa15d1 --- /dev/null +++ b/libtdepim/komposer/core/tests/testmanager.h @@ -0,0 +1,26 @@ +#ifndef TESTMANAGER_H +#define TESTMANAGER_H + +#include <tqobject.h> + +namespace Komposer { + class Plugin; + class PluginManager; +} +using Komposer::Plugin; + +class TestManager : public TQObject +{ + Q_OBJECT + TQ_OBJECT +public: + TestManager( TQObject *parent ); + +public slots: + void slotPluginLoaded( Plugin *plugin ); + void slotAllPluginsLoaded(); +private: + Komposer::PluginManager *m_manager; +}; + +#endif |