LCOV - code coverage report
Current view: top level - widget/gtk - nsPrintOptionsGTK.cpp (source / functions) Hit Total Coverage
Test: output.info Lines: 2 41 4.9 %
Date: 2017-07-14 16:53:18 Functions: 1 7 14.3 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
       2             : /* This Source Code Form is subject to the terms of the Mozilla Public
       3             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       4             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
       5             : 
       6             : #include "nsPrintOptionsGTK.h"
       7             : #include "nsPrintSettingsGTK.h"
       8             : 
       9             : using namespace mozilla::embedding;
      10             : 
      11             : /** ---------------------------------------------------
      12             :  *  See documentation in nsPrintOptionsWin.h
      13             :  *      @update 6/21/00 dwc
      14             :  */
      15           1 : nsPrintOptionsGTK::nsPrintOptionsGTK()
      16             : {
      17             : 
      18           1 : }
      19             : 
      20             : /** ---------------------------------------------------
      21             :  *  See documentation in nsPrintOptionsImpl.h
      22             :  *      @update 6/21/00 dwc
      23             :  */
      24           0 : nsPrintOptionsGTK::~nsPrintOptionsGTK()
      25             : {
      26           0 : }
      27             : 
      28             : static void
      29           0 : serialize_gtk_printsettings_to_printdata(const gchar *key,
      30             :                                          const gchar *value,
      31             :                                          gpointer aData)
      32             : {
      33           0 :   PrintData* data = (PrintData*)aData;
      34           0 :   CStringKeyValue pair;
      35           0 :   pair.key() = key;
      36           0 :   pair.value() = value;
      37           0 :   data->GTKPrintSettings().AppendElement(pair);
      38           0 : }
      39             : 
      40             : NS_IMETHODIMP
      41           0 : nsPrintOptionsGTK::SerializeToPrintData(nsIPrintSettings* aSettings,
      42             :                                         nsIWebBrowserPrint* aWBP,
      43             :                                         PrintData* data)
      44             : {
      45           0 :   nsresult rv = nsPrintOptions::SerializeToPrintData(aSettings, aWBP, data);
      46           0 :   NS_ENSURE_SUCCESS(rv, rv);
      47             : 
      48           0 :   nsCOMPtr<nsPrintSettingsGTK> settingsGTK(do_QueryInterface(aSettings));
      49           0 :   NS_ENSURE_STATE(settingsGTK);
      50             : 
      51           0 :   GtkPrintSettings* gtkPrintSettings = settingsGTK->GetGtkPrintSettings();
      52           0 :   NS_ENSURE_STATE(gtkPrintSettings);
      53             : 
      54             :   gtk_print_settings_foreach(
      55             :     gtkPrintSettings,
      56             :     serialize_gtk_printsettings_to_printdata,
      57           0 :     data);
      58             : 
      59           0 :   return NS_OK;
      60             : }
      61             : 
      62             : NS_IMETHODIMP
      63           0 : nsPrintOptionsGTK::DeserializeToPrintSettings(const PrintData& data,
      64             :                                               nsIPrintSettings* settings)
      65             : {
      66           0 :   nsCOMPtr<nsPrintSettingsGTK> settingsGTK(do_QueryInterface(settings));
      67           0 :   NS_ENSURE_STATE(settingsGTK);
      68             : 
      69           0 :   nsresult rv = nsPrintOptions::DeserializeToPrintSettings(data, settings);
      70           0 :   NS_ENSURE_SUCCESS(rv, rv);
      71             : 
      72             :   // Instead of re-using the GtkPrintSettings that nsIPrintSettings is
      73             :   // wrapping, we'll create a new one to deserialize to and replace it
      74             :   // within nsIPrintSettings.
      75           0 :   GtkPrintSettings* newGtkPrintSettings = gtk_print_settings_new();
      76             : 
      77           0 :   for (uint32_t i = 0; i < data.GTKPrintSettings().Length(); ++i) {
      78           0 :     CStringKeyValue pair = data.GTKPrintSettings()[i];
      79           0 :     gtk_print_settings_set(newGtkPrintSettings,
      80           0 :                            pair.key().get(),
      81           0 :                            pair.value().get());
      82             :   }
      83             : 
      84           0 :   settingsGTK->SetGtkPrintSettings(newGtkPrintSettings);
      85             : 
      86             :   // nsPrintSettingsGTK is holding a reference to newGtkPrintSettings
      87           0 :   g_object_unref(newGtkPrintSettings);
      88           0 :   newGtkPrintSettings = nullptr;
      89           0 :   return NS_OK;
      90             : }
      91             : 
      92           0 : nsresult nsPrintOptionsGTK::_CreatePrintSettings(nsIPrintSettings **_retval)
      93             : {
      94           0 :   *_retval = nullptr;
      95           0 :   nsPrintSettingsGTK* printSettings = new nsPrintSettingsGTK(); // does not initially ref count
      96           0 :   NS_ENSURE_TRUE(printSettings, NS_ERROR_OUT_OF_MEMORY);
      97             : 
      98           0 :   NS_ADDREF(*_retval = printSettings); // ref count
      99             : 
     100           0 :   return NS_OK;
     101             : }
     102             : 

Generated by: LCOV version 1.13