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 #include "picturebrowserplugin.h"
8 
9 // See scplugin.h and pluginmanager.{cpp,h} for detail on what these methods
10 // do. That documentatation is not duplicated here.
11 // Please don't implement the functionality of your plugin here; do that
12 // in mypluginimpl.h and mypluginimpl.cpp .
13 
PictureBrowserPlugin()14 PictureBrowserPlugin::PictureBrowserPlugin()
15 {
16 	// Set action info in languageChange, so we only have to do
17 	// it in one place.
18 	languageChange();
19 }
20 
~PictureBrowserPlugin()21 PictureBrowserPlugin::~PictureBrowserPlugin()
22 {
23 }
24 
cleanupPlugin()25 bool PictureBrowserPlugin::cleanupPlugin()
26 {
27 	closePictureBrowser();
28 	return true;
29 }
30 
languageChange()31 void PictureBrowserPlugin::languageChange()
32 {
33 	// Note that we leave the unused members unset. They'll be initialised
34 	// with their default ctors during construction.
35 	// Action name
36 	m_actionInfo.name = "Picture Browser";
37 	// Action text for menu, including &accel
38 	m_actionInfo.text = tr ( "&Picture Browser..." );
39 	// Menu
40 	m_actionInfo.menu = "Extras";
41 	// If needed, what item to add the menu item after
42 	m_actionInfo.menuAfterName = "extrasManageImages";
43 	// If needed, the keyboard shortcut for the plugin
44 	//m_actionInfo.keySequence = "CTRL+ALT+F3"
45 	// Should the menu item be enabled when the app starts
46 	// (even without a document open) ?
47 	m_actionInfo.enabledOnStartup = false;
48 	m_actionInfo.needsNumObjects = -1;
49 }
50 
fullTrName() const51 QString PictureBrowserPlugin::fullTrName() const
52 {
53 	return QObject::tr ( "Picture Browser" );
54 }
55 
getAboutData() const56 const ScActionPlugin::AboutData* PictureBrowserPlugin::getAboutData() const
57 {
58 	AboutData* about = new AboutData;
59 	Q_CHECK_PTR ( about );
60 	return about;
61 }
62 
deleteAboutData(const AboutData * about) const63 void PictureBrowserPlugin::deleteAboutData(const AboutData* about) const
64 {
65 	Q_ASSERT ( about );
66 	delete about;
67 }
68 
run(ScribusDoc * doc,const QString & target)69 bool PictureBrowserPlugin::run(ScribusDoc* doc, const QString& target)
70 {
71 	//picturebrowser isn't running yet, so create it
72 	if (!m_pictureBrowser)
73 	{
74 		m_pictureBrowser = new PictureBrowser(doc, nullptr);
75 		if (!m_pictureBrowser)
76 			return false;
77 
78 		connect(m_pictureBrowser, SIGNAL (destroyed()), this, SLOT (pictureBrowserClosed()));
79 	}
80 	//picturebrowser exists, just bring it to the top
81 	else
82 	{
83 		m_pictureBrowser->hide();
84 	}
85 
86 	Q_CHECK_PTR (m_pictureBrowser);
87 
88 	m_pictureBrowser->setAttribute ( Qt::WA_DeleteOnClose );
89 	//show, get on top and activate window
90 	m_pictureBrowser->show();
91 	m_pictureBrowser->raise();
92 	m_pictureBrowser->activateWindow();
93 
94 	return true;
95 }
96 
setDoc(ScribusDoc * doc)97 void PictureBrowserPlugin::setDoc(ScribusDoc* doc)
98 {
99 	if (m_pictureBrowser)
100 		m_pictureBrowser->changedDocument(doc);
101 }
102 
unsetDoc()103 void PictureBrowserPlugin::unsetDoc()
104 {
105 	if (m_pictureBrowser)
106 		m_pictureBrowser->closedDocument();
107 }
108 
changedDoc(ScribusDoc * doc)109 void PictureBrowserPlugin::changedDoc(ScribusDoc* doc)
110 {
111 //	if (m_pictureBrowser)
112 //		m_pictureBrowser->changedDocument (doc);
113 }
114 
closePictureBrowser()115 void PictureBrowserPlugin::closePictureBrowser()
116 {
117 	if (m_pictureBrowser)
118 	{
119 		if (m_pictureBrowser->isVisible())
120 			m_pictureBrowser->close();
121 		delete m_pictureBrowser;
122 		m_pictureBrowser = nullptr;
123 	}
124 }
125 
pictureBrowserClosed()126 void PictureBrowserPlugin::pictureBrowserClosed()
127 {
128 	m_pictureBrowser = nullptr;
129 }
130 
131 // Low level plugin API
picturebrowser_getPluginAPIVersion()132 int picturebrowser_getPluginAPIVersion()
133 {
134 	return PLUGIN_API_VERSION;
135 }
136 
picturebrowser_getPlugin()137 ScPlugin* picturebrowser_getPlugin()
138 {
139 	PictureBrowserPlugin* plug = new PictureBrowserPlugin();
140 	Q_CHECK_PTR ( plug );
141 	return plug;
142 }
143 
picturebrowser_freePlugin(ScPlugin * plugin)144 void picturebrowser_freePlugin(ScPlugin* plugin)
145 {
146 	PictureBrowserPlugin* plug = qobject_cast<PictureBrowserPlugin*> ( plugin );
147 	Q_ASSERT ( plug );
148 	delete plug;
149 }
150