Commit f7e8fad1 authored by David Jarvie's avatar David Jarvie
Browse files

Provide global function to get parent window for dialogues

parent ec0f679a
......@@ -70,20 +70,28 @@
#include <iostream>
#include <climits>
static const int RESOURCES_TIMEOUT = 30; // timeout (seconds) for resources to be populated
namespace
{
const int RESOURCES_TIMEOUT = 30; // timeout (seconds) for resources to be populated
/******************************************************************************
* Find the maximum number of seconds late which a late-cancel alarm is allowed
* to be. This is calculated as the late cancel interval, plus a few seconds
* leeway to cater for any timing irregularities.
*/
static inline int maxLateness(int lateCancel)
inline int maxLateness(int lateCancel)
{
static const int LATENESS_LEEWAY = 5;
int lc = (lateCancel >= 1) ? (lateCancel - 1)*60 : 0;
return LATENESS_LEEWAY + lc;
}
QWidget* mainWidget()
{
return MainWindow::mainMainWindow();
}
}
KAlarmApp* KAlarmApp::mInstance = nullptr;
int KAlarmApp::mActiveCount = 0;
......@@ -219,6 +227,7 @@ bool KAlarmApp::initialiseTimerResources()
if (!ResourcesCalendar::instance())
{
qCDebug(KALARM_LOG) << "KAlarmApp::initialise: initialising calendars";
Desktop::setMainWindowFunc(&mainWidget);
DataModel::initialise();
ResourcesCalendar::initialise();
DisplayCalendar::initialise();
......@@ -307,10 +316,10 @@ bool KAlarmApp::restoreSession()
}
--mActiveCount;
if (quitIf(0)) // quit if no windows are open
return false; // quitIf() can sometimes return, despite calling exit()
if (quitIf(0)) // quit if no windows are open
return false; // quitIf() can sometimes return, despite calling exit()
startProcessQueue(); // start processing the execution queue
startProcessQueue(); // start processing the execution queue
return true;
}
......
/*
* desktop.cpp - desktop functions
* Program: kalarm
* Copyright © 2008-2019 David Jarvie <djarvie@kde.org>
* Copyright © 2008-2020 David Jarvie <djarvie@kde.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......@@ -32,6 +32,8 @@
namespace Desktop
{
QWidget* (*mMainWindowFunc)() {nullptr};
/******************************************************************************
* Find the identity of the desktop we are running on.
*/
......@@ -67,6 +69,19 @@ QRect workArea(int screen)
return screens[screen]->availableGeometry();
}
/******************************************************************************
* Return the top level application window, for use as parent for dialogues etc.
*/
QWidget* mainWindow()
{
return (*mMainWindowFunc)();
}
void setMainWindowFunc(QWidget* (*func)())
{
mMainWindowFunc = func;
}
} // namespace Desktop
// vim: et sw=4:
/*
* desktop.h - desktop functions
* Program: kalarm
* Copyright © 2008-2019 by David Jarvie <djarvie@kde.org>
* Copyright © 2008-2020 David Jarvie <djarvie@kde.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......@@ -22,6 +22,7 @@
#define DESKTOP_H
#include <QRect>
class QWidget;
namespace Desktop
{
......@@ -39,6 +40,12 @@ QString currentIdentityName();
QRect workArea(int screen = -1);
/** Return the top level application window, for use as parent for dialogues etc. */
QWidget* mainWindow();
/** Set the function to return the parent window for prompt and information messages. */
void setMainWindowFunc(QWidget* (*func)());
} // namespace Desktop
#endif // DESKTOP_H
......
......@@ -64,7 +64,7 @@ static_assert((int)ResourceDataModelBase::UserRole>=(int)Akonadi::EntityTreeMode
=============================================================================*/
AkonadiDataModel* AkonadiDataModel::mInstance = nullptr;
int AkonadiDataModel::mTimeHourPos = -2;
int AkonadiDataModel::mTimeHourPos = -2;
/******************************************************************************
* Construct and return the singleton.
......
......@@ -22,7 +22,6 @@
#include "kalarmsettings.h"
#include "kalarmdirsettings.h"
#include "mainwindow.h"
#include "resources/akonadidatamodel.h"
#include "resources/akonadiresource.h"
#include "resources/akonadicalendarupdater.h"
......
......@@ -20,7 +20,7 @@
#include "calendarupdater.h"
#include "mainwindow.h"
#include "lib/desktop.h"
#include <KLocalizedString>
......@@ -39,7 +39,7 @@ CalendarUpdater::CalendarUpdater(ResourceId resourceId, bool ignoreKeepFormat, Q
: QObject(parent)
, mResourceId(resourceId)
, mParent(parent)
, mPromptParent(promptParent ? promptParent : MainWindow::mainMainWindow())
, mPromptParent(promptParent ? promptParent : Desktop::mainWindow())
, mIgnoreKeepFormat(ignoreKeepFormat)
, mDuplicate(containsResource(resourceId))
{
......
......@@ -22,8 +22,8 @@
#include "resources.h"
#include "mainwindow.h"
#include "preferences.h"
#include "lib/desktop.h"
#include "lib/messagebox.h"
#include "kalarm_debug.h"
......@@ -615,14 +615,14 @@ void ResourceDataModelBase::handleResourceMessage(ResourceType::MessageType type
if (type == ResourceType::MessageType::Error)
{
qCDebug(KALARM_LOG) << "Resource Error!" << message << details;
KAMessageBox::detailedError(MainWindow::mainMainWindow(), message, details);
KAMessageBox::detailedError(Desktop::mainWindow(), message, details);
}
else if (type == ResourceType::MessageType::Info)
{
qCDebug(KALARM_LOG) << "Resource user message:" << message << details;
// KMessageBox::informationList looks bad, so use our own formatting.
const QString msg = details.isEmpty() ? message : message + QStringLiteral("\n\n") + details;
KAMessageBox::information(MainWindow::mainMainWindow(), msg);
KAMessageBox::information(Desktop::mainWindow(), msg);
}
}
......
......@@ -25,7 +25,6 @@
#include "resourcemodel.h"
#include "resourceselectdialog.h"
#include "mainwindow.h"
#include "preferences.h"
#include "lib/autoqpointer.h"
#include "lib/messagebox.h"
......
Markdown is supported
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