Ejemplo n.º 1
0
int GenericChannel::handleRead(EncodeBuffer &encodeBuffer, const unsigned char *message,
                               unsigned int length)
{
#ifdef TEST
    *logofs << "handleRead: Called for FD#" << fd_
            << " with " << encodeBuffer.getLength()
            << " bytes already encoded.\n"
            << logofs_flush;
#endif

    //
    // Pointer to located message and
    // its size in bytes.
    //

    const unsigned char *inputMessage;
    unsigned int inputLength;

    //
    // Tag message as generic data in compression
    // routine. Opcode is not actually transferred
    // over the network.
    //

    unsigned char inputOpcode = X_NXInternalGenericData;

#if defined(TEST) || defined(INFO)
    *logofs << "handleRead: Trying to read from FD#"
            << fd_ << " at " << strMsTimestamp() << ".\n"
            << logofs_flush;
#endif

    int result = readBuffer_.readMessage();

#ifdef DEBUG
    *logofs << "handleRead: Read result on FD#" << fd_
            << " is " << result << ".\n"
            << logofs_flush;
#endif

    if (result < 0)
    {
        //
        // Let the proxy close the channel.
        //

        return -1;
    }
    else if (result == 0)
    {
#if defined(TEST) || defined(INFO)

        *logofs << "handleRead: PANIC! No data read from FD#"
                << fd_ << " while encoding messages.\n"
                << logofs_flush;

        HandleCleanup();

#endif

        return 0;
    }

#if defined(TEST) || defined(INFO) || defined(FLUSH)
    *logofs << "handleRead: Encoding messages for FD#" << fd_
            << " with " << readBuffer_.getLength() << " bytes "
            << "in the buffer.\n" << logofs_flush;
#endif

    //
    // Divide the available data in multiple
    // messages and encode them one by one.
    //

    if (proxy -> handleAsyncSwitch(fd_) < 0)
    {
        return -1;
    }

    while ((inputMessage = readBuffer_.getMessage(inputLength)) != NULL)
    {
        encodeBuffer.encodeValue(inputLength, 32, 14);

        if (isCompressed() == 1)
        {
            unsigned int compressedDataSize = 0;
            unsigned char *compressedData   = NULL;

            if (handleCompress(encodeBuffer, inputOpcode, 0,
                               inputMessage, inputLength, compressedData,
                               compressedDataSize) < 0)
            {
                return -1;
            }
        }
        else
        {
            encodeBuffer.encodeMemory(inputMessage, inputLength);
        }

        int bits = encodeBuffer.diffBits();

#if defined(TEST) || defined(OPCODES)
        *logofs << "handleRead: Handled generic data for FD#" << fd_
                << ". " << inputLength << " bytes in, " << bits << " bits ("
                << ((float) bits) / 8 << " bytes) out.\n" << logofs_flush;
#endif

        addProtocolBits(inputLength << 3, bits);

        if (isPrioritized() == 1)
        {
            priority_++;
        }

    } // End of while ((inputMessage = readBuffer_.getMessage(inputLength)) != NULL) ...

    //
    // All data has been read from the read buffer.
    // We still need to mark the end of the encode
    // buffer just before sending the frame. This
    // allows us to accomodate multiple reads in
    // a single frame.
    //

    if (priority_ > 0)
    {
#if defined(TEST) || defined(INFO)
        *logofs << "handleRead: WARNING! Requesting flush "
                << "because of " << priority_ << " prioritized "
                << "messages for FD#" << fd_ << ".\n"
                << logofs_flush;
#endif

        if (proxy -> handleAsyncPriority() < 0)
        {
            return -1;
        }

        //
        // Reset the priority flag.
        //

        priority_ = 0;
    }

    //
    // Flush if we produced enough data.
    //

    if (proxy -> canAsyncFlush() == 1)
    {
#if defined(TEST) || defined(INFO)
        *logofs << "handleRead: WARNING! Requesting flush "
                << "because of enough data or timeout on the "
                << "proxy link.\n" << logofs_flush;
#endif

        if (proxy -> handleAsyncFlush() < 0)
        {
            return -1;
        }
    }

#if defined(TEST) || defined(INFO)

    if (transport_ -> pending() != 0 ||
            readBuffer_.checkMessage() != 0)
    {
        *logofs << "handleRead: PANIC! Buffer for X descriptor FD#"
                << fd_ << " has " << transport_ -> pending()
                << " bytes to read.\n" << logofs_flush;

        HandleCleanup();
    }

#endif

    //
    // Reset the read buffer.
    //

    readBuffer_.fullReset();

    return 1;
}
Ejemplo n.º 2
0
CustomFDialog::CustomFDialog(QWidget *parent, QString wDir, QString caption, QString filter, int flags)
			: QDialog(parent), optionFlags(flags)
{
	setModal(true);
	setWindowTitle(caption);
	setWindowIcon(QIcon(loadIcon("AppIcon.png")));
	vboxLayout = new QVBoxLayout(this);
	vboxLayout->setSpacing(5);
	vboxLayout->setMargin(10);
    hboxLayout = new QHBoxLayout;
	hboxLayout->setSpacing(5);
	hboxLayout->setMargin(0);
	fileDialog = new ScFileWidget(this);
	hboxLayout->addWidget(fileDialog);
	fileDialog->setIconProvider(new ImIconProvider());
	fileDialog->setFilter(filter);
	fileDialog->selectFilter(filter);
	fileDialog->setDirectory(wDir);
	vboxLayout1 = new QVBoxLayout;
	vboxLayout1->setSpacing(0);
	vboxLayout1->setMargin(0);
	vboxLayout1->setContentsMargins(0, 37, 0, 0);
	vboxLayout1->setAlignment( Qt::AlignTop );
	pw = new FDialogPreview( this );
	pw->setMinimumSize(QSize(200, 200));
	pw->setMaximumSize(QSize(200, 200));
	vboxLayout1->addWidget(pw);
	hboxLayout->addLayout(vboxLayout1);
	vboxLayout->addLayout(hboxLayout);
    QHBoxLayout *hboxLayout1 = new QHBoxLayout;
	hboxLayout1->setSpacing(5);
	hboxLayout1->setContentsMargins(9, 0, 0, 0);
	showPreview = new QCheckBox(this);
	showPreview->setText( tr("Show Preview"));
	showPreview->setToolTip( tr("Show a preview and information for the selected file"));
	showPreview->setChecked(true);
	previewIsShown = true;
	hboxLayout1->addWidget(showPreview);
	QSpacerItem *spacerItem = new QSpacerItem(2, 2, QSizePolicy::Expanding, QSizePolicy::Minimum);
	hboxLayout1->addItem(spacerItem);
	OKButton = new QPushButton( CommonStrings::tr_OK, this);
	OKButton->setDefault( true );
	hboxLayout1->addWidget( OKButton );
	CancelB = new QPushButton( CommonStrings::tr_Cancel, this);
	CancelB->setAutoDefault( false );
	hboxLayout1->addWidget( CancelB );
	vboxLayout->addLayout(hboxLayout1);
	SaveZip=NULL;
	WithFonts=NULL;
	WithProfiles=NULL;
	if (flags & fdDirectoriesOnly)
	{
		Layout = new QFrame(this);
		Layout1 = new QHBoxLayout(Layout);
		Layout1->setSpacing( 0 );
		Layout1->setContentsMargins(9, 0, 0, 0);
		SaveZip = new QCheckBox( tr( "&Compress File" ), Layout);
		Layout1->addWidget(SaveZip, Qt::AlignLeft);
		QSpacerItem* spacer = new QSpacerItem( 2, 2, QSizePolicy::Expanding, QSizePolicy::Minimum );
		Layout1->addItem( spacer );
		vboxLayout->addWidget(Layout);
		LayoutC = new QFrame(this);
		Layout1C = new QHBoxLayout(LayoutC);
		Layout1C->setSpacing( 0 );
		Layout1C->setContentsMargins(9, 0, 0, 0);
		WithFonts = new QCheckBox( tr( "&Include Fonts" ), LayoutC);
		Layout1C->addWidget(WithFonts, Qt::AlignLeft);
		WithProfiles = new QCheckBox( tr( "&Include Color Profiles" ), LayoutC);
		Layout1C->addWidget(WithProfiles, Qt::AlignLeft);
		QSpacerItem* spacer2 = new QSpacerItem( 2, 2, QSizePolicy::Expanding, QSizePolicy::Minimum );
		Layout1C->addItem( spacer2 );
		vboxLayout->addWidget(LayoutC);
		fileDialog->setFileMode(QFileDialog::DirectoryOnly);
		pw->hide();
		showPreview->setVisible(false);
		showPreview->setChecked(false);
		previewIsShown = false;
	}
	else
	{
		if (flags & fdCompressFile)
		{
			Layout = new QFrame(this);
			Layout1 = new QHBoxLayout(Layout);
			Layout1->setSpacing( 5 );
			Layout1->setContentsMargins(9, 0, 0, 0);
			SaveZip = new QCheckBox( tr( "&Compress File" ), Layout);
			Layout1->addWidget(SaveZip);
			QSpacerItem* spacer = new QSpacerItem( 2, 2, QSizePolicy::Expanding, QSizePolicy::Minimum );
			Layout1->addItem( spacer );
		}
		if (flags & fdExistingFiles)
			fileDialog->setFileMode(QFileDialog::ExistingFile);
		else
		{
			fileDialog->setFileMode(QFileDialog::AnyFile);
			if (flags & fdCompressFile)
				vboxLayout->addWidget(Layout);
		}
		
		if (SaveZip!=NULL)
			SaveZip->setToolTip( "<qt>" + tr( "Compress the Scribus document on save" ) + "</qt>");
		if (WithFonts!=NULL)
			WithFonts->setToolTip( "<qt>" + tr( "Include fonts when collecting files for the document. Be sure to know and understand licensing information for any fonts you collect and possibly redistribute." ) + "</qt>");
		if (WithProfiles!=NULL)
			WithProfiles->setToolTip( "<qt>" + tr( "Include color profiles when collecting files for the document" ) + "</qt>");
		
		if (flags & fdShowCodecs)
		{
			LayoutC = new QFrame(this);
			Layout1C = new QHBoxLayout(LayoutC);
			Layout1C->setSpacing( 0 );
			Layout1C->setContentsMargins(9, 0, 0, 0);
			TxCodeT = new QLabel(this);
			TxCodeT->setText( tr("Encoding:"));
			Layout1C->addWidget(TxCodeT);
			TxCodeM = new ScComboBox(LayoutC);
			TxCodeM->setEditable(false);
			QString tmp_txc[] = {"ISO 8859-1", "ISO 8859-2", "ISO 8859-3",
								"ISO 8859-4", "ISO 8859-5", "ISO 8859-6",
								"ISO 8859-7", "ISO 8859-8", "ISO 8859-9",
								"ISO 8859-10", "ISO 8859-13", "ISO 8859-14",
								"ISO 8859-15", "UTF-8", "UTF-16", "KOI8-R", "KOI8-U",
								"CP1250", "CP1251", "CP1252", "CP1253",
								"CP1254", "CP1255", "CP1256", "CP1257",
								"Apple Roman"};
			size_t array = sizeof(tmp_txc) / sizeof(*tmp_txc);
			for (uint a = 0; a < array; ++a)
				TxCodeM->addItem(tmp_txc[a]);
			QString localEn = QTextCodec::codecForLocale()->name();
			if (localEn == "ISO-10646-UCS-2")
				localEn = "UTF-16";
			bool hasIt = false;
			for (int cc = 0; cc < TxCodeM->count(); ++cc)
			{
				if (TxCodeM->itemText(cc) == localEn)
				{
					TxCodeM->setCurrentIndex(cc);
					hasIt = true;
					break;
				}
			}
			if (!hasIt)
			{
				TxCodeM->addItem(localEn);
				TxCodeM->setCurrentIndex(TxCodeM->count()-1);
			}
			TxCodeM->setMinimumSize(QSize(200, 0));
			Layout1C->addWidget(TxCodeM);
			QSpacerItem* spacer2 = new QSpacerItem( 2, 2, QSizePolicy::Expanding, QSizePolicy::Minimum );
			Layout1C->addItem( spacer2 );
			vboxLayout->addWidget(LayoutC);
		}
		bool setter2 = flags & fdHidePreviewCheckBox;
		if (!setter2)
		{
			bool setter = flags & fdShowPreview;
			showPreview->setChecked(setter);
			previewIsShown = setter;
			pw->setVisible(setter);
		}
		else
		{
			showPreview->hide();
			previewIsShown = false;
			pw->setVisible(false);
		}
		if (flags & fdCompressFile)
			connect(SaveZip, SIGNAL(clicked()), this, SLOT(handleCompress()));
	}
#if QT_VERSION >= 0x040600
	fileDialog->setNameFilterDetailsVisible(false);
#else
	fileDialog->setOption(QFileDialog::HideNameFilterDetails);
#endif
	extZip = "gz";
	connect(OKButton, SIGNAL(clicked()), this, SLOT(accept()));
	connect(CancelB, SIGNAL(clicked()), this, SLOT(reject()));
	connect(showPreview, SIGNAL(clicked()), this, SLOT(togglePreview()));
	connect(fileDialog, SIGNAL(currentChanged(const QString &)), this, SLOT(fileClicked(const QString &)));
	connect(fileDialog, SIGNAL(filesSelected(const QStringList &)), this, SLOT(accept()));
	connect(fileDialog, SIGNAL(accepted()), this, SLOT(accept()));
	connect(fileDialog, SIGNAL(rejected()), this, SLOT(reject()));
	resize(minimumSizeHint());
}