Ejemplo n.º 1
0
/*
void ListJobs::v_connectionLost()
{
	if( m_parentWindow != (QWidget*)Watch::getDialog()) m_parentWindow->close();
}
*/
void ListJobs::contextMenuEvent( QContextMenuEvent *event)
{
	QMenu menu(this);
	QMenu * submenu;
	QAction *action;

	ItemJob* jobitem = (ItemJob*)getCurrentItem();
	if( jobitem == NULL ) return;
	int selectedItemsCount = getSelectedItemsCount();

	if( jobitem->folders.size())
	{
		if( af::Environment::hasRULES())
		{
			action = new QAction("Open RULES", this);
			connect( action, SIGNAL( triggered() ), this, SLOT( actOpenRULES() ));
			menu.addAction( action);

			menu.addSeparator();
		}

		submenu = new QMenu("Folders", this);

		QMapIterator<QString,QString> it( jobitem->folders);
		while( it.hasNext())
		{
			it.next();

			action = new QAction( QString("\"") + it.key() + "\":", this);
			action->setEnabled( false);
			submenu->addAction( action);

			ActionString * action_str = new ActionString( it.value(), it.value(), this);
			connect( action_str, SIGNAL( triggeredString(QString) ), this, SLOT( actBrowseFolder(QString) ));
			submenu->addAction( action_str);
		}

		menu.addMenu( submenu);
		menu.addSeparator();
	}

	action = new QAction( "Show Log", this);
	connect( action, SIGNAL( triggered() ), this, SLOT( actRequestLog() ));
	menu.addAction( action);

	action = new QAction( "Show Error Hosts", this);
	connect( action, SIGNAL( triggered() ), this, SLOT( actRequestErrorHostsList() ));
	menu.addAction( action);

	action = new QAction( "Reset Error Hosts", this);
	connect( action, SIGNAL( triggered() ), this, SLOT( actResetErrorHosts() ));
	menu.addAction( action);

	action = new QAction( "Restart Error Tasks", this);
	connect( action, SIGNAL( triggered() ), this, SLOT( actRestartErrors() ));
	if( selectedItemsCount == 1) action->setEnabled( jobitem->state & AFJOB::STATE_ERROR_MASK);
	menu.addAction( action);

	menu.addSeparator();

	submenu = new QMenu("Start/Stop/Restart", this);
	menu.addMenu( submenu);

	action = new QAction( "Restart Running Tasks", this);
	connect( action, SIGNAL( triggered() ), this, SLOT( actRestartRunning() ));
	if( selectedItemsCount == 1) action->setEnabled( jobitem->state & AFJOB::STATE_RUNNING_MASK);
	submenu->addAction( action);

	action = new QAction( "Restart Skipped Tasks", this);
	connect( action, SIGNAL( triggered() ), this, SLOT( actRestartSkipped() ));
	if( selectedItemsCount == 1) action->setEnabled( jobitem->state & AFJOB::STATE_SKIPPED_MASK);
	submenu->addAction( action);

	action = new QAction( "Restart Done Tasks", this);
	connect( action, SIGNAL( triggered() ), this, SLOT( actRestartDone() ));
	submenu->addAction( action);

	menu.addSeparator();

	action = new QAction("Start Job", this);
	connect( action, SIGNAL( triggered() ), this, SLOT( actStart()   ));
	if( selectedItemsCount == 1) action->setEnabled( jobitem->state & AFJOB::STATE_OFFLINE_MASK);
	submenu->addAction( action);

	action = new QAction("Pause Job", this);
	connect( action, SIGNAL( triggered() ), this, SLOT( actPause()   ));
	if( selectedItemsCount == 1) action->setEnabled( false == (jobitem->state & AFJOB::STATE_OFFLINE_MASK));
	submenu->addAction( action);

	action = new QAction("Stop Job", this);
	connect( action, SIGNAL( triggered() ), this, SLOT( actStop()    ));
	if( selectedItemsCount == 1) action->setEnabled( jobitem->state & AFJOB::STATE_RUNNING_MASK);
	submenu->addAction( action);

	action = new QAction("Restart Job", this);
	connect( action, SIGNAL( triggered() ), this, SLOT( actRestart() ));
	if( selectedItemsCount == 1) action->setEnabled(( jobitem->time_started != 0 ) || ( jobitem->state & AFJOB::STATE_SKIPPED_MASK ));
	submenu->addAction( action);

	action = new QAction("Restart&&Pause", this);
	connect( action, SIGNAL( triggered() ), this, SLOT( actRestartPause() ));
	if( selectedItemsCount == 1) action->setEnabled(( jobitem->time_started != 0 ) || ( jobitem->state & AFJOB::STATE_SKIPPED_MASK ));
	submenu->addAction( action);

	menu.addSeparator();

	if( af::Environment::VISOR() == false)
	{
		  action = new QAction( "Move Up", this);
		  connect( action, SIGNAL( triggered() ), this, SLOT( actMoveUp() ));
		  menu.addAction( action);
		  action = new QAction( "Move Down", this);
		  connect( action, SIGNAL( triggered() ), this, SLOT( actMoveDown() ));
		  menu.addAction( action);
		  action = new QAction( "Move Top", this);
		  connect( action, SIGNAL( triggered() ), this, SLOT( actMoveTop() ));
		  menu.addAction( action);
		  action = new QAction( "Move Bottom", this);
		  connect( action, SIGNAL( triggered() ), this, SLOT( actMoveBottom() ));
		  menu.addAction( action);
	}
	else
	{
		  action = new QAction("Change Owner", this);
		  connect( action, SIGNAL( triggered() ), this, SLOT( actSetUser() ));
		  menu.addAction( action);
	}
	menu.addSeparator();

	submenu = new QMenu( "Set Parameter", this);

	action = new QAction( "Max Running Tasks", this);
	connect( action, SIGNAL( triggered() ), this, SLOT( actMaxRunningTasks() ));
	submenu->addAction( action);
	action = new QAction( "Max Run Tasks Per Host", this);
	connect( action, SIGNAL( triggered() ), this, SLOT( actMaxRunTasksPerHost() ));
	submenu->addAction( action);
	action = new QAction( "Hosts Mask", this);
	connect( action, SIGNAL( triggered() ), this, SLOT( actHostsMask() ));
	submenu->addAction( action);
	action = new QAction( "Hosts Exclude Mask", this);
	connect( action, SIGNAL( triggered() ), this, SLOT( actHostsMaskExclude() ));
	submenu->addAction( action);

	if(( af::Environment::VISOR()) || ( af::Environment::getPermUserModJobPriority()))
	{
	   action = new QAction( "Priority", this);
	   connect( action, SIGNAL( triggered() ), this, SLOT( actPriority() ));
	   submenu->addAction( action);
	}

	action = new QAction( "Depend Mask", this);
	connect( action, SIGNAL( triggered() ), this, SLOT( actDependMask() ));
	submenu->addAction( action);
	action = new QAction( "Global Depend Mask", this);
	connect( action, SIGNAL( triggered() ), this, SLOT( actDependMaskGlobal() ));
	submenu->addAction( action);
	action = new QAction( "Wait Time", this);
	connect( action, SIGNAL( triggered() ), this, SLOT( actWaitTime() ));
	submenu->addAction( action);
	action = new QAction( "Preview Approval", this);
	connect( action, SIGNAL( triggered() ), this, SLOT( actPreviewApproval() ));
	submenu->addAction( action);
	action = new QAction( "No Preview Approval", this);
	connect( action, SIGNAL( triggered() ), this, SLOT( actNoPreviewApproval() ));
	submenu->addAction( action);
	action = new QAction( "OS Needed", this);
	connect( action, SIGNAL( triggered() ), this, SLOT( actNeedOS() ));
	submenu->addAction( action);
	action = new QAction( "Properties Needed", this);
	connect( action, SIGNAL( triggered() ), this, SLOT( actNeedProperties() ));
	submenu->addAction( action);
	action = new QAction( "Post Command", this);
	connect( action, SIGNAL( triggered() ), this, SLOT( actPostCommand() ));
	submenu->addAction( action);
	action = new QAction( "Life Time", this);
	connect( action, SIGNAL( triggered() ), this, SLOT( actLifeTime() ));
	submenu->addAction( action);

	submenu->addSeparator();

	action = new QAction( "Hidden", this);
	connect( action, SIGNAL( triggered() ), this, SLOT( actSetHidden() ));
	submenu->addAction( action);
	action = new QAction( "Not Hidden", this);
	connect( action, SIGNAL( triggered() ), this, SLOT( actUnsetHidden() ));
	submenu->addAction( action);

	submenu->addSeparator();

	action = new QAction( "Annotation", this);
	connect( action, SIGNAL( triggered() ), this, SLOT( actAnnotate() ));
	submenu->addAction( action);
	action = new QAction( "Custom Data", this);
	connect( action, SIGNAL( triggered() ), this, SLOT( actCustomData() ));
	submenu->addAction( action);

	menu.addMenu( submenu);

	menu.addSeparator();

	if( selectedItemsCount == 1)
	{
		if( jobitem->getBlocksNum() > 1)
		{
			submenu = new QMenu( "Tasks Blocks", this);
			for( int b = -1; b < jobitem->getBlocksNum(); b++)
			{
				QMenu * subsubmenu = new QMenu( b == -1 ? QString("_to_all_") : jobitem->getBlockName(b), this);
				jobitem->generateMenu( b, subsubmenu , this);
				submenu->addMenu( subsubmenu);
			}
		}
		else
		{
			submenu = new QMenu( "Tasks Block", this);
			jobitem->generateMenu( 0, submenu, this);
		}
	}
	else
	{
		submenu = new QMenu( "All Selected Blocks", this);
		jobitem->generateMenu( -1, submenu, this);
	}
	menu.addMenu( submenu);

	menu.addSeparator();

	action = new QAction( "Listen", this);
	connect( action, SIGNAL( triggered() ), this, SLOT( actListenJob() ));
	menu.addAction( action);

	menu.addSeparator();

	// System job ID is 1, and can not be deleted
	if( jobitem->getId() != 1 )
	{
		action = new QAction( "Delete All Done", this);
		connect( action, SIGNAL( triggered() ), this, SLOT( actDeleteDone()));
		menu.addAction( action);

		action = new QAction( "Delete", this);
		connect( action, SIGNAL( triggered() ), this, SLOT( actDelete()));
		menu.addAction( action);
	}

	menu.exec(event->globalPos());
}
Ejemplo n.º 2
0
void ListTasks::contextMenuEvent(QContextMenuEvent *event)
{
	Item* item = getCurrentItem();
	if( item == NULL) return;

	QMenu menu(this);
	QAction *action;

	int id = item->getId();
	switch( id)
	 {
		  case ItemJobBlock::ItemId:
		  {
				ItemJobBlock *itemBlock = (ItemJobBlock*)item;
				if( itemBlock->files.size() )
				{
					 action = new QAction( "Browse Files...", this);
					 connect( action, SIGNAL( triggered() ), this, SLOT( actBrowseFolder() ));
					 menu.addAction( action);
					 menu.addSeparator();
				}

				QMenu * submenu = new QMenu( "Change Block", this);
				itemBlock->generateMenu( itemBlock->getNumBlock(), &menu, this, submenu);

				menu.addMenu( submenu);
				menu.addSeparator();

				submenu = new QMenu( "Change Tasks", this);
				menu.addMenu( submenu);

				action = new QAction( "Set Command", this);
				connect( action, SIGNAL( triggered() ), this, SLOT( actBlockCommand() ));
				submenu->addAction( action);

				action = new QAction( "Set Working Directory", this);
				connect( action, SIGNAL( triggered() ), this, SLOT( actBlockWorkingDir() ));
				submenu->addAction( action);

				action = new QAction( "Set Post Command", this);
				connect( action, SIGNAL( triggered() ), this, SLOT( actBlockCmdPost() ));
				submenu->addAction( action);

				action = new QAction( "Set Files", this);
				connect( action, SIGNAL( triggered() ), this, SLOT( actBlockFiles() ));
				submenu->addAction( action);

				action = new QAction( "Set Service Type", this);
				connect( action, SIGNAL( triggered() ), this, SLOT( actBlockService() ));
				submenu->addAction( action);

				action = new QAction( "Set Parser Type", this);
				connect( action, SIGNAL( triggered() ), this, SLOT( actBlockParser() ));
				submenu->addAction( action);

				break;
		  }
		case ItemJobTask::ItemId:
		{
			ActionId * actionid = new ActionId( 0, "Output", this);
			connect( actionid, SIGNAL( triggeredId( int ) ), this, SLOT( actTaskStdOut( int ) ));
			menu.addAction( actionid);

			if( m_job_id != AFJOB::SYSJOB_ID )
			{
				int startCount = ((ItemJobTask*)(item))->taskprogress.starts_count;
				if( startCount > 1 )
				{
					QMenu * submenu = new QMenu( "outputs", this);
					for( int i = 1; i < startCount; i++)
					{
						actionid = new ActionId( i, QString("session #%1").arg(i), this);
						connect( actionid, SIGNAL( triggeredId( int ) ), this, SLOT( actTaskStdOut( int ) ));
						submenu->addAction( actionid);
					}
					menu.addMenu( submenu);
				}
			}

			action = new QAction( "Log", this);
			connect( action, SIGNAL( triggered() ), this, SLOT( actTaskLog() ));
			menu.addAction( action);

			action = new QAction( "Info", this);
			connect( action, SIGNAL( triggered() ), this, SLOT( actTaskInfo() ));
			menu.addAction( action);

			action = new QAction( "Listen", this);
			connect( action, SIGNAL( triggered() ), this, SLOT( actTaskListen() ));
			menu.addAction( action);

			action = new QAction( "Error Hosts", this);
			connect( action, SIGNAL( triggered() ), this, SLOT( actTaskErrorHosts() ));
			menu.addAction( action);

			std::vector<std::string> files = ((ItemJobTask*)(item))->genFiles();
			if( files.size())
			{
				if( af::Environment::getPreviewCmds().size() > 0 )
				{
					menu.addSeparator();

					action = new QAction( "Browse Files...", this);
					connect( action, SIGNAL( triggered() ), this, SLOT( actBrowseFolder() ));
					menu.addAction( action);

				if( ((ItemJobTask*)(item))->isBlockNumeric() )
				{
					QMenu * submenu_cmd = new QMenu( "Preview", this);
					int p = 0;
					for( std::vector<std::string>::const_iterator it = af::Environment::getPreviewCmds().begin(); it != af::Environment::getPreviewCmds().end(); it++, p++)
					{
						if( files.size() > 1)
						{
							QString file = afqt::stoq((*it).c_str());
							QMenu * submenu_img = new QMenu( QString("%1").arg( file), this);
							for( int i = 0; i < files.size(); i++)
							{
								QString imgname = file.right(99);
								ActionIdId * actionid = new ActionIdId( p, i, imgname, this);
								connect( actionid, SIGNAL( triggeredId(int,int) ), this, SLOT( actTaskPreview(int,int) ));
								submenu_img->addAction( actionid);
							}
							submenu_cmd->addMenu( submenu_img);
						}
						else
						{
							ActionIdId * actionid = new ActionIdId( p, 0, QString("%1").arg( QString::fromUtf8((*it).c_str())), this);
							connect( actionid, SIGNAL( triggeredId(int,int) ), this, SLOT( actTaskPreview(int,int) ));
							submenu_cmd->addAction( actionid);
						}
					}