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
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 :
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 :
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
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 )
2004-09-24 08:04:33 +00:00
: QPopupMenu ( 0L , " konq_popupmenu " ) ,
2004-12-20 18:11:51 +00:00
m_actions ( actions ) , m_ownActions ( static_cast < QWidget * > ( 0 ) , " KonqPopupMenu::m_ownActions " ) ,
m_pMenuNew ( newMenu ) , m_sViewURL ( viewURL ) , m_lstItems ( items ) , m_pManager ( mgr )
1999-04-27 09:04:36 +00:00
{
2004-09-24 08:04:33 +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 ,
2004-04-20 23:07:20 +00:00
QWidget * parentWidget ,
2003-10-09 14:02:59 +00:00
bool showProperties )
2004-12-20 18:11:51 +00:00
: QPopupMenu ( parentWidget , " konq_popupmenu " ) , m_actions ( actions ) , m_ownActions ( static_cast < QWidget * > ( 0 ) , " KonqPopupMenu::m_ownActions " ) , 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
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 )
2004-12-20 18:11:51 +00:00
: QPopupMenu ( parentWidget , " konq_popupmenu " ) , m_actions ( actions ) , m_ownActions ( static_cast < QWidget * > ( 0 ) , " KonqPopupMenu::m_ownActions " ) , 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
{
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 )
{
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 ) ;
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 ;
2004-10-20 07:50:45 +00:00
bool sWriting = sDeleting & & m_lstItems . first ( ) - > isWritable ( ) ;
2003-08-05 15:04:54 +00:00
m_sMimeType = m_lstItems . first ( ) - > mimetype ( ) ;
2004-04-20 23:07:20 +00:00
QString mimeGroup = m_sMimeType . left ( m_sMimeType . find ( ' / ' ) ) ;
2003-08-05 15:04:54 +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 ;
bool isLocal = m_lstItems . first ( ) - > isLocalFile ( ) ;
bool isTrashLink = false ;
2003-08-05 15:04:54 +00:00
m_lstPopupURLs . clear ( ) ;
int id = 0 ;
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 ) ;
2004-12-10 21:35:06 +00:00
QStringList mimeTypeList ;
2003-08-05 15:04:54 +00:00
// Check whether all URLs are correct
for ( ; it . current ( ) ; + + it )
{
2004-12-31 14:19:48 +00:00
url = ( * it ) - > mostLocalURL ( isLocal ) ;
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 ( ) )
2004-04-20 23:07:20 +00:00
{
2003-08-05 15:04:54 +00:00
m_sMimeType = QString : : null ; // mimetypes are different => null
1999-08-04 10:50:58 +00:00
2004-04-20 23:07:20 +00:00
if ( mimeGroup ! = ( * it ) - > mimetype ( ) . left ( ( * it ) - > mimetype ( ) . find ( ' / ' ) ) )
mimeGroup = QString : : null ; // mimetype groups are different as well!
}
2004-12-10 21:35:06 +00:00
if ( mimeTypeList . findIndex ( ( * it ) - > mimetype ( ) ) = = - 1 )
mimeTypeList < < ( * it ) - > mimetype ( ) ;
2004-09-24 09:20:59 +00:00
if ( isLocal & & ! url . isLocalFile ( ) )
isLocal = false ;
2003-08-05 15:04:54 +00:00
if ( ! bTrashIncluded & &
2004-09-07 16:30:13 +00:00
( * it ) - > url ( ) . protocol ( ) = = " trash " & &
( * it ) - > url ( ) . path ( ) . length ( ) < = 1 )
2003-08-05 15:04:54 +00:00
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 )
2004-10-20 07:50:45 +00:00
sWriting = KProtocolInfo : : supportsWriting ( url ) & & ( * it ) - > isWritable ( ) ;
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 ) ;
2004-11-02 12:45:38 +00:00
if ( ( * it ) - > mimetype ( ) . startsWith ( " media/ " ) )
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 )
{
2005-01-18 10:10:23 +00:00
KURL firstPopupURL ( m_lstItems . first ( ) - > url ( ) ) ;
2003-08-05 15:04:54 +00:00
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 */ ) ;
2005-01-18 10:10:23 +00:00
if ( isLocal & & m_sMimeType = = " application/x-desktop " ) {
KSimpleConfig cfg ( firstPopupURL . path ( ) , true ) ;
cfg . setDesktopGroup ( ) ;
isTrashLink = ( cfg . readEntry ( " Type " ) = = " Link " & & cfg . readEntry ( " URL " ) = = " trash:/ " ) ;
if ( isTrashLink ) {
sDeleting = false ;
}
}
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-05-05 19:36:50 +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 ;
2004-11-10 13:43:14 +00:00
bool isIntoTrash = url . protocol ( ) = = " trash " & & ! isCurrentTrash ; // trashed file, not trash:/ itself
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
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
2005-01-18 10:10:23 +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.
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 " ) ;
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 )
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 ) ;
addAction ( m_pMenuNew ) ;
2003-10-09 14:02:59 +00:00
addSeparator ( ) ;
}
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
{
2004-11-10 13:43:14 +00:00
KAction * actNewDir = new KAction ( i18n ( " Create &Folder... " ) , " folder_new " , 0 , this , SLOT ( slotPopupNewDir ( ) ) , & m_ownActions , " newdir " ) ;
addAction ( actNewDir ) ;
2003-08-05 15:04:54 +00:00
addSeparator ( ) ;
}
}
2004-11-10 13:43:14 +00:00
} else if ( isIntoTrash ) {
// Trashed item, offer restoring
act = new KAction ( i18n ( " &Restore " ) , 0 , this , SLOT ( slotPopupRestoreTrashedItems ( ) ) , & m_ownActions , " restore " ) ;
addAction ( act ) ;
}
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 )
addAction ( " up " ) ;
addAction ( " back " ) ;
addAction ( " forward " ) ;
if ( d - > m_itemFlags & KParts : : BrowserExtension : : ShowReload )
addAction ( " reload " ) ;
addSeparator ( ) ;
}
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 )
{
addAction ( actNewWindow ) ;
addSeparator ( ) ;
}
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 ) {
addAction ( " cut " ) ;
2003-08-05 15:04:54 +00:00
}
2004-11-10 13:43:14 +00:00
addAction ( " copy " ) ;
}
2003-08-05 15:04:54 +00:00
2004-11-10 13:43:14 +00:00
if ( S_ISDIR ( mode ) & & sWriting ) {
if ( currentDir )
addAction ( " paste " ) ;
else
addAction ( " pasteto " ) ;
}
if ( ! currentDir )
{
2005-01-18 10:10:23 +00:00
if ( m_lstItems . count ( ) = = 1 & & sMoving )
2004-11-10 13:43:14 +00:00
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 ;
else if ( KApplication : : keyboardMouseState ( ) & Qt : : ShiftButton ) {
addTrash = false ;
addDel = true ;
}
2005-01-23 09:31:31 +00:00
else {
KConfigGroup configGroup ( kapp - > config ( ) , " KDE " ) ;
if ( configGroup . readBoolEntry ( " 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 )
addAction ( " trash " ) ;
if ( addDel )
addAction ( " del " ) ;
2003-08-05 15:04:54 +00:00
}
}
2004-11-10 13:43:14 +00:00
if ( isCurrentTrash )
{
2005-04-20 08:18:54 +00:00
act = new KAction ( i18n ( " &Empty Trash Bin " ) , " emptytrash " , 0 , this , SLOT ( slotPopupEmptyTrashBin ( ) ) , & m_ownActions , " empytrash " ) ;
2004-11-10 13:43:14 +00:00
addAction ( act ) ;
}
addGroup ( " editactions " ) ;
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
2004-09-06 22:22:05 +00:00
PopupServices s ;
2005-01-26 23:57:41 +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
2004-09-06 22:22:05 +00:00
s . builtin = KDEDesktopMimeType : : builtinServices ( m_lstItems . first ( ) - > url ( ) ) ;
const QString path = m_lstItems . first ( ) - > url ( ) . path ( ) ;
KSimpleConfig cfg ( path , true ) ;
cfg . setDesktopGroup ( ) ;
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 ) ;
( * list ) = KDEDesktopMimeType : : userDefinedServices ( path , cfg , 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 )
{
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 ) )
{
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 ) ;
2004-09-06 22:23:10 +00:00
( * list ) + = KDEDesktopMimeType : : userDefinedServices ( dotDirectoryFile , cfg , 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
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 " ) )
{
2005-01-18 10:10:23 +00:00
const QString app = cfg . readEntry ( " X-KDE-ShowIfRunning " ) ;
2003-08-28 16:15:50 +00:00
if ( ! kapp - > dcopClient ( ) - > isApplicationRegistered ( app . utf8 ( ) ) )
continue ;
}
2005-05-05 19:36:50 +00:00
if ( cfg . hasKey ( " X-KDE-ShowIfDcopCall " ) )
{
QString dcopcall = cfg . readEntry ( " X-KDE-ShowIfDcopCall " ) ;
const QCString app = dcopcall . section ( ' ' , 0 , 0 ) . utf8 ( ) ;
//if( !kapp->dcopClient()->isApplicationRegistered( app ))
// continue; //app does not exist so cannot send call
QByteArray dataToSend ;
QDataStream dataStream ( dataToSend , IO_WriteOnly ) ;
dataStream < < m_lstPopupURLs ;
QCString replyType ;
QByteArray replyData ;
QCString object = dcopcall . section ( ' ' , 1 , - 2 ) . utf8 ( ) ;
QString function = dcopcall . section ( ' ' , - 1 ) ;
if ( ! function . endsWith ( " (KURL::List) " ) ) {
kdWarning ( ) < < " Desktop file " < < * eIt < < " contains an invalid X-KDE-ShowIfDcopCall - the function must take the exact parameter (KURL::List) and must be specified. " < < endl ;
continue ; //Be safe.
}
if ( ! kapp - > dcopClient ( ) - > call ( app , object ,
function . utf8 ( ) ,
dataToSend , replyType , replyData , true , 1000 ) )
continue ;
if ( replyType ! = " bool " | | ! replyData [ 0 ] )
continue ;
}
2004-09-23 12:59:03 +00:00
if ( cfg . hasKey ( " X-KDE-Protocol " ) )
{
const QString protocol = cfg . readEntry ( " X-KDE-Protocol " ) ;
2005-01-26 23:57:41 +00:00
if ( protocol ! = urlForServiceMenu . protocol ( ) )
2004-09-23 12:59:03 +00:00
continue ;
}
2005-01-26 23:57:41 +00:00
else if ( urlForServiceMenu . protocol ( ) = = " trash " )
{
// Require servicemenus for the trash to ask for protocol=trash explicitely.
// Trashed files aren't supposed to be available for actions.
// One might want a servicemenu for trash.desktop itself though.
continue ;
}
2004-09-23 12:59:03 +00:00
if ( cfg . hasKey ( " X-KDE-Require " ) )
{
const QStringList capabilities = cfg . readListEntry ( " X-KDE-Require " ) ;
if ( capabilities . contains ( " Write " ) & & ! sWriting )
continue ;
}
2005-05-06 19:56:08 +00:00
if ( ( cfg . hasKey ( " Actions " ) | | cfg . hasKey ( " X-KDE-GetActionMenu " ) ) & & cfg . hasKey ( " ServiceTypes " ) )
2003-08-05 15:04:54 +00:00
{
2005-01-18 10:10:23 +00:00
const QStringList types = cfg . readListEntry ( " ServiceTypes " ) ;
const QStringList excludeTypes = cfg . readListEntry ( " ExcludeServiceTypes " ) ;
2003-08-05 15:04:54 +00:00
bool ok = false ;
// check for exact matches or a typeglob'd mimetype if we have a mimetype
2005-01-18 10:10:23 +00:00
for ( QStringList : : ConstIterator it = types . begin ( ) ;
2004-04-20 23:07:20 +00:00
it ! = types . end ( ) & & ! ok ;
2004-04-08 11:42:00 +00:00
+ + it )
2003-08-05 15:04:54 +00:00
{
// first check if we have an all mimetype
2004-11-25 07:02:45 +00:00
bool checkTheMimetypes = false ;
2003-08-05 15:04:54 +00:00
if ( * it = = " all/all " | |
* it = = " allfiles " /*compat with KDE up to 3.0.3*/ )
{
2004-11-25 07:02:45 +00:00
checkTheMimetypes = true ;
2003-08-05 15:04:54 +00:00
}
// next, do we match all files?
2004-04-08 11:01:13 +00:00
if ( ! ok & &
2004-09-24 09:20:59 +00:00
! isDirectory & &
2004-04-08 11:01:13 +00:00
* it = = " all/allfiles " )
2003-08-05 15:04:54 +00:00
{
2004-11-25 07:02:45 +00:00
checkTheMimetypes = true ;
2003-08-05 15:04:54 +00:00
}
2004-04-20 23:07:20 +00:00
// if we have a mimetype, see if we have an exact or a type globbed match
2004-04-08 11:01:13 +00:00
if ( ! ok & &
2004-04-20 23:07:20 +00:00
( ! m_sMimeType . isEmpty ( ) & &
* it = = m_sMimeType ) | |
( ! mimeGroup . isEmpty ( ) & &
2003-08-05 15:04:54 +00:00
( ( * it ) . right ( 1 ) = = " * " & &
( * it ) . left ( ( * it ) . find ( ' / ' ) ) = = mimeGroup ) ) )
2004-11-25 07:02:45 +00:00
{
checkTheMimetypes = true ;
}
if ( checkTheMimetypes )
2003-08-05 15:04:54 +00:00
{
2004-04-08 11:01:13 +00:00
ok = true ;
2005-01-18 10:10:23 +00:00
for ( QStringList : : ConstIterator itex = excludeTypes . begin ( ) ; itex ! = excludeTypes . end ( ) ; + + itex )
2004-04-08 11:01:13 +00:00
{
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 )
{
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-05-06 19:56:08 +00:00
2004-09-06 22:22:05 +00:00
ServiceList * list = s . selectList ( priority , submenuName ) ;
2005-05-06 19:56:08 +00:00
( * list ) + = KDEDesktopMimeType : : userDefinedServices ( * dIt + * eIt , cfg , url . isLocalFile ( ) , m_lstPopupURLs ) ;
}
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
{
2005-01-26 23:57:41 +00:00
QString constraint = " Type == 'Application' and DesktopEntryName != 'kfmclient' and DesktopEntryName != 'kfmclient_dir' and DesktopEntryName != 'kfmclient_html' " ;
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
offers = KTrader : : self ( ) - > query ( first , 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 ( ) )
addSeparator ( ) ;
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
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
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
}
2004-09-24 09:20:59 +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 ;
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
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
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 ) & &
2003-12-21 10:01:10 +00:00
actionMenu . lastChild ( ) . toElement ( ) . tagName ( ) . lower ( ) ! = " separator " )
{
QDomElement separator = m_doc . createElement ( " separator " ) ;
actionMenu . appendChild ( separator ) ;
}
2003-08-05 15:04:54 +00:00
2004-09-06 22:22:05 +00:00
userItemCount + = insertServicesSubmenus ( s . userSubmenus , actionMenu , false ) ;
userItemCount + = insertServices ( s . user , actionMenu , false ) ;
userItemCount + = insertServices ( s . builtin , m_menuElement , true ) ;
2000-03-19 00:44:31 +00:00
2004-09-06 22:22:05 +00:00
userItemCount + = insertServicesSubmenus ( s . userToplevelSubmenus , m_menuElement , false ) ;
userItemCount + = insertServices ( s . userToplevel , m_menuElement , 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
{
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
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
{
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
2003-08-05 15:04:54 +00:00
addMerge ( 0 ) ;
2004-09-06 18:40:43 +00:00
//kdDebug() << k_funcinfo << domDocument().toString() << endl;
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 ( )
{
2004-09-24 07:56:05 +00:00
KPropertiesDialog * dlg = showPropertiesDialog ( ) ;
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 ;
2004-09-24 07:56:05 +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
}
2004-09-07 18:25:28 +00:00
void KonqPopupMenu : : slotPopupRestoreTrashedItems ( )
{
KonqOperations : : restoreTrashedItems ( m_lstPopupURLs ) ;
}
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 ( )
{
2004-09-13 09:15:09 +00:00
KBookmarkGroup 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-09-13 09:15:09 +00:00
root = m_pManager - > addBookmarkDialog ( url . prettyURL ( ) , title ) ;
2002-02-27 04:44:03 +00:00
}
else
{
2004-09-13 09:15:09 +00:00
root = m_pManager - > root ( ) ;
2002-02-27 04:44:03 +00:00
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 ( )
{
2004-09-24 08:04:33 +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 ( )
2004-09-24 07:56:05 +00:00
{
( void ) showPropertiesDialog ( ) ;
}
KPropertiesDialog * KonqPopupMenu : : showPropertiesDialog ( )
1999-04-27 09:04:36 +00:00
{
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
2004-09-24 07:56:05 +00:00
return new KPropertiesDialog ( item - > url ( ) , d - > m_parentWidget ) ;
2000-11-06 19:51:00 +00:00
}
}
2004-09-24 07:56:05 +00:00
return 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 ;
}
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
KTrader : : OfferList plugin_offers ;
unsigned int pluginCount = 0 ;
plugin_offers = KTrader : : self ( ) - > query ( m_sMimeType . isNull ( ) ? QString : : fromLatin1 ( " all/all " ) : m_sMimeType , " 'KonqPopupMenu/Plugin' in ServiceTypes " ) ;
if ( plugin_offers . isEmpty ( ) )
return ; // no plugins installed do not bother about it
KTrader : : OfferList : : ConstIterator iterator = plugin_offers . begin ( ) ;
KTrader : : OfferList : : ConstIterator end = plugin_offers . end ( ) ;
addGroup ( " plugins " ) ;
// travers the offerlist
for ( ; iterator ! = end ; + + iterator , + + pluginCount ) {
//kdDebug() << (*iterator)->library() << endl;
KonqPopupMenuPlugin * plugin =
KParts : : ComponentFactory : :
createInstanceFromLibrary < KonqPopupMenuPlugin > ( QFile : : encodeName ( ( * iterator ) - > library ( ) ) ,
this ,
( * iterator ) - > name ( ) . latin1 ( ) ) ;
if ( ! plugin )
continue ;
QString pluginClientName = QString : : fromLatin1 ( " Plugin%1 " ) . arg ( pluginCount ) ;
addMerge ( pluginClientName ) ;
plugin - > domDocument ( ) . documentElement ( ) . setAttribute ( " name " , pluginClientName ) ;
m_pluginList . append ( plugin ) ;
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
2004-09-24 08:04:33 +00:00
KURL KonqPopupMenu : : url ( ) const // ### should be viewURL()
{
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
2004-09-24 08:04:33 +00:00
KURL : : List KonqPopupMenu : : popupURLList ( ) const
{
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
2001-10-31 22:29:33 +00:00
KonqPopupMenuPlugin : : KonqPopupMenuPlugin ( KonqPopupMenu * parent , const char * name )
2004-09-24 08:04:33 +00:00
: QObject ( parent , name )
{
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"