Skip to content

Commit

Permalink
Merge pull request #105 from neochapay/devel
Browse files Browse the repository at this point in the history
[Lipstick] Create screenshot service. Fixes #85
  • Loading branch information
locusf committed Jan 14, 2020
2 parents 4f4cc7c + 1b15171 commit 71becd5
Show file tree
Hide file tree
Showing 8 changed files with 201 additions and 6 deletions.
2 changes: 2 additions & 0 deletions glacier-home.pro
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,14 @@ CONFIG += qt link_pkgconfig
QT += quick compositor dbus
DEFINES += QT_COMPOSITOR_QUICK
HEADERS += \
src/fileutils.h \
src/glacierwindowmodel.h

LIBS += -lnemodevicelock
MOC_DIR = .moc

SOURCES += \
src/fileutils.cpp \
src/main.cpp \
src/glacierwindowmodel.cpp

Expand Down
1 change: 1 addition & 0 deletions rpm/lipstick-glacier-home-qt5.spec
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Requires: qt5-qtquickcontrols-nemo >= 5.1.1
Requires: nemo-qml-plugin-contextkit-qt5
Requires: connman-qt5
Requires: libqofono-qt5-declarative
Requires: libngf-qt5-declarative
Requires: nemo-theme-glacier
Requires: google-opensans-fonts
Requires: mpris-qt5-qml-plugin
Expand Down
47 changes: 47 additions & 0 deletions src/fileutils.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// This file is part of glacier-home, a nice user experience for NemoMobile.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
// Copyright (c) 2020, Chupligin Sergey <neochapay@gmail.com>

#include "fileutils.h"

#include <QStandardPaths>
#include <QDir>
#include <QDateTime>

FileUtils::FileUtils(QObject *parent) : QObject(parent)
{

}

QString FileUtils::getScreenshotPath()
{
QString screenshotDir = QStandardPaths::writableLocation(QStandardPaths::PicturesLocation)+"/Screenshots";

QDir scrDir;

if(!scrDir.exists(screenshotDir)) {
scrDir.mkpath(screenshotDir);
}

QString path = screenshotDir+"/"+tr("Screenshot")+"_"+QDateTime::currentDateTime().toString("ddMMyyyy-hhmmss")+".png";

return path;
}
16 changes: 16 additions & 0 deletions src/fileutils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#ifndef FILEUTILS_H
#define FILEUTILS_H

#include <QObject>

class FileUtils: public QObject
{
Q_OBJECT
public:
explicit FileUtils(QObject *parent = 0);

Q_INVOKABLE QString getScreenshotPath();

};

#endif // FILEUTILS_H
6 changes: 6 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include <lipstickqmlpath.h>

#include "glacierwindowmodel.h"
#include "fileutils.h"


int main(int argc, char **argv)
Expand All @@ -45,6 +46,9 @@ int main(int argc, char **argv)

QmlPath::append("/usr/share/lipstick-glacier-home-qt5/qml");
QGuiApplication::setFont(QFont("Open Sans"));

FileUtils *fileUtils = new FileUtils();

app.setCompositorPath("/usr/share/lipstick-glacier-home-qt5/qml/compositor.qml");
Qt::ScreenOrientation nativeOrientation = app.primaryScreen()->nativeOrientation();
QByteArray v = qgetenv("GLACIER_NATIVEORIENTATION");
Expand All @@ -69,6 +73,8 @@ int main(int argc, char **argv)
if (nativeOrientation == Qt::PrimaryOrientation)
nativeOrientation = app.primaryScreen()->primaryOrientation();
app.engine()->rootContext()->setContextProperty("nativeOrientation", nativeOrientation);
app.engine()->rootContext()->setContextProperty("fileUtils", fileUtils);

qmlRegisterType<GlacierWindowModel>("org.nemomobile.glacier", 1, 0 ,"GlacierWindowModel");
app.setQmlPath("/usr/share/lipstick-glacier-home-qt5/qml/MainScreen.qml");
// Give these to the environment inside the lipstick homescreen
Expand Down
9 changes: 9 additions & 0 deletions src/qml/MainScreen.qml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import "scripts/desktop.js" as Desktop
import "mainscreen"
import "dialogs"
import "volumecontrol"
import "system"

Page {
id: desktop
Expand Down Expand Up @@ -160,6 +161,10 @@ Page {
}
}

function makeScreenshot() {
screenshot.capture()
}

Pager {
id: pager
anchors.topMargin: statusbar.height
Expand Down Expand Up @@ -208,6 +213,10 @@ Page {
id: audioWarnigDialog
}

Screenshot{
id: screenshot
}

Connections{
target: feeds
onXChanged: {
Expand Down
80 changes: 80 additions & 0 deletions src/qml/system/Screenshot.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/****************************************************************************************
**
** Copyright (C) 2020 Chupligin Sergey <neochapay@gmail.com>
** All rights reserved.
**
** You may use this file under the terms of BSD license as follows:
**
** Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions are met:
** * Redistributions of source code must retain the above copyright
** notice, this list of conditions and the following disclaimer.
** * Redistributions in binary form must reproduce the above copyright
** notice, this list of conditions and the following disclaimer in the
** documentation and/or other materials provided with the distribution.
** * Neither the name of the author nor the
** names of its contributors may be used to endorse or promote products
** derived from this software without specific prior written permission.
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
** DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR
** ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
** (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
** ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
**
****************************************************************************************/

import QtQuick 2.6
import QtQuick.Controls 1.0
import QtQuick.Controls.Nemo 1.0
import QtQuick.Controls.Styles.Nemo 1.0

import org.nemomobile.lipstick 0.1
import org.nemomobile.notifications 1.0
import org.nemomobile.ngf 1.0

import org.nemomobile.glacier 1.0

Item {
id: screenShoter
property var filePath: "";

function capture() {
filePath = fileUtils.getScreenshotPath();

if(Lipstick.takeScreenshot(filePath)) {
captureNoize.play()
saveNotify.publish()

console.log("Capture:"+filePath)
}else{
console.log("Capture fail")
}
}

NonGraphicalFeedback {
id: captureNoize
event: "camera_shutter"
}

Notification{
id: saveNotify
category: qsTr("Desktop")
summary: qsTr("Screenshot saved")
body: ""
itemCount: 1
remoteActions: [ {
"name": "default",
"service": "org.nemomobile.gallery",
"path": "/org/nemomobile/gallery",
"iface": "org.nemomobile.gallery",
"method": "showDir",
"arguments": [filePath]
}]
}
}
46 changes: 40 additions & 6 deletions src/qml/volumecontrol/VolumeControl.qml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ Rectangle{
color: Theme.backgroundColor

property int pressedKey
property bool upPress
property bool downPress

visible: volumeControl.windowVisible

Expand Down Expand Up @@ -109,16 +111,34 @@ Rectangle{
volumeChange()
keyPressTimer.start()
maxMinTimer.start()
screenShotTimer.start()

if (volumeControl.windowVisible) {
voltimer.restart()
}

if(key == Qt.Key_VolumeUp) {
upPress = true;
}

if(key == Qt.Key_VolumeDown) {
downPress = true;
}
}

onVolumeKeyReleased: {
keyPressTimer.stop()
maxMinTimer.stop()
screenShotTimer.stop()
volumeControlWindow.pressedKey = ""

if(key == Qt.Key_VolumeUp) {
upPress = false;
}

if(key == Qt.Key_VolumeDown) {
downPress = false;
}
}

onWindowVisibleChanged: {
Expand All @@ -128,13 +148,25 @@ Rectangle{
}
}
}
Timer{
id: screenShotTimer
interval: 2000
onTriggered: {
if(upPress && downPress) {
volumeControlWindow.visible = false
Desktop.instance.makeScreenshot();
}
}
}

Timer{
id: keyPressTimer
interval: 500
onTriggered: {
volumeChange()
voltimer.restart()
if(!upPress || !downPress) {
volumeChange()
voltimer.restart()
}
}
repeat: true
}
Expand All @@ -143,10 +175,12 @@ Rectangle{
id: maxMinTimer
interval: 1900
onTriggered: {
if(volumeControlWindow.pressedKey == Qt.Key_VolumeUp) {
volumeControl.volume = volumeSlider.maximumValue
} else if(volumeControlWindow.pressedKey == Qt.Key_VolumeDown) {
volumeControl.volume = 0
if(!upPress || !downPress) {
if(volumeControlWindow.pressedKey == Qt.Key_VolumeUp) {
volumeControl.volume = volumeSlider.maximumValue
} else if(volumeControlWindow.pressedKey == Qt.Key_VolumeDown) {
volumeControl.volume = 0
}
}
}
}
Expand Down

0 comments on commit 71becd5

Please sign in to comment.