← Back to team overview

ubuntu-touch-coreapps-reviewers team mailing list archive

[Merge] lp:~verzegnassi-stefano/ubuntu-docviewer-app/plugins-renaming into lp:ubuntu-docviewer-app

 

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

Commit message:
- Moved DocviewerFile class in the DocumentViewer module.
- Refactored DocviewerFile class:
- Renamed com.ubuntu.popplerqmlplugin module in DocumentViewer.PDF

Requested reviews:
  Ubuntu Document Viewer Developers (ubuntu-docviewer-dev)
Related bugs:
  Bug #1445011 in Ubuntu Document Viewer App: "DocviewerFile class sends pathChanged signal twice"
  https://bugs.launchpad.net/ubuntu-docviewer-app/+bug/1445011

For more details, see:
https://code.launchpad.net/~verzegnassi-stefano/ubuntu-docviewer-app/plugins-renaming/+merge/256353

- Moved DocviewerFile class in the DocumentViewer module.
We already have the DocumentsModel class in this module: there's no reason why we should use two different imports in the main QML file for two classes that are pretty complementary.

- Refactored DocviewerFile class
This solves a long standing issue that used to make PDF plugin to load pages twice. No more need for workaround it.

- Renamed com.ubuntu.popplerqmlplugin module in DocumentViewer.PDF
I just don't like the old name.

We still have a com.ubuntu.fileqmlplugin that actually does nothing, but it will be probably re-used in future for providing an advanced text editor.
-- 
Your team Ubuntu Document Viewer Developers is requested to review the proposed merge of lp:~verzegnassi-stefano/ubuntu-docviewer-app/plugins-renaming into lp:ubuntu-docviewer-app.
=== modified file 'po/com.ubuntu.docviewer.pot'
--- po/com.ubuntu.docviewer.pot	2015-04-13 15:56:00 +0000
+++ po/com.ubuntu.docviewer.pot	2015-04-15 16:12:14 +0000
@@ -8,7 +8,7 @@
 msgstr ""
 "Project-Id-Version: \n"
 "Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2015-04-13 17:55+0200\n"
+"POT-Creation-Date: 2015-04-15 16:41+0200\n"
 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
 "Language-Team: LANGUAGE <LL@xxxxxx>\n"
@@ -215,7 +215,7 @@
 msgstr ""
 
 #: ../src/app/qml/documentPage/DocumentPage.qml:25
-#: /home/stefano/Progetti/doc-viewer/build-adv-import-handler-Desktop-Default/po/com.ubuntu.docviewer.desktop.in.in.h:1
+#: /home/stefano/Progetti/doc-viewer/build-ubuntu-docviewer-app-Desktop-Default/po/com.ubuntu.docviewer.desktop.in.in.h:1
 msgid "Document Viewer"
 msgstr ""
 
@@ -294,16 +294,16 @@
 msgid "Loading..."
 msgstr ""
 
-#: ../src/app/qml/ubuntu-docviewer-app.qml:167
+#: ../src/app/qml/ubuntu-docviewer-app.qml:166
 msgid "Document successfully imported!"
 msgid_plural "Documents successfully imported!"
 msgstr[0] ""
 msgstr[1] ""
 
-#: ../src/app/qml/ubuntu-docviewer-app.qml:170
+#: ../src/app/qml/ubuntu-docviewer-app.qml:169
 msgid "Open"
 msgstr ""
 
-#: /home/stefano/Progetti/doc-viewer/build-adv-import-handler-Desktop-Default/po/com.ubuntu.docviewer.desktop.in.in.h:2
+#: /home/stefano/Progetti/doc-viewer/build-ubuntu-docviewer-app-Desktop-Default/po/com.ubuntu.docviewer.desktop.in.in.h:2
 msgid "documents;viewer;pdf;reader;"
 msgstr ""

=== modified file 'src/app/CMakeLists.txt'
--- src/app/CMakeLists.txt	2015-02-13 15:30:01 +0000
+++ src/app/CMakeLists.txt	2015-04-15 16:12:14 +0000
@@ -10,6 +10,7 @@
     docviewer-application.cpp
     urlhandler.cpp
     quick/documentmodel.cpp
+    quick/docviewerfile.cpp
     ${QML_SRCS}
 )
 

=== modified file 'src/app/docviewer-application.cpp'
--- src/app/docviewer-application.cpp	2015-04-10 15:41:35 +0000
+++ src/app/docviewer-application.cpp	2015-04-15 16:12:14 +0000
@@ -22,6 +22,7 @@
 #include "command-line-parser.h"
 #include "urlhandler.h"
 #include "quick/documentmodel.h"
+#include "quick/docviewerfile.h"
 
 #include <QQuickItem>
 #include <QStandardPaths>
@@ -121,6 +122,7 @@
     m_view->engine()->setImportPathList(importPathList);
 
     qmlRegisterType<SortFilterDocumentModel>("DocumentViewer", 1, 0, "DocumentsModel");
+    qmlRegisterType<DocviewerFile>("DocumentViewer", 1, 0, "File");
 }
 
 /*!

=== modified file 'src/app/qml/common/DetailsPage.qml'
--- src/app/qml/common/DetailsPage.qml	2015-03-04 17:44:36 +0000
+++ src/app/qml/common/DetailsPage.qml	2015-04-15 16:12:14 +0000
@@ -35,24 +35,24 @@
         }
         ListItem.Subtitled {
             text: i18n.tr("Size")
-            subText: Utils.printSize(i18n, file.size)
+            subText: Utils.printSize(i18n, file.info.size)
         }
 
         ListItem.Subtitled {
             text: i18n.tr("Created")
-            subText: file.creationTime.toLocaleString(Qt.locale())
+            subText: file.info.creationTime.toLocaleString(Qt.locale())
         }
 
         ListItem.Subtitled {
             text: i18n.tr("Last modified")
-            subText: file.lastModified.toLocaleString(Qt.locale())
+            subText: file.info.lastModified.toLocaleString(Qt.locale())
         }
 
         ListItem.Subtitled {
             id: mimetypeItem
             objectName: "mimetypeItem"
             text: i18n.tr("MIME type")
-            subText: file.mimetype
+            subText: file.mimetype.name
         }
     }
 }

=== modified file 'src/app/qml/pdfView/PdfView.qml'
--- src/app/qml/pdfView/PdfView.qml	2015-04-10 15:41:35 +0000
+++ src/app/qml/pdfView/PdfView.qml	2015-04-15 16:12:14 +0000
@@ -16,7 +16,7 @@
 
 import QtQuick 2.3
 import Ubuntu.Components 1.1
-import com.ubuntu.popplerqmlplugin 1.0 as PDF
+import DocumentViewer.PDF 1.0 as PDF
 
 import "../common/utils.js" as Utils
 import "../upstreamComponents"
@@ -99,8 +99,8 @@
         id: poppler
 
         property bool isLoading: true
+        path: file.path
 
-        Component.onCompleted: path = file.path
         onPagesLoaded: {
             isLoading = false;
 

=== modified file 'src/app/qml/textView/TextViewDefaultHeader.qml'
--- src/app/qml/textView/TextViewDefaultHeader.qml	2015-03-26 13:58:31 +0000
+++ src/app/qml/textView/TextViewDefaultHeader.qml	2015-04-15 16:12:14 +0000
@@ -51,7 +51,7 @@
                 elide: Text.ElideMiddle
 
                 fontSize: "small"
-                text: file.description
+                text: file.mimetype.description
             }
         }
     }

=== modified file 'src/app/qml/ubuntu-docviewer-app.qml'
--- src/app/qml/ubuntu-docviewer-app.qml	2015-04-13 15:56:00 +0000
+++ src/app/qml/ubuntu-docviewer-app.qml	2015-04-15 16:12:14 +0000
@@ -17,7 +17,6 @@
 import QtQuick 2.3
 import Ubuntu.Components 1.1
 import Ubuntu.Components.Popups 1.0
-import com.ubuntu.fileqmlplugin 1.0
 import DocumentViewer 1.0
 
 import "common"
@@ -99,7 +98,7 @@
         id: file
         objectName: "file"
 
-        onMimetypeChanged: LoadComponent.load(mimetype)
+        onMimetypeChanged: LoadComponent.load(mimetype.name)
         onErrorChanged: {
             if (error == -1)
                 PopupUtils.open(Qt.resolvedUrl("common/FileNotFoundDialog.qml"),

=== renamed file 'src/plugin/file-qml-plugin/docviewerFile.cpp' => 'src/app/quick/docviewerfile.cpp'
--- src/plugin/file-qml-plugin/docviewerFile.cpp	2015-02-04 08:35:41 +0000
+++ src/app/quick/docviewerfile.cpp	2015-04-15 16:12:14 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2013-2014 Canonical, Ltd.
+ * Copyright (C) 2013-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 version 3, as published
@@ -21,12 +21,12 @@
 #include <QDir>
 #include <QMimeDatabase>
 
-#include "docviewerFile.h"
+#include "docviewerfile.h"
 
 /*
  ----8<-----
 
- import org.docviewer.file 1.0
+ import DocumentViewer 1.0
 
  Rectangle {
    width: 200
@@ -37,13 +37,13 @@
       path: "the/path/of/file"
 
       onMimetypeChanged: {
-        do.something(mimetype);
+        do.something(mimetype.name);
       }
    }
 
    Text {
      anchors.centerIn: parent
-     text: helloType.helloworld
+     text: mimetype.description
    }
  }
 
@@ -52,70 +52,68 @@
 
 DocviewerFile::DocviewerFile(QObject *parent) :
     QObject(parent),
-    path("")
-{
-}
-DocviewerFile::~DocviewerFile() {
-    
-}
-
-void DocviewerFile::setPath(QString p) {
-    if (p.isEmpty()) {
-        this->path = "";
+    m_path("")
+{
+    connect(this, SIGNAL(pathChanged()), this, SLOT(open()));
+}
+
+DocviewerFile::~DocviewerFile()
+{
+    //
+}
+
+void DocviewerFile::setPath(const QString &path)
+{
+    if (m_path == path)
+        return;
+
+    QFileInfo file(QDir::currentPath(), path);
+
+    m_path = file.absoluteFilePath();
+    Q_EMIT pathChanged();
+
+    qDebug() << "[FILE] Path parsed as:" << m_path;
+}
+
+void DocviewerFile::open()
+{
+    if (m_path.isEmpty())
+        return;
+
+    QFileInfo file(m_path);
+
+    if (file.exists()) {
+        qDebug() << "[FILE] Extracting information from the file...";
+
+        /** Get info of the file **/
+        m_info["size"] = file.size();
+        m_info["lastModified"] = file.lastModified();
+        m_info["creationTime"] = file.created();
+        Q_EMIT infoChanged();
+
+        /** Get mimetype **/
+        this->setMimetype();
     }
+
     else {
-        this->path = QFileInfo(QDir::currentPath(), p).absoluteFilePath();
-    }
-
-    qDebug() << "[FILE] Path parsed as:" << this->path;
-
-    this->open();
-
-    emit pathChanged();
-}
-
-void DocviewerFile::open() {
-    if (!path.isEmpty())
-    {
-        QFileInfo file(path);
-
-        if (file.exists()) {
-            qDebug() << "[FILE] Extracting information from the file...";
-
-            /**Get info of the file**/
-            size = file.size();
-            emit sizeChanged();
-
-            lastmodified = file.lastModified();
-            emit lastmodifiedChanged();
-
-            creationTime = file.created();
-            emit creationTimeChanged();
-
-            /**Get mimetype**/
-            this->readMimeType();
-        }
-        else {
-            qDebug() << "[FILE] ERROR: Requested file does not exist!";
-            error = -1;
-            emit errorChanged();
-        }
-    }
-}
-
-void DocviewerFile::readMimeType()
+        qDebug() << "[FILE] ERROR: Requested file does not exist!";
+        m_error = -1;
+        Q_EMIT errorChanged();
+    }
+}
+
+void DocviewerFile::setMimetype()
 {
-    QMimeDatabase db;
-    mimetype = db.mimeTypeForFile(this->path).name();
-    description = db.mimeTypeForFile(this->path).comment();
-
-    if (mimetype == "application/octet-stream") {
-        // Returned by Qt when it cannot determinate the mime type
-        mimetype = "Unknown";
-    }
-
-    qDebug() << "[FILE] Requested file mime type:" << mimetype;
-    qDebug() << "[FILE] Requested file description:" << description;
-    emit mimetypeChanged();
-    emit descriptionChanged();
+    QMimeType mime = QMimeDatabase().mimeTypeForFile(m_path);
+
+    m_mimetype["name"] = mime.name();
+    m_mimetype["description"] = mime.comment();
+
+    // Use a more user-friendly value for 'name' when Qt can not determinate the
+    // mime type.
+    if (m_mimetype.value("name") == "application/octet-stream")
+        m_mimetype["name"] = "Unknown";
+
+    qDebug() << "[FILE] Requested file mime type:" << m_mimetype.value("name");
+    Q_EMIT mimetypeChanged();
 }

=== renamed file 'src/plugin/file-qml-plugin/docviewerFile.h' => 'src/app/quick/docviewerfile.h'
--- src/plugin/file-qml-plugin/docviewerFile.h	2015-01-30 16:38:10 +0000
+++ src/app/quick/docviewerfile.h	2015-04-15 16:12:14 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2013-2014 Canonical, Ltd.
+ * Copyright (C) 2013-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 version 3, as published
@@ -27,11 +27,8 @@
 {
     Q_OBJECT
     Q_PROPERTY( QString path READ getPath WRITE setPath NOTIFY pathChanged )
-    Q_PROPERTY( QString mimetype READ getMimetype NOTIFY mimetypeChanged )
-    Q_PROPERTY( QString description READ getDescription NOTIFY descriptionChanged )
-    Q_PROPERTY( qint64 size READ getSize NOTIFY sizeChanged )
-    Q_PROPERTY( QDateTime lastModified READ getLastmodified NOTIFY lastmodifiedChanged )
-    Q_PROPERTY( QDateTime creationTime READ getCreationTime NOTIFY creationTimeChanged )
+    Q_PROPERTY( QVariantMap mimetype READ getMimetype NOTIFY mimetypeChanged)
+    Q_PROPERTY( QVariantMap info READ getInfo NOTIFY infoChanged)
     Q_PROPERTY( int error READ getError NOTIFY errorChanged )
     
 public:
@@ -39,41 +36,29 @@
     ~DocviewerFile();
     
 protected:
-    QString getPath() { return path; }
-    void setPath(QString p);
-
-    QString getMimetype() { return mimetype; }
-
-    QString getDescription() { return description; }
-
-    qint64 getSize() { return size; }
-
-    QDateTime getLastmodified() { return lastmodified; }
-
-    QDateTime getCreationTime() { return creationTime; }
-
-    int getError() { return error; }
+    QString getPath() { return m_path; }
+    void setPath(const QString &path);
+
+    QVariantMap getMimetype() { return m_mimetype; }
+    QVariantMap getInfo() { return m_info; }
+    int getError() { return m_error; }
     
-    QString path;
-    QString mimetype;
-    QString description;
-    qint64 size;
-    QDateTime lastmodified;
-    QDateTime creationTime;
-    int error;
-
-private:
-    void open();
-    void readMimeType();
-
 Q_SIGNALS:
     void pathChanged();
     void mimetypeChanged();
-    void descriptionChanged();
-    void sizeChanged();
-    void lastmodifiedChanged();
-    void creationTimeChanged();
     void errorChanged();
+    void infoChanged();
+
+private slots:
+    void open();
+
+private:
+    void setMimetype();
+
+    QString m_path;
+    QVariantMap m_mimetype;
+    QVariantMap m_info;
+    int m_error;
 };
 
 #endif // DOCVIEWERFILE_H

=== modified file 'src/plugin/file-qml-plugin/CMakeLists.txt'
--- src/plugin/file-qml-plugin/CMakeLists.txt	2015-01-29 16:35:28 +0000
+++ src/plugin/file-qml-plugin/CMakeLists.txt	2015-04-15 16:12:14 +0000
@@ -4,7 +4,6 @@
 #add the sources to compile
 set(fileqmlplugin_SRCS
 	backend.cpp
-	docviewerFile.cpp
 	fileReader.cpp
 )
 

=== modified file 'src/plugin/file-qml-plugin/backend.cpp'
--- src/plugin/file-qml-plugin/backend.cpp	2015-01-29 16:24:50 +0000
+++ src/plugin/file-qml-plugin/backend.cpp	2015-04-15 16:12:14 +0000
@@ -19,7 +19,6 @@
 #include <QtQml/QQmlContext>
 
 #include "backend.h"
-#include "docviewerFile.h"
 #include "fileReader.h"
 
 void BackendPlugin::registerTypes(const char *uri)
@@ -28,7 +27,6 @@
     
     //@uri com.ubuntu.fileqmlplugin
 
-    qmlRegisterType<DocviewerFile>(uri, 1, 0, "File");
     qmlRegisterType<FileReader>(uri, 1, 0, "FileReader");    
 
 }

=== modified file 'src/plugin/poppler-qml-plugin/CMakeLists.txt'
--- src/plugin/poppler-qml-plugin/CMakeLists.txt	2015-02-04 19:19:21 +0000
+++ src/plugin/poppler-qml-plugin/CMakeLists.txt	2015-04-15 16:12:14 +0000
@@ -1,4 +1,4 @@
-set(PLUGIN_DIR com/ubuntu/popplerqmlplugin)
+set(PLUGIN_DIR DocumentViewer/PDF)
 include_directories(
 	${CMAKE_CURRENT_SOURCE_DIR}
 	${CMAKE_CURRENT_BINARY_DIR}

=== modified file 'src/plugin/poppler-qml-plugin/plugin.cpp'
--- src/plugin/poppler-qml-plugin/plugin.cpp	2015-01-30 19:20:39 +0000
+++ src/plugin/poppler-qml-plugin/plugin.cpp	2015-04-15 16:12:14 +0000
@@ -24,9 +24,9 @@
 
 void PopplerPlugin::registerTypes(const char *uri)
 {
-    Q_ASSERT(uri == QLatin1String("com.ubuntu.popplerqmlplugin"));
+    Q_ASSERT(uri == QLatin1String("DocumentViewer.PDF"));
     
-    //@uri com.ubuntu.popplerqmlplugin
+    //@uri DocumentViewer.PDF
     qmlRegisterType<PdfDocument>(uri, 1, 0, "Document");
     qmlRegisterType<VerticalView>(uri, 1, 0, "VerticalView");
 }

=== modified file 'src/plugin/poppler-qml-plugin/qmldir'
--- src/plugin/poppler-qml-plugin/qmldir	2014-10-28 22:10:16 +0000
+++ src/plugin/poppler-qml-plugin/qmldir	2015-04-15 16:12:14 +0000
@@ -1,2 +1,2 @@
-module com.ubuntu.popplerqmlplugin
+module DocumentViewer.PDF
 plugin popplerqmlplugin


Follow ups