00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <qdir.h>
00022
00023 #include <klocale.h>
00024 #include <kapplication.h>
00025 #include <kbookmarkmanager.h>
00026 #include <kdebug.h>
00027 #include <krun.h>
00028 #include <kprotocolinfo.h>
00029 #include <kiconloader.h>
00030 #include <kinputdialog.h>
00031 #include <kglobalsettings.h>
00032 #include <kstandarddirs.h>
00033 #include <kxmlguifactory.h>
00034 #include <kxmlguibuilder.h>
00035 #include <kparts/componentfactory.h>
00036
00037 #include <assert.h>
00038
00039 #include <kfileshare.h>
00040 #include <kprocess.h>
00041
00042 #include "kpropertiesdialog.h"
00043 #include "knewmenu.h"
00044 #include "konq_popupmenu.h"
00045 #include "konq_operations.h"
00046 #include <dcopclient.h>
00047
00048
00049 class KonqPopupMenuGUIBuilder : public KXMLGUIBuilder
00050 {
00051 public:
00052 KonqPopupMenuGUIBuilder( QPopupMenu *menu )
00053 : KXMLGUIBuilder( 0 )
00054 {
00055 m_menu = menu;
00056 }
00057 virtual ~KonqPopupMenuGUIBuilder()
00058 {
00059 }
00060
00061 virtual QWidget *createContainer( QWidget *parent, int index,
00062 const QDomElement &element,
00063 int &id )
00064 {
00065 if ( !parent && element.attribute( "name" ) == "popupmenu" )
00066 return m_menu;
00067
00068 return KXMLGUIBuilder::createContainer( parent, index, element, id );
00069 }
00070
00071 QPopupMenu *m_menu;
00072 };
00073
00074 class KonqPopupMenu::KonqPopupMenuPrivate
00075 {
00076 public:
00077 KonqPopupMenuPrivate() : m_parentWidget(0)
00078 {
00079 m_itemFlags=KParts::BrowserExtension::DefaultPopupItems;
00080 }
00081 QString m_urlTitle;
00082 QWidget *m_parentWidget;
00083 KParts::BrowserExtension::PopupFlags m_itemFlags;
00084 };
00085
00086 KonqPopupMenu::ProtocolInfo::ProtocolInfo( )
00087 {
00088 m_Reading = false;
00089 m_Writing = false;
00090 m_Deleting = false;
00091 m_Moving = false;
00092 m_TrashIncluded = false;
00093 }
00094 bool KonqPopupMenu::ProtocolInfo::supportsReading() const
00095 {
00096 return m_Reading;
00097 }
00098 bool KonqPopupMenu::ProtocolInfo::supportsWriting() const
00099 {
00100 return m_Writing;
00101 }
00102 bool KonqPopupMenu::ProtocolInfo::supportsDeleting() const
00103 {
00104 return m_Deleting;
00105 }
00106 bool KonqPopupMenu::ProtocolInfo::supportsMoving() const
00107 {
00108 return m_Moving;
00109 }
00110 bool KonqPopupMenu::ProtocolInfo::trashIncluded() const
00111 {
00112 return m_TrashIncluded;
00113 }
00114
00115 KonqPopupMenu::KonqPopupMenu( KBookmarkManager *mgr, const KFileItemList &items,
00116 KURL viewURL,
00117 KActionCollection & actions,
00118 KNewMenu * newMenu,
00119 bool showProperties )
00120 : QPopupMenu( 0L, "konq_popupmenu" ), m_actions( actions ), m_ownActions( static_cast<QObject *>( 0 ), "KonqPopupMenu::m_ownActions" ),
00121 m_pMenuNew( newMenu ), m_sViewURL(viewURL), m_lstItems(items), m_pManager(mgr)
00122
00123 {
00124 KonqPopupFlags kpf = ( showProperties ? ShowProperties : IsLink ) | ShowNewWindow;
00125 init(0, kpf, KParts::BrowserExtension::DefaultPopupItems);
00126 }
00127
00128 KonqPopupMenu::KonqPopupMenu( KBookmarkManager *mgr, const KFileItemList &items,
00129 KURL viewURL,
00130 KActionCollection & actions,
00131 KNewMenu * newMenu,
00132 QWidget * parentWidget,
00133 bool showProperties )
00134 : QPopupMenu( parentWidget, "konq_popupmenu" ), m_actions( actions ), m_ownActions( static_cast<QObject *>( 0 ), "KonqPopupMenu::m_ownActions" ), m_pMenuNew( newMenu ), m_sViewURL(viewURL), m_lstItems(items), m_pManager(mgr)
00135 {
00136 KonqPopupFlags kpf = ( showProperties ? ShowProperties : IsLink ) | ShowNewWindow;
00137 init(parentWidget, kpf, KParts::BrowserExtension::DefaultPopupItems);
00138 }
00139
00140 KonqPopupMenu::KonqPopupMenu( KBookmarkManager *mgr, const KFileItemList &items,
00141 const KURL& viewURL,
00142 KActionCollection & actions,
00143 KNewMenu * newMenu,
00144 QWidget * parentWidget,
00145 KonqPopupFlags kpf,
00146 KParts::BrowserExtension::PopupFlags flags)
00147 : QPopupMenu( parentWidget, "konq_popupmenu" ), m_actions( actions ), m_ownActions( static_cast<QObject *>( 0 ), "KonqPopupMenu::m_ownActions" ), m_pMenuNew( newMenu ), m_sViewURL(viewURL), m_lstItems(items), m_pManager(mgr)
00148 {
00149 init(parentWidget, kpf, flags);
00150 }
00151
00152 void KonqPopupMenu::init (QWidget * parentWidget, KonqPopupFlags kpf, KParts::BrowserExtension::PopupFlags flags)
00153 {
00154 d = new KonqPopupMenuPrivate;
00155 d->m_parentWidget = parentWidget;
00156 d->m_itemFlags = flags;
00157 setup(kpf);
00158 }
00159
00160
00161 int KonqPopupMenu::insertServicesSubmenus(const QMap<QString, ServiceList>& submenus,
00162 QDomElement& menu,
00163 bool isBuiltin)
00164 {
00165 int count = 0;
00166 QMap<QString, ServiceList>::ConstIterator it;
00167
00168 for (it = submenus.begin(); it != submenus.end(); ++it)
00169 {
00170 if (it.data().isEmpty())
00171 {
00172
00173 continue;
00174 }
00175
00176 QDomElement actionSubmenu = m_doc.createElement( "menu" );
00177 actionSubmenu.setAttribute( "name", "actions " + it.key() );
00178 menu.appendChild( actionSubmenu );
00179 QDomElement subtext = m_doc.createElement( "text" );
00180 actionSubmenu.appendChild( subtext );
00181 subtext.appendChild( m_doc.createTextNode( it.key() ) );
00182 count += insertServices(it.data(), actionSubmenu, isBuiltin);
00183 }
00184
00185 return count;
00186 }
00187
00188 int KonqPopupMenu::insertServices(const ServiceList& list,
00189 QDomElement& menu,
00190 bool isBuiltin)
00191 {
00192 static int id = 1000;
00193 int count = 0;
00194
00195 ServiceList::const_iterator it = list.begin();
00196 for( ; it != list.end(); ++it )
00197 {
00198 if ((*it).isEmpty())
00199 {
00200 if (!menu.firstChild().isNull() &&
00201 menu.lastChild().toElement().tagName().lower() != "separator")
00202 {
00203 QDomElement separator = m_doc.createElement( "separator" );
00204 menu.appendChild(separator);
00205 }
00206 continue;
00207 }
00208
00209 if (isBuiltin || (*it).m_display == true)
00210 {
00211 QCString name;
00212 name.setNum( id );
00213 name.prepend( isBuiltin ? "builtinservice_" : "userservice_" );
00214 KAction * act = new KAction( (*it).m_strName, 0,
00215 this, SLOT( slotRunService() ),
00216 &m_ownActions, name );
00217
00218 if ( !(*it).m_strIcon.isEmpty() )
00219 {
00220 QPixmap pix = SmallIcon( (*it).m_strIcon );
00221 act->setIconSet( pix );
00222 }
00223
00224 addAction( act, menu );
00225
00226 m_mapPopupServices[ id++ ] = *it;
00227 ++count;
00228 }
00229 }
00230
00231 return count;
00232 }
00233
00234 bool KonqPopupMenu::KIOSKAuthorizedAction(KConfig& cfg)
00235 {
00236 if ( !cfg.hasKey( "X-KDE-AuthorizeAction") )
00237 {
00238 return true;
00239 }
00240
00241 QStringList list = cfg.readListEntry("X-KDE-AuthorizeAction");
00242 if (kapp && !list.isEmpty())
00243 {
00244 for(QStringList::ConstIterator it = list.begin();
00245 it != list.end();
00246 ++it)
00247 {
00248 if (!kapp->authorize((*it).stripWhiteSpace()))
00249 {
00250 return false;
00251 }
00252 }
00253 }
00254
00255 return true;
00256 }
00257
00258
00259 void KonqPopupMenu::setup(KonqPopupFlags kpf)
00260 {
00261 assert( m_lstItems.count() >= 1 );
00262
00263 m_ownActions.setWidget( this );
00264
00265 bool bIsLink = (kpf & IsLink);
00266 bool currentDir = false;
00267 bool sReading = true;
00268 bool sWriting = true;
00269 bool sDeleting = true;
00270 bool sMoving = true;
00271 m_sMimeType = m_lstItems.first()->mimetype();
00272 QString mimeGroup = m_sMimeType.left(m_sMimeType.find('/'));
00273 mode_t mode = m_lstItems.first()->mode();
00274 bool isDirectory = m_sMimeType == "inode/directory";
00275 bool bTrashIncluded = false;
00276 bool bCanChangeSharing = false;
00277 m_lstPopupURLs.clear();
00278 int id = 0;
00279 if( isDirectory && m_lstItems.first()->isLocalFile())
00280 bCanChangeSharing=true;
00281 setFont(KGlobalSettings::menuFont());
00282 m_pluginList.setAutoDelete( true );
00283 m_ownActions.setHighlightingEnabled( true );
00284
00285 attrName = QString::fromLatin1( "name" );
00286
00287 prepareXMLGUIStuff();
00288 m_builder = new KonqPopupMenuGUIBuilder( this );
00289 m_factory = new KXMLGUIFactory( m_builder );
00290
00291 KURL url;
00292 KFileItemListIterator it ( m_lstItems );
00293
00294 bool devicesFile = false;
00295 for ( ; it.current(); ++it )
00296 {
00297 url = (*it)->url();
00298
00299
00300 m_lstPopupURLs.append( url );
00301
00302
00303 if ( mode != (*it)->mode() )
00304 mode = 0;
00305
00306
00307 if ( m_sMimeType != (*it)->mimetype() )
00308 {
00309 m_sMimeType = QString::null;
00310
00311 if ( mimeGroup != (*it)->mimetype().left((*it)->mimetype().find('/')))
00312 mimeGroup = QString::null;
00313 }
00314
00315 if ( !bTrashIncluded &&
00316 (*it)->url().isLocalFile() &&
00317 (*it)->url().path( 1 ) == KGlobalSettings::trashPath() )
00318 bTrashIncluded = true;
00319
00320 if ( sReading )
00321 sReading = KProtocolInfo::supportsReading( url );
00322
00323 if ( sWriting )
00324 sWriting = KProtocolInfo::supportsWriting( url );
00325
00326 if ( sDeleting )
00327 sDeleting = KProtocolInfo::supportsDeleting( url );
00328
00329 if ( sMoving )
00330 sMoving = KProtocolInfo::supportsMoving( url );
00331 if ( url.protocol().find("device", 0, false)==0)
00332 devicesFile = true;
00333 }
00334
00335 if ( bTrashIncluded )
00336 {
00337 sMoving = false;
00338 sDeleting = false;
00339 }
00340
00341 url = m_sViewURL;
00342 url.cleanPath();
00343
00344 m_info.m_Reading = sReading;
00345 m_info.m_Writing = sWriting;
00346 m_info.m_Deleting = sDeleting;
00347 m_info.m_Moving = sMoving;
00348 m_info.m_TrashIncluded = bTrashIncluded;
00349
00350
00351 if ( m_lstItems.count() == 1 )
00352 {
00353 KURL firstPopupURL ( m_lstItems.first()->url() );
00354 firstPopupURL.cleanPath();
00355
00356
00357 currentDir = firstPopupURL.equals( url, true );
00358 }
00359
00360 bool isCurrentTrash = ( url.isLocalFile() &&
00361 url.path(1) == KGlobalSettings::trashPath() &&
00362 currentDir) ||
00363 ( m_lstItems.count() == 1 && bTrashIncluded );
00364 bool isIntoTrash = url.isLocalFile() && url.path(1).startsWith(KGlobalSettings::trashPath());
00365 clear();
00366
00368
00369 KAction * act;
00370
00371 if (!isCurrentTrash)
00372 addMerge( "konqueror" );
00373
00374 bool isKDesktop = QCString( kapp->name() ) == "kdesktop";
00375 KAction *actNewWindow = 0;
00376
00377 if (( kpf & ShowProperties ) && isKDesktop &&
00378 !kapp->authorize("editable_desktop_icons"))
00379 {
00380 kpf &= ~ShowProperties;
00381 }
00382
00383
00384
00385 if ( ((kpf & ShowNewWindow) != 0) && sReading )
00386 {
00387 QString openStr = isKDesktop ? i18n( "&Open" ) : i18n( "Open in New &Window" );
00388 actNewWindow = new KAction( openStr, "window_new", 0, this, SLOT( slotPopupNewView() ), &m_ownActions, "newview" );
00389 }
00390
00391 if ( actNewWindow && !isKDesktop )
00392 {
00393 if (isCurrentTrash)
00394 actNewWindow->setStatusText( i18n( "Open the trash in a new window" ) );
00395 else
00396 actNewWindow->setStatusText( i18n( "Open the document in a new window" ) );
00397 }
00398
00399 if ( isCurrentTrash )
00400 {
00401 if (actNewWindow)
00402 {
00403 addAction( actNewWindow );
00404 addSeparator();
00405 }
00406 addGroup( "tabhandling" );
00407
00408 act = new KAction( i18n( "&Empty Trash Bin" ), 0, this, SLOT( slotPopupEmptyTrashBin() ), &m_ownActions, "empytrash" );
00409 addAction( act );
00410 if ( KPropertiesDialog::canDisplay( m_lstItems ) && (kpf & ShowProperties) )
00411 {
00412 act = new KAction( i18n( "&Properties" ), 0, this, SLOT( slotPopupProperties() ),
00413 &m_ownActions, "properties" );
00414 addAction( act );
00415 }
00416 m_factory->addClient( this );
00417 return;
00418 }
00419 else
00420 {
00421 if ( S_ISDIR(mode) && sWriting && !isIntoTrash )
00422 {
00423 if ( currentDir && m_pMenuNew )
00424 {
00425
00426 m_pMenuNew->slotCheckUpToDate();
00427 m_pMenuNew->setPopupFiles( m_lstPopupURLs );
00428
00429 addAction( m_pMenuNew );
00430
00431 addSeparator();
00432 }
00433 else
00434 {
00435 if (d->m_itemFlags & KParts::BrowserExtension::ShowCreateDirectory)
00436 {
00437 KAction *actNewDir = new KAction( i18n( "Create &Folder..." ), "folder_new", 0, this, SLOT( slotPopupNewDir() ), &m_ownActions, "newdir" );
00438 addAction( actNewDir );
00439 addSeparator();
00440 }
00441 }
00442 }
00443
00444 if (d->m_itemFlags & KParts::BrowserExtension::ShowNavigationItems)
00445 {
00446 addAction( "back" );
00447 addAction( "forward" );
00448 if (d->m_itemFlags & KParts::BrowserExtension::ShowUp)
00449 addAction( "up" );
00450 if (d->m_itemFlags & KParts::BrowserExtension::ShowReload)
00451 addAction( "reload" );
00452 addSeparator();
00453 }
00454
00455
00456 if (actNewWindow)
00457 {
00458 addAction( actNewWindow );
00459 addSeparator();
00460 }
00461 addGroup( "tabhandling" );
00462
00463 if ( !bIsLink )
00464 {
00465 if ( !currentDir && sReading && !isIntoTrash &&!devicesFile ) {
00466 if ( sDeleting ) {
00467 addAction( "cut" );
00468 }
00469 addAction( "copy" );
00470 }
00471
00472 if ( S_ISDIR(mode) && sWriting && !isIntoTrash) {
00473 if ( currentDir )
00474 addAction( "paste" );
00475 else
00476 addAction( "pasteto" );
00477 }
00478 if ( !isIntoTrash )
00479 {
00480 if (!currentDir )
00481 {
00482 if ( m_lstItems.count() == 1 && sWriting )
00483 addAction("rename");
00484
00485 if ( sMoving )
00486 addAction( "trash" );
00487
00488 if ( sDeleting ) {
00489 addAction( "del" );
00490 }
00491 }
00492 }
00493 }
00494 addGroup( "editactions" );
00495 }
00496
00497 if (d->m_itemFlags & KParts::BrowserExtension::ShowTextSelectionItems) {
00498 addMerge( 0 );
00499 m_factory->addClient( this );
00500 return;
00501 }
00502
00503 if ( !isCurrentTrash && !isIntoTrash && (d->m_itemFlags & KParts::BrowserExtension::ShowBookmark))
00504 {
00505 addSeparator();
00506 QString caption;
00507 if (currentDir)
00508 {
00509 bool httpPage = (m_sViewURL.protocol().find("http", 0, false) == 0);
00510 if (httpPage)
00511 caption = i18n("&Bookmark This Page");
00512 else
00513 caption = i18n("&Bookmark This Location");
00514 }
00515 else if (S_ISDIR(mode))
00516 caption = i18n("&Bookmark This Folder");
00517 else if (bIsLink)
00518 caption = i18n("&Bookmark This Link");
00519 else
00520 caption = i18n("&Bookmark This File");
00521
00522 act = new KAction( caption, "bookmark_add", 0, this, SLOT( slotPopupAddToBookmark() ), &m_ownActions, "bookmark_add" );
00523 if (m_lstItems.count() > 1)
00524 act->setEnabled(false);
00525 if (kapp->authorizeKAction("bookmarks"))
00526 addAction( act );
00527 if (bIsLink)
00528 addGroup( "linkactions" );
00529 }
00530
00532
00533 ServiceList builtin;
00534 ServiceList user, userToplevel, userPriority;
00535 QMap<QString, ServiceList> userSubmenus, userToplevelSubmenus, userPrioritySubmenus;
00536
00537 bool isSingleLocal = (m_lstItems.count() == 1 && m_lstItems.first()->url().isLocalFile());
00538
00539 if ( m_sMimeType == "application/x-desktop" && isSingleLocal )
00540 {
00541
00542 builtin = KDEDesktopMimeType::builtinServices( m_lstItems.first()->url() );
00543 user = KDEDesktopMimeType::userDefinedServices( m_lstItems.first()->url().path(), url.isLocalFile() );
00544 }
00545
00546 if ( !isCurrentTrash && !isIntoTrash && sReading)
00547 {
00548
00549
00550
00551
00552 if (isDirectory && isSingleLocal)
00553 {
00554 QString dotDirectoryFile = m_lstItems.first()->url().path(1).append(".directory");
00555 KSimpleConfig cfg( dotDirectoryFile, true );
00556 cfg.setDesktopGroup();
00557
00558 if (KIOSKAuthorizedAction(cfg))
00559 {
00560 QString submenuName = cfg.readEntry( "X-KDE-Submenu" );
00561 if (submenuName.isEmpty())
00562 {
00563 user += KDEDesktopMimeType::userDefinedServices( dotDirectoryFile, true );
00564 }
00565 else
00566 {
00567 userSubmenus[submenuName] += KDEDesktopMimeType::userDefinedServices( dotDirectoryFile, true );
00568 }
00569 }
00570 }
00571
00572 QStringList dirs = KGlobal::dirs()->findDirs( "data", "konqueror/servicemenus/" );
00573 QStringList::ConstIterator dIt = dirs.begin();
00574 QStringList::ConstIterator dEnd = dirs.end();
00575
00576 for (; dIt != dEnd; ++dIt )
00577 {
00578 QDir dir( *dIt );
00579
00580 QStringList entries = dir.entryList( "*.desktop", QDir::Files );
00581 QStringList::ConstIterator eIt = entries.begin();
00582 QStringList::ConstIterator eEnd = entries.end();
00583
00584 for (; eIt != eEnd; ++eIt )
00585 {
00586 KSimpleConfig cfg( *dIt + *eIt, true );
00587 cfg.setDesktopGroup();
00588
00589 if (!KIOSKAuthorizedAction(cfg))
00590 {
00591 continue;
00592 }
00593
00594 if ( cfg.hasKey( "X-KDE-ShowIfRunning" ) )
00595 {
00596 QString app = cfg.readEntry( "X-KDE-ShowIfRunning" );
00597 if ( !kapp->dcopClient()->isApplicationRegistered( app.utf8() ) )
00598 continue;
00599 }
00600
00601 if ( cfg.hasKey( "Actions" ) && cfg.hasKey( "ServiceTypes" ) )
00602 {
00603 QStringList types = cfg.readListEntry( "ServiceTypes" );
00604 QStringList excludeTypes = cfg.readListEntry( "ExcludeServiceTypes" );
00605 bool ok = false;
00606
00607
00608 for (QStringList::iterator it = types.begin();
00609 it != types.end() && !ok;
00610 ++it)
00611 {
00612
00613
00614
00615
00616
00617 if (*it == "all/all" ||
00618 *it == "allfiles" )
00619 {
00620 ok = true;
00621 for (QStringList::iterator itex = excludeTypes.begin(); itex != excludeTypes.end(); ++itex)
00622 {
00623 if( ((*itex).right(1) == "*" && (*itex).left((*itex).find('/')) == mimeGroup) ||
00624 ((*itex) == m_sMimeType) )
00625 {
00626 ok = false;
00627 break;
00628 }
00629 }
00630 }
00631
00632
00633 if (!ok &&
00634 !isDirectory &&
00635 *it == "all/allfiles")
00636 {
00637 ok = true;
00638 for (QStringList::iterator itex = excludeTypes.begin(); itex != excludeTypes.end(); ++itex)
00639 {
00640 if( ((*itex).right(1) == "*" && (*itex).left((*itex).find('/')) == mimeGroup) ||
00641 ((*itex) == m_sMimeType) )
00642 {
00643 ok = false;
00644 break;
00645 }
00646 }
00647
00648 }
00649
00650
00651 if (!ok &&
00652 (!m_sMimeType.isEmpty() &&
00653 *it == m_sMimeType) ||
00654 (!mimeGroup.isEmpty() &&
00655 ((*it).right(1) == "*" &&
00656 (*it).left((*it).find('/')) == mimeGroup)))
00657 {
00658 ok = true;
00659 for (QStringList::iterator itex = excludeTypes.begin(); itex != excludeTypes.end(); ++itex)
00660 {
00661 if( ((*itex).right(1) == "*" && (*itex).left((*itex).find('/')) == mimeGroup) ||
00662 ((*itex) == m_sMimeType) )
00663 {
00664 ok = false;
00665 break;
00666 }
00667 }
00668 }
00669 }
00670
00671 if ( ok )
00672 {
00673
00674
00675 QString priority = cfg.readEntry("X-KDE-Priority");
00676 QString submenuName = cfg.readEntry( "X-KDE-Submenu" );
00677 ServiceList* list = &user;
00678
00679 if (submenuName.isEmpty())
00680 {
00681 if (priority == "TopLevel")
00682 {
00683 list = &userToplevel;
00684 }
00685 else if (priority == "Important")
00686 {
00687 list = &userPriority;
00688 }
00689 }
00690 else if (priority == "TopLevel")
00691 {
00692 list = &(userToplevelSubmenus[submenuName]);
00693 }
00694 else if (priority == "Important")
00695 {
00696 list = &(userPrioritySubmenus[submenuName]);
00697 }
00698 else
00699 {
00700 list = &(userSubmenus[submenuName]);
00701 }
00702
00703 (*list) += KDEDesktopMimeType::userDefinedServices( *dIt + *eIt, url.isLocalFile() );
00704 }
00705 }
00706 }
00707 }
00708
00709 KTrader::OfferList offers;
00710
00711 if (kapp->authorizeKAction("openwith"))
00712 {
00713
00714
00715 offers = KTrader::self()->query( m_sMimeType.isNull( ) ? QString::fromLatin1( "all/all" ) : m_sMimeType ,
00716 "Type == 'Application' and DesktopEntryName != 'kfmclient' and DesktopEntryName != 'kfmclient_dir' and DesktopEntryName != 'kfmclient_html'" );
00717 }
00718
00720
00721 m_mapPopup.clear();
00722 m_mapPopupServices.clear();
00723 if ( !devicesFile)
00724 {
00725 if ( !offers.isEmpty() )
00726 {
00727
00728 addSeparator();
00729
00730 id = 1;
00731
00732 QDomElement menu = m_menuElement;
00733
00734 if ( offers.count() > 1 )
00735 {
00736 menu = m_doc.createElement( "menu" );
00737 menu.setAttribute( "name", "openwith submenu" );
00738 m_menuElement.appendChild( menu );
00739 QDomElement text = m_doc.createElement( "text" );
00740 menu.appendChild( text );
00741 text.appendChild( m_doc.createTextNode( i18n("&Open With") ) );
00742 }
00743
00744 if ( menu == m_menuElement )
00745 {
00746 KAction *openWithAct = new KAction( i18n( "&Open With..." ), 0, this, SLOT( slotPopupOpenWith() ), &m_ownActions, "openwith" );
00747 addAction( openWithAct, menu );
00748 }
00749
00750 KTrader::OfferList::ConstIterator it = offers.begin();
00751 for( ; it != offers.end(); it++ )
00752 {
00753 QCString nam;
00754 nam.setNum( id );
00755
00756 act = new KAction( (*it)->name(), (*it)->pixmap( KIcon::Small ), 0,
00757 this, SLOT( slotRunService() ),
00758 &m_ownActions, nam.prepend( "appservice_" ) );
00759 addAction( act, menu );
00760
00761 m_mapPopup[ id++ ] = *it;
00762 }
00763
00764 if ( menu != m_menuElement )
00765 {
00766 addSeparator( menu );
00767 KAction *openWithAct = new KAction( i18n( "&Other..." ), 0, this, SLOT( slotPopupOpenWith() ), &m_ownActions, "openwith" );
00768 addAction( openWithAct, menu );
00769 }
00770 }
00771 else
00772 {
00773 addSeparator();
00774 act = new KAction( i18n( "&Open With..." ), 0, this, SLOT( slotPopupOpenWith() ), &m_ownActions, "openwith" );
00775 addAction( act );
00776 }
00777
00778 addGroup( "preview" );
00779 }
00780 }
00781
00782
00783 QDomElement actionMenu = m_menuElement;
00784 int userItemCount = 0;
00785 if (user.count() + userSubmenus.count() +
00786 userPriority.count() + userPrioritySubmenus.count() > 1)
00787 {
00788
00789 actionMenu = m_doc.createElement( "menu" );
00790 actionMenu.setAttribute( "name", "actions submenu" );
00791 m_menuElement.appendChild( actionMenu );
00792 QDomElement text = m_doc.createElement( "text" );
00793 actionMenu.appendChild( text );
00794 text.appendChild( m_doc.createTextNode( i18n("Ac&tions") ) );
00795 }
00796
00797 userItemCount += insertServicesSubmenus(userPrioritySubmenus, actionMenu, false);
00798 userItemCount += insertServices(userPriority, actionMenu, false);
00799
00800
00801 if (userItemCount > 0 &&
00802 (user.count() > 0 ||
00803 userSubmenus.count() > 0 ||
00804 builtin.count() > 0) &&
00805 actionMenu.lastChild().toElement().tagName().lower() != "separator")
00806 {
00807 QDomElement separator = m_doc.createElement( "separator" );
00808 actionMenu.appendChild(separator);
00809 }
00810
00811 userItemCount += insertServicesSubmenus(userSubmenus, actionMenu, false);
00812 userItemCount += insertServices(user, actionMenu, false);
00813 userItemCount += insertServices(builtin, m_menuElement, true);
00814
00815 userItemCount += insertServicesSubmenus(userToplevelSubmenus, m_menuElement, false);
00816 userItemCount += insertServices(userToplevel, m_menuElement, false);
00817
00818 if (userItemCount > 0)
00819 {
00820 addSeparator();
00821 }
00822
00823 if ( !isCurrentTrash && !isIntoTrash && !devicesFile && sReading)
00824 addPlugins( );
00825
00826 if ( KPropertiesDialog::canDisplay( m_lstItems ) && (kpf & ShowProperties) )
00827 {
00828 act = new KAction( i18n( "&Properties" ), 0, this, SLOT( slotPopupProperties() ),
00829 &m_ownActions, "properties" );
00830 addAction( act );
00831 }
00832
00833 while ( !m_menuElement.lastChild().isNull() &&
00834 m_menuElement.lastChild().toElement().tagName().lower() == "separator" )
00835 m_menuElement.removeChild( m_menuElement.lastChild() );
00836
00837 if( bCanChangeSharing && !isCurrentTrash && !isIntoTrash )
00838 {
00839 if(KFileShare::authorization()==KFileShare::Authorized)
00840 {
00841 addSeparator();
00842 act = new KAction( i18n("Share"), 0, this, SLOT( slotOpenShareFileDialog() ),
00843 &m_ownActions, "sharefile" );
00844 addAction( act );
00845 }
00846 }
00847
00848
00849 addMerge( 0 );
00850
00851 m_factory->addClient( this );
00852 }
00853
00854 void KonqPopupMenu::slotOpenShareFileDialog()
00855 {
00856
00857
00858
00859
00860
00861 if ( m_lstItems.count() == 1 )
00862 {
00863 KFileItem * item = m_lstItems.first();
00864 if (item->entry().count() == 0)
00865 {
00866
00867 KPropertiesDialog*dlg= new KPropertiesDialog( item->url(), d->m_parentWidget );
00868 dlg->showFileSharingPage();
00869
00870 return;
00871 }
00872 }
00873 KPropertiesDialog*dlg=new KPropertiesDialog( m_lstItems, d->m_parentWidget );
00874 dlg->showFileSharingPage();
00875 }
00876
00877 KonqPopupMenu::~KonqPopupMenu()
00878 {
00879 m_pluginList.clear();
00880 delete m_factory;
00881 delete m_builder;
00882 delete d;
00883 kdDebug(1203) << "~KonqPopupMenu leave" << endl;
00884 }
00885
00886 void KonqPopupMenu::setURLTitle( const QString& urlTitle )
00887 {
00888 d->m_urlTitle = urlTitle;
00889 }
00890
00891 void KonqPopupMenu::slotPopupNewView()
00892 {
00893 KURL::List::ConstIterator it = m_lstPopupURLs.begin();
00894 for ( ; it != m_lstPopupURLs.end(); it++ )
00895 (void) new KRun(*it);
00896 }
00897
00898 void KonqPopupMenu::slotPopupNewDir()
00899 {
00900 if (m_lstPopupURLs.empty())
00901 return;
00902
00903 KonqOperations::newDir(d->m_parentWidget, m_lstPopupURLs.first());
00904 }
00905
00906 void KonqPopupMenu::slotPopupEmptyTrashBin()
00907 {
00908 KonqOperations::emptyTrash();
00909 }
00910
00911 void KonqPopupMenu::slotPopupOpenWith()
00912 {
00913 KRun::displayOpenWithDialog( m_lstPopupURLs );
00914 }
00915
00916 void KonqPopupMenu::slotPopupAddToBookmark()
00917 {
00918 KBookmarkGroup root;
00919 if ( m_lstPopupURLs.count() == 1 ) {
00920 KURL url = m_lstPopupURLs.first();
00921 QString title = d->m_urlTitle.isEmpty() ? url.prettyURL() : d->m_urlTitle;
00922 root = m_pManager->addBookmarkDialog( url.prettyURL(), title );
00923 }
00924 else
00925 {
00926 root = m_pManager->root();
00927 KURL::List::ConstIterator it = m_lstPopupURLs.begin();
00928 for ( ; it != m_lstPopupURLs.end(); it++ )
00929 root.addBookmark( m_pManager, (*it).prettyURL(), (*it) );
00930 }
00931 m_pManager->emitChanged( root );
00932 }
00933
00934 void KonqPopupMenu::slotRunService()
00935 {
00936 QCString senderName = sender()->name();
00937 int id = senderName.mid( senderName.find( '_' ) + 1 ).toInt();
00938
00939
00940 QMap<int,KService::Ptr>::Iterator it = m_mapPopup.find( id );
00941 if ( it != m_mapPopup.end() )
00942 {
00943 KRun::run( **it, m_lstPopupURLs );
00944 return;
00945 }
00946
00947
00948 QMap<int,KDEDesktopMimeType::Service>::Iterator it2 = m_mapPopupServices.find( id );
00949 if ( it2 != m_mapPopupServices.end() )
00950 {
00951 KDEDesktopMimeType::executeService( m_lstPopupURLs, it2.data() );
00952 }
00953
00954 return;
00955 }
00956
00957 void KonqPopupMenu::slotPopupMimeType()
00958 {
00959 KonqOperations::editMimeType( m_sMimeType );
00960 }
00961
00962 void KonqPopupMenu::slotPopupProperties()
00963 {
00964
00965
00966
00967
00968 if ( m_lstItems.count() == 1 )
00969 {
00970 KFileItem * item = m_lstItems.first();
00971 if (item->entry().count() == 0)
00972 {
00973
00974 (void) new KPropertiesDialog( item->url(), d->m_parentWidget );
00975 return;
00976 }
00977 }
00978 (void) new KPropertiesDialog( m_lstItems, d->m_parentWidget );
00979 }
00980
00981 KAction *KonqPopupMenu::action( const QDomElement &element ) const
00982 {
00983 QCString name = element.attribute( attrName ).ascii();
00984 KAction *res = m_ownActions.action( name );
00985
00986 if ( !res )
00987 res = m_actions.action( name );
00988
00989 if ( !res && m_pMenuNew && strcmp( name, m_pMenuNew->name() ) == 0 )
00990 return m_pMenuNew;
00991
00992 return res;
00993 }
00994 KActionCollection *KonqPopupMenu::actionCollection() const
00995 {
00996 return const_cast<KActionCollection *>( &m_ownActions );
00997 }
00998
00999 QString KonqPopupMenu::mimeType( ) const {
01000 return m_sMimeType;
01001 }
01002 KonqPopupMenu::ProtocolInfo KonqPopupMenu::protocolInfo() const
01003 {
01004 return m_info;
01005 }
01006 void KonqPopupMenu::addPlugins( ){
01007
01008
01009 KTrader::OfferList plugin_offers;
01010 unsigned int pluginCount = 0;
01011 plugin_offers = KTrader::self()->query( m_sMimeType.isNull() ? QString::fromLatin1( "all/all" ) : m_sMimeType , "'KonqPopupMenu/Plugin' in ServiceTypes");
01012 if ( plugin_offers.isEmpty() )
01013 return;
01014
01015 KTrader::OfferList::ConstIterator iterator = plugin_offers.begin( );
01016 KTrader::OfferList::ConstIterator end = plugin_offers.end( );
01017
01018 addGroup( "plugins" );
01019
01020 for(; iterator != end; ++iterator, ++pluginCount ){
01021 KonqPopupMenuPlugin *plugin =
01022 KParts::ComponentFactory::
01023 createInstanceFromLibrary<KonqPopupMenuPlugin>( (*iterator)->library().local8Bit(),
01024 this,
01025 (*iterator)->name().latin1() );
01026 if ( !plugin )
01027 continue;
01028 QString pluginClientName = QString::fromLatin1( "Plugin%1" ).arg( pluginCount );
01029 addMerge( pluginClientName );
01030 plugin->domDocument().documentElement().setAttribute( "name", pluginClientName );
01031 m_pluginList.append( plugin );
01032 insertChildClient( plugin );
01033 }
01034
01035 addMerge( "plugins" );
01036 addSeparator();
01037 }
01038 KURL KonqPopupMenu::url( ) const {
01039 return m_sViewURL;
01040 }
01041 KFileItemList KonqPopupMenu::fileItemList( ) const {
01042 return m_lstItems;
01043 }
01044 KURL::List KonqPopupMenu::popupURLList( ) const {
01045 return m_lstPopupURLs;
01046 }
01051 KonqPopupMenuPlugin::KonqPopupMenuPlugin( KonqPopupMenu *parent, const char *name )
01052 : QObject( parent, name ) {
01053 }
01054 KonqPopupMenuPlugin::~KonqPopupMenuPlugin( ){
01055
01056 }
01057 #include "konq_popupmenu.moc"