/*
 * ************************************************************************************************************
 * Author: Marcin Załęczny
 * Copyright (C)2011 Marcin Załęczny <mzaleczny@hotmail.com>
 * License: The GNU Lesser General Public License, version 3.0 (LGPLv3)
 * Library Name: mzstdprint
 * Version: 1.02
 * First release date:   2011-02-03
 * Current release date: 2011-03-04
 *
 *
 * This file is part of mzstdprint library
 * 
 * mzstdprint library is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * mzstdprint library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 * ************************************************************************************************************
 */

#include "mzPrinterInfo.h"



VOID CPrinterInfo::_commonInit() {
    this->setRealClassName(L"CPrinterInfo");
    this->reset();
}

CPrinterInfo::CPrinterInfo() {
    this->_commonInit();
}

CPrinterInfo::CPrinterInfo(PRINTER_INFO_1* info) {
    this->_commonInit();
    this->set(info);
}

CPrinterInfo::CPrinterInfo(PRINTER_INFO_2* info) {
    this->_commonInit();
    this->set(info);
}

CPrinterInfo::CPrinterInfo(PRINTER_INFO_4* info) {
    this->_commonInit();
    this->set(info);
}

CPrinterInfo::CPrinterInfo(PRINTER_INFO_5* info) {
    this->_commonInit();
    this->set(info);
}

CPrinterInfo::~CPrinterInfo() {
}

CString CPrinterInfo::toString() {
    CString s, attributes, status;
    s = FormatMessage(L"Printer name: %s\n"
                        L"    Server name: %s\n"    L"    Share name: %s\n"         L"    Port name: %s\n"
                        L"    Driver name: %s\n"    L"    Comment: %s\n"            L"    Location: %s\n"
                        L"    Sep file: %s\n"       L"    Print processor: %s\n"    L"    Data type: %s\n"
                        L"    Parameters: %s\n"     L"    Attributes: %ddx [%s]\n"  L"    Priority: %ddx\n"
                        L"    Default priority: %ddx\n"    L"    Start time: %ud\n" L"    Until time: %ud\n"
                        L"    Status: %ddx [%s]\n"
                        L"    Jobs: %ddx\n"         L"    Average PPM: %ddx\n"
                        L"    Flags: %ud\n"        L"    Device not selected timeout: %ud\n"
                        L"    Transmission retry timeout: %ud\n"   L"    Description: %s\n",
                        this->name.toWCHAR(),         this->serverName.toWCHAR(),       this->shareName.toWCHAR(),
                        this->portName.toWCHAR(),
                        this->driverName.toWCHAR(),   this->comment.toWCHAR(),          this->location.toWCHAR(),
                        this->sepFile.toWCHAR(),      this->printProcessor.toWCHAR(),   this->dataType.toWCHAR(),
                        this->parameters.toWCHAR(),   this->attributes, attributes.toWCHAR(),
                        this->priority,     this->defaultPriority,
                        this->startTime,    this->untilTime,
                        this->status, status.toWCHAR(),
                        this->jobs,
                        this->averagePPM,
                        this->flags,
                        this->deviceNotSelectedTimeout,
                        this->transmissionRetryTimeout,
                        this->description.toWCHAR());
    return s;
}


VOID CPrinterInfo::reset() {
    this->name = COMMON_EMPTY_STRING;
    this->serverName = COMMON_EMPTY_STRING;
    this->shareName = COMMON_EMPTY_STRING;
    this->portName = COMMON_EMPTY_STRING;
    this->driverName = COMMON_EMPTY_STRING;
    this->comment = COMMON_EMPTY_STRING;
    this->location = COMMON_EMPTY_STRING;
    this->sepFile = COMMON_EMPTY_STRING;
    this->printProcessor = COMMON_EMPTY_STRING;
    this->dataType = COMMON_EMPTY_STRING;
    this->parameters = COMMON_EMPTY_STRING;
    this->flags = 0;
    this->description = COMMON_EMPTY_STRING;
    this->attributes = 0;
    this->priority = 0;
    this->defaultPriority = 0;
    this->startTime = 0;
    this->untilTime = 0;
    this->status = 0;
    this->jobs = 0;
    this->averagePPM = 0;
    this->deviceNotSelectedTimeout = 0;
    this->transmissionRetryTimeout = 0;
}

VOID CPrinterInfo::set(PRINTER_INFO_1* info) {
    this->name = info->pName;
    this->flags = info->Flags;
    this->description = info->pDescription;
    this->comment = info->pComment;
}

VOID CPrinterInfo::set(PRINTER_INFO_2* info) {
    this->name = info->pPrinterName;
    this->serverName = info->pServerName;
    this->shareName = info->pShareName;
    this->portName = info->pPortName;
    this->driverName = info->pDriverName;
    this->comment = info->pComment;
    this->location = info->pLocation;
    this->sepFile = info->pSepFile;
    this->printProcessor = info->pPrintProcessor;
    this->dataType = info->pDatatype;
    this->parameters = info->pParameters;
    this->attributes = info->Attributes;
    this->priority = info->Priority;
    this->defaultPriority = info->DefaultPriority;
    this->startTime = info->StartTime;
    this->untilTime = info->UntilTime;
    this->status = info->Status;
    this->jobs = info->cJobs;
    this->averagePPM = info->AveragePPM;
}

VOID CPrinterInfo::set(PRINTER_INFO_4* info) {
    this->name = info->pPrinterName;
    this->serverName = info->pServerName;
    this->attributes = info->Attributes;
}

VOID CPrinterInfo::set(PRINTER_INFO_5* info) {
    this->name = info->pPrinterName;
    this->portName = info->pPortName;
    this->attributes = info->Attributes;
    this->deviceNotSelectedTimeout = info->DeviceNotSelectedTimeout;
    this->transmissionRetryTimeout = info->TransmissionRetryTimeout;
}
