1 /*
2     SPDX-License-Identifier: GPL-2.0-or-later
3 
4     SPDX-FileCopyrightText: 2002 Dario Abatianni <eisfuchs@tigress.com>
5     SPDX-FileCopyrightText: 2005 Ismail Donmez <ismail@kde.org>
6     SPDX-FileCopyrightText: 2005 Peter Simonsson <psn@linux.se>
7     SPDX-FileCopyrightText: 2005 John Tapsell <johnflux@gmail.com>
8     SPDX-FileCopyrightText: 2005-2008 Eike Hein <hein@kde.org>
9 */
10 
11 #ifndef APPLICATION_H
12 #define APPLICATION_H
13 
14 #include <QNetworkConfigurationManager>
15 
16 #include "preferences.h"
17 #include "mainwindow.h"
18 #include "server.h"
19 #include "osd.h"
20 #include "identity.h"
21 #include "ircqueue.h"
22 
23 #include <QApplication>
24 
25 class ConnectionManager;
26 class AwayManager;
27 class ScriptLauncher;
28 class Server;
29 class QuickConnectDialog;
30 class Images;
31 class ServerGroupSettings;
32 class QStandardItemModel;
33 class QCommandLineParser;
34 
35 class KTextEdit;
36 
37 namespace Konversation
38 {
39     class DBus;
40     class IdentDBus;
41     class Sound;
42     class NotificationHandler;
43 
44     namespace DCC
45     {
46         class TransferManager;
47     }
48 }
49 
50 namespace KWallet
51 {
52     class Wallet;
53 }
54 
55 
56 class Application : public QApplication
57 {
58     Q_OBJECT
59     friend class ConnectionManager;
60 
61     public:
62         /** This function in general shouldn't be called, because in the future there
63          *  may be multiple windows.
64          *  However, in some situations we have messageboxes that aren't targeted for
65          *  any particular main window, such as general errors from dcop calls.
66          *
67          *  Note to any MDI developer - get this to return any of the windows, or some
68          *  'main' one.
69          */
getMainWindow()70         MainWindow* getMainWindow() const { return mainWindow; }
71 
getConnectionManager()72         ConnectionManager* getConnectionManager() const { return m_connectionManager; }
getAwayManager()73         AwayManager* getAwayManager() const { return m_awayManager; }
getScriptLauncher()74         ScriptLauncher* getScriptLauncher() const { return m_scriptLauncher; }
getDccTransferManager()75         Konversation::DCC::TransferManager* getDccTransferManager() const { return m_dccTransferManager; }
76 
77         // HACK
78         void showQueueTuner(bool);
79 
80         // URL-Catcher
getUrlModel()81         QStandardItemModel* getUrlModel() const { return m_urlModel; }
82 
83         Application(int &argc, char **argv);
84         ~Application() override;
85 
86         static Application* instance();
87 
88         /** For D-Bus, a user can be specified as user@irc.server.net
89          *  or user\@servergroup or using the unicode separator symbol 0xE120 instead
90          *  of the "@".  This function takes a string like the above examples, and
91          *  modifies ircnick and serverOrGroup to contain the split up string.  If
92          *  the string doesn't have an @ or 0xE120, ircnick is set to the
93          *  nick_server, and serverOrGroup is set to empty.
94          *  Behaviour is undefined for serverOrGroup if multiple @ or 0xE120 are found.
95          *  @param nick_server A string containting ircnick and possibly servername or server group
96          *  @param ircnick This is modified to contain the ircnick
97          *  @param serverOrGroup This is modified to contain the servername, servergroup or an empty string.
98          */
99         static void splitNick_Server(const QString& nick_server, QString &ircnick, QString &serverOrGroup);
100 
101         /** Tries to find a nickinfo for a given ircnick on a given ircserver.
102          *  @param ircnick The case-insensitive ircnick of the person you want to find.  e.g. "johnflux"
103          *  @param serverOrGroup The case-insensitive server name (e.g. "irc.kde.org") or server group name (e.g. "libera"), or null to search all servers
104          *  @return A nickinfo for this user and server if one is found.
105          */
106         NickInfoPtr getNickInfo(const QString &ircnick, const QString &serverOrGroup);
107 
108         Konversation::Sound* sound() const;
109 
110         OSDWidget* osd() const;
111 
112         IRCQueue::EmptyingRate staticrates[Server::_QueueListSize];
113 
images()114         Images* images() const { return m_images; }
115 
notificationHandler()116         Konversation::NotificationHandler* notificationHandler() const { return m_notificationHandler; }
117 
118         // auto replacement for input or output lines
119         QPair<QString, int> doAutoreplace(const QString& text, bool output, int cursorPos = -1) const;
120 
121         // inline auto replacement for input lines
122         void doInlineAutoreplace(KTextEdit* textEdit) const;
123 
124         void newInstance(QCommandLineParser *args);
125         void restoreInstance();
126 
127         static void openUrl(const QString& url);
128 
129         /// The wallet used to store passwords. Opens the wallet if it's closed.
130         KWallet::Wallet* wallet();
131 
abortScheduledRestart()132         void abortScheduledRestart() { m_restartScheduled = false; }
133 
134         /// The command line parser is needed for handling parsing arguments on new activations.
setCommandLineParser(QCommandLineParser * parser)135         void setCommandLineParser(QCommandLineParser *parser) { m_commandLineParser = parser; }
commandLineParser()136         QCommandLineParser *commandLineParser() const { return m_commandLineParser; }
137 
138     Q_SIGNALS:
139         void serverGroupsChanged(const Konversation::ServerGroupSettingsPtr serverGroup);
140         void appearanceChanged(); // FIXME TODO: Rather than relying on this catch-all, consumers should be rewritten to catch appropriate QEvents.
141 
142     public Q_SLOTS:
143         void restart();
144 
145         void readOptions();
146         void saveOptions(bool updateGUI=true);
147 
148         void fetchQueueRates(); ///< on Application::readOptions()
149         void stashQueueRates(); ///< on application exit
150         void resetQueueRates(); ///< when QueueTuner says to
countOfQueues()151         int countOfQueues() { return Server::_QueueListSize-1; }
152 
153         void prepareShutdown();
154 
155         void storeUrl(const QString& origin, const QString& newUrl, const QDateTime& dateTime);
156 
157         void handleActivate(const QStringList& arguments);
158 
159     protected:
160         bool event(QEvent* event) override;
161 
162     private Q_SLOTS:
163         void openQuickConnectDialog();
164 
165         void dbusMultiServerRaw(const QString &command);
166         void dbusRaw(const QString& connection, const QString &command);
167         void dbusSay(const QString& connection, const QString& target, const QString& command);
168         void dbusInfo(const QString& string);
169         void sendMultiServerCommand(const QString& command, const QString& parameter);
170 
171         void updateProxySettings();
172 
173         void closeWallet();
174 
175     private:
176         void implementRestart();
177         enum AutoConnectMode { NoAutoConnect, AutoConnect };
178         enum WindowRestoreMode { NoWindowRestore, WindowRestore };
179         void createMainWindow(AutoConnectMode autoConnectMode, WindowRestoreMode restoreMode);
180 
181     private:
182         ConnectionManager* m_connectionManager;
183         AwayManager* m_awayManager;
184         Konversation::DCC::TransferManager* m_dccTransferManager;
185         ScriptLauncher* m_scriptLauncher;
186         QStandardItemModel* m_urlModel;
187         Konversation::DBus* dbusObject;
188         Konversation::IdentDBus* identDBus;
189         QPointer<MainWindow> mainWindow;
190         OSDWidget* m_osd;
191         mutable Konversation::Sound* m_sound;
192         QuickConnectDialog* quickConnectDialog;
193         Images* m_images;
194         bool m_restartScheduled;
195 
196         Konversation::NotificationHandler* m_notificationHandler;
197 
198         KWallet::Wallet* m_wallet;
199 
200 // Silence deprecation warnings as long as there is no known substitute for QNetworkConfigurationManager
201 QT_WARNING_PUSH
202 QT_WARNING_DISABLE_CLANG("-Wdeprecated-declarations")
203 QT_WARNING_DISABLE_GCC("-Wdeprecated-declarations")
204         QNetworkConfigurationManager* m_networkConfigurationManager;
205 QT_WARNING_POP
206 
207         QCommandLineParser *m_commandLineParser;
208         QStringList m_restartArguments;
209 
210         Q_DISABLE_COPY(Application)
211 };
212 
213 #endif
214 
215 // kate: space-indent on; tab-width 4; indent-width 4; mixed-indent off; replace-tabs on;
216 // vim: set et sw=4 ts=4 cino=l1,cs,U1:
217