File indexing completed on 2023-09-24 09:47:30
0001 /* 0002 This file is part of Lokalize 0003 0004 SPDX-FileCopyrightText: 2008-2014 Nick Shaforostoff <shafff@ukr.net> 0005 SPDX-FileCopyrightText: 2018-2019 Simon Depiets <sdepiets@gmail.com> 0006 0007 SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0008 */ 0009 0010 #ifndef LOKALIZEMAINWINDOW_H 0011 #define LOKALIZEMAINWINDOW_H 0012 0013 #include "pos.h" 0014 0015 #include <kxmlguiwindow.h> 0016 #include <kconfiggroup.h> 0017 0018 #include <QPointer> 0019 #include <QMap> 0020 #include <QUrl> 0021 #include <QMdiArea> 0022 #include <QDBusObjectPath> 0023 0024 class QLabel; 0025 class QMdiSubWindow; 0026 class QMdiArea; 0027 class QActionGroup; 0028 class LokalizeMdiArea; 0029 class KRecentFilesAction; 0030 class EditorTab; 0031 class MultiEditorAdaptor; 0032 class FileSearchTab; 0033 namespace TM 0034 { 0035 class TMTab; 0036 } 0037 0038 /** 0039 * @short Lokalize MDI (tabbed) window. 0040 * 0041 * Sets up actions, and maintains their connection with active subwindow via ActionProxy 0042 * As such, it handles the menus, toolbars, and status bars. 0043 * 0044 * It is known as Lokalize in kross scripts and as 0045 * '/ThisIsWhatYouWant : org.kde.Lokalize.MainWindow' in qdbusviewer 0046 * 0047 * @author Nick Shaforostoff <shafff@ukr.net> 0048 */ 0049 class LokalizeMainWindow: public KXmlGuiWindow 0050 { 0051 Q_OBJECT 0052 Q_CLASSINFO("D-Bus Interface", "org.kde.Lokalize.MainWindow") 0053 //qdbuscpp2xml -m -s lokalizemainwindow.h -o org.kde.lokalize.MainWindow.xml 0054 0055 public: 0056 LokalizeMainWindow(); 0057 ~LokalizeMainWindow() override; 0058 0059 protected: 0060 void saveProjectState(KConfigGroup&); 0061 void saveProperties(KConfigGroup& stateGroup) override; 0062 bool queryClose() override; 0063 void readProperties(const KConfigGroup& stateGroup) override; 0064 void registerDBusAdaptor(); 0065 void setupActions(); 0066 0067 private Q_SLOTS: 0068 void slotSubWindowActivated(QMdiSubWindow*); 0069 void initLater(); 0070 void applyToBeActiveSubWindow(); 0071 void projectLoaded(); 0072 void projectSettingsChanged(); 0073 0074 void editorClosed(QObject* obj); 0075 void resetMultiEditorAdaptor(); 0076 0077 void openProject(const QUrl& url) 0078 { 0079 openProject(url.toLocalFile()); //convenience overload for recent projects action 0080 } 0081 void openProject() 0082 { 0083 openProject(QString()); 0084 } 0085 0086 0087 public Q_SLOTS: 0088 /** 0089 * Adds new editor with @param path loaded, 0090 * or just activates already existing editor with this file. 0091 */ 0092 Q_SCRIPTABLE int openFileInEditor(const QString& path); 0093 Q_SCRIPTABLE int openFileInEditorAt(const QString& path, const QString& source, const QString& ctxt); 0094 int lookupInTranslationMemory(DocPosition::Part part, const QString& text); 0095 Q_SCRIPTABLE int lookupInTranslationMemory(const QString& source, const QString& target); 0096 Q_SCRIPTABLE int showTranslationMemory(); 0097 Q_SCRIPTABLE void showProjectOverview(); 0098 Q_SCRIPTABLE QObject* projectOverview(); 0099 0100 Q_SCRIPTABLE bool closeProject(); 0101 Q_SCRIPTABLE void openProject(QString path); 0102 Q_SCRIPTABLE QString currentProject(); 0103 0104 /// @returns 0 if current tab is not of Editor type 0105 Q_SCRIPTABLE QObject* activeEditor(); 0106 0107 /// @returns editor with @param path loaded or 0 if there is no such editor. 0108 Q_SCRIPTABLE QObject* editorForFile(const QString& path); 0109 /** 0110 * # part of editor DBus path: /ThisIsWhatYouWant/Editor/# 0111 * @returns -1 if there is no such editor 0112 */ 0113 Q_SCRIPTABLE int editorIndexForFile(const QString& path); 0114 0115 /// @returns Unix process ID 0116 Q_SCRIPTABLE int pid(); 0117 0118 /// @returns smth like 'org.kde.lokalize-####' where #### is pid() 0119 Q_SCRIPTABLE QString dbusName(); 0120 0121 Q_SCRIPTABLE void busyCursor(bool busy); 0122 //Q_SCRIPTABLE void processEvents(); 0123 0124 //returns 0 if error 0125 EditorTab* fileOpen_(QString url, const bool setAsActive); 0126 EditorTab* fileOpen(QString url = QString(), int entry = 0, bool setAsActive = true, const QString& mergeFile = QString(), bool silent = false); 0127 EditorTab* fileOpen(const QString& url, const QString& source, const QString& ctxt, const bool setAsActive); 0128 EditorTab* fileOpen(const QString& url, DocPosition docPos, int selection, const bool setAsActive); 0129 EditorTab* fileOpen(const QUrl& url) 0130 { 0131 return fileOpen(url.toLocalFile(), 0, true); 0132 } 0133 TM::TMTab* showTM(); 0134 FileSearchTab* showFileSearch(bool activate = true); 0135 void fileSearchNext(); 0136 void addFilesToSearch(const QStringList&); 0137 0138 void widgetTextCapture(); 0139 Q_SIGNALS: 0140 Q_SCRIPTABLE void editorAdded(); 0141 Q_SCRIPTABLE void editorActivated(); 0142 0143 private: 0144 LokalizeMdiArea* m_mdiArea; 0145 QPointer<QMdiSubWindow> m_prevSubWindow{}; 0146 QPointer<QMdiSubWindow> m_projectSubWindow{}; 0147 QPointer<QMdiSubWindow> m_translationMemorySubWindow{}; 0148 QPointer<QMdiSubWindow> m_fileSearchSubWindow{}; 0149 QPointer<QMdiSubWindow> m_toBeActiveSubWindow{}; //used during session restore 0150 0151 QActionGroup* m_editorActions{}; 0152 QActionGroup* m_managerActions{}; 0153 KRecentFilesAction* m_openRecentFileAction{}; 0154 KRecentFilesAction* m_openRecentProjectAction{}; 0155 QVector<QLabel*> m_statusBarLabels; 0156 0157 QByteArray m_lastEditorState; 0158 0159 //used for kross API 0160 EditorTab* m_spareEditor{}; 0161 MultiEditorAdaptor* m_multiEditorAdaptor{}; 0162 0163 //using QPointer switches it.value() to 0 before we get to destroyed() handler 0164 //typedef QMap<QUrl, QPointer<QMdiSubWindow> > FileToEditor; 0165 typedef QMap<QString, QMdiSubWindow*> FileToEditor; 0166 FileToEditor m_fileToEditor; 0167 }; 0168 0169 class LokalizeMdiArea: public QMdiArea 0170 { 0171 Q_OBJECT 0172 public Q_SLOTS: 0173 void activateNextSubWindow(); 0174 void activatePreviousSubWindow(); 0175 }; 0176 0177 class DelayedFileOpener: public QObject 0178 { 0179 Q_OBJECT 0180 public: 0181 DelayedFileOpener(const QVector<QString>& urls, LokalizeMainWindow* lmw); 0182 0183 private Q_SLOTS: 0184 void doOpen(); 0185 0186 private: 0187 QVector<QString> m_urls; 0188 LokalizeMainWindow* m_lmw{}; 0189 }; 0190 0191 0192 #endif