← Back to team overview

ubuntu-touch-coreapps-reviewers team mailing list archive

[Merge] lp:~verzegnassi-stefano/ubuntu-docviewer-app/desktop-support2 into lp:ubuntu-docviewer-app

 

Stefano Verzegnassi has proposed merging lp:~verzegnassi-stefano/ubuntu-docviewer-app/desktop-support2 into lp:ubuntu-docviewer-app.

Commit message:
Better desktop/pocket-desktop support, by detecting the number of mice and touchpads connected to the device. This uses QInputInfo, available in the Qt snapshots - imported version from unity 8 trunk (rev.2080).

WORKAROUND: This makes new BottomEdge component fully working on desktop

Requested reviews:
  Jenkins Bot (ubuntu-core-apps-jenkins-bot): continuous-integration
  Stefano Verzegnassi (verzegnassi-stefano)
  Nicholas Skaggs (nskaggs)

For more details, see:
https://code.launchpad.net/~verzegnassi-stefano/ubuntu-docviewer-app/desktop-support2/+merge/284901

Better desktop/pocket-desktop support, by detecting the number of mice and touchpads connected to the device. This uses QInputInfo, available in the Qt snapshots - imported version from unity 8 trunk (rev.2080).

WORKAROUND: This makes new BottomEdge component fully working on desktop
-- 
Your team Ubuntu Document Viewer Developers is subscribed to branch lp:ubuntu-docviewer-app.
=== modified file 'debian/control'
--- debian/control	2016-01-14 21:33:47 +0000
+++ debian/control	2016-02-03 13:44:53 +0000
@@ -17,7 +17,9 @@
                qtdeclarative5-qtquick2-plugin,
                qtdeclarative5-private-dev,
                qtbase5-private-dev,
-               qtdeclarative5-test-plugin
+               qtdeclarative5-test-plugin,
+               libudev-dev,
+               libevdev-dev,
 Standards-Version: 3.9.6
 Section: misc
 Homepage: https://launchpad.net/ubuntu-docviewer-app

=== modified file 'src/app/qml/common/ContentHubProxy.qml'
--- src/app/qml/common/ContentHubProxy.qml	2015-10-10 12:03:30 +0000
+++ src/app/qml/common/ContentHubProxy.qml	2016-02-03 13:44:53 +0000
@@ -53,11 +53,11 @@
                 for (var i=0; i<activeTransfer.items.length; i++) {
                     var sourcePath = internal.getPathFromUrl(activeTransfer.items[i].url)
 
-                    if (DocumentViewer.isFileSupported(sourcePath)) {
-                        var documentsLocation = DocumentViewer.getXdgDocumentsLocation()
+                    if (FileUtils.isFileSupported(sourcePath)) {
+                        var documentsLocation = FileUtils.getXdgDocumentsLocation()
 
                         // Check if we have already imported the same document in the past.
-                        var earlierImportedFile = DocumentViewer.checkIfFileAlreadyImported(sourcePath, [documentsLocation])
+                        var earlierImportedFile = FileUtils.checkIfFileAlreadyImported(sourcePath, [documentsLocation])
                         if (earlierImportedFile.length > 0) {
                             // Document has been already imported in the past.
                             // Append the path of the earlier copy of the
@@ -65,7 +65,7 @@
                             importedDocsModel.append({ path: earlierImportedFile })
                         } else {
                             // No document has been found, so we can safely copy it.
-                            var destPath = DocumentViewer.buildDestinationPath(documentsLocation, sourcePath);
+                            var destPath = FileUtils.buildDestinationPath(documentsLocation, sourcePath);
 
                             internal.importDocument(sourcePath, destPath)
                         }
@@ -120,7 +120,7 @@
         }
 
         function importDocument(sourcePath, destPath) {
-            DocumentViewer.copy(sourcePath, destPath)
+            FileUtils.copy(sourcePath, destPath)
             importedDocsModel.append({ path: destPath })
         }
 

=== modified file 'src/app/qml/common/DetailsPage.qml'
--- src/app/qml/common/DetailsPage.qml	2015-12-27 12:10:06 +0000
+++ src/app/qml/common/DetailsPage.qml	2016-02-03 13:44:53 +0000
@@ -40,12 +40,12 @@
 
             SubtitledListItem {
                 text: i18n.tr("File")
-                subText: DocumentViewer.getFileNameFromPath(file.path)
+                subText: FileUtils.getFileNameFromPath(file.path)
             }
 
             SubtitledListItem {
                 text: i18n.tr("Location")
-                subText: DocumentViewer.getCanonicalPath(file.path)
+                subText: FileUtils.getCanonicalPath(file.path)
             }
 
             SubtitledListItem {

=== modified file 'src/app/qml/common/PickImportedDialog.qml'
--- src/app/qml/common/PickImportedDialog.qml	2015-12-26 18:27:13 +0000
+++ src/app/qml/common/PickImportedDialog.qml	2016-02-03 13:44:53 +0000
@@ -40,7 +40,7 @@
             }
 
             Label {
-                text: DocumentViewer.getFileBaseNameFromPath(model.path)
+                text: FileUtils.getFileBaseNameFromPath(model.path)
                 anchors {
                     left: parent.left; right: parent.right
                     margins: units.gu(2)

=== modified file 'src/app/qml/loView/LOViewDefaultHeader.qml'
--- src/app/qml/loView/LOViewDefaultHeader.qml	2015-11-30 12:12:10 +0000
+++ src/app/qml/loView/LOViewDefaultHeader.qml	2016-02-03 13:44:53 +0000
@@ -73,7 +73,7 @@
             Layout.preferredHeight: units.gu(4)
 
             view: targetPage.contentItem.loView
-            visible: targetPage.contentItem && (DocumentViewer.desktopMode || mainView.wideWindow)
+            visible: targetPage.contentItem && (ConvergenceUtils.desktopMode || mainView.wideWindow)
         }
     }
 

=== modified file 'src/app/qml/loView/LOViewPage.qml'
--- src/app/qml/loView/LOViewPage.qml	2016-01-29 12:12:54 +0000
+++ src/app/qml/loView/LOViewPage.qml	2016-02-03 13:44:53 +0000
@@ -32,7 +32,7 @@
     property bool isTextDocument: loPage.contentItem && (loPage.contentItem.loDocument.documentType === LibreOffice.Document.TextDocument)
     property bool isSpreadsheet: loPage.contentItem && (loPage.contentItem.loDocument.documentType === LibreOffice.Document.SpreadsheetDocument)
 
-    title: DocumentViewer.getFileBaseNameFromPath(file.path);
+    title: FileUtils.getFileBaseNameFromPath(file.path);
     flickable: isTextDocument ? loPage.contentItem.loView : null
 
     splashScreen: Splashscreen { }

=== modified file 'src/app/qml/pdfView/PdfPresentation.qml'
--- src/app/qml/pdfView/PdfPresentation.qml	2016-01-23 12:34:25 +0000
+++ src/app/qml/pdfView/PdfPresentation.qml	2016-02-03 13:44:53 +0000
@@ -24,7 +24,7 @@
     property var poppler
     property bool isPresentation: true
     anchors.fill: parent
-    title: DocumentViewer.getFileBaseNameFromPath(poppler.path)
+    title: FileUtils.getFileBaseNameFromPath(poppler.path)
     focus: true
 
     header: PageHeader {

=== modified file 'src/app/qml/pdfView/PdfView.qml'
--- src/app/qml/pdfView/PdfView.qml	2016-01-29 12:23:24 +0000
+++ src/app/qml/pdfView/PdfView.qml	2016-02-03 13:44:53 +0000
@@ -26,7 +26,7 @@
 
 Page {
     id: pdfPage
-    title: DocumentViewer.getFileBaseNameFromPath(file.path)
+    title: FileUtils.getFileBaseNameFromPath(file.path)
 
     header: PageHeader {
         flickable: pdfView

=== modified file 'src/app/qml/textView/TextView.qml'
--- src/app/qml/textView/TextView.qml	2015-12-26 18:27:13 +0000
+++ src/app/qml/textView/TextView.qml	2016-02-03 13:44:53 +0000
@@ -23,7 +23,7 @@
 
 Page {
     id: textPage
-    title: DocumentViewer.getFileBaseNameFromPath(file.path)
+    title: FileUtils.getFileBaseNameFromPath(file.path)
 
     // Reset night mode shader settings when closing the page
     // Component.onDestruction: mainView.nightModeEnabled = false

=== modified file 'src/app/qml/ubuntu-docviewer-app.qml'
--- src/app/qml/ubuntu-docviewer-app.qml	2016-01-14 13:07:09 +0000
+++ src/app/qml/ubuntu-docviewer-app.qml	2016-02-03 13:44:53 +0000
@@ -80,7 +80,7 @@
     onIsLandscapeChanged: {
         // If device orientation is landscape and screen width is limited,
         // force hiding Unity 8 indicators panel.
-        if (!DocumentViewer.desktopMode && mainView.isLandscape &&
+        if (!ConvergenceUtils.desktopMode && mainView.isLandscape &&
                 mainView.width < units.gu(51)) {
             mainView.fullscreen = true
             return;
@@ -202,6 +202,13 @@
         }
     }
 
+    // WORKAROUND: Not yet implemented in the SDK
+    Binding {
+        target: QuickUtils
+        property: "mouseAttached"
+        value: ConvergenceUtils.mouseAttached
+    }
+
     property bool nightModeEnabled: false
     layer.effect: NightModeShader {}
     layer.enabled: nightModeEnabled && (pageStack.depth > 1) && !pageStack.currentPage.isPresentation

=== modified file 'src/plugin/file-qml-plugin/CMakeLists.txt'
--- src/plugin/file-qml-plugin/CMakeLists.txt	2015-10-21 13:16:12 +0000
+++ src/plugin/file-qml-plugin/CMakeLists.txt	2016-02-03 13:44:53 +0000
@@ -1,23 +1,48 @@
+# This includes a temporary snapshot of the WIP QInputInfo API as we
+# require this in docviewer now but upstream isn't finished yet.
+# Eventually this should be dropped in favor of the upstream
+# QInputInfo API.
+
 set(PLUGIN_DIR DocumentViewer)
-include_directories(${CMAKE_CURRENT_SOURCE_DIR})
 
 find_package(Qt5Core)
 find_package(Qt5Qml)
 find_package(Qt5Quick)
 
+pkg_check_modules(LIBUDEV REQUIRED libudev)
+pkg_check_modules(LIBEVDEV REQUIRED libevdev)
+
+include_directories(
+    ${CMAKE_CURRENT_SOURCE_DIR}
+    ${LIBUDEV_INCLUDE_DIRS}
+    ${LIBEVDEV_INCLUDE_DIRS}
+    InputInfo/
+)
+
+# QInputInfo sources
+set(inputinfo_SRCS
+    InputInfo/qinputinfo.cpp
+    InputInfo/qinputinfo.h
+    InputInfo/linux/qinputdeviceinfo_linux.cpp
+    InputInfo/linux/qinputdeviceinfo_linux_p.h
+)
+
 #add the sources to compile
 set(fileqmlplugin_SRCS
     backend.cpp
     documentmodel.cpp
     fswatcher.cpp
     docviewerfile.cpp
-    docviewerutils.cpp
+    fileutils.cpp
+    ubuntuconvergenceutils.cpp
 )
 
 add_library(fileqmlplugin MODULE
+    ${inputinfo_SRCS}
     ${fileqmlplugin_SRCS}
 )
 
+target_link_libraries(fileqmlplugin ${LIBUDEV_LDFLAGS} ${LIBEVDEV_LDFLAGS} )
 qt5_use_modules(fileqmlplugin Qml Quick)
 
 # Copy the plugin, the qmldir file and other assets to the build dir for running in QtCreator

=== modified file 'src/plugin/file-qml-plugin/backend.cpp'
--- src/plugin/file-qml-plugin/backend.cpp	2015-09-19 15:40:22 +0000
+++ src/plugin/file-qml-plugin/backend.cpp	2016-02-03 13:44:53 +0000
@@ -21,27 +21,38 @@
 #include "backend.h"
 #include "documentmodel.h"
 #include "docviewerfile.h"
-#include "docviewerutils.h"
-
-static QObject *registerDocviewerUtils (QQmlEngine *engine, QJSEngine *scriptEngine)
-{
-    Q_UNUSED(engine)
-    Q_UNUSED(scriptEngine)
-
-    DocviewerUtils *ch = new DocviewerUtils();
-    return ch;
+#include "fileutils.h"
+#include "ubuntuconvergenceutils.h"
+
+static QObject *registerFileUtils (QQmlEngine *engine, QJSEngine *scriptEngine)
+{
+    Q_UNUSED(engine)
+    Q_UNUSED(scriptEngine)
+
+    DocviewerFileUtils *f = new DocviewerFileUtils();
+    return f;
+}
+
+static QObject *registerConvergenceUtils (QQmlEngine *engine, QJSEngine *scriptEngine)
+{
+    Q_UNUSED(engine)
+    Q_UNUSED(scriptEngine)
+
+    UbuntuConvergenceUtils *c = new UbuntuConvergenceUtils();
+    return c;
 }
 
 void BackendPlugin::registerTypes(const char *uri)
 {
     Q_ASSERT(uri == QLatin1String("DocumentViewer"));
-    
+
     //@uri DocumentViewer
 
     qmlRegisterType<DocumentModel>(uri, 1, 0, "DocumentsModel");
     qmlRegisterType<DocviewerFile>(uri, 1, 0, "File");
 
-    qmlRegisterSingletonType<DocviewerUtils>(uri, 1, 0, "DocumentViewer", registerDocviewerUtils);
+    qmlRegisterSingletonType<DocviewerFileUtils>(uri, 1, 0, "FileUtils", registerFileUtils);
+    qmlRegisterSingletonType<UbuntuConvergenceUtils>(uri, 1, 0, "ConvergenceUtils", registerConvergenceUtils);
 }
 
 void BackendPlugin::initializeEngine(QQmlEngine *engine, const char *uri)

=== modified file 'src/plugin/file-qml-plugin/documentmodel.cpp'
--- src/plugin/file-qml-plugin/documentmodel.cpp	2015-09-19 15:40:22 +0000
+++ src/plugin/file-qml-plugin/documentmodel.cpp	2016-02-03 13:44:53 +0000
@@ -17,7 +17,7 @@
 
 #include "documentmodel.h"
 #include "fswatcher.h"
-#include "docviewerutils.h"
+#include "fileutils.h"
 
 #include <QStandardPaths>
 #include <QDir>
@@ -115,7 +115,7 @@
 
 bool DocumentModel::isFileSupported(const QString &path)
 {
-    return DocviewerUtils::isFileSupported(path);
+    return DocviewerFileUtils::isFileSupported(path);
 }
 
 QHash<int, QByteArray> DocumentModel::roleNames() const

=== removed file 'src/plugin/file-qml-plugin/docviewerutils.cpp'
--- src/plugin/file-qml-plugin/docviewerutils.cpp	2015-12-27 12:10:06 +0000
+++ src/plugin/file-qml-plugin/docviewerutils.cpp	1970-01-01 00:00:00 +0000
@@ -1,184 +0,0 @@
-/*
-  Copyright (C) 2015 Canonical, Ltd.
-
-  This program is free software: you can redistribute it and/or modify
-  it under the terms of the GNU General Public License 3 as published by
-  the Free Software Foundation.
-
-  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 "docviewerutils.h"
-
-#include <QFileInfo>
-#include <QDir>
-#include <QMimeDatabase>
-#include <QStandardPaths>
-#include <QDirIterator>
-#include <QDateTime>
-#include <QtGui/QGuiApplication>
-
-bool DocviewerUtils::desktopMode() const
-{
-    // Assume that platformName (QtUbuntu) with ubuntu
-    // in name means it's running on device
-    // TODO: replace this check with SDK call for formfactor
-    QString platform = QGuiApplication::platformName();
-    return !((platform == "ubuntu") || (platform == "ubuntumirclient"));
-}
-
-bool DocviewerUtils::exists(const QString &path)
-{
-    QFileInfo fi(path);
-
-    if (fi.isFile())
-        return fi.exists();
-
-    // else
-    return QDir(path).exists();
-}
-
-bool DocviewerUtils::copy(const QString &source, const QString &destination)
-{
-    return QFile::copy(source, destination);
-}
-
-bool DocviewerUtils::isFileSupported(const QString &path)
-{
-    QMimeDatabase mdb;
-    const QString mimetype = mdb.mimeTypeForFile(path).name();
-
-    return mimetype.startsWith("text/")
-            || mimetype == "application/pdf"
-            || mimetype.startsWith("application/vnd.oasis.opendocument")
-            || mimetype == "application/msword"
-            || mimetype == "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
-            || mimetype == "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
-            || mimetype == "application/vnd.openxmlformats-officedocument.presentationml.presentation"
-            || mimetype == "application/vnd.ms-excel"
-            || mimetype == "application/vnd.ms-powerpoint";
-}
-
-QString DocviewerUtils::getXdgDocumentsLocation()
-{
-    return QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation);
-}
-
-QString DocviewerUtils::buildDestinationPath(const QString &destinationDir, const QString &sourcePath)
-{
-    QFileInfo fi(sourcePath);
-
-    /*
-      We don't support formats that use a double extension
-      (e.g. tar.gz), so we can safely use completeBaseName() and
-      suffix() functions, in order to properly detect the name of
-      the document even when there's a dot in the middle of the name.
-    */
-    QString suffix = fi.suffix();
-    QString filenameWithoutSuffix = fi.completeBaseName();
-
-    QMimeDatabase mdb;
-    QMimeType mt = mdb.mimeTypeForFile(sourcePath);
-
-    // If the filename doesn't have an extension add one from the
-    // detected mimetype
-    if (suffix.isEmpty())
-        suffix = mt.preferredSuffix();
-
-    QString dir = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation) + QDir::separator();
-    QString destination = QString("%1.%2").arg(dir + filenameWithoutSuffix, suffix);
-
-    // If there's already a file of this name, reformat it to
-    // "filename (copy x).png" where x is a number, incremented until we find an
-    // available filename.
-    if (QFile::exists(destination)) {
-        /*
-         TRANSLATORS: This string is used for renaming a copied file,
-         when a file with the same name already exists in user's
-         Documents folder.
-
-         e.g. "Manual_Aquaris_E4.5_ubuntu_EN.pdf" will become
-              "Manual_Aquaris_E4.5_ubuntu_EN (copy 2).pdf"
-
-              where "2" is given by the argument "%1"
-        */
-        QString reformattedSuffix = QString(tr("copy %1"));
-
-        // Check if the file has already a "copy" suffix
-        // If so, remove it since we will update it later.
-        QRegExp rx(" \\(" + reformattedSuffix.arg(QString("\\d+")) + "\\)");
-        int reformattedSuffixPos = filenameWithoutSuffix.lastIndexOf(rx);
-
-        if (reformattedSuffixPos != -1)
-            filenameWithoutSuffix.truncate(reformattedSuffixPos);
-
-        // Add the right "copy" suffix.
-        int append = 1;
-        while (QFile::exists(destination)) {
-            destination = QString("%1 (%2).%3").arg(
-                        dir + filenameWithoutSuffix,
-                        reformattedSuffix.arg(QString::number(append)),
-                        suffix);
-            append++;
-        }
-    }
-
-    return destination;
-}
-
-// Return the path of the file, if found in the storageLocation paths,
-// otherwise return an empty string.
-// Used for prevent importing of a second copy of a file through ContentHub.
-QString DocviewerUtils::checkIfFileAlreadyImported(const QString &filePath, const QStringList &storageLocationList)
-{
-    QFileInfo fi(filePath);
-    QStringList files;
-
-    // Get the list of all the files in the watched folders
-    Q_FOREACH(const QString &storageLocation, storageLocationList) {
-        QDirIterator dir(storageLocation, QDir::Files | QDir::NoDotAndDotDot | QDir::Readable,
-                         QDirIterator::Subdirectories);
-
-        while (dir.hasNext())
-        {
-            dir.next();
-            files.append(dir.filePath());
-        }
-    }
-
-    // Check if there's a file with the same name in the list
-    Q_FOREACH(const QString &file, files) {
-        if (file.endsWith(fi.fileName())) {
-            // Seems there could be already the same file in the watched
-            // folders. Check also size and lastModified date.
-            QFileInfo fileToCheck(file);
-
-            if (fi.size() == fileToCheck.size() &&
-                    fi.lastModified() == fileToCheck.lastModified())
-                return file;
-        }
-    }
-
-    return QString();
-}
-
-QString DocviewerUtils::getFileBaseNameFromPath(const QString &filePath)
-{
-    return QFileInfo(filePath).completeBaseName();
-}
-
-QString DocviewerUtils::getFileNameFromPath(const QString &filePath)
-{
-    return QFileInfo(filePath).fileName();
-}
-
-QString DocviewerUtils::getCanonicalPath(const QString &filePath)
-{
-    return QFileInfo(filePath).canonicalPath();
-}

=== removed file 'src/plugin/file-qml-plugin/docviewerutils.h'
--- src/plugin/file-qml-plugin/docviewerutils.h	2015-12-27 12:10:06 +0000
+++ src/plugin/file-qml-plugin/docviewerutils.h	1970-01-01 00:00:00 +0000
@@ -1,45 +0,0 @@
-/*
-  Copyright (C) 2015 Canonical, Ltd.
-
-  This program is free software: you can redistribute it and/or modify
-  it under the terms of the GNU General Public License 3 as published by
-  the Free Software Foundation.
-
-  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 DOCVIEWERUTILS_H
-#define DOCVIEWERUTILS_H
-
-#include <QObject>
-
-class DocviewerUtils : public QObject
-{
-    Q_OBJECT
-    Q_PROPERTY(bool desktopMode READ desktopMode CONSTANT)
-
-public:
-    bool desktopMode() const;
-
-    Q_INVOKABLE static bool exists(const QString &path);
-    Q_INVOKABLE static bool copy(const QString &source, const QString &destination);
-
-    Q_INVOKABLE static bool isFileSupported(const QString &path);
-    Q_INVOKABLE static QString getXdgDocumentsLocation();
-
-    Q_INVOKABLE static QString buildDestinationPath(const QString &destinationDir, const QString &sourcePath);
-
-    Q_INVOKABLE static QString checkIfFileAlreadyImported(const QString &filePath, const QStringList &storageLocationList);
-
-    Q_INVOKABLE static QString getFileBaseNameFromPath(const QString &filePath);
-    Q_INVOKABLE static QString getFileNameFromPath(const QString &filePath);
-    Q_INVOKABLE static QString getCanonicalPath(const QString &filePath);
-};
-
-#endif // DOCVIEWERUTILS_H


Follow ups