Cherry-picking upstream version 0.12.0.

ubuntu/bionic
Alf Gaida 7 years ago
parent 3709bb882d
commit e6892a6c73

@ -3,7 +3,7 @@ Upstream Authors:
Hong Jen Yee (PCMan) <pcman.tw@gmail.com> Hong Jen Yee (PCMan) <pcman.tw@gmail.com>
Copyright: Copyright:
Copyright (c) 2013-2016 LXQt team Copyright (c) 2013-2017 LXQt team
License: LGPL-2.1+ License: LGPL-2.1+
The full text of the licenses can be found in the 'COPYING' file. The full text of the licenses can be found in the 'COPYING' file.

@ -1,7 +1,36 @@
lxqt-qtplugin-0.11.1 / 2016-12-11 lxqt-qtplugin-0.12.0 / 2017-10-21
================================= =================================
* Set an informal patch version
* Don't export github templates
* Flag unused vars in onServiceOwnerChanged
* Fix missing variable declaration
* Handle QML (as @PCMan suggested)
* Use mime functions added by @PCMan
* Loading and saving window/splitter size
* Central positioning with respect to parent
* Set window title correctly
* Qt version conditions
* Just made it compilable
* Handle mime-type filters for file dialog. Set custom file dialog labels.
* Update options properly.
* Implement a basic file dialog helper using libfm-qt's Fm::FileDialog.
* Avoid using Qt-specific keywords such as signal/slot and foreach. Instead, use macros.
* LXQtPlatformTheme: Make Qt use default palette (#22)
* LXQtPlatformTheme: Add icon FollowColorScheme config (#21)
* Prevent a possible C++11 range for detach (#20)
* Use the CMake MODULE library type.
* LXQtPlatformTheme: Propagate wheelScrollLines
* LXQtPlatformTheme: Do not provide own palette
* Fix multiple StatusNotifierItems.
* Bump year
* Updates lxqt-build-tools required version
0.11.1 / 2016-12-11
===================
* Release 0.11.1: Update changelog
* Use lxqt-build-tools * Use lxqt-build-tools
* Use the new lxqt-build-tools package * Use the new lxqt-build-tools package
* Remove cpack (#14) * Remove cpack (#14)

@ -3,18 +3,24 @@ project(lxqt-qtplugin)
include(GNUInstallDirs) include(GNUInstallDirs)
set(LXQTBT_MINIMUM_VERSION "0.1.0") set(LXQTBT_MINIMUM_VERSION "0.4.0")
set(CMAKE_AUTOMOC ON) set(CMAKE_AUTOMOC ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON) set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_POSITION_INDEPENDENT_CODE ON) set(CMAKE_POSITION_INDEPENDENT_CODE ON)
find_package(Qt5Widgets REQUIRED QUIET) find_package(Qt5Widgets REQUIRED)
find_package(Qt5LinguistTools REQUIRED QUIET) find_package(Qt5LinguistTools REQUIRED)
find_package(Qt5DBus REQUIRED QUIET) find_package(Qt5DBus REQUIRED)
find_package(dbusmenu-qt5 REQUIRED QUIET) find_package(dbusmenu-qt5 REQUIRED)
find_package(lxqt-build-tools ${LXQTBT_MINIMUM_VERSION} REQUIRED) find_package(lxqt-build-tools ${LXQTBT_MINIMUM_VERSION} REQUIRED)
find_package(Qt5XdgIconLoader REQUIRED QUIET) find_package(Qt5XdgIconLoader REQUIRED)
# Patch Version 0
# for file dialog support
find_package(Qt5X11Extras REQUIRED)
find_package(fm-qt REQUIRED)
include(LXQtCompilerSettings NO_POLICY_SCOPE) include(LXQtCompilerSettings NO_POLICY_SCOPE)

@ -6,6 +6,7 @@ include_directories(
set(qtlxqt_HDRS set(qtlxqt_HDRS
lxqtplatformtheme.h lxqtplatformtheme.h
lxqtsystemtrayicon.h lxqtsystemtrayicon.h
lxqtfiledialoghelper.h
statusnotifieritem/statusnotifieritem.h statusnotifieritem/statusnotifieritem.h
statusnotifieritem/dbustypes.h statusnotifieritem/dbustypes.h
) )
@ -14,6 +15,7 @@ set(qtlxqt_SRCS
main.cpp main.cpp
lxqtplatformtheme.cpp lxqtplatformtheme.cpp
lxqtsystemtrayicon.cpp lxqtsystemtrayicon.cpp
lxqtfiledialoghelper.cpp
statusnotifieritem/statusnotifieritem.cpp statusnotifieritem/statusnotifieritem.cpp
statusnotifieritem/dbustypes.cpp statusnotifieritem/dbustypes.cpp
) )
@ -24,15 +26,17 @@ qt5_add_dbus_adaptor(qtlxqt_SRCS
StatusNotifierItem StatusNotifierItem
) )
add_library(qtlxqt SHARED ${qtlxqt_HDRS} ${qtlxqt_SRCS}) add_library(qtlxqt MODULE ${qtlxqt_HDRS} ${qtlxqt_SRCS})
target_link_libraries(qtlxqt target_link_libraries(qtlxqt
Qt5::Widgets Qt5::Widgets
Qt5::DBus Qt5::DBus
dbusmenu-qt5 dbusmenu-qt5
Qt5XdgIconLoader Qt5XdgIconLoader
fm-qt
) )
# there is no standard way to get the plugin dir of Qt5 with cmake # there is no standard way to get the plugin dir of Qt5 with cmake
# The best way is get_target_property(QT_PLUGINS_DIR Qt5::QGtk2ThemePlugin LOCATION). # The best way is get_target_property(QT_PLUGINS_DIR Qt5::QGtk2ThemePlugin LOCATION).
# This directly returns the platformthemes dir. However, this does not work # This directly returns the platformthemes dir. However, this does not work

@ -0,0 +1,224 @@
#include "lxqtfiledialoghelper.h"
#include <libfm-qt/libfmqt.h>
#include <libfm-qt/filedialog.h>
#include <QWindow>
#include <QDebug>
#include <QTimer>
#include <QSettings>
#include <memory>
static std::unique_ptr<Fm::LibFmQt> libfmQtContext_;
LXQtFileDialogHelper::LXQtFileDialogHelper() {
if(!libfmQtContext_) {
// initialize libfm-qt only once
libfmQtContext_ = std::unique_ptr<Fm::LibFmQt>{new Fm::LibFmQt()};
}
// can only be used after libfm-qt initialization
dlg_ = std::unique_ptr<Fm::FileDialog>(new Fm::FileDialog());
connect(dlg_.get(), &Fm::FileDialog::accepted, [this]() {
saveSettings();
accept();
});
connect(dlg_.get(), &Fm::FileDialog::rejected, [this]() {
saveSettings();
reject();
});
connect(dlg_.get(), &Fm::FileDialog::fileSelected, this, &LXQtFileDialogHelper::fileSelected);
connect(dlg_.get(), &Fm::FileDialog::filesSelected, this, &LXQtFileDialogHelper::filesSelected);
connect(dlg_.get(), &Fm::FileDialog::currentChanged, this, &LXQtFileDialogHelper::currentChanged);
connect(dlg_.get(), &Fm::FileDialog::directoryEntered, this, &LXQtFileDialogHelper::directoryEntered);
connect(dlg_.get(), &Fm::FileDialog::filterSelected, this, &LXQtFileDialogHelper::filterSelected);
}
LXQtFileDialogHelper::~LXQtFileDialogHelper() {
}
void LXQtFileDialogHelper::exec() {
dlg_->exec();
}
bool LXQtFileDialogHelper::show(Qt::WindowFlags windowFlags, Qt::WindowModality windowModality, QWindow* parent) {
dlg_->setAttribute(Qt::WA_NativeWindow, true); // without this, sometimes windowHandle() will return nullptr
dlg_->setWindowFlags(windowFlags);
dlg_->setWindowModality(windowModality);
// Reference: KDE implementation
// https://github.com/KDE/plasma-integration/blob/master/src/platformtheme/kdeplatformfiledialoghelper.cpp
dlg_->windowHandle()->setTransientParent(parent);
loadSettings();
// central positioning with respect to the parent window
if(parent && parent->isVisible()) {
dlg_->move(parent->x() + (parent->width() - dlg_->width()) / 2,
parent->y() + (parent->height() - dlg_->height()) / 2);
}
applyOptions();
// NOTE: the timer here is required as a workaround borrowed from KDE. Without this, the dialog UI will be blocked.
// QFileDialog calls our platform plugin to show our own native file dialog instead of showing its widget.
// However, it still creates a hidden dialog internally, and then make it modal.
// So user input from all other windows that are not the children of the QFileDialog widget will be blocked.
// This includes our own dialog. After the return of this show() method, QFileDialog creates its own window and
// then make it modal, which blocks our UI. The timer schedule a delayed popup of our file dialog, so we can
// show again after QFileDialog and override the modal state. Then our UI can be unblocked.
QTimer::singleShot(0, dlg_.get(), &QDialog::show);
dlg_->setFocus();
return true;
}
void LXQtFileDialogHelper::hide() {
dlg_->hide();
}
bool LXQtFileDialogHelper::defaultNameFilterDisables() const {
return false;
}
void LXQtFileDialogHelper::setDirectory(const QUrl& directory) {
dlg_->setDirectory(directory);
}
QUrl LXQtFileDialogHelper::directory() const {
return dlg_->directory();
}
void LXQtFileDialogHelper::selectFile(const QUrl& filename) {
dlg_->selectFile(filename);
}
QList<QUrl> LXQtFileDialogHelper::selectedFiles() const {
return dlg_->selectedFiles();
}
void LXQtFileDialogHelper::setFilter() {
// FIXME: what's this?
// The gtk+ 3 file dialog helper in Qt5 update options in this method.
applyOptions();
}
void LXQtFileDialogHelper::selectNameFilter(const QString& filter) {
dlg_->selectNameFilter(filter);
}
#if QT_VERSION >= QT_VERSION_CHECK(5, 9, 0)
QString LXQtFileDialogHelper::selectedMimeTypeFilter() const {
return dlg_->selectedMimeTypeFilter();
}
void LXQtFileDialogHelper::selectMimeTypeFilter(const QString& filter) {
dlg_->selectMimeTypeFilter(filter);
}
#endif
QString LXQtFileDialogHelper::selectedNameFilter() const {
return dlg_->selectedNameFilter();
}
bool LXQtFileDialogHelper::isSupportedUrl(const QUrl& url) const {
return dlg_->isSupportedUrl(url);
}
void LXQtFileDialogHelper::applyOptions() {
auto& opt = options();
// set title
if(opt->windowTitle().isEmpty()) {
dlg_->setWindowTitle(opt->acceptMode() == QFileDialogOptions::AcceptOpen ? tr("Open File")
: tr("Save File"));
}
else {
dlg_->setWindowTitle(opt->windowTitle());
}
dlg_->setFilter(opt->filter());
dlg_->setViewMode(opt->viewMode() == QFileDialogOptions::Detail ? Fm::FolderView::DetailedListMode
: Fm::FolderView::CompactMode);
dlg_->setFileMode(QFileDialog::FileMode(opt->fileMode()));
dlg_->setAcceptMode(QFileDialog::AcceptMode(opt->acceptMode())); // also sets a default label for accept button
// bool useDefaultNameFilters() const;
dlg_->setNameFilters(opt->nameFilters());
if(!opt->mimeTypeFilters().empty()) {
dlg_->setMimeTypeFilters(opt->mimeTypeFilters());
}
dlg_->setDefaultSuffix(opt->defaultSuffix());
// QStringList history() const;
// explicitly set labels
for(int i = 0; i < QFileDialogOptions::DialogLabelCount; ++i) {
auto label = static_cast<QFileDialogOptions::DialogLabel>(i);
if(opt->isLabelExplicitlySet(label)) {
dlg_->setLabelText(static_cast<QFileDialog::DialogLabel>(label), opt->labelText(label));
}
}
auto url = opt->initialDirectory();
if(url.isValid()) {
dlg_->setDirectory(url);
}
#if QT_VERSION >= QT_VERSION_CHECK(5, 9, 0)
auto filter = opt->initiallySelectedMimeTypeFilter();
if(!filter.isEmpty()) {
selectMimeTypeFilter(filter);
}
else {
filter = opt->initiallySelectedNameFilter();
if(!filter.isEmpty()) {
selectNameFilter(opt->initiallySelectedNameFilter());
}
}
#else
auto filter = opt->initiallySelectedNameFilter();
if(!filter.isEmpty()) {
selectNameFilter(filter);
}
#endif
auto selectedFiles = opt->initiallySelectedFiles();
for(const auto& selectedFile: selectedFiles) {
selectFile(selectedFile);
}
// QStringList supportedSchemes() const;
}
void LXQtFileDialogHelper::loadSettings() {
QSettings settings(QSettings::UserScope, "lxqt", "filedialog");
settings.beginGroup ("Sizes");
dlg_->resize(settings.value("WindowSize", QSize(700, 500)).toSize());
dlg_->setSplitterPos(settings.value("SplitterPos", 200).toInt());
settings.endGroup();
}
void LXQtFileDialogHelper::saveSettings() {
QSettings settings(QSettings::UserScope, "lxqt", "filedialog");
settings.beginGroup ("Sizes");
QSize windowSize = dlg_->size();
if(settings.value("WindowSize") != windowSize) { // no redundant write
settings.setValue("WindowSize", windowSize);
}
int splitterPos = dlg_->splitterPos();
if(settings.value("SplitterPos") != splitterPos) {
settings.setValue("SplitterPos", splitterPos);
}
settings.endGroup();
}
/*
FileDialogPlugin::FileDialogPlugin() {
}
QPlatformFileDialogHelper *FileDialogPlugin::createHelper() {
return new LXQtFileDialogHelper();
}
*/

@ -0,0 +1,50 @@
#ifndef LXQTFILEDIALOGHELPER_H
#define LXQTFILEDIALOGHELPER_H
#include <qpa/qplatformdialoghelper.h> // this private header is subject to changes
#include <memory>
namespace Fm {
class FileDialog;
}
class Q_GUI_EXPORT LXQtFileDialogHelper : public QPlatformFileDialogHelper {
Q_OBJECT
public:
LXQtFileDialogHelper();
virtual ~LXQtFileDialogHelper();
// QPlatformDialogHelper
void exec() override;
bool show(Qt::WindowFlags windowFlags, Qt::WindowModality windowModality, QWindow *parent) override;
void hide() override;
// QPlatformFileDialogHelper
bool defaultNameFilterDisables() const override;
void setDirectory(const QUrl &directory) override;
QUrl directory() const override;
void selectFile(const QUrl &filename) override;
QList<QUrl> selectedFiles() const override;
void setFilter() override;
void selectNameFilter(const QString &filter) override;
#if QT_VERSION >= QT_VERSION_CHECK(5, 9, 0)
QString selectedMimeTypeFilter() const override;
void selectMimeTypeFilter(const QString &filter) override;
#endif
QString selectedNameFilter() const override;
bool isSupportedUrl(const QUrl &url) const override;
private:
void applyOptions();
void loadSettings();
void saveSettings();
private:
std::unique_ptr<Fm::FileDialog> dlg_;
};
#endif // LXQTFILEDIALOGHELPER_H

@ -46,8 +46,11 @@
#include <QStyle> #include <QStyle>
#include <private/xdgiconloader/xdgiconloader_p.h> #include <private/xdgiconloader/xdgiconloader_p.h>
#include "lxqtfiledialoghelper.h"
LXQtPlatformTheme::LXQtPlatformTheme(): LXQtPlatformTheme::LXQtPlatformTheme():
settingsWatcher_(NULL) iconFollowColorScheme_(true)
, settingsWatcher_(NULL)
{ {
// When the plugin is loaded, it seems that the app is not yet running and // When the plugin is loaded, it seems that the app is not yet running and
// QThread environment is not completely set up. So creating filesystem watcher // QThread environment is not completely set up. So creating filesystem watcher
@ -80,6 +83,7 @@ void LXQtPlatformTheme::loadSettings() {
// icon theme // icon theme
iconTheme_ = settings.value("icon_theme", "oxygen").toString(); iconTheme_ = settings.value("icon_theme", "oxygen").toString();
iconFollowColorScheme_ = settings.value("icon_follow_color_scheme", iconFollowColorScheme_).toBool();
// read other widget related settings form LxQt settings. // read other widget related settings form LxQt settings.
QByteArray tb_style = settings.value("tool_button_style").toByteArray(); QByteArray tb_style = settings.value("tool_button_style").toByteArray();
@ -164,6 +168,7 @@ void LXQtPlatformTheme::onSettingsChanged() {
if(iconTheme_ != oldIconTheme) { // the icon theme is changed if(iconTheme_ != oldIconTheme) { // the icon theme is changed
XdgIconLoader::instance()->updateSystemTheme(); // this is a private internal API of Qt5. XdgIconLoader::instance()->updateSystemTheme(); // this is a private internal API of Qt5.
} }
XdgIconLoader::instance()->setFollowColorScheme(iconFollowColorScheme_);
// if font is changed // if font is changed
if(oldFont != fontStr_ || oldFixedFont != fixedFontStr_){ if(oldFont != fontStr_ || oldFixedFont != fixedFontStr_){
@ -184,6 +189,8 @@ void LXQtPlatformTheme::onSettingsChanged() {
QApplication::setFont(font_); QApplication::setFont(font_);
} }
QApplication::setWheelScrollLines(wheelScrollLines_.toInt());
// emit a ThemeChange event to all widgets // emit a ThemeChange event to all widgets
Q_FOREACH(QWidget* widget, QApplication::allWidgets()) { Q_FOREACH(QWidget* widget, QApplication::allWidgets()) {
// Qt5 added a QEvent::ThemeChange event. // Qt5 added a QEvent::ThemeChange event.
@ -193,21 +200,26 @@ void LXQtPlatformTheme::onSettingsChanged() {
} }
bool LXQtPlatformTheme::usePlatformNativeDialog(DialogType type) const { bool LXQtPlatformTheme::usePlatformNativeDialog(DialogType type) const {
if(type == FileDialog
&& qobject_cast<QApplication *>(QCoreApplication::instance())) { // QML may not have qApp
// use our own file dialog
return true;
}
return false; return false;
} }
#if 0
QPlatformDialogHelper *LXQtPlatformTheme::createPlatformDialogHelper(DialogType type) const { QPlatformDialogHelper *LXQtPlatformTheme::createPlatformDialogHelper(DialogType type) const {
return 0; if(type == FileDialog
&& qobject_cast<QApplication *>(QCoreApplication::instance())) { // QML may not have qApp
// use our own file dialog
return new LXQtFileDialogHelper();
}
return nullptr;
} }
#endif
const QPalette *LXQtPlatformTheme::palette(Palette type) const { const QPalette *LXQtPlatformTheme::palette(Palette type) const {
return nullptr;
if (type == QPlatformTheme::SystemPalette)
// the default constructor uses the default palette
return new QPalette;
return QPlatformTheme::palette(type);
} }
const QFont *LXQtPlatformTheme::font(Font type) const { const QFont *LXQtPlatformTheme::font(Font type) const {
@ -288,6 +300,9 @@ QVariant LXQtPlatformTheme::themeHint(ThemeHint hint) const {
break; break;
case MouseDoubleClickDistance: case MouseDoubleClickDistance:
break; break;
case WheelScrollLines:
return wheelScrollLines_;
break;
default: default:
break; break;
} }
@ -320,9 +335,9 @@ QStringList LXQtPlatformTheme::xdgIconThemePaths() const
xdgDataDirs = QLatin1String("/usr/local/share/:/usr/share/"); xdgDataDirs = QLatin1String("/usr/local/share/:/usr/share/");
xdgDirs.append(xdgDataDirs); xdgDirs.append(xdgDataDirs);
foreach (const QString &s, xdgDirs) { for (const auto &s: xdgDirs) {
const QStringList r = s.split(QLatin1Char(':'), QString::SkipEmptyParts); const QStringList r = s.split(QLatin1Char(':'), QString::SkipEmptyParts);
foreach (const QString &xdgDir, r) { for (const auto& xdgDir: r) {
const QFileInfo xdgIconsDir(xdgDir + QStringLiteral("/icons")); const QFileInfo xdgIconsDir(xdgDir + QStringLiteral("/icons"));
if (xdgIconsDir.isDir()) if (xdgIconsDir.isDir())
paths.append(xdgIconsDir.absoluteFilePath()); paths.append(xdgIconsDir.absoluteFilePath());

@ -48,7 +48,7 @@ public:
// virtual QPlatformMenuBar* createPlatformMenuBar() const; // virtual QPlatformMenuBar* createPlatformMenuBar() const;
virtual bool usePlatformNativeDialog(DialogType type) const; virtual bool usePlatformNativeDialog(DialogType type) const;
// virtual QPlatformDialogHelper *createPlatformDialogHelper(DialogType type) const; virtual QPlatformDialogHelper *createPlatformDialogHelper(DialogType type) const;
virtual const QPalette *palette(Palette type = SystemPalette) const; virtual const QPalette *palette(Palette type = SystemPalette) const;
@ -90,6 +90,7 @@ private:
QString iconTheme_; QString iconTheme_;
Qt::ToolButtonStyle toolButtonStyle_; Qt::ToolButtonStyle toolButtonStyle_;
bool singleClickActivate_; bool singleClickActivate_;
bool iconFollowColorScheme_;
// other Qt settings // other Qt settings
// widget // widget

@ -297,12 +297,12 @@ void LXQtSystemTrayIcon::init()
connect(mSni, &StatusNotifierItem::activateRequested, [this](const QPoint &) connect(mSni, &StatusNotifierItem::activateRequested, [this](const QPoint &)
{ {
emit activated(QPlatformSystemTrayIcon::Trigger); Q_EMIT activated(QPlatformSystemTrayIcon::Trigger);
}); });
connect(mSni, &StatusNotifierItem::secondaryActivateRequested, [this](const QPoint &) connect(mSni, &StatusNotifierItem::secondaryActivateRequested, [this](const QPoint &)
{ {
emit activated(QPlatformSystemTrayIcon::MiddleClick); Q_EMIT activated(QPlatformSystemTrayIcon::MiddleClick);
}); });
} }
} }

@ -43,17 +43,23 @@ StatusNotifierItem::StatusNotifierItem(QString id, QObject *parent)
mTitle("Test"), mTitle("Test"),
mStatus("Active"), mStatus("Active"),
mMenu(nullptr), mMenu(nullptr),
mMenuExporter(nullptr) mMenuExporter(nullptr),
mSessionBus(QDBusConnection::connectToBus(QDBusConnection::SessionBus, mService))
{ {
// Separate DBus connection to the session bus is created, because QDbus does not provide
// a way to register different objects for different services with the same paths.
// For status notifiers we need different /StatusNotifierItem for each service.
// register service // register service
QDBusConnection::sessionBus().registerService(mService);
QDBusConnection::sessionBus().registerObject("/StatusNotifierItem", this); mSessionBus.registerService(mService);
mSessionBus.registerObject(QLatin1String("/StatusNotifierItem"), this);
registerToHost(); registerToHost();
// monitor the watcher service in case the host restarts // monitor the watcher service in case the host restarts
QDBusServiceWatcher *watcher = new QDBusServiceWatcher("org.kde.StatusNotifierWatcher", QDBusServiceWatcher *watcher = new QDBusServiceWatcher("org.kde.StatusNotifierWatcher",
QDBusConnection::sessionBus(), mSessionBus,
QDBusServiceWatcher::WatchForOwnerChange, QDBusServiceWatcher::WatchForOwnerChange,
this); this);
connect(watcher, &QDBusServiceWatcher::serviceOwnerChanged, connect(watcher, &QDBusServiceWatcher::serviceOwnerChanged,
@ -62,9 +68,9 @@ StatusNotifierItem::StatusNotifierItem(QString id, QObject *parent)
StatusNotifierItem::~StatusNotifierItem() StatusNotifierItem::~StatusNotifierItem()
{ {
QDBusConnection::sessionBus().unregisterObject("/StatusNotifierItem"); mSessionBus.unregisterObject(QLatin1String("/StatusNotifierItem"));
QDBusConnection::sessionBus().unregisterService(mService); mSessionBus.unregisterService(mService);
QDBusConnection::sessionBus().disconnectFromBus(mService); QDBusConnection::disconnectFromBus(mService);
} }
void StatusNotifierItem::registerToHost() void StatusNotifierItem::registerToHost()
@ -72,13 +78,16 @@ void StatusNotifierItem::registerToHost()
QDBusInterface interface("org.kde.StatusNotifierWatcher", QDBusInterface interface("org.kde.StatusNotifierWatcher",
"/StatusNotifierWatcher", "/StatusNotifierWatcher",
"org.kde.StatusNotifierWatcher", "org.kde.StatusNotifierWatcher",
QDBusConnection::sessionBus()); mSessionBus);
interface.asyncCall("RegisterStatusNotifierItem", mService); interface.asyncCall("RegisterStatusNotifierItem", mService);
} }
void StatusNotifierItem::onServiceOwnerChanged(const QString& service, const QString& oldOwner, void StatusNotifierItem::onServiceOwnerChanged(const QString& service, const QString& oldOwner,
const QString& newOwner) const QString& newOwner)
{ {
Q_UNUSED(service);
Q_UNUSED(oldOwner);
if (!newOwner.isEmpty()) if (!newOwner.isEmpty())
registerToHost(); registerToHost();
} }
@ -95,7 +104,7 @@ void StatusNotifierItem::setTitle(const QString &title)
return; return;
mTitle = title; mTitle = title;
emit mAdaptor->NewTitle(); Q_EMIT mAdaptor->NewTitle();
} }
void StatusNotifierItem::setStatus(const QString &status) void StatusNotifierItem::setStatus(const QString &status)
@ -104,7 +113,7 @@ void StatusNotifierItem::setStatus(const QString &status)
return; return;
mStatus = status; mStatus = status;
emit mAdaptor->NewStatus(mStatus); Q_EMIT mAdaptor->NewStatus(mStatus);
} }
void StatusNotifierItem::setMenuPath(const QString& path) void StatusNotifierItem::setMenuPath(const QString& path)
@ -118,7 +127,7 @@ void StatusNotifierItem::setIconByName(const QString &name)
return; return;
mIconName = name; mIconName = name;
emit mAdaptor->NewIcon(); Q_EMIT mAdaptor->NewIcon();
} }
void StatusNotifierItem::setIconByPixmap(const QIcon &icon) void StatusNotifierItem::setIconByPixmap(const QIcon &icon)
@ -129,7 +138,7 @@ void StatusNotifierItem::setIconByPixmap(const QIcon &icon)
mIconCacheKey = icon.cacheKey(); mIconCacheKey = icon.cacheKey();
mIcon = iconToPixmapList(icon); mIcon = iconToPixmapList(icon);
mIconName.clear(); mIconName.clear();
emit mAdaptor->NewIcon(); Q_EMIT mAdaptor->NewIcon();
} }
void StatusNotifierItem::setOverlayIconByName(const QString &name) void StatusNotifierItem::setOverlayIconByName(const QString &name)
@ -138,7 +147,7 @@ void StatusNotifierItem::setOverlayIconByName(const QString &name)
return; return;
mOverlayIconName = name; mOverlayIconName = name;
emit mAdaptor->NewOverlayIcon(); Q_EMIT mAdaptor->NewOverlayIcon();
} }
void StatusNotifierItem::setOverlayIconByPixmap(const QIcon &icon) void StatusNotifierItem::setOverlayIconByPixmap(const QIcon &icon)
@ -149,7 +158,7 @@ void StatusNotifierItem::setOverlayIconByPixmap(const QIcon &icon)
mOverlayIconCacheKey = icon.cacheKey(); mOverlayIconCacheKey = icon.cacheKey();
mOverlayIcon = iconToPixmapList(icon); mOverlayIcon = iconToPixmapList(icon);
mOverlayIconName.clear(); mOverlayIconName.clear();
emit mAdaptor->NewOverlayIcon(); Q_EMIT mAdaptor->NewOverlayIcon();
} }
void StatusNotifierItem::setAttentionIconByName(const QString &name) void StatusNotifierItem::setAttentionIconByName(const QString &name)
@ -158,7 +167,7 @@ void StatusNotifierItem::setAttentionIconByName(const QString &name)
return; return;
mAttentionIconName = name; mAttentionIconName = name;
emit mAdaptor->NewAttentionIcon(); Q_EMIT mAdaptor->NewAttentionIcon();
} }
void StatusNotifierItem::setAttentionIconByPixmap(const QIcon &icon) void StatusNotifierItem::setAttentionIconByPixmap(const QIcon &icon)
@ -169,7 +178,7 @@ void StatusNotifierItem::setAttentionIconByPixmap(const QIcon &icon)
mAttentionIconCacheKey = icon.cacheKey(); mAttentionIconCacheKey = icon.cacheKey();
mAttentionIcon = iconToPixmapList(icon); mAttentionIcon = iconToPixmapList(icon);
mAttentionIconName.clear(); mAttentionIconName.clear();
emit mAdaptor->NewAttentionIcon(); Q_EMIT mAdaptor->NewAttentionIcon();
} }
void StatusNotifierItem::setToolTipTitle(const QString &title) void StatusNotifierItem::setToolTipTitle(const QString &title)
@ -178,7 +187,7 @@ void StatusNotifierItem::setToolTipTitle(const QString &title)
return; return;
mTooltipTitle = title; mTooltipTitle = title;
emit mAdaptor->NewToolTip(); Q_EMIT mAdaptor->NewToolTip();
} }
void StatusNotifierItem::setToolTipSubTitle(const QString &subTitle) void StatusNotifierItem::setToolTipSubTitle(const QString &subTitle)
@ -187,7 +196,7 @@ void StatusNotifierItem::setToolTipSubTitle(const QString &subTitle)
return; return;
mTooltipSubtitle = subTitle; mTooltipSubtitle = subTitle;
emit mAdaptor->NewToolTip(); Q_EMIT mAdaptor->NewToolTip();
} }
void StatusNotifierItem::setToolTipIconByName(const QString &name) void StatusNotifierItem::setToolTipIconByName(const QString &name)
@ -196,7 +205,7 @@ void StatusNotifierItem::setToolTipIconByName(const QString &name)
return; return;
mTooltipIconName = name; mTooltipIconName = name;
emit mAdaptor->NewToolTip(); Q_EMIT mAdaptor->NewToolTip();
} }
void StatusNotifierItem::setToolTipIconByPixmap(const QIcon &icon) void StatusNotifierItem::setToolTipIconByPixmap(const QIcon &icon)
@ -207,7 +216,7 @@ void StatusNotifierItem::setToolTipIconByPixmap(const QIcon &icon)
mTooltipIconCacheKey = icon.cacheKey(); mTooltipIconCacheKey = icon.cacheKey();
mTooltipIcon = iconToPixmapList(icon); mTooltipIcon = iconToPixmapList(icon);
mTooltipIconName.clear(); mTooltipIconName.clear();
emit mAdaptor->NewToolTip(); Q_EMIT mAdaptor->NewToolTip();
} }
void StatusNotifierItem::setContextMenu(QMenu* menu) void StatusNotifierItem::setContextMenu(QMenu* menu)
@ -227,7 +236,7 @@ void StatusNotifierItem::setContextMenu(QMenu* menu)
if (nullptr != mMenu) if (nullptr != mMenu)
{ {
connect(mMenu, &QObject::destroyed, this, &StatusNotifierItem::onMenuDestroyed); connect(mMenu, &QObject::destroyed, this, &StatusNotifierItem::onMenuDestroyed);
mMenuExporter = new DBusMenuExporter{this->menu().path(), mMenu}; mMenuExporter = new DBusMenuExporter{this->menu().path(), mMenu, mSessionBus};
} }
} }
@ -236,7 +245,7 @@ void StatusNotifierItem::Activate(int x, int y)
if (mStatus == "NeedsAttention") if (mStatus == "NeedsAttention")
mStatus = "Active"; mStatus = "Active";
emit activateRequested(QPoint(x, y)); Q_EMIT activateRequested(QPoint(x, y));
} }
void StatusNotifierItem::SecondaryActivate(int x, int y) void StatusNotifierItem::SecondaryActivate(int x, int y)
@ -244,7 +253,7 @@ void StatusNotifierItem::SecondaryActivate(int x, int y)
if (mStatus == "NeedsAttention") if (mStatus == "NeedsAttention")
mStatus = "Active"; mStatus = "Active";
emit secondaryActivateRequested(QPoint(x, y)); Q_EMIT secondaryActivateRequested(QPoint(x, y));
} }
void StatusNotifierItem::ContextMenu(int x, int y) void StatusNotifierItem::ContextMenu(int x, int y)
@ -264,14 +273,14 @@ void StatusNotifierItem::Scroll(int delta, const QString &orientation)
if (orientation.toLower() == "horizontal") if (orientation.toLower() == "horizontal")
orient = Qt::Horizontal; orient = Qt::Horizontal;
emit scrollRequested(delta, orient); Q_EMIT scrollRequested(delta, orient);
} }
void StatusNotifierItem::showMessage(const QString& title, const QString& msg, void StatusNotifierItem::showMessage(const QString& title, const QString& msg,
const QString& iconName, int secs) const QString& iconName, int secs)
{ {
QDBusInterface interface("org.freedesktop.Notifications", "/org/freedesktop/Notifications", QDBusInterface interface("org.freedesktop.Notifications", "/org/freedesktop/Notifications",
"org.freedesktop.Notifications", QDBusConnection::sessionBus()); "org.freedesktop.Notifications", mSessionBus);
interface.call("Notify", mTitle, (uint) 0, iconName, title, interface.call("Notify", mTitle, (uint) 0, iconName, title,
msg, QStringList(), QVariantMap(), secs); msg, QStringList(), QVariantMap(), secs);
} }
@ -281,7 +290,8 @@ IconPixmapList StatusNotifierItem::iconToPixmapList(const QIcon& icon)
IconPixmapList pixmapList; IconPixmapList pixmapList;
// long live KDE! // long live KDE!
for (const QSize &size : icon.availableSizes()) const QList<QSize> sizes = icon.availableSizes();
for (const QSize &size : sizes)
{ {
QImage image = icon.pixmap(size).toImage(); QImage image = icon.pixmap(size).toImage();

@ -32,6 +32,7 @@
#include <QObject> #include <QObject>
#include <QIcon> #include <QIcon>
#include <QMenu> #include <QMenu>
#include <QDBusConnection>
#include "dbustypes.h" #include "dbustypes.h"
@ -132,7 +133,7 @@ public:
*/ */
void setContextMenu(QMenu *menu); void setContextMenu(QMenu *menu);
public slots: public Q_SLOTS:
void Activate(int x, int y); void Activate(int x, int y);
void SecondaryActivate(int x, int y); void SecondaryActivate(int x, int y);
void ContextMenu(int x, int y); void ContextMenu(int x, int y);
@ -144,12 +145,12 @@ private:
void registerToHost(); void registerToHost();
IconPixmapList iconToPixmapList(const QIcon &icon); IconPixmapList iconToPixmapList(const QIcon &icon);
private slots: private Q_SLOTS:
void onServiceOwnerChanged(const QString &service, const QString &oldOwner, void onServiceOwnerChanged(const QString &service, const QString &oldOwner,
const QString &newOwner); const QString &newOwner);
void onMenuDestroyed(); void onMenuDestroyed();
signals: Q_SIGNALS:
void activateRequested(const QPoint &pos); void activateRequested(const QPoint &pos);
void secondaryActivateRequested(const QPoint &pos); void secondaryActivateRequested(const QPoint &pos);
void scrollRequested(int delta, Qt::Orientation orientation); void scrollRequested(int delta, Qt::Orientation orientation);
@ -176,6 +177,7 @@ private:
QMenu *mMenu; QMenu *mMenu;
QDBusObjectPath mMenuPath; QDBusObjectPath mMenuPath;
DBusMenuExporter *mMenuExporter; DBusMenuExporter *mMenuExporter;
QDBusConnection mSessionBus;
static int mServiceCounter; static int mServiceCounter;
}; };

Loading…
Cancel
Save