24 #include <kapplication.h>
25 #include <kbookmarkmanager.h>
28 #include <kprotocolinfo.h>
29 #include <kiconloader.h>
30 #include <kinputdialog.h>
31 #include <kglobalsettings.h>
32 #include <kstandarddirs.h>
33 #include <kxmlguifactory.h>
34 #include <kxmlguibuilder.h>
35 #include <kparts/componentfactory.h>
39 #include <kfileshare.h>
42 #include "kpropertiesdialog.h"
44 #include "konq_popupmenu.h"
45 #include "konq_operations.h"
46 #include "konq_xmlguiclient.h"
47 #include <dcopclient.h>
71 class KonqPopupMenuGUIBuilder :
public KXMLGUIBuilder
74 KonqPopupMenuGUIBuilder( TQPopupMenu *menu )
79 virtual ~KonqPopupMenuGUIBuilder()
83 virtual TQWidget *createContainer( TQWidget *parent,
int index,
84 const TQDomElement &element,
87 if ( !parent && element.attribute(
"name" ) ==
"popupmenu" )
90 return KXMLGUIBuilder::createContainer( parent, index, element,
id );
96 class KonqPopupMenu::KonqPopupMenuPrivate
99 KonqPopupMenuPrivate() : m_parentWidget( 0 ),
100 m_itemFlags( KParts::BrowserExtension::DefaultPopupItems )
104 TQWidget *m_parentWidget;
105 KParts::BrowserExtension::PopupFlags m_itemFlags;
108 KonqPopupMenu::ProtocolInfo::ProtocolInfo()
114 m_TrashIncluded =
false;
117 bool KonqPopupMenu::ProtocolInfo::supportsReading()
const
122 bool KonqPopupMenu::ProtocolInfo::supportsWriting()
const
127 bool KonqPopupMenu::ProtocolInfo::supportsDeleting()
const
132 bool KonqPopupMenu::ProtocolInfo::supportsMoving()
const
137 bool KonqPopupMenu::ProtocolInfo::trashIncluded()
const
139 return m_TrashIncluded;
147 ServiceList* selectList(
const TQString& priority,
const TQString& submenuName );
150 ServiceList user, userToplevel, userPriority;
151 TQMap<TQString, ServiceList> userSubmenus, userToplevelSubmenus, userPrioritySubmenus;
154 ServiceList* PopupServices::selectList(
const TQString& priority,
const TQString& submenuName )
158 if (submenuName.isEmpty())
160 if (priority ==
"TopLevel")
162 return &userToplevel;
164 else if (priority ==
"Important")
166 return &userPriority;
169 else if (priority ==
"TopLevel")
171 return &(userToplevelSubmenus[submenuName]);
173 else if (priority ==
"Important")
175 return &(userPrioritySubmenus[submenuName]);
179 return &(userSubmenus[submenuName]);
188 KActionCollection & actions,
190 bool showProperties )
191 : TQPopupMenu( 0L,
"konq_popupmenu" ),
192 m_actions( actions ), m_ownActions( static_cast<TQWidget *>( 0 ),
"KonqPopupMenu::m_ownActions" ),
193 m_pMenuNew( newMenu ), m_sViewURL(viewURL), m_lstItems(items), m_pManager(mgr)
196 init(0, kpf, KParts::BrowserExtension::DefaultPopupItems);
201 KActionCollection & actions,
203 TQWidget * parentWidget,
204 bool showProperties )
205 : 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)
208 init(parentWidget, kpf, KParts::BrowserExtension::DefaultPopupItems);
213 KActionCollection & actions,
215 TQWidget * parentWidget,
217 KParts::BrowserExtension::PopupFlags flags)
218 : 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)
220 init(parentWidget, kpf, flags);
223 void KonqPopupMenu::init (TQWidget * parentWidget, KonqPopupFlags kpf, KParts::BrowserExtension::PopupFlags flags)
225 d =
new KonqPopupMenuPrivate;
226 d->m_parentWidget = parentWidget;
227 d->m_itemFlags = flags;
231 int KonqPopupMenu::insertServicesSubmenus(
const TQMap<TQString, ServiceList>& submenus,
236 TQMap<TQString, ServiceList>::ConstIterator it;
238 for (it = submenus.begin(); it != submenus.end(); ++it)
240 if (it.data().isEmpty())
246 TQDomElement actionSubmenu = m_doc.createElement(
"menu" );
247 actionSubmenu.setAttribute(
"name",
"actions " + it.key() );
248 menu.appendChild( actionSubmenu );
249 TQDomElement subtext = m_doc.createElement(
"text" );
250 actionSubmenu.appendChild( subtext );
251 subtext.appendChild( m_doc.createTextNode( it.key() ) );
252 count += insertServices(it.data(), actionSubmenu, isBuiltin);
258 int KonqPopupMenu::insertServices(
const ServiceList& list,
262 static int id = 1000;
265 ServiceList::const_iterator it = list.begin();
266 for( ; it != list.end(); ++it )
270 if (!menu.firstChild().isNull() &&
271 menu.lastChild().toElement().tagName().lower() !=
"separator")
273 TQDomElement separator = m_doc.createElement(
"separator" );
274 menu.appendChild(separator);
279 if (isBuiltin || (*it).m_display ==
true)
283 name.prepend( isBuiltin ?
"builtinservice_" :
"userservice_" );
284 KAction * act =
new KAction( TQString((*it).m_strName).replace(
'&',
"&&"), 0,
285 TQT_TQOBJECT(
this), TQT_SLOT( slotRunService() ),
286 &m_ownActions, name );
288 if ( !(*it).m_strIcon.isEmpty() )
290 TQPixmap pix = SmallIcon( (*it).m_strIcon );
291 act->setIconSet( pix );
294 addAction( act, menu );
296 m_mapPopupServices[
id++ ] = *it;
304 bool KonqPopupMenu::KIOSKAuthorizedAction(KConfig& cfg)
306 if ( !cfg.hasKey(
"X-KDE-AuthorizeAction") )
311 TQStringList list = cfg.readListEntry(
"X-KDE-AuthorizeAction");
312 if (kapp && !list.isEmpty())
314 for(TQStringList::ConstIterator it = list.begin();
318 if (!kapp->authorize((*it).stripWhiteSpace()))
329 void KonqPopupMenu::setup(KonqPopupFlags kpf)
331 assert( m_lstItems.count() >= 1 );
333 m_ownActions.setWidget(
this );
335 const bool bIsLink = (kpf &
IsLink);
336 bool currentDir =
false;
337 bool sReading =
true;
338 bool sDeleting = ( d->m_itemFlags & KParts::BrowserExtension::NoDeletion ) == 0;
339 bool sMoving = sDeleting;
340 bool sWriting = sDeleting && m_lstItems.first()->isWritable();
341 m_sMimeType = m_lstItems.first()->mimetype();
342 TQString mimeGroup = m_sMimeType.left(m_sMimeType.find(
'/'));
343 mode_t mode = m_lstItems.first()->mode();
344 bool isDirectory = S_ISDIR(mode);
345 bool bTrashIncluded =
false;
346 bool mediaFiles =
false;
347 bool isReallyLocal = m_lstItems.first()->isLocalFile();
348 bool isLocal = isReallyLocal
349 || m_lstItems.first()->url().protocol()==
"media"
350 || m_lstItems.first()->url().protocol()==
"system";
351 bool isTrashLink =
false;
352 m_lstPopupURLs.clear();
354 setFont(KGlobalSettings::menuFont());
355 m_pluginList.setAutoDelete(
true );
356 m_ownActions.setHighlightingEnabled(
true );
358 attrName = TQString::fromLatin1(
"name" );
360 prepareXMLGUIStuff();
361 m_builder =
new KonqPopupMenuGUIBuilder(
this );
362 m_factory =
new KXMLGUIFactory( m_builder );
365 KFileItemListIterator it ( m_lstItems );
366 TQStringList mimeTypeList;
368 for ( ; it.current(); ++it )
373 m_lstPopupURLs.append( url );
376 if ( mode != (*it)->mode() )
380 if ( m_sMimeType != (*it)->mimetype() )
382 m_sMimeType = TQString::null;
384 if ( mimeGroup != (*it)->mimetype().left((*it)->mimetype().find(
'/')))
385 mimeGroup = TQString::null;
388 if ( mimeTypeList.findIndex( (*it)->mimetype() ) == -1 )
389 mimeTypeList << (*it)->mimetype();
391 if ( isReallyLocal && !url.isLocalFile() )
392 isReallyLocal =
false;
393 if ( isLocal && !url.isLocalFile() && url.protocol() !=
"media" && url.protocol() !=
"system" )
396 if ( !bTrashIncluded && (
397 ( url.protocol() ==
"trash" && url.path().length() <= 1 )
398 || url.url() ==
"system:/trash" || url.url() ==
"system:/trash/" ) ) {
399 bTrashIncluded =
true;
404 sReading = KProtocolInfo::supportsReading( url );
407 sWriting = KProtocolInfo::supportsWriting( url ) && (*it)->isWritable();
410 sDeleting = KProtocolInfo::supportsDeleting( url );
413 sMoving = KProtocolInfo::supportsMoving( url );
414 if ( (*it)->mimetype().startsWith(
"media/") )
421 if ( m_lstItems.count() == 1 )
423 KURL firstPopupURL( m_lstItems.first()->url() );
424 firstPopupURL.cleanPath();
427 currentDir = firstPopupURL.equals( url,
true );
428 if ( isLocal && ((m_sMimeType ==
"application/x-desktop")
429 || (m_sMimeType ==
"media/builtin-mydocuments")
430 || (m_sMimeType ==
"media/builtin-mycomputer")
431 || (m_sMimeType ==
"media/builtin-mynetworkplaces")
432 || (m_sMimeType ==
"media/builtin-printers")
433 || (m_sMimeType ==
"media/builtin-trash")
434 || (m_sMimeType ==
"media/builtin-webbrowser")) ) {
435 KSimpleConfig cfg( firstPopupURL.path(), true );
436 cfg.setDesktopGroup();
437 isTrashLink = ( cfg.readEntry(
"Type") ==
"Link" && cfg.readEntry(
"URL") ==
"trash:/" );
445 m_info.m_Reading = sReading;
446 m_info.m_Writing = sWriting;
447 m_info.m_Deleting = sDeleting;
448 m_info.m_Moving = sMoving;
449 m_info.m_TrashIncluded = bTrashIncluded;
452 bool isCurrentTrash = ( m_lstItems.count() == 1 && bTrashIncluded ) || isTrashLink;
453 bool isIntoTrash = ( url.protocol() ==
"trash" || url.url().startsWith(
"system:/trash" ) ) && !isCurrentTrash;
455 bool isSingleMedium = m_lstItems.count() == 1 && mediaFiles;
463 addMerge(
"konqueror" );
465 bool isKDesktop = TQCString( kapp->name() ) ==
"kdesktop";
466 KAction *actNewWindow = 0;
469 !kapp->authorize(
"editable_desktop_icons"))
471 kpf &= ~ShowProperties;
476 if ( ((kpf & ShowNewWindow) != 0) && sReading )
478 TQString openStr = isKDesktop ? i18n(
"&Open" ) : i18n(
"Open in New &Window" );
479 actNewWindow =
new KAction( openStr,
"window_new", 0, TQT_TQOBJECT(
this), TQT_SLOT( slotPopupNewView() ), &m_ownActions,
"newview" );
482 if ( actNewWindow && !isKDesktop )
485 actNewWindow->setToolTip( i18n(
"Open the trash in a new window" ) );
486 else if (isSingleMedium)
487 actNewWindow->setToolTip( i18n(
"Open the medium in a new window") );
489 actNewWindow->setToolTip( i18n(
"Open the document in a new window" ) );
492 if ( S_ISDIR(mode) && sWriting && !isCurrentTrash )
494 if ( currentDir && m_pMenuNew )
500 addAction( m_pMenuNew );
506 if (d->m_itemFlags & KParts::BrowserExtension::ShowCreateDirectory)
508 KAction *actNewDir =
new KAction( i18n(
"Create &Folder..." ),
"folder_new", 0, TQT_TQOBJECT(
this), TQT_SLOT( slotPopupNewDir() ), &m_ownActions,
"newdir" );
509 addAction( actNewDir );
513 }
else if ( isIntoTrash ) {
515 act =
new KAction( i18n(
"&Restore" ), 0, TQT_TQOBJECT(
this), TQT_SLOT( slotPopupRestoreTrashedItems() ), &m_ownActions,
"restore" );
519 if (d->m_itemFlags & KParts::BrowserExtension::ShowNavigationItems)
521 if (d->m_itemFlags & KParts::BrowserExtension::ShowUp)
524 addAction(
"forward" );
525 if (d->m_itemFlags & KParts::BrowserExtension::ShowReload)
526 addAction(
"reload" );
533 addAction( actNewWindow );
536 addGroup(
"tabhandling" );
540 if ( !currentDir && sReading ) {
547 if ( S_ISDIR(mode) && sWriting ) {
549 addAction(
"paste" );
551 addAction(
"pasteto" );
555 if ( m_lstItems.count() == 1 && sMoving )
556 addAction(
"rename" );
558 bool addTrash =
false;
561 if ( sMoving && !isIntoTrash && !isTrashLink )
567 else if (KApplication::keyboardMouseState() & TQt::ShiftButton) {
572 KConfigGroup configGroup( kapp->config(),
"KDE" );
573 if ( configGroup.readBoolEntry(
"ShowDeleteCommand",
false ) )
579 addAction(
"trash" );
584 if ( isCurrentTrash )
586 act =
new KAction( i18n(
"&Empty Trash Bin" ),
"emptytrash", 0, TQT_TQOBJECT(
this), TQT_SLOT( slotPopupEmptyTrashBin() ), &m_ownActions,
"empytrash" );
587 KSimpleConfig trashConfig(
"trashrc",
true );
588 trashConfig.setGroup(
"Status" );
589 act->setEnabled( !trashConfig.readBoolEntry(
"Empty",
true ) );
592 addGroup(
"editactions" );
594 if (d->m_itemFlags & KParts::BrowserExtension::ShowTextSelectionItems) {
596 m_factory->addClient(
this );
600 if ( !isCurrentTrash && !isIntoTrash && (d->m_itemFlags & KParts::BrowserExtension::ShowBookmark))
606 bool httpPage = (m_sViewURL.protocol().find(
"http", 0,
false) == 0);
608 caption = i18n(
"&Bookmark This Page");
610 caption = i18n(
"&Bookmark This Location");
612 else if (S_ISDIR(mode))
613 caption = i18n(
"&Bookmark This Folder");
615 caption = i18n(
"&Bookmark This Link");
617 caption = i18n(
"&Bookmark This File");
619 act =
new KAction( caption,
"bookmark_add", 0, TQT_TQOBJECT(
this), TQT_SLOT( slotPopupAddToBookmark() ), &m_ownActions,
"bookmark_add" );
620 if (m_lstItems.count() > 1)
621 act->setEnabled(
false);
622 if (kapp->authorizeKAction(
"bookmarks"))
625 addGroup(
"linkactions" );
630 const bool isSingleLocal = m_lstItems.count() == 1 && isLocal;
632 KURL urlForServiceMenu( m_lstItems.first()->url() );
633 if (isLocal && !isReallyLocal) {
635 urlForServiceMenu = m_lstItems.first()->mostLocalURL(dummy);
639 if ( ((m_sMimeType ==
"application/x-desktop")
640 || (m_sMimeType ==
"media/builtin-mydocuments")
641 || (m_sMimeType ==
"media/builtin-mycomputer")
642 || (m_sMimeType ==
"media/builtin-mynetworkplaces")
643 || (m_sMimeType ==
"media/builtin-printers")
644 || (m_sMimeType ==
"media/builtin-trash")
645 || (m_sMimeType ==
"media/builtin-webbrowser")) && isSingleLocal )
648 s.builtin = KDEDesktopMimeType::builtinServices( urlForServiceMenu );
649 const TQString path = urlForServiceMenu.path();
650 KSimpleConfig cfg( path,
true );
651 cfg.setDesktopGroup();
652 const TQString priority = cfg.readEntry(
"X-KDE-Priority");
653 const TQString submenuName = cfg.readEntry(
"X-KDE-Submenu" );
654 if ( cfg.readEntry(
"Type") ==
"Link" ) {
655 urlForServiceMenu = cfg.readEntry(
"URL");
659 ServiceList* list = s.selectList( priority, submenuName );
660 (*list) = KDEDesktopMimeType::userDefinedServices( path, cfg, urlForServiceMenu.isLocalFile() );
669 if (isDirectory && isSingleLocal)
671 TQString dotDirectoryFile = urlForServiceMenu.path(1).append(
".directory");
672 KSimpleConfig cfg( dotDirectoryFile,
true );
673 cfg.setDesktopGroup();
675 if (KIOSKAuthorizedAction(cfg))
677 const TQString priority = cfg.readEntry(
"X-KDE-Priority");
678 const TQString submenuName = cfg.readEntry(
"X-KDE-Submenu" );
679 ServiceList* list = s.selectList( priority, submenuName );
680 (*list) += KDEDesktopMimeType::userDefinedServices( dotDirectoryFile, cfg,
true );
685 const TQStringList entries = KGlobal::dirs()->findAllResources(
"data",
686 "konqueror/servicemenus/*.desktop",
689 TQStringList::ConstIterator eIt = entries.begin();
690 const TQStringList::ConstIterator eEnd = entries.end();
691 for (; eIt != eEnd; ++eIt )
693 KSimpleConfig cfg( *eIt,
true );
694 cfg.setDesktopGroup();
696 if (!KIOSKAuthorizedAction(cfg))
701 if ( cfg.hasKey(
"X-KDE-ShowIfRunning" ) )
703 const TQString app = cfg.readEntry(
"X-KDE-ShowIfRunning" );
704 if ( !kapp->dcopClient()->isApplicationRegistered( app.utf8() ) )
707 if ( cfg.hasKey(
"X-KDE-ShowIfDcopCall" ) )
709 TQString dcopcall = cfg.readEntry(
"X-KDE-ShowIfDcopCall" );
710 const TQCString app = TQString(dcopcall.section(
' ', 0,0)).utf8();
715 TQByteArray dataToSend;
716 TQDataStream dataStream(dataToSend, IO_WriteOnly);
717 dataStream << m_lstPopupURLs;
720 TQByteArray replyData;
721 TQCString
object = TQString(dcopcall.section(
' ', 1,-2)).utf8();
722 TQString
function = TQString(dcopcall.section(
' ', -1));
723 if(!
function.endsWith(
"(KURL::List)")) {
724 kdWarning() <<
"Desktop file " << *eIt <<
" contains an invalid X-KDE-ShowIfDcopCall - the function must take the exact parameter (KURL::List) and must be specified." << endl;
728 if(!kapp->dcopClient()->call( app,
object,
730 dataToSend, replyType, replyData,
true, 1000))
732 if(replyType !=
"bool" || !replyData[0])
736 if ( cfg.hasKey(
"X-KDE-Protocol" ) )
738 const TQString protocol = cfg.readEntry(
"X-KDE-Protocol" );
739 if ( protocol != urlForServiceMenu.protocol() )
742 else if ( cfg.hasKey(
"X-KDE-Protocols" ) )
744 TQStringList protocols = TQStringList::split(
"," , cfg.readEntry(
"X-KDE-Protocols" ) );
745 if ( !protocols.contains( urlForServiceMenu.protocol() ) )
748 else if ( urlForServiceMenu.protocol() ==
"trash" || urlForServiceMenu.url().startsWith(
"system:/trash" ) )
756 if ( cfg.hasKey(
"X-KDE-Require" ) )
758 const TQStringList capabilities = cfg.readListEntry(
"X-KDE-Require" );
759 if ( capabilities.contains(
"Write" ) && !sWriting )
762 if ( (cfg.hasKey(
"Actions" ) || cfg.hasKey(
"X-KDE-GetActionMenu") ) && cfg.hasKey(
"ServiceTypes" ) )
764 const TQStringList types = cfg.readListEntry(
"ServiceTypes" );
765 const TQStringList excludeTypes = cfg.readListEntry(
"ExcludeServiceTypes" );
769 for (TQStringList::ConstIterator it = types.begin();
770 it != types.end() && !ok;
774 bool checkTheMimetypes =
false;
775 if (*it ==
"all/all" ||
778 checkTheMimetypes =
true;
784 *it ==
"all/allfiles")
786 checkTheMimetypes =
true;
791 (!m_sMimeType.isEmpty() &&
792 *it == m_sMimeType) ||
793 (!mimeGroup.isEmpty() &&
794 ((*it).right(1) ==
"*" &&
795 (*it).left((*it).find(
'/')) == mimeGroup)))
797 checkTheMimetypes =
true;
800 if (checkTheMimetypes)
803 for (TQStringList::ConstIterator itex = excludeTypes.begin(); itex != excludeTypes.end(); ++itex)
805 if( ((*itex).right(1) ==
"*" && (*itex).left((*itex).find(
'/')) == mimeGroup) ||
806 ((*itex) == m_sMimeType) )
817 const TQString priority = cfg.readEntry(
"X-KDE-Priority");
818 const TQString submenuName = cfg.readEntry(
"X-KDE-Submenu" );
820 ServiceList* list = s.selectList( priority, submenuName );
821 (*list) += KDEDesktopMimeType::userDefinedServices( *eIt, cfg, url.isLocalFile(), m_lstPopupURLs );
826 KTrader::OfferList offers;
828 if (kapp->authorizeKAction(
"openwith"))
830 TQString constraint =
"Type == 'Application' and DesktopEntryName != 'kfmclient' and DesktopEntryName != 'kfmclient_dir' and DesktopEntryName != 'kfmclient_html'";
831 TQString subConstraint =
" and '%1' in ServiceTypes";
833 TQStringList::ConstIterator it = mimeTypeList.begin();
834 TQStringList::ConstIterator end = mimeTypeList.end();
835 Q_ASSERT( it != end );
836 TQString first = *it;
838 while ( it != end ) {
839 constraint += subConstraint.arg( *it );
843 offers = KTrader::self()->query( first, constraint );
849 m_mapPopupServices.clear();
852 if ( !isDirectory || isLocal )
857 if ( !offers.isEmpty() )
862 TQDomElement menu = m_menuElement;
864 if ( offers.count() > 1 )
866 menu = m_doc.createElement(
"menu" );
867 menu.setAttribute(
"name",
"openwith submenu" );
868 m_menuElement.appendChild( menu );
869 TQDomElement text = m_doc.createElement(
"text" );
870 menu.appendChild( text );
871 text.appendChild( m_doc.createTextNode( i18n(
"&Open With") ) );
874 KTrader::OfferList::ConstIterator it = offers.begin();
875 for( ; it != offers.end(); it++ )
877 KService::Ptr service = (*it);
883 const TQString onlyShowIn = service->property(
"OnlyShowIn", TQVariant::String).toString();
884 if ( !onlyShowIn.isEmpty() ) {
885 const TQStringList aList = TQStringList::split(
';', onlyShowIn);
886 if (!aList.contains(
"KDE"))
889 const TQString notShowIn = service->property(
"NotShowIn", TQVariant::String).toString();
890 if ( !notShowIn.isEmpty() ) {
891 const TQStringList aList = TQStringList::split(
';', notShowIn);
892 if (aList.contains(
"KDE"))
899 TQString actionName( (*it)->name().replace(
"&",
"&&") );
900 if ( menu == m_menuElement )
901 actionName = i18n(
"Open with %1" ).arg( actionName );
903 act =
new KAction( actionName, (*it)->pixmap( KIcon::Small ), 0,
904 TQT_TQOBJECT(
this), TQT_SLOT( slotRunService() ),
905 &m_ownActions, nam.prepend(
"appservice_" ) );
906 addAction( act, menu );
908 m_mapPopup[
id++ ] = *it;
911 TQString openWithActionName;
912 if ( menu != m_menuElement )
914 addSeparator( menu );
915 openWithActionName = i18n(
"&Other..." );
919 openWithActionName = i18n(
"&Open With..." );
921 KAction *openWithAct =
new KAction( openWithActionName, 0, TQT_TQOBJECT(
this), TQT_SLOT( slotPopupOpenWith() ), &m_ownActions,
"openwith" );
922 addAction( openWithAct, menu );
926 act =
new KAction( i18n(
"&Open With..." ), 0, TQT_TQOBJECT(
this), TQT_SLOT( slotPopupOpenWith() ), &m_ownActions,
"openwith" );
931 addGroup(
"preview" );
935 TQDomElement actionMenu = m_menuElement;
936 int userItemCount = 0;
937 if (s.user.count() + s.userSubmenus.count() +
938 s.userPriority.count() + s.userPrioritySubmenus.count() > 1)
941 actionMenu = m_doc.createElement(
"menu" );
942 actionMenu.setAttribute(
"name",
"actions submenu" );
943 m_menuElement.appendChild( actionMenu );
944 TQDomElement text = m_doc.createElement(
"text" );
945 actionMenu.appendChild( text );
946 text.appendChild( m_doc.createTextNode( i18n(
"Ac&tions") ) );
949 userItemCount += insertServicesSubmenus(s.userPrioritySubmenus, actionMenu,
false);
950 userItemCount += insertServices(s.userPriority, actionMenu,
false);
953 if (userItemCount > 0 &&
954 (s.user.count() > 0 ||
955 s.userSubmenus.count() > 0 ||
956 s.builtin.count() > 0) &&
957 actionMenu.lastChild().toElement().tagName().lower() !=
"separator")
959 TQDomElement separator = m_doc.createElement(
"separator" );
960 actionMenu.appendChild(separator);
963 userItemCount += insertServicesSubmenus(s.userSubmenus, actionMenu,
false);
964 userItemCount += insertServices(s.user, actionMenu,
false);
965 userItemCount += insertServices(s.builtin, m_menuElement,
true);
967 userItemCount += insertServicesSubmenus(s.userToplevelSubmenus, m_menuElement,
false);
968 userItemCount += insertServices(s.userToplevel, m_menuElement,
false);
970 if ( userItemCount > 0 )
975 if ( !isCurrentTrash && !isIntoTrash && !mediaFiles && sReading )
978 if ( KPropertiesDialog::canDisplay( m_lstItems ) && (kpf & ShowProperties) )
980 act =
new KAction( i18n(
"&Properties" ), 0, TQT_TQOBJECT(
this), TQT_SLOT( slotPopupProperties() ),
981 &m_ownActions,
"properties" );
985 while ( !m_menuElement.lastChild().isNull() &&
986 m_menuElement.lastChild().toElement().tagName().lower() ==
"separator" )
987 m_menuElement.removeChild( m_menuElement.lastChild() );
989 if ( isDirectory && isLocal )
991 if ( KFileShare::authorization() == KFileShare::Authorized )
994 act =
new KAction( i18n(
"Share"), 0, TQT_TQOBJECT(
this), TQT_SLOT( slotOpenShareFileDialog() ),
995 &m_ownActions,
"sharefile" );
1003 m_factory->addClient(
this );
1006 void KonqPopupMenu::slotOpenShareFileDialog()
1008 KPropertiesDialog* dlg = showPropertiesDialog();
1009 dlg->showFileSharingPage();
1014 m_pluginList.clear();
1023 d->m_urlTitle = urlTitle;
1026 void KonqPopupMenu::slotPopupNewView()
1028 KURL::List::ConstIterator it = m_lstPopupURLs.begin();
1029 for ( ; it != m_lstPopupURLs.end(); it++ )
1030 (
void)
new KRun(*it);
1033 void KonqPopupMenu::slotPopupNewDir()
1035 if (m_lstPopupURLs.empty())
1041 void KonqPopupMenu::slotPopupEmptyTrashBin()
1043 KonqOperations::emptyTrash();
1046 void KonqPopupMenu::slotPopupRestoreTrashedItems()
1048 KonqOperations::restoreTrashedItems( m_lstPopupURLs );
1051 void KonqPopupMenu::slotPopupOpenWith()
1053 KRun::displayOpenWithDialog( m_lstPopupURLs );
1056 void KonqPopupMenu::slotPopupAddToBookmark()
1058 KBookmarkGroup root;
1059 if ( m_lstPopupURLs.count() == 1 ) {
1060 KURL url = m_lstPopupURLs.first();
1061 TQString title = d->m_urlTitle.isEmpty() ? url.prettyURL() : d->m_urlTitle;
1062 root = m_pManager->addBookmarkDialog( url.prettyURL(), title );
1066 root = m_pManager->root();
1067 KURL::List::ConstIterator it = m_lstPopupURLs.begin();
1068 for ( ; it != m_lstPopupURLs.end(); it++ )
1069 root.addBookmark( m_pManager, (*it).prettyURL(), (*it) );
1071 m_pManager->emitChanged( root );
1074 void KonqPopupMenu::slotRunService()
1076 TQCString senderName = TQT_TQOBJECT_CONST(sender())->name();
1077 int id = senderName.mid( senderName.find(
'_' ) + 1 ).toInt();
1080 TQMap<int,KService::Ptr>::Iterator it = m_mapPopup.find(
id );
1081 if ( it != m_mapPopup.end() )
1083 KRun::run( **it, m_lstPopupURLs );
1088 TQMap<int,KDEDesktopMimeType::Service>::Iterator it2 = m_mapPopupServices.find(
id );
1089 if ( it2 != m_mapPopupServices.end() )
1091 KDEDesktopMimeType::executeService( m_lstPopupURLs, it2.data() );
1097 void KonqPopupMenu::slotPopupMimeType()
1102 void KonqPopupMenu::slotPopupProperties()
1104 (void)showPropertiesDialog();
1107 KPropertiesDialog* KonqPopupMenu::showPropertiesDialog()
1113 if ( m_lstItems.count() == 1 )
1115 KFileItem * item = m_lstItems.first();
1116 if (item->entry().count() == 0)
1119 return new KPropertiesDialog( item->url(), d->m_parentWidget );
1122 return new KPropertiesDialog( m_lstItems, d->m_parentWidget );
1127 TQCString name = element.attribute( attrName ).ascii();
1128 KAction *res = m_ownActions.action( static_cast<const char *>(name) );
1131 res = m_actions.action( static_cast<const char *>(name) );
1133 if ( !res && m_pMenuNew && strcmp( name, m_pMenuNew->name() ) == 0 )
1139 KActionCollection *KonqPopupMenu::actionCollection()
const
1141 return const_cast<KActionCollection *
>( &m_ownActions );
1144 TQString KonqPopupMenu::mimeType()
const
1149 KonqPopupMenu::ProtocolInfo KonqPopupMenu::protocolInfo()
const
1154 void KonqPopupMenu::addPlugins()
1158 KTrader::OfferList plugin_offers;
1159 unsigned int pluginCount = 0;
1160 plugin_offers = KTrader::self()->query( m_sMimeType.isNull() ? TQString::fromLatin1(
"all/all" ) : m_sMimeType,
"'KonqPopupMenu/Plugin' in ServiceTypes");
1161 if ( plugin_offers.isEmpty() )
1164 KTrader::OfferList::ConstIterator iterator = plugin_offers.begin();
1165 KTrader::OfferList::ConstIterator end = plugin_offers.end();
1167 addGroup(
"plugins" );
1169 for(; iterator != end; ++iterator, ++pluginCount ) {
1171 KonqPopupMenuPlugin *plugin =
1172 KParts::ComponentFactory::
1173 createInstanceFromLibrary<KonqPopupMenuPlugin>( TQFile::encodeName( (*iterator)->library() ),
1175 (*iterator)->name().latin1() );
1179 TQString pluginClientName = TQString::fromLatin1(
"Plugin%1" ).arg( pluginCount );
1180 addMerge( pluginClientName );
1181 plugin->domDocument().documentElement().setAttribute(
"name", pluginClientName );
1182 m_pluginList.append( plugin );
1183 insertChildClient( plugin );
1187 addMerge(
"plugins" );
1190 KURL KonqPopupMenu::url() const
1195 KFileItemList KonqPopupMenu::fileItemList()
const
1200 KURL::List KonqPopupMenu::popupURLList()
const
1202 return m_lstPopupURLs;
1209 KonqPopupMenuPlugin::KonqPopupMenuPlugin(
KonqPopupMenu *parent,
const char *name )
1210 : TQObject( parent, name )
1214 KonqPopupMenuPlugin::~KonqPopupMenuPlugin()
1218 #include "konq_popupmenu.moc"