Commit 823d2106 authored by Alexander Lohnau's avatar Alexander Lohnau 💬
Browse files

Run clang-format

If you want git blame to ignore formatting revisions run:
git config blame.ignoreRevsFile .git-blame-ignore-revs
parent 69b7aec0
......@@ -23,30 +23,34 @@
#include "../plugin/appmenumodel.h"
#include <QAction>
#include <QDBusConnection>
#include <QDBusConnectionInterface>
#include <QKeyEvent>
#include <QMenu>
#include <QMouseEvent>
#include <QQuickItem>
#include <QDBusConnection>
#include <QDBusConnectionInterface>
#include <QTimer>
#include <QQuickWindow>
#include <QScreen>
#include <QTimer>
int AppMenuApplet::s_refs = 0;
namespace {
QString viewService() { return QStringLiteral("org.kde.kappmenuview"); }
namespace
{
QString viewService()
{
return QStringLiteral("org.kde.kappmenuview");
}
}
AppMenuApplet::AppMenuApplet(QObject *parent, const QVariantList &data)
: Plasma::Applet(parent, data)
{
++s_refs;
//if we're the first, register the service
// if we're the first, register the service
if (s_refs == 1) {
QDBusConnection::sessionBus().interface()->registerService(viewService(),
QDBusConnectionInterface::QueueService,
QDBusConnectionInterface::DontAllowReplacement);
QDBusConnectionInterface::QueueService,
QDBusConnectionInterface::DontAllowReplacement);
}
/*it registers or unregisters the service when the destroyed value of the applet change,
and not in the dtor, because:
......@@ -57,16 +61,16 @@ AppMenuApplet::AppMenuApplet(QObject *parent, const QVariantList &data)
will have to be registered again*/
connect(this, &Applet::destroyedChanged, this, [](bool destroyed) {
if (destroyed) {
//if we were the last, unregister
// if we were the last, unregister
if (--s_refs == 0) {
QDBusConnection::sessionBus().interface()->unregisterService(viewService());
}
} else {
//if we're the first, register the service
// if we're the first, register the service
if (++s_refs == 1) {
QDBusConnection::sessionBus().interface()->registerService(viewService(),
QDBusConnectionInterface::QueueService,
QDBusConnectionInterface::DontAllowReplacement);
QDBusConnectionInterface::QueueService,
QDBusConnectionInterface::DontAllowReplacement);
}
}
});
......@@ -114,7 +118,7 @@ void AppMenuApplet::setCurrentIndex(int currentIndex)
if (m_currentIndex != currentIndex) {
m_currentIndex = currentIndex;
emit currentIndexChanged();
}
}
}
QQuickItem *AppMenuApplet::buttonGrid() const
......@@ -136,20 +140,20 @@ QMenu *AppMenuApplet::createMenu(int idx) const
QAction *action = nullptr;
if (view() == CompactView) {
menu = new QMenu();
for (int i=0; i<m_model->rowCount(); i++) {
const QModelIndex index = m_model->index(i, 0);
const QVariant data = m_model->data(index, AppMenuModel::ActionRole);
action = (QAction *)data.value<void *>();
menu->addAction(action);
}
menu->setAttribute(Qt::WA_DeleteOnClose);
} else if (view() == FullView) {
menu = new QMenu();
for (int i = 0; i < m_model->rowCount(); i++) {
const QModelIndex index = m_model->index(i, 0);
const QVariant data = m_model->data(index, AppMenuModel::ActionRole);
action = (QAction *)data.value<void *>();
menu->addAction(action);
}
menu->setAttribute(Qt::WA_DeleteOnClose);
} else if (view() == FullView) {
const QModelIndex index = m_model->index(idx, 0);
const QVariant data = m_model->data(index, AppMenuModel::ActionRole);
action = (QAction *)data.value<void *>();
if (action) {
menu = action->menu();
menu = action->menu();
}
}
......@@ -173,14 +177,13 @@ void AppMenuApplet::trigger(QQuickItem *ctx, int idx)
QMenu *actionMenu = createMenu(idx);
if (actionMenu) {
//this is a workaround where Qt will fail to realize a mouse has been released
// this is a workaround where Qt will fail to realize a mouse has been released
// this happens if a window which does not accept focus spawns a new window that takes focus and X grab
// whilst the mouse is depressed
// https://bugreports.qt.io/browse/QTBUG-59044
// this causes the next click to go missing
//by releasing manually we avoid that situation
// by releasing manually we avoid that situation
auto ungrabMouseHack = [ctx]() {
if (ctx && ctx->window() && ctx->window()->mouseGrabberItem()) {
// FIXME event forge thing enters press and hold move mode :/
......@@ -189,7 +192,7 @@ void AppMenuApplet::trigger(QQuickItem *ctx, int idx)
};
QTimer::singleShot(0, ctx, ungrabMouseHack);
//end workaround
// end workaround
const auto &geo = ctx->window()->screen()->availableVirtualGeometry();
......@@ -201,13 +204,13 @@ void AppMenuApplet::trigger(QQuickItem *ctx, int idx)
actionMenu->adjustSize();
pos = QPoint(qBound(geo.x(), pos.x(), geo.x() + geo.width() - actionMenu->width()),
qBound(geo.y(), pos.y(), geo.y() + geo.height() - actionMenu->height()));
qBound(geo.y(), pos.y(), geo.y() + geo.height() - actionMenu->height()));
if (view() == FullView) {
actionMenu->installEventFilter(this);
}
actionMenu->winId();//create window handle
actionMenu->winId(); // create window handle
actionMenu->windowHandle()->setTransientParent(ctx->window());
// hide the old menu only after showing the new one to avoid brief focus flickering on X11.
......@@ -221,7 +224,7 @@ void AppMenuApplet::trigger(QQuickItem *ctx, int idx)
QMenu *oldMenu = m_currentMenu;
m_currentMenu = actionMenu;
if (oldMenu && oldMenu != actionMenu) {
//don't initialize the currentIndex when another menu is already shown
// don't initialize the currentIndex when another menu is already shown
disconnect(oldMenu, &QMenu::aboutToHide, this, &AppMenuApplet::onMenuAboutToHide);
oldMenu->hide();
}
......
......@@ -32,7 +32,7 @@ class AppMenuApplet : public Plasma::Applet
{
Q_OBJECT
Q_PROPERTY(AppMenuModel* model READ model WRITE setModel NOTIFY modelChanged)
Q_PROPERTY(AppMenuModel *model READ model WRITE setModel NOTIFY modelChanged)
Q_PROPERTY(int view READ view WRITE setView NOTIFY viewChanged)
......@@ -80,7 +80,6 @@ private:
void setCurrentIndex(int currentIndex);
void onMenuAboutToHide();
int m_currentIndex = -1;
int m_viewType = FullView;
QPointer<QMenu> m_currentMenu;
......
......@@ -24,23 +24,21 @@
#include "appmenumodel.h"
#include <QAction>
#include <QMenu>
#include <QDBusConnection>
#include <QDBusConnectionInterface>
#include <QDBusServiceWatcher>
#include <QGuiApplication>
#include <QMenu>
#include <dbusmenuimporter.h>
#include <abstracttasksmodel.h>
#include <dbusmenuimporter.h>
class KDBusMenuImporter : public DBusMenuImporter
{
public:
KDBusMenuImporter(const QString &service, const QString &path, QObject *parent)
: DBusMenuImporter(service, path, parent)
{
}
protected:
......@@ -48,23 +46,25 @@ protected:
{
return QIcon::fromTheme(name);
}
};
AppMenuModel::AppMenuModel(QObject *parent)
: QAbstractListModel(parent),
m_serviceWatcher(new QDBusServiceWatcher(this)),
m_tasksModel(new TaskManager::TasksModel(this))
: QAbstractListModel(parent)
, m_serviceWatcher(new QDBusServiceWatcher(this))
, m_tasksModel(new TaskManager::TasksModel(this))
{
m_tasksModel->setFilterByScreen(true);
connect(m_tasksModel, &TaskManager::TasksModel::activeTaskChanged, this, &AppMenuModel::onActiveWindowChanged);
connect(m_tasksModel, &TaskManager::TasksModel::dataChanged, [=](const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles = QVector<int>()) {
Q_UNUSED(topLeft)
Q_UNUSED(bottomRight)
if (roles.contains(TaskManager::AbstractTasksModel::ApplicationMenuObjectPath) || roles.contains(TaskManager::AbstractTasksModel::ApplicationMenuServiceName) || roles.isEmpty()) {
onActiveWindowChanged();
}
});
connect(m_tasksModel,
&TaskManager::TasksModel::dataChanged,
[=](const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles = QVector<int>()) {
Q_UNUSED(topLeft)
Q_UNUSED(bottomRight)
if (roles.contains(TaskManager::AbstractTasksModel::ApplicationMenuObjectPath)
|| roles.contains(TaskManager::AbstractTasksModel::ApplicationMenuServiceName) || roles.isEmpty()) {
onActiveWindowChanged();
}
});
connect(m_tasksModel, &TaskManager::TasksModel::activityChanged, this, &AppMenuModel::onActiveWindowChanged);
connect(m_tasksModel, &TaskManager::TasksModel::virtualDesktopChanged, this, &AppMenuModel::onActiveWindowChanged);
connect(m_tasksModel, &TaskManager::TasksModel::countChanged, this, &AppMenuModel::onActiveWindowChanged);
......@@ -80,10 +80,9 @@ AppMenuModel::AppMenuModel(QObject *parent)
onActiveWindowChanged();
m_serviceWatcher->setConnection(QDBusConnection::sessionBus());
//if our current DBus connection gets lost, close the menu
//we'll select the new menu when the focus changes
connect(m_serviceWatcher, &QDBusServiceWatcher::serviceUnregistered, this, [this](const QString &serviceName)
{
// if our current DBus connection gets lost, close the menu
// we'll select the new menu when the focus changes
connect(m_serviceWatcher, &QDBusServiceWatcher::serviceUnregistered, this, [this](const QString &serviceName) {
if (serviceName == m_serviceName) {
setMenuAvailable(false);
emit modelNeedsUpdate();
......@@ -187,7 +186,7 @@ QVariant AppMenuModel::data(const QModelIndex &index, int role) const
if (role == MenuRole) { // TODO this should be Qt::DisplayRole
return actions.at(row)->text();
} else if (role == ActionRole) {
return QVariant::fromValue((void *) actions.at(row));
return QVariant::fromValue((void *)actions.at(row));
}
return QVariant();
......@@ -220,9 +219,9 @@ void AppMenuModel::updateApplicationMenu(const QString &serviceName, const QStri
return;
}
//cache first layer of sub menus, which we'll be popping up
const auto actions = m_menu->actions();
for(QAction *a: actions) {
// cache first layer of sub menus, which we'll be popping up
const auto actions = m_menu->actions();
for (QAction *a : actions) {
// signal dataChanged when the action changes
connect(a, &QAction::changed, this, [this, a] {
if (m_menuAvailable && m_menu) {
......
......@@ -22,11 +22,11 @@
#ifndef APPMENUMODEL_H
#define APPMENUMODEL_H
#include <QAbstractListModel>
#include <QStringList>
#include <KWindowSystem>
#include <QAbstractListModel>
#include <QPointer>
#include <QRect>
#include <QStringList>
#include <tasksmodel.h>
class QMenu;
......@@ -48,7 +48,7 @@ public:
~AppMenuModel() override;
enum AppMenuRole {
MenuRole = Qt::UserRole+1, // TODO this should be Qt::DisplayRole
MenuRole = Qt::UserRole + 1, // TODO this should be Qt::DisplayRole
ActionRole,
};
......@@ -85,7 +85,7 @@ private:
bool m_updatePending = false;
bool m_visible = true;
TaskManager::TasksModel* m_tasksModel;
TaskManager::TasksModel *m_tasksModel;
//! current active window used
WId m_currentWindowId = 0;
......
......@@ -23,7 +23,6 @@
#include "appmenumodel.h"
#include <QQmlEngine>
void AppmenuPlugin::registerTypes(const char *uri)
{
Q_ASSERT(uri == QLatin1String("org.kde.plasma.private.appmenu"));
......
......@@ -34,4 +34,3 @@ public:
};
#endif
......@@ -26,7 +26,6 @@
CalendarApplet::CalendarApplet(QObject *parent, const QVariantList &data)
: Plasma::Applet(parent, data)
{
}
CalendarApplet::~CalendarApplet()
......
......@@ -34,5 +34,4 @@ public:
~CalendarApplet() override;
Q_INVOKABLE int weekNumber(const QDateTime &dateTime) const;
};
......@@ -27,9 +27,9 @@
#include <QMenu>
#include <QRegularExpression>
ClipboardMenu::ClipboardMenu(QObject *parent) : QObject(parent)
ClipboardMenu::ClipboardMenu(QObject *parent)
: QObject(parent)
{
}
ClipboardMenu::~ClipboardMenu() = default;
......@@ -64,19 +64,19 @@ void ClipboardMenu::setupMenu(QAction *action)
{
QMenu *menu = new QMenu;
/*
* The refresh rate of m_currentDate depends of what is shown in the plasmoid.
* If only minutes are shown, the value is updated at the full minute and
* seconds are always 0 or 59 and thus useless/confusing to offer for copy.
* Use a reference to the config's showSeconds to decide if seconds are sent
* to the clipboard. There was no workaround found ...
*/
/*
* The refresh rate of m_currentDate depends of what is shown in the plasmoid.
* If only minutes are shown, the value is updated at the full minute and
* seconds are always 0 or 59 and thus useless/confusing to offer for copy.
* Use a reference to the config's showSeconds to decide if seconds are sent
* to the clipboard. There was no workaround found ...
*/
connect(menu, &QMenu::aboutToShow, this, [this, menu] {
menu->clear();
const QDate date = m_currentDate.date();
const QTime time = m_currentDate.time();
const QRegularExpression rx ("[^0-9:]");
const QRegularExpression rx("[^0-9:]");
const QChar ws = QLatin1Char(' ');
QString s;
QAction *a;
......@@ -130,7 +130,7 @@ void ClipboardMenu::setupMenu(QAction *action)
a = menu->addAction(s);
a->setData(s);
}
s = date.toString(Qt::SystemLocaleLongDate) + ws + time.toString(Qt::SystemLocaleShortDate);
s = date.toString(Qt::SystemLocaleLongDate) + ws + time.toString(Qt::SystemLocaleShortDate);
a = menu->addAction(s);
a->setData(s);
......@@ -138,11 +138,11 @@ void ClipboardMenu::setupMenu(QAction *action)
QMenu *otherCalendarsMenu = menu->addMenu(i18n("Other Calendars"));
/* Add ICU Calendars if QLocale is ready for
Chinese, Coptic, Ethiopic, (Gregorian), Hebrew, Indian, Islamic, Persian
/* Add ICU Calendars if QLocale is ready for
Chinese, Coptic, Ethiopic, (Gregorian), Hebrew, Indian, Islamic, Persian
otherCalendarsMenu->addSeparator();
*/
otherCalendarsMenu->addSeparator();
*/
s = QString::number(m_currentDate.toMSecsSinceEpoch() / 1000);
a = otherCalendarsMenu->addAction(i18nc("unix timestamp (seconds since 1.1.1970)", "%1 (UNIX Time)", s));
a->setData(s);
......
......@@ -50,7 +50,6 @@ signals:
void currentDateChanged();
void secondsIncludedChanged();
private:
QDateTime m_currentDate;
bool m_secondsIncluded = false;
......
......@@ -16,7 +16,6 @@
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef DIGITALCLOCKPLUGIN_H
#define DIGITALCLOCKPLUGIN_H
......
......@@ -24,7 +24,6 @@
class TimeZoneData
{
public:
QString id;
QString region;
......@@ -33,7 +32,6 @@ public:
bool checked;
bool isLocalTimeZone;
int offsetFromUtc;
};
#endif // TIMEZONEDATA_H
......@@ -21,9 +21,9 @@
#include "timezonemodel.h"
#include "timezonesi18n.h"
#include <QTimeZone>
#include <QStringMatcher>
#include <KLocalizedString>
#include <QStringMatcher>
#include <QTimeZone>
TimeZoneFilterProxy::TimeZoneFilterProxy(QObject *parent)
: QSortFilterProxyModel(parent)
......@@ -46,8 +46,7 @@ bool TimeZoneFilterProxy::filterAcceptsRow(int source_row, const QModelIndex &so
const QString region = sourceModel()->index(source_row, 0, source_parent).data(TimeZoneModel::RegionRole).toString();
const QString comment = sourceModel()->index(source_row, 0, source_parent).data(TimeZoneModel::CommentRole).toString();
if (m_stringMatcher.indexIn(city) != -1 || m_stringMatcher.indexIn(region) != -1 ||
m_stringMatcher.indexIn(comment) != -1) {
if (m_stringMatcher.indexIn(city) != -1 || m_stringMatcher.indexIn(region) != -1 || m_stringMatcher.indexIn(comment) != -1) {
return true;
}
......@@ -74,8 +73,8 @@ void TimeZoneFilterProxy::setOnlyShowChecked(const bool show)
//=============================================================================
TimeZoneModel::TimeZoneModel(QObject *parent)
: QAbstractListModel(parent),
m_timezonesI18n(new TimezonesI18n(this))
: QAbstractListModel(parent)
, m_timezonesI18n(new TimezonesI18n(this))
{
update();
}
......@@ -95,7 +94,7 @@ QVariant TimeZoneModel::data(const QModelIndex &index, int role) const
if (index.isValid()) {
TimeZoneData currentData = m_data.at(index.row());
switch(role) {
switch (role) {
case TimeZoneIdRole:
return currentData.id;
case RegionRole:
......@@ -169,9 +168,7 @@ void TimeZoneModel::update()
const QStringList splitted = QString::fromUtf8(zone.id()).split(QStringLiteral("/"));
// CITY | COUNTRY | CONTINENT
const QString key = QStringLiteral("%1|%2|%3").arg(splitted.last(),
QLocale::countryToString(zone.country()),
splitted.first());
const QString key = QStringLiteral("%1|%2|%3").arg(splitted.last(), QLocale::countryToString(zone.country()), splitted.first());
cities.append(key);
zonesByCity.insert(key, zone);
......@@ -191,8 +188,9 @@ void TimeZoneModel::update()
TimeZoneData newData;
newData.isLocalTimeZone = false;
newData.id = timeZone.id();
newData.region = timeZone.country() == QLocale::AnyCountry ? QString()
: m_timezonesI18n->i18nContinents(cityCountryContinent.at(2)) + QLatin1Char('/') + m_timezonesI18n->i18nCountry(timeZone.country());
newData.region = timeZone.country() == QLocale::AnyCountry
? QString()
: m_timezonesI18n->i18nContinents(cityCountryContinent.at(2)) + QLatin1Char('/') + m_timezonesI18n->i18nCountry(timeZone.country());
newData.city = m_timezonesI18n->i18nCity(cityCountryContinent.at(0));
newData.comment = comment;
newData.checked = false;
......@@ -244,8 +242,7 @@ QHash<int, QByteArray> TimeZoneModel::roleNames() const
void TimeZoneModel::sortTimeZones()
{
std::sort(m_selectedTimeZones.begin(), m_selectedTimeZones.end(),
[this](const QString &a, const QString &b) {
return m_offsetData.value(a) < m_offsetData.value(b);
});
std::sort(m_selectedTimeZones.begin(), m_selectedTimeZones.end(), [this](const QString &a, const QString &b) {
return m_offsetData.value(a) < m_offsetData.value(b);
});
}
......@@ -22,9 +22,9 @@
#ifndef TIMEZONESI18N_H
#define TIMEZONESI18N_H
#include <QObject>
#include <QHash>
#include <QLocale>
#include <QObject>
class TimezonesI18n : public QObject
{
......
......@@ -58,7 +58,6 @@
IconApplet::IconApplet(QObject *parent, const QVariantList &data)
: Plasma::Applet(parent, data)
{
}
IconApplet::~IconApplet()
......@@ -240,7 +239,7 @@ void IconApplet::populate()
if (downloadFavIcon) {
KIO::FavIconRequestJob *job = new KIO::FavIconRequestJob(m_url);
connect(job, &KIO::FavIconRequestJob::result, this, [job, backingDesktopFile, this](KJob *){
connect(job, &KIO::FavIconRequestJob::result, this, [job, backingDesktopFile, this](KJob *) {
if (!job->error()) {
KDesktopFile(backingDesktopFile).desktopGroup().writeEntry(QStringLiteral("Icon"), job->iconFile());
......@@ -394,7 +393,7 @@ QList<QAction *> IconApplet::contextualActions()
if (!m_openContainingFolderAction) {
if (KProtocolManager::supportsListing(linkUrl)) {
m_openContainingFolderAction = new QAction(QIcon::fromTheme(QStringLiteral("document-open-folder")), i18n("Open Containing Folder"), this);
connect(m_openContainingFolderAction, &QAction::triggered, this, [ linkUrl] {
connect(m_openContainingFolderAction, &QAction::triggered, this, [linkUrl] {
KIO::highlightInFileManager({linkUrl});
});
}
......@@ -432,7 +431,7 @@ void IconApplet::run()
connect(m_startupTasksModel, &QAbstractItemModel::rowsAboutToBeRemoved, this, std::bind(handleRow, false /*busy*/, _1, _2, _3));
}
KIO::OpenUrlJob* job = new KIO::OpenUrlJob(QUrl::fromLocalFile(m_localPath));
KIO::OpenUrlJob *job = new KIO::OpenUrlJob(QUrl::fromLocalFile(m_localPath));
job->setRunExecutables(true); // so it can launch apps
job->setUiDelegate(new KNotificationJobUiDelegate(KJobUiDelegate::AutoHandlingEnabled));
job->start();
......@@ -455,7 +454,7 @@ void IconApplet::processDrop(QObject *dropEvent)
auto service = new KService(localPath);
if (service->isApplication()) {
KIO::ApplicationLauncherJob* job = new KIO::ApplicationLauncherJob(KService::Ptr(service));
KIO::ApplicationLauncherJob *job = new KIO::ApplicationLauncherJob(KService::Ptr(service));
job->setUrls(urls);
job->setUiDelegate(new KNotificationJobUiDelegate(KJobUiDelegate::AutoHandlingEnabled));
job->start();
......@@ -539,8 +538,7 @@ QList<QUrl> IconApplet::urlsFromDrop(QObject *dropEvent)
bool IconApplet::isExecutable(const QMimeType &mimeType)
{
return (mimeType.inherits(QStringLiteral("application/x-executable"))
|| mimeType.inherits(QStringLiteral("application/x-shellscript")));
return (mimeType.inherits(QStringLiteral("application/x-executable")) || mimeType.inherits(QStringLiteral("application/x-shellscript")));
}
void IconApplet::configure()
......
......@@ -107,5 +107,4 @@ private:
QPointer<KPropertiesDialog> m_configDialog;
TaskManager::StartupTasksModel *m_startupTasksModel = nullptr;
};
......@@ -22,7 +22,7 @@
#include <QDebug>
AbstractEntry::AbstractEntry(AbstractModel *owner)
: m_owner(owner)
: m_owner(owner)
{
}
......@@ -50,7 +50,6 @@ QString AbstractEntry::name() const
return QString();
}
QString AbstractEntry::group() const
{
return QString();
......@@ -91,7 +90,7 @@ QVariantList AbstractEntry::actions() const
return QVariantList();
}
bool AbstractEntry::run(const QString& actionId, const QVariant &argument)
bool AbstractEntry::run(const QString &actionId, const QVariant &argument)
{
Q_UNUSED(actionId)
Q_UNUSED(argument)
......@@ -99,10 +98,12 @@ bool AbstractEntry::run(const QString& actionId, const QVariant &argument)
return false;
}