Commit 10df8145 authored by Friedrich W. H. Kossebau's avatar Friedrich W. H. Kossebau
Browse files

Fix broken restore by session management

parent b5c741d2
......@@ -139,138 +139,146 @@ void Application::implementRestart()
KProcess::startDetached(QCoreApplication::applicationFilePath(), m_restartArguments);
}
void Application::newInstance(QCommandLineParser *args)
void Application::createMainWindow(AutoConnectMode autoConnectMode, WindowRestoreMode restoreMode)
{
QString url;
if (!args->positionalArguments().isEmpty())
url = args->positionalArguments().at(0);
if (!mainWindow)
{
connect(this, &Application::aboutToQuit, this, &Application::prepareShutdown);
connect(this, &Application::aboutToQuit, this, &Application::prepareShutdown);
m_connectionManager = new ConnectionManager(this);
m_connectionManager = new ConnectionManager(this);
m_awayManager = new AwayManager(this);
m_awayManager = new AwayManager(this);
connect(m_connectionManager, &ConnectionManager::identityOnline, m_awayManager, &AwayManager::identityOnline);
connect(m_connectionManager, &ConnectionManager::identityOffline, m_awayManager, &AwayManager::identityOffline);
connect(m_connectionManager, &ConnectionManager::connectionChangedAwayState, m_awayManager, &AwayManager::updateGlobalAwayAction);
connect(m_connectionManager, &ConnectionManager::identityOnline, m_awayManager, &AwayManager::identityOnline);
connect(m_connectionManager, &ConnectionManager::identityOffline, m_awayManager, &AwayManager::identityOffline);
connect(m_connectionManager, &ConnectionManager::connectionChangedAwayState, m_awayManager, &AwayManager::updateGlobalAwayAction);
// Silence deprecation warnings as long as there is no known substitute for QNetworkConfigurationManager
QT_WARNING_PUSH
QT_WARNING_DISABLE_CLANG("-Wdeprecated-declarations")
QT_WARNING_DISABLE_GCC("-Wdeprecated-declarations")
m_networkConfigurationManager = new QNetworkConfigurationManager();
connect(m_networkConfigurationManager, &QNetworkConfigurationManager::onlineStateChanged, m_connectionManager, &ConnectionManager::onOnlineStateChanged);
m_networkConfigurationManager = new QNetworkConfigurationManager();
connect(m_networkConfigurationManager, &QNetworkConfigurationManager::onlineStateChanged, m_connectionManager, &ConnectionManager::onOnlineStateChanged);
QT_WARNING_POP
m_scriptLauncher = new ScriptLauncher(this);
m_scriptLauncher = new ScriptLauncher(this);
// an instance of DccTransferManager needs to be created before GUI class instances' creation.
m_dccTransferManager = new DCC::TransferManager(this);
// an instance of DccTransferManager needs to be created before GUI class instances' creation.
m_dccTransferManager = new DCC::TransferManager(this);
// make sure all vars are initialized properly
quickConnectDialog = nullptr;
// make sure all vars are initialized properly
quickConnectDialog = nullptr;
// Sound object used to play sound is created when needed.
m_sound = nullptr;
// Sound object used to play sound is created when needed.
m_sound = nullptr;
// initialize OSD display here, so we can read the Preferences::properly
m_osd = new OSDWidget(QStringLiteral("Konversation"));
// initialize OSD display here, so we can read the Preferences::properly
m_osd = new OSDWidget(QStringLiteral("Konversation"));
Preferences::self();
readOptions();
Preferences::self();
readOptions();
// Images object providing LEDs, NickIcons
m_images = new Images();
// Images object providing LEDs, NickIcons
m_images = new Images();
m_urlModel = new QStandardItemModel(0, 3, this);
m_urlModel = new QStandardItemModel(0, 3, this);
// Auto-alias scripts. This adds any missing aliases
QStringList aliasList(Preferences::self()->aliasList());
const QStringList scripts(Preferences::defaultAliasList());
bool changed = false;
for (const QString& script : scripts) {
if (!aliasList.contains(script)) {
changed = true;
aliasList.append(script);
}
// Auto-alias scripts. This adds any missing aliases
QStringList aliasList(Preferences::self()->aliasList());
const QStringList scripts(Preferences::defaultAliasList());
bool changed = false;
for (const QString& script : scripts) {
if (!aliasList.contains(script)) {
changed = true;
aliasList.append(script);
}
if(changed)
Preferences::self()->setAliasList(aliasList);
}
if(changed)
Preferences::self()->setAliasList(aliasList);
// open main window
mainWindow = new MainWindow();
// open main window
mainWindow = new MainWindow();
connect(mainWindow.data(), &MainWindow::showQuickConnectDialog, this, &Application::openQuickConnectDialog);
connect(Preferences::self(), &Preferences::updateTrayIcon, mainWindow.data(), &MainWindow::updateTrayIcon);
connect(mainWindow.data(), &MainWindow::endNotification, m_osd, &OSDWidget::hide);
// take care of user style changes, setting back colors and stuff
connect(mainWindow.data(), &MainWindow::showQuickConnectDialog, this, &Application::openQuickConnectDialog);
connect(Preferences::self(), &Preferences::updateTrayIcon, mainWindow.data(), &MainWindow::updateTrayIcon);
connect(mainWindow.data(), &MainWindow::endNotification, m_osd, &OSDWidget::hide);
// take care of user style changes, setting back colors and stuff
// apply GUI settings
Q_EMIT appearanceChanged();
// apply GUI settings
Q_EMIT appearanceChanged();
if (Preferences::self()->showTrayIcon() && Preferences::self()->hideToTrayOnStartup())
mainWindow->hide();
else
mainWindow->show();
if (restoreMode == WindowRestore)
mainWindow->restore();
else if (Preferences::self()->showTrayIcon() && Preferences::self()->hideToTrayOnStartup())
mainWindow->hide();
else
mainWindow->show();
bool openServerList = Preferences::self()->showServerList();
bool openServerList = Preferences::self()->showServerList();
// handle autoconnect on startup
const Konversation::ServerGroupHash serverGroups = Preferences::serverGroupHash();
// handle autoconnect on startup
const Konversation::ServerGroupHash serverGroups = Preferences::serverGroupHash();
if (!args->isSet(QStringLiteral("noautoconnect")) && url.isEmpty() && !args->isSet(QStringLiteral("server")))
{
QList<ServerGroupSettingsPtr> serversToAutoconnect;
for (const auto& server : serverGroups) {
if (server->autoConnectEnabled()) {
openServerList = false;
serversToAutoconnect << server;
}
if (autoConnectMode == AutoConnect)
{
QList<ServerGroupSettingsPtr> serversToAutoconnect;
for (const auto& server : serverGroups) {
if (server->autoConnectEnabled()) {
openServerList = false;
serversToAutoconnect << server;
}
}
std::sort(serversToAutoconnect.begin(), serversToAutoconnect.end(), [] (const ServerGroupSettingsPtr &left, const ServerGroupSettingsPtr &right)
{
return left->sortIndex() < right->sortIndex();
});
std::sort(serversToAutoconnect.begin(), serversToAutoconnect.end(), [] (const ServerGroupSettingsPtr &left, const ServerGroupSettingsPtr &right)
{
return left->sortIndex() < right->sortIndex();
});
for (const auto& server : qAsConst(serversToAutoconnect)) {
m_connectionManager->connectTo(Konversation::CreateNewConnection, server->id());
}
for (const auto& server : qAsConst(serversToAutoconnect)) {
m_connectionManager->connectTo(Konversation::CreateNewConnection, server->id());
}
}
if (openServerList) mainWindow->openServerList();
if (openServerList) mainWindow->openServerList();
connect(this, &Application::serverGroupsChanged, this, &Application::saveOptions);
connect(this, &Application::serverGroupsChanged, this, &Application::saveOptions);
// prepare dbus interface
dbusObject = new Konversation::DBus(this);
QDBusConnection::sessionBus().registerObject(QStringLiteral("/irc"), dbusObject, QDBusConnection::ExportNonScriptableSlots);
identDBus = new Konversation::IdentDBus(this);
QDBusConnection::sessionBus().registerObject(QStringLiteral("/identity"), identDBus, QDBusConnection::ExportNonScriptableSlots);
// prepare dbus interface
dbusObject = new Konversation::DBus(this);
QDBusConnection::sessionBus().registerObject(QStringLiteral("/irc"), dbusObject, QDBusConnection::ExportNonScriptableSlots);
identDBus = new Konversation::IdentDBus(this);
QDBusConnection::sessionBus().registerObject(QStringLiteral("/identity"), identDBus, QDBusConnection::ExportNonScriptableSlots);
if (dbusObject)
{
connect(dbusObject,&DBus::dbusMultiServerRaw,
this,&Application::dbusMultiServerRaw );
connect(dbusObject,&DBus::dbusRaw,
this,&Application::dbusRaw );
connect(dbusObject,&DBus::dbusSay,
this,&Application::dbusSay );
connect(dbusObject,&DBus::dbusInfo,
this,&Application::dbusInfo );
connect(dbusObject,&DBus::dbusInsertMarkerLine,
mainWindow.data(),&MainWindow::insertMarkerLine);
connect(dbusObject, &DBus::connectTo,
m_connectionManager,
QOverload<Konversation::ConnectionFlag, const QString&, const QString&, const QString&, const QString&, const QString&, bool>::of(&ConnectionManager::connectTo));
}
if (dbusObject)
{
connect(dbusObject,&DBus::dbusMultiServerRaw,
this,&Application::dbusMultiServerRaw );
connect(dbusObject,&DBus::dbusRaw,
this,&Application::dbusRaw );
connect(dbusObject,&DBus::dbusSay,
this,&Application::dbusSay );
connect(dbusObject,&DBus::dbusInfo,
this,&Application::dbusInfo );
connect(dbusObject,&DBus::dbusInsertMarkerLine,
mainWindow.data(),&MainWindow::insertMarkerLine);
connect(dbusObject, &DBus::connectTo,
m_connectionManager,
QOverload<Konversation::ConnectionFlag, const QString&, const QString&, const QString&, const QString&, const QString&, bool>::of(&ConnectionManager::connectTo));
}
m_notificationHandler = new Konversation::NotificationHandler(this);
m_notificationHandler = new Konversation::NotificationHandler(this);
connect(this, &Application::appearanceChanged, this, &Application::updateProxySettings);
}
connect(this, &Application::appearanceChanged, this, &Application::updateProxySettings);
void Application::newInstance(QCommandLineParser *args)
{
QString url;
if (!args->positionalArguments().isEmpty())
url = args->positionalArguments().at(0);
if (!mainWindow)
{
const AutoConnectMode autoConnectMode = (!args->isSet(QStringLiteral("noautoconnect")) && url.isEmpty() && !args->isSet(QStringLiteral("server"))) ? AutoConnect : NoAutoConnect;
createMainWindow(autoConnectMode, NoWindowRestore);
}
else if (args->isSet(QStringLiteral("restart")))
{
......@@ -295,6 +303,11 @@ QT_WARNING_POP
return;
}
void Application::restoreInstance()
{
createMainWindow(AutoConnect, WindowRestore);
}
Application* Application::instance()
{
return qobject_cast<Application*>(QApplication::instance());
......
......@@ -122,6 +122,7 @@ class Application : public QApplication
void doInlineAutoreplace(KTextEdit* textEdit) const;
void newInstance(QCommandLineParser *args);
void restoreInstance();
static void openUrl(const QString& url);
......@@ -173,6 +174,9 @@ class Application : public QApplication
private:
void implementRestart();
enum AutoConnectMode { NoAutoConnect, AutoConnect };
enum WindowRestoreMode { NoWindowRestore, WindowRestore };
void createMainWindow(AutoConnectMode autoConnectMode, WindowRestoreMode restoreMode);
private:
ConnectionManager* m_connectionManager;
......
......@@ -139,7 +139,10 @@ int main(int argc, char* argv[])
KDBusService dbusService(startOptions);
app.newInstance(&cmdLineParser);
if (app.isSessionRestored() && KMainWindow::canBeRestored(1))
app.restoreInstance();
else
app.newInstance(&cmdLineParser);
app.setCommandLineParser(&cmdLineParser);
QObject::connect(&dbusService, &KDBusService::activateRequested,
......
......@@ -35,6 +35,7 @@
#include <KStandardAction>
#include <KLocalizedString>
#include <KMessageBox>
#include <KConfigGui>
#include <QSplitter>
#include <QIcon>
......@@ -671,6 +672,23 @@ bool MainWindow::queryClose()
return true;
}
bool MainWindow::restore()
{
// Default restore behavior shows the window based on the flag passed to it
// We need to read the respective session data before calling the method,
// so we can pass it in.
KConfigGroup config(KConfigGui::sessionConfig(), QStringLiteral("1"));
const bool show = !config.readEntry("docked", false);
return KXmlGuiWindow::restore(1, show);
}
void MainWindow::saveProperties(KConfigGroup &config)
{
KXmlGuiWindow::saveProperties(config);
config.writeEntry("docked", isHidden());
}
void MainWindow::hideEvent(QHideEvent *e)
{
Q_EMIT triggerRememberLine();
......
......@@ -44,6 +44,7 @@ class MainWindow : public KXmlGuiWindow
ViewContainer* getViewContainer() const { return m_viewContainer; }
Konversation::TrayIcon* systemTrayIcon() const { return m_trayIcon; }
bool restore();
/** Some errors need to be shown, even when konversation is minimized.
*/
......@@ -82,6 +83,8 @@ class MainWindow : public KXmlGuiWindow
bool queryClose() override;
bool event(QEvent* e) override;
void saveProperties(KConfigGroup &config) override;
private Q_SLOTS:
/** This is connected to the preferences settingsChanged signal and acts to compress
* multiple successively settingsChanged() signals into a single output
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment