diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 87ad8e4..53eccc1 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -227,6 +227,16 @@ void MainWindow::onMenuPrintPreview() void MainWindow::onMenuPrint() { + QCDScene *cdscene = getScene( m_mdiArea ); + if( !cdscene ) + return; + + QLightScribe::PrintParameters params; + QLightDrive *drive = QDialogPrint::exec( this, params ); + if( !drive ) + return; + + QLightScribe::instance()->print( drive, params, cdscene ); } void MainWindow::onMenuSaveAs() diff --git a/src/qlightscribe.cpp b/src/qlightscribe.cpp index 16d92f6..bbeecdd 100644 --- a/src/qlightscribe.cpp +++ b/src/qlightscribe.cpp @@ -125,6 +125,8 @@ QPixmap QLightScribe::preview( QLightDrive *drive, const PrintParameters ¶ms m_task->m_size = size; m_task->m_image = printScene( scene ); + m_aborted = false; + m_waitQueue->wakeOne(); while( !m_task->m_done ) @@ -144,6 +146,8 @@ QPixmap QLightScribe::preview( QLightDrive *drive, const PrintParameters ¶ms return pixmap; } +#include + void QLightScribe::print( QLightDrive *drive, const PrintParameters ¶ms, QCDScene *scene ) { QMutexLocker lock( m_mutex ); @@ -155,11 +159,15 @@ void QLightScribe::print( QLightDrive *drive, const PrintParameters ¶ms, QCD m_task->m_parameters = params; m_task->m_image = printScene( scene ); + m_aborted = false; + m_waitQueue->wakeOne(); while( !m_task->m_done ) m_waitDone->wait( m_mutex ); + std::cout << "print Error: " << m_task->m_error.toStdString() << std::endl; + delete m_task; m_task = 0; } @@ -179,6 +187,32 @@ void QLightScribe::stopThread() const size_t bitmapHeaderSize = 54; +bool QLightScribe::clAbortLabel() +{ + return QLightScribe::instance()->m_aborted; +} + +void QLightScribe::clReportPrepareProgress(long current, long final) +{ + std::cout << "clReportPrepareProgress - " << current << " final: " << final << std::endl; +} + +void QLightScribe::clReportLabelProgress(long current, long final) +{ + std::cout << "clReportLabelProgress - " << current << " final: " << final << std::endl; +} + +void QLightScribe::clReportFinished(LSError status) +{ + std::cout << "clReporrFinished " << status << std::endl; +} + +bool QLightScribe::clReportLabelTimeEstimate(long time) +{ + std::cout << "clReportLabelTimeEstimate " << time << std::endl; + return false; +} + void QLightScribe::run() { QMutexLocker lock( m_mutex ); @@ -223,7 +257,7 @@ void QLightScribe::run() m_task->m_image->save( &buffer, "bmp", 100 ); int found = -1; - for( int i = 0; i < printers.Count(); ++i ) + for( size_t i = 0; i < printers.Count(); ++i ) if( printers.Item( i ).GetPrinterDisplayName() == m_task->m_selectedDrive->displayName().toStdString() ) { found = i; break; @@ -235,6 +269,15 @@ void QLightScribe::run() function = "LS_DiscPrinter_OpenPrintSession"; DiscPrintSession session = printer.OpenPrintSession(); + LS_PrintCallbacks callbacks; + callbacks.AbortLabel = clAbortLabel; + callbacks.ReportPrepareProgress = clReportPrepareProgress; + callbacks.ReportLabelProgress = clReportLabelProgress; + callbacks.ReportFinished = clReportFinished; + callbacks.ReportLabelTimeEstimate = clReportLabelTimeEstimate; + + session.SetProgressCallback( &callbacks ); + if( m_task->m_action == Task::preview ) { LS_Size size; @@ -259,12 +302,34 @@ void QLightScribe::run() true ); } else { // print here + function = "LS_DiscPrinter_LockDriveTray"; + //printer.LockDriveTray(); + + function = "LS_DiscPrinter_AddExclusiveUse"; + //printer.AddExclusiveUse(); + + function = "LS_DiscPrintSession_Print"; + session.PrintDisc( LS_windows_bitmap, + LS_LabelMode( m_task->m_parameters.m_labelMode ), + LS_DrawOptions( m_task->m_parameters.m_drawOptions ), + LS_PrintQuality( m_task->m_parameters.m_printQuality ), + LS_MediaOptimizationLevel( m_task->m_parameters.m_mediaOptimizationLevel ), + ba.data() + 14, + bitmapHeaderSize - 14, + ba.data() + bitmapHeaderSize, + ba.size() - bitmapHeaderSize ); + + function = "LS_DiscPrinter_ReleaseExclusiveUse"; + //printer.ReleaseExclusiveUse(); + + function = "LS_DiscPrinter_UnlockDriveTray"; + //printer.UnlockDriveTray(); } function = ""; } } catch( LightScribe::LSException &ex ) { - m_task->m_error = function + tr( " failed with code %n", 0, ex.GetCode() ); + m_task->m_error = function + tr( " failed with code 0x" ) + QString::number( ex.GetCode(), 16 ); } catch( const QString &err ) { m_task->m_error = err; diff --git a/src/qlightscribe.h b/src/qlightscribe.h index 733078a..f3f9f1f 100644 --- a/src/qlightscribe.h +++ b/src/qlightscribe.h @@ -26,6 +26,8 @@ #include +#include + class QCDScene; class QMutex; class QWaitCondition; @@ -93,6 +95,7 @@ public: QPixmap preview( QLightDrive *drive, const PrintParameters ¶ms, QCDScene *scene, const QSize &size ) throw( QString ); void print( QLightDrive *drive, const PrintParameters ¶ms, QCDScene *scene ); + friend bool clAbortLabel(); public slots: void abort(); void stopThread(); @@ -107,6 +110,12 @@ protected: virtual void run (); private: + static bool clAbortLabel(); + static void clReportPrepareProgress(long current, long final); + static void clReportLabelProgress(long current, long final); + static void clReportFinished(LSError status); + static bool clReportLabelTimeEstimate(long time); + QLightScribe(); virtual ~QLightScribe();