[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-devel
Subject:    Re: How to pipe with KShellProcess
From:       Phlip <pplumlee () omnigon ! com>
Date:       2001-02-26 6:47:21
[Download RAW message or body]

Proclaimed Waldo Bastian from the mountaintops:

> When you get wroteStdin() you can send a next block (if you have that) when
> you get receivedStdout().

Thanks! And immediately after posting, I Googled this post:

	http://www.geocrawler.com/archives/3/311/2000/7/0/4120213/

So to complete the trail, here's the complete sample I craved:


	void
KantMainWindow::slotFilterReceivedStdout (KProcess * pProcess, char * got, 
int len)
{

	assert (pProcess == m_pFilterShellProcess);
	
	if (got && len)
		{
		
  //  TODO: got a better idea?

  		while (len--)  m_strFilterOutput += *got++;
//		POP_(m_strFilterOutput);
		}

}

    
	void
KantMainWindow::slotFilterReceivedStderr (KProcess * pProcess, char * got, 
int len)
	{
	slotFilterReceivedStdout (pProcess, got, len);
	}

   
	void
KantMainWindow::slotFilterProcessExited (KProcess * pProcess)
{

	assert (pProcess == m_pFilterShellProcess);
	if (!viewManager)  return;
	KantView * kv (viewManager -> activeView ());
	if (!kv) return;
	QString marked (view.markedText ());
	if (strlen (marked.latin1 ()) > 0)  kv -> keyDelete ();
	kv -> insertText (m_strFilterOutput);
//	slipInNewText (*kv, "", m_strFilterOutput, "", false);
	m_strFilterOutput = "";

}


        static void  //  PCP
slipInFilter (KShellProcess & shell, KantView & view, QString command)
{

  QString marked (view.markedText ());

//  POP_(command.latin1 ());
  shell.clearArguments ();
  shell << command.latin1 ();

  bool started (shell.start (KProcess::NotifyOnExit, KProcess::All));
//  POP_(started);

  bool sentDataIn (shell.writeStdin (marked.latin1 (), marked.length ()));
//  POP_(sentDataIn);

  //  TODO: Put up a modal dialog to defend the text from further
  //  keystrokes while the command is out. With a cancel button...  

}


	void
KantMainWindow::slotFilterCloseStdin (KProcess * pProcess)
	{
	assert (pProcess == m_pFilterShellProcess);
	pProcess -> closeStdin ();
	}


                 void
KantMainWindow::slotEditFilter ()  //  PCP
{
  if (!viewManager)  return;
  KantView * kv (viewManager -> activeView ());
  if (!kv) return;

  QString text ( KantPrompt ( "Filter",
                        "Enter command to pipe selected text thru",
                        this
                        ) );

  if ( !text.isEmpty () )
      {
      m_strFilterOutput = "";
      
      if (!m_pFilterShellProcess)
      	{
      	m_pFilterShellProcess = new KShellProcess;
      	
	connect ( m_pFilterShellProcess, SIGNAL(wroteStdin(KProcess *)),
			   this, SLOT(slotFilterCloseStdin (KProcess *)));
	
	connect ( m_pFilterShellProcess, SIGNAL(receivedStdout(KProcess*,char*,int)),
	  	       this, SLOT(slotFilterReceivedStdout(KProcess*,char*,int)) );
    
	connect ( m_pFilterShellProcess, SIGNAL(receivedStderr(KProcess*,char*,int)),
	 	       this, SLOT(slotFilterReceivedStderr(KProcess*,char*,int)) );
    
	connect ( m_pFilterShellProcess, SIGNAL(processExited(KProcess*)),
		       this, SLOT(slotFilterProcessExited(KProcess*) ) ) ;
      	}
      
      slipInFilter (*m_pFilterShellProcess, *kv, text);
      }
}

Wish I'd thought of Slots and Signals. ;-)

-- 
  Phlip                          phlip_cpp@my-deja.com
============== http://phlip.webjump.com ==============
  --  "In my experience, the customer doesn't know what he wants
       until you don't give it to him." --David Brady  --
 
>> Visit http://master.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic