2020-07-29 21:02:21 +03:00
|
|
|
/* -*- 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 "nsPrinterCUPS.h"
|
|
|
|
|
2020-08-04 08:41:27 +03:00
|
|
|
nsPrinterCUPS::nsPrinterCUPS(const nsCUPSShim& aShim, cups_dest_t* aPrinter,
|
|
|
|
nsTArray<RefPtr<nsIPaper>>&& aPaperList)
|
|
|
|
: mShim(aShim), mPaperList(std::move(aPaperList)) {
|
2020-07-29 21:02:21 +03:00
|
|
|
MOZ_ASSERT(aPrinter);
|
|
|
|
MOZ_ASSERT(mShim.IsInitialized());
|
|
|
|
DebugOnly<const int> numCopied = aShim.mCupsCopyDest(aPrinter, 0, &mPrinter);
|
|
|
|
MOZ_ASSERT(numCopied == 1);
|
|
|
|
mPrinterInfo = aShim.mCupsCopyDestInfo(CUPS_HTTP_DEFAULT, mPrinter);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsPrinterCUPS::~nsPrinterCUPS() {
|
|
|
|
if (mPrinterInfo) {
|
|
|
|
mShim.mCupsFreeDestInfo(mPrinterInfo);
|
|
|
|
}
|
|
|
|
if (mPrinter) {
|
|
|
|
mShim.mCupsFreeDests(1, mPrinter);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS(nsPrinterCUPS, nsIPrinter);
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPrinterCUPS::GetName(nsAString& aName) {
|
|
|
|
aName = NS_ConvertUTF8toUTF16(mPrinter->name);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPrinterCUPS::GetPaperList(nsTArray<RefPtr<nsIPaper>>& aPaperList) {
|
2020-08-04 08:41:27 +03:00
|
|
|
aPaperList.Assign(mPaperList);
|
2020-07-29 21:02:21 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPrinterCUPS::GetSupportsDuplex(bool* aSupportsDuplex) {
|
|
|
|
MOZ_ASSERT(aSupportsDuplex);
|
|
|
|
if (mSupportsDuplex.isNothing()) {
|
|
|
|
mSupportsDuplex = Some(Supports(CUPS_SIDES, CUPS_SIDES_TWO_SIDED_PORTRAIT));
|
|
|
|
}
|
|
|
|
*aSupportsDuplex = mSupportsDuplex.value();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2020-08-03 14:45:35 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPrinterCUPS::GetSupportsColor(bool* aSupportsColor) {
|
|
|
|
MOZ_ASSERT(aSupportsColor);
|
|
|
|
// Dummy implementation waiting platform specific one.
|
|
|
|
*aSupportsColor = false;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2020-07-29 21:02:21 +03:00
|
|
|
bool nsPrinterCUPS::Supports(const char* option, const char* value) const {
|
|
|
|
MOZ_ASSERT(mPrinterInfo);
|
|
|
|
return mShim.mCupsCheckDestSupported(CUPS_HTTP_DEFAULT, mPrinter,
|
|
|
|
mPrinterInfo, option, value);
|
|
|
|
}
|