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>
|
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>
|
1999-07-05 13:47:57 +00:00
|
|
|
#include <qclipboard.h>
|
|
|
|
#include <qapplication.h>
|
|
|
|
#include <qdragobject.h>
|
1999-04-27 09:04:36 +00:00
|
|
|
|
2000-04-04 22:24:42 +00:00
|
|
|
#include <krun.h>
|
1999-04-27 09:04:36 +00:00
|
|
|
#include <kbookmark.h>
|
1999-05-24 20:04:01 +00:00
|
|
|
#include <kdebug.h>
|
2000-02-19 20:30:21 +00:00
|
|
|
#include <kio/job.h>
|
|
|
|
#include <kio/paste.h>
|
2000-02-19 23:15:17 +00:00
|
|
|
#include <kopenwith.h>
|
1999-09-02 21:09:32 +00:00
|
|
|
#include <kmessagebox.h>
|
1999-04-27 09:04:36 +00:00
|
|
|
#include <kprotocolmanager.h>
|
1999-10-20 22:54:37 +00:00
|
|
|
#include <kservice.h>
|
1999-05-31 07:15:48 +00:00
|
|
|
#include <ktrader.h>
|
1999-04-27 09:04:36 +00:00
|
|
|
#include <kurl.h>
|
|
|
|
#include <kuserprofile.h>
|
2000-03-17 16:35:18 +00:00
|
|
|
#include <kglobalsettings.h>
|
1999-08-08 19:53:28 +00:00
|
|
|
#include <kglobal.h>
|
|
|
|
#include <kstddirs.h>
|
2000-04-01 17:09:44 +00:00
|
|
|
#include <kxmlgui.h>
|
|
|
|
#include <kxmlguibuilder.h>
|
1999-04-27 09:04:36 +00:00
|
|
|
|
1999-10-17 15:19:54 +00:00
|
|
|
#include <assert.h>
|
|
|
|
|
1999-04-27 09:45:54 +00:00
|
|
|
#include "kpropsdlg.h"
|
1999-04-27 09:04:36 +00:00
|
|
|
#include "knewmenu.h"
|
1999-10-17 15:19:54 +00:00
|
|
|
#include "konqpopupmenu.h"
|
2000-04-15 15:22:56 +00:00
|
|
|
#include "konqoperations.h"
|
1999-04-27 09:04:36 +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,
|
|
|
|
const QDomElement &element, const QByteArray &containerStateBuffer,
|
|
|
|
int &id )
|
|
|
|
{
|
|
|
|
if ( !parent && element.attribute( "name" ) == "popupmenu" )
|
|
|
|
return m_menu;
|
|
|
|
|
|
|
|
return KXMLGUIBuilder::createContainer( parent, index, element, containerStateBuffer, id );
|
|
|
|
}
|
|
|
|
|
|
|
|
QPopupMenu *m_menu;
|
|
|
|
};
|
|
|
|
|
2000-04-10 15:59:25 +00:00
|
|
|
KonqPopupMenu::KonqPopupMenu( const KFileItemList &items,
|
2000-02-19 20:30:21 +00:00
|
|
|
KURL viewURL,
|
2000-03-25 07:07:56 +00:00
|
|
|
KActionCollection & actions,
|
2000-04-08 15:55:05 +00:00
|
|
|
KNewMenu * newMenu )
|
2000-04-01 17:09:44 +00:00
|
|
|
: QPopupMenu( 0L, "konq_popupmenu" ), m_actions( actions ), m_pMenuNew( newMenu ),
|
1999-10-17 15:19:54 +00:00
|
|
|
m_sViewURL(viewURL), m_lstItems(items)
|
1999-04-27 09:04:36 +00:00
|
|
|
{
|
1999-08-04 10:50:58 +00:00
|
|
|
assert( m_lstItems.count() >= 1 );
|
1999-04-27 09:04:36 +00:00
|
|
|
|
|
|
|
bool currentDir = false;
|
|
|
|
bool sReading = true;
|
|
|
|
bool sWriting = true;
|
|
|
|
bool sDeleting = true;
|
|
|
|
bool sMoving = true;
|
1999-09-24 22:47:25 +00:00
|
|
|
m_sMimeType = m_lstItems.first()->mimetype();
|
2000-03-18 15:19:43 +00:00
|
|
|
mode_t mode = m_lstItems.first()->mode();
|
1999-08-04 10:50:58 +00:00
|
|
|
m_lstPopupURLs.clear();
|
1999-04-27 09:04:36 +00:00
|
|
|
int id;
|
|
|
|
|
2000-03-22 07:06:56 +00:00
|
|
|
setFont(KGlobal::menuFont());
|
|
|
|
|
2000-04-01 17:09:44 +00:00
|
|
|
attrName = QString::fromLatin1( "name" );
|
2000-04-04 22:24:42 +00:00
|
|
|
|
2000-04-01 17:09:44 +00:00
|
|
|
prepareXMLGUIStuff();
|
|
|
|
|
1999-04-27 09:04:36 +00:00
|
|
|
KProtocolManager pManager = KProtocolManager::self();
|
1999-12-18 20:30:37 +00:00
|
|
|
|
1999-04-27 09:04:36 +00:00
|
|
|
KURL url;
|
2000-04-10 15:59:25 +00:00
|
|
|
KFileItemListIterator it ( m_lstItems );
|
1999-04-27 09:04:36 +00:00
|
|
|
// Check whether all URLs are correct
|
1999-08-04 10:50:58 +00:00
|
|
|
for ( ; it.current(); ++it )
|
1999-04-27 09:04:36 +00:00
|
|
|
{
|
1999-08-04 10:50:58 +00:00
|
|
|
url = (*it)->url();
|
1999-04-27 09:04:36 +00:00
|
|
|
|
1999-08-04 10:50:58 +00:00
|
|
|
// Build the list of URLs
|
2000-02-19 20:30:21 +00:00
|
|
|
m_lstPopupURLs.append( url );
|
1999-04-27 09:04:36 +00:00
|
|
|
|
1999-08-04 10:50:58 +00:00
|
|
|
// Determine if common mode among all URLs
|
|
|
|
if ( mode != (*it)->mode() )
|
|
|
|
mode = 0; // modes are different => reset to 0
|
|
|
|
|
|
|
|
// Determine if common mimetype among all URLs
|
1999-09-24 22:47:25 +00:00
|
|
|
if ( m_sMimeType != (*it)->mimetype() )
|
|
|
|
m_sMimeType = QString::null; // mimetypes are different => null
|
1999-08-04 10:50:58 +00:00
|
|
|
|
2000-03-18 15:19:43 +00:00
|
|
|
QString protocol = url.protocol();
|
1999-04-27 09:04:36 +00:00
|
|
|
|
|
|
|
if ( sReading )
|
|
|
|
sReading = pManager.supportsReading( protocol );
|
|
|
|
|
|
|
|
if ( sWriting )
|
|
|
|
sWriting = pManager.supportsWriting( protocol );
|
1999-12-18 20:30:37 +00:00
|
|
|
|
1999-04-27 09:04:36 +00:00
|
|
|
if ( sDeleting )
|
|
|
|
sDeleting = pManager.supportsDeleting( protocol );
|
|
|
|
|
|
|
|
if ( sMoving )
|
|
|
|
sMoving = pManager.supportsMoving( protocol );
|
|
|
|
}
|
|
|
|
|
|
|
|
//check if current url is trash
|
2000-02-19 20:30:21 +00:00
|
|
|
url = m_sViewURL;
|
1999-04-27 09:04:36 +00:00
|
|
|
url.cleanPath();
|
1999-12-18 20:30:37 +00:00
|
|
|
|
2000-03-18 15:19:43 +00:00
|
|
|
bool isCurrentTrash = ( url.isLocalFile() &&
|
|
|
|
url.path(1) == KGlobalSettings::trashPath() );
|
1999-04-27 09:04:36 +00:00
|
|
|
|
|
|
|
//check if url is current directory
|
1999-08-04 10:50:58 +00:00
|
|
|
if ( m_lstItems.count() == 1 )
|
1999-04-27 09:04:36 +00:00
|
|
|
{
|
1999-08-04 10:50:58 +00:00
|
|
|
KURL firstPopupURL ( m_lstItems.first()->url() );
|
1999-04-27 09:04:36 +00:00
|
|
|
firstPopupURL.cleanPath();
|
2000-03-18 15:19:43 +00:00
|
|
|
//kdDebug(1203) << "View path is " << url.url() << endl;
|
|
|
|
//kdDebug(1203) << "First popup path is " << firstPopupURL.url() << endl;
|
|
|
|
currentDir = firstPopupURL.cmp( url, true /* ignore_trailing */ );
|
1999-04-27 09:04:36 +00:00
|
|
|
}
|
1999-12-18 20:30:37 +00:00
|
|
|
|
1999-10-17 15:19:54 +00:00
|
|
|
QObject::disconnect( this, SIGNAL( activated( int ) ), this, SLOT( slotPopup( int ) ) );
|
1999-04-27 09:04:36 +00:00
|
|
|
|
1999-10-17 15:19:54 +00:00
|
|
|
clear();
|
1999-04-27 09:04:36 +00:00
|
|
|
|
1999-09-28 00:27:57 +00:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2000-03-25 07:07:56 +00:00
|
|
|
KAction * act;
|
1999-04-27 09:04:36 +00:00
|
|
|
|
2000-04-01 17:09:44 +00:00
|
|
|
addMerge( "konqueror" );
|
|
|
|
|
|
|
|
m_paNewView = new KAction( i18n( "New View" ), 0, this, SLOT( slotPopupNewView() ), &m_ownActions, "newview" );
|
2000-03-18 15:19:43 +00:00
|
|
|
|
|
|
|
if ( isCurrentTrash && currentDir )
|
1999-04-27 09:04:36 +00:00
|
|
|
{
|
2000-04-01 17:09:44 +00:00
|
|
|
addAction( m_paNewView );
|
|
|
|
addSeparator();
|
|
|
|
|
|
|
|
act = new KAction( i18n( "Empty Trash Bin" ), 0, this, SLOT( slotPopupEmptyTrashBin() ), &m_ownActions, "empytrash" );
|
|
|
|
addAction( act );
|
1999-12-18 20:30:37 +00:00
|
|
|
}
|
|
|
|
else
|
1999-04-27 09:04:36 +00:00
|
|
|
{
|
1999-10-17 15:19:54 +00:00
|
|
|
if ( S_ISDIR( mode ) ) // all URLs are directories
|
|
|
|
{
|
2000-04-06 22:00:15 +00:00
|
|
|
if ( sWriting && m_pMenuNew ) // Add the "new" menu
|
1999-12-18 20:30:37 +00:00
|
|
|
{
|
|
|
|
// As requested by KNewMenu :
|
|
|
|
m_pMenuNew->slotCheckUpToDate();
|
|
|
|
m_pMenuNew->setPopupFiles( m_lstPopupURLs );
|
1999-04-27 09:04:36 +00:00
|
|
|
|
2000-04-06 22:00:15 +00:00
|
|
|
addAction( m_pMenuNew );
|
1999-04-27 09:04:36 +00:00
|
|
|
|
2000-04-06 22:00:15 +00:00
|
|
|
addSeparator();
|
|
|
|
}
|
1999-04-27 09:04:36 +00:00
|
|
|
|
2000-04-01 17:09:44 +00:00
|
|
|
if ( currentDir ) {
|
|
|
|
addAction( "up" );
|
2000-04-06 22:00:15 +00:00
|
|
|
addAction( "back" );
|
|
|
|
addAction( "forward" );
|
2000-04-08 20:31:49 +00:00
|
|
|
addAction( "reload" );
|
2000-04-09 09:41:40 +00:00
|
|
|
addGroup( "reload" );
|
2000-04-06 22:00:15 +00:00
|
|
|
addSeparator();
|
1999-10-17 15:19:54 +00:00
|
|
|
}
|
1999-04-27 09:04:36 +00:00
|
|
|
|
2000-04-01 17:09:44 +00:00
|
|
|
addAction( m_paNewView );
|
|
|
|
addSeparator();
|
1999-10-17 15:19:54 +00:00
|
|
|
}
|
2000-03-18 15:19:43 +00:00
|
|
|
else // not all URLs are dirs
|
1999-08-16 19:24:24 +00:00
|
|
|
{
|
2000-04-06 22:00:15 +00:00
|
|
|
// HACK - should be also possible for anything we can embed
|
2000-03-18 15:19:43 +00:00
|
|
|
if ( m_sViewURL.protocol() == "http" )
|
1999-10-17 15:19:54 +00:00
|
|
|
{
|
2000-04-01 17:09:44 +00:00
|
|
|
addAction( m_paNewView );
|
2000-04-08 16:54:22 +00:00
|
|
|
addSeparator();
|
1999-10-17 15:19:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-04-06 22:00:15 +00:00
|
|
|
if ( sReading ) {
|
|
|
|
if ( sDeleting ) {
|
|
|
|
addAction( "cut" );
|
|
|
|
}
|
2000-04-01 17:09:44 +00:00
|
|
|
addAction( "copy" );
|
1999-12-18 20:30:37 +00:00
|
|
|
}
|
|
|
|
|
2000-03-18 15:19:43 +00:00
|
|
|
if ( sWriting ) {
|
2000-04-01 17:09:44 +00:00
|
|
|
addAction( "paste" );
|
2000-03-18 15:19:43 +00:00
|
|
|
}
|
1999-10-17 15:19:54 +00:00
|
|
|
|
2000-03-18 15:19:43 +00:00
|
|
|
if ( sMoving && !currentDir ) {
|
2000-04-01 17:09:44 +00:00
|
|
|
addAction( "trash" );
|
1999-12-18 20:30:37 +00:00
|
|
|
}
|
|
|
|
|
2000-03-18 15:19:43 +00:00
|
|
|
if ( sDeleting && !currentDir ) {
|
2000-04-01 17:09:44 +00:00
|
|
|
addAction( "del" );
|
|
|
|
if ( m_sViewURL.isLocalFile() )
|
|
|
|
addAction( "shred" );
|
2000-03-18 15:19:43 +00:00
|
|
|
}
|
1999-04-27 09:04:36 +00:00
|
|
|
}
|
|
|
|
|
2000-04-01 17:09:44 +00:00
|
|
|
act = new KAction( i18n( "Add To Bookmarks" ), 0, this, SLOT( slotPopupAddToBookmark() ), &m_ownActions, "addbookmark" );
|
|
|
|
addAction( act );
|
1999-04-27 09:04:36 +00:00
|
|
|
|
1999-09-28 00:27:57 +00:00
|
|
|
//////////////////////////////////////////////////////
|
|
|
|
|
1999-09-24 22:47:25 +00:00
|
|
|
bool bLastSepInserted = false;
|
|
|
|
|
|
|
|
if ( !m_sMimeType.isNull() ) // common mimetype among all URLs ?
|
1999-04-27 09:04:36 +00:00
|
|
|
{
|
1999-08-04 10:50:58 +00:00
|
|
|
// Query the trader for offers associated to this mimetype
|
1999-12-18 20:30:37 +00:00
|
|
|
|
2000-03-19 00:44:31 +00:00
|
|
|
// 2 - Look for builtin and user-defined services
|
1999-05-06 05:03:16 +00:00
|
|
|
QValueList<KDEDesktopMimeType::Service> builtin;
|
|
|
|
QValueList<KDEDesktopMimeType::Service> user;
|
1999-09-28 00:27:57 +00:00
|
|
|
if ( m_sMimeType == "application/x-desktop" ) // .desktop file
|
1999-04-27 09:04:36 +00:00
|
|
|
{
|
1999-09-28 00:27:57 +00:00
|
|
|
// get builtin services, like mount/unmount
|
1999-08-07 15:39:41 +00:00
|
|
|
builtin = KDEDesktopMimeType::builtinServices( m_lstItems.first()->url() );
|
|
|
|
user = KDEDesktopMimeType::userDefinedServices( m_lstItems.first()->url() );
|
1999-04-27 09:04:36 +00:00
|
|
|
}
|
1999-08-08 19:53:28 +00:00
|
|
|
|
2000-03-19 00:44:31 +00:00
|
|
|
// 3 - Look for "servicesmenus" bindings (konqueror-specific user-defined services)
|
1999-08-08 19:53:28 +00:00
|
|
|
QStringList dirs = KGlobal::dirs()->findDirs( "data", "konqueror/servicemenus/" );
|
|
|
|
QStringList::ConstIterator dIt = dirs.begin();
|
|
|
|
QStringList::ConstIterator dEnd = dirs.end();
|
1999-12-18 20:30:37 +00:00
|
|
|
|
1999-08-08 19:53:28 +00:00
|
|
|
for (; dIt != dEnd; ++dIt )
|
|
|
|
{
|
|
|
|
QDir dir( *dIt );
|
1999-12-18 20:30:37 +00:00
|
|
|
|
1999-08-08 19:53:28 +00:00
|
|
|
QStringList entries = dir.entryList( QDir::Files );
|
|
|
|
QStringList::ConstIterator eIt = entries.begin();
|
|
|
|
QStringList::ConstIterator eEnd = entries.end();
|
|
|
|
|
|
|
|
for (; eIt != eEnd; ++eIt )
|
|
|
|
{
|
|
|
|
KSimpleConfig cfg( *dIt + *eIt, true );
|
1999-12-18 20:30:37 +00:00
|
|
|
|
1999-08-10 17:12:32 +00:00
|
|
|
cfg.setDesktopGroup();
|
1999-08-08 19:53:28 +00:00
|
|
|
|
1999-08-10 17:12:32 +00:00
|
|
|
if ( cfg.hasKey( "Actions" ) && cfg.hasKey( "ServiceTypes" ) &&
|
1999-09-24 22:47:25 +00:00
|
|
|
cfg.readListEntry( "ServiceTypes" ).contains( m_sMimeType ) )
|
1999-08-08 19:53:28 +00:00
|
|
|
{
|
|
|
|
KURL u( *dIt + *eIt );
|
|
|
|
user += KDEDesktopMimeType::userDefinedServices( u );
|
|
|
|
}
|
1999-12-18 20:30:37 +00:00
|
|
|
|
1999-08-08 19:53:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
1999-12-18 20:30:37 +00:00
|
|
|
|
2000-03-19 00:44:31 +00:00
|
|
|
// 4 - Query for applications
|
|
|
|
KTrader::OfferList offers = KTrader::self()->query( m_sMimeType, "Type == 'Application'" );
|
1999-04-27 09:04:36 +00:00
|
|
|
|
2000-03-19 00:44:31 +00:00
|
|
|
//// Ok, we have everything, now insert
|
1999-12-18 20:30:37 +00:00
|
|
|
|
1999-04-27 09:04:36 +00:00
|
|
|
m_mapPopup.clear();
|
2000-03-19 00:44:31 +00:00
|
|
|
m_mapPopupServices.clear();
|
2000-04-08 20:31:49 +00:00
|
|
|
|
2000-04-15 04:42:04 +00:00
|
|
|
QString openWithText = i18n( "Open With" );
|
1999-12-18 20:30:37 +00:00
|
|
|
|
2000-04-08 15:55:05 +00:00
|
|
|
if ( !offers.isEmpty() || !user.isEmpty() || !builtin.isEmpty() )
|
1999-12-18 20:30:37 +00:00
|
|
|
{
|
2000-04-08 15:55:05 +00:00
|
|
|
// First block, app offers + user
|
2000-04-01 17:09:44 +00:00
|
|
|
addSeparator();
|
|
|
|
|
|
|
|
id = 1;
|
2000-03-19 00:44:31 +00:00
|
|
|
|
|
|
|
bool insertedOffer = false;
|
|
|
|
|
2000-04-08 16:54:22 +00:00
|
|
|
QDomElement menu = m_menuElement;
|
2000-04-08 20:31:49 +00:00
|
|
|
|
2000-04-08 16:54:22 +00:00
|
|
|
if ( offers.count() > 1 )
|
|
|
|
{
|
|
|
|
menu = m_doc.createElement( "menu" );
|
|
|
|
m_menuElement.appendChild( menu );
|
|
|
|
QDomElement text = m_doc.createElement( "text" );
|
|
|
|
menu.appendChild( text );
|
|
|
|
text.appendChild( m_doc.createTextNode( openWithText ) );
|
2000-04-15 04:42:04 +00:00
|
|
|
openWithText = i18n( "Other..." );
|
2000-04-08 16:54:22 +00:00
|
|
|
}
|
2000-04-08 20:31:49 +00:00
|
|
|
|
2000-04-08 16:54:22 +00:00
|
|
|
KAction *openWithAct = new KAction( openWithText, 0, this, SLOT( slotPopupOpenWith() ), &m_ownActions, "openwith" );
|
2000-04-08 20:31:49 +00:00
|
|
|
|
2000-04-08 16:54:22 +00:00
|
|
|
if ( menu == m_menuElement )
|
|
|
|
{
|
|
|
|
addAction( openWithAct, menu );
|
|
|
|
addSeparator();
|
|
|
|
}
|
2000-04-08 20:31:49 +00:00
|
|
|
|
|
|
|
addGroup( "preview" );
|
2000-04-09 09:41:40 +00:00
|
|
|
|
2000-03-19 00:44:31 +00:00
|
|
|
// KServiceTypeProfile::OfferList::Iterator it = offers.begin();
|
2000-04-08 15:55:05 +00:00
|
|
|
KTrader::OfferList::ConstIterator it = offers.begin();
|
2000-03-19 00:44:31 +00:00
|
|
|
for( ; it != offers.end(); it++ )
|
|
|
|
{
|
2000-04-01 17:09:44 +00:00
|
|
|
QCString nam;
|
|
|
|
nam.setNum( id );
|
|
|
|
|
2000-04-24 13:47:34 +00:00
|
|
|
act = new KAction( (*it)->name(), (*it)->pixmap( KIcon::Small ), 0,
|
2000-04-04 22:24:42 +00:00
|
|
|
this, SLOT( slotRunService() ),
|
2000-04-01 17:09:44 +00:00
|
|
|
&m_ownActions, nam.prepend( "appservice_" ) );
|
2000-04-08 16:54:22 +00:00
|
|
|
addAction( act, menu );
|
2000-04-01 17:09:44 +00:00
|
|
|
|
|
|
|
m_mapPopup[ id++ ] = *it;
|
|
|
|
|
2000-03-19 00:44:31 +00:00
|
|
|
insertedOffer = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
QValueList<KDEDesktopMimeType::Service>::Iterator it2 = user.begin();
|
|
|
|
for( ; it2 != user.end(); ++it2 )
|
|
|
|
{
|
|
|
|
if ((*it2).m_display == true)
|
|
|
|
{
|
2000-04-01 17:09:44 +00:00
|
|
|
QCString nam;
|
|
|
|
nam.setNum( id );
|
|
|
|
act = new KAction( (*it2).m_strName, 0, this, SLOT( slotRunService() ), &m_ownActions, nam.prepend( "userservice_" ) );
|
|
|
|
|
2000-03-19 00:44:31 +00:00
|
|
|
if ( !(*it2).m_strIcon.isEmpty() )
|
|
|
|
{
|
2000-04-02 20:49:56 +00:00
|
|
|
QPixmap pix = SmallIcon( (*it2).m_strIcon );
|
2000-04-01 17:09:44 +00:00
|
|
|
act->setIconSet( pix );
|
2000-03-19 00:44:31 +00:00
|
|
|
}
|
2000-04-01 17:09:44 +00:00
|
|
|
|
2000-04-08 16:54:22 +00:00
|
|
|
addAction( act, menu );
|
2000-04-01 17:09:44 +00:00
|
|
|
|
|
|
|
m_mapPopupServices[ id++ ] = *it2;
|
2000-03-19 00:44:31 +00:00
|
|
|
insertedOffer = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-04-08 16:54:22 +00:00
|
|
|
if ( menu != m_menuElement )
|
|
|
|
{
|
|
|
|
addSeparator( menu );
|
|
|
|
addAction( openWithAct, menu );
|
|
|
|
}
|
2000-04-08 20:31:49 +00:00
|
|
|
|
2000-03-19 00:44:31 +00:00
|
|
|
// Second block, builtin
|
|
|
|
if ( insertedOffer )
|
2000-04-01 17:09:44 +00:00
|
|
|
addSeparator();
|
2000-03-19 00:44:31 +00:00
|
|
|
|
2000-04-08 16:54:22 +00:00
|
|
|
insertedOffer = false;
|
2000-04-08 20:31:49 +00:00
|
|
|
|
2000-03-19 00:44:31 +00:00
|
|
|
it2 = builtin.begin();
|
|
|
|
for( ; it2 != builtin.end(); ++it2 )
|
1999-11-05 02:01:02 +00:00
|
|
|
{
|
2000-04-01 17:09:44 +00:00
|
|
|
QCString nam;
|
|
|
|
nam.setNum( id );
|
|
|
|
|
2000-04-08 16:54:22 +00:00
|
|
|
act = new KAction( (*it2).m_strName, 0, this, SLOT( slotRunService() ), &m_ownActions, nam.prepend( "builtinservice_" ) );
|
2000-04-01 17:09:44 +00:00
|
|
|
|
2000-01-26 03:51:00 +00:00
|
|
|
if ( !(*it2).m_strIcon.isEmpty() )
|
|
|
|
{
|
2000-04-02 20:49:56 +00:00
|
|
|
QPixmap pix = SmallIcon( (*it2).m_strIcon );
|
2000-04-01 17:09:44 +00:00
|
|
|
act->setIconSet( pix );
|
2000-01-26 03:51:00 +00:00
|
|
|
}
|
2000-04-01 17:09:44 +00:00
|
|
|
|
2000-04-08 16:54:22 +00:00
|
|
|
addAction( act, menu );
|
2000-04-01 17:09:44 +00:00
|
|
|
|
|
|
|
m_mapPopupServices[ id++ ] = *it2;
|
2000-04-08 16:54:22 +00:00
|
|
|
insertedOffer = true;
|
1999-11-05 02:01:02 +00:00
|
|
|
}
|
2000-04-08 20:31:49 +00:00
|
|
|
|
2000-04-08 16:54:22 +00:00
|
|
|
if ( insertedOffer )
|
|
|
|
addSeparator();
|
1999-04-27 09:04:36 +00:00
|
|
|
}
|
2000-03-19 00:44:31 +00:00
|
|
|
else
|
2000-04-08 16:54:22 +00:00
|
|
|
{
|
2000-04-01 17:09:44 +00:00
|
|
|
addSeparator();
|
2000-04-15 04:42:04 +00:00
|
|
|
openWithText += "..."; //Show "..." only when no application binding is found!!
|
2000-04-08 16:54:22 +00:00
|
|
|
act = new KAction( openWithText, 0, this, SLOT( slotPopupOpenWith() ), &m_ownActions, "openwith" );
|
|
|
|
addAction( act );
|
|
|
|
addSeparator();
|
|
|
|
}
|
1999-04-27 09:04:36 +00:00
|
|
|
|
1999-09-24 22:47:25 +00:00
|
|
|
bLastSepInserted = true;
|
1999-12-18 20:30:37 +00:00
|
|
|
|
2000-04-01 17:09:44 +00:00
|
|
|
// or "File Type Properties" ?
|
2000-04-04 22:24:42 +00:00
|
|
|
act = new KAction( i18n( "Edit File Type..." ), 0, this, SLOT( slotPopupMimeType() ),
|
2000-04-01 17:09:44 +00:00
|
|
|
&m_ownActions, "editfiletype" );
|
|
|
|
addAction( act );
|
1999-09-24 22:47:25 +00:00
|
|
|
}
|
2000-04-01 17:09:44 +00:00
|
|
|
|
1999-08-04 10:50:58 +00:00
|
|
|
if ( PropertiesDialog::canDisplay( m_lstItems ) )
|
1999-04-27 09:04:36 +00:00
|
|
|
{
|
2000-04-01 17:09:44 +00:00
|
|
|
if ( !bLastSepInserted ) addSeparator();
|
2000-04-04 22:24:42 +00:00
|
|
|
|
|
|
|
act = new KAction( i18n( "Properties..." ), 0, this, SLOT( slotPopupProperties() ),
|
2000-04-01 17:09:44 +00:00
|
|
|
&m_ownActions, "properties" );
|
|
|
|
addAction( act );
|
1999-04-27 09:04:36 +00:00
|
|
|
}
|
2000-04-01 17:09:44 +00:00
|
|
|
|
|
|
|
addMerge( 0 );
|
2000-04-04 22:24:42 +00:00
|
|
|
|
2000-04-01 17:09:44 +00:00
|
|
|
m_factory->addClient( this );
|
1999-04-27 09:04:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
KonqPopupMenu::~KonqPopupMenu()
|
|
|
|
{
|
2000-04-01 17:09:44 +00:00
|
|
|
delete m_factory;
|
|
|
|
delete m_builder;
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
void KonqPopupMenu::slotPopupEmptyTrashBin()
|
|
|
|
{
|
2000-04-27 17:59:11 +00:00
|
|
|
KonqOperations::emptyTrash();
|
1999-04-27 09:04:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void KonqPopupMenu::slotPopupOpenWith()
|
|
|
|
{
|
2000-04-17 17:39:29 +00:00
|
|
|
KOpenWithDlg l( m_lstPopupURLs );
|
1999-04-27 09:04:36 +00:00
|
|
|
if ( l.exec() )
|
|
|
|
{
|
1999-07-14 12:49:00 +00:00
|
|
|
KService::Ptr service = l.service();
|
1999-08-11 14:50:43 +00:00
|
|
|
if ( !!service )
|
1999-04-27 09:04:36 +00:00
|
|
|
{
|
|
|
|
KRun::run( *service, m_lstPopupURLs );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
QString exec = l.text();
|
|
|
|
exec += " %f";
|
1999-07-11 17:09:28 +00:00
|
|
|
KRun::run( exec, m_lstPopupURLs );
|
1999-04-27 09:04:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void KonqPopupMenu::slotPopupAddToBookmark()
|
|
|
|
{
|
|
|
|
KBookmark *root = KBookmarkManager::self()->root();
|
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++ )
|
2000-02-19 20:30:21 +00:00
|
|
|
(void)new KBookmark( KBookmarkManager::self(), root, (*it).decodedURL(), *it );
|
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() )
|
|
|
|
{
|
|
|
|
KURL::List::Iterator it3 = m_lstPopupURLs.begin();
|
|
|
|
for( ; it3 != m_lstPopupURLs.end(); ++it3 )
|
|
|
|
KDEDesktopMimeType::executeService( (*it3).path(), it2.data() );
|
|
|
|
}
|
1999-04-27 09:04:36 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1999-09-24 22:47:25 +00:00
|
|
|
void KonqPopupMenu::slotPopupMimeType()
|
|
|
|
{
|
2000-04-15 15:22:56 +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()
|
|
|
|
{
|
1999-08-04 10:50:58 +00:00
|
|
|
(void) new PropertiesDialog( m_lstItems );
|
1999-04-27 09:04:36 +00:00
|
|
|
}
|
|
|
|
|
2000-04-01 17:09:44 +00:00
|
|
|
KAction *KonqPopupMenu::action( const QDomElement &element ) const
|
|
|
|
{
|
2000-04-04 22:24:42 +00:00
|
|
|
QString name = element.attribute( attrName );
|
2000-04-01 17:09:44 +00:00
|
|
|
|
|
|
|
KAction *res = m_ownActions.action( name );
|
|
|
|
|
|
|
|
if ( !res )
|
|
|
|
res = m_actions.action( name );
|
|
|
|
|
|
|
|
if ( !res && strcmp( name, m_pMenuNew->name() ) == 0 )
|
|
|
|
return m_pMenuNew;
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
QDomDocument KonqPopupMenu::document() const
|
|
|
|
{
|
|
|
|
return m_doc;
|
|
|
|
}
|
|
|
|
|
2000-04-08 16:54:22 +00:00
|
|
|
void KonqPopupMenu::addAction( KAction *act, const QDomElement &menu )
|
2000-04-01 17:09:44 +00:00
|
|
|
{
|
2000-04-08 16:54:22 +00:00
|
|
|
addAction( act->name(), menu );
|
2000-04-01 17:09:44 +00:00
|
|
|
}
|
|
|
|
|
2000-04-08 16:54:22 +00:00
|
|
|
void KonqPopupMenu::addAction( const char *name, const QDomElement &menu )
|
2000-04-08 20:31:49 +00:00
|
|
|
{
|
2000-04-04 22:24:42 +00:00
|
|
|
static QString tagAction = QString::fromLatin1( "action" );
|
2000-04-08 20:31:49 +00:00
|
|
|
|
2000-04-08 16:54:22 +00:00
|
|
|
QDomElement parent = menu;
|
|
|
|
if ( parent.isNull() )
|
|
|
|
parent = m_menuElement;
|
2000-04-08 20:31:49 +00:00
|
|
|
|
2000-04-01 17:09:44 +00:00
|
|
|
QDomElement e = m_doc.createElement( tagAction );
|
2000-04-08 16:54:22 +00:00
|
|
|
parent.appendChild( e );
|
2000-04-01 17:09:44 +00:00
|
|
|
e.setAttribute( attrName, name );
|
|
|
|
}
|
|
|
|
|
2000-04-08 16:54:22 +00:00
|
|
|
void KonqPopupMenu::addSeparator( const QDomElement &menu )
|
2000-04-01 17:09:44 +00:00
|
|
|
{
|
2000-04-04 22:24:42 +00:00
|
|
|
static QString tagSeparator = QString::fromLatin1( "separator" );
|
2000-04-08 20:31:49 +00:00
|
|
|
|
2000-04-08 16:54:22 +00:00
|
|
|
QDomElement parent = menu;
|
|
|
|
if ( parent.isNull() )
|
|
|
|
parent = m_menuElement;
|
2000-04-08 20:31:49 +00:00
|
|
|
|
2000-04-08 16:54:22 +00:00
|
|
|
parent.appendChild( m_doc.createElement( tagSeparator ) );
|
2000-04-01 17:09:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void KonqPopupMenu::addMerge( const char *name )
|
|
|
|
{
|
2000-04-04 22:24:42 +00:00
|
|
|
static QString tagMerge = QString::fromLatin1( "merge" );
|
2000-04-01 17:09:44 +00:00
|
|
|
QDomElement merge = m_doc.createElement( tagMerge );
|
|
|
|
m_menuElement.appendChild( merge );
|
|
|
|
if ( name )
|
|
|
|
merge.setAttribute( attrName, name );
|
2000-04-04 22:24:42 +00:00
|
|
|
}
|
2000-04-01 17:09:44 +00:00
|
|
|
|
2000-04-08 20:31:49 +00:00
|
|
|
void KonqPopupMenu::addGroup( const QString &grp )
|
|
|
|
{
|
|
|
|
QDomElement group = m_doc.createElement( "definegroup" );
|
|
|
|
m_menuElement.appendChild( group );
|
|
|
|
group.setAttribute( "name", grp );
|
2000-04-09 09:41:40 +00:00
|
|
|
}
|
2000-04-08 20:31:49 +00:00
|
|
|
|
2000-04-01 17:09:44 +00:00
|
|
|
void KonqPopupMenu::prepareXMLGUIStuff()
|
|
|
|
{
|
|
|
|
m_doc = QDomDocument( "kpartgui" );
|
|
|
|
|
|
|
|
QDomElement root = m_doc.createElement( "kpartgui" );
|
|
|
|
m_doc.appendChild( root );
|
|
|
|
root.setAttribute( attrName, "popupmenu" );
|
|
|
|
|
|
|
|
m_menuElement = m_doc.createElement( "Menu" );
|
|
|
|
root.appendChild( m_menuElement );
|
|
|
|
m_menuElement.setAttribute( attrName, "popupmenu" );
|
|
|
|
|
|
|
|
m_builder = new KonqPopupMenuGUIBuilder( this );
|
|
|
|
m_factory = new KXMLGUIFactory( m_builder );
|
|
|
|
}
|
|
|
|
|
1999-10-17 15:19:54 +00:00
|
|
|
#include "konqpopupmenu.moc"
|