[gnome-maps] Fix broken route printing after ES6 modules migration



commit 2212dc9aae3a7ea93ecdd9d858d0cd979d8d67ed
Author: Marcus Lundblad <ml dfupdate se>
Date:   Thu Aug 11 23:26:14 2022 +0200

    Fix broken route printing after ES6 modules migration
    
    Printing routes has been broken since the migration to ES6
    modules.

 src/longPrintLayout.js    |  7 +++++--
 src/mainWindow.js         |  4 ++--
 src/printOperation.js     | 39 ++++++++++++++++++++++-----------------
 src/shortPrintLayout.js   |  2 +-
 src/transitPrintLayout.js | 22 +++++++++++-----------
 5 files changed, 41 insertions(+), 33 deletions(-)
---
diff --git a/src/longPrintLayout.js b/src/longPrintLayout.js
index 4833319d..21cf51d8 100644
--- a/src/longPrintLayout.js
+++ b/src/longPrintLayout.js
@@ -20,6 +20,7 @@
 import GObject from 'gi://GObject';
 
 import {PrintLayout} from './printLayout.js';
+import {Route} from './route.js';
 import {TurnPoint} from './route.js';
 
 const _NUM_MINIMAPS = 5;
@@ -44,7 +45,7 @@ export class LongPrintLayout extends PrintLayout {
         delete params.route;
 
         /* (Header + 3 maps) + instructions */
-        let totalSurfaces = 4 + this._route.turnPoints.length;
+        let totalSurfaces = 4 + route.turnPoints.length;
 
         /* Plus via points */
         route.turnPoints.forEach((turnPoint) => {
@@ -115,7 +116,7 @@ export class LongPrintLayout extends PrintLayout {
                                   turnPoint);
             this._cursorY += dy;
 
-            if (turnPoint.type === Route.TurnPointType.VIA) {
+            if (turnPoint.type === TurnPoint.Type.VIA) {
                 let tmpY = this._cursorY;
 
                 first = Math.max(0, (i + 1) - (_NUM_MINIMAPS / 2));
@@ -139,3 +140,5 @@ export class LongPrintLayout extends PrintLayout {
                           miniMapViewZoomLevel, points);
     }
 }
+
+GObject.registerClass(LongPrintLayout);
diff --git a/src/mainWindow.js b/src/mainWindow.js
index 6429dbc1..ff7d0326 100644
--- a/src/mainWindow.js
+++ b/src/mainWindow.js
@@ -463,7 +463,7 @@ export class MainWindow extends Gtk.ApplicationWindow {
                 break;
 
             case Geoclue.State.DENIED:
-                let dialog = new LocationServiceDialog.LocationServiceDialog({
+                let dialog = new LocationServiceDialog({
                     visible: true,
                     transient_for: this,
                     modal: true });
@@ -513,7 +513,7 @@ export class MainWindow extends Gtk.ApplicationWindow {
 
     _printRouteActivate() {
         if (this._mapView.routeShowing) {
-            let operation = new PrintOperation.PrintOperation({ mainWindow: this });
+            let operation = new PrintOperation({ mainWindow: this });
         }
     }
 
diff --git a/src/printOperation.js b/src/printOperation.js
index 78c02c3f..47dbb2ba 100644
--- a/src/printOperation.js
+++ b/src/printOperation.js
@@ -65,13 +65,6 @@ export class PrintOperation {
         let width = context.get_width();
         let height = context.get_height();
 
-        GLib.timeout_add(null, _MIN_TIME_TO_ABORT, () => {
-            if (!this._layout.renderFinished) {
-                this._abortDialog.show();
-            }
-            return false;
-        }, null);
-
         if (selectedTransitItinerary) {
             this._layout =
                 new TransitPrintLayout({ itinerary: selectedTransitItinerary,
@@ -79,15 +72,23 @@ export class PrintOperation {
                                          pageHeight: height });
         } else {
             if (route.distance > _SHORT_LAYOUT_MAX_DISTANCE) {
-                return new LongPrintLayout({ route: route,
-                                             pageWidth: pageWidth,
-                                             pageHeight: pageHeight });
+                this._layout = new LongPrintLayout({ route: route,
+                                                     pageWidth: width,
+                                                     pageHeight: height });
             } else {
-                return new ShortPrintLayout({ route: route,
-                                              pageWidth: pageWidth,
-                                              pageHeight: pageHeight });
+                this._layout = new ShortPrintLayout({ route: route,
+                                                      pageWidth: width,
+                                                      pageHeight: height });
             }
         }
+
+        GLib.timeout_add(null, _MIN_TIME_TO_ABORT, () => {
+            if (!this._layout.renderFinished) {
+                this._abortDialog.show();
+            }
+            return false;
+        });
+
         this._layout.render();
     }
 
@@ -101,11 +102,15 @@ export class PrintOperation {
     }
 
     _paginate(operation, context) {
-        if (this._layout.renderFinished) {
-            operation.set_n_pages(this._layout.numPages);
-            this._abortDialog.close();
+        if (this._layout) {
+            if (this._layout.renderFinished) {
+                operation.set_n_pages(this._layout.numPages);
+                this._abortDialog.close();
+            }
+            return this._layout.renderFinished;
+        } else {
+            return false;
         }
-        return this._layout.renderFinished;
     }
 
     _drawPage(operation, context, page_num, data) {
diff --git a/src/shortPrintLayout.js b/src/shortPrintLayout.js
index 80067710..2875c51c 100644
--- a/src/shortPrintLayout.js
+++ b/src/shortPrintLayout.js
@@ -34,7 +34,7 @@ export class ShortPrintLayout extends PrintLayout {
         delete params.route;
 
         /* (Header +  map) + instructions */
-        let totalSurfaces = 2 + this._route.turnPoints.length;
+        let totalSurfaces = 2 + route.turnPoints.length;
         params.totalSurfaces = totalSurfaces;
 
         super(params);
diff --git a/src/transitPrintLayout.js b/src/transitPrintLayout.js
index 1339b62e..4693edde 100644
--- a/src/transitPrintLayout.js
+++ b/src/transitPrintLayout.js
@@ -68,21 +68,22 @@ export class TransitPrintLayout extends PrintLayout {
         let itinerary = params.itinerary;
         delete params.itinerary;
 
-        params.totalSurfaces = this._getNumberOfSurfaces();
+        params.totalSurfaces =
+            TransitPrintLayout._getNumberOfSurfaces(itinerary);
 
         super(params);
 
         this._itinerary = itinerary;
     }
 
-    _getNumberOfSurfaces() {
+    static _getNumberOfSurfaces(itinerary) {
         // always one fixed surface for the title label
         let numSurfaces = 1;
 
-        for (let i = 0; i < this._itinerary.legs.length; i++) {
+        for (let leg of itinerary.legs) {
             numSurfaces++;
             // add a surface when a leg of the itinerary should have a map view
-            if (this._legHasMiniMap(i))
+            if (TransitPrintLayout._legHasMiniMap(leg))
                 numSurfaces++;
         }
 
@@ -143,10 +144,10 @@ export class TransitPrintLayout extends PrintLayout {
     }
 
     _createBBox(leg) {
-        return Champlain.BoundingBox({ top:    leg.bbox.top,
-                                       left:   leg.bbox.left,
-                                       bottom: leg.bbox.bottom,
-                                       right:  leg.bbox.right });
+        return new Champlain.BoundingBox({ top:    leg.bbox.top,
+                                           left:   leg.bbox.left,
+                                           bottom: leg.bbox.bottom,
+                                           right:  leg.bbox.right });
     }
 
     _createStartMarker(leg, previousLeg) {
@@ -287,8 +288,7 @@ export class TransitPrintLayout extends PrintLayout {
         this._addSurface(surface, x, y, pageNum);
     }
 
-    _legHasMiniMap(index) {
-        let leg = this._itinerary.legs[index];
+    static _legHasMiniMap(leg) {
         return !leg.transit;
     }
 
@@ -315,7 +315,7 @@ export class TransitPrintLayout extends PrintLayout {
 
         for (let i = 0; i < this._itinerary.legs.length; i++) {
             let leg = this._itinerary.legs[i];
-            let hasMap = this._legHasMiniMap(i);
+            let hasMap = TransitPrintLayout._legHasMiniMap(leg);
             let instructionDy = instructionHeight + instructionMargin;
             let mapDy = hasMap ? mapViewHeight + mapViewMargin : 0;
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]