Scribus
Open source desktop publishing at your fingertips
scplugin.h
1 /*
2 For general Scribus (>=1.3.2) copyright and licensing information please refer
3 to the COPYING file provided with the program. Following this notice may exist
4 a copyright and/or license notice that predates the release of Scribus 1.3.2
5 for which a new license (GPL+exception) is in place.
6 */
7 #ifndef _SCPLUGIN_H
8 #define _SCPLUGIN_H
9 
10 #include <QObject>
11 #include <QWidget>
12 #include <QString>
13 #include <QPixmap>
14 #include <QDateTime>
15 #include <QIcon>
16 #include "scribusapi.h"
17 
18 class ScribusDoc;
19 class ScribusMainWindow;
20 class DeferredTask;
21 class PrefsPanel;
22 class Prefs_Pane;
23 
90 class SCRIBUS_API ScPlugin : public QObject
91 {
92  Q_OBJECT
93 
99  public:
100 
103  struct AboutData
104  {
106  QString authors;
110  QString description;
112  QString version;
114  QDateTime releaseDate;
116  QString copyright;
121  QString license;
122  };
123 
130  ScPlugin();
131 
139  virtual ~ScPlugin() = 0;
140 
147  virtual const QString fullTrName() const = 0;
148 
174  virtual bool newPrefsPanelWidget(QWidget* parent, PrefsPanel*& panel,
175  QString& caption, QPixmap& icon);
176  virtual bool newPrefsPanelWidget(QWidget* parent, Prefs_Pane*& panel,
177  QString& caption, QPixmap& icon);
178 
190  virtual const AboutData* getAboutData() const = 0;
191  virtual void deleteAboutData(const AboutData* about) const = 0;
192 
200  const QString & lastError() const;
201 
203  bool hasLastError() const;
204 
206  void clearLastError();
207 
219  virtual void languageChange() = 0;
220 
222  const QString pluginTypeName() const;
223 
225  virtual void addToMainWindowMenu(ScribusMainWindow *) = 0;
226 
228  virtual void setDoc(ScribusDoc* doc);
229  virtual void unsetDoc();
230  virtual void changedDoc(ScribusDoc* doc);
231  protected:
233  QString m_lastError;
234 };
235 
236 
248 class SCRIBUS_API ScActionPlugin : public ScPlugin
249 {
250  Q_OBJECT
251 
252  public:
253 
258  ScActionPlugin();
259 
261  virtual ~ScActionPlugin() = 0;
262 
263  // Information about actions, to be returned by actionInfo()
264  struct ActionInfo {
265  QString name; // name of action
266  QString text; // text to display to user
267  QString helpText; // help text for ToolTips and StatusTips
268  QString keySequence;
269  QString menu;
270  QString menuAfterName;
271  QString parentMenu;
272  QString subMenuName;
273  QString toolbar; // Name of the ToolBar the action is to be inserted, if that toolbar doesn't exits it will be created
274  QString toolBarName; // translateable ToolBar title
275  QPixmap icon1;
276  QPixmap icon2;
277  QList<int> notSuitableFor; // a list of PageItem type values which the plugin can *not* handle
278  QList<int> forAppMode; // a list of AppMode values for which the plugin will be active, an empty list indicates that the plugin is always active
279  int needsNumObjects; // plugin needs this number of selected Objects. -1 = needs no Object, num > 2 any number of Objects is allowed
280  QList<int> firstObjectType; // when needsNumObjects is 2 this list contains the Object Types of the first object on the selection
281  QList<int> secondObjectType; // when needsNumObjects is 2 this list contains the Object Types of the second object on the selection
282  // -1 indicates that any kind of object is possible. Otherwise the selection must contain the 2 Object Types
283  // for the Plugin Action to be enabled
284  bool enabledOnStartup;
285  bool enabledForStoryEditor;
286  QString seMenu;
287  QString seParentMenu;
288  QString seKeySequence;
289  };
290 
291  // Return an ActionInfo instance to the caller
292  const ActionInfo & actionInfo() const;
304  virtual bool handleSelection(ScribusDoc* doc, int SelectedType = -1);
305 
306  public slots:
318  virtual bool cleanupPlugin() { return false; }
319 
346  virtual bool run(ScribusDoc* doc, QString target = QString::null) = 0;
347 
355  virtual bool run(QWidget* parent, ScribusDoc* doc, QString target = QString::null);
356 
372  virtual bool run(ScribusDoc* doc, QIODevice* target);
373 
414  virtual DeferredTask* runAsync(QString target = QString::null);
415 
423  virtual DeferredTask* runAsync(QIODevice* target);
424 
425  // Compat kludge ... we store a QString result from any successful
426  // run(...) call in m_runResult and let callers retrive it here.
427  // DO NOT USE THIS INTERFACE FOR NEW PLUG-INS; you should
428  // dynamic_cast<> to the plugin type then call a plug-in specific
429  // method instead.
431  const QString & runResult() const;
432 
433  protected:
434  // Action info. To be set up by ctor.
435  ActionInfo m_actionInfo;
436  // Obsolete - see runResult()
437  QString m_runResult;
438  ScribusDoc* m_Doc;
439 };
440 
454 class SCRIBUS_API ScPersistentPlugin : public ScPlugin
455 {
456  Q_OBJECT
457 
458  public:
459 
465 
467  virtual ~ScPersistentPlugin() = 0;
468 
493  virtual bool initPlugin() = 0;
494 
506  virtual bool cleanupPlugin() = 0;
507 };
508 
509 // Plug-in API version used to check if we can load the plug-in. This
510 // does *NOT* ensure that the plug-in will be compatible with the internal
511 // Scribus APIs, only that the ScPlugin class and its standard subclasses
512 // will be compatible with what we expect, and that "extern C" functions
513 // we need will be present and work as expected. It's a preprocessor directive
514 // to make sure that it's compiled into each plugin rather than referenced
515 // from the main code.
516 //
517 // The API version is currently simply incremented with each incompatible
518 // change. Future versions may introduce a minor/major scheme if necessary.
519 #define PLUGIN_API_VERSION 0x00000106
520 
521 
522 #endif
QString shortDescription
One-liner description of the function of the plugin.
Definition: scplugin.h:108
A plug-in that performs a single action.
Definition: scplugin.h:248
QString version
Text plug-in version string.
Definition: scplugin.h:112
Abstract super class for all Scribus plug-ins.
Definition: scplugin.h:90
This Class is the base class for your application. It sets up the main window and providing a menubar...
Definition: scribus.h:123
QDateTime releaseDate
Date of the release of this version.
Definition: scplugin.h:114
QString description
Longer description of the plugin.
Definition: scplugin.h:110
the Document Class
Definition: scribusdoc.h:90
QString authors
Author name(s) and email address(es)
Definition: scplugin.h:106
QString license
Definition: scplugin.h:121
ScPlugin provides an interface to ask plugins for information about themselves.
Definition: scplugin.h:103
A plug-in that is resident for the lifetime of the app.
Definition: scplugin.h:454
A base class for all preferences panels.
Definition: prefspanel.h:21
Definition: prefs_pane.h:14
DeferredTask is an abstraction of a generally long-running operation that is done in small steps unde...
Definition: deferredtask.h:37
Definition: scplugin.h:264
QString m_lastError
Human readable, translated version of last error to occur.
Definition: scplugin.h:233
QString copyright
Copyright string.
Definition: scplugin.h:116
virtual bool cleanupPlugin()
Deactivates the plugin for unloading / program quit.
Definition: scplugin.h:318