mirror of
https://bitbucket.org/smil3y/kdelibs.git
synced 2025-02-23 10:22:48 +00:00
generic: drop scripting and tray support
after changes to multiple sub-projects (Katie, kdelibs, kde-workspace and kde-extraapps) that finally happened, can write lots about it but I will keep it short - by rewriting parts that were using js/qml (e.g. the plasma applets) the desktop startup was reduced to half, also the legacy tray thing shall be no more (anything that needs tray icon shall be a plasma applet now) thus some applications and features will be dropped aswell. see all repositories for the changes done Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
parent
45b0ff8106
commit
fbfb374b9c
104 changed files with 59 additions and 9376 deletions
|
@ -457,7 +457,6 @@ add_subdirectory( cmake )
|
|||
|
||||
add_subdirectory( includes )
|
||||
add_subdirectory( interfaces )
|
||||
add_subdirectory( kdeclarative )
|
||||
add_subdirectory( kdecore )
|
||||
add_subdirectory( kded )
|
||||
add_subdirectory( kdeui )
|
||||
|
|
|
@ -32,7 +32,6 @@ set(cmakeFiles
|
|||
FindFontconfig.cmake
|
||||
FindGettextPO.cmake
|
||||
FindGLIB2.cmake
|
||||
FindGMP.cmake
|
||||
FindGphoto2.cmake
|
||||
FindKmod.cmake
|
||||
FindLibATASmart.cmake
|
||||
|
@ -44,10 +43,8 @@ set(cmakeFiles
|
|||
FindLibSSH.cmake
|
||||
FindLibTorrent.cmake
|
||||
FindLibUSB.cmake
|
||||
FindLibVNCServer.cmake
|
||||
FindLightDM.cmake
|
||||
FindLibGit2.cmake
|
||||
FindMPFR.cmake
|
||||
FindMtp.cmake
|
||||
FindPCIUTILS.cmake
|
||||
FindPoppler.cmake
|
||||
|
|
|
@ -1,27 +0,0 @@
|
|||
# Try to find GMP, once done this will define:
|
||||
#
|
||||
# GMP_FOUND - system has GMP
|
||||
# GMP_INCLUDE_DIR - the GMP include directory
|
||||
# GMP_LIBRARIES - the libraries needed to use GMP
|
||||
#
|
||||
# Copyright (c) 2020 Ivailo Monev <xakepa10@gmail.com>
|
||||
#
|
||||
# Redistribution and use is allowed according to the terms of the BSD license.
|
||||
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
|
||||
|
||||
find_path(GMP_INCLUDE_DIR
|
||||
NAMES gmp.h
|
||||
HINTS $ENV{GMPDIR}/include
|
||||
)
|
||||
|
||||
find_library(GMP_LIBRARIES
|
||||
NAMES gmp
|
||||
HINTS $ENV{GMPDIR}/lib
|
||||
)
|
||||
|
||||
include(FindPackageHandleStandardArgs)
|
||||
find_package_handle_standard_args(GMP
|
||||
REQUIRED_VARS GMP_LIBRARIES GMP_INCLUDE_DIR
|
||||
)
|
||||
|
||||
mark_as_advanced(GMP_INCLUDE_DIR GMP_LIBRARIES)
|
|
@ -1,44 +0,0 @@
|
|||
# cmake macro to test LIBVNCSERVER LIB
|
||||
|
||||
# Copyright (c) 2006, Alessandro Praduroux <pradu@pradu.it>
|
||||
# Copyright (c) 2007, Urs Wolfer <uwolfer @ kde.org>
|
||||
#
|
||||
# Redistribution and use is allowed according to the terms of the BSD license.
|
||||
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
|
||||
|
||||
INCLUDE(CheckStructHasMember)
|
||||
INCLUDE(CMakePushCheckState)
|
||||
|
||||
IF (LIBVNCSERVER_INCLUDE_DIR AND LIBVNCSERVER_LIBRARIES)
|
||||
# Already in cache, be silent
|
||||
SET(LIBVNCSERVER_FIND_QUIETLY TRUE)
|
||||
ENDIF (LIBVNCSERVER_INCLUDE_DIR AND LIBVNCSERVER_LIBRARIES)
|
||||
|
||||
FIND_PATH(LIBVNCSERVER_INCLUDE_DIR rfb/rfb.h)
|
||||
|
||||
FIND_LIBRARY(LIBVNCSERVER_LIBRARIES NAMES vncserver libvncserver)
|
||||
|
||||
# libvncserver and libvncclient are in the same package, so it does
|
||||
# not make sense to add a new cmake script for finding libvncclient.
|
||||
# instead just find the libvncclient also in this file.
|
||||
FIND_PATH(LIBVNCCLIENT_INCLUDE_DIR rfb/rfbclient.h)
|
||||
FIND_LIBRARY(LIBVNCCLIENT_LIBRARIES NAMES vncclient libvncclient)
|
||||
|
||||
IF (LIBVNCSERVER_INCLUDE_DIR AND LIBVNCSERVER_LIBRARIES)
|
||||
cmake_reset_check_state()
|
||||
SET(CMAKE_REQUIRED_INCLUDES "${LIBVNCSERVER_INCLUDE_DIR}")
|
||||
CHECK_STRUCT_HAS_MEMBER(rfbClient GotXCutText rfb/rfbclient.h LIBVNCSERVER_FOUND)
|
||||
cmake_reset_check_state()
|
||||
ENDIF (LIBVNCSERVER_INCLUDE_DIR AND LIBVNCSERVER_LIBRARIES)
|
||||
|
||||
IF (LIBVNCSERVER_FOUND)
|
||||
IF (NOT LIBVNCSERVER_FIND_QUIETLY)
|
||||
MESSAGE(STATUS "Found LibVNCServer: ${LIBVNCSERVER_LIBRARIES}")
|
||||
ENDIF (NOT LIBVNCSERVER_FIND_QUIETLY)
|
||||
ELSE (LIBVNCSERVER_FOUND)
|
||||
IF (LIBVNCSERVER_FIND_REQUIRED)
|
||||
MESSAGE(FATAL_ERROR "Could NOT find acceptable version of LibVNCServer (version 0.9 or later required).")
|
||||
ENDIF (LIBVNCSERVER_FIND_REQUIRED)
|
||||
ENDIF (LIBVNCSERVER_FOUND)
|
||||
|
||||
MARK_AS_ADVANCED(LIBVNCSERVER_INCLUDE_DIR LIBVNCSERVER_LIBRARIES)
|
|
@ -1,37 +0,0 @@
|
|||
# Try to find MPFR, once done this will define:
|
||||
#
|
||||
# MPFR_FOUND - system has MPFR
|
||||
# MPFR_INCLUDE_DIR - the MPFR include directory
|
||||
# MPFR_LIBRARIES - the libraries needed to use MPFR
|
||||
#
|
||||
# Copyright (c) 2020 Ivailo Monev <xakepa10@gmail.com>
|
||||
#
|
||||
# Redistribution and use is allowed according to the terms of the BSD license.
|
||||
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
|
||||
|
||||
find_package(PkgConfig REQUIRED)
|
||||
pkg_check_modules(PC_MPFR QUIET mpfr)
|
||||
|
||||
set(MPFR_INCLUDE_DIR ${PC_MPFR_INCLUDE_DIRS})
|
||||
set(MPFR_LIBRARIES ${PC_MPFR_LIBRARIES})
|
||||
set(MPFR_VERSION ${PC_MPFR_VERSION})
|
||||
|
||||
if(NOT MPFR_INCLUDE_DIR OR NOT MPFR_LIBRARIES)
|
||||
find_path(MPFR_INCLUDE_DIR
|
||||
NAMES mpfr.h
|
||||
HINTS $ENV{MPFRDIR}/include
|
||||
)
|
||||
|
||||
find_library(MPFR_LIBRARIES
|
||||
NAMES mpfr
|
||||
HINTS $ENV{MPFRDIR}/lib
|
||||
)
|
||||
endif()
|
||||
|
||||
include(FindPackageHandleStandardArgs)
|
||||
find_package_handle_standard_args(MPFR
|
||||
VERSION_VAR MPFR_VERSION
|
||||
REQUIRED_VARS MPFR_LIBRARIES MPFR_INCLUDE_DIR
|
||||
)
|
||||
|
||||
mark_as_advanced(MPFR_INCLUDE_DIR MPFR_LIBRARIES)
|
|
@ -79,8 +79,6 @@ install(
|
|||
KDEDModule
|
||||
KDEPrintDialog
|
||||
KCalendarWidget
|
||||
KDBusMenuExporter
|
||||
KDBusMenuImporter
|
||||
KDesktopFile
|
||||
KDialog
|
||||
KDialogButtonBox
|
||||
|
@ -201,7 +199,6 @@ install(
|
|||
KPassivePopup
|
||||
KPassivePopupMessageHandler
|
||||
KPasswordDialog
|
||||
KPasteTextAction
|
||||
KPixmap
|
||||
KPixmapWidget
|
||||
KPluginFactory
|
||||
|
@ -261,14 +258,12 @@ install(
|
|||
KStartupInfoId
|
||||
KStatusBar
|
||||
KStatusBarJobTracker
|
||||
KStatusNotifierItem
|
||||
KStringHandler
|
||||
KStyle
|
||||
KSycoca
|
||||
KSycocaEntry
|
||||
KSystemEventFilter
|
||||
KSystemTimeZones
|
||||
KSystemTrayIcon
|
||||
KTabBar
|
||||
KTabWidget
|
||||
KTempDir
|
||||
|
@ -477,18 +472,15 @@ install(
|
|||
Plasma/Animation
|
||||
Plasma/Animator
|
||||
Plasma/Applet
|
||||
Plasma/AppletScript
|
||||
Plasma/BusyWidget
|
||||
Plasma/CheckBox
|
||||
Plasma/ComboBox
|
||||
Plasma/ConfigLoader
|
||||
Plasma/Containment
|
||||
Plasma/ContainmentActions
|
||||
Plasma/Corona
|
||||
Plasma/DataContainer
|
||||
Plasma/DataEngine
|
||||
Plasma/DataEngineManager
|
||||
Plasma/DeclarativeWidget
|
||||
Plasma/Delegate
|
||||
Plasma/Dialog
|
||||
Plasma/DialogShadows
|
||||
|
@ -516,7 +508,6 @@ install(
|
|||
Plasma/RadioButton
|
||||
Plasma/RunnerContext
|
||||
Plasma/RunnerManager
|
||||
Plasma/ScriptEngine
|
||||
Plasma/ScrollBar
|
||||
Plasma/ScrollWidget
|
||||
Plasma/Separator
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
#include "../kdbusmenuexporter.h"
|
|
@ -1 +0,0 @@
|
|||
#include "../kdbusmenuimporter.h"
|
|
@ -1 +0,0 @@
|
|||
#include "../kpastetextaction.h"
|
|
@ -1 +0,0 @@
|
|||
#include "../kstatusnotifieritem.h"
|
|
@ -1 +0,0 @@
|
|||
#include "../ksystemtrayicon.h"
|
|
@ -1 +0,0 @@
|
|||
#include "../../plasma/scripting/appletscript.h"
|
|
@ -1 +0,0 @@
|
|||
#include "../../plasma/configloader.h"
|
|
@ -1 +0,0 @@
|
|||
#include "../../plasma/widgets/declarativewidget.h"
|
|
@ -1 +0,0 @@
|
|||
#include "../../plasma/scripting/scriptengine.h"
|
|
@ -1,60 +0,0 @@
|
|||
project(kdeclarative)
|
||||
|
||||
if(KDE_PLATFORM_FEATURE_BINARY_COMPATIBLE_FEATURE_REDUCTION)
|
||||
set(KDECLARATIVE_NO_KIO TRUE)
|
||||
endif()
|
||||
|
||||
configure_file(
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/config-kdeclarative.h.cmake
|
||||
${CMAKE_CURRENT_BINARY_DIR}/config-kdeclarative.h
|
||||
)
|
||||
|
||||
include_directories(
|
||||
${CMAKE_SOURCE_DIR}
|
||||
${CMAKE_BINARY_DIR}
|
||||
${KDE4_KIO_INCLUDES}
|
||||
${KDE4_KDEUI_INCLUDES}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
${CMAKE_CURRENT_BINARY_DIR}
|
||||
)
|
||||
|
||||
set(kdeclarative_LIB_SRCS
|
||||
kdeclarative.cpp
|
||||
private/engineaccess.cpp
|
||||
private/kiconprovider.cpp
|
||||
bindings/qscriptnonguibookkeeping.cpp
|
||||
bindings/i18n.cpp
|
||||
bindings/icon.cpp
|
||||
bindings/image.cpp
|
||||
bindings/locale.cpp
|
||||
bindings/url.cpp
|
||||
)
|
||||
|
||||
add_library(kdeclarative SHARED ${kdeclarative_LIB_SRCS})
|
||||
|
||||
set_target_properties(kdeclarative PROPERTIES
|
||||
VERSION ${GENERIC_LIB_VERSION}
|
||||
SOVERSION ${GENERIC_LIB_SOVERSION}
|
||||
)
|
||||
|
||||
target_link_libraries(kdeclarative PUBLIC
|
||||
${QT_QTSCRIPT_LIBRARY}
|
||||
${QT_QTDECLARATIVE_LIBRARY}
|
||||
kdecore
|
||||
kdeui
|
||||
)
|
||||
|
||||
generate_export_header(kdeclarative)
|
||||
|
||||
install(
|
||||
FILES
|
||||
kdeclarative.h
|
||||
${CMAKE_CURRENT_BINARY_DIR}/kdeclarative_export.h
|
||||
DESTINATION ${KDE4_INCLUDE_INSTALL_DIR}
|
||||
)
|
||||
|
||||
install(
|
||||
TARGETS kdeclarative
|
||||
EXPORT kdelibsTargets
|
||||
DESTINATION ${KDE4_LIB_INSTALL_DIR}
|
||||
)
|
|
@ -1,38 +0,0 @@
|
|||
/****************************************************************************
|
||||
**
|
||||
** This file is part of the Qt Script Generator.
|
||||
**
|
||||
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
||||
**
|
||||
** Contact: Nokia Corporation info@qt.nokia.com
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
** This file may be used under the terms of the GNU Lesser General Public
|
||||
** License version 2.1 as published by the Free Software Foundation
|
||||
** and appearing in the file LICENSE.LGPL included in the packaging of
|
||||
** this file. Please review the following information to ensure the GNU
|
||||
** Lesser General Public License version 2.1 requirements will be met:
|
||||
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** Copyright (C) 2011 Nokia. All rights reserved
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef QTSCRIPTEXTENSIONS_GLOBAL_H
|
||||
#define QTSCRIPTEXTENSIONS_GLOBAL_H
|
||||
|
||||
#include <QScriptValue>
|
||||
#include <QScriptContext>
|
||||
#include <QScriptEngine>
|
||||
|
||||
#define DECLARE_SELF(Class, __fn__) \
|
||||
Class* self = qscriptvalue_cast<Class*>(ctx->thisObject()); \
|
||||
if (!self) { \
|
||||
return ctx->throwError(QScriptContext::TypeError, \
|
||||
QString::fromLatin1("%0.prototype.%1: this object is not a %0") \
|
||||
.arg(#Class).arg(#__fn__)); \
|
||||
}
|
||||
|
||||
#define ADD_ENUM_VALUE(__c__, __ns__, __v__) \
|
||||
__c__.setProperty(#__v__, QScriptValue(__c__.engine(), __ns__::__v__))
|
||||
|
||||
#endif // QTSCRIPTEXTENSIONS_GLOBAL_H
|
|
@ -1,125 +0,0 @@
|
|||
/*
|
||||
* Copyright 2009 Aaron Seigo <aseigo@kde.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Library General Public License version 2 as
|
||||
* published by the Free Software Foundation
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this program; if not, write to the
|
||||
* Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "i18n_p.h"
|
||||
|
||||
#include <QtScript/QScriptContext>
|
||||
#include <QtScript/QScriptEngine>
|
||||
|
||||
#include <kdebug.h>
|
||||
#include <klocalizedstring.h>
|
||||
|
||||
QScriptValue jsi18n(QScriptContext *context, QScriptEngine *engine)
|
||||
{
|
||||
Q_UNUSED(engine)
|
||||
|
||||
if (context->argumentCount() < 1) {
|
||||
kDebug() << i18n("i18n() takes at least one argument");
|
||||
return engine->undefinedValue();
|
||||
}
|
||||
|
||||
KLocalizedString message = ki18n(context->argument(0).toString().toUtf8());
|
||||
|
||||
const int numArgs = context->argumentCount();
|
||||
for (int i = 1; i < numArgs; ++i) {
|
||||
message = message.subs(context->argument(i).toString());
|
||||
}
|
||||
|
||||
return message.toString();
|
||||
}
|
||||
|
||||
QScriptValue jsi18nc(QScriptContext *context, QScriptEngine *engine)
|
||||
{
|
||||
Q_UNUSED(engine)
|
||||
|
||||
const int numArgs = context->argumentCount();
|
||||
if (numArgs < 2) {
|
||||
kDebug() << i18n("i18nc() takes at least two arguments");
|
||||
return engine->undefinedValue();
|
||||
}
|
||||
|
||||
KLocalizedString message = ki18nc(context->argument(0).toString().toUtf8(),
|
||||
context->argument(1).toString().toUtf8());
|
||||
|
||||
for (int i = 2; i < numArgs; ++i) {
|
||||
message = message.subs(context->argument(i).toString());
|
||||
}
|
||||
|
||||
return message.toString();
|
||||
}
|
||||
|
||||
QScriptValue jsi18np(QScriptContext *context, QScriptEngine *engine)
|
||||
{
|
||||
Q_UNUSED(engine)
|
||||
|
||||
const int numArgs = context->argumentCount();
|
||||
if (numArgs < 2) {
|
||||
kDebug() << i18n("i18np() takes at least two arguments");
|
||||
return engine->undefinedValue();
|
||||
}
|
||||
|
||||
KLocalizedString message = ki18np(context->argument(0).toString().toUtf8(),
|
||||
context->argument(1).toString().toUtf8());
|
||||
|
||||
for (int i = 2; i < numArgs; ++i) {
|
||||
QScriptValue v = context->argument(i);
|
||||
if (v.isNumber()) {
|
||||
message = message.subs(v.toInt32());
|
||||
} else {
|
||||
message = message.subs(v.toString());
|
||||
}
|
||||
}
|
||||
|
||||
return message.toString();
|
||||
}
|
||||
|
||||
QScriptValue jsi18ncp(QScriptContext *context, QScriptEngine *engine)
|
||||
{
|
||||
Q_UNUSED(engine)
|
||||
|
||||
const int numArgs = context->argumentCount();
|
||||
if (numArgs < 3) {
|
||||
kDebug() << i18n("i18ncp() takes at least three arguments");
|
||||
return engine->undefinedValue();
|
||||
}
|
||||
|
||||
KLocalizedString message = ki18ncp(context->argument(0).toString().toUtf8(),
|
||||
context->argument(1).toString().toUtf8(),
|
||||
context->argument(2).toString().toUtf8());
|
||||
|
||||
for (int i = 3; i < numArgs; ++i) {
|
||||
QScriptValue v = context->argument(i);
|
||||
if (v.isNumber()) {
|
||||
message = message.subs(v.toInt32());
|
||||
} else {
|
||||
message = message.subs(v.toString());
|
||||
}
|
||||
}
|
||||
|
||||
return message.toString();
|
||||
}
|
||||
|
||||
void bindI18N(QScriptEngine *engine)
|
||||
{
|
||||
QScriptValue global = engine->globalObject();
|
||||
global.setProperty("i18n", engine->newFunction(jsi18n));
|
||||
global.setProperty("i18nc", engine->newFunction(jsi18nc));
|
||||
global.setProperty("i18np", engine->newFunction(jsi18np));
|
||||
global.setProperty("i18ncp", engine->newFunction(jsi18ncp));
|
||||
}
|
||||
|
|
@ -1,34 +0,0 @@
|
|||
/*
|
||||
* Copyright 2009 Aaron Seigo <aseigo@kde.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Library General Public License version 2 as
|
||||
* published by the Free Software Foundation
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this program; if not, write to the
|
||||
* Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef I18N_P_H
|
||||
#define I18N_P_H
|
||||
|
||||
#include <QtScript/QScriptValue>
|
||||
|
||||
#include <QScriptContext>
|
||||
#include <QScriptEngine>
|
||||
|
||||
QScriptValue jsi18n(QScriptContext *context, QScriptEngine *engine);
|
||||
QScriptValue jsi18nc(QScriptContext *context, QScriptEngine *engine);
|
||||
QScriptValue jsi18np(QScriptContext *context, QScriptEngine *engine);
|
||||
QScriptValue jsi18ncp(QScriptContext *context, QScriptEngine *engine);
|
||||
void bindI18N(QScriptEngine *engine);
|
||||
|
||||
#endif //I18N_P_H
|
||||
|
|
@ -1,112 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2009 Aaron J. Seigo <aseigo@kde.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Library General Public License version 2 as
|
||||
* published by the Free Software Foundation
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this program; if not, write to the
|
||||
* Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include <QtScript/QScriptValue>
|
||||
#include <QtScript/QScriptEngine>
|
||||
#include <QtScript/QScriptContext>
|
||||
|
||||
#include <kicon.h>
|
||||
|
||||
#include "backportglobal.h"
|
||||
|
||||
Q_DECLARE_METATYPE(QIcon)
|
||||
Q_DECLARE_METATYPE(QIcon*)
|
||||
Q_DECLARE_METATYPE(KIcon)
|
||||
Q_DECLARE_METATYPE(KIcon*)
|
||||
|
||||
static QScriptValue iconCtor(QScriptContext *ctx, QScriptEngine *eng)
|
||||
{
|
||||
if (ctx->argumentCount() > 0) {
|
||||
QScriptValue v = ctx->argument(0);
|
||||
if (v.isString()) {
|
||||
QIcon icon = KIcon(v.toString());
|
||||
return qScriptValueFromValue(eng, icon);
|
||||
} else if (v.isVariant()) {
|
||||
QVariant variant = v.toVariant();
|
||||
QPixmap p = variant.value<QPixmap>();
|
||||
if (!p.isNull()) {
|
||||
return qScriptValueFromValue(eng, QIcon(p));
|
||||
}
|
||||
}
|
||||
}
|
||||
return qScriptValueFromValue(eng, QIcon());
|
||||
}
|
||||
|
||||
static QScriptValue iconAddPixmap(QScriptContext *ctx, QScriptEngine *eng)
|
||||
{
|
||||
DECLARE_SELF(QIcon, addPixmap);
|
||||
|
||||
if (ctx->argumentCount() > 0) {
|
||||
QScriptValue arg = ctx->argument(0);
|
||||
|
||||
if (arg.isVariant()) {
|
||||
QVariant variant = arg.toVariant();
|
||||
QPixmap p = variant.value<QPixmap>();
|
||||
if (!p.isNull()) {
|
||||
self->addPixmap(p);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return eng->undefinedValue();
|
||||
}
|
||||
|
||||
static QScriptValue iconAddFile(QScriptContext *ctx, QScriptEngine *eng)
|
||||
{
|
||||
DECLARE_SELF(QIcon, addFile);
|
||||
|
||||
if (ctx->argumentCount() > 0) {
|
||||
QScriptValue arg = ctx->argument(0);
|
||||
|
||||
if (arg.isString()) {
|
||||
self->addFile(arg.toString());
|
||||
}
|
||||
}
|
||||
|
||||
return eng->undefinedValue();
|
||||
}
|
||||
|
||||
static QScriptValue iconIsNull(QScriptContext *ctx, QScriptEngine *eng)
|
||||
{
|
||||
Q_UNUSED(eng)
|
||||
DECLARE_SELF(QIcon, null);
|
||||
return self->isNull();
|
||||
}
|
||||
|
||||
QScriptValue constructIconClass(QScriptEngine *eng)
|
||||
{
|
||||
QScriptValue proto = qScriptValueFromValue(eng, QIcon());
|
||||
QScriptValue::PropertyFlags getter = QScriptValue::PropertyGetter;
|
||||
// QScriptValue::PropertyFlags setter = QScriptValue::PropertySetter;
|
||||
proto.setProperty("addPixmap", eng->newFunction(iconAddPixmap));
|
||||
proto.setProperty("addFile", eng->newFunction(iconAddFile));
|
||||
proto.setProperty("null", eng->newFunction(iconIsNull), getter);
|
||||
|
||||
QScriptValue ctorFun = eng->newFunction(iconCtor, proto);
|
||||
ADD_ENUM_VALUE(ctorFun, QIcon, Normal);
|
||||
ADD_ENUM_VALUE(ctorFun, QIcon, Disabled);
|
||||
ADD_ENUM_VALUE(ctorFun, QIcon, Active);
|
||||
ADD_ENUM_VALUE(ctorFun, QIcon, Selected);
|
||||
ADD_ENUM_VALUE(ctorFun, QIcon, Off);
|
||||
ADD_ENUM_VALUE(ctorFun, QIcon, On);
|
||||
|
||||
eng->setDefaultPrototype(qMetaTypeId<QIcon>(), proto);
|
||||
|
||||
return ctorFun;
|
||||
}
|
||||
|
|
@ -1,101 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2023 Ivailo Monev <xakepa10@gmail.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Library General Public License version 2 as
|
||||
* published by the Free Software Foundation
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this program; if not, write to the
|
||||
* Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include <QtScript/QScriptValue>
|
||||
#include <QtScript/QScriptEngine>
|
||||
#include <QtScript/QScriptContext>
|
||||
|
||||
#include <QImage>
|
||||
#include <QPixmap>
|
||||
|
||||
#include "backportglobal.h"
|
||||
|
||||
Q_DECLARE_METATYPE(QImage)
|
||||
Q_DECLARE_METATYPE(QImage*)
|
||||
Q_DECLARE_METATYPE(QPixmap)
|
||||
Q_DECLARE_METATYPE(QPixmap*)
|
||||
|
||||
static QScriptValue imageCtor(QScriptContext *ctx, QScriptEngine *eng)
|
||||
{
|
||||
if (ctx->argumentCount() > 0) {
|
||||
QScriptValue v = ctx->argument(0);
|
||||
if (v.isString()) {
|
||||
return qScriptValueFromValue(eng, QImage(v.toString()));
|
||||
} else if (v.isVariant()) {
|
||||
QVariant variant = v.toVariant();
|
||||
QPixmap p = variant.value<QPixmap>();
|
||||
if (!p.isNull()) {
|
||||
return qScriptValueFromValue(eng, p.toImage());
|
||||
}
|
||||
}
|
||||
}
|
||||
return qScriptValueFromValue(eng, QImage());
|
||||
}
|
||||
|
||||
static QScriptValue imageIsNull(QScriptContext *ctx, QScriptEngine *eng)
|
||||
{
|
||||
Q_UNUSED(eng)
|
||||
DECLARE_SELF(QImage, null);
|
||||
return self->isNull();
|
||||
}
|
||||
|
||||
static QScriptValue imageWidth(QScriptContext *ctx, QScriptEngine *eng)
|
||||
{
|
||||
Q_UNUSED(eng)
|
||||
DECLARE_SELF(QImage, width);
|
||||
return self->width();
|
||||
}
|
||||
|
||||
static QScriptValue imageHeight(QScriptContext *ctx, QScriptEngine *eng)
|
||||
{
|
||||
Q_UNUSED(eng)
|
||||
DECLARE_SELF(QImage, height);
|
||||
return self->height();
|
||||
}
|
||||
|
||||
static QScriptValue imageDepth(QScriptContext *ctx, QScriptEngine *eng)
|
||||
{
|
||||
Q_UNUSED(eng)
|
||||
DECLARE_SELF(QImage, depth);
|
||||
return self->depth();
|
||||
}
|
||||
|
||||
static QScriptValue imageHasAlphaChannel(QScriptContext *ctx, QScriptEngine *eng)
|
||||
{
|
||||
Q_UNUSED(eng)
|
||||
DECLARE_SELF(QImage, hasAlphaChannel);
|
||||
return self->hasAlphaChannel();
|
||||
}
|
||||
|
||||
QScriptValue constructImageClass(QScriptEngine *eng)
|
||||
{
|
||||
QScriptValue proto = qScriptValueFromValue(eng, QImage());
|
||||
QScriptValue::PropertyFlags getter = QScriptValue::PropertyGetter;
|
||||
// QScriptValue::PropertyFlags setter = QScriptValue::PropertySetter;
|
||||
proto.setProperty("null", eng->newFunction(imageIsNull), getter);
|
||||
proto.setProperty("width", eng->newFunction(imageWidth), getter);
|
||||
proto.setProperty("height", eng->newFunction(imageHeight), getter);
|
||||
proto.setProperty("depth", eng->newFunction(imageDepth), getter);
|
||||
proto.setProperty("hasAlphaChannel", eng->newFunction(imageHasAlphaChannel), getter);
|
||||
|
||||
QScriptValue ctorFun = eng->newFunction(imageCtor, proto);
|
||||
|
||||
eng->setDefaultPrototype(qMetaTypeId<QImage>(), proto);
|
||||
|
||||
return ctorFun;
|
||||
}
|
|
@ -1,116 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2023 Ivailo Monev <xakepa10@gmail.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Library General Public License version 2 as
|
||||
* published by the Free Software Foundation
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this program; if not, write to the
|
||||
* Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include <QtScript/QScriptValue>
|
||||
#include <QtScript/QScriptEngine>
|
||||
#include <QtScript/QScriptContext>
|
||||
|
||||
#include <QLocale>
|
||||
|
||||
#include "backportglobal.h"
|
||||
|
||||
Q_DECLARE_METATYPE(QLocale)
|
||||
Q_DECLARE_METATYPE(QLocale*)
|
||||
|
||||
static QScriptValue localeCtor(QScriptContext *ctx, QScriptEngine *eng)
|
||||
{
|
||||
if (ctx->argumentCount() > 0) {
|
||||
QScriptValue v = ctx->argument(0);
|
||||
if (v.isString()) {
|
||||
return qScriptValueFromValue(eng, QLocale(v.toString()));
|
||||
}
|
||||
}
|
||||
return qScriptValueFromValue(eng, QLocale());
|
||||
}
|
||||
|
||||
static QScriptValue localeName(QScriptContext *ctx, QScriptEngine *eng)
|
||||
{
|
||||
Q_UNUSED(eng)
|
||||
DECLARE_SELF(QLocale, name);
|
||||
return self->name();
|
||||
}
|
||||
|
||||
static QScriptValue localeDecimalPoint(QScriptContext *ctx, QScriptEngine *eng)
|
||||
{
|
||||
Q_UNUSED(eng)
|
||||
DECLARE_SELF(QLocale, decimalPoint);
|
||||
return QString(self->decimalPoint());
|
||||
}
|
||||
|
||||
static QScriptValue localeGroupSeparator(QScriptContext *ctx, QScriptEngine *eng)
|
||||
{
|
||||
Q_UNUSED(eng)
|
||||
DECLARE_SELF(QLocale, groupSeparator);
|
||||
return QString(self->groupSeparator());
|
||||
}
|
||||
|
||||
static QScriptValue localePercent(QScriptContext *ctx, QScriptEngine *eng)
|
||||
{
|
||||
Q_UNUSED(eng)
|
||||
DECLARE_SELF(QLocale, percent);
|
||||
return QString(self->percent());
|
||||
}
|
||||
|
||||
static QScriptValue localeZeroDigit(QScriptContext *ctx, QScriptEngine *eng)
|
||||
{
|
||||
Q_UNUSED(eng)
|
||||
DECLARE_SELF(QLocale, zeroDigit);
|
||||
return QString(self->zeroDigit());
|
||||
}
|
||||
|
||||
static QScriptValue localeNegativeSign(QScriptContext *ctx, QScriptEngine *eng)
|
||||
{
|
||||
Q_UNUSED(eng)
|
||||
DECLARE_SELF(QLocale, negativeSign);
|
||||
return QString(self->negativeSign());
|
||||
}
|
||||
|
||||
static QScriptValue localePositiveSign(QScriptContext *ctx, QScriptEngine *eng)
|
||||
{
|
||||
Q_UNUSED(eng)
|
||||
DECLARE_SELF(QLocale, positiveSign);
|
||||
return QString(self->positiveSign());
|
||||
}
|
||||
|
||||
static QScriptValue localeExponential(QScriptContext *ctx, QScriptEngine *eng)
|
||||
{
|
||||
Q_UNUSED(eng)
|
||||
DECLARE_SELF(QLocale, exponential);
|
||||
return QString(self->exponential());
|
||||
}
|
||||
|
||||
QScriptValue constructLocaleClass(QScriptEngine *eng)
|
||||
{
|
||||
QScriptValue proto = qScriptValueFromValue(eng, QLocale());
|
||||
QScriptValue::PropertyFlags getter = QScriptValue::PropertyGetter;
|
||||
// QScriptValue::PropertyFlags setter = QScriptValue::PropertySetter;
|
||||
proto.setProperty("name", eng->newFunction(localeName), getter);
|
||||
proto.setProperty("decimalPoint", eng->newFunction(localeDecimalPoint), getter);
|
||||
proto.setProperty("groupSeparator", eng->newFunction(localeGroupSeparator), getter);
|
||||
proto.setProperty("percent", eng->newFunction(localePercent), getter);
|
||||
proto.setProperty("zeroDigit", eng->newFunction(localeZeroDigit), getter);
|
||||
proto.setProperty("negativeSign", eng->newFunction(localeNegativeSign), getter);
|
||||
proto.setProperty("positiveSign", eng->newFunction(localePositiveSign), getter);
|
||||
proto.setProperty("exponential", eng->newFunction(localeExponential), getter);
|
||||
|
||||
QScriptValue ctorFun = eng->newFunction(localeCtor, proto);
|
||||
|
||||
eng->setDefaultPrototype(qMetaTypeId<QLocale>(), proto);
|
||||
|
||||
return ctorFun;
|
||||
}
|
|
@ -1,114 +0,0 @@
|
|||
/*
|
||||
* Copyright 2007-2008 Richard J. Moore <rich@kde.org>
|
||||
* Copyright 2009 Aaron J. Seigo <aseigo@kde.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Library General Public License version 2 as
|
||||
* published by the Free Software Foundation
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this program; if not, write to the
|
||||
* Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include <QtScript/QScriptEngine>
|
||||
#include <QtScript/QScriptValueIterator>
|
||||
|
||||
#include <config-kdeclarative.h>
|
||||
|
||||
#include <kconfiggroup.h>
|
||||
#include <kjob.h>
|
||||
#ifndef KDECLARATIVE_NO_KIO
|
||||
#include <kio/global.h>
|
||||
#include <kio/job.h>
|
||||
#endif
|
||||
#include <ksharedconfig.h>
|
||||
|
||||
Q_DECLARE_METATYPE(KConfigGroup)
|
||||
|
||||
Q_DECLARE_METATYPE(KJob *)
|
||||
|
||||
typedef KJob* KJobPtr;
|
||||
QScriptValue qScriptValueFromKJob(QScriptEngine *engine, const KJobPtr &job)
|
||||
{
|
||||
return engine->newQObject(const_cast<KJob *>(job), QScriptEngine::AutoOwnership, QScriptEngine::PreferExistingWrapperObject);
|
||||
}
|
||||
|
||||
void qKJobFromQScriptValue(const QScriptValue &scriptValue, KJobPtr &job)
|
||||
{
|
||||
QObject *obj = scriptValue.toQObject();
|
||||
job = static_cast<KJob *>(obj);
|
||||
}
|
||||
|
||||
#ifndef KDECLARATIVE_NO_KIO
|
||||
Q_DECLARE_METATYPE(KIO::Job *)
|
||||
typedef KIO::Job* KioJobPtr;
|
||||
QScriptValue qScriptValueFromKIOJob(QScriptEngine *engine, const KioJobPtr &job)
|
||||
{
|
||||
return engine->newQObject(const_cast<KIO::Job *>(job), QScriptEngine::AutoOwnership, QScriptEngine::PreferExistingWrapperObject);
|
||||
}
|
||||
|
||||
void qKIOJobFromQScriptValue(const QScriptValue &scriptValue, KioJobPtr &job)
|
||||
{
|
||||
QObject *obj = scriptValue.toQObject();
|
||||
job = static_cast<KIO::Job *>(obj);
|
||||
}
|
||||
#endif
|
||||
|
||||
QScriptValue qScriptValueFromKConfigGroup(QScriptEngine *engine, const KConfigGroup &config)
|
||||
{
|
||||
QScriptValue obj = engine->newObject();
|
||||
|
||||
if (!config.isValid()) {
|
||||
return obj;
|
||||
}
|
||||
|
||||
QMap<QString, QString> entryMap = config.entryMap();
|
||||
QMapIterator<QString, QString> it(entryMap);
|
||||
|
||||
//setting the group name
|
||||
obj.setProperty("__file", QScriptValue(engine, config.config()->name()));
|
||||
obj.setProperty("__name", QScriptValue(engine, config.name()));
|
||||
|
||||
//setting the key/value pairs
|
||||
while(it.hasNext()) {
|
||||
it.next();
|
||||
//kDebug() << "setting" << it.key() << "to" << it.value();
|
||||
QString prop = it.key();
|
||||
prop.replace(' ', '_');
|
||||
obj.setProperty(prop, it.value());
|
||||
}
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
void kConfigGroupFromScriptValue(const QScriptValue& obj, KConfigGroup &config)
|
||||
{
|
||||
config = KConfigGroup(KSharedConfig::openConfig(obj.property("__file").toString()), obj.property("__name").toString());
|
||||
|
||||
QScriptValueIterator it(obj);
|
||||
|
||||
while (it.hasNext()) {
|
||||
it.next();
|
||||
//kDebug() << it.name() << "is" << it.value().toString();
|
||||
if (it.name() != "__name") {
|
||||
config.writeEntry(it.name(), it.value().toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void registerNonGuiMetaTypes(QScriptEngine *engine)
|
||||
{
|
||||
qScriptRegisterMetaType<KConfigGroup>(engine, qScriptValueFromKConfigGroup, kConfigGroupFromScriptValue, QScriptValue());
|
||||
qScriptRegisterMetaType<KJob *>(engine, qScriptValueFromKJob, qKJobFromQScriptValue);
|
||||
#ifndef KDECLARATIVE_NO_KIO
|
||||
qScriptRegisterMetaType<KIO::Job *>(engine, qScriptValueFromKIOJob, qKIOJobFromQScriptValue);
|
||||
#endif
|
||||
}
|
||||
|
|
@ -1,117 +0,0 @@
|
|||
/*
|
||||
* Copyright 2007 Richard J. Moore <rich@kde.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Library General Public License version 2 as
|
||||
* published by the Free Software Foundation
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this program; if not, write to the
|
||||
* Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include <QtScript/QScriptValue>
|
||||
#include <QtScript/QScriptEngine>
|
||||
#include <QtScript/QScriptContext>
|
||||
#include <kurl.h>
|
||||
#include "backportglobal.h"
|
||||
|
||||
Q_DECLARE_METATYPE(KUrl*)
|
||||
//Q_DECLARE_METATYPE(KUrl) unneeded; found in kurl.h
|
||||
|
||||
static QScriptValue urlCtor(QScriptContext *ctx, QScriptEngine *eng)
|
||||
{
|
||||
if (ctx->argumentCount() == 1)
|
||||
{
|
||||
QString url = ctx->argument(0).toString();
|
||||
return qScriptValueFromValue(eng, KUrl(url));
|
||||
}
|
||||
|
||||
return qScriptValueFromValue(eng, KUrl());
|
||||
}
|
||||
|
||||
static QScriptValue toString(QScriptContext *ctx, QScriptEngine *eng)
|
||||
{
|
||||
DECLARE_SELF(KUrl, toString);
|
||||
return QScriptValue(eng, self->prettyUrl());
|
||||
}
|
||||
|
||||
static QScriptValue protocol(QScriptContext *ctx, QScriptEngine *eng)
|
||||
{
|
||||
DECLARE_SELF(KUrl, protocol);
|
||||
if (ctx->argumentCount()) {
|
||||
QString v = ctx->argument(0).toString();
|
||||
self->setScheme(v);
|
||||
}
|
||||
|
||||
return QScriptValue(eng, self->protocol());
|
||||
}
|
||||
|
||||
static QScriptValue host(QScriptContext *ctx, QScriptEngine *eng)
|
||||
{
|
||||
DECLARE_SELF(KUrl, protocol);
|
||||
if (ctx->argumentCount()) {
|
||||
QString v = ctx->argument(0).toString();
|
||||
self->setHost(v);
|
||||
}
|
||||
|
||||
return QScriptValue(eng, self->host());
|
||||
}
|
||||
|
||||
static QScriptValue path(QScriptContext *ctx, QScriptEngine *eng)
|
||||
{
|
||||
DECLARE_SELF(KUrl, path);
|
||||
if (ctx->argumentCount()) {
|
||||
QString v = ctx->argument(0).toString();
|
||||
self->setPath(v);
|
||||
}
|
||||
|
||||
return QScriptValue(eng, self->path());
|
||||
}
|
||||
|
||||
static QScriptValue user(QScriptContext *ctx, QScriptEngine *eng)
|
||||
{
|
||||
DECLARE_SELF(KUrl, user);
|
||||
if (ctx->argumentCount()) {
|
||||
QString v = ctx->argument(0).toString();
|
||||
self->setUserName(v);
|
||||
}
|
||||
|
||||
return QScriptValue(eng, self->userName());
|
||||
}
|
||||
|
||||
static QScriptValue password(QScriptContext *ctx, QScriptEngine *eng)
|
||||
{
|
||||
DECLARE_SELF(KUrl, password);
|
||||
if (ctx->argumentCount()) {
|
||||
QString v = ctx->argument(0).toString();
|
||||
self->setPassword(v);
|
||||
}
|
||||
|
||||
return QScriptValue(eng, self->password());
|
||||
}
|
||||
|
||||
QScriptValue constructKUrlClass(QScriptEngine *eng)
|
||||
{
|
||||
QScriptValue proto = qScriptValueFromValue(eng, KUrl());
|
||||
QScriptValue::PropertyFlags getter = QScriptValue::PropertyGetter;
|
||||
QScriptValue::PropertyFlags setter = QScriptValue::PropertySetter;
|
||||
|
||||
proto.setProperty("toString", eng->newFunction(toString), getter);
|
||||
proto.setProperty("protocol", eng->newFunction(protocol), getter | setter);
|
||||
proto.setProperty("host", eng->newFunction(host), getter | setter);
|
||||
proto.setProperty("path", eng->newFunction(path), getter | setter);
|
||||
proto.setProperty("user", eng->newFunction(user), getter | setter);
|
||||
proto.setProperty("password", eng->newFunction(password), getter | setter);
|
||||
|
||||
eng->setDefaultPrototype(qMetaTypeId<KUrl*>(), proto);
|
||||
eng->setDefaultPrototype(qMetaTypeId<KUrl>(), proto);
|
||||
|
||||
return eng->newFunction(urlCtor, proto);
|
||||
}
|
|
@ -1,2 +0,0 @@
|
|||
#cmakedefine KDECLARATIVE_NO_KIO
|
||||
|
|
@ -1,213 +0,0 @@
|
|||
/*
|
||||
* Copyright 2011 Marco Martin <mart@kde.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Library General Public License as
|
||||
* published by the Free Software Foundation; either version 2, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this program; if not, write to the
|
||||
* Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "kdeclarative.h"
|
||||
#include "bindings/i18n_p.h"
|
||||
#include "private/kdeclarative_p.h"
|
||||
#include "private/engineaccess_p.h"
|
||||
#include "private/kiconprovider_p.h"
|
||||
|
||||
#include <QtDeclarative/QDeclarativeComponent>
|
||||
#include <QtDeclarative/QDeclarativeContext>
|
||||
#include <QtDeclarative/QDeclarativeEngine>
|
||||
#include <QtDeclarative/QDeclarativeExpression>
|
||||
#include <QtScript/QScriptEngine>
|
||||
#include <QtScript/QScriptValueIterator>
|
||||
#include <QtScript/QScriptEngineAgent>
|
||||
#include <QtScript/QScriptContextInfo>
|
||||
#include <kcmdlineargs.h>
|
||||
#include <kdebug.h>
|
||||
#include <kglobal.h>
|
||||
#include <kstandarddirs.h>
|
||||
#include <kurl.h>
|
||||
#include <kconfiggroup.h>
|
||||
#include <ksharedconfig.h>
|
||||
|
||||
void registerNonGuiMetaTypes(QScriptEngine *engine);
|
||||
QScriptValue constructIconClass(QScriptEngine *engine);
|
||||
QScriptValue constructImageClass(QScriptEngine *engine);
|
||||
QScriptValue constructLocaleClass(QScriptEngine *engine);
|
||||
QScriptValue constructKUrlClass(QScriptEngine *engine);
|
||||
|
||||
class KScriptEngineAgent : public QScriptEngineAgent
|
||||
{
|
||||
public:
|
||||
KScriptEngineAgent(QScriptEngine *engine);
|
||||
|
||||
// reimplementation
|
||||
void exceptionThrow(qint64 scriptId, const QScriptValue &exception, bool hasHandler) final;
|
||||
|
||||
private:
|
||||
Q_DISABLE_COPY(KScriptEngineAgent);
|
||||
};
|
||||
|
||||
KScriptEngineAgent::KScriptEngineAgent(QScriptEngine *engine)
|
||||
: QScriptEngineAgent(engine)
|
||||
{
|
||||
engine->setAgent(this);
|
||||
};
|
||||
|
||||
void KScriptEngineAgent::exceptionThrow(qint64 scriptId, const QScriptValue &exception, bool hasHandler)
|
||||
{
|
||||
// qDebug() << Q_FUNC_INFO << scriptId;
|
||||
|
||||
if (!hasHandler) {
|
||||
QScriptEngine* engine = QScriptEngineAgent::engine();
|
||||
if (Q_UNLIKELY(!engine)) {
|
||||
kWarning() << "No engine";
|
||||
return;
|
||||
}
|
||||
|
||||
QScriptContext* engineContext = engine->currentContext();
|
||||
if (Q_UNLIKELY(!engineContext)) {
|
||||
kWarning() << "No engine context";
|
||||
return;
|
||||
}
|
||||
|
||||
QScriptContextInfo contextInfo(engineContext);
|
||||
const QString infoFile = contextInfo.fileName();
|
||||
const QString infoLine = QString::number(contextInfo.lineNumber());
|
||||
const QString infoString = QString::fromLatin1("%1:%2").arg(infoFile, infoLine);
|
||||
kDebug() << infoString << exception.toString();
|
||||
}
|
||||
}
|
||||
|
||||
KDeclarativePrivate::KDeclarativePrivate()
|
||||
{
|
||||
}
|
||||
|
||||
KDeclarative::KDeclarative()
|
||||
: d(new KDeclarativePrivate)
|
||||
{
|
||||
}
|
||||
|
||||
KDeclarative::~KDeclarative()
|
||||
{
|
||||
delete d;
|
||||
}
|
||||
|
||||
|
||||
void KDeclarative::setDeclarativeEngine(QDeclarativeEngine *engine)
|
||||
{
|
||||
if (d->declarativeEngine.data() == engine) {
|
||||
return;
|
||||
}
|
||||
d->declarativeEngine = engine;
|
||||
}
|
||||
|
||||
QDeclarativeEngine *KDeclarative::declarativeEngine() const
|
||||
{
|
||||
return d->declarativeEngine.data();
|
||||
}
|
||||
|
||||
void KDeclarative::initialize()
|
||||
{
|
||||
//Glorious hack:steal the engine
|
||||
//create the access object
|
||||
EngineAccess *engineAccess = new EngineAccess(this);
|
||||
d->declarativeEngine.data()->rootContext()->setContextProperty("__engineAccess", engineAccess);
|
||||
|
||||
//make engineaccess set our d->scriptengine
|
||||
QDeclarativeExpression *expr = new QDeclarativeExpression(d->declarativeEngine.data()->rootContext(), d->declarativeEngine.data()->rootContext()->contextObject(), "__engineAccess.setEngine(this)");
|
||||
expr->evaluate();
|
||||
delete expr;
|
||||
|
||||
//we don't need engineaccess anymore
|
||||
d->declarativeEngine.data()->rootContext()->setContextProperty("__engineAccess", 0);
|
||||
engineAccess->deleteLater();
|
||||
|
||||
//fail?
|
||||
if (!d->scriptEngine) {
|
||||
kWarning() << "Failed to get the script engine";
|
||||
return;
|
||||
}
|
||||
|
||||
//change the old globalobject with a new read/write copy
|
||||
QScriptValue originalGlobalObject = d->scriptEngine.data()->globalObject();
|
||||
|
||||
QScriptValue newGlobalObject = d->scriptEngine.data()->newObject();
|
||||
|
||||
QScriptValueIterator iter(originalGlobalObject);
|
||||
while (iter.hasNext()) {
|
||||
iter.next();
|
||||
|
||||
if (iter.name() == QLatin1String("version")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
newGlobalObject.setProperty(iter.scriptName(), iter.value());
|
||||
}
|
||||
|
||||
d->scriptEngine.data()->setGlobalObject(newGlobalObject);
|
||||
}
|
||||
|
||||
void KDeclarative::setupBindings()
|
||||
{
|
||||
QScriptEngine *engine = d->scriptEngine.data();
|
||||
if (!engine) {
|
||||
return;
|
||||
}
|
||||
|
||||
/*tell the engine to search for import in the kde4 plugin dirs.
|
||||
addImportPath adds the path at the beginning, so to honour user's
|
||||
paths we need to traverse the list in reverse order*/
|
||||
|
||||
const QStringList importPathList = KGlobal::dirs()->findDirs("module", "imports");
|
||||
QStringListIterator importPathIterator(importPathList);
|
||||
importPathIterator.toBack();
|
||||
while (importPathIterator.hasPrevious()) {
|
||||
d->declarativeEngine.data()->addImportPath(importPathIterator.previous());
|
||||
}
|
||||
|
||||
QScriptValue global = engine->globalObject();
|
||||
|
||||
//KConfig and KJob
|
||||
registerNonGuiMetaTypes(d->scriptEngine.data());
|
||||
|
||||
// Stuff from Katie
|
||||
global.setProperty("QIcon", constructIconClass(engine));
|
||||
global.setProperty("QImage", constructImageClass(engine));
|
||||
global.setProperty("QLocale", constructLocaleClass(engine));
|
||||
|
||||
// Add stuff from KDE libs
|
||||
bindI18N(engine);
|
||||
qScriptRegisterSequenceMetaType<KUrl::List>(engine);
|
||||
global.setProperty("Url", constructKUrlClass(engine));
|
||||
|
||||
// setup ImageProvider for KDE icons
|
||||
d->declarativeEngine.data()->addImageProvider(QString("icon"), new KIconProvider);
|
||||
|
||||
// the engine should take ownership
|
||||
(void)new KScriptEngineAgent(engine);
|
||||
}
|
||||
|
||||
QScriptEngine *KDeclarative::scriptEngine() const
|
||||
{
|
||||
return d->scriptEngine.data();
|
||||
}
|
||||
|
||||
QString KDeclarative::defaultComponentsTarget()
|
||||
{
|
||||
return QLatin1String("desktop");
|
||||
}
|
||||
|
||||
QString KDeclarative::componentsTarget()
|
||||
{
|
||||
return defaultComponentsTarget();
|
||||
}
|
|
@ -1,65 +0,0 @@
|
|||
/*
|
||||
* Copyright 2011 Marco Martin <mart@kde.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Library General Public License as
|
||||
* published by the Free Software Foundation; either version 2, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this program; if not, write to the
|
||||
* Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef KDECLARATIVE_H
|
||||
#define KDECLARATIVE_H
|
||||
|
||||
#include <kdeclarative_export.h>
|
||||
|
||||
#include <QStringList>
|
||||
|
||||
#include <QDeclarativeEngine>
|
||||
#include <QScriptEngine>
|
||||
|
||||
class KDeclarativePrivate;
|
||||
|
||||
class KDECLARATIVE_EXPORT KDeclarative
|
||||
{
|
||||
public:
|
||||
explicit KDeclarative();
|
||||
~KDeclarative();
|
||||
|
||||
void initialize();
|
||||
void setupBindings();
|
||||
|
||||
void setDeclarativeEngine(QDeclarativeEngine *engine);
|
||||
QDeclarativeEngine *declarativeEngine() const;
|
||||
|
||||
QScriptEngine *scriptEngine() const;
|
||||
|
||||
/**
|
||||
* @return the QML components target, e.g. "desktop", "tablet" or "touch". The string relates
|
||||
* to the platform form factor.
|
||||
* @since 4.10
|
||||
*/
|
||||
static QString componentsTarget();
|
||||
|
||||
/**
|
||||
* @return the default components target; can be used to compare against the returned value
|
||||
* from @see componentsTarget()
|
||||
* @since 4.10
|
||||
*/
|
||||
static QString defaultComponentsTarget();
|
||||
|
||||
private:
|
||||
KDeclarativePrivate *const d;
|
||||
friend class EngineAccess;
|
||||
};
|
||||
|
||||
#endif
|
|
@ -1,41 +0,0 @@
|
|||
/*
|
||||
* Copyright 2010 Marco Martin <mart@kde.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Library General Public License as
|
||||
* published by the Free Software Foundation; either version 2, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this program; if not, write to the
|
||||
* Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "engineaccess_p.h"
|
||||
#include "kdeclarative.h"
|
||||
#include "kdeclarative_p.h"
|
||||
|
||||
#include <QtScript/QScriptEngine>
|
||||
|
||||
EngineAccess::EngineAccess(KDeclarative *parent)
|
||||
: QObject(0),
|
||||
m_kDeclarative(parent)
|
||||
{
|
||||
}
|
||||
|
||||
EngineAccess::~EngineAccess()
|
||||
{
|
||||
}
|
||||
|
||||
void EngineAccess::setEngine(QScriptValue val)
|
||||
{
|
||||
m_kDeclarative->d->scriptEngine = val.engine();
|
||||
}
|
||||
|
||||
#include "moc_engineaccess_p.cpp"
|
|
@ -1,45 +0,0 @@
|
|||
/*
|
||||
* Copyright 2010 Marco Martin <mart@kde.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Library General Public License as
|
||||
* published by the Free Software Foundation; either version 2, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this program; if not, write to the
|
||||
* Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef ENGINEACCESS_P_H
|
||||
#define ENGINEACCESS_P_H
|
||||
|
||||
#include <QtCore/QObject>
|
||||
|
||||
#include <QtScript/QScriptValue>
|
||||
|
||||
class KDeclarative;
|
||||
|
||||
class EngineAccess : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
|
||||
public:
|
||||
EngineAccess(KDeclarative *parent);
|
||||
~EngineAccess();
|
||||
|
||||
Q_INVOKABLE void setEngine(QScriptValue val);
|
||||
|
||||
private:
|
||||
KDeclarative *m_kDeclarative;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
|
@ -1,36 +0,0 @@
|
|||
/*
|
||||
* Copyright 2011 Marco Martin <mart@kde.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Library General Public License as
|
||||
* published by the Free Software Foundation; either version 2, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this program; if not, write to the
|
||||
* Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef KDECLARATIVE_P_H
|
||||
#define KDECLARATIVE_P_H
|
||||
|
||||
#include "kdeclarative.h"
|
||||
|
||||
#include <QtCore/qsharedpointer.h>
|
||||
|
||||
class KDeclarativePrivate
|
||||
{
|
||||
public:
|
||||
KDeclarativePrivate();
|
||||
|
||||
QWeakPointer<QDeclarativeEngine> declarativeEngine;
|
||||
QWeakPointer<QScriptEngine> scriptEngine;
|
||||
};
|
||||
|
||||
#endif
|
|
@ -1,73 +0,0 @@
|
|||
/***************************************************************************
|
||||
* Copyright 2011 Artur Duque de Souza <asouza@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 *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program; if not, write to the *
|
||||
* Free Software Foundation, Inc., *
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . *
|
||||
***************************************************************************/
|
||||
|
||||
#include "kiconprovider_p.h"
|
||||
#include "kicon.h"
|
||||
#include "kiconloader.h"
|
||||
#include "kiconeffect.h"
|
||||
|
||||
#include <QPixmap>
|
||||
#include <QSize>
|
||||
|
||||
KIconProvider::KIconProvider()
|
||||
: QDeclarativeImageProvider(QDeclarativeImageProvider::Pixmap)
|
||||
{
|
||||
}
|
||||
|
||||
QPixmap KIconProvider::requestPixmap(const QString &id, QSize *size, const QSize &requestedSize)
|
||||
{
|
||||
// handle QIcon::state
|
||||
const QStringList source = id.split('/');
|
||||
if (source.size() < 1) {
|
||||
return QDeclarativeImageProvider::requestPixmap(id, size, requestedSize);
|
||||
}
|
||||
|
||||
QPixmap pixmap;
|
||||
if (requestedSize.isValid()) {
|
||||
pixmap = KIcon(source.at(0)).pixmap(requestedSize);
|
||||
} else if (size->isValid()) {
|
||||
pixmap = KIcon(source.at(0)).pixmap(*size);
|
||||
} else {
|
||||
pixmap = KIcon(source.at(0)).pixmap(IconSize(KIconLoader::Desktop));
|
||||
}
|
||||
|
||||
if (source.size() == 2) {
|
||||
KIconEffect *effect = KIconLoader::global()->iconEffect();
|
||||
const QString state(source.at(1));
|
||||
int finalState = KIconLoader::DefaultState;
|
||||
|
||||
if (state == QLatin1String("active")) {
|
||||
finalState = KIconLoader::ActiveState;
|
||||
} else if (state == QLatin1String("disabled")) {
|
||||
finalState = KIconLoader::DisabledState;
|
||||
} else if (state == QLatin1String("last")) {
|
||||
finalState = KIconLoader::LastState;
|
||||
}
|
||||
|
||||
// apply the effect for state
|
||||
pixmap = effect->apply(pixmap, KIconLoader::Desktop, finalState);
|
||||
}
|
||||
|
||||
if (!pixmap.isNull() && size) {
|
||||
*size = pixmap.size();
|
||||
}
|
||||
|
||||
return pixmap;
|
||||
}
|
||||
|
|
@ -1,34 +0,0 @@
|
|||
/***************************************************************************
|
||||
* Copyright 2011 Artur Duque de Souza <asouza@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 *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program; if not, write to the *
|
||||
* Free Software Foundation, Inc., *
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . *
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef ICON_PROVIDER_H
|
||||
#define ICON_PROVIDER_H
|
||||
|
||||
#include <QDeclarativeImageProvider>
|
||||
|
||||
|
||||
class KIconProvider : public QDeclarativeImageProvider
|
||||
{
|
||||
|
||||
public:
|
||||
KIconProvider();
|
||||
QPixmap requestPixmap(const QString &id, QSize *size, const QSize &requestedSize) final;
|
||||
};
|
||||
|
||||
#endif
|
|
@ -30,7 +30,6 @@
|
|||
297 kdeui (KNotificationRestrictions)
|
||||
299 kdeui (KNotification)
|
||||
300 kdeui (KConfigDialogManager)
|
||||
301 kdeui (KDBusMenu)
|
||||
700 kutils (KSettings::Dialog)
|
||||
701 kutils (KSettings::Dispatcher)
|
||||
702 kutils (KPluginSelector)
|
||||
|
|
|
@ -278,7 +278,6 @@ KCmdLineArgsStatic::KCmdLineArgsStatic () {
|
|||
#ifdef Q_WS_X11
|
||||
kde_options.add("waitforwm", ki18n("Waits for a WM_NET compatible windowmanager"));
|
||||
#endif
|
||||
kde_options.add("tray", ki18n("Show tray icon"));
|
||||
kde_options.add("geometry <geometry>", ki18n("sets the client geometry of the main widget - see man X for the argument format (usually WidthxHeight+XPos+YPos)"));
|
||||
kde_options.add("smkey <sessionKey>"); // this option is obsolete and exists only to allow smooth upgrades from sessions
|
||||
}
|
||||
|
|
|
@ -73,8 +73,6 @@ void KAutostartTest::testStartphase_data()
|
|||
QTest::addColumn<int>("startPhase");
|
||||
if ( KAutostart::isServiceRegistered("plasma-desktop") )
|
||||
QTest::newRow("plasma-desktop") << "plasma-desktop" << (int)KAutostart::BaseDesktop;
|
||||
if ( KAutostart::isServiceRegistered("klipper") )
|
||||
QTest::newRow("klipper") << "klipper" << (int)KAutostart::Applications;
|
||||
QTest::newRow("does not exist") << "doesnotexist"
|
||||
<< (int)KAutostart::Applications;
|
||||
}
|
||||
|
|
|
@ -55,7 +55,6 @@ set(kdeui_LIB_SRCS
|
|||
actions/kdualaction.cpp
|
||||
actions/kfontaction.cpp
|
||||
actions/kfontsizeaction.cpp
|
||||
actions/kpastetextaction.cpp
|
||||
actions/krecentfilesaction.cpp
|
||||
actions/kselectaction.cpp
|
||||
actions/kstandardaction.cpp
|
||||
|
@ -154,12 +153,6 @@ set(kdeui_LIB_SRCS
|
|||
notifications/knotification.cpp
|
||||
notifications/knotificationconfigwidget.cpp
|
||||
notifications/knotificationrestrictions.cpp
|
||||
notifications/kdbusmenuexporter.cpp
|
||||
notifications/kdbusmenuimporter.cpp
|
||||
notifications/kdbusmenu_p.cpp
|
||||
notifications/ksystemtrayicon.cpp
|
||||
notifications/kstatusnotifieritem.cpp
|
||||
notifications/kstatusnotifieritemdbus_p.cpp
|
||||
paged/kpagedialog.cpp
|
||||
paged/kpageview.cpp
|
||||
paged/kpageview_p.cpp
|
||||
|
@ -257,17 +250,6 @@ set(kdeui_LIB_SRCS
|
|||
windowmanagement/netwm.cpp
|
||||
)
|
||||
|
||||
qt4_add_dbus_interface(kdeui_LIB_SRCS
|
||||
notifications/org.kde.StatusNotifierWatcher.xml
|
||||
statusnotifierwatcher_interface
|
||||
)
|
||||
|
||||
qt4_add_dbus_adaptor(kdeui_LIB_SRCS
|
||||
notifications/org.kde.StatusNotifierItem.xml
|
||||
notifications/kstatusnotifieritemdbus_p.h
|
||||
KStatusNotifierItemDBus
|
||||
)
|
||||
|
||||
if (X11_Xkb_FOUND AND X11_Xkbfile_FOUND)
|
||||
include_directories (
|
||||
${X11_Xkb_INCLUDE_PATH}
|
||||
|
@ -383,7 +365,6 @@ install(
|
|||
actions/kcodecaction.h
|
||||
actions/kfontaction.h
|
||||
actions/kfontsizeaction.h
|
||||
actions/kpastetextaction.h
|
||||
actions/krecentfilesaction.h
|
||||
actions/kselectaction.h
|
||||
actions/kstandardaction.h
|
||||
|
@ -461,13 +442,9 @@ install(
|
|||
kernel/kglobalsettings.h
|
||||
kernel/ksystemeventfilter.h
|
||||
kernel/ktoolinvocation.h
|
||||
notifications/kstatusnotifieritem.h
|
||||
notifications/ksystemtrayicon.h
|
||||
notifications/knotification.h
|
||||
notifications/knotificationconfigwidget.h
|
||||
notifications/knotificationrestrictions.h
|
||||
notifications/kdbusmenuexporter.h
|
||||
notifications/kdbusmenuimporter.h
|
||||
paged/kpagedialog.h
|
||||
paged/kpageview.h
|
||||
paged/kpagewidget.h
|
||||
|
@ -585,7 +562,5 @@ install(
|
|||
FILES
|
||||
jobs/org.kde.JobViewServer.xml
|
||||
jobs/org.kde.JobView.xml
|
||||
notifications/org.kde.StatusNotifierItem.xml
|
||||
notifications/org.kde.StatusNotifierWatcher.xml
|
||||
DESTINATION ${KDE4_DBUS_INTERFACES_INSTALL_DIR}
|
||||
)
|
||||
|
|
|
@ -1,141 +0,0 @@
|
|||
/* This file is part of the KDE libraries
|
||||
Copyright (C) 1999 Reginald Stadlbauer <reggie@kde.org>
|
||||
(C) 1999 Simon Hausmann <hausmann@kde.org>
|
||||
(C) 2000 Nicolas Hadacek <haadcek@kde.org>
|
||||
(C) 2000 Kurt Granroth <granroth@kde.org>
|
||||
(C) 2000 Michael Koch <koch@kde.org>
|
||||
(C) 2001 Holger Freyther <freyther@kde.org>
|
||||
(C) 2002 Ellis Whitehead <ellis@kde.org>
|
||||
(C) 2002 Joseph Wenninger <jowenn@kde.org>
|
||||
(C) 2003 Andras Mantia <amantia@kde.org>
|
||||
(C) 2005-2006 Hamish Rodda <rodda@kde.org>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License version 2 as published by the Free Software Foundation.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public License
|
||||
along with this library; see the file COPYING.LIB. If not, write to
|
||||
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "kpastetextaction.h"
|
||||
|
||||
#include <QtGui/QClipboard>
|
||||
#include <QtDBus/QtDBus>
|
||||
|
||||
#include <kapplication.h>
|
||||
#include <kdebug.h>
|
||||
#include <kicon.h>
|
||||
#include <klocale.h>
|
||||
|
||||
#include "kmenu.h"
|
||||
|
||||
class KPasteTextActionPrivate
|
||||
{
|
||||
public:
|
||||
KPasteTextActionPrivate(KPasteTextAction *parent)
|
||||
: q(parent),
|
||||
m_popup(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
~KPasteTextActionPrivate()
|
||||
{
|
||||
delete m_popup;
|
||||
}
|
||||
|
||||
void _k_menuAboutToShow();
|
||||
void _k_slotTriggered(QAction*);
|
||||
|
||||
void init();
|
||||
|
||||
KPasteTextAction *q;
|
||||
KMenu *m_popup;
|
||||
};
|
||||
|
||||
KPasteTextAction::KPasteTextAction(QObject *parent)
|
||||
: KAction(parent),
|
||||
d(new KPasteTextActionPrivate(this))
|
||||
{
|
||||
d->init();
|
||||
}
|
||||
|
||||
KPasteTextAction::KPasteTextAction(const QString &text, QObject *parent)
|
||||
: KAction(parent),
|
||||
d(new KPasteTextActionPrivate(this))
|
||||
{
|
||||
d->init();
|
||||
setText(text);
|
||||
}
|
||||
|
||||
KPasteTextAction::KPasteTextAction(const KIcon &icon, const QString &text, QObject *parent)
|
||||
: KAction(icon, text, parent),
|
||||
d(new KPasteTextActionPrivate(this))
|
||||
{
|
||||
d->init();
|
||||
}
|
||||
|
||||
void KPasteTextActionPrivate::init()
|
||||
{
|
||||
m_popup = new KMenu();
|
||||
q->connect(m_popup, SIGNAL(aboutToShow()), q, SLOT(_k_menuAboutToShow()));
|
||||
q->connect(m_popup, SIGNAL(triggered(QAction*)), q, SLOT(_k_slotTriggered(QAction*)));
|
||||
}
|
||||
|
||||
KPasteTextAction::~KPasteTextAction()
|
||||
{
|
||||
delete d;
|
||||
}
|
||||
|
||||
void KPasteTextActionPrivate::_k_menuAboutToShow()
|
||||
{
|
||||
m_popup->clear();
|
||||
QStringList list;
|
||||
QDBusInterface klipper("org.kde.klipper", "/klipper", "org.kde.klipper.klipper");
|
||||
if (klipper.isValid()) {
|
||||
QDBusReply<QStringList> reply = klipper.call("getClipboardHistoryMenu");
|
||||
if (reply.isValid()) {
|
||||
list = reply;
|
||||
}
|
||||
}
|
||||
QString clipboardText = qApp->clipboard()->text(QClipboard::Clipboard);
|
||||
if (list.isEmpty()) {
|
||||
list << clipboardText;
|
||||
}
|
||||
bool found = false;
|
||||
const QFontMetrics fm = m_popup->fontMetrics();
|
||||
foreach (const QString &string, list) {
|
||||
QString text = fm.elidedText(string.simplified(), Qt::ElideMiddle, fm.maxWidth() * 20);
|
||||
text.replace('&', "&&");
|
||||
QAction* action = m_popup->addAction(text);
|
||||
if (!found && string == clipboardText) {
|
||||
action->setChecked(true);
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void KPasteTextActionPrivate::_k_slotTriggered(QAction* action)
|
||||
{
|
||||
QDBusInterface klipper("org.kde.klipper", "/klipper", "org.kde.klipper.klipper");
|
||||
if (klipper.isValid()) {
|
||||
QDBusReply<QString> reply = klipper.call("getClipboardHistoryItem", m_popup->actions().indexOf(action));
|
||||
if (!reply.isValid()) {
|
||||
return;
|
||||
}
|
||||
QString clipboardText = reply;
|
||||
reply = klipper.call("setClipboardContents", clipboardText);
|
||||
if (reply.isValid()) {
|
||||
kDebug(129) << "Clipboard: " << qApp->clipboard()->text(QClipboard::Clipboard);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#include "moc_kpastetextaction.cpp"
|
|
@ -1,89 +0,0 @@
|
|||
/* This file is part of the KDE libraries
|
||||
Copyright (C) 1999 Reginald Stadlbauer <reggie@kde.org>
|
||||
(C) 1999 Simon Hausmann <hausmann@kde.org>
|
||||
(C) 2000 Nicolas Hadacek <haadcek@kde.org>
|
||||
(C) 2000 Kurt Granroth <granroth@kde.org>
|
||||
(C) 2000 Michael Koch <koch@kde.org>
|
||||
(C) 2001 Holger Freyther <freyther@kde.org>
|
||||
(C) 2002 Ellis Whitehead <ellis@kde.org>
|
||||
(C) 2003 Andras Mantia <amantia@kde.org>
|
||||
(C) 2005-2006 Hamish Rodda <rodda@kde.org>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License version 2 as published by the Free Software Foundation.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public License
|
||||
along with this library; see the file COPYING.LIB. If not, write to
|
||||
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef KPASTETEXTACTION_H
|
||||
#define KPASTETEXTACTION_H
|
||||
|
||||
#include <kaction.h>
|
||||
|
||||
|
||||
class KPasteTextActionPrivate;
|
||||
/**
|
||||
* An action for pasting text from the clipboard.
|
||||
* It's useful for text handling applications as
|
||||
* when plugged into a toolbar it provides a menu
|
||||
* with the clipboard history if klipper is running.
|
||||
* If klipper is not running, the menu has only one
|
||||
* item: the current clipboard content.
|
||||
*/
|
||||
class KDEUI_EXPORT KPasteTextAction: public KAction
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
/**
|
||||
* Constructs an action with the specified parent.
|
||||
*
|
||||
* @param parent The parent of this action.
|
||||
*/
|
||||
explicit KPasteTextAction(QObject *parent);
|
||||
|
||||
~KPasteTextAction();
|
||||
|
||||
/**
|
||||
* Constructs an action with text; a shortcut may be specified by
|
||||
* the ampersand character (e.g. \"&Option\" creates a shortcut with key \e O )
|
||||
*
|
||||
* This is the most common KAction used when you do not have a
|
||||
* corresponding icon (note that it won't appear in the current version
|
||||
* of the "Edit ToolBar" dialog, because an action needs an icon to be
|
||||
* plugged in a toolbar...).
|
||||
*
|
||||
* @param text The text that will be displayed.
|
||||
* @param parent The parent of this action.
|
||||
*/
|
||||
KPasteTextAction(const QString &text, QObject *parent);
|
||||
|
||||
/**
|
||||
* Constructs an action with text and an icon; a shortcut may be specified by
|
||||
* the ampersand character (e.g. \"&Option\" creates a shortcut with key \e O )
|
||||
*
|
||||
* This is the other common KAction used. Use it when you
|
||||
* \e do have a corresponding icon.
|
||||
*
|
||||
* @param icon The icon to display.
|
||||
* @param text The text that will be displayed.
|
||||
* @param parent The parent of this action.
|
||||
*/
|
||||
KPasteTextAction(const KIcon &icon, const QString &text, QObject *parent);
|
||||
|
||||
private:
|
||||
KPasteTextActionPrivate * const d;
|
||||
|
||||
Q_PRIVATE_SLOT(d, void _k_menuAboutToShow())
|
||||
Q_PRIVATE_SLOT(d, void _k_slotTriggered(QAction*))
|
||||
};
|
||||
|
||||
#endif
|
|
@ -40,7 +40,6 @@
|
|||
#include "kdualaction.h"
|
||||
#include "krecentfilesaction.h"
|
||||
#include "ktogglefullscreenaction.h"
|
||||
#include "kpastetextaction.h"
|
||||
#include "kactioncollection.h"
|
||||
|
||||
namespace KStandardAction
|
||||
|
@ -156,9 +155,6 @@ KAction *create(StandardAction id, const QObject *recvr, const char *slot, QObje
|
|||
pAction = new KToggleFullScreenAction(parent);
|
||||
pAction->setCheckable(true);
|
||||
break;
|
||||
case PasteText:
|
||||
pAction = new KPasteTextAction(parent);
|
||||
break;
|
||||
// Same as default, but with the app icon
|
||||
case AboutApp:
|
||||
pAction = new KAction(parent);
|
||||
|
@ -306,11 +302,6 @@ KAction *paste( const QObject *recvr, const char *slot, QObject *parent )
|
|||
return KStandardAction::create( Paste, recvr, slot, parent );
|
||||
}
|
||||
|
||||
KAction *pasteText( const QObject *recvr, const char *slot, QObject *parent )
|
||||
{
|
||||
return KStandardAction::create( PasteText, recvr, slot, parent );
|
||||
}
|
||||
|
||||
KAction *clear( const QObject *recvr, const char *slot, QObject *parent )
|
||||
{
|
||||
return KStandardAction::create( Clear, recvr, slot, parent );
|
||||
|
|
|
@ -159,7 +159,6 @@ namespace KStandardAction
|
|||
ConfigureNotifications,
|
||||
FullScreen,
|
||||
Clear,
|
||||
PasteText,
|
||||
SwitchApplicationLanguage
|
||||
};
|
||||
|
||||
|
@ -346,13 +345,6 @@ namespace KStandardAction
|
|||
*/
|
||||
KDEUI_EXPORT KAction *paste(const QObject *recvr, const char *slot, QObject *parent);
|
||||
|
||||
/**
|
||||
* Paste the contents of clipboard at the current mouse or cursor
|
||||
* position. Provide a button on the toolbar with the clipboard history
|
||||
* menu if Klipper is running.
|
||||
*/
|
||||
KDEUI_EXPORT KAction *pasteText(const QObject *recvr, const char *slot, QObject *parent);
|
||||
|
||||
/**
|
||||
* Clear the content of the focus widget
|
||||
*/
|
||||
|
|
|
@ -57,7 +57,6 @@ static const KStandardActionInfo g_rgActionInfo[] =
|
|||
{ Cut, KStandardShortcut::Cut, "edit_cut", I18N_NOOP("Cu&t"), I18N_NOOP("Cut selection to clipboard"), "edit-cut" },
|
||||
{ Copy, KStandardShortcut::Copy, "edit_copy", I18N_NOOP("&Copy"), I18N_NOOP("Copy selection to clipboard"), "edit-copy" },
|
||||
{ Paste, KStandardShortcut::Paste, "edit_paste", I18N_NOOP("&Paste"), I18N_NOOP("Paste clipboard content"), "edit-paste" },
|
||||
{ PasteText, KStandardShortcut::Paste, "edit_paste", I18N_NOOP("&Paste"), I18N_NOOP("Paste clipboard content"), "edit-paste" },
|
||||
{ Clear, KStandardShortcut::Clear, "edit_clear", I18N_NOOP("C&lear"), 0, "edit-clear" },
|
||||
{ SelectAll, KStandardShortcut::SelectAll, "edit_select_all", I18N_NOOP("Select &All"), 0, "edit-select-all" },
|
||||
{ Deselect, KStandardShortcut::Deselect, "edit_deselect", I18N_NOOP("Dese&lect"), 0, 0 },
|
||||
|
|
|
@ -57,7 +57,6 @@
|
|||
#include "kde_file.h"
|
||||
#include "kstartupinfo.h"
|
||||
#include "kcomponentdata.h"
|
||||
#include "kstatusnotifieritem.h"
|
||||
#include "kmainwindow.h"
|
||||
#include "kmenu.h"
|
||||
#include "kactioncollection.h"
|
||||
|
@ -116,155 +115,6 @@ static void quit_handler(int sig)
|
|||
qApp->quit();
|
||||
}
|
||||
|
||||
class KAppStatusNotifierItem : public KStatusNotifierItem
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
KAppStatusNotifierItem(const KComponentData &componentData, QObject* parent = nullptr);
|
||||
|
||||
private Q_SLOTS:
|
||||
void slotActivateRequested(bool active, const QPoint &pos);
|
||||
void slotSkipTaskBar();
|
||||
void slotSkipPager();
|
||||
void slotWindowChanged(WId id);
|
||||
|
||||
private:
|
||||
void updateStatus(const QString &name, const QString &icon);
|
||||
|
||||
private:
|
||||
QAction* m_skiptaskbaraction;
|
||||
QAction* m_skippageraction;
|
||||
};
|
||||
|
||||
KAppStatusNotifierItem::KAppStatusNotifierItem(const KComponentData &componentData, QObject* parent)
|
||||
: KStatusNotifierItem(QString::number(::getpid()), parent),
|
||||
m_skiptaskbaraction(nullptr),
|
||||
m_skippageraction(nullptr)
|
||||
{
|
||||
setCategory(KStatusNotifierItem::ApplicationStatus);
|
||||
setStatus(KStatusNotifierItem::Active);
|
||||
|
||||
// TODO: -icon argument override
|
||||
updateStatus(
|
||||
componentData.aboutData()->programName(),
|
||||
componentData.aboutData()->programIconName()
|
||||
);
|
||||
|
||||
connect(
|
||||
this, SIGNAL(activateRequested(bool,QPoint)),
|
||||
this, SLOT(slotActivateRequested(bool,QPoint))
|
||||
);
|
||||
|
||||
bool skiptaskbar = false;
|
||||
bool skippager = false;
|
||||
const QList<KMainWindow*> mainwindows = KMainWindow::memberList();
|
||||
foreach (const KMainWindow* mainwindow, mainwindows) {
|
||||
const WId mainwindowid = mainwindow->winId();
|
||||
NETWinInfo netwininfo(
|
||||
QX11Info::display(), mainwindowid, QX11Info::appRootWindow(),
|
||||
NET::XAWMState | NET::WMState
|
||||
);
|
||||
if (netwininfo.state() & NET::SkipTaskbar) {
|
||||
skiptaskbar = true;
|
||||
}
|
||||
if (netwininfo.state() & NET::SkipPager) {
|
||||
skippager = true;
|
||||
}
|
||||
}
|
||||
|
||||
m_skiptaskbaraction = new QAction(i18n("Skip &Taskbar"), contextMenu()->contextMenu());
|
||||
m_skiptaskbaraction->setCheckable(true);
|
||||
m_skiptaskbaraction->setChecked(skiptaskbar);
|
||||
connect(m_skiptaskbaraction, SIGNAL(triggered()), this, SLOT(slotSkipTaskBar()));
|
||||
actionCollection()->addAction("tray_skiptaskbar", m_skiptaskbaraction);
|
||||
contextMenu()->addAction(m_skiptaskbaraction);
|
||||
|
||||
m_skippageraction = new QAction(i18n("Skip &Pager"), contextMenu()->contextMenu());
|
||||
m_skippageraction->setCheckable(true);
|
||||
m_skippageraction->setChecked(skippager);
|
||||
connect(m_skippageraction, SIGNAL(triggered()), this, SLOT(slotSkipPager()));
|
||||
actionCollection()->addAction("tray_skippager", m_skippageraction);
|
||||
contextMenu()->addAction(m_skippageraction);
|
||||
|
||||
connect(KWindowSystem::self(), SIGNAL(windowChanged(WId)), this, SLOT(slotWindowChanged(WId)));
|
||||
}
|
||||
|
||||
void KAppStatusNotifierItem::updateStatus(const QString &name, const QString &icon)
|
||||
{
|
||||
if (!name.isEmpty()) {
|
||||
setTitle(name);
|
||||
} else {
|
||||
setTitle(i18n("KAppStatusNotifierItem"));
|
||||
}
|
||||
if (!icon.isEmpty()) {
|
||||
setIconByName(icon);
|
||||
} else {
|
||||
setIconByName("xorg");
|
||||
}
|
||||
setToolTip(icon, name, QString());
|
||||
}
|
||||
|
||||
void KAppStatusNotifierItem::slotActivateRequested(bool active, const QPoint &pos)
|
||||
{
|
||||
Q_UNUSED(active);
|
||||
Q_UNUSED(pos);
|
||||
const QList<KMainWindow*> mainwindows = KMainWindow::memberList();
|
||||
foreach (const KMainWindow* mainwindow, mainwindows) {
|
||||
const WId mainwindowid = mainwindow->winId();
|
||||
NETWinInfo netwininfo(
|
||||
QX11Info::display(), mainwindowid, QX11Info::appRootWindow(),
|
||||
NET::XAWMState | NET::WMState
|
||||
);
|
||||
kDebug() << "window state is" << mainwindowid << netwininfo.mappingState();
|
||||
if (netwininfo.mappingState() != NET::Visible) {
|
||||
KWindowSystem::activateWindow(mainwindowid);
|
||||
} else {
|
||||
KWindowSystem::minimizeWindow(mainwindowid);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void KAppStatusNotifierItem::slotSkipTaskBar()
|
||||
{
|
||||
const bool skiptaskbar = m_skiptaskbaraction->isChecked();
|
||||
const QList<KMainWindow*> mainwindows = KMainWindow::memberList();
|
||||
foreach (const KMainWindow* mainwindow, mainwindows) {
|
||||
const WId mainwindowid = mainwindow->winId();
|
||||
if (skiptaskbar) {
|
||||
KWindowSystem::clearState(mainwindowid, NET::SkipTaskbar);
|
||||
} else {
|
||||
KWindowSystem::setState(mainwindowid, NET::SkipTaskbar);
|
||||
}
|
||||
}
|
||||
m_skiptaskbaraction->setChecked(!skiptaskbar);
|
||||
}
|
||||
|
||||
void KAppStatusNotifierItem::slotSkipPager()
|
||||
{
|
||||
const bool skippager = m_skippageraction->isChecked();
|
||||
const QList<KMainWindow*> mainwindows = KMainWindow::memberList();
|
||||
foreach (const KMainWindow* mainwindow, mainwindows) {
|
||||
const WId mainwindowid = mainwindow->winId();
|
||||
if (skippager) {
|
||||
KWindowSystem::clearState(mainwindowid, NET::SkipPager);
|
||||
} else {
|
||||
KWindowSystem::setState(mainwindowid, NET::SkipPager);
|
||||
}
|
||||
}
|
||||
m_skippageraction->setChecked(!skippager);
|
||||
}
|
||||
|
||||
void KAppStatusNotifierItem::slotWindowChanged(WId id)
|
||||
{
|
||||
Q_UNUSED(id);
|
||||
QString subtitle;
|
||||
const QList<KMainWindow*> mainwindows = KMainWindow::memberList();
|
||||
foreach (const KMainWindow* mainwindow, mainwindows) {
|
||||
subtitle.append(QString::fromLatin1("<p>%1</p>").arg(mainwindow->windowTitle()));
|
||||
}
|
||||
setToolTipSubTitle(subtitle);
|
||||
}
|
||||
|
||||
/*
|
||||
Private data to make keeping binary compatibility easier
|
||||
*/
|
||||
|
@ -279,7 +129,6 @@ public:
|
|||
, session_save(false)
|
||||
, pSessionConfig(nullptr)
|
||||
, bSessionManagement(true)
|
||||
, statusNotifier(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -291,7 +140,6 @@ public:
|
|||
, session_save(false)
|
||||
, pSessionConfig(nullptr)
|
||||
, bSessionManagement(true)
|
||||
, statusNotifier(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -303,7 +151,6 @@ public:
|
|||
, session_save(false)
|
||||
, pSessionConfig(nullptr)
|
||||
, bSessionManagement(true)
|
||||
, statusNotifier(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -325,34 +172,8 @@ public:
|
|||
QString sessionKey;
|
||||
KConfig* pSessionConfig; //instance specific application config object
|
||||
bool bSessionManagement;
|
||||
|
||||
KAppStatusNotifierItem *statusNotifier;
|
||||
};
|
||||
|
||||
|
||||
void kAppCreateTray()
|
||||
{
|
||||
if (!kapp || kapp->d->statusNotifier) {
|
||||
return;
|
||||
}
|
||||
KCmdLineArgs *args = KCmdLineArgs::parsedArgs("kde");
|
||||
if (!args) {
|
||||
return;
|
||||
}
|
||||
if (args->isSet("tray")) {
|
||||
kapp->d->statusNotifier = new KAppStatusNotifierItem(kapp->d->componentData, kapp);
|
||||
}
|
||||
}
|
||||
|
||||
void kAppDestroyTray()
|
||||
{
|
||||
if (!kapp) {
|
||||
return;
|
||||
}
|
||||
delete kapp->d->statusNotifier;
|
||||
kapp->d->statusNotifier = nullptr;
|
||||
}
|
||||
|
||||
static QList< QWeakPointer< QWidget > > *x11Filter = 0;
|
||||
|
||||
/**
|
||||
|
@ -745,16 +566,6 @@ void KApplication::saveState( QSessionManager& sm )
|
|||
delete d->pSessionConfig;
|
||||
d->pSessionConfig = 0;
|
||||
|
||||
// tell the session manager about our new lifecycle
|
||||
QStringList restartCommand = sm.restartCommand();
|
||||
|
||||
KCmdLineArgs *args = KCmdLineArgs::parsedArgs("kde");
|
||||
if (args && args->isSet("tray")) {
|
||||
restartCommand.append(QLatin1String("-tray"));
|
||||
}
|
||||
|
||||
sm.setRestartCommand( restartCommand );
|
||||
|
||||
// finally: do session management
|
||||
bool canceled = false;
|
||||
foreach(KSessionManager* it, KSessionManager::sessionClients()) {
|
||||
|
@ -1010,4 +821,3 @@ void KApplicationPrivate::_k_disableAutorestartSlot()
|
|||
}
|
||||
|
||||
#include "moc_kapplication.cpp"
|
||||
#include "kapplication.moc"
|
||||
|
|
|
@ -1,73 +0,0 @@
|
|||
/* This file is part of the KDE libraries
|
||||
Copyright (C) 2023 Ivailo Monev <xakepa10@gmail.com>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public License
|
||||
along with this library; see the file COPYING.LIB. If not, write to
|
||||
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "kdbusmenu_p.h"
|
||||
|
||||
QDBusArgument& operator<<(QDBusArgument &argument, const KDBusMenu &kdbusmenu)
|
||||
{
|
||||
argument.beginStructure();
|
||||
argument << kdbusmenu.icon;
|
||||
argument << kdbusmenu.title;
|
||||
argument << kdbusmenu.icondata;
|
||||
argument.endStructure();
|
||||
return argument;
|
||||
}
|
||||
|
||||
const QDBusArgument& operator>>(const QDBusArgument &argument, KDBusMenu &kdbusmenu)
|
||||
{
|
||||
argument.beginStructure();
|
||||
argument >> kdbusmenu.icon;
|
||||
argument >> kdbusmenu.title;
|
||||
argument >> kdbusmenu.icondata;
|
||||
argument.endStructure();
|
||||
return argument;
|
||||
}
|
||||
|
||||
|
||||
QDBusArgument& operator<<(QDBusArgument &argument, const KDBusMenuAction &kdbusmenuaction)
|
||||
{
|
||||
argument.beginStructure();
|
||||
argument << kdbusmenuaction.id;
|
||||
argument << kdbusmenuaction.text << kdbusmenuaction.icon;
|
||||
argument << kdbusmenuaction.tooltip << kdbusmenuaction.statustip << kdbusmenuaction.whatsthis;
|
||||
argument << kdbusmenuaction.separator << kdbusmenuaction.checkable << kdbusmenuaction.checked << kdbusmenuaction.enabled << kdbusmenuaction.visible;
|
||||
argument << kdbusmenuaction.shortcuts;
|
||||
argument << kdbusmenuaction.icondata;
|
||||
argument << kdbusmenuaction.title;
|
||||
argument << kdbusmenuaction.exclusive;
|
||||
argument << kdbusmenuaction.submenu;
|
||||
argument.endStructure();
|
||||
return argument;
|
||||
}
|
||||
|
||||
const QDBusArgument& operator>>(const QDBusArgument &argument, KDBusMenuAction &kdbusmenuaction)
|
||||
{
|
||||
argument.beginStructure();
|
||||
argument >> kdbusmenuaction.id;
|
||||
argument >> kdbusmenuaction.text >> kdbusmenuaction.icon;
|
||||
argument >> kdbusmenuaction.tooltip >> kdbusmenuaction.statustip >> kdbusmenuaction.whatsthis;
|
||||
argument >> kdbusmenuaction.separator >> kdbusmenuaction.checkable >> kdbusmenuaction.checked >> kdbusmenuaction.enabled >> kdbusmenuaction.visible;
|
||||
argument >> kdbusmenuaction.shortcuts;
|
||||
argument >> kdbusmenuaction.icondata;
|
||||
argument >> kdbusmenuaction.title;
|
||||
argument >> kdbusmenuaction.exclusive;
|
||||
argument >> kdbusmenuaction.submenu;
|
||||
argument.endStructure();
|
||||
return argument;
|
||||
}
|
|
@ -1,148 +0,0 @@
|
|||
/* This file is part of the KDE libraries
|
||||
Copyright (C) 2023 Ivailo Monev <xakepa10@gmail.com>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public License
|
||||
along with this library; see the file COPYING.LIB. If not, write to
|
||||
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef KDBUSMENU_H
|
||||
#define KDBUSMENU_H
|
||||
|
||||
#include "kiconloader.h"
|
||||
#include "kdebug.h"
|
||||
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
#include <QDBusArgument>
|
||||
#include <QAction>
|
||||
#include <QMenu>
|
||||
#include <QImageWriter>
|
||||
#include <QBuffer>
|
||||
#include <QPixmap>
|
||||
|
||||
static const int s_kdbusmenuiconsize = KIconLoader::SizeSmall;
|
||||
static const QByteArray s_kdbusmenuiconformat = QImageWriter::defaultImageFormat();
|
||||
// see kdebug.areas
|
||||
static const int s_kdbusmenuarea = 301;
|
||||
|
||||
struct KDBusMenu
|
||||
{
|
||||
QString icon;
|
||||
QString title;
|
||||
QByteArray icondata;
|
||||
};
|
||||
Q_DECLARE_METATYPE(KDBusMenu);
|
||||
|
||||
QDBusArgument& operator<<(QDBusArgument &argument, const KDBusMenu &kdbusmenu);
|
||||
const QDBusArgument& operator>>(const QDBusArgument &argument, KDBusMenu &kdbusmenu);
|
||||
|
||||
struct KDBusMenuAction
|
||||
{
|
||||
quint64 id;
|
||||
QString text;
|
||||
QString icon;
|
||||
QString tooltip;
|
||||
QString statustip;
|
||||
QString whatsthis;
|
||||
bool separator;
|
||||
bool checkable;
|
||||
bool checked;
|
||||
bool enabled;
|
||||
bool visible;
|
||||
QStringList shortcuts;
|
||||
QByteArray icondata;
|
||||
bool title;
|
||||
bool exclusive;
|
||||
bool submenu;
|
||||
};
|
||||
Q_DECLARE_METATYPE(KDBusMenuAction);
|
||||
Q_DECLARE_METATYPE(QList<KDBusMenuAction>);
|
||||
|
||||
QDBusArgument& operator<<(QDBusArgument &argument, const KDBusMenuAction &kdbusmenuaction);
|
||||
const QDBusArgument& operator>>(const QDBusArgument &argument, KDBusMenuAction &kdbusmenuaction);
|
||||
|
||||
static quint64 kDBusMenuActionID(const QAction *action)
|
||||
{
|
||||
return quint64(quintptr(action));
|
||||
}
|
||||
|
||||
static QByteArray kDBusMenuIconData(const QIcon &actionicon)
|
||||
{
|
||||
QBuffer iconbuffer;
|
||||
QPixmap iconpixmap = actionicon.pixmap(s_kdbusmenuiconsize);
|
||||
if (iconpixmap.isNull()) {
|
||||
// it is common for actions to not have a icon
|
||||
kDebug(s_kdbusmenuarea) << "Action/menu icon name is empty and icon pixmap is null";
|
||||
return QByteArray();
|
||||
}
|
||||
const bool iconsaved = iconpixmap.save(&iconbuffer, s_kdbusmenuiconformat);
|
||||
if (!iconsaved) {
|
||||
kWarning(s_kdbusmenuarea) << "Could not save action/menu icon pixmap";
|
||||
return QByteArray();
|
||||
}
|
||||
return iconbuffer.data();
|
||||
}
|
||||
|
||||
static QIcon kDBusMenuIcon(const QByteArray &actionicondata)
|
||||
{
|
||||
if (actionicondata.isEmpty()) {
|
||||
// see kDBusMenuIconData()
|
||||
return QIcon();
|
||||
}
|
||||
QPixmap actionpixmap;
|
||||
const bool pixmaploaded = actionpixmap.loadFromData(actionicondata, s_kdbusmenuiconformat);
|
||||
if (!pixmaploaded) {
|
||||
kWarning(s_kdbusmenuarea) << "Could not load action/menu icon pixmap";
|
||||
return QIcon();
|
||||
}
|
||||
return QIcon(actionpixmap);
|
||||
}
|
||||
|
||||
static QAction* kDBusMenuAction(QMenu *menu, const KDBusMenuAction &actionproperties)
|
||||
{
|
||||
QAction* action = new QAction(menu);
|
||||
action->setText(actionproperties.text);
|
||||
action->setToolTip(actionproperties.tooltip);
|
||||
action->setStatusTip(actionproperties.statustip);
|
||||
action->setWhatsThis(actionproperties.whatsthis);
|
||||
action->setSeparator(actionproperties.separator);
|
||||
action->setCheckable(actionproperties.checkable);
|
||||
action->setChecked(actionproperties.checked);
|
||||
action->setEnabled(actionproperties.enabled);
|
||||
action->setVisible(actionproperties.visible);
|
||||
QList<QKeySequence> shortcuts;
|
||||
shortcuts.reserve(actionproperties.shortcuts.size());
|
||||
foreach (const QString &keysequence, actionproperties.shortcuts) {
|
||||
shortcuts.append(QKeySequence::fromString(keysequence));
|
||||
}
|
||||
action->setShortcuts(shortcuts);
|
||||
if (actionproperties.exclusive) {
|
||||
QActionGroup *actiongroup = new QActionGroup(action);
|
||||
actiongroup->addAction(action);
|
||||
}
|
||||
action->setData(QVariant(actionproperties.id));
|
||||
return action;
|
||||
}
|
||||
|
||||
static void kDBusSetIcon(QAction *action, const QIcon &icon)
|
||||
{
|
||||
// because KIcon is never null setting icon on separator makes it look odd
|
||||
if (action->isSeparator()) {
|
||||
return;
|
||||
}
|
||||
action->setIcon(icon);
|
||||
}
|
||||
|
||||
#endif // KDBUSMENU_H
|
|
@ -1,225 +0,0 @@
|
|||
/* This file is part of the KDE libraries
|
||||
Copyright (C) 2023 Ivailo Monev <xakepa10@gmail.com>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public License
|
||||
along with this library; see the file COPYING.LIB. If not, write to
|
||||
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "kdbusmenuexporter.h"
|
||||
#include "kdebug.h"
|
||||
#include "kdbusmenu_p.h"
|
||||
|
||||
#include <QDBusAbstractAdaptor>
|
||||
#include <QPointer>
|
||||
#include <QToolButton>
|
||||
#include <QWidgetAction>
|
||||
#include <qdbusmetatype.h>
|
||||
|
||||
class KDBusMenuAdaptor: public QDBusAbstractAdaptor
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_CLASSINFO("D-Bus Interface", "org.kde.DBusMenu")
|
||||
public:
|
||||
KDBusMenuAdaptor(KDBusMenuExporter *exporter, QMenu* menu);
|
||||
|
||||
public Q_SLOTS:
|
||||
KDBusMenu menu() const;
|
||||
|
||||
QList<KDBusMenuAction> actions(quint64 actionid = 0) const;
|
||||
bool triggerAction(quint64 actionid) const;
|
||||
|
||||
private:
|
||||
KDBusMenuExporter* m_exporter;
|
||||
QPointer<QMenu> m_menu;
|
||||
};
|
||||
|
||||
KDBusMenuAdaptor::KDBusMenuAdaptor(KDBusMenuExporter *exporter, QMenu* menu)
|
||||
: QDBusAbstractAdaptor(exporter),
|
||||
m_exporter(exporter),
|
||||
m_menu(menu)
|
||||
{
|
||||
qDBusRegisterMetaType<KDBusMenu>();
|
||||
qDBusRegisterMetaType<KDBusMenuAction>();
|
||||
qDBusRegisterMetaType<QList<KDBusMenuAction>>();
|
||||
}
|
||||
|
||||
KDBusMenu KDBusMenuAdaptor::menu() const
|
||||
{
|
||||
KDBusMenu result;
|
||||
if (m_menu.isNull()) {
|
||||
kWarning(s_kdbusmenuarea) << "Menu is null";
|
||||
return result;
|
||||
}
|
||||
// NOTE: KStatusNotifierItem adds actions to the menu when aboutToShow is emitted
|
||||
const bool menusignaled = QMetaObject::invokeMethod(m_menu.data(), "aboutToShow", Qt::DirectConnection);
|
||||
if (!menusignaled) {
|
||||
kWarning(s_kdbusmenuarea) << "Could not invoke menu aboutToShow() signal";
|
||||
}
|
||||
const QIcon menuicon = m_menu->icon();
|
||||
result.icon = menuicon.name();
|
||||
result.title = m_menu->title();
|
||||
if (result.icon.isEmpty()) {
|
||||
result.icondata = kDBusMenuIconData(menuicon);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
QList<KDBusMenuAction> KDBusMenuAdaptor::actions(quint64 actionid) const
|
||||
{
|
||||
QList<KDBusMenuAction> result;
|
||||
if (m_menu.isNull()) {
|
||||
kWarning(s_kdbusmenuarea) << "Menu is null";
|
||||
return result;
|
||||
}
|
||||
QList<QAction*> actionslist;
|
||||
if (actionid == 0) {
|
||||
actionslist = m_menu->actions();
|
||||
} else {
|
||||
foreach (const QAction* action, m_menu->actions()) {
|
||||
const quint64 itactionid = kDBusMenuActionID(action);
|
||||
if (actionid == itactionid) {
|
||||
const QMenu* actionmenu = action->menu();
|
||||
if (!actionmenu) {
|
||||
kWarning(s_kdbusmenuarea) << "Requested actions for non-menu action" << actionid;
|
||||
return result;
|
||||
}
|
||||
actionslist = actionmenu->actions();
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach (QAction* action, actionslist) {
|
||||
const quint64 itactionid = kDBusMenuActionID(action);
|
||||
kDebug(s_kdbusmenuarea) << "Exporting action" << itactionid;
|
||||
KDBusMenuAction actionproperties;
|
||||
// see kdeui/widgets/kmenu.cpp
|
||||
actionproperties.title = (action->objectName() == QLatin1String("kmenu_title"));
|
||||
if (actionproperties.title) {
|
||||
const QWidgetAction *actionwidget = qobject_cast<QWidgetAction*>(action);
|
||||
if (!actionwidget) {
|
||||
kWarning(s_kdbusmenuarea) << "Title has no widget" << itactionid;
|
||||
} else {
|
||||
const QToolButton *actionbutton = qobject_cast<QToolButton*>(actionwidget->defaultWidget());
|
||||
if (!actionbutton) {
|
||||
kWarning(s_kdbusmenuarea) << "Title has no button" << itactionid;
|
||||
} else {
|
||||
action = actionbutton->defaultAction();
|
||||
}
|
||||
}
|
||||
}
|
||||
actionproperties.id = itactionid;
|
||||
actionproperties.text = action->text();
|
||||
actionproperties.icon = m_exporter->iconNameForAction(action);
|
||||
actionproperties.tooltip = action->toolTip();
|
||||
actionproperties.statustip = action->statusTip();
|
||||
actionproperties.whatsthis = action->whatsThis();
|
||||
actionproperties.separator = action->isSeparator();
|
||||
actionproperties.checkable = action->isCheckable();
|
||||
actionproperties.checked = action->isChecked();
|
||||
actionproperties.enabled = action->isEnabled();
|
||||
actionproperties.visible = action->isVisible();
|
||||
QStringList shortcuts;
|
||||
foreach (const QKeySequence &keysequence, action->shortcuts()) {
|
||||
shortcuts.append(keysequence.toString());
|
||||
}
|
||||
actionproperties.shortcuts = shortcuts;
|
||||
if (actionproperties.icon.isEmpty()) {
|
||||
actionproperties.icondata = kDBusMenuIconData(action->icon());
|
||||
}
|
||||
const QActionGroup* actiongroup = action->actionGroup();
|
||||
actionproperties.exclusive = (actiongroup && actiongroup->isExclusive());
|
||||
const QMenu* actionmenu = action->menu();
|
||||
actionproperties.submenu = (actionmenu != nullptr);
|
||||
result.append(actionproperties);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
bool KDBusMenuAdaptor::triggerAction(quint64 actionid) const
|
||||
{
|
||||
kDebug(s_kdbusmenuarea) << "Triggering action" << actionid;
|
||||
if (m_menu.isNull()) {
|
||||
kWarning(s_kdbusmenuarea) << "Menu is null";
|
||||
return false;
|
||||
}
|
||||
foreach (QAction* action, m_menu->actions()) {
|
||||
quint64 itactionid = kDBusMenuActionID(action);
|
||||
if (itactionid == actionid) {
|
||||
return QMetaObject::invokeMethod(action, "triggered");
|
||||
}
|
||||
const QMenu* actionmenu = action->menu();
|
||||
if (actionmenu) {
|
||||
foreach (QAction* subaction, actionmenu->actions()) {
|
||||
itactionid = kDBusMenuActionID(subaction);
|
||||
if (itactionid == actionid) {
|
||||
return QMetaObject::invokeMethod(subaction, "triggered");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
kWarning(s_kdbusmenuarea) << "Could not find action for" << actionid;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
class KDBusMenuExporterPrivate
|
||||
{
|
||||
public:
|
||||
KDBusMenuExporterPrivate();
|
||||
|
||||
KDBusMenuAdaptor* adaptor;
|
||||
QString objectpath;
|
||||
QString connectionname;
|
||||
};
|
||||
|
||||
KDBusMenuExporterPrivate::KDBusMenuExporterPrivate()
|
||||
: adaptor(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
KDBusMenuExporter::KDBusMenuExporter(const QString &objectpath, QMenu *menu, const QDBusConnection &connection)
|
||||
: QObject(menu),
|
||||
d(new KDBusMenuExporterPrivate())
|
||||
{
|
||||
kDebug(s_kdbusmenuarea) << "Exporting menu" << objectpath;
|
||||
|
||||
d->adaptor = new KDBusMenuAdaptor(this, menu);
|
||||
d->objectpath = objectpath;
|
||||
d->connectionname = connection.name();
|
||||
|
||||
QDBusConnection dbusconnection(connection.name());
|
||||
dbusconnection.registerObject(objectpath, this);
|
||||
}
|
||||
|
||||
KDBusMenuExporter::~KDBusMenuExporter()
|
||||
{
|
||||
QDBusConnection dbusconnection(d->connectionname);
|
||||
dbusconnection.unregisterObject(d->objectpath);
|
||||
delete d;
|
||||
}
|
||||
|
||||
QString KDBusMenuExporter::iconNameForAction(QAction *action)
|
||||
{
|
||||
if (!action) {
|
||||
return QString();
|
||||
}
|
||||
const QIcon icon = action->icon();
|
||||
if (action->isIconVisibleInMenu() && !icon.isNull()) {
|
||||
return icon.name();
|
||||
}
|
||||
return QString();
|
||||
}
|
||||
|
||||
#include "kdbusmenuexporter.moc"
|
|
@ -1,67 +0,0 @@
|
|||
/* This file is part of the KDE libraries
|
||||
Copyright (C) 2023 Ivailo Monev <xakepa10@gmail.com>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public License
|
||||
along with this library; see the file COPYING.LIB. If not, write to
|
||||
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef KDBUSMENUEXPORTER_H
|
||||
#define KDBUSMENUEXPORTER_H
|
||||
|
||||
#include "kdeui_export.h"
|
||||
|
||||
#include <QDBusConnection>
|
||||
#include <QMenu>
|
||||
#include <QAction>
|
||||
|
||||
class KDBusMenuExporterPrivate;
|
||||
|
||||
/*!
|
||||
D-Bus menu exporting class
|
||||
|
||||
KDBusMenuExporter class can be used to export menu (QMenu or KMenu) from one application
|
||||
to other applications.
|
||||
|
||||
@since 4.23
|
||||
@see KDBusMenuImporter
|
||||
*/
|
||||
class KDEUI_EXPORT KDBusMenuExporter : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
/*!
|
||||
@brief Creates menu exporter for the given object path @p objectpath, path @p path and
|
||||
connection @p connection.
|
||||
@note The exporter is parented to the menu @p menu thus when the menu is destroyed the
|
||||
exporter becomes non-operational and should not be used.
|
||||
*/
|
||||
KDBusMenuExporter(const QString &objectpath, QMenu *menu, const QDBusConnection &connection = QDBusConnection::sessionBus());
|
||||
virtual ~KDBusMenuExporter();
|
||||
|
||||
protected:
|
||||
/*!
|
||||
@brief Reimplement to provide custom icons for actions and menus. The default
|
||||
implementation returns the action icon name.
|
||||
*/
|
||||
virtual QString iconNameForAction(QAction *action);
|
||||
|
||||
private:
|
||||
KDBusMenuExporterPrivate *d;
|
||||
Q_DISABLE_COPY(KDBusMenuExporter);
|
||||
|
||||
friend class KDBusMenuAdaptor;
|
||||
};
|
||||
|
||||
#endif // KDBUSMENUEXPORTER_H
|
|
@ -1,158 +0,0 @@
|
|||
/* This file is part of the KDE libraries
|
||||
Copyright (C) 2023 Ivailo Monev <xakepa10@gmail.com>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public License
|
||||
along with this library; see the file COPYING.LIB. If not, write to
|
||||
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "kdbusmenuimporter.h"
|
||||
#include "kmenu.h"
|
||||
#include "kdebug.h"
|
||||
#include "kdbusmenu_p.h"
|
||||
|
||||
#include <QDBusInterface>
|
||||
#include <QDBusReply>
|
||||
#include <qdbusmetatype.h>
|
||||
|
||||
class KDBusMenuImporterPrivate
|
||||
{
|
||||
public:
|
||||
KDBusMenuImporterPrivate();
|
||||
|
||||
QDBusInterface* interface;
|
||||
QMenu* menu;
|
||||
};
|
||||
|
||||
KDBusMenuImporterPrivate::KDBusMenuImporterPrivate()
|
||||
: interface(nullptr),
|
||||
menu(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
KDBusMenuImporter::KDBusMenuImporter(const QString &service, const QString &path, QObject *parent)
|
||||
: QObject(parent),
|
||||
d(new KDBusMenuImporterPrivate())
|
||||
{
|
||||
kDebug(s_kdbusmenuarea) << "Importing menu" << service << path;
|
||||
|
||||
qDBusRegisterMetaType<KDBusMenu>();
|
||||
qDBusRegisterMetaType<KDBusMenuAction>();
|
||||
qDBusRegisterMetaType<QList<KDBusMenuAction>>();
|
||||
|
||||
QDBusConnection dbusconnection = QDBusConnection::sessionBus();
|
||||
d->interface = new QDBusInterface(service, path, QString::fromLatin1("org.kde.DBusMenu"), dbusconnection, this);
|
||||
}
|
||||
|
||||
KDBusMenuImporter::~KDBusMenuImporter()
|
||||
{
|
||||
delete d;
|
||||
}
|
||||
|
||||
QMenu* KDBusMenuImporter::menu() const
|
||||
{
|
||||
return d->menu;
|
||||
}
|
||||
|
||||
void KDBusMenuImporter::updateMenu()
|
||||
{
|
||||
kDebug(s_kdbusmenuarea) << "Updating menu";
|
||||
if (!d->menu) {
|
||||
d->menu = createMenu(nullptr);
|
||||
} else {
|
||||
d->menu->clear();
|
||||
}
|
||||
QDBusReply<KDBusMenu> menureply = d->interface->call("menu");
|
||||
if (!menureply.isValid()) {
|
||||
kWarning(s_kdbusmenuarea) << "Invalid menu reply" << menureply.error();
|
||||
return;
|
||||
}
|
||||
const KDBusMenu menuproperties = menureply.value();
|
||||
d->menu->setTitle(menuproperties.title);
|
||||
QIcon menuicon = iconForName(menuproperties.icon);
|
||||
if (menuicon.isNull()) {
|
||||
menuicon = kDBusMenuIcon(menuproperties.icondata);
|
||||
}
|
||||
d->menu->setIcon(menuicon);
|
||||
|
||||
QDBusReply<QList<KDBusMenuAction>> actionsreply = d->interface->call("actions");
|
||||
if (!actionsreply.isValid()) {
|
||||
kWarning(s_kdbusmenuarea) << "Invalid actions reply" << actionsreply.error();
|
||||
return;
|
||||
}
|
||||
foreach (const KDBusMenuAction &actionproperties, actionsreply.value()) {
|
||||
const quint64 actionid = actionproperties.id;
|
||||
kDebug(s_kdbusmenuarea) << "Importing action" << actionid;
|
||||
QIcon actionicon = iconForName(actionproperties.icon);
|
||||
if (actionicon.isNull()) {
|
||||
actionicon = kDBusMenuIcon(actionproperties.icondata);
|
||||
}
|
||||
QAction* action = nullptr;
|
||||
if (actionproperties.title) {
|
||||
// see kdeui/widgets/kmenu.cpp
|
||||
action = KMenu::titleAction(actionicon, actionproperties.text, d->menu);
|
||||
} else {
|
||||
action = kDBusMenuAction(d->menu, actionproperties);
|
||||
}
|
||||
if (actionproperties.submenu) {
|
||||
QDBusReply<QList<KDBusMenuAction>> subactionsreply = d->interface->call("actions", actionid);
|
||||
if (!subactionsreply.isValid()) {
|
||||
kWarning(s_kdbusmenuarea) << "Invalid sub-actions reply" << subactionsreply.error();
|
||||
return;
|
||||
}
|
||||
QMenu* subactionmenu = createMenu(d->menu);
|
||||
foreach (const KDBusMenuAction &subactionproperties, subactionsreply.value()) {
|
||||
QIcon subactionicon = iconForName(subactionproperties.icon);
|
||||
if (subactionicon.isNull()) {
|
||||
subactionicon = kDBusMenuIcon(subactionproperties.icondata);
|
||||
}
|
||||
QAction* subaction = kDBusMenuAction(subactionmenu, subactionproperties);
|
||||
kDBusSetIcon(subaction, subactionicon);
|
||||
connect(subaction, SIGNAL(triggered()), this, SLOT(slotActionTriggered()));
|
||||
subactionmenu->addAction(subaction);
|
||||
}
|
||||
action->setMenu(subactionmenu);
|
||||
}
|
||||
kDBusSetIcon(action, actionicon);
|
||||
connect(action, SIGNAL(triggered()), this, SLOT(slotActionTriggered()));
|
||||
d->menu->addAction(action);
|
||||
}
|
||||
emit menuUpdated();
|
||||
}
|
||||
|
||||
QMenu* KDBusMenuImporter::createMenu(QWidget *parent)
|
||||
{
|
||||
return new QMenu(parent);
|
||||
}
|
||||
|
||||
QIcon KDBusMenuImporter::iconForName(const QString &name)
|
||||
{
|
||||
return QIcon::fromTheme(name);
|
||||
}
|
||||
|
||||
void KDBusMenuImporter::slotActionTriggered()
|
||||
{
|
||||
QAction* action = qobject_cast<QAction*>(sender());
|
||||
const quint64 actionid = action->data().toULongLong();
|
||||
kDebug(s_kdbusmenuarea) << "Action triggered" << actionid;
|
||||
QDBusReply<bool> triggerreply = d->interface->call("triggerAction", actionid);
|
||||
if (!triggerreply.isValid()) {
|
||||
kWarning(s_kdbusmenuarea) << "Invalid action trigger reply" << triggerreply.error();
|
||||
return;
|
||||
}
|
||||
if (triggerreply.value() != true) {
|
||||
kWarning(s_kdbusmenuarea) << "Could not trigger action" << actionid;
|
||||
}
|
||||
}
|
|
@ -1,89 +0,0 @@
|
|||
/* This file is part of the KDE libraries
|
||||
Copyright (C) 2023 Ivailo Monev <xakepa10@gmail.com>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public License
|
||||
along with this library; see the file COPYING.LIB. If not, write to
|
||||
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef KDBUSMENUIMPORTER_H
|
||||
#define KDBUSMENUIMPORTER_H
|
||||
|
||||
#include "kdeui_export.h"
|
||||
|
||||
#include <QMenu>
|
||||
#include <QIcon>
|
||||
#include <QWidget>
|
||||
#include <QAction>
|
||||
|
||||
class KDBusMenuImporterPrivate;
|
||||
|
||||
/*!
|
||||
D-Bus menu importing class
|
||||
|
||||
KDBusMenuImporter class can be used to import menu (QMenu or KMenu) from other application
|
||||
exported via KDBusMenuExporter.
|
||||
|
||||
@since 4.23
|
||||
@see KDBusMenuExporter
|
||||
*/
|
||||
class KDEUI_EXPORT KDBusMenuImporter : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
/*!
|
||||
@brief Creates menu importer for the given service @p service and path @p path.
|
||||
*/
|
||||
KDBusMenuImporter(const QString &service, const QString &path, QObject *parent = 0);
|
||||
virtual ~KDBusMenuImporter();
|
||||
|
||||
/*!
|
||||
@brief Returns nearly perfect copy of the exported menu, if any.
|
||||
*/
|
||||
QMenu* menu() const;
|
||||
|
||||
public Q_SLOTS:
|
||||
/*!
|
||||
@brief Forces update of the menu, must be called for @p KDBusMenuImporter::menu() to return
|
||||
valid menu.
|
||||
*/
|
||||
void updateMenu();
|
||||
|
||||
Q_SIGNALS:
|
||||
/*!
|
||||
@brief Signals that the menu was updated.
|
||||
*/
|
||||
void menuUpdated();
|
||||
|
||||
protected:
|
||||
/*!
|
||||
@brief Reimplement to provide custom menus, affects the root menu and sub-menus. The
|
||||
default implementation simply creates QMenu parented to @p parent.
|
||||
*/
|
||||
virtual QMenu* createMenu(QWidget *parent);
|
||||
/*!
|
||||
@brief Reimplement to provide custom icons for actions and menus. The default
|
||||
implementation returns the result of QIcon::fromTheme() for @p name.
|
||||
*/
|
||||
virtual QIcon iconForName(const QString &name);
|
||||
|
||||
private Q_SLOTS:
|
||||
void slotActionTriggered();
|
||||
|
||||
private:
|
||||
KDBusMenuImporterPrivate *d;
|
||||
Q_DISABLE_COPY(KDBusMenuImporter);
|
||||
};
|
||||
|
||||
#endif // KDBUSMENUIMPORTER_H
|
|
@ -1,921 +0,0 @@
|
|||
/* This file is part of the KDE libraries
|
||||
Copyright 2009 by Marco Martin <notmart@gmail.com>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License (LGPL) as published by the Free Software Foundation;
|
||||
either version 2 of the License, or (at your option) any later
|
||||
version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public License
|
||||
along with this library; see the file COPYING.LIB. If not, write to
|
||||
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include "kstatusnotifieritem.h"
|
||||
#include "kstatusnotifieritemprivate_p.h"
|
||||
#include "kstatusnotifieritemdbus_p.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QPainter>
|
||||
#include <QMetaObject>
|
||||
#include <QTimer>
|
||||
|
||||
#include <kdebug.h>
|
||||
#include <ksystemtrayicon.h>
|
||||
#include <kaboutdata.h>
|
||||
#include <kicon.h>
|
||||
#include <kmenu.h>
|
||||
#include <kaction.h>
|
||||
#include <kwindowinfo.h>
|
||||
#include <kwindowsystem.h>
|
||||
#include <kmessagebox.h>
|
||||
#include <kactioncollection.h>
|
||||
#include <kstandarddirs.h>
|
||||
#include <kglobal.h>
|
||||
#include <kdbusmenuexporter.h>
|
||||
|
||||
#include "statusnotifieritemadaptor.h"
|
||||
|
||||
static const QString s_statusNotifierWatcherServiceName("org.kde.StatusNotifierWatcher");
|
||||
|
||||
KStatusNotifierItem::KStatusNotifierItem(QObject *parent)
|
||||
: QObject(parent),
|
||||
d(new KStatusNotifierItemPrivate(this))
|
||||
{
|
||||
d->init(QString());
|
||||
}
|
||||
|
||||
|
||||
KStatusNotifierItem::KStatusNotifierItem(const QString &id, QObject *parent)
|
||||
: QObject(parent),
|
||||
d(new KStatusNotifierItemPrivate(this))
|
||||
{
|
||||
d->init(id);
|
||||
}
|
||||
|
||||
KStatusNotifierItem::~KStatusNotifierItem()
|
||||
{
|
||||
delete d->statusNotifierWatcher;
|
||||
delete d->systemTrayIcon;
|
||||
if (!qApp->closingDown()) {
|
||||
delete d->menu;
|
||||
}
|
||||
delete d;
|
||||
KGlobal::deref();
|
||||
}
|
||||
|
||||
QString KStatusNotifierItem::id() const
|
||||
{
|
||||
//kDebug(299) << "id requested" << d->id;
|
||||
return d->id;
|
||||
}
|
||||
|
||||
void KStatusNotifierItem::setCategory(const ItemCategory category)
|
||||
{
|
||||
d->category = category;
|
||||
}
|
||||
|
||||
KStatusNotifierItem::ItemStatus KStatusNotifierItem::status() const
|
||||
{
|
||||
return d->status;
|
||||
}
|
||||
|
||||
KStatusNotifierItem::ItemCategory KStatusNotifierItem::category() const
|
||||
{
|
||||
return d->category;
|
||||
}
|
||||
|
||||
void KStatusNotifierItem::setTitle(const QString &title)
|
||||
{
|
||||
d->title = title;
|
||||
}
|
||||
|
||||
void KStatusNotifierItem::setStatus(const ItemStatus status)
|
||||
{
|
||||
if (d->status == status) {
|
||||
return;
|
||||
}
|
||||
|
||||
d->status = status;
|
||||
emit d->statusNotifierItemDBus->NewStatus(metaObject()->enumerator(metaObject()->indexOfEnumerator("ItemStatus")).valueToKey(d->status));
|
||||
|
||||
if (d->systemTrayIcon) {
|
||||
d->syncLegacySystemTrayIcon();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//normal icon
|
||||
|
||||
void KStatusNotifierItem::setIconByName(const QString &name)
|
||||
{
|
||||
if (d->iconName == name) {
|
||||
return;
|
||||
}
|
||||
|
||||
d->serializedIcon = KDbusImageVector();
|
||||
d->iconName = name;
|
||||
emit d->statusNotifierItemDBus->NewIcon();
|
||||
if (d->systemTrayIcon) {
|
||||
d->systemTrayIcon->setIcon(KIcon(name));
|
||||
}
|
||||
}
|
||||
|
||||
QString KStatusNotifierItem::iconName() const
|
||||
{
|
||||
return d->iconName;
|
||||
}
|
||||
|
||||
void KStatusNotifierItem::setIconByPixmap(const QIcon &icon)
|
||||
{
|
||||
if (d->icon.cacheKey() == icon.cacheKey()) {
|
||||
return;
|
||||
}
|
||||
|
||||
d->iconName.clear();
|
||||
d->serializedIcon = d->iconToVector(icon);
|
||||
emit d->statusNotifierItemDBus->NewIcon();
|
||||
|
||||
d->icon = icon;
|
||||
if (d->systemTrayIcon) {
|
||||
d->systemTrayIcon->setIcon(icon);
|
||||
}
|
||||
}
|
||||
|
||||
QIcon KStatusNotifierItem::iconPixmap() const
|
||||
{
|
||||
return d->icon;
|
||||
}
|
||||
|
||||
void KStatusNotifierItem::setOverlayIconByName(const QString &name)
|
||||
{
|
||||
if (d->overlayIconName == name) {
|
||||
return;
|
||||
}
|
||||
|
||||
d->overlayIconName = name;
|
||||
emit d->statusNotifierItemDBus->NewOverlayIcon();
|
||||
if (d->systemTrayIcon) {
|
||||
QPixmap iconPixmap = KIcon(d->iconName).pixmap(KIconLoader::SizeSmallMedium, KIconLoader::SizeSmallMedium);
|
||||
if (!name.isEmpty()) {
|
||||
QPixmap overlayPixmap = KIcon(d->overlayIconName).pixmap(KIconLoader::SizeSmallMedium/2, KIconLoader::SizeSmallMedium/2);
|
||||
QPainter p(&iconPixmap);
|
||||
p.drawPixmap(iconPixmap.width()-overlayPixmap.width(), iconPixmap.height()-overlayPixmap.height(), overlayPixmap);
|
||||
p.end();
|
||||
}
|
||||
d->systemTrayIcon->setIcon(iconPixmap);
|
||||
}
|
||||
}
|
||||
|
||||
QString KStatusNotifierItem::overlayIconName() const
|
||||
{
|
||||
return d->overlayIconName;
|
||||
}
|
||||
|
||||
void KStatusNotifierItem::setOverlayIconByPixmap(const QIcon &icon)
|
||||
{
|
||||
if (d->overlayIconName.isEmpty() && d->overlayIcon.cacheKey() == icon.cacheKey()) {
|
||||
return;
|
||||
}
|
||||
|
||||
d->overlayIconName.clear();
|
||||
d->serializedOverlayIcon = d->iconToVector(icon);
|
||||
emit d->statusNotifierItemDBus->NewOverlayIcon();
|
||||
|
||||
d->overlayIcon = icon;
|
||||
if (d->systemTrayIcon) {
|
||||
QPixmap iconPixmap = d->icon.pixmap(KIconLoader::SizeSmallMedium, KIconLoader::SizeSmallMedium);
|
||||
QPixmap overlayPixmap = d->overlayIcon.pixmap(KIconLoader::SizeSmallMedium/2, KIconLoader::SizeSmallMedium/2);
|
||||
|
||||
QPainter p(&iconPixmap);
|
||||
p.drawPixmap(iconPixmap.width()-overlayPixmap.width(), iconPixmap.height()-overlayPixmap.height(), overlayPixmap);
|
||||
p.end();
|
||||
d->systemTrayIcon->setIcon(iconPixmap);
|
||||
}
|
||||
}
|
||||
|
||||
QIcon KStatusNotifierItem::overlayIconPixmap() const
|
||||
{
|
||||
return d->overlayIcon;
|
||||
}
|
||||
|
||||
//Icons for requesting attention state
|
||||
|
||||
void KStatusNotifierItem::setAttentionIconByName(const QString &name)
|
||||
{
|
||||
if (d->attentionIconName == name) {
|
||||
return;
|
||||
}
|
||||
|
||||
d->serializedAttentionIcon = KDbusImageVector();
|
||||
d->attentionIconName = name;
|
||||
emit d->statusNotifierItemDBus->NewAttentionIcon();
|
||||
}
|
||||
|
||||
QString KStatusNotifierItem::attentionIconName() const
|
||||
{
|
||||
return d->attentionIconName;
|
||||
}
|
||||
|
||||
void KStatusNotifierItem::setAttentionIconByPixmap(const QIcon &icon)
|
||||
{
|
||||
if (d->attentionIconName.isEmpty() && d->attentionIcon.cacheKey() == icon.cacheKey()) {
|
||||
return;
|
||||
}
|
||||
|
||||
d->attentionIconName.clear();
|
||||
d->serializedAttentionIcon = d->iconToVector(icon);
|
||||
d->attentionIcon = icon;
|
||||
emit d->statusNotifierItemDBus->NewAttentionIcon();
|
||||
}
|
||||
|
||||
QIcon KStatusNotifierItem::attentionIconPixmap() const
|
||||
{
|
||||
return d->attentionIcon;
|
||||
}
|
||||
|
||||
//ToolTip
|
||||
|
||||
void KStatusNotifierItem::setToolTip(const QString &iconName, const QString &title, const QString &subTitle)
|
||||
{
|
||||
if (d->toolTipIconName == iconName &&
|
||||
d->toolTipTitle == title &&
|
||||
d->toolTipSubTitle == subTitle) {
|
||||
return;
|
||||
}
|
||||
|
||||
d->serializedToolTipIcon = KDbusImageVector();
|
||||
d->toolTipIconName = iconName;
|
||||
|
||||
d->toolTipTitle = title;
|
||||
if (d->systemTrayIcon) {
|
||||
d->systemTrayIcon->setToolTip(title);
|
||||
}
|
||||
|
||||
d->toolTipSubTitle = subTitle;
|
||||
emit d->statusNotifierItemDBus->NewToolTip();
|
||||
}
|
||||
|
||||
void KStatusNotifierItem::setToolTip(const QIcon &icon, const QString &title, const QString &subTitle)
|
||||
{
|
||||
if (d->toolTipIconName.isEmpty() && d->toolTipIcon.cacheKey() == icon.cacheKey() &&
|
||||
d->toolTipTitle == title &&
|
||||
d->toolTipSubTitle == subTitle) {
|
||||
return;
|
||||
}
|
||||
|
||||
d->toolTipIconName.clear();
|
||||
d->serializedToolTipIcon = d->iconToVector(icon);
|
||||
d->toolTipIcon = icon;
|
||||
|
||||
d->toolTipTitle = title;
|
||||
if (d->systemTrayIcon) {
|
||||
d->systemTrayIcon->setToolTip(title);
|
||||
}
|
||||
|
||||
d->toolTipSubTitle = subTitle;
|
||||
emit d->statusNotifierItemDBus->NewToolTip();
|
||||
}
|
||||
|
||||
void KStatusNotifierItem::setToolTipIconByName(const QString &name)
|
||||
{
|
||||
if (d->toolTipIconName == name) {
|
||||
return;
|
||||
}
|
||||
|
||||
d->serializedToolTipIcon = KDbusImageVector();
|
||||
d->toolTipIconName = name;
|
||||
emit d->statusNotifierItemDBus->NewToolTip();
|
||||
}
|
||||
|
||||
QString KStatusNotifierItem::toolTipIconName() const
|
||||
{
|
||||
return d->toolTipIconName;
|
||||
}
|
||||
|
||||
void KStatusNotifierItem::setToolTipIconByPixmap(const QIcon &icon)
|
||||
{
|
||||
if (d->toolTipIconName.isEmpty() && d->toolTipIcon.cacheKey() == icon.cacheKey()) {
|
||||
return;
|
||||
}
|
||||
|
||||
d->toolTipIconName.clear();
|
||||
d->serializedToolTipIcon = d->iconToVector(icon);
|
||||
d->toolTipIcon = icon;
|
||||
emit d->statusNotifierItemDBus->NewToolTip();
|
||||
}
|
||||
|
||||
QIcon KStatusNotifierItem::toolTipIconPixmap() const
|
||||
{
|
||||
return d->toolTipIcon;
|
||||
}
|
||||
|
||||
void KStatusNotifierItem::setToolTipTitle(const QString &title)
|
||||
{
|
||||
if (d->toolTipTitle == title) {
|
||||
return;
|
||||
}
|
||||
|
||||
d->toolTipTitle = title;
|
||||
emit d->statusNotifierItemDBus->NewToolTip();
|
||||
if (d->systemTrayIcon) {
|
||||
d->systemTrayIcon->setToolTip(title);
|
||||
}
|
||||
}
|
||||
|
||||
QString KStatusNotifierItem::toolTipTitle() const
|
||||
{
|
||||
return d->toolTipTitle;
|
||||
}
|
||||
|
||||
void KStatusNotifierItem::setToolTipSubTitle(const QString &subTitle)
|
||||
{
|
||||
if (d->toolTipSubTitle == subTitle) {
|
||||
return;
|
||||
}
|
||||
|
||||
d->toolTipSubTitle = subTitle;
|
||||
emit d->statusNotifierItemDBus->NewToolTip();
|
||||
}
|
||||
|
||||
QString KStatusNotifierItem::toolTipSubTitle() const
|
||||
{
|
||||
return d->toolTipSubTitle;
|
||||
}
|
||||
|
||||
void KStatusNotifierItem::setContextMenu(KMenu *menu)
|
||||
{
|
||||
if (d->menu && d->menu != menu) {
|
||||
d->menu->removeEventFilter(this);
|
||||
delete d->menu;
|
||||
}
|
||||
|
||||
if (!menu) {
|
||||
d->menu = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
if (d->systemTrayIcon) {
|
||||
d->systemTrayIcon->setContextMenu(menu);
|
||||
} else if (d->menu != menu) {
|
||||
if (getenv("KSNI_NO_DBUSMENU")) {
|
||||
// This is a hack to make it possible to disable DBusMenu in an
|
||||
// application. The string "/NO_DBUSMENU" must be the same as in
|
||||
// DBusSystemTrayWidget::findDBusMenuInterface() in the Plasma
|
||||
// systemtray applet.
|
||||
d->menuObjectPath = "/NO_DBUSMENU";
|
||||
menu->installEventFilter(this);
|
||||
} else {
|
||||
d->menuObjectPath = "/MenuBar";
|
||||
new KDBusMenuExporter(d->menuObjectPath, menu, d->statusNotifierItemDBus->dbusConnection());
|
||||
}
|
||||
|
||||
connect(menu, SIGNAL(aboutToShow()), this, SLOT(contextMenuAboutToShow()));
|
||||
}
|
||||
|
||||
d->menu = menu;
|
||||
d->menu->setParent(0);
|
||||
}
|
||||
|
||||
KMenu *KStatusNotifierItem::contextMenu() const
|
||||
{
|
||||
return d->menu;
|
||||
}
|
||||
|
||||
void KStatusNotifierItem::setAssociatedWidget(QWidget *associatedWidget)
|
||||
{
|
||||
if (associatedWidget) {
|
||||
d->associatedWidget = associatedWidget->window();
|
||||
} else {
|
||||
d->associatedWidget = 0;
|
||||
}
|
||||
|
||||
if (d->systemTrayIcon) {
|
||||
delete d->systemTrayIcon;
|
||||
d->systemTrayIcon = 0;
|
||||
d->setLegacySystemTrayEnabled(true);
|
||||
}
|
||||
|
||||
if (d->associatedWidget && d->associatedWidget != d->menu) {
|
||||
QAction *action = d->actionCollection->action("minimizeRestore");
|
||||
|
||||
if (!action) {
|
||||
action = d->actionCollection->addAction("minimizeRestore");
|
||||
action->setText(i18n("&Minimize"));
|
||||
connect(action, SIGNAL(triggered(bool)), this, SLOT(minimizeRestore()));
|
||||
}
|
||||
|
||||
#ifdef Q_WS_X11
|
||||
KWindowInfo info = KWindowSystem::windowInfo(d->associatedWidget->winId(), NET::WMDesktop);
|
||||
d->onAllDesktops = info.onAllDesktops();
|
||||
#else
|
||||
d->onAllDesktops = false;
|
||||
#endif
|
||||
} else {
|
||||
if (d->menu && d->hasQuit) {
|
||||
QAction *action = d->actionCollection->action("minimizeRestore");
|
||||
if (action) {
|
||||
d->menu->removeAction(action);
|
||||
}
|
||||
}
|
||||
|
||||
d->onAllDesktops = false;
|
||||
}
|
||||
}
|
||||
|
||||
QWidget *KStatusNotifierItem::associatedWidget() const
|
||||
{
|
||||
return d->associatedWidget;
|
||||
}
|
||||
|
||||
KActionCollection *KStatusNotifierItem::actionCollection() const
|
||||
{
|
||||
return d->actionCollection;
|
||||
}
|
||||
|
||||
void KStatusNotifierItem::setStandardActionsEnabled(bool enabled)
|
||||
{
|
||||
if (d->standardActionsEnabled == enabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
d->standardActionsEnabled = enabled;
|
||||
|
||||
if (d->menu && !enabled && d->hasQuit) {
|
||||
QAction *action = d->actionCollection->action("minimizeRestore");
|
||||
if (action) {
|
||||
d->menu->removeAction(action);
|
||||
}
|
||||
|
||||
action = d->actionCollection->action(KStandardAction::name(KStandardAction::Quit));
|
||||
if (action) {
|
||||
d->menu->removeAction(action);
|
||||
}
|
||||
|
||||
|
||||
d->hasQuit = false;
|
||||
}
|
||||
}
|
||||
|
||||
bool KStatusNotifierItem::standardActionsEnabled() const
|
||||
{
|
||||
return d->standardActionsEnabled;
|
||||
}
|
||||
|
||||
QString KStatusNotifierItem::title() const
|
||||
{
|
||||
return d->title;
|
||||
}
|
||||
|
||||
void KStatusNotifierItem::activate(const QPoint &pos)
|
||||
{
|
||||
//if the user activated the icon the NeedsAttention state is no longer necessary
|
||||
//FIXME: always true?
|
||||
if (d->status == NeedsAttention) {
|
||||
d->status = Active;
|
||||
emit d->statusNotifierItemDBus->NewStatus(metaObject()->enumerator(metaObject()->indexOfEnumerator("ItemStatus")).valueToKey(d->status));
|
||||
}
|
||||
|
||||
if (d->associatedWidget == d->menu) {
|
||||
d->statusNotifierItemDBus->ContextMenu(pos.x(), pos.y());
|
||||
return;
|
||||
}
|
||||
|
||||
if (d->menu->isVisible()) {
|
||||
d->menu->hide();
|
||||
}
|
||||
|
||||
if (!d->associatedWidget) {
|
||||
emit activateRequested(true, pos);
|
||||
return;
|
||||
}
|
||||
|
||||
d->checkVisibility(pos);
|
||||
}
|
||||
|
||||
bool KStatusNotifierItemPrivate::checkVisibility(QPoint pos, bool perform)
|
||||
{
|
||||
#if defined(Q_WS_X11)
|
||||
KWindowInfo info1 = KWindowSystem::windowInfo(associatedWidget->winId(), NET::XAWMState | NET::WMState | NET::WMDesktop);
|
||||
// mapped = visible (but possibly obscured)
|
||||
bool mapped = (info1.mappingState() == NET::Visible) && !info1.isMinimized();
|
||||
|
||||
// - not mapped -> show, raise, focus
|
||||
// - mapped
|
||||
// - obscured -> raise, focus
|
||||
// - not obscured -> hide
|
||||
//info1.mappingState() != NET::Visible -> window on another desktop?
|
||||
if (!mapped) {
|
||||
if (perform) {
|
||||
minimizeRestore(true);
|
||||
emit q->activateRequested(true, pos);
|
||||
}
|
||||
|
||||
return true;
|
||||
} else {
|
||||
QListIterator< WId > it (KWindowSystem::stackingOrder());
|
||||
it.toBack();
|
||||
while (it.hasPrevious()) {
|
||||
WId id = it.previous();
|
||||
if (id == associatedWidget->winId()) {
|
||||
break;
|
||||
}
|
||||
|
||||
KWindowInfo info2 = KWindowSystem::windowInfo(id,
|
||||
NET::WMDesktop | NET::WMGeometry | NET::XAWMState | NET::WMState | NET::WMWindowType);
|
||||
|
||||
if (info2.mappingState() != NET::Visible) {
|
||||
continue; // not visible on current desktop -> ignore
|
||||
}
|
||||
|
||||
if (!info2.geometry().intersects(associatedWidget->geometry())) {
|
||||
continue; // not obscuring the window -> ignore
|
||||
}
|
||||
|
||||
if (!info1.hasState(NET::KeepAbove) && info2.hasState(NET::KeepAbove)) {
|
||||
continue; // obscured by window kept above -> ignore
|
||||
}
|
||||
|
||||
NET::WindowType type = info2.windowType(NET::NormalMask | NET::DesktopMask
|
||||
| NET::DockMask | NET::ToolbarMask | NET::MenuMask | NET::DialogMask
|
||||
| NET::UtilityMask | NET::SplashMask);
|
||||
|
||||
if (type == NET::Dock) {
|
||||
continue; // obscured by dock -> ignore
|
||||
}
|
||||
|
||||
if (perform) {
|
||||
KWindowSystem::raiseWindow(associatedWidget->winId());
|
||||
KWindowSystem::forceActiveWindow(associatedWidget->winId());
|
||||
emit q->activateRequested(true, pos);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//not on current desktop?
|
||||
if (!info1.isOnCurrentDesktop()) {
|
||||
if (perform) {
|
||||
KWindowSystem::activateWindow(associatedWidget->winId());
|
||||
emit q->activateRequested(true, pos);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
if (perform) {
|
||||
minimizeRestore(false); // hide
|
||||
emit q->activateRequested(false, pos);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool KStatusNotifierItem::eventFilter(QObject *watched, QEvent *event)
|
||||
{
|
||||
if (d->systemTrayIcon == 0) {
|
||||
//FIXME: ugly ugly workaround to weird QMenu's focus problems
|
||||
if (watched == d->menu &&
|
||||
(event->type() == QEvent::WindowDeactivate || (event->type() == QEvent::MouseButtonRelease && static_cast<QMouseEvent*>(event)->button() == Qt::LeftButton))) {
|
||||
//put at the back of even queue to let the action activate anyways
|
||||
QTimer::singleShot(0, this, SLOT(hideMenu()));
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
//KStatusNotifierItemPrivate
|
||||
|
||||
static const int s_protocolVersion = 0;
|
||||
|
||||
KStatusNotifierItemPrivate::KStatusNotifierItemPrivate(KStatusNotifierItem *item)
|
||||
: q(item),
|
||||
category(KStatusNotifierItem::ApplicationStatus),
|
||||
status(KStatusNotifierItem::Passive),
|
||||
menu(0),
|
||||
titleAction(0),
|
||||
statusNotifierWatcher(0),
|
||||
systemTrayIcon(0),
|
||||
hasQuit(false),
|
||||
onAllDesktops(false),
|
||||
standardActionsEnabled(true)
|
||||
{
|
||||
}
|
||||
|
||||
void KStatusNotifierItemPrivate::init(const QString &extraId)
|
||||
{
|
||||
// Ensure that closing the last KMainWindow doesn't exit the application
|
||||
// if a system tray icon is still present.
|
||||
KGlobal::ref();
|
||||
|
||||
qDBusRegisterMetaType<KDbusImageStruct>();
|
||||
qDBusRegisterMetaType<KDbusImageVector>();
|
||||
qDBusRegisterMetaType<KDbusToolTipStruct>();
|
||||
|
||||
actionCollection = new KActionCollection(q);
|
||||
statusNotifierItemDBus = new KStatusNotifierItemDBus(q);
|
||||
q->setAssociatedWidget(qobject_cast<QWidget*>(q->parent()));
|
||||
|
||||
QDBusServiceWatcher *watcher = new QDBusServiceWatcher(s_statusNotifierWatcherServiceName,
|
||||
QDBusConnection::sessionBus(),
|
||||
QDBusServiceWatcher::WatchForOwnerChange,
|
||||
q);
|
||||
QObject::connect(watcher, SIGNAL(serviceOwnerChanged(QString,QString,QString)),
|
||||
q, SLOT(serviceChange(QString,QString,QString)));
|
||||
|
||||
//create a default menu, just like in KSystemtrayIcon
|
||||
KMenu *m = new KMenu(associatedWidget);
|
||||
titleAction = m->addTitle(qApp->windowIcon(), KGlobal::caption());
|
||||
m->setTitle(KGlobal::mainComponent().aboutData()->programName());
|
||||
q->setContextMenu(m);
|
||||
|
||||
KStandardAction::quit(q, SLOT(maybeQuit()), actionCollection);
|
||||
|
||||
id = title = KGlobal::mainComponent().aboutData()->programName();
|
||||
|
||||
if (!extraId.isEmpty()) {
|
||||
id.append('_').append(extraId);
|
||||
}
|
||||
|
||||
// Init iconThemePath to the app folder for now
|
||||
QStringList dirs = KGlobal::dirs()->findDirs("appdata", "icons");
|
||||
if (!dirs.isEmpty()) {
|
||||
iconThemePath = dirs.first();
|
||||
}
|
||||
|
||||
registerToDaemon();
|
||||
}
|
||||
|
||||
void KStatusNotifierItemPrivate::registerToDaemon()
|
||||
{
|
||||
kDebug(299) << "Registering a client interface to the KStatusNotifierWatcher";
|
||||
if (!statusNotifierWatcher) {
|
||||
statusNotifierWatcher = new org::kde::StatusNotifierWatcher(s_statusNotifierWatcherServiceName, "/StatusNotifierWatcher",
|
||||
QDBusConnection::sessionBus());
|
||||
QObject::connect(statusNotifierWatcher, SIGNAL(StatusNotifierHostRegistered()),
|
||||
q, SLOT(checkForRegisteredHosts()));
|
||||
QObject::connect(statusNotifierWatcher, SIGNAL(StatusNotifierHostUnregistered()),
|
||||
q, SLOT(checkForRegisteredHosts()));
|
||||
}
|
||||
|
||||
if (statusNotifierWatcher->isValid() &&
|
||||
statusNotifierWatcher->property("ProtocolVersion").toInt() == s_protocolVersion) {
|
||||
|
||||
statusNotifierWatcher->RegisterStatusNotifierItem(statusNotifierItemDBus->service());
|
||||
setLegacySystemTrayEnabled(false);
|
||||
} else {
|
||||
kDebug(299)<<"KStatusNotifierWatcher not reachable";
|
||||
setLegacySystemTrayEnabled(true);
|
||||
}
|
||||
}
|
||||
|
||||
void KStatusNotifierItemPrivate::serviceChange(const QString &name, const QString &oldOwner, const QString &newOwner)
|
||||
{
|
||||
Q_UNUSED(name)
|
||||
if (newOwner.isEmpty()) {
|
||||
//unregistered
|
||||
kDebug(299) << "Connection to the KStatusNotifierWatcher lost";
|
||||
setLegacyMode(true);
|
||||
delete statusNotifierWatcher;
|
||||
statusNotifierWatcher = 0;
|
||||
} else if (oldOwner.isEmpty()) {
|
||||
//registered
|
||||
setLegacyMode(false);
|
||||
}
|
||||
}
|
||||
|
||||
void KStatusNotifierItemPrivate::checkForRegisteredHosts()
|
||||
{
|
||||
setLegacyMode(!statusNotifierWatcher ||
|
||||
!statusNotifierWatcher->property("IsStatusNotifierHostRegistered").toBool());
|
||||
}
|
||||
|
||||
void KStatusNotifierItemPrivate::setLegacyMode(bool legacy)
|
||||
{
|
||||
if (legacy == (systemTrayIcon != 0)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (legacy) {
|
||||
//unregistered
|
||||
setLegacySystemTrayEnabled(true);
|
||||
} else {
|
||||
//registered
|
||||
registerToDaemon();
|
||||
}
|
||||
}
|
||||
|
||||
void KStatusNotifierItemPrivate::legacyWheelEvent(int delta)
|
||||
{
|
||||
statusNotifierItemDBus->Scroll(delta, "vertical");
|
||||
}
|
||||
|
||||
void KStatusNotifierItemPrivate::legacyActivated(QSystemTrayIcon::ActivationReason reason)
|
||||
{
|
||||
if (reason == QSystemTrayIcon::MiddleClick) {
|
||||
emit q->secondaryActivateRequested(systemTrayIcon->geometry().topLeft());
|
||||
}
|
||||
}
|
||||
|
||||
void KStatusNotifierItemPrivate::setLegacySystemTrayEnabled(bool enabled)
|
||||
{
|
||||
if (enabled == (systemTrayIcon != 0)) {
|
||||
// already in the correct state
|
||||
return;
|
||||
}
|
||||
|
||||
if (enabled) {
|
||||
if (!systemTrayIcon) {
|
||||
systemTrayIcon = new KStatusNotifierLegacyIcon(associatedWidget);
|
||||
syncLegacySystemTrayIcon();
|
||||
systemTrayIcon->setToolTip(toolTipTitle);
|
||||
systemTrayIcon->show();
|
||||
QObject::connect(systemTrayIcon, SIGNAL(wheel(int)), q, SLOT(legacyWheelEvent(int)));
|
||||
QObject::connect(systemTrayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), q, SLOT(legacyActivated(QSystemTrayIcon::ActivationReason)));
|
||||
}
|
||||
|
||||
if (menu) {
|
||||
menu->setWindowFlags(Qt::Popup);
|
||||
}
|
||||
} else {
|
||||
delete systemTrayIcon;
|
||||
systemTrayIcon = 0;
|
||||
|
||||
if (menu) {
|
||||
menu->setWindowFlags(Qt::Window);
|
||||
}
|
||||
}
|
||||
|
||||
if (menu) {
|
||||
KMenu *m = menu;
|
||||
menu = 0;
|
||||
q->setContextMenu(m);
|
||||
}
|
||||
}
|
||||
|
||||
void KStatusNotifierItemPrivate::syncLegacySystemTrayIcon()
|
||||
{
|
||||
if (status == KStatusNotifierItem::NeedsAttention) {
|
||||
if (!attentionIconName.isNull()) {
|
||||
systemTrayIcon->setIcon(KIcon(attentionIconName));
|
||||
} else {
|
||||
systemTrayIcon->setIcon(attentionIcon);
|
||||
}
|
||||
} else {
|
||||
if (!iconName.isNull()) {
|
||||
systemTrayIcon->setIcon(KIcon(iconName));
|
||||
} else {
|
||||
systemTrayIcon->setIcon(icon);
|
||||
}
|
||||
}
|
||||
|
||||
systemTrayIcon->setToolTip(toolTipTitle);
|
||||
}
|
||||
|
||||
void KStatusNotifierItemPrivate::contextMenuAboutToShow()
|
||||
{
|
||||
if (!hasQuit && standardActionsEnabled) {
|
||||
// we need to add the actions to the menu afterwards so that these items
|
||||
// appear at the _END_ of the menu
|
||||
menu->addSeparator();
|
||||
if (associatedWidget && associatedWidget != menu) {
|
||||
QAction *action = actionCollection->action("minimizeRestore");
|
||||
|
||||
if (action) {
|
||||
menu->addAction(action);
|
||||
}
|
||||
}
|
||||
|
||||
QAction *action = actionCollection->action(KStandardAction::name(KStandardAction::Quit));
|
||||
|
||||
if (action) {
|
||||
menu->addAction(action);
|
||||
}
|
||||
|
||||
hasQuit = true;
|
||||
}
|
||||
|
||||
if (associatedWidget && associatedWidget != menu) {
|
||||
QAction* action = actionCollection->action("minimizeRestore");
|
||||
if (checkVisibility(QPoint(0, 0), false)) {
|
||||
action->setText(i18n("&Restore"));
|
||||
} else {
|
||||
action->setText(i18n("&Minimize"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void KStatusNotifierItemPrivate::maybeQuit()
|
||||
{
|
||||
QString caption = KGlobal::caption();
|
||||
QString query = i18n("<qt>Are you sure you want to quit <b>%1</b>?</qt>", caption);
|
||||
|
||||
if (KMessageBox::warningContinueCancel(associatedWidget, query,
|
||||
i18n("Confirm Quit From System Tray"),
|
||||
KStandardGuiItem::quit(),
|
||||
KStandardGuiItem::cancel(),
|
||||
QString("systemtrayquit%1")
|
||||
.arg(caption)) == KMessageBox::Continue) {
|
||||
qApp->quit();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void KStatusNotifierItemPrivate::minimizeRestore()
|
||||
{
|
||||
q->activate(QPoint(0, 0));
|
||||
}
|
||||
|
||||
void KStatusNotifierItemPrivate::hideMenu()
|
||||
{
|
||||
menu->hide();
|
||||
}
|
||||
|
||||
void KStatusNotifierItemPrivate::minimizeRestore(bool show)
|
||||
{
|
||||
#ifdef Q_WS_X11
|
||||
KWindowInfo info = KWindowSystem::windowInfo(associatedWidget->winId(), NET::WMDesktop | NET::WMFrameExtents);
|
||||
if (show) {
|
||||
if (onAllDesktops) {
|
||||
KWindowSystem::setOnAllDesktops(associatedWidget->winId(), true);
|
||||
} else {
|
||||
KWindowSystem::setCurrentDesktop(info.desktop());
|
||||
}
|
||||
|
||||
associatedWidget->move(info.frameGeometry().topLeft()); // avoid placement policies
|
||||
associatedWidget->show();
|
||||
associatedWidget->raise();
|
||||
KWindowSystem::raiseWindow(associatedWidget->winId());
|
||||
KWindowSystem::forceActiveWindow(associatedWidget->winId());
|
||||
} else {
|
||||
onAllDesktops = info.onAllDesktops();
|
||||
associatedWidget->hide();
|
||||
}
|
||||
#else
|
||||
if (show) {
|
||||
associatedWidget->show();
|
||||
associatedWidget->raise();
|
||||
KWindowSystem::forceActiveWindow(associatedWidget->winId());
|
||||
} else {
|
||||
associatedWidget->hide();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
KDbusImageStruct KStatusNotifierItemPrivate::imageToStruct(const QImage &image)
|
||||
{
|
||||
KDbusImageStruct icon;
|
||||
icon.width = image.width();
|
||||
icon.height = image.height();
|
||||
if (image.format() == QImage::Format_ARGB32) {
|
||||
icon.data = QByteArray((const char*)image.constBits(), image.byteCount());
|
||||
} else {
|
||||
QImage image32 = image.convertToFormat(QImage::Format_ARGB32);
|
||||
icon.data = QByteArray((const char*)image32.constBits(), image32.byteCount());
|
||||
}
|
||||
|
||||
return icon;
|
||||
}
|
||||
|
||||
KDbusImageVector KStatusNotifierItemPrivate::iconToVector(const QIcon &icon)
|
||||
{
|
||||
KDbusImageVector iconVector;
|
||||
|
||||
QPixmap iconPixmap;
|
||||
|
||||
bool imageAdded = false;
|
||||
const QList<QSize> availableSizes = icon.availableSizes();
|
||||
foreach (const QSize &size, availableSizes) {
|
||||
// hopefully huge and enormous not necessary right now since it's quite costly
|
||||
if (size.width() <= KIconLoader::SizeLarge) {
|
||||
imageAdded = true;
|
||||
iconPixmap = icon.pixmap(size);
|
||||
iconVector.append(imageToStruct(iconPixmap.toImage()));
|
||||
}
|
||||
}
|
||||
if (!imageAdded && !availableSizes.isEmpty()) {
|
||||
// but if only enormous size is available scale it down and add that, this happens to be
|
||||
// the case for some window icons
|
||||
iconPixmap = icon.pixmap(KIconLoader::SizeLarge);
|
||||
iconVector.append(imageToStruct(iconPixmap.toImage()));
|
||||
}
|
||||
|
||||
return iconVector;
|
||||
}
|
||||
|
||||
#include "moc_kstatusnotifieritem.cpp"
|
||||
#include "moc_kstatusnotifieritemprivate_p.cpp"
|
|
@ -1,445 +0,0 @@
|
|||
/* This file is part of the KDE libraries
|
||||
Copyright 2009 by Marco Martin <notmart@gmail.com>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License (LGPL) as published by the Free Software Foundation;
|
||||
either version 2 of the License, or (at your option) any later
|
||||
version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public License
|
||||
along with this library; see the file COPYING.LIB. If not, write to
|
||||
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef KSTATUSNOTIFIERITEM_H
|
||||
#define KSTATUSNOTIFIERITEM_H
|
||||
|
||||
#include <QtCore/QObject>
|
||||
#include <QtDBus/QDBusArgument>
|
||||
#include <QtCore/QPoint>
|
||||
|
||||
#include "kdeui_export.h"
|
||||
|
||||
class KActionCollection;
|
||||
class KMenu;
|
||||
class KStatusNotifierItemPrivate;
|
||||
|
||||
/**
|
||||
* \brief %KDE Status notifier Item protocol implementation
|
||||
*
|
||||
* This class implements the Status notifier Item Dbus specification.
|
||||
* It provides an icon similar to the classical systemtray icons,
|
||||
* with some key differences:
|
||||
*
|
||||
* - the actual representation is done by the systemtray (or the app behaving
|
||||
* like it) itself, not by this app. Since 4.5 this also includes the menu,
|
||||
* which means you cannot use embed widgets in the menu.
|
||||
*
|
||||
* - there is communication between the systemtray and the icon owner, so the
|
||||
* system tray can know if the application is in a normal or in a requesting
|
||||
* attention state.
|
||||
*
|
||||
* - icons are divided in categories, so the systemtray can represent in a
|
||||
* different way the icons from normal applications and for instance the ones
|
||||
* about hardware status.
|
||||
*
|
||||
* Whenever possible you should prefer passing icon by name rather than by
|
||||
* pixmap because:
|
||||
*
|
||||
* - it is much lighter on Dbus (no need to pass all image pixels).
|
||||
*
|
||||
* - it makes it possible for the systemtray to load an icon of the appropriate
|
||||
* size or to replace your icon with a systemtray specific icon which matches
|
||||
* with the desktop theme.
|
||||
*
|
||||
* - some implementations of the system tray do not support passing icons by
|
||||
* pixmap and will show a blank icon instead.
|
||||
*
|
||||
* @author Marco Martin <notmart@gmail.com>
|
||||
* @since 4.4
|
||||
*/
|
||||
class KDEUI_EXPORT KStatusNotifierItem : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
Q_ENUMS(ItemStatus)
|
||||
Q_ENUMS(ItemCategory)
|
||||
Q_PROPERTY( ItemCategory category READ category WRITE setCategory )
|
||||
Q_PROPERTY( QString title READ title WRITE setTitle )
|
||||
Q_PROPERTY( ItemStatus status READ status WRITE setStatus )
|
||||
Q_PROPERTY( QString iconName READ iconName WRITE setIconByName )
|
||||
Q_PROPERTY( QString overlayIconName READ overlayIconName WRITE setOverlayIconByName )
|
||||
Q_PROPERTY( QString attentionIconName READ attentionIconName WRITE setAttentionIconByName )
|
||||
Q_PROPERTY( QString toolTipIconName READ toolTipIconName WRITE setToolTipIconByName )
|
||||
Q_PROPERTY( QString toolTipTitle READ toolTipTitle WRITE setToolTipTitle )
|
||||
Q_PROPERTY( QString toolTipSubTitle READ toolTipSubTitle WRITE setToolTipSubTitle )
|
||||
|
||||
friend class KStatusNotifierItemDBus;
|
||||
friend class KStatusNotifierItemPrivate;
|
||||
public:
|
||||
/**
|
||||
* All the possible status this icon can have, depending on the
|
||||
* importance of the events that happens in the parent application
|
||||
*/
|
||||
enum ItemStatus {
|
||||
/// Nothing is happening in the application, so showing this icon is not required
|
||||
Passive = 1,
|
||||
/// The application is doing something, or it is important that the
|
||||
/// icon is always reachable from the user
|
||||
Active = 2,
|
||||
/// The application requests the attention of the user, for instance
|
||||
/// battery running out or a new IM message was received
|
||||
NeedsAttention = 3
|
||||
};
|
||||
|
||||
/**
|
||||
* Different kinds of applications announce their type to the systemtray,
|
||||
* so can be drawn in a different way or in a different place
|
||||
*/
|
||||
enum ItemCategory {
|
||||
/// An icon for a normal application, can be seen as its taskbar entry
|
||||
ApplicationStatus = 1,
|
||||
/// This is a communication oriented application; this icon will be used
|
||||
/// for things such as the notification of a new message
|
||||
Communications = 2,
|
||||
/// This is a system service, it can show itself in the system tray if
|
||||
/// it requires interaction from the user or wants to inform him about
|
||||
/// something
|
||||
SystemServices = 3,
|
||||
/// This application shows hardware status or a means to control it
|
||||
Hardware = 4,
|
||||
};
|
||||
|
||||
/**
|
||||
* Construct a new status notifier item
|
||||
*
|
||||
* @param parent the parent object for this object. If the object passed in as
|
||||
* a parent is also a QWidget, it will be used as the main application window
|
||||
* represented by this icon and will be shown/hidden when an activation is requested.
|
||||
* @see associatedWidget
|
||||
**/
|
||||
explicit KStatusNotifierItem(QObject *parent = 0);
|
||||
|
||||
/**
|
||||
* Construct a new status notifier item with a unique identifier.
|
||||
* If your application has more than one status notifier item and the user
|
||||
* should be able to manipulate them separately (e.g. mark them for hiding
|
||||
* in a user interface), the id can be used to differentiate between them.
|
||||
*
|
||||
* The id should remain consistent even between application restarts.
|
||||
* Status notifier items without ids default to the application's name for the id.
|
||||
* This id may be used, for instance, by hosts displaying status notifier items to
|
||||
* associate configuration information with this item in a way that can persist
|
||||
* between sessions or application restarts.
|
||||
*
|
||||
* @param id the unique id for this icon
|
||||
* @param parent the parent object for this object. If the object passed in as
|
||||
* a parent is also a QWidget, it will be used as the main application window
|
||||
* represented by this icon and will be shown/hidden when an activation is requested.
|
||||
* @see associatedWidget
|
||||
**/
|
||||
explicit KStatusNotifierItem(const QString &id, QObject *parent = 0);
|
||||
|
||||
~KStatusNotifierItem();
|
||||
|
||||
/**
|
||||
* @return The id which was specified in the constructor. This should be
|
||||
* guaranteed to be consistent between application starts and
|
||||
* untranslated, as host applications displaying items may use it for
|
||||
* storing configuration related to this item.
|
||||
*/
|
||||
QString id() const;
|
||||
|
||||
/**
|
||||
* Sets the category for this icon, usually it's needed to call this function only once
|
||||
*
|
||||
* @param category the new category for this icon
|
||||
*/
|
||||
void setCategory(const ItemCategory category);
|
||||
|
||||
/**
|
||||
* @return the application category
|
||||
*/
|
||||
ItemCategory category() const;
|
||||
|
||||
/**
|
||||
* Sets a title for this icon
|
||||
*/
|
||||
void setTitle(const QString &title);
|
||||
|
||||
/**
|
||||
* @return the title of this icon
|
||||
*/
|
||||
QString title() const;
|
||||
|
||||
/**
|
||||
* Sets a new status for this icon.
|
||||
*/
|
||||
void setStatus(const ItemStatus status);
|
||||
|
||||
/**
|
||||
* @return the current application status
|
||||
*/
|
||||
ItemStatus status() const;
|
||||
|
||||
//Main icon related functions
|
||||
/**
|
||||
* Sets a new main icon for the system tray
|
||||
*
|
||||
* @param name it must be a KIconLoader compatible name, this is
|
||||
* the preferred way to set an icon
|
||||
*/
|
||||
void setIconByName(const QString &name);
|
||||
|
||||
/**
|
||||
* @return the name of the main icon to be displayed
|
||||
* if image() is not empty this will always return an empty string
|
||||
*/
|
||||
QString iconName() const;
|
||||
|
||||
/**
|
||||
* Sets a new main icon for the system tray
|
||||
*
|
||||
* @param pixmap our icon, use setIcon(const QString) when possible
|
||||
*/
|
||||
void setIconByPixmap(const QIcon &icon);
|
||||
|
||||
/**
|
||||
* @return a pixmap of the icon
|
||||
*/
|
||||
QIcon iconPixmap() const;
|
||||
|
||||
/**
|
||||
* Sets an icon to be used as overlay for the main one
|
||||
* @param icon name, if name is and empty QString()
|
||||
* (and overlayIconPixmap() is empty too) the icon will be removed
|
||||
*/
|
||||
void setOverlayIconByName(const QString &name);
|
||||
|
||||
/**
|
||||
* @return the name of the icon to be used as overlay fr the main one
|
||||
*/
|
||||
QString overlayIconName() const;
|
||||
|
||||
/**
|
||||
* Sets an icon to be used as overlay for the main one
|
||||
* setOverlayIconByPixmap(QIcon()) will remove the overlay when
|
||||
* overlayIconName() is empty too.
|
||||
*
|
||||
* @param pixmap our overlay icon, use setOverlayIcon(const QString) when possible.
|
||||
*/
|
||||
void setOverlayIconByPixmap(const QIcon &icon);
|
||||
|
||||
/**
|
||||
* @return a pixmap of the icon
|
||||
*/
|
||||
QIcon overlayIconPixmap() const;
|
||||
|
||||
//Requesting attention icon
|
||||
|
||||
/**
|
||||
* Sets a new icon that should be used when the application
|
||||
* wants to request attention (usually the systemtray
|
||||
* will blink between this icon and the main one)
|
||||
*
|
||||
* @param name KIconLoader-compatible name of icon to use
|
||||
*/
|
||||
void setAttentionIconByName(const QString &name);
|
||||
|
||||
/**
|
||||
* @return the name of the icon to be displayed when the application
|
||||
* is requesting the user's attention
|
||||
* if attentionImage() is not empty this will always return an empty string
|
||||
*/
|
||||
QString attentionIconName() const;
|
||||
|
||||
/**
|
||||
* Sets the pixmap of the requesting attention icon.
|
||||
* Use setAttentionIcon(const QString) instead when possible.
|
||||
*
|
||||
* @param icon QIcon to use for requesting attention.
|
||||
*/
|
||||
void setAttentionIconByPixmap(const QIcon &icon);
|
||||
|
||||
/**
|
||||
* @return a pixmap of the requesting attention icon
|
||||
*/
|
||||
QIcon attentionIconPixmap() const;
|
||||
|
||||
//ToolTip handling
|
||||
/**
|
||||
* Sets a new toolTip or this icon, a toolTip is composed of an icon,
|
||||
* a title ad a text, all fields are optional.
|
||||
*
|
||||
* @param iconName a KIconLoader compatible name for the tootip icon
|
||||
* @param title tootip title
|
||||
* @param subTitle subtitle for the toolTip
|
||||
*/
|
||||
void setToolTip(const QString &iconName, const QString &title, const QString &subTitle);
|
||||
|
||||
/**
|
||||
* Sets a new toolTip or this status notifier item.
|
||||
* This is an overloaded member provided for convenience
|
||||
*/
|
||||
void setToolTip(const QIcon &icon, const QString &title, const QString &subTitle);
|
||||
|
||||
/**
|
||||
* Set a new icon for the toolTip
|
||||
*
|
||||
* @param name the name for the icon
|
||||
*/
|
||||
void setToolTipIconByName(const QString &name);
|
||||
|
||||
/**
|
||||
* @return the name of the toolTip icon
|
||||
* if toolTipImage() is not empty this will always return an empty string
|
||||
*/
|
||||
QString toolTipIconName() const;
|
||||
|
||||
/**
|
||||
* Set a new icon for the toolTip.
|
||||
*
|
||||
* Use setToolTipIconByName(QString) if possible.
|
||||
* @param pixmap representing the icon
|
||||
*/
|
||||
void setToolTipIconByPixmap(const QIcon &icon);
|
||||
|
||||
/**
|
||||
* @return a serialization of the toolTip icon data
|
||||
*/
|
||||
QIcon toolTipIconPixmap() const;
|
||||
|
||||
/**
|
||||
* Sets a new title for the toolTip
|
||||
*/
|
||||
void setToolTipTitle(const QString &title);
|
||||
|
||||
/**
|
||||
* @return the title of the main icon toolTip
|
||||
*/
|
||||
QString toolTipTitle() const;
|
||||
|
||||
/**
|
||||
* Sets a new subtitle for the toolTip
|
||||
*/
|
||||
void setToolTipSubTitle(const QString &subTitle);
|
||||
|
||||
/**
|
||||
* @return the subtitle of the main icon toolTip
|
||||
*/
|
||||
QString toolTipSubTitle() const;
|
||||
|
||||
/**
|
||||
* Sets a new context menu for this StatusNotifierItem.
|
||||
* the menu will be shown with a contextMenu(int,int)
|
||||
* call by the systemtray over dbus
|
||||
* usually you don't need to call this unless you want to use
|
||||
* a custom KMenu subclass as context menu
|
||||
*/
|
||||
void setContextMenu(KMenu *menu);
|
||||
|
||||
/**
|
||||
* Access the context menu associated to this status notifier item
|
||||
*/
|
||||
KMenu *contextMenu() const;
|
||||
|
||||
/**
|
||||
* Sets the main widget associated with this StatusNotifierItem
|
||||
*
|
||||
* If you pass contextMenu() as a parent then the menu will be displayed
|
||||
* when the user activate the icon. In this case the activate() method will
|
||||
* not be called and the activateRequested() signal will not be emitted
|
||||
*
|
||||
* @param parent the new main widget: must be a top level window,
|
||||
* if it's not parent->window() will be used instead.
|
||||
*/
|
||||
void setAssociatedWidget(QWidget *parent);
|
||||
|
||||
/**
|
||||
* Access the main widget associated with this StatusNotifierItem
|
||||
*/
|
||||
QWidget *associatedWidget() const;
|
||||
|
||||
/**
|
||||
* All the actions present in the menu
|
||||
*/
|
||||
KActionCollection *actionCollection() const;
|
||||
|
||||
/**
|
||||
* Sets whether to show the standard items in the menu, such as Quit
|
||||
*/
|
||||
void setStandardActionsEnabled(bool enabled);
|
||||
|
||||
/**
|
||||
* @return if the standard items in the menu, such as Quit
|
||||
*/
|
||||
bool standardActionsEnabled() const;
|
||||
|
||||
public Q_SLOTS:
|
||||
|
||||
/**
|
||||
* Shows the main widget and try to position it on top
|
||||
* of the other windows, if the widget is already visible, hide it.
|
||||
*
|
||||
* @param pos if it's a valid position it represents the mouse coordinates when the event was triggered
|
||||
*/
|
||||
virtual void activate(const QPoint &pos = QPoint());
|
||||
|
||||
Q_SIGNALS:
|
||||
/**
|
||||
* Inform the host application that the mouse wheel
|
||||
* (or another mean of scrolling that the visualization provides) has been used
|
||||
*
|
||||
* @param delta the amount of scrolling, can be either positive or negative
|
||||
* @param orientation direction of the scrolling, can be either horizontal or vertical
|
||||
*/
|
||||
void scrollRequested(int delta, Qt::Orientation orientation);
|
||||
|
||||
/**
|
||||
* Inform the host application that an activation has been requested,
|
||||
* for instance left mouse click, but this is not guaranteed since
|
||||
* it's dependent from the visualization
|
||||
* @param active if it's true the application asked for the activatin
|
||||
* of the main window, if it's false it asked for hiding
|
||||
* @param pos the position in the screen where the user clicked to
|
||||
* trigger this signal, QPoint() if it's not the consequence of a mouse click.
|
||||
*/
|
||||
void activateRequested(bool active, const QPoint &pos);
|
||||
|
||||
/**
|
||||
* Alternate activate action,
|
||||
* for instance right mouse click, but this is not guaranteed since
|
||||
* it's dependent from the visualization
|
||||
*
|
||||
* @param pos the position in the screen where the user clicked to
|
||||
* trigger this signal, QPoint() if it's not the consequence of a mouse click.
|
||||
*/
|
||||
void secondaryActivateRequested(const QPoint &pos);
|
||||
|
||||
protected:
|
||||
bool eventFilter(QObject *watched, QEvent *event);
|
||||
|
||||
private:
|
||||
KStatusNotifierItemPrivate *const d;
|
||||
|
||||
Q_PRIVATE_SLOT(d, void serviceChange(const QString& name,
|
||||
const QString& oldOwner,
|
||||
const QString& newOwner))
|
||||
Q_PRIVATE_SLOT(d, void checkForRegisteredHosts())
|
||||
Q_PRIVATE_SLOT(d, void registerToDaemon())
|
||||
Q_PRIVATE_SLOT(d, void contextMenuAboutToShow())
|
||||
Q_PRIVATE_SLOT(d, void maybeQuit())
|
||||
Q_PRIVATE_SLOT(d, void minimizeRestore())
|
||||
Q_PRIVATE_SLOT(d, void hideMenu())
|
||||
Q_PRIVATE_SLOT(d, void legacyWheelEvent(int))
|
||||
Q_PRIVATE_SLOT(d, void legacyActivated(QSystemTrayIcon::ActivationReason))
|
||||
};
|
||||
|
||||
#endif
|
|
@ -1,308 +0,0 @@
|
|||
/* This file is part of the KDE libraries
|
||||
Copyright 2009 by Marco Martin <notmart@gmail.com>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License (LGPL) as published by the Free Software Foundation;
|
||||
either version 2 of the License, or (at your option) any later
|
||||
version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public License
|
||||
along with this library; see the file COPYING.LIB. If not, write to
|
||||
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "kstatusnotifieritemdbus_p.h"
|
||||
#include "kstatusnotifieritemprivate_p.h"
|
||||
#include "kstatusnotifieritem.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QMetaObject>
|
||||
|
||||
#include <kdebug.h>
|
||||
#include <ksystemtrayicon.h>
|
||||
#include <kaboutdata.h>
|
||||
#include <kicon.h>
|
||||
#include <kmenu.h>
|
||||
#include <kaction.h>
|
||||
#include <kwindowinfo.h>
|
||||
#include <kwindowsystem.h>
|
||||
#include <kmessagebox.h>
|
||||
#include <kactioncollection.h>
|
||||
|
||||
#include "statusnotifierwatcher_interface.h"
|
||||
#include "statusnotifieritemadaptor.h"
|
||||
|
||||
// Marshall the ImageStruct data into a D-BUS argument
|
||||
const QDBusArgument &operator<<(QDBusArgument &argument, const KDbusImageStruct &icon)
|
||||
{
|
||||
argument.beginStructure();
|
||||
argument << icon.width;
|
||||
argument << icon.height;
|
||||
argument << icon.data;
|
||||
argument.endStructure();
|
||||
return argument;
|
||||
}
|
||||
|
||||
// Retrieve the ImageStruct data from the D-BUS argument
|
||||
const QDBusArgument &operator>>(const QDBusArgument &argument, KDbusImageStruct &icon)
|
||||
{
|
||||
qint32 width;
|
||||
qint32 height;
|
||||
QByteArray data;
|
||||
|
||||
argument.beginStructure();
|
||||
argument >> width;
|
||||
argument >> height;
|
||||
argument >> data;
|
||||
argument.endStructure();
|
||||
|
||||
icon.width = width;
|
||||
icon.height = height;
|
||||
icon.data = data;
|
||||
|
||||
return argument;
|
||||
}
|
||||
|
||||
|
||||
// Marshall the ImageVector data into a D-BUS argument
|
||||
const QDBusArgument &operator<<(QDBusArgument &argument, const KDbusImageVector &iconVector)
|
||||
{
|
||||
argument.beginArray(qMetaTypeId<KDbusImageStruct>());
|
||||
for (int i=0; i<iconVector.size(); ++i) {
|
||||
argument << iconVector[i];
|
||||
}
|
||||
argument.endArray();
|
||||
return argument;
|
||||
}
|
||||
|
||||
// Retrieve the ImageVector data from the D-BUS argument
|
||||
const QDBusArgument &operator>>(const QDBusArgument &argument, KDbusImageVector &iconVector)
|
||||
{
|
||||
argument.beginArray();
|
||||
iconVector.clear();
|
||||
|
||||
while ( !argument.atEnd() ) {
|
||||
KDbusImageStruct element;
|
||||
argument >> element;
|
||||
iconVector.append(element);
|
||||
}
|
||||
|
||||
argument.endArray();
|
||||
|
||||
|
||||
return argument;
|
||||
}
|
||||
|
||||
// Marshall the ToolTipStruct data into a D-BUS argument
|
||||
const QDBusArgument &operator<<(QDBusArgument &argument, const KDbusToolTipStruct &toolTip)
|
||||
{
|
||||
argument.beginStructure();
|
||||
argument << toolTip.icon;
|
||||
argument << toolTip.image;
|
||||
argument << toolTip.title;
|
||||
argument << toolTip.subTitle;
|
||||
argument.endStructure();
|
||||
return argument;
|
||||
}
|
||||
|
||||
// Retrieve the ToolTipStruct data from the D-BUS argument
|
||||
const QDBusArgument &operator>>(const QDBusArgument &argument, KDbusToolTipStruct &toolTip)
|
||||
{
|
||||
QString icon;
|
||||
KDbusImageVector image;
|
||||
QString title;
|
||||
QString subTitle;
|
||||
|
||||
argument.beginStructure();
|
||||
argument >> icon;
|
||||
argument >> image;
|
||||
argument >> title;
|
||||
argument >> subTitle;
|
||||
argument.endStructure();
|
||||
|
||||
toolTip.icon = icon;
|
||||
toolTip.image = image;
|
||||
toolTip.title = title;
|
||||
toolTip.subTitle = subTitle;
|
||||
|
||||
return argument;
|
||||
}
|
||||
|
||||
|
||||
int KStatusNotifierItemDBus::s_serviceCount = 0;
|
||||
|
||||
KStatusNotifierItemDBus::KStatusNotifierItemDBus(KStatusNotifierItem *parent)
|
||||
: QObject(parent),
|
||||
m_statusNotifierItem(parent),
|
||||
m_service(QString("org.kde.StatusNotifierItem-%1-%2")
|
||||
.arg(QCoreApplication::applicationPid())
|
||||
.arg(++s_serviceCount)),
|
||||
m_dbus(QDBusConnection::connectToBus(QDBusConnection::SessionBus, m_service))
|
||||
{
|
||||
new StatusNotifierItemAdaptor(this);
|
||||
kDebug(299) << "service is" << m_service;
|
||||
m_dbus.registerService(m_service);
|
||||
m_dbus.registerObject("/StatusNotifierItem", this);
|
||||
}
|
||||
|
||||
KStatusNotifierItemDBus::~KStatusNotifierItemDBus()
|
||||
{
|
||||
m_dbus.unregisterObject("/StatusNotifierItem");
|
||||
m_dbus.unregisterService(m_service);
|
||||
m_dbus.disconnectFromBus(m_service);
|
||||
}
|
||||
|
||||
QDBusConnection KStatusNotifierItemDBus::dbusConnection() const
|
||||
{
|
||||
return m_dbus;
|
||||
}
|
||||
|
||||
QString KStatusNotifierItemDBus::service() const
|
||||
{
|
||||
return m_service;
|
||||
}
|
||||
|
||||
bool KStatusNotifierItemDBus::ItemIsMenu() const
|
||||
{
|
||||
return (m_statusNotifierItem->d->associatedWidget == m_statusNotifierItem->d->menu);
|
||||
}
|
||||
|
||||
//DBUS slots
|
||||
|
||||
QString KStatusNotifierItemDBus::Category() const
|
||||
{
|
||||
return m_statusNotifierItem->metaObject()->enumerator(m_statusNotifierItem->metaObject()->indexOfEnumerator("ItemCategory")).valueToKey(m_statusNotifierItem->category());
|
||||
}
|
||||
|
||||
QString KStatusNotifierItemDBus::Title() const
|
||||
{
|
||||
return m_statusNotifierItem->title();
|
||||
}
|
||||
|
||||
QString KStatusNotifierItemDBus::Id() const
|
||||
{
|
||||
return m_statusNotifierItem->id();
|
||||
}
|
||||
|
||||
QString KStatusNotifierItemDBus::Status() const
|
||||
{
|
||||
return m_statusNotifierItem->metaObject()->enumerator(m_statusNotifierItem->metaObject()->indexOfEnumerator("ItemStatus")).valueToKey(m_statusNotifierItem->status());
|
||||
}
|
||||
|
||||
qlonglong KStatusNotifierItemDBus::WindowId() const
|
||||
{
|
||||
if (m_statusNotifierItem->d->associatedWidget && m_statusNotifierItem->d->associatedWidget != m_statusNotifierItem->d->menu) {
|
||||
return static_cast<qlonglong>(m_statusNotifierItem->d->associatedWidget->winId());
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//Icon
|
||||
|
||||
QString KStatusNotifierItemDBus::IconName() const
|
||||
{
|
||||
return m_statusNotifierItem->iconName();
|
||||
}
|
||||
|
||||
KDbusImageVector KStatusNotifierItemDBus::IconPixmap() const
|
||||
{
|
||||
return m_statusNotifierItem->d->serializedIcon;
|
||||
}
|
||||
|
||||
QString KStatusNotifierItemDBus::OverlayIconName() const
|
||||
{
|
||||
return m_statusNotifierItem->overlayIconName();
|
||||
}
|
||||
|
||||
KDbusImageVector KStatusNotifierItemDBus::OverlayIconPixmap() const
|
||||
{
|
||||
return m_statusNotifierItem->d->serializedOverlayIcon;
|
||||
}
|
||||
|
||||
//Requesting attention icon
|
||||
|
||||
QString KStatusNotifierItemDBus::AttentionIconName() const
|
||||
{
|
||||
return m_statusNotifierItem->attentionIconName();
|
||||
}
|
||||
|
||||
KDbusImageVector KStatusNotifierItemDBus::AttentionIconPixmap() const
|
||||
{
|
||||
return m_statusNotifierItem->d->serializedAttentionIcon;
|
||||
}
|
||||
|
||||
|
||||
//ToolTip
|
||||
|
||||
KDbusToolTipStruct KStatusNotifierItemDBus::ToolTip() const
|
||||
{
|
||||
KDbusToolTipStruct toolTip;
|
||||
toolTip.icon = m_statusNotifierItem->toolTipIconName();
|
||||
toolTip.image = m_statusNotifierItem->d->serializedToolTipIcon;
|
||||
toolTip.title = m_statusNotifierItem->toolTipTitle();
|
||||
toolTip.subTitle = m_statusNotifierItem->toolTipSubTitle();
|
||||
|
||||
return toolTip;
|
||||
}
|
||||
|
||||
QString KStatusNotifierItemDBus::IconThemePath() const
|
||||
{
|
||||
return m_statusNotifierItem->d->iconThemePath;
|
||||
}
|
||||
|
||||
//Menu
|
||||
QDBusObjectPath KStatusNotifierItemDBus::Menu() const
|
||||
{
|
||||
return QDBusObjectPath(m_statusNotifierItem->d->menuObjectPath);
|
||||
}
|
||||
|
||||
//Interaction
|
||||
|
||||
void KStatusNotifierItemDBus::ContextMenu(int x, int y)
|
||||
{
|
||||
if (!m_statusNotifierItem->d->menu) {
|
||||
return;
|
||||
}
|
||||
|
||||
//TODO: nicer placement, possible?
|
||||
if (!m_statusNotifierItem->d->menu->isVisible()) {
|
||||
m_statusNotifierItem->d->menu->setWindowFlags(Qt::Window|Qt::FramelessWindowHint);
|
||||
m_statusNotifierItem->d->menu->popup(QPoint(x,y));
|
||||
KWindowSystem::setState(m_statusNotifierItem->d->menu->winId(), NET::SkipTaskbar|NET::SkipPager|NET::KeepAbove);
|
||||
KWindowSystem::setType(m_statusNotifierItem->d->menu->winId(), NET::PopupMenu);
|
||||
KWindowSystem::forceActiveWindow(m_statusNotifierItem->d->menu->winId());
|
||||
} else {
|
||||
m_statusNotifierItem->d->menu->hide();
|
||||
}
|
||||
}
|
||||
|
||||
void KStatusNotifierItemDBus::Activate(int x, int y)
|
||||
{
|
||||
if (m_statusNotifierItem->d->associatedWidget == m_statusNotifierItem->d->menu) {
|
||||
ContextMenu(x, y);
|
||||
} else {
|
||||
m_statusNotifierItem->activate(QPoint(x,y));
|
||||
}
|
||||
}
|
||||
|
||||
void KStatusNotifierItemDBus::SecondaryActivate(int x, int y)
|
||||
{
|
||||
emit m_statusNotifierItem->secondaryActivateRequested(QPoint(x,y));
|
||||
}
|
||||
|
||||
void KStatusNotifierItemDBus::Scroll(int delta, const QString &orientation)
|
||||
{
|
||||
Qt::Orientation dir = (orientation.toLower() == "horizontal" ? Qt::Horizontal : Qt::Vertical);
|
||||
emit m_statusNotifierItem->scrollRequested(delta, dir);
|
||||
}
|
||||
|
||||
#include "moc_kstatusnotifieritemdbus_p.cpp"
|
|
@ -1,242 +0,0 @@
|
|||
/* This file is part of the KDE libraries
|
||||
Copyright 2009 by Marco Martin <notmart@gmail.com>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License (LGPL) as published by the Free Software Foundation;
|
||||
either version 2 of the License, or (at your option) any later
|
||||
version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public License
|
||||
along with this library; see the file COPYING.LIB. If not, write to
|
||||
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef KSTATUSNOTIFIERITEMDBUS_H
|
||||
#define KSTATUSNOTIFIERITEMDBUS_H
|
||||
|
||||
#include <kdedmodule.h>
|
||||
|
||||
#include <QObject>
|
||||
#include <QDBusArgument>
|
||||
#include <QDBusConnection>
|
||||
#include <QtDBus/qdbusextratypes.h>
|
||||
#include <QPixmap>
|
||||
|
||||
//Custom message type for DBus
|
||||
struct KDbusImageStruct {
|
||||
int width;
|
||||
int height;
|
||||
QByteArray data;
|
||||
};
|
||||
|
||||
typedef QVector<KDbusImageStruct> KDbusImageVector;
|
||||
|
||||
struct KDbusToolTipStruct {
|
||||
QString icon;
|
||||
KDbusImageVector image;
|
||||
QString title;
|
||||
QString subTitle;
|
||||
};
|
||||
|
||||
class KStatusNotifierItem;
|
||||
|
||||
class KStatusNotifierItemDBus : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
Q_PROPERTY(QString Category READ Category)
|
||||
Q_PROPERTY(QString Id READ Id)
|
||||
Q_PROPERTY(QString Title READ Title)
|
||||
Q_PROPERTY(QString Status READ Status)
|
||||
Q_PROPERTY(qlonglong WindowId READ WindowId)
|
||||
Q_PROPERTY(bool ItemIsMenu READ ItemIsMenu)
|
||||
Q_PROPERTY(QString IconName READ IconName)
|
||||
Q_PROPERTY(KDbusImageVector IconPixmap READ IconPixmap)
|
||||
Q_PROPERTY(QString OverlayIconName READ OverlayIconName)
|
||||
Q_PROPERTY(KDbusImageVector OverlayIconPixmap READ OverlayIconPixmap)
|
||||
Q_PROPERTY(QString AttentionIconName READ AttentionIconName)
|
||||
Q_PROPERTY(KDbusImageVector AttentionIconPixmap READ AttentionIconPixmap)
|
||||
Q_PROPERTY(KDbusToolTipStruct ToolTip READ ToolTip)
|
||||
Q_PROPERTY(QString IconThemePath READ IconThemePath)
|
||||
Q_PROPERTY(QDBusObjectPath Menu READ Menu)
|
||||
|
||||
friend class KStatusNotifierItem;
|
||||
public:
|
||||
KStatusNotifierItemDBus(KStatusNotifierItem *parent);
|
||||
~KStatusNotifierItemDBus();
|
||||
|
||||
/**
|
||||
* @return the dbus connection used by this object
|
||||
*/
|
||||
QDBusConnection dbusConnection() const;
|
||||
|
||||
/**
|
||||
* @return the service this object is registered on the bus under
|
||||
*/
|
||||
QString service() const;
|
||||
|
||||
/**
|
||||
* @return the category of the application associated to this item
|
||||
* @see Category
|
||||
*/
|
||||
QString Category() const;
|
||||
|
||||
/**
|
||||
* @return the id of this item
|
||||
*/
|
||||
QString Id() const;
|
||||
|
||||
/**
|
||||
* @return the title of this item
|
||||
*/
|
||||
QString Title() const;
|
||||
|
||||
/**
|
||||
* @return The status of this item
|
||||
* @see Status
|
||||
*/
|
||||
QString Status() const;
|
||||
|
||||
/**
|
||||
* @return The id of the main window of the application that controls the item
|
||||
*/
|
||||
qlonglong WindowId() const;
|
||||
|
||||
/**
|
||||
* @return The item only support the context menu, the visualization should prefer sending ContextMenu() instead of Activate()
|
||||
*/
|
||||
bool ItemIsMenu() const;
|
||||
|
||||
/**
|
||||
* @return the name of the main icon to be displayed
|
||||
* if image() is not empty this will always return an empty string
|
||||
*/
|
||||
QString IconName() const;
|
||||
|
||||
/**
|
||||
* @return a serialization of the icon data
|
||||
*/
|
||||
KDbusImageVector IconPixmap() const;
|
||||
|
||||
/**
|
||||
* @return the name of the overlay of the main icon to be displayed
|
||||
* if image() is not empty this will always return an empty string
|
||||
*/
|
||||
QString OverlayIconName() const;
|
||||
|
||||
/**
|
||||
* @return a serialization of the icon data
|
||||
*/
|
||||
KDbusImageVector OverlayIconPixmap() const;
|
||||
|
||||
/**
|
||||
* @return the name of the icon to be displayed when the application
|
||||
* is requesting the user's attention
|
||||
* if attentionImage() is not empty this will always return an empty string
|
||||
*/
|
||||
QString AttentionIconName() const;
|
||||
|
||||
/**
|
||||
* @return a serialization of the requesting attention icon data
|
||||
*/
|
||||
KDbusImageVector AttentionIconPixmap() const;
|
||||
|
||||
/**
|
||||
* all the data needed for a tooltip
|
||||
*/
|
||||
KDbusToolTipStruct ToolTip() const;
|
||||
|
||||
/**
|
||||
* @return path to extra icon theme, to load application specific icons
|
||||
*/
|
||||
QString IconThemePath() const;
|
||||
|
||||
/**
|
||||
* @return object path to the dbusmenu object
|
||||
*/
|
||||
QDBusObjectPath Menu() const;
|
||||
|
||||
public Q_SLOTS:
|
||||
//interaction
|
||||
/**
|
||||
* Shows the context menu associated to this item
|
||||
* at the desired screen position
|
||||
*/
|
||||
void ContextMenu(int x, int y);
|
||||
|
||||
/**
|
||||
* Shows the main widget and try to position it on top
|
||||
* of the other windows, if the widget is already visible, hide it.
|
||||
*/
|
||||
void Activate(int x, int y);
|
||||
|
||||
/**
|
||||
* The user activated the item in an alternate way (for instance with middle mouse button, this depends from the systray implementation)
|
||||
*/
|
||||
void SecondaryActivate(int x, int y);
|
||||
|
||||
/**
|
||||
* Inform this item that the mouse wheel was used on its representation
|
||||
*/
|
||||
void Scroll(int delta, const QString &orientation);
|
||||
|
||||
Q_SIGNALS:
|
||||
/**
|
||||
* Inform the systemtray that the own main icon has been changed,
|
||||
* so should be reloaded
|
||||
*/
|
||||
void NewIcon();
|
||||
|
||||
/**
|
||||
* Inform the systemtray that there is a new icon to be used as overlay
|
||||
*/
|
||||
void NewOverlayIcon();
|
||||
|
||||
/**
|
||||
* Inform the systemtray that the requesting attention icon
|
||||
* has been changed, so should be reloaded
|
||||
*/
|
||||
void NewAttentionIcon();
|
||||
|
||||
/**
|
||||
* Inform the systemtray that something in the tooltip has been changed
|
||||
*/
|
||||
void NewToolTip();
|
||||
|
||||
/**
|
||||
* Signal the new status when it has been changed
|
||||
* @see Status
|
||||
*/
|
||||
void NewStatus(const QString &status);
|
||||
|
||||
private:
|
||||
KStatusNotifierItem *m_statusNotifierItem;
|
||||
QString m_service;
|
||||
QDBusConnection m_dbus;
|
||||
static int s_serviceCount;
|
||||
};
|
||||
|
||||
|
||||
const QDBusArgument &operator<<(QDBusArgument &argument, const KDbusImageStruct &icon);
|
||||
const QDBusArgument &operator>>(const QDBusArgument &argument, KDbusImageStruct &icon);
|
||||
|
||||
Q_DECLARE_METATYPE(KDbusImageStruct)
|
||||
|
||||
const QDBusArgument &operator<<(QDBusArgument &argument, const KDbusImageVector &iconVector);
|
||||
const QDBusArgument &operator>>(const QDBusArgument &argument, KDbusImageVector &iconVector);
|
||||
|
||||
Q_DECLARE_METATYPE(KDbusImageVector)
|
||||
|
||||
const QDBusArgument &operator<<(QDBusArgument &argument, const KDbusToolTipStruct &toolTip);
|
||||
const QDBusArgument &operator>>(const QDBusArgument &argument, KDbusToolTipStruct &toolTip);
|
||||
|
||||
Q_DECLARE_METATYPE(KDbusToolTipStruct)
|
||||
|
||||
#endif
|
|
@ -1,131 +0,0 @@
|
|||
/* This file is part of the KDE libraries
|
||||
Copyright 2009 by Marco Martin <notmart@gmail.com>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License (LGPL) as published by the Free Software Foundation;
|
||||
either version 2 of the License, or (at your option) any later
|
||||
version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public License
|
||||
along with this library; see the file COPYING.LIB. If not, write to
|
||||
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef KSTATUSNOTIFIERITEMPRIVATE_H
|
||||
#define KSTATUSNOTIFIERITEMPRIVATE_H
|
||||
|
||||
#include <QtCore/qpointer.h>
|
||||
#include <QtGui/qevent.h>
|
||||
#include <QAction>
|
||||
|
||||
#include <ksystemtrayicon.h>
|
||||
|
||||
#include "kstatusnotifieritem.h"
|
||||
#include "kstatusnotifieritemdbus_p.h"
|
||||
|
||||
#include "statusnotifierwatcher_interface.h"
|
||||
|
||||
class KActionCollection;
|
||||
class KSystemTrayIcon;
|
||||
class KMenu;
|
||||
|
||||
// this class is needed because we can't just put an event filter on it:
|
||||
// the events that are passed to QSystemTrayIcon are done so in a way that
|
||||
// bypasses the usual event filtering mechanisms *sigh*
|
||||
class KStatusNotifierLegacyIcon : public KSystemTrayIcon
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
KStatusNotifierLegacyIcon(QWidget *parent)
|
||||
: KSystemTrayIcon(parent)
|
||||
{
|
||||
}
|
||||
|
||||
bool event(QEvent *e)
|
||||
{
|
||||
if (e->type() == QEvent::Wheel) {
|
||||
QWheelEvent *wheelEvent = static_cast<QWheelEvent *>(e);
|
||||
emit wheel(wheelEvent->delta());
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
Q_SIGNALS:
|
||||
void wheel(int);
|
||||
};
|
||||
|
||||
class KStatusNotifierItemPrivate
|
||||
{
|
||||
public:
|
||||
KStatusNotifierItemPrivate(KStatusNotifierItem *item);
|
||||
|
||||
void init(const QString &extraId);
|
||||
void registerToDaemon();
|
||||
void serviceChange(const QString &name, const QString &oldOwner, const QString &newOwner);
|
||||
void setLegacySystemTrayEnabled(bool enabled);
|
||||
void syncLegacySystemTrayIcon();
|
||||
void contextMenuAboutToShow();
|
||||
void maybeQuit();
|
||||
void minimizeRestore();
|
||||
void minimizeRestore(bool show);
|
||||
void hideMenu();
|
||||
void setLegacyMode(bool legacy);
|
||||
void checkForRegisteredHosts();
|
||||
void legacyWheelEvent(int delta);
|
||||
void legacyActivated(QSystemTrayIcon::ActivationReason reason);
|
||||
|
||||
KDbusImageStruct imageToStruct(const QImage &image);
|
||||
KDbusImageVector iconToVector(const QIcon &icon);
|
||||
bool checkVisibility(QPoint pos, bool perform = true);
|
||||
|
||||
KStatusNotifierItem *q;
|
||||
|
||||
KStatusNotifierItem::ItemCategory category;
|
||||
QString id;
|
||||
QString title;
|
||||
KStatusNotifierItem::ItemStatus status;
|
||||
|
||||
QString iconName;
|
||||
KDbusImageVector serializedIcon;
|
||||
QIcon icon;
|
||||
|
||||
QString overlayIconName;
|
||||
KDbusImageVector serializedOverlayIcon;
|
||||
QIcon overlayIcon;
|
||||
|
||||
QString attentionIconName;
|
||||
QIcon attentionIcon;
|
||||
KDbusImageVector serializedAttentionIcon;
|
||||
|
||||
QString toolTipIconName;
|
||||
KDbusImageVector serializedToolTipIcon;
|
||||
QIcon toolTipIcon;
|
||||
QString toolTipTitle;
|
||||
QString toolTipSubTitle;
|
||||
QString iconThemePath;
|
||||
QString menuObjectPath;
|
||||
|
||||
KMenu *menu;
|
||||
KActionCollection* actionCollection;
|
||||
QWidget *associatedWidget;
|
||||
QAction* titleAction;
|
||||
org::kde::StatusNotifierWatcher *statusNotifierWatcher;
|
||||
|
||||
KSystemTrayIcon *systemTrayIcon;
|
||||
KStatusNotifierItemDBus *statusNotifierItemDBus;
|
||||
|
||||
bool hasQuit;
|
||||
bool onAllDesktops;
|
||||
bool standardActionsEnabled;
|
||||
};
|
||||
|
||||
#endif
|
|
@ -1,334 +0,0 @@
|
|||
/* This file is part of the KDE libraries
|
||||
|
||||
Copyright (C) 1999 Matthias Ettrich (ettrich@kde.org)
|
||||
Copyright (c) 2007 by Charles Connell <charles@connells.org>
|
||||
Copyright (C) 2008 Lukas Appelhans <l.appelhans@gmx.de>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public License
|
||||
along with this library; see the file COPYING.LIB. If not, write to
|
||||
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "ksystemtrayicon.h"
|
||||
#include "kaboutdata.h"
|
||||
#include "kaction.h"
|
||||
#include "kcomponentdata.h"
|
||||
#include "klocale.h"
|
||||
#include "kmenu.h"
|
||||
#include "kmessagebox.h"
|
||||
#include "kshortcut.h"
|
||||
#include "kactioncollection.h"
|
||||
#include "kstandardaction.h"
|
||||
#include <kwindowsystem.h>
|
||||
|
||||
#ifdef Q_WS_X11
|
||||
#include <QtGui/qx11info_x11.h>
|
||||
#endif
|
||||
|
||||
#include <kiconloader.h>
|
||||
#include <kapplication.h>
|
||||
#include <kconfiggroup.h>
|
||||
|
||||
#include <QToolButton>
|
||||
|
||||
class KSystemTrayIconPrivate
|
||||
{
|
||||
public:
|
||||
KSystemTrayIconPrivate(KSystemTrayIcon* trayIcon, QWidget* parent)
|
||||
: q(trayIcon)
|
||||
{
|
||||
actionCollection = new KActionCollection( trayIcon );
|
||||
hasQuit = false;
|
||||
onAllDesktops = false;
|
||||
window = parent;
|
||||
}
|
||||
|
||||
~KSystemTrayIconPrivate()
|
||||
{
|
||||
delete actionCollection;
|
||||
delete menu;
|
||||
}
|
||||
|
||||
KSystemTrayIcon* q;
|
||||
KActionCollection* actionCollection;
|
||||
KMenu* menu;
|
||||
QWidget* window;
|
||||
QAction* titleAction;
|
||||
bool onAllDesktops : 1; // valid only when the parent widget was hidden
|
||||
bool hasQuit : 1;
|
||||
};
|
||||
|
||||
KSystemTrayIcon::KSystemTrayIcon( QWidget* parent )
|
||||
: QSystemTrayIcon( parent ),
|
||||
d( new KSystemTrayIconPrivate( this, parent ) )
|
||||
{
|
||||
init( parent );
|
||||
}
|
||||
|
||||
KSystemTrayIcon::KSystemTrayIcon( const QString& icon, QWidget* parent )
|
||||
: QSystemTrayIcon( loadIcon( icon ), parent ),
|
||||
d( new KSystemTrayIconPrivate( this, parent ) )
|
||||
{
|
||||
init( parent );
|
||||
}
|
||||
|
||||
KSystemTrayIcon::KSystemTrayIcon( const QIcon& icon, QWidget* parent )
|
||||
: QSystemTrayIcon( icon, parent ),
|
||||
d( new KSystemTrayIconPrivate( this, parent ) )
|
||||
{
|
||||
init( parent );
|
||||
}
|
||||
|
||||
void KSystemTrayIcon::init( QWidget* parent )
|
||||
{
|
||||
// Ensure that closing the last KMainWindow doesn't exit the application
|
||||
// if a system tray icon is still present.
|
||||
KGlobal::ref();
|
||||
d->menu = new KMenu( parent );
|
||||
d->titleAction = d->menu->addTitle( qApp->windowIcon(), KGlobal::caption() );
|
||||
d->menu->setTitle( KGlobal::mainComponent().aboutData()->programName() );
|
||||
connect( d->menu, SIGNAL(aboutToShow()), this, SLOT(contextMenuAboutToShow()) );
|
||||
setContextMenu( d->menu );
|
||||
|
||||
KStandardAction::quit( this, SLOT(maybeQuit()), d->actionCollection );
|
||||
|
||||
if ( parent )
|
||||
{
|
||||
QAction *action = d->actionCollection->addAction("minimizeRestore");
|
||||
action->setText(i18n("Minimize"));
|
||||
connect( action, SIGNAL(triggered(bool)), this, SLOT(minimizeRestoreAction()) );
|
||||
|
||||
#ifdef Q_WS_X11
|
||||
KWindowInfo info = KWindowSystem::windowInfo( parent->winId(), NET::WMDesktop );
|
||||
d->onAllDesktops = info.onAllDesktops();
|
||||
#else
|
||||
d->onAllDesktops = false;
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
d->onAllDesktops = false;
|
||||
}
|
||||
|
||||
connect( this, SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
|
||||
SLOT(activateOrHide(QSystemTrayIcon::ActivationReason)) );
|
||||
}
|
||||
|
||||
QWidget *KSystemTrayIcon::parentWidget() const
|
||||
{
|
||||
return d->window;
|
||||
}
|
||||
|
||||
KSystemTrayIcon::~KSystemTrayIcon()
|
||||
{
|
||||
delete d;
|
||||
KGlobal::deref();
|
||||
}
|
||||
|
||||
void KSystemTrayIcon::contextMenuAboutToShow( )
|
||||
{
|
||||
if ( !d->hasQuit )
|
||||
{
|
||||
// we need to add the actions to the menu afterwards so that these items
|
||||
// appear at the _END_ of the menu
|
||||
d->menu->addSeparator();
|
||||
QAction* action = d->actionCollection->action( "minimizeRestore" );
|
||||
|
||||
if ( action )
|
||||
{
|
||||
d->menu->addAction( action );
|
||||
}
|
||||
|
||||
action = d->actionCollection->action( KStandardAction::name( KStandardAction::Quit ) );
|
||||
|
||||
if ( action )
|
||||
{
|
||||
d->menu->addAction( action );
|
||||
}
|
||||
|
||||
d->hasQuit = true;
|
||||
}
|
||||
|
||||
if ( d->window )
|
||||
{
|
||||
QAction* action = d->actionCollection->action("minimizeRestore");
|
||||
if ( d->window->isVisible() )
|
||||
{
|
||||
action->setText( i18n("&Minimize") );
|
||||
}
|
||||
else
|
||||
{
|
||||
action->setText( i18n("&Restore") );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// called from the popup menu - always do what the menu entry says,
|
||||
// i.e. if the window is shown, no matter if active or not, the menu
|
||||
// entry is "minimize", otherwise it's "restore"
|
||||
void KSystemTrayIcon::minimizeRestoreAction()
|
||||
{
|
||||
if ( d->window )
|
||||
{
|
||||
bool restore = !( d->window->isVisible() );
|
||||
minimizeRestore( restore );
|
||||
}
|
||||
}
|
||||
|
||||
void KSystemTrayIcon::maybeQuit()
|
||||
{
|
||||
QString caption = KGlobal::caption();
|
||||
QString query = i18n("<qt>Are you sure you want to quit <b>%1</b>?</qt>",
|
||||
caption);
|
||||
if (KMessageBox::warningContinueCancel(d->window, query,
|
||||
i18n("Confirm Quit From System Tray"),
|
||||
KStandardGuiItem::quit(),
|
||||
KStandardGuiItem::cancel(),
|
||||
QString("systemtrayquit%1")
|
||||
.arg(caption)) !=
|
||||
KMessageBox::Continue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
emit quitSelected();
|
||||
qApp->quit();
|
||||
}
|
||||
|
||||
// if the window is not the active one, show it if needed, and activate it
|
||||
// (just like taskbar); otherwise hide it
|
||||
void KSystemTrayIcon::activateOrHide( QSystemTrayIcon::ActivationReason reasonCalled )
|
||||
{
|
||||
if ( reasonCalled != QSystemTrayIcon::Trigger )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
QWidget *pw = d->window;
|
||||
if ( !pw )
|
||||
{
|
||||
return;
|
||||
}
|
||||
#if defined(Q_WS_X11)
|
||||
KWindowInfo info1 = KWindowSystem::windowInfo( pw->winId(), NET::XAWMState | NET::WMState );
|
||||
// mapped = visible (but possibly obscured)
|
||||
bool mapped = (info1.mappingState() == NET::Visible) && !info1.isMinimized();
|
||||
// - not mapped -> show, raise, focus
|
||||
// - mapped
|
||||
// - obscured -> raise, focus
|
||||
// - not obscured -> hide
|
||||
if( !mapped )
|
||||
minimizeRestore( true );
|
||||
else
|
||||
{
|
||||
QListIterator< WId > it (KWindowSystem::stackingOrder());
|
||||
it.toBack();
|
||||
while( it.hasPrevious() )
|
||||
{
|
||||
WId id = it.previous();
|
||||
if( id == pw->winId() )
|
||||
break;
|
||||
KWindowInfo info2 = KWindowSystem::windowInfo( id,
|
||||
NET::WMGeometry | NET::XAWMState | NET::WMState | NET::WMWindowType );
|
||||
if( info2.mappingState() != NET::Visible )
|
||||
continue; // not visible on current desktop -> ignore
|
||||
if( !info2.geometry().intersects( pw->geometry()))
|
||||
continue; // not obscuring the window -> ignore
|
||||
if( !info1.hasState( NET::KeepAbove ) && info2.hasState( NET::KeepAbove ))
|
||||
continue; // obscured by window kept above -> ignore
|
||||
NET::WindowType type = info2.windowType( NET::NormalMask | NET::DesktopMask
|
||||
| NET::DockMask | NET::ToolbarMask | NET::MenuMask | NET::DialogMask
|
||||
| NET::UtilityMask | NET::SplashMask );
|
||||
if( type == NET::Dock )
|
||||
continue; // obscured by dock -> ignore
|
||||
pw->raise();
|
||||
KWindowSystem::activateWindow( pw->winId());
|
||||
return;
|
||||
}
|
||||
minimizeRestore( false ); // hide
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void KSystemTrayIcon::minimizeRestore( bool restore )
|
||||
{
|
||||
QWidget* pw = d->window;
|
||||
if (!pw)
|
||||
return;
|
||||
#ifdef Q_WS_X11
|
||||
KWindowInfo info = KWindowSystem::windowInfo(pw->winId(), NET::WMGeometry | NET::WMDesktop);
|
||||
if (restore) {
|
||||
if (d->onAllDesktops) {
|
||||
KWindowSystem::setOnAllDesktops(pw->winId(), true);
|
||||
} else {
|
||||
KWindowSystem::setCurrentDesktop(info.desktop());
|
||||
}
|
||||
pw->move(info.geometry().topLeft()); // avoid placement policies
|
||||
pw->show();
|
||||
pw->raise();
|
||||
KWindowSystem::activateWindow(pw->winId());
|
||||
} else {
|
||||
d->onAllDesktops = info.onAllDesktops();
|
||||
pw->hide();
|
||||
}
|
||||
#else
|
||||
if ( restore )
|
||||
{
|
||||
pw->show();
|
||||
pw->raise();
|
||||
KWindowSystem::forceActiveWindow( pw->winId() );
|
||||
} else {
|
||||
pw->hide();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
KActionCollection* KSystemTrayIcon::actionCollection()
|
||||
{
|
||||
return d->actionCollection;
|
||||
}
|
||||
|
||||
QIcon KSystemTrayIcon::loadIcon(const QString &icon, const KComponentData &componentData)
|
||||
{
|
||||
KConfigGroup cg(componentData.config(), "System Tray");
|
||||
const int iconWidth = cg.readEntry("systrayIconWidth", 22);
|
||||
return KIconLoader::global()->loadIcon( icon, KIconLoader::Panel, iconWidth );
|
||||
}
|
||||
|
||||
void KSystemTrayIcon::toggleActive()
|
||||
{
|
||||
activateOrHide( QSystemTrayIcon::Trigger );
|
||||
}
|
||||
|
||||
bool KSystemTrayIcon::parentWidgetTrayClose() const
|
||||
{
|
||||
if( kapp != NULL && kapp->sessionSaving())
|
||||
return false; // normal close
|
||||
return true;
|
||||
}
|
||||
|
||||
void KSystemTrayIcon::setContextMenuTitle(QAction *action)
|
||||
{
|
||||
// can never be null, and is always the requsted type, so no need to do null checks after casts.
|
||||
QToolButton *button = static_cast<QToolButton*>((static_cast<QWidgetAction*>(d->titleAction))->defaultWidget());
|
||||
button->setDefaultAction(action);
|
||||
}
|
||||
|
||||
QAction *KSystemTrayIcon::contextMenuTitle() const
|
||||
{
|
||||
QToolButton *button = static_cast<QToolButton*>((static_cast<QWidgetAction*>(d->titleAction))->defaultWidget());
|
||||
return button->defaultAction();
|
||||
}
|
||||
|
||||
#include "moc_ksystemtrayicon.cpp"
|
|
@ -1,164 +0,0 @@
|
|||
/* This file is part of the KDE libraries
|
||||
Copyright (C) 1999 Matthias Ettrich <ettrich@kde.org>
|
||||
Copyright (C) 2007 by Charles Connell <charles@connells.org>
|
||||
Copyright (C) 2008 Lukas Appelhans <l.appelhans@gmx.de>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License version 2 as published by the Free Software Foundation.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public License
|
||||
along with this library; see the file COPYING.LIB. If not, write to
|
||||
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
#ifndef KSYSTEMTRAY_H
|
||||
#define KSYSTEMTRAY_H
|
||||
|
||||
#include <kdeui_export.h>
|
||||
#include <kglobal.h>
|
||||
|
||||
#include <QSystemTrayIcon>
|
||||
#include <QAction>
|
||||
|
||||
class KActionCollection;
|
||||
class KSystemTrayIconPrivate;
|
||||
|
||||
/**
|
||||
* \brief %KDE System Tray Window class
|
||||
*
|
||||
* This class implements system tray windows.
|
||||
*
|
||||
* A tray window is a small window (typically 22x22 pixel) that docks
|
||||
* into the system tray in the desktop panel. It usually displays an
|
||||
* icon or an animated icon there. The icon represents
|
||||
* the application, similar to a taskbar button, but consumes less
|
||||
* screen space.
|
||||
*
|
||||
* When the user clicks with the left mouse button on the icon, the
|
||||
* main application window is shown/raised and activated. With the
|
||||
* right mouse button, she gets a popupmenu with application specific
|
||||
* commands, including "Minimize/Restore" and "Quit".
|
||||
*
|
||||
* Please note that this class is being phased out in favor of the KStatusNotifierItem
|
||||
* class, you should consider to use it instead if you are writing a new application
|
||||
* or consider porting the code that uses this class to the KStatusNotifierItem API.
|
||||
*
|
||||
* Also, QSystemTrayIcon::showMessage(..) should not be
|
||||
* used for KDE application because the popup message has no KDE standard
|
||||
* look & feel and cannot be controlled by KDE configurations.
|
||||
* Use KNotification or KPassivePopup instead.
|
||||
*
|
||||
* @author Matthias Ettrich <ettrich@kde.org>
|
||||
**/
|
||||
class KDEUI_EXPORT KSystemTrayIcon : public QSystemTrayIcon //krazy:exclude=qclasses
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
/**
|
||||
* Construct a system tray icon.
|
||||
*
|
||||
* The parent widget @p parent has a special meaning:
|
||||
* Besides owning the tray window, the parent widget will
|
||||
* disappear from taskbars when it is iconified while the tray
|
||||
* window is visible. This is the desired behavior. After all,
|
||||
* the tray window @p is the parent's taskbar icon.
|
||||
*
|
||||
* Furthermore, the parent widget is shown or raised respectively
|
||||
* when the user clicks on the tray window with the left mouse
|
||||
* button.
|
||||
**/
|
||||
explicit KSystemTrayIcon( QWidget* parent = 0 );
|
||||
|
||||
/**
|
||||
* Same as above but allows one to define the icon by name that should
|
||||
* be used for the system tray icon.
|
||||
*/
|
||||
explicit KSystemTrayIcon( const QString& icon, QWidget* parent = 0 );
|
||||
|
||||
/**
|
||||
* Same as above but allows one to define the icon by name that should
|
||||
* be used for the system tray icon.
|
||||
*/
|
||||
explicit KSystemTrayIcon( const QIcon& icon, QWidget* parent = 0 );
|
||||
|
||||
/**
|
||||
* Destructor
|
||||
*/
|
||||
~KSystemTrayIcon();
|
||||
|
||||
/**
|
||||
Easy access to the actions in the context menu
|
||||
Currently includes KStandardAction::Quit and minimizeRestore
|
||||
*/
|
||||
KActionCollection* actionCollection();
|
||||
|
||||
/**
|
||||
Returns the QWidget set by the constructor
|
||||
*/
|
||||
QWidget *parentWidget() const;
|
||||
|
||||
/**
|
||||
Function to be used from function handling closing of the window associated
|
||||
with the tray icon (i.e. QWidget::closeEvent(), KMainWindow::queryClose() or
|
||||
similar). When false is returned, the window closing should proceed normally,
|
||||
when true is returned, special systray-related handling should take place.
|
||||
*/
|
||||
bool parentWidgetTrayClose() const;
|
||||
|
||||
/**
|
||||
* Loads an icon @p icon using the icon loader class of the given componentData @p componentData.
|
||||
* The icon is applied the panel effect as it should only be used to be shown in the
|
||||
* system tray.
|
||||
* It's commonly used in the form : systray->setPixmap( systray->loadIcon( "mysystray" ) );
|
||||
*/
|
||||
static QIcon loadIcon(const QString &icon, const KComponentData &componentData = KGlobal::mainComponent());
|
||||
|
||||
/**
|
||||
* Sets the context menu title action to @p action.
|
||||
* The following code shows how to change the current title.
|
||||
* <code>
|
||||
* QAction *titleAction = contextMenuTitle();
|
||||
* titleAction->setText("New Title");
|
||||
* setContextMenuTitle(titleAction);
|
||||
* </code>
|
||||
* @since 4.1
|
||||
*/
|
||||
void setContextMenuTitle(QAction *action);
|
||||
|
||||
/**
|
||||
* Returns the context menu title action.
|
||||
* @since 4.1
|
||||
*/
|
||||
QAction *contextMenuTitle() const;
|
||||
|
||||
Q_SIGNALS:
|
||||
/**
|
||||
* Emitted when quit is selected in the menu. If you want to perform any other
|
||||
* action than to close the main application window please connect to this signal.
|
||||
*/
|
||||
void quitSelected();
|
||||
|
||||
public Q_SLOTS:
|
||||
void toggleActive();
|
||||
|
||||
private Q_SLOTS:
|
||||
void contextMenuAboutToShow();
|
||||
void minimizeRestoreAction();
|
||||
void maybeQuit();
|
||||
void activateOrHide( QSystemTrayIcon::ActivationReason reasonCalled );
|
||||
|
||||
private:
|
||||
void init( QWidget* );
|
||||
void minimizeRestore( bool restore );
|
||||
|
||||
KSystemTrayIconPrivate* const d;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
@ -1,93 +0,0 @@
|
|||
<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN" "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
|
||||
<node>
|
||||
<interface name="org.kde.StatusNotifierItem">
|
||||
|
||||
<property name="Category" type="s" access="read"/>
|
||||
<property name="Id" type="s" access="read"/>
|
||||
<property name="Title" type="s" access="read"/>
|
||||
<property name="Status" type="s" access="read"/>
|
||||
<property name="WindowId" type="x" access="read"/>
|
||||
|
||||
<!-- An additional path to add to the theme search path to find the icons specified above. -->
|
||||
<property name="IconThemePath" type="s" access="read"/>
|
||||
<property name="Menu" type="o" access="read"/>
|
||||
<property name="ItemIsMenu" type="b" access="read"/>
|
||||
|
||||
|
||||
<!-- main icon -->
|
||||
<!-- names are preferred over pixmaps -->
|
||||
<property name="IconName" type="s" access="read"/>
|
||||
|
||||
<!--struct containing width, height and image data-->
|
||||
<property name="IconPixmap" type="(iiay)" access="read">
|
||||
<annotation name="org.qtproject.QtDBus.QtTypeName" value="KDbusImageVector"/>
|
||||
</property>
|
||||
|
||||
<property name="OverlayIconName" type="s" access="read"/>
|
||||
|
||||
<property name="OverlayIconPixmap" type="(iiay)" access="read">
|
||||
<annotation name="org.qtproject.QtDBus.QtTypeName" value="KDbusImageVector"/>
|
||||
</property>
|
||||
|
||||
|
||||
<!-- Requesting attention icon -->
|
||||
<property name="AttentionIconName" type="s" access="read"/>
|
||||
|
||||
<!--same definition as image-->
|
||||
<property name="AttentionIconPixmap" type="(iiay)" access="read">
|
||||
<annotation name="org.qtproject.QtDBus.QtTypeName" value="KDbusImageVector"/>
|
||||
</property>
|
||||
|
||||
|
||||
<!-- tooltip data -->
|
||||
|
||||
<!--(iiay) is an image-->
|
||||
<property name="ToolTip" type="(s(iiay)ss)" access="read">
|
||||
<annotation name="org.qtproject.QtDBus.QtTypeName" value="KDbusToolTipStruct"/>
|
||||
</property>
|
||||
|
||||
|
||||
<!-- interaction: the systemtray wants the application to do something -->
|
||||
<method name="ContextMenu">
|
||||
<!-- we're passing the coordinates of the icon, so the app knows where to put the popup window -->
|
||||
<arg name="x" type="i" direction="in"/>
|
||||
<arg name="y" type="i" direction="in"/>
|
||||
</method>
|
||||
|
||||
<method name="Activate">
|
||||
<arg name="x" type="i" direction="in"/>
|
||||
<arg name="y" type="i" direction="in"/>
|
||||
</method>
|
||||
|
||||
<method name="SecondaryActivate">
|
||||
<arg name="x" type="i" direction="in"/>
|
||||
<arg name="y" type="i" direction="in"/>
|
||||
</method>
|
||||
|
||||
<method name="Scroll">
|
||||
<arg name="delta" type="i" direction="in"/>
|
||||
<arg name="orientation" type="s" direction="in"/>
|
||||
</method>
|
||||
|
||||
<!-- Signals: the client wants to change something in the status-->
|
||||
<signal name="NewTitle">
|
||||
</signal>
|
||||
|
||||
<signal name="NewIcon">
|
||||
</signal>
|
||||
|
||||
<signal name="NewAttentionIcon">
|
||||
</signal>
|
||||
|
||||
<signal name="NewOverlayIcon">
|
||||
</signal>
|
||||
|
||||
<signal name="NewToolTip">
|
||||
</signal>
|
||||
|
||||
<signal name="NewStatus">
|
||||
<arg name="status" type="s"/>
|
||||
</signal>
|
||||
|
||||
</interface>
|
||||
</node>
|
|
@ -1,42 +0,0 @@
|
|||
<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN" "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
|
||||
<node>
|
||||
<interface name="org.kde.StatusNotifierWatcher">
|
||||
|
||||
<!-- methods -->
|
||||
<method name="RegisterStatusNotifierItem">
|
||||
<arg name="service" type="s" direction="in"/>
|
||||
</method>
|
||||
|
||||
<method name="RegisterStatusNotifierHost">
|
||||
<arg name="service" type="s" direction="in"/>
|
||||
</method>
|
||||
|
||||
|
||||
<!-- properties -->
|
||||
|
||||
<property name="RegisteredStatusNotifierItems" type="as" access="read">
|
||||
<annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="QStringList"/>
|
||||
</property>
|
||||
|
||||
<property name="IsStatusNotifierHostRegistered" type="b" access="read"/>
|
||||
|
||||
<property name="ProtocolVersion" type="i" access="read"/>
|
||||
|
||||
|
||||
<!-- signals -->
|
||||
|
||||
<signal name="StatusNotifierItemRegistered">
|
||||
<arg type="s"/>
|
||||
</signal>
|
||||
|
||||
<signal name="StatusNotifierItemUnregistered">
|
||||
<arg type="s"/>
|
||||
</signal>
|
||||
|
||||
<signal name="StatusNotifierHostRegistered">
|
||||
</signal>
|
||||
|
||||
<signal name="StatusNotifierHostUnregistered">
|
||||
</signal>
|
||||
</interface>
|
||||
</node>
|
|
@ -197,9 +197,6 @@ K_GLOBAL_STATIC(KMWSessionManager, ksm)
|
|||
K_GLOBAL_STATIC(QList<KMainWindow*>, sMemberList)
|
||||
static bool being_first = true;
|
||||
|
||||
extern void kAppCreateTray();
|
||||
extern void kAppDestroyTray();
|
||||
|
||||
KMainWindow::KMainWindow( QWidget* parent, Qt::WindowFlags f )
|
||||
: QMainWindow(parent, f), k_ptr(new KMainWindowPrivate)
|
||||
{
|
||||
|
@ -273,8 +270,6 @@ void KMainWindowPrivate::init(KMainWindow *_q)
|
|||
letDirtySettings = true;
|
||||
|
||||
sizeApplied = false;
|
||||
|
||||
kAppCreateTray();
|
||||
}
|
||||
|
||||
static bool endsWithHashNumber( const QString& s )
|
||||
|
@ -455,9 +450,6 @@ KMainWindow::~KMainWindow()
|
|||
sMemberList->removeAll( this );
|
||||
delete static_cast<QObject *>(k_ptr->dockResizeListener); //so we don't get anymore events after k_ptr is destroyed
|
||||
delete k_ptr;
|
||||
if (sMemberList->isEmpty()) {
|
||||
kAppDestroyTray();
|
||||
}
|
||||
KGlobal::deref();
|
||||
}
|
||||
|
||||
|
|
|
@ -132,6 +132,3 @@ Type=bool
|
|||
|
||||
[PropertyDef::X-KDE-Protocols]
|
||||
Type=QStringList
|
||||
|
||||
[PropertyDef::X-KDE-HasTrayOption]
|
||||
Type=bool
|
||||
|
|
|
@ -154,16 +154,6 @@
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0" colspan="3" >
|
||||
<widget class="QCheckBox" name="systrayCheck" >
|
||||
<property name="whatsThis" >
|
||||
<string>Check this option if you want to have a system tray handle for your application.</string>
|
||||
</property>
|
||||
<property name="text" >
|
||||
<string>&Place in system tray</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
|
|
|
@ -2989,8 +2989,6 @@ public:
|
|||
, m_terminalBool(false)
|
||||
, m_suidBool(false)
|
||||
, m_startupBool(false)
|
||||
, m_systrayBool(false)
|
||||
, m_canSystrayBool(false)
|
||||
{
|
||||
}
|
||||
~KDesktopPropsPluginPrivate()
|
||||
|
@ -3009,8 +3007,6 @@ public:
|
|||
bool m_terminalBool;
|
||||
bool m_suidBool;
|
||||
bool m_startupBool;
|
||||
bool m_systrayBool;
|
||||
bool m_canSystrayBool;
|
||||
};
|
||||
|
||||
KDesktopPropsPlugin::KDesktopPropsPlugin(KPropertiesDialog *props)
|
||||
|
@ -3067,12 +3063,6 @@ KDesktopPropsPlugin::KDesktopPropsPlugin(KPropertiesDialog *props)
|
|||
QString genNameStr = _config.readGenericName();
|
||||
QString commentStr = _config.readComment();
|
||||
QString commandStr = config.readEntry("Exec", QString());
|
||||
if (commandStr.endsWith(QLatin1String(" -tray"))) {
|
||||
commandStr.chop(6);
|
||||
d->m_systrayBool = true;
|
||||
} else {
|
||||
d->m_systrayBool = false;
|
||||
}
|
||||
|
||||
d->m_origCommandStr = commandStr;
|
||||
QString pathStr = config.readEntry("Path", QString()); // not readPathEntry, see kservice.cpp
|
||||
|
@ -3082,7 +3072,6 @@ KDesktopPropsPlugin::KDesktopPropsPlugin(KPropertiesDialog *props)
|
|||
d->m_suidUserStr = config.readEntry("X-KDE-Username");
|
||||
d->m_startupBool = config.readEntry("StartupNotify", false);
|
||||
d->m_startupClassStr = config.readEntry("StartupWMClass", QString());
|
||||
d->m_canSystrayBool = config.readEntry("X-KDE-HasTrayOption", false);
|
||||
|
||||
const QStringList mimeTypes = config.readXdgListEntry("MimeType");
|
||||
|
||||
|
@ -3219,11 +3208,7 @@ void KDesktopPropsPlugin::applyChanges()
|
|||
config.writeEntry("GenericName", d->w->genNameEdit->text() );
|
||||
config.writeEntry("GenericName", d->w->genNameEdit->text(), KConfigGroup::Persistent | KConfigGroup::Localized ); // for compat
|
||||
|
||||
if (d->m_systrayBool) {
|
||||
config.writeEntry("Exec", d->w->commandEdit->text().append(" -tray"));
|
||||
} else {
|
||||
config.writeEntry("Exec", d->w->commandEdit->text());
|
||||
}
|
||||
config.writeEntry("Exec", d->w->commandEdit->text());
|
||||
config.writeEntry("Path", d->w->pathEdit->lineEdit()->text()); // not writePathEntry, see kservice.cpp
|
||||
|
||||
// Write mimeTypes
|
||||
|
@ -3253,7 +3238,6 @@ void KDesktopPropsPlugin::applyChanges()
|
|||
config.writeEntry("X-KDE-Username", d->m_suidUserStr);
|
||||
config.writeEntry("StartupNotify", d->m_startupBool);
|
||||
config.writeEntry("StartupWMClass", d->m_startupClassStr);
|
||||
config.writeEntry("X-KDE-HasTrayOption", d->m_canSystrayBool);
|
||||
config.sync();
|
||||
|
||||
// KSycoca update needed?
|
||||
|
@ -3326,8 +3310,6 @@ void KDesktopPropsPlugin::slotAdvanced()
|
|||
w.startupClassEdit->setText(d->m_startupClassStr);
|
||||
w.startupClassEdit->setEnabled(d->m_startupBool);
|
||||
w.startupClassLabel->setEnabled(d->m_startupBool);
|
||||
w.systrayCheck->setChecked(d->m_systrayBool);
|
||||
w.systrayCheck->setEnabled(d->m_canSystrayBool);
|
||||
|
||||
// Provide username completion up to 1000 users.
|
||||
KCompletion *kcom = new KCompletion;
|
||||
|
@ -3353,7 +3335,6 @@ void KDesktopPropsPlugin::slotAdvanced()
|
|||
connect(w.suidEdit, SIGNAL(textChanged(QString)), this, SIGNAL(changed()) );
|
||||
connect(w.startupInfoCheck, SIGNAL(toggled(bool)), this, SIGNAL(changed()) );
|
||||
connect(w.startupClassEdit, SIGNAL(textChanged(QString)), this, SIGNAL(changed()) );
|
||||
connect(w.systrayCheck, SIGNAL(toggled(bool)), this, SIGNAL(changed()) );
|
||||
|
||||
if (dlg.exec() == QDialog::Accepted) {
|
||||
d->m_terminalOptionStr = w.terminalEdit->text().trimmed();
|
||||
|
@ -3362,7 +3343,6 @@ void KDesktopPropsPlugin::slotAdvanced()
|
|||
d->m_suidUserStr = w.suidEdit->text().trimmed();
|
||||
d->m_startupBool = w.startupInfoCheck->isChecked();
|
||||
d->m_startupClassStr = w.startupClassEdit->text().trimmed();
|
||||
d->m_systrayBool = w.systrayCheck->isChecked();
|
||||
|
||||
if (w.terminalCloseCheck->isChecked()) {
|
||||
d->m_terminalOptionStr.append(" --noclose");
|
||||
|
|
|
@ -9,8 +9,6 @@ include_directories(
|
|||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
${KDE4_KDECORE_INCLUDES}
|
||||
${KDE4_KDEUI_INCLUDES}
|
||||
${CMAKE_SOURCE_DIR}/kdeclarative
|
||||
${CMAKE_BINARY_DIR}/kdeclarative
|
||||
${CMAKE_SOURCE_DIR}/plasma/extenders
|
||||
# for the export headers
|
||||
${CMAKE_BINARY_DIR}/kutils
|
||||
|
@ -27,11 +25,6 @@ if(NOT PLASMA_NO_SOLID)
|
|||
set(PLASMA_EXTRA_LIBS ${PLASMA_EXTRA_LIBS} solid)
|
||||
endif()
|
||||
|
||||
if(NOT PLASMA_NO_KUTILS)
|
||||
include_directories(${CMAKE_SOURCE_DIR}/kutils)
|
||||
set(PLASMA_EXTRA_LIBS ${PLASMA_EXTRA_LIBS} kcmutils)
|
||||
endif()
|
||||
|
||||
configure_file(
|
||||
config-plasma.h.cmake
|
||||
${CMAKE_CURRENT_BINARY_DIR}/config-plasma.h
|
||||
|
@ -62,7 +55,6 @@ set(plasma_LIB_SRCS
|
|||
animations/widgetsnapshot.cpp
|
||||
animations/zoom.cpp
|
||||
applet.cpp
|
||||
configloader.cpp
|
||||
containment.cpp
|
||||
containmentactions.cpp
|
||||
containmentactionspluginsconfig.cpp
|
||||
|
@ -84,7 +76,6 @@ set(plasma_LIB_SRCS
|
|||
private/applethandle.cpp
|
||||
private/associatedapplicationmanager.cpp
|
||||
private/datacontainer_p.cpp
|
||||
private/dataenginebindings.cpp
|
||||
private/dataengineconsumer.cpp
|
||||
private/extenderapplet.cpp
|
||||
private/extenderitemmimedata.cpp
|
||||
|
@ -100,8 +91,6 @@ set(plasma_LIB_SRCS
|
|||
runnercontext.cpp
|
||||
runnermanager.cpp
|
||||
runnersyntax.cpp
|
||||
scripting/appletscript.cpp
|
||||
scripting/scriptengine.cpp
|
||||
service.cpp
|
||||
servicejob.cpp
|
||||
svg.cpp
|
||||
|
@ -113,7 +102,6 @@ set(plasma_LIB_SRCS
|
|||
windoweffects.cpp
|
||||
widgets/checkbox.cpp
|
||||
widgets/combobox.cpp
|
||||
widgets/declarativewidget.cpp
|
||||
widgets/flashinglabel.cpp
|
||||
widgets/frame.cpp
|
||||
widgets/groupbox.cpp
|
||||
|
@ -153,16 +141,11 @@ set_source_files_properties(
|
|||
add_library(plasma SHARED ${plasma_LIB_SRCS})
|
||||
|
||||
target_link_libraries(plasma PUBLIC
|
||||
${QT_QTUITOOLS_LIBRARY}
|
||||
${QT_QTSCRIPT_LIBRARY}
|
||||
${QT_QTNETWORK_LIBRARY}
|
||||
${QT_QTXML_LIBRARY}
|
||||
${QT_QTSVG_LIBRARY}
|
||||
${QT_QTDECLARATIVE_LIBRARY}
|
||||
${PLASMA_EXTRA_LIBS}
|
||||
kdecore
|
||||
kdeui
|
||||
kdeclarative
|
||||
)
|
||||
|
||||
target_link_libraries(plasma PRIVATE ${X11_LIBRARIES})
|
||||
|
@ -192,7 +175,6 @@ install(
|
|||
animations/animation.h
|
||||
animator.h
|
||||
applet.h
|
||||
configloader.h
|
||||
containment.h
|
||||
containmentactions.h
|
||||
containmentactionspluginsconfig.h
|
||||
|
@ -232,7 +214,6 @@ install(
|
|||
FILES
|
||||
widgets/checkbox.h
|
||||
widgets/combobox.h
|
||||
widgets/declarativewidget.h
|
||||
widgets/flashinglabel.h
|
||||
widgets/frame.h
|
||||
widgets/groupbox.h
|
||||
|
@ -260,13 +241,6 @@ install(
|
|||
DESTINATION ${KDE4_INCLUDE_INSTALL_DIR}/plasma/widgets
|
||||
)
|
||||
|
||||
install(
|
||||
FILES
|
||||
scripting/appletscript.h
|
||||
scripting/scriptengine.h
|
||||
DESTINATION ${KDE4_INCLUDE_INSTALL_DIR}/plasma/scripting
|
||||
)
|
||||
|
||||
install(
|
||||
FILES
|
||||
animations/animation.h
|
||||
|
@ -282,7 +256,6 @@ install(
|
|||
data/servicetypes/plasma-containmentactions.desktop
|
||||
data/servicetypes/plasma-dataengine.desktop
|
||||
data/servicetypes/plasma-runner.desktop
|
||||
data/servicetypes/plasma-scriptengine.desktop
|
||||
data/servicetypes/plasma-toolbox.desktop
|
||||
data/servicetypes/plasma-wallpaper.desktop
|
||||
DESTINATION ${KDE4_SERVICETYPES_INSTALL_DIR}
|
||||
|
|
|
@ -421,8 +421,7 @@ class PLASMA_EXPORT AbstractRunner : public QObject
|
|||
protected Q_SLOTS:
|
||||
/**
|
||||
* Reimplement this slot to run any initialization routines on first load.
|
||||
* By default, it calls reloadConfiguration(); for scripted Runners this
|
||||
* method also sets up the ScriptEngine.
|
||||
* By default, it calls reloadConfiguration()
|
||||
*/
|
||||
void init();
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@
|
|||
#include <QEvent>
|
||||
#include <QFile>
|
||||
#include <QGraphicsGridLayout>
|
||||
#include <QtGui/qgraphicssceneevent.h>
|
||||
#include <QGraphicsSceneHoverEvent>
|
||||
#include <QGraphicsView>
|
||||
#include <QLabel>
|
||||
#include <QList>
|
||||
|
@ -42,9 +42,8 @@
|
|||
#include <QPainter>
|
||||
#include <QRegExp>
|
||||
#include <QSize>
|
||||
#include <QtGui/qstyleoption.h>
|
||||
#include <QStyleOptionGraphicsItem>
|
||||
#include <QTextDocument>
|
||||
#include <QUiLoader>
|
||||
#include <QVBoxLayout>
|
||||
#include <QWidget>
|
||||
|
||||
|
@ -64,20 +63,13 @@
|
|||
#include <kwindowsystem.h>
|
||||
#include <kpushbutton.h>
|
||||
#include <krandom.h>
|
||||
|
||||
#ifndef PLASMA_NO_KUTILS
|
||||
#include <kcmoduleinfo.h>
|
||||
#include <kcmoduleproxy.h>
|
||||
#else
|
||||
#include <kcmodule.h>
|
||||
#endif
|
||||
#include <kconfigskeleton.h>
|
||||
|
||||
#ifndef PLASMA_NO_SOLID
|
||||
#include <solid/powermanagement.h>
|
||||
#endif
|
||||
|
||||
#include "abstracttoolbox.h"
|
||||
#include "configloader.h"
|
||||
#include "containment.h"
|
||||
#include "corona.h"
|
||||
#include "dataenginemanager.h"
|
||||
|
@ -86,7 +78,6 @@
|
|||
#include "extenders/extenderitem.h"
|
||||
#include "package.h"
|
||||
#include "plasma.h"
|
||||
#include "scripting/appletscript.h"
|
||||
#include "svg.h"
|
||||
#include "framesvg.h"
|
||||
#include "popupapplet.h"
|
||||
|
@ -188,14 +179,6 @@ Applet::Applet(QObject *parentObject, const QVariantList &args)
|
|||
// inflexibility of KService::createInstance
|
||||
}
|
||||
|
||||
Applet::Applet(const QString &packagePath, uint appletId, const QVariantList &args)
|
||||
: QGraphicsWidget(0),
|
||||
d(new AppletPrivate(KService::Ptr(new KService(packagePath + "/metadata.desktop")), 0, appletId, this))
|
||||
{
|
||||
Q_UNUSED(args) // FIXME?
|
||||
d->init(packagePath);
|
||||
}
|
||||
|
||||
Applet::~Applet()
|
||||
{
|
||||
//let people know that i will die
|
||||
|
@ -223,25 +206,9 @@ Applet::~Applet()
|
|||
delete d;
|
||||
}
|
||||
|
||||
PackageStructure::Ptr Applet::packageStructure()
|
||||
{
|
||||
if (!AppletPrivate::packageStructure) {
|
||||
AppletPrivate::packageStructure = new PlasmoidPackage();
|
||||
}
|
||||
|
||||
return AppletPrivate::packageStructure;
|
||||
}
|
||||
|
||||
void Applet::init()
|
||||
{
|
||||
setFlag(ItemIsMovable, true);
|
||||
if (d->script) {
|
||||
d->setupScriptSupport();
|
||||
|
||||
if (!d->script->init() && !d->failed) {
|
||||
setFailedToLaunch(true, i18n("Script initialization failed"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
uint Applet::id() const
|
||||
|
@ -290,14 +257,6 @@ void Applet::save(KConfigGroup &g) const
|
|||
|
||||
KConfigGroup appletConfigGroup(&group, "Configuration");
|
||||
saveState(appletConfigGroup);
|
||||
|
||||
if (d->configLoader) {
|
||||
// we're saving so we know its changed, we don't need or want the configChanged
|
||||
// signal bubbling up at this point due to that
|
||||
disconnect(d->configLoader, SIGNAL(configChanged()), this, SLOT(propagateConfigChanged()));
|
||||
d->configLoader->writeConfig();
|
||||
connect(d->configLoader, SIGNAL(configChanged()), this, SLOT(propagateConfigChanged()));
|
||||
}
|
||||
}
|
||||
|
||||
void Applet::restore(KConfigGroup &group)
|
||||
|
@ -414,10 +373,6 @@ void Applet::setFailedToLaunch(bool failed, const QString &reason)
|
|||
|
||||
void Applet::saveState(KConfigGroup &group) const
|
||||
{
|
||||
if (d->script) {
|
||||
emit d->script->saveState(group);
|
||||
}
|
||||
|
||||
if (group.config()->name() != config().config()->name()) {
|
||||
// we're being saved to a different file!
|
||||
// let's just copy the current values in our configuration over
|
||||
|
@ -535,10 +490,6 @@ void AppletPrivate::cleanUpAndDelete()
|
|||
}
|
||||
}
|
||||
|
||||
if (configLoader) {
|
||||
configLoader->setDefaults();
|
||||
}
|
||||
|
||||
resetConfigurationObject();
|
||||
|
||||
if (q->scene()) {
|
||||
|
@ -661,21 +612,11 @@ void AppletPrivate::destroyMessageOverlay()
|
|||
}
|
||||
}
|
||||
|
||||
ConfigLoader *Applet::configScheme() const
|
||||
{
|
||||
return d->configLoader;
|
||||
}
|
||||
|
||||
DataEngine *Applet::dataEngine(const QString &name) const
|
||||
{
|
||||
return d->dataEngine(name);
|
||||
}
|
||||
|
||||
const Package *Applet::package() const
|
||||
{
|
||||
return d->package;
|
||||
}
|
||||
|
||||
QGraphicsView *Applet::view() const
|
||||
{
|
||||
// It's assumed that we won't be visible on more than one view here.
|
||||
|
@ -744,22 +685,15 @@ void Applet::constraintsEvent(Plasma::Constraints constraints)
|
|||
Q_UNUSED(constraints)
|
||||
//kDebug() << constraints << "constraints are FormFactor: " << formFactor()
|
||||
// << ", Location: " << location();
|
||||
if (d->script) {
|
||||
d->script->constraintsEvent(constraints);
|
||||
}
|
||||
}
|
||||
|
||||
void Applet::initExtenderItem(ExtenderItem *item)
|
||||
{
|
||||
if (d->script) {
|
||||
emit extenderItemRestored(item);
|
||||
} else {
|
||||
kWarning() << "Missing implementation of initExtenderItem in the applet "
|
||||
<< item->config().readEntry("SourceAppletPluginName", "")
|
||||
<< "!\n Any applet that uses extenders should implement initExtenderItem to "
|
||||
<< "instantiate a widget. Destroying the item...";
|
||||
item->destroy();
|
||||
}
|
||||
kWarning() << "Missing implementation of initExtenderItem in the applet "
|
||||
<< item->config().readEntry("SourceAppletPluginName", "")
|
||||
<< "!\n Any applet that uses extenders should implement initExtenderItem to "
|
||||
<< "instantiate a widget. Destroying the item...";
|
||||
item->destroy();
|
||||
}
|
||||
|
||||
Extender *Applet::extender() const
|
||||
|
@ -834,6 +768,7 @@ QString Applet::pluginName() const
|
|||
|
||||
bool Applet::shouldConserveResources() const
|
||||
{
|
||||
#warning TODO: remove this method, applets should use the solid method
|
||||
#ifndef PLASMA_NO_SOLID
|
||||
return Solid::PowerManagement::appShouldConserveResources();
|
||||
#else
|
||||
|
@ -1360,7 +1295,7 @@ int Applet::type() const
|
|||
QList<QAction*> Applet::contextualActions()
|
||||
{
|
||||
//kDebug() << "empty context actions";
|
||||
return d->script ? d->script->contextualActions() : QList<QAction*>();
|
||||
return QList<QAction*>();
|
||||
}
|
||||
|
||||
QAction *Applet::action(const QString &name) const
|
||||
|
@ -1445,11 +1380,7 @@ void Applet::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QW
|
|||
|
||||
void Applet::paintInterface(QPainter *painter, const QStyleOptionGraphicsItem *option, const QRect &contentsRect)
|
||||
{
|
||||
if (d->script) {
|
||||
d->script->paintInterface(painter, option, contentsRect);
|
||||
} else {
|
||||
//kDebug() << "Applet::paintInterface() default impl";
|
||||
}
|
||||
//kDebug() << "Applet::paintInterface() default impl";
|
||||
}
|
||||
|
||||
FormFactor Applet::formFactor() const
|
||||
|
@ -1832,91 +1763,9 @@ void Applet::showConfigurationInterface()
|
|||
return;
|
||||
}
|
||||
|
||||
if (d->package) {
|
||||
KConfigDialog *dialog = 0;
|
||||
|
||||
const QString uiFile = d->package->filePath("mainconfigui");
|
||||
KDesktopFile df(d->package->path() + "/metadata.desktop");
|
||||
const QStringList kcmPlugins = df.desktopGroup().readEntry("X-Plasma-ConfigPlugins", QStringList());
|
||||
if (!uiFile.isEmpty() || !kcmPlugins.isEmpty()) {
|
||||
KConfigSkeleton *configLoader = d->configLoader ? d->configLoader : new KConfigSkeleton();
|
||||
dialog = new AppletConfigDialog(0, d->configDialogId(), configLoader);
|
||||
|
||||
if (!d->configLoader) {
|
||||
// delete the temporary when this dialog is done
|
||||
configLoader->setParent(dialog);
|
||||
}
|
||||
|
||||
dialog->setWindowTitle(d->configWindowTitle());
|
||||
dialog->setAttribute(Qt::WA_DeleteOnClose, true);
|
||||
bool hasPages = false;
|
||||
|
||||
QFile f(uiFile);
|
||||
QUiLoader loader;
|
||||
QWidget *w = loader.load(&f);
|
||||
if (w) {
|
||||
dialog->addPage(w, i18n("Settings"), icon(), i18n("%1 Settings", name()));
|
||||
hasPages = true;
|
||||
}
|
||||
|
||||
foreach (const QString &kcm, kcmPlugins) {
|
||||
#ifndef PLASMA_NO_KUTILS
|
||||
KCModuleProxy *module = new KCModuleProxy(kcm);
|
||||
if (module->realModule()) {
|
||||
//preemptively load modules to prevent save() crashing on some kcms, like powerdevil ones
|
||||
module->load();
|
||||
connect(module, SIGNAL(changed(bool)), dialog, SLOT(settingsModified(bool)));
|
||||
connect(dialog, SIGNAL(okClicked()),
|
||||
module->realModule(), SLOT(save()));
|
||||
connect(dialog, SIGNAL(applyClicked()),
|
||||
module->realModule(), SLOT(save()));
|
||||
dialog->addPage(module, module->moduleInfo().moduleName(), module->moduleInfo().icon());
|
||||
hasPages = true;
|
||||
} else {
|
||||
delete module;
|
||||
}
|
||||
#else
|
||||
KService::Ptr service = KService::serviceByStorageId(kcm);
|
||||
if (service) {
|
||||
QString error;
|
||||
KCModule *module = service->createInstance<KCModule>(dialog, QVariantList(), &error);
|
||||
if (module) {
|
||||
module->load();
|
||||
connect(module, SIGNAL(changed(bool)), dialog, SLOT(settingsModified(bool)));
|
||||
connect(dialog, SIGNAL(okClicked()),
|
||||
module, SLOT(save()));
|
||||
connect(dialog, SIGNAL(applyClicked()),
|
||||
module, SLOT(save()));
|
||||
dialog->addPage(module, service->name(), service->icon());
|
||||
hasPages = true;
|
||||
} else {
|
||||
#ifndef NDEBUG
|
||||
kDebug() << "failed to load kcm" << kcm << "for" << name();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
if (hasPages) {
|
||||
d->addGlobalShortcutsPage(dialog);
|
||||
dialog->show();
|
||||
} else {
|
||||
delete dialog;
|
||||
dialog = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (!dialog && d->script) {
|
||||
d->script->showConfigurationInterface();
|
||||
}
|
||||
} else if (d->script) {
|
||||
d->script->showConfigurationInterface();
|
||||
} else {
|
||||
KConfigDialog *dialog = d->generateGenericConfigDialog();
|
||||
d->addStandardConfigurationPages(dialog);
|
||||
showConfigurationInterface(dialog);
|
||||
}
|
||||
KConfigDialog *dialog = d->generateGenericConfigDialog();
|
||||
d->addStandardConfigurationPages(dialog);
|
||||
showConfigurationInterface(dialog);
|
||||
|
||||
emit releaseVisualFocus();
|
||||
}
|
||||
|
@ -2021,12 +1870,9 @@ void AppletPrivate::configDialogFinished()
|
|||
}
|
||||
|
||||
|
||||
if (!configLoader) {
|
||||
// the config loader will trigger this for us, so we don't need to.
|
||||
propagateConfigChanged();
|
||||
if (KConfigDialog *dialog = qobject_cast<KConfigDialog *>(q->sender())) {
|
||||
dialog->enableButton(KDialog::Apply, false);
|
||||
}
|
||||
propagateConfigChanged();
|
||||
if (KConfigDialog *dialog = qobject_cast<KConfigDialog *>(q->sender())) {
|
||||
dialog->enableButton(KDialog::Apply, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2071,12 +1917,6 @@ void AppletPrivate::propagateConfigChanged()
|
|||
|
||||
void Applet::configChanged()
|
||||
{
|
||||
if (d->script) {
|
||||
if (d->configLoader) {
|
||||
d->configLoader->readConfig();
|
||||
}
|
||||
d->script->configChanged();
|
||||
}
|
||||
}
|
||||
|
||||
void Applet::createConfigurationInterface(KConfigDialog *parent)
|
||||
|
@ -2229,24 +2069,6 @@ QStringList Applet::listCategories(const QString &parentApp, bool visibleOnly)
|
|||
return categories;
|
||||
}
|
||||
|
||||
Applet *Applet::loadPlasmoid(const QString &path, uint appletId, const QVariantList &args)
|
||||
{
|
||||
if (QFile::exists(path + "/metadata.desktop")) {
|
||||
KService service(path + "/metadata.desktop");
|
||||
const QStringList& types = service.serviceTypes();
|
||||
|
||||
if (types.contains("Plasma/Containment")) {
|
||||
return new Containment(path, appletId, args);
|
||||
} else if (types.contains("Plasma/PopupApplet")) {
|
||||
return new PopupApplet(path, appletId, args);
|
||||
} else {
|
||||
return new Applet(path, appletId, args);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Applet *Applet::load(const QString &appletName, uint appletId, const QVariantList &args)
|
||||
{
|
||||
return PluginLoader::loadApplet(appletName, appletId, args);
|
||||
|
@ -2325,15 +2147,6 @@ QVariant Applet::itemChange(GraphicsItemChange change, const QVariant &value)
|
|||
return ret;
|
||||
}
|
||||
|
||||
QPainterPath Applet::shape() const
|
||||
{
|
||||
if (d->script) {
|
||||
return d->script->shape();
|
||||
}
|
||||
|
||||
return QGraphicsWidget::shape();
|
||||
}
|
||||
|
||||
QSizeF Applet::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const
|
||||
{
|
||||
QSizeF hint = QGraphicsWidget::sizeHint(which, constraint);
|
||||
|
@ -2484,9 +2297,6 @@ AppletPrivate::AppletPrivate(KService::Ptr service, const KPluginInfo *info, int
|
|||
messageOverlay(0),
|
||||
messageOverlayProxy(0),
|
||||
busyWidget(0),
|
||||
script(0),
|
||||
package(0),
|
||||
configLoader(0),
|
||||
actions(AppletPrivate::defaultActions(applet)),
|
||||
activationAction(0),
|
||||
itemStatus(UnknownStatus),
|
||||
|
@ -2515,18 +2325,12 @@ AppletPrivate::~AppletPrivate()
|
|||
|
||||
delete extender.data();
|
||||
|
||||
delete script;
|
||||
script = 0;
|
||||
delete package;
|
||||
package = 0;
|
||||
delete configLoader;
|
||||
configLoader = 0;
|
||||
delete mainConfig;
|
||||
mainConfig = 0;
|
||||
delete modificationsTimer;
|
||||
}
|
||||
|
||||
void AppletPrivate::init(const QString &packagePath)
|
||||
void AppletPrivate::init()
|
||||
{
|
||||
// WARNING: do not access config() OR globalConfig() in this method!
|
||||
// that requires a scene, which is not available at this point
|
||||
|
@ -2568,73 +2372,6 @@ void AppletPrivate::init(const QString &packagePath)
|
|||
}
|
||||
//kDebug() << "size" << size;
|
||||
q->resize(size);
|
||||
|
||||
QString api = appletDescription.property("X-Plasma-API").toString();
|
||||
|
||||
// we have a scripted plasmoid
|
||||
if (!api.isEmpty()) {
|
||||
// find where the Package is
|
||||
QString path = packagePath.isEmpty() ? appletDescription.pluginName() : packagePath;
|
||||
// create the package and see if we have something real
|
||||
PackageStructure::Ptr structure = Plasma::packageStructure(api, Plasma::AppletComponent);
|
||||
package = new Package(path, structure);
|
||||
//kDebug() << "***** package is" << package->path();
|
||||
|
||||
if (package->isValid()) {
|
||||
// now we try and set up the script engine.
|
||||
// it will be parented to this applet and so will get
|
||||
// deleted when the applet does
|
||||
|
||||
script = Plasma::loadScriptEngine(api, q);
|
||||
if (!script) {
|
||||
delete package;
|
||||
package = 0;
|
||||
q->setFailedToLaunch(true,
|
||||
i18nc("API or programming language the widget was written in, name of the widget",
|
||||
"Could not create a %1 ScriptEngine for the %2 widget.",
|
||||
api, appletDescription.name()));
|
||||
}
|
||||
} else {
|
||||
q->setFailedToLaunch(true, i18nc("Package file, name of the widget",
|
||||
"Could not open the %1 package required for the %2 widget.",
|
||||
appletDescription.pluginName(), appletDescription.name()));
|
||||
delete package;
|
||||
package = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// put all setup routines for script here. at this point we can assume that
|
||||
// package exists and that we have a script engine
|
||||
void AppletPrivate::setupScriptSupport()
|
||||
{
|
||||
if (!package) {
|
||||
return;
|
||||
}
|
||||
|
||||
kDebug() << "setting up script support, package is in" << package->path()
|
||||
<< "which is a" << package->structure()->type() << "package"
|
||||
<< ", main script is" << package->filePath("mainscript");
|
||||
|
||||
QString translationsPath = package->filePath("translations");
|
||||
if (!translationsPath.isEmpty()) {
|
||||
//FIXME: we should _probably_ use a KComponentData to segregate the applets
|
||||
// from each other; but I want to get the basics working first :)
|
||||
KGlobal::dirs()->addResourceDir("locale", translationsPath);
|
||||
KGlobal::locale()->insertCatalog(package->metadata().pluginName());
|
||||
}
|
||||
|
||||
QString xmlPath = package->filePath("mainconfigxml");
|
||||
if (!xmlPath.isEmpty()) {
|
||||
QFile file(xmlPath);
|
||||
KConfigGroup config = q->config();
|
||||
configLoader = new ConfigLoader(&config, &file);
|
||||
QObject::connect(configLoader, SIGNAL(configChanged()), q, SLOT(propagateConfigChanged()));
|
||||
}
|
||||
|
||||
if (!package->filePath("mainconfigui").isEmpty()) {
|
||||
q->setHasConfigurationInterface(true);
|
||||
}
|
||||
}
|
||||
|
||||
QString AppletPrivate::globalName() const
|
||||
|
@ -2689,7 +2426,6 @@ KConfigGroup *AppletPrivate::mainConfigGroup()
|
|||
return mainConfig;
|
||||
}
|
||||
|
||||
bool newGroup = false;
|
||||
if (isContainment) {
|
||||
Corona *corona = qobject_cast<Corona*>(q->scene());
|
||||
KConfigGroup containmentConfig;
|
||||
|
@ -2701,10 +2437,6 @@ KConfigGroup *AppletPrivate::mainConfigGroup()
|
|||
containmentConfig = KConfigGroup(KGlobal::config(), "Containments");
|
||||
}
|
||||
|
||||
if (package && !containmentConfig.hasGroup(QString::number(appletId))) {
|
||||
newGroup = true;
|
||||
}
|
||||
|
||||
mainConfig = new KConfigGroup(&containmentConfig, QString::number(appletId));
|
||||
} else {
|
||||
KConfigGroup appletConfig;
|
||||
|
@ -2725,23 +2457,9 @@ KConfigGroup *AppletPrivate::mainConfigGroup()
|
|||
appletConfig = KConfigGroup(KGlobal::config(), "Applets");
|
||||
}
|
||||
|
||||
if (package && !appletConfig.hasGroup(QString::number(appletId))) {
|
||||
newGroup = true;
|
||||
}
|
||||
|
||||
mainConfig = new KConfigGroup(&appletConfig, QString::number(appletId));
|
||||
}
|
||||
|
||||
if (newGroup) {
|
||||
//see if we have a default configuration in our package
|
||||
const QString defaultConfigFile = q->package()->filePath("defaultconfig");
|
||||
if (!defaultConfigFile.isEmpty()) {
|
||||
kDebug() << "copying default config: " << q->package()->filePath("defaultconfig");
|
||||
KConfigGroup defaultConfig(KSharedConfig::openConfig(defaultConfigFile)->group("Configuration"));
|
||||
defaultConfig.copyTo(mainConfig);
|
||||
}
|
||||
}
|
||||
|
||||
return mainConfig;
|
||||
}
|
||||
|
||||
|
@ -2811,7 +2529,6 @@ void ContainmentPrivate::checkRemoveAction()
|
|||
uint AppletPrivate::s_maxAppletId = 0;
|
||||
int AppletPrivate::s_maxZValue = 0;
|
||||
int AppletPrivate::s_minZValue = 0;
|
||||
PackageStructure::Ptr AppletPrivate::packageStructure(0);
|
||||
|
||||
AppletOverlayWidget::AppletOverlayWidget(QGraphicsWidget *parent)
|
||||
: QGraphicsWidget(parent),
|
||||
|
|
|
@ -28,13 +28,12 @@
|
|||
#include <QWidget>
|
||||
#include <QGraphicsView>
|
||||
|
||||
#include <kurl.h>
|
||||
#include <kconfiggroup.h>
|
||||
#include <kplugininfo.h>
|
||||
#include <kshortcut.h>
|
||||
#include <kdeversion.h>
|
||||
|
||||
#include <plasma/configloader.h>
|
||||
#include <plasma/packagestructure.h>
|
||||
#include <plasma/plasma.h>
|
||||
#include <plasma/animator.h>
|
||||
#include <plasma/framesvg.h>
|
||||
|
@ -51,8 +50,6 @@ class Context;
|
|||
class DataEngine;
|
||||
class Extender;
|
||||
class ExtenderItem;
|
||||
class Package;
|
||||
|
||||
|
||||
/**
|
||||
* @class Applet plasma/applet.h <Plasma/Applet>
|
||||
|
@ -66,9 +63,8 @@ class Package;
|
|||
* management of data engines (e.g. all data engines accessed via
|
||||
* Applet::dataEngine(const QString&) are properly deref'd on Applet
|
||||
* destruction), background painting (allowing for consistent and complex
|
||||
* look and feel in just one line of code for applets), loading and starting
|
||||
* of scripting support for each applet, providing access to the associated
|
||||
* plasmoid package (if any) and access to configuration data.
|
||||
* look and feel in just one line of code for applets), providing access to
|
||||
* the to configuration data.
|
||||
*/
|
||||
class PLASMA_EXPORT Applet : public QGraphicsWidget
|
||||
{
|
||||
|
@ -109,11 +105,6 @@ class PLASMA_EXPORT Applet : public QGraphicsWidget
|
|||
|
||||
~Applet();
|
||||
|
||||
/**
|
||||
* @return a package structure representing an Applet
|
||||
*/
|
||||
static PackageStructure::Ptr packageStructure();
|
||||
|
||||
/**
|
||||
* @return the id of this applet
|
||||
*/
|
||||
|
@ -168,14 +159,6 @@ class PLASMA_EXPORT Applet : public QGraphicsWidget
|
|||
*/
|
||||
KConfigGroup globalConfig() const;
|
||||
|
||||
/**
|
||||
* Returns the config skeleton object from this applet's package,
|
||||
* if any.
|
||||
*
|
||||
* @return config skeleton object, or 0 if none
|
||||
**/
|
||||
ConfigLoader *configScheme() const;
|
||||
|
||||
/**
|
||||
* Loads the given DataEngine
|
||||
*
|
||||
|
@ -195,14 +178,6 @@ class PLASMA_EXPORT Applet : public QGraphicsWidget
|
|||
*/
|
||||
Q_INVOKABLE DataEngine *dataEngine(const QString &name) const;
|
||||
|
||||
/**
|
||||
* Accessor for the associated Package object if any.
|
||||
* Generally, only Plasmoids come in a Package.
|
||||
*
|
||||
* @return the Package object, or 0 if none
|
||||
**/
|
||||
const Package *package() const;
|
||||
|
||||
/**
|
||||
* Returns the view this widget is visible on, or 0 if none can be found.
|
||||
* @warning do NOT assume this will always return a view!
|
||||
|
@ -325,23 +300,6 @@ class PLASMA_EXPORT Applet : public QGraphicsWidget
|
|||
static QStringList listCategories(const QString &parentApp = QString(),
|
||||
bool visibleOnly = true);
|
||||
|
||||
/**
|
||||
* Attempts to load an applet from a package
|
||||
*
|
||||
* Returns a pointer to the applet if successful.
|
||||
* The caller takes responsibility for the applet, including
|
||||
* deleting it when no longer needed.
|
||||
*
|
||||
* @param path the path to the package
|
||||
* @param appletId unique ID to assign the applet, or zero to have one
|
||||
* assigned automatically.
|
||||
* @param args to send the applet extra arguments
|
||||
* @return a pointer to the loaded applet, or 0 on load failure
|
||||
* @since 4.3
|
||||
**/
|
||||
static Applet *loadPlasmoid(const QString &path, uint appletId = 0,
|
||||
const QVariantList &args = QVariantList());
|
||||
|
||||
/**
|
||||
* Attempts to load an applet
|
||||
*
|
||||
|
@ -1030,11 +988,6 @@ class PLASMA_EXPORT Applet : public QGraphicsWidget
|
|||
*/
|
||||
QVariant itemChange(GraphicsItemChange change, const QVariant &value);
|
||||
|
||||
/**
|
||||
* Reimplemented from QGraphicsItem
|
||||
*/
|
||||
QPainterPath shape() const;
|
||||
|
||||
/**
|
||||
* Reimplemented from QGraphicsLayoutItem
|
||||
*/
|
||||
|
@ -1045,18 +998,7 @@ class PLASMA_EXPORT Applet : public QGraphicsWidget
|
|||
*/
|
||||
void timerEvent(QTimerEvent *event);
|
||||
|
||||
|
||||
private:
|
||||
/**
|
||||
* @internal This constructor is to be used with the Package loading system.
|
||||
*
|
||||
* @param parent a QObject parent; you probably want to pass in 0
|
||||
* @param args a list of strings containing two entries: the service id
|
||||
* and the applet id
|
||||
* @since 4.3
|
||||
*/
|
||||
Applet(const QString &packagePath, uint appletId, const QVariantList &args);
|
||||
|
||||
Q_PRIVATE_SLOT(d, void setFocus())
|
||||
Q_PRIVATE_SLOT(d, void themeChanged())
|
||||
Q_PRIVATE_SLOT(d, void cleanUpAndDelete())
|
||||
|
@ -1081,7 +1023,6 @@ class PLASMA_EXPORT Applet : public QGraphicsWidget
|
|||
friend class CoronaPrivate;
|
||||
friend class Containment;
|
||||
friend class ContainmentPrivate;
|
||||
friend class AppletScript;
|
||||
friend class AppletHandle;
|
||||
friend class AppletPrivate;
|
||||
friend class PluginLoader;
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
#cmakedefine PLASMA_NO_SOLID
|
||||
#cmakedefine PLASMA_NO_KIO
|
||||
#cmakedefine PLASMA_NO_KUTILS
|
||||
#cmakedefine PLASMA_NO_GLOBAL_SHORTCUTS
|
||||
|
||||
|
|
|
@ -1,432 +0,0 @@
|
|||
/*
|
||||
* Copyright 2007 Aaron Seigo <aseigo@kde.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Library General Public License as
|
||||
* published by the Free Software Foundation; either version 2, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this program; if not, write to the
|
||||
* Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "configloader.h"
|
||||
#include "private/configloader_p.h"
|
||||
|
||||
#include <QColor>
|
||||
#include <QFont>
|
||||
#include <QHash>
|
||||
#include <QXmlInputSource>
|
||||
|
||||
#include <kdebug.h>
|
||||
#include <kurl.h>
|
||||
|
||||
namespace Plasma
|
||||
{
|
||||
class ConfigLoaderHandler : public QXmlDefaultHandler
|
||||
{
|
||||
public:
|
||||
ConfigLoaderHandler(ConfigLoader *config, ConfigLoaderPrivate *d);
|
||||
bool startElement(const QString &namespaceURI, const QString &localName,
|
||||
const QString &qName, const QXmlAttributes &atts);
|
||||
bool endElement(const QString &namespaceURI, const QString &localName,
|
||||
const QString &qName);
|
||||
bool characters(const QString &ch);
|
||||
|
||||
private:
|
||||
void addItem();
|
||||
void resetState();
|
||||
|
||||
ConfigLoader *m_config;
|
||||
ConfigLoaderPrivate *d;
|
||||
int m_min;
|
||||
int m_max;
|
||||
QString m_name;
|
||||
QString m_key;
|
||||
QString m_type;
|
||||
QString m_label;
|
||||
QString m_default;
|
||||
QString m_cdata;
|
||||
QString m_whatsThis;
|
||||
KConfigSkeleton::ItemEnum::Choice m_choice;
|
||||
QList<KConfigSkeleton::ItemEnum::Choice> m_enumChoices;
|
||||
bool m_haveMin;
|
||||
bool m_haveMax;
|
||||
bool m_inChoice;
|
||||
};
|
||||
|
||||
void ConfigLoaderPrivate::parse(ConfigLoader *loader, QIODevice *xml)
|
||||
{
|
||||
QXmlInputSource source(xml);
|
||||
QXmlSimpleReader reader;
|
||||
ConfigLoaderHandler handler(loader, this);
|
||||
reader.setContentHandler(&handler);
|
||||
reader.parse(&source, false);
|
||||
}
|
||||
|
||||
ConfigLoaderHandler::ConfigLoaderHandler(ConfigLoader *config, ConfigLoaderPrivate *d)
|
||||
: QXmlDefaultHandler(),
|
||||
m_config(config),
|
||||
d(d)
|
||||
{
|
||||
resetState();
|
||||
}
|
||||
|
||||
bool ConfigLoaderHandler::startElement(const QString &namespaceURI, const QString &localName,
|
||||
const QString &qName, const QXmlAttributes &attrs)
|
||||
{
|
||||
Q_UNUSED(namespaceURI)
|
||||
Q_UNUSED(qName)
|
||||
|
||||
// kDebug() << "ConfigLoaderHandler::startElement(" << localName << qName;
|
||||
int numAttrs = attrs.count();
|
||||
QString tag = localName.toLower();
|
||||
if (tag == "group") {
|
||||
QString group;
|
||||
for (int i = 0; i < numAttrs; ++i) {
|
||||
QString name = attrs.localName(i).toLower();
|
||||
if (name == "name") {
|
||||
//kDebug() << "set group to" << attrs.value(i);
|
||||
group = attrs.value(i);
|
||||
}
|
||||
}
|
||||
if (group.isEmpty()) {
|
||||
group = d->baseGroup;
|
||||
} else {
|
||||
d->groups.append(group);
|
||||
if (!d->baseGroup.isEmpty()) {
|
||||
group = d->baseGroup + '\x1d' + group;
|
||||
}
|
||||
}
|
||||
m_config->setCurrentGroup(group);
|
||||
} else if (tag == "entry") {
|
||||
for (int i = 0; i < numAttrs; ++i) {
|
||||
QString name = attrs.localName(i).toLower();
|
||||
if (name == "name") {
|
||||
m_name = attrs.value(i).trimmed();
|
||||
} else if (name == "type") {
|
||||
m_type = attrs.value(i).toLower();
|
||||
} else if (name == "key") {
|
||||
m_key = attrs.value(i).trimmed();
|
||||
}
|
||||
}
|
||||
} else if (tag == "choice") {
|
||||
m_choice.name.clear();
|
||||
m_choice.label.clear();
|
||||
m_choice.whatsThis.clear();
|
||||
for (int i = 0; i < numAttrs; ++i) {
|
||||
QString name = attrs.localName(i).toLower();
|
||||
if (name == "name") {
|
||||
m_choice.name = attrs.value(i);
|
||||
}
|
||||
}
|
||||
m_inChoice = true;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ConfigLoaderHandler::characters(const QString &ch)
|
||||
{
|
||||
m_cdata.append(ch);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ConfigLoaderHandler::endElement(const QString &namespaceURI,
|
||||
const QString &localName, const QString &qName)
|
||||
{
|
||||
Q_UNUSED(namespaceURI)
|
||||
Q_UNUSED(qName)
|
||||
|
||||
// kDebug() << "ConfigLoaderHandler::endElement(" << localName << qName;
|
||||
const QString tag = localName.toLower();
|
||||
if (tag == "entry") {
|
||||
addItem();
|
||||
resetState();
|
||||
} else if (tag == "label") {
|
||||
if (m_inChoice) {
|
||||
m_choice.label = m_cdata.trimmed();
|
||||
} else {
|
||||
m_label = m_cdata.trimmed();
|
||||
}
|
||||
} else if (tag == "whatsthis") {
|
||||
if (m_inChoice) {
|
||||
m_choice.whatsThis = m_cdata.trimmed();
|
||||
} else {
|
||||
m_whatsThis = m_cdata.trimmed();
|
||||
}
|
||||
} else if (tag == "default") {
|
||||
m_default = m_cdata.trimmed();
|
||||
} else if (tag == "min") {
|
||||
m_min = m_cdata.toInt(&m_haveMin);
|
||||
} else if (tag == "max") {
|
||||
m_max = m_cdata.toInt(&m_haveMax);
|
||||
} else if (tag == "choice") {
|
||||
m_enumChoices.append(m_choice);
|
||||
m_inChoice = false;
|
||||
}
|
||||
|
||||
m_cdata.clear();
|
||||
return true;
|
||||
}
|
||||
|
||||
void ConfigLoaderHandler::addItem()
|
||||
{
|
||||
if (m_name.isEmpty()) {
|
||||
if (m_key.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_name = m_key;
|
||||
}
|
||||
|
||||
m_name.remove(' ');
|
||||
|
||||
KConfigSkeletonItem *item = 0;
|
||||
|
||||
if (m_type == "bool") {
|
||||
bool defaultValue = m_default.toLower() == "true";
|
||||
item = m_config->addItemBool(m_name, *d->newBool(), defaultValue, m_key);
|
||||
} else if (m_type == "color") {
|
||||
QColor color;
|
||||
|
||||
if (m_default.count(',') == 3) {
|
||||
const QStringList values = m_default.split(',');
|
||||
|
||||
color = QColor(values.at(0).toInt(), values.at(1).toInt(), values.at(2).toInt(), values.at(3).toInt());
|
||||
} else {
|
||||
color = QColor(m_default);
|
||||
}
|
||||
|
||||
item = m_config->addItemColor(m_name, *d->newColor(), color, m_key);
|
||||
} else if (m_type == "datetime") {
|
||||
item = m_config->addItemDateTime(m_name, *d->newDateTime(),
|
||||
QDateTime::fromString(m_default), m_key);
|
||||
} else if (m_type == "enum") {
|
||||
m_key = (m_key.isEmpty()) ? m_name : m_key;
|
||||
KConfigSkeleton::ItemEnum *enumItem =
|
||||
new KConfigSkeleton::ItemEnum(m_config->currentGroup(),
|
||||
m_key, *d->newInt(),
|
||||
m_enumChoices,
|
||||
m_default.toUInt());
|
||||
m_config->addItem(enumItem, m_name);
|
||||
item = enumItem;
|
||||
} else if (m_type == "font") {
|
||||
item = m_config->addItemFont(m_name, *d->newFont(), QFont(m_default), m_key);
|
||||
} else if (m_type == "int") {
|
||||
KConfigSkeleton::ItemInt *intItem = m_config->addItemInt(m_name, *d->newInt(),
|
||||
m_default.toInt(), m_key);
|
||||
|
||||
if (m_haveMin) {
|
||||
intItem->setMinValue(m_min);
|
||||
}
|
||||
|
||||
if (m_haveMax) {
|
||||
intItem->setMaxValue(m_max);
|
||||
}
|
||||
|
||||
item = intItem;
|
||||
} else if (m_type == "path") {
|
||||
item = m_config->addItemPath(m_name, *d->newString(), m_default, m_key);
|
||||
} else if (m_type == "string") {
|
||||
item = m_config->addItemString(m_name, *d->newString(), m_default, m_key);
|
||||
} else if (m_type == "stringlist") {
|
||||
//FIXME: the split() is naive and will break on lists with ,'s in them
|
||||
item = m_config->addItemStringList(m_name, *d->newStringList(),
|
||||
m_default.split(','), m_key);
|
||||
} else if (m_type == "uint") {
|
||||
KConfigSkeleton::ItemUInt *uintItem =
|
||||
m_config->addItemUInt(m_name, *d->newUint(), m_default.toUInt(), m_key);
|
||||
if (m_haveMin) {
|
||||
uintItem->setMinValue(m_min);
|
||||
}
|
||||
if (m_haveMax) {
|
||||
uintItem->setMaxValue(m_max);
|
||||
}
|
||||
item = uintItem;
|
||||
} else if (m_type == "url") {
|
||||
m_key = (m_key.isEmpty()) ? m_name : m_key;
|
||||
KConfigSkeleton::ItemUrl *urlItem =
|
||||
new KConfigSkeleton::ItemUrl(m_config->currentGroup(),
|
||||
m_key, *d->newUrl(),
|
||||
m_default);
|
||||
m_config->addItem(urlItem, m_name);
|
||||
item = urlItem;
|
||||
} else if (m_type == "double") {
|
||||
KConfigSkeleton::ItemDouble *doubleItem = m_config->addItemDouble(m_name,
|
||||
*d->newDouble(), m_default.toDouble(), m_key);
|
||||
if (m_haveMin) {
|
||||
doubleItem->setMinValue(m_min);
|
||||
}
|
||||
if (m_haveMax) {
|
||||
doubleItem->setMaxValue(m_max);
|
||||
}
|
||||
item = doubleItem;
|
||||
} else if (m_type == "intlist") {
|
||||
QStringList tmpList = m_default.split(',');
|
||||
QList<int> defaultList;
|
||||
foreach (const QString &tmp, tmpList) {
|
||||
defaultList.append(tmp.toInt());
|
||||
}
|
||||
item = m_config->addItemIntList(m_name, *d->newIntList(), defaultList, m_key);
|
||||
} else if (m_type == "longlong") {
|
||||
KConfigSkeleton::ItemLongLong *longlongItem = m_config->addItemLongLong(m_name,
|
||||
*d->newLongLong(), m_default.toLongLong(), m_key);
|
||||
if (m_haveMin) {
|
||||
longlongItem->setMinValue(m_min);
|
||||
}
|
||||
if (m_haveMax) {
|
||||
longlongItem->setMaxValue(m_max);
|
||||
}
|
||||
item = longlongItem;
|
||||
/* No addItemPathList in KConfigSkeleton ?
|
||||
} else if (m_type == "PathList") {
|
||||
//FIXME: the split() is naive and will break on lists with ,'s in them
|
||||
item = m_config->addItemPathList(m_name, *d->newStringList(), m_default.split(","), m_key);
|
||||
*/
|
||||
} else if (m_type == "point") {
|
||||
QPoint defaultPoint;
|
||||
QStringList tmpList = m_default.split(',');
|
||||
if (tmpList.size() >= 2) {
|
||||
defaultPoint.setX(tmpList[0].toInt());
|
||||
defaultPoint.setY(tmpList[1].toInt());
|
||||
}
|
||||
item = m_config->addItemPoint(m_name, *d->newPoint(), defaultPoint, m_key);
|
||||
} else if (m_type == "rect") {
|
||||
QRect defaultRect;
|
||||
QStringList tmpList = m_default.split(',');
|
||||
if (tmpList.size() >= 4) {
|
||||
defaultRect.setCoords(tmpList[0].toInt(), tmpList[1].toInt(),
|
||||
tmpList[2].toInt(), tmpList[3].toInt());
|
||||
}
|
||||
item = m_config->addItemRect(m_name, *d->newRect(), defaultRect, m_key);
|
||||
} else if (m_type == "size") {
|
||||
QSize defaultSize;
|
||||
QStringList tmpList = m_default.split(',');
|
||||
if (tmpList.size() >= 2) {
|
||||
defaultSize.setWidth(tmpList[0].toInt());
|
||||
defaultSize.setHeight(tmpList[1].toInt());
|
||||
}
|
||||
item = m_config->addItemSize(m_name, *d->newSize(), defaultSize, m_key);
|
||||
} else if (m_type == "ulonglong") {
|
||||
KConfigSkeleton::ItemULongLong *ulonglongItem =
|
||||
m_config->addItemULongLong(m_name, *d->newULongLong(), m_default.toULongLong(), m_key);
|
||||
if (m_haveMin) {
|
||||
ulonglongItem->setMinValue(m_min);
|
||||
}
|
||||
if (m_haveMax) {
|
||||
ulonglongItem->setMaxValue(m_max);
|
||||
}
|
||||
item = ulonglongItem;
|
||||
/* No addItemUrlList in KConfigSkeleton ?
|
||||
} else if (m_type == "urllist") {
|
||||
//FIXME: the split() is naive and will break on lists with ,'s in them
|
||||
QStringList tmpList = m_default.split(",");
|
||||
KUrl::List defaultList;
|
||||
foreach (const QString& tmp, tmpList) {
|
||||
defaultList.append(KUrl(tmp));
|
||||
}
|
||||
item = m_config->addItemUrlList(m_name, *d->newUrlList(), defaultList, m_key);*/
|
||||
}
|
||||
|
||||
if (item) {
|
||||
item->setLabel(m_label);
|
||||
item->setWhatsThis(m_whatsThis);
|
||||
d->keysToNames.insert(item->group() + item->key(), item->name());
|
||||
}
|
||||
}
|
||||
|
||||
void ConfigLoaderHandler::resetState()
|
||||
{
|
||||
m_haveMin = false;
|
||||
m_min = 0;
|
||||
m_haveMax = false;
|
||||
m_max = 0;
|
||||
m_name.clear();
|
||||
m_type.clear();
|
||||
m_label.clear();
|
||||
m_default.clear();
|
||||
m_key.clear();
|
||||
m_whatsThis.clear();
|
||||
m_enumChoices.clear();
|
||||
m_inChoice = false;
|
||||
}
|
||||
|
||||
ConfigLoader::ConfigLoader(const QString &configFile, QIODevice *xml, QObject *parent)
|
||||
: KConfigSkeleton(configFile, parent),
|
||||
d(new ConfigLoaderPrivate)
|
||||
{
|
||||
d->parse(this, xml);
|
||||
}
|
||||
|
||||
ConfigLoader::ConfigLoader(KSharedConfigPtr config, QIODevice *xml, QObject *parent)
|
||||
: KConfigSkeleton(config, parent),
|
||||
d(new ConfigLoaderPrivate)
|
||||
{
|
||||
d->parse(this, xml);
|
||||
}
|
||||
|
||||
//FIXME: obviously this is broken and should be using the group as the root,
|
||||
// but KConfigSkeleton does not currently support this. it will eventually though,
|
||||
// at which point this can be addressed properly
|
||||
ConfigLoader::ConfigLoader(const KConfigGroup *config, QIODevice *xml, QObject *parent)
|
||||
: KConfigSkeleton(KSharedConfig::openConfig(config->config()->name(), KConfig::SimpleConfig), parent),
|
||||
d(new ConfigLoaderPrivate)
|
||||
{
|
||||
KConfigGroup group = config->parent();
|
||||
d->baseGroup = config->name();
|
||||
while (group.isValid() && group.name() != "<default>") {
|
||||
d->baseGroup = group.name() + '\x1d' + d->baseGroup;
|
||||
group = group.parent();
|
||||
}
|
||||
d->parse(this, xml);
|
||||
}
|
||||
|
||||
ConfigLoader::~ConfigLoader()
|
||||
{
|
||||
delete d;
|
||||
}
|
||||
|
||||
KConfigSkeletonItem *ConfigLoader::findItemByGroup(const QString &group, const QString &key) const
|
||||
{
|
||||
return KConfigSkeleton::findItem(d->keysToNames[group + key]);
|
||||
}
|
||||
|
||||
QVariant ConfigLoader::property(const QString &name) const
|
||||
{
|
||||
KConfigSkeletonItem *item = KConfigSkeleton::findItem(name);
|
||||
if (item) {
|
||||
return item->property();
|
||||
}
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
bool ConfigLoader::hasGroup(const QString &group) const
|
||||
{
|
||||
return d->groups.contains(group);
|
||||
}
|
||||
|
||||
QStringList ConfigLoader::groupList() const
|
||||
{
|
||||
return d->groups;
|
||||
}
|
||||
|
||||
void ConfigLoader::usrWriteConfig()
|
||||
{
|
||||
if (d->saveDefaults) {
|
||||
KConfigSkeletonItem::List itemList = items();
|
||||
for(int i = 0; i < itemList.size(); i++) {
|
||||
KConfigGroup cg(config(), itemList.at(i)->group());
|
||||
cg.writeEntry(itemList.at(i)->key(), "");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // Plasma namespace
|
|
@ -1,149 +0,0 @@
|
|||
/*
|
||||
* Copyright 2007 Aaron Seigo <aseigo@kde.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Library General Public License as
|
||||
* published by the Free Software Foundation; either version 2, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this program; if not, write to the
|
||||
* Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef PLASMA_CONFIGLOADER_H
|
||||
#define PLASMA_CONFIGLOADER_H
|
||||
|
||||
#include <kconfiggroup.h>
|
||||
#include <kconfigskeleton.h>
|
||||
#include <ksharedconfig.h>
|
||||
|
||||
#include <plasma/plasma_export.h>
|
||||
|
||||
/**
|
||||
* @class ConfigLoader plasma/configloader.h <Plasma/ConfigLoader>
|
||||
*
|
||||
* @short A KConfigSkeleton that populates itself based on KConfigXT XML
|
||||
*
|
||||
* This class allows one to ship an XML file and reconstitute it into a
|
||||
* KConfigSkeleton object at runtime. Common usage might look like this:
|
||||
*
|
||||
* \code
|
||||
* QFile file(xmlFilePath);
|
||||
* Plasma::ConfigLoader appletConfig(configFilePath, &file);
|
||||
* \endcode
|
||||
*
|
||||
* Alternatively, any QIODevice may be used in place of QFile in the
|
||||
* example above.
|
||||
*
|
||||
* Currently the following data types are supported:
|
||||
*
|
||||
* @li bools
|
||||
* @li colors
|
||||
* @li datetimes
|
||||
* @li enumerations
|
||||
* @li fonts
|
||||
* @li ints
|
||||
* @li passwords
|
||||
* @li paths
|
||||
* @li strings
|
||||
* @li stringlists
|
||||
* @li uints
|
||||
* @li urls
|
||||
* @li doubles
|
||||
* @li int lists
|
||||
* @li longlongs
|
||||
* @li path lists
|
||||
* @li points
|
||||
* @li rects
|
||||
* @li sizes
|
||||
* @li ulonglongs
|
||||
* @li url lists
|
||||
**/
|
||||
|
||||
namespace Plasma
|
||||
{
|
||||
|
||||
class ConfigLoaderPrivate;
|
||||
|
||||
class PLASMA_EXPORT ConfigLoader : public KConfigSkeleton
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Creates a KConfigSkeleton populated using the definition found in
|
||||
* the XML data passed in.
|
||||
*
|
||||
* @param configFile path to the configuration file to use
|
||||
* @param xml the xml data; must be valid KConfigXT data
|
||||
* @param parent optional QObject parent
|
||||
**/
|
||||
ConfigLoader(const QString &configFile, QIODevice *xml, QObject *parent = 0);
|
||||
|
||||
/**
|
||||
* Creates a KConfigSkeleton populated using the definition found in
|
||||
* the XML data passed in.
|
||||
*
|
||||
* @param config the configuration object to use
|
||||
* @param xml the xml data; must be valid KConfigXT data
|
||||
* @param parent optional QObject parent
|
||||
**/
|
||||
ConfigLoader(KSharedConfigPtr config, QIODevice *xml, QObject *parent = 0);
|
||||
|
||||
/**
|
||||
* Creates a KConfigSkeleton populated using the definition found in
|
||||
* the XML data passed in.
|
||||
*
|
||||
* @param config the group to use as the root for configuration items
|
||||
* @param xml the xml data; must be valid KConfigXT data
|
||||
* @param parent optional QObject parent
|
||||
**/
|
||||
ConfigLoader(const KConfigGroup *config, QIODevice *xml, QObject *parent = 0);
|
||||
~ConfigLoader();
|
||||
|
||||
/**
|
||||
* Finds the item for the given group and key.
|
||||
*
|
||||
* @param group the group in the config file to look in
|
||||
* @param key the configuration key to find
|
||||
* @return the associated KConfigSkeletonItem, or 0 if none
|
||||
*/
|
||||
KConfigSkeletonItem *findItemByGroup(const QString &group, const QString &key) const;
|
||||
|
||||
/**
|
||||
* Returns the property (variantized value) of the named item
|
||||
*/
|
||||
QVariant property(const QString &name) const;
|
||||
|
||||
/**
|
||||
* Check to see if a group exists
|
||||
*
|
||||
* @param group the name of the group to check for
|
||||
* @return true if the group exists, or false if it does not
|
||||
*/
|
||||
bool hasGroup(const QString &group) const;
|
||||
|
||||
/**
|
||||
* @return the list of groups defined by the XML
|
||||
*/
|
||||
QStringList groupList() const;
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Hack used to force writing when no default exists in config file.
|
||||
*/
|
||||
void usrWriteConfig();
|
||||
|
||||
private:
|
||||
friend class Service;
|
||||
ConfigLoaderPrivate * const d;
|
||||
};
|
||||
|
||||
} // Plasma namespace
|
||||
|
||||
#endif //multiple inclusion guard
|
|
@ -126,16 +126,6 @@ Containment::Containment(QObject *parent, const QVariantList &args)
|
|||
setBackgroundHints(NoBackground);
|
||||
}
|
||||
|
||||
Containment::Containment(const QString &packagePath, uint appletId, const QVariantList &args)
|
||||
: Plasma::Applet(packagePath, appletId, args),
|
||||
d(new ContainmentPrivate(this))
|
||||
{
|
||||
// WARNING: do not access config() OR globalConfig() in this method!
|
||||
// that requires a scene, which is not available at this point
|
||||
setPos(0, 0);
|
||||
setBackgroundHints(NoBackground);
|
||||
}
|
||||
|
||||
Containment::~Containment()
|
||||
{
|
||||
// Applet touches our dptr if we are a containment and is the superclass (think of dtors)
|
||||
|
|
|
@ -38,7 +38,6 @@ namespace Plasma
|
|||
|
||||
class AppletHandle;
|
||||
class DataEngine;
|
||||
class Package;
|
||||
class Corona;
|
||||
class View;
|
||||
class Wallpaper;
|
||||
|
@ -595,16 +594,6 @@ Q_SIGNALS:
|
|||
AbstractToolBox *toolBox() const;
|
||||
|
||||
private:
|
||||
/**
|
||||
* @internal This constructor is to be used with the Package loading system.
|
||||
*
|
||||
* @param parent a QObject parent; you probably want to pass in 0
|
||||
* @param args a list of strings containing two entries: the service id
|
||||
* and the applet id
|
||||
* @since 4.3
|
||||
*/
|
||||
Containment(const QString &packagePath, uint appletId, const QVariantList &args);
|
||||
|
||||
Q_PRIVATE_SLOT(d, void appletDestroyed(Plasma::Applet*))
|
||||
Q_PRIVATE_SLOT(d, void appletAppearAnimationComplete())
|
||||
Q_PRIVATE_SLOT(d, void triggerShowAddWidgets())
|
||||
|
@ -621,7 +610,6 @@ Q_SIGNALS:
|
|||
|
||||
friend class Applet;
|
||||
friend class AppletPrivate;
|
||||
friend class AppletScript;
|
||||
friend class CoronaPrivate;
|
||||
friend class ContainmentPrivate;
|
||||
friend class ContainmentActions;
|
||||
|
|
|
@ -82,9 +82,6 @@ Comment[x-test]=xxPlasma appletxx
|
|||
Comment[zh_CN]=Plasma 小程序
|
||||
Comment[zh_TW]=Plasma 小程式
|
||||
|
||||
[PropertyDef::X-Plasma-API]
|
||||
Type=QString
|
||||
|
||||
[PropertyDef::X-Plasma-DropMimeTypes]
|
||||
Type=QStringList
|
||||
|
||||
|
|
|
@ -1,86 +0,0 @@
|
|||
[Desktop Entry]
|
||||
Type=ServiceType
|
||||
X-KDE-ServiceType=Plasma/ScriptEngine
|
||||
|
||||
Comment=Scripting language extension for Plasma
|
||||
Comment[ar]=امتداد لغة سكربت لبلازما
|
||||
Comment[as]=Plasma ৰ কাৰণে স্ক্ৰিপ্টিং ভাষাৰ সম্প্ৰসাৰণ
|
||||
Comment[ast]=Estensión de llinguaxe de guiones pa Plasma
|
||||
Comment[be@latin]=Pašyreńnie skryptavaj movy dla systemy „Plasma”
|
||||
Comment[bg]=Разширение на Plasma за скриптов език
|
||||
Comment[bs]=Proširenje Plazme za skriptne jezike
|
||||
Comment[ca]=Extensió de llenguatge d'scripts per al Plasma
|
||||
Comment[ca@valencia]=Extensió de llenguatge d'scripts per al Plasma
|
||||
Comment[cs]=Rozšíření pro skriptovací jazyky Plasma
|
||||
Comment[da]=Scriptsprog-udvidelse til Plasma
|
||||
Comment[de]=Skriptsprachen-Erweiterung für Plasma
|
||||
Comment[el]=Επέκταση γλώσσας σεναρίων για το Plasma
|
||||
Comment[en_GB]=Scripting language extension for Plasma
|
||||
Comment[eo]=Skriptlingva etendaĵo por Plasma
|
||||
Comment[es]=Extensión de lenguaje de script para Plasma
|
||||
Comment[et]=Skriptikeele laiendus Plasmale
|
||||
Comment[eu]=Plasmarako script lengoaien gehigarria
|
||||
Comment[fi]=Skriptauskielituki Plasmalle
|
||||
Comment[fr]=Extension du langage de script pour Plasma
|
||||
Comment[fy]=Scripting taal taheaksel foar Plasma
|
||||
Comment[ga]=Eisínteacht teanga scriptithe le haghaidh Plasma
|
||||
Comment[gl]=Extensión de linguaxe de scripts para o Plasma
|
||||
Comment[gu]=પ્લાઝમા માટે સ્ક્રિપ્ટીંગ ભાષા એક્સટેન્શન
|
||||
Comment[he]=הרחבת שפת תסריטים של Plasma
|
||||
Comment[hne]=प्लाज्मा बर स्क्रिप्टिंग भाखा
|
||||
Comment[hr]=Proširenje Plasme za skriptne jezike
|
||||
Comment[hsb]=Skriptowa rěč jako Plasma-ekstensija
|
||||
Comment[hu]=Szkriptkezelő bővítmény a Plasmához
|
||||
Comment[ia]=Extension del language de script de Plasma
|
||||
Comment[id]=Tambahan bahasa skrip untuk Plasma
|
||||
Comment[is]=Framlenging á skriftunarmál fyrir Plasma
|
||||
Comment[it]=Estensione linguaggio scripting per Plasma
|
||||
Comment[ja]=Plasma のためのスクリプト言語拡張
|
||||
Comment[kk]=Plasma-ның скрипт тілі
|
||||
Comment[km]=ផ្នែកបន្ថែមភាសាស្គ្រីបសម្រាប់ប្លាស្មា
|
||||
Comment[kn]=ಪ್ಲಾಸ್ಮಾ ಕ್ಕೆ ವಿಧಿಗುಚ್ಛ (ಸ್ಕ್ರಿಪ್ಟ್) ರಚನಾ ಭಾಷೆ ಯ ವಿಸ್ತರಣೆ
|
||||
Comment[ko]=Plasma 스크립트 언어 확장
|
||||
Comment[ku]=Pêveka zimanê skrîpt kirinê ji bo Plasma
|
||||
Comment[lt]=Scenarijų kalbos praplėtimas, skirtas Plasma
|
||||
Comment[lv]=Skriptēšanas valodu Plasma paplašinājums
|
||||
Comment[mai]=प्लाजमाक लेल स्क्रिप्टिंग भाषाक विस्तार
|
||||
Comment[ml]=പ്ലാസ്മയ്ക്കുള്ള സ്ക്രിപ്റ്റിങ്ങ് ഭാഷാ എക്സ്റ്റന്ഷന്
|
||||
Comment[mr]=प्लाज्मा साठी स्क्रिप्टींग भाषा एक्सटेंशन
|
||||
Comment[nb]=Skriptspråk-utvidelse for Plasma
|
||||
Comment[nds]=Skriptspraak-Verwiedern för Plasma
|
||||
Comment[nl]=Scripttaalextensie voor Plasma
|
||||
Comment[nn]=Skriptspråkutviding for Plasma
|
||||
Comment[pa]=ਪਲਾਜ਼ਮਾ ਲਈ ਸਕ੍ਰਿਪਟਿੰਗ ਭਾਸ਼ਾ ਇਕਸਟੈਨਸ਼ਨ
|
||||
Comment[pl]=Rozszerzenie języka skryptów dla Plazmy
|
||||
Comment[pt]=Extensão de linguagens de programação para o Plasma
|
||||
Comment[pt_BR]=Extensão de linguagem de script do Plasma
|
||||
Comment[ro]=Extensie de limbaj pentru scripturi Plasma
|
||||
Comment[ru]=Поддержка языков сценариев для Plasma
|
||||
Comment[se]=Skriptagiellaviiddádus Plasmai
|
||||
Comment[si]=Plasma සඳහා ස්කටිප්ට භාෂා දිගුව
|
||||
Comment[sk]=Rozšírenie pre skriptovacie jazyky Plasma
|
||||
Comment[sl]=Razširitev skriptnega jezika za Plasmo
|
||||
Comment[sr]=Проширење Плазме за скриптне језике
|
||||
Comment[sr@ijekavian]=Проширење Плазме за скриптне језике
|
||||
Comment[sr@ijekavianlatin]=Proširenje Plasme za skriptne jezike
|
||||
Comment[sr@latin]=Proširenje Plasme za skriptne jezike
|
||||
Comment[sv]=Skriptspråksutökning för Plasma
|
||||
Comment[ta]=பிளாஸ்மாவிற்கான குறுநிரலாக்க மொழி விரிவாக்கம்
|
||||
Comment[tg]=Скрипти забонҳои иловагӣ барои Plasma
|
||||
Comment[th]=ส่วนเสริมภาษาสคริปต์สำหรับพลาสมา
|
||||
Comment[tr]=Plasma için betik dili eklentisi
|
||||
Comment[tt]=Plasma өчен скрипт телләр өстәмәсе
|
||||
Comment[ug]=Plasma نىڭ قوليازما تىل كېڭەيتىلمىسى
|
||||
Comment[uk]=Розширення скриптових мов для Плазми
|
||||
Comment[vi]=Phần mở rộng ngôn ngữ lệnh cho Plasma
|
||||
Comment[wa]=Rawete di lingaedje di scriptaedje po Plasma
|
||||
Comment[x-test]=xxScripting language extension for Plasmaxx
|
||||
Comment[zh_CN]=Plasma 的脚本语言扩展
|
||||
Comment[zh_TW]=Plasma 文稿語言延伸
|
||||
|
||||
[PropertyDef::X-Plasma-ComponentTypes]
|
||||
Type=QStringList
|
||||
|
||||
[PropertyDef::X-Plasma-PackageFormat]
|
||||
Type=QString
|
||||
|
|
@ -32,7 +32,6 @@
|
|||
#include "pluginloader.h"
|
||||
#include "private/dataengine_p.h"
|
||||
#include "private/datacontainer_p.h"
|
||||
#include "scripting/scriptengine.h"
|
||||
|
||||
namespace Plasma
|
||||
{
|
||||
|
|
|
@ -49,7 +49,6 @@
|
|||
#include "widgets/iconwidget.h"
|
||||
#include "widgets/pushbutton.h"
|
||||
|
||||
#include "private/applethandle_p.h"
|
||||
#include "private/extender_p.h"
|
||||
#include "private/extenderapplet_p.h"
|
||||
#include "private/extendergroup_p.h"
|
||||
|
|
|
@ -49,7 +49,6 @@ class PackageMetadataPrivate
|
|||
QString pluginName;
|
||||
QString type;
|
||||
QString serviceType;
|
||||
QString api;
|
||||
};
|
||||
|
||||
PackageMetadata::PackageMetadata(const PackageMetadata &other)
|
||||
|
@ -102,7 +101,6 @@ void PackageMetadata::write(const QString &filename) const
|
|||
config.writeEntry("X-KDE-PluginInfo-Website", d->website);
|
||||
config.writeEntry("X-KDE-PluginInfo-License", d->license);
|
||||
config.writeEntry("X-KDE-PluginInfo-Category", d->category);
|
||||
config.writeEntry("X-Plasma-API", d->api);
|
||||
config.writeEntry("X-KDE-ParentApp", d->app);
|
||||
config.writeEntry("Type", d->type);
|
||||
}
|
||||
|
@ -147,7 +145,6 @@ void PackageMetadata::read(const QString &filename)
|
|||
d->website = config.readEntry("X-KDE-PluginInfo-Website", d->website);
|
||||
d->license = config.readEntry("X-KDE-PluginInfo-License", d->license);
|
||||
d->category = config.readEntry("X-KDE-PluginInfo-Category", d->category);
|
||||
d->api = config.readEntry("X-Plasma-API", d->api);
|
||||
d->app = config.readEntry("X-KDE-ParentApp", d->app);
|
||||
d->type = config.readEntry("Type", d->type);
|
||||
}
|
||||
|
@ -227,16 +224,6 @@ QString PackageMetadata::type() const
|
|||
return d->type;
|
||||
}
|
||||
|
||||
QString PackageMetadata::implementationApi() const
|
||||
{
|
||||
return d->api;
|
||||
}
|
||||
|
||||
void PackageMetadata::setImplementationApi(const QString &api)
|
||||
{
|
||||
d->api = api;
|
||||
}
|
||||
|
||||
QString PackageMetadata::pluginName() const
|
||||
{
|
||||
return d->pluginName;
|
||||
|
|
|
@ -89,7 +89,6 @@ public:
|
|||
QString application() const;
|
||||
QString category() const;
|
||||
QString pluginName() const;
|
||||
QString implementationApi() const;
|
||||
|
||||
QString type() const;
|
||||
|
||||
|
@ -187,11 +186,6 @@ public:
|
|||
*/
|
||||
void setPluginName(const QString &name);
|
||||
|
||||
/**
|
||||
* Set the implementation API this package uses.
|
||||
*/
|
||||
void setImplementationApi(const QString &api);
|
||||
|
||||
private:
|
||||
PackageMetadataPrivate * const d;
|
||||
};
|
||||
|
|
|
@ -45,6 +45,11 @@
|
|||
namespace Plasma
|
||||
{
|
||||
|
||||
static PackageStructure::Ptr defaultPackageStructure()
|
||||
{
|
||||
return PackageStructure::Ptr(new PackageStructure());
|
||||
}
|
||||
|
||||
class ContentStructure
|
||||
{
|
||||
public:
|
||||
|
@ -122,22 +127,22 @@ PackageStructure::Ptr PackageStructure::load(const QString &packageFormat)
|
|||
PackageStructure::Ptr structure;
|
||||
|
||||
if (packageFormat == "Plasma/Applet") {
|
||||
structure = defaultPackageStructure(AppletComponent);
|
||||
structure = defaultPackageStructure();
|
||||
structure->d->type = "Plasma/Applet";
|
||||
} else if (packageFormat == "Plasma/DataEngine") {
|
||||
structure = defaultPackageStructure(DataEngineComponent);
|
||||
structure = defaultPackageStructure();
|
||||
structure->d->type = "Plasma/DataEngine";
|
||||
} else if (packageFormat == "Plasma/Runner") {
|
||||
structure = defaultPackageStructure(RunnerComponent);
|
||||
structure = defaultPackageStructure();
|
||||
structure->d->type = "Plasma/Runner";
|
||||
} else if (packageFormat == "Plasma/Wallpaper") {
|
||||
structure = defaultPackageStructure(WallpaperComponent);
|
||||
structure = defaultPackageStructure();
|
||||
structure->d->type = "Plasma/Wallpaper";
|
||||
} else if (packageFormat == "Plasma/Theme") {
|
||||
structure = Theme::packageStructure();
|
||||
structure->d->type = "Plasma/Theme";
|
||||
} else if (packageFormat == "Plasma/Generic") {
|
||||
structure = defaultPackageStructure(GenericComponent);
|
||||
structure = defaultPackageStructure();
|
||||
structure->d->type = "Plasma/Generic";
|
||||
structure->setDefaultPackageRoot("plasma/packages/");
|
||||
}
|
||||
|
|
|
@ -31,21 +31,6 @@
|
|||
namespace Plasma
|
||||
{
|
||||
|
||||
qreal scalingFactor(ZoomLevel level)
|
||||
{
|
||||
switch (level) {
|
||||
case DesktopZoom:
|
||||
return 1;
|
||||
case GroupZoom:
|
||||
return 0.5;
|
||||
case OverviewZoom:
|
||||
return 0.2;
|
||||
}
|
||||
|
||||
// to make odd compilers not warn like silly beasts
|
||||
return 1;
|
||||
}
|
||||
|
||||
Direction locationToDirection(Location location)
|
||||
{
|
||||
switch (location) {
|
||||
|
|
|
@ -147,27 +147,6 @@ enum PopupPlacement {
|
|||
to the bottom of the widget */
|
||||
};
|
||||
|
||||
/**
|
||||
* Flip enumeration
|
||||
*/
|
||||
enum FlipDirection {
|
||||
NoFlip = 0, /**< Do not flip */
|
||||
HorizontalFlip = 1, /**< Flip horizontally */
|
||||
VerticalFlip = 2 /**< Flip vertically */
|
||||
};
|
||||
Q_DECLARE_FLAGS(Flip, FlipDirection)
|
||||
|
||||
/**
|
||||
* Zoom levels that Plasma is aware of...
|
||||
**/
|
||||
enum ZoomLevel {
|
||||
DesktopZoom = 0, /**< Normal desktop usage, plasmoids are painted normally
|
||||
and have full interaction */
|
||||
GroupZoom, /**< Plasmoids are shown as icons in visual groups; drag
|
||||
and drop and limited context menu interaction only */
|
||||
OverviewZoom /**< Groups become icons themselves */
|
||||
};
|
||||
|
||||
/**
|
||||
* Possible timing alignments
|
||||
**/
|
||||
|
@ -254,17 +233,6 @@ enum ItemStatus {
|
|||
};
|
||||
Q_ENUMS(ItemStatus)
|
||||
|
||||
enum AnnouncementMethod {
|
||||
NoAnnouncement = 0, /**< No announcements **/
|
||||
ZeroconfAnnouncement = 1 /**< Announcements via ZeroConf **/
|
||||
};
|
||||
Q_DECLARE_FLAGS(AnnouncementMethods, AnnouncementMethod)
|
||||
|
||||
/**
|
||||
* @return the scaling factor (0..1) for a ZoomLevel
|
||||
**/
|
||||
PLASMA_EXPORT qreal scalingFactor(ZoomLevel level);
|
||||
|
||||
/**
|
||||
* Converts a location to a direction. Handy for figuring out which way to send a popup based on
|
||||
* location or to point arrows and other directional items.
|
||||
|
@ -309,7 +277,6 @@ PLASMA_EXPORT QList<QAction*> actionsFromMenu(QMenu *menu,
|
|||
} // Plasma namespace
|
||||
|
||||
Q_DECLARE_OPERATORS_FOR_FLAGS(Plasma::Constraints)
|
||||
Q_DECLARE_OPERATORS_FOR_FLAGS(Plasma::Flip)
|
||||
Q_DECLARE_OPERATORS_FOR_FLAGS(Plasma::ComponentTypes)
|
||||
Q_DECLARE_OPERATORS_FOR_FLAGS(Plasma::MessageButtons)
|
||||
|
||||
|
|
|
@ -72,22 +72,6 @@ Applet *PluginLoader::loadApplet(const QString &name, uint appletId, const QVari
|
|||
QVariantList allArgs;
|
||||
allArgs << offer->storageId() << appletId << args;
|
||||
|
||||
if (!offer->property("X-Plasma-API").toString().isEmpty()) {
|
||||
kDebug() << "we have a script using the"
|
||||
<< offer->property("X-Plasma-API").toString() << "API";
|
||||
if (isContainment) {
|
||||
return new Containment(0, allArgs);
|
||||
} else {
|
||||
if (offer->serviceTypes().contains("Plasma/Containment")) {
|
||||
return new Containment(0, allArgs);
|
||||
} else if (offer->serviceTypes().contains("Plasma/PopupApplet")) {
|
||||
return new PopupApplet(0, allArgs);
|
||||
} else {
|
||||
return new Applet(0, allArgs);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Applet *applet = 0;
|
||||
QString error;
|
||||
if (name == "internal:extender") {
|
||||
|
@ -117,13 +101,8 @@ DataEngine *PluginLoader::loadDataEngine(const QString &name)
|
|||
} else {
|
||||
QVariantList allArgs;
|
||||
allArgs << offers.first()->storageId();
|
||||
QString api = offers.first()->property("X-Plasma-API").toString();
|
||||
if (api.isEmpty()) {
|
||||
if (offers.first()) {
|
||||
engine = offers.first()->createInstance<Plasma::DataEngine>(0, allArgs, &error);
|
||||
}
|
||||
} else {
|
||||
engine = new DataEngine(0, offers.first());
|
||||
if (offers.first()) {
|
||||
engine = offers.first()->createInstance<Plasma::DataEngine>(0, allArgs, &error);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -27,7 +27,6 @@
|
|||
#include <QGraphicsLinearLayout>
|
||||
#include <QTimer>
|
||||
#include <QVBoxLayout>
|
||||
#include <QDeclarativeItem>
|
||||
|
||||
#include <kicon.h>
|
||||
#include <kiconloader.h>
|
||||
|
@ -45,7 +44,6 @@
|
|||
#include "plasma/extenders/extenderitem.h"
|
||||
#include "plasma/package.h"
|
||||
#include "plasma/theme.h"
|
||||
#include "plasma/scripting/appletscript.h"
|
||||
#include "plasma/tooltipmanager.h"
|
||||
#include "plasma/widgets/iconwidget.h"
|
||||
|
||||
|
@ -58,12 +56,6 @@ PopupApplet::PopupApplet(QObject *parent, const QVariantList &args)
|
|||
{
|
||||
}
|
||||
|
||||
PopupApplet::PopupApplet(const QString &packagePath, uint appletId, const QVariantList &args)
|
||||
: Plasma::Applet(packagePath, appletId, args),
|
||||
d(new PopupAppletPrivate(this))
|
||||
{
|
||||
}
|
||||
|
||||
PopupApplet::~PopupApplet()
|
||||
{
|
||||
delete widget();
|
||||
|
@ -90,16 +82,7 @@ void PopupApplet::setPopupIcon(const QIcon &icon)
|
|||
|
||||
void PopupApplet::setPopupIcon(const QString &iconName)
|
||||
{
|
||||
// Attempt 1: is it in the plasmoid package?
|
||||
if (package()) {
|
||||
const QString file = package()->filePath("images", iconName);
|
||||
if (!file.isEmpty()) {
|
||||
setPopupIcon(KIcon(file));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Attempt 2: is it a svg in the icons directory?
|
||||
// Is it a svg in the icons directory?
|
||||
const QString name = QString("icons/") + iconName.split("-").first();
|
||||
if (!Plasma::Theme::defaultTheme()->imagePath(name).isEmpty()) {
|
||||
d->createIconWidget();
|
||||
|
@ -237,21 +220,19 @@ void PopupAppletPrivate::popupConstraintsEvent(Plasma::Constraints constraints)
|
|||
minimum = qWidget->minimumSizeHint();
|
||||
}
|
||||
|
||||
//99% of the times q->parentWidget() is the containment, but using it we can also manage the applet-in-applet case (i.e. systray)
|
||||
//there are also cases where the parentlayoutitem is bigger than the containment (e.g. newspaper)
|
||||
QDeclarativeItem *di = qobject_cast<QDeclarativeItem *>(q->parentObject());
|
||||
// 99% of the times q->parentWidget() is the containment, but using it we can also manage
|
||||
// the applet-in-applet case (i.e. systray) there are also cases where the parentlayoutitem
|
||||
// is bigger than the containment
|
||||
if (q->parentLayoutItem()) {
|
||||
parentSize = q->parentLayoutItem()->geometry().size();
|
||||
} else if (q->parentWidget()) {
|
||||
parentSize = q->parentWidget()->size();
|
||||
} else if (di) {
|
||||
parentSize = QSizeF(di->width(), di->height());
|
||||
}
|
||||
|
||||
//check if someone did the nasty trick of applets in applets, in this case we always want to be collapsed
|
||||
// check if someone did the nasty trick of applets in applets, in this case we always want to be collapsed
|
||||
QGraphicsWidget *candidateParentApplet = q;
|
||||
Plasma::Applet *parentApplet = 0;
|
||||
//this loop should be executed normally a single time, at most 2-3 times for quite complex containments
|
||||
// this loop should be executed normally a single time, at most 2-3 times for quite complex containments
|
||||
while (candidateParentApplet) {
|
||||
candidateParentApplet = candidateParentApplet->parentWidget();
|
||||
parentApplet = qobject_cast<Plasma::Applet *>(candidateParentApplet);
|
||||
|
@ -666,9 +647,6 @@ Qt::AlignmentFlag PopupApplet::popupAlignment() const
|
|||
|
||||
void PopupApplet::popupEvent(bool popped)
|
||||
{
|
||||
if (Applet::d->script) {
|
||||
emit Applet::d->script->popupEvent(popped);
|
||||
}
|
||||
}
|
||||
|
||||
void PopupApplet::setPassivePopup(bool passive)
|
||||
|
|
|
@ -211,16 +211,6 @@ protected:
|
|||
void timerEvent(QTimerEvent *event);
|
||||
|
||||
private:
|
||||
/**
|
||||
* @internal This constructor is to be used with the Package loading system.
|
||||
*
|
||||
* @param parent a QObject parent; you probably want to pass in 0
|
||||
* @param args a list of strings containing two entries: the service id
|
||||
* and the applet id
|
||||
* @since 4.3
|
||||
*/
|
||||
PopupApplet(const QString &packagePath, uint appletId, const QVariantList &args);
|
||||
|
||||
Q_PRIVATE_SLOT(d, void internalTogglePopup())
|
||||
Q_PRIVATE_SLOT(d, void hideTimedPopup())
|
||||
Q_PRIVATE_SLOT(d, void clearPopupLostFocus())
|
||||
|
|
|
@ -39,7 +39,6 @@ namespace Plasma
|
|||
|
||||
class Dialog;
|
||||
class FrameSvg;
|
||||
class AppletScript;
|
||||
class Wallpaper;
|
||||
class BusyWidget;
|
||||
class PushButton;
|
||||
|
@ -96,11 +95,7 @@ public:
|
|||
AppletPrivate(KService::Ptr service, const KPluginInfo *info, int uniqueID, Applet *applet);
|
||||
~AppletPrivate();
|
||||
|
||||
void init(const QString &packagePath = QString());
|
||||
|
||||
// put all setup routines for script here. at this point we can assume that
|
||||
// package exists and that we have a script engin
|
||||
void setupScriptSupport();
|
||||
void init();
|
||||
|
||||
/**
|
||||
* Sets whether or not this Applet is acting as a Containment
|
||||
|
@ -140,7 +135,6 @@ public:
|
|||
static uint s_maxAppletId;
|
||||
static int s_maxZValue;
|
||||
static int s_minZValue;
|
||||
static PackageStructure::Ptr packageStructure;
|
||||
|
||||
//TODO: examine the usage of memory here; there's a pretty large
|
||||
// number of members at this point.
|
||||
|
@ -176,10 +170,7 @@ public:
|
|||
QWeakPointer<Plasma::PushButton> messageCancelButton;
|
||||
QWeakPointer<QAction> messageCloseAction;
|
||||
|
||||
// sripting and package stuff
|
||||
AppletScript *script;
|
||||
Package *package;
|
||||
ConfigLoader *configLoader;
|
||||
// package stuff
|
||||
QWeakPointer<AppletHandle> handle;
|
||||
|
||||
// actions stuff; put activationAction into actions?
|
||||
|
@ -203,13 +194,12 @@ public:
|
|||
QBasicTimer *modificationsTimer;
|
||||
|
||||
// a great green field of booleans :)
|
||||
bool hasConfigurationInterface : 1;
|
||||
bool failed : 1;
|
||||
bool isContainment : 1;
|
||||
bool square : 1;
|
||||
bool transient : 1;
|
||||
bool needsConfig : 1;
|
||||
bool started : 1;
|
||||
bool hasConfigurationInterface;
|
||||
bool failed;
|
||||
bool isContainment;
|
||||
bool transient ;
|
||||
bool needsConfig;
|
||||
bool started;
|
||||
};
|
||||
|
||||
} // Plasma namespace
|
||||
|
|
|
@ -1,221 +0,0 @@
|
|||
/*
|
||||
* Copyright 2007-2008 Aaron Seigo <aseigo@kde.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Library General Public License as
|
||||
* published by the Free Software Foundation; either version 2, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this program; if not, write to the
|
||||
* Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef PLASMA_CONFIGLOADER_P_H
|
||||
#define PLASMA_CONFIGLOADER_P_H
|
||||
|
||||
namespace Plasma
|
||||
{
|
||||
|
||||
class ConfigLoaderPrivate
|
||||
{
|
||||
public:
|
||||
ConfigLoaderPrivate()
|
||||
: saveDefaults(false)
|
||||
{
|
||||
}
|
||||
|
||||
~ConfigLoaderPrivate()
|
||||
{
|
||||
qDeleteAll(bools);
|
||||
qDeleteAll(strings);
|
||||
qDeleteAll(stringlists);
|
||||
qDeleteAll(colors);
|
||||
qDeleteAll(fonts);
|
||||
qDeleteAll(ints);
|
||||
qDeleteAll(uints);
|
||||
qDeleteAll(urls);
|
||||
qDeleteAll(dateTimes);
|
||||
qDeleteAll(doubles);
|
||||
qDeleteAll(intlists);
|
||||
qDeleteAll(longlongs);
|
||||
qDeleteAll(points);
|
||||
qDeleteAll(rects);
|
||||
qDeleteAll(sizes);
|
||||
qDeleteAll(ulonglongs);
|
||||
qDeleteAll(urllists);
|
||||
}
|
||||
|
||||
bool *newBool()
|
||||
{
|
||||
bool *v = new bool(false);
|
||||
bools.append(v);
|
||||
return v;
|
||||
}
|
||||
|
||||
QString *newString()
|
||||
{
|
||||
QString *v = new QString();
|
||||
strings.append(v);
|
||||
return v;
|
||||
}
|
||||
|
||||
QStringList *newStringList()
|
||||
{
|
||||
QStringList *v = new QStringList();
|
||||
stringlists.append(v);
|
||||
return v;
|
||||
}
|
||||
|
||||
QColor *newColor()
|
||||
{
|
||||
QColor *v = new QColor();
|
||||
colors.append(v);
|
||||
return v;
|
||||
}
|
||||
|
||||
QFont *newFont()
|
||||
{
|
||||
QFont *v = new QFont();
|
||||
fonts.append(v);
|
||||
return v;
|
||||
}
|
||||
|
||||
qint32 *newInt()
|
||||
{
|
||||
qint32 *v = new qint32(0);
|
||||
ints.append(v);
|
||||
return v;
|
||||
}
|
||||
|
||||
quint32 *newUint()
|
||||
{
|
||||
quint32 *v = new quint32(0);
|
||||
uints.append(v);
|
||||
return v;
|
||||
}
|
||||
|
||||
KUrl *newUrl()
|
||||
{
|
||||
KUrl *v = new KUrl;
|
||||
urls.append(v);
|
||||
return v;
|
||||
}
|
||||
|
||||
QDateTime *newDateTime()
|
||||
{
|
||||
QDateTime *v = new QDateTime();
|
||||
dateTimes.append(v);
|
||||
return v;
|
||||
}
|
||||
|
||||
double *newDouble()
|
||||
{
|
||||
double *v = new double;
|
||||
doubles.append(v);
|
||||
return v;
|
||||
}
|
||||
|
||||
QList<qint32>* newIntList()
|
||||
{
|
||||
QList<qint32> *v = new QList<qint32>();
|
||||
intlists.append(v);
|
||||
return v;
|
||||
}
|
||||
|
||||
qint64 *newLongLong()
|
||||
{
|
||||
qint64 *v = new qint64(0);
|
||||
longlongs.append(v);
|
||||
return v;
|
||||
}
|
||||
|
||||
QPoint *newPoint()
|
||||
{
|
||||
QPoint *v = new QPoint();
|
||||
points.append(v);
|
||||
return v;
|
||||
}
|
||||
|
||||
QRect *newRect()
|
||||
{
|
||||
QRect *v = new QRect();
|
||||
rects.append(v);
|
||||
return v;
|
||||
}
|
||||
|
||||
QSize *newSize()
|
||||
{
|
||||
QSize *v = new QSize();
|
||||
sizes.append(v);
|
||||
return v;
|
||||
}
|
||||
|
||||
quint64 *newULongLong()
|
||||
{
|
||||
quint64 *v = new quint64(0);
|
||||
ulonglongs.append(v);
|
||||
return v;
|
||||
}
|
||||
|
||||
KUrl::List *newUrlList()
|
||||
{
|
||||
KUrl::List *v = new KUrl::List();
|
||||
urllists.append(v);
|
||||
return v;
|
||||
}
|
||||
|
||||
void parse(ConfigLoader *loader, QIODevice *xml);
|
||||
|
||||
/**
|
||||
* Whether or not to write out default values.
|
||||
*
|
||||
* @param writeDefaults true if defaults should be written out
|
||||
*/
|
||||
void setWriteDefaults(bool writeDefaults)
|
||||
{
|
||||
saveDefaults = writeDefaults;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if default values will also be written out
|
||||
*/
|
||||
bool writeDefaults() const
|
||||
{
|
||||
return saveDefaults;
|
||||
}
|
||||
|
||||
|
||||
QList<bool *> bools;
|
||||
QList<QString *> strings;
|
||||
QList<QStringList *> stringlists;
|
||||
QList<QColor *> colors;
|
||||
QList<QFont *> fonts;
|
||||
QList<qint32 *> ints;
|
||||
QList<quint32 *> uints;
|
||||
QList<KUrl *> urls;
|
||||
QList<QDateTime *> dateTimes;
|
||||
QList<double *> doubles;
|
||||
QList<QList<qint32> *> intlists;
|
||||
QList<qint64 *> longlongs;
|
||||
QList<QPoint *> points;
|
||||
QList<QRect *> rects;
|
||||
QList<QSize *> sizes;
|
||||
QList<quint64 *> ulonglongs;
|
||||
QList<KUrl::List *> urllists;
|
||||
QString baseGroup;
|
||||
QStringList groups;
|
||||
QHash<QString, QString> keysToNames;
|
||||
bool saveDefaults;
|
||||
};
|
||||
|
||||
} // namespace Plasma
|
||||
|
||||
#endif
|
||||
|
|
@ -1,66 +0,0 @@
|
|||
/*
|
||||
* Copyright 2007 Richard J. Moore <rich@kde.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Library General Public License version 2 as
|
||||
* published by the Free Software Foundation
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this program; if not, write to the
|
||||
* Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "dataenginebindings_p.h"
|
||||
|
||||
typedef Plasma::Service *ServicePtr;
|
||||
QScriptValue qScriptValueFromService(QScriptEngine *engine, const ServicePtr &service)
|
||||
{
|
||||
return engine->newQObject(const_cast<Plasma::Service *>(service), QScriptEngine::AutoOwnership, QScriptEngine::PreferExistingWrapperObject);
|
||||
}
|
||||
|
||||
void serviceFromQScriptValue(const QScriptValue &scriptValue, ServicePtr &service)
|
||||
{
|
||||
QObject *obj = scriptValue.toQObject();
|
||||
service = static_cast<Plasma::Service *>(obj);
|
||||
}
|
||||
|
||||
typedef Plasma::DataEngine *DataEnginePtr;
|
||||
QScriptValue qScriptValueFromDataEngine(QScriptEngine *engine, const DataEnginePtr &dataEngine)
|
||||
{
|
||||
return engine->newQObject(const_cast<Plasma::DataEngine *>(dataEngine), QScriptEngine::AutoOwnership, QScriptEngine::PreferExistingWrapperObject);
|
||||
}
|
||||
|
||||
void dataEngineFromQScriptValue(const QScriptValue &scriptValue, DataEnginePtr &dataEngine)
|
||||
{
|
||||
QObject *obj = scriptValue.toQObject();
|
||||
dataEngine = static_cast<Plasma::DataEngine *>(obj);
|
||||
}
|
||||
|
||||
typedef Plasma::ServiceJob *ServiceJobPtr;
|
||||
QScriptValue qScriptValueFromServiceJob(QScriptEngine *engine, const ServiceJobPtr &serviceJob)
|
||||
{
|
||||
return engine->newQObject(const_cast<Plasma::ServiceJob *>(serviceJob), QScriptEngine::AutoOwnership, QScriptEngine::PreferExistingWrapperObject);
|
||||
}
|
||||
|
||||
void serviceJobFromQScriptValue(const QScriptValue &scriptValue, ServiceJobPtr &serviceJob)
|
||||
{
|
||||
QObject *obj = scriptValue.toQObject();
|
||||
serviceJob = static_cast<Plasma::ServiceJob *>(obj);
|
||||
}
|
||||
|
||||
void registerDataEngineMetaTypes(QScriptEngine *engine)
|
||||
{
|
||||
qRegisterMetaType<Plasma::DataEngine::Data>("Plasma::DataEngine::Data");
|
||||
qRegisterMetaType<Plasma::DataEngine::Data>("DataEngine::Data");
|
||||
qScriptRegisterMapMetaType<Plasma::DataEngine::Data>(engine);
|
||||
qScriptRegisterMetaType<Plasma::Service *>(engine, qScriptValueFromService, serviceFromQScriptValue);
|
||||
qScriptRegisterMetaType<Plasma::DataEngine *>(engine, qScriptValueFromDataEngine, dataEngineFromQScriptValue);
|
||||
qScriptRegisterMetaType<Plasma::ServiceJob *>(engine, qScriptValueFromServiceJob, serviceJobFromQScriptValue);
|
||||
}
|
||||
|
|
@ -1,83 +0,0 @@
|
|||
/*
|
||||
* Copyright 2007 Richard J. Moore <rich@kde.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Library General Public License version 2 as
|
||||
* published by the Free Software Foundation
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this program; if not, write to the
|
||||
* Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef DATAENGINE_H
|
||||
#define DATAENGINE_H
|
||||
|
||||
#include <QScriptEngine>
|
||||
#include <QScriptValue>
|
||||
#include <QScriptValueIterator>
|
||||
#include <kdebug.h>
|
||||
|
||||
#include <dataengine.h>
|
||||
#include <service.h>
|
||||
#include <servicejob.h>
|
||||
|
||||
using namespace Plasma;
|
||||
|
||||
Q_DECLARE_METATYPE(DataEngine::Dict)
|
||||
Q_DECLARE_METATYPE(DataEngine::Data)
|
||||
|
||||
template <class M>
|
||||
QScriptValue qScriptValueFromMap(QScriptEngine *eng, const M &map)
|
||||
{
|
||||
//kDebug() << "qScriptValueFromMap called";
|
||||
QScriptValue obj = eng->newObject();
|
||||
typename M::const_iterator begin = map.constBegin();
|
||||
typename M::const_iterator end = map.constEnd();
|
||||
typename M::const_iterator it;
|
||||
for (it = begin; it != end; ++it) {
|
||||
if (it.value().type() == QVariant::Hash) {
|
||||
obj.setProperty(it.key(), qScriptValueFromMap(eng, it.value().toHash()));
|
||||
} else if (it.value().type() == QVariant::Map) {
|
||||
obj.setProperty(it.key(), qScriptValueFromMap(eng, it.value().toMap()));
|
||||
} else {
|
||||
obj.setProperty(it.key(), qScriptValueFromValue(eng, it.value()));
|
||||
}
|
||||
}
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
template <class M>
|
||||
void qScriptValueToMap(const QScriptValue &value, M &map)
|
||||
{
|
||||
//kDebug() << "qScriptValueToMap called";
|
||||
QScriptValueIterator it(value);
|
||||
while (it.hasNext()) {
|
||||
it.next();
|
||||
map[it.name()] = qscriptvalue_cast<typename M::mapped_type>(it.value());
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
int qScriptRegisterMapMetaType(
|
||||
QScriptEngine *engine,
|
||||
const QScriptValue &prototype = QScriptValue()
|
||||
#ifndef qdoc
|
||||
, T * /* dummy */ = 0
|
||||
#endif
|
||||
)
|
||||
{
|
||||
return qScriptRegisterMetaType<T>(engine, qScriptValueFromMap, qScriptValueToMap, prototype);
|
||||
}
|
||||
|
||||
void registerDataEngineMetaTypes(QScriptEngine *engine);
|
||||
|
||||
#endif // DATAENGINE_H
|
||||
|
|
@ -35,59 +35,6 @@
|
|||
namespace Plasma
|
||||
{
|
||||
|
||||
PlasmoidPackage::PlasmoidPackage(QObject *parent)
|
||||
: Plasma::PackageStructure(parent, QString("Plasmoid"))
|
||||
{
|
||||
QStringList platform;
|
||||
platform << "platformcontents/desktop" << "contents";
|
||||
setContentsPrefixPaths(platform);
|
||||
|
||||
addDirectoryDefinition("images", "images", i18n("Images"));
|
||||
addDirectoryDefinition("theme", "theme", i18n("Themed Images"));
|
||||
QStringList mimetypes;
|
||||
mimetypes << "image/svg+xml" << "image/png" << "image/jpeg";
|
||||
setMimetypes("images", mimetypes);
|
||||
setMimetypes("theme", mimetypes);
|
||||
|
||||
addDirectoryDefinition("config", "config", i18n("Configuration Definitions"));
|
||||
mimetypes.clear();
|
||||
mimetypes << "text/xml";
|
||||
setMimetypes("config", mimetypes);
|
||||
|
||||
addDirectoryDefinition("ui", "ui", i18n("User Interface"));
|
||||
setMimetypes("ui", mimetypes);
|
||||
|
||||
addDirectoryDefinition("data", "data", i18n("Data Files"));
|
||||
|
||||
addDirectoryDefinition("scripts", "code", i18n("Executable Scripts"));
|
||||
mimetypes.clear();
|
||||
mimetypes << "text/plain";
|
||||
setMimetypes("scripts", mimetypes);
|
||||
|
||||
addDirectoryDefinition("translations", "locale", i18n("Translations"));
|
||||
|
||||
addFileDefinition("mainconfigui", "ui/config.ui", i18n("Main Config UI File"));
|
||||
addFileDefinition("mainconfigxml", "config/main.xml", i18n("Configuration XML file"));
|
||||
addFileDefinition("mainscript", "code/main", i18n("Main Script File"));
|
||||
addFileDefinition("defaultconfig", "config/default-configrc", i18n("Default configuration"));
|
||||
setRequired("mainscript", true);
|
||||
}
|
||||
|
||||
PlasmoidPackage::~PlasmoidPackage()
|
||||
{
|
||||
}
|
||||
|
||||
void PlasmoidPackage::pathChanged()
|
||||
{
|
||||
KDesktopFile config(path() + "/metadata.desktop");
|
||||
KConfigGroup cg = config.desktopGroup();
|
||||
QString mainScript = cg.readEntry("X-Plasma-MainScript", QString());
|
||||
if (!mainScript.isEmpty()) {
|
||||
addFileDefinition("mainscript", mainScript, i18n("Main Script File"));
|
||||
setRequired("mainscript", true);
|
||||
}
|
||||
}
|
||||
|
||||
ThemePackage::ThemePackage(QObject *parent)
|
||||
: Plasma::PackageStructure(parent, QString("Plasma Theme"))
|
||||
{
|
||||
|
|
|
@ -30,19 +30,6 @@
|
|||
namespace Plasma
|
||||
{
|
||||
|
||||
class PlasmoidPackage : public PackageStructure
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit PlasmoidPackage(QObject *parent = 0);
|
||||
~PlasmoidPackage();
|
||||
|
||||
protected:
|
||||
void pathChanged();
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
class ThemePackage : public PackageStructure
|
||||
{
|
||||
Q_OBJECT
|
||||
|
@ -85,8 +72,6 @@ public:
|
|||
explicit ContainmentActionsPackage(QObject *parent = 0);
|
||||
};
|
||||
|
||||
PackageStructure::Ptr defaultPackageStructure(ComponentType type);
|
||||
|
||||
} // namespace Plasma
|
||||
|
||||
#endif // LIBS_PLASMA_PACKAGES_P_H
|
||||
|
|
|
@ -233,19 +233,12 @@ public:
|
|||
if (runner) {
|
||||
runner->setParent(q);
|
||||
} else {
|
||||
const QString api = service->property("X-Plasma-API").toString();
|
||||
|
||||
if (api.isEmpty()) {
|
||||
QVariantList args;
|
||||
args << service->storageId();
|
||||
QString error;
|
||||
runner = service->createInstance<AbstractRunner>(q, args, &error);
|
||||
if (!runner) {
|
||||
kDebug() << "Failed to load runner:" << service->name() << ". error reported:" << error;
|
||||
}
|
||||
} else {
|
||||
//kDebug() << "got a script runner known as" << api;
|
||||
runner = new AbstractRunner(service, q);
|
||||
QVariantList args;
|
||||
args << service->storageId();
|
||||
QString error;
|
||||
runner = service->createInstance<AbstractRunner>(q, args, &error);
|
||||
if (!runner) {
|
||||
kDebug() << "Failed to load runner:" << service->name() << ". error reported:" << error;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,259 +0,0 @@
|
|||
/*
|
||||
* Copyright 2007 by Aaron Seigo <aseigo@kde.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Library General Public License as
|
||||
* published by the Free Software Foundation; either version 2, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this program; if not, write to the
|
||||
* Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "scripting/appletscript.h"
|
||||
|
||||
#include "kconfig.h"
|
||||
#include "kconfigdialog.h"
|
||||
|
||||
#include "animator.h"
|
||||
#include "applet.h"
|
||||
#include "package.h"
|
||||
#include "private/applet_p.h"
|
||||
|
||||
namespace Plasma
|
||||
{
|
||||
|
||||
class AppletScriptPrivate
|
||||
{
|
||||
public:
|
||||
Applet *applet;
|
||||
};
|
||||
|
||||
AppletScript::AppletScript(QObject *parent)
|
||||
: ScriptEngine(parent),
|
||||
d(new AppletScriptPrivate)
|
||||
{
|
||||
d->applet = 0;
|
||||
}
|
||||
|
||||
AppletScript::~AppletScript()
|
||||
{
|
||||
delete d;
|
||||
}
|
||||
|
||||
void AppletScript::setApplet(Plasma::Applet *applet)
|
||||
{
|
||||
d->applet = applet;
|
||||
}
|
||||
|
||||
Applet *AppletScript::applet() const
|
||||
{
|
||||
Q_ASSERT(d->applet);
|
||||
return d->applet;
|
||||
}
|
||||
|
||||
void AppletScript::paintInterface(QPainter *painter,
|
||||
const QStyleOptionGraphicsItem *option,
|
||||
const QRect &contentsRect)
|
||||
{
|
||||
Q_UNUSED(painter);
|
||||
Q_UNUSED(option);
|
||||
Q_UNUSED(contentsRect);
|
||||
}
|
||||
|
||||
QSizeF AppletScript::size() const
|
||||
{
|
||||
if (applet()) {
|
||||
return applet()->size();
|
||||
}
|
||||
|
||||
return QSizeF();
|
||||
}
|
||||
|
||||
void AppletScript::constraintsEvent(Plasma::Constraints constraints)
|
||||
{
|
||||
Q_UNUSED(constraints);
|
||||
}
|
||||
|
||||
QList<QAction*> AppletScript::contextualActions()
|
||||
{
|
||||
return QList<QAction*>();
|
||||
}
|
||||
|
||||
QPainterPath AppletScript::shape() const
|
||||
{
|
||||
if (applet()) {
|
||||
QPainterPath path;
|
||||
path.addRect(applet()->boundingRect());
|
||||
return path;
|
||||
}
|
||||
|
||||
return QPainterPath();
|
||||
}
|
||||
|
||||
void AppletScript::setHasConfigurationInterface(bool hasInterface)
|
||||
{
|
||||
if (applet()) {
|
||||
applet()->setHasConfigurationInterface(hasInterface);
|
||||
}
|
||||
}
|
||||
|
||||
void AppletScript::setConfigurationRequired(bool req, const QString &reason)
|
||||
{
|
||||
if (applet()) {
|
||||
applet()->setConfigurationRequired(req, reason);
|
||||
}
|
||||
}
|
||||
|
||||
void AppletScript::setFailedToLaunch(bool failed, const QString &reason)
|
||||
{
|
||||
if (applet()) {
|
||||
applet()->setFailedToLaunch(failed, reason);
|
||||
}
|
||||
}
|
||||
|
||||
void AppletScript::configNeedsSaving() const
|
||||
{
|
||||
if (applet()) {
|
||||
emit applet()->configNeedsSaving();
|
||||
}
|
||||
}
|
||||
|
||||
void AppletScript::showConfigurationInterface()
|
||||
{
|
||||
if (applet()) {
|
||||
KConfigDialog *dialog = applet()->d->generateGenericConfigDialog();
|
||||
applet()->d->addStandardConfigurationPages(dialog);
|
||||
dialog->show();
|
||||
}
|
||||
}
|
||||
|
||||
KConfigDialog *AppletScript::standardConfigurationDialog()
|
||||
{
|
||||
if (applet()) {
|
||||
return applet()->d->generateGenericConfigDialog();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void AppletScript::addStandardConfigurationPages(KConfigDialog *dialog)
|
||||
{
|
||||
if (applet()) {
|
||||
applet()->d->addStandardConfigurationPages(dialog);
|
||||
}
|
||||
}
|
||||
|
||||
void AppletScript::showMessage(const QIcon &icon, const QString &message, const MessageButtons buttons)
|
||||
{
|
||||
if (applet()) {
|
||||
applet()->showMessage(icon, message, buttons);
|
||||
}
|
||||
}
|
||||
|
||||
void AppletScript::registerAsDragHandle(QGraphicsItem *item)
|
||||
{
|
||||
if (applet()) {
|
||||
applet()->registerAsDragHandle(item);
|
||||
}
|
||||
}
|
||||
|
||||
void AppletScript::unregisterAsDragHandle(QGraphicsItem *item)
|
||||
{
|
||||
if (applet()) {
|
||||
applet()->unregisterAsDragHandle(item);
|
||||
}
|
||||
}
|
||||
|
||||
bool AppletScript::isRegisteredAsDragHandle(QGraphicsItem *item)
|
||||
{
|
||||
if (applet()) {
|
||||
return applet()->isRegisteredAsDragHandle(item);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void AppletScript::configChanged()
|
||||
{
|
||||
}
|
||||
|
||||
DataEngine *AppletScript::dataEngine(const QString &engine) const
|
||||
{
|
||||
Q_ASSERT(d->applet);
|
||||
return d->applet->dataEngine(engine);
|
||||
}
|
||||
|
||||
QString AppletScript::mainScript() const
|
||||
{
|
||||
Q_ASSERT(d->applet);
|
||||
return d->applet->package()->filePath("mainscript");
|
||||
}
|
||||
|
||||
const Package *AppletScript::package() const
|
||||
{
|
||||
Q_ASSERT(d->applet);
|
||||
return d->applet->package();
|
||||
}
|
||||
|
||||
KPluginInfo AppletScript::description() const
|
||||
{
|
||||
Q_ASSERT(d->applet);
|
||||
return d->applet->d->appletDescription;
|
||||
}
|
||||
|
||||
Extender *AppletScript::extender() const
|
||||
{
|
||||
Q_ASSERT(d->applet);
|
||||
return d->applet->extender();
|
||||
}
|
||||
|
||||
bool AppletScript::drawWallpaper() const
|
||||
{
|
||||
Q_ASSERT(d->applet);
|
||||
Plasma::Containment *cont = qobject_cast<Plasma::Containment *>(d->applet);
|
||||
if (cont) {
|
||||
return cont->drawWallpaper();
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void AppletScript::setDrawWallpaper(bool drawWallpaper)
|
||||
{
|
||||
Q_ASSERT(d->applet);
|
||||
Plasma::Containment *cont = qobject_cast<Plasma::Containment *>(d->applet);
|
||||
if (cont) {
|
||||
cont->setDrawWallpaper(drawWallpaper);
|
||||
}
|
||||
}
|
||||
|
||||
Containment::Type AppletScript::containmentType() const
|
||||
{
|
||||
Q_ASSERT(d->applet);
|
||||
Plasma::Containment *cont = qobject_cast<Plasma::Containment *>(d->applet);
|
||||
if (cont) {
|
||||
return cont->containmentType();
|
||||
} else {
|
||||
return Containment::NoContainmentType;
|
||||
}
|
||||
}
|
||||
|
||||
void AppletScript::setContainmentType(Containment::Type type)
|
||||
{
|
||||
Q_ASSERT(d->applet);
|
||||
Plasma::Containment *cont = qobject_cast<Plasma::Containment *>(d->applet);
|
||||
if (cont) {
|
||||
cont->setContainmentType(type);
|
||||
}
|
||||
}
|
||||
|
||||
} // Plasma namespace
|
||||
|
||||
#include "moc_appletscript.cpp"
|
|
@ -1,268 +0,0 @@
|
|||
/*
|
||||
* Copyright 2007 by Aaron Seigo <aseigo@kde.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Library General Public License as
|
||||
* published by the Free Software Foundation; either version 2, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this program; if not, write to the
|
||||
* Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef PLASMA_APPLETSCRIPT_H
|
||||
#define PLASMA_APPLETSCRIPT_H
|
||||
|
||||
#include <QtCore/QObject>
|
||||
#include <QtCore/QRect>
|
||||
#include <QtCore/qsize.h>
|
||||
|
||||
#include <kplugininfo.h>
|
||||
|
||||
#include <plasma/containment.h>
|
||||
#include <plasma/plasma_export.h>
|
||||
#include <plasma/scripting/scriptengine.h>
|
||||
|
||||
#include <QAction>
|
||||
#include <QPainter>
|
||||
#include <QStyleOptionGraphicsItem>
|
||||
class KConfigDialog;
|
||||
|
||||
namespace Plasma
|
||||
{
|
||||
|
||||
class Animation;
|
||||
class AppletScriptPrivate;
|
||||
class Extender;
|
||||
|
||||
/**
|
||||
* @class AppletScript plasma/scripting/appletscript.h <Plasma/Scripting/AppletScript>
|
||||
*
|
||||
* @short Provides a restricted interface for scripted applets.
|
||||
*/
|
||||
class PLASMA_EXPORT AppletScript : public ScriptEngine
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
/**
|
||||
* Default constructor for an AppletScript.
|
||||
*
|
||||
* Subclasses should not attempt to access the Plasma::Applet
|
||||
* associated with this AppletScript in the constructor. All
|
||||
* such set up that requires the Applet itself should be done
|
||||
* in the init() method.
|
||||
*/
|
||||
explicit AppletScript(QObject *parent = 0);
|
||||
~AppletScript();
|
||||
|
||||
/**
|
||||
* Sets the applet associated with this AppletScript
|
||||
*/
|
||||
void setApplet(Plasma::Applet *applet);
|
||||
|
||||
/**
|
||||
* Returns the Plasma::Applet associated with this script component
|
||||
*/
|
||||
Plasma::Applet *applet() const;
|
||||
|
||||
/**
|
||||
* Called when the script should paint the applet
|
||||
*
|
||||
* @param painter the QPainter to use
|
||||
* @param option the style option containing such flags as selection, level of detail, etc
|
||||
* @param contentsRect the rect to paint within; automatically adjusted for
|
||||
* the background, if any
|
||||
*/
|
||||
virtual void paintInterface(QPainter *painter,
|
||||
const QStyleOptionGraphicsItem *option,
|
||||
const QRect &contentsRect);
|
||||
|
||||
/**
|
||||
* Returns the area within which contents can be painted.
|
||||
**/
|
||||
Q_INVOKABLE QSizeF size() const;
|
||||
|
||||
/**
|
||||
* Called when any of the geometry constraints have been updated.
|
||||
*
|
||||
* This is always called prior to painting and should be used as an
|
||||
* opportunity to layout the widget, calculate sizings, etc.
|
||||
*
|
||||
* Do not call update() from this method; an update() will be triggered
|
||||
* at the appropriate time for the applet.
|
||||
*
|
||||
* @param constraints the type of constraints that were updated
|
||||
*/
|
||||
virtual void constraintsEvent(Plasma::Constraints constraints);
|
||||
|
||||
/**
|
||||
* Returns a list of context-related QAction instances.
|
||||
*
|
||||
* @return A list of actions. The default implementation returns an
|
||||
* empty list.
|
||||
*/
|
||||
virtual QList<QAction*> contextualActions();
|
||||
|
||||
/**
|
||||
* Returns the shape of the widget, defaults to the bounding rect
|
||||
*/
|
||||
virtual QPainterPath shape() const;
|
||||
|
||||
/**
|
||||
* Sets whether or not this script has a configuration interface or not
|
||||
*
|
||||
* @param hasInterface true if the applet is user configurable
|
||||
*/
|
||||
void setHasConfigurationInterface(bool hasInterface);
|
||||
|
||||
/**
|
||||
* @see Applet
|
||||
*/
|
||||
void setConfigurationRequired(bool req, const QString &reason = QString());
|
||||
|
||||
/**
|
||||
* @see Applet
|
||||
*/
|
||||
void setFailedToLaunch(bool failed, const QString &reason = QString());
|
||||
|
||||
/**
|
||||
* @see Applet
|
||||
*/
|
||||
void configNeedsSaving() const;
|
||||
|
||||
/**
|
||||
* @see Applet
|
||||
*/
|
||||
Extender *extender() const;
|
||||
|
||||
//FIXME plasma2: setWallpaperEnabled and setContainmentType should become public?
|
||||
/**
|
||||
* @return true if the applet is a containment AND if the wallpaper is enabled
|
||||
* @see Containment
|
||||
* @since 4.7
|
||||
*/
|
||||
bool drawWallpaper() const;
|
||||
/**
|
||||
* set if the containment draws its own wallpaper: it has no effect if the applet is not a containment
|
||||
* @see Containment
|
||||
* @since 4.7
|
||||
*/
|
||||
void setDrawWallpaper(bool drawWallpaper);
|
||||
|
||||
/**
|
||||
* @see Containment
|
||||
* @since 4.7
|
||||
*/
|
||||
Containment::Type containmentType() const;
|
||||
|
||||
/**
|
||||
* @see Containment
|
||||
* @since 4.7
|
||||
*/
|
||||
void setContainmentType(Containment::Type type);
|
||||
|
||||
Q_SIGNALS:
|
||||
/**
|
||||
* @see Applet
|
||||
*/
|
||||
void saveState(KConfigGroup &group) const;
|
||||
|
||||
/**
|
||||
* @see PopupApplet
|
||||
*/
|
||||
void popupEvent(bool popped) const;
|
||||
|
||||
public Q_SLOTS:
|
||||
|
||||
/**
|
||||
* Show a configuration dialog.
|
||||
*/
|
||||
virtual void showConfigurationInterface();
|
||||
|
||||
/**
|
||||
* Configure was changed.
|
||||
*/
|
||||
virtual void configChanged();
|
||||
|
||||
protected:
|
||||
/**
|
||||
* @param engine name of the engine
|
||||
* @return a data engine associated with this plasmoid
|
||||
*/
|
||||
Q_INVOKABLE DataEngine *dataEngine(const QString &engine) const;
|
||||
|
||||
/**
|
||||
* @return absolute path to the main script file for this plasmoid
|
||||
*/
|
||||
QString mainScript() const;
|
||||
|
||||
/**
|
||||
* @return the Package associated with this plasmoid which can
|
||||
* be used to request resources, such as images and
|
||||
* interface files.
|
||||
*/
|
||||
const Package *package() const;
|
||||
|
||||
/**
|
||||
* @return the KPluginInfo associated with this plasmoid
|
||||
*/
|
||||
KPluginInfo description() const;
|
||||
|
||||
/**
|
||||
* @return a standard Plasma applet configuration dialog, ready
|
||||
* to have pages added to it.
|
||||
*
|
||||
* Note that the dialog returned is set to delete on close.
|
||||
*/
|
||||
KConfigDialog *standardConfigurationDialog();
|
||||
|
||||
/**
|
||||
* This method should be called after a scripting applet has added
|
||||
* its own pages to a configuration dialog
|
||||
*
|
||||
* @since 4.3.1
|
||||
*/
|
||||
void addStandardConfigurationPages(KConfigDialog *dialog);
|
||||
|
||||
/**
|
||||
* @see Applet
|
||||
*/
|
||||
void showMessage(const QIcon &icon, const QString &message, const MessageButtons buttons);
|
||||
|
||||
/**
|
||||
* @see Applet
|
||||
*/
|
||||
void registerAsDragHandle(QGraphicsItem *item);
|
||||
|
||||
/**
|
||||
* @see Applet
|
||||
*/
|
||||
void unregisterAsDragHandle(QGraphicsItem *item);
|
||||
|
||||
/**
|
||||
* @see Applet
|
||||
*/
|
||||
bool isRegisteredAsDragHandle(QGraphicsItem *item);
|
||||
|
||||
private:
|
||||
friend class Applet;
|
||||
friend class PopupApplet;
|
||||
|
||||
AppletScriptPrivate *const d;
|
||||
};
|
||||
|
||||
#define K_EXPORT_PLASMA_APPLETSCRIPTENGINE(libname, classname) \
|
||||
K_PLUGIN_FACTORY(factory, registerPlugin<classname>();) \
|
||||
K_EXPORT_PLUGIN(factory("plasma_appletscriptengine_" #libname))
|
||||
|
||||
} //Plasma namespace
|
||||
|
||||
#endif
|
|
@ -1,199 +0,0 @@
|
|||
/*
|
||||
* Copyright 2007 by Aaron Seigo <aseigo@kde.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Library General Public License as
|
||||
* published by the Free Software Foundation; either version 2, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this program; if not, write to the
|
||||
* Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "scripting/scriptengine.h"
|
||||
|
||||
#include <kdebug.h>
|
||||
#include <kservice.h>
|
||||
#include <kservicetypetrader.h>
|
||||
|
||||
#include "abstractrunner.h"
|
||||
#include "applet.h"
|
||||
#include "dataengine.h"
|
||||
#include "package.h"
|
||||
#include "scripting/appletscript.h"
|
||||
|
||||
#include "private/packages_p.h"
|
||||
|
||||
namespace Plasma
|
||||
{
|
||||
|
||||
ScriptEngine::ScriptEngine(QObject *parent)
|
||||
: QObject(parent)
|
||||
{
|
||||
}
|
||||
|
||||
ScriptEngine::~ScriptEngine()
|
||||
{
|
||||
// delete d;
|
||||
}
|
||||
|
||||
bool ScriptEngine::init()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
const Package *ScriptEngine::package() const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
QString ScriptEngine::mainScript() const
|
||||
{
|
||||
return QString();
|
||||
}
|
||||
|
||||
QStringList knownLanguages(ComponentTypes types)
|
||||
{
|
||||
QString constraintTemplate = "'%1' in [X-Plasma-ComponentTypes]";
|
||||
QString constraint;
|
||||
|
||||
if (types & AppletComponent) {
|
||||
constraint.append(constraintTemplate.arg("Applet"));
|
||||
}
|
||||
|
||||
KService::List offers = KServiceTypeTrader::self()->query("Plasma/ScriptEngine", constraint);
|
||||
//kDebug() << "Applet::knownApplets constraint was '" << constraint
|
||||
// << "' which got us " << offers.count() << " matches";
|
||||
|
||||
QStringList languages;
|
||||
foreach (const KService::Ptr &service, offers) {
|
||||
QString language = service->property("X-Plasma-API").toString();
|
||||
if (!languages.contains(language)) {
|
||||
languages.append(language);
|
||||
}
|
||||
}
|
||||
|
||||
return languages;
|
||||
}
|
||||
|
||||
KService::List engineOffers(const QString &language, ComponentType type)
|
||||
{
|
||||
if (language.isEmpty()) {
|
||||
return KService::List();
|
||||
}
|
||||
|
||||
QRegExp re("[^a-zA-Z0-9\\-_]");
|
||||
if (re.indexIn(language) != -1) {
|
||||
kDebug() << "invalid language attempted:" << language;
|
||||
return KService::List();
|
||||
}
|
||||
|
||||
QString component;
|
||||
switch (type) {
|
||||
case AppletComponent: {
|
||||
component = "Applet";
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
return KService::List();
|
||||
}
|
||||
}
|
||||
|
||||
QString constraint = QString("[X-Plasma-API] == '%1' and "
|
||||
"'%2' in [X-Plasma-ComponentTypes]").arg(language, component);
|
||||
KService::List offers = KServiceTypeTrader::self()->query("Plasma/ScriptEngine", constraint);
|
||||
/* kDebug() << "********************* loadingApplet with Plasma/ScriptEngine" << constraint
|
||||
<< "resulting in" << offers.count() << "results";*/
|
||||
if (offers.isEmpty()) {
|
||||
kDebug() << "No offers for \"" << language << "\"";
|
||||
}
|
||||
|
||||
return offers;
|
||||
}
|
||||
|
||||
ScriptEngine *loadEngine(const QString &language, ComponentType type, QObject *parent)
|
||||
{
|
||||
KService::List offers = engineOffers(language, type);
|
||||
|
||||
QVariantList args;
|
||||
QString error;
|
||||
|
||||
ScriptEngine *engine = 0;
|
||||
foreach (const KService::Ptr &service, offers) {
|
||||
switch (type) {
|
||||
case AppletComponent: {
|
||||
engine = service->createInstance<Plasma::AppletScript>(parent, args, &error);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (engine) {
|
||||
return engine;
|
||||
}
|
||||
|
||||
kDebug() << "Couldn't load script engine for language " << language
|
||||
<< "! error reported: " << error;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
AppletScript *loadScriptEngine(const QString &language, Applet *applet)
|
||||
{
|
||||
AppletScript *engine =
|
||||
static_cast<AppletScript*>(loadEngine(language, AppletComponent, applet));
|
||||
|
||||
if (engine) {
|
||||
engine->setApplet(applet);
|
||||
}
|
||||
|
||||
return engine;
|
||||
}
|
||||
|
||||
PackageStructure::Ptr defaultPackageStructure(ComponentType type)
|
||||
{
|
||||
switch (type) {
|
||||
case AppletComponent:
|
||||
case GenericComponent:
|
||||
return PackageStructure::Ptr(new PlasmoidPackage());
|
||||
default:
|
||||
// TODO: we don't have any special structures for other components yet
|
||||
break;
|
||||
}
|
||||
|
||||
return PackageStructure::Ptr(new PackageStructure());
|
||||
}
|
||||
|
||||
PackageStructure::Ptr packageStructure(const QString &language, ComponentType type)
|
||||
{
|
||||
KService::List offers = engineOffers(language, type);
|
||||
|
||||
if (offers.isEmpty()) {
|
||||
return defaultPackageStructure(type);
|
||||
}
|
||||
|
||||
KService::Ptr offer = offers.first();
|
||||
QString packageFormat = offer->property("X-Plasma-PackageFormat").toString();
|
||||
|
||||
if (packageFormat.isEmpty()) {
|
||||
return defaultPackageStructure(type);
|
||||
} else {
|
||||
PackageStructure::Ptr structure = PackageStructure::load(packageFormat);
|
||||
return structure;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Plasma
|
||||
|
||||
#include "moc_scriptengine.cpp"
|
||||
|
|
@ -1,118 +0,0 @@
|
|||
/*
|
||||
* Copyright 2007 by Aaron Seigo <aseigo@kde.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Library General Public License as
|
||||
* published by the Free Software Foundation; either version 2, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this program; if not, write to the
|
||||
* Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef PLASMA_SCRIPTENGINE_H
|
||||
#define PLASMA_SCRIPTENGINE_H
|
||||
|
||||
#include <plasma/plasma_export.h>
|
||||
#include <plasma/packagestructure.h>
|
||||
#include <plasma/plasma.h>
|
||||
|
||||
#include <QtCore/QObject>
|
||||
#include <QtCore/QRect>
|
||||
#include <QtCore/qsize.h>
|
||||
|
||||
#include <QPainter>
|
||||
#include <QStyleOptionGraphicsItem>
|
||||
|
||||
namespace Plasma
|
||||
{
|
||||
|
||||
class AbstractRunner;
|
||||
class Applet;
|
||||
class AppletScript;
|
||||
class DataEngine;
|
||||
class Wallpaper;
|
||||
class Package;
|
||||
|
||||
/**
|
||||
* @class ScriptEngine plasma/scripting/scriptengine.h <Plasma/Scripting/ScriptEngine>
|
||||
*
|
||||
* @short The base class for scripting interfaces to be used in loading
|
||||
* plasmoids of a given language.
|
||||
*
|
||||
* All ScriptEngines should export as consistent an interface as possible
|
||||
* so that the learning curve is limited. In particular, the following
|
||||
* API should be made available in the script environment:
|
||||
*
|
||||
* TODO: define the actual scripting APIas ...
|
||||
* PlasmaApplet - the applet of this plasmoid
|
||||
* LoadUserInterface(String uiFile) - loads and returns a given UI file
|
||||
* LoadImage - loads an image resource out of the plasmoid's package
|
||||
* PlasmaSvg - creates and returns an Svg file
|
||||
**/
|
||||
|
||||
class PLASMA_EXPORT ScriptEngine : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
~ScriptEngine();
|
||||
|
||||
/**
|
||||
* Called when it is safe to initialize the internal state of the engine
|
||||
*/
|
||||
virtual bool init();
|
||||
|
||||
protected:
|
||||
explicit ScriptEngine(QObject *parent = 0);
|
||||
|
||||
/**
|
||||
* @return absolute path to the main script file for this plasmoid
|
||||
*/
|
||||
virtual QString mainScript() const;
|
||||
|
||||
/**
|
||||
* @return the Package associated with this plasmoid which can
|
||||
* be used to request resources, such as images and
|
||||
* interface files.
|
||||
*/
|
||||
virtual const Package *package() const;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param types a set of ComponentTypes flags for which to look up the
|
||||
* language support for
|
||||
* @return a list of all supported languages for the given type(s).
|
||||
**/
|
||||
PLASMA_EXPORT QStringList knownLanguages(ComponentTypes types);
|
||||
|
||||
/**
|
||||
* Loads an Applet script engine for the given language.
|
||||
*
|
||||
* @param language the language to load for
|
||||
* @param applet the Plasma::Applet for this script
|
||||
* @return pointer to the AppletScript or 0 on failure; the caller is responsible
|
||||
* for the return object which will be parented to the Applet
|
||||
**/
|
||||
PLASMA_EXPORT AppletScript *loadScriptEngine(const QString &language, Applet *applet);
|
||||
|
||||
/**
|
||||
* Loads an appropriate PackageStructure for the given language and type
|
||||
*
|
||||
* @param language the language to load the PackageStructure for
|
||||
* @param type the component type
|
||||
* @return a guarded PackageStructure pointer
|
||||
*/
|
||||
PLASMA_EXPORT PackageStructure::Ptr packageStructure(const QString &language, ComponentType type);
|
||||
|
||||
} // namespace Plasma
|
||||
|
||||
#endif
|
||||
|
|
@ -291,21 +291,10 @@ void SvgPrivate::createRenderer()
|
|||
|
||||
//kDebug() << kBacktrace();
|
||||
if (themed && path.isEmpty() && !themeFailed) {
|
||||
Applet *applet = qobject_cast<Applet*>(q->parent());
|
||||
if (applet && applet->package()) {
|
||||
path = applet->package()->filePath("images", themePath + ".svg");
|
||||
|
||||
if (path.isEmpty()) {
|
||||
path = applet->package()->filePath("images", themePath + ".svgz");
|
||||
}
|
||||
}
|
||||
|
||||
if (path.isEmpty()) {
|
||||
path = actualTheme()->imagePath(themePath);
|
||||
themeFailed = path.isEmpty();
|
||||
if (themeFailed) {
|
||||
kWarning() << "No image path found for" << themePath;
|
||||
}
|
||||
path = actualTheme()->imagePath(themePath);
|
||||
themeFailed = path.isEmpty();
|
||||
if (themeFailed) {
|
||||
kWarning() << "No image path found for" << themePath;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -12,9 +12,6 @@ MACRO(PLASMA_UNIT_TESTS)
|
|||
ENDMACRO(PLASMA_UNIT_TESTS)
|
||||
|
||||
PLASMA_UNIT_TESTS(
|
||||
packagestructuretest
|
||||
packagemetadatatest
|
||||
plasmoidpackagetest
|
||||
runnercontexttest
|
||||
configloadertest
|
||||
)
|
||||
|
|
|
@ -1,213 +0,0 @@
|
|||
/********************************************************************************
|
||||
* Copyright 2010 by Martin Blumenstingl <darklight.xdarklight@googlemail.com> *
|
||||
* *
|
||||
* This library is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU Library General Public *
|
||||
* License as published by the Free Software Foundation; either *
|
||||
* version 2 of the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This library is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
|
||||
* Library General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Library General Public License *
|
||||
* along with this library; see the file COPYING.LIB. If not, write to *
|
||||
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, *
|
||||
* Boston, MA 02110-1301, USA. *
|
||||
*********************************************************************************/
|
||||
|
||||
#include "configloadertest.h"
|
||||
|
||||
#include <kconfig.h>
|
||||
#include <kconfiggroup.h>
|
||||
#include <kdebug.h>
|
||||
#include <kconfigskeleton.h>
|
||||
|
||||
#include "plasma/configloader.h"
|
||||
|
||||
Q_DECLARE_METATYPE(QList<int>)
|
||||
|
||||
#define TEST_NAME QString::fromLatin1("configloadertest")
|
||||
|
||||
#define GET_CONFIG_ITEM_VALUE(type, configName) \
|
||||
KConfigSkeletonItem* item = cl->findItemByGroup(TEST_NAME, configName); \
|
||||
/* Check if we got back a valid item. */ \
|
||||
QVERIFY(item != 0); \
|
||||
/* Cast the item to the given type. */ \
|
||||
type typeItem = dynamic_cast<type>(item); \
|
||||
/* Make sure the cast was successful. */ \
|
||||
QVERIFY(typeItem != 0);
|
||||
|
||||
void ConfigLoaderTest::init()
|
||||
{
|
||||
QString fileName = TEST_NAME + QString::fromLatin1(".xml");
|
||||
configFile = new QFile(QString::fromLatin1(KDESRCDIR) + QString::fromLatin1("/") + fileName);
|
||||
cl = new Plasma::ConfigLoader(configFile->fileName(), configFile);
|
||||
}
|
||||
|
||||
void ConfigLoaderTest::cleanup()
|
||||
{
|
||||
delete cl;
|
||||
delete configFile;
|
||||
}
|
||||
|
||||
void ConfigLoaderTest::boolDefaultValue()
|
||||
{
|
||||
GET_CONFIG_ITEM_VALUE(KCoreConfigSkeleton::ItemBool*, "DefaultBoolItem");
|
||||
|
||||
QVERIFY(typeItem->isEqual(true));
|
||||
}
|
||||
|
||||
void ConfigLoaderTest::colorDefaultValue()
|
||||
{
|
||||
GET_CONFIG_ITEM_VALUE(KConfigSkeleton::ItemColor*, "DefaultColorItem");
|
||||
|
||||
QVERIFY(typeItem->isEqual(QColor("#00FF00")));
|
||||
}
|
||||
|
||||
void ConfigLoaderTest::colorWithAlphaDefaultValue()
|
||||
{
|
||||
GET_CONFIG_ITEM_VALUE(KConfigSkeleton::ItemColor*, "DefaultColorWithAlphaItem");
|
||||
|
||||
QVERIFY(typeItem->isEqual(QColor(100, 100, 100, 100)));
|
||||
}
|
||||
|
||||
void ConfigLoaderTest::dateTimeDefaultValue()
|
||||
{
|
||||
GET_CONFIG_ITEM_VALUE(KCoreConfigSkeleton::ItemDateTime*, "DefaultDateTimeItem");
|
||||
|
||||
QVERIFY(typeItem->isEqual(QDateTime::fromString("Thu Sep 09 2010")));
|
||||
}
|
||||
|
||||
void ConfigLoaderTest::enumDefaultValue()
|
||||
{
|
||||
GET_CONFIG_ITEM_VALUE(KConfigSkeleton::ItemEnum*, "DefaultEnumItem");
|
||||
|
||||
QVERIFY(typeItem->isEqual(3));
|
||||
}
|
||||
|
||||
void ConfigLoaderTest::fontDefaultValue()
|
||||
{
|
||||
GET_CONFIG_ITEM_VALUE(KConfigSkeleton::ItemFont*, "DefaultFontItem");
|
||||
|
||||
QVERIFY(typeItem->isEqual(QFont("DejaVu Sans")));
|
||||
}
|
||||
|
||||
void ConfigLoaderTest::intDefaultValue()
|
||||
{
|
||||
GET_CONFIG_ITEM_VALUE(KCoreConfigSkeleton::ItemInt*, "DefaultIntItem");
|
||||
|
||||
QVERIFY(typeItem->isEqual(27));
|
||||
}
|
||||
|
||||
void ConfigLoaderTest::pathDefaultValue()
|
||||
{
|
||||
GET_CONFIG_ITEM_VALUE(KConfigSkeleton::ItemPath*, "DefaultPathItem");
|
||||
|
||||
QVERIFY(typeItem->isEqual(QString::fromLatin1("/dev/null")));
|
||||
}
|
||||
|
||||
void ConfigLoaderTest::stringDefaultValue()
|
||||
{
|
||||
GET_CONFIG_ITEM_VALUE(KConfigSkeleton::ItemString*, "DefaultStringItem");
|
||||
|
||||
QVERIFY(typeItem->isEqual(QString::fromLatin1("TestString")));
|
||||
}
|
||||
|
||||
void ConfigLoaderTest::stringListDefaultValue()
|
||||
{
|
||||
GET_CONFIG_ITEM_VALUE(KConfigSkeleton::ItemStringList*, "DefaultStringListItem");
|
||||
|
||||
// Create a string list with the expected values.
|
||||
QStringList expected;
|
||||
expected.append("One");
|
||||
expected.append("Two");
|
||||
expected.append("Three");
|
||||
expected.append("Four");
|
||||
expected.append("Five");
|
||||
|
||||
QVERIFY(typeItem->isEqual(expected));
|
||||
}
|
||||
|
||||
void ConfigLoaderTest::uintDefaultValue()
|
||||
{
|
||||
GET_CONFIG_ITEM_VALUE(KCoreConfigSkeleton::ItemUInt*, "DefaultUIntItem");
|
||||
|
||||
QVERIFY(typeItem->isEqual(7U));
|
||||
}
|
||||
|
||||
void ConfigLoaderTest::urlDefaultValue()
|
||||
{
|
||||
GET_CONFIG_ITEM_VALUE(KCoreConfigSkeleton::ItemUrl*, "DefaultUrlItem");
|
||||
|
||||
QVERIFY(typeItem->isEqual(KUrl("http://kde.org")));
|
||||
}
|
||||
|
||||
void ConfigLoaderTest::doubleDefaultValue()
|
||||
{
|
||||
GET_CONFIG_ITEM_VALUE(KCoreConfigSkeleton::ItemDouble*, "DefaultDoubleItem");
|
||||
|
||||
QVERIFY(typeItem->isEqual(13.37));
|
||||
}
|
||||
|
||||
void ConfigLoaderTest::intListDefaultValue()
|
||||
{
|
||||
GET_CONFIG_ITEM_VALUE(KCoreConfigSkeleton::ItemIntList*, "DefaultIntListItem");
|
||||
|
||||
// Create a int list with the expected values.
|
||||
QList<int> expected;
|
||||
expected.append(1);
|
||||
expected.append(1);
|
||||
expected.append(2);
|
||||
expected.append(3);
|
||||
expected.append(5);
|
||||
expected.append(8);
|
||||
|
||||
QVERIFY(typeItem->isEqual(qVariantFromValue(expected)));
|
||||
}
|
||||
|
||||
void ConfigLoaderTest::longLongDefaultValue()
|
||||
{
|
||||
GET_CONFIG_ITEM_VALUE(KCoreConfigSkeleton::ItemLongLong*, "DefaultLongLongItem");
|
||||
|
||||
QVERIFY(typeItem->isEqual(Q_INT64_C(-9211372036854775808)));
|
||||
}
|
||||
|
||||
void ConfigLoaderTest::pointDefaultValue()
|
||||
{
|
||||
GET_CONFIG_ITEM_VALUE(KCoreConfigSkeleton::ItemPoint*, "DefaultPointItem");
|
||||
|
||||
QVERIFY(typeItem->isEqual(QPoint(185, 857)));
|
||||
}
|
||||
|
||||
void ConfigLoaderTest::rectDefaultValue()
|
||||
{
|
||||
GET_CONFIG_ITEM_VALUE(KCoreConfigSkeleton::ItemRect*, "DefaultRectItem");
|
||||
|
||||
// Create a new QRect with the expected value.
|
||||
QRect expected;
|
||||
expected.setCoords(3, 7, 951, 358);
|
||||
|
||||
QVERIFY(typeItem->isEqual(expected));
|
||||
}
|
||||
|
||||
void ConfigLoaderTest::sizeDefaultValue()
|
||||
{
|
||||
GET_CONFIG_ITEM_VALUE(KCoreConfigSkeleton::ItemSize*, "DefaultSizeItem");
|
||||
|
||||
QVERIFY(typeItem->isEqual(QSize(640, 480)));
|
||||
}
|
||||
|
||||
void ConfigLoaderTest::ulongLongDefaultValue()
|
||||
{
|
||||
GET_CONFIG_ITEM_VALUE(KCoreConfigSkeleton::ItemULongLong*, "DefaultULongLongItem");
|
||||
|
||||
QVERIFY(typeItem->isEqual(Q_UINT64_C(9223372036854775806)));
|
||||
}
|
||||
|
||||
|
||||
QTEST_KDEMAIN(ConfigLoaderTest, NoGUI)
|
||||
|
||||
//#include "configloadertest.moc"
|
||||
|
|
@ -1,67 +0,0 @@
|
|||
/********************************************************************************
|
||||
* Copyright 2010 by Martin Blumenstingl <darklight.xdarklight@googlemail.com> *
|
||||
* *
|
||||
* This library is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU Library General Public *
|
||||
* License as published by the Free Software Foundation; either *
|
||||
* version 2 of the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This library is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
|
||||
* Library General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Library General Public License *
|
||||
* along with this library; see the file COPYING.LIB. If not, write to *
|
||||
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, *
|
||||
* Boston, MA 02110-1301, USA. *
|
||||
*********************************************************************************/
|
||||
|
||||
#ifndef CONFIGLOADERTEST_H
|
||||
#define CONFIGLOADERTEST_H
|
||||
|
||||
#include <qtest_kde.h>
|
||||
|
||||
namespace Plasma
|
||||
{
|
||||
class ConfigLoader;
|
||||
}
|
||||
|
||||
#include <QFile>
|
||||
|
||||
class ConfigLoaderTest : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public Q_SLOTS:
|
||||
void init();
|
||||
void cleanup();
|
||||
|
||||
private Q_SLOTS:
|
||||
void boolDefaultValue();
|
||||
void colorDefaultValue();
|
||||
void colorWithAlphaDefaultValue();
|
||||
void dateTimeDefaultValue();
|
||||
void enumDefaultValue();
|
||||
void fontDefaultValue();
|
||||
void intDefaultValue();
|
||||
void pathDefaultValue();
|
||||
void stringDefaultValue();
|
||||
void stringListDefaultValue();
|
||||
void uintDefaultValue();
|
||||
void urlDefaultValue();
|
||||
void doubleDefaultValue();
|
||||
void intListDefaultValue();
|
||||
void longLongDefaultValue();
|
||||
void pointDefaultValue();
|
||||
void rectDefaultValue();
|
||||
void sizeDefaultValue();
|
||||
void ulongLongDefaultValue();
|
||||
|
||||
private:
|
||||
Plasma::ConfigLoader* cl;
|
||||
QFile* configFile;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
@ -1,71 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<kcfg xmlns="http://www.kde.org/standards/kcfg/1.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.kde.org/standards/kcfg/1.0
|
||||
http://www.kde.org/standards/kcfg/1.0/kcfg.xsd" >
|
||||
<kcfgfile name="keystatusplasmoidrc"/>
|
||||
|
||||
<group name="configloadertest">
|
||||
<entry name="DefaultBoolItem" type="Bool">
|
||||
<default>true</default>
|
||||
</entry>
|
||||
<entry name="DefaultColorItem" type="Color">
|
||||
<default>#00FF00</default>
|
||||
</entry>
|
||||
<entry name="DefaultColorWithAlphaItem" type="Color">
|
||||
<default>100,100,100,100</default>
|
||||
</entry>
|
||||
<entry name="DefaultDateTimeItem" type="DateTime">
|
||||
<default>Thu Sep 09 2010</default>
|
||||
</entry>
|
||||
<entry name="DefaultEnumItem" type="Enum">
|
||||
<default>3</default>
|
||||
<choice name="One" value="1" />
|
||||
<choice name="Two" value="2" />
|
||||
<choice name="Three" value="3" />
|
||||
<choice name="Four" value="4" />
|
||||
</entry>
|
||||
<entry name="DefaultFontItem" type="Font">
|
||||
<default>DejaVu Sans</default>
|
||||
</entry>
|
||||
<entry name="DefaultIntItem" type="Int">
|
||||
<default>27</default>
|
||||
</entry>
|
||||
<entry name="DefaultPathItem" type="Path">
|
||||
<default>/dev/null</default>
|
||||
</entry>
|
||||
<entry name="DefaultStringItem" type="String">
|
||||
<default>TestString</default>
|
||||
</entry>
|
||||
<entry name="DefaultStringListItem" type="StringList">
|
||||
<default>One,Two,Three,Four,Five</default>
|
||||
</entry>
|
||||
<entry name="DefaultUIntItem" type="UInt">
|
||||
<default>7</default>
|
||||
</entry>
|
||||
<entry name="DefaultUrlItem" type="Url">
|
||||
<default>http://kde.org</default>
|
||||
</entry>
|
||||
<entry name="DefaultDoubleItem" type="Double">
|
||||
<default>13.37</default>
|
||||
</entry>
|
||||
<entry name="DefaultIntListItem" type="IntList">
|
||||
<default>1,1,2,3,5,8</default>
|
||||
</entry>
|
||||
<entry name="DefaultLongLongItem" type="LongLong">
|
||||
<default>-9211372036854775808</default>
|
||||
</entry>
|
||||
<entry name="DefaultPointItem" type="Point">
|
||||
<default>185,857</default>
|
||||
</entry>
|
||||
<entry name="DefaultRectItem" type="Rect">
|
||||
<default>3,7,951,358</default>
|
||||
</entry>
|
||||
<entry name="DefaultSizeItem" type="Size">
|
||||
<default>640,480</default>
|
||||
</entry>
|
||||
<entry name="DefaultULongLongItem" type="ULongLong">
|
||||
<default>9223372036854775806</default>
|
||||
</entry>
|
||||
</group>
|
||||
</kcfg>
|
|
@ -1,215 +0,0 @@
|
|||
/******************************************************************************
|
||||
* Copyright 2007 by Aaron Seigo <aseigo@kde.org> *
|
||||
* *
|
||||
* This library is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU Library General Public *
|
||||
* License as published by the Free Software Foundation; either *
|
||||
* version 2 of the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This library is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
|
||||
* Library General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Library General Public License *
|
||||
* along with this library; see the file COPYING.LIB. If not, write to *
|
||||
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, *
|
||||
* Boston, MA 02110-1301, USA. *
|
||||
*******************************************************************************/
|
||||
|
||||
#include "packagestructuretest.h"
|
||||
|
||||
#include <kconfig.h>
|
||||
#include <kconfiggroup.h>
|
||||
#include <kdebug.h>
|
||||
|
||||
#include "plasma/package.h"
|
||||
#include "plasma/packagestructure.h"
|
||||
#include "plasma/applet.h"
|
||||
|
||||
class NoPrefixes : public Plasma::PackageStructure
|
||||
{
|
||||
public:
|
||||
explicit NoPrefixes()
|
||||
: Plasma::PackageStructure(0, "StructureLess")
|
||||
{
|
||||
setContentsPrefixPaths(QStringList());
|
||||
addDirectoryDefinition("bin", "bin", "bin");
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
void PackageStructureTest::init()
|
||||
{
|
||||
ps = Plasma::Applet::packageStructure();
|
||||
}
|
||||
|
||||
void PackageStructureTest::cleanup()
|
||||
{
|
||||
}
|
||||
|
||||
void PackageStructureTest::emptyContentsPrefix()
|
||||
{
|
||||
Plasma::PackageStructure::Ptr structure(new NoPrefixes);
|
||||
Plasma::Package package("/", structure);
|
||||
QString path(package.filePath("bin", "ls"));
|
||||
qDebug() << path;
|
||||
QCOMPARE(path, QString("/bin/ls"));
|
||||
}
|
||||
|
||||
void PackageStructureTest::type()
|
||||
{
|
||||
QCOMPARE(ps->type(), QString("Plasmoid"));
|
||||
}
|
||||
|
||||
void PackageStructureTest::directories()
|
||||
{
|
||||
QList<QByteArray> dirs;
|
||||
dirs << "config" << "data" << "images" << "scripts" << "theme" << "translations" << "ui";
|
||||
|
||||
QList<QByteArray> psDirs = ps->directories();
|
||||
|
||||
QCOMPARE(dirs.count(), psDirs.count());
|
||||
|
||||
for (int i = 0; i < psDirs.count(); ++i) {
|
||||
QCOMPARE(dirs[i], psDirs[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void PackageStructureTest::requiredDirectories()
|
||||
{
|
||||
QCOMPARE(ps->requiredDirectories().size(), 0);
|
||||
}
|
||||
|
||||
void PackageStructureTest::files()
|
||||
{
|
||||
QList<QByteArray> files;
|
||||
files << "defaultconfig" << "mainconfigui" << "mainconfigxml" << "mainscript";
|
||||
|
||||
QList<QByteArray> psFiles = ps->files();
|
||||
|
||||
//for (int i = 0; i < psFiles.count(); ++i) {
|
||||
// qDebug() << psFiles[i];
|
||||
//}
|
||||
QCOMPARE(files.count(), psFiles.count());
|
||||
for (int i = 0; i < files.count(); ++i) {
|
||||
QCOMPARE(files[i], psFiles[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void PackageStructureTest::requiredFiles()
|
||||
{
|
||||
QList<QByteArray> files;
|
||||
files << "mainscript";
|
||||
|
||||
QList<QByteArray> psFiles = ps->requiredFiles();
|
||||
|
||||
QCOMPARE(files.count(), psFiles.count());
|
||||
for (int i = 0; i < files.count(); ++i) {
|
||||
QCOMPARE(files[i], psFiles[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void PackageStructureTest::path()
|
||||
{
|
||||
QCOMPARE(ps->path("images"), QString("images"));
|
||||
QCOMPARE(ps->path("mainscript"), QString("code/main"));
|
||||
}
|
||||
|
||||
void PackageStructureTest::name()
|
||||
{
|
||||
QCOMPARE(ps->name("config"), i18n("Configuration Definitions"));
|
||||
QCOMPARE(ps->name("mainscript"), i18n("Main Script File"));
|
||||
}
|
||||
|
||||
void PackageStructureTest::required()
|
||||
{
|
||||
QVERIFY(ps->isRequired("mainscript"));
|
||||
}
|
||||
|
||||
void PackageStructureTest::mimetypes()
|
||||
{
|
||||
QStringList mimetypes;
|
||||
mimetypes << "image/svg+xml" << "image/png" << "image/jpeg";
|
||||
QCOMPARE(ps->mimetypes("images"), mimetypes);
|
||||
QCOMPARE(ps->mimetypes("theme"), mimetypes);
|
||||
}
|
||||
|
||||
void PackageStructureTest::read()
|
||||
{
|
||||
QString structurePath = QString(KDESRCDIR) + "/plasmoidpackagerc";
|
||||
KConfig config(structurePath, KConfig::SimpleConfig);
|
||||
Plasma::PackageStructure structure;
|
||||
structure.read(&config);
|
||||
|
||||
// check some names
|
||||
QCOMPARE(structure.name("config"), i18n("Configuration Definitions"));
|
||||
QCOMPARE(structure.name("mainscript"), i18n("Main Script File"));
|
||||
|
||||
// check some paths
|
||||
QCOMPARE(structure.path("images"), QString("images"));
|
||||
QCOMPARE(structure.path("mainscript"), QString("code/main"));
|
||||
|
||||
// compare files
|
||||
QList<QByteArray> files;
|
||||
files << "mainconfiggui" << "mainconfigxml" << "mainscript";
|
||||
|
||||
QList<QByteArray> psFiles = structure.files();
|
||||
|
||||
QCOMPARE(psFiles.count(), files.count());
|
||||
for (int i = 0; i < files.count(); ++i) {
|
||||
QCOMPARE(psFiles[i], files[i]);
|
||||
}
|
||||
|
||||
// compare required files
|
||||
QList<QByteArray> reqFiles = structure.requiredFiles();
|
||||
QCOMPARE(reqFiles.count(), 1);
|
||||
QCOMPARE(reqFiles[0], QByteArray("mainscript"));
|
||||
|
||||
// compare directories
|
||||
QList <QByteArray> dirs;
|
||||
dirs << "config" << "configui" << "images" << "scripts";
|
||||
QList <QByteArray> psDirs = structure.directories();
|
||||
QCOMPARE(psDirs.count(), dirs.count());
|
||||
for (int i = 0; i < dirs.count(); i++) {
|
||||
QCOMPARE(psDirs[i], dirs[i]);
|
||||
}
|
||||
QCOMPARE(structure.requiredDirectories().size(), 0);
|
||||
}
|
||||
|
||||
void PackageStructureTest::write()
|
||||
{
|
||||
QString file1 = QDir::homePath() + "/.kde-unit-test/packagerc";
|
||||
QString file2 = QString(KDESRCDIR) + "/plasmoidpackagerc";
|
||||
|
||||
KConfig config(file1, KConfig::SimpleConfig);
|
||||
ps->write(&config);
|
||||
|
||||
// check type
|
||||
QCOMPARE(config.group("").readEntry("Type", QString()), QString("Plasmoid"));
|
||||
|
||||
// check groups
|
||||
QStringList groups;
|
||||
groups << "images" << "theme" << "config" << "data" << "defaultconfig" << "scripts"
|
||||
<< "mainconfigui" << "mainconfigxml" << "mainscript"
|
||||
<< "translations" << "ui";
|
||||
groups.sort();
|
||||
|
||||
QStringList actualGroups = config.groupList();
|
||||
actualGroups.sort();
|
||||
//kDebug() << actualGroups;
|
||||
QCOMPARE(actualGroups, groups);
|
||||
|
||||
// check scripts
|
||||
KConfigGroup scripts = config.group("scripts");
|
||||
QCOMPARE(scripts.readEntry("Path", QString()), QString("code"));
|
||||
QCOMPARE(scripts.readEntry("Name", QString()), QString("Executable Scripts"));
|
||||
QCOMPARE(scripts.readEntry("Mimetypes", QStringList()), QStringList() << "text/plain");
|
||||
QCOMPARE(scripts.readEntry("Directory", false), true);
|
||||
QCOMPARE(scripts.readEntry("Required", false), false);
|
||||
}
|
||||
|
||||
QTEST_KDEMAIN(PackageStructureTest, NoGUI)
|
||||
|
||||
//#include "packagestructuretest.moc"
|
||||
|
|
@ -1,38 +0,0 @@
|
|||
Type=Plasmoid
|
||||
|
||||
[images]
|
||||
Path=images
|
||||
Name=Images
|
||||
Mimetypes=image/svg+xml,image/png,image/jpeg
|
||||
Directory=true
|
||||
|
||||
[config]
|
||||
Path=config/xml
|
||||
Name=Configuration Definitions
|
||||
Mimetypes=text/xml
|
||||
Directory=true
|
||||
|
||||
[configui]
|
||||
Path=config/ui
|
||||
Name=Configuration UI
|
||||
Mimetypes=text/xml
|
||||
Directory=true
|
||||
|
||||
[scripts]
|
||||
Path=code
|
||||
Name=Executable Scripts
|
||||
Mimetypes=text/*
|
||||
Directory=true
|
||||
|
||||
[mainconfiggui]
|
||||
Path=config/ui/main.ui
|
||||
Name=Main Config UI File
|
||||
|
||||
[mainconfigxml]
|
||||
Path=config/ui/main.xml
|
||||
Name=Configuration XML File
|
||||
|
||||
[mainscript]
|
||||
Path=code/main
|
||||
Name=Main Script File
|
||||
Required=true
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Reference in a new issue