void GCUserView::qlv_contextMenuRequested(Q3ListViewItem *i, const QPoint &pos, int)
{
	if(!i || !i->parent() || !gcDlg_)
		return;

	QPointer<GCUserViewItem> lvi = (GCUserViewItem *)i;
	bool self = gcDlg_->nick() == i->text(0);
	GCUserViewItem* c = (GCUserViewItem*) findEntry(gcDlg_->nick());
	if (!c) {
		qWarning(QString("groupchatdlg.cpp: Self ('%1') not found in contactlist").arg(gcDlg_->nick()));
		return;
	}
	Q3PopupMenu *pm = new Q3PopupMenu;
	pm->insertItem(IconsetFactory::icon("psi/sendMessage").icon(), tr("Send &message"), 0);
	pm->insertItem(IconsetFactory::icon("psi/start-chat").icon(), tr("Open &chat window"), 1);
	pm->insertSeparator();
	pm->insertItem(tr("&Kick"),10);
	pm->setItemEnabled(10, MUCManager::canKick(c->s.mucItem(),lvi->s.mucItem()));
	pm->insertItem(tr("&Ban"),11);
	pm->setItemEnabled(11, MUCManager::canBan(c->s.mucItem(),lvi->s.mucItem()));

	Q3PopupMenu* rm = new Q3PopupMenu(pm);
	rm->insertItem(tr("Visitor"),12);
	rm->setItemChecked(12, lvi->s.mucItem().role() == MUCItem::Visitor);
	rm->setItemEnabled(12, (!self || lvi->s.mucItem().role() == MUCItem::Visitor) && MUCManager::canSetRole(c->s.mucItem(),lvi->s.mucItem(),MUCItem::Visitor));
	rm->insertItem(tr("Participant"),13);
	rm->setItemChecked(13, lvi->s.mucItem().role() == MUCItem::Participant);
	rm->setItemEnabled(13, (!self || lvi->s.mucItem().role() == MUCItem::Participant) && MUCManager::canSetRole(c->s.mucItem(),lvi->s.mucItem(),MUCItem::Participant));
	rm->insertItem(tr("Moderator"),14);
	rm->setItemChecked(14, lvi->s.mucItem().role() == MUCItem::Moderator);
	rm->setItemEnabled(14, (!self || lvi->s.mucItem().role() == MUCItem::Moderator) && MUCManager::canSetRole(c->s.mucItem(),lvi->s.mucItem(),MUCItem::Moderator));
	pm->insertItem(tr("Change role"),rm);

	/*Q3PopupMenu* am = new Q3PopupMenu(pm);
	am->insertItem(tr("Unaffiliated"),15);
	am->setItemChecked(15, lvi->s.mucItem().affiliation() == MUCItem::NoAffiliation);
	am->setItemEnabled(15, (!self || lvi->s.mucItem().affiliation() == MUCItem::NoAffiliation) && MUCManager::canSetAffiliation(c->s.mucItem(),lvi->s.mucItem(),MUCItem::NoAffiliation));
	am->insertItem(tr("Member"),16);
	am->setItemChecked(16, lvi->s.mucItem().affiliation() == MUCItem::Member);
	am->setItemEnabled(16,  (!self || lvi->s.mucItem().affiliation() == MUCItem::Member) && MUCManager::canSetAffiliation(c->s.mucItem(),lvi->s.mucItem(),MUCItem::Member));
	am->insertItem(tr("Administrator"),17);
	am->setItemChecked(17, lvi->s.mucItem().affiliation() == MUCItem::Admin);
	am->setItemEnabled(17,  (!self || lvi->s.mucItem().affiliation() == MUCItem::Admin) && MUCManager::canSetAffiliation(c->s.mucItem(),lvi->s.mucItem(),MUCItem::Admin));
	am->insertItem(tr("Owner"),18);
	am->setItemChecked(18, lvi->s.mucItem().affiliation() == MUCItem::Owner);
	am->setItemEnabled(18,  (!self || lvi->s.mucItem().affiliation() == MUCItem::Owner) && MUCManager::canSetAffiliation(c->s.mucItem(),lvi->s.mucItem(),MUCItem::Owner));
	pm->insertItem(tr("Change affiliation"),am);*/
	pm->insertSeparator();
	//pm->insertItem(tr("Send &file"), 4);
	//pm->insertSeparator();
	pm->insertItem(tr("Check &Status"), 2);
	pm->insertItem(IconsetFactory::icon("psi/vCard").icon(), tr("User &Info"), 3);
	int x = pm->exec(pos);
	bool enabled = pm->isItemEnabled(x) || rm->isItemEnabled(x);
	delete pm;

	if(x == -1 || !enabled || lvi.isNull())
		return;
	action(lvi->text(0), lvi->s, x);
}
Esempio n. 2
0
void QSofaListView::RunSofaRightClicked( Q3ListViewItem *item,
        const QPoint& point,
        int index )
{

    if( item == NULL) return;
    //updateMatchingObjectmodel();
    bool object_hasData = false;
    if(object_.type == typeObject)
    {
        object_hasData = object_.ptr.Object->getDataFields().size() > 0 ? true : false;
    }
    Q3PopupMenu *contextMenu = new Q3PopupMenu ( this, "ContextMenu" );
    if( object_.isNode() )
    {
        int index_menu = contextMenu->insertItem("Focus", this,SLOT(focusNode()) );
        bool enable = object_.ptr.Node->f_bbox.getValue().isValid() && !object_.ptr.Node->f_bbox.getValue().isFlat();
        contextMenu->setItemEnabled(index_menu,enable);
    }
    if( object_.isObject() )
    {
        int index_menu = contextMenu->insertItem("Focus", this,SLOT( focusObject() ) );
        bool enable = object_.ptr.Object->f_bbox.getValue().isValid() && !object_.ptr.Object->f_bbox.getValue().isFlat() ;
        contextMenu->setItemEnabled(index_menu,enable);
    }
    contextMenu->insertSeparator();

    //Creation of the context Menu
    if ( object_.type == typeNode)
    {
        contextMenu->insertItem ( "Collapse", this, SLOT ( collapseNode() ) );
        contextMenu->insertItem ( "Expand", this, SLOT ( expandNode() ) );
        contextMenu->insertSeparator ();
        /*****************************************************************************************************************/
        if (object_.ptr.Node->isActive())
            contextMenu->insertItem ( "Deactivate", this, SLOT ( DeactivateNode() ) );
        else
            contextMenu->insertItem ( "Activate", this, SLOT ( ActivateNode() ) );
        contextMenu->insertSeparator ();
        /*****************************************************************************************************************/

        contextMenu->insertItem ( "Save Node", this, SLOT ( SaveNode() ) );
        contextMenu->insertItem ( "Export OBJ", this, SLOT ( exportOBJ() ) );

        if ( attribute_ == SIMULATION)
        {
            contextMenu->insertItem ( "Add Node", this, SLOT ( RaiseAddObject() ) );

            int index_menu = contextMenu->insertItem ( "Remove Node", this, SLOT ( RemoveNode() ) );
            //If one of the elements or child of the current node is beeing modified, you cannot allow the user to erase the node
            if ( !isNodeErasable ( object_.ptr.Node ) )
                contextMenu->setItemEnabled ( index_menu,false );
        }
    }
    contextMenu->insertItem ( "Modify", this, SLOT ( Modify() ) );
    if(object_hasData)
    {
        if(item->childCount() > 0)
        {
            contextMenu->insertItem("Hide Datas",this, SLOT ( HideDatas() ) );
        }
        else
        {
            contextMenu->insertItem("Show Datas", this, SLOT ( ShowDatas() ) );
        }
    }
    contextMenu->popup ( point, index );
}
Esempio n. 3
0
void GCUserView::qlv_contextMenuRequested(Q3ListViewItem *i, const QPoint &pos, int)
{
	if(!i || !i->parent() || !gcDlg_)
		return;

	QPointer<GCUserViewItem> lvi = (GCUserViewItem *)i;
	bool self = gcDlg_->nick() == i->text(0);
	GCUserViewItem* c = (GCUserViewItem*) findEntry(gcDlg_->nick());
	if (!c) {
		qWarning() << QString("groupchatdlg.cpp: Self ('%1') not found in contactlist").arg(gcDlg_->nick());
		return;
	}
	Q3PopupMenu *pm = new Q3PopupMenu;
	pm->insertItem(IconsetFactory::icon("psi/sendMessage").icon(), tr("Send &Message"), 0);
	pm->insertItem(IconsetFactory::icon("psi/start-chat").icon(), tr("Open &Chat Window"), 1);
	pm->insertSeparator();

	// Kick and Ban submenus
	QStringList reasons = PsiOptions::instance()->getOption("options.muc.reasons").toStringList();
	int cntReasons=reasons.count();
	if (cntReasons>99) cntReasons=99; // Only first 99 reasons
	
	Q3PopupMenu *kickMenu = new Q3PopupMenu(pm);
	kickMenu->insertItem(tr("No reason"),10);
	kickMenu->insertItem(tr("Custom reason"),100);
	kickMenu->insertSeparator();
	bool canKick=MUCManager::canKick(c->s.mucItem(),lvi->s.mucItem());
	for (int i=0; i<cntReasons; ++i)
		kickMenu->insertItem(reasons[i], 101+i);
	kickMenu->setEnabled(canKick);
	
	Q3PopupMenu *banMenu = new Q3PopupMenu(pm);
        banMenu->insertItem(tr("No reason"),11);
	banMenu->insertItem(tr("Custom reason"),200);
	banMenu->insertSeparator();
	bool canBan=MUCManager::canBan(c->s.mucItem(),lvi->s.mucItem());
	for (int i=0; i<cntReasons; ++i)
		banMenu->insertItem(reasons[i], 201+i);
	banMenu->setEnabled(canBan);

	pm->insertItem(tr("&Kick"), kickMenu);
	pm->setItemEnabled(10, canKick);
	pm->insertItem(tr("&Ban"), banMenu);
	pm->setItemEnabled(11, canBan);

	Q3PopupMenu* rm = new Q3PopupMenu(pm);
	rm->insertItem(tr("Visitor"),12);
	rm->setItemChecked(12, lvi->s.mucItem().role() == MUCItem::Visitor);
	rm->setItemEnabled(12, (!self || lvi->s.mucItem().role() == MUCItem::Visitor) && MUCManager::canSetRole(c->s.mucItem(),lvi->s.mucItem(),MUCItem::Visitor));
	rm->insertItem(tr("Participant"),13);
	rm->setItemChecked(13, lvi->s.mucItem().role() == MUCItem::Participant);
	rm->setItemEnabled(13, (!self || lvi->s.mucItem().role() == MUCItem::Participant) && MUCManager::canSetRole(c->s.mucItem(),lvi->s.mucItem(),MUCItem::Participant));
	rm->insertItem(tr("Moderator"),14);
	rm->setItemChecked(14, lvi->s.mucItem().role() == MUCItem::Moderator);
	rm->setItemEnabled(14, (!self || lvi->s.mucItem().role() == MUCItem::Moderator) && MUCManager::canSetRole(c->s.mucItem(),lvi->s.mucItem(),MUCItem::Moderator));
	pm->insertItem(tr("Change Role"),rm);

	/*Q3PopupMenu* am = new Q3PopupMenu(pm);
	am->insertItem(tr("Unaffiliated"),15);
	am->setItemChecked(15, lvi->s.mucItem().affiliation() == MUCItem::NoAffiliation);
	am->setItemEnabled(15, (!self || lvi->s.mucItem().affiliation() == MUCItem::NoAffiliation) && MUCManager::canSetAffiliation(c->s.mucItem(),lvi->s.mucItem(),MUCItem::NoAffiliation));
	am->insertItem(tr("Member"),16);
	am->setItemChecked(16, lvi->s.mucItem().affiliation() == MUCItem::Member);
	am->setItemEnabled(16,  (!self || lvi->s.mucItem().affiliation() == MUCItem::Member) && MUCManager::canSetAffiliation(c->s.mucItem(),lvi->s.mucItem(),MUCItem::Member));
	am->insertItem(tr("Administrator"),17);
	am->setItemChecked(17, lvi->s.mucItem().affiliation() == MUCItem::Admin);
	am->setItemEnabled(17,  (!self || lvi->s.mucItem().affiliation() == MUCItem::Admin) && MUCManager::canSetAffiliation(c->s.mucItem(),lvi->s.mucItem(),MUCItem::Admin));
	am->insertItem(tr("Owner"),18);
	am->setItemChecked(18, lvi->s.mucItem().affiliation() == MUCItem::Owner);
	am->setItemEnabled(18,  (!self || lvi->s.mucItem().affiliation() == MUCItem::Owner) && MUCManager::canSetAffiliation(c->s.mucItem(),lvi->s.mucItem(),MUCItem::Owner));
	pm->insertItem(tr("Change Affiliation"),am);*/
	pm->insertSeparator();
	//pm->insertItem(tr("Send &File"), 4);
	//pm->insertSeparator();
	pm->insertItem(tr("Check &Status"), 2);
	pm->insertItem(IconsetFactory::icon("psi/vCard").icon(), tr("User &Info"), 3);
	int x = pm->exec(pos);
	bool enabled = pm->isItemEnabled(x) || rm->isItemEnabled(x) || kickMenu->isItemEnabled(x) || banMenu->isItemEnabled(x);
	delete pm;

	if(x == -1 || !enabled || lvi.isNull())
		return;
	action(lvi->text(0), lvi->s, x);
}