mirror of
https://invent.kde.org/system/dolphin
synced 2024-09-20 08:51:24 +00:00
Fixed major bug with the way we enabled the "standard actions", leading
to crashes when using the popup in the dirtree (and then e.g. the cut action in the toolbar). We now store the status of the actions in a bitfield in KonqView. Thanks to Simon for the idea for this clean fix. This also removes the need for the guiActivateEvent hacks. svn path=/trunk/kdebase/konqueror/; revision=74001
This commit is contained in:
parent
8881be5f36
commit
684f4e1ced
|
@ -99,6 +99,7 @@ template class QList<KToggleAction>;
|
|||
|
||||
QList<KonqMainWindow> *KonqMainWindow::s_lstViews = 0;
|
||||
KonqMainWindow::ActionSlotMap *KonqMainWindow::s_actionSlotMap = 0;
|
||||
KonqMainWindow::ActionNumberMap *KonqMainWindow::s_actionNumberMap = 0;
|
||||
KCompletion * KonqMainWindow::s_pCompletion = 0;
|
||||
|
||||
KonqMainWindow::KonqMainWindow( const KURL &initialURL, bool openInitialURL, const char *name )
|
||||
|
@ -110,7 +111,17 @@ KonqMainWindow::KonqMainWindow( const KURL &initialURL, bool openInitialURL, con
|
|||
s_lstViews->append( this );
|
||||
|
||||
if ( !s_actionSlotMap )
|
||||
{
|
||||
s_actionSlotMap = new ActionSlotMap( KParts::BrowserExtension::actionSlotMap() );
|
||||
s_actionNumberMap = new ActionNumberMap;
|
||||
ActionSlotMap::ConstIterator it = s_actionSlotMap->begin();
|
||||
ActionSlotMap::ConstIterator itEnd = s_actionSlotMap->end();
|
||||
for ( int i=0 ; it != itEnd ; ++it, ++i )
|
||||
{
|
||||
kdDebug(1202) << " action " << it.key() << " number " << i << endl;
|
||||
s_actionNumberMap->insert( it.key(), i );
|
||||
}
|
||||
}
|
||||
|
||||
m_currentView = 0L;
|
||||
m_pBookmarkMenu = 0L;
|
||||
|
@ -1400,7 +1411,7 @@ void KonqMainWindow::slotPartActivated( KParts::Part *part )
|
|||
if ( ext )
|
||||
{
|
||||
//kdDebug() << "Connecting extension for view " << newView << endl;
|
||||
connectExtension( ext );
|
||||
connectExtension( m_currentView, ext );
|
||||
createGUI( part );
|
||||
}
|
||||
else
|
||||
|
@ -2182,7 +2193,7 @@ bool KonqMainWindow::eventFilter(QObject*obj,QEvent *ev)
|
|||
|
||||
void KonqMainWindow::slotClipboardDataChanged()
|
||||
{
|
||||
//kdDebug(1202) << "KonqMainWindow::slotClipboardDataChanged()" << endl;
|
||||
kdDebug(1202) << "KonqMainWindow::slotClipboardDataChanged()" << endl;
|
||||
QMimeSource *data = QApplication::clipboard()->data();
|
||||
m_paPaste->setEnabled( data->provides( "text/plain" ) );
|
||||
bool hasSelection = m_combo->lineEdit()->hasMarkedText();
|
||||
|
@ -2625,13 +2636,13 @@ QString KonqMainWindow::findIndexFile( const QString &dir )
|
|||
return QString::null;
|
||||
}
|
||||
|
||||
void KonqMainWindow::connectExtension( KParts::BrowserExtension *ext )
|
||||
void KonqMainWindow::connectExtension( KonqView * view, KParts::BrowserExtension *ext )
|
||||
{
|
||||
kdDebug(1202) << "Connecting extension " << ext << endl;
|
||||
ActionSlotMap::ConstIterator it = s_actionSlotMap->begin();
|
||||
ActionSlotMap::ConstIterator itEnd = s_actionSlotMap->end();
|
||||
|
||||
QStrList slotNames = ext->metaObject()->slotNames();
|
||||
QStrList slotNames = ext->metaObject()->slotNames();
|
||||
|
||||
for ( ; it != itEnd ; ++it )
|
||||
{
|
||||
|
@ -2639,19 +2650,19 @@ void KonqMainWindow::connectExtension( KParts::BrowserExtension *ext )
|
|||
//kdDebug(1202) << it.key() << endl;
|
||||
if ( act )
|
||||
{
|
||||
bool enable = false;
|
||||
// Does the extension have a slot with the name of this action ?
|
||||
if ( slotNames.contains( it.key()+"()" ) )
|
||||
{
|
||||
connect( act, SIGNAL( activated() ), ext, it.data() /* SLOT(slot name) */ );
|
||||
enable = true;
|
||||
}
|
||||
act->setEnabled( enable );
|
||||
int actionNumber = (*s_actionNumberMap)[ it.key() ];
|
||||
act->setEnabled( view->actionStatus()[ actionNumber ] );
|
||||
kdDebug() << "KonqMainWindow::connectExtension connecting to " << it.key() << " (" << actionNumber << ") and setting it to " << act->isEnabled() << endl;
|
||||
} else
|
||||
act->setEnabled(false);
|
||||
|
||||
} else kdError(1202) << "Error in BrowserExtension::actionSlotMap(), unknown action : " << it.key() << endl;
|
||||
}
|
||||
|
||||
connect( ext, SIGNAL( enableAction( const char *, bool ) ),
|
||||
this, SLOT( slotEnableAction( const char *, bool ) ) );
|
||||
}
|
||||
|
||||
void KonqMainWindow::disconnectExtension( KParts::BrowserExtension *ext )
|
||||
|
@ -2672,17 +2683,18 @@ void KonqMainWindow::disconnectExtension( KParts::BrowserExtension *ext )
|
|||
act->disconnect( ext );
|
||||
}
|
||||
}
|
||||
disconnect( ext, SIGNAL( enableAction( const char *, bool ) ),
|
||||
this, SLOT( slotEnableAction( const char *, bool ) ) );
|
||||
}
|
||||
|
||||
void KonqMainWindow::slotEnableAction( const char * name, bool enabled )
|
||||
void KonqMainWindow::enableAction( const char * name, bool enabled )
|
||||
{
|
||||
KAction * act = actionCollection()->action( name );
|
||||
if (!act)
|
||||
kdWarning(1202) << "Unknown action " << name << " - can't enable" << endl;
|
||||
else
|
||||
{
|
||||
kdDebug(1202) << "KonqMainWindow::enableAction " << name << " " << enabled << endl;
|
||||
act->setEnabled( enabled );
|
||||
}
|
||||
|
||||
// Update "copy files" and "move files" accordingly
|
||||
if (m_paCopyFiles && !strcmp( name, "copy" ))
|
||||
|
@ -2854,7 +2866,7 @@ void KonqMainWindow::slotPopupMenu( KXMLGUIClient *client, const QPoint &_global
|
|||
if ( m_oldView->browserExtension() )
|
||||
disconnectExtension( m_oldView->browserExtension() );
|
||||
if ( m_currentView->browserExtension() )
|
||||
connectExtension( m_currentView->browserExtension() );
|
||||
connectExtension( m_currentView, m_currentView->browserExtension() );
|
||||
}
|
||||
|
||||
kdDebug(1202) << "KonqMainWindow::slotPopupMenu( " << client << "...)" << " current view=" << m_currentView << " " << m_currentView->part()->className() << endl;
|
||||
|
@ -2932,7 +2944,7 @@ void KonqMainWindow::slotPopupMenu( KXMLGUIClient *client, const QPoint &_global
|
|||
if ( m_currentView->browserExtension() )
|
||||
disconnectExtension( m_currentView->browserExtension() );
|
||||
if ( m_oldView->browserExtension() )
|
||||
connectExtension( m_oldView->browserExtension() );
|
||||
connectExtension( m_oldView, m_oldView->browserExtension() );
|
||||
}
|
||||
|
||||
m_currentView = m_oldView;
|
||||
|
|
|
@ -175,6 +175,8 @@ public:
|
|||
*/
|
||||
KToggleAction * linkViewAction() { return m_paLinkView; }
|
||||
|
||||
void enableAction( const char * name, bool enabled );
|
||||
|
||||
/**
|
||||
* The default settings "allow HTML" - the one used when creating a new view
|
||||
* Might not match the current view !
|
||||
|
@ -265,7 +267,6 @@ public slots:
|
|||
|
||||
protected slots:
|
||||
void slotViewCompleted( KonqView * view );
|
||||
void slotEnableAction( const char * name, bool enabled );
|
||||
|
||||
void slotURLEntered( const QString &text );
|
||||
|
||||
|
@ -366,7 +367,7 @@ private:
|
|||
*/
|
||||
QString findIndexFile( const QString &directory );
|
||||
|
||||
void connectExtension( KParts::BrowserExtension *ext );
|
||||
void connectExtension( KonqView * view, KParts::BrowserExtension *ext );
|
||||
void disconnectExtension( KParts::BrowserExtension *ext );
|
||||
|
||||
void plugViewModeActions();
|
||||
|
@ -490,11 +491,13 @@ private:
|
|||
|
||||
static QList<KonqMainWindow> *s_lstViews;
|
||||
|
||||
typedef QMap<QCString,QCString> ActionSlotMap;
|
||||
static ActionSlotMap *s_actionSlotMap;
|
||||
|
||||
QString m_currentDir; // stores current dir for relative URLs whenever applicable
|
||||
|
||||
public: // public for KonqView
|
||||
typedef QMap<QCString,QCString> ActionSlotMap;
|
||||
static ActionSlotMap *s_actionSlotMap;
|
||||
typedef QMap<QCString,int> ActionNumberMap;
|
||||
static ActionNumberMap *s_actionNumberMap;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -312,6 +312,22 @@ void KonqView::connectPart( )
|
|||
connect( ext, SIGNAL( openURLNotify() ),
|
||||
this, SLOT( slotOpenURLNotify() ) );
|
||||
|
||||
connect( ext, SIGNAL( enableAction( const char *, bool ) ),
|
||||
this, SLOT( slotEnableAction( const char *, bool ) ) );
|
||||
|
||||
// Set the initial status of the actions depending on whether
|
||||
// they're supported or not
|
||||
KonqMainWindow::ActionSlotMap::ConstIterator it = KonqMainWindow::s_actionSlotMap->begin();
|
||||
KonqMainWindow::ActionSlotMap::ConstIterator itEnd = KonqMainWindow::s_actionSlotMap->end();
|
||||
QStrList slotNames = ext->metaObject()->slotNames();
|
||||
|
||||
for ( int i=0 ; it != itEnd ; ++it, ++i )
|
||||
{
|
||||
// Does the extension have a slot with the name of this action ?
|
||||
m_actionStatus.setBit( i, slotNames.contains( it.key()+"()" ) );
|
||||
}
|
||||
kdDebug(1202) << "KonqView::connectPart m_actionStatus initially set to " << QString::number(m_actionStatus.val,2) << endl;
|
||||
|
||||
callExtensionBoolMethod( "setSaveViewPropertiesLocally(bool)", m_pMainWindow->saveViewPropertiesLocally() );
|
||||
|
||||
QVariant urlDropHandling;
|
||||
|
@ -330,6 +346,20 @@ void KonqView::connectPart( )
|
|||
m_pPart->widget()->installEventFilter( this );
|
||||
}
|
||||
|
||||
void KonqView::slotEnableAction( const char * name, bool enabled )
|
||||
{
|
||||
kdDebug(1202) << "KonqView::slotEnableAction " << name << " " << enabled << endl;
|
||||
KonqMainWindow::ActionNumberMap::ConstIterator it = KonqMainWindow::s_actionNumberMap->find( name );
|
||||
if ( it != KonqMainWindow::s_actionNumberMap->end() )
|
||||
{
|
||||
m_actionStatus.setBit( it.data(), enabled );
|
||||
kdDebug() << "KonqView::slotEnableAction setting bit " << it.data() << " to " << enabled << endl;
|
||||
if ( m_pMainWindow->currentView() == this )
|
||||
m_pMainWindow->enableAction( name, enabled );
|
||||
} else
|
||||
kdWarning(1202) << "KonqView::slotEnableAction unknown action " << name << endl;
|
||||
}
|
||||
|
||||
void KonqView::slotStarted( KIO::Job * job )
|
||||
{
|
||||
//kdDebug(1202) << "KonqView::slotStarted" << job << endl;
|
||||
|
|
|
@ -240,7 +240,7 @@ public:
|
|||
void setToggleView( bool b ) { m_bToggleView = b; }
|
||||
bool isToggleView() const { return m_bToggleView; }
|
||||
|
||||
void setService( const KService::Ptr &s ) { m_service = s; }
|
||||
void setService( const KService::Ptr &s ) { m_service = s; }
|
||||
KService::Ptr service() { return m_service; }
|
||||
|
||||
KTrader::OfferList partServiceOffers() { return m_partServiceOffers; }
|
||||
|
@ -260,6 +260,20 @@ public:
|
|||
|
||||
KonqViewIface * dcopObject();
|
||||
|
||||
// Status of the actions for this view
|
||||
class KBitArray
|
||||
{
|
||||
public:
|
||||
int val;
|
||||
KBitArray() { val = 0; }
|
||||
bool operator [](int index) { return (val & (1 << index)) ? true : false; }
|
||||
void setBit(int index, bool value) {
|
||||
if (value) val = val | (1 << index);
|
||||
else val = val & ~(1 << index);
|
||||
}
|
||||
};
|
||||
KBitArray & actionStatus() { return m_actionStatus; }
|
||||
|
||||
static QStringList childFrameNames( KParts::ReadOnlyPart *part );
|
||||
|
||||
static KParts::BrowserHostExtension *hostExtension( KParts::ReadOnlyPart *part, const QString &name );
|
||||
|
@ -298,6 +312,7 @@ protected slots:
|
|||
*/
|
||||
void slotSelectionInfo( const KFileItemList &items );
|
||||
void slotOpenURLNotify();
|
||||
void slotEnableAction( const char * name, bool enabled );
|
||||
|
||||
protected:
|
||||
/**
|
||||
|
@ -360,6 +375,7 @@ protected:
|
|||
QString m_serviceType;
|
||||
QString m_name;
|
||||
KonqViewIface * m_dcopObject;
|
||||
KBitArray m_actionStatus;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue