You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1251 lines
43 KiB
1251 lines
43 KiB
15 years ago
|
/* This file is part of the KDE project
|
||
|
Copyright (C) 1998, 1999 David Faure <faure@kde.org>
|
||
|
Copyright (C) 2001 Holger Freyther <freyther@yahoo.com>
|
||
|
|
||
|
This library is free software; you can redistribute it and/or
|
||
|
modify it under the terms of the GNU Library General Public
|
||
|
License as published by the Free Software Foundation; either
|
||
|
version 2 of the License, or (at your option) any later version.
|
||
|
|
||
|
This library is distributed in the hope that it will be useful,
|
||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||
|
Library General Public License for more details.
|
||
|
|
||
|
You should have received a copy of the GNU Library General Public License
|
||
|
along with this library; see the file COPYING.LIB. If not, write to
|
||
|
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||
|
Boston, MA 02110-1301, USA.
|
||
|
*/
|
||
|
|
||
14 years ago
|
#include <tqdir.h>
|
||
12 years ago
|
#include <tqeventloop.h>
|
||
15 years ago
|
|
||
12 years ago
|
#include <tdelocale.h>
|
||
12 years ago
|
#include <tdeapplication.h>
|
||
15 years ago
|
#include <kbookmarkmanager.h>
|
||
|
#include <kdebug.h>
|
||
|
#include <krun.h>
|
||
|
#include <kprotocolinfo.h>
|
||
|
#include <kiconloader.h>
|
||
|
#include <kinputdialog.h>
|
||
12 years ago
|
#include <tdeglobalsettings.h>
|
||
15 years ago
|
#include <kstandarddirs.h>
|
||
|
#include <kxmlguifactory.h>
|
||
|
#include <kxmlguibuilder.h>
|
||
12 years ago
|
#include <tdeparts/componentfactory.h>
|
||
15 years ago
|
|
||
|
#include <assert.h>
|
||
|
|
||
12 years ago
|
#include <tdefileshare.h>
|
||
15 years ago
|
#include <kprocess.h>
|
||
|
|
||
|
#include "kpropertiesdialog.h"
|
||
|
#include "knewmenu.h"
|
||
|
#include "konq_popupmenu.h"
|
||
|
#include "konq_operations.h"
|
||
14 years ago
|
#include "konq_xmlguiclient.h"
|
||
15 years ago
|
#include <dcopclient.h>
|
||
|
|
||
|
/*
|
||
|
Test cases:
|
||
|
iconview file: background
|
||
|
iconview file: file (with and without servicemenus)
|
||
|
iconview file: directory
|
||
|
iconview remote protocol (e.g. ftp: or fish:)
|
||
|
iconview trash:/
|
||
|
sidebar directory tree
|
||
|
sidebar Devices / Hard Disc
|
||
12 years ago
|
tdehtml background
|
||
|
tdehtml link
|
||
|
tdehtml image (www.kde.org RMB on K logo)
|
||
|
tdehtmlimage (same as above, then choose View image, then RMB)
|
||
|
selected text in tdehtml
|
||
15 years ago
|
embedded katepart
|
||
|
kdesktop folder
|
||
|
trash link on desktop
|
||
|
trashed file or directory
|
||
|
application .desktop file
|
||
13 years ago
|
Then the same after uninstalling tdeaddons/konq-plugins (kuick and arkplugin in particular)
|
||
15 years ago
|
*/
|
||
|
|
||
|
class KonqPopupMenuGUIBuilder : public KXMLGUIBuilder
|
||
|
{
|
||
|
public:
|
||
14 years ago
|
KonqPopupMenuGUIBuilder( TQPopupMenu *menu )
|
||
15 years ago
|
: KXMLGUIBuilder( 0 )
|
||
|
{
|
||
|
m_menu = menu;
|
||
|
}
|
||
|
virtual ~KonqPopupMenuGUIBuilder()
|
||
|
{
|
||
|
}
|
||
|
|
||
14 years ago
|
virtual TQWidget *createContainer( TQWidget *parent, int index,
|
||
|
const TQDomElement &element,
|
||
15 years ago
|
int &id )
|
||
|
{
|
||
|
if ( !parent && element.attribute( "name" ) == "popupmenu" )
|
||
|
return m_menu;
|
||
|
|
||
|
return KXMLGUIBuilder::createContainer( parent, index, element, id );
|
||
|
}
|
||
|
|
||
14 years ago
|
TQPopupMenu *m_menu;
|
||
15 years ago
|
};
|
||
|
|
||
|
class KonqPopupMenu::KonqPopupMenuPrivate
|
||
|
{
|
||
|
public:
|
||
14 years ago
|
KonqPopupMenuPrivate() : m_parentWidget( 0 ),
|
||
15 years ago
|
m_itemFlags( KParts::BrowserExtension::DefaultPopupItems )
|
||
|
{
|
||
|
}
|
||
14 years ago
|
TQString m_urlTitle;
|
||
14 years ago
|
TQWidget *m_parentWidget;
|
||
15 years ago
|
KParts::BrowserExtension::PopupFlags m_itemFlags;
|
||
12 years ago
|
|
||
|
bool localURLSlotFired;
|
||
|
KURL localURLResultURL;
|
||
|
bool localURLResultIsLocal;
|
||
15 years ago
|
};
|
||
|
|
||
|
KonqPopupMenu::ProtocolInfo::ProtocolInfo()
|
||
|
{
|
||
|
m_Reading = false;
|
||
|
m_Writing = false;
|
||
|
m_Deleting = false;
|
||
|
m_Moving = false;
|
||
|
m_TrashIncluded = false;
|
||
|
}
|
||
|
|
||
|
bool KonqPopupMenu::ProtocolInfo::supportsReading() const
|
||
|
{
|
||
|
return m_Reading;
|
||
|
}
|
||
|
|
||
|
bool KonqPopupMenu::ProtocolInfo::supportsWriting() const
|
||
|
{
|
||
|
return m_Writing;
|
||
|
}
|
||
|
|
||
|
bool KonqPopupMenu::ProtocolInfo::supportsDeleting() const
|
||
|
{
|
||
|
return m_Deleting;
|
||
|
}
|
||
|
|
||
|
bool KonqPopupMenu::ProtocolInfo::supportsMoving() const
|
||
|
{
|
||
|
return m_Moving;
|
||
|
}
|
||
|
|
||
|
bool KonqPopupMenu::ProtocolInfo::trashIncluded() const
|
||
|
{
|
||
|
return m_TrashIncluded;
|
||
|
}
|
||
|
|
||
|
// This helper class stores the .desktop-file actions and the servicemenus
|
||
13 years ago
|
// in order to support X-TDE-Priority and X-TDE-Submenu.
|
||
15 years ago
|
class PopupServices
|
||
|
{
|
||
|
public:
|
||
14 years ago
|
ServiceList* selectList( const TQString& priority, const TQString& submenuName );
|
||
15 years ago
|
|
||
|
ServiceList builtin;
|
||
|
ServiceList user, userToplevel, userPriority;
|
||
14 years ago
|
TQMap<TQString, ServiceList> userSubmenus, userToplevelSubmenus, userPrioritySubmenus;
|
||
15 years ago
|
};
|
||
|
|
||
14 years ago
|
ServiceList* PopupServices::selectList( const TQString& priority, const TQString& submenuName )
|
||
15 years ago
|
{
|
||
|
// we use the categories .desktop entry to define submenus
|
||
|
// if none is defined, we just pop it in the main menu
|
||
|
if (submenuName.isEmpty())
|
||
|
{
|
||
|
if (priority == "TopLevel")
|
||
|
{
|
||
|
return &userToplevel;
|
||
|
}
|
||
|
else if (priority == "Important")
|
||
|
{
|
||
|
return &userPriority;
|
||
|
}
|
||
|
}
|
||
|
else if (priority == "TopLevel")
|
||
|
{
|
||
|
return &(userToplevelSubmenus[submenuName]);
|
||
|
}
|
||
|
else if (priority == "Important")
|
||
|
{
|
||
|
return &(userPrioritySubmenus[submenuName]);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
return &(userSubmenus[submenuName]);
|
||
|
}
|
||
|
return &user;
|
||
|
}
|
||
|
|
||
|
//////////////////
|
||
|
|
||
|
KonqPopupMenu::KonqPopupMenu( KBookmarkManager *mgr, const KFileItemList &items,
|
||
|
KURL viewURL,
|
||
12 years ago
|
TDEActionCollection & actions,
|
||
15 years ago
|
KNewMenu * newMenu,
|
||
|
bool showProperties )
|
||
14 years ago
|
: TQPopupMenu( 0L, "konq_popupmenu" ),
|
||
|
m_actions( actions ), m_ownActions( static_cast<TQWidget *>( 0 ), "KonqPopupMenu::m_ownActions" ),
|
||
15 years ago
|
m_pMenuNew( newMenu ), m_sViewURL(viewURL), m_lstItems(items), m_pManager(mgr)
|
||
|
{
|
||
|
KonqPopupFlags kpf = ( showProperties ? ShowProperties : IsLink ) | ShowNewWindow;
|
||
|
init(0, kpf, KParts::BrowserExtension::DefaultPopupItems);
|
||
|
}
|
||
|
|
||
|
KonqPopupMenu::KonqPopupMenu( KBookmarkManager *mgr, const KFileItemList &items,
|
||
|
KURL viewURL,
|
||
12 years ago
|
TDEActionCollection & actions,
|
||
15 years ago
|
KNewMenu * newMenu,
|
||
14 years ago
|
TQWidget * parentWidget,
|
||
15 years ago
|
bool showProperties )
|
||
14 years ago
|
: 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)
|
||
15 years ago
|
{
|
||
|
KonqPopupFlags kpf = ( showProperties ? ShowProperties : IsLink ) | ShowNewWindow;
|
||
14 years ago
|
init(parentWidget, kpf, KParts::BrowserExtension::DefaultPopupItems);
|
||
15 years ago
|
}
|
||
|
|
||
|
KonqPopupMenu::KonqPopupMenu( KBookmarkManager *mgr, const KFileItemList &items,
|
||
|
const KURL& viewURL,
|
||
12 years ago
|
TDEActionCollection & actions,
|
||
15 years ago
|
KNewMenu * newMenu,
|
||
14 years ago
|
TQWidget * parentWidget,
|
||
15 years ago
|
KonqPopupFlags kpf,
|
||
|
KParts::BrowserExtension::PopupFlags flags)
|
||
14 years ago
|
: 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)
|
||
15 years ago
|
{
|
||
14 years ago
|
init(parentWidget, kpf, flags);
|
||
15 years ago
|
}
|
||
|
|
||
14 years ago
|
void KonqPopupMenu::init (TQWidget * parentWidget, KonqPopupFlags kpf, KParts::BrowserExtension::PopupFlags flags)
|
||
15 years ago
|
{
|
||
|
d = new KonqPopupMenuPrivate;
|
||
14 years ago
|
d->m_parentWidget = parentWidget;
|
||
15 years ago
|
d->m_itemFlags = flags;
|
||
|
setup(kpf);
|
||
|
}
|
||
|
|
||
14 years ago
|
int KonqPopupMenu::insertServicesSubmenus(const TQMap<TQString, ServiceList>& submenus,
|
||
|
TQDomElement& menu,
|
||
15 years ago
|
bool isBuiltin)
|
||
|
{
|
||
|
int count = 0;
|
||
14 years ago
|
TQMap<TQString, ServiceList>::ConstIterator it;
|
||
15 years ago
|
|
||
|
for (it = submenus.begin(); it != submenus.end(); ++it)
|
||
|
{
|
||
|
if (it.data().isEmpty())
|
||
|
{
|
||
|
//avoid empty sub-menus
|
||
|
continue;
|
||
|
}
|
||
|
|
||
14 years ago
|
TQDomElement actionSubmenu = m_doc.createElement( "menu" );
|
||
15 years ago
|
actionSubmenu.setAttribute( "name", "actions " + it.key() );
|
||
|
menu.appendChild( actionSubmenu );
|
||
14 years ago
|
TQDomElement subtext = m_doc.createElement( "text" );
|
||
15 years ago
|
actionSubmenu.appendChild( subtext );
|
||
|
subtext.appendChild( m_doc.createTextNode( it.key() ) );
|
||
|
count += insertServices(it.data(), actionSubmenu, isBuiltin);
|
||
|
}
|
||
|
|
||
|
return count;
|
||
|
}
|
||
|
|
||
|
int KonqPopupMenu::insertServices(const ServiceList& list,
|
||
14 years ago
|
TQDomElement& menu,
|
||
15 years ago
|
bool isBuiltin)
|
||
|
{
|
||
|
static int id = 1000;
|
||
|
int count = 0;
|
||
|
|
||
|
ServiceList::const_iterator it = list.begin();
|
||
|
for( ; it != list.end(); ++it )
|
||
|
{
|
||
|
if ((*it).isEmpty())
|
||
|
{
|
||
|
if (!menu.firstChild().isNull() &&
|
||
|
menu.lastChild().toElement().tagName().lower() != "separator")
|
||
|
{
|
||
14 years ago
|
TQDomElement separator = m_doc.createElement( "separator" );
|
||
15 years ago
|
menu.appendChild(separator);
|
||
|
}
|
||
|
continue;
|
||
|
}
|
||
|
|
||
|
if (isBuiltin || (*it).m_display == true)
|
||
|
{
|
||
14 years ago
|
TQCString name;
|
||
15 years ago
|
name.setNum( id );
|
||
|
name.prepend( isBuiltin ? "builtinservice_" : "userservice_" );
|
||
12 years ago
|
TDEAction * act = new TDEAction( TQString((*it).m_strName).replace('&',"&&"), 0,
|
||
14 years ago
|
TQT_TQOBJECT(this), TQT_SLOT( slotRunService() ),
|
||
15 years ago
|
&m_ownActions, name );
|
||
|
|
||
|
if ( !(*it).m_strIcon.isEmpty() )
|
||
|
{
|
||
14 years ago
|
TQPixmap pix = SmallIcon( (*it).m_strIcon );
|
||
15 years ago
|
act->setIconSet( pix );
|
||
|
}
|
||
|
|
||
13 years ago
|
addAction( act, menu ); // Add to toplevel menu
|
||
15 years ago
|
|
||
|
m_mapPopupServices[ id++ ] = *it;
|
||
|
++count;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return count;
|
||
|
}
|
||
|
|
||
12 years ago
|
bool KonqPopupMenu::KIOSKAuthorizedAction(TDEConfig& cfg)
|
||
15 years ago
|
{
|
||
13 years ago
|
if ( !cfg.hasKey( "X-TDE-AuthorizeAction") )
|
||
15 years ago
|
{
|
||
|
return true;
|
||
|
}
|
||
|
|
||
13 years ago
|
TQStringList list = cfg.readListEntry("X-TDE-AuthorizeAction");
|
||
15 years ago
|
if (kapp && !list.isEmpty())
|
||
|
{
|
||
14 years ago
|
for(TQStringList::ConstIterator it = list.begin();
|
||
15 years ago
|
it != list.end();
|
||
|
++it)
|
||
|
{
|
||
|
if (!kapp->authorize((*it).stripWhiteSpace()))
|
||
|
{
|
||
|
return false;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
|
||
|
void KonqPopupMenu::setup(KonqPopupFlags kpf)
|
||
|
{
|
||
|
assert( m_lstItems.count() >= 1 );
|
||
|
|
||
|
m_ownActions.setWidget( this );
|
||
|
|
||
5 years ago
|
const bool bIsLink = (kpf & IsLink);
|
||
|
bool currentDir = false;
|
||
|
bool sReading = true;
|
||
|
bool sDeleting = ( d->m_itemFlags & KParts::BrowserExtension::NoDeletion ) == 0;
|
||
|
bool sMoving = sDeleting;
|
||
|
bool sWriting = sDeleting && m_lstItems.first()->isWritable();
|
||
|
m_sMimeType = m_lstItems.first()->mimetype();
|
||
13 years ago
|
TQString mimeGroup = m_sMimeType.left(m_sMimeType.find('/'));
|
||
5 years ago
|
mode_t mode = m_lstItems.first()->mode();
|
||
|
bool isDirectory = S_ISDIR(mode);
|
||
|
bool isMediaFile = false;
|
||
|
bool isEncryptedMediaFile = false;
|
||
|
bool isReallyLocal = m_lstItems.first()->isLocalFile();
|
||
|
bool isLocal = isReallyLocal || m_lstItems.first()->url().protocol()=="media" ||
|
||
|
m_lstItems.first()->url().protocol()=="system";
|
||
|
bool isTrashIncluded = false;
|
||
15 years ago
|
bool isTrashLink = false;
|
||
|
m_lstPopupURLs.clear();
|
||
|
int id = 0;
|
||
12 years ago
|
setFont(TDEGlobalSettings::menuFont());
|
||
15 years ago
|
m_pluginList.setAutoDelete( true );
|
||
|
m_ownActions.setHighlightingEnabled( true );
|
||
|
|
||
13 years ago
|
attrName = TQString::fromLatin1( "name" );
|
||
15 years ago
|
|
||
|
prepareXMLGUIStuff();
|
||
|
m_builder = new KonqPopupMenuGUIBuilder( this );
|
||
|
m_factory = new KXMLGUIFactory( m_builder );
|
||
|
|
||
|
KURL url;
|
||
|
KFileItemListIterator it ( m_lstItems );
|
||
14 years ago
|
TQStringList mimeTypeList;
|
||
15 years ago
|
// Check whether all URLs are correct
|
||
|
for ( ; it.current(); ++it )
|
||
|
{
|
||
|
url = (*it)->url();
|
||
|
|
||
|
// Build the list of URLs
|
||
|
m_lstPopupURLs.append( url );
|
||
|
|
||
|
// Determine if common mode among all URLs
|
||
|
if ( mode != (*it)->mode() )
|
||
|
mode = 0; // modes are different => reset to 0
|
||
|
|
||
|
// Determine if common mimetype among all URLs
|
||
|
if ( m_sMimeType != (*it)->mimetype() )
|
||
|
{
|
||
14 years ago
|
m_sMimeType = TQString::null; // mimetypes are different => null
|
||
15 years ago
|
|
||
13 years ago
|
if ( mimeGroup != (*it)->mimetype().left((*it)->mimetype().find('/')))
|
||
14 years ago
|
mimeGroup = TQString::null; // mimetype groups are different as well!
|
||
15 years ago
|
}
|
||
|
|
||
13 years ago
|
if ( mimeTypeList.findIndex( (*it)->mimetype() ) == -1 )
|
||
15 years ago
|
mimeTypeList << (*it)->mimetype();
|
||
|
|
||
|
if ( isReallyLocal && !url.isLocalFile() )
|
||
|
isReallyLocal = false;
|
||
|
if ( isLocal && !url.isLocalFile() && url.protocol() != "media" && url.protocol() != "system" )
|
||
|
isLocal = false;
|
||
|
|
||
5 years ago
|
if ( !isTrashIncluded && (
|
||
15 years ago
|
( url.protocol() == "trash" && url.path().length() <= 1 )
|
||
|
|| url.url() == "system:/trash" || url.url() == "system:/trash/" ) ) {
|
||
5 years ago
|
isTrashIncluded = true;
|
||
15 years ago
|
isLocal = false;
|
||
|
}
|
||
|
|
||
|
if ( sReading )
|
||
|
sReading = KProtocolInfo::supportsReading( url );
|
||
|
|
||
|
if ( sWriting )
|
||
|
sWriting = KProtocolInfo::supportsWriting( url ) && (*it)->isWritable();
|
||
|
|
||
|
if ( sDeleting )
|
||
|
sDeleting = KProtocolInfo::supportsDeleting( url );
|
||
|
|
||
|
if ( sMoving )
|
||
|
sMoving = KProtocolInfo::supportsMoving( url );
|
||
5 years ago
|
if ( (*it)->mimetype().startsWith("media/") ) {
|
||
|
isMediaFile = true;
|
||
|
if ( (*it)->mimetype().contains("encrypted")) {
|
||
|
isEncryptedMediaFile = true;
|
||
|
}
|
||
|
}
|
||
15 years ago
|
}
|
||
12 years ago
|
|
||
|
// If a local path is available, monitor that instead of the given remote URL...
|
||
|
KURL realURL = m_sViewURL;
|
||
|
if (!realURL.isLocalFile()) {
|
||
11 years ago
|
d->localURLSlotFired = false;
|
||
12 years ago
|
TDEIO::LocalURLJob* localURLJob = TDEIO::localURL(m_sViewURL);
|
||
12 years ago
|
if (localURLJob) {
|
||
11 years ago
|
connect(localURLJob, TQT_SIGNAL(localURL(TDEIO::LocalURLJob*, const KURL&, bool)), this, TQT_SLOT(slotLocalURL(TDEIO::LocalURLJob*, const KURL&, bool)));
|
||
12 years ago
|
connect(localURLJob, TQT_SIGNAL(destroyed()), this, TQT_SLOT(slotLocalURLKIODestroyed()));
|
||
|
while (!d->localURLSlotFired) {
|
||
11 years ago
|
kapp->eventLoop()->enterLoop();
|
||
12 years ago
|
}
|
||
|
if (d->localURLResultIsLocal) {
|
||
|
realURL = d->localURLResultURL;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
url = realURL;
|
||
15 years ago
|
url.cleanPath();
|
||
|
|
||
|
//check if url is current directory
|
||
|
if ( m_lstItems.count() == 1 )
|
||
|
{
|
||
|
KURL firstPopupURL( m_lstItems.first()->url() );
|
||
|
firstPopupURL.cleanPath();
|
||
|
//kdDebug(1203) << "View path is " << url.url() << endl;
|
||
|
//kdDebug(1203) << "First popup path is " << firstPopupURL.url() << endl;
|
||
12 years ago
|
currentDir = firstPopupURL.equals( url, true /* ignore_trailing */, true /* ignore_internalReferenceURLS */ );
|
||
14 years ago
|
if ( isLocal && ((m_sMimeType == "application/x-desktop")
|
||
|
|| (m_sMimeType == "media/builtin-mydocuments")
|
||
|
|| (m_sMimeType == "media/builtin-mycomputer")
|
||
|
|| (m_sMimeType == "media/builtin-mynetworkplaces")
|
||
|
|| (m_sMimeType == "media/builtin-printers")
|
||
|
|| (m_sMimeType == "media/builtin-trash")
|
||
|
|| (m_sMimeType == "media/builtin-webbrowser")) ) {
|
||
15 years ago
|
KSimpleConfig cfg( firstPopupURL.path(), true );
|
||
|
cfg.setDesktopGroup();
|
||
|
isTrashLink = ( cfg.readEntry("Type") == "Link" && cfg.readEntry("URL") == "trash:/" );
|
||
|
}
|
||
|
|
||
|
if ( isTrashLink ) {
|
||
|
sDeleting = false;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
m_info.m_Reading = sReading;
|
||
|
m_info.m_Writing = sWriting;
|
||
|
m_info.m_Deleting = sDeleting;
|
||
|
m_info.m_Moving = sMoving;
|
||
5 years ago
|
m_info.m_TrashIncluded = isTrashIncluded;
|
||
15 years ago
|
|
||
|
// isCurrentTrash: popup on trash:/ itself, or on the trash.desktop link
|
||
5 years ago
|
bool isCurrentTrash = ( m_lstItems.count() == 1 && isTrashIncluded ) || isTrashLink;
|
||
15 years ago
|
bool isIntoTrash = ( url.protocol() == "trash" || url.url().startsWith( "system:/trash" ) ) && !isCurrentTrash; // trashed file, not trash:/ itself
|
||
5 years ago
|
//kdDebug() << "isLocal=" << isLocal << " url=" << url << " isCurrentTrash=" << isCurrentTrash << " isIntoTrash=" << isIntoTrash << " isTrashIncluded=" << isTrashIncluded << endl;
|
||
15 years ago
|
clear();
|
||
|
|
||
|
//////////////////////////////////////////////////////////////////////////
|
||
|
|
||
12 years ago
|
TDEAction * act;
|
||
15 years ago
|
|
||
|
if (!isCurrentTrash)
|
||
|
addMerge( "konqueror" );
|
||
|
|
||
14 years ago
|
bool isKDesktop = TQCString( kapp->name() ) == "kdesktop";
|
||
15 years ago
|
|
||
|
if (( kpf & ShowProperties ) && isKDesktop &&
|
||
|
!kapp->authorize("editable_desktop_icons"))
|
||
|
{
|
||
|
kpf &= ~ShowProperties; // remove flag
|
||
|
}
|
||
|
|
||
|
// Either 'newview' is in the actions we're given (probably in the tabhandling group)
|
||
|
// or we need to insert it ourselves (e.g. for kdesktop). In the first case, actNewWindow must remain 0.
|
||
5 years ago
|
if ( ((kpf & ShowNewWindow) != 0) && sReading && !isEncryptedMediaFile)
|
||
15 years ago
|
{
|
||
14 years ago
|
TQString openStr = isKDesktop ? i18n( "&Open" ) : i18n( "Open in New &Window" );
|
||
5 years ago
|
TDEAction *actNewWindow = new TDEAction( openStr, "window-new", 0, TQT_TQOBJECT(this), TQT_SLOT( slotPopupNewView() ), &m_ownActions, "newview" );
|
||
|
actNewWindow->setToolTip( i18n( "Open item in a new window" ) );
|
||
|
addAction( actNewWindow );
|
||
|
addSeparator();
|
||
15 years ago
|
}
|
||
|
|
||
|
if ( S_ISDIR(mode) && sWriting && !isCurrentTrash ) // A dir, and we can create things into it
|
||
|
{
|
||
|
if ( currentDir && m_pMenuNew ) // Current dir -> add the "new" menu
|
||
|
{
|
||
|
// As requested by KNewMenu :
|
||
|
m_pMenuNew->slotCheckUpToDate();
|
||
|
m_pMenuNew->setPopupFiles( m_lstPopupURLs );
|
||
|
|
||
13 years ago
|
addAction( m_pMenuNew );
|
||
15 years ago
|
|
||
|
addSeparator();
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
if (d->m_itemFlags & KParts::BrowserExtension::ShowCreateDirectory)
|
||
|
{
|
||
10 years ago
|
TDEAction *actNewDir = new TDEAction( i18n( "Create &Folder..." ), "folder-new", 0, TQT_TQOBJECT(this), TQT_SLOT( slotPopupNewDir() ), &m_ownActions, "newdir" );
|
||
13 years ago
|
addAction( actNewDir );
|
||
15 years ago
|
addSeparator();
|
||
|
}
|
||
|
}
|
||
|
} else if ( isIntoTrash ) {
|
||
|
// Trashed item, offer restoring
|
||
12 years ago
|
act = new TDEAction( i18n( "&Restore" ), 0, TQT_TQOBJECT(this), TQT_SLOT( slotPopupRestoreTrashedItems() ), &m_ownActions, "restore" );
|
||
13 years ago
|
addAction( act );
|
||
15 years ago
|
}
|
||
|
|
||
|
if (d->m_itemFlags & KParts::BrowserExtension::ShowNavigationItems)
|
||
|
{
|
||
|
if (d->m_itemFlags & KParts::BrowserExtension::ShowUp)
|
||
13 years ago
|
addAction( "up" );
|
||
|
addAction( "back" );
|
||
|
addAction( "forward" );
|
||
15 years ago
|
if (d->m_itemFlags & KParts::BrowserExtension::ShowReload)
|
||
13 years ago
|
addAction( "reload" );
|
||
15 years ago
|
addSeparator();
|
||
|
}
|
||
|
|
||
5 years ago
|
if (!isEncryptedMediaFile)
|
||
15 years ago
|
{
|
||
5 years ago
|
addGroup( "tabhandling" ); // includes a separator
|
||
15 years ago
|
}
|
||
|
|
||
|
if ( !bIsLink )
|
||
|
{
|
||
|
if ( !currentDir && sReading ) {
|
||
|
if ( sDeleting ) {
|
||
13 years ago
|
addAction( "cut" );
|
||
15 years ago
|
}
|
||
13 years ago
|
addAction( "copy" );
|
||
15 years ago
|
}
|
||
|
|
||
|
if ( S_ISDIR(mode) && sWriting ) {
|
||
|
if ( currentDir )
|
||
13 years ago
|
addAction( "paste" );
|
||
15 years ago
|
else
|
||
13 years ago
|
addAction( "pasteto" );
|
||
15 years ago
|
}
|
||
|
if ( !currentDir )
|
||
|
{
|
||
|
if ( m_lstItems.count() == 1 && sMoving )
|
||
13 years ago
|
addAction( "rename" );
|
||
15 years ago
|
|
||
|
bool addTrash = false;
|
||
|
bool addDel = false;
|
||
|
|
||
|
if ( sMoving && !isIntoTrash && !isTrashLink )
|
||
|
addTrash = true;
|
||
|
|
||
|
if ( sDeleting ) {
|
||
|
if ( !isLocal )
|
||
|
addDel = true;
|
||
12 years ago
|
else if (TDEApplication::keyboardMouseState() & TQt::ShiftButton) {
|
||
15 years ago
|
addTrash = false;
|
||
|
addDel = true;
|
||
|
}
|
||
|
else {
|
||
12 years ago
|
TDEConfigGroup configGroup( kapp->config(), "KDE" );
|
||
15 years ago
|
if ( configGroup.readBoolEntry( "ShowDeleteCommand", false ) )
|
||
|
addDel = true;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if ( addTrash )
|
||
13 years ago
|
addAction( "trash" );
|
||
15 years ago
|
if ( addDel )
|
||
13 years ago
|
addAction( "del" );
|
||
15 years ago
|
}
|
||
|
}
|
||
|
if ( isCurrentTrash )
|
||
|
{
|
||
12 years ago
|
act = new TDEAction( i18n( "&Empty Trash Bin" ), "emptytrash", 0, TQT_TQOBJECT(this), TQT_SLOT( slotPopupEmptyTrashBin() ), &m_ownActions, "empytrash" );
|
||
15 years ago
|
KSimpleConfig trashConfig( "trashrc", true );
|
||
14 years ago
|
trashConfig.setGroup( "Status" );
|
||
15 years ago
|
act->setEnabled( !trashConfig.readBoolEntry( "Empty", true ) );
|
||
13 years ago
|
addAction( act );
|
||
15 years ago
|
}
|
||
|
addGroup( "editactions" );
|
||
|
|
||
|
if (d->m_itemFlags & KParts::BrowserExtension::ShowTextSelectionItems) {
|
||
|
addMerge( 0 );
|
||
|
m_factory->addClient( this );
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
if ( !isCurrentTrash && !isIntoTrash && (d->m_itemFlags & KParts::BrowserExtension::ShowBookmark))
|
||
|
{
|
||
|
addSeparator();
|
||
14 years ago
|
TQString caption;
|
||
15 years ago
|
if (currentDir)
|
||
|
{
|
||
13 years ago
|
bool httpPage = (m_sViewURL.protocol().find("http", 0, false) == 0);
|
||
15 years ago
|
if (httpPage)
|
||
|
caption = i18n("&Bookmark This Page");
|
||
|
else
|
||
|
caption = i18n("&Bookmark This Location");
|
||
|
}
|
||
|
else if (S_ISDIR(mode))
|
||
|
caption = i18n("&Bookmark This Folder");
|
||
|
else if (bIsLink)
|
||
|
caption = i18n("&Bookmark This Link");
|
||
|
else
|
||
|
caption = i18n("&Bookmark This File");
|
||
|
|
||
12 years ago
|
act = new TDEAction( caption, "bookmark_add", 0, TQT_TQOBJECT(this), TQT_SLOT( slotPopupAddToBookmark() ), &m_ownActions, "bookmark_add" );
|
||
15 years ago
|
if (m_lstItems.count() > 1)
|
||
|
act->setEnabled(false);
|
||
12 years ago
|
if (kapp->authorizeTDEAction("bookmarks"))
|
||
13 years ago
|
addAction( act );
|
||
15 years ago
|
if (bIsLink)
|
||
|
addGroup( "linkactions" );
|
||
|
}
|
||
|
|
||
|
//////////////////////////////////////////////////////
|
||
|
|
||
|
const bool isSingleLocal = m_lstItems.count() == 1 && isLocal;
|
||
|
PopupServices s;
|
||
|
KURL urlForServiceMenu( m_lstItems.first()->url() );
|
||
|
if (isLocal && !isReallyLocal) { // media or system
|
||
|
bool dummy;
|
||
|
urlForServiceMenu = m_lstItems.first()->mostLocalURL(dummy);
|
||
|
}
|
||
|
|
||
|
// 1 - Look for builtin and user-defined services
|
||
14 years ago
|
if ( ((m_sMimeType == "application/x-desktop")
|
||
|
|| (m_sMimeType == "media/builtin-mydocuments")
|
||
|
|| (m_sMimeType == "media/builtin-mycomputer")
|
||
|
|| (m_sMimeType == "media/builtin-mynetworkplaces")
|
||
|
|| (m_sMimeType == "media/builtin-printers")
|
||
|
|| (m_sMimeType == "media/builtin-trash")
|
||
|
|| (m_sMimeType == "media/builtin-webbrowser")) && isSingleLocal ) // .desktop file
|
||
15 years ago
|
{
|
||
|
// get builtin services, like mount/unmount
|
||
|
s.builtin = KDEDesktopMimeType::builtinServices( urlForServiceMenu );
|
||
14 years ago
|
const TQString path = urlForServiceMenu.path();
|
||
15 years ago
|
KSimpleConfig cfg( path, true );
|
||
|
cfg.setDesktopGroup();
|
||
13 years ago
|
const TQString priority = cfg.readEntry("X-TDE-Priority");
|
||
|
const TQString submenuName = cfg.readEntry( "X-TDE-Submenu" );
|
||
15 years ago
|
if ( cfg.readEntry("Type") == "Link" ) {
|
||
|
urlForServiceMenu = cfg.readEntry("URL");
|
||
|
// TODO: Do we want to make all the actions apply on the target
|
||
|
// of the .desktop file instead of the .desktop file itself?
|
||
|
}
|
||
|
ServiceList* list = s.selectList( priority, submenuName );
|
||
|
(*list) = KDEDesktopMimeType::userDefinedServices( path, cfg, urlForServiceMenu.isLocalFile() );
|
||
|
}
|
||
|
|
||
|
if ( sReading )
|
||
|
{
|
||
|
|
||
|
// 2 - Look for "servicesmenus" bindings (konqueror-specific user-defined services)
|
||
|
|
||
|
// first check the .directory if this is a directory
|
||
|
if (isDirectory && isSingleLocal)
|
||
|
{
|
||
14 years ago
|
TQString dotDirectoryFile = urlForServiceMenu.path(1).append(".directory");
|
||
15 years ago
|
KSimpleConfig cfg( dotDirectoryFile, true );
|
||
|
cfg.setDesktopGroup();
|
||
|
|
||
|
if (KIOSKAuthorizedAction(cfg))
|
||
|
{
|
||
13 years ago
|
const TQString priority = cfg.readEntry("X-TDE-Priority");
|
||
|
const TQString submenuName = cfg.readEntry( "X-TDE-Submenu" );
|
||
15 years ago
|
ServiceList* list = s.selectList( priority, submenuName );
|
||
|
(*list) += KDEDesktopMimeType::userDefinedServices( dotDirectoryFile, cfg, true );
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// findAllResources() also removes duplicates
|
||
4 years ago
|
TQStringList entries = TDEGlobal::dirs()->findAllResources("data",
|
||
|
"konqueror/servicemenus/*.desktop", false, true);
|
||
|
entries.sort(); // sort to ensure consistent order in popup menu
|
||
14 years ago
|
TQStringList::ConstIterator eIt = entries.begin();
|
||
|
const TQStringList::ConstIterator eEnd = entries.end();
|
||
15 years ago
|
for (; eIt != eEnd; ++eIt )
|
||
|
{
|
||
|
KSimpleConfig cfg( *eIt, true );
|
||
|
cfg.setDesktopGroup();
|
||
|
|
||
|
if (!KIOSKAuthorizedAction(cfg))
|
||
|
{
|
||
|
continue;
|
||
|
}
|
||
|
|
||
13 years ago
|
if ( cfg.hasKey( "X-TDE-ShowIfRunning" ) )
|
||
15 years ago
|
{
|
||
13 years ago
|
const TQString app = cfg.readEntry( "X-TDE-ShowIfRunning" );
|
||
15 years ago
|
if ( !kapp->dcopClient()->isApplicationRegistered( app.utf8() ) )
|
||
|
continue;
|
||
|
}
|
||
13 years ago
|
if ( cfg.hasKey( "X-TDE-ShowIfDcopCall" ) )
|
||
15 years ago
|
{
|
||
13 years ago
|
TQString dcopcall = cfg.readEntry( "X-TDE-ShowIfDcopCall" );
|
||
14 years ago
|
const TQCString app = TQString(dcopcall.section(' ', 0,0)).utf8();
|
||
15 years ago
|
|
||
|
//if( !kapp->dcopClient()->isApplicationRegistered( app ))
|
||
|
// continue; //app does not exist so cannot send call
|
||
|
|
||
14 years ago
|
TQByteArray dataToSend;
|
||
|
TQDataStream dataStream(dataToSend, IO_WriteOnly);
|
||
15 years ago
|
dataStream << m_lstPopupURLs;
|
||
|
|
||
14 years ago
|
TQCString replyType;
|
||
|
TQByteArray replyData;
|
||
14 years ago
|
TQCString object = TQString(dcopcall.section(' ', 1,-2)).utf8();
|
||
|
TQString function = TQString(dcopcall.section(' ', -1));
|
||
15 years ago
|
if(!function.endsWith("(KURL::List)")) {
|
||
13 years ago
|
kdWarning() << "Desktop file " << *eIt << " contains an invalid X-TDE-ShowIfDcopCall - the function must take the exact parameter (KURL::List) and must be specified." << endl;
|
||
15 years ago
|
continue; //Be safe.
|
||
|
}
|
||
|
|
||
|
if(!kapp->dcopClient()->call( app, object,
|
||
|
function.utf8(),
|
||
|
dataToSend, replyType, replyData, true, 1000))
|
||
|
continue;
|
||
|
if(replyType != "bool" || !replyData[0])
|
||
|
continue;
|
||
|
|
||
|
}
|
||
13 years ago
|
if ( cfg.hasKey( "X-TDE-Protocol" ) )
|
||
15 years ago
|
{
|
||
13 years ago
|
const TQString protocol = cfg.readEntry( "X-TDE-Protocol" );
|
||
15 years ago
|
if ( protocol != urlForServiceMenu.protocol() )
|
||
|
continue;
|
||
|
}
|
||
13 years ago
|
else if ( cfg.hasKey( "X-TDE-Protocols" ) )
|
||
15 years ago
|
{
|
||
13 years ago
|
TQStringList protocols = TQStringList::split( "," , cfg.readEntry( "X-TDE-Protocols" ) );
|
||
13 years ago
|
if ( !protocols.contains( urlForServiceMenu.protocol() ) )
|
||
15 years ago
|
continue;
|
||
|
}
|
||
|
else if ( urlForServiceMenu.protocol() == "trash" || urlForServiceMenu.url().startsWith( "system:/trash" ) )
|
||
|
{
|
||
|
// Require servicemenus for the trash to ask for protocol=trash explicitely.
|
||
|
// Trashed files aren't supposed to be available for actions.
|
||
|
// One might want a servicemenu for trash.desktop itself though.
|
||
|
continue;
|
||
|
}
|
||
|
|
||
13 years ago
|
if ( cfg.hasKey( "X-TDE-Require" ) )
|
||
15 years ago
|
{
|
||
13 years ago
|
const TQStringList capabilities = cfg.readListEntry( "X-TDE-Require" );
|
||
13 years ago
|
if ( capabilities.contains( "Write" ) && !sWriting )
|
||
15 years ago
|
continue;
|
||
|
}
|
||
10 years ago
|
if ( (cfg.hasKey( "Actions" ) || cfg.hasKey( "X-TDE-GetActionMenu") ) && cfg.hasKey( "X-TDE-ServiceTypes" ) )
|
||
15 years ago
|
{
|
||
10 years ago
|
const TQStringList types = cfg.readListEntry( "X-TDE-ServiceTypes" );
|
||
|
const TQStringList excludeTypes = cfg.readListEntry( "X-TDE-ExcludeServiceTypes" );
|
||
15 years ago
|
bool ok = false;
|
||
|
|
||
|
// check for exact matches or a typeglob'd mimetype if we have a mimetype
|
||
14 years ago
|
for (TQStringList::ConstIterator it = types.begin();
|
||
15 years ago
|
it != types.end() && !ok;
|
||
|
++it)
|
||
|
{
|
||
|
// first check if we have an all mimetype
|
||
|
bool checkTheMimetypes = false;
|
||
|
if (*it == "all/all" ||
|
||
|
*it == "allfiles" /*compat with KDE up to 3.0.3*/)
|
||
|
{
|
||
|
checkTheMimetypes = true;
|
||
|
}
|
||
|
|
||
|
// next, do we match all files?
|
||
|
if (!ok &&
|
||
|
!isDirectory &&
|
||
|
*it == "all/allfiles")
|
||
|
{
|
||
|
checkTheMimetypes = true;
|
||
|
}
|
||
|
|
||
|
// if we have a mimetype, see if we have an exact or a type globbed match
|
||
12 years ago
|
if ((!ok &&
|
||
15 years ago
|
(!m_sMimeType.isEmpty() &&
|
||
12 years ago
|
*it == m_sMimeType)) ||
|
||
15 years ago
|
(!mimeGroup.isEmpty() &&
|
||
12 years ago
|
(((*it).right(1) == "*") &&
|
||
13 years ago
|
(*it).left((*it).find('/')) == mimeGroup)))
|
||
15 years ago
|
{
|
||
|
checkTheMimetypes = true;
|
||
|
}
|
||
|
|
||
|
if (checkTheMimetypes)
|
||
|
{
|
||
|
ok = true;
|
||
14 years ago
|
for (TQStringList::ConstIterator itex = excludeTypes.begin(); itex != excludeTypes.end(); ++itex)
|
||
15 years ago
|
{
|
||
13 years ago
|
if( ((*itex).right(1) == "*" && (*itex).left((*itex).find('/')) == mimeGroup) ||
|
||
15 years ago
|
((*itex) == m_sMimeType) )
|
||
|
{
|
||
|
ok = false;
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if ( ok )
|
||
|
{
|
||
13 years ago
|
const TQString priority = cfg.readEntry("X-TDE-Priority");
|
||
|
const TQString submenuName = cfg.readEntry( "X-TDE-Submenu" );
|
||
15 years ago
|
|
||
4 years ago
|
ServiceList *list = s.selectList( priority, submenuName );
|
||
15 years ago
|
(*list) += KDEDesktopMimeType::userDefinedServices( *eIt, cfg, url.isLocalFile(), m_lstPopupURLs );
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
12 years ago
|
TDETrader::OfferList offers;
|
||
15 years ago
|
|
||
12 years ago
|
if (kapp->authorizeTDEAction("openwith"))
|
||
15 years ago
|
{
|
||
14 years ago
|
TQString constraint = "Type == 'Application' and DesktopEntryName != 'kfmclient' and DesktopEntryName != 'kfmclient_dir' and DesktopEntryName != 'kfmclient_html'";
|
||
|
TQString subConstraint = " and '%1' in ServiceTypes";
|
||
15 years ago
|
|
||
14 years ago
|
TQStringList::ConstIterator it = mimeTypeList.begin();
|
||
|
TQStringList::ConstIterator end = mimeTypeList.end();
|
||
15 years ago
|
Q_ASSERT( it != end );
|
||
14 years ago
|
TQString first = *it;
|
||
15 years ago
|
++it;
|
||
|
while ( it != end ) {
|
||
|
constraint += subConstraint.arg( *it );
|
||
|
++it;
|
||
|
}
|
||
|
|
||
12 years ago
|
offers = TDETrader::self()->query( first, constraint );
|
||
15 years ago
|
}
|
||
|
|
||
|
//// Ok, we have everything, now insert
|
||
|
|
||
|
m_mapPopup.clear();
|
||
|
m_mapPopupServices.clear();
|
||
|
// "Open With..." for folders is really not very useful, especially for remote folders.
|
||
|
// (media:/something, or trash:/, or ftp://...)
|
||
|
if ( !isDirectory || isLocal )
|
||
|
{
|
||
|
if ( hasAction() )
|
||
|
addSeparator();
|
||
|
|
||
|
if ( !offers.isEmpty() )
|
||
|
{
|
||
|
// First block, app and preview offers
|
||
|
id = 1;
|
||
|
|
||
14 years ago
|
TQDomElement menu = m_menuElement;
|
||
15 years ago
|
|
||
|
if ( offers.count() > 1 ) // submenu 'open with'
|
||
|
{
|
||
|
menu = m_doc.createElement( "menu" );
|
||
|
menu.setAttribute( "name", "openwith submenu" );
|
||
|
m_menuElement.appendChild( menu );
|
||
14 years ago
|
TQDomElement text = m_doc.createElement( "text" );
|
||
15 years ago
|
menu.appendChild( text );
|
||
|
text.appendChild( m_doc.createTextNode( i18n("&Open With") ) );
|
||
|
}
|
||
|
|
||
12 years ago
|
TDETrader::OfferList::ConstIterator it = offers.begin();
|
||
15 years ago
|
for( ; it != offers.end(); it++ )
|
||
|
{
|
||
|
KService::Ptr service = (*it);
|
||
|
|
||
13 years ago
|
// Skip OnlyShowIn=Foo and NotShowIn=TDE entries,
|
||
15 years ago
|
// but still offer NoDisplay=true entries, that's the
|
||
|
// whole point of such desktop files. This is why we don't
|
||
|
// use service->noDisplay() here.
|
||
14 years ago
|
const TQString onlyShowIn = service->property("OnlyShowIn", TQVariant::String).toString();
|
||
15 years ago
|
if ( !onlyShowIn.isEmpty() ) {
|
||
14 years ago
|
const TQStringList aList = TQStringList::split(';', onlyShowIn);
|
||
13 years ago
|
if (!aList.contains("TDE"))
|
||
15 years ago
|
continue;
|
||
|
}
|
||
14 years ago
|
const TQString notShowIn = service->property("NotShowIn", TQVariant::String).toString();
|
||
15 years ago
|
if ( !notShowIn.isEmpty() ) {
|
||
14 years ago
|
const TQStringList aList = TQStringList::split(';', notShowIn);
|
||
13 years ago
|
if (aList.contains("TDE"))
|
||
15 years ago
|
continue;
|
||
|
}
|
||
|
|
||
14 years ago
|
TQCString nam;
|
||
15 years ago
|
nam.setNum( id );
|
||
|
|
||
13 years ago
|
TQString actionName( (*it)->name().replace("&", "&&") );
|
||
15 years ago
|
if ( menu == m_menuElement ) // no submenu -> prefix single offer
|
||
|
actionName = i18n( "Open with %1" ).arg( actionName );
|
||
|
|
||
12 years ago
|
act = new TDEAction( actionName, (*it)->pixmap( TDEIcon::Small ), 0,
|
||
14 years ago
|
TQT_TQOBJECT(this), TQT_SLOT( slotRunService() ),
|
||
15 years ago
|
&m_ownActions, nam.prepend( "appservice_" ) );
|
||
13 years ago
|
addAction( act, menu );
|
||
15 years ago
|
|
||
|
m_mapPopup[ id++ ] = *it;
|
||
|
}
|
||
|
|
||
14 years ago
|
TQString openWithActionName;
|
||
15 years ago
|
if ( menu != m_menuElement ) // submenu
|
||
|
{
|
||
|
addSeparator( menu );
|
||
|
openWithActionName = i18n( "&Other..." );
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
openWithActionName = i18n( "&Open With..." );
|
||
|
}
|
||
12 years ago
|
TDEAction *openWithAct = new TDEAction( openWithActionName, 0, TQT_TQOBJECT(this), TQT_SLOT( slotPopupOpenWith() ), &m_ownActions, "openwith" );
|
||
13 years ago
|
addAction( openWithAct, menu );
|
||
15 years ago
|
}
|
||
|
else // no app offers -> Open With...
|
||
|
{
|
||
12 years ago
|
act = new TDEAction( i18n( "&Open With..." ), 0, TQT_TQOBJECT(this), TQT_SLOT( slotPopupOpenWith() ), &m_ownActions, "openwith" );
|
||
13 years ago
|
addAction( act );
|
||
15 years ago
|
}
|
||
|
|
||
|
}
|
||
|
addGroup( "preview" );
|
||
|
}
|
||
|
|
||
|
// Second block, builtin + user
|
||
14 years ago
|
TQDomElement actionMenu = m_menuElement;
|
||
15 years ago
|
int userItemCount = 0;
|
||
|
if (s.user.count() + s.userSubmenus.count() +
|
||
|
s.userPriority.count() + s.userPrioritySubmenus.count() > 1)
|
||
|
{
|
||
|
// we have more than one item, so let's make a submenu
|
||
|
actionMenu = m_doc.createElement( "menu" );
|
||
|
actionMenu.setAttribute( "name", "actions submenu" );
|
||
|
m_menuElement.appendChild( actionMenu );
|
||
14 years ago
|
TQDomElement text = m_doc.createElement( "text" );
|
||
15 years ago
|
actionMenu.appendChild( text );
|
||
|
text.appendChild( m_doc.createTextNode( i18n("Ac&tions") ) );
|
||
|
}
|
||
|
|
||
|
userItemCount += insertServicesSubmenus(s.userPrioritySubmenus, actionMenu, false);
|
||
|
userItemCount += insertServices(s.userPriority, actionMenu, false);
|
||
|
|
||
|
// see if we need to put a separator between our priority items and our regular items
|
||
|
if (userItemCount > 0 &&
|
||
|
(s.user.count() > 0 ||
|
||
|
s.userSubmenus.count() > 0 ||
|
||
|
s.builtin.count() > 0) &&
|
||
|
actionMenu.lastChild().toElement().tagName().lower() != "separator")
|
||
|
{
|
||
14 years ago
|
TQDomElement separator = m_doc.createElement( "separator" );
|
||
15 years ago
|
actionMenu.appendChild(separator);
|
||
|
}
|
||
|
|
||
|
userItemCount += insertServicesSubmenus(s.userSubmenus, actionMenu, false);
|
||
|
userItemCount += insertServices(s.user, actionMenu, false);
|
||
|
userItemCount += insertServices(s.builtin, m_menuElement, true);
|
||
|
|
||
|
userItemCount += insertServicesSubmenus(s.userToplevelSubmenus, m_menuElement, false);
|
||
|
userItemCount += insertServices(s.userToplevel, m_menuElement, false);
|
||
|
|
||
|
if ( userItemCount > 0 )
|
||
|
{
|
||
|
addPendingSeparator();
|
||
|
}
|
||
|
|
||
5 years ago
|
if ( !isCurrentTrash && !isIntoTrash && !isMediaFile && sReading )
|
||
15 years ago
|
addPlugins(); // now it's time to add plugins
|
||
|
|
||
|
if ( KPropertiesDialog::canDisplay( m_lstItems ) && (kpf & ShowProperties) )
|
||
|
{
|
||
4 years ago
|
act = new TDEAction( i18n( "&Properties" ), "edit", 0, TQT_TQOBJECT(this), TQT_SLOT( slotPopupProperties() ),
|
||
15 years ago
|
&m_ownActions, "properties" );
|
||
13 years ago
|
addAction( act );
|
||
15 years ago
|
}
|
||
|
|
||
|
while ( !m_menuElement.lastChild().isNull() &&
|
||
|
m_menuElement.lastChild().toElement().tagName().lower() == "separator" )
|
||
|
m_menuElement.removeChild( m_menuElement.lastChild() );
|
||
|
|
||
|
if ( isDirectory && isLocal )
|
||
|
{
|
||
|
if ( KFileShare::authorization() == KFileShare::Authorized )
|
||
|
{
|
||
|
addSeparator();
|
||
12 years ago
|
act = new TDEAction( i18n("Share"), 0, TQT_TQOBJECT(this), TQT_SLOT( slotOpenShareFileDialog() ),
|
||
15 years ago
|
&m_ownActions, "sharefile" );
|
||
13 years ago
|
addAction( act );
|
||
15 years ago
|
}
|
||
|
}
|
||
|
|
||
|
addMerge( 0 );
|
||
|
//kdDebug() << k_funcinfo << domDocument().toString() << endl;
|
||
|
|
||
|
m_factory->addClient( this );
|
||
|
}
|
||
|
|
||
|
void KonqPopupMenu::slotOpenShareFileDialog()
|
||
|
{
|
||
|
KPropertiesDialog* dlg = showPropertiesDialog();
|
||
|
dlg->showFileSharingPage();
|
||
|
}
|
||
|
|
||
|
KonqPopupMenu::~KonqPopupMenu()
|
||
|
{
|
||
|
m_pluginList.clear();
|
||
|
delete m_factory;
|
||
|
delete m_builder;
|
||
|
delete d;
|
||
|
//kdDebug(1203) << "~KonqPopupMenu leave" << endl;
|
||
|
}
|
||
|
|
||
14 years ago
|
void KonqPopupMenu::setURLTitle( const TQString& urlTitle )
|
||
15 years ago
|
{
|
||
|
d->m_urlTitle = urlTitle;
|
||
|
}
|
||
|
|
||
|
void KonqPopupMenu::slotPopupNewView()
|
||
|
{
|
||
|
KURL::List::ConstIterator it = m_lstPopupURLs.begin();
|
||
|
for ( ; it != m_lstPopupURLs.end(); it++ )
|
||
|
(void) new KRun(*it);
|
||
|
}
|
||
|
|
||
|
void KonqPopupMenu::slotPopupNewDir()
|
||
|
{
|
||
|
if (m_lstPopupURLs.empty())
|
||
|
return;
|
||
|
|
||
14 years ago
|
KonqOperations::newDir(d->m_parentWidget, m_lstPopupURLs.first());
|
||
15 years ago
|
}
|
||
|
|
||
|
void KonqPopupMenu::slotPopupEmptyTrashBin()
|
||
|
{
|
||
|
KonqOperations::emptyTrash();
|
||
|
}
|
||
|
|
||
|
void KonqPopupMenu::slotPopupRestoreTrashedItems()
|
||
|
{
|
||
|
KonqOperations::restoreTrashedItems( m_lstPopupURLs );
|
||
|
}
|
||
|
|
||
|
void KonqPopupMenu::slotPopupOpenWith()
|
||
|
{
|
||
|
KRun::displayOpenWithDialog( m_lstPopupURLs );
|
||
|
}
|
||
|
|
||
|
void KonqPopupMenu::slotPopupAddToBookmark()
|
||
|
{
|
||
|
KBookmarkGroup root;
|
||
|
if ( m_lstPopupURLs.count() == 1 ) {
|
||
|
KURL url = m_lstPopupURLs.first();
|
||
14 years ago
|
TQString title = d->m_urlTitle.isEmpty() ? url.prettyURL() : d->m_urlTitle;
|
||
15 years ago
|
root = m_pManager->addBookmarkDialog( url.prettyURL(), title );
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
root = m_pManager->root();
|
||
|
KURL::List::ConstIterator it = m_lstPopupURLs.begin();
|
||
|
for ( ; it != m_lstPopupURLs.end(); it++ )
|
||
|
root.addBookmark( m_pManager, (*it).prettyURL(), (*it) );
|
||
|
}
|
||
|
m_pManager->emitChanged( root );
|
||
|
}
|
||
|
|
||
|
void KonqPopupMenu::slotRunService()
|
||
|
{
|
||
14 years ago
|
TQCString senderName = TQT_TQOBJECT_CONST(sender())->name();
|
||
13 years ago
|
int id = senderName.mid( senderName.find( '_' ) + 1 ).toInt();
|
||
15 years ago
|
|
||
|
// Is it a usual service (application)
|
||
13 years ago
|
TQMap<int,KService::Ptr>::Iterator it = m_mapPopup.find( id );
|
||
15 years ago
|
if ( it != m_mapPopup.end() )
|
||
|
{
|
||
|
KRun::run( **it, m_lstPopupURLs );
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
// Is it a service specific to desktop entry files ?
|
||
13 years ago
|
TQMap<int,KDEDesktopMimeType::Service>::Iterator it2 = m_mapPopupServices.find( id );
|
||
15 years ago
|
if ( it2 != m_mapPopupServices.end() )
|
||
|
{
|
||
|
KDEDesktopMimeType::executeService( m_lstPopupURLs, it2.data() );
|
||
|
}
|
||
|
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
void KonqPopupMenu::slotPopupMimeType()
|
||
|
{
|
||
|
KonqOperations::editMimeType( m_sMimeType );
|
||
|
}
|
||
|
|
||
|
void KonqPopupMenu::slotPopupProperties()
|
||
|
{
|
||
|
(void)showPropertiesDialog();
|
||
|
}
|
||
|
|
||
|
KPropertiesDialog* KonqPopupMenu::showPropertiesDialog()
|
||
|
{
|
||
12 years ago
|
// It may be that the tdefileitem was created by hand
|
||
15 years ago
|
// (see KonqKfmIconView::slotMouseButtonPressed)
|
||
|
// In that case, we can get more precise info in the properties
|
||
|
// (like permissions) if we stat the URL.
|
||
|
if ( m_lstItems.count() == 1 )
|
||
|
{
|
||
|
KFileItem * item = m_lstItems.first();
|
||
|
if (item->entry().count() == 0) // this item wasn't listed by a slave
|
||
|
{
|
||
|
// KPropertiesDialog will use stat to get more info on the file
|
||
14 years ago
|
return new KPropertiesDialog( item->url(), d->m_parentWidget );
|
||
15 years ago
|
}
|
||
|
}
|
||
14 years ago
|
return new KPropertiesDialog( m_lstItems, d->m_parentWidget );
|
||
15 years ago
|
}
|
||
|
|
||
12 years ago
|
TDEAction *KonqPopupMenu::action( const TQDomElement &element ) const
|
||
15 years ago
|
{
|
||
14 years ago
|
TQCString name = element.attribute( attrName ).ascii();
|
||
12 years ago
|
TDEAction *res = m_ownActions.action( static_cast<const char *>(name) );
|
||
15 years ago
|
|
||
|
if ( !res )
|
||
14 years ago
|
res = m_actions.action( static_cast<const char *>(name) );
|
||
15 years ago
|
|
||
|
if ( !res && m_pMenuNew && strcmp( name, m_pMenuNew->name() ) == 0 )
|
||
|
return m_pMenuNew;
|
||
|
|
||
|
return res;
|
||
|
}
|
||
|
|
||
12 years ago
|
TDEActionCollection *KonqPopupMenu::actionCollection() const
|
||
15 years ago
|
{
|
||
12 years ago
|
return const_cast<TDEActionCollection *>( &m_ownActions );
|
||
15 years ago
|
}
|
||
|
|
||
14 years ago
|
TQString KonqPopupMenu::mimeType() const
|
||
15 years ago
|
{
|
||
|
return m_sMimeType;
|
||
|
}
|
||
|
|
||
|
KonqPopupMenu::ProtocolInfo KonqPopupMenu::protocolInfo() const
|
||
|
{
|
||
|
return m_info;
|
||
|
}
|
||
|
|
||
|
void KonqPopupMenu::addPlugins()
|
||
|
{
|
||
|
// search for Konq_PopupMenuPlugins inspired by simons kpropsdlg
|
||
|
//search for a plugin with the right protocol
|
||
12 years ago
|
TDETrader::OfferList plugin_offers;
|
||
15 years ago
|
unsigned int pluginCount = 0;
|
||
12 years ago
|
plugin_offers = TDETrader::self()->query( m_sMimeType.isNull() ? TQString::fromLatin1( "all/all" ) : m_sMimeType, "'KonqPopupMenu/Plugin' in ServiceTypes");
|
||
15 years ago
|
if ( plugin_offers.isEmpty() )
|
||
|
return; // no plugins installed do not bother about it
|
||
|
|
||
12 years ago
|
TDETrader::OfferList::ConstIterator iterator = plugin_offers.begin();
|
||
|
TDETrader::OfferList::ConstIterator end = plugin_offers.end();
|
||
15 years ago
|
|
||
|
addGroup( "plugins" );
|
||
|
// travers the offerlist
|
||
|
for(; iterator != end; ++iterator, ++pluginCount ) {
|
||
|
//kdDebug() << (*iterator)->library() << endl;
|
||
|
KonqPopupMenuPlugin *plugin =
|
||
|
KParts::ComponentFactory::
|
||
14 years ago
|
createInstanceFromLibrary<KonqPopupMenuPlugin>( TQFile::encodeName( (*iterator)->library() ),
|
||
14 years ago
|
TQT_TQOBJECT(this),
|
||
15 years ago
|
(*iterator)->name().latin1() );
|
||
|
if ( !plugin )
|
||
|
continue;
|
||
|
// This make the kuick plugin insert its stuff above "Properties"
|
||
13 years ago
|
TQString pluginClientName = TQString::fromLatin1( "Plugin%1" ).arg( pluginCount );
|
||
15 years ago
|
addMerge( pluginClientName );
|
||
|
plugin->domDocument().documentElement().setAttribute( "name", pluginClientName );
|
||
|
m_pluginList.append( plugin );
|
||
|
insertChildClient( plugin );
|
||
|
}
|
||
|
|
||
|
// ## Where is this used?
|
||
|
addMerge( "plugins" );
|
||
|
}
|
||
|
|
||
|
KURL KonqPopupMenu::url() const // ### should be viewURL()
|
||
|
{
|
||
|
return m_sViewURL;
|
||
|
}
|
||
|
|
||
|
KFileItemList KonqPopupMenu::fileItemList() const
|
||
|
{
|
||
|
return m_lstItems;
|
||
|
}
|
||
|
|
||
|
KURL::List KonqPopupMenu::popupURLList() const
|
||
|
{
|
||
|
return m_lstPopupURLs;
|
||
|
}
|
||
|
|
||
11 years ago
|
void KonqPopupMenu::slotLocalURL(TDEIO::LocalURLJob *job, const KURL& url, bool isLocal)
|
||
12 years ago
|
{
|
||
|
d->localURLSlotFired = true;
|
||
|
d->localURLResultURL = url;
|
||
|
d->localURLResultIsLocal = isLocal;
|
||
11 years ago
|
kapp->eventLoop()->exitLoop();
|
||
12 years ago
|
}
|
||
|
|
||
|
void KonqPopupMenu::slotLocalURLKIODestroyed()
|
||
|
{
|
||
|
if (!d->localURLSlotFired) {
|
||
|
d->localURLSlotFired = true;
|
||
|
d->localURLResultURL = KURL();
|
||
|
d->localURLResultIsLocal = false;
|
||
11 years ago
|
kapp->eventLoop()->exitLoop();
|
||
12 years ago
|
}
|
||
|
}
|
||
|
|
||
15 years ago
|
/**
|
||
|
Plugin
|
||
|
*/
|
||
|
|
||
|
KonqPopupMenuPlugin::KonqPopupMenuPlugin( KonqPopupMenu *parent, const char *name )
|
||
14 years ago
|
: TQObject( parent, name )
|
||
15 years ago
|
{
|
||
|
}
|
||
|
|
||
|
KonqPopupMenuPlugin::~KonqPopupMenuPlugin()
|
||
|
{
|
||
|
}
|
||
|
|
||
|
#include "konq_popupmenu.moc"
|