| 1 | #include "PrinterController.h" |
| 2 | #include "PrintRunner.h" |
| 3 | #include "PagePrinter.h" |
| 4 | #include "HerculesStudio.h" |
| 5 | |
| 6 | /* |
| 7 | * PrinterController ---> runner -+-> PrinterSocket.connect |
| 8 | * V A V |
| 9 | * | | | |
| 10 | * | +---newData----- + |
| 11 | * | |
| 12 | * +-----------> Printer.print |
| 13 | */ |
| 14 | |
| 15 | PrinterController::PrinterController(PrinterItemConstPtr printerItem, PdfPrinterPtr printer) : |
| 16 | mPrinterItem(printerItem), mPrinter(printer), mRunner(NULL) |
| 17 | { |
| 18 | } |
| 19 | |
| 20 | PrinterController::~PrinterController() |
| 21 | { |
| 22 | |
| 23 | } |
| 24 | |
| 25 | void PrinterController::exec() |
| 26 | { |
| 27 | if (mRunner.isNull()) |
| 28 | { |
| 29 | mRunner = PrintRunnerPtr(new PrintRunner(mQueue, mPrinterItem, 132*80*2)); |
| 30 | connect(mRunner.data(), SIGNAL(newData()), this, SLOT(lineReceived())); |
| 31 | connect(mRunner.data(), SIGNAL(connected()), this, SIGNAL(connected())); |
| 32 | connect(mRunner.data(), SIGNAL(disconnected()), this, SIGNAL(disconnected())); |
| 33 | connect(mRunner.data(), SIGNAL(waiting()), this, SIGNAL(waiting())); |
| 34 | connect(mRunner.data(), SIGNAL(stoppedWaiting()), this, SIGNAL(stoppedWaiting())); |
| 35 | } |
| 36 | mRunner->start(); |
| 37 | hOutDebug(0,"Print runner started"); |
| 38 | } |
| 39 | |
| 40 | void PrinterController::stop() |
| 41 | { |
| 42 | if (!mRunner.isNull()) { |
| 43 | if (mRunner->isRunning()) |
| 44 | { |
| 45 | mRunner->stop(); |
| 46 | } |
| 47 | for (int i=0; i<10 && !mRunner->isFinished(); i++) |
| 48 | QThread::msleep(50); |
| 49 | mPrinter->close(); |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | |
| 54 | void PrinterController::lineReceived() |
| 55 | { |
| 56 | while(!mQueue.empty()) |
| 57 | { |
| 58 | mPrinter->print(mQueue.front()); |
| 59 | mQueue.pop_front(); |
| 60 | } |
| 61 | } |