Commit 32a97412 authored by Camilo Higuita's avatar Camilo Higuita

polishing compact mode, toolbars and moving android and kde code to mauikit...

polishing compact mode, toolbars and moving android and kde code to mauikit and using it fromt here better
parent 78b0a73b
#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 bool &light)
{
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());
if(light)
{
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();
}
QString Android::homePath()
{
QAndroidJniObject mediaDir = QAndroidJniObject::callStaticObjectMethod("android/os/Environment", "getExternalStorageDirectory", "()Ljava/io/File;");
QAndroidJniObject mediaPath = mediaDir.callObjectMethod( "getAbsolutePath", "()Ljava/lang/String;" );
return mediaPath.toString();
}
QStringList Android::defaultPaths()
{
QStringList paths;
paths.append(PATHS::HomePath);
paths.append(PATHS::DocumentsPath);
paths.append(PATHS::MusicPath);
paths.append(PATHS::VideosPath);
paths.append(PATHS::PicturesPath);
paths.append(PATHS::DownloadsPath);
return paths;
}
#ifndef ANDROID_H
#define ANDROID_H
#include <QObject>
#include <QString>
#include <QAndroidActivityResultReceiver>
#include <QObject>
#include <QAndroidJniObject>
#include <QAndroidJniEnvironment>
#include <QtAndroid>
#include <QStringList>
#include <QString>
class Android : public QObject
{
Q_OBJECT
public:
explicit Android(QObject *parent = nullptr);
Q_INVOKABLE void statusbarColor(const QString &bg, const bool &light);
Q_INVOKABLE void shareDialog(const QString &url);
Q_INVOKABLE static QStringList defaultPaths();
Q_INVOKABLE static QString homePath();
public slots:
};
namespace PATHS {
const QString HomePath = Android::homePath();
const QString PicturesPath = HomePath+"/"+QAndroidJniObject::getStaticObjectField("android/os/Environment", "DIRECTORY_PICTURES", "Ljava/lang/String;").toString();
const QString DownloadsPath = HomePath+"/"+QAndroidJniObject::getStaticObjectField("android/os/Environment", "DIRECTORY_DOWNLOADS", "Ljava/lang/String;").toString();
const QString DocumentsPath = HomePath+"/"+QAndroidJniObject::getStaticObjectField("android/os/Environment", "DIRECTORY_DOCUMENTS", "Ljava/lang/String;").toString();
const QString MusicPath = HomePath+"/"+QAndroidJniObject::getStaticObjectField("android/os/Environment", "DIRECTORY_MUSIC", "Ljava/lang/String;").toString();
const QString VideosPath = HomePath+"/"+QAndroidJniObject::getStaticObjectField("android/os/Environment", "DIRECTORY_MOVIES", "Ljava/lang/String;").toString();
}
#endif // ANDROID_H
QT += androidextras
RESOURCES += \
$$PWD/android.qrc \
$$PWD/../kirigami-icons.qrc \
......@@ -7,12 +5,6 @@ RESOURCES += \
ANDROID_PACKAGE_SOURCE_DIR = $$PWD
HEADERS += \
$$PWD/android.h
SOURCES += \
$$PWD/android.cpp
DISTFILES += \
$$PWD/AndroidManifest.xml \
$$PWD/gradle/wrapper/gradle-wrapper.jar \
......
......@@ -9,7 +9,6 @@ CONFIG += c++11
TARGET = index
DESTDIR = $$OUT_PWD/../
include($$PWD/../mauikit/mauikit.pri)
linux:unix:!android {
......@@ -28,6 +27,9 @@ linux:unix:!android {
message("Unknown configuration")
}
include($$PWD/../mauikit/mauikit.pri)
# The following define makes your compiler emit warnings if you use
# any feature of Qt which as been marked deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
......
......@@ -8,11 +8,8 @@
#include <QDebug>
#include "inx.h"
#if defined(Q_OS_ANDROID)
#include "../android/android.h"
#elif (defined (Q_OS_LINUX) && !defined (Q_OS_ANDROID))
#if (defined (Q_OS_LINUX) && !defined (Q_OS_ANDROID))
#include "../kde/notify.h"
#include "../kde/kdeconnect.h"
#include "../kde/kde.h"
#endif
......@@ -172,6 +169,9 @@ QVariantList Index::getBookmarks()
QVariantList Index::getCustomPaths()
{
#ifdef Q_OS_ANDROID
return QVariantList();
#endif
return QVariantList
{
QVariantMap
......@@ -372,40 +372,10 @@ bool Index::createFile(const QString &path, const QString &name)
return false;
}
QVariantList Index::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 Index::runApplication(const QString &exec, const QString &url)
{
#if (defined (Q_OS_LINUX) && !defined (Q_OS_ANDROID))
return url.isEmpty() ? KDE::launchApp(exec) : KDE::openWithApp(exec, url);
#endif
}
QVariantList Index::getKDEConnectDevices()
{
#if (defined (Q_OS_LINUX) && !defined (Q_OS_ANDROID))
return KdeConnect::getDevices();
#endif
}
bool Index::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 Index::attachToEmail(const QString &url)
{
#if (defined (Q_OS_LINUX) && !defined (Q_OS_ANDROID))
KDE::attachEmail(url);
return KDE::launchApp(exec);
#endif
}
......
......@@ -47,15 +47,8 @@ public:
Q_INVOKABLE static bool createFile(const QString &path, const QString &name);
/*KDE*/
Q_INVOKABLE static QVariantList openWith(const QString &url);
Q_INVOKABLE static void runApplication(const QString &exec, const QString &url);
Q_INVOKABLE static QVariantList getKDEConnectDevices();
Q_INVOKABLE static bool sendToDevice(const QString &name, const QString &id, const QString &url);
Q_INVOKABLE static void attachToEmail(const QString &url);
private:
QFileSystemWatcher *watcher;
......
......@@ -13,9 +13,8 @@
#include <QMimeType>
#include <QMimeData>
#include <QMimeDatabase>
#if defined(Q_OS_ANDROID)
#include "../android/android.h"
#include "../mauikit/src/android/mauiandroid.h"
#endif
namespace INX
......@@ -67,7 +66,7 @@ const QString DocumentsPath = PATHS::DocumentsPath;
const QString HomePath = PATHS::HomePath;
const QString MusicPath = PATHS::MusicPath;
const QString VideosPath = PATHS::VideosPath;
const QString DesktopPath = PATHS::HomePath;
const QStringList defaultPaths =
{
HomePath,
......@@ -86,7 +85,6 @@ const QMap<QString, QString> folderIcon
{HomePath, "user-home"},
{MusicPath, "folder-music"},
{VideosPath, "folder-videos"},
{DesktopPath, "user-desktop"}
};
......@@ -248,7 +246,6 @@ inline QVariant loadSettings(const QString &key, const QString &group, const QVa
return variant;
}
}
#endif // INX_H
......@@ -12,7 +12,6 @@
#ifdef Q_OS_ANDROID
#include <QGuiApplication>
#include <QIcon>
#include "../android/android.h"
#else
#include <QApplication>
#endif
......@@ -59,8 +58,6 @@ int main(int argc, char *argv[])
#ifdef Q_OS_ANDROID
QIcon::setThemeName("Luv");
Android android;
context->setContextProperty("android", &android);
#else
QStringList importPathList = engine.importPathList();
importPathList.prepend(QCoreApplication::applicationDirPath() + "/kde/qmltermwidget");
......
......@@ -30,6 +30,7 @@ Maui.ApplicationWindow
pageStack.separatorVisible: pageStack.wideMode
highlightColor: "#8682dd"
altColor: "#43455a"
altToolBars: false
headBar.middleContent: PathBar
{
......@@ -38,6 +39,55 @@ Maui.ApplicationWindow
width: headBar.width * (isMobile ? 0.6 : 0.8)
}
footBar.visible: pageStack.currentIndex !== 0 || pageStack.wideMode
footBar.leftContent: Maui.ToolButton
{
id: viewBtn
iconName: browser.detailsView ? "view-list-icons" : "view-list-details"
onClicked: browser.switchView()
}
footBar.middleContent: Row
{
spacing: space.medium
Maui.ToolButton
{
iconName: "go-previous"
onClicked: browser.goBack()
}
Maui.ToolButton
{
id: favIcon
iconName: "go-up"
onClicked: browser.goUp()
}
Maui.ToolButton
{
iconName: "go-next"
onClicked: browser.goNext()
}
}
footBar.rightContent: [
Maui.ToolButton
{
iconName: "documentinfo"
iconColor: browser.detailsDrawer.visible ? highlightColor : textColor
onClicked: browser.detailsDrawer.visible ? browser.detailsDrawer.close() :
browser.detailsDrawer.show(browser.currentPath)
},
Maui.ToolButton
{
iconName: "overflow-menu"
onClicked: browser.browserMenu.show()
}
]
PlacesSidebar
{
id: placesSidebar
......@@ -106,11 +156,9 @@ Maui.ApplicationWindow
onFinished: inx.createFile(browser.currentPath, text)
}
ShareDialog
Maui.ShareDialog
{
id: shareDialog
parent: browser
}
Component.onCompleted: if(isAndroid) android.statusbarColor(backgroundColor, true)
}
......@@ -8,7 +8,6 @@
<file>widgets/sidebar/PlacesSidebar.qml</file>
<file>widgets_templates/IndexDelegate.qml</file>
<file>widgets/views/Browser.qml</file>
<file>widgets/views/BrowserFooter.qml</file>
<file>widgets_templates/ItemMenu.qml</file>
<file>Index.js</file>
<file>widgets/views/PathBar.qml</file>
......
......@@ -105,11 +105,6 @@ Maui.Page
focus: true
headBarVisible: false
footer: BrowserFooter
{
id: browserFooter
}
contentItem : ColumnLayout
{
spacing: 0
......
import QtQuick 2.0
import QtQuick.Controls 2.2
import QtQuick.Layouts 1.3
import org.kde.maui 1.0 as Maui
Maui.ToolBar
{
position: ToolBar.Footer
leftContent: Maui.ToolButton
{
id: viewBtn
iconName: browser.detailsView ? "view-list-icons" : "view-list-details"
onClicked: browser.switchView()
}
middleContent: Row
{
spacing: space.medium
Maui.ToolButton
{
iconName: "go-previous"
onClicked: browser.goBack()
}
Maui.ToolButton
{
id: favIcon
iconName: "go-up"
onClicked: browser.goUp()
}
Maui.ToolButton
{
iconName: "go-next"
onClicked: browser.goNext()
}
}
rightContent: [
Maui.ToolButton
{
iconName: "documentinfo"
iconColor: detailsDrawer.visible ? highlightColor : textColor
onClicked: detailsDrawer.visible ? detailsDrawer.close() :
detailsDrawer.show(currentPath)
},
Maui.ToolButton
{
iconName: "overflow-menu"
onClicked: browserMenu.show()
}
]
}
......@@ -11,7 +11,7 @@ Drawer
edge: Qt.RightEdge
width: Kirigami.Units.gridUnit * 17
height: browserContainer.height
y: isMobile ? browser.headBar.height : headBar.height
y: root.headBar.height
// visible: opened ? pageStack.currentIndex = 1 && pageStack.wideMode : false
clip: true
property string currentUrl: ""
......@@ -130,7 +130,7 @@ Drawer
iconColor: altColorText
onClicked:
{
isAndroid ? android.shareDialog(currentUrl) :
isAndroid ? Maui.Android.shareDialog(currentUrl) :
shareDialog.show(currentUrl)
close()
}
......
......@@ -33,66 +33,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
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));
}
QVariantList KDE::getApps()
{
QVariantList res;
......@@ -186,10 +126,3 @@ void KDE::launchApp(const QString &app)
KService service(app);
KRun::runApplication(service,{}, nullptr);
}
//res << QVariantMap { {INX::MODEL_NAME[INX::MODEL_KEY::ICON], s->icon()},
//{INX::MODEL_NAME[INX::MODEL_KEY::LABEL], s->name()},
//{INX::MODEL_NAME[INX::MODEL_KEY::PATH], s->entryPath()}
......@@ -29,10 +29,7 @@ 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);
explicit KDE(QObject *parent = nullptr);
static QVariantList getApps();
static QVariantList getApps(const QString &groupStr);
static void launchApp(const QString &app);
......
......@@ -11,10 +11,8 @@ DISTFILES += \
HEADERS += \
$$PWD/kde.h \
$$PWD/kdeconnect.h \
$$PWD/notify.h
SOURCES += \
$$PWD/kde.cpp \
$$PWD/kdeconnect.cpp \
$$PWD/notify.cpp
/***
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
mauikit @ c8ba828a
Subproject commit c8ba828a5b7df80c90b18094bd736a0971071234
/home/camilo/Coding/qml/buho/mauikit
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment