27static const char *pt_pagesize[] = {
 
   28    "ledger", I18N_NOOP(
"Ledger"),
 
   29    "legal", I18N_NOOP(
"US Legal"),
 
   30    "letter", I18N_NOOP(
"US Letter"),
 
   31    "a4", I18N_NOOP(
"A4"),
 
   32    "a3", I18N_NOOP(
"A3"),
 
   33    "b4", I18N_NOOP(
"B4"),
 
   34    "b5", I18N_NOOP(
"B5"),
 
   37static int pt_nup[] = { 1, 2, 4, 8, -1 };
 
   38static const char *pt_bool[] = {
 
   39    "YES", I18N_NOOP(
"Enabled"),
 
   40    "NO", I18N_NOOP(
"Disabled"),
 
   44void setupBooleanOption(DrBooleanOption *opt)
 
   49        DrBase  *ch = 
new DrBase();
 
   50        ch->setName(pt_bool[i++]);
 
   51        ch->set(
"text",pt_bool[i++]);
 
   56TQString nextWord(
const TQString& s, 
int& pos)
 
   59    while (s[p1].isSpace() && p1 < (
int)s.length()) p1++;
 
   68        while (!s[p2].isSpace() && p2 < (
int)s.length()) p2++;
 
   71    return s.mid(p1,p2-p1);
 
   76bool PrintcapEntry::readLine(
const TQString& line)
 
   78    QStringList l = TQStringList::split(
':',line,
false);
 
   84        if ((p=m_name.find(
'|')) != -1)
 
   85            m_name = m_name.left(p);
 
   87        for (uint i=1; i<l.count(); i++)
 
   89            int p = l[i].find(
'=');
 
   91            TQString    key = l[i].left(p);
 
   92            TQString    value = l[i].right(l[i].length()-(l[i][p] == 
'=' ? p+1 : p));
 
  100void PrintcapEntry::writeEntry(TQTextStream& t)
 
  102    if (m_comment.isEmpty()) t << 
"# Entry for printer " << m_name << endl;
 
  103    else t << m_comment << endl;
 
  105    for (TQMap<TQString,TQString>::ConstIterator it=m_args.begin(); it!=m_args.end(); ++it)
 
  107        t << 
"\\\n\t:" << it.key();
 
  108        if (!it.data().isEmpty())
 
  109            t << ((*it)[0] == 
'#' ? 
"" : 
"=") << *it;
 
  115TQString PrintcapEntry::comment(
int index)
 
  118    if (m_comment.startsWith(
"##PRINTTOOL3##"))
 
  121        for (
int i=0;i<index;i++)
 
  122            w = nextWord(m_comment,p);
 
  127KMPrinter* PrintcapEntry::createPrinter()
 
  129    KMPrinter   *printer = 
new KMPrinter();
 
  130    printer->setName(m_name);
 
  131    printer->setPrinterName(m_name);
 
  132    printer->setInstanceName(TQString::null);
 
  133    printer->setState(KMPrinter::Idle);
 
  134    printer->setType(KMPrinter::Printer);
 
  140TQStringList splitPrinttoolLine(
const TQString& line)
 
  143    int         p = line.find(
':');
 
  146        l.append(line.left(p));
 
  147        p = line.find(
'{',p);
 
  149            l.append(line.right(line.length()-l[0].length()-1).stripWhiteSpace());
 
  154                int     q = line.find(
'}',p);
 
  157                    l.append(line.mid(p+1,q-p-1));
 
  158                    p = line.find(
'{',q);
 
  167bool PrinttoolEntry::readEntry(TQTextStream& t)
 
  172    m_resolutions.setAutoDelete(
true);
 
  173    m_depths.setAutoDelete(
true);
 
  174    m_resolutions.clear();
 
  178        line = getPrintcapLine(t);
 
  181        if (line == 
"EndEntry")
 
  182            return !m_name.isEmpty();
 
  183        QStringList l = splitPrinttoolLine(line);
 
  186            if (l[0] == 
"StartEntry") m_name = l[1];
 
  187            else if (l[0] == 
"GSDriver") m_gsdriver = l[1];
 
  188            else if (l[0] == 
"About") m_about = l[1];
 
  189            else if (l[0] == 
"Description") m_description = l[1];
 
  190            else if (l[0] == 
"Resolution" && l.count() > 2)
 
  192                Resolution  *resol = 
new Resolution;
 
  194                resol->xdpi = l[1].toInt(&ok);
 
  195                if (ok) resol->ydpi = l[2].toInt(&ok);
 
  197                    resol->comment = l[3];
 
  198                if (ok) m_resolutions.append(resol);
 
  201            else if (l[0] == 
"BitsPerPixel" && l.count() > 1)
 
  203                BitsPerPixel    *dpth = 
new BitsPerPixel;
 
  206                    dpth->comment = l[2];
 
  207                m_depths.append(dpth);
 
  214DrMain* PrinttoolEntry::createDriver()
 
  217    DrMain  *dr = 
new DrMain();
 
  219    dr->set(
"description",m_description);
 
  220    dr->set(
"text",m_description);
 
  221    dr->set(
"drtype",
"printtool");
 
  224    DrListOption    *lopt(0);
 
  225    DrStringOption  *sopt(0);
 
  226    DrBooleanOption *bopt(0);
 
  229    if (m_gsdriver != 
"TEXT")
 
  233        gr->set(
"text",i18n(
"GhostScript settings"));
 
  237        lopt = 
new DrListOption();
 
  238        lopt->setName(
"GSDEVICE");
 
  239        lopt->set(
"text",i18n(
"Driver"));
 
  240        lopt->set(
"default",m_gsdriver);
 
  243        ch->setName(m_gsdriver);
 
  244        ch->set(
"text",m_gsdriver);
 
  246        lopt->setValueText(m_gsdriver);
 
  250        if (m_resolutions.count() > 0)
 
  252            lopt = 
new DrListOption();
 
  253            lopt->setName(
"RESOLUTION");
 
  254            lopt->set(
"text",i18n(
"Resolution"));
 
  256            TQPtrListIterator<Resolution>   it(m_resolutions);
 
  257            for (
int i=0;it.current();++it,i++)
 
  260                ch->setName(TQString::fromLatin1(
"%1x%2").arg(it.current()->xdpi).arg(it.current()->ydpi));
 
  261                if (it.current()->comment.isEmpty())
 
  262                    ch->set(
"text",TQString::fromLatin1(
"%1x%2 DPI").arg(it.current()->xdpi).arg(it.current()->ydpi));
 
  264                    ch->set(
"text",TQString::fromLatin1(
"%2x%3 DPI (%1)").arg(it.current()->comment).arg(it.current()->xdpi).arg(it.current()->ydpi));
 
  267            TQString    defval = lopt->choices()->first()->name();
 
  268            lopt->set(
"default",defval);
 
  269            lopt->setValueText(defval);
 
  273        if (m_depths.count() > 0)
 
  275            lopt = 
new DrListOption();
 
  276            lopt->setName(
"COLOR");
 
  277            lopt->set(
"text",i18n(
"Color depth"));
 
  279            TQPtrListIterator<BitsPerPixel> it(m_depths);
 
  280            for (
int i=0;it.current();++it,i++)
 
  283                if (m_gsdriver != 
"uniprint")
 
  284                    ch->setName(TQString::fromLatin1(
"-dBitsPerPixel=%1").arg(it.current()->bpp));
 
  286                    ch->setName(it.current()->bpp);
 
  287                if (it.current()->comment.isEmpty())
 
  288                    ch->set(
"text",it.current()->bpp);
 
  290                    ch->set(
"text",TQString::fromLatin1(
"%1 - %2").arg(it.current()->bpp).arg(it.current()->comment));
 
  293            TQString    defval = lopt->choices()->first()->name();
 
  294            lopt->set(
"default",defval);
 
  295            lopt->setValueText(defval);
 
  299        sopt = 
new DrStringOption;
 
  300        sopt->setName(
"EXTRA_GS_OPTIONS");
 
  301        sopt->set(
"text",i18n(
"Additional GS options"));
 
  307    gr->set(
"text",i18n(
"General"));
 
  311    lopt = 
new DrListOption();
 
  312    lopt->setName(
"PAPERSIZE");
 
  313    lopt->set(
"text",i18n(
"Page size"));
 
  314    lopt->set(
"default",
"letter");
 
  317    while (pt_pagesize[i])
 
  320        ch->setName(pt_pagesize[i++]);
 
  321        ch->set(
"text",i18n(pt_pagesize[i++]));
 
  324    lopt->setValueText(
"letter");
 
  327    lopt = 
new DrListOption();
 
  328    lopt->setName(
"NUP");
 
  329    lopt->set(
"text",i18n(
"Pages per sheet"));
 
  330    lopt->set(
"default",
"1");
 
  333    while (pt_nup[i] != -1)
 
  336        ch->setName(TQString::number(pt_nup[i++]));
 
  337        ch->set(
"text",ch->name());
 
  340    lopt->setValueText(
"1");
 
  343    sopt = 
new DrStringOption();
 
  344    sopt->setName(
"RTLFTMAR");
 
  345    sopt->set(
"text",i18n(
"Left/right margin (1/72 in)"));
 
  346    sopt->setValueText(
"18");
 
  348    sopt = 
new DrStringOption();
 
  349    sopt->setName(
"TOPBOTMAR");
 
  350    sopt->set(
"text",i18n(
"Top/bottom margin (1/72 in)"));
 
  351    sopt->setValueText(
"18");
 
  356    gr->set(
"text",i18n(
"Text options"));
 
  360    bopt = 
new DrBooleanOption();
 
  361    bopt->setName(
"TEXT_SEND_EOF");
 
  362    bopt->set(
"text",i18n(
"Send EOF after job to eject page"));
 
  364    setupBooleanOption(bopt);
 
  365    bopt->setValueText(
"NO");
 
  368    bopt = 
new DrBooleanOption();
 
  369    bopt->setName(
"CRLFTRANS");
 
  370    bopt->set(
"text",i18n(
"Fix stair-stepping text"));
 
  372    setupBooleanOption(bopt);
 
  373    bopt->choices()->first()->setName(
"1");
 
  374    bopt->choices()->last()->setName(
"0");
 
  375    bopt->setValueText(
"0");
 
  377    if (m_gsdriver != 
"POSTSCRIPT")
 
  380        bopt = 
new DrBooleanOption();
 
  381        bopt->setName(
"ASCII_TO_PS");
 
  382        bopt->set(
"text",i18n(
"Fast text printing (non-PS printers only)"));
 
  384        setupBooleanOption(bopt);
 
  385        bopt->choices()->first()->setName(
"NO");
 
  386        bopt->choices()->last()->setName(
"YES");
 
  387        bopt->setValueText(
"NO");
 
  395TQString getPrintcapLine(TQTextStream& t, TQString *lastcomment)
 
  397    TQString    line, buffer, comm;
 
  400        buffer = t.readLine().stripWhiteSpace();
 
  401        if (buffer.isEmpty() || buffer[0] == 
'#')
 
  407        if (line.right(1) == 
"\\")
 
  409            line.truncate(line.length()-1);
 
  410            line = line.stripWhiteSpace();