зеркало из https://github.com/mozilla/gecko-dev.git
Backed out changeset a71e53a3e455 (bug 1657874) for CUPSPrinterList.h related bustage CLOSED TREE
This commit is contained in:
Родитель
99cb02ee89
Коммит
5664de44fd
|
@ -0,0 +1,41 @@
|
|||
/* -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 2; -*- */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "CUPSPrinterList.h"
|
||||
|
||||
#include "mozilla/Assertions.h"
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
CUPSPrinterList::~CUPSPrinterList() {
|
||||
MOZ_ASSERT(mShim.IsInitialized());
|
||||
// cupsFreeDests is safe to call on a zero-length or null array.
|
||||
mShim.cupsFreeDests(mNumPrinters, mPrinters);
|
||||
}
|
||||
|
||||
void CUPSPrinterList::Initialize() {
|
||||
MOZ_ASSERT(mShim.IsInitialized());
|
||||
mNumPrinters = mShim.cupsGetDests(&mPrinters);
|
||||
}
|
||||
|
||||
cups_dest_t* CUPSPrinterList::FindPrinterByName(const char* aName) {
|
||||
MOZ_ASSERT(aName);
|
||||
return mShim.cupsGetDest(aName, /* instance */ nullptr, mNumPrinters,
|
||||
mPrinters);
|
||||
}
|
||||
|
||||
cups_dest_t* CUPSPrinterList::GetPrinter(int i) {
|
||||
if (i < 0 || i >= mNumPrinters)
|
||||
MOZ_CRASH("CUPSPrinterList::GetPrinter out of range");
|
||||
return mPrinters + i;
|
||||
}
|
||||
|
||||
cups_dest_t* CUPSPrinterList::GetDefaultPrinter() {
|
||||
// Passing in nullptr for the name will return the default, if any.
|
||||
return mShim.cupsGetNamedDest(CUPS_HTTP_DEFAULT, /* name */ nullptr,
|
||||
/* instance */ nullptr);
|
||||
}
|
||||
|
||||
} // namespace mozilla
|
|
@ -0,0 +1,58 @@
|
|||
/* -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 2; -*- */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#ifndef nsCUPSPrinterList_h___
|
||||
#define nsCUPSPrinterList_h___
|
||||
|
||||
#include "nsCUPSShim.h"
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
/**
|
||||
* @brief Enumerates all CUPS printers and provides lookup by name.
|
||||
*/
|
||||
class CUPSPrinterList {
|
||||
public:
|
||||
CUPSPrinterList(const CUPSPrinterList&) = delete;
|
||||
explicit CUPSPrinterList(const nsCUPSShim& aShim) : mShim(aShim) {}
|
||||
~CUPSPrinterList();
|
||||
|
||||
/**
|
||||
* @brief fetches the printer list.
|
||||
*
|
||||
* This is a blocking call.
|
||||
*/
|
||||
void Initialize();
|
||||
|
||||
/**
|
||||
* @brief Looks up a printer by CUPS name.
|
||||
*/
|
||||
cups_dest_t* FindPrinterByName(const char* name);
|
||||
|
||||
int NumPrinters() const { return mNumPrinters; }
|
||||
|
||||
/**
|
||||
* @brief Gets a printer by index.
|
||||
*
|
||||
* This does NOT copy the printer's data.
|
||||
*/
|
||||
cups_dest_t* GetPrinter(int i);
|
||||
|
||||
/**
|
||||
* @brief Gets the system default printer.
|
||||
*
|
||||
* This does NOT copy the printer's data.
|
||||
*/
|
||||
cups_dest_t* GetDefaultPrinter();
|
||||
|
||||
private:
|
||||
const nsCUPSShim& mShim;
|
||||
cups_dest_t* mPrinters = nullptr;
|
||||
int mNumPrinters = 0;
|
||||
};
|
||||
|
||||
} // namespace mozilla
|
||||
|
||||
#endif /* nsCUPSPrinter_h___ */
|
|
@ -248,6 +248,7 @@ if CONFIG['MOZ_XUL'] and CONFIG['NS_PRINTING']:
|
|||
|
||||
if toolkit in ('cocoa', 'gtk'):
|
||||
UNIFIED_SOURCES += [
|
||||
'CUPSPrinterList.cpp',
|
||||
'nsCUPSShim.cpp',
|
||||
'nsPrinterCUPS.cpp',
|
||||
'nsPrinterListCUPS.cpp',
|
||||
|
|
|
@ -4,10 +4,9 @@
|
|||
|
||||
#include "nsPrinterListCUPS.h"
|
||||
|
||||
#include "mozilla/IntegerRange.h"
|
||||
#include "CUPSPrinterList.h"
|
||||
#include "nsCUPSShim.h"
|
||||
#include "nsPrinterCUPS.h"
|
||||
#include "nsString.h"
|
||||
#include "prenv.h"
|
||||
|
||||
static nsCUPSShim sCupsShim;
|
||||
|
@ -18,12 +17,12 @@ nsPrinterListCUPS::GetPrinters(nsTArray<RefPtr<nsIPrinter>>& aPrinters) {
|
|||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
cups_dest_t* printers = nullptr;
|
||||
auto numPrinters = sCupsShim.cupsGetDests(&printers);
|
||||
aPrinters.SetCapacity(numPrinters);
|
||||
mozilla::CUPSPrinterList cupsPrinterList(sCupsShim);
|
||||
cupsPrinterList.Initialize();
|
||||
aPrinters.SetCapacity(cupsPrinterList.NumPrinters());
|
||||
|
||||
for (auto i : mozilla::IntegerRange(0, numPrinters)) {
|
||||
cups_dest_t* dest = printers + i;
|
||||
for (int i = 0; i < cupsPrinterList.NumPrinters(); i++) {
|
||||
cups_dest_t* const dest = cupsPrinterList.GetPrinter(i);
|
||||
|
||||
nsString displayName;
|
||||
GetDisplayNameForPrinter(*dest, displayName);
|
||||
|
@ -33,7 +32,6 @@ nsPrinterListCUPS::GetPrinters(nsTArray<RefPtr<nsIPrinter>>& aPrinters) {
|
|||
aPrinters.AppendElement(cupsPrinter);
|
||||
}
|
||||
|
||||
sCupsShim.cupsFreeDests(numPrinters, printers);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -43,10 +41,10 @@ nsPrinterListCUPS::GetSystemDefaultPrinterName(nsAString& aName) {
|
|||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
// Passing in nullptr for the name will return the default, if any.
|
||||
const cups_dest_t* dest =
|
||||
sCupsShim.cupsGetNamedDest(CUPS_HTTP_DEFAULT, /* name */ nullptr,
|
||||
/* instance */ nullptr);
|
||||
mozilla::CUPSPrinterList cupsPrinterList(sCupsShim);
|
||||
cupsPrinterList.Initialize();
|
||||
|
||||
cups_dest_t* const dest = cupsPrinterList.GetDefaultPrinter();
|
||||
if (!dest) {
|
||||
return NS_ERROR_GFX_PRINTER_NO_PRINTER_AVAILABLE;
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче