예제 #1
0
void SearchListView::setupUsers() {
	mUsersMenu->clear();

	QStringList users;
	QTreeWidgetItemIterator it(this, QTreeWidgetItemIterator::Selected | QTreeWidgetItemIterator::NotHidden);

	while (*it) {
		SearchListItem* item = dynamic_cast<SearchListItem*>(*it);

		if(item && users.indexOf(item->user()) == -1)
		{
			users << item->user();
		}
		++it;
	}


    int numusers = users.size();
    mPopupMenu->removeAction(mUsersMenu->menuAction());
    delete mUsersMenu;
    if (numusers <= 0) {
        mUsersMenu = mPopupMenu->addMenu(tr("Users"));
        return;
    }
    else if (numusers == 1) {
        mUsersMenu = new Usermenu(mPopupMenu);
        dynamic_cast<Usermenu*>(mUsersMenu)->setup(users.first());
        QAction * usermenu = mPopupMenu->addMenu(mUsersMenu);
        usermenu->setText(tr("User '%1'").arg(users.first()));
    }
    else {
        QStringListIterator usersIt(users);
        mUsersMenu = mPopupMenu->addMenu(tr("Users"));
        while (usersIt.hasNext()) {
            QString username = usersIt.next();
            Usermenu *m = new Usermenu(mUsersMenu);
            m->setup(username);
            QAction * usermenu = mUsersMenu->addMenu(static_cast<QMenu*>(m));
            usermenu->setText(username);
        }
    }
}
예제 #2
0
void Transfers::setupUsers() {
	mUsersMenu->clear();

	QStringList users;
	QTreeWidgetItemIterator it(mPoppedUpload ? mUploads : mDownloads, QTreeWidgetItemIterator::Selected );
	for(; *it; ++it) {
		TransferListItem* item = dynamic_cast<TransferListItem*>(*it);
		if(item && !users.contains(item->user()))
		{
			users << item->user();
		}
	}

    int numusers = users.size();
    mTransferMenu->removeAction(mUsersMenu->menuAction());
    delete mUsersMenu;
    if (numusers <= 0) {
        mUsersMenu = mTransferMenu->addMenu(tr("Users"));
        return;
    }
    else if (numusers == 1) {
        mUsersMenu = new Usermenu(mTransferMenu);
        dynamic_cast<Usermenu*>(mUsersMenu)->setup(users.first());
        QAction * usermenu = mTransferMenu->addMenu(mUsersMenu);
        usermenu->setText(tr("User '%1'").arg(users.first()));
    }
    else {
        QStringListIterator usersIt(users);
        mUsersMenu = mTransferMenu->addMenu(tr("Users"));
        while (usersIt.hasNext()) {
            QString username = usersIt.next();
            Usermenu *m = new Usermenu(mUsersMenu);
            m->setup(username);
            QAction * usermenu = mUsersMenu->addMenu(static_cast<QMenu*>(m));
            usermenu->setText(username);
        }
    }
}