1999-05-12 02:26:56 +00:00
|
|
|
/* This file is part of the KDE project
|
|
|
|
Copyright (C) 1998, 1999 David Faure <faure@kde.org>
|
2001-10-30 18:09:01 +00:00
|
|
|
Copyright (C) 2001 Holger Freyther <freyther@yahoo.com>
|
1999-12-18 20:30:37 +00:00
|
|
|
|
1999-05-12 02:26:56 +00:00
|
|
|
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.
|
1999-12-18 20:30:37 +00:00
|
|
|
|
1999-05-12 02:26:56 +00:00
|
|
|
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.
|
1999-12-18 20:30:37 +00:00
|
|
|
|
1999-05-12 02:26:56 +00:00
|
|
|
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., 59 Temple Place - Suite 330,
|
|
|
|
Boston, MA 02111-1307, USA.
|
1999-12-18 20:30:37 +00:00
|
|
|
*/
|
1999-05-12 02:26:56 +00:00
|
|
|
|
1999-04-27 09:04:36 +00:00
|
|
|
#include <qdir.h>
|
|
|
|
|
2000-08-24 02:56:03 +00:00
|
|
|
#include <klocale.h>
|
2002-07-12 10:16:33 +00:00
|
|
|
#include <kapplication.h>
|
2000-10-26 03:50:30 +00:00
|
|
|
#include <kbookmarkmanager.h>
|
1999-05-24 20:04:01 +00:00
|
|
|
#include <kdebug.h>
|
2002-01-11 18:21:23 +00:00
|
|
|
#include <krun.h>
|
2000-07-10 20:25:27 +00:00
|
|
|
#include <kprotocolinfo.h>
|
2001-10-12 10:15:14 +00:00
|
|
|
#include <kiconloader.h>
|
2003-06-08 14:44:34 +00:00
|
|
|
#include <kinputdialog.h>
|
2000-03-17 16:35:18 +00:00
|
|
|
#include <kglobalsettings.h>
|
2001-10-12 10:15:14 +00:00
|
|
|
#include <kstandarddirs.h>
|
2001-10-21 00:30:27 +00:00
|
|
|
#include <kxmlguifactory.h>
|
2000-04-01 17:09:44 +00:00
|
|
|
#include <kxmlguibuilder.h>
|
2001-10-31 15:52:36 +00:00
|
|
|
#include <kparts/componentfactory.h>
|
1999-04-27 09:04:36 +00:00
|
|
|
|
1999-10-17 15:19:54 +00:00
|
|
|
#include <assert.h>
|
|
|
|
|
2002-04-16 17:06:27 +00:00
|
|
|
#include <kfileshare.h>
|
|
|
|
#include <kprocess.h>
|
|
|
|
|
2002-02-21 00:54:06 +00:00
|
|
|
#include "kpropertiesdialog.h"
|
1999-04-27 09:04:36 +00:00
|
|
|
#include "knewmenu.h"
|
2000-07-27 09:23:48 +00:00
|
|
|
#include "konq_popupmenu.h"
|
|
|
|
#include "konq_operations.h"
|
2003-08-28 16:15:50 +00:00
|
|
|
#include <dcopclient.h>
|
1999-04-27 09:04:36 +00:00
|
|
|
|
2003-05-19 17:24:46 +00:00
|
|
|
|
2000-04-01 17:09:44 +00:00
|
|
|
class KonqPopupMenuGUIBuilder : public KXMLGUIBuilder
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
KonqPopupMenuGUIBuilder( QPopupMenu *menu )
|
|
|
|
: KXMLGUIBuilder( 0 )
|
|
|
|
{
|
|
|
|
m_menu = menu;
|
|
|
|
}
|
|
|
|
virtual ~KonqPopupMenuGUIBuilder()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual QWidget *createContainer( QWidget *parent, int index,
|
2000-07-25 18:50:48 +00:00
|
|
|
const QDomElement &element,
|
2000-04-01 17:09:44 +00:00
|
|
|
int &id )
|
|
|
|
{
|
|
|
|
if ( !parent && element.attribute( "name" ) == "popupmenu" )
|
|
|
|
return m_menu;
|
|
|
|
|
2000-07-13 22:04:11 +00:00
|
|
|
return KXMLGUIBuilder::createContainer( parent, index, element, id );
|
2000-04-01 17:09:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QPopupMenu *m_menu;
|
|
|
|
};
|
|
|
|
|
2001-12-12 14:10:22 +00:00
|
|
|
class KonqPopupMenu::KonqPopupMenuPrivate
|
|
|
|
{
|
|
|
|
public:
|
2003-07-04 17:22:49 +00:00
|
|
|
KonqPopupMenuPrivate() : m_parentWidget(0)
|
2003-06-18 16:48:39 +00:00
|
|
|
{
|
2003-09-26 07:53:17 +00:00
|
|
|
m_itemFlags=KParts::BrowserExtension::DefaultPopupItems;
|
2003-06-18 16:48:39 +00:00
|
|
|
}
|
2002-02-27 04:44:03 +00:00
|
|
|
QString m_urlTitle;
|
2002-11-20 11:35:24 +00:00
|
|
|
QWidget *m_parentWidget;
|
2003-09-26 07:53:17 +00:00
|
|
|
KParts::BrowserExtension::PopupFlags m_itemFlags;
|
2001-12-12 14:10:22 +00:00
|
|
|
};
|
2002-02-27 04:44:03 +00:00
|
|
|
|
2002-01-21 20:46:23 +00:00
|
|
|
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;
|
|
|
|
}
|
2001-12-12 14:10:22 +00:00
|
|
|
|
2002-03-04 13:42:26 +00:00
|
|
|
KonqPopupMenu::KonqPopupMenu( KBookmarkManager *mgr, const KFileItemList &items,
|
2000-02-19 20:30:21 +00:00
|
|
|
KURL viewURL,
|
2000-03-25 07:07:56 +00:00
|
|
|
KActionCollection & actions,
|
2000-07-12 22:03:24 +00:00
|
|
|
KNewMenu * newMenu,
|
2003-10-09 14:02:59 +00:00
|
|
|
bool showProperties )
|
2003-06-18 21:05:34 +00:00
|
|
|
: QPopupMenu( 0L, "konq_popupmenu" ), m_actions( actions ), m_ownActions( static_cast<QObject *>( 0 ), "KonqPopupMenu::m_ownActions" ),
|
2002-05-09 07:17:44 +00:00
|
|
|
m_pMenuNew( newMenu ), m_sViewURL(viewURL), m_lstItems(items), m_pManager(mgr)
|
2003-06-18 16:48:39 +00:00
|
|
|
|
1999-04-27 09:04:36 +00:00
|
|
|
{
|
2003-10-09 14:02:59 +00:00
|
|
|
KonqPopupFlags kpf = ( showProperties ? ShowProperties : IsLink ) | ShowNewWindow;
|
|
|
|
init(0, kpf, KParts::BrowserExtension::DefaultPopupItems);
|
2002-11-20 11:35:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
KonqPopupMenu::KonqPopupMenu( KBookmarkManager *mgr, const KFileItemList &items,
|
|
|
|
KURL viewURL,
|
|
|
|
KActionCollection & actions,
|
|
|
|
KNewMenu * newMenu,
|
|
|
|
QWidget * parentWidget,
|
2003-10-09 14:02:59 +00:00
|
|
|
bool showProperties )
|
2003-10-05 23:34:49 +00:00
|
|
|
: QPopupMenu( parentWidget, "konq_popupmenu" ), m_actions( actions ), m_ownActions( static_cast<QObject *>( 0 ), "KonqPopupMenu::m_ownActions" ), m_pMenuNew( newMenu ), m_sViewURL(viewURL), m_lstItems(items), m_pManager(mgr)
|
2003-06-18 16:48:39 +00:00
|
|
|
{
|
2003-10-09 14:02:59 +00:00
|
|
|
KonqPopupFlags kpf = ( showProperties ? ShowProperties : IsLink ) | ShowNewWindow;
|
|
|
|
init(parentWidget, kpf, KParts::BrowserExtension::DefaultPopupItems);
|
2003-06-18 16:48:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
KonqPopupMenu::KonqPopupMenu( KBookmarkManager *mgr, const KFileItemList &items,
|
2003-10-09 14:02:59 +00:00
|
|
|
const KURL& viewURL,
|
2003-06-18 16:48:39 +00:00
|
|
|
KActionCollection & actions,
|
|
|
|
KNewMenu * newMenu,
|
|
|
|
QWidget * parentWidget,
|
2003-10-09 14:02:59 +00:00
|
|
|
KonqPopupFlags kpf,
|
|
|
|
KParts::BrowserExtension::PopupFlags flags)
|
2003-10-05 23:34:49 +00:00
|
|
|
: QPopupMenu( parentWidget, "konq_popupmenu" ), m_actions( actions ), m_ownActions( static_cast<QObject *>( 0 ), "KonqPopupMenu::m_ownActions" ), m_pMenuNew( newMenu ), m_sViewURL(viewURL), m_lstItems(items), m_pManager(mgr)
|
2003-06-18 16:48:39 +00:00
|
|
|
{
|
2003-10-09 14:02:59 +00:00
|
|
|
init(parentWidget, kpf, flags);
|
2003-06-18 16:48:39 +00:00
|
|
|
}
|
|
|
|
|
2003-10-09 14:02:59 +00:00
|
|
|
void KonqPopupMenu::init (QWidget * parentWidget, KonqPopupFlags kpf, KParts::BrowserExtension::PopupFlags flags)
|
2002-11-20 11:35:24 +00:00
|
|
|
{
|
|
|
|
d = new KonqPopupMenuPrivate;
|
|
|
|
d->m_parentWidget = parentWidget;
|
2003-09-26 07:53:17 +00:00
|
|
|
d->m_itemFlags = flags;
|
2003-10-09 14:02:59 +00:00
|
|
|
setup(kpf);
|
2002-11-20 11:35:24 +00:00
|
|
|
}
|
|
|
|
|
2003-05-19 17:24:46 +00:00
|
|
|
|
2003-12-21 10:01:10 +00:00
|
|
|
int KonqPopupMenu::insertServicesSubmenus(const QMap<QString, ServiceList>& submenus,
|
|
|
|
QDomElement& menu,
|
|
|
|
bool isBuiltin)
|
|
|
|
{
|
|
|
|
int count = 0;
|
|
|
|
QMap<QString, ServiceList>::ConstIterator it;
|
|
|
|
|
|
|
|
for (it = submenus.begin(); it != submenus.end(); ++it)
|
|
|
|
{
|
|
|
|
if (it.data().isEmpty())
|
|
|
|
{
|
|
|
|
//avoid empty sub-menus
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
QDomElement actionSubmenu = m_doc.createElement( "menu" );
|
|
|
|
actionSubmenu.setAttribute( "name", "actions " + it.key() );
|
|
|
|
menu.appendChild( actionSubmenu );
|
|
|
|
QDomElement subtext = m_doc.createElement( "text" );
|
|
|
|
actionSubmenu.appendChild( subtext );
|
|
|
|
subtext.appendChild( m_doc.createTextNode( it.key() ) );
|
|
|
|
count += insertServices(it.data(), actionSubmenu, isBuiltin);
|
|
|
|
}
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
2003-06-18 16:48:39 +00:00
|
|
|
|
2003-12-21 10:01:10 +00:00
|
|
|
int KonqPopupMenu::insertServices(const ServiceList& list,
|
|
|
|
QDomElement& menu,
|
|
|
|
bool isBuiltin)
|
2003-05-19 17:24:46 +00:00
|
|
|
{
|
|
|
|
static int id = 1000;
|
2003-12-21 10:01:10 +00:00
|
|
|
int count = 0;
|
2003-05-19 17:24:46 +00:00
|
|
|
|
|
|
|
ServiceList::const_iterator it = list.begin();
|
|
|
|
for( ; it != list.end(); ++it )
|
|
|
|
{
|
2003-07-28 22:06:29 +00:00
|
|
|
if ((*it).isEmpty())
|
|
|
|
{
|
|
|
|
if (!menu.firstChild().isNull() &&
|
|
|
|
menu.lastChild().toElement().tagName().lower() != "separator")
|
|
|
|
{
|
|
|
|
QDomElement separator = m_doc.createElement( "separator" );
|
|
|
|
menu.appendChild(separator);
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2003-05-19 17:24:46 +00:00
|
|
|
if (isBuiltin || (*it).m_display == true)
|
|
|
|
{
|
|
|
|
QCString name;
|
|
|
|
name.setNum( id );
|
|
|
|
name.prepend( isBuiltin ? "builtinservice_" : "userservice_" );
|
|
|
|
KAction * act = new KAction( (*it).m_strName, 0,
|
|
|
|
this, SLOT( slotRunService() ),
|
|
|
|
&m_ownActions, name );
|
|
|
|
|
|
|
|
if ( !(*it).m_strIcon.isEmpty() )
|
|
|
|
{
|
|
|
|
QPixmap pix = SmallIcon( (*it).m_strIcon );
|
|
|
|
act->setIconSet( pix );
|
|
|
|
}
|
|
|
|
|
|
|
|
addAction( act, menu ); // Add to toplevel menu
|
|
|
|
|
|
|
|
m_mapPopupServices[ id++ ] = *it;
|
2003-12-21 10:01:10 +00:00
|
|
|
++count;
|
2003-05-19 17:24:46 +00:00
|
|
|
}
|
|
|
|
}
|
2003-12-21 10:01:10 +00:00
|
|
|
|
|
|
|
return count;
|
2003-05-19 17:24:46 +00:00
|
|
|
}
|
|
|
|
|
2003-07-28 22:06:29 +00:00
|
|
|
bool KonqPopupMenu::KIOSKAuthorizedAction(KConfig& cfg)
|
|
|
|
{
|
|
|
|
if ( !cfg.hasKey( "X-KDE-AuthorizeAction") )
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
QStringList list = cfg.readListEntry("X-KDE-AuthorizeAction");
|
|
|
|
if (kapp && !list.isEmpty())
|
|
|
|
{
|
|
|
|
for(QStringList::ConstIterator it = list.begin();
|
|
|
|
it != list.end();
|
|
|
|
++it)
|
|
|
|
{
|
|
|
|
if (!kapp->authorize((*it).stripWhiteSpace()))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-10-09 14:02:59 +00:00
|
|
|
void KonqPopupMenu::setup(KonqPopupFlags kpf)
|
2002-11-20 11:35:24 +00:00
|
|
|
{
|
2003-08-05 15:04:54 +00:00
|
|
|
assert( m_lstItems.count() >= 1 );
|
|
|
|
|
|
|
|
m_ownActions.setWidget( this );
|
|
|
|
|
2003-10-09 14:02:59 +00:00
|
|
|
bool bIsLink = (kpf & IsLink);
|
2003-08-05 15:04:54 +00:00
|
|
|
bool currentDir = false;
|
|
|
|
bool sReading = true;
|
|
|
|
bool sWriting = true;
|
|
|
|
bool sDeleting = true;
|
|
|
|
bool sMoving = true;
|
|
|
|
m_sMimeType = m_lstItems.first()->mimetype();
|
|
|
|
mode_t mode = m_lstItems.first()->mode();
|
|
|
|
bool isDirectory = m_sMimeType == "inode/directory";
|
|
|
|
bool bTrashIncluded = false;
|
|
|
|
bool bCanChangeSharing = false;
|
|
|
|
m_lstPopupURLs.clear();
|
|
|
|
int id = 0;
|
|
|
|
if( isDirectory && m_lstItems.first()->isLocalFile())
|
|
|
|
bCanChangeSharing=true;
|
|
|
|
setFont(KGlobalSettings::menuFont());
|
|
|
|
m_pluginList.setAutoDelete( true );
|
|
|
|
m_ownActions.setHighlightingEnabled( true );
|
|
|
|
|
|
|
|
attrName = QString::fromLatin1( "name" );
|
|
|
|
|
|
|
|
prepareXMLGUIStuff();
|
|
|
|
m_builder = new KonqPopupMenuGUIBuilder( this );
|
|
|
|
m_factory = new KXMLGUIFactory( m_builder );
|
|
|
|
|
|
|
|
KURL url;
|
|
|
|
KFileItemListIterator it ( m_lstItems );
|
|
|
|
// Check whether all URLs are correct
|
2003-08-31 13:38:31 +00:00
|
|
|
bool devicesFile = false;
|
2003-08-05 15:04:54 +00:00
|
|
|
for ( ; it.current(); ++it )
|
|
|
|
{
|
|
|
|
url = (*it)->url();
|
1999-04-27 09:04:36 +00:00
|
|
|
|
2003-08-05 15:04:54 +00:00
|
|
|
// Build the list of URLs
|
|
|
|
m_lstPopupURLs.append( url );
|
1999-04-27 09:04:36 +00:00
|
|
|
|
2003-08-05 15:04:54 +00:00
|
|
|
// Determine if common mode among all URLs
|
|
|
|
if ( mode != (*it)->mode() )
|
|
|
|
mode = 0; // modes are different => reset to 0
|
1999-08-04 10:50:58 +00:00
|
|
|
|
2003-08-05 15:04:54 +00:00
|
|
|
// Determine if common mimetype among all URLs
|
|
|
|
if ( m_sMimeType != (*it)->mimetype() )
|
|
|
|
m_sMimeType = QString::null; // mimetypes are different => null
|
1999-08-04 10:50:58 +00:00
|
|
|
|
2003-08-05 15:04:54 +00:00
|
|
|
if ( !bTrashIncluded &&
|
|
|
|
(*it)->url().isLocalFile() &&
|
|
|
|
(*it)->url().path( 1 ) == KGlobalSettings::trashPath() )
|
|
|
|
bTrashIncluded = true;
|
2000-08-07 18:34:11 +00:00
|
|
|
|
2003-08-05 15:04:54 +00:00
|
|
|
if ( sReading )
|
|
|
|
sReading = KProtocolInfo::supportsReading( url );
|
1999-04-27 09:04:36 +00:00
|
|
|
|
2003-08-05 15:04:54 +00:00
|
|
|
if ( sWriting )
|
|
|
|
sWriting = KProtocolInfo::supportsWriting( url );
|
1999-12-18 20:30:37 +00:00
|
|
|
|
2003-08-05 15:04:54 +00:00
|
|
|
if ( sDeleting )
|
|
|
|
sDeleting = KProtocolInfo::supportsDeleting( url );
|
1999-04-27 09:04:36 +00:00
|
|
|
|
2003-08-05 15:04:54 +00:00
|
|
|
if ( sMoving )
|
|
|
|
sMoving = KProtocolInfo::supportsMoving( url );
|
2003-08-31 13:38:31 +00:00
|
|
|
if ( url.protocol().find("device", 0, false)==0)
|
|
|
|
devicesFile = true;
|
2003-08-05 15:04:54 +00:00
|
|
|
}
|
|
|
|
// Be on the safe side when including the trash
|
|
|
|
if ( bTrashIncluded )
|
|
|
|
{
|
|
|
|
sMoving = false;
|
|
|
|
sDeleting = false;
|
|
|
|
}
|
|
|
|
//check if current url is trash
|
|
|
|
url = m_sViewURL;
|
|
|
|
url.cleanPath();
|
|
|
|
|
|
|
|
m_info.m_Reading = sReading;
|
|
|
|
m_info.m_Writing = sWriting;
|
|
|
|
m_info.m_Deleting = sDeleting;
|
|
|
|
m_info.m_Moving = sMoving;
|
|
|
|
m_info.m_TrashIncluded = bTrashIncluded;
|
|
|
|
|
|
|
|
//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;
|
2003-08-30 16:40:14 +00:00
|
|
|
currentDir = firstPopupURL.equals( url, true /* ignore_trailing */ );
|
2003-08-05 15:04:54 +00:00
|
|
|
}
|
2003-01-26 21:31:52 +00:00
|
|
|
|
2003-08-05 15:04:54 +00:00
|
|
|
bool isCurrentTrash = ( url.isLocalFile() &&
|
|
|
|
url.path(1) == KGlobalSettings::trashPath() &&
|
|
|
|
currentDir) ||
|
|
|
|
( m_lstItems.count() == 1 && bTrashIncluded );
|
2003-08-19 22:10:57 +00:00
|
|
|
bool isIntoTrash = url.isLocalFile() && url.path(1).startsWith(KGlobalSettings::trashPath());
|
2003-08-05 15:04:54 +00:00
|
|
|
clear();
|
1999-09-28 00:27:57 +00:00
|
|
|
|
2003-08-05 15:04:54 +00:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
1999-04-27 09:04:36 +00:00
|
|
|
|
2003-08-05 15:04:54 +00:00
|
|
|
KAction * act;
|
2000-04-01 17:09:44 +00:00
|
|
|
|
2003-08-05 15:04:54 +00:00
|
|
|
if (!isCurrentTrash)
|
|
|
|
addMerge( "konqueror" );
|
2003-07-04 04:27:59 +00:00
|
|
|
|
2003-08-05 15:04:54 +00:00
|
|
|
bool isKDesktop = QCString( kapp->name() ) == "kdesktop";
|
2003-10-09 14:02:59 +00:00
|
|
|
KAction *actNewWindow = 0;
|
2003-07-04 04:27:59 +00:00
|
|
|
|
2003-10-09 14:02:59 +00:00
|
|
|
if (( kpf & ShowProperties ) && isKDesktop &&
|
2003-08-29 11:57:06 +00:00
|
|
|
!kapp->authorize("editable_desktop_icons"))
|
|
|
|
{
|
2003-10-09 14:02:59 +00:00
|
|
|
kpf &= ~ShowProperties; // remove flag
|
2003-08-29 11:57:06 +00:00
|
|
|
}
|
|
|
|
|
2003-10-09 14:02:59 +00:00
|
|
|
// 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.
|
|
|
|
if ( kpf & ShowNewWindow )
|
2003-08-05 15:04:54 +00:00
|
|
|
{
|
2003-10-09 14:02:59 +00:00
|
|
|
QString openStr = isKDesktop ? i18n( "&Open" ) : i18n( "Open in New &Window" );
|
|
|
|
actNewWindow = new KAction( openStr, "window_new", 0, this, SLOT( slotPopupNewView() ), &m_ownActions, "newview" );
|
2003-08-05 15:04:54 +00:00
|
|
|
}
|
2000-03-18 15:19:43 +00:00
|
|
|
|
2003-10-09 14:02:59 +00:00
|
|
|
if ( actNewWindow && !isKDesktop )
|
2003-08-05 15:04:54 +00:00
|
|
|
{
|
|
|
|
if (isCurrentTrash)
|
2003-10-09 14:02:59 +00:00
|
|
|
actNewWindow->setStatusText( i18n( "Open the trash in a new window" ) );
|
2003-08-05 15:04:54 +00:00
|
|
|
else
|
2003-10-09 14:02:59 +00:00
|
|
|
actNewWindow->setStatusText( i18n( "Open the document in a new window" ) );
|
2003-08-05 15:04:54 +00:00
|
|
|
}
|
2000-04-01 17:09:44 +00:00
|
|
|
|
2003-08-05 15:04:54 +00:00
|
|
|
if ( isCurrentTrash )
|
2003-01-26 21:31:52 +00:00
|
|
|
{
|
2003-10-09 14:02:59 +00:00
|
|
|
if (actNewWindow)
|
|
|
|
{
|
|
|
|
addAction( actNewWindow );
|
|
|
|
addSeparator();
|
|
|
|
}
|
|
|
|
addGroup( "tabhandling" ); // includes a separator
|
2003-08-05 15:04:54 +00:00
|
|
|
|
|
|
|
act = new KAction( i18n( "&Empty Trash Bin" ), 0, this, SLOT( slotPopupEmptyTrashBin() ), &m_ownActions, "empytrash" );
|
|
|
|
addAction( act );
|
2003-10-09 14:02:59 +00:00
|
|
|
if ( KPropertiesDialog::canDisplay( m_lstItems ) && (kpf & ShowProperties) )
|
2003-08-05 15:04:54 +00:00
|
|
|
{
|
|
|
|
act = new KAction( i18n( "&Properties" ), 0, this, SLOT( slotPopupProperties() ),
|
|
|
|
&m_ownActions, "properties" );
|
|
|
|
addAction( act );
|
|
|
|
}
|
|
|
|
m_factory->addClient( this );
|
|
|
|
return;
|
2003-01-26 21:31:52 +00:00
|
|
|
}
|
2003-08-05 15:04:54 +00:00
|
|
|
else
|
1999-10-17 15:19:54 +00:00
|
|
|
{
|
2003-08-19 21:55:57 +00:00
|
|
|
if ( S_ISDIR(mode) && sWriting && !isIntoTrash ) // A dir, and we can create things into it
|
2003-08-05 15:04:54 +00:00
|
|
|
{
|
|
|
|
if ( currentDir && m_pMenuNew ) // Current dir -> add the "new" menu
|
|
|
|
{
|
|
|
|
// As requested by KNewMenu :
|
|
|
|
m_pMenuNew->slotCheckUpToDate();
|
|
|
|
m_pMenuNew->setPopupFiles( m_lstPopupURLs );
|
1999-04-27 09:04:36 +00:00
|
|
|
|
2003-08-05 15:04:54 +00:00
|
|
|
addAction( m_pMenuNew );
|
1999-04-27 09:04:36 +00:00
|
|
|
|
2003-08-05 15:04:54 +00:00
|
|
|
addSeparator();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2003-09-26 07:53:17 +00:00
|
|
|
if (d->m_itemFlags & KParts::BrowserExtension::ShowCreateDirectory)
|
2003-08-05 15:04:54 +00:00
|
|
|
{
|
2003-10-21 23:11:41 +00:00
|
|
|
KAction *actNewDir = new KAction( i18n( "Create &Folder..." ), "folder_new", 0, this, SLOT( slotPopupNewDir() ), &m_ownActions, "newdir" );
|
2003-08-05 15:04:54 +00:00
|
|
|
addAction( actNewDir );
|
|
|
|
addSeparator();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-09-26 07:53:17 +00:00
|
|
|
if (d->m_itemFlags & KParts::BrowserExtension::ShowNavigationItems)
|
2003-06-18 16:48:39 +00:00
|
|
|
{
|
2003-09-26 08:13:48 +00:00
|
|
|
if (d->m_itemFlags & KParts::BrowserExtension::ShowUp)
|
2003-09-26 07:53:17 +00:00
|
|
|
addAction( "up" );
|
2003-08-05 15:04:54 +00:00
|
|
|
addAction( "back" );
|
|
|
|
addAction( "forward" );
|
2003-09-26 07:53:17 +00:00
|
|
|
if (d->m_itemFlags & KParts::BrowserExtension::ShowReload)
|
|
|
|
addAction( "reload" );
|
2003-08-05 15:04:54 +00:00
|
|
|
addSeparator();
|
2003-06-18 16:48:39 +00:00
|
|
|
}
|
1999-04-27 09:04:36 +00:00
|
|
|
|
2003-10-09 14:02:59 +00:00
|
|
|
// "open in new window" is either provided by us, or by the tabhandling group
|
|
|
|
if (actNewWindow)
|
|
|
|
{
|
|
|
|
addAction( actNewWindow );
|
|
|
|
addSeparator();
|
|
|
|
}
|
|
|
|
addGroup( "tabhandling" ); // includes a separator
|
2001-12-11 17:40:02 +00:00
|
|
|
|
2003-09-12 16:25:11 +00:00
|
|
|
if ( !bIsLink )
|
|
|
|
{
|
|
|
|
if ( !currentDir && sReading && !isIntoTrash &&!devicesFile ) {
|
|
|
|
if ( sDeleting ) {
|
|
|
|
addAction( "cut" );
|
|
|
|
}
|
|
|
|
addAction( "copy" );
|
2003-08-05 15:04:54 +00:00
|
|
|
}
|
|
|
|
|
2003-09-12 16:25:11 +00:00
|
|
|
if ( S_ISDIR(mode) && sWriting && !isIntoTrash) {
|
|
|
|
if ( currentDir )
|
|
|
|
addAction( "paste" );
|
|
|
|
else
|
|
|
|
addAction( "pasteto" );
|
|
|
|
}
|
|
|
|
if ( !isIntoTrash )
|
2003-08-19 21:55:57 +00:00
|
|
|
{
|
2003-09-12 16:25:11 +00:00
|
|
|
if (!currentDir )
|
|
|
|
{
|
|
|
|
if ( m_lstItems.count() == 1 && sWriting )
|
|
|
|
addAction("rename");
|
2003-08-05 15:04:54 +00:00
|
|
|
|
2003-09-12 16:25:11 +00:00
|
|
|
if ( sMoving )
|
|
|
|
addAction( "trash" );
|
2003-08-05 15:04:54 +00:00
|
|
|
|
2003-09-12 16:25:11 +00:00
|
|
|
if ( sDeleting ) {
|
|
|
|
addAction( "del" );
|
|
|
|
}
|
2003-08-19 21:55:57 +00:00
|
|
|
}
|
2003-08-05 15:04:54 +00:00
|
|
|
}
|
|
|
|
}
|
2003-09-12 16:25:11 +00:00
|
|
|
addGroup( "editactions" );
|
2003-08-05 15:04:54 +00:00
|
|
|
}
|
2004-03-30 15:58:57 +00:00
|
|
|
|
|
|
|
if (d->m_itemFlags & KParts::BrowserExtension::ShowTextSelectionItems) {
|
|
|
|
addMerge( 0 );
|
|
|
|
m_factory->addClient( this );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2003-09-26 07:53:17 +00:00
|
|
|
if ( !isCurrentTrash && !isIntoTrash && (d->m_itemFlags & KParts::BrowserExtension::ShowBookmark))
|
2001-12-11 17:40:02 +00:00
|
|
|
{
|
2003-09-12 16:25:11 +00:00
|
|
|
addSeparator();
|
2003-09-11 20:24:01 +00:00
|
|
|
QString caption;
|
|
|
|
if (currentDir)
|
|
|
|
{
|
|
|
|
bool httpPage = (m_sViewURL.protocol().find("http", 0, false) == 0);
|
|
|
|
if (httpPage)
|
|
|
|
caption = i18n("&Bookmark This Page");
|
|
|
|
else
|
|
|
|
caption = i18n("&Bookmark This Location");
|
|
|
|
}
|
|
|
|
else if (S_ISDIR(mode))
|
2003-10-21 23:11:41 +00:00
|
|
|
caption = i18n("&Bookmark This Folder");
|
2003-09-12 16:25:11 +00:00
|
|
|
else if (bIsLink)
|
2003-09-11 20:24:01 +00:00
|
|
|
caption = i18n("&Bookmark This Link");
|
2003-09-12 16:25:11 +00:00
|
|
|
else
|
|
|
|
caption = i18n("&Bookmark This File");
|
2003-09-26 07:53:17 +00:00
|
|
|
|
2003-09-11 20:24:01 +00:00
|
|
|
act = new KAction( caption, "bookmark_add", 0, this, SLOT( slotPopupAddToBookmark() ), &m_ownActions, "bookmark_add" );
|
|
|
|
if (m_lstItems.count() > 1)
|
|
|
|
act->setEnabled(false);
|
2003-08-05 15:04:54 +00:00
|
|
|
if (kapp->authorizeKAction("bookmarks"))
|
|
|
|
addAction( act );
|
2003-09-12 16:25:11 +00:00
|
|
|
if (bIsLink)
|
|
|
|
addGroup( "linkactions" );
|
1999-10-17 15:19:54 +00:00
|
|
|
}
|
|
|
|
|
2003-08-05 15:04:54 +00:00
|
|
|
//////////////////////////////////////////////////////
|
2002-03-07 13:00:03 +00:00
|
|
|
|
2003-08-05 15:04:54 +00:00
|
|
|
ServiceList builtin;
|
2003-12-21 10:01:10 +00:00
|
|
|
ServiceList user, userToplevel, userPriority;
|
|
|
|
QMap<QString, ServiceList> userSubmenus, userToplevelSubmenus, userPrioritySubmenus;
|
1999-12-18 20:30:37 +00:00
|
|
|
|
2003-08-05 15:04:54 +00:00
|
|
|
bool isSingleLocal = (m_lstItems.count() == 1 && m_lstItems.first()->url().isLocalFile());
|
|
|
|
// 1 - Look for builtin and user-defined services
|
|
|
|
if ( m_sMimeType == "application/x-desktop" && isSingleLocal ) // .desktop file
|
|
|
|
{
|
|
|
|
// get builtin services, like mount/unmount
|
|
|
|
builtin = KDEDesktopMimeType::builtinServices( m_lstItems.first()->url() );
|
|
|
|
user = KDEDesktopMimeType::userDefinedServices( m_lstItems.first()->url().path(), url.isLocalFile() );
|
2000-03-18 15:19:43 +00:00
|
|
|
}
|
1999-10-17 15:19:54 +00:00
|
|
|
|
2003-08-19 21:55:57 +00:00
|
|
|
if ( !isCurrentTrash && !isIntoTrash)
|
2000-11-25 21:52:59 +00:00
|
|
|
{
|
|
|
|
|
2003-08-05 15:04:54 +00:00
|
|
|
// 2 - Look for "servicesmenus" bindings (konqueror-specific user-defined services)
|
1999-12-18 20:30:37 +00:00
|
|
|
|
2003-08-05 15:04:54 +00:00
|
|
|
// first check the .directory if this is a directory
|
|
|
|
if (isDirectory && isSingleLocal)
|
|
|
|
{
|
|
|
|
QString dotDirectoryFile = m_lstItems.first()->url().path(1).append(".directory");
|
|
|
|
KSimpleConfig cfg( dotDirectoryFile, true );
|
|
|
|
cfg.setDesktopGroup();
|
2000-11-19 19:14:07 +00:00
|
|
|
|
2003-08-05 15:04:54 +00:00
|
|
|
if (KIOSKAuthorizedAction(cfg))
|
|
|
|
{
|
|
|
|
QString submenuName = cfg.readEntry( "X-KDE-Submenu" );
|
|
|
|
if (submenuName.isEmpty())
|
|
|
|
{
|
|
|
|
user += KDEDesktopMimeType::userDefinedServices( dotDirectoryFile, true );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
userSubmenus[submenuName] += KDEDesktopMimeType::userDefinedServices( dotDirectoryFile, true );
|
|
|
|
}
|
|
|
|
}
|
2000-11-25 21:52:59 +00:00
|
|
|
}
|
1999-04-27 09:04:36 +00:00
|
|
|
|
2003-08-05 15:04:54 +00:00
|
|
|
QStringList dirs = KGlobal::dirs()->findDirs( "data", "konqueror/servicemenus/" );
|
|
|
|
QStringList::ConstIterator dIt = dirs.begin();
|
|
|
|
QStringList::ConstIterator dEnd = dirs.end();
|
1999-09-28 00:27:57 +00:00
|
|
|
|
2003-08-05 15:04:54 +00:00
|
|
|
for (; dIt != dEnd; ++dIt )
|
|
|
|
{
|
|
|
|
QDir dir( *dIt );
|
1999-08-08 19:53:28 +00:00
|
|
|
|
2003-12-21 21:08:38 +00:00
|
|
|
QStringList entries = dir.entryList( "*.desktop", QDir::Files );
|
2003-08-05 15:04:54 +00:00
|
|
|
QStringList::ConstIterator eIt = entries.begin();
|
|
|
|
QStringList::ConstIterator eEnd = entries.end();
|
2003-07-04 17:22:49 +00:00
|
|
|
|
2003-08-05 15:04:54 +00:00
|
|
|
for (; eIt != eEnd; ++eIt )
|
|
|
|
{
|
|
|
|
KSimpleConfig cfg( *dIt + *eIt, true );
|
|
|
|
cfg.setDesktopGroup();
|
|
|
|
|
|
|
|
if (!KIOSKAuthorizedAction(cfg))
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2003-08-28 16:15:50 +00:00
|
|
|
if ( cfg.hasKey( "X-KDE-ShowIfRunning" ) )
|
|
|
|
{
|
|
|
|
QString app = cfg.readEntry( "X-KDE-ShowIfRunning" );
|
|
|
|
if ( !kapp->dcopClient()->isApplicationRegistered( app.utf8() ) )
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2003-08-05 15:04:54 +00:00
|
|
|
if ( cfg.hasKey( "Actions" ) && cfg.hasKey( "ServiceTypes" ) )
|
|
|
|
{
|
|
|
|
QStringList types = cfg.readListEntry( "ServiceTypes" );
|
2003-08-23 17:55:47 +00:00
|
|
|
QStringList excludeTypes = cfg.readListEntry( "ExcludeServiceTypes" );
|
2003-08-05 15:04:54 +00:00
|
|
|
bool ok = false;
|
|
|
|
QString mimeGroup = m_sMimeType.left(m_sMimeType.find('/'));
|
|
|
|
|
|
|
|
// check for exact matches or a typeglob'd mimetype if we have a mimetype
|
2004-04-08 11:42:00 +00:00
|
|
|
for (QStringList::iterator it = types.begin();
|
|
|
|
it != types.end() && !ok;
|
|
|
|
++it)
|
2003-08-05 15:04:54 +00:00
|
|
|
{
|
|
|
|
// we could cram the following three if statements into
|
|
|
|
// one gigantic boolean statement but that would be a
|
|
|
|
// hororr show for readability
|
|
|
|
|
|
|
|
// first check if we have an all mimetype
|
|
|
|
if (*it == "all/all" ||
|
|
|
|
*it == "allfiles" /*compat with KDE up to 3.0.3*/)
|
|
|
|
{
|
2004-04-08 11:01:13 +00:00
|
|
|
ok = true;
|
|
|
|
for (QStringList::iterator itex = excludeTypes.begin(); itex != excludeTypes.end(); ++itex)
|
|
|
|
{
|
|
|
|
if( ((*itex).right(1) == "*" && (*itex).left((*itex).find('/')) == mimeGroup) ||
|
|
|
|
((*itex) == m_sMimeType) )
|
|
|
|
{
|
|
|
|
ok = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2003-08-05 15:04:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// next, do we match all files?
|
2004-04-08 11:01:13 +00:00
|
|
|
if (!ok &&
|
|
|
|
!isDirectory /* ## or inherits from it */ &&
|
|
|
|
*it == "all/allfiles")
|
2003-08-05 15:04:54 +00:00
|
|
|
{
|
2004-04-08 11:01:13 +00:00
|
|
|
ok = true;
|
|
|
|
for (QStringList::iterator itex = excludeTypes.begin(); itex != excludeTypes.end(); ++itex)
|
|
|
|
{
|
|
|
|
if( ((*itex).right(1) == "*" && (*itex).left((*itex).find('/')) == mimeGroup) ||
|
|
|
|
((*itex) == m_sMimeType) )
|
|
|
|
{
|
|
|
|
ok = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2004-03-09 17:38:58 +00:00
|
|
|
|
2003-08-05 15:04:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// if we have a mimetype, see if we have an exact or type
|
|
|
|
// globbed match
|
2004-04-08 11:01:13 +00:00
|
|
|
if (!ok &&
|
|
|
|
!m_sMimeType.isNull() &&
|
2003-08-05 15:04:54 +00:00
|
|
|
(*it == m_sMimeType ||
|
|
|
|
((*it).right(1) == "*" &&
|
|
|
|
(*it).left((*it).find('/')) == mimeGroup)))
|
|
|
|
{
|
2004-04-08 11:01:13 +00:00
|
|
|
ok = true;
|
|
|
|
for (QStringList::iterator itex = excludeTypes.begin(); itex != excludeTypes.end(); ++itex)
|
|
|
|
{
|
|
|
|
if( ((*itex).right(1) == "*" && (*itex).left((*itex).find('/')) == mimeGroup) ||
|
|
|
|
((*itex) == m_sMimeType) )
|
|
|
|
{
|
|
|
|
ok = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2003-08-05 15:04:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( ok )
|
|
|
|
{
|
|
|
|
// we use the categories .desktop entry to define submenus
|
|
|
|
// if none is defined, we just pop it in the main menu
|
2003-12-21 10:51:38 +00:00
|
|
|
QString priority = cfg.readEntry("X-KDE-Priority");
|
2003-08-05 15:04:54 +00:00
|
|
|
QString submenuName = cfg.readEntry( "X-KDE-Submenu" );
|
2003-12-21 10:01:10 +00:00
|
|
|
ServiceList* list = &user;
|
|
|
|
|
2003-08-05 15:04:54 +00:00
|
|
|
if (submenuName.isEmpty())
|
|
|
|
{
|
2003-12-21 10:51:38 +00:00
|
|
|
if (priority == "TopLevel")
|
2003-12-21 10:01:10 +00:00
|
|
|
{
|
|
|
|
list = &userToplevel;
|
|
|
|
}
|
2003-12-21 10:51:38 +00:00
|
|
|
else if (priority == "Important")
|
2003-12-21 10:01:10 +00:00
|
|
|
{
|
|
|
|
list = &userPriority;
|
|
|
|
}
|
|
|
|
}
|
2003-12-21 10:51:38 +00:00
|
|
|
else if (priority == "TopLevel")
|
2003-12-21 10:01:10 +00:00
|
|
|
{
|
|
|
|
list = &(userToplevelSubmenus[submenuName]);
|
|
|
|
}
|
2003-12-21 10:51:38 +00:00
|
|
|
else if (priority == "Important")
|
2003-12-21 10:01:10 +00:00
|
|
|
{
|
|
|
|
list = &(userPrioritySubmenus[submenuName]);
|
2003-08-05 15:04:54 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2003-12-21 10:01:10 +00:00
|
|
|
list = &(userSubmenus[submenuName]);
|
2003-08-05 15:04:54 +00:00
|
|
|
}
|
2003-12-21 10:01:10 +00:00
|
|
|
|
|
|
|
(*list) += KDEDesktopMimeType::userDefinedServices( *dIt + *eIt, url.isLocalFile() );
|
2003-08-05 15:04:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2003-07-28 22:06:29 +00:00
|
|
|
|
2003-08-05 15:04:54 +00:00
|
|
|
KTrader::OfferList offers;
|
2003-07-28 22:06:29 +00:00
|
|
|
|
2003-08-05 15:04:54 +00:00
|
|
|
if (kapp->authorizeKAction("openwith"))
|
2003-07-28 22:06:29 +00:00
|
|
|
{
|
2003-08-05 15:04:54 +00:00
|
|
|
// if check m_sMimeType.isNull (no commom mime type) set it to all/all
|
|
|
|
// 3 - Query for applications
|
|
|
|
offers = KTrader::self()->query( m_sMimeType.isNull( ) ? QString::fromLatin1( "all/all" ) : m_sMimeType ,
|
|
|
|
"Type == 'Application' and DesktopEntryName != 'kfmclient' and DesktopEntryName != 'kfmclient_dir' and DesktopEntryName != 'kfmclient_html'" );
|
2003-07-28 22:06:29 +00:00
|
|
|
}
|
2003-08-05 15:04:54 +00:00
|
|
|
|
|
|
|
//// Ok, we have everything, now insert
|
|
|
|
|
|
|
|
m_mapPopup.clear();
|
|
|
|
m_mapPopupServices.clear();
|
2003-08-31 13:38:31 +00:00
|
|
|
if ( !devicesFile)
|
2003-07-28 22:06:29 +00:00
|
|
|
{
|
2003-08-31 13:38:31 +00:00
|
|
|
if ( !offers.isEmpty() )
|
|
|
|
{
|
|
|
|
// First block, app and preview offers
|
|
|
|
addSeparator();
|
2003-07-28 22:06:29 +00:00
|
|
|
|
2003-08-31 13:38:31 +00:00
|
|
|
id = 1;
|
1999-12-18 20:30:37 +00:00
|
|
|
|
2003-08-31 13:38:31 +00:00
|
|
|
QDomElement menu = m_menuElement;
|
2003-01-12 16:30:51 +00:00
|
|
|
|
2003-08-31 13:38:31 +00:00
|
|
|
if ( offers.count() > 1 ) // submenu 'open with'
|
|
|
|
{
|
|
|
|
menu = m_doc.createElement( "menu" );
|
|
|
|
menu.setAttribute( "name", "openwith submenu" );
|
|
|
|
m_menuElement.appendChild( menu );
|
|
|
|
QDomElement text = m_doc.createElement( "text" );
|
|
|
|
menu.appendChild( text );
|
|
|
|
text.appendChild( m_doc.createTextNode( i18n("&Open With") ) );
|
|
|
|
}
|
1999-04-27 09:04:36 +00:00
|
|
|
|
2003-08-31 13:38:31 +00:00
|
|
|
if ( menu == m_menuElement ) // no submenu -> open with... above the single offer
|
|
|
|
{
|
|
|
|
KAction *openWithAct = new KAction( i18n( "&Open With..." ), 0, this, SLOT( slotPopupOpenWith() ), &m_ownActions, "openwith" );
|
|
|
|
addAction( openWithAct, menu );
|
|
|
|
}
|
1999-12-18 20:30:37 +00:00
|
|
|
|
2003-08-31 13:38:31 +00:00
|
|
|
KTrader::OfferList::ConstIterator it = offers.begin();
|
|
|
|
for( ; it != offers.end(); it++ )
|
|
|
|
{
|
|
|
|
QCString nam;
|
|
|
|
nam.setNum( id );
|
2000-04-08 20:31:49 +00:00
|
|
|
|
2003-08-31 13:38:31 +00:00
|
|
|
act = new KAction( (*it)->name(), (*it)->pixmap( KIcon::Small ), 0,
|
|
|
|
this, SLOT( slotRunService() ),
|
|
|
|
&m_ownActions, nam.prepend( "appservice_" ) );
|
|
|
|
addAction( act, menu );
|
2000-04-01 17:09:44 +00:00
|
|
|
|
2003-08-31 13:38:31 +00:00
|
|
|
m_mapPopup[ id++ ] = *it;
|
|
|
|
}
|
2000-03-19 00:44:31 +00:00
|
|
|
|
2003-08-31 13:38:31 +00:00
|
|
|
if ( menu != m_menuElement ) // submenu
|
|
|
|
{
|
|
|
|
addSeparator( menu );
|
|
|
|
KAction *openWithAct = new KAction( i18n( "&Other..." ), 0, this, SLOT( slotPopupOpenWith() ), &m_ownActions, "openwith" );
|
|
|
|
addAction( openWithAct, menu ); // Other...
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else // no app offers -> Open With...
|
2003-08-05 15:04:54 +00:00
|
|
|
{
|
2003-08-31 13:38:31 +00:00
|
|
|
addSeparator();
|
|
|
|
act = new KAction( i18n( "&Open With..." ), 0, this, SLOT( slotPopupOpenWith() ), &m_ownActions, "openwith" );
|
|
|
|
addAction( act );
|
2003-08-05 15:04:54 +00:00
|
|
|
}
|
2000-04-08 20:31:49 +00:00
|
|
|
|
2003-08-31 13:38:31 +00:00
|
|
|
addGroup( "preview" );
|
|
|
|
}
|
2003-08-05 15:04:54 +00:00
|
|
|
}
|
2003-12-21 10:01:10 +00:00
|
|
|
|
2003-08-05 15:04:54 +00:00
|
|
|
// Second block, builtin + user
|
2003-12-21 10:01:10 +00:00
|
|
|
QDomElement actionMenu = m_menuElement;
|
|
|
|
int userItemCount = 0;
|
|
|
|
if (user.count() + userSubmenus.count() +
|
2004-03-26 17:38:51 +00:00
|
|
|
userPriority.count() + userPrioritySubmenus.count() > 1)
|
2003-08-05 15:04:54 +00:00
|
|
|
{
|
2003-12-21 10:01:10 +00:00
|
|
|
// 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 );
|
|
|
|
QDomElement text = m_doc.createElement( "text" );
|
|
|
|
actionMenu.appendChild( text );
|
|
|
|
text.appendChild( m_doc.createTextNode( i18n("Ac&tions") ) );
|
|
|
|
}
|
2003-09-09 19:13:25 +00:00
|
|
|
|
2003-12-21 10:01:10 +00:00
|
|
|
userItemCount += insertServicesSubmenus(userPrioritySubmenus, actionMenu, false);
|
|
|
|
userItemCount += insertServices(userPriority, actionMenu, false);
|
2000-06-21 00:02:30 +00:00
|
|
|
|
2003-12-21 10:01:10 +00:00
|
|
|
// see if we need to put a separator between our priority items and our regular items
|
|
|
|
if (userItemCount > 0 &&
|
|
|
|
(user.count() > 0 ||
|
|
|
|
userSubmenus.count() > 0 ||
|
|
|
|
builtin.count() > 0) &&
|
|
|
|
actionMenu.lastChild().toElement().tagName().lower() != "separator")
|
|
|
|
{
|
|
|
|
QDomElement separator = m_doc.createElement( "separator" );
|
|
|
|
actionMenu.appendChild(separator);
|
|
|
|
}
|
2003-08-05 15:04:54 +00:00
|
|
|
|
2003-12-21 10:01:10 +00:00
|
|
|
userItemCount += insertServicesSubmenus(userSubmenus, actionMenu, false);
|
|
|
|
userItemCount += insertServices(user, actionMenu, false);
|
|
|
|
userItemCount += insertServices(builtin, m_menuElement, true);
|
2000-03-19 00:44:31 +00:00
|
|
|
|
2003-12-21 10:01:10 +00:00
|
|
|
userItemCount += insertServicesSubmenus(userToplevelSubmenus, m_menuElement, false);
|
|
|
|
userItemCount += insertServices(userToplevel, m_menuElement, false);
|
2003-05-19 17:24:46 +00:00
|
|
|
|
2003-12-21 10:01:10 +00:00
|
|
|
if (userItemCount > 0)
|
|
|
|
{
|
|
|
|
addSeparator();
|
|
|
|
}
|
2003-05-19 17:24:46 +00:00
|
|
|
|
2003-08-31 13:38:31 +00:00
|
|
|
if ( !isCurrentTrash && !isIntoTrash && !devicesFile)
|
2003-08-05 15:04:54 +00:00
|
|
|
addPlugins( ); // now it's time to add plugins
|
1999-12-18 20:30:37 +00:00
|
|
|
|
2003-10-09 14:02:59 +00:00
|
|
|
if ( KPropertiesDialog::canDisplay( m_lstItems ) && (kpf & ShowProperties) )
|
2003-08-05 15:04:54 +00:00
|
|
|
{
|
|
|
|
act = new KAction( i18n( "&Properties" ), 0, this, SLOT( slotPopupProperties() ),
|
|
|
|
&m_ownActions, "properties" );
|
|
|
|
addAction( act );
|
|
|
|
}
|
2000-04-01 17:09:44 +00:00
|
|
|
|
2003-08-05 15:04:54 +00:00
|
|
|
while ( !m_menuElement.lastChild().isNull() &&
|
2000-07-13 11:11:35 +00:00
|
|
|
m_menuElement.lastChild().toElement().tagName().lower() == "separator" )
|
2003-08-05 15:04:54 +00:00
|
|
|
m_menuElement.removeChild( m_menuElement.lastChild() );
|
2000-07-13 11:11:35 +00:00
|
|
|
|
2003-08-19 21:55:57 +00:00
|
|
|
if( bCanChangeSharing && !isCurrentTrash && !isIntoTrash)
|
2003-08-05 15:04:54 +00:00
|
|
|
{
|
|
|
|
if(KFileShare::authorization()==KFileShare::Authorized)
|
|
|
|
{
|
|
|
|
addSeparator();
|
2004-03-30 12:52:49 +00:00
|
|
|
act = new KAction( i18n("Share"), 0, this, SLOT( slotOpenShareFileDialog() ),
|
2003-08-05 15:04:54 +00:00
|
|
|
&m_ownActions, "sharefile" );
|
|
|
|
addAction( act );
|
|
|
|
}
|
|
|
|
}
|
2002-04-16 17:06:27 +00:00
|
|
|
|
2000-04-04 22:24:42 +00:00
|
|
|
|
2003-08-05 15:04:54 +00:00
|
|
|
addMerge( 0 );
|
|
|
|
|
|
|
|
m_factory->addClient( this );
|
1999-04-27 09:04:36 +00:00
|
|
|
}
|
|
|
|
|
2002-04-16 17:06:27 +00:00
|
|
|
void KonqPopupMenu::slotOpenShareFileDialog()
|
|
|
|
{
|
2002-06-17 10:52:42 +00:00
|
|
|
//kdDebug()<<"KonqPopupMenu::slotOpenShareFileDialog()\n";
|
|
|
|
// It may be that the kfileitem was created by hand
|
|
|
|
// (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 )
|
2002-04-16 17:06:27 +00:00
|
|
|
{
|
2002-06-17 10:52:42 +00:00
|
|
|
KFileItem * item = m_lstItems.first();
|
|
|
|
if (item->entry().count() == 0) // this item wasn't listed by a slave
|
2002-04-16 17:06:27 +00:00
|
|
|
{
|
2002-06-17 10:52:42 +00:00
|
|
|
// KPropertiesDialog will use stat to get more info on the file
|
2002-11-20 11:35:24 +00:00
|
|
|
KPropertiesDialog*dlg= new KPropertiesDialog( item->url(), d->m_parentWidget );
|
2002-06-17 10:52:42 +00:00
|
|
|
dlg->showFileSharingPage();
|
2002-04-16 17:06:27 +00:00
|
|
|
|
2002-06-17 10:52:42 +00:00
|
|
|
return;
|
2002-04-16 17:06:27 +00:00
|
|
|
}
|
|
|
|
}
|
2002-11-20 11:35:24 +00:00
|
|
|
KPropertiesDialog*dlg=new KPropertiesDialog( m_lstItems, d->m_parentWidget );
|
2002-06-17 10:52:42 +00:00
|
|
|
dlg->showFileSharingPage();
|
2002-04-16 17:06:27 +00:00
|
|
|
}
|
|
|
|
|
1999-04-27 09:04:36 +00:00
|
|
|
KonqPopupMenu::~KonqPopupMenu()
|
|
|
|
{
|
2002-01-23 20:59:23 +00:00
|
|
|
m_pluginList.clear();
|
2000-04-01 17:09:44 +00:00
|
|
|
delete m_factory;
|
|
|
|
delete m_builder;
|
2001-12-12 14:10:22 +00:00
|
|
|
delete d;
|
2002-01-21 12:28:38 +00:00
|
|
|
kdDebug(1203) << "~KonqPopupMenu leave" << endl;
|
1999-04-27 09:04:36 +00:00
|
|
|
}
|
|
|
|
|
2002-02-27 04:44:03 +00:00
|
|
|
void KonqPopupMenu::setURLTitle( const QString& urlTitle )
|
|
|
|
{
|
|
|
|
d->m_urlTitle = urlTitle;
|
|
|
|
}
|
|
|
|
|
1999-04-27 09:04:36 +00:00
|
|
|
void KonqPopupMenu::slotPopupNewView()
|
|
|
|
{
|
2000-02-19 20:30:21 +00:00
|
|
|
KURL::List::ConstIterator it = m_lstPopupURLs.begin();
|
1999-04-27 09:04:36 +00:00
|
|
|
for ( ; it != m_lstPopupURLs.end(); it++ )
|
|
|
|
(void) new KRun(*it);
|
|
|
|
}
|
|
|
|
|
2001-12-12 14:10:22 +00:00
|
|
|
void KonqPopupMenu::slotPopupNewDir()
|
|
|
|
{
|
2003-08-30 16:40:14 +00:00
|
|
|
if (m_lstPopupURLs.empty())
|
|
|
|
return;
|
2003-08-31 10:21:01 +00:00
|
|
|
|
2003-08-30 16:40:14 +00:00
|
|
|
KonqOperations::newDir(d->m_parentWidget, m_lstPopupURLs.first());
|
2001-12-12 14:10:22 +00:00
|
|
|
}
|
|
|
|
|
1999-04-27 09:04:36 +00:00
|
|
|
void KonqPopupMenu::slotPopupEmptyTrashBin()
|
|
|
|
{
|
2000-04-28 13:06:35 +00:00
|
|
|
KonqOperations::emptyTrash();
|
1999-04-27 09:04:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void KonqPopupMenu::slotPopupOpenWith()
|
|
|
|
{
|
2002-01-11 18:21:23 +00:00
|
|
|
KRun::displayOpenWithDialog( m_lstPopupURLs );
|
1999-04-27 09:04:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void KonqPopupMenu::slotPopupAddToBookmark()
|
|
|
|
{
|
2002-03-04 13:42:26 +00:00
|
|
|
KBookmarkGroup root = m_pManager->root();
|
2002-02-27 04:44:03 +00:00
|
|
|
if ( m_lstPopupURLs.count() == 1 ) {
|
|
|
|
KURL url = m_lstPopupURLs.first();
|
|
|
|
QString title = d->m_urlTitle.isEmpty() ? url.prettyURL() : d->m_urlTitle;
|
2004-03-13 13:14:26 +00:00
|
|
|
root.addBookmark( m_pManager, title, url );
|
2002-02-27 04:44:03 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
KURL::List::ConstIterator it = m_lstPopupURLs.begin();
|
|
|
|
for ( ; it != m_lstPopupURLs.end(); it++ )
|
2004-03-13 13:14:26 +00:00
|
|
|
root.addBookmark( m_pManager, (*it).prettyURL(), (*it) );
|
2002-02-27 04:44:03 +00:00
|
|
|
}
|
2002-03-04 13:42:26 +00:00
|
|
|
m_pManager->emitChanged( root );
|
1999-04-27 09:04:36 +00:00
|
|
|
}
|
|
|
|
|
2000-04-01 17:09:44 +00:00
|
|
|
void KonqPopupMenu::slotRunService()
|
1999-04-27 09:04:36 +00:00
|
|
|
{
|
2000-04-01 17:09:44 +00:00
|
|
|
QCString senderName = sender()->name();
|
|
|
|
int id = senderName.mid( senderName.find( '_' ) + 1 ).toInt();
|
|
|
|
|
2000-03-19 00:44:31 +00:00
|
|
|
// Is it a usual service (application)
|
1999-08-12 19:33:19 +00:00
|
|
|
QMap<int,KService::Ptr>::Iterator it = m_mapPopup.find( id );
|
1999-04-27 09:04:36 +00:00
|
|
|
if ( it != m_mapPopup.end() )
|
|
|
|
{
|
1999-08-12 19:33:19 +00:00
|
|
|
KRun::run( **it, m_lstPopupURLs );
|
1999-04-27 09:04:36 +00:00
|
|
|
return;
|
|
|
|
}
|
1999-12-18 20:30:37 +00:00
|
|
|
|
2000-03-19 00:44:31 +00:00
|
|
|
// Is it a service specific to desktop entry files ?
|
|
|
|
QMap<int,KDEDesktopMimeType::Service>::Iterator it2 = m_mapPopupServices.find( id );
|
|
|
|
if ( it2 != m_mapPopupServices.end() )
|
|
|
|
{
|
2000-11-21 18:07:11 +00:00
|
|
|
KDEDesktopMimeType::executeService( m_lstPopupURLs, it2.data() );
|
2000-03-19 00:44:31 +00:00
|
|
|
}
|
1999-04-27 09:04:36 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1999-09-24 22:47:25 +00:00
|
|
|
void KonqPopupMenu::slotPopupMimeType()
|
|
|
|
{
|
2000-04-15 15:22:56 +00:00
|
|
|
KonqOperations::editMimeType( m_sMimeType );
|
1999-09-24 22:47:25 +00:00
|
|
|
}
|
|
|
|
|
1999-04-27 09:04:36 +00:00
|
|
|
void KonqPopupMenu::slotPopupProperties()
|
|
|
|
{
|
2000-11-06 19:51:00 +00:00
|
|
|
// It may be that the kfileitem was created by hand
|
|
|
|
// (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
|
2002-11-20 11:35:24 +00:00
|
|
|
(void) new KPropertiesDialog( item->url(), d->m_parentWidget );
|
2000-11-06 19:51:00 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2002-11-20 11:35:24 +00:00
|
|
|
(void) new KPropertiesDialog( m_lstItems, d->m_parentWidget );
|
1999-04-27 09:04:36 +00:00
|
|
|
}
|
|
|
|
|
2000-04-01 17:09:44 +00:00
|
|
|
KAction *KonqPopupMenu::action( const QDomElement &element ) const
|
|
|
|
{
|
2000-07-04 16:33:30 +00:00
|
|
|
QCString name = element.attribute( attrName ).ascii();
|
2000-04-01 17:09:44 +00:00
|
|
|
KAction *res = m_ownActions.action( name );
|
|
|
|
|
|
|
|
if ( !res )
|
|
|
|
res = m_actions.action( name );
|
|
|
|
|
2003-01-12 20:10:44 +00:00
|
|
|
if ( !res && m_pMenuNew && strcmp( name, m_pMenuNew->name() ) == 0 )
|
2000-04-01 17:09:44 +00:00
|
|
|
return m_pMenuNew;
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
2001-05-01 10:04:44 +00:00
|
|
|
KActionCollection *KonqPopupMenu::actionCollection() const
|
|
|
|
{
|
|
|
|
return const_cast<KActionCollection *>( &m_ownActions );
|
|
|
|
}
|
|
|
|
|
2001-10-31 15:52:36 +00:00
|
|
|
QString KonqPopupMenu::mimeType( ) const {
|
2001-10-30 18:09:01 +00:00
|
|
|
return m_sMimeType;
|
2000-04-01 17:09:44 +00:00
|
|
|
}
|
2002-01-21 20:46:23 +00:00
|
|
|
KonqPopupMenu::ProtocolInfo KonqPopupMenu::protocolInfo() const
|
|
|
|
{
|
|
|
|
return m_info;
|
|
|
|
}
|
2001-10-30 18:09:01 +00:00
|
|
|
void KonqPopupMenu::addPlugins( ){
|
2001-10-31 15:52:36 +00:00
|
|
|
// search for Konq_PopupMenuPlugins inspired by simons kpropsdlg
|
|
|
|
//search for a plugin with the right protocol
|
2001-10-31 20:26:37 +00:00
|
|
|
KTrader::OfferList plugin_offers;
|
2001-12-02 19:10:42 +00:00
|
|
|
unsigned int pluginCount = 0;
|
2001-10-31 21:26:54 +00:00
|
|
|
plugin_offers = KTrader::self()->query( m_sMimeType.isNull() ? QString::fromLatin1( "all/all" ) : m_sMimeType , "'KonqPopupMenu/Plugin' in ServiceTypes");
|
2002-02-27 04:44:03 +00:00
|
|
|
if ( plugin_offers.isEmpty() )
|
2002-01-21 12:28:38 +00:00
|
|
|
return; // no plugins installed do not bother about it
|
|
|
|
|
2002-01-21 20:46:23 +00:00
|
|
|
KTrader::OfferList::ConstIterator iterator = plugin_offers.begin( );
|
|
|
|
KTrader::OfferList::ConstIterator end = plugin_offers.end( );
|
|
|
|
|
2002-01-21 12:28:38 +00:00
|
|
|
addGroup( "plugins" );
|
2001-10-30 18:09:01 +00:00
|
|
|
// travers the offerlist
|
2001-12-02 19:10:42 +00:00
|
|
|
for(; iterator != end; ++iterator, ++pluginCount ){
|
2001-10-31 15:52:36 +00:00
|
|
|
KonqPopupMenuPlugin *plugin =
|
|
|
|
KParts::ComponentFactory::
|
|
|
|
createInstanceFromLibrary<KonqPopupMenuPlugin>( (*iterator)->library().local8Bit(),
|
|
|
|
this,
|
|
|
|
(*iterator)->name().latin1() );
|
|
|
|
if ( !plugin )
|
2001-10-30 18:09:01 +00:00
|
|
|
continue;
|
2001-12-02 19:10:42 +00:00
|
|
|
QString pluginClientName = QString::fromLatin1( "Plugin%1" ).arg( pluginCount );
|
|
|
|
addMerge( pluginClientName );
|
|
|
|
plugin->domDocument().documentElement().setAttribute( "name", pluginClientName );
|
2001-10-30 18:09:01 +00:00
|
|
|
m_pluginList.append( plugin );
|
2001-10-31 15:52:36 +00:00
|
|
|
insertChildClient( plugin );
|
2001-10-30 18:09:01 +00:00
|
|
|
}
|
2000-04-01 17:09:44 +00:00
|
|
|
|
2002-01-21 12:28:38 +00:00
|
|
|
addMerge( "plugins" );
|
|
|
|
addSeparator();
|
2000-04-01 17:09:44 +00:00
|
|
|
}
|
2001-10-30 18:09:01 +00:00
|
|
|
KURL KonqPopupMenu::url( ) const {
|
|
|
|
return m_sViewURL;
|
2000-04-01 17:09:44 +00:00
|
|
|
}
|
2001-10-30 18:09:01 +00:00
|
|
|
KFileItemList KonqPopupMenu::fileItemList( ) const {
|
|
|
|
return m_lstItems;
|
2000-04-04 22:24:42 +00:00
|
|
|
}
|
2001-10-30 18:09:01 +00:00
|
|
|
KURL::List KonqPopupMenu::popupURLList( ) const {
|
|
|
|
return m_lstPopupURLs;
|
2000-04-09 09:41:40 +00:00
|
|
|
}
|
2001-10-30 18:09:01 +00:00
|
|
|
/**
|
|
|
|
Plugin
|
|
|
|
*/
|
2000-04-08 20:31:49 +00:00
|
|
|
|
2001-10-31 22:29:33 +00:00
|
|
|
KonqPopupMenuPlugin::KonqPopupMenuPlugin( KonqPopupMenu *parent, const char *name )
|
|
|
|
: QObject( parent, name ) {
|
2000-04-01 17:09:44 +00:00
|
|
|
}
|
2001-10-30 18:09:01 +00:00
|
|
|
KonqPopupMenuPlugin::~KonqPopupMenuPlugin( ){
|
2000-04-01 17:09:44 +00:00
|
|
|
|
2001-10-30 18:09:01 +00:00
|
|
|
}
|
2000-07-27 09:23:48 +00:00
|
|
|
#include "konq_popupmenu.moc"
|