Commit 8bd14a83 authored by Camilo Higuita's avatar Camilo Higuita

intial move to Maui.Page

parent a4369bbd
......@@ -7,12 +7,6 @@ RESOURCES += \
$$PWD/android.qrc \
$$PWD/../kirigami-icons.qrc
HEADERS += \
$$PWD/android.h
SOURCES += \
$$PWD/android.cpp \
RESOURCES += \
$$PWD/../icons.qrc
......
#include "android.h"
#include <QException>
#include <QColor>
#include <QDebug>
class InterfaceConnFailedException : public QException
{
public:
void raise() const { throw *this; }
InterfaceConnFailedException *clone() const { return new InterfaceConnFailedException(*this); }
};
Android::Android(QObject *parent) : QObject(parent)
{
}
void Android::statusbarColor(const QString &bg, const QString &fg)
{
QtAndroid::runOnAndroidThread([=]() {
QAndroidJniObject window = QtAndroid::androidActivity().callObjectMethod("getWindow", "()Landroid/view/Window;");
window.callMethod<void>("addFlags", "(I)V", 0x80000000);
window.callMethod<void>("clearFlags", "(I)V", 0x04000000);
window.callMethod<void>("setStatusBarColor", "(I)V", QColor(bg).rgba());
QAndroidJniObject decorView = window.callObjectMethod("getDecorView", "()Landroid/view/View;");
decorView.callMethod<void>("setSystemUiVisibility", "(I)V", 0x00002000);
});
}
void Android::shareDialog(const QString &url)
{
qDebug()<< "trying to share dialog";
QAndroidJniEnvironment _env;
QAndroidJniObject activity = QAndroidJniObject::callStaticObjectMethod("org/qtproject/qt5/android/QtNative", "activity", "()Landroid/app/Activity;"); //activity is valid
if (_env->ExceptionCheck()) {
_env->ExceptionClear();
throw InterfaceConnFailedException();
}
if ( activity.isValid() )
{
QAndroidJniObject::callStaticMethod<void>("com/example/android/tools/SendIntent",
"sendPic",
"(Landroid/app/Activity;Ljava/lang/String;)V",
activity.object<jobject>(),
QAndroidJniObject::fromString(url).object<jstring>());
if (_env->ExceptionCheck()) {
_env->ExceptionClear();
throw InterfaceConnFailedException();
}
}else
throw InterfaceConnFailedException();
}
#ifndef ANDROID_H
#define ANDROID_H
#include <QObject>
#include <QString>
#include <QAndroidActivityResultReceiver>
#include <QObject>
#include <QAndroidJniObject>
#include <QAndroidJniEnvironment>
#include <QtAndroid>
class Android : public QObject
{
Q_OBJECT
public:
explicit Android(QObject *parent = nullptr);
Q_INVOKABLE void statusbarColor(const QString &bg, const QString &fg);
Q_INVOKABLE void shareDialog(const QString &url);
signals:
public slots:
};
#endif // ANDROID_H
QT += KService KNotifications KNotifications KI18n
QT += KIOCore KIOFileWidgets KIOWidgets KNTLM
HEADERS += \
$$PWD/kde.h \
$$PWD/notify.h \
$$PWD/kdeconnect.h
SOURCES += \
$$PWD/kde.cpp \
$$PWD/notify.cpp \
$$PWD/kdeconnect.cpp
desktop.files += $$PWD/../org.kde.pix.desktop
desktop.path += /usr/share/applications
INSTALLS += desktop
/***
Pix Copyright (C) 2018 Camilo Higuita
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
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 3 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, see <http://www.gnu.org/licenses/>.
***/
#include "kde.h"
#include <KService>
#include <KMimeTypeTrader>
#include <KToolInvocation>
#include <KLocalizedString>
#include <QDebug>
#include <KRun>
#include <QFileInfo>
KDE::KDE(QObject *parent) : QObject(parent)
{
}
static QVariantMap createActionItem(const QString &label, const QString &actionId, const QVariant &argument = QVariant())
{
QVariantMap map;
map["serviceLabel"] = label;
map["actionId"] = actionId;
if (argument.isValid())
map["actionArgument"] = argument;
return map;
}
QVariantList KDE::mimeApps(const QUrl &url)
{
qDebug()<<"trying to get mimes";
QVariantList list;
if (url.isValid())
{
auto fileItem = new KFileItem(url);
fileItem->determineMimeType();
KService::List services = KMimeTypeTrader::self()->query(fileItem->mimetype(), "Application");
if (!services.isEmpty())
foreach (const KService::Ptr service, services)
{
const QString text = service->name().replace('&', "&&");
QVariantMap item = createActionItem(text, "_kicker_fileItem_openWith", service->entryPath());
item["serviceIcon"] = service->icon();
item["serviceExec"] = service->exec();
list << item;
}
list << createActionItem(i18n("Properties"), "_kicker_fileItem_properties");
return list;
} else return list;
}
void KDE::openWithApp(const QString &exec, const QString &url)
{
KService service(exec);
KRun::runApplication(service,{url}, nullptr);
}
void KDE::attachEmail(const QString &url)
{
qDebug()<< "invoking email"<< url;
QFileInfo file(url);
KToolInvocation::invokeMailer("", "", "", file.baseName(), "Sent from Pix", "", {url});
// QDesktopServices::openUrl(QUrl("mailto:?subject=test&body=test&attachment;="
// + url));
}
/***
Pix Copyright (C) 2018 Camilo Higuita
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
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 3 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, see <http://www.gnu.org/licenses/>.
***/
#ifndef KDE_H
#define KDE_H
#include <QObject>
#include <QVariantList>
#include <KFileItem>
class KDE : public QObject
{
Q_OBJECT
public:
explicit KDE(QObject *parent = nullptr);
static QVariantList mimeApps(const QUrl &url);
static void openWithApp(const QString &exec, const QString &url);
static void attachEmail(const QString &url);
signals:
public slots:
};
#endif // KDE_H
/***
Pix Copyright (C) 2018 Camilo Higuita
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
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 3 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, see <http://www.gnu.org/licenses/>.
***/
#include "kdeconnect.h"
#include <QProcess>
KdeConnect::KdeConnect(QObject *parent) : QObject(parent)
{
}
QVariantList KdeConnect::getDevices()
{
QVariantList devices;
QProcess process;
process.start("kdeconnect-cli -a");
process.waitForFinished();
// auto output = process->readAllStandardOutput();
process.setReadChannel(QProcess::StandardOutput);
while (process.canReadLine())
{
QString line = QString::fromLocal8Bit(process.readLine());
if(line.contains("(paired and reachable)"))
{
QVariantMap _devices;
QStringList items = line.split(" ");
auto serviceKey = QString(items.at(2));
auto serviceLabel = QString(items.at(1)).replace(":","");
_devices.insert("serviceKey", serviceKey);
_devices.insert("serviceLabel", serviceLabel);
devices.append(_devices);
}
}
return devices;
}
bool KdeConnect::sendToDevice(const QString &device, const QString &id, const QString &url)
{
QString deviceName = device;
QString deviceKey = id;
auto process = new QProcess();
connect(process, static_cast<void(QProcess::*)(int, QProcess::ExitStatus)>(&QProcess::finished),
[=](int exitCode, QProcess::ExitStatus exitStatus)
{
// BabeWindow::nof->notify("Song sent to " + deviceName,title +" by "+ artist);
// process->deleteLater();
});
process->start("kdeconnect-cli -d " +deviceKey+ " --share " +"\""+ url+"\"");
return true;
}
/***
Pix Copyright (C) 2018 Camilo Higuita
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
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 3 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, see <http://www.gnu.org/licenses/>.
***/
#ifndef KDECONNECT_H
#define KDECONNECT_H
#include <QObject>
#include <QMap>
#include <QString>
#include <QVariantList>
class KdeConnect : public QObject
{
Q_OBJECT
public:
explicit KdeConnect(QObject *parent = nullptr);
static QVariantList getDevices();
static bool sendToDevice(const QString &device, const QString &id, const QString &url);
signals:
public slots:
};
#endif // KDECONNECT_H
/***
Pix Copyright (C) 2018 Camilo Higuita
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
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 3 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, see <http://www.gnu.org/licenses/>.
***/
#include "notify.h"
Notify::Notify(QObject *parent) : QObject(parent)
{}
Notify::~Notify()
{
qDebug()<<"DELETING KNOTIFY";
}
void Notify::notify(const QString &title, const QString &body)
{
// notification->setComponentName(QStringLiteral("Babe"));
auto notification = new KNotification(QStringLiteral("Notify"),KNotification::CloseOnTimeout, this);
connect(notification, &KNotification::closed, notification, &KNotification::deleteLater);
notification->setTitle(QStringLiteral("%1").arg(title));
notification->setText(QStringLiteral("%1").arg(body));
notification->sendEvent();
}
/***
Pix Copyright (C) 2018 Camilo Higuita
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
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 3 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, see <http://www.gnu.org/licenses/>.
***/
#ifndef NOTIFY_H
#define NOTIFY_H
#include <QObject>
#include <QByteArray>
#include <klocalizedstring.h>
#include <knotifyconfig.h>
#include <knotification.h>
#include <QStandardPaths>
#include <QPixmap>
#include <QDebug>
#include <QMap>
#include "../src/utils/pic.h"
class Notify : public QObject
{
Q_OBJECT
public:
explicit Notify(QObject *parent = nullptr);
~Notify();
void notify(const QString &title, const QString &body);
private:
};
#endif // NOTIFY_H
......@@ -29,7 +29,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifdef Q_OS_ANDROID
#include <QGuiApplication>
#include <QIcon>
#include "android/android.h"
#else
#include <QApplication>
#endif
......@@ -120,7 +119,6 @@ int main(int argc, char *argv[])
#ifdef Q_OS_ANDROID
QIcon::setThemeName("Luv");
Android android;
context->setContextProperty("android", &android);
#endif
#ifdef MAUI_APP
......
......@@ -14,8 +14,6 @@ DESTDIR = $$OUT_PWD/../
linux:unix:!android {
message(Building for Linux KDE)
include(kde/KDE.pri)
} else:android {
message(Building helpers for Android)
......
......@@ -37,7 +37,6 @@ import "widgets/views/Viewer"
import "widgets/views/Search"
import "view_models"
import "widgets/dialogs/share"
import "widgets/dialogs/Albums"
import "widgets/dialogs/Tags"
......@@ -183,13 +182,13 @@ Maui.ApplicationWindow
id: picMenu
onFavClicked: VIEWER.fav(url)
onRemoveClicked: PIX.removePic(url)
onShareClicked: isAndroid ? android.shareDialog(url) : shareDialog.show(url)
onShareClicked: isAndroid ? Maui.Android.shareDialog(url) : shareDialog.show(url)
onAddClicked: albumsDialog.show(url)
onTagsClicked: tagsDialog.show(url)
onShowFolderClicked: pix.showInFolder(url)
}
ShareDialog
Maui.ShareDialog
{
id: shareDialog
}
......@@ -213,6 +212,4 @@ Maui.ApplicationWindow
onRefreshViews: PIX.refreshViews()
onViewPics: VIEWER.open(pics, 0)
}
Component.onCompleted: if(isAndroid) android.statusbarColor(backgroundColor, textColor)
}
......@@ -31,12 +31,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <QColor>
#include <QDesktopServices>
#if (defined (Q_OS_LINUX) && !defined (Q_OS_ANDROID))
#include "kde/notify.h"
#include "kde/kdeconnect.h"
#include "kde/kde.h"
#endif
using namespace PIX;
Pix::Pix(QObject *parent) : DBActions(parent)
......@@ -231,44 +225,6 @@ QVariantMap Pix::getParentDir(const QString &path)
}
QVariantList Pix::openWith(const QString &url)
{
#if (defined (Q_OS_LINUX) && !defined (Q_OS_ANDROID))
return KDE::mimeApps(url);
#elif defined (Q_OS_ANDROID)
return QVariantList();
#endif
}
void Pix::runApplication(const QString &exec, const QString &url)
{
qDebug()<<"RUN:"<<exec<<url;
#if (defined (Q_OS_LINUX) && !defined (Q_OS_ANDROID))
return KDE::openWithApp(exec, url);
#endif
}
QVariantList Pix::getDevices()
{
#if (defined (Q_OS_LINUX) && !defined (Q_OS_ANDROID))
return KdeConnect::getDevices();
#endif
}
bool Pix::sendToDevice(const QString &name, const QString &id, const QString &url)
{
#if (defined (Q_OS_LINUX) && !defined (Q_OS_ANDROID))
return KdeConnect::sendToDevice(name, id, url);
#endif
}
void Pix::attachToEmail(const QString &url)
{
#if (defined (Q_OS_LINUX) && !defined (Q_OS_ANDROID))
KDE::attachEmail(url);
#endif
}
bool Pix::removeFile(const QString &url)
{
QFile file(url);
......
......@@ -68,15 +68,6 @@ public:
Q_INVOKABLE static QVariantList getDirs(const QString &pathUrl);
Q_INVOKABLE static QVariantMap getParentDir(const QString &path);
/*KDE*/
Q_INVOKABLE static QVariantList openWith(const QString &url);
Q_INVOKABLE static void runApplication(const QString &exec, const QString &url);
Q_INVOKABLE static QVariantList getDevices();
Q_INVOKABLE static bool sendToDevice(const QString &name, const QString &id, const QString &url);
Q_INVOKABLE static void attachToEmail(const QString &url);
/*File actions*/
Q_INVOKABLE bool removeFile(const QString &url);
Q_INVOKABLE void showInFolder(const QString &url);
......
......@@ -10,8 +10,6 @@
<file>view_models/PixPic.qml</file>
<file>view_models/PixHolder.qml</file>
<file>db/Query.js</file>
<file>view_models/SideBar.qml</file>
<file>view_models/PixButton.qml</file>
<file>view_models/PixPage.qml</file>
<file>widgets/views/Folders/FoldersView.qml</file>
<file>widgets/views/Gallery/GalleryView.qml</file>
......@@ -26,9 +24,6 @@
<file>widgets/views/Viewer/Viewer.js</file>
<file>widgets/views/Folders/PicsView.qml</file>
<file>view_models/PixPopup.qml</file>
<file>widgets/dialogs/share/ShareDialog.qml</file>
<file>widgets/dialogs/share/ShareGrid.qml</file>
<file>widgets/dialogs/share/ShareDelegate.qml</file>
<file>widgets/views/Pix.js</file>
<file>widgets/PixFooter.qml</file>
<file>widgets/custom/TagBar/TagBar.qml</file>
......
import QtQuick 2.9
import QtQuick.Controls 2.2
import org.kde.kirigami 2.2 as Kirigami
import QtQuick.Controls.impl 2.3
ToolButton
{
id: babeButton
property bool isMask : true
property string iconName
property int size : iconSizes.medium
property color iconColor: textColor
readonly property string defaultColor : textColor
property bool anim : false
spacing: space.small
icon.name: iconName
icon.width: size
icon.height: size
icon.color: !isMask ? "transparent" : (down ? highlightColor : (iconColor || defaultColor))
display: isWide ? AbstractButton.TextBesideIcon : AbstractButton.IconOnly
onClicked: if(anim) animIcon.running = true
flat: true
highlighted: false
contentItem: IconLabel
{
spacing: babeButton.spacing
mirrored: babeButton.mirrored
display: babeButton.display
icon: babeButton.icon
text: babeButton.text
font: babeButton.font
color: iconColor
}
SequentialAnimation
{
id: animIcon
PropertyAnimation
{
target: babeButton
property: "icon.color"
easing.type: Easing.InOutQuad
from: highlightColor
to: iconColor
duration: 500
}
}
}
......@@ -3,8 +3,9 @@ import QtQuick.Layouts 1.3
import QtQuick 2.9
import "../widgets/views/Viewer/Viewer.js" as VIEWER
import org.kde.kirigami 2.0 as Kirigami
import org.kde.maui 1.0 as Maui
PixPage
Maui.Page
{
id: gridPage
......@@ -69,18 +70,16 @@ PixPage
}
}
headerbarTitle: gridModel.count+" "+qsTr("images")
headBarTitle: gridModel.count+" "+qsTr("images")
headerBarRight: [
PixButton
{
id: menuBtn
iconName: "overflow-menu"
onClicked: isMobile? gridMenu.open() : gridMenu.popup()
}
]
headBar.rightContent: Maui.ToolButton
{
id: menuBtn
iconName: "overflow-menu"
onClicked: isMobile? gridMenu.open() : gridMenu.popup()
}
content: GridView
contentData: GridView
{
id: grid
width: parent.width
......@@ -88,9 +87,6 @@ PixPage
clip: true
Layout.fillWidth: true
Layout.fillHeight: true
cellWidth: itemSize + itemSpacing
cellHeight: itemSize + itemSpacing
......
......@@ -2,6 +2,7 @@ import QtQuick 2.9
import QtQuick.Controls 2.2
import QtQuick.Layouts 1.3
import org.kde.kirigami 2.2 as Kirigami
import org.kde.maui 1.0 as Maui
Page
{
......@@ -41,7 +42,7 @@ Page
id: headerbarLayout
anchors.fill: parent
PixButton
Maui.ToolButton
{
id: exitBtn
Layout.alignment : Qt.AlignLeft
......
......@@ -2,6 +2,7 @@ import QtQuick 2.9
import QtQuick.Controls 2.2
import QtQuick.Layouts 1.3
import QtGraphicalEffects 1.0
import org.kde.maui 1.0 as Maui
ItemDelegate
{
......@@ -45,7 +46,7 @@ ItemDelegate
}
}
PixButton
Maui.ToolButton
{
id: emblem