gecko-dev/widget/CUPSPrinterList.cpp

42 строки
1.3 KiB
C++

/* -*- 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