mirror of
https://gitee.com/openharmony/print_print_fwk
synced 2024-11-23 08:59:47 +00:00
commit
39d80d4f6d
@ -412,10 +412,10 @@ void PrinterInfo::Dump() const
|
||||
capability_.Dump();
|
||||
}
|
||||
if (hasUri_) {
|
||||
PRINT_HILOGD("uri: %{private}s", option_.c_str());
|
||||
PRINT_HILOGD("uri: %{private}s", uri_.c_str());
|
||||
}
|
||||
if (hasPrinterMake_) {
|
||||
PRINT_HILOGD("printerMake: %{private}s", option_.c_str());
|
||||
PRINT_HILOGD("printerMake: %{private}s", printerMake_.c_str());
|
||||
}
|
||||
if (hasOption_) {
|
||||
PRINT_HILOGD("option: %{private}s", option_.c_str());
|
||||
|
@ -191,6 +191,7 @@ private:
|
||||
bool RemoveSinglePrinterInfo(const std::string &printerId);
|
||||
void HandlePrinterStateChangeRegister(const std::string &eventType);
|
||||
void HandlePrinterChangeRegister(const std::string &eventType);
|
||||
bool UpdateAddedPrinterInCups(const std::string &printerId, const std::string &printerUri);
|
||||
public:
|
||||
bool AddVendorPrinterToDiscovery(const std::string &globalVendorName, const PrinterInfo &info) override;
|
||||
bool UpdateVendorPrinterToDiscovery(const std::string &globalVendorName, const PrinterInfo &info) override;
|
||||
|
@ -55,6 +55,7 @@ public:
|
||||
void GetAddedPrinterListFromSystemData(std::vector<std::string> &printerNameList);
|
||||
void UpdatePrinterStatus(const std::string &printerId, PrinterStatus printerStatus);
|
||||
bool UpdatePrinterAlias(const std::string& printerId, const std::string& printerAlias);
|
||||
void UpdatePrinterUri(const std::shared_ptr<PrinterInfo> &printerInfo);
|
||||
void QueryPrinterInfoById(const std::string &printerId, PrinterInfo &printerInfo);
|
||||
bool CheckPrinterBusy(const std::string &printerId);
|
||||
bool GetAllPrintUser(std::vector<int32_t> &allPrintUserList);
|
||||
|
@ -1428,14 +1428,10 @@ void PrintServiceAbility::SendQueuePrintJob(const std::string &printerId)
|
||||
bool PrintServiceAbility::CheckPrinterUriDifferent(const std::shared_ptr<PrinterInfo> &info)
|
||||
{
|
||||
CupsPrinterInfo cupsPrinter;
|
||||
std::string option = info->GetOption();
|
||||
if (printSystemData_.QueryCupsPrinterInfoByPrinterId(info->GetPrinterId(), cupsPrinter) && json::accept(option)) {
|
||||
json optionJson = json::parse(option);
|
||||
if (optionJson.contains("printerUri") && optionJson["printerUri"].is_string()) {
|
||||
std::string printerUri = optionJson["printerUri"].get<std::string>();
|
||||
if (!printerUri.empty() && printerUri != cupsPrinter.uri) {
|
||||
return true;
|
||||
}
|
||||
if (printSystemData_.QueryCupsPrinterInfoByPrinterId(info->GetPrinterId(), cupsPrinter)) {
|
||||
std::string printerUri = info->GetUri();
|
||||
if (!printerUri.empty() && printerUri != cupsPrinter.uri) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
@ -2983,6 +2979,12 @@ int32_t PrintServiceAbility::AddSinglePrinterInfo(const PrinterInfo &info, const
|
||||
|
||||
if (printSystemData_.IsPrinterAdded(infoPtr->GetPrinterId()) &&
|
||||
!printSystemData_.CheckPrinterBusy(infoPtr->GetPrinterId())) {
|
||||
if (CheckPrinterUriDifferent(infoPtr)) {
|
||||
if (UpdateAddedPrinterInCups(infoPtr->GetPrinterId(), infoPtr->GetUri())) {
|
||||
printSystemData_.UpdatePrinterUri(infoPtr);
|
||||
printSystemData_.SaveCupsPrinterMap();
|
||||
}
|
||||
}
|
||||
infoPtr->SetPrinterStatus(PRINTER_STATUS_IDLE);
|
||||
printSystemData_.UpdatePrinterStatus(infoPtr->GetPrinterId(), PRINTER_STATUS_IDLE);
|
||||
SendPrinterEventChangeEvent(PRINTER_EVENT_STATE_CHANGED, *infoPtr);
|
||||
@ -3368,4 +3370,19 @@ void PrintServiceAbility::HandlePrinterChangeRegister(const std::string &eventTy
|
||||
PRINT_HILOGD("end HandlePrinterChangeRegister, printAppCount_: %{public}u", printAppCount_);
|
||||
}
|
||||
}
|
||||
|
||||
bool PrintServiceAbility::UpdateAddedPrinterInCups(const std::string &printerId, const std::string &printerUri)
|
||||
{
|
||||
CupsPrinterInfo cupsPrinter;
|
||||
if (printSystemData_.QueryCupsPrinterInfoByPrinterId(printerId, cupsPrinter)) {
|
||||
int32_t ret = DelayedSingleton<PrintCupsClient>::GetInstance()->
|
||||
AddPrinterToCups(printerUri, cupsPrinter.name, cupsPrinter.maker);
|
||||
if (ret != E_PRINT_NONE) {
|
||||
PRINT_HILOGE("UpdateAddedPrinterInCups error = %{public}d.", ret);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
} // namespace OHOS::Print
|
||||
|
@ -289,6 +289,15 @@ bool PrintSystemData::UpdatePrinterAlias(const std::string& printerId, const std
|
||||
return false;
|
||||
}
|
||||
|
||||
void PrintSystemData::UpdatePrinterUri(const std::shared_ptr<PrinterInfo> &printerInfo)
|
||||
{
|
||||
auto info = addedPrinterMap_.Find(printerInfo->GetPrinterId());
|
||||
if (info != nullptr) {
|
||||
info->uri = printerInfo->GetUri();
|
||||
PRINT_HILOGI("UpdatePrinterUri success");
|
||||
}
|
||||
}
|
||||
|
||||
void PrintSystemData::InsertPrinterInfo(const std::string &printerId, const PrinterInfo &printerInfo)
|
||||
{
|
||||
auto iter = addedPrinterInfoList_.find(printerId);
|
||||
@ -819,7 +828,7 @@ void PrintSystemData::AddPrinterToDiscovery(std::shared_ptr<PrinterInfo> printer
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(discoveredListMutex);
|
||||
if (printerInfo != nullptr) {
|
||||
discoveredPrinterInfoList_.insert(std::make_pair(printerInfo->GetPrinterId(), printerInfo));
|
||||
discoveredPrinterInfoList_[printerInfo->GetPrinterId()] = printerInfo;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user