22 #include <tqeventloop.h>
24 #include <tdelocale.h>
25 #include <tdeapplication.h>
26 #include <kbookmarkmanager.h>
29 #include <kprotocolinfo.h>
30 #include <kiconloader.h>
31 #include <kinputdialog.h>
32 #include <tdeglobalsettings.h>
33 #include <kstandarddirs.h>
34 #include <kxmlguifactory.h>
35 #include <kxmlguibuilder.h>
36 #include <tdeparts/componentfactory.h>
40 #include <tdefileshare.h>
43 #include "kpropertiesdialog.h"
45 #include "konq_popupmenu.h"
46 #include "konq_operations.h"
47 #include "konq_xmlguiclient.h"
48 #include <dcopclient.h>
72 class KonqPopupMenuGUIBuilder :
public KXMLGUIBuilder
75 KonqPopupMenuGUIBuilder( TQPopupMenu *menu )
80 virtual ~KonqPopupMenuGUIBuilder()
84 virtual TQWidget *createContainer( TQWidget *parent,
int index,
85 const TQDomElement &element,
88 if ( !parent && element.attribute(
"name" ) ==
"popupmenu" )
91 return KXMLGUIBuilder::createContainer( parent, index, element,
id );
97 class KonqPopupMenu::KonqPopupMenuPrivate
100 KonqPopupMenuPrivate() : m_parentWidget( 0 ),
101 m_itemFlags( KParts::BrowserExtension::DefaultPopupItems )
105 TQWidget *m_parentWidget;
106 KParts::BrowserExtension::PopupFlags m_itemFlags;
108 bool localURLSlotFired;
109 KURL localURLResultURL;
110 bool localURLResultIsLocal;
113 KonqPopupMenu::ProtocolInfo::ProtocolInfo()
119 m_TrashIncluded =
false;
122 bool KonqPopupMenu::ProtocolInfo::supportsReading()
const
127 bool KonqPopupMenu::ProtocolInfo::supportsWriting()
const
132 bool KonqPopupMenu::ProtocolInfo::supportsDeleting()
const
137 bool KonqPopupMenu::ProtocolInfo::supportsMoving()
const
142 bool KonqPopupMenu::ProtocolInfo::trashIncluded()
const
144 return m_TrashIncluded;
152 ServiceList* selectList(
const TQString& priority,
const TQString& submenuName );
155 ServiceList user, userToplevel, userPriority;
156 TQMap<TQString, ServiceList> userSubmenus, userToplevelSubmenus, userPrioritySubmenus;
159 ServiceList* PopupServices::selectList(
const TQString& priority,
const TQString& submenuName )
163 if (submenuName.isEmpty())
165 if (priority ==
"TopLevel")
167 return &userToplevel;
169 else if (priority ==
"Important")
171 return &userPriority;
174 else if (priority ==
"TopLevel")
176 return &(userToplevelSubmenus[submenuName]);
178 else if (priority ==
"Important")
180 return &(userPrioritySubmenus[submenuName]);
184 return &(userSubmenus[submenuName]);
193 TDEActionCollection & actions,
195 bool showProperties )
196 : TQPopupMenu( 0L,
"konq_popupmenu" ),
197 m_actions( actions ), m_ownActions( static_cast<TQWidget *>( 0 ),
"KonqPopupMenu::m_ownActions" ),
198 m_pMenuNew( newMenu ), m_sViewURL(viewURL), m_lstItems(items), m_pManager(mgr)
201 init(0, kpf, KParts::BrowserExtension::DefaultPopupItems);
206 TDEActionCollection & actions,
208 TQWidget * parentWidget,
209 bool showProperties )
210 : TQPopupMenu( parentWidget,
"konq_popupmenu" ), m_actions( actions ), m_ownActions( static_cast<TQWidget *>( 0 ),
"KonqPopupMenu::m_ownActions" ), m_pMenuNew( newMenu ), m_sViewURL(viewURL), m_lstItems(items), m_pManager(mgr)
213 init(parentWidget, kpf, KParts::BrowserExtension::DefaultPopupItems);
218 TDEActionCollection & actions,
220 TQWidget * parentWidget,
222 KParts::BrowserExtension::PopupFlags flags)
223 : TQPopupMenu( parentWidget,
"konq_popupmenu" ), m_actions( actions ), m_ownActions( static_cast<TQWidget *>( 0 ),
"KonqPopupMenu::m_ownActions" ), m_pMenuNew( newMenu ), m_sViewURL(viewURL), m_lstItems(items), m_pManager(mgr)
225 init(parentWidget, kpf, flags);
228 void KonqPopupMenu::init (TQWidget * parentWidget, KonqPopupFlags kpf, KParts::BrowserExtension::PopupFlags flags)
230 d =
new KonqPopupMenuPrivate;
231 d->m_parentWidget = parentWidget;
232 d->m_itemFlags = flags;
236 int KonqPopupMenu::insertServicesSubmenus(
const TQMap<TQString, ServiceList>& submenus,
241 TQMap<TQString, ServiceList>::ConstIterator it;
243 for (it = submenus.begin(); it != submenus.end(); ++it)
245 if (it.data().isEmpty())
251 TQDomElement actionSubmenu = m_doc.createElement(
"menu" );
252 actionSubmenu.setAttribute(
"name",
"actions " + it.key() );
253 menu.appendChild( actionSubmenu );
254 TQDomElement subtext = m_doc.createElement(
"text" );
255 actionSubmenu.appendChild( subtext );
256 subtext.appendChild( m_doc.createTextNode( it.key() ) );
257 count += insertServices(it.data(), actionSubmenu, isBuiltin);
263 int KonqPopupMenu::insertServices(
const ServiceList& list,
267 static int id = 1000;
270 ServiceList::const_iterator it = list.begin();
271 for( ; it != list.end(); ++it )
275 if (!menu.firstChild().isNull() &&
276 menu.lastChild().toElement().tagName().lower() !=
"separator")
278 TQDomElement separator = m_doc.createElement(
"separator" );
279 menu.appendChild(separator);
284 if (isBuiltin || (*it).m_display ==
true)
288 name.prepend( isBuiltin ?
"builtinservice_" :
"userservice_" );
289 TDEAction * act =
new TDEAction( TQString((*it).m_strName).replace(
'&',
"&&"), 0,
290 TQT_TQOBJECT(
this), TQT_SLOT( slotRunService() ),
291 &m_ownActions, name );
293 if ( !(*it).m_strIcon.isEmpty() )
295 TQPixmap pix = SmallIcon( (*it).m_strIcon );
296 act->setIconSet( pix );
299 addAction( act, menu );
301 m_mapPopupServices[
id++ ] = *it;
309 bool KonqPopupMenu::KIOSKAuthorizedAction(TDEConfig& cfg)
311 if ( !cfg.hasKey(
"X-TDE-AuthorizeAction") )
316 TQStringList list = cfg.readListEntry(
"X-TDE-AuthorizeAction");
317 if (kapp && !list.isEmpty())
319 for(TQStringList::ConstIterator it = list.begin();
323 if (!kapp->authorize((*it).stripWhiteSpace()))
334 void KonqPopupMenu::setup(KonqPopupFlags kpf)
336 assert( m_lstItems.count() >= 1 );
338 m_ownActions.setWidget(
this );
340 const bool bIsLink = (kpf &
IsLink);
341 bool currentDir =
false;
342 bool sReading =
true;
343 bool sDeleting = ( d->m_itemFlags & KParts::BrowserExtension::NoDeletion ) == 0;
344 bool sMoving = sDeleting;
345 bool sWriting = sDeleting && m_lstItems.first()->isWritable();
346 m_sMimeType = m_lstItems.first()->mimetype();
347 TQString mimeGroup = m_sMimeType.left(m_sMimeType.find(
'/'));
348 mode_t mode = m_lstItems.first()->mode();
349 bool isDirectory = S_ISDIR(mode);
350 bool bTrashIncluded =
false;
351 bool mediaFiles =
false;
352 bool isReallyLocal = m_lstItems.first()->isLocalFile();
353 bool isLocal = isReallyLocal
354 || m_lstItems.first()->url().protocol()==
"media"
355 || m_lstItems.first()->url().protocol()==
"system";
356 bool isTrashLink =
false;
357 m_lstPopupURLs.clear();
359 setFont(TDEGlobalSettings::menuFont());
360 m_pluginList.setAutoDelete(
true );
361 m_ownActions.setHighlightingEnabled(
true );
363 attrName = TQString::fromLatin1(
"name" );
365 prepareXMLGUIStuff();
366 m_builder =
new KonqPopupMenuGUIBuilder(
this );
367 m_factory =
new KXMLGUIFactory( m_builder );
370 KFileItemListIterator it ( m_lstItems );
371 TQStringList mimeTypeList;
373 for ( ; it.current(); ++it )
378 m_lstPopupURLs.append( url );
381 if ( mode != (*it)->mode() )
385 if ( m_sMimeType != (*it)->mimetype() )
387 m_sMimeType = TQString::null;
389 if ( mimeGroup != (*it)->mimetype().left((*it)->mimetype().find(
'/')))
390 mimeGroup = TQString::null;
393 if ( mimeTypeList.findIndex( (*it)->mimetype() ) == -1 )
394 mimeTypeList << (*it)->mimetype();
396 if ( isReallyLocal && !url.isLocalFile() )
397 isReallyLocal =
false;
398 if ( isLocal && !url.isLocalFile() && url.protocol() !=
"media" && url.protocol() !=
"system" )
401 if ( !bTrashIncluded && (
402 ( url.protocol() ==
"trash" && url.path().length() <= 1 )
403 || url.url() ==
"system:/trash" || url.url() ==
"system:/trash/" ) ) {
404 bTrashIncluded =
true;
409 sReading = KProtocolInfo::supportsReading( url );
412 sWriting = KProtocolInfo::supportsWriting( url ) && (*it)->isWritable();
415 sDeleting = KProtocolInfo::supportsDeleting( url );
418 sMoving = KProtocolInfo::supportsMoving( url );
419 if ( (*it)->mimetype().startsWith(
"media/") )
424 KURL realURL = m_sViewURL;
425 if (!realURL.isLocalFile()) {
426 d->localURLSlotFired =
false;
427 TDEIO::LocalURLJob* localURLJob = TDEIO::localURL(m_sViewURL);
429 connect(localURLJob, TQT_SIGNAL(localURL(TDEIO::LocalURLJob*,
const KURL&,
bool)),
this, TQT_SLOT(slotLocalURL(TDEIO::LocalURLJob*,
const KURL&,
bool)));
430 connect(localURLJob, TQT_SIGNAL(destroyed()),
this, TQT_SLOT(slotLocalURLKIODestroyed()));
431 while (!d->localURLSlotFired) {
432 kapp->eventLoop()->enterLoop();
434 if (d->localURLResultIsLocal) {
435 realURL = d->localURLResultURL;
444 if ( m_lstItems.count() == 1 )
446 KURL firstPopupURL( m_lstItems.first()->url() );
447 firstPopupURL.cleanPath();
450 currentDir = firstPopupURL.equals( url,
true ,
true );
451 if ( isLocal && ((m_sMimeType ==
"application/x-desktop")
452 || (m_sMimeType ==
"media/builtin-mydocuments")
453 || (m_sMimeType ==
"media/builtin-mycomputer")
454 || (m_sMimeType ==
"media/builtin-mynetworkplaces")
455 || (m_sMimeType ==
"media/builtin-printers")
456 || (m_sMimeType ==
"media/builtin-trash")
457 || (m_sMimeType ==
"media/builtin-webbrowser")) ) {
458 KSimpleConfig cfg( firstPopupURL.path(), true );
459 cfg.setDesktopGroup();
460 isTrashLink = ( cfg.readEntry(
"Type") ==
"Link" && cfg.readEntry(
"URL") ==
"trash:/" );
468 m_info.m_Reading = sReading;
469 m_info.m_Writing = sWriting;
470 m_info.m_Deleting = sDeleting;
471 m_info.m_Moving = sMoving;
472 m_info.m_TrashIncluded = bTrashIncluded;
475 bool isCurrentTrash = ( m_lstItems.count() == 1 && bTrashIncluded ) || isTrashLink;
476 bool isIntoTrash = ( url.protocol() ==
"trash" || url.url().startsWith(
"system:/trash" ) ) && !isCurrentTrash;
478 bool isSingleMedium = m_lstItems.count() == 1 && mediaFiles;
486 addMerge(
"konqueror" );
488 bool isKDesktop = TQCString( kapp->name() ) ==
"kdesktop";
489 TDEAction *actNewWindow = 0;
492 !kapp->authorize(
"editable_desktop_icons"))
494 kpf &= ~ShowProperties;
499 if ( ((kpf & ShowNewWindow) != 0) && sReading )
501 TQString openStr = isKDesktop ? i18n(
"&Open" ) : i18n(
"Open in New &Window" );
502 actNewWindow =
new TDEAction( openStr,
"window-new", 0, TQT_TQOBJECT(
this), TQT_SLOT( slotPopupNewView() ), &m_ownActions,
"newview" );
505 if ( actNewWindow && !isKDesktop )
508 actNewWindow->setToolTip( i18n(
"Open the trash in a new window" ) );
509 else if (isSingleMedium)
510 actNewWindow->setToolTip( i18n(
"Open the medium in a new window") );
512 actNewWindow->setToolTip( i18n(
"Open the document in a new window" ) );
515 if ( S_ISDIR(mode) && sWriting && !isCurrentTrash )
517 if ( currentDir && m_pMenuNew )
523 addAction( m_pMenuNew );
529 if (d->m_itemFlags & KParts::BrowserExtension::ShowCreateDirectory)
531 TDEAction *actNewDir =
new TDEAction( i18n(
"Create &Folder..." ),
"folder-new", 0, TQT_TQOBJECT(
this), TQT_SLOT( slotPopupNewDir() ), &m_ownActions,
"newdir" );
532 addAction( actNewDir );
536 }
else if ( isIntoTrash ) {
538 act =
new TDEAction( i18n(
"&Restore" ), 0, TQT_TQOBJECT(
this), TQT_SLOT( slotPopupRestoreTrashedItems() ), &m_ownActions,
"restore" );
542 if (d->m_itemFlags & KParts::BrowserExtension::ShowNavigationItems)
544 if (d->m_itemFlags & KParts::BrowserExtension::ShowUp)
547 addAction(
"forward" );
548 if (d->m_itemFlags & KParts::BrowserExtension::ShowReload)
549 addAction(
"reload" );
556 addAction( actNewWindow );
559 addGroup(
"tabhandling" );
563 if ( !currentDir && sReading ) {
570 if ( S_ISDIR(mode) && sWriting ) {
572 addAction(
"paste" );
574 addAction(
"pasteto" );
578 if ( m_lstItems.count() == 1 && sMoving )
579 addAction(
"rename" );
581 bool addTrash =
false;
584 if ( sMoving && !isIntoTrash && !isTrashLink )
590 else if (TDEApplication::keyboardMouseState() & TQt::ShiftButton) {
595 TDEConfigGroup configGroup( kapp->config(),
"KDE" );
596 if ( configGroup.readBoolEntry(
"ShowDeleteCommand",
false ) )
602 addAction(
"trash" );
607 if ( isCurrentTrash )
609 act =
new TDEAction( i18n(
"&Empty Trash Bin" ),
"emptytrash", 0, TQT_TQOBJECT(
this), TQT_SLOT( slotPopupEmptyTrashBin() ), &m_ownActions,
"empytrash" );
610 KSimpleConfig trashConfig(
"trashrc",
true );
611 trashConfig.setGroup(
"Status" );
612 act->setEnabled( !trashConfig.readBoolEntry(
"Empty",
true ) );
615 addGroup(
"editactions" );
617 if (d->m_itemFlags & KParts::BrowserExtension::ShowTextSelectionItems) {
619 m_factory->addClient(
this );
623 if ( !isCurrentTrash && !isIntoTrash && (d->m_itemFlags & KParts::BrowserExtension::ShowBookmark))
629 bool httpPage = (m_sViewURL.protocol().find(
"http", 0,
false) == 0);
631 caption = i18n(
"&Bookmark This Page");
633 caption = i18n(
"&Bookmark This Location");
635 else if (S_ISDIR(mode))
636 caption = i18n(
"&Bookmark This Folder");
638 caption = i18n(
"&Bookmark This Link");
640 caption = i18n(
"&Bookmark This File");
642 act =
new TDEAction( caption,
"bookmark_add", 0, TQT_TQOBJECT(
this), TQT_SLOT( slotPopupAddToBookmark() ), &m_ownActions,
"bookmark_add" );
643 if (m_lstItems.count() > 1)
644 act->setEnabled(
false);
645 if (kapp->authorizeTDEAction(
"bookmarks"))
648 addGroup(
"linkactions" );
653 const bool isSingleLocal = m_lstItems.count() == 1 && isLocal;
655 KURL urlForServiceMenu( m_lstItems.first()->url() );
656 if (isLocal && !isReallyLocal) {
658 urlForServiceMenu = m_lstItems.first()->mostLocalURL(dummy);
662 if ( ((m_sMimeType ==
"application/x-desktop")
663 || (m_sMimeType ==
"media/builtin-mydocuments")
664 || (m_sMimeType ==
"media/builtin-mycomputer")
665 || (m_sMimeType ==
"media/builtin-mynetworkplaces")
666 || (m_sMimeType ==
"media/builtin-printers")
667 || (m_sMimeType ==
"media/builtin-trash")
668 || (m_sMimeType ==
"media/builtin-webbrowser")) && isSingleLocal )
671 s.builtin = KDEDesktopMimeType::builtinServices( urlForServiceMenu );
672 const TQString path = urlForServiceMenu.path();
673 KSimpleConfig cfg( path,
true );
674 cfg.setDesktopGroup();
675 const TQString priority = cfg.readEntry(
"X-TDE-Priority");
676 const TQString submenuName = cfg.readEntry(
"X-TDE-Submenu" );
677 if ( cfg.readEntry(
"Type") ==
"Link" ) {
678 urlForServiceMenu = cfg.readEntry(
"URL");
682 ServiceList* list = s.selectList( priority, submenuName );
683 (*list) = KDEDesktopMimeType::userDefinedServices( path, cfg, urlForServiceMenu.isLocalFile() );
692 if (isDirectory && isSingleLocal)
694 TQString dotDirectoryFile = urlForServiceMenu.path(1).append(
".directory");
695 KSimpleConfig cfg( dotDirectoryFile,
true );
696 cfg.setDesktopGroup();
698 if (KIOSKAuthorizedAction(cfg))
700 const TQString priority = cfg.readEntry(
"X-TDE-Priority");
701 const TQString submenuName = cfg.readEntry(
"X-TDE-Submenu" );
702 ServiceList* list = s.selectList( priority, submenuName );
703 (*list) += KDEDesktopMimeType::userDefinedServices( dotDirectoryFile, cfg,
true );
708 TQStringList entries = TDEGlobal::dirs()->findAllResources(
"data",
709 "konqueror/servicemenus/*.desktop",
false,
true);
711 TQStringList::ConstIterator eIt = entries.begin();
712 const TQStringList::ConstIterator eEnd = entries.end();
713 for (; eIt != eEnd; ++eIt )
715 KSimpleConfig cfg( *eIt,
true );
716 cfg.setDesktopGroup();
718 if (!KIOSKAuthorizedAction(cfg))
723 if ( cfg.hasKey(
"X-TDE-ShowIfRunning" ) )
725 const TQString app = cfg.readEntry(
"X-TDE-ShowIfRunning" );
726 if ( !kapp->dcopClient()->isApplicationRegistered( app.utf8() ) )
729 if ( cfg.hasKey(
"X-TDE-ShowIfDcopCall" ) )
731 TQString dcopcall = cfg.readEntry(
"X-TDE-ShowIfDcopCall" );
732 const TQCString app = TQString(dcopcall.section(
' ', 0,0)).utf8();
737 TQByteArray dataToSend;
738 TQDataStream dataStream(dataToSend, IO_WriteOnly);
739 dataStream << m_lstPopupURLs;
742 TQByteArray replyData;
743 TQCString
object = TQString(dcopcall.section(
' ', 1,-2)).utf8();
744 TQString
function = TQString(dcopcall.section(
' ', -1));
745 if(!
function.endsWith(
"(KURL::List)")) {
746 kdWarning() <<
"Desktop file " << *eIt <<
" contains an invalid X-TDE-ShowIfDcopCall - the function must take the exact parameter (KURL::List) and must be specified." << endl;
750 if(!kapp->dcopClient()->call( app,
object,
752 dataToSend, replyType, replyData,
true, 1000))
754 if(replyType !=
"bool" || !replyData[0])
758 if ( cfg.hasKey(
"X-TDE-Protocol" ) )
760 const TQString protocol = cfg.readEntry(
"X-TDE-Protocol" );
761 if ( protocol != urlForServiceMenu.protocol() )
764 else if ( cfg.hasKey(
"X-TDE-Protocols" ) )
766 TQStringList protocols = TQStringList::split(
"," , cfg.readEntry(
"X-TDE-Protocols" ) );
767 if ( !protocols.contains( urlForServiceMenu.protocol() ) )
770 else if ( urlForServiceMenu.protocol() ==
"trash" || urlForServiceMenu.url().startsWith(
"system:/trash" ) )
778 if ( cfg.hasKey(
"X-TDE-Require" ) )
780 const TQStringList capabilities = cfg.readListEntry(
"X-TDE-Require" );
781 if ( capabilities.contains(
"Write" ) && !sWriting )
784 if ( (cfg.hasKey(
"Actions" ) || cfg.hasKey(
"X-TDE-GetActionMenu") ) && cfg.hasKey(
"X-TDE-ServiceTypes" ) )
786 const TQStringList types = cfg.readListEntry(
"X-TDE-ServiceTypes" );
787 const TQStringList excludeTypes = cfg.readListEntry(
"X-TDE-ExcludeServiceTypes" );
791 for (TQStringList::ConstIterator it = types.begin();
792 it != types.end() && !ok;
796 bool checkTheMimetypes =
false;
797 if (*it ==
"all/all" ||
800 checkTheMimetypes =
true;
806 *it ==
"all/allfiles")
808 checkTheMimetypes =
true;
813 (!m_sMimeType.isEmpty() &&
814 *it == m_sMimeType)) ||
815 (!mimeGroup.isEmpty() &&
816 (((*it).right(1) ==
"*") &&
817 (*it).left((*it).find(
'/')) == mimeGroup)))
819 checkTheMimetypes =
true;
822 if (checkTheMimetypes)
825 for (TQStringList::ConstIterator itex = excludeTypes.begin(); itex != excludeTypes.end(); ++itex)
827 if( ((*itex).right(1) ==
"*" && (*itex).left((*itex).find(
'/')) == mimeGroup) ||
828 ((*itex) == m_sMimeType) )
839 const TQString priority = cfg.readEntry(
"X-TDE-Priority");
840 const TQString submenuName = cfg.readEntry(
"X-TDE-Submenu" );
842 ServiceList *list = s.selectList( priority, submenuName );
843 (*list) += KDEDesktopMimeType::userDefinedServices( *eIt, cfg, url.isLocalFile(), m_lstPopupURLs );
848 TDETrader::OfferList offers;
850 if (kapp->authorizeTDEAction(
"openwith"))
852 TQString constraint =
"Type == 'Application' and DesktopEntryName != 'kfmclient' and DesktopEntryName != 'kfmclient_dir' and DesktopEntryName != 'kfmclient_html'";
853 TQString subConstraint =
" and '%1' in ServiceTypes";
855 TQStringList::ConstIterator it = mimeTypeList.begin();
856 TQStringList::ConstIterator end = mimeTypeList.end();
857 Q_ASSERT( it != end );
858 TQString first = *it;
860 while ( it != end ) {
861 constraint += subConstraint.arg( *it );
865 offers = TDETrader::self()->query( first, constraint );
871 m_mapPopupServices.clear();
874 if ( !isDirectory || isLocal )
879 if ( !offers.isEmpty() )
884 TQDomElement menu = m_menuElement;
886 if ( offers.count() > 1 )
888 menu = m_doc.createElement(
"menu" );
889 menu.setAttribute(
"name",
"openwith submenu" );
890 m_menuElement.appendChild( menu );
891 TQDomElement text = m_doc.createElement(
"text" );
892 menu.appendChild( text );
893 text.appendChild( m_doc.createTextNode( i18n(
"&Open With") ) );
896 TDETrader::OfferList::ConstIterator it = offers.begin();
897 for( ; it != offers.end(); it++ )
899 KService::Ptr service = (*it);
905 const TQString onlyShowIn = service->property(
"OnlyShowIn", TQVariant::String).toString();
906 if ( !onlyShowIn.isEmpty() ) {
907 const TQStringList aList = TQStringList::split(
';', onlyShowIn);
908 if (!aList.contains(
"TDE"))
911 const TQString notShowIn = service->property(
"NotShowIn", TQVariant::String).toString();
912 if ( !notShowIn.isEmpty() ) {
913 const TQStringList aList = TQStringList::split(
';', notShowIn);
914 if (aList.contains(
"TDE"))
921 TQString actionName( (*it)->name().replace(
"&",
"&&") );
922 if ( menu == m_menuElement )
923 actionName = i18n(
"Open with %1" ).arg( actionName );
925 act =
new TDEAction( actionName, (*it)->pixmap( TDEIcon::Small ), 0,
926 TQT_TQOBJECT(
this), TQT_SLOT( slotRunService() ),
927 &m_ownActions, nam.prepend(
"appservice_" ) );
928 addAction( act, menu );
930 m_mapPopup[
id++ ] = *it;
933 TQString openWithActionName;
934 if ( menu != m_menuElement )
936 addSeparator( menu );
937 openWithActionName = i18n(
"&Other..." );
941 openWithActionName = i18n(
"&Open With..." );
943 TDEAction *openWithAct =
new TDEAction( openWithActionName, 0, TQT_TQOBJECT(
this), TQT_SLOT( slotPopupOpenWith() ), &m_ownActions,
"openwith" );
944 addAction( openWithAct, menu );
948 act =
new TDEAction( i18n(
"&Open With..." ), 0, TQT_TQOBJECT(
this), TQT_SLOT( slotPopupOpenWith() ), &m_ownActions,
"openwith" );
953 addGroup(
"preview" );
957 TQDomElement actionMenu = m_menuElement;
958 int userItemCount = 0;
959 if (s.user.count() + s.userSubmenus.count() +
960 s.userPriority.count() + s.userPrioritySubmenus.count() > 1)
963 actionMenu = m_doc.createElement(
"menu" );
964 actionMenu.setAttribute(
"name",
"actions submenu" );
965 m_menuElement.appendChild( actionMenu );
966 TQDomElement text = m_doc.createElement(
"text" );
967 actionMenu.appendChild( text );
968 text.appendChild( m_doc.createTextNode( i18n(
"Ac&tions") ) );
971 userItemCount += insertServicesSubmenus(s.userPrioritySubmenus, actionMenu,
false);
972 userItemCount += insertServices(s.userPriority, actionMenu,
false);
975 if (userItemCount > 0 &&
976 (s.user.count() > 0 ||
977 s.userSubmenus.count() > 0 ||
978 s.builtin.count() > 0) &&
979 actionMenu.lastChild().toElement().tagName().lower() !=
"separator")
981 TQDomElement separator = m_doc.createElement(
"separator" );
982 actionMenu.appendChild(separator);
985 userItemCount += insertServicesSubmenus(s.userSubmenus, actionMenu,
false);
986 userItemCount += insertServices(s.user, actionMenu,
false);
987 userItemCount += insertServices(s.builtin, m_menuElement,
true);
989 userItemCount += insertServicesSubmenus(s.userToplevelSubmenus, m_menuElement,
false);
990 userItemCount += insertServices(s.userToplevel, m_menuElement,
false);
992 if ( userItemCount > 0 )
997 if ( !isCurrentTrash && !isIntoTrash && !mediaFiles && sReading )
1000 if ( KPropertiesDialog::canDisplay( m_lstItems ) && (kpf & ShowProperties) )
1002 act =
new TDEAction( i18n(
"&Properties" ),
"edit", 0, TQT_TQOBJECT(
this), TQT_SLOT( slotPopupProperties() ),
1003 &m_ownActions,
"properties" );
1007 while ( !m_menuElement.lastChild().isNull() &&
1008 m_menuElement.lastChild().toElement().tagName().lower() ==
"separator" )
1009 m_menuElement.removeChild( m_menuElement.lastChild() );
1011 if ( isDirectory && isLocal )
1013 if ( KFileShare::authorization() == KFileShare::Authorized )
1016 act =
new TDEAction( i18n(
"Share"), 0, TQT_TQOBJECT(
this), TQT_SLOT( slotOpenShareFileDialog() ),
1017 &m_ownActions,
"sharefile" );
1025 m_factory->addClient(
this );
1028 void KonqPopupMenu::slotOpenShareFileDialog()
1030 KPropertiesDialog* dlg = showPropertiesDialog();
1031 dlg->showFileSharingPage();
1036 m_pluginList.clear();
1045 d->m_urlTitle = urlTitle;
1048 void KonqPopupMenu::slotPopupNewView()
1050 KURL::List::ConstIterator it = m_lstPopupURLs.begin();
1051 for ( ; it != m_lstPopupURLs.end(); it++ )
1052 (
void)
new KRun(*it);
1055 void KonqPopupMenu::slotPopupNewDir()
1057 if (m_lstPopupURLs.empty())
1063 void KonqPopupMenu::slotPopupEmptyTrashBin()
1065 KonqOperations::emptyTrash();
1068 void KonqPopupMenu::slotPopupRestoreTrashedItems()
1070 KonqOperations::restoreTrashedItems( m_lstPopupURLs );
1073 void KonqPopupMenu::slotPopupOpenWith()
1075 KRun::displayOpenWithDialog( m_lstPopupURLs );
1078 void KonqPopupMenu::slotPopupAddToBookmark()
1080 KBookmarkGroup root;
1081 if ( m_lstPopupURLs.count() == 1 ) {
1082 KURL url = m_lstPopupURLs.first();
1083 TQString title = d->m_urlTitle.isEmpty() ? url.prettyURL() : d->m_urlTitle;
1084 root = m_pManager->addBookmarkDialog( url.prettyURL(), title );
1088 root = m_pManager->root();
1089 KURL::List::ConstIterator it = m_lstPopupURLs.begin();
1090 for ( ; it != m_lstPopupURLs.end(); it++ )
1091 root.addBookmark( m_pManager, (*it).prettyURL(), (*it) );
1093 m_pManager->emitChanged( root );
1096 void KonqPopupMenu::slotRunService()
1098 TQCString senderName = TQT_TQOBJECT_CONST(sender())->name();
1099 int id = senderName.mid( senderName.find(
'_' ) + 1 ).toInt();
1102 TQMap<int,KService::Ptr>::Iterator it = m_mapPopup.find(
id );
1103 if ( it != m_mapPopup.end() )
1105 KRun::run( **it, m_lstPopupURLs );
1110 TQMap<int,KDEDesktopMimeType::Service>::Iterator it2 = m_mapPopupServices.find(
id );
1111 if ( it2 != m_mapPopupServices.end() )
1113 KDEDesktopMimeType::executeService( m_lstPopupURLs, it2.data() );
1119 void KonqPopupMenu::slotPopupMimeType()
1124 void KonqPopupMenu::slotPopupProperties()
1126 (void)showPropertiesDialog();
1129 KPropertiesDialog* KonqPopupMenu::showPropertiesDialog()
1135 if ( m_lstItems.count() == 1 )
1137 KFileItem * item = m_lstItems.first();
1138 if (item->entry().count() == 0)
1141 return new KPropertiesDialog( item->url(), d->m_parentWidget );
1144 return new KPropertiesDialog( m_lstItems, d->m_parentWidget );
1149 TQCString name = element.attribute( attrName ).ascii();
1150 TDEAction *res = m_ownActions.action( static_cast<const char *>(name) );
1153 res = m_actions.action( static_cast<const char *>(name) );
1155 if ( !res && m_pMenuNew && strcmp( name, m_pMenuNew->name() ) == 0 )
1161 TDEActionCollection *KonqPopupMenu::actionCollection()
const
1163 return const_cast<TDEActionCollection *
>( &m_ownActions );
1166 TQString KonqPopupMenu::mimeType()
const
1171 KonqPopupMenu::ProtocolInfo KonqPopupMenu::protocolInfo()
const
1176 void KonqPopupMenu::addPlugins()
1180 TDETrader::OfferList plugin_offers;
1181 unsigned int pluginCount = 0;
1182 plugin_offers = TDETrader::self()->query( m_sMimeType.isNull() ? TQString::fromLatin1(
"all/all" ) : m_sMimeType,
"'KonqPopupMenu/Plugin' in ServiceTypes");
1183 if ( plugin_offers.isEmpty() )
1186 TDETrader::OfferList::ConstIterator iterator = plugin_offers.begin();
1187 TDETrader::OfferList::ConstIterator end = plugin_offers.end();
1189 addGroup(
"plugins" );
1191 for(; iterator != end; ++iterator, ++pluginCount ) {
1193 KonqPopupMenuPlugin *plugin =
1194 KParts::ComponentFactory::
1195 createInstanceFromLibrary<KonqPopupMenuPlugin>( TQFile::encodeName( (*iterator)->library() ),
1197 (*iterator)->name().latin1() );
1201 TQString pluginClientName = TQString::fromLatin1(
"Plugin%1" ).arg( pluginCount );
1202 addMerge( pluginClientName );
1203 plugin->domDocument().documentElement().setAttribute(
"name", pluginClientName );
1204 m_pluginList.append( plugin );
1205 insertChildClient( plugin );
1209 addMerge(
"plugins" );
1212 KURL KonqPopupMenu::url() const
1217 KFileItemList KonqPopupMenu::fileItemList()
const
1222 KURL::List KonqPopupMenu::popupURLList()
const
1224 return m_lstPopupURLs;
1227 void KonqPopupMenu::slotLocalURL(TDEIO::LocalURLJob *job,
const KURL& url,
bool isLocal)
1229 d->localURLSlotFired =
true;
1230 d->localURLResultURL = url;
1231 d->localURLResultIsLocal = isLocal;
1232 kapp->eventLoop()->exitLoop();
1235 void KonqPopupMenu::slotLocalURLKIODestroyed()
1237 if (!d->localURLSlotFired) {
1238 d->localURLSlotFired =
true;
1239 d->localURLResultURL = KURL();
1240 d->localURLResultIsLocal =
false;
1241 kapp->eventLoop()->exitLoop();
1249 KonqPopupMenuPlugin::KonqPopupMenuPlugin(
KonqPopupMenu *parent,
const char *name )
1250 : TQObject( parent, name )
1254 KonqPopupMenuPlugin::~KonqPopupMenuPlugin()
1258 #include "konq_popupmenu.moc"