File indexing completed on 2024-04-21 05:03:27
0001 /************************************************************************************** 0002 Copyright (C) 2003 by Jeroen Wijnhout (Jeroen.Wijnhout@kdemail.net) 0003 2011-2018 by Michel Ludwig (michel.ludwig@kdemail.net) 0004 **************************************************************************************/ 0005 0006 /*************************************************************************** 0007 * * 0008 * This program is free software; you can redistribute it and/or modify * 0009 * it under the terms of the GNU General Public License as published by * 0010 * the Free Software Foundation; either version 2 of the License, or * 0011 * (at your option) any later version. * 0012 * * 0013 ****************************************************************************/ 0014 0015 #ifndef KILETOOLMANAGER_H 0016 #define KILETOOLMANAGER_H 0017 0018 #include <QList> 0019 #include <QObject> 0020 #include <QQueue> 0021 #include <QStackedWidget> 0022 #include <QStringList> 0023 0024 #include "kiletool.h" 0025 #include "tool_utils.h" 0026 0027 /*********************************************************************************************************** 0028 * CAUTION!! 0029 * It must be ensured that no event loop is started whenever some tool operation 0030 * is running. This includes running code inside the tool classes! 0031 * 0032 * The reason for that is that an event loop might trigger the deletion a tool object for which code 0033 * is currently executed, for instance with the 'stopLivePreview' method. 0034 * An event loop is executed, for example, within the 'documentSave' method of KatePart. Although the event 0035 * loop doesn't process user events, the document modification timer might still be triggered in such 0036 * an event loop and 'stopLivePreview' will be called. Now, no document saving is performed inside tool 0037 * classes anymore (including the tool manager). 0038 *********************************************************************************************************** 0039 * Also, it is important that parsing has to be finished before any tool is processed; for example, when 0040 * a project is being opened and the right master document still has to be determined through parsing. 0041 ***********************************************************************************************************/ 0042 0043 class QTimer; 0044 0045 class QAction; 0046 class KActionCollection; 0047 class KConfig; 0048 class KSelectAction; 0049 class KTextEdit; 0050 0051 class KileInfo; 0052 namespace KileParser { 0053 class Manager; 0054 } 0055 namespace KileView { 0056 class Manager; 0057 } 0058 namespace KileWidget { 0059 class OutputView; 0060 } 0061 0062 namespace KileTool 0063 { 0064 class Factory; 0065 class LivePreviewManager; 0066 0067 class QueueItem 0068 { 0069 public: 0070 explicit QueueItem(Base *tool, bool block = false); 0071 ~QueueItem(); 0072 0073 Base* tool() const { 0074 return m_tool; 0075 } 0076 bool shouldBlock() { 0077 return m_bBlock; 0078 } 0079 0080 private: 0081 Base *m_tool; 0082 bool m_bBlock; 0083 }; 0084 0085 class Queue : public QQueue<QueueItem*> 0086 { 0087 public: 0088 Base* tool() const; 0089 bool shouldBlock() const; 0090 0091 void enqueueNext(QueueItem *); 0092 }; 0093 0094 class Manager : public QObject 0095 { 0096 friend class Base; 0097 Q_OBJECT 0098 0099 public: 0100 Manager(KileInfo *ki, KConfig *config, KileWidget::OutputView *output, QStackedWidget* stack, uint to, KActionCollection *); 0101 ~Manager(); 0102 public: 0103 Base* createTool(const QString& name, const QString &cfg = QString(), bool prepare = false); 0104 inline Base* createTool(const ToolConfigPair& p, bool prepare = false) 0105 { 0106 return createTool(p.first, p.second, prepare); 0107 } 0108 bool configure(Base*, const QString &cfg = QString()); 0109 bool retrieveEntryMap(const QString & name, Config & map, bool usequeue = true, bool useproject = true, const QString & cfg = QString()); 0110 void saveEntryMap(const QString & name, Config & map, bool usequeue = true, bool useproject = true); 0111 QString currentGroup(const QString &name, bool usequeue = true, bool useproject = true); 0112 0113 void wantGUIState(const QString &); 0114 0115 QStackedWidget* widgetStack() { 0116 return m_stack; 0117 } 0118 KileView::Manager* viewManager(); 0119 KileTool::LivePreviewManager* livePreviewManager(); 0120 KileParser::Manager* parserManager(); 0121 0122 KileInfo * info() { 0123 return m_ki; 0124 } 0125 KConfig * config() { 0126 return m_config; 0127 } 0128 0129 void setFactory(Factory* fac) { 0130 m_factory = fac; 0131 } 0132 Factory* factory() { 0133 return m_factory; 0134 } 0135 0136 bool queryContinue(const QString & question, const QString & caption = QString()); 0137 0138 bool shouldBlock(); 0139 int lastResult() { 0140 return m_nLastResult; 0141 } 0142 0143 // convenience method; also see the static method of the same name below 0144 void setConfigName(const QString &tool, const QString &name); 0145 0146 bool containsBibliographyTool(const ToolConfigPair& p) const; 0147 ToolConfigPair findFirstBibliographyToolForCommand(const QString& command) const; 0148 0149 public Q_SLOTS: 0150 void run(KileTool::Base *tool); 0151 0152 void stopLivePreview(); 0153 0154 private: 0155 void setEnabledStopButton(bool state); 0156 void initTool(Base*); 0157 0158 private Q_SLOTS: 0159 int runImmediately(Base *tool, bool insertAtTop = false, bool block = false, Base *parent = Q_NULLPTR); 0160 int runNextInQueue(); 0161 void enableClear(); 0162 0163 void started(KileTool::Base *tool); 0164 void done(KileTool::Base *tool, int result); 0165 0166 void stop(); //should be a slot that stops the active tool and clears the queue 0167 void stopActionDestroyed(); 0168 0169 // must be used when a child tool is launched from within another tool! 0170 int runChildNext(Base *parent, Base *tool, bool block = false); 0171 0172 void toolScheduledAfterParsingDestroyed(KileTool::Base *tool); 0173 void handleDocumentParsingComplete(); 0174 0175 void currentLaTeXOutputHandlerChanged(LaTeXOutputHandler* handler); 0176 0177 void bibliographyBackendSelectedByUser(); 0178 void buildBibliographyBackendSelection(); 0179 void resetAutodetectedBibliographyBackend(); 0180 0181 Q_SIGNALS: 0182 void requestGUIState(const QString &); 0183 void jumpToFirstError(); 0184 void toolStarted(); 0185 void previewDone(); 0186 // emitted when a tool spawns another tool (parent, child). 0187 void childToolSpawned(KileTool::Base*,KileTool::Base*); 0188 0189 private: 0190 KileInfo *m_ki; 0191 KConfig *m_config; 0192 KileWidget::OutputView *m_output; 0193 QStackedWidget *m_stack; 0194 QAction *m_stopAction; 0195 Factory *m_factory; 0196 Queue m_queue; 0197 QTimer *m_timer; 0198 bool m_bClear; 0199 int m_nLastResult; 0200 uint m_nTimeout; 0201 QQueue<Base*> m_toolsScheduledAfterParsingList; 0202 KSelectAction *m_bibliographyBackendSelectAction; 0203 QAction *m_bibliographyBackendAutodetectAction; 0204 QAction *m_bibliographyBackendResetAutodetectedAction; 0205 QMap<ToolConfigPair, QAction *> m_bibliographyBackendActionMap; 0206 QList<ToolConfigPair> m_bibliographyToolsList; 0207 0208 void createActions(KActionCollection *ac); 0209 0210 void deleteLivePreviewToolsFromQueue(); 0211 void deleteLivePreviewToolsFromRunningAfterParsingQueue(); 0212 }; 0213 0214 QStringList toolList(KConfig *config, bool menuOnly = false); 0215 QStringList configNames(const QString &tool, KConfig *config); 0216 0217 QList<ToolConfigPair> toolsWithConfigurationsBasedOnClass(KConfig *config, const QString& className); 0218 0219 // configuration names must be in English, i.e. not translated! 0220 QString configName(const QString &tool, KConfig *config); 0221 void setConfigName(const QString &tool, const QString &name, KConfig *config); 0222 0223 QString groupFor(const QString& tool, KConfig *config); 0224 QString groupFor(const QString& tool, const QString& cfg = "Default"); 0225 0226 void extract(const QString& str, QString &tool, QString &cfg); 0227 QString format(const QString& tool, const QString &cfg); 0228 0229 QString commandFor(const QString& toolName, const QString& configName, KConfig *config); 0230 inline QString commandFor(const ToolConfigPair& p, KConfig *config) 0231 { 0232 return commandFor(p.first, p.second, config); 0233 } 0234 0235 0236 QString menuFor(const QString &tool, KConfig *config); 0237 QString iconFor(const QString &tool, KConfig *config); 0238 0239 0240 QString categoryFor(const QString &clss); 0241 0242 void setGUIOptions(const QString &tool, const QString &menu, const QString &icon, KConfig *config); 0243 } 0244 0245 #endif