FreeburnCommandDialog.cpp
上传用户:cnxinhai
上传日期:2013-08-06
资源大小:265k
文件大小:11k
- /* This is the class definition for the Executing Command Output Dialog.
- *
- * Copyright (C) 2001, 2002 Adam Schlag
- */
- /*
- * FreeBurn Software License
- * (based on the Apache Software License)
- *
- * Version 1.1
- *
- * Copyright (c) 2001, 2002 The FreeBurn Project. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * 3. The end-user documentation included with the redistribution, if any, must
- * include the following acknowledgment:
- *
- * "This product includes software developed by the FreeBurn
- * Project (http://freeburn.sourceforge.net/)."
- *
- * Alternately, this acknowledgment may appear in the software itself,
- * if and wherever such third-party acknowledgments normally appear.
- *
- * 4. The names "FreeBurn" and "FreeBurn Project" must not be
- * used to endorse or promote products derived from this software
- * without prior written permission. For written permission, please
- * contact aschlag@users.sourceforge.net.
- *
- * 5. Products derived from this software may not be called "FreeBurn",
- * nor may "FreeBurn" appear in their name, without prior written
- * permission of the FreeBurn Project.
- *
- * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE FREEBURN PROJECT OR ITS
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
- * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * This software consists of voluntary contributions made by many
- * individuals on behalf of the FreeBurn Project. For more
- * information on the FreeBurn Project and FreeBurn, please see
- * <http://freeburn.sourceforge.net/>.
- *
- * This software is distributed with software that is released under the GNU
- * General Public License (GPL). You can find the terms of this license in the
- * file GPL.txt distributed in this package. You can find information on the
- * software distributed with this package in the file PROGRAMS.txt.
- */
- #include <fx.h>
- #include <FXPNGIcon.h>
- #include "FreeburnCommandDialog.h"
- #include "FreeburnDefs.h"
- #include "FreeburnCommandDialogText.h"
- #ifndef FREEBURN_ICONS_H
- #include "FreeburnIcons.h"
- #define FREEBURN_ICONS_H
- #endif
- #include "FreeburnHelper.h"
- #include "FreeBurn.h"
- // Message Map for the CFreeburnCommandDialog class
- FXDEFMAP(CFreeburnCommandDialog) CFreeburnCommandDialogMap[]={
- //________Message_Type___________________ID________________________________Message_Handler____
- FXMAPFUNC(SEL_COMMAND, CFreeburnCommandDialog::ID_SAVELOG, CFreeburnCommandDialog::saveOutputLog)
- };
- FXIMPLEMENT(CFreeburnCommandDialog,FXDialogBox,CFreeburnCommandDialogMap,ARRAYNUMBER(CFreeburnCommandDialogMap))
- // Construct command dialog box
- CFreeburnCommandDialog::CFreeburnCommandDialog(FXWindow* owner):
- FXDialogBox(owner,fbCommandDialogTitleText,DECOR_TITLE|DECOR_BORDER, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4)
- {
- // create a font that adds bold to the default font (for labels)
- FXFont* systemFont = getApp()->getNormalFont();
- FXFontDesc systemFontDesc;
- systemFont->getFontDesc(systemFontDesc);
- systemFontDesc.weight = FONTWEIGHT_BOLD;
- FXFont* boldSystemFont = new FXFont(getApp(), systemFontDesc);
-
- // set up the main container for the dialog
- FXVerticalFrame* mainFrame = new FXVerticalFrame(this, LAYOUT_SIDE_TOP|LAYOUT_FILL_X|LAYOUT_FILL_Y);
-
- // set up the switcher to change between the regular and log views
- FXSwitcher* commandSwitcher = new FXSwitcher(mainFrame, LAYOUT_FILL_X|LAYOUT_FILL_Y);
-
- // frame for the contents of the regular command output
- FXVerticalFrame* commandFrame = new FXVerticalFrame(commandSwitcher, LAYOUT_FILL_X|LAYOUT_FILL_Y);
-
- // add the title label
- new FXLabel(commandFrame, fbCommandDialogTitleLabelText, NULL, LAYOUT_LEFT);
-
- // add a horizontal ridge separator
- new FXHorizontalSeparator(commandFrame, SEPARATOR_RIDGE|LAYOUT_FILL_X);
- // add the label specifying the command
- FXLabel* labelCommand = new FXLabel(commandFrame, fbCommandDialogCommandLabelText, NULL, LAYOUT_LEFT);
- labelCommand->setFont(boldSystemFont);
-
- // add the label specifying the actual command string
- m_CommandLabel = new FXLabel(commandFrame, EMPTY_STRING, NULL, LAYOUT_LEFT|JUSTIFY_LEFT);
-
- // add the label specifying the current line of output
- FXLabel* labelOutput = new FXLabel(commandFrame, fbCommandDialogOutputLabelText, NULL, LAYOUT_LEFT);
- labelOutput->setFont(boldSystemFont);
-
- // add the label that will contain the current line of output
- m_OutputLabel = new FXLabel(commandFrame, EMPTY_STRING, NULL, LAYOUT_LEFT|JUSTIFY_LEFT);
-
- // set up the show log button
- m_ShowLogButton = new FXButton(commandFrame, fbCommandDialogShowOutputLogButtonText, NULL,
- commandSwitcher, FXSwitcher::ID_OPEN_SECOND, BUTTON_DEFAULT|LAYOUT_RIGHT|LAYOUT_BOTTOM|FRAME_RAISED);
-
- // frame for the contents of the output log stuff
- FXVerticalFrame* logFrame = new FXVerticalFrame(commandSwitcher, LAYOUT_FILL_X|LAYOUT_FILL_Y);
-
- // set the output text area
- m_OutputText = new FXText(logFrame,this,ID_LOGTEXT,LAYOUT_LEFT);
- m_OutputText->setEditable(FALSE);
- m_OutputText->setVisRows(10);
- m_OutputText->setVisCols(80);
- FXFont* textFont = new FXFont(getApp(), FIXED_FONT, 10);
- m_OutputText->setFont(textFont);
-
- // set up a horizontal frame for containing the hide/save log buttons with no default bottom padding
- FXHorizontalFrame* logButtonFrame = new FXHorizontalFrame(logFrame, LAYOUT_FILL_X|PACK_UNIFORM_WIDTH,
- 0, 0, 0, 0, 0, 0, 0, 0);
- // add the hide log button
- m_HideLogButton = new FXButton(logButtonFrame, fbCommandDialogHideOutputLogButtonText, NULL,
- commandSwitcher, FXSwitcher::ID_OPEN_FIRST, BUTTON_DEFAULT|LAYOUT_RIGHT|LAYOUT_BOTTOM|FRAME_RAISED);
- // add the save log button
- m_SaveLogButton = new FXButton(logButtonFrame, fbCommandDialogSaveOutputLogButtonText, NULL,
- this, ID_SAVELOG, BUTTON_DEFAULT|LAYOUT_RIGHT|ICON_BEFORE_TEXT|LAYOUT_BOTTOM|FRAME_RAISED);
- // disable the button (it will be enabled when we're done getting output
- m_SaveLogButton->disable();
-
- // set up the buttons for closing the dialog
- new FXHorizontalSeparator(mainFrame, SEPARATOR_GROOVE|LAYOUT_FILL_X);
- FXHorizontalFrame* buttonFrame = new FXHorizontalFrame(mainFrame, LAYOUT_BOTTOM|LAYOUT_FILL_X|PACK_UNIFORM_WIDTH);
- m_OkButton = new FXButton(buttonFrame, fbCommandDialogOkButtonText, NULL, this, FXDialogBox::ID_ACCEPT,
- BUTTON_DEFAULT|LAYOUT_RIGHT|FRAME_RAISED|FRAME_THICK, 0, 0, 0, 0, 20, 20);
- // disable the button (it will be enabled when we're done getting output)
- m_OkButton->disable();
- }
- // Clean up
- CFreeburnCommandDialog::~CFreeburnCommandDialog()
- {
- }
- // set the save icon
- void CFreeburnCommandDialog::setSaveIcon(FXIcon* saveIcon)
- {
- m_SaveLogButton->setIcon(saveIcon);
- }
- // set the text in the command label
- void CFreeburnCommandDialog::setCommandLabelText(FXString& commandString)
- {
- // set up method variables so we can break the string if it's too long
- FXString displayString = commandString;
- FXString outputString;
- FXint stringLength = displayString.length();
- FXint insertPos = 0;
-
- // now we want to add a '' and a newline each 80 characters
- // (we're using 80 because it's usually how wide a command console is)
- while (stringLength > CONSOLE_LINE_SIZE)
- {
- insertPos = insertPos + CONSOLE_LINE_SIZE;
- displayString.insert(insertPos, COMMAND_BREAK);
- stringLength = stringLength - CONSOLE_LINE_SIZE;
- }
-
- m_CommandLabel->setText(displayString);
-
- // also add the command (and other text) to the text area
- outputString = fbCommandDialogCommandLineText;
- m_OutputText->appendText(outputString.text(), outputString.length());
- m_OutputText->appendText(commandString.text(), commandString.length());
- outputString.clear();
- outputString = fbCommandDialogOutputLineText;
- m_OutputText->appendText(outputString.text(), outputString.length());
- m_OutputText->setBottomLine(m_OutputText->getCursorPos());
- }
- // get a line of text output and do some processing to it for display to the user
- void CFreeburnCommandDialog::sendOutputText (FXString& outputString)
- {
- // remove any carriage return characters in the output string
- while (outputString.count('r') > 0)
- {
- outputString.remove(outputString.findf('r'), 1);
- }
- // also remove any backspace characters
- while (outputString.count('b') > 0)
- {
- outputString.remove(outputString.findf('b'), 1);
- }
-
- // set the output label to the current line of output text
- m_OutputLabel->setText(outputString);
-
- // append this line of text to the text area and scroll the text
- // widget to the bottom line
- m_OutputText->appendText(outputString.text(), outputString.length());
- m_OutputText->setBottomLine(m_OutputText->getCursorPos());
- }
- // message handler to save the output of the log to a text file
- long CFreeburnCommandDialog::saveOutputLog(FXObject*, FXSelector, void*)
- {
- FXString outFile = m_OutputText->getText();
- outFile.trim();
-
- FreeburnHelper::saveNewTextFile(this->getOwner(), outFile);
-
- return 1;
- }
- // this method is run when the main applicatino receives the message that
- // the thread thats catching the process output is complete.
- void CFreeburnCommandDialog::outputComplete()
- {
- // insert the text to the output area that the output is complete
- FXString outputString = fbCommandDialogOutputDoneText;
- m_OutputText->appendText(outputString.text(), outputString.length());
-
- // enable the "OK" button so the dialog can be closed and the "save log"
- // button so the user can save the output log if they choose to save it
- m_SaveLogButton->enable();
- m_OkButton->enable();
- }