Subversion Repositories Scribus

Rev

Rev 4504 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
4485 cbradney 1
/*
2
For general Scribus (>=1.3.2) copyright and licensing information please refer
3
to the COPYING file provided with the program. Following this notice may exist
4
a copyright and/or license notice that predates the release of Scribus 1.3.2
5
for which a new license (GPL+exception) is in place.
6
*/
7
#include "printerutil.h"
8
 
9
#if defined( HAVE_CUPS )
10
 #include <cups/cups.h>
11
#elif defined(_WIN32)
12
 #include <windows.h>
13
 #include <winspool.h>
14
#endif
15
 
16
#include <qstringlist.h>
17
 
18
#include "util.h"
19
 
20
QStringList PrinterUtil::getPrinterNames()
21
{
22
        QString printerName;
23
        QStringList printerNames;
24
#if defined (HAVE_CUPS)
25
        cups_dest_t *dests;
26
        int num_dests = cupsGetDests(&dests);
27
        for (int pr = 0; pr < num_dests; ++pr)
28
        {
29
                printerName = QString(dests[pr].name);
30
                printerNames.append(printerName);
31
        }
32
        cupsFreeDests(num_dests, dests);
33
#elif defined(_WIN32)
34
        DWORD size;
35
        DWORD numPrinters;
36
        PRINTER_INFO_2* printerInfos = NULL;
37
    EnumPrinters ( PRINTER_ENUM_LOCAL|PRINTER_ENUM_CONNECTIONS , NULL, 2, NULL, 0, &size, &numPrinters );
38
        printerInfos = (PRINTER_INFO_2*) malloc(size);
39
        if ( EnumPrinters ( PRINTER_ENUM_LOCAL|PRINTER_ENUM_CONNECTIONS, NULL, 2, (LPBYTE) printerInfos, size, &size, &numPrinters ) )
40
        {
41
                for ( uint i = 0; i < numPrinters; i++)
42
                {
43
                        printerName = printerInfos[i].pPrinterName;
44
                        printerNames.append(printerName);
45
                }
46
                printerNames.sort();   
47
        }
48
        if ( printerInfos) free(printerInfos);
49
#else
50
        QString tmp;
51
        QString Pcap;
52
        QStringList wt;
53
        if (loadText("/etc/printcap", &Pcap))
54
        {
55
                QTextStream ts(&Pcap, IO_ReadOnly);
56
                while(!ts.atEnd())
57
                {
58
                        tmp = ts.readLine();
59
                        if (tmp.isEmpty())
60
                                continue;
61
                        if ((tmp[0] != '#') && (tmp[0] != ' ') && (tmp[0] != '\n') && (tmp[0] != '\t'))
62
                        {
63
                                tmp = tmp.stripWhiteSpace();
64
                                tmp = tmp.left(tmp.length() - (tmp.right(2) == ":\\" ? 2 : 1));
65
                                wt = QStringList::split("|", tmp);
66
                                printerName = wt[0];
67
                                printerNames.append(printerName);
68
                        }
69
                }
70
        }
71
#endif
72
        return printerNames;
73
}