void PrinterModel::insertDest(int pos, const KCupsPrinter &printer) { // Create the printer item QStandardItem *stdItem = new QStandardItem(printer.name()); stdItem->setData(printer.name(), DestName); stdItem->setIcon(printer.icon()); // update the item updateDest(stdItem, printer); // insert the printer Item insertRow(pos, stdItem); }
void ConfigurePrinterInterface::ConfigurePrinter(const QString &destName) { if (!m_uis.contains(destName)) { // Reserve this since the CUPS call might take a long time m_uis[destName] = 0; QStringList att; att << KCUPS_PRINTER_NAME; att << KCUPS_PRINTER_TYPE; // Get destinations with these attributes KCupsRequest *request = new KCupsRequest; request->getPrinters(att); request->waitTillFinished(); bool found = false; KCupsPrinter printer; KCupsPrinters printers = request->printers(); for (int i = 0; i < printers.size(); i++) { if (printers.at(i).name() == destName) { printer = printers.at(i); found = true; break; } } request->deleteLater(); if (found) { ConfigureDialog *ui = new ConfigureDialog(printer.name(), printer.isClass()); connect(m_updateUi, SIGNAL(timeout()), ui, SLOT(update())); connect(ui, SIGNAL(finished()), this, SLOT(RemovePrinter())); ui->show(); m_uis[printer.name()] = ui; } else { // Remove the reservation m_uis.remove(destName); // if no destination was found and we aren't showing // a queue quit the app if (m_uis.isEmpty()) { emit quit(); } return; } } // Check it it's not reserved if (m_uis.value(destName)) { KWindowSystem::forceActiveWindow(m_uis.value(destName)->winId()); } }
void ModifyPrinter::setValues(const KCupsPrinter &printer) { // qCDebug(PM_CONFIGURE_PRINTER) << values; if (m_isClass) { ui->membersLV->setSelectedPrinters(printer.memberNames().join(QLatin1String("|"))); } else { ui->makeCB->clear(); ui->makeCB->setProperty("different", false); ui->makeCB->setProperty("lastIndex", 0); ui->makeCB->insertItem(0, i18n("Current - %1", printer.makeAndModel()), PPDDefault); ui->makeCB->insertSeparator(1); ui->makeCB->insertItem(2, i18n("Select a custom driver"), PPDList); } ui->membersLV->setProperty("different", false); ui->descriptionLE->setText(printer.info()); ui->descriptionLE->setProperty("orig_text", printer.info()); ui->descriptionLE->setProperty("different", false); ui->locationLE->setText(printer.location()); ui->locationLE->setProperty("orig_text", printer.location()); ui->locationLE->setProperty("different", false); ui->connectionLE->setText(printer.deviceUri()); ui->connectionLE->setProperty("orig_text", printer.deviceUri()); ui->connectionLE->setProperty("different", false); // clear old values m_changes = 0; m_changedValues.clear(); emit changed(0); }
void PrintersEngine::updatePrinterSource(const KCupsPrinter &printer) { QString source = printer.name(); Data sourceData = query(source); bool changed = false; if (sourceData[QLatin1String("printerName")] != printer.name()) { sourceData[QLatin1String("printerName")] = printer.name(); changed = true; } if (sourceData[QLatin1String("info")] != printer.info()) { sourceData[QLatin1String("info")] = printer.info(); changed = true; } QString state; switch (printer.state()) { case KCupsPrinter::Idle: state = QLatin1String("idle"); break; case KCupsPrinter::Printing: state = QLatin1String("printing"); break; case KCupsPrinter::Stoped: state = QLatin1String("stopped"); break; default: state = QLatin1String("unknown"); } if (sourceData[QLatin1String("stateEnum")] != state) { sourceData[QLatin1String("stateEnum")] = state; changed = true; } if (sourceData[QLatin1String("stateMessage")] != printer.stateMsg()) { sourceData[QLatin1String("stateMessage")] = printer.stateMsg(); changed = true; } if (sourceData[QLatin1String("iconName")] != printer.iconName()) { sourceData[QLatin1String("iconName")] = printer.iconName(); changed = true; } if (changed) { // update only if data changes to avoid uneeded updates on the views setData(source, sourceData); } kDebug() << source << changed; }
void PrinterBehavior::setValues(const KCupsPrinter &printer) { int defaultChoice; ui->errorPolicyCB->clear(); foreach (const QString &value, printer.errorPolicySupported()) { ui->errorPolicyCB->addItem(errorPolicyString(value), value); } QStringList errorPolicy = printer.errorPolicy(); if (!errorPolicy.isEmpty()) { defaultChoice = ui->errorPolicyCB->findData(errorPolicy.first()); ui->errorPolicyCB->setCurrentIndex(defaultChoice); ui->errorPolicyCB->setProperty("defaultChoice", defaultChoice); } ui->operationPolicyCB->clear(); foreach (const QString &value, printer.opPolicySupported()) { ui->operationPolicyCB->addItem(operationPolicyString(value), value); } QStringList operationPolicy = printer.opPolicy(); if (!errorPolicy.isEmpty()) { defaultChoice = ui->operationPolicyCB->findData(operationPolicy.first()); ui->operationPolicyCB->setCurrentIndex(defaultChoice); ui->operationPolicyCB->setProperty("defaultChoice", defaultChoice); } ui->startingBannerCB->clear(); ui->endingBannerCB->clear(); foreach (const QString &value, printer.jobSheetsSupported()) { ui->startingBannerCB->addItem(jobSheetsString(value), value); ui->endingBannerCB->addItem(jobSheetsString(value), value); } QStringList bannerPolicy = printer.jobSheetsDefault(); if (bannerPolicy.size() == 2) { defaultChoice = ui->startingBannerCB->findData(bannerPolicy.at(0)); ui->startingBannerCB->setCurrentIndex(defaultChoice); ui->startingBannerCB->setProperty("defaultChoice", defaultChoice); defaultChoice = ui->endingBannerCB->findData(bannerPolicy.at(1)); ui->endingBannerCB->setCurrentIndex(defaultChoice); ui->endingBannerCB->setProperty("defaultChoice", defaultChoice); } if (!printer.requestingUserNameAllowed().isEmpty()) { QStringList list = printer.requestingUserNameAllowed(); list.sort(); // sort the list here to be able to comapare it later ui->usersELB->setEnabled(true); if (list != ui->usersELB->items()) { ui->usersELB->clear(); ui->usersELB->insertStringList(list); } ui->usersELB->setProperty("defaultList", list); ui->allowRB->setProperty("defaultChoice", true); // Set checked AFTER the default choice was set // otherwise the signal will be emmited // which sets that we have a change ui->allowRB->setChecked(true); } else if (!printer.requestingUserNameDenied().isEmpty()) { QStringList list = printer.requestingUserNameDenied(); list.sort(); // sort the list here to be able to comapare it later ui->usersELB->setEnabled(true); if (list != ui->usersELB->items()) { ui->usersELB->clear(); ui->usersELB->insertStringList(list); } ui->usersELB->setProperty("defaultList", list); ui->allowRB->setProperty("defaultChoice", false); // Set checked AFTER the default choice was set // otherwise the signal will be emmited // which sets that we have a change ui->preventRB->setChecked(true); } // Clear previous changes m_changes = 0; emit changed(false); m_changedValues.clear(); ui->errorPolicyCB->setProperty("different", false); ui->operationPolicyCB->setProperty("different", false); ui->startingBannerCB->setProperty("different", false); ui->endingBannerCB->setProperty("different", false); ui->usersELB->setProperty("different", false); }
void PrinterModel::updateDest(QStandardItem *destItem, const KCupsPrinter &printer) { // store if the printer is the network default bool isDefault = printer.isDefault(); if (isDefault != destItem->data(DestIsDefault).toBool()) { destItem->setData(isDefault, DestIsDefault); } // store the printer state QString status = destStatus(printer.state(), printer.stateMsg()); if (status != destItem->data(DestStatus)) { destItem->setData(status, DestStatus); } // store if the printer is shared bool shared = printer.isShared(); if (shared != destItem->data(DestIsShared)) { destItem->setData(shared, DestIsShared); } // store if the printer is accepting jobs bool accepting = printer.isAcceptingJobs(); if (accepting != destItem->data(DestIsAcceptingJobs)) { destItem->setData(accepting, DestIsAcceptingJobs); } // store if the printer is a class // the printer-type param is a flag bool isClass = printer.isClass(); if (isClass != destItem->data(DestIsClass)) { destItem->setData(isClass, DestIsClass); } // store if the printer type // the printer-type param is a flag uint printerType = printer.type(); if (printerType != destItem->data(DestType)) { destItem->setData(printerType, DestType); } // store the printer location QString location = printer.location(); if (location != destItem->data(DestLocation).toString()) { destItem->setData(location, DestLocation); } if (destItem->data(DestName).toString() != destItem->text()){ if (destItem->text() != destItem->data(DestName).toString()){ destItem->setText(destItem->data(DestName).toString()); } } // store the printer description QString description = printer.info(); if (description != destItem->data(DestDescription).toString()){ destItem->setData(description, DestDescription); } // store the printer kind QString kind = printer.makeAndModel(); if (kind != destItem->data(DestKind)) { destItem->setData(kind, DestKind); } // store the printer commands QStringList commands = printer.commands(); if (commands != destItem->data(DestCommands)) { destItem->setData(commands, DestCommands); } int markerChangeTime = printer.markerChangeTime(); if (markerChangeTime != destItem->data(DestMarkerChangeTime)) { destItem->setData(printer.markerChangeTime(), DestMarkerChangeTime); QVariantHash markers; markers["marker-change-time"] = printer.markerChangeTime(); markers["marker-colors"] = printer.argument("marker-colors"); markers["marker-levels"] = printer.argument("marker-levels"); markers["marker-names"] = printer.argument("marker-names"); markers["marker-types"] = printer.argument("marker-types"); destItem->setData(markers, DestMarkers); } }
ConfigureDialog::ConfigureDialog(const QString &destName, bool isClass, QWidget *parent) : KPageDialog(parent) { setFaceType(List); setModal(false); setStandardButtons(QDialogButtonBox::Ok | QDialogButtonBox::Cancel | QDialogButtonBox::Apply); setWindowTitle(destName); setWindowIcon(QIcon::fromTheme("configure")); enableButtonApply(false); // Needed so we have our dialog size saved setAttribute(Qt::WA_DeleteOnClose); QStringList attr; KPageWidgetItem *page; modifyPrinter = new ModifyPrinter(destName, isClass, this); PrinterBehavior *printerBehavior = new PrinterBehavior(destName, isClass, this); attr << modifyPrinter->neededValues(); attr << printerBehavior->neededValues(); attr << KCUPS_PRINTER_TYPE; // needed to know if it's a remote printer attr << KCUPS_PRINTER_MAKE_AND_MODEL; KCupsPrinter printer; QPointer<KCupsRequest> request = new KCupsRequest; request->getPrinterAttributes(destName, isClass, attr); request->waitTillFinished(); if (!request) { return; } if (!request->hasError() && !request->printers().isEmpty()){ printer = request->printers().first(); } // qCDebug(PM_CONFIGURE_PRINTER) << "VALUES" << printer.a rgument(); // qCDebug(PM_CONFIGURE_PRINTER) << "marker" << values["marker-levels"].value<QList<int> >(); request->deleteLater(); // qCDebug(PM_CONFIGURE_PRINTER) << values; if (printer.type() & CUPS_PRINTER_LOCAL) { qCDebug(PM_CONFIGURE_PRINTER) << "CUPS_PRINTER_LOCAL"; } isClass = printer.isClass(); bool isRemote = false; if (printer.type() & CUPS_PRINTER_REMOTE) { qCDebug(PM_CONFIGURE_PRINTER) << "CUPS_PRINTER_REMOTE"; isRemote = true; } if (printer.type() & CUPS_PRINTER_BW) { qCDebug(PM_CONFIGURE_PRINTER) << "CUPS_PRINTER_BW"; } if (printer.type() & CUPS_PRINTER_COLOR) { qCDebug(PM_CONFIGURE_PRINTER) << "CUPS_PRINTER_COLOR"; } if (printer.type() & CUPS_PRINTER_MFP) { qCDebug(PM_CONFIGURE_PRINTER) << "CUPS_PRINTER_MFP"; } modifyPrinter->setRemote(isRemote); modifyPrinter->setValues(printer); page = new KPageWidgetItem(modifyPrinter, i18n("Modify Printer")); page->setHeader(i18n("Configure")); page->setIcon(QIcon::fromTheme("dialog-information")); // CONNECT this signal ONLY to the first Page connect(modifyPrinter, SIGNAL(changed(bool)), this, SLOT(enableButtonApply(bool))); addPage(page); if (!isClass) { // At least on localhost:631 modify printer does not show printer options // for classes printerOptions = new PrinterOptions(destName, isClass, isRemote, this); page = new KPageWidgetItem(printerOptions, i18n("Printer Options")); page->setHeader(i18n("Set the Default Printer Options")); page->setIcon(QIcon::fromTheme("view-pim-tasks")); addPage(page); connect(modifyPrinter, SIGNAL(ppdChanged()), this, SLOT(ppdChanged())); modifyPrinter->setCurrentMake(printerOptions->currentMake()); modifyPrinter->setCurrentMakeAndModel(printerOptions->currentMakeAndModel()); } printerBehavior->setRemote(isRemote); printerBehavior->setValues(printer); page = new KPageWidgetItem(printerBehavior, i18n("Banners, Policies and Allowed Users")); page->setHeader(i18n("Banners, Policies and Allowed Users")); page->setIcon(QIcon::fromTheme("feed-subscribe")); addPage(page); // connect this after ALL pages were added, otherwise the slot will be called connect(this, SIGNAL(currentPageChanged(KPageWidgetItem*,KPageWidgetItem*)), SLOT(currentPageChanged(KPageWidgetItem*,KPageWidgetItem*))); KConfigGroup group(KSharedConfig::openConfig("print-manager"), "ConfigureDialog"); KWindowConfig::restoreWindowSize(windowHandle(), group); connect(buttonBox(), SIGNAL(clicked(QAbstractButton*)), this, SLOT(slotButtonClicked(QAbstractButton*))); }