[rkward-cvs] rkward/rkward/windows rcontrolwindow.cpp,1.1,1.2 rcontrolwindow.h,1.1,1.2

Thomas Friedrichsmeier tfry at users.sourceforge.net
Fri Oct 14 15:57:45 UTC 2005


Update of /cvsroot/rkward/rkward/rkward/windows
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3234/rkward/windows

Modified Files:
	rcontrolwindow.cpp rcontrolwindow.h 
Log Message:
RControlWindow much better, but still incomplete

Index: rcontrolwindow.cpp
===================================================================
RCS file: /cvsroot/rkward/rkward/rkward/windows/rcontrolwindow.cpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** rcontrolwindow.cpp	13 Oct 2005 21:01:57 -0000	1.1
--- rcontrolwindow.cpp	14 Oct 2005 15:57:43 -0000	1.2
***************
*** 57,61 ****
  	commands_view->addColumn (i18n ("Flags"));
  	commands_view->addColumn (i18n ("Description"));
! 	commands_view->setSorting (-1);
  	main_vbox->addWidget (commands_view);
  
--- 57,61 ----
  	commands_view->addColumn (i18n ("Flags"));
  	commands_view->addColumn (i18n ("Description"));
! 	commands_view->setSorting (0);		// actually, we ignore the column, and do our own sorting
  	main_vbox->addWidget (commands_view);
  
***************
*** 70,78 ****
  	RK_TRACE (APP);
  
- //	refreshCommands ();		// TODO: can't do this yet. Take care of the mutext first.
  	KMdiChildView::show ();
  }
  
  void RControlWindow::addChain (RCommandChain *chain) {
  	RK_TRACE (APP);
  
--- 70,81 ----
  	RK_TRACE (APP);
  
  	KMdiChildView::show ();
+ 	MUTEX_LOCK;
+ 	refreshCommands ();
+ 	MUTEX_UNLOCK;
  }
  
  void RControlWindow::addChain (RCommandChain *chain) {
+ 	if (!isShown ()) return;	// do expensive GUI stuff only when visible
  	RK_TRACE (APP);
  
***************
*** 80,111 ****
  	dummy->command = 0;
  	dummy->chain = chain;
! 	addCommands (dummy, chain_map[chain]);
  	delete dummy;
  }
  
! void RControlWindow::addCommand (RCommand *command, RCommandChain *chain) {
  	RK_TRACE (APP);
  
! 	addCommand (command, chain_map[chain]);
  }
  
  void RControlWindow::updateChain (RCommandChain *chain) {
  	RK_TRACE (APP);
  }
  
  void RControlWindow::updateCommand (RCommand *command) {
  	RK_TRACE (APP);
  }
  
! void RControlWindow::removeChain (RCommandChain *chain) {
  	RK_TRACE (APP);
  }
  
! void RControlWindow::removeCommand (RCommand *command) {
  	RK_TRACE (APP);
  }
  
  void RControlWindow::refreshCommands () {
- //	if (!isShown ()) return;	// do expensive GUI stuff only when visible
  	RK_TRACE (APP);
  
--- 83,140 ----
  	dummy->command = 0;
  	dummy->chain = chain;
! 	addCommands (dummy, chain_map[chain->parent]);
  	delete dummy;
  }
  
! void RControlWindow::addCommand (RCommand *command, RCommandChain *parent) {
! 	if (!isShown ()) return;	// do expensive GUI stuff only when visible
  	RK_TRACE (APP);
  
! 	if (!parent) parent = RCommandStack::regular_stack;
! 	addCommand (command, chain_map[parent]);
  }
  
  void RControlWindow::updateChain (RCommandChain *chain) {
+ 	if (!isShown ()) return;	// do expensive GUI stuff only when visible
  	RK_TRACE (APP);
+ 
+ 	chain_map[chain]->update (chain);
  }
  
  void RControlWindow::updateCommand (RCommand *command) {
+ 	if (!isShown ()) return;	// do expensive GUI stuff only when visible
  	RK_TRACE (APP);
+ 
+ 	command_map[command]->update (command);
  }
  
! void RControlWindow::removeCommand (RCommand *command) {
! 	if (!isShown ()) return;	// do expensive GUI stuff only when visible
  	RK_TRACE (APP);
+ 
+ 	RControlWindowListViewItem *item = command_map[command];
+ 	RControlWindowListViewItem *chain = static_cast<RControlWindowListViewItem *> (item->parent ());
+ 
+ 	delete item;
+ 	command_map.remove (command);
+ 
+ /* close parent chain(s) if applicable. This basically mimics the behavior in RCommandStack::pop () */
+ 	while (chain && chain->chain_closed && chain->parent () && (!chain->firstChild ())) {
+ 		RControlWindowListViewItem *del = chain;
+ 		chain = static_cast<RControlWindowListViewItem *> (chain->parent ());
+ 		chain_map.remove (del->chain);
+ 		delete del;
+ 	}
  }
  
! void RControlWindow::setCommandRunning (RCommand *command) {
! 	if (!isShown ()) return;	// do expensive GUI stuff only when visible
  	RK_TRACE (APP);
+ 
+ 	RK_ASSERT (command_map[command]);
+ 	command_map[command]->setText (2, "Running");
  }
  
  void RControlWindow::refreshCommands () {
  	RK_TRACE (APP);
  
***************
*** 121,148 ****
  
  	delete dummy;
  }
  
! void RControlWindow::addCommands (RChainOrCommand *coc, QListViewItem *parent) {
! //	if (!isShown ()) return;	// do expensive GUI stuff only when visible
  	RK_TRACE (APP);
  
  	if (coc->chain) {
! 		QListViewItem *item;
  		RCommandChain *chain = coc->chain;
  		if (!parent) {
! 			item = new QListViewItem (commands_view, i18n ("Command Stack"));
! 		} else {
! 			item = new QListViewItem (parent);
! 		}
! 		item->setText (1, i18n ("Chain"));
! 		if (chain->closed) {
! 			item->setText (2, i18n ("Closed"));
  		} else {
! 			item->setText (2, i18n ("Open"));
  		}
  		item->setOpen (true);
  		chain_map.insert (chain, item);
! 		// new QListViewItems are always added at the top, so we need to walk the list backwards
! 		for (RChainOrCommand *nc = chain->commands.last (); nc; nc = chain->commands.prev ()) {
  			addCommands (nc, item);
  		}
--- 150,182 ----
  
  	delete dummy;
+ 
+ /* add the currently running command (if needed). It is not in the stack. */
+ 	RCommand *running = RKGlobals::rInterface ()->runningCommand ();
+ 	if (running && (!command_map.contains (running))) {
+ 		RControlWindowListViewItem *item = static_cast <RControlWindowListViewItem *> (commands_view->firstChild ());
+ 		while (item->chain && item->firstChild ()) {
+ 			item = static_cast <RControlWindowListViewItem *> (item->firstChild ());
+ 		}
+ 		addCommand (running, item);
+ 	}
+ 	if (running) setCommandRunning (running);
  }
  
! void RControlWindow::addCommands (RChainOrCommand *coc, RControlWindowListViewItem *parent) {
  	RK_TRACE (APP);
  
  	if (coc->chain) {
! 		RControlWindowListViewItem *item;
  		RCommandChain *chain = coc->chain;
  		if (!parent) {
! 			item = new RControlWindowListViewItem (commands_view);
! 			item->setText (0, i18n ("Command Stack"));
  		} else {
! 			item = new RControlWindowListViewItem (parent);
  		}
  		item->setOpen (true);
  		chain_map.insert (chain, item);
! 		item->update (chain);
! 		for (RChainOrCommand *nc = chain->commands.first (); nc; nc = chain->commands.next ()) {
  			addCommands (nc, item);
  		}
***************
*** 153,180 ****
  }
  
! void RControlWindow::addCommand (RCommand *command, QListViewItem *parent) {
  	RK_TRACE (APP);
  
! 	QString text = command->command ().left (40);
! 	if (text.length () > 37) {
! 		text = text.left (37) + "...";
! 	}
! 
! 	QString type;
! 	if (command->type () & RCommand::User) type += "U";
! 	if (command->type () & RCommand::Plugin) type += "P";
! 	if (command->type () & RCommand::PluginCom) type += "C";
! 	if (command->type () & RCommand::App) type += "A";
! 	if (command->type () & RCommand::Sync) type += "S";
! 	if (command->type () & RCommand::EmptyCommand) type += "E";
! 	if (command->type () & (RCommand::GetIntVector | RCommand::GetRealVector | RCommand::GetStringVector)) type += "D";
! 	if (command->type () & RCommand::DirectToOutput) type += "O";
! 
! 	QString flags;
! 	if (command->type () & RCommand::Canceled) flags = i18n ("Cancelled");
! 
! 	QListViewItem *item = new QListViewItem (parent, text, type, flags, command->rkEquivalent ());
  	item->setMultiLinesEnabled (true);
  	command_map.insert (command, item);
  }
  
--- 187,198 ----
  }
  
! void RControlWindow::addCommand (RCommand *command, RControlWindowListViewItem *parent) {
  	RK_TRACE (APP);
  
! 	RControlWindowListViewItem *item = new RControlWindowListViewItem (parent);
  	item->setMultiLinesEnabled (true);
  	command_map.insert (command, item);
+ 
+ 	item->update (command);
  }
  
***************
*** 219,221 ****
--- 237,322 ----
  }
  
+ //############# END RContolWindowPart #######################
+ //############# BEGIN RContolWindowListViewItem #################
+ 
+ // static
+ unsigned int RControlWindowListViewItem::lid = 0;
+ 
+ RControlWindowListViewItem::RControlWindowListViewItem (QListViewItem *parent) : QListViewItem (parent) {
+ 	chain = 0;
+ 	chain_closed = false;
+ 
+ 	id = ++lid;
+ }
+ 
+ RControlWindowListViewItem::RControlWindowListViewItem (QListView *parent) : QListViewItem (parent) {
+ 	chain = 0;
+ 	chain_closed = false;
+ 
+ 	id = ++lid;
+ }
+ 
+ RControlWindowListViewItem::~RControlWindowListViewItem () {
+ }
+ 
+ int RControlWindowListViewItem::compare (QListViewItem *i, int, bool ascending) const {
+ 	unsigned int comp_id = static_cast<RControlWindowListViewItem *> (i)->id;
+ 	if (ascending) {
+ 		if (comp_id > id) {
+ 			return -1;
+ 		} /* else if (comp_id == id) {		// all items have a unique id!
+ 			return 0;
+ 		}*/
+ 		return 1;
+ 	} else {
+ 		if (comp_id > id) {
+ 			return 1;
+ 		} /* else if (comp_id == id) {		// all items have a unique id!
+ 			return 0;
+ 		}*/
+ 		return -1;
+ 	}
+ }
+ 
+ void RControlWindowListViewItem::update (RCommand *command) {
+ 	RK_TRACE (APP);
+ 	RK_ASSERT (this);
+ 
+ 	QString dummy = command->command ().left (40);
+ 	if (dummy.length () > 37) {
+ 		dummy = dummy.left (37) + "...";
+ 	}
+ 	setText (0, dummy);
+ 
+ 	dummy = "";
+ 	if (command->type () & RCommand::User) dummy += "U";
+ 	if (command->type () & RCommand::Plugin) dummy += "P";
+ 	if (command->type () & RCommand::PluginCom) dummy += "C";
+ 	if (command->type () & RCommand::App) dummy += "A";
+ 	if (command->type () & RCommand::Sync) dummy += "S";
+ 	if (command->type () & RCommand::EmptyCommand) dummy += "E";
+ 	if (command->type () & (RCommand::GetIntVector | RCommand::GetRealVector | RCommand::GetStringVector)) dummy += "D";
+ 	if (command->type () & RCommand::DirectToOutput) dummy += "O";
+ 	setText (1, dummy);
+ 
+ 	if (command->type () & RCommand::Canceled) setText (2, i18n ("Cancelled"));
+ 
+ 	setText (3, command->rkEquivalent ());
+ }
+ 
+ void RControlWindowListViewItem::update (RCommandChain *cchain) {
+ 	RK_TRACE (APP);
+ 	RK_ASSERT (this);
+ 	
+ 	chain = cchain;
+ 	chain_closed = cchain->closed;
+ 
+ 	setText (1, i18n ("Chain"));
+ 	if (chain_closed) {
+ 		setText (2, i18n ("Closed"));
+ 	} else {
+ 		setText (2, i18n ("Open (Waiting)"));
+ 	}
+ }
+ 
  #include "rcontrolwindow.moc"

Index: rcontrolwindow.h
===================================================================
RCS file: /cvsroot/rkward/rkward/rkward/windows/rcontrolwindow.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** rcontrolwindow.h	13 Oct 2005 21:01:57 -0000	1.1
--- rcontrolwindow.h	14 Oct 2005 15:57:43 -0000	1.2
***************
*** 24,34 ****
  #include <qmap.h>
  #include <qlabel.h>
  
- class QListView;
  class QPushButton;
- class QListViewItem;
  class RCommand;
  class RCommandChain;
  class RChainOrCommand;
  
  /**
--- 24,34 ----
  #include <qmap.h>
  #include <qlabel.h>
+ #include <qlistview.h>
  
  class QPushButton;
  class RCommand;
  class RCommandChain;
  class RChainOrCommand;
+ class RControlWindowListViewItem;
  
  /**
***************
*** 56,68 ****
  public:
  	void addChain (RCommandChain *chain);
! 	void addCommand (RCommand *command, RCommandChain *chain);
  	void updateChain (RCommandChain *chain);
  	void updateCommand (RCommand *command);
- 	void removeChain (RCommandChain *chain);
  	void removeCommand (RCommand *command);
! 
! // TODO: move to private. The above functions should be used instead.
! /** causes the RControlWindow (if shown) to refresh it's entire list of commands. Warning! Does not lock the mutex. Lock the mutex before calling this! */
! 	void refreshCommands ();
  
  /** reimplemented to refresh list of commands when showing. */
--- 56,64 ----
  public:
  	void addChain (RCommandChain *chain);
! 	void addCommand (RCommand *command, RCommandChain *parent);
  	void updateChain (RCommandChain *chain);
  	void updateCommand (RCommand *command);
  	void removeCommand (RCommand *command);
! 	void setCommandRunning (RCommand *command);
  
  /** reimplemented to refresh list of commands when showing. */
***************
*** 77,85 ****
  	QPushButton *cancel_button;
  	QPushButton *pause_button;
! 	void addCommands (RChainOrCommand *coc, QListViewItem *parent);
! 	void addCommand (RCommand *command, QListViewItem *parent);
  
! 	QMap <RCommand *, QListViewItem *> command_map;
! 	QMap <RCommandChain *, QListViewItem *> chain_map;
  
  	bool paused;
--- 73,84 ----
  	QPushButton *cancel_button;
  	QPushButton *pause_button;
! 	void addCommands (RChainOrCommand *coc, RControlWindowListViewItem *parent);
! 	void addCommand (RCommand *command, RControlWindowListViewItem *parent);
  
! /** causes the RControlWindow (if shown) to refresh it's entire list of commands. Warning! Does not lock the mutex. Lock the mutex before calling this! */
! 	void refreshCommands ();
! 
! 	QMap <RCommand *, RControlWindowListViewItem *> command_map;
! 	QMap <RCommandChain *, RControlWindowListViewItem *> chain_map;
  
  	bool paused;
***************
*** 102,104 ****
--- 101,134 ----
  };
  
+ /**
+ 	\brief ListViewItem used in RControlWindow
+ 
+ A listview-item with a convenience constructor, and storing some additional information. For use in RControlWindow only.
+ 
+ */
+ class RControlWindowListViewItem : public QListViewItem {
+ public:
+ /** constructor. */
+ 	RControlWindowListViewItem (QListViewItem *parent);
+ /** constructor. */
+ 	RControlWindowListViewItem (QListView *parent);
+ /** destructor */
+ 	~RControlWindowListViewItem ();
+ 
+ /** initialize/update item according to command flags, status, etc. */
+ 	void update (RCommand *command);
+ /** initialize/update item according to chain flags, status, etc. */
+ 	void update (RCommandChain *chain);
+ 
+ /** warning! do not try to access members of this pointer! RCommandChains get deleted in the stack when done, without notice. Use this pointer only to check, whether this is a chain, and to remove it from the RControlWindow::chain_map! */
+ 	RCommandChain *chain;
+ 	bool chain_closed;
+ 
+ 	unsigned int id;
+ 	static unsigned int lid;
+ 
+ /** reimplemented to always have the top of the stack at the top */
+ 	int compare (QListViewItem *i, int col, bool ascending) const;
+ };
+ 
  #endif





More information about the rkward-tracker mailing list