22#include <tqeventloop.h> 
   25#include <tdeapplication.h> 
   26#include <kbookmarkmanager.h> 
   29#include <kprotocolinfo.h> 
   30#include <kiconloader.h> 
   31#include <kinputdialog.h> 
   32#include <tdeglobalsettings.h> 
   33#include <tdestandarddirs.h> 
   34#include <kxmlguifactory.h> 
   35#include <kxmlguibuilder.h> 
   36#include <tdeparts/componentfactory.h> 
   40#include <tdefileshare.h> 
   41#include <tdeprocess.h> 
   43#include "kpropertiesdialog.h" 
   45#include "konq_popupmenu.h" 
   46#include "konq_operations.h" 
   47#include "konq_xmlguiclient.h" 
   48#include <dcopclient.h> 
   72class KonqPopupMenuGUIBuilder : 
public KXMLGUIBuilder
 
   75  KonqPopupMenuGUIBuilder( TQPopupMenu *menu )
 
   80  virtual ~KonqPopupMenuGUIBuilder()
 
   84  virtual TQWidget *createContainer( TQWidget *parent, 
int index,
 
   85          const TQDomElement &element,
 
   88    if ( !parent && element.attribute( 
"name" ) == 
"popupmenu" )
 
   91    return KXMLGUIBuilder::createContainer( parent, index, element, 
id );
 
   97class KonqPopupMenu::KonqPopupMenuPrivate
 
  100  KonqPopupMenuPrivate() : m_parentWidget( 0 ),
 
  101                           m_itemFlags( KParts::BrowserExtension::DefaultPopupItems )
 
  105  TQWidget *m_parentWidget;
 
  106  KParts::BrowserExtension::PopupFlags m_itemFlags;
 
  108  bool localURLSlotFired;
 
  109  KURL localURLResultURL;
 
  110  bool localURLResultIsLocal;
 
  113KonqPopupMenu::ProtocolInfo::ProtocolInfo()
 
  119  m_TrashIncluded = 
false;
 
  122bool KonqPopupMenu::ProtocolInfo::supportsReading()
 const 
  127bool KonqPopupMenu::ProtocolInfo::supportsWriting()
 const 
  132bool KonqPopupMenu::ProtocolInfo::supportsDeleting()
 const 
  137bool KonqPopupMenu::ProtocolInfo::supportsMoving()
 const 
  142bool KonqPopupMenu::ProtocolInfo::trashIncluded()
 const 
  144  return m_TrashIncluded;
 
  152    ServiceList* selectList( 
const TQString& priority, 
const TQString& submenuName );
 
  155    ServiceList user, userToplevel, userPriority;
 
  156    TQMap<TQString, ServiceList> userSubmenus, userToplevelSubmenus, userPrioritySubmenus;
 
  159ServiceList* PopupServices::selectList( 
const TQString& priority, 
const TQString& submenuName )
 
  163    if (submenuName.isEmpty())
 
  165        if (priority == 
"TopLevel")
 
  167            return &userToplevel;
 
  169        else if (priority == 
"Important")
 
  171            return &userPriority;
 
  174    else if (priority == 
"TopLevel")
 
  176        return &(userToplevelSubmenus[submenuName]);
 
  178    else if (priority == 
"Important")
 
  180        return &(userPrioritySubmenus[submenuName]);
 
  184        return &(userSubmenus[submenuName]);
 
  193                              TDEActionCollection & actions,
 
  195                              bool showProperties )
 
  196    : TQPopupMenu( 0L, 
"konq_popupmenu" ),
 
  197      m_actions( actions ), m_ownActions( static_cast<TQWidget *>( 0 ), 
"KonqPopupMenu::m_ownActions" ),
 
  198          m_pMenuNew( newMenu ), m_sViewURL(viewURL), m_lstItems(items), m_pManager(mgr)
 
  201    init(0, kpf, KParts::BrowserExtension::DefaultPopupItems);
 
  206                              TDEActionCollection & actions,
 
  208                              TQWidget * parentWidget,
 
  209                              bool showProperties )
 
  210    : TQPopupMenu( parentWidget, 
"konq_popupmenu" ), m_actions( actions ), m_ownActions( static_cast<TQWidget *>( 0 ), 
"KonqPopupMenu::m_ownActions" ), m_pMenuNew( newMenu ), m_sViewURL(viewURL), m_lstItems(items), m_pManager(mgr)
 
  213    init(parentWidget, kpf, KParts::BrowserExtension::DefaultPopupItems);
 
  218                              TDEActionCollection & actions,
 
  220                              TQWidget * parentWidget,
 
  222                              KParts::BrowserExtension::PopupFlags flags)
 
  223  : TQPopupMenu( parentWidget, 
"konq_popupmenu" ), m_actions( actions ), m_ownActions( static_cast<TQWidget *>( 0 ), 
"KonqPopupMenu::m_ownActions" ), m_pMenuNew( newMenu ), m_sViewURL(viewURL), m_lstItems(items), m_pManager(mgr)
 
  225    init(parentWidget, kpf, flags);
 
  228void KonqPopupMenu::init (TQWidget * parentWidget, KonqPopupFlags kpf, KParts::BrowserExtension::PopupFlags flags)
 
  230    d = 
new KonqPopupMenuPrivate;
 
  231    d->m_parentWidget = parentWidget;
 
  232    d->m_itemFlags = flags;
 
  236int KonqPopupMenu::insertServicesSubmenus(
const TQMap<TQString, ServiceList>& submenus,
 
  241    TQMap<TQString, ServiceList>::ConstIterator it;
 
  243    for (it = submenus.begin(); it != submenus.end(); ++it)
 
  245        if (it.data().isEmpty())
 
  251        TQDomElement actionSubmenu = m_doc.createElement( 
"menu" );
 
  252        actionSubmenu.setAttribute( 
"name", 
"actions " + it.key() );
 
  253        menu.appendChild( actionSubmenu );
 
  254        TQDomElement subtext = m_doc.createElement( 
"text" );
 
  255        actionSubmenu.appendChild( subtext );
 
  256        subtext.appendChild( m_doc.createTextNode( it.key() ) );
 
  257        count += insertServices(it.data(), actionSubmenu, isBuiltin);
 
  263int KonqPopupMenu::insertServices(
const ServiceList& list,
 
  267    static int id = 1000;
 
  270    ServiceList::const_iterator it = list.begin();
 
  271    for( ; it != list.end(); ++it )
 
  275            if (!menu.firstChild().isNull() &&
 
  276                menu.lastChild().toElement().tagName().lower() != 
"separator")
 
  278                TQDomElement separator = m_doc.createElement( 
"separator" );
 
  279                menu.appendChild(separator);
 
  284        if (isBuiltin || (*it).m_display == 
true)
 
  288            name.prepend( isBuiltin ? 
"builtinservice_" : 
"userservice_" );
 
  289            TDEAction * act = 
new TDEAction( TQString((*it).m_strName).replace(
'&',
"&&"), 0,
 
  290                                         this, TQ_SLOT( slotRunService() ),
 
  291                                         &m_ownActions, name );
 
  293            if ( !(*it).m_strIcon.isEmpty() )
 
  295                TQPixmap pix = SmallIcon( (*it).m_strIcon );
 
  296                act->setIconSet( pix );
 
  299            addAction( act, menu ); 
 
  301            m_mapPopupServices[ 
id++ ] = *it;
 
  309bool KonqPopupMenu::KIOSKAuthorizedAction(TDEConfig& cfg)
 
  311    if ( !cfg.hasKey( 
"X-TDE-AuthorizeAction") )
 
  316    TQStringList list = cfg.readListEntry(
"X-TDE-AuthorizeAction");
 
  317    if (tdeApp && !list.isEmpty())
 
  319        for(TQStringList::ConstIterator it = list.begin();
 
  323            if (!tdeApp->authorize((*it).stripWhiteSpace()))
 
  334void KonqPopupMenu::setup(KonqPopupFlags kpf)
 
  336    assert( m_lstItems.count() >= 1 );
 
  338    m_ownActions.setWidget( 
this );
 
  340    const bool bIsLink   = (kpf & 
IsLink);
 
  341    bool currentDir      = 
false;
 
  342    bool sReading        = 
true;
 
  343    bool sDeleting       = ( d->m_itemFlags & KParts::BrowserExtension::NoDeletion ) == 0;
 
  344    bool sMoving         = sDeleting;
 
  345    bool sWriting        = sDeleting && m_lstItems.first()->isWritable();
 
  346    m_sMimeType          = m_lstItems.first()->mimetype();
 
  347    TQString mimeGroup   = m_sMimeType.left(m_sMimeType.find(
'/'));
 
  348    mode_t mode          = m_lstItems.first()->mode();
 
  349    bool isDirectory     = S_ISDIR(mode);
 
  350    bool isMediaFile     = 
false;
 
  351    bool isEncryptedMediaFile = 
false;
 
  352    bool isReallyLocal   = m_lstItems.first()->isLocalFile();
 
  353    bool isLocal         = isReallyLocal || m_lstItems.first()->url().protocol()==
"media" ||
 
  354                           m_lstItems.first()->url().protocol()==
"system";
 
  355    bool isTrashIncluded = 
false;
 
  356    bool isTrashLink     = 
false;
 
  357    m_lstPopupURLs.clear();
 
  359    setFont(TDEGlobalSettings::menuFont());
 
  360    m_pluginList.setAutoDelete( 
true );
 
  361    m_ownActions.setHighlightingEnabled( 
true );
 
  363    attrName = TQString::fromLatin1( 
"name" );
 
  365    prepareXMLGUIStuff();
 
  366    m_builder = 
new KonqPopupMenuGUIBuilder( 
this );
 
  367    m_factory = 
new KXMLGUIFactory( m_builder );
 
  370    KFileItemListIterator it ( m_lstItems );
 
  371    TQStringList mimeTypeList;
 
  373    for ( ; it.current(); ++it )
 
  378        m_lstPopupURLs.append( url );
 
  381        if ( mode != (*it)->mode() )
 
  385        if ( m_sMimeType != (*it)->mimetype() )
 
  387            m_sMimeType = TQString::null; 
 
  389            if ( mimeGroup != (*it)->mimetype().left((*it)->mimetype().find(
'/')))
 
  390                mimeGroup = TQString::null; 
 
  393        if ( mimeTypeList.findIndex( (*it)->mimetype() ) == -1 )
 
  394            mimeTypeList << (*it)->mimetype();
 
  396        if ( isReallyLocal && !url.isLocalFile() )
 
  397            isReallyLocal = 
false;
 
  398        if ( isLocal && !url.isLocalFile() && url.protocol() != 
"media" && url.protocol() != 
"system" )
 
  401        if ( !isTrashIncluded && (
 
  402             ( url.protocol() == 
"trash" && url.path().length() <= 1 )
 
  403             || url.url() == 
"system:/trash" || url.url() == 
"system:/trash/" ) ) {
 
  404            isTrashIncluded = 
true;
 
  409            sReading = KProtocolInfo::supportsReading( url );
 
  412            sWriting = KProtocolInfo::supportsWriting( url ) && (*it)->isWritable();
 
  415            sDeleting = KProtocolInfo::supportsDeleting( url );
 
  418            sMoving = KProtocolInfo::supportsMoving( url );
 
  419        if ( (*it)->mimetype().startsWith(
"media/") ) {
 
  421            if ( (*it)->mimetype().contains(
"encrypted")) {
 
  422                isEncryptedMediaFile = 
true;
 
  428    KURL realURL = m_sViewURL;
 
  429    if (!realURL.isLocalFile()) {
 
  430        d->localURLSlotFired = 
false;
 
  431        TDEIO::LocalURLJob* localURLJob = TDEIO::localURL(m_sViewURL);
 
  433            connect(localURLJob, TQ_SIGNAL(localURL(TDEIO::LocalURLJob*, 
const KURL&, 
bool)), 
this, TQ_SLOT(slotLocalURL(TDEIO::LocalURLJob*, 
const KURL&, 
bool)));
 
  434            connect(localURLJob, TQ_SIGNAL(destroyed()), 
this, TQ_SLOT(slotLocalURLKIODestroyed()));
 
  435            while (!d->localURLSlotFired) {
 
  436                tdeApp->eventLoop()->enterLoop();
 
  438            if (d->localURLResultIsLocal) {
 
  439                realURL = d->localURLResultURL;
 
  448    if ( m_lstItems.count() == 1 )
 
  450        KURL firstPopupURL( m_lstItems.first()->url() );
 
  451        firstPopupURL.cleanPath();
 
  454        currentDir = firstPopupURL.equals( url, 
true , 
true  );
 
  455        if ( isLocal && ((m_sMimeType == 
"application/x-desktop")
 
  456                      || (m_sMimeType == 
"media/builtin-mydocuments")
 
  457                      || (m_sMimeType == 
"media/builtin-mycomputer")
 
  458                      || (m_sMimeType == 
"media/builtin-mynetworkplaces")
 
  459                      || (m_sMimeType == 
"media/builtin-printers")
 
  460                      || (m_sMimeType == 
"media/builtin-trash")
 
  461                      || (m_sMimeType == 
"media/builtin-webbrowser")) ) {
 
  462            TDESimpleConfig cfg( firstPopupURL.path(), 
true );
 
  463            cfg.setDesktopGroup();
 
  464            isTrashLink = ( cfg.readEntry(
"Type") == 
"Link" && cfg.readEntry(
"URL") == 
"trash:/" );
 
  472    m_info.m_Reading = sReading;
 
  473    m_info.m_Writing = sWriting;
 
  474    m_info.m_Deleting = sDeleting;
 
  475    m_info.m_Moving = sMoving;
 
  476    m_info.m_TrashIncluded = isTrashIncluded;
 
  479    bool isCurrentTrash = ( m_lstItems.count() == 1 && isTrashIncluded ) || isTrashLink;
 
  480    bool isIntoTrash = ( url.protocol() == 
"trash" || url.url().startsWith( 
"system:/trash" ) ) && !isCurrentTrash; 
 
  489        addMerge( 
"konqueror" );
 
  491    bool isKDesktop = TQCString( tdeApp->name() ) == 
"kdesktop";
 
  494        !tdeApp->authorize(
"editable_desktop_icons"))
 
  496        kpf &= ~ShowProperties; 
 
  501    if ( ((kpf & ShowNewWindow) != 0) && sReading  && !isEncryptedMediaFile)
 
  503        TQString openStr = isKDesktop ? i18n( 
"&Open" ) : i18n( 
"Open in New &Window" );
 
  504        TDEAction *actNewWindow = 
new TDEAction( openStr, 
"window-new", 0, 
this, TQ_SLOT( slotPopupNewView() ), &m_ownActions, 
"newview" );
 
  505        actNewWindow->setToolTip( i18n( 
"Open item in a new window" ) );
 
  506        addAction( actNewWindow );
 
  510    if ( S_ISDIR(mode) && sWriting && !isCurrentTrash ) 
 
  512        if ( currentDir && m_pMenuNew ) 
 
  518            addAction( m_pMenuNew );
 
  524            if (d->m_itemFlags & KParts::BrowserExtension::ShowCreateDirectory)
 
  526                TDEAction *actNewDir = 
new TDEAction( i18n( 
"Create &Folder..." ), 
"folder-new", 0, 
this, TQ_SLOT( slotPopupNewDir() ), &m_ownActions, 
"newdir" );
 
  527                addAction( actNewDir );
 
  531    } 
else if ( isIntoTrash ) {
 
  533        act = 
new TDEAction( i18n( 
"&Restore" ), 0, 
this, TQ_SLOT( slotPopupRestoreTrashedItems() ), &m_ownActions, 
"restore" );
 
  537    if (d->m_itemFlags & KParts::BrowserExtension::ShowNavigationItems)
 
  539        if (d->m_itemFlags & KParts::BrowserExtension::ShowUp)
 
  542        addAction( 
"forward" );
 
  543        if (d->m_itemFlags & KParts::BrowserExtension::ShowReload)
 
  544            addAction( 
"reload" );
 
  548    if (!isEncryptedMediaFile)
 
  550        addGroup( 
"tabhandling" ); 
 
  555        if ( !currentDir && sReading ) {
 
  562        if ( S_ISDIR(mode) && sWriting ) {
 
  564                addAction( 
"paste" );
 
  566                addAction( 
"pasteto" );
 
  570            if ( m_lstItems.count() == 1 && sMoving )
 
  571                addAction( 
"rename" );
 
  573            bool addTrash = 
false;
 
  576            if ( sMoving && !isIntoTrash && !isTrashLink )
 
  582                else if (TDEApplication::keyboardMouseState() & TQt::ShiftButton) {
 
  587                    TDEConfigGroup configGroup( tdeApp->config(), 
"KDE" );
 
  588                    if ( configGroup.readBoolEntry( 
"ShowDeleteCommand", 
false ) )
 
  594                addAction( 
"trash" );
 
  599    if ( isCurrentTrash )
 
  601        act = 
new TDEAction( i18n( 
"&Empty Trash Bin" ), 
"emptytrash", 0, 
this, TQ_SLOT( slotPopupEmptyTrashBin() ), &m_ownActions, 
"empytrash" );
 
  602        TDESimpleConfig trashConfig( 
"trashrc", 
true );
 
  603        trashConfig.setGroup( 
"Status" );
 
  604        act->setEnabled( !trashConfig.readBoolEntry( 
"Empty", 
true ) );
 
  607    addGroup( 
"editactions" );
 
  609    if (d->m_itemFlags & KParts::BrowserExtension::ShowTextSelectionItems) {
 
  611      m_factory->addClient( 
this );
 
  615    if ( !isCurrentTrash && !isIntoTrash && (d->m_itemFlags & KParts::BrowserExtension::ShowBookmark))
 
  621           bool httpPage = (m_sViewURL.protocol().find(
"http", 0, 
false) == 0);
 
  623              caption = i18n(
"&Bookmark This Page");
 
  625              caption = i18n(
"&Bookmark This Location");
 
  627        else if (S_ISDIR(mode))
 
  628           caption = i18n(
"&Bookmark This Folder");
 
  630           caption = i18n(
"&Bookmark This Link");
 
  632           caption = i18n(
"&Bookmark This File");
 
  634        act = 
new TDEAction( caption, 
"bookmark_add", 0, 
this, TQ_SLOT( slotPopupAddToBookmark() ), &m_ownActions, 
"bookmark_add" );
 
  635        if (m_lstItems.count() > 1)
 
  636            act->setEnabled(
false);
 
  637        if (tdeApp->authorizeTDEAction(
"bookmarks"))
 
  640            addGroup( 
"linkactions" );
 
  645    const bool isSingleLocal = m_lstItems.count() == 1 && isLocal;
 
  647    KURL urlForServiceMenu( m_lstItems.first()->url() );
 
  648    if (isLocal && !isReallyLocal) { 
 
  650        urlForServiceMenu = m_lstItems.first()->mostLocalURL(dummy);
 
  654    if ( ((m_sMimeType == 
"application/x-desktop")
 
  655       || (m_sMimeType == 
"media/builtin-mydocuments")
 
  656       || (m_sMimeType == 
"media/builtin-mycomputer")
 
  657       || (m_sMimeType == 
"media/builtin-mynetworkplaces")
 
  658       || (m_sMimeType == 
"media/builtin-printers")
 
  659       || (m_sMimeType == 
"media/builtin-trash")
 
  660       || (m_sMimeType == 
"media/builtin-webbrowser")) && isSingleLocal ) 
 
  663        s.builtin = KDEDesktopMimeType::builtinServices( urlForServiceMenu );
 
  664        const TQString path = urlForServiceMenu.path();
 
  665        TDESimpleConfig cfg( path, 
true );
 
  666        cfg.setDesktopGroup();
 
  667        const TQString priority = cfg.readEntry(
"X-TDE-Priority");
 
  668        const TQString submenuName = cfg.readEntry( 
"X-TDE-Submenu" );
 
  669        if ( cfg.readEntry(
"Type") == 
"Link" ) {
 
  670           urlForServiceMenu = cfg.readEntry(
"URL");
 
  674        ServiceList* list = s.selectList( priority, submenuName );
 
  675        (*list) = KDEDesktopMimeType::userDefinedServices( path, cfg, urlForServiceMenu.isLocalFile() );
 
  684        if (isDirectory && isSingleLocal)
 
  686            TQString dotDirectoryFile = urlForServiceMenu.path(1).append(
".directory");
 
  687            TDESimpleConfig cfg( dotDirectoryFile, 
true );
 
  688            cfg.setDesktopGroup();
 
  690            if (KIOSKAuthorizedAction(cfg))
 
  692                const TQString priority = cfg.readEntry(
"X-TDE-Priority");
 
  693                const TQString submenuName = cfg.readEntry( 
"X-TDE-Submenu" );
 
  694                ServiceList* list = s.selectList( priority, submenuName );
 
  695                (*list) += KDEDesktopMimeType::userDefinedServices( dotDirectoryFile, cfg, 
true );
 
  700        TQStringList entries = TDEGlobal::dirs()->findAllResources(
"data",
 
  701                "konqueror/servicemenus/*.desktop", 
false, 
true);
 
  703        TQStringList::ConstIterator eIt = entries.begin();
 
  704        const TQStringList::ConstIterator eEnd = entries.end();
 
  705        for (; eIt != eEnd; ++eIt )
 
  707            TDESimpleConfig cfg( *eIt, 
true );
 
  708            cfg.setDesktopGroup();
 
  710            if (!KIOSKAuthorizedAction(cfg))
 
  715            if ( cfg.hasKey( 
"X-TDE-ShowIfRunning" ) )
 
  717                const TQString app = cfg.readEntry( 
"X-TDE-ShowIfRunning" );
 
  718                if ( !tdeApp->dcopClient()->isApplicationRegistered( app.utf8() ) )
 
  721            if ( cfg.hasKey( 
"X-TDE-ShowIfDcopCall" ) )
 
  723                TQString dcopcall = cfg.readEntry( 
"X-TDE-ShowIfDcopCall" );
 
  724                const TQCString app = TQString(dcopcall.section(
' ', 0,0)).utf8();
 
  729                TQByteArray dataToSend;
 
  730                TQDataStream dataStream(dataToSend, IO_WriteOnly);
 
  731                dataStream << m_lstPopupURLs;
 
  734                TQByteArray replyData;
 
  735                TQCString 
object = TQString(dcopcall.section(
' ', 1,-2)).utf8();
 
  736                TQString function =  TQString(dcopcall.section(
' ', -1));
 
  737                if(!function.endsWith(
"(KURL::List)")) {
 
  738                    kdWarning() << 
"Desktop file " << *eIt << 
" contains an invalid X-TDE-ShowIfDcopCall - the function must take the exact parameter (KURL::List) and must be specified." << endl;
 
  742                if(!tdeApp->dcopClient()->call( app, 
object,
 
  744                                              dataToSend, replyType, replyData, 
true, 1000))
 
  746                if(replyType != 
"bool" || !replyData[0])
 
  750            if ( cfg.hasKey( 
"X-TDE-Protocol" ) )
 
  752                const TQString protocol = cfg.readEntry( 
"X-TDE-Protocol" );
 
  753                if ( protocol != urlForServiceMenu.protocol() )
 
  756            else if ( cfg.hasKey( 
"X-TDE-Protocols" ) )
 
  758                TQStringList protocols = TQStringList::split( 
"," , cfg.readEntry( 
"X-TDE-Protocols" ) );
 
  759                if ( !protocols.contains( urlForServiceMenu.protocol() ) )
 
  762            else if ( urlForServiceMenu.protocol() == 
"trash" || urlForServiceMenu.url().startsWith( 
"system:/trash" ) )
 
  770            if ( cfg.hasKey( 
"X-TDE-Require" ) )
 
  772                const TQStringList capabilities = cfg.readListEntry( 
"X-TDE-Require" );
 
  773                if ( capabilities.contains( 
"Write" ) && !sWriting )
 
  776            if ( (cfg.hasKey( 
"Actions" ) || cfg.hasKey( 
"X-TDE-GetActionMenu") ) && cfg.hasKey( 
"X-TDE-ServiceTypes" ) )
 
  778                const TQStringList types = cfg.readListEntry( 
"X-TDE-ServiceTypes" );
 
  779                const TQStringList excludeTypes = cfg.readListEntry( 
"X-TDE-ExcludeServiceTypes" );
 
  783                for (TQStringList::ConstIterator it = types.begin();
 
  784                     it != types.end() && !ok;
 
  788                    bool checkTheMimetypes = 
false;
 
  789                    if (*it == 
"all/all" ||
 
  792                        checkTheMimetypes = 
true;
 
  798                        *it == 
"all/allfiles")
 
  800                        checkTheMimetypes = 
true;
 
  805                        (!m_sMimeType.isEmpty() &&
 
  806                         *it == m_sMimeType)) ||
 
  807                        (!mimeGroup.isEmpty() &&
 
  808                         (((*it).right(1) == 
"*") &&
 
  809                          (*it).left((*it).find(
'/')) == mimeGroup)))
 
  811                        checkTheMimetypes = 
true;
 
  814                    if (checkTheMimetypes)
 
  817                        for (TQStringList::ConstIterator itex = excludeTypes.begin(); itex != excludeTypes.end(); ++itex)
 
  819                            if( ((*itex).right(1) == 
"*" && (*itex).left((*itex).find(
'/')) == mimeGroup) ||
 
  820                                ((*itex) == m_sMimeType) )
 
  831                    const TQString priority = cfg.readEntry(
"X-TDE-Priority");
 
  832                    const TQString submenuName = cfg.readEntry( 
"X-TDE-Submenu" );
 
  834                    ServiceList *list = s.selectList( priority, submenuName );
 
  835                    (*list) += KDEDesktopMimeType::userDefinedServices( *eIt, cfg, url.isLocalFile(), m_lstPopupURLs );
 
  840        TDETrader::OfferList offers;
 
  842        if (tdeApp->authorizeTDEAction(
"openwith"))
 
  844            TQString constraint = 
"Type == 'Application' and DesktopEntryName != 'kfmclient' and DesktopEntryName != 'kfmclient_dir' and DesktopEntryName != 'kfmclient_html'";
 
  845            TQString subConstraint = 
" and '%1' in ServiceTypes";
 
  847            TQStringList::ConstIterator it = mimeTypeList.begin();
 
  848            TQStringList::ConstIterator end = mimeTypeList.end();
 
  849            Q_ASSERT( it != end );
 
  850            TQString first = *it;
 
  852            while ( it != end ) {
 
  853                constraint += subConstraint.arg( *it );
 
  857            offers = TDETrader::self()->query( first, constraint );
 
  863        m_mapPopupServices.clear();
 
  866        if ( !isDirectory || isLocal )
 
  871            if ( !offers.isEmpty() )
 
  876                TQDomElement menu = m_menuElement;
 
  878                if ( offers.count() > 1 ) 
 
  880                    menu = m_doc.createElement( 
"menu" );
 
  881                    menu.setAttribute( 
"name", 
"openwith submenu" );
 
  882                    m_menuElement.appendChild( menu );
 
  883                    TQDomElement text = m_doc.createElement( 
"text" );
 
  884                    menu.appendChild( text );
 
  885                    text.appendChild( m_doc.createTextNode( i18n(
"&Open With") ) );
 
  888                TDETrader::OfferList::ConstIterator it = offers.begin();
 
  889                for( ; it != offers.end(); it++ )
 
  891                    KService::Ptr service = (*it);
 
  897                    const TQString onlyShowIn = service->property(
"OnlyShowIn", TQVariant::String).toString();
 
  898                    if ( !onlyShowIn.isEmpty() ) {
 
  899                        const TQStringList aList = TQStringList::split(
';', onlyShowIn);
 
  900                        if (!aList.contains(
"TDE"))
 
  903                    const TQString notShowIn = service->property(
"NotShowIn", TQVariant::String).toString();
 
  904                    if ( !notShowIn.isEmpty() ) {
 
  905                        const TQStringList aList = TQStringList::split(
';', notShowIn);
 
  906                        if (aList.contains(
"TDE"))
 
  913                    TQString actionName( (*it)->name().replace(
"&", 
"&&") );
 
  914                    if ( menu == m_menuElement ) 
 
  915                        actionName = i18n( 
"Open with %1" ).arg( actionName );
 
  917                    act = 
new TDEAction( actionName, (*it)->pixmap( TDEIcon::Small ), 0,
 
  918                                       this, TQ_SLOT( slotRunService() ),
 
  919                                       &m_ownActions, nam.prepend( 
"appservice_" ) );
 
  920                    addAction( act, menu );
 
  922                    m_mapPopup[ 
id++ ] = *it;
 
  925                TQString openWithActionName;
 
  926                if ( menu != m_menuElement ) 
 
  928                    addSeparator( menu );
 
  929                    openWithActionName = i18n( 
"&Other..." );
 
  933                    openWithActionName = i18n( 
"&Open With..." );
 
  935                TDEAction *openWithAct = 
new TDEAction( openWithActionName, 0, 
this, TQ_SLOT( slotPopupOpenWith() ), &m_ownActions, 
"openwith" );
 
  936                addAction( openWithAct, menu );
 
  940                act = 
new TDEAction( i18n( 
"&Open With..." ), 0, 
this, TQ_SLOT( slotPopupOpenWith() ), &m_ownActions, 
"openwith" );
 
  945        addGroup( 
"preview" );
 
  949    TQDomElement actionMenu = m_menuElement;
 
  950    int userItemCount = 0;
 
  951    if (s.user.count() + s.userSubmenus.count() +
 
  952        s.userPriority.count() + s.userPrioritySubmenus.count() > 1)
 
  955        actionMenu = m_doc.createElement( 
"menu" );
 
  956        actionMenu.setAttribute( 
"name", 
"actions submenu" );
 
  957        m_menuElement.appendChild( actionMenu );
 
  958        TQDomElement text = m_doc.createElement( 
"text" );
 
  959        actionMenu.appendChild( text );
 
  960        text.appendChild( m_doc.createTextNode( i18n(
"Ac&tions") ) );
 
  963    userItemCount += insertServicesSubmenus(s.userPrioritySubmenus, actionMenu, 
false);
 
  964    userItemCount += insertServices(s.userPriority, actionMenu, 
false);
 
  967    if (userItemCount > 0 &&
 
  968        (s.user.count() > 0 ||
 
  969         s.userSubmenus.count() > 0 ||
 
  970         s.builtin.count() > 0) &&
 
  971         actionMenu.lastChild().toElement().tagName().lower() != 
"separator")
 
  973        TQDomElement separator = m_doc.createElement( 
"separator" );
 
  974        actionMenu.appendChild(separator);
 
  977    userItemCount += insertServicesSubmenus(s.userSubmenus, actionMenu, 
false);
 
  978    userItemCount += insertServices(s.user, actionMenu, 
false);
 
  979    userItemCount += insertServices(s.builtin, m_menuElement, 
true);
 
  981    userItemCount += insertServicesSubmenus(s.userToplevelSubmenus, m_menuElement, 
false);
 
  982    userItemCount += insertServices(s.userToplevel, m_menuElement, 
false);
 
  984    if ( userItemCount > 0 )
 
  989    if ( !isCurrentTrash && !isIntoTrash && !isMediaFile && sReading )
 
  992    if ( KPropertiesDialog::canDisplay( m_lstItems ) && (kpf & 
ShowProperties) )
 
  994        act = 
new TDEAction( i18n( 
"&Properties" ), 
"edit", 0, 
this, TQ_SLOT( slotPopupProperties() ),
 
  995                           &m_ownActions, 
"properties" );
 
  999    while ( !m_menuElement.lastChild().isNull() &&
 
 1000            m_menuElement.lastChild().toElement().tagName().lower() == 
"separator" )
 
 1001        m_menuElement.removeChild( m_menuElement.lastChild() );
 
 1003    if ( isDirectory && isLocal )
 
 1005        if ( KFileShare::authorization() == KFileShare::Authorized )
 
 1008            act = 
new TDEAction( i18n(
"Share"), 0, 
this, TQ_SLOT( slotOpenShareFileDialog() ),
 
 1009                               &m_ownActions, 
"sharefile" );
 
 1017    m_factory->addClient( 
this );
 
 1020void KonqPopupMenu::slotOpenShareFileDialog()
 
 1022    KPropertiesDialog* dlg = showPropertiesDialog();
 
 1023    dlg->showFileSharingPage();
 
 1028  m_pluginList.clear();
 
 1037    d->m_urlTitle = urlTitle;
 
 1040void KonqPopupMenu::slotPopupNewView()
 
 1042  KURL::List::ConstIterator it = m_lstPopupURLs.begin();
 
 1043  for ( ; it != m_lstPopupURLs.end(); it++ )
 
 1044    (
void) 
new KRun(*it);
 
 1047void KonqPopupMenu::slotPopupNewDir()
 
 1049  if (m_lstPopupURLs.empty())
 
 1055void KonqPopupMenu::slotPopupEmptyTrashBin()
 
 1057  KonqOperations::emptyTrash();
 
 1060void KonqPopupMenu::slotPopupRestoreTrashedItems()
 
 1062  KonqOperations::restoreTrashedItems( m_lstPopupURLs );
 
 1065void KonqPopupMenu::slotPopupOpenWith()
 
 1067  KRun::displayOpenWithDialog( m_lstPopupURLs );
 
 1070void KonqPopupMenu::slotPopupAddToBookmark()
 
 1072  KBookmarkGroup root;
 
 1073  if ( m_lstPopupURLs.count() == 1 ) {
 
 1074    KURL url = m_lstPopupURLs.first();
 
 1075    TQString title = d->m_urlTitle.isEmpty() ? url.prettyURL() : d->m_urlTitle;
 
 1076    root = m_pManager->addBookmarkDialog( url.prettyURL(), title );
 
 1080    root = m_pManager->root();
 
 1081    KURL::List::ConstIterator it = m_lstPopupURLs.begin();
 
 1082    for ( ; it != m_lstPopupURLs.end(); it++ )
 
 1083      root.addBookmark( m_pManager, (*it).prettyURL(), (*it) );
 
 1085  m_pManager->emitChanged( root );
 
 1088void KonqPopupMenu::slotRunService()
 
 1090  TQCString senderName = sender()->name();
 
 1091  int id = senderName.mid( senderName.find( 
'_' ) + 1 ).toInt();
 
 1094  TQMap<int,KService::Ptr>::Iterator it = m_mapPopup.find( 
id );
 
 1095  if ( it != m_mapPopup.end() )
 
 1097    KRun::run( **it, m_lstPopupURLs );
 
 1102  TQMap<int,KDEDesktopMimeType::Service>::Iterator it2 = m_mapPopupServices.find( 
id );
 
 1103  if ( it2 != m_mapPopupServices.end() )
 
 1105      KDEDesktopMimeType::executeService( m_lstPopupURLs, it2.data() );
 
 1111void KonqPopupMenu::slotPopupMimeType()
 
 1116void KonqPopupMenu::slotPopupProperties()
 
 1118    (void)showPropertiesDialog();
 
 1121KPropertiesDialog* KonqPopupMenu::showPropertiesDialog()
 
 1127    if ( m_lstItems.count() == 1 )
 
 1129        KFileItem * item = m_lstItems.first();
 
 1130        if (item->entry().count() == 0) 
 
 1133            return new KPropertiesDialog( item->url(), d->m_parentWidget );
 
 1136    return new KPropertiesDialog( m_lstItems, d->m_parentWidget );
 
 1141  TQCString name = element.attribute( attrName ).ascii();
 
 1142  TDEAction *res = m_ownActions.action( 
static_cast<const char *
>(name) );
 
 1145    res = m_actions.action( 
static_cast<const char *
>(name) );
 
 1147  if ( !res && m_pMenuNew && strcmp( name, m_pMenuNew->name() ) == 0 )
 
 1153TDEActionCollection *KonqPopupMenu::actionCollection()
 const 
 1155    return const_cast<TDEActionCollection *
>( &m_ownActions );
 
 1158TQString KonqPopupMenu::mimeType()
 const 
 1163KonqPopupMenu::ProtocolInfo KonqPopupMenu::protocolInfo()
 const 
 1168void KonqPopupMenu::addPlugins()
 
 1172    TDETrader::OfferList plugin_offers;
 
 1173    unsigned int pluginCount = 0;
 
 1174    plugin_offers = TDETrader::self()->query( m_sMimeType.isNull() ? TQString::fromLatin1( 
"all/all" ) : m_sMimeType, 
"'KonqPopupMenu/Plugin' in ServiceTypes");
 
 1175    if ( plugin_offers.isEmpty() )
 
 1178    TDETrader::OfferList::ConstIterator iterator = plugin_offers.begin();
 
 1179    TDETrader::OfferList::ConstIterator end = plugin_offers.end();
 
 1181    addGroup( 
"plugins" );
 
 1183    for(; iterator != end; ++iterator, ++pluginCount ) {
 
 1185        KonqPopupMenuPlugin *plugin =
 
 1186            KParts::ComponentFactory::
 
 1187            createInstanceFromLibrary<KonqPopupMenuPlugin>( TQFile::encodeName( (*iterator)->library() ),
 
 1189                                                            (*iterator)->name().latin1() );
 
 1193        TQString pluginClientName = TQString::fromLatin1( 
"Plugin%1" ).arg( pluginCount );
 
 1194        addMerge( pluginClientName );
 
 1195        plugin->domDocument().documentElement().setAttribute( 
"name", pluginClientName );
 
 1196        m_pluginList.append( plugin );
 
 1197        insertChildClient( plugin );
 
 1201    addMerge( 
"plugins" );
 
 1204KURL KonqPopupMenu::url() const 
 
 1209KFileItemList KonqPopupMenu::fileItemList()
 const 
 1214KURL::List KonqPopupMenu::popupURLList()
 const 
 1216  return m_lstPopupURLs;
 
 1219void KonqPopupMenu::slotLocalURL(TDEIO::LocalURLJob *job, 
const KURL& url, 
bool isLocal)
 
 1221  d->localURLSlotFired = 
true;
 
 1222  d->localURLResultURL = url;
 
 1223  d->localURLResultIsLocal = isLocal;
 
 1224  tdeApp->eventLoop()->exitLoop();
 
 1227void KonqPopupMenu::slotLocalURLKIODestroyed()
 
 1229  if (!d->localURLSlotFired) {
 
 1230    d->localURLSlotFired = 
true;
 
 1231    d->localURLResultURL = KURL();
 
 1232    d->localURLResultIsLocal = 
false;
 
 1233    tdeApp->eventLoop()->exitLoop();
 
 1241KonqPopupMenuPlugin::KonqPopupMenuPlugin( 
KonqPopupMenu *parent, 
const char *name )
 
 1242    : TQObject( parent, name )
 
 1246KonqPopupMenuPlugin::~KonqPopupMenuPlugin()
 
 1250#include "konq_popupmenu.moc" 
static void newDir(TQWidget *parent, const KURL &baseURL)
Ask for the name of a new directory and create it.
 
static void editMimeType(const TQString &mimeType)
Pop up properties dialog for mimetype mimeType.
 
void addPendingSeparator()
only add a separator if an action is added afterwards