void Configuration::setServiceMenu()
{
    KMenu *menu = qobject_cast<KMenu*>(sender());

    if (menu->actions().count() > 1)
    {
        return;
    }

    KServiceGroup::Ptr rootGroup = KServiceGroup::group(menu->actions()[0]->data().toString());

    if (!rootGroup || !rootGroup->isValid() || rootGroup->noDisplay())
    {
        return;
    }

    KServiceGroup::List list = rootGroup->entries(true, true, true, true);

    QAction *action = menu->addAction(KIcon("list-add"), i18n("Add This Menu"));
    action->setData(rootGroup->relPath());

    menu->addSeparator();

    for (int i = 0; i < list.count(); ++i)
    {
        if (list.at(i)->isType(KST_KService))
        {
            const KService::Ptr service = KService::Ptr::staticCast(list.at(i));

            action = menu->addAction(KIcon(service->icon()), service->name());
            action->setEnabled(false);
        }
        else if (list.at(i)->isType(KST_KServiceGroup))
        {
            const KServiceGroup::Ptr group = KServiceGroup::Ptr::staticCast(list.at(i));

            if (group->noDisplay() || group->childCount() == 0)
            {
                continue;
            }

            KMenu *subMenu = new KMenu(menu);

            QAction *action = subMenu->addAction(QString());
            action->setData(group->relPath());
            action->setVisible(false);

            action = menu->addAction(KIcon(group->icon()), group->caption());
            action->setMenu(subMenu);

            connect(subMenu, SIGNAL(aboutToShow()), this, SLOT(setServiceMenu()));
        }
        else if (list.at(i)->isType(KST_KServiceSeparator))
        {
            menu->addSeparator();
        }
    }
}
Example #2
0
void TabBar::contextMenu(int tab, const QPoint &pos)
{
    KActionMenu *closedTabsMenu = setupHistoryActions();

    m_actualIndex = tab;

    KMenu menu;
    MainWindow *mainWindow = rApp->mainWindow();

    menu.addAction(mainWindow->actionByName(QL1S("new_tab")));
    menu.addAction(mainWindow->actionByName(QL1S("clone_tab")));
    if (count() > 1)
    {
        menu.addAction(mainWindow->actionByName(QL1S("detach_tab")));
    }
    menu.addAction(mainWindow->actionByName(QL1S("open_last_closed_tab")));
    menu.addAction(closedTabsMenu);
    menu.addSeparator();
    menu.addAction(mainWindow->actionByName(QL1S("close_tab")));
    if (count() > 1)
    {
        menu.addAction(mainWindow->actionByName(QL1S("close_other_tabs")));
    }
    menu.addSeparator();
    menu.addAction(mainWindow->actionByName(QL1S("reload_tab")));
    if (count() > 1)
    {
        menu.addAction(mainWindow->actionByName(QL1S("reload_all_tabs")));
    }
    menu.exec(pos);
}
void KUI_project::setupMenuFile()
{
  
  KMenu *fileMenu = new KMenu(i18n("&File"),this);
   
  KAction *action = KStandardAction::openNew(this, SLOT(newProjectDialogSlot()), collection);
  fileMenu->addAction(collection->addAction("new_file", action));
  
  fileMenu->addSeparator();
  
  action = KStandardAction::open(this, SLOT(openFileSlot()), collection);
  fileMenu->addAction(collection->addAction("open_file", action));
  
  action = KStandardAction::save(this, SLOT(saveFileSlot()), collection);
  action->setEnabled(false);
  //fileMenu->addAction(collection->addAction("save_file", action)); 
  
  action = KStandardAction::saveAs(this, SLOT(saveAsFileSlot()), collection);
  action->setEnabled(false);      
  //fileMenu->addAction(collection->addAction("save_as_file", action));
  
  fileMenu->addSeparator();
  
  action = KStandardAction::quit(this, SLOT(close()), collection);
  fileMenu->addAction(collection->addAction("quit", action)); 
  
  menuBar->addMenu(fileMenu);
}
Example #4
0
File: tray.cpp Project: KDE/kget
/** class Tray
  * Reimplementation of the KStatusNotifierItem class
  */
Tray::Tray(MainWindow * parent)
    : KStatusNotifierItem(parent)
{
    // set up the context menu
    KMenu * cm = contextMenu();
    cm->addAction( parent->actionCollection()->action("new_download") );
    cm->addAction( parent->actionCollection()->action("import_links") );
    cm->addSeparator();
    cm->addAction( parent->actionCollection()->action("start_all_download") );
    cm->addAction( parent->actionCollection()->action("stop_all_download") );
    cm->addSeparator();
    cm->addAction( parent->actionCollection()->action("konqueror_integration") );
    cm->addAction( parent->actionCollection()->action("options_configure") );

    // Set up basic tray parameters
    setCategory(ApplicationStatus);
    setIconByName("kget");
    setTitle(i18n("KGet"));
    setContextMenu(cm);
    setAssociatedWidget(parent);
    setToolTipIconByName("kget");
    setToolTipTitle(i18n("Download Manager"));
    // Not of much use atm, but maybe we want to set this later?
    // setToolTipSubTitle("[..]");

    // filter middle mouse clicks to ask scheduler to paste URL
    connect( this, SIGNAL(secondaryActivateRequested(QPoint)),
             this, SLOT(slotActivated()) );
}
Example #5
0
void
BlockAnalyzer::contextMenuEvent( QContextMenuEvent * )
{
    KMenu *menu = new KMenu( this );
    menu->setTitle( i18n( "Framerate" ) );

    QAction *a = menu->addAction( i18n("50 fps"), this, SLOT( set50fps() ) );
    if( timeout() == 50 ) a->setChecked( true );

    a = menu->addAction( i18n("33 fps"), this, SLOT( set33fps() ) );
    if( timeout() == 33 ) a->setChecked( true );
    
    a = menu->addAction( i18n("25 fps"), this, SLOT( set25fps() ) );
    if( timeout() == 25 ) a->setChecked( true );
    
    a = menu->addAction( i18n("20 fps"), this, SLOT( set20fps() ) );
    if( timeout() == 20 ) a->setChecked( true );
    
    a = menu->addAction( i18n("10 fps"), this, SLOT( set10fps() ) );
    if( timeout() == 10 ) a->setChecked( true );

#if defined HAVE_LIBVISUAL
    menu->addSeparator();
    menu->addAction( Amarok::actionCollection()->action( "visualizations" ) );
#endif
    menu->exec();
}
void Container::contextMenu( int currentTab, QPoint pos )
{
    KMenu menu;

    emit tabContextMenuRequested(viewForWidget(widget(currentTab)), &menu);

    menu.addSeparator();
    QAction* closeTabAction = menu.addAction( KIcon("document-close"), i18n( "Close File" ) );
    QAction* closeOtherTabsAction = menu.addAction( KIcon("document-close"), i18n( "Close Other Files" ) );
    QAction* closeAllTabsAction = menu.addAction( KIcon("document-close"), i18n( "Close All Files" ) );

    QAction* triggered = menu.exec(pos);

    if (triggered) {
        if ( triggered == closeTabAction ) {
            closeRequest(currentTab);
        } else if ( triggered == closeOtherTabsAction ) {
            // activate the remaining tab
            widgetActivated(currentTab);
            // first get the widgets to be closed since otherwise the indices will be wrong
            QList<QWidget*> otherTabs;
            for ( int i = 0; i < count(); ++i ) {
                if ( i != currentTab ) {
                    otherTabs << widget(i);
                }
            }
            // finally close other tabs
            foreach( QWidget* tab, otherTabs ) {
                closeRequest(tab);
            }
        } else if ( triggered == closeAllTabsAction ) {
void Widget::themeMenuAboutToShow()
{
  if ( !d->mStorageModel )
    return;

  KMenu * menu = dynamic_cast< KMenu * >( sender() );
  if ( !menu )
    return;

  menu->clear();

  menu->addTitle( i18n( "Theme" ) );

  QActionGroup * grp = new QActionGroup( menu );

  const QHash< QString, Theme * > & themes = Manager::instance()->themes();

  QAction * act;

  QList< const Theme * > sortedThemes;

  for ( QHash< QString, Theme * >::ConstIterator ci = themes.constBegin(); ci != themes.constEnd(); ++ci )
  {
    int idx = 0;
    int cnt = sortedThemes.count();
    while ( idx < cnt )
    {
      if ( sortedThemes.at( idx )->name() > ( *ci )->name() )
      {
        sortedThemes.insert( idx, *ci );
        break;
      }
      idx++;
    }

    if ( idx == cnt )
      sortedThemes.append( *ci );
  }

  for ( QList< const Theme * >::ConstIterator it = sortedThemes.constBegin(); it != sortedThemes.constEnd(); ++it )
  {
    act = menu->addAction( ( *it )->name() );
    act->setCheckable( true );
    grp->addAction( act );
    act->setChecked( d->mLastThemeId == ( *it )->id() );
    act->setData( QVariant( ( *it )->id() ) );
    connect( act, SIGNAL( triggered( bool ) ),
             SLOT( themeSelected( bool ) ) );
  }

  menu->addSeparator();

  act = menu->addAction( i18n( "Configure..." ) );
  connect( act, SIGNAL( triggered( bool ) ),
           SLOT( configureThemes() ) );
}
Example #8
0
 DemoWidget() : QWidget()
 {
     menu = new KMenu("Popup Menu:");
     menu->addAction( "Item1" );
     menu->addAction( "Item2" );
     menu->addSeparator();
     QAction *a = new QAction( "Quit", this );
     menu->addAction( a );
     connect( a, SIGNAL(triggered()), qApp, SLOT(quit()));
 }
void KTNEFMain::contextMenuEvent( QContextMenuEvent *event )
{
  QList<KTNEFAttach *> list = mView->getSelection();
  if ( !list.count() ) {
    return;
  }

  QAction *view = 0;
  QAction *viewWith = 0;
  QAction *prop = 0;
  KMenu *menu = new KMenu();
  if ( list.count() == 1 ) {
    view = menu->addAction( KIcon( "document-open" ),
                            i18nc( "@action:inmenu", "View" ) );
    viewWith = menu->addAction( i18nc( "@action:inmenu", "View With..." ) );
    menu->addSeparator();
  }
  QAction *extract = menu->addAction( i18nc( "@action:inmenu", "Extract" ) );
  QAction *extractTo = menu->addAction( KIcon( "archive-extract" ),
                                        i18nc( "@action:inmenu", "Extract To..." ) );
  if ( list.count() == 1 ) {
    menu->addSeparator();
   prop = menu->addAction( KIcon( "document-properties" ),
                           i18nc( "@action:inmenu", "Properties" ) );
  }

  QAction *a = menu->exec( event->globalPos(), 0 );
  if ( a ) {
    if ( a == view ) {
      viewFile();
    } else if ( a == viewWith ) {
      viewFileAs();
    } else if ( a == extract ) {
      extractFile();
    } else if ( a == extractTo ) {
      extractFileTo();
    } else if ( a == prop ) {
      propertiesFile();
    }
  }
  delete menu;
}
Example #10
0
void
AlbumsView::contextMenuEvent( QGraphicsSceneContextMenuEvent *event )
{
    KAction *appendAction = new KAction( KIcon( "media-track-add-amarok" ), i18n( "&Append to Playlist" ), this );
    KAction *loadAction   = new KAction( KIcon( "folder-open" ), i18nc( "Replace the currently loaded tracks with these", "&Load" ), this );
    KAction *queueAction  = new KAction( KIcon( "media-track-queue-amarok" ), i18n( "&Queue" ), this );
    KAction *editAction   = new KAction( KIcon( "media-track-edit-amarok" ), i18n( "Edit Track Details" ), this );
    
    connect( appendAction, SIGNAL( triggered() ), this, SLOT( slotAppendSelected() ) );
    connect( loadAction  , SIGNAL( triggered() ), this, SLOT( slotPlaySelected() ) );
    connect( queueAction , SIGNAL( triggered() ), this, SLOT( slotQueueSelected() ) );
    connect( editAction  , SIGNAL( triggered() ), this, SLOT( slotEditSelected() ) );

    KMenu menu;
    menu.addAction( appendAction );
    menu.addAction( loadAction );
    menu.addAction( queueAction );
    menu.addSeparator();
    menu.addAction( editAction );

    QModelIndex index = nativeWidget()->indexAt( event->pos().toPoint() );
    if( index.isValid() )
    {
        QStandardItem *item = static_cast<QStandardItemModel*>( model() )->itemFromIndex( index );
        AlbumItem *album = dynamic_cast<AlbumItem*>(item);
        if( album )
        {
            Meta::AlbumPtr albumPtr = album->album();
            Meta::CustomActionsCapability *cac = albumPtr->create<Meta::CustomActionsCapability>();
            if( cac )
            {
                QList<PopupDropperAction *> actions = cac->customActions();

                menu.addSeparator();
                foreach( PopupDropperAction *action, actions )
                    menu.addAction( action );
            }
        }
    }

    menu.exec( event->screenPos() );
}
Example #11
0
QAction* addMenuSeparator(long widget, long menu)
{
    Karamba* currTheme = (Karamba*)widget;
    KMenu* tmp = (KMenu*)menu;

    QAction *sep = 0;
    if (menuExists(currTheme, tmp)) {
        sep = tmp->addSeparator();
    }

    return sep;
}
void
ServiceCollectionTreeView::contextMenuEvent( QContextMenuEvent * event )
{
    if ( m_playableTracks )
        CollectionTreeView::contextMenuEvent( event );
    else
    {
        QModelIndexList indices = selectedIndexes();
        if( filterModel() )
        {
            QModelIndexList tmp;
            foreach( const QModelIndex &idx, indices )
            {
                tmp.append( filterModel()->mapToSource( idx ) );
            }
            indices = tmp;
        }

        if( !indices.isEmpty() )
        {
            KMenu menu;
            if( indices.count() == 1 )
            {
                if( indices.first().isValid() && indices.first().internalPointer() )
                {
                    Meta::DataPtr data = static_cast<CollectionTreeItem*>( indices.first().internalPointer() )->data();
                    if( data )
                    {
                        Meta::CustomActionsCapability *cac = data->create<Meta::CustomActionsCapability>();
                        if( cac )
                        {
                            QList<PopupDropperAction*> actions = cac->customActions();
                            if( actions.count() )
                                menu.addSeparator();
                            foreach( PopupDropperAction *action, actions )
                                menu.addAction( action );
                            delete cac;
                        }
                    }
                }
            }

            if( menu.actions().count() > 0 )
            {
                (void)menu.exec( event->globalPos() );
                QSet<CollectionTreeItem*> items;
                foreach( const QModelIndex &index, indices )
                {
                    if( index.isValid() && index.internalPointer() )
                        items.insert( static_cast<CollectionTreeItem*>( index.internalPointer() ) );
                }
            }
void ArchiveMailWidget::customContextMenuRequested(const QPoint&)
{
  const QList<QTreeWidgetItem *> listItems = mWidget->treeWidget->selectedItems();
  KMenu menu;
  menu.addAction(i18n("Add..."),this,SLOT(slotAddItem()));
  if( !listItems.isEmpty() ) {
   if( listItems.count() == 1) {
      menu.addAction(i18n("Open Containing Folder..."),this,SLOT(slotOpenFolder()));
    }
    menu.addSeparator();
    menu.addAction(i18n("Delete"),this,SLOT(slotRemoveItem()));
  }
  menu.exec(QCursor::pos());
}
Example #14
0
void
FileView::contextMenuEvent( QContextMenuEvent *e )
{
    if( !model() )
        return;

    //trying to do fancy stuff while showing places only leads to tears!
    if( model()->objectName() == "PLACESMODEL" )
    {
        e->accept();
        return;
    }

    QModelIndexList indices = selectedIndexes();
    // Abort if nothing is selected
    if( indices.isEmpty() )
        return;

    KMenu menu;
    foreach( QAction *action, actionsForIndices( indices, PlaylistAction ) )
        menu.addAction( action );
    menu.addSeparator();

    // Create Copy/Move to menu items
    // ported from old filebrowser
    QList<Collections::Collection*> writableCollections;
    QHash<Collections::Collection*, CollectionManager::CollectionStatus> hash =
            CollectionManager::instance()->collections();
    QHash<Collections::Collection*, CollectionManager::CollectionStatus>::const_iterator it =
            hash.constBegin();
    while( it != hash.constEnd() )
    {
        Collections::Collection *coll = it.key();
        if( coll && coll->isWritable() )
            writableCollections.append( coll );
        ++it;
    }
    if( !writableCollections.isEmpty() )
    {
        QMenu *copyMenu = new QMenu( i18n( "Copy to Collection" ), &menu );
        copyMenu->setIcon( KIcon( "edit-copy" ) );
        foreach( Collections::Collection *coll, writableCollections )
        {
            CollectionAction *copyAction = new CollectionAction( coll, &menu );
            connect( copyAction, SIGNAL(triggered()), this, SLOT(slotPrepareCopyTracks()) );
            copyMenu->addAction( copyAction );
        }
KMenu* Contact::popupMenu()
{
	KMenu *menu = new KMenu();

	QString titleText;
	const QString nick = nickName();
	if( nick == contactId() )
		titleText = QString::fromLatin1( "%1 (%2)" ).arg( contactId(), onlineStatus().description() );
	else
		titleText = QString::fromLatin1( "%1 <%2> (%3)" ).arg( nick, contactId(), onlineStatus().description() );
	menu->addTitle( titleText );

	if( metaContact() && metaContact()->isTemporary() && contactId() != account()->myself()->contactId() )
	{
		KAction *actionAddContact = new KAction( KIcon("list-add-user"), i18n( "&Add to Your Contact List" ), menu );
		connect( actionAddContact, SIGNAL(triggered(bool)), this, SLOT(slotAddContact()) );

		menu->addAction(actionAddContact);
		menu->addSeparator();
	}
Example #16
0
void TabBar::emptyAreaContextMenu(const QPoint &pos)
{
    setupHistoryActions();

    KMenu menu;
    MainWindow *mainWindow = Application::instance()->mainWindow();

    menu.addAction(mainWindow->actionByName( QL1S("new_tab") ));
    menu.addAction(mainWindow->actionByName( QL1S("open_last_closed_tab") ));
    menu.addAction(mainWindow->actionByName( QL1S("closed_tab_menu") ));
    menu.addSeparator();
    menu.addAction(mainWindow->actionByName( QL1S("reload_all_tabs") ));

    KToolBar *mainBar = mainWindow->toolBar("mainToolBar");
    if(!mainBar->isVisible())
    {
        menu.addAction( mainBar->toggleViewAction() );
    }

    menu.exec(pos);
}
Example #17
0
void TwitterPostWidget::checkAnchor(const QUrl& url)
{
    QString scheme = url.scheme();
    TwitterApiMicroBlog* blog = qobject_cast<TwitterApiMicroBlog*>(currentAccount()->microblog());
    TwitterApiAccount *account = qobject_cast<TwitterApiAccount*>(currentAccount());
    if( scheme == "tag" ) {
        blog->searchBackend()->requestSearchResults(currentAccount(),
                                                    KUrl::fromPunycode(url.host().toUtf8()),
                                                    (int)TwitterSearch::ReferenceHashtag);
    } else if(scheme == "user") {
        KMenu menu;
        KAction * info = new KAction( KIcon("user-identity"), i18nc("Who is user", "Who is %1", url.host()),
                                      &menu );
        KAction * from = new KAction(KIcon("edit-find-user"), i18nc("Posts from user", "Posts from %1",url.host()),
                                     &menu);
        KAction * to = new KAction(KIcon("meeting-attending"), i18nc("Replies to user", "Replies to %1",
                                                                     url.host()),
                                   &menu);
        KAction *cont = new KAction(KIcon("user-properties"),i18nc("Including user name", "Including %1",
                                                                   url.host()),
                                    &menu);
        KAction * openInBrowser = new KAction(KIcon("applications-internet"),
                                              i18nc("Open profile page in browser",
                                                    "Open profile in browser"), &menu);
        from->setData(TwitterSearch::FromUser);
        to->setData(TwitterSearch::ToUser);
        cont->setData(TwitterSearch::ReferenceUser);
        menu.addAction(info);
        menu.addAction(from);
        menu.addAction(to);
        menu.addAction(cont);
        menu.addAction(openInBrowser);

        //Subscribe/UnSubscribe/Block
        bool isSubscribe = false;
        QString accountUsername = currentAccount()->username().toLower();
        QString postUsername = url.host().toLower();
        KAction *subscribe = 0, *block = 0, *replyTo = 0, *dMessage = 0;
        if(accountUsername != postUsername){
            menu.addSeparator();
            QMenu *actionsMenu = menu.addMenu(KIcon("applications-system"), i18n("Actions"));
            replyTo = new KAction(KIcon("edit-undo"), i18nc("Write a message to user attention", "Write to %1",
                                                          url.host()), actionsMenu);
            actionsMenu->addAction(replyTo);
            if( account->friendsList().contains( url.host(),
                Qt::CaseInsensitive ) ){
                dMessage = new KAction(KIcon("mail-message-new"), i18nc("Send direct message to user",
                                                                        "Send private message to %1",
                                                                        url.host()), actionsMenu);
                actionsMenu->addAction(dMessage);
                isSubscribe = false;//It's UnSubscribe
                subscribe = new KAction( KIcon("list-remove-user"),
                                         i18nc("Unfollow user",
                                               "Unfollow %1", url.host()), actionsMenu);
            } else {
                isSubscribe = true;
                subscribe = new KAction( KIcon("list-add-user"),
                                         i18nc("Follow user",
                                               "Follow %1", url.host()), actionsMenu);
            }
            block = new KAction( KIcon("dialog-cancel"),
                                 i18nc("Block user",
                                       "Block %1", url.host()), actionsMenu);
            actionsMenu->addAction(subscribe);
            actionsMenu->addAction(block);
        }

        QAction * ret = menu.exec(QCursor::pos());
        if(ret == 0)
            return;
        if(ret == info) {
            TwitterApiWhoisWidget *wd = new TwitterApiWhoisWidget(account, url.host(),  currentPost(), this);
            wd->show(QCursor::pos());
            return;
        } else if(ret == subscribe){
            if(isSubscribe) {
                blog->createFriendship(currentAccount(), url.host());
            } else {
                blog->destroyFriendship(currentAccount(), url.host());
            }
            return;
        }else if(ret == block){
            blog->blockUser(currentAccount(), url.host());
            return;
        } else if(ret == openInBrowser){
            Choqok::openUrl( QUrl( currentAccount()->microblog()->profileUrl(currentAccount(), url.host()) ) );
            return;
        } else if(ret == replyTo){
            emit reply( QString("@%1").arg(url.host()), QString() );
            return;
        } else if(ret == dMessage){
                blog->showDirectMessageDialog(account,url.host());
            return;
        }
        int type = ret->data().toInt();
        blog->searchBackend()->requestSearchResults(currentAccount(),
                                                    url.host(),
                                                    type);
    } else
        TwitterApiPostWidget::checkAnchor(url);
}
Example #18
0
// build a context menu
void UserMenuTree::contextMenuRequested(const QPoint &pos)
{
	KILE_DEBUG() << "context menu requested ..." ;

	m_popupItem = dynamic_cast<UserMenuItem*>(itemAt(pos));
	if ( !m_popupItem ) {
		KILE_DEBUG() << "... no item found";
		return;
	}

	KILE_DEBUG() << "... popup item found: " << m_popupItem->text(0);
	bool submenu = ( m_popupItem->menutype() ==  UserMenuData::Submenu );
	bool separator = ( m_popupItem->menutype() ==  UserMenuData::Separator );

	KMenu popup;
	QAction *action = NULL;
	QSignalMapper signalMapper;
	connect(&signalMapper, SIGNAL(mapped(int)), this, SLOT(slotPopupActivated(int)));

	// insert standard menu items
	action = popup.addAction(KIcon("usermenu-insert-above.png"),i18n("Insert above"), &signalMapper, SLOT(map()));
	signalMapper.setMapping(action, POPUP_INSERT_ABOVE);
	action = popup.addAction(KIcon("usermenu-insert-below.png"),i18n("Insert below"), &signalMapper, SLOT(map()));
	signalMapper.setMapping(action, POPUP_INSERT_BELOW);
	popup.addSeparator();

	// insert separators
	if ( !separator ) {
		action = popup.addAction(KIcon("usermenu-separator-above.png"),i18n("Insert a separator above"), &signalMapper, SLOT(map()));
		signalMapper.setMapping(action, POPUP_SEPARATOR_ABOVE);
		action = popup.addAction(KIcon("usermenu-separator-below.png"),i18n("Insert a separator below"), &signalMapper, SLOT(map()));
		signalMapper.setMapping(action, POPUP_SEPARATOR_BELOW);
		popup.addSeparator();
	}

	// insert submenus
	action = popup.addAction(KIcon("usermenu-submenu-above.png"),i18n("Insert a submenu above"), &signalMapper, SLOT(map()));
	signalMapper.setMapping(action, POPUP_SUBMENU_ABOVE);
	action = popup.addAction(KIcon("usermenu-submenu-below.png"),i18n("Insert a submenu below"), &signalMapper, SLOT(map()));
	signalMapper.setMapping(action, POPUP_SUBMENU_BELOW);
	popup.addSeparator();

	// insert into submenus
	if ( submenu ) {
		action = popup.addAction(KIcon("usermenu-into-submenu.png"),i18n("Insert into this submenu"), &signalMapper, SLOT(map()));
		signalMapper.setMapping(action, POPUP_INTO_SUBMENU);
		action = popup.addAction(i18n("Insert a separator into this submenu"), &signalMapper, SLOT(map()));
		signalMapper.setMapping(action, POPUP_SEPARATOR_INTO_SUBMENU);
		action = popup.addAction(i18n("Insert a submenu into this submenu"), &signalMapper, SLOT(map()));
		signalMapper.setMapping(action, POPUP_SUBMENU_INTO_SUBMENU);
		popup.addSeparator();
	}

	// delete actions
	action = popup.addAction(KIcon("usermenu-delete.png"),i18n("Delete this item"), &signalMapper, SLOT(map()));
	signalMapper.setMapping(action,POPUP_DELETE_ITEM);
	popup.addSeparator();
	action = popup.addAction(KIcon("usermenu-clear.png"),i18n("Delete the complete tree"), &signalMapper, SLOT(map()));
	signalMapper.setMapping(action, POPUP_DELETE_TREE);

	// expand/collapse tree
	if ( submenu ) {
		popup.addSeparator();
		if ( m_popupItem->isExpanded() ) {
			action = popup.addAction(i18n("Collapse submenu"), &signalMapper, SLOT(map()));
			signalMapper.setMapping(action,POPUP_COLLAPSE_ITEM);
		}
		else  {
			action = popup.addAction(i18n("Expand submenu"), &signalMapper, SLOT(map()));
			signalMapper.setMapping(action,POPUP_EXPAND_ITEM);
		}
		popup.addSeparator();
		action = popup.addAction(i18n("Collapse complete tree"), &signalMapper, SLOT(map()));
		signalMapper.setMapping(action,POPUP_COLLAPSE_TREE);
		action = popup.addAction(i18n("Expand complete tree"), &signalMapper, SLOT(map()));
		signalMapper.setMapping(action,POPUP_EXPAND_TREE);
	}

	// if there are any errors with this item, some info is available
	int error = m_popupItem->data(0,Qt::UserRole+2).toInt();
	if ( error != UserMenuItem::MODEL_ERROR_NONE ) {
		popup.addSeparator();
		action = popup.addAction(KIcon("help-about.png"),i18n("Info"), &signalMapper, SLOT(map()));
		signalMapper.setMapping(action, POPUP_ITEM_INFO);
	}

	// const QPoint& pos parameter in the customContextMenuRequested() signal is normally in widget coordinates.
	// But classes like QTreeWidget, which inherit from QAbstractScrollArea1 instead use the coordinates of their viewport()
	if ( !popup.isEmpty() ) {
		popup.exec( viewport()->mapToGlobal(pos) );
	}
}
void Launcher::dropUrls(const KUrl::List &urls, Qt::KeyboardModifiers modifiers)
{
    if (m_serviceGroup || !urls.count())
    {
        return;
    }

    if (m_mimeType->is("inode/directory"))
    {
        Qt::DropAction dropAction = Qt::CopyAction;

        if ((modifiers & Qt::ShiftModifier && modifiers & Qt::ControlModifier) || modifiers & Qt::AltModifier)
        {
            dropAction = Qt::LinkAction;
        }
        else if (modifiers & Qt::ShiftModifier)
        {
            dropAction = Qt::MoveAction;
        }
        else if (modifiers & Qt::ControlModifier)
        {
            dropAction = Qt::CopyAction;
        }
        else
        {
            KMenu *menu = new KMenu;
            QAction *moveAction = menu->addAction(KIcon("go-jump"), i18nc("@action:inmenu", "&Move Here\t<shortcut>%1</shortcut>", QKeySequence(Qt::ShiftModifier).toString()));
            QAction *copyAction = menu->addAction(KIcon("edit-copy"), i18nc("@action:inmenu", "&Copy Here\t<shortcut>%1</shortcut>", QKeySequence(Qt::ControlModifier).toString()));
            QAction *linkAction = menu->addAction(KIcon("insert-link"), i18nc("@action:inmenu", "&Link Here\t<shortcut>%1</shortcut>", QKeySequence(Qt::ControlModifier + Qt::ShiftModifier).toString()));

            menu->addSeparator();
            menu->addAction(KIcon("process-stop"), i18nc("@action:inmenu", "Cancel"));

            QAction *activatedAction = menu->exec(QCursor::pos());

            delete menu;

            if (activatedAction == moveAction)
            {
                dropAction = Qt::MoveAction;
            }
            else if (activatedAction == copyAction)
            {
                dropAction = Qt::CopyAction;
            }
            else if (activatedAction == linkAction)
            {
                dropAction = Qt::LinkAction;
            }
            else
            {
                return;
            }
        }

        switch (dropAction)
        {
            case Qt::MoveAction:
                KIO::move(urls, m_targetUrl);

                break;
            case Qt::CopyAction:
                KIO::copy(urls, m_targetUrl);

                break;
            case Qt::LinkAction:
                KIO::link(urls, m_targetUrl);

                break;
            default:
                return;
        }
    }
    else if (m_isExecutable)
    {
        QString arguments;
        QString command;

        for (int i = 0; i < urls.count(); ++i)
        {
            arguments += ' ' + KShell::quoteArg(urls[i].isLocalFile()?urls[i].path():urls[i].prettyUrl());
        }

        if (KDesktopFile::isDesktopFile(m_launcherUrl.toLocalFile()))
        {
            KDesktopFile desktopFile(m_launcherUrl.toLocalFile());
            KConfigGroup config = desktopFile.desktopGroup();

            command = config.readPathEntry("Exec", QString());

            if (command.isEmpty())
            {
                command = KShell::quoteArg(m_launcherUrl.path());
            }
        }
        else
        {
            command = KShell::quoteArg(m_launcherUrl.path());
        }

        KRun::runCommand(command + ' ' + arguments, NULL);
    }
}
Example #20
0
void Widget::sortOrderMenuAboutToShow()
{
  if ( !d->mAggregation )
    return;

  KMenu * menu = dynamic_cast< KMenu * >( sender() );
  if ( !menu )
    return;

  menu->clear();

  menu->addTitle( i18n( "Message Sort Order" ) );

  QActionGroup * grp;
  QAction * act;
  QList< QPair< QString, int > > options;
  QList< QPair< QString, int > >::ConstIterator it;

  grp = new QActionGroup( menu );

  options = SortOrder::enumerateMessageSortingOptions( d->mAggregation->threading() );

  for ( it = options.constBegin(); it != options.constEnd(); ++it )
  {
    act = menu->addAction( ( *it ).first );
    act->setCheckable( true );
    grp->addAction( act );
    act->setChecked( d->mSortOrder.messageSorting() == ( *it ).second );
    act->setData( QVariant( ( *it ).second ) );
  }

  connect( grp, SIGNAL( triggered( QAction * ) ),
           SLOT( messageSortingSelected( QAction * ) ) );

  options = SortOrder::enumerateMessageSortDirectionOptions( d->mSortOrder.messageSorting() );

  if ( options.size() >= 2 )
  {
    menu->addTitle( i18n( "Message Sort Direction" ) );

    grp = new QActionGroup( menu );

    for ( it = options.constBegin(); it != options.constEnd(); ++it )
    {
      act = menu->addAction( ( *it ).first );
      act->setCheckable( true );
      grp->addAction( act );
      act->setChecked( d->mSortOrder.messageSortDirection() == ( *it ).second );
      act->setData( QVariant( ( *it ).second ) );
    }

    connect( grp, SIGNAL( triggered( QAction * ) ),
             SLOT( messageSortDirectionSelected( QAction * ) ) );
  }

  options = SortOrder::enumerateGroupSortingOptions( d->mAggregation->grouping() );

  if ( options.size() >= 2 )
  {
    menu->addTitle( i18n( "Group Sort Order" ) );

    grp = new QActionGroup( menu );

    for ( it = options.constBegin(); it != options.constEnd(); ++it )
    {
      act = menu->addAction( ( *it ).first );
      act->setCheckable( true );
      grp->addAction( act );
      act->setChecked( d->mSortOrder.groupSorting() == ( *it ).second );
      act->setData( QVariant( ( *it ).second ) );
    }

    connect( grp, SIGNAL( triggered( QAction * ) ),
             SLOT( groupSortingSelected( QAction * ) ) );
  }

  options = SortOrder::enumerateGroupSortDirectionOptions( d->mAggregation->grouping(),
                                                           d->mSortOrder.groupSorting() );

  if ( options.size() >= 2 )
  {
    menu->addTitle( i18n( "Group Sort Direction" ) );

    grp = new QActionGroup( menu );

    for ( it = options.constBegin(); it != options.constEnd(); ++it )
    {
      act = menu->addAction( ( *it ).first );
      act->setCheckable( true );
      grp->addAction( act );
      act->setChecked( d->mSortOrder.groupSortDirection() == ( *it ).second );
      act->setData( QVariant( ( *it ).second ) );
    }

    connect( grp, SIGNAL( triggered( QAction * ) ),
             SLOT( groupSortDirectionSelected( QAction * ) ) );
  }

  menu->addSeparator();
  act = menu->addAction( i18n( "Folder Always Uses This Sort Order" ) );
  act->setCheckable( true );
  act->setChecked( d->mStorageUsesPrivateSortOrder );
  connect( act, SIGNAL( triggered( bool ) ),
           SLOT( setPrivateSortOrderForStorage() ) );
}