Skip to content
This repository was archived by the owner on Dec 25, 2023. It is now read-only.

Commit 4733da4

Browse files
author
Alexis López Zubieta
committed
Initial port of the notifications plasma applet from plasma-workspace 5.33
0 parents  commit 4733da4

31 files changed

+3513
-0
lines changed

Diff for: .gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
CMakeLists.txt.user

Diff for: CMakeLists.txt

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
project(nomad-notifitacions-applet)
2+
3+
set(PROJECT_VERSION "1.0")
4+
set(PROJECT_VERSION_MAJOR 1)
5+
6+
cmake_minimum_required(VERSION 2.8.12 FATAL_ERROR)
7+
8+
find_package(ECM 1.8.0 REQUIRED NO_MODULE)
9+
set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH} ${ECM_KDE_MODULE_DIR})
10+
11+
include(KDEInstallDirs)
12+
include(KDECMakeSettings)
13+
include(KDECompilerSettings NO_POLICY_SCOPE)
14+
15+
include(ECMPackageConfigHelpers)
16+
include(ECMOptionalAddSubdirectory)
17+
include(FeatureSummary)
18+
19+
find_package(Qt5 ${QT_MIN_VERSION} CONFIG REQUIRED COMPONENTS
20+
Core
21+
Qml
22+
Quick
23+
)
24+
25+
26+
find_package(KF5 REQUIRED
27+
I18n Plasma WindowSystem KIO)
28+
29+
30+
31+
add_subdirectory(lib)
32+
add_subdirectory(plugin)
33+
34+
plasma_install_package(package org.nomad.notifications)
35+
36+
file(GLOB_RECURSE APPLET_SRCS package/*)
37+
add_custom_target(AppletFiles ALL echo SOURCES ${APPLET_SRCS})

Diff for: INSTALL

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# (0) Minimum Requirements (tested, but might be lower)
2+
- Qt >= 5.7.0
3+
- KDE Workspace >= 5.8.0
4+
- Plasma Framework >= 5.32
5+
6+
# (1) Standard way: having root permission
7+
cd /path/to/src-dir/
8+
mkdir build
9+
cd build
10+
cmake -DCMAKE_INSTALL_PREFIX=`kde4-config --prefix` -DCMAKE_BUILD_TYPE=Release -DLIB_INSTALL_DIR=lib -DKDE_INSTALL_USE_QT_SYS_PATHS=ON ../
11+
make
12+
make install
13+
14+
# (2) Alternative way: having non-root permission
15+
cd /path/to/src-dir/
16+
mkdir build
17+
cd build
18+
cmake -DCMAKE_INSTALL_PREFIX=`kde4-config --localprefix` -DCMAKE_BUILD_TYPE=Release -DLIB_INSTALL_DIR=lib -DKDE_INSTALL_USE_QT_SYS_PATHS=ON ../
19+
make
20+
make install

Diff for: lib/CMakeLists.txt

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
set(notificationsapplet_SRCS
2+
notificationsapplet.cpp
3+
)
4+
5+
add_library(nomad_applet_notifications MODULE ${notificationsapplet_SRCS})
6+
7+
kcoreaddons_desktop_to_json(nomad_applet_notifications ../package/metadata.desktop)
8+
9+
target_link_libraries(nomad_applet_notifications
10+
KF5::WindowSystem
11+
KF5::Plasma
12+
KF5::ConfigCore)
13+
14+
install(TARGETS nomad_applet_notifications DESTINATION ${PLUGIN_INSTALL_DIR}/plasma/applets)

Diff for: lib/notificationsapplet.cpp

+131
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
/*
2+
* Copyright 2014 (c) Martin Klapetek <[email protected]>
3+
*
4+
* This program is free software; you can redistribute it and/or
5+
* modify it under the terms of the GNU General Public License as
6+
* published by the Free Software Foundation; either version 2 of
7+
* the License or (at your option) version 3 or any later version
8+
* accepted by the membership of KDE e.V. (or its successor approved
9+
* by the membership of KDE e.V.), which shall act as a proxy
10+
* defined in Section 14 of version 3 of the license.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
19+
*
20+
*/
21+
22+
#include "notificationsapplet.h"
23+
24+
#include <KConfigGroup>
25+
#include <KWindowSystem>
26+
27+
#include <Plasma/Containment>
28+
#include <Plasma/Corona>
29+
30+
#include <QDebug>
31+
32+
NotificationsApplet::NotificationsApplet(QObject *parent, const QVariantList &data)
33+
: Plasma::Applet(parent, data),
34+
m_availableScreenRect(0,0,0,0)
35+
{
36+
}
37+
38+
NotificationsApplet::~NotificationsApplet()
39+
{
40+
}
41+
42+
void NotificationsApplet::init()
43+
{
44+
m_popupPosition = (NotificationsHelper::PositionOnScreen)configScreenPosition();
45+
46+
connect(this, &Plasma::Applet::locationChanged,
47+
this, &NotificationsApplet::onAppletLocationChanged);
48+
49+
connect(containment(), &Plasma::Containment::screenChanged,
50+
this, &NotificationsApplet::onScreenChanges);
51+
52+
Q_ASSERT(containment());
53+
Q_ASSERT(containment()->corona());
54+
connect(containment()->corona(), &Plasma::Corona::availableScreenRectChanged, this, &NotificationsApplet::onScreenChanges);
55+
56+
Plasma::Applet::init();
57+
58+
onScreenChanges();
59+
onAppletLocationChanged();
60+
}
61+
62+
void NotificationsApplet::onScreenChanges()
63+
{
64+
m_availableScreenRect = containment()->corona()->availableScreenRect(containment()->screen());
65+
Q_EMIT availableScreenRectChanged(m_availableScreenRect);
66+
}
67+
68+
QRect NotificationsApplet::availableScreenRect() const
69+
{
70+
return m_availableScreenRect;
71+
}
72+
73+
void NotificationsApplet::onAppletLocationChanged()
74+
{
75+
if (configScreenPosition() == 0) {
76+
// If the screenPosition is set to default,
77+
// just follow the panel
78+
setScreenPositionFromAppletLocation();
79+
}
80+
}
81+
82+
uint NotificationsApplet::screenPosition() const
83+
{
84+
return m_popupPosition;
85+
}
86+
87+
void NotificationsApplet::onScreenPositionChanged(uint position)
88+
{
89+
KConfigGroup globalGroup = globalConfig();
90+
globalGroup.writeEntry("popupPosition", position);
91+
globalGroup.sync();
92+
93+
// If the position is set to default, let the setScreenPositionFromAppletLocation()
94+
// figure out the effective position, otherwise just set it to m_popupPosition
95+
// and emit the change
96+
if (position == NotificationsHelper::Default) {
97+
setScreenPositionFromAppletLocation();
98+
} else {
99+
m_popupPosition = (NotificationsHelper::PositionOnScreen)position;
100+
Q_EMIT screenPositionChanged(m_popupPosition);
101+
}
102+
}
103+
104+
uint NotificationsApplet::configScreenPosition() const
105+
{
106+
KConfigGroup globalGroup = globalConfig();
107+
return globalGroup.readEntry("popupPosition", 0); //0 is default
108+
}
109+
110+
void NotificationsApplet::setScreenPositionFromAppletLocation()
111+
{
112+
if (location() == Plasma::Types::TopEdge) {
113+
if (QGuiApplication::isRightToLeft()) {
114+
m_popupPosition = NotificationsHelper::TopLeft;
115+
} else {
116+
m_popupPosition = NotificationsHelper::TopRight;
117+
}
118+
} else {
119+
if (QGuiApplication::isRightToLeft()) {
120+
m_popupPosition = NotificationsHelper::BottomLeft;
121+
} else {
122+
m_popupPosition = NotificationsHelper::BottomRight;
123+
}
124+
}
125+
126+
Q_EMIT screenPositionChanged(m_popupPosition);
127+
}
128+
129+
K_EXPORT_PLASMA_APPLET_WITH_JSON(notifications, NotificationsApplet, "metadata.json")
130+
131+
#include "notificationsapplet.moc"

Diff for: lib/notificationsapplet.h

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
* Copyright 2014 (c) Martin Klapetek <[email protected]>
3+
*
4+
* This program is free software; you can redistribute it and/or
5+
* modify it under the terms of the GNU General Public License as
6+
* published by the Free Software Foundation; either version 2 of
7+
* the License or (at your option) version 3 or any later version
8+
* accepted by the membership of KDE e.V. (or its successor approved
9+
* by the membership of KDE e.V.), which shall act as a proxy
10+
* defined in Section 14 of version 3 of the license.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
19+
*
20+
*/
21+
22+
#ifndef NOTIFICATIONS_APPLET_H
23+
#define NOTIFICATIONS_APPLET_H
24+
25+
#include <Plasma/Applet>
26+
27+
#include "../plugin/notificationshelper.h"
28+
29+
class NotificationsApplet : public Plasma::Applet
30+
{
31+
Q_OBJECT
32+
Q_PROPERTY(uint screenPosition READ screenPosition WRITE onScreenPositionChanged NOTIFY screenPositionChanged)
33+
Q_PROPERTY(QRect availableScreenRect READ availableScreenRect NOTIFY availableScreenRectChanged)
34+
35+
public:
36+
NotificationsApplet(QObject *parent, const QVariantList &data);
37+
~NotificationsApplet() override;
38+
39+
uint screenPosition() const;
40+
41+
// This is the screen position that is stored
42+
// in the config file, used to initialize the
43+
// applet settings dialog
44+
Q_INVOKABLE uint configScreenPosition() const;
45+
46+
QRect availableScreenRect() const;
47+
48+
public Q_SLOTS:
49+
void init() Q_DECL_OVERRIDE;
50+
void onScreenPositionChanged(uint position);
51+
void onAppletLocationChanged();
52+
53+
Q_SIGNALS:
54+
void screenPositionChanged(uint position);
55+
void availableScreenRectChanged(const QRect &availableScreenRect);
56+
57+
private:
58+
void setScreenPositionFromAppletLocation();
59+
void onScreenChanges();
60+
61+
NotificationsHelper::PositionOnScreen m_popupPosition;
62+
QRect m_availableScreenRect;
63+
};
64+
65+
66+
#endif // NOTIFICATIONS_APPLET

Diff for: package/Messages.sh

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#! /usr/bin/env bash
2+
$EXTRACTRC `find . -name \*.rc -o -name \*.ui -o -name \*.kcfg` >> rc.cpp
3+
$XGETTEXT `find . -name \*.qml` -L Java -o $podir/plasma_applet_org.nomad.notifications.pot
4+
$XGETTEXT rc.cpp -jo $podir/plasma_applet_org.nomad.notifications.pot
5+
rm -f rc.cpp

Diff for: package/contents/code/uiproperties.js

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Copyright 2012 Marco Martin <[email protected]>
3+
*
4+
* This program is free software; you can redistribute it and/or modify
5+
* it under the terms of the GNU Library General Public License as
6+
* published by the Free Software Foundation; either version 2, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU Library General Public License for more details
13+
*
14+
* You should have received a copy of the GNU Library General Public
15+
* License along with this program; if not, write to the
16+
* Free Software Foundation, Inc.,
17+
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18+
*/
19+
20+
21+
var toolIconSize = units.iconSizes.smallMedium
22+
var layoutSpacing = 4
23+
var touchInput = false

Diff for: package/contents/config/config.qml

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Copyright 2014 Kai Uwe Broulik <[email protected]>
3+
*
4+
* This program is free software; you can redistribute it and/or
5+
* modify it under the terms of the GNU General Public License as
6+
* published by the Free Software Foundation; either version 2 of
7+
* the License or (at your option) version 3 or any later version
8+
* accepted by the membership of KDE e.V. (or its successor approved
9+
* by the membership of KDE e.V.), which shall act as a proxy
10+
* defined in Section 14 of version 3 of the license.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* along with this program. If not, see <http://www.gnu.org/licenses/>
19+
*/
20+
21+
import QtQuick 2.0
22+
23+
import org.kde.plasma.configuration 2.0
24+
25+
ConfigModel {
26+
ConfigCategory {
27+
name: i18n("Information")
28+
icon: "preferences-desktop-notification"
29+
source: "configNotifications.qml"
30+
}
31+
}

Diff for: package/contents/config/main.xml

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<kcfg xmlns="http://www.kde.org/standards/kcfg/1.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://www.kde.org/standards/kcfg/1.0
5+
http://www.kde.org/standards/kcfg/1.0/kcfg.xsd" >
6+
<kcfgfile name=""/>
7+
8+
<group name="General">
9+
<entry name="showNotifications" type="Bool">
10+
<label>Show the notifications</label>
11+
<default>true</default>
12+
</entry>
13+
<entry name="showJobs" type="Bool">
14+
<label>Show the jobs progress</label>
15+
<default>true</default>
16+
</entry>
17+
</group>
18+
19+
</kcfg>

0 commit comments

Comments
 (0)