Commit a7f1ca98 authored by Daniel Nicoletti's avatar Daniel Nicoletti

A few code improvements on configure-printer

parent 8771d213
......@@ -72,10 +72,10 @@ void ConfigurePrinterInterface::ConfigurePrinter(const QString &destName)
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);
const KCupsPrinters printers = request->printers();
for (const KCupsPrinter &p : printers) {
if (p.name() == destName) {
printer = p;
found = true;
break;
}
......
......@@ -60,7 +60,7 @@ void PrinterBehavior::setValues(const KCupsPrinter &printer)
for (const QString &value : errorPolicySupported) {
ui->errorPolicyCB->addItem(errorPolicyString(value), value);
}
QStringList errorPolicy = printer.errorPolicy();
const QStringList errorPolicy = printer.errorPolicy();
if (!errorPolicy.isEmpty()) {
defaultChoice = ui->errorPolicyCB->findData(errorPolicy.first());
ui->errorPolicyCB->setCurrentIndex(defaultChoice);
......@@ -72,7 +72,7 @@ void PrinterBehavior::setValues(const KCupsPrinter &printer)
for (const QString &value : opPolicySupported) {
ui->operationPolicyCB->addItem(operationPolicyString(value), value);
}
QStringList operationPolicy = printer.opPolicy();
const QStringList operationPolicy = printer.opPolicy();
if (!errorPolicy.isEmpty()) {
defaultChoice = ui->operationPolicyCB->findData(operationPolicy.first());
ui->operationPolicyCB->setCurrentIndex(defaultChoice);
......@@ -86,7 +86,7 @@ void PrinterBehavior::setValues(const KCupsPrinter &printer)
ui->startingBannerCB->addItem(jobSheetsString(value), value);
ui->endingBannerCB->addItem(jobSheetsString(value), value);
}
QStringList bannerPolicy = printer.jobSheetsDefault();
const QStringList bannerPolicy = printer.jobSheetsDefault();
if (bannerPolicy.size() == 2) {
defaultChoice = ui->startingBannerCB->findData(bannerPolicy.at(0));
ui->startingBannerCB->setCurrentIndex(defaultChoice);
......@@ -147,11 +147,10 @@ void PrinterBehavior::userListChanged()
ui-> usersELB->setEnabled(true);
}
QStringList currentList, defaultList;
currentList = ui->usersELB->items();
QStringList currentList = ui->usersELB->items();
// sort the list so we can be sure it's different
currentList.sort();
defaultList = ui->usersELB->property("defaultList").value<QStringList>();
const QStringList defaultList = ui->usersELB->property("defaultList").toStringList();
bool isDifferent = currentList != defaultList;
if (isDifferent == false && currentList.isEmpty() == false) {
......@@ -175,23 +174,26 @@ void PrinterBehavior::currentIndexChangedCB(int index)
{
auto comboBox = qobject_cast<QComboBox*>(sender());
bool isDifferent = comboBox->property("defaultChoice").toInt() != index;
qCDebug(PM_CONFIGURE_PRINTER) << Q_FUNC_INFO << "isDifferent" << isDifferent << this;
if (isDifferent != comboBox->property("different").toBool()) {
// it's different from the last time so add or remove changes
isDifferent ? m_changes++ : m_changes--;
comboBox->setProperty("different", isDifferent);
qCDebug(PM_CONFIGURE_PRINTER) << Q_FUNC_INFO << m_changes << this;
emit changed(m_changes);
}
QString attribute = comboBox->property("AttributeName").toString();
const QString attribute = comboBox->property("AttributeName").toString();
QVariant value;
// job-sheets-default has always two values
if (attribute == QLatin1String("job-sheets-default")) {
QStringList values;
values << ui->startingBannerCB->itemData(ui->startingBannerCB->currentIndex()).toString();
values << ui->endingBannerCB->itemData(ui->endingBannerCB->currentIndex()).toString();
value = values;
value = QStringList({
ui->startingBannerCB->itemData(ui->startingBannerCB->currentIndex()).toString(),
ui->endingBannerCB->itemData(ui->endingBannerCB->currentIndex()).toString()
});
} else {
value = comboBox->itemData(index).toString();
}
......
......@@ -249,8 +249,8 @@ QWidget* PrinterOptions::pickBoolean(ppd_option_t *option, const QString &keywor
for (i = 0, choice = option->choices;
i < option->num_choices;
++i, ++choice) {
QString choiceName = m_codec->toUnicode(choice->choice);
QString cText = m_codec->toUnicode(choice->text);
const QString choiceName = m_codec->toUnicode(choice->choice);
const QString cText = m_codec->toUnicode(choice->text);
auto button = new QRadioButton(cText, widget);
button->setChecked(defChoice == choiceName);
......@@ -307,13 +307,13 @@ QWidget* PrinterOptions::pickMany(ppd_option_t *option, const QString &keyword,
int i;
ppd_choice_t *choice;
QString oDefChoice = m_codec->toUnicode(option->defchoice);
const QString oDefChoice = m_codec->toUnicode(option->defchoice);
// Iterate over the choices in the option
for (i = 0, choice = option->choices;
i < option->num_choices;
++i, ++choice) {
QString cName = m_codec->toUnicode(choice->choice);
QString cText = m_codec->toUnicode(choice->text);
const QString cName = m_codec->toUnicode(choice->choice);
const QString cText = m_codec->toUnicode(choice->text);
auto item = new QStandardItem(cText);
item->setData(cName);
......@@ -333,14 +333,14 @@ QWidget* PrinterOptions::pickOne(ppd_option_t *option, const QString &keyword, Q
{
int i;
ppd_choice_t *choice;
QString defChoice = m_codec->toUnicode(option->defchoice);
const QString defChoice = m_codec->toUnicode(option->defchoice);
auto comboBox = new QComboBox(parent);
// Iterate over the choices in the option
for (i = 0, choice = option->choices;
i < option->num_choices;
++i, ++choice) {
QString cName = m_codec->toUnicode(choice->choice);
QString cText = m_codec->toUnicode(choice->text);
const QString cName = m_codec->toUnicode(choice->choice);
const QString cText = m_codec->toUnicode(choice->text);
comboBox->addItem(cText, cName);
}
......@@ -400,9 +400,10 @@ PrinterOptions::~PrinterOptions()
const char * /* O - Value of variable */
PrinterOptions::getVariable(const char *name) const /* I - Name of variable */
{
QString keyword = m_codec->toUnicode(name);
if (m_customValues.contains(keyword)) {
QString value = m_customValues[keyword]->property("currentChoice").toString();
const QString keyword = m_codec->toUnicode(name);
auto it = m_customValues.constFind(keyword);
if (it != m_customValues.constEnd()) {
const QString value = it.value()->property("currentChoice").toString();
return m_codec->fromUnicode(value).constData();
} else {
return NULL;
......
......@@ -61,7 +61,7 @@ int main(int argc, char **argv)
app.configurePrinter(printerName);
} else {
qCWarning(PM_CONFIGURE_PRINTER) << "No printer was specified";
return 1;
parser.showHelp(1);
}
return app.exec();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment