Skip to content

Commit

Permalink
Applets on the desktop
Browse files Browse the repository at this point in the history
First applet is a weather applet
  • Loading branch information
kollix committed Nov 3, 2017
1 parent 312c971 commit c35458d
Show file tree
Hide file tree
Showing 15 changed files with 1,217 additions and 22 deletions.
11 changes: 8 additions & 3 deletions CMakeLists.txt
Expand Up @@ -15,7 +15,7 @@ find_package(Qt5 CONFIG REQUIRED COMPONENTS
)

find_package(KF5 REQUIRED COMPONENTS
WindowSystem WidgetsAddons ConfigWidgets Config KIO IconThemes ItemViews
WindowSystem WidgetsAddons ConfigWidgets Config KIO IconThemes ItemViews Archive
Notifications I18n NetworkManagerQt Service Solid BluezQt KCMUtils Crash DBusAddons
)

Expand All @@ -32,7 +32,7 @@ set(SOURCES
PagerButton.cxx
WindowList.cxx
ClockWidget.cxx
ConfigureClockWidgetDialog.cxx
ClockWidgetConfigureDialog.cxx
TaskBar.cxx
TaskBarButton.cxx
LockLogout.cxx
Expand All @@ -49,9 +49,13 @@ set(SOURCES
DeviceList.cxx
Battery.cxx
Bluetooth.cxx

DesktopApplet.cxx
WeatherApplet.cxx
WeatherAppletConfigureDialog.cxx
)

ki18n_wrap_ui(UI_FILES ConfigureDesktopDialog.ui)
ki18n_wrap_ui(UI_FILES ConfigureDesktopDialog.ui WeatherAppletConfigureDialog.ui)

set(statusnotifieritem_xml ${KNOTIFICATIONS_DBUS_INTERFACES_DIR}/kf5_org.kde.StatusNotifierItem.xml)
set_source_files_properties(${statusnotifieritem_xml} PROPERTIES
Expand Down Expand Up @@ -90,6 +94,7 @@ target_link_libraries(${TARGET}
KF5::Crash
KF5::DBusAddons
KF5::ItemViews
KF5::Archive
)

install(TARGETS ${TARGET} ${INSTALL_TARGETS_DEFAULT_ARGS})
Expand Down
4 changes: 2 additions & 2 deletions ClockWidget.cxx
Expand Up @@ -18,7 +18,7 @@
*/

#include <ClockWidget.hxx>
#include <ConfigureClockWidgetDialog.hxx>
#include <ClockWidgetConfigureDialog.hxx>

#include <QVBoxLayout>
#include <QHBoxLayout>
Expand Down Expand Up @@ -112,7 +112,7 @@ ClockWidget::ClockWidget(DesktopPanel *parent)
connect(action, &QAction::triggered,
[this]()
{
ConfigureClockWidgetDialog dialog(parentWidget(), timeZoneIds);
ClockWidgetConfigureDialog dialog(parentWidget(), timeZoneIds);
dialog.setWindowTitle(i18n("Select Timezones"));
dialog.resize(600, 400);
if ( dialog.exec() == QDialog::Accepted )
Expand Down
Expand Up @@ -17,7 +17,7 @@
along with liquidshell. If not, see <http://www.gnu.org/licenses/>.
*/

#include <ConfigureClockWidgetDialog.hxx>
#include <ClockWidgetConfigureDialog.hxx>

#include <QTreeWidget>
#include <QDialogButtonBox>
Expand All @@ -32,7 +32,7 @@

//--------------------------------------------------------------------------------

ConfigureClockWidgetDialog::ConfigureClockWidgetDialog(QWidget *parent, const QVector<QByteArray> &timeZoneIds)
ClockWidgetConfigureDialog::ClockWidgetConfigureDialog(QWidget *parent, const QVector<QByteArray> &timeZoneIds)
: QDialog(parent)
{
tree = new QTreeWidget;
Expand Down Expand Up @@ -84,7 +84,7 @@ ConfigureClockWidgetDialog::ConfigureClockWidgetDialog(QWidget *parent, const QV

//--------------------------------------------------------------------------------

QVector<QByteArray> ConfigureClockWidgetDialog::getSelectedTimeZoneIds() const
QVector<QByteArray> ClockWidgetConfigureDialog::getSelectedTimeZoneIds() const
{
QVector<QByteArray> timeZoneIds;

Expand Down
Expand Up @@ -17,23 +17,21 @@
along with liquidshell. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef _ConfigureClockWidgetDialog_H_
#define _ConfigureClockWidgetDialog_H_
#ifndef _ClockWidgetConfigureDialog_H_
#define _ClockWidgetConfigureDialog_H_

#include <QDialog>
class QTreeWidget;

class ConfigureClockWidgetDialog : public QDialog
class ClockWidgetConfigureDialog : public QDialog
{
Q_OBJECT

public:
ConfigureClockWidgetDialog(QWidget *parent, const QVector<QByteArray> &timeZoneIds);
ClockWidgetConfigureDialog(QWidget *parent, const QVector<QByteArray> &timeZoneIds);

QVector<QByteArray> getSelectedTimeZoneIds() const;

private slots:

private:
QTreeWidget *tree;
};
Expand Down
136 changes: 136 additions & 0 deletions DesktopApplet.cxx
@@ -0,0 +1,136 @@
/*
Copyright 2017 Martin Koller, kollix@aon.at
This file is part of liquidshell.
liquidshell 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 3 of the License, or
(at your option) any later version.
liquidshell 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 liquidshell. If not, see <http://www.gnu.org/licenses/>.
*/

#include <DesktopApplet.hxx>

#include <QAction>
#include <QIcon>
#include <QAbstractButton>
#include <QMessageBox>
#include <QDebug>

#include <KLocalizedString>
#include <KConfig>
#include <KConfigGroup>

//--------------------------------------------------------------------------------

DesktopApplet::DesktopApplet(QWidget *parent, const QString &theId)
: QFrame(parent), id(theId)
{
setFrameShape(QFrame::StyledPanel);
setContextMenuPolicy(Qt::ActionsContextMenu);

QAction *action = new QAction(this);
action->setIcon(QIcon::fromTheme("preferences-system-windows-move"));
action->setText(i18n("Change Size && Position"));
addAction(action);
connect(action, &QAction::triggered, this, &DesktopApplet::startGeometryChange);

action = new QAction(this);
action->setIcon(QIcon::fromTheme("window-close"));
action->setText(i18n("Remove this Applet"));
addAction(action);
connect(action, &QAction::triggered, this, &DesktopApplet::removeThisApplet);

buttons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this);
buttons->adjustSize();
buttons->hide();
connect(buttons, &QDialogButtonBox::clicked, this, &DesktopApplet::finishGeometryChange);
}

//--------------------------------------------------------------------------------

void DesktopApplet::loadConfig()
{
KConfig config;
KConfigGroup group = config.group(id);
setGeometry(group.readEntry("rect", QRect(30, 30, 600, 400)));
onDesktop = group.readEntry("onDesktop", int(NET::OnAllDesktops));
}

//--------------------------------------------------------------------------------

void DesktopApplet::saveConfig()
{
KConfig config;
KConfigGroup group = config.group(id);
group.writeEntry("rect", geometry());
group.writeEntry("onDesktop", onDesktop);
}

//--------------------------------------------------------------------------------

void DesktopApplet::startGeometryChange()
{
buttons->raise();
buttons->show();

oldRect = geometry();
setWindowFlags(Qt::Window);
setWindowTitle(i18n("%1: Change Size & Position").arg(id));

if ( onDesktop == NET::OnAllDesktops )
KWindowSystem::setOnAllDesktops(winId(), true);

show();
setGeometry(oldRect);
}

//--------------------------------------------------------------------------------

void DesktopApplet::finishGeometryChange(QAbstractButton *clicked)
{
KWindowInfo info(winId(), NET::WMDesktop);
if ( info.valid() )
onDesktop = info.desktop();

buttons->hide();
QRect rect = geometry();
setWindowFlags(Qt::Widget);
show();

if ( buttons->buttonRole(clicked) == QDialogButtonBox::AcceptRole )
{
setGeometry(rect);
KConfig config;
KConfigGroup group = config.group(id);
group.writeEntry("rect", rect);
group.writeEntry("onDesktop", onDesktop);
}
else
{
setGeometry(oldRect);
}
}

//--------------------------------------------------------------------------------

void DesktopApplet::removeThisApplet()
{
if ( QMessageBox::question(this, i18n("Remove Applet"),
i18n("Really remove this applet?")) == QMessageBox::Yes )
{
KConfig config;
config.deleteGroup(id);
emit removeThis(this);
}
}

//--------------------------------------------------------------------------------
60 changes: 60 additions & 0 deletions DesktopApplet.hxx
@@ -0,0 +1,60 @@
/*
Copyright 2017 Martin Koller, kollix@aon.at
This file is part of liquidshell.
liquidshell 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 3 of the License, or
(at your option) any later version.
liquidshell 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 liquidshell. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef _DesktopApplet_H_
#define _DesktopApplet_H_

#include <QFrame>
#include <QDialogButtonBox>
#include <KWindowSystem>

class DesktopApplet : public QFrame
{
Q_OBJECT

public:
DesktopApplet(QWidget *parent, const QString &theId);

virtual void loadConfig();
virtual void saveConfig();

bool isConfiguring() const { return buttons->isVisible(); }

const QString &getId() const { return id; }
int isOnDesktop(int d) const { return (onDesktop == NET::OnAllDesktops) || (onDesktop == d); }

signals:
void geometryChanged();
void removeThis(DesktopApplet *);

protected:
QString id;

private slots:
void startGeometryChange();
void finishGeometryChange(QAbstractButton *clicked);
void removeThisApplet();

private:
QDialogButtonBox *buttons = nullptr;
QRect oldRect;
int onDesktop = NET::OnAllDesktops;
};

#endif

0 comments on commit c35458d

Please sign in to comment.