Exemple #1
0
bool PPDLoader::putFooProcessedData(const QVariant &var)
{
    QMap< QString, QVariant >::ConstIterator it = var.mapFind("args_byname");
    if(it != var.mapEnd())
    {
        QVariant opts = it.data();
        for(it = opts.mapBegin(); it != opts.mapEnd(); ++it)
        {
            QMap< QString, QVariant > opt = it.data().toMap();
            QString type = opt["type"].toString();
            if(type == "float" || type == "int")
            {
                DrBase *o;
                if(type == "float")
                    o = new DrFloatOption;
                else
                    o = new DrIntegerOption;
                o->setName(opt["name"].toString());
                o->set("text", opt["comment"].toString());
                o->set("minval", opt["min"].toString());
                o->set("maxval", opt["max"].toString());
                o->set("default", opt["default"].toString());
                o->setValueText(o->get("default"));

                DrGroup *grp = 0;
                DrBase *old = m_groups.top()->findOption(o->name(), &grp);
                if(old)
                {
                    if(old->type() == DrBase::List)
                    {
                        QStringList vals;
                        QPtrListIterator< DrBase > it(*(static_cast< DrListOption * >(old)->choices()));
                        for(; it.current(); ++it)
                            vals.append(it.current()->name());
                        o->set("fixedvals", vals.join("|"));
                    }
                    grp->removeOption(o->name());
                    grp->addOption(o);
                }
                else
                {
                    qWarning("Option %s not found in original PPD file", o->name().latin1());
                    delete o;
                }
            }
        }
    }
    return true;
}
Exemple #2
0
void KXmlCommandAdvancedDlg::viewItem(TQListViewItem *item)
{
	m_dummy->setEnabled((item != 0));
	m_name->setText("");
	m_desc->setText("");
	m_format->setText("");
	m_default->setText("");
	m_values->clear();
	m_edit1->setText("");
	m_edit2->setText("");
	m_persistent->setChecked( false );
	int	typeId(-1);
	if (item)
	{
		m_name->setText(item->text(1));
		m_desc->setText(item->text(0));

		DrBase	*opt = (m_opts.contains(item->text(1)) ? m_opts[item->text(1)] : 0);
		if (opt)
		{
			bool	isgroup = (opt->type() < DrBase::String);
			if (!isgroup)
			{
				m_type->setCurrentItem(opt->type() - DrBase::String);
				typeId = m_type->currentItem();
				m_format->setText(opt->get("format"));
				m_default->setText(opt->get("default"));
			}
			m_type->setEnabled(!isgroup);
			m_default->setEnabled(!isgroup);
			m_format->setEnabled(!isgroup);
			m_stack->setEnabled(!isgroup);

			switch (opt->type())
			{
				case DrBase::Float:
				case DrBase::Integer:
					m_edit1->setText(opt->get("minval"));
					m_edit2->setText(opt->get("maxval"));
					break;
				case DrBase::Boolean:
				case DrBase::List:
					{
						TQPtrListIterator<DrBase>	it(*(static_cast<DrListOption*>(opt)->choices()));
						TQListViewItem	*item(0);
						for (; it.current(); ++it)
						{
							item = new TQListViewItem(m_values, item, it.current()->name(), it.current()->get("text"));
							item->setRenameEnabled(0, true);
							item->setRenameEnabled(1, true);
						}
						break;
					}
				default:
					break;
			}

			m_addgrp->setEnabled(isgroup);
			m_addopt->setEnabled(isgroup);

			TQListViewItem	*prevItem = findPrev(item), *nextItem = findNext(item);
			DrBase	*prevOpt = (prevItem && m_opts.contains(prevItem->text(1)) ? m_opts[prevItem->text(1)] : 0);
			DrBase	*nextOpt = (nextItem && m_opts.contains(nextItem->text(1)) ? m_opts[nextItem->text(1)] : 0);
			m_up->setEnabled(prevOpt && !(prevOpt->type() < DrBase::String && opt->type() >= DrBase::String));
			m_down->setEnabled(nextOpt && !(isgroup && nextOpt->type() >= DrBase::String));

			m_persistent->setChecked( opt->get( "persistent" ) == "1" );
		}

		m_delopt->setEnabled(true);
		m_dummy->setEnabled(opt);
	}
	else
	{
		m_delopt->setEnabled(false);
		m_addopt->setEnabled(m_view->currentItem() && m_view->isEnabled());
		m_addgrp->setEnabled(m_view->currentItem() && m_view->isEnabled());
		m_up->setEnabled(false);
		m_down->setEnabled(false);
	}
	slotTypeChanged(typeId);
	m_apply->setEnabled(false);
}
Exemple #3
0
void KXmlCommandAdvancedDlg::slotApplyChanges()
{
	TQListViewItem	*item = m_view->currentItem();
	if (item)
	{
		if (m_name->text().isEmpty() || m_name->text() == "__root__")
		{
			KMessageBox::error(this, i18n("Invalid identification name. Empty strings and \"__root__\" are not allowed."));
			return;
		}

		m_apply->setEnabled(false);

		DrBase	*opt = (m_opts.contains(item->text(1)) ? m_opts[item->text(1)] : 0);
		m_opts.remove(item->text(1));
		delete opt;

		// update tree item
		item->setText(0, m_desc->text());
		item->setText(1, m_name->text());

		// recreate option
		if (m_type->isEnabled())
		{
			int	type = m_type->currentItem() + DrBase::String;
			switch (type)
			{
				case DrBase::Integer:
				case DrBase::Float:
					if (type == DrBase::Integer)
						opt = new DrIntegerOption;
					else
						opt = new DrFloatOption;
					opt->set("minval", m_edit1->text());
					opt->set("maxval", m_edit2->text());
					break;
				case DrBase::List:
				case DrBase::Boolean:
					{
						if (type == DrBase::List)
							opt = new DrListOption;
						else
							opt = new DrBooleanOption;
						DrListOption	*lopt = static_cast<DrListOption*>(opt);
						TQListViewItem	*item = m_values->firstChild();
						while (item)
						{
							DrBase	*choice = new DrBase;
							choice->setName(item->text(0));
							choice->set("text", item->text(1));
							lopt->addChoice(choice);
							item = item->nextSibling();
						}
						break;
					}
				case DrBase::String:
					opt = new DrStringOption;
					break;

			}
			opt->set("format", m_format->text());
			opt->set("default", m_default->text());
			opt->setValueText(opt->get("default"));
		}
		else
			opt = new DrGroup;

		opt->setName((m_name->text().isEmpty() ? generateId(m_opts) : m_name->text()));
		opt->set("text", m_desc->text());
		opt->set( "persistent", m_persistent->isChecked() ? "1" : "0" );

		m_opts[opt->name()] = opt;
	}
}
Exemple #4
0
void KPrinterImpl::preparePrinting(KPrinter *printer)
{
	// page size -> try to find page size and margins from driver file
	// use "PageSize" as option name to find the wanted page size. It's
	// up to the driver loader to use that option name.
	KMManager	*mgr = KMFactory::self()->manager();
	DrMain	*driver = mgr->loadPrinterDriver(mgr->findPrinter(printer->printerName()), false);
	if (driver)
	{
		// Find the page size:
		// 1) print option
		// 2) default driver option
		QString	psname = printer->option("PageSize");
		if (psname.isEmpty())
		{
			DrListOption	*opt = (DrListOption*)driver->findOption("PageSize");
			if (opt) psname = opt->get("default");
		}
		if (!psname.isEmpty())
		{
			printer->setOption("kde-pagesize",TQString::number((int)pageNameToPageSize(psname)));
			DrPageSize	*ps = driver->findPageSize(psname);
			if (ps)
			{
				printer->setRealPageSize( ps );
			}
		}

		// Find the numerical resolution
		// 1) print option (Resolution)
		// 2) default driver option (Resolution)
		// 3) default printer resolution
		// The resolution must have the format: XXXdpi or XXXxYYYdpi. In the second
		// case the YYY value is used as resolution.
		TQString res = printer->option( "Resolution" );
		if ( res.isEmpty() )
		{
			DrBase *opt = driver->findOption( "Resolution" );
			if ( opt )
				res = opt->get( "default" );
			if ( res.isEmpty() )
				res = driver->get( "resolution" );
		}
		if ( !res.isEmpty() )
		{
			TQRegExp re( "(\\d+)(?:x(\\d+))?dpi" );
			if ( re.search( res ) != -1 )
			{
				if ( !re.cap( 2 ).isEmpty() )
					printer->setOption( "kde-resolution", re.cap( 2 ) );
				else
					printer->setOption( "kde-resolution", re.cap( 1 ) );
			}
		}

		// Find the supported fonts
		TQString fonts = driver->get( "fonts" );
		if ( !fonts.isEmpty() )
			printer->setOption( "kde-fonts", fonts );

		delete driver;
	}

}