LCOV - code coverage report
Current view: top level - svtools/source/dialogs - prnsetup.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 197 0.0 %
Date: 2014-04-14 Functions: 0 22 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <svtools/prnsetup.hxx>
      21             : #include <svtools/svtools.hrc>
      22             : #include <svtools/svtresid.hxx>
      23             : #include <vcl/print.hxx>
      24             : 
      25             : 
      26             : 
      27           0 : void ImplFillPrnDlgListBox( const Printer* pPrinter,
      28             :                             ListBox* pBox, PushButton* pPropBtn )
      29             : {
      30           0 :     ImplFreePrnDlgListBox( pBox );
      31             : 
      32           0 :     const std::vector<OUString>& rPrinters = Printer::GetPrinterQueues();
      33           0 :     unsigned int nCount = rPrinters.size();
      34           0 :     if ( nCount )
      35             :     {
      36           0 :         for( unsigned int i = 0; i < nCount; i++ )
      37           0 :             pBox->InsertEntry( rPrinters[i] );
      38           0 :         pBox->SelectEntry( pPrinter->GetName() );
      39             :     }
      40             : 
      41           0 :     pBox->Enable( nCount != 0 );
      42           0 :     pPropBtn->Show( pPrinter->HasSupport( SUPPORT_SETUPDIALOG ) );
      43           0 : }
      44             : 
      45             : 
      46             : 
      47           0 : void ImplFreePrnDlgListBox( ListBox* pBox, bool bClear )
      48             : {
      49           0 :     if ( bClear )
      50           0 :         pBox->Clear();
      51           0 : }
      52             : 
      53             : 
      54             : 
      55           0 : Printer* ImplPrnDlgListBoxSelect( ListBox* pBox, PushButton* pPropBtn,
      56             :                                   Printer* pPrinter, Printer* pTempPrinter )
      57             : {
      58           0 :     if ( pBox->GetSelectEntryPos() != LISTBOX_ENTRY_NOTFOUND )
      59             :     {
      60           0 :         const QueueInfo* pInfo = Printer::GetQueueInfo( pBox->GetSelectEntry(), true );
      61           0 :         if( pInfo)
      62             :         {
      63           0 :             if ( !pTempPrinter )
      64             :             {
      65           0 :                 if ( (pPrinter->GetName() == pInfo->GetPrinterName()) &&
      66           0 :                      (pPrinter->GetDriverName() == pInfo->GetDriver()) )
      67           0 :                     pTempPrinter = new Printer( pPrinter->GetJobSetup() );
      68             :                 else
      69           0 :                     pTempPrinter = new Printer( *pInfo );
      70             :             }
      71             :             else
      72             :             {
      73           0 :                 if ( (pTempPrinter->GetName() != pInfo->GetPrinterName()) ||
      74           0 :                      (pTempPrinter->GetDriverName() != pInfo->GetDriver()) )
      75             :                 {
      76           0 :                     delete pTempPrinter;
      77           0 :                     pTempPrinter = new Printer( *pInfo );
      78             :                 }
      79             :             }
      80             : 
      81           0 :             pPropBtn->Enable( pTempPrinter->HasSupport( SUPPORT_SETUPDIALOG ) );
      82             :         }
      83             :         else
      84           0 :             pPropBtn->Disable();
      85             :     }
      86             :     else
      87           0 :         pPropBtn->Disable();
      88             : 
      89           0 :     return pTempPrinter;
      90             : }
      91             : 
      92             : 
      93             : 
      94           0 : Printer* ImplPrnDlgUpdatePrinter( Printer* pPrinter, Printer* pTempPrinter )
      95             : {
      96           0 :     OUString aPrnName;
      97           0 :     if ( pTempPrinter )
      98           0 :         aPrnName = pTempPrinter->GetName();
      99             :     else
     100           0 :         aPrnName = pPrinter->GetName();
     101             : 
     102           0 :     if ( ! Printer::GetQueueInfo( aPrnName, false ) )
     103             :     {
     104           0 :         if ( pTempPrinter )
     105           0 :             delete pTempPrinter;
     106           0 :         pTempPrinter = new Printer;
     107             :     }
     108             : 
     109           0 :     return pTempPrinter;
     110             : }
     111             : 
     112             : 
     113             : 
     114           0 : void ImplPrnDlgUpdateQueueInfo( ListBox* pBox, QueueInfo& rInfo )
     115             : {
     116           0 :     if ( pBox->GetSelectEntryPos() != LISTBOX_ENTRY_NOTFOUND )
     117             :     {
     118           0 :         const QueueInfo* pInfo = Printer::GetQueueInfo( pBox->GetSelectEntry(), true );
     119           0 :         if( pInfo )
     120           0 :             rInfo = *pInfo;
     121             :     }
     122           0 : }
     123             : 
     124             : 
     125             : 
     126           0 : static OUString ImplPrnDlgAddString(const OUString& rStr, const OUString& rAddStr)
     127             : {
     128           0 :     OUString aStr(rStr);
     129           0 :     if (!aStr.isEmpty())
     130           0 :         aStr += "; " ;
     131           0 :     return aStr + rAddStr;
     132             : }
     133             : 
     134             : 
     135             : 
     136           0 : static OUString ImplPrnDlgAddResString(const OUString& rStr, sal_uInt16 nResId)
     137             : {
     138           0 :     return ImplPrnDlgAddString(rStr, SVT_RESSTR(nResId));
     139             : }
     140             : 
     141             : 
     142             : 
     143           0 : OUString ImplPrnDlgGetStatusText( const QueueInfo& rInfo )
     144             : {
     145           0 :     OUString aStr;
     146           0 :     sal_uLong nStatus = rInfo.GetStatus();
     147             : 
     148             :     // Default-Printer
     149           0 :     if ( !rInfo.GetPrinterName().isEmpty() &&
     150           0 :          (rInfo.GetPrinterName() == Printer::GetDefaultPrinterName()) )
     151           0 :         aStr = ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_DEFPRINTER );
     152             : 
     153             :     // Status
     154           0 :     if ( nStatus & QUEUE_STATUS_READY )
     155           0 :         aStr = ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_READY );
     156           0 :     if ( nStatus & QUEUE_STATUS_PAUSED )
     157           0 :         aStr = ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_PAUSED );
     158           0 :     if ( nStatus & QUEUE_STATUS_PENDING_DELETION )
     159           0 :         aStr = ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_PENDING );
     160           0 :     if ( nStatus & QUEUE_STATUS_BUSY )
     161           0 :         aStr = ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_BUSY );
     162           0 :     if ( nStatus & QUEUE_STATUS_INITIALIZING )
     163           0 :         aStr = ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_INITIALIZING );
     164           0 :     if ( nStatus & QUEUE_STATUS_WAITING )
     165           0 :         aStr = ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_WAITING );
     166           0 :     if ( nStatus & QUEUE_STATUS_WARMING_UP )
     167           0 :         aStr = ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_WARMING_UP );
     168           0 :     if ( nStatus & QUEUE_STATUS_PROCESSING )
     169           0 :         aStr = ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_PROCESSING );
     170           0 :     if ( nStatus & QUEUE_STATUS_PRINTING )
     171           0 :         aStr = ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_PRINTING );
     172           0 :     if ( nStatus & QUEUE_STATUS_OFFLINE )
     173           0 :         aStr = ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_OFFLINE );
     174           0 :     if ( nStatus & QUEUE_STATUS_ERROR )
     175           0 :         aStr = ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_ERROR );
     176           0 :     if ( nStatus & QUEUE_STATUS_SERVER_UNKNOWN )
     177           0 :         aStr = ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_SERVER_UNKNOWN );
     178           0 :     if ( nStatus & QUEUE_STATUS_PAPER_JAM )
     179           0 :         aStr = ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_PAPER_JAM );
     180           0 :     if ( nStatus & QUEUE_STATUS_PAPER_OUT )
     181           0 :         aStr = ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_PAPER_OUT );
     182           0 :     if ( nStatus & QUEUE_STATUS_MANUAL_FEED )
     183           0 :         aStr = ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_MANUAL_FEED );
     184           0 :     if ( nStatus & QUEUE_STATUS_PAPER_PROBLEM )
     185           0 :         aStr = ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_PAPER_PROBLEM );
     186           0 :     if ( nStatus & QUEUE_STATUS_IO_ACTIVE )
     187           0 :         aStr = ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_IO_ACTIVE );
     188           0 :     if ( nStatus & QUEUE_STATUS_OUTPUT_BIN_FULL )
     189           0 :         aStr = ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_OUTPUT_BIN_FULL );
     190           0 :     if ( nStatus & QUEUE_STATUS_TONER_LOW )
     191           0 :         aStr = ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_TONER_LOW );
     192           0 :     if ( nStatus & QUEUE_STATUS_NO_TONER )
     193           0 :         aStr = ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_NO_TONER );
     194           0 :     if ( nStatus & QUEUE_STATUS_PAGE_PUNT )
     195           0 :         aStr = ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_PAGE_PUNT );
     196           0 :     if ( nStatus & QUEUE_STATUS_USER_INTERVENTION )
     197           0 :         aStr = ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_USER_INTERVENTION );
     198           0 :     if ( nStatus & QUEUE_STATUS_OUT_OF_MEMORY )
     199           0 :         aStr = ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_OUT_OF_MEMORY );
     200           0 :     if ( nStatus & QUEUE_STATUS_DOOR_OPEN )
     201           0 :         aStr = ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_DOOR_OPEN );
     202           0 :     if ( nStatus & QUEUE_STATUS_POWER_SAVE )
     203           0 :         aStr = ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_POWER_SAVE );
     204             : 
     205             :     // Anzahl Jobs
     206           0 :     sal_uLong nJobs = rInfo.GetJobs();
     207           0 :     if ( nJobs && (nJobs != QUEUE_JOBS_DONTKNOW) )
     208             :     {
     209           0 :         OUString aJobStr( SVT_RESSTR( STR_SVT_PRNDLG_JOBCOUNT ) );
     210           0 :         OUString aJobs( OUString::number( nJobs ) );
     211           0 :         aStr = ImplPrnDlgAddString(aStr, aJobStr.replaceAll("%d", aJobs));
     212             :     }
     213             : 
     214           0 :     return aStr;
     215             : }
     216             : 
     217             : 
     218             : 
     219           0 : PrinterSetupDialog::PrinterSetupDialog(Window* pParent)
     220             :     : ModalDialog(pParent, "PrinterSetupDialog",
     221           0 :         "svt/ui/printersetupdialog.ui")
     222             : {
     223           0 :     get(m_pLbName, "name");
     224           0 :     m_pLbName->SetStyle(m_pLbName->GetStyle() | WB_SORT);
     225           0 :     get(m_pBtnProperties, "properties");
     226           0 :     get(m_pBtnOptions, "options");
     227           0 :     get(m_pFiStatus, "status");
     228           0 :     get(m_pFiType, "type");
     229           0 :     get(m_pFiLocation, "location");
     230           0 :     get(m_pFiComment, "comment");
     231             : 
     232             :     // show options button only if link is set
     233           0 :     m_pBtnOptions->Hide();
     234             : 
     235           0 :     mpPrinter       = NULL;
     236           0 :     mpTempPrinter   = NULL;
     237             : 
     238           0 :     maStatusTimer.SetTimeout( IMPL_PRINTDLG_STATUS_UPDATE );
     239           0 :     maStatusTimer.SetTimeoutHdl( LINK( this, PrinterSetupDialog, ImplStatusHdl ) );
     240           0 :     m_pBtnProperties->SetClickHdl( LINK( this, PrinterSetupDialog, ImplPropertiesHdl ) );
     241           0 :     m_pLbName->SetSelectHdl( LINK( this, PrinterSetupDialog, ImplChangePrinterHdl ) );
     242           0 : }
     243             : 
     244             : 
     245             : 
     246           0 : PrinterSetupDialog::~PrinterSetupDialog()
     247             : {
     248           0 :     ImplFreePrnDlgListBox(m_pLbName, false);
     249           0 :     delete mpTempPrinter;
     250           0 : }
     251             : 
     252             : 
     253             : 
     254           0 : void PrinterSetupDialog::SetOptionsHdl( const Link& rLink )
     255             : {
     256           0 :     m_pBtnOptions->SetClickHdl( rLink );
     257           0 :     m_pBtnOptions->Show( rLink.IsSet() );
     258           0 : }
     259             : 
     260           0 : void PrinterSetupDialog::ImplSetInfo()
     261             : {
     262           0 :     const QueueInfo* pInfo = Printer::GetQueueInfo(m_pLbName->GetSelectEntry(), true);
     263           0 :     if ( pInfo )
     264             :     {
     265           0 :         m_pFiType->SetText( pInfo->GetDriver() );
     266           0 :         m_pFiLocation->SetText( pInfo->GetLocation() );
     267           0 :         m_pFiComment->SetText( pInfo->GetComment() );
     268           0 :         m_pFiStatus->SetText( ImplPrnDlgGetStatusText( *pInfo ) );
     269             :     }
     270             :     else
     271             :     {
     272           0 :         OUString aTempStr;
     273           0 :         m_pFiType->SetText( aTempStr );
     274           0 :         m_pFiLocation->SetText( aTempStr );
     275           0 :         m_pFiComment->SetText( aTempStr );
     276           0 :         m_pFiStatus->SetText( aTempStr );
     277             :     }
     278           0 : }
     279             : 
     280             : 
     281             : 
     282           0 : IMPL_LINK_NOARG(PrinterSetupDialog, ImplStatusHdl)
     283             : {
     284           0 :     QueueInfo aInfo;
     285           0 :     ImplPrnDlgUpdateQueueInfo(m_pLbName, aInfo);
     286           0 :     m_pFiStatus->SetText( ImplPrnDlgGetStatusText( aInfo ) );
     287             : 
     288           0 :     return 0;
     289             : }
     290             : 
     291             : 
     292             : 
     293           0 : IMPL_LINK_NOARG(PrinterSetupDialog, ImplPropertiesHdl)
     294             : {
     295           0 :     if ( !mpTempPrinter )
     296           0 :         mpTempPrinter = new Printer( mpPrinter->GetJobSetup() );
     297           0 :     mpTempPrinter->Setup( this );
     298             : 
     299           0 :     return 0;
     300             : }
     301             : 
     302             : 
     303             : 
     304           0 : IMPL_LINK_NOARG(PrinterSetupDialog, ImplChangePrinterHdl)
     305             : {
     306             :     mpTempPrinter = ImplPrnDlgListBoxSelect(m_pLbName, m_pBtnProperties,
     307           0 :                                              mpPrinter, mpTempPrinter );
     308           0 :     ImplSetInfo();
     309           0 :     return 0;
     310             : }
     311             : 
     312             : 
     313             : 
     314           0 : bool PrinterSetupDialog::Notify( NotifyEvent& rNEvt )
     315             : {
     316           0 :     if ( (rNEvt.GetType() == EVENT_GETFOCUS) && IsReallyVisible() )
     317           0 :         ImplStatusHdl( &maStatusTimer );
     318             : 
     319           0 :     return ModalDialog::Notify( rNEvt );
     320             : }
     321             : 
     322             : 
     323             : 
     324           0 : void PrinterSetupDialog::DataChanged( const DataChangedEvent& rDCEvt )
     325             : {
     326           0 :     if ( rDCEvt.GetType() == DATACHANGED_PRINTER )
     327             :     {
     328           0 :         mpTempPrinter = ImplPrnDlgUpdatePrinter( mpPrinter, mpTempPrinter );
     329             :         Printer* pPrn;
     330           0 :         if ( mpTempPrinter )
     331           0 :             pPrn = mpTempPrinter;
     332             :         else
     333           0 :             pPrn = mpPrinter;
     334           0 :         ImplFillPrnDlgListBox(pPrn, m_pLbName, m_pBtnProperties);
     335           0 :         ImplSetInfo();
     336             :     }
     337             : 
     338           0 :     ModalDialog::DataChanged( rDCEvt );
     339           0 : }
     340             : 
     341             : 
     342             : 
     343           0 : short PrinterSetupDialog::Execute()
     344             : {
     345           0 :     if ( !mpPrinter || mpPrinter->IsPrinting() || mpPrinter->IsJobActive() )
     346             :     {
     347             :         SAL_WARN( "svtools.dialogs", "PrinterSetupDialog::Execute() - No Printer or printer is printing" );
     348           0 :         return sal_False;
     349             :     }
     350             : 
     351           0 :     Printer::updatePrinters();
     352             : 
     353           0 :     ImplFillPrnDlgListBox(mpPrinter, m_pLbName, m_pBtnProperties);
     354           0 :     ImplSetInfo();
     355           0 :     maStatusTimer.Start();
     356             : 
     357             :     // start dialog
     358           0 :     short nRet = ModalDialog::Execute();
     359             : 
     360             :     // update data if the dialog was terminated with OK
     361           0 :     if ( nRet == sal_True )
     362             :     {
     363           0 :         if ( mpTempPrinter )
     364           0 :             mpPrinter->SetPrinterProps( mpTempPrinter );
     365             :     }
     366             : 
     367           0 :     maStatusTimer.Stop();
     368             : 
     369           0 :     return nRet;
     370             : }
     371             : 
     372             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10