mirror of
https://invent.kde.org/system/dolphin
synced 2024-09-12 12:54:29 +00:00
Fix crash when triggereing the "Compare files" action via D-Bus
If the number of selected items is not two, Dolphin disables this action. However, it is still possible to trigger it via D-Bus, and this could cause a crash in DolphinMainWindow::compareFiles() because this function did not test at all if there are really two items selected. This patch adds such a check and simplifies the code in that function. BUG: 325517 FIXED-IN: 4.11.3
This commit is contained in:
parent
0c55297ce4
commit
96ba990d86
|
@ -999,50 +999,23 @@ void DolphinMainWindow::goHome(Qt::MouseButtons buttons)
|
|||
|
||||
void DolphinMainWindow::compareFiles()
|
||||
{
|
||||
// The method is only invoked if exactly 2 files have
|
||||
// been selected. The selected files may be:
|
||||
// - both in the primary view
|
||||
// - both in the secondary view
|
||||
// - one in the primary view and the other in the secondary
|
||||
// view
|
||||
Q_ASSERT(m_viewTab[m_tabIndex].primaryView);
|
||||
const DolphinViewContainer* primaryViewContainer = m_viewTab[m_tabIndex].primaryView;
|
||||
Q_ASSERT(primaryViewContainer);
|
||||
KFileItemList items = primaryViewContainer->view()->selectedItems();
|
||||
|
||||
KUrl urlA;
|
||||
KUrl urlB;
|
||||
|
||||
KFileItemList items = m_viewTab[m_tabIndex].primaryView->view()->selectedItems();
|
||||
|
||||
switch (items.count()) {
|
||||
case 0: {
|
||||
Q_ASSERT(m_viewTab[m_tabIndex].secondaryView);
|
||||
items = m_viewTab[m_tabIndex].secondaryView->view()->selectedItems();
|
||||
Q_ASSERT(items.count() == 2);
|
||||
urlA = items[0].url();
|
||||
urlB = items[1].url();
|
||||
break;
|
||||
const DolphinViewContainer* secondaryViewContainer = m_viewTab[m_tabIndex].secondaryView;
|
||||
if (secondaryViewContainer) {
|
||||
items.append(secondaryViewContainer->view()->selectedItems());
|
||||
}
|
||||
|
||||
case 1: {
|
||||
urlA = items[0].url();
|
||||
Q_ASSERT(m_viewTab[m_tabIndex].secondaryView);
|
||||
items = m_viewTab[m_tabIndex].secondaryView->view()->selectedItems();
|
||||
Q_ASSERT(items.count() == 1);
|
||||
urlB = items[0].url();
|
||||
break;
|
||||
if (items.count() != 2) {
|
||||
// The action is disabled in this case, but it could have been triggered
|
||||
// via D-Bus, see https://bugs.kde.org/show_bug.cgi?id=325517
|
||||
return;
|
||||
}
|
||||
|
||||
case 2: {
|
||||
urlA = items[0].url();
|
||||
urlB = items[1].url();
|
||||
break;
|
||||
}
|
||||
|
||||
default: {
|
||||
// may not happen: compareFiles may only get invoked if 2
|
||||
// files are selected
|
||||
Q_ASSERT(false);
|
||||
}
|
||||
}
|
||||
KUrl urlA = items.at(0).url();
|
||||
KUrl urlB = items.at(1).url();
|
||||
|
||||
QString command("kompare -c \"");
|
||||
command.append(urlA.pathOrUrl());
|
||||
|
|
Loading…
Reference in a new issue