1999-05-12 02:26:56 +00:00
|
|
|
/* This file is part of the KDE project
|
2006-01-10 08:57:20 +00:00
|
|
|
Copyright (C) 1998-2006 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
|
2005-10-05 08:44:32 +00:00
|
|
|
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
2005-07-04 19:02:09 +00:00
|
|
|
Boston, MA 02110-1301, USA.
|
1999-12-18 20:30:37 +00:00
|
|
|
*/
|
1999-05-12 02:26:56 +00:00
|
|
|
|
2006-05-02 15:52:32 +00:00
|
|
|
#include "konq_popupmenu.h"
|
|
|
|
#include "kpropertiesdialog.h"
|
|
|
|
#include "knewmenu.h"
|
|
|
|
#include "konq_operations.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>
|
2007-09-03 07:53:52 +00:00
|
|
|
#include <kbookmarkdialog.h>
|
1999-05-24 20:04:01 +00:00
|
|
|
#include <kdebug.h>
|
2002-01-11 18:21:23 +00:00
|
|
|
#include <krun.h>
|
2006-05-22 07:59:05 +00:00
|
|
|
#include <kprotocolmanager.h>
|
2006-08-04 15:10:05 +00:00
|
|
|
#include <kicon.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>
|
2007-08-31 22:52:52 +00:00
|
|
|
#include <kmimetypetrader.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>
|
2007-02-20 07:00:30 +00:00
|
|
|
#include <kconfiggroup.h>
|
|
|
|
#include <kdesktopfile.h>
|
2002-04-16 17:06:27 +00:00
|
|
|
#include <kfileshare.h>
|
2005-10-03 10:21:33 +00:00
|
|
|
#include <kauthorized.h>
|
2005-11-08 10:20:07 +00:00
|
|
|
#include <kglobal.h>
|
2007-02-20 07:00:30 +00:00
|
|
|
|
2006-07-02 18:31:00 +00:00
|
|
|
#include <QtDBus/QtDBus>
|
2006-05-11 08:04:23 +00:00
|
|
|
#include <QDir>
|
2006-05-02 15:52:32 +00:00
|
|
|
#include <QPixmap>
|
1999-04-27 09:04:36 +00:00
|
|
|
|
2004-09-06 18:40:43 +00:00
|
|
|
/*
|
|
|
|
Test cases:
|
2004-09-24 07:56:05 +00:00
|
|
|
iconview file: background
|
|
|
|
iconview file: file (with and without servicemenus)
|
|
|
|
iconview file: directory
|
|
|
|
iconview remote protocol (e.g. ftp: or fish:)
|
2004-09-24 09:20:59 +00:00
|
|
|
iconview trash:/
|
2004-09-06 18:40:43 +00:00
|
|
|
sidebar directory tree
|
2004-09-24 09:20:59 +00:00
|
|
|
sidebar Devices / Hard Disc
|
2004-09-06 18:40:43 +00:00
|
|
|
khtml background
|
|
|
|
khtml link
|
|
|
|
khtml image (www.kde.org RMB on K logo)
|
|
|
|
khtmlimage (same as above, then choose View image, then RMB)
|
|
|
|
selected text in khtml
|
|
|
|
embedded katepart
|
|
|
|
kdesktop folder
|
2004-09-07 16:30:13 +00:00
|
|
|
trash link on desktop
|
|
|
|
trashed file or directory
|
|
|
|
application .desktop file
|
2004-09-06 18:40:43 +00:00
|
|
|
Then the same after uninstalling kdeaddons/konq-plugins (kuick and arkplugin in particular)
|
|
|
|
*/
|
2003-05-19 17:24:46 +00:00
|
|
|
|
2000-04-01 17:09:44 +00:00
|
|
|
class KonqPopupMenuGUIBuilder : public KXMLGUIBuilder
|
|
|
|
{
|
|
|
|
public:
|
2006-05-02 15:52:32 +00:00
|
|
|
KonqPopupMenuGUIBuilder( QMenu *menu )
|
2000-04-01 17:09:44 +00:00
|
|
|
: 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
|
|
|
}
|
|
|
|
|
2006-05-02 15:52:32 +00:00
|
|
|
QMenu *m_menu;
|
2000-04-01 17:09:44 +00:00
|
|
|
};
|
|
|
|
|
2001-12-12 14:10:22 +00:00
|
|
|
class KonqPopupMenu::KonqPopupMenuPrivate
|
|
|
|
{
|
|
|
|
public:
|
2004-09-24 08:04:33 +00:00
|
|
|
KonqPopupMenuPrivate() : m_parentWidget( 0 ),
|
|
|
|
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
|
|
|
|
2004-09-24 08:04:33 +00:00
|
|
|
KonqPopupMenu::ProtocolInfo::ProtocolInfo()
|
2002-01-21 20:46:23 +00:00
|
|
|
{
|
|
|
|
m_Reading = false;
|
|
|
|
m_Writing = false;
|
|
|
|
m_Deleting = false;
|
|
|
|
m_Moving = false;
|
|
|
|
m_TrashIncluded = false;
|
|
|
|
}
|
2004-09-24 08:04:33 +00:00
|
|
|
|
2002-01-21 20:46:23 +00:00
|
|
|
bool KonqPopupMenu::ProtocolInfo::supportsReading() const
|
|
|
|
{
|
|
|
|
return m_Reading;
|
|
|
|
}
|
2004-09-24 08:04:33 +00:00
|
|
|
|
2002-01-21 20:46:23 +00:00
|
|
|
bool KonqPopupMenu::ProtocolInfo::supportsWriting() const
|
|
|
|
{
|
|
|
|
return m_Writing;
|
|
|
|
}
|
2004-09-24 08:04:33 +00:00
|
|
|
|
2002-01-21 20:46:23 +00:00
|
|
|
bool KonqPopupMenu::ProtocolInfo::supportsDeleting() const
|
|
|
|
{
|
|
|
|
return m_Deleting;
|
|
|
|
}
|
2004-09-24 08:04:33 +00:00
|
|
|
|
2002-01-21 20:46:23 +00:00
|
|
|
bool KonqPopupMenu::ProtocolInfo::supportsMoving() const
|
|
|
|
{
|
|
|
|
return m_Moving;
|
|
|
|
}
|
2004-09-24 08:04:33 +00:00
|
|
|
|
2002-01-21 20:46:23 +00:00
|
|
|
bool KonqPopupMenu::ProtocolInfo::trashIncluded() const
|
|
|
|
{
|
|
|
|
return m_TrashIncluded;
|
|
|
|
}
|
2001-12-12 14:10:22 +00:00
|
|
|
|
2004-09-06 22:22:05 +00:00
|
|
|
// This helper class stores the .desktop-file actions and the servicemenus
|
|
|
|
// in order to support X-KDE-Priority and X-KDE-Submenu.
|
|
|
|
class PopupServices
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ServiceList* selectList( const QString& priority, const QString& submenuName );
|
|
|
|
|
|
|
|
ServiceList builtin;
|
|
|
|
ServiceList user, userToplevel, userPriority;
|
|
|
|
QMap<QString, ServiceList> userSubmenus, userToplevelSubmenus, userPrioritySubmenus;
|
|
|
|
};
|
|
|
|
|
|
|
|
ServiceList* PopupServices::selectList( const QString& priority, const QString& submenuName )
|
|
|
|
{
|
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
|
2004-09-24 08:04:33 +00:00
|
|
|
//////////////////
|
2004-09-06 22:22:05 +00:00
|
|
|
|
2003-06-18 16:48:39 +00:00
|
|
|
KonqPopupMenu::KonqPopupMenu( KBookmarkManager *mgr, const KFileItemList &items,
|
2006-01-24 08:32:09 +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,
|
2006-11-23 22:21:46 +00:00
|
|
|
KParts::BrowserExtension::PopupFlags flags )
|
2006-05-02 15:52:32 +00:00
|
|
|
: QMenu( parentWidget ),
|
|
|
|
m_actions( actions ),
|
|
|
|
m_ownActions( static_cast<QWidget *>( 0 ) ),
|
|
|
|
m_pMenuNew( newMenu ),
|
|
|
|
m_sViewURL(viewURL),
|
|
|
|
m_lstItems(items),
|
|
|
|
m_pManager(mgr)
|
2003-06-18 16:48:39 +00:00
|
|
|
{
|
2004-09-24 08:04:33 +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
|
|
|
{
|
2005-10-03 13:10:28 +00:00
|
|
|
m_ownActions.setObjectName("KonqPopupMenu::m_ownActions");
|
2004-09-24 08:04:33 +00:00
|
|
|
d = new KonqPopupMenuPrivate;
|
|
|
|
d->m_parentWidget = parentWidget;
|
|
|
|
d->m_itemFlags = flags;
|
|
|
|
setup(kpf);
|
2002-11-20 11:35:24 +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)
|
|
|
|
{
|
2006-02-21 19:30:58 +00:00
|
|
|
if (it.value().isEmpty())
|
2003-12-21 10:01:10 +00:00
|
|
|
{
|
|
|
|
//avoid empty sub-menus
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2005-09-17 13:40:40 +00:00
|
|
|
QDomElement actionSubmenu = domDocument().createElement( "menu" );
|
2003-12-21 10:01:10 +00:00
|
|
|
actionSubmenu.setAttribute( "name", "actions " + it.key() );
|
|
|
|
menu.appendChild( actionSubmenu );
|
2005-09-17 13:40:40 +00:00
|
|
|
QDomElement subtext = domDocument().createElement( "text" );
|
2003-12-21 10:01:10 +00:00
|
|
|
actionSubmenu.appendChild( subtext );
|
2005-09-17 13:40:40 +00:00
|
|
|
subtext.appendChild( domDocument().createTextNode( it.key() ) );
|
2006-02-21 19:30:58 +00:00
|
|
|
count += insertServices(it.value(), actionSubmenu, isBuiltin);
|
2003-12-21 10:01:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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() &&
|
2005-10-10 10:21:04 +00:00
|
|
|
menu.lastChild().toElement().tagName().toLower() != "separator")
|
2003-07-28 22:06:29 +00:00
|
|
|
{
|
2005-09-17 13:40:40 +00:00
|
|
|
QDomElement separator = domDocument().createElement( "separator" );
|
2003-07-28 22:06:29 +00:00
|
|
|
menu.appendChild(separator);
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2003-05-19 17:24:46 +00:00
|
|
|
if (isBuiltin || (*it).m_display == true)
|
|
|
|
{
|
2005-07-28 14:59:42 +00:00
|
|
|
QString name;
|
2003-05-19 17:24:46 +00:00
|
|
|
name.setNum( id );
|
|
|
|
name.prepend( isBuiltin ? "builtinservice_" : "userservice_" );
|
2007-01-08 22:39:24 +00:00
|
|
|
QAction* act = m_ownActions.addAction( name.toLatin1() );
|
|
|
|
act->setText( QString((*it).m_strName).replace('&',"&&") );
|
2006-04-02 06:34:44 +00:00
|
|
|
connect(act, SIGNAL(triggered()), this, SLOT(slotRunService()));
|
2003-05-19 17:24:46 +00:00
|
|
|
|
|
|
|
if ( !(*it).m_strIcon.isEmpty() )
|
|
|
|
{
|
2006-03-22 13:32:49 +00:00
|
|
|
act->setIcon( KIcon((*it).m_strIcon) );
|
2003-05-19 17:24:46 +00:00
|
|
|
}
|
|
|
|
|
2007-01-08 22:39:24 +00:00
|
|
|
KonqXMLGUIClient::addAction( name, menu ); // Add to toplevel menu
|
2003-05-19 17:24:46 +00:00
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2007-02-20 11:42:48 +00:00
|
|
|
bool KonqPopupMenu::KIOSKAuthorizedAction(const KConfigGroup& cfg)
|
2003-07-28 22:06:29 +00:00
|
|
|
{
|
|
|
|
if ( !cfg.hasKey( "X-KDE-AuthorizeAction") )
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2006-01-26 15:16:50 +00:00
|
|
|
QStringList list = cfg.readEntry("X-KDE-AuthorizeAction", QStringList() );
|
2003-07-28 22:06:29 +00:00
|
|
|
if (kapp && !list.isEmpty())
|
|
|
|
{
|
|
|
|
for(QStringList::ConstIterator it = list.begin();
|
|
|
|
it != list.end();
|
|
|
|
++it)
|
|
|
|
{
|
2005-11-08 10:20:07 +00:00
|
|
|
if (!KAuthorized::authorize((*it).trimmed()))
|
2003-07-28 22:06:29 +00:00
|
|
|
{
|
|
|
|
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
|
|
|
{
|
2006-05-02 15:52:32 +00:00
|
|
|
Q_ASSERT( m_lstItems.count() >= 1 );
|
2003-08-05 15:04:54 +00:00
|
|
|
|
2005-01-18 10:10:23 +00:00
|
|
|
const bool bIsLink = (kpf & IsLink);
|
2003-08-05 15:04:54 +00:00
|
|
|
bool currentDir = false;
|
|
|
|
bool sReading = true;
|
2004-10-19 20:37:45 +00:00
|
|
|
bool sDeleting = ( d->m_itemFlags & KParts::BrowserExtension::NoDeletion ) == 0;
|
|
|
|
bool sMoving = sDeleting;
|
2007-10-01 08:00:48 +00:00
|
|
|
bool sWriting = sDeleting && m_lstItems.first().isWritable();
|
|
|
|
m_sMimeType = m_lstItems.first().mimetype();
|
2006-03-23 17:19:24 +00:00
|
|
|
QString mimeGroup = m_sMimeType.left(m_sMimeType.indexOf('/'));
|
2007-10-01 08:00:48 +00:00
|
|
|
mode_t mode = m_lstItems.first().mode();
|
2004-09-24 09:20:59 +00:00
|
|
|
bool isDirectory = S_ISDIR(mode);
|
2003-08-05 15:04:54 +00:00
|
|
|
bool bTrashIncluded = false;
|
2005-01-18 10:10:23 +00:00
|
|
|
bool mediaFiles = false;
|
2007-10-01 08:00:48 +00:00
|
|
|
bool isLocal = m_lstItems.first().isLocalFile()
|
|
|
|
|| m_lstItems.first().url().protocol()=="media"
|
|
|
|
|| m_lstItems.first().url().protocol()=="system";
|
2005-01-18 10:10:23 +00:00
|
|
|
bool isTrashLink = false;
|
2003-08-05 15:04:54 +00:00
|
|
|
m_lstPopupURLs.clear();
|
|
|
|
int id = 0;
|
|
|
|
setFont(KGlobalSettings::menuFont());
|
|
|
|
|
2005-09-12 13:14:55 +00:00
|
|
|
attrName = QLatin1String( "name" );
|
2003-08-05 15:04:54 +00:00
|
|
|
|
|
|
|
prepareXMLGUIStuff();
|
|
|
|
m_builder = new KonqPopupMenuGUIBuilder( this );
|
|
|
|
m_factory = new KXMLGUIFactory( m_builder );
|
|
|
|
|
2006-01-24 08:32:09 +00:00
|
|
|
KUrl url;
|
2006-01-10 08:57:20 +00:00
|
|
|
KFileItemList::const_iterator it = m_lstItems.begin();
|
|
|
|
const KFileItemList::const_iterator kend = m_lstItems.end();
|
2004-12-10 21:35:06 +00:00
|
|
|
QStringList mimeTypeList;
|
2003-08-05 15:04:54 +00:00
|
|
|
// Check whether all URLs are correct
|
2006-01-10 08:57:20 +00:00
|
|
|
for ( ; it != kend; ++it )
|
2003-08-05 15:04:54 +00:00
|
|
|
{
|
2007-10-01 08:00:48 +00:00
|
|
|
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
|
2007-10-01 08:00:48 +00:00
|
|
|
if ( mode != (*it).mode() )
|
2003-08-05 15:04:54 +00:00
|
|
|
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
|
2007-10-01 08:00:48 +00:00
|
|
|
if ( m_sMimeType != (*it).mimetype() )
|
2004-04-20 23:07:20 +00:00
|
|
|
{
|
2006-01-02 16:09:13 +00:00
|
|
|
m_sMimeType.clear(); // mimetypes are different => null
|
1999-08-04 10:50:58 +00:00
|
|
|
|
2007-10-01 08:00:48 +00:00
|
|
|
if ( mimeGroup != (*it).mimetype().left((*it).mimetype().indexOf('/')))
|
2006-01-02 16:09:13 +00:00
|
|
|
mimeGroup.clear(); // mimetype groups are different as well!
|
2004-04-20 23:07:20 +00:00
|
|
|
}
|
|
|
|
|
2007-10-01 08:00:48 +00:00
|
|
|
if ( mimeTypeList.indexOf( (*it).mimetype() ) == -1 )
|
|
|
|
mimeTypeList << (*it).mimetype();
|
2004-12-10 21:35:06 +00:00
|
|
|
|
2005-06-03 16:55:19 +00:00
|
|
|
if ( isLocal && !url.isLocalFile() && url.protocol() != "media" && url.protocol() != "system" )
|
2004-09-24 09:20:59 +00:00
|
|
|
isLocal = false;
|
|
|
|
|
2005-06-03 23:18:33 +00:00
|
|
|
if ( !bTrashIncluded && (
|
|
|
|
( url.protocol() == "trash" && url.path().length() <= 1 )
|
|
|
|
|| url.url() == "system:/trash" || url.url() == "system:/trash/" ) ) {
|
2003-08-05 15:04:54 +00:00
|
|
|
bTrashIncluded = true;
|
2005-06-03 16:55:19 +00:00
|
|
|
isLocal = false;
|
|
|
|
}
|
2000-08-07 18:34:11 +00:00
|
|
|
|
2003-08-05 15:04:54 +00:00
|
|
|
if ( sReading )
|
2006-05-22 07:59:05 +00:00
|
|
|
sReading = KProtocolManager::supportsReading( url );
|
1999-04-27 09:04:36 +00:00
|
|
|
|
2003-08-05 15:04:54 +00:00
|
|
|
if ( sWriting )
|
2007-10-01 08:00:48 +00:00
|
|
|
sWriting = KProtocolManager::supportsWriting( url ) && (*it).isWritable();
|
1999-12-18 20:30:37 +00:00
|
|
|
|
2003-08-05 15:04:54 +00:00
|
|
|
if ( sDeleting )
|
2006-05-22 07:59:05 +00:00
|
|
|
sDeleting = KProtocolManager::supportsDeleting( url );
|
1999-04-27 09:04:36 +00:00
|
|
|
|
2003-08-05 15:04:54 +00:00
|
|
|
if ( sMoving )
|
2006-05-22 07:59:05 +00:00
|
|
|
sMoving = KProtocolManager::supportsMoving( url );
|
2007-10-01 08:00:48 +00:00
|
|
|
if ( (*it).mimetype().startsWith("media/") )
|
2004-11-02 12:45:38 +00:00
|
|
|
mediaFiles = true;
|
2003-08-05 15:04:54 +00:00
|
|
|
}
|
|
|
|
url = m_sViewURL;
|
|
|
|
url.cleanPath();
|
|
|
|
|
|
|
|
//check if url is current directory
|
|
|
|
if ( m_lstItems.count() == 1 )
|
|
|
|
{
|
2007-10-01 08:00:48 +00:00
|
|
|
KUrl firstPopupURL( m_lstItems.first().url() );
|
2003-08-05 15:04:54 +00:00
|
|
|
firstPopupURL.cleanPath();
|
2007-08-03 06:40:12 +00:00
|
|
|
//kDebug(1203) << "View path is " << url.url();
|
|
|
|
//kDebug(1203) << "First popup path is " << firstPopupURL.url();
|
2006-05-08 13:33:51 +00:00
|
|
|
currentDir = firstPopupURL.equals( url, KUrl::CompareWithoutTrailingSlash );
|
2005-01-18 10:10:23 +00:00
|
|
|
if ( isLocal && m_sMimeType == "application/x-desktop" ) {
|
2007-02-20 07:00:30 +00:00
|
|
|
KDesktopFile desktopFile( firstPopupURL.path() );
|
|
|
|
const KConfigGroup cfg = desktopFile.desktopGroup();
|
2005-01-18 10:10:23 +00:00
|
|
|
isTrashLink = ( cfg.readEntry("Type") == "Link" && cfg.readEntry("URL") == "trash:/" );
|
2005-06-03 13:54:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( isTrashLink ) {
|
|
|
|
sDeleting = false;
|
2005-01-18 10:10:23 +00:00
|
|
|
}
|
2003-08-05 15:04:54 +00:00
|
|
|
}
|
2005-01-18 10:10:23 +00:00
|
|
|
const bool isSingleLocal = m_lstItems.count() == 1 && isLocal;
|
|
|
|
|
|
|
|
m_info.m_Reading = sReading;
|
|
|
|
m_info.m_Writing = sWriting;
|
|
|
|
m_info.m_Deleting = sDeleting;
|
2005-06-03 23:18:33 +00:00
|
|
|
m_info.m_Moving = sMoving;
|
2005-01-18 10:10:23 +00:00
|
|
|
m_info.m_TrashIncluded = bTrashIncluded;
|
2003-01-26 21:31:52 +00:00
|
|
|
|
2005-01-18 10:10:23 +00:00
|
|
|
// isCurrentTrash: popup on trash:/ itself, or on the trash.desktop link
|
|
|
|
bool isCurrentTrash = ( m_lstItems.count() == 1 && bTrashIncluded ) || isTrashLink;
|
2005-06-03 23:18:33 +00:00
|
|
|
bool isIntoTrash = ( url.protocol() == "trash" || url.url().startsWith( "system:/trash" ) ) && !isCurrentTrash; // trashed file, not trash:/ itself
|
2007-08-03 06:40:12 +00:00
|
|
|
//kDebug() << "isLocal=" << isLocal << " url=" << url << " isCurrentTrash=" << isCurrentTrash << " isIntoTrash=" << isIntoTrash << " bTrashIncluded=" << bTrashIncluded;
|
2004-11-02 12:45:38 +00:00
|
|
|
bool isSingleMedium = m_lstItems.count() == 1 && mediaFiles;
|
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
|
|
|
|
2007-01-08 22:39:24 +00:00
|
|
|
QAction * 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
|
|
|
|
2006-03-23 17:19:24 +00:00
|
|
|
bool isKDesktop = QByteArray( kapp->objectName().toUtf8() ) == "kdesktop";
|
2007-01-08 22:39:24 +00:00
|
|
|
QAction *actNewWindow = 0;
|
2003-07-04 04:27:59 +00:00
|
|
|
|
2005-09-08 09:35:29 +00:00
|
|
|
if (( kpf & ShowProperties ) && isKDesktop &&
|
2005-10-03 10:50:16 +00:00
|
|
|
!KAuthorized::authorizeKAction("editable_desktop_icons"))
|
2003-08-29 11:57:06 +00:00
|
|
|
{
|
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.
|
2004-06-12 21:43:11 +00:00
|
|
|
if ( ((kpf & ShowNewWindow) != 0) && sReading )
|
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" );
|
2007-01-08 22:39:24 +00:00
|
|
|
actNewWindow = m_ownActions.addAction( "newview" );
|
2007-03-08 19:32:19 +00:00
|
|
|
actNewWindow->setIcon( KIcon("window-new") );
|
2007-01-08 22:39:24 +00:00
|
|
|
actNewWindow->setText( openStr );
|
2006-04-02 06:34:44 +00:00
|
|
|
connect(actNewWindow, SIGNAL(triggered()), this, SLOT(slotPopupNewView()));
|
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)
|
2004-12-20 18:11:51 +00:00
|
|
|
actNewWindow->setToolTip( i18n( "Open the trash in a new window" ) );
|
2004-11-02 12:45:38 +00:00
|
|
|
else if (isSingleMedium)
|
2004-12-20 18:11:51 +00:00
|
|
|
actNewWindow->setToolTip( i18n( "Open the medium in a new window") );
|
2003-08-05 15:04:54 +00:00
|
|
|
else
|
2004-12-20 18:11:51 +00:00
|
|
|
actNewWindow->setToolTip( i18n( "Open the document in a new window" ) );
|
2003-08-05 15:04:54 +00:00
|
|
|
}
|
2000-04-01 17:09:44 +00:00
|
|
|
|
2004-11-10 13:43:14 +00:00
|
|
|
if ( S_ISDIR(mode) && sWriting && !isCurrentTrash ) // A dir, and we can create things into it
|
2003-01-26 21:31:52 +00:00
|
|
|
{
|
2004-11-10 13:43:14 +00:00
|
|
|
if ( currentDir && m_pMenuNew ) // Current dir -> add the "new" menu
|
2003-10-09 14:02:59 +00:00
|
|
|
{
|
2004-11-10 13:43:14 +00:00
|
|
|
// As requested by KNewMenu :
|
|
|
|
m_pMenuNew->slotCheckUpToDate();
|
|
|
|
m_pMenuNew->setPopupFiles( m_lstPopupURLs );
|
|
|
|
|
2007-01-08 22:39:24 +00:00
|
|
|
KonqXMLGUIClient::addAction( m_pMenuNew->objectName() );
|
2004-11-10 13:43:14 +00:00
|
|
|
|
2005-07-28 14:59:42 +00:00
|
|
|
KonqXMLGUIClient::addSeparator();
|
2003-10-09 14:02:59 +00:00
|
|
|
}
|
2004-11-10 13:43:14 +00:00
|
|
|
else
|
2003-08-05 15:04:54 +00:00
|
|
|
{
|
2004-11-10 13:43:14 +00:00
|
|
|
if (d->m_itemFlags & KParts::BrowserExtension::ShowCreateDirectory)
|
2003-08-05 15:04:54 +00:00
|
|
|
{
|
2007-01-08 22:39:24 +00:00
|
|
|
QAction *actNewDir = m_ownActions.addAction( "newdir" );
|
2007-03-08 19:32:19 +00:00
|
|
|
actNewDir->setIcon( KIcon("folder-new") );
|
2007-01-08 22:39:24 +00:00
|
|
|
actNewDir->setText( i18n( "Create &Folder..." ) );
|
2006-04-02 06:34:44 +00:00
|
|
|
connect(actNewDir, SIGNAL(triggered()), this, SLOT(slotPopupNewDir()));
|
2007-01-08 22:39:24 +00:00
|
|
|
KonqXMLGUIClient::addAction( "newdir" );
|
2005-07-28 14:59:42 +00:00
|
|
|
KonqXMLGUIClient::addSeparator();
|
2003-08-05 15:04:54 +00:00
|
|
|
}
|
|
|
|
}
|
2004-11-10 13:43:14 +00:00
|
|
|
} else if ( isIntoTrash ) {
|
|
|
|
// Trashed item, offer restoring
|
2007-01-08 22:39:24 +00:00
|
|
|
act = m_ownActions.addAction( "restore" );
|
|
|
|
act->setText( i18n( "&Restore" ) );
|
2006-04-02 06:34:44 +00:00
|
|
|
connect(act, SIGNAL(triggered()), this, SLOT(slotPopupRestoreTrashedItems()));
|
2007-01-08 22:39:24 +00:00
|
|
|
KonqXMLGUIClient::addAction( "restore" );
|
2004-11-10 13:43:14 +00:00
|
|
|
}
|
2003-08-05 15:04:54 +00:00
|
|
|
|
2004-11-10 13:43:14 +00:00
|
|
|
if (d->m_itemFlags & KParts::BrowserExtension::ShowNavigationItems)
|
|
|
|
{
|
|
|
|
if (d->m_itemFlags & KParts::BrowserExtension::ShowUp)
|
2005-07-28 14:59:42 +00:00
|
|
|
KonqXMLGUIClient::addAction( "up" );
|
|
|
|
KonqXMLGUIClient::addAction( "back" );
|
|
|
|
KonqXMLGUIClient::addAction( "forward" );
|
2004-11-10 13:43:14 +00:00
|
|
|
if (d->m_itemFlags & KParts::BrowserExtension::ShowReload)
|
2005-07-28 14:59:42 +00:00
|
|
|
KonqXMLGUIClient::addAction( "reload" );
|
|
|
|
KonqXMLGUIClient::addSeparator();
|
2004-11-10 13:43:14 +00:00
|
|
|
}
|
1999-04-27 09:04:36 +00:00
|
|
|
|
2004-11-10 13:43:14 +00:00
|
|
|
// "open in new window" is either provided by us, or by the tabhandling group
|
|
|
|
if (actNewWindow)
|
|
|
|
{
|
2007-01-08 22:39:24 +00:00
|
|
|
KonqXMLGUIClient::addAction( "newview" );
|
2005-07-28 14:59:42 +00:00
|
|
|
KonqXMLGUIClient::addSeparator();
|
2004-11-10 13:43:14 +00:00
|
|
|
}
|
2005-07-28 14:59:42 +00:00
|
|
|
KonqXMLGUIClient::addGroup( "tabhandling" ); // includes a separator
|
2001-12-11 17:40:02 +00:00
|
|
|
|
2004-11-10 13:43:14 +00:00
|
|
|
if ( !bIsLink )
|
|
|
|
{
|
|
|
|
if ( !currentDir && sReading ) {
|
|
|
|
if ( sDeleting ) {
|
2005-07-28 14:59:42 +00:00
|
|
|
KonqXMLGUIClient::addAction( "cut" );
|
2003-08-05 15:04:54 +00:00
|
|
|
}
|
2005-07-28 14:59:42 +00:00
|
|
|
KonqXMLGUIClient::addAction( "copy" );
|
2004-11-10 13:43:14 +00:00
|
|
|
}
|
2003-08-05 15:04:54 +00:00
|
|
|
|
2004-11-10 13:43:14 +00:00
|
|
|
if ( S_ISDIR(mode) && sWriting ) {
|
|
|
|
if ( currentDir )
|
2005-07-28 14:59:42 +00:00
|
|
|
KonqXMLGUIClient::addAction( "paste" );
|
2004-11-10 13:43:14 +00:00
|
|
|
else
|
2005-07-28 14:59:42 +00:00
|
|
|
KonqXMLGUIClient::addAction( "pasteto" );
|
2004-11-10 13:43:14 +00:00
|
|
|
}
|
|
|
|
if ( !currentDir )
|
|
|
|
{
|
2005-01-18 10:10:23 +00:00
|
|
|
if ( m_lstItems.count() == 1 && sMoving )
|
2005-07-28 14:59:42 +00:00
|
|
|
KonqXMLGUIClient::addAction( "rename" );
|
2003-08-05 15:04:54 +00:00
|
|
|
|
2005-04-05 15:14:14 +00:00
|
|
|
bool addTrash = false;
|
|
|
|
bool addDel = false;
|
|
|
|
|
2005-01-18 10:10:23 +00:00
|
|
|
if ( sMoving && !isIntoTrash && !isTrashLink )
|
2005-04-05 15:14:14 +00:00
|
|
|
addTrash = true;
|
2003-08-05 15:04:54 +00:00
|
|
|
|
2004-11-10 13:43:14 +00:00
|
|
|
if ( sDeleting ) {
|
2005-01-23 09:31:31 +00:00
|
|
|
if ( !isLocal )
|
2005-04-05 15:14:14 +00:00
|
|
|
addDel = true;
|
2005-10-21 14:36:26 +00:00
|
|
|
else if (QApplication::keyboardModifiers() & Qt::ShiftModifier) {
|
2005-04-05 15:14:14 +00:00
|
|
|
addTrash = false;
|
|
|
|
addDel = true;
|
|
|
|
}
|
2005-01-23 09:31:31 +00:00
|
|
|
else {
|
2005-11-08 10:20:07 +00:00
|
|
|
KConfigGroup configGroup( KGlobal::config(), "KDE" );
|
2007-02-09 16:55:14 +00:00
|
|
|
if ( configGroup.readEntry( "ShowDeleteCommand", false) )
|
2005-04-05 15:14:14 +00:00
|
|
|
addDel = true;
|
2005-01-23 09:31:31 +00:00
|
|
|
}
|
2003-08-05 15:04:54 +00:00
|
|
|
}
|
2005-04-05 15:14:14 +00:00
|
|
|
|
|
|
|
if ( addTrash )
|
2005-07-28 14:59:42 +00:00
|
|
|
KonqXMLGUIClient::addAction( "trash" );
|
2005-04-05 15:14:14 +00:00
|
|
|
if ( addDel )
|
2005-07-28 14:59:42 +00:00
|
|
|
KonqXMLGUIClient::addAction( "del" );
|
2003-08-05 15:04:54 +00:00
|
|
|
}
|
|
|
|
}
|
2004-11-10 13:43:14 +00:00
|
|
|
if ( isCurrentTrash )
|
|
|
|
{
|
2007-01-08 22:39:24 +00:00
|
|
|
act = m_ownActions.addAction( "emptytrash" );
|
|
|
|
act->setIcon( KIcon("emptytrash") );
|
|
|
|
act->setText( i18n( "&Empty Trash Bin" ) );
|
2007-02-20 07:00:30 +00:00
|
|
|
KConfig trashConfig( "trashrc", KConfig::OnlyLocal);
|
|
|
|
act->setEnabled( !trashConfig.group("Status").readEntry( "Empty", true ) );
|
2006-04-02 06:34:44 +00:00
|
|
|
connect(act, SIGNAL(triggered()), this, SLOT(slotPopupEmptyTrashBin()));
|
2007-01-08 22:39:24 +00:00
|
|
|
KonqXMLGUIClient::addAction( "emptytrash" );
|
2004-11-10 13:43:14 +00:00
|
|
|
}
|
2005-07-28 14:59:42 +00:00
|
|
|
KonqXMLGUIClient::addGroup( "editactions" );
|
2004-03-30 15:58:57 +00:00
|
|
|
|
|
|
|
if (d->m_itemFlags & KParts::BrowserExtension::ShowTextSelectionItems) {
|
2005-07-28 14:59:42 +00:00
|
|
|
KonqXMLGUIClient::addMerge( 0 );
|
2004-03-30 15:58:57 +00:00
|
|
|
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
|
|
|
{
|
2005-07-28 14:59:42 +00:00
|
|
|
KonqXMLGUIClient::addSeparator();
|
2003-09-11 20:24:01 +00:00
|
|
|
QString caption;
|
|
|
|
if (currentDir)
|
|
|
|
{
|
2006-03-23 17:19:24 +00:00
|
|
|
bool httpPage = (m_sViewURL.protocol().indexOf("http", 0, Qt::CaseInsensitive) == 0);
|
2003-09-11 20:24:01 +00:00
|
|
|
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
|
|
|
|
2007-01-08 22:39:24 +00:00
|
|
|
act = m_ownActions.addAction( "bookmark_add" );
|
2007-03-08 19:32:19 +00:00
|
|
|
act->setIcon( KIcon("bookmark-new") );
|
2007-01-08 22:39:24 +00:00
|
|
|
act->setText( caption );
|
2006-04-02 06:34:44 +00:00
|
|
|
connect(act, SIGNAL(triggered()), this, SLOT(slotPopupAddToBookmark()));
|
2003-09-11 20:24:01 +00:00
|
|
|
if (m_lstItems.count() > 1)
|
|
|
|
act->setEnabled(false);
|
2005-10-03 10:21:33 +00:00
|
|
|
if (KAuthorized::authorizeKAction("bookmarks"))
|
2007-01-08 22:39:24 +00:00
|
|
|
KonqXMLGUIClient::addAction( "bookmark_add" );
|
2003-09-12 16:25:11 +00:00
|
|
|
if (bIsLink)
|
2005-07-28 14:59:42 +00:00
|
|
|
KonqXMLGUIClient::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
|
|
|
|
2004-09-06 22:22:05 +00:00
|
|
|
PopupServices s;
|
2007-10-01 08:00:48 +00:00
|
|
|
KUrl urlForServiceMenu( m_lstItems.first().url() );
|
1999-12-18 20:30:37 +00:00
|
|
|
|
2003-08-05 15:04:54 +00:00
|
|
|
// 1 - Look for builtin and user-defined services
|
|
|
|
if ( m_sMimeType == "application/x-desktop" && isSingleLocal ) // .desktop file
|
|
|
|
{
|
|
|
|
// get builtin services, like mount/unmount
|
2007-10-01 08:00:48 +00:00
|
|
|
s.builtin = KDesktopFileActions::builtinServices( m_lstItems.first().url() );
|
|
|
|
const QString path = m_lstItems.first().url().path();
|
2007-02-20 07:00:30 +00:00
|
|
|
KDesktopFile desktopFile( path );
|
|
|
|
KConfigGroup cfg = desktopFile.desktopGroup();
|
2004-09-06 22:22:05 +00:00
|
|
|
const QString priority = cfg.readEntry("X-KDE-Priority");
|
|
|
|
const QString submenuName = cfg.readEntry( "X-KDE-Submenu" );
|
2005-01-26 23:57:41 +00:00
|
|
|
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?
|
|
|
|
}
|
2004-09-06 22:22:05 +00:00
|
|
|
ServiceList* list = s.selectList( priority, submenuName );
|
2007-03-26 08:24:06 +00:00
|
|
|
(*list) = KDesktopFileActions::userDefinedServices( path, desktopFile, url.isLocalFile() );
|
2000-03-18 15:19:43 +00:00
|
|
|
}
|
1999-10-17 15:19:54 +00:00
|
|
|
|
2004-09-23 12:59:03 +00:00
|
|
|
if ( sReading )
|
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)
|
|
|
|
{
|
2007-10-01 08:00:48 +00:00
|
|
|
QString dotDirectoryFile = m_lstItems.first().url().path( KUrl::AddTrailingSlash ).append(".directory");
|
2007-02-20 07:00:30 +00:00
|
|
|
KDesktopFile desktopFile( dotDirectoryFile );
|
|
|
|
const KConfigGroup cfg = desktopFile.desktopGroup();
|
2000-11-19 19:14:07 +00:00
|
|
|
|
2007-02-20 11:42:48 +00:00
|
|
|
if (KIOSKAuthorizedAction(cfg))
|
2003-08-05 15:04:54 +00:00
|
|
|
{
|
2004-09-06 22:22:05 +00:00
|
|
|
const QString priority = cfg.readEntry("X-KDE-Priority");
|
|
|
|
const QString submenuName = cfg.readEntry( "X-KDE-Submenu" );
|
|
|
|
ServiceList* list = s.selectList( priority, submenuName );
|
2007-03-26 08:24:06 +00:00
|
|
|
(*list) += KDesktopFileActions::userDefinedServices( dotDirectoryFile, desktopFile, true );
|
2003-08-05 15:04:54 +00:00
|
|
|
}
|
2000-11-25 21:52:59 +00:00
|
|
|
}
|
1999-04-27 09:04:36 +00:00
|
|
|
|
2006-04-11 21:44:43 +00:00
|
|
|
// findAllResources() also removes duplicates
|
|
|
|
const QStringList entries = KGlobal::dirs()->findAllResources( "data",
|
|
|
|
"konqueror/servicemenus/*.desktop",
|
2007-02-12 16:17:46 +00:00
|
|
|
KStandardDirs::NoDuplicates );
|
2006-04-11 21:44:43 +00:00
|
|
|
QStringList::ConstIterator eIt = entries.begin();
|
|
|
|
const QStringList::ConstIterator eEnd = entries.end();
|
|
|
|
for (; eIt != eEnd; ++eIt )
|
2003-08-05 15:04:54 +00:00
|
|
|
{
|
2007-02-20 07:00:30 +00:00
|
|
|
KDesktopFile desktopFile( *eIt );
|
|
|
|
const KConfigGroup cfg = desktopFile.desktopGroup();
|
2003-07-04 17:22:49 +00:00
|
|
|
|
2007-02-20 11:42:48 +00:00
|
|
|
if (!KIOSKAuthorizedAction(cfg))
|
2003-08-05 15:04:54 +00:00
|
|
|
{
|
2006-04-11 21:44:43 +00:00
|
|
|
continue;
|
|
|
|
}
|
2003-08-05 15:04:54 +00:00
|
|
|
|
2006-04-11 21:44:43 +00:00
|
|
|
if ( cfg.hasKey( "X-KDE-ShowIfRunning" ) )
|
|
|
|
{
|
|
|
|
const QString app = cfg.readEntry( "X-KDE-ShowIfRunning" );
|
2007-02-01 15:39:05 +00:00
|
|
|
if ( QDBusConnection::sessionBus().interface()->isServiceRegistered( app ) )
|
2003-08-05 15:04:54 +00:00
|
|
|
continue;
|
2006-04-11 21:44:43 +00:00
|
|
|
}
|
2006-06-05 13:03:49 +00:00
|
|
|
if ( cfg.hasKey( "X-KDE-ShowIfDBusCall" ) )
|
2006-04-11 21:44:43 +00:00
|
|
|
{
|
2006-06-05 13:03:49 +00:00
|
|
|
QString calldata = cfg.readEntry( "X-KDE-ShowIfDBusCall" );
|
|
|
|
QStringList parts = calldata.split(' ');
|
|
|
|
const QString &app = parts.at(0);
|
|
|
|
const QString &obj = parts.at(1);
|
|
|
|
QString interface = parts.at(2);
|
|
|
|
QString method;
|
|
|
|
int pos = interface.lastIndexOf( QLatin1Char( '.' ) );
|
|
|
|
if ( pos != -1 ) {
|
|
|
|
method = interface.mid(pos + 1);
|
|
|
|
interface.truncate(pos);
|
2003-08-05 15:04:54 +00:00
|
|
|
}
|
|
|
|
|
2006-06-05 13:03:49 +00:00
|
|
|
//if ( !QDBus::sessionBus().busService()->nameHasOwner( app ) )
|
|
|
|
// continue; //app does not exist so cannot send call
|
|
|
|
|
2006-07-02 18:31:00 +00:00
|
|
|
QDBusMessage reply = QDBusInterface( app, obj, interface ).
|
2006-06-05 13:03:49 +00:00
|
|
|
call( method, m_lstPopupURLs.toStringList() );
|
2006-08-21 20:18:49 +00:00
|
|
|
if ( reply.arguments().count() < 1 || reply.arguments().at(0).type() != QVariant::Bool || !reply.arguments().at(0).toBool() )
|
2005-01-26 23:57:41 +00:00
|
|
|
continue;
|
2004-09-23 12:59:03 +00:00
|
|
|
|
2006-04-11 21:44:43 +00:00
|
|
|
}
|
|
|
|
if ( cfg.hasKey( "X-KDE-Protocol" ) )
|
|
|
|
{
|
|
|
|
const QString protocol = cfg.readEntry( "X-KDE-Protocol" );
|
|
|
|
if ( protocol != urlForServiceMenu.protocol() )
|
|
|
|
continue;
|
|
|
|
}
|
2006-05-24 16:32:18 +00:00
|
|
|
else if ( cfg.hasKey( "X-KDE-Protocols" ) )
|
|
|
|
{
|
|
|
|
const QStringList protocols = cfg.readEntry( "X-KDE-Protocols" ).split( ',' );
|
|
|
|
if ( !protocols.contains( urlForServiceMenu.protocol() ) )
|
|
|
|
continue;
|
|
|
|
}
|
2006-04-11 21:44:43 +00:00
|
|
|
else if ( urlForServiceMenu.protocol() == "trash" || urlForServiceMenu.url().startsWith( "system:/trash" ) )
|
|
|
|
{
|
2006-06-19 01:43:22 +00:00
|
|
|
// Require servicemenus for the trash to ask for protocol=trash explicitly.
|
2006-04-11 21:44:43 +00:00
|
|
|
// Trashed files aren't supposed to be available for actions.
|
|
|
|
// One might want a servicemenu for trash.desktop itself though.
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( cfg.hasKey( "X-KDE-Require" ) )
|
|
|
|
{
|
|
|
|
const QStringList capabilities = cfg.readEntry( "X-KDE-Require" , QStringList() );
|
|
|
|
if ( capabilities.contains( "Write" ) && !sWriting )
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if ( (cfg.hasKey( "Actions" ) || cfg.hasKey( "X-KDE-GetActionMenu") ) && cfg.hasKey( "ServiceTypes" ) )
|
|
|
|
{
|
|
|
|
const QStringList types = cfg.readEntry( "ServiceTypes" , QStringList() );
|
|
|
|
const QStringList excludeTypes = cfg.readEntry( "ExcludeServiceTypes" , QStringList() );
|
|
|
|
bool ok = false;
|
|
|
|
|
|
|
|
// check for exact matches or a typeglob'd mimetype if we have a mimetype
|
|
|
|
for (QStringList::ConstIterator it = types.begin();
|
|
|
|
it != types.end() && !ok;
|
|
|
|
++it)
|
2003-08-05 15:04:54 +00:00
|
|
|
{
|
2006-04-11 21:44:43 +00:00
|
|
|
// 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*/)
|
2003-08-05 15:04:54 +00:00
|
|
|
{
|
2006-04-11 21:44:43 +00:00
|
|
|
checkTheMimetypes = true;
|
|
|
|
}
|
2003-08-05 15:04:54 +00:00
|
|
|
|
2006-04-11 21:44:43 +00:00
|
|
|
// next, do we match all files?
|
|
|
|
if (!ok &&
|
|
|
|
!isDirectory &&
|
|
|
|
*it == "all/allfiles")
|
|
|
|
{
|
|
|
|
checkTheMimetypes = true;
|
|
|
|
}
|
2003-08-05 15:04:54 +00:00
|
|
|
|
2006-04-11 21:44:43 +00:00
|
|
|
// if we have a mimetype, see if we have an exact or a type globbed match
|
|
|
|
if (!ok &&
|
|
|
|
(!m_sMimeType.isEmpty() &&
|
|
|
|
*it == m_sMimeType) ||
|
|
|
|
(!mimeGroup.isEmpty() &&
|
|
|
|
((*it).right(1) == "*" &&
|
|
|
|
(*it).left((*it).indexOf('/')) == mimeGroup)))
|
|
|
|
{
|
|
|
|
checkTheMimetypes = true;
|
|
|
|
}
|
2004-11-25 07:02:45 +00:00
|
|
|
|
2006-04-11 21:44:43 +00:00
|
|
|
if (checkTheMimetypes)
|
|
|
|
{
|
|
|
|
ok = true;
|
|
|
|
for (QStringList::ConstIterator itex = excludeTypes.begin(); itex != excludeTypes.end(); ++itex)
|
2003-08-05 15:04:54 +00:00
|
|
|
{
|
2006-04-11 21:44:43 +00:00
|
|
|
if( ((*itex).right(1) == "*" && (*itex).left((*itex).indexOf('/')) == mimeGroup) ||
|
|
|
|
((*itex) == m_sMimeType) )
|
2004-04-08 11:01:13 +00:00
|
|
|
{
|
2006-04-11 21:44:43 +00:00
|
|
|
ok = false;
|
|
|
|
break;
|
2004-04-08 11:01:13 +00:00
|
|
|
}
|
2003-08-05 15:04:54 +00:00
|
|
|
}
|
|
|
|
}
|
2006-04-11 21:44:43 +00:00
|
|
|
}
|
2003-08-05 15:04:54 +00:00
|
|
|
|
2006-04-11 21:44:43 +00:00
|
|
|
if ( ok )
|
|
|
|
{
|
|
|
|
const QString priority = cfg.readEntry("X-KDE-Priority");
|
|
|
|
const QString submenuName = cfg.readEntry( "X-KDE-Submenu" );
|
2005-06-03 23:18:33 +00:00
|
|
|
|
2006-04-11 21:44:43 +00:00
|
|
|
ServiceList* list = s.selectList( priority, submenuName );
|
2007-03-26 08:24:06 +00:00
|
|
|
(*list) += KDesktopFileActions::userDefinedServices( *eIt, desktopFile, url.isLocalFile(), m_lstPopupURLs );
|
2003-08-05 15:04:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2003-07-28 22:06:29 +00:00
|
|
|
|
2006-05-22 07:59:05 +00:00
|
|
|
KService::List offers;
|
2003-07-28 22:06:29 +00:00
|
|
|
|
2005-10-03 10:21:33 +00:00
|
|
|
if (KAuthorized::authorizeKAction("openwith"))
|
2003-07-28 22:06:29 +00:00
|
|
|
{
|
2006-09-15 04:09:35 +00:00
|
|
|
QString constraint = "DesktopEntryName != 'kfmclient' and DesktopEntryName != 'kfmclient_dir' and DesktopEntryName != 'kfmclient_html'";
|
2005-01-26 23:57:41 +00:00
|
|
|
QString subConstraint = " and '%1' in ServiceTypes";
|
|
|
|
|
|
|
|
QStringList::ConstIterator it = mimeTypeList.begin();
|
|
|
|
QStringList::ConstIterator end = mimeTypeList.end();
|
|
|
|
Q_ASSERT( it != end );
|
|
|
|
QString first = *it;
|
|
|
|
++it;
|
|
|
|
while ( it != end ) {
|
|
|
|
constraint += subConstraint.arg( *it );
|
|
|
|
++it;
|
|
|
|
}
|
2004-12-10 21:35:06 +00:00
|
|
|
|
2006-09-15 04:09:35 +00:00
|
|
|
offers = KMimeTypeTrader::self()->query( first, "Application", constraint );
|
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();
|
2004-09-24 09:20:59 +00:00
|
|
|
// "Open With..." for folders is really not very useful, especially for remote folders.
|
2004-11-02 12:45:38 +00:00
|
|
|
// (media:/something, or trash:/, or ftp://...)
|
2004-09-24 09:20:59 +00:00
|
|
|
if ( !isDirectory || isLocal )
|
2003-07-28 22:06:29 +00:00
|
|
|
{
|
2004-09-06 18:40:43 +00:00
|
|
|
if ( hasAction() )
|
2005-07-28 14:59:42 +00:00
|
|
|
KonqXMLGUIClient::addSeparator();
|
2004-09-06 18:40:43 +00:00
|
|
|
|
2003-08-31 13:38:31 +00:00
|
|
|
if ( !offers.isEmpty() )
|
|
|
|
{
|
|
|
|
// First block, app and preview offers
|
|
|
|
id = 1;
|
1999-12-18 20:30:37 +00:00
|
|
|
|
2005-09-17 13:40:40 +00:00
|
|
|
QDomElement menu = domElement();
|
2003-01-12 16:30:51 +00:00
|
|
|
|
2003-08-31 13:38:31 +00:00
|
|
|
if ( offers.count() > 1 ) // submenu 'open with'
|
|
|
|
{
|
2005-09-17 13:40:40 +00:00
|
|
|
menu = domDocument().createElement( "menu" );
|
2003-08-31 13:38:31 +00:00
|
|
|
menu.setAttribute( "name", "openwith submenu" );
|
2005-09-17 13:40:40 +00:00
|
|
|
domElement().appendChild( menu );
|
|
|
|
QDomElement text = domDocument().createElement( "text" );
|
2003-08-31 13:38:31 +00:00
|
|
|
menu.appendChild( text );
|
2005-09-17 13:40:40 +00:00
|
|
|
text.appendChild( domDocument().createTextNode( i18n("&Open With") ) );
|
2003-08-31 13:38:31 +00:00
|
|
|
}
|
1999-04-27 09:04:36 +00:00
|
|
|
|
2006-05-22 07:59:05 +00:00
|
|
|
KService::List::ConstIterator it = offers.begin();
|
2003-08-31 13:38:31 +00:00
|
|
|
for( ; it != offers.end(); it++ )
|
|
|
|
{
|
2006-06-13 18:15:17 +00:00
|
|
|
KService::Ptr service = (*it);
|
2006-10-10 11:14:59 +00:00
|
|
|
|
|
|
|
// Skip OnlyShowIn=Foo and NotShowIn=KDE entries,
|
|
|
|
// 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.
|
|
|
|
const QString onlyShowIn = service->property("OnlyShowIn", QVariant::String).toString();
|
|
|
|
if ( !onlyShowIn.isEmpty() ) {
|
2007-04-05 14:23:22 +00:00
|
|
|
const QStringList aList = onlyShowIn.split(';', QString::SkipEmptyParts);
|
2006-10-10 11:14:59 +00:00
|
|
|
if (!aList.contains("KDE"))
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
const QString notShowIn = service->property("NotShowIn", QVariant::String).toString();
|
|
|
|
if ( !notShowIn.isEmpty() ) {
|
2007-04-05 14:23:22 +00:00
|
|
|
const QStringList aList = notShowIn.split(';', QString::SkipEmptyParts);
|
2006-10-10 11:14:59 +00:00
|
|
|
if (aList.contains("KDE"))
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2005-09-14 12:57:24 +00:00
|
|
|
|
2005-12-27 09:23:21 +00:00
|
|
|
QByteArray nam;
|
2003-08-31 13:38:31 +00:00
|
|
|
nam.setNum( id );
|
2007-09-24 19:51:29 +00:00
|
|
|
nam.prepend( "appservice_" );
|
2000-04-08 20:31:49 +00:00
|
|
|
|
2006-06-13 18:15:17 +00:00
|
|
|
QString actionName( service->name().replace( "&", "&&" ) );
|
2005-09-17 13:40:40 +00:00
|
|
|
if ( menu == domElement() ) // no submenu -> prefix single offer
|
2006-04-10 11:57:13 +00:00
|
|
|
actionName = i18n( "Open with %1" , actionName );
|
2005-06-06 17:33:25 +00:00
|
|
|
|
2007-09-24 19:51:29 +00:00
|
|
|
act = m_ownActions.addAction( nam );
|
2007-01-08 22:39:24 +00:00
|
|
|
act->setIcon( KIcon( service->icon() ) );
|
|
|
|
act->setText( actionName );
|
2006-04-02 06:34:44 +00:00
|
|
|
connect(act, SIGNAL(triggered()), this, SLOT(slotRunService()));
|
2007-09-24 19:51:29 +00:00
|
|
|
KonqXMLGUIClient::addAction( nam.constData(), 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
|
|
|
|
2005-06-06 20:14:34 +00:00
|
|
|
QString openWithActionName;
|
2005-09-17 13:40:40 +00:00
|
|
|
if ( menu != domElement() ) // submenu
|
2003-08-31 13:38:31 +00:00
|
|
|
{
|
2005-07-28 14:59:42 +00:00
|
|
|
KonqXMLGUIClient::addSeparator( menu );
|
2005-06-06 20:14:34 +00:00
|
|
|
openWithActionName = i18n( "&Other..." );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
openWithActionName = i18n( "&Open With..." );
|
2003-08-31 13:38:31 +00:00
|
|
|
}
|
2007-01-08 22:39:24 +00:00
|
|
|
QAction *openWithAct = m_ownActions.addAction( "openwith" );
|
|
|
|
openWithAct->setText( openWithActionName );
|
2006-04-02 06:34:44 +00:00
|
|
|
connect(openWithAct, SIGNAL(triggered()), this, SLOT(slotPopupOpenWith()));
|
2007-01-08 22:39:24 +00:00
|
|
|
KonqXMLGUIClient::addAction( "openwith", menu );
|
2003-08-31 13:38:31 +00:00
|
|
|
}
|
|
|
|
else // no app offers -> Open With...
|
2003-08-05 15:04:54 +00:00
|
|
|
{
|
2007-01-08 22:39:24 +00:00
|
|
|
act = m_ownActions.addAction( "openwith" );
|
|
|
|
act->setText( i18n( "&Open With..." ) );
|
2006-04-02 06:34:44 +00:00
|
|
|
connect(act, SIGNAL(triggered()), this, SLOT(slotPopupOpenWith()));
|
2007-01-08 22:39:24 +00:00
|
|
|
KonqXMLGUIClient::addAction( "openwith" );
|
2003-08-05 15:04:54 +00:00
|
|
|
}
|
2000-04-08 20:31:49 +00:00
|
|
|
|
2003-08-31 13:38:31 +00:00
|
|
|
}
|
2005-07-28 14:59:42 +00:00
|
|
|
KonqXMLGUIClient::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
|
2005-09-17 13:40:40 +00:00
|
|
|
QDomElement actionMenu = domElement();
|
2003-12-21 10:01:10 +00:00
|
|
|
int userItemCount = 0;
|
2004-09-06 22:22:05 +00:00
|
|
|
if (s.user.count() + s.userSubmenus.count() +
|
|
|
|
s.userPriority.count() + s.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
|
2005-09-17 13:40:40 +00:00
|
|
|
actionMenu = domDocument().createElement( "menu" );
|
2003-12-21 10:01:10 +00:00
|
|
|
actionMenu.setAttribute( "name", "actions submenu" );
|
2005-09-17 13:40:40 +00:00
|
|
|
domElement().appendChild( actionMenu );
|
|
|
|
QDomElement text = domDocument().createElement( "text" );
|
2003-12-21 10:01:10 +00:00
|
|
|
actionMenu.appendChild( text );
|
2005-09-17 13:40:40 +00:00
|
|
|
text.appendChild( domDocument().createTextNode( i18n("Ac&tions") ) );
|
2003-12-21 10:01:10 +00:00
|
|
|
}
|
2003-09-09 19:13:25 +00:00
|
|
|
|
2004-09-06 22:22:05 +00:00
|
|
|
userItemCount += insertServicesSubmenus(s.userPrioritySubmenus, actionMenu, false);
|
|
|
|
userItemCount += insertServices(s.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 &&
|
2004-09-06 22:22:05 +00:00
|
|
|
(s.user.count() > 0 ||
|
|
|
|
s.userSubmenus.count() > 0 ||
|
|
|
|
s.builtin.count() > 0) &&
|
2005-10-10 10:21:04 +00:00
|
|
|
actionMenu.lastChild().toElement().tagName().toLower() != "separator")
|
2003-12-21 10:01:10 +00:00
|
|
|
{
|
2005-09-17 13:40:40 +00:00
|
|
|
QDomElement separator = domDocument().createElement( "separator" );
|
2003-12-21 10:01:10 +00:00
|
|
|
actionMenu.appendChild(separator);
|
|
|
|
}
|
2005-09-17 13:40:40 +00:00
|
|
|
QDomElement element = domElement( );
|
2004-09-06 22:22:05 +00:00
|
|
|
userItemCount += insertServicesSubmenus(s.userSubmenus, actionMenu, false);
|
|
|
|
userItemCount += insertServices(s.user, actionMenu, false);
|
2005-09-17 13:40:40 +00:00
|
|
|
userItemCount += insertServices(s.builtin, element, true);
|
2000-03-19 00:44:31 +00:00
|
|
|
|
2005-09-17 13:40:40 +00:00
|
|
|
userItemCount += insertServicesSubmenus(s.userToplevelSubmenus, element, false);
|
|
|
|
userItemCount += insertServices(s.userToplevel, element, false);
|
2003-05-19 17:24:46 +00:00
|
|
|
|
2004-09-24 08:04:33 +00:00
|
|
|
if ( userItemCount > 0 )
|
2003-12-21 10:01:10 +00:00
|
|
|
{
|
2004-09-06 18:40:43 +00:00
|
|
|
addPendingSeparator();
|
2003-12-21 10:01:10 +00:00
|
|
|
}
|
2003-05-19 17:24:46 +00:00
|
|
|
|
2004-11-02 12:45:38 +00:00
|
|
|
if ( !isCurrentTrash && !isIntoTrash && !mediaFiles && sReading )
|
2004-09-24 08:04:33 +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
|
|
|
{
|
2007-01-08 22:39:24 +00:00
|
|
|
act = m_ownActions.addAction( "properties" );
|
|
|
|
act->setText( i18n( "&Properties" ) );
|
2006-04-02 06:34:44 +00:00
|
|
|
connect(act, SIGNAL(triggered()), this, SLOT(slotPopupProperties()));
|
2007-01-08 22:39:24 +00:00
|
|
|
KonqXMLGUIClient::addAction( "properties" );
|
2003-08-05 15:04:54 +00:00
|
|
|
}
|
2000-04-01 17:09:44 +00:00
|
|
|
|
2005-09-17 13:40:40 +00:00
|
|
|
while ( !domElement().lastChild().isNull() &&
|
2005-10-10 10:21:04 +00:00
|
|
|
domElement().lastChild().toElement().tagName().toLower() == "separator" )
|
2005-09-17 13:40:40 +00:00
|
|
|
domElement().removeChild( domElement().lastChild() );
|
2000-07-13 11:11:35 +00:00
|
|
|
|
2004-09-24 09:20:59 +00:00
|
|
|
if ( isDirectory && isLocal )
|
2003-08-05 15:04:54 +00:00
|
|
|
{
|
2004-09-24 08:04:33 +00:00
|
|
|
if ( KFileShare::authorization() == KFileShare::Authorized )
|
2003-08-05 15:04:54 +00:00
|
|
|
{
|
2005-07-28 14:59:42 +00:00
|
|
|
KonqXMLGUIClient::addSeparator();
|
2007-01-08 22:39:24 +00:00
|
|
|
act = m_ownActions.addAction( "sharefile" );
|
|
|
|
act->setText( i18n("Share") );
|
2006-04-02 06:34:44 +00:00
|
|
|
connect(act, SIGNAL(triggered()), this, SLOT(slotOpenShareFileDialog()));
|
2007-01-08 22:39:24 +00:00
|
|
|
KonqXMLGUIClient::addAction( "sharefile" );
|
2003-08-05 15:04:54 +00:00
|
|
|
}
|
|
|
|
}
|
2002-04-16 17:06:27 +00:00
|
|
|
|
2005-07-28 14:59:42 +00:00
|
|
|
KonqXMLGUIClient::addMerge( 0 );
|
2007-08-20 21:33:48 +00:00
|
|
|
//kDebug() << domDocument().toString();
|
2003-08-05 15:04:54 +00:00
|
|
|
|
|
|
|
m_factory->addClient( this );
|
1999-04-27 09:04:36 +00:00
|
|
|
}
|
|
|
|
|
2002-04-16 17:06:27 +00:00
|
|
|
void KonqPopupMenu::slotOpenShareFileDialog()
|
|
|
|
{
|
2006-12-26 10:27:29 +00:00
|
|
|
KPropertiesDialog* dlg = new KPropertiesDialog( m_lstItems, d->m_parentWidget );
|
2002-06-17 10:52:42 +00:00
|
|
|
dlg->showFileSharingPage();
|
2006-12-26 10:27:29 +00:00
|
|
|
dlg->exec();
|
2002-04-16 17:06:27 +00:00
|
|
|
}
|
|
|
|
|
1999-04-27 09:04:36 +00:00
|
|
|
KonqPopupMenu::~KonqPopupMenu()
|
|
|
|
{
|
2000-04-01 17:09:44 +00:00
|
|
|
delete m_factory;
|
|
|
|
delete m_builder;
|
2001-12-12 14:10:22 +00:00
|
|
|
delete d;
|
2007-08-03 06:40:12 +00:00
|
|
|
//kDebug(1203) << "~KonqPopupMenu leave";
|
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()
|
|
|
|
{
|
2006-01-24 08:32:09 +00:00
|
|
|
KUrl::List::ConstIterator it = m_lstPopupURLs.begin();
|
1999-04-27 09:04:36 +00:00
|
|
|
for ( ; it != m_lstPopupURLs.end(); it++ )
|
2005-10-03 10:50:16 +00:00
|
|
|
(void) new KRun(*it,this);
|
1999-04-27 09:04:36 +00:00
|
|
|
}
|
|
|
|
|
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()
|
|
|
|
{
|
2006-11-23 22:21:46 +00:00
|
|
|
KonqOperations::emptyTrash( d->m_parentWidget );
|
1999-04-27 09:04:36 +00:00
|
|
|
}
|
|
|
|
|
2004-09-07 18:25:28 +00:00
|
|
|
void KonqPopupMenu::slotPopupRestoreTrashedItems()
|
|
|
|
{
|
2006-11-23 22:21:46 +00:00
|
|
|
KonqOperations::restoreTrashedItems( m_lstPopupURLs, d->m_parentWidget );
|
2004-09-07 18:25:28 +00:00
|
|
|
}
|
|
|
|
|
1999-04-27 09:04:36 +00:00
|
|
|
void KonqPopupMenu::slotPopupOpenWith()
|
|
|
|
{
|
2006-11-23 22:21:46 +00:00
|
|
|
KRun::displayOpenWithDialog( m_lstPopupURLs, d->m_parentWidget );
|
1999-04-27 09:04:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void KonqPopupMenu::slotPopupAddToBookmark()
|
|
|
|
{
|
2004-09-13 09:15:09 +00:00
|
|
|
KBookmarkGroup root;
|
2002-02-27 04:44:03 +00:00
|
|
|
if ( m_lstPopupURLs.count() == 1 ) {
|
2006-01-24 08:32:09 +00:00
|
|
|
KUrl url = m_lstPopupURLs.first();
|
2006-05-22 07:01:23 +00:00
|
|
|
QString title = d->m_urlTitle.isEmpty() ? url.prettyUrl() : d->m_urlTitle;
|
2007-09-03 07:53:52 +00:00
|
|
|
KBookmarkDialog dlg( m_pManager, this);
|
|
|
|
dlg.addBookmark( title, url.url());
|
2002-02-27 04:44:03 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-09-13 09:15:09 +00:00
|
|
|
root = m_pManager->root();
|
2006-01-24 08:32:09 +00:00
|
|
|
KUrl::List::ConstIterator it = m_lstPopupURLs.begin();
|
2002-02-27 04:44:03 +00:00
|
|
|
for ( ; it != m_lstPopupURLs.end(); it++ )
|
2007-08-13 09:27:01 +00:00
|
|
|
root.addBookmark( (*it).prettyUrl(), (*it) );
|
2007-09-03 07:53:52 +00:00
|
|
|
m_pManager->emitChanged( root );
|
2002-02-27 04:44:03 +00:00
|
|
|
}
|
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
|
|
|
{
|
2006-03-23 17:19:24 +00:00
|
|
|
QByteArray senderName = sender()->objectName().toUtf8();
|
|
|
|
int id = senderName.mid( senderName.indexOf( '_' ) + 1 ).toInt();
|
2000-04-01 17:09:44 +00:00
|
|
|
|
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() )
|
|
|
|
{
|
2006-05-22 07:59:05 +00:00
|
|
|
KRun::run( **it, m_lstPopupURLs, topLevelWidget() );
|
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 ?
|
2007-03-26 08:24:06 +00:00
|
|
|
QMap<int,KDesktopFileActions::Service>::Iterator it2 = m_mapPopupServices.find( id );
|
2000-03-19 00:44:31 +00:00
|
|
|
if ( it2 != m_mapPopupServices.end() )
|
|
|
|
{
|
2007-03-26 08:24:06 +00:00
|
|
|
KDesktopFileActions::executeService( m_lstPopupURLs, it2.value() );
|
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()
|
|
|
|
{
|
2007-05-07 15:10:51 +00:00
|
|
|
KonqOperations::editMimeType( m_sMimeType, d->m_parentWidget );
|
1999-09-24 22:47:25 +00:00
|
|
|
}
|
|
|
|
|
1999-04-27 09:04:36 +00:00
|
|
|
void KonqPopupMenu::slotPopupProperties()
|
2004-09-24 07:56:05 +00:00
|
|
|
{
|
2006-12-26 10:27:29 +00:00
|
|
|
KPropertiesDialog::showDialog( m_lstItems, d->m_parentWidget );
|
1999-04-27 09:04:36 +00:00
|
|
|
}
|
|
|
|
|
2006-12-04 20:44:12 +00:00
|
|
|
QAction *KonqPopupMenu::action( const QDomElement &element ) const
|
2000-04-01 17:09:44 +00:00
|
|
|
{
|
2005-07-28 14:59:42 +00:00
|
|
|
QByteArray name = element.attribute( attrName ).toLatin1();
|
|
|
|
|
2006-12-04 20:44:12 +00:00
|
|
|
QAction *res = m_ownActions.action( name.data() );
|
2000-04-01 17:09:44 +00:00
|
|
|
|
|
|
|
if ( !res )
|
2005-07-28 14:59:42 +00:00
|
|
|
res = m_actions.action( name.data() );
|
2000-04-01 17:09:44 +00:00
|
|
|
|
2006-03-23 17:19:24 +00:00
|
|
|
if ( !res && m_pMenuNew && strcmp( name.data(), m_pMenuNew->objectName().toUtf8() ) == 0 )
|
2000-04-01 17:09:44 +00:00
|
|
|
return m_pMenuNew;
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
2004-09-24 08:04:33 +00:00
|
|
|
|
2001-05-01 10:04:44 +00:00
|
|
|
KActionCollection *KonqPopupMenu::actionCollection() const
|
|
|
|
{
|
2004-09-24 08:04:33 +00:00
|
|
|
return const_cast<KActionCollection *>( &m_ownActions );
|
2001-05-01 10:04:44 +00:00
|
|
|
}
|
|
|
|
|
2004-09-24 08:04:33 +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
|
|
|
}
|
2004-09-24 08:04:33 +00:00
|
|
|
|
2002-01-21 20:46:23 +00:00
|
|
|
KonqPopupMenu::ProtocolInfo KonqPopupMenu::protocolInfo() const
|
|
|
|
{
|
2004-09-24 08:04:33 +00:00
|
|
|
return m_info;
|
2002-01-21 20:46:23 +00:00
|
|
|
}
|
2000-04-01 17:09:44 +00:00
|
|
|
|
2004-09-24 08:04:33 +00:00
|
|
|
void KonqPopupMenu::addPlugins()
|
|
|
|
{
|
|
|
|
// search for Konq_PopupMenuPlugins inspired by simons kpropsdlg
|
|
|
|
//search for a plugin with the right protocol
|
2006-05-22 07:59:05 +00:00
|
|
|
KService::List plugin_offers;
|
2004-09-24 08:04:33 +00:00
|
|
|
unsigned int pluginCount = 0;
|
2006-07-16 14:13:23 +00:00
|
|
|
plugin_offers = KMimeTypeTrader::self()->query( m_sMimeType.isNull() ? QLatin1String( "all/all" ) : m_sMimeType, "KonqPopupMenu/Plugin" );
|
2004-09-24 08:04:33 +00:00
|
|
|
if ( plugin_offers.isEmpty() )
|
|
|
|
return; // no plugins installed do not bother about it
|
|
|
|
|
2006-05-22 07:59:05 +00:00
|
|
|
KService::List::ConstIterator iterator = plugin_offers.begin();
|
|
|
|
KService::List::ConstIterator end = plugin_offers.end();
|
2004-09-24 08:04:33 +00:00
|
|
|
|
|
|
|
addGroup( "plugins" );
|
|
|
|
// travers the offerlist
|
|
|
|
for(; iterator != end; ++iterator, ++pluginCount ) {
|
2007-08-03 06:40:12 +00:00
|
|
|
//kDebug() << (*iterator)->library();
|
2004-09-24 08:04:33 +00:00
|
|
|
KonqPopupMenuPlugin *plugin =
|
2005-10-04 08:49:51 +00:00
|
|
|
KLibLoader::createInstance<KonqPopupMenuPlugin>( QFile::encodeName( (*iterator)->library() ),
|
2006-05-08 13:33:51 +00:00
|
|
|
this );
|
2004-09-24 08:04:33 +00:00
|
|
|
if ( !plugin )
|
|
|
|
continue;
|
2006-05-11 19:40:14 +00:00
|
|
|
plugin->setObjectName( (*iterator)->name() );
|
2004-09-24 08:04:33 +00:00
|
|
|
QString pluginClientName = QString::fromLatin1( "Plugin%1" ).arg( pluginCount );
|
|
|
|
addMerge( pluginClientName );
|
|
|
|
plugin->domDocument().documentElement().setAttribute( "name", pluginClientName );
|
|
|
|
insertChildClient( plugin );
|
|
|
|
}
|
|
|
|
|
2004-09-24 09:20:59 +00:00
|
|
|
// ## Where is this used?
|
2004-09-24 08:04:33 +00:00
|
|
|
addMerge( "plugins" );
|
2000-04-01 17:09:44 +00:00
|
|
|
}
|
2004-09-06 18:40:43 +00:00
|
|
|
|
2006-01-24 08:32:09 +00:00
|
|
|
KUrl KonqPopupMenu::url() const // ### should be viewURL()
|
2004-09-24 08:04:33 +00:00
|
|
|
{
|
2001-10-30 18:09:01 +00:00
|
|
|
return m_sViewURL;
|
2000-04-01 17:09:44 +00:00
|
|
|
}
|
2004-09-06 18:40:43 +00:00
|
|
|
|
2004-09-24 08:04:33 +00:00
|
|
|
KFileItemList KonqPopupMenu::fileItemList() const
|
|
|
|
{
|
2001-10-30 18:09:01 +00:00
|
|
|
return m_lstItems;
|
2000-04-04 22:24:42 +00:00
|
|
|
}
|
2004-09-06 18:40:43 +00:00
|
|
|
|
2006-01-24 08:32:09 +00:00
|
|
|
KUrl::List KonqPopupMenu::popupURLList() const
|
2004-09-24 08:04:33 +00:00
|
|
|
{
|
2001-10-30 18:09:01 +00:00
|
|
|
return m_lstPopupURLs;
|
2000-04-09 09:41:40 +00:00
|
|
|
}
|
2004-09-06 18:40:43 +00:00
|
|
|
|
2001-10-30 18:09:01 +00:00
|
|
|
/**
|
2004-04-20 23:07:20 +00:00
|
|
|
Plugin
|
2001-10-30 18:09:01 +00:00
|
|
|
*/
|
2000-04-08 20:31:49 +00:00
|
|
|
|
2006-05-16 15:53:02 +00:00
|
|
|
KonqPopupMenuPlugin::KonqPopupMenuPlugin( KonqPopupMenu *parent )
|
2006-04-02 06:34:44 +00:00
|
|
|
: QObject( parent )
|
2004-09-24 08:04:33 +00:00
|
|
|
{
|
2000-04-01 17:09:44 +00:00
|
|
|
}
|
|
|
|
|
2004-09-24 08:04:33 +00:00
|
|
|
KonqPopupMenuPlugin::~KonqPopupMenuPlugin()
|
|
|
|
{
|
2001-10-30 18:09:01 +00:00
|
|
|
}
|
2004-09-24 08:04:33 +00:00
|
|
|
|
2000-07-27 09:23:48 +00:00
|
|
|
#include "konq_popupmenu.moc"
|