2004-08-26 21:17:24 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* Copyright (C) 2002 by Wilco Greven <greven@kde.org> *
|
|
|
|
* Copyright (C) 2002 by Chris Cheney <ccheney@cheney.cx> *
|
|
|
|
* Copyright (C) 2003 by Benjamin Meyer <benjamin@csh.rit.edu> *
|
|
|
|
* Copyright (C) 2003-2004 by Christophe Devriese *
|
|
|
|
* <Christophe.Devriese@student.kuleuven.ac.be> *
|
|
|
|
* Copyright (C) 2003 by Laurent Montel <montel@kde.org> *
|
2013-03-14 22:09:07 +00:00
|
|
|
* Copyright (C) 2003-2004 by Albert Astals Cid <aacid@kde.org> *
|
2004-08-26 21:17:24 +00:00
|
|
|
* Copyright (C) 2003 by Luboš Luňák <l.lunak@kde.org> *
|
|
|
|
* Copyright (C) 2003 by Malcolm Hunter <malcolm.hunter@gmx.co.uk> *
|
|
|
|
* Copyright (C) 2004 by Dominique Devriese <devriese@kde.org> *
|
|
|
|
* Copyright (C) 2004 by Dirk Mueller <mueller@kde.org> *
|
2017-11-16 08:57:58 +00:00
|
|
|
* Copyright (C) 2017 Klarälvdalens Datakonsult AB, a KDAB Group *
|
|
|
|
* company, info@kdab.com. Work sponsored by the *
|
|
|
|
* LiMux project of the city of Munich *
|
2004-08-26 21:17:24 +00:00
|
|
|
* *
|
|
|
|
* This program is free software; you can redistribute it and/or modify *
|
|
|
|
* it under the terms of the GNU General Public License as published by *
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or *
|
|
|
|
* (at your option) any later version. *
|
|
|
|
***************************************************************************/
|
2004-01-15 05:42:12 +00:00
|
|
|
|
2007-04-19 18:30:20 +00:00
|
|
|
#include "shell.h"
|
|
|
|
|
2005-01-02 14:29:37 +00:00
|
|
|
// qt/kde includes
|
2014-08-13 20:57:48 +00:00
|
|
|
#include <QDesktopWidget>
|
|
|
|
#include <QTimer>
|
|
|
|
#include <QDBusConnection>
|
|
|
|
#include <QMenuBar>
|
|
|
|
#include <QApplication>
|
2016-05-30 22:13:36 +00:00
|
|
|
#include <QFileDialog>
|
2014-08-13 20:57:48 +00:00
|
|
|
#include <KPluginLoader>
|
|
|
|
#include <KMessageBox>
|
2014-09-11 13:18:05 +00:00
|
|
|
#include <QMimeType>
|
|
|
|
#include <QMimeDatabase>
|
2014-08-13 20:57:48 +00:00
|
|
|
#include <KStandardAction>
|
|
|
|
#include <KToolBar>
|
|
|
|
#include <KRecentFilesAction>
|
|
|
|
#include <KServiceTypeTrader>
|
|
|
|
#include <KToggleFullScreenAction>
|
|
|
|
#include <KActionCollection>
|
|
|
|
#include <KWindowSystem>
|
2014-10-17 21:30:54 +00:00
|
|
|
#include <QTabWidget>
|
2014-08-13 20:57:48 +00:00
|
|
|
#include <KXMLGUIFactory>
|
2014-04-09 21:29:13 +00:00
|
|
|
#include <QDragMoveEvent>
|
2014-07-30 22:15:21 +00:00
|
|
|
#include <QTabBar>
|
2014-08-13 20:57:48 +00:00
|
|
|
#include <KConfigGroup>
|
2014-08-13 11:07:44 +00:00
|
|
|
#include <KUrlMimeData>
|
2014-10-19 13:17:37 +00:00
|
|
|
#include <KLocalizedString>
|
|
|
|
#include <KSharedConfig>
|
2016-05-30 22:13:36 +00:00
|
|
|
#include <KIO/Global>
|
2018-04-13 15:35:17 +00:00
|
|
|
#ifdef WITH_KACTIVITIES
|
2012-10-04 18:17:13 +00:00
|
|
|
#include <KActivities/ResourceInstance>
|
|
|
|
#endif
|
|
|
|
|
2005-01-02 14:29:37 +00:00
|
|
|
// local includes
|
2007-01-04 00:20:50 +00:00
|
|
|
#include "kdocumentviewer.h"
|
2014-02-08 11:15:15 +00:00
|
|
|
#include "../interfaces/viewerinterface.h"
|
2009-10-08 23:48:04 +00:00
|
|
|
#include "shellutils.h"
|
2002-09-02 20:21:47 +00:00
|
|
|
|
2010-10-14 19:22:55 +00:00
|
|
|
static const char *shouldShowMenuBarComingFromFullScreen = "shouldShowMenuBarComingFromFullScreen";
|
|
|
|
static const char *shouldShowToolBarComingFromFullScreen = "shouldShowToolBarComingFromFullScreen";
|
|
|
|
|
2015-03-16 22:55:57 +00:00
|
|
|
static const char* const SESSION_URL_KEY = "Urls";
|
|
|
|
static const char* const SESSION_TAB_KEY = "ActiveTab";
|
|
|
|
|
2014-08-08 20:35:53 +00:00
|
|
|
Shell::Shell( const QString &serializedOptions )
|
|
|
|
: KParts::MainWindow(), m_menuBarWasShown(true), m_toolBarWasShown(true)
|
2017-03-18 00:58:05 +00:00
|
|
|
#ifndef Q_OS_WIN
|
2017-09-05 21:27:18 +00:00
|
|
|
, m_activityResource(nullptr)
|
2012-10-04 18:17:13 +00:00
|
|
|
#endif
|
2014-10-01 22:56:00 +00:00
|
|
|
, m_isValid(true)
|
2002-09-02 20:21:47 +00:00
|
|
|
{
|
2015-10-29 12:37:11 +00:00
|
|
|
setObjectName( QStringLiteral( "okular::Shell#" ) );
|
2007-01-04 21:06:44 +00:00
|
|
|
setContextMenuPolicy( Qt::NoContextMenu );
|
2015-11-28 15:08:19 +00:00
|
|
|
// otherwise .rc file won't be found by unit test
|
|
|
|
setComponentName(QStringLiteral("okular"), QString());
|
2002-09-02 20:21:47 +00:00
|
|
|
// set the shell's ui resource file
|
2015-10-29 12:37:11 +00:00
|
|
|
setXMLFile(QStringLiteral("shell.rc"));
|
2007-07-29 21:36:02 +00:00
|
|
|
m_fileformatsscanned = false;
|
2017-09-05 21:27:18 +00:00
|
|
|
m_showMenuBarAction = nullptr;
|
2002-09-02 20:21:47 +00:00
|
|
|
// this routine will find and load our Part. it finds the Part by
|
|
|
|
// name which is a bad idea usually.. but it's alright in this
|
|
|
|
// case since our Part is made for this Shell
|
2015-10-29 12:37:11 +00:00
|
|
|
KPluginLoader loader(QStringLiteral("okularpart"));
|
2014-08-10 20:01:13 +00:00
|
|
|
m_partFactory = loader.factory();
|
2014-02-08 10:44:26 +00:00
|
|
|
if (!m_partFactory)
|
2002-09-02 20:21:47 +00:00
|
|
|
{
|
|
|
|
// if we couldn't find our Part, we exit since the Shell by
|
|
|
|
// itself can't do anything useful
|
2014-10-01 22:56:00 +00:00
|
|
|
m_isValid = false;
|
2014-08-10 20:01:13 +00:00
|
|
|
KMessageBox::error(this, i18n("Unable to find the Okular component: %1", loader.errorString()));
|
2002-09-02 20:21:47 +00:00
|
|
|
return;
|
|
|
|
}
|
2008-10-06 17:39:30 +00:00
|
|
|
|
2012-10-08 21:51:58 +00:00
|
|
|
// now that the Part plugin is loaded, create the part
|
2014-02-08 10:44:26 +00:00
|
|
|
KParts::ReadWritePart* const firstPart = m_partFactory->create< KParts::ReadWritePart >( this );
|
|
|
|
if (firstPart)
|
2008-10-06 17:39:30 +00:00
|
|
|
{
|
2014-02-08 10:44:26 +00:00
|
|
|
// Setup tab bar
|
2014-10-17 21:30:54 +00:00
|
|
|
m_tabWidget = new QTabWidget( this );
|
2014-02-08 10:44:26 +00:00
|
|
|
m_tabWidget->setTabsClosable( true );
|
|
|
|
m_tabWidget->setElideMode( Qt::ElideRight );
|
2014-09-09 15:49:10 +00:00
|
|
|
m_tabWidget->tabBar()->hide();
|
2014-02-13 22:24:40 +00:00
|
|
|
m_tabWidget->setDocumentMode( true );
|
2014-07-30 22:15:21 +00:00
|
|
|
m_tabWidget->setMovable( true );
|
2016-01-30 18:28:41 +00:00
|
|
|
|
|
|
|
m_tabWidget->setAcceptDrops(true);
|
|
|
|
m_tabWidget->installEventFilter(this);
|
|
|
|
|
2015-10-29 12:37:11 +00:00
|
|
|
connect( m_tabWidget, &QTabWidget::currentChanged, this, &Shell::setActiveTab );
|
|
|
|
connect( m_tabWidget, &QTabWidget::tabCloseRequested, this, &Shell::closeTab );
|
|
|
|
connect( m_tabWidget->tabBar(), &QTabBar::tabMoved, this, &Shell::moveTabData );
|
2014-02-08 10:44:26 +00:00
|
|
|
|
|
|
|
setCentralWidget( m_tabWidget );
|
|
|
|
|
2008-10-06 17:39:30 +00:00
|
|
|
// then, setup our actions
|
|
|
|
setupActions();
|
2015-10-29 12:37:11 +00:00
|
|
|
connect( QCoreApplication::instance(), &QCoreApplication::aboutToQuit, this, &QObject::deleteLater );
|
2008-10-06 17:39:30 +00:00
|
|
|
// and integrate the part's GUI with the shell's
|
2008-10-12 16:28:57 +00:00
|
|
|
setupGUI(Keys | ToolBar | Save);
|
2014-02-08 10:44:26 +00:00
|
|
|
|
|
|
|
m_tabs.append( firstPart );
|
Overhaul annotations UX
Create a new new annotation toolbar to replace the current one as discussed in the task T8076.
Fixes:
BUG: 386578
BUG: 374728
BUG: 352310
BUG: 330518
BUG: 341914
BUG: 157289
BUG: 358057
BUG: 412767
BUG: 413595
BUG: 420462
FIXED-IN: 1.11.0
Test Plan
Before testing this revision
Delete or Temporary move aside the following files:
~/.config/okularpartrc
~/.config/okularrc
~/.local/share/kxmlgui5/okular/part.rc
~/.local/share/kxmlgui5/okular/shell.rc
Nomenclature
Actions in the main toolbar:
Quick annotations
Actions in the annotation toolbar:
Annotation actions Highlighter, Underline, Squiggle, Strike out, Typewriter,
Inline note, Popup note, Freehand line, Arrow, Straight line, Rectangle, Ellipse,
Polygon, Stamp
Annotation config actions Line width, Color, Inner color, Opacity, Font, Annotation settings
Other actions Add to Quick Annotations, Pin
Autotests
First run: annotation toolbar is not visible
Selecting Tools > Annotations shows the annotation toolbar (below the main toolbar by default)
Select an annotation > toolbar is shown
Select a quick annotation > toolbar is shown
Hide action (red cross) on the toolbar hides the toolbar
Keys 1-9,0 select the (builtin) Annotation actions (one case tested)
Keys Alt+1-9,0 select the quick annotation actions (one case tested)
No annotation action selected: Quick Annotations is enabled, Add to quick annotations is disabled, Annotation config actions are disabled, Pin is enabled
The current document is an image: Highlighter, Underline, Squiggle, Strike out are disabled (also in Quick annotations)
The current document is protected: All actions are disabled
Select annotation: the Annotation config actions are enabled and their values set to the ones for the current annotation (taken from okularpartrc)
Click an annotation action when none selected: browse mode is selected
Click the currently selected annotation action: the action is unchecked and the tool disabled (back to browse mode)
Click ESC: the currently selected annotation action is unchecked
If Pin unchecked the selected annotation is unchecked after it has be used once and we are back to Browse mode
The annotation systems works when multiple Okular tabs are open (the selected annotation is per-tab)
Manual tests
(TODO) Check that kconf_update updates the key AnnotationTools to QuickAnnotationTools in ~/.config/okularpartrc
Color icon is a format-text-color (if inline note or typewriter) or format-stroke-color for all other annotations
All actions have tooltips (some change based on the fact that the icon is enabled or not)
If a custom Line Width or Opacity is set through the Annotation Settings dialog, its value appears as a new checked action in the Line width or Opacity menu
If a custom stamp is selected through the Annotation Settings dialog, its name or filename (without path) appears as a new checked action in the Stamp menu
In Configure Okular > Annotations it is only possible to configure the quick annotations. Modifying them here updates the Quick annotations list after clicking Apply
The current document is an image: Highlighter, Underline, Squiggle, Strike out are disabled in Quick annotations
The state of Pin action is remembered across Okular launches
Selecting a quick action selects the corresponding action and loads its config values (color, line width, ...)
Setting the color and fill color works for all annotations (to be tested carefully, can be problematic for typewriter and inline note given the different internal mechanism to store the color in the settings)
Test stamp annotation (handled differently from the rest of the annotations)
Merge Request: https://invent.kde.org/graphics/okular/-/merge_requests/105
2020-06-04 13:01:31 +00:00
|
|
|
m_tabWidget->addTab( firstPart->widget(), QString() ); // triggers setActiveTab that calls createGUI( part )
|
|
|
|
|
|
|
|
connectPart( firstPart );
|
2008-10-06 17:39:30 +00:00
|
|
|
|
2012-12-20 23:32:27 +00:00
|
|
|
readSettings();
|
|
|
|
|
2014-08-08 20:35:53 +00:00
|
|
|
m_unique = ShellUtils::unique(serializedOptions);
|
|
|
|
if (m_unique)
|
2012-10-08 21:58:47 +00:00
|
|
|
{
|
2015-10-29 12:37:11 +00:00
|
|
|
m_unique = QDBusConnection::sessionBus().registerService(QStringLiteral("org.kde.okular"));
|
2012-10-08 21:58:47 +00:00
|
|
|
if (!m_unique)
|
|
|
|
KMessageBox::information(this, i18n("There is already a unique Okular instance running. This instance won't be the unique one."));
|
|
|
|
}
|
2016-07-12 19:12:58 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
QString serviceName = QStringLiteral("org.kde.okular-") + QString::number(qApp->applicationPid());
|
|
|
|
QDBusConnection::sessionBus().registerService(serviceName);
|
|
|
|
}
|
2014-08-08 20:35:53 +00:00
|
|
|
if (ShellUtils::noRaise(serializedOptions))
|
2013-03-09 15:34:45 +00:00
|
|
|
{
|
|
|
|
setAttribute(Qt::WA_ShowWithoutActivating);
|
|
|
|
}
|
2015-04-03 20:29:38 +00:00
|
|
|
|
2015-10-29 12:37:11 +00:00
|
|
|
QDBusConnection::sessionBus().registerObject(QStringLiteral("/okularshell"), this, QDBusConnection::ExportScriptableSlots);
|
2008-09-21 22:52:02 +00:00
|
|
|
}
|
2012-10-08 22:08:05 +00:00
|
|
|
else
|
|
|
|
{
|
2014-10-01 22:56:00 +00:00
|
|
|
m_isValid = false;
|
2012-10-08 22:08:05 +00:00
|
|
|
KMessageBox::error(this, i18n("Unable to find the Okular component."));
|
|
|
|
}
|
2005-06-24 16:43:45 +00:00
|
|
|
}
|
|
|
|
|
2016-01-30 18:28:41 +00:00
|
|
|
bool Shell::eventFilter(QObject *obj, QEvent *event)
|
|
|
|
{
|
2016-07-11 20:57:11 +00:00
|
|
|
Q_UNUSED(obj);
|
|
|
|
|
2016-01-30 18:28:41 +00:00
|
|
|
QDragMoveEvent* dmEvent = dynamic_cast<QDragMoveEvent*>(event);
|
|
|
|
if (dmEvent) {
|
|
|
|
bool accept = dmEvent->mimeData()->hasUrls();
|
|
|
|
event->setAccepted(accept);
|
|
|
|
return accept;
|
|
|
|
}
|
|
|
|
|
|
|
|
QDropEvent* dEvent = dynamic_cast<QDropEvent*>(event);
|
|
|
|
if (dEvent) {
|
|
|
|
const QList<QUrl> list = KUrlMimeData::urlsFromMimeData(dEvent->mimeData());
|
|
|
|
handleDroppedUrls(list);
|
|
|
|
dEvent->setAccepted(true);
|
|
|
|
return true;
|
|
|
|
}
|
2020-01-06 22:04:22 +00:00
|
|
|
|
|
|
|
// Handle middle button click events on the tab bar
|
|
|
|
if (obj == m_tabWidget && event->type() == QEvent::MouseButtonRelease) {
|
|
|
|
QMouseEvent* mEvent = static_cast<QMouseEvent*>(event);
|
|
|
|
if (mEvent->button() == Qt::MiddleButton) {
|
|
|
|
int tabIndex = m_tabWidget->tabBar()->tabAt(mEvent->pos());
|
|
|
|
if (tabIndex != -1) {
|
|
|
|
closeTab(tabIndex);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-02-20 17:45:46 +00:00
|
|
|
return KParts::MainWindow::eventFilter(obj, event);
|
2016-01-30 18:28:41 +00:00
|
|
|
}
|
|
|
|
|
2014-10-01 22:56:00 +00:00
|
|
|
bool Shell::isValid() const
|
|
|
|
{
|
|
|
|
return m_isValid;
|
|
|
|
}
|
|
|
|
|
2012-08-20 22:35:41 +00:00
|
|
|
void Shell::showOpenRecentMenu()
|
|
|
|
{
|
|
|
|
m_recent->menu()->popup(QCursor::pos());
|
|
|
|
}
|
|
|
|
|
2002-09-02 20:21:47 +00:00
|
|
|
Shell::~Shell()
|
|
|
|
{
|
2014-02-08 10:44:26 +00:00
|
|
|
if( !m_tabs.empty() )
|
2012-08-18 16:36:30 +00:00
|
|
|
{
|
|
|
|
writeSettings();
|
2020-01-02 23:16:36 +00:00
|
|
|
for( const TabState &tab : qAsConst( m_tabs ) )
|
2014-02-08 10:44:26 +00:00
|
|
|
{
|
2020-01-02 23:16:36 +00:00
|
|
|
tab.part->closeUrl( false );
|
2014-02-08 10:44:26 +00:00
|
|
|
}
|
2015-03-16 22:55:57 +00:00
|
|
|
m_tabs.clear();
|
2012-08-18 16:36:30 +00:00
|
|
|
}
|
2014-08-08 20:35:53 +00:00
|
|
|
if (m_unique)
|
2015-10-29 12:37:11 +00:00
|
|
|
QDBusConnection::sessionBus().unregisterService(QStringLiteral("org.kde.okular"));
|
2015-11-04 10:59:10 +00:00
|
|
|
|
|
|
|
delete m_tabWidget;
|
2002-09-02 20:21:47 +00:00
|
|
|
}
|
|
|
|
|
2014-04-09 21:29:13 +00:00
|
|
|
// Open a new document if we have space for it
|
|
|
|
// This can hang if called on a unique instance and openUrl pops a messageBox
|
2016-02-26 16:04:40 +00:00
|
|
|
bool Shell::openDocument( const QUrl& url, const QString &serializedOptions )
|
2014-04-09 21:29:13 +00:00
|
|
|
{
|
|
|
|
if( m_tabs.size() <= 0 )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
KParts::ReadWritePart* const part = m_tabs[0].part;
|
|
|
|
|
|
|
|
// Return false if we can't open new tabs and the only part is occupied
|
2014-08-08 20:35:53 +00:00
|
|
|
if ( !dynamic_cast<Okular::ViewerInterface*>(part)->openNewFilesInTabs()
|
|
|
|
&& !part->url().isEmpty()
|
|
|
|
&& !ShellUtils::unique(serializedOptions))
|
|
|
|
{
|
2014-04-09 21:29:13 +00:00
|
|
|
return false;
|
2014-08-08 20:35:53 +00:00
|
|
|
}
|
2014-04-09 21:29:13 +00:00
|
|
|
|
2014-08-08 20:35:53 +00:00
|
|
|
openUrl( url, serializedOptions );
|
2014-04-09 21:29:13 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-02-26 16:04:40 +00:00
|
|
|
bool Shell::openDocument( const QString& urlString, const QString &serializedOptions )
|
|
|
|
{
|
|
|
|
return openDocument(QUrl(urlString), serializedOptions);
|
|
|
|
}
|
|
|
|
|
2014-04-09 21:29:13 +00:00
|
|
|
bool Shell::canOpenDocs( int numDocs, int desktop )
|
|
|
|
{
|
|
|
|
if( m_tabs.size() <= 0 || numDocs <= 0 || m_unique )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
KParts::ReadWritePart* const part = m_tabs[0].part;
|
|
|
|
const bool allowTabs = dynamic_cast<Okular::ViewerInterface*>(part)->openNewFilesInTabs();
|
|
|
|
|
|
|
|
if( !allowTabs && (numDocs > 1 || !part->url().isEmpty()) )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
const KWindowInfo winfo( window()->effectiveWinId(), KWindowSystem::WMDesktop );
|
|
|
|
if( winfo.desktop() != desktop )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-08-14 11:35:43 +00:00
|
|
|
void Shell::openUrl( const QUrl & url, const QString &serializedOptions )
|
2003-09-14 17:44:18 +00:00
|
|
|
{
|
2014-02-08 10:44:26 +00:00
|
|
|
const int activeTab = m_tabWidget->currentIndex();
|
|
|
|
if ( activeTab < m_tabs.size() )
|
2005-01-27 17:31:07 +00:00
|
|
|
{
|
2014-02-08 11:15:15 +00:00
|
|
|
KParts::ReadWritePart* const activePart = m_tabs[activeTab].part;
|
|
|
|
if( !activePart->url().isEmpty() )
|
2012-09-04 18:04:01 +00:00
|
|
|
{
|
2012-09-19 20:40:06 +00:00
|
|
|
if( m_unique )
|
|
|
|
{
|
2014-08-08 20:35:53 +00:00
|
|
|
applyOptionsToPart( activePart, serializedOptions );
|
|
|
|
activePart->openUrl( url );
|
2012-09-19 20:40:06 +00:00
|
|
|
}
|
2012-09-19 20:44:18 +00:00
|
|
|
else
|
|
|
|
{
|
2014-02-08 11:15:15 +00:00
|
|
|
if( dynamic_cast<Okular::ViewerInterface *>(activePart)->openNewFilesInTabs() )
|
2014-02-08 10:44:26 +00:00
|
|
|
{
|
2014-08-08 20:35:53 +00:00
|
|
|
openNewTab( url, serializedOptions );
|
2014-02-08 10:44:26 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-08-08 20:35:53 +00:00
|
|
|
Shell* newShell = new Shell( serializedOptions );
|
2014-02-08 10:44:26 +00:00
|
|
|
newShell->show();
|
2014-09-09 14:09:40 +00:00
|
|
|
newShell->openUrl( url, serializedOptions );
|
2014-02-08 10:44:26 +00:00
|
|
|
}
|
2012-09-19 20:44:18 +00:00
|
|
|
}
|
2012-09-04 18:04:01 +00:00
|
|
|
}
|
2012-09-19 20:44:18 +00:00
|
|
|
else
|
2008-11-09 21:40:06 +00:00
|
|
|
{
|
2014-02-08 10:44:26 +00:00
|
|
|
m_tabWidget->setTabText( activeTab, url.fileName() );
|
2014-08-08 20:35:53 +00:00
|
|
|
applyOptionsToPart( activePart, serializedOptions );
|
2014-02-08 11:15:15 +00:00
|
|
|
bool openOk = activePart->openUrl( url );
|
2018-05-09 00:45:12 +00:00
|
|
|
const bool isstdin = url.fileName() == QLatin1String( "-" ) || url.scheme() == QLatin1String( "fd" );
|
2012-09-19 20:44:18 +00:00
|
|
|
if ( !isstdin )
|
|
|
|
{
|
|
|
|
if ( openOk )
|
2012-10-04 18:17:13 +00:00
|
|
|
{
|
2018-04-13 15:35:17 +00:00
|
|
|
#ifdef WITH_KACTIVITIES
|
2012-10-04 18:17:13 +00:00
|
|
|
if ( !m_activityResource )
|
|
|
|
m_activityResource = new KActivities::ResourceInstance( window()->winId(), this );
|
|
|
|
|
|
|
|
m_activityResource->setUri( url );
|
|
|
|
#endif
|
2012-09-19 20:44:18 +00:00
|
|
|
m_recent->addUrl( url );
|
2012-10-04 18:17:13 +00:00
|
|
|
}
|
2012-09-19 20:44:18 +00:00
|
|
|
else
|
2020-02-10 23:22:06 +00:00
|
|
|
{
|
2012-09-19 20:44:18 +00:00
|
|
|
m_recent->removeUrl( url );
|
2020-02-10 23:22:06 +00:00
|
|
|
closeTab( activeTab );
|
|
|
|
}
|
2012-09-19 20:44:18 +00:00
|
|
|
}
|
2008-11-09 21:40:06 +00:00
|
|
|
}
|
2005-01-27 17:31:07 +00:00
|
|
|
}
|
2003-09-14 17:44:18 +00:00
|
|
|
}
|
|
|
|
|
2012-09-04 18:04:01 +00:00
|
|
|
void Shell::closeUrl()
|
|
|
|
{
|
2014-02-08 10:44:26 +00:00
|
|
|
closeTab( m_tabWidget->currentIndex() );
|
2012-09-04 18:04:01 +00:00
|
|
|
}
|
2003-09-14 17:44:18 +00:00
|
|
|
|
|
|
|
void Shell::readSettings()
|
2002-09-02 20:21:47 +00:00
|
|
|
{
|
2014-09-12 08:54:00 +00:00
|
|
|
m_recent->loadEntries( KSharedConfig::openConfig()->group( "Recent Files" ) );
|
2005-01-27 17:31:07 +00:00
|
|
|
m_recent->setEnabled( true ); // force enabling
|
|
|
|
|
2014-09-12 08:54:00 +00:00
|
|
|
const KConfigGroup group = KSharedConfig::openConfig()->group( "Desktop Entry" );
|
2007-02-20 15:25:05 +00:00
|
|
|
bool fullScreen = group.readEntry( "FullScreen", false );
|
2003-09-15 12:12:53 +00:00
|
|
|
setFullScreen( fullScreen );
|
2015-04-03 20:29:38 +00:00
|
|
|
|
2010-10-14 19:22:55 +00:00
|
|
|
if (fullScreen)
|
|
|
|
{
|
|
|
|
m_menuBarWasShown = group.readEntry( shouldShowMenuBarComingFromFullScreen, true );
|
|
|
|
m_toolBarWasShown = group.readEntry( shouldShowToolBarComingFromFullScreen, true );
|
|
|
|
}
|
2002-09-02 20:21:47 +00:00
|
|
|
}
|
|
|
|
|
2003-09-14 17:44:18 +00:00
|
|
|
void Shell::writeSettings()
|
|
|
|
{
|
2014-09-12 08:54:00 +00:00
|
|
|
m_recent->saveEntries( KSharedConfig::openConfig()->group( "Recent Files" ) );
|
|
|
|
KConfigGroup group = KSharedConfig::openConfig()->group( "Desktop Entry" );
|
2007-02-20 15:25:05 +00:00
|
|
|
group.writeEntry( "FullScreen", m_fullScreenAction->isChecked() );
|
2010-10-14 19:22:55 +00:00
|
|
|
if (m_fullScreenAction->isChecked())
|
|
|
|
{
|
|
|
|
group.writeEntry( shouldShowMenuBarComingFromFullScreen, m_menuBarWasShown );
|
|
|
|
group.writeEntry( shouldShowToolBarComingFromFullScreen, m_toolBarWasShown );
|
|
|
|
}
|
2014-09-12 08:54:00 +00:00
|
|
|
KSharedConfig::openConfig()->sync();
|
2003-09-15 12:12:53 +00:00
|
|
|
}
|
|
|
|
|
2005-01-20 17:33:05 +00:00
|
|
|
void Shell::setupActions()
|
2002-09-02 20:21:47 +00:00
|
|
|
{
|
2006-12-19 12:23:43 +00:00
|
|
|
KStandardAction::open(this, SLOT(fileOpen()), actionCollection());
|
2014-08-13 16:33:42 +00:00
|
|
|
m_recent = KStandardAction::openRecent( this, SLOT(openUrl(QUrl)), actionCollection() );
|
2006-04-25 12:37:27 +00:00
|
|
|
m_recent->setToolBarMode( KRecentFilesAction::MenuMode );
|
2016-10-29 14:32:24 +00:00
|
|
|
connect( m_recent, &QAction::triggered, this, &Shell::showOpenRecentMenu );
|
2007-09-12 00:09:35 +00:00
|
|
|
m_recent->setToolTip( i18n("Click to open a file\nClick and hold to open a recent file") );
|
2005-01-27 17:31:07 +00:00
|
|
|
m_recent->setWhatsThis( i18n( "<b>Click</b> to open a file or <b>Click and hold</b> to select a recent file" ) );
|
2014-02-08 10:44:26 +00:00
|
|
|
m_printAction = KStandardAction::print( this, SLOT(print()), actionCollection() );
|
2005-01-27 17:31:07 +00:00
|
|
|
m_printAction->setEnabled( false );
|
2012-09-04 18:04:01 +00:00
|
|
|
m_closeAction = KStandardAction::close( this, SLOT(closeUrl()), actionCollection() );
|
|
|
|
m_closeAction->setEnabled( false );
|
2014-02-08 10:44:26 +00:00
|
|
|
KStandardAction::quit(this, SLOT(close()), actionCollection());
|
2002-09-02 20:21:47 +00:00
|
|
|
|
2003-03-17 04:10:33 +00:00
|
|
|
setStandardToolBarMenuEnabled(true);
|
2002-09-02 20:21:47 +00:00
|
|
|
|
2011-07-31 19:22:04 +00:00
|
|
|
m_showMenuBarAction = KStandardAction::showMenubar( this, SLOT(slotShowMenubar()), actionCollection());
|
|
|
|
m_fullScreenAction = KStandardAction::fullScreen( this, SLOT(slotUpdateFullScreen()), this,actionCollection() );
|
2014-02-08 10:44:26 +00:00
|
|
|
|
2015-10-29 12:37:11 +00:00
|
|
|
m_nextTabAction = actionCollection()->addAction(QStringLiteral("tab-next"));
|
2014-02-08 10:44:26 +00:00
|
|
|
m_nextTabAction->setText( i18n("Next Tab") );
|
2014-10-04 19:48:01 +00:00
|
|
|
actionCollection()->setDefaultShortcuts(m_nextTabAction, KStandardShortcut::tabNext());
|
2014-02-08 10:44:26 +00:00
|
|
|
m_nextTabAction->setEnabled( false );
|
2015-10-29 12:37:11 +00:00
|
|
|
connect( m_nextTabAction, &QAction::triggered, this, &Shell::activateNextTab );
|
2014-02-08 10:44:26 +00:00
|
|
|
|
2015-10-29 12:37:11 +00:00
|
|
|
m_prevTabAction = actionCollection()->addAction(QStringLiteral("tab-previous"));
|
2014-02-08 10:44:26 +00:00
|
|
|
m_prevTabAction->setText( i18n("Previous Tab") );
|
2014-10-04 19:48:01 +00:00
|
|
|
actionCollection()->setDefaultShortcuts(m_prevTabAction, KStandardShortcut::tabPrev());
|
2014-02-08 10:44:26 +00:00
|
|
|
m_prevTabAction->setEnabled( false );
|
2015-10-29 12:37:11 +00:00
|
|
|
connect( m_prevTabAction, &QAction::triggered, this, &Shell::activatePrevTab );
|
2020-01-06 22:04:22 +00:00
|
|
|
|
|
|
|
m_undoCloseTab = actionCollection()->addAction(QStringLiteral("undo-close-tab"));
|
|
|
|
m_undoCloseTab->setText( i18n("Undo close tab") );
|
|
|
|
actionCollection()->setDefaultShortcut(m_undoCloseTab, QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_T));
|
|
|
|
m_undoCloseTab->setIcon(QIcon::fromTheme(QStringLiteral("edit-undo")));
|
|
|
|
m_undoCloseTab->setEnabled( false );
|
|
|
|
connect( m_undoCloseTab, &QAction::triggered, this, &Shell::undoCloseTab );
|
2002-09-02 20:21:47 +00:00
|
|
|
}
|
|
|
|
|
2007-02-20 15:48:18 +00:00
|
|
|
void Shell::saveProperties(KConfigGroup &group)
|
2002-09-02 20:21:47 +00:00
|
|
|
{
|
2015-08-03 10:58:30 +00:00
|
|
|
if ( !m_isValid ) // part couldn't be loaded, nothing to save
|
|
|
|
return;
|
|
|
|
|
2015-03-16 22:55:57 +00:00
|
|
|
// Gather lists of settings to preserve
|
|
|
|
QStringList urls;
|
2020-01-02 23:16:36 +00:00
|
|
|
for( const TabState &tab : qAsConst( m_tabs ) )
|
2015-03-16 22:55:57 +00:00
|
|
|
{
|
2020-01-02 23:16:36 +00:00
|
|
|
urls.append( tab.part->url().url() );
|
2015-03-16 22:55:57 +00:00
|
|
|
}
|
|
|
|
group.writePathEntry( SESSION_URL_KEY, urls );
|
|
|
|
group.writeEntry( SESSION_TAB_KEY, m_tabWidget->currentIndex() );
|
2002-09-02 20:21:47 +00:00
|
|
|
}
|
|
|
|
|
2007-02-21 15:12:57 +00:00
|
|
|
void Shell::readProperties(const KConfigGroup &group)
|
2002-09-02 20:21:47 +00:00
|
|
|
{
|
2015-03-16 22:55:57 +00:00
|
|
|
// Reopen documents based on saved settings
|
|
|
|
QStringList urls = group.readPathEntry( SESSION_URL_KEY, QStringList() );
|
2018-10-27 11:49:45 +00:00
|
|
|
int desiredTab = group.readEntry<int>( SESSION_TAB_KEY, 0 );
|
2015-03-16 22:55:57 +00:00
|
|
|
|
|
|
|
while( !urls.isEmpty() )
|
|
|
|
{
|
2015-03-17 07:47:52 +00:00
|
|
|
openUrl( QUrl(urls.takeFirst()) );
|
2015-03-16 22:55:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( desiredTab < m_tabs.size() )
|
|
|
|
{
|
|
|
|
setActiveTab( desiredTab );
|
|
|
|
}
|
2002-09-02 20:21:47 +00:00
|
|
|
}
|
|
|
|
|
2007-02-07 17:25:51 +00:00
|
|
|
QStringList Shell::fileFormats() const
|
2005-07-15 17:17:13 +00:00
|
|
|
{
|
2007-02-07 17:25:51 +00:00
|
|
|
QStringList supportedPatterns;
|
2005-07-15 17:17:13 +00:00
|
|
|
|
2015-10-29 12:37:11 +00:00
|
|
|
QString constraint( QStringLiteral("(Library == 'okularpart')") );
|
2008-01-02 00:37:51 +00:00
|
|
|
QLatin1String basePartService( "KParts/ReadOnlyPart" );
|
|
|
|
KService::List offers = KServiceTypeTrader::self()->query( basePartService, constraint );
|
2008-11-11 18:24:06 +00:00
|
|
|
KService::List::ConstIterator it = offers.constBegin(), itEnd = offers.constEnd();
|
2008-01-02 00:37:51 +00:00
|
|
|
for ( ; it != itEnd; ++it )
|
2007-02-07 17:25:51 +00:00
|
|
|
{
|
2008-01-02 00:37:51 +00:00
|
|
|
KService::Ptr service = *it;
|
2016-07-12 23:43:30 +00:00
|
|
|
QStringList mimeTypes = service->mimeTypes();
|
2016-05-30 22:13:36 +00:00
|
|
|
|
|
|
|
supportedPatterns += mimeTypes;
|
2005-07-15 17:17:13 +00:00
|
|
|
}
|
|
|
|
|
2007-02-07 17:25:51 +00:00
|
|
|
return supportedPatterns;
|
2005-07-15 17:17:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Shell::fileOpen()
|
|
|
|
{
|
|
|
|
// this slot is called whenever the File->Open menu is selected,
|
|
|
|
// the Open shortcut is pressed (usually CTRL+O) or the Open toolbar
|
|
|
|
// button is clicked
|
2014-02-08 10:44:26 +00:00
|
|
|
const int activeTab = m_tabWidget->currentIndex();
|
2007-07-29 21:36:02 +00:00
|
|
|
if ( !m_fileformatsscanned )
|
2007-05-24 20:41:29 +00:00
|
|
|
{
|
2014-02-08 10:44:26 +00:00
|
|
|
const KDocumentViewer* const doc = qobject_cast<KDocumentViewer*>(m_tabs[activeTab].part);
|
|
|
|
if ( doc )
|
|
|
|
m_fileformats = doc->supportedMimeTypes();
|
2007-05-24 20:41:29 +00:00
|
|
|
|
|
|
|
if ( m_fileformats.isEmpty() )
|
|
|
|
m_fileformats = fileFormats();
|
2005-07-15 17:17:13 +00:00
|
|
|
|
2007-07-29 21:36:02 +00:00
|
|
|
m_fileformatsscanned = true;
|
2005-07-15 17:17:13 +00:00
|
|
|
}
|
2007-07-29 21:36:02 +00:00
|
|
|
|
2016-01-30 19:00:25 +00:00
|
|
|
QUrl startDir;
|
2014-02-08 10:44:26 +00:00
|
|
|
const KParts::ReadWritePart* const curPart = m_tabs[activeTab].part;
|
|
|
|
if ( curPart->url().isLocalFile() )
|
2016-05-30 22:13:36 +00:00
|
|
|
startDir = KIO::upUrl(curPart->url());
|
2015-10-21 11:30:36 +00:00
|
|
|
|
2016-05-30 22:13:36 +00:00
|
|
|
QPointer<QFileDialog> dlg( new QFileDialog( this ));
|
|
|
|
dlg->setDirectoryUrl( startDir );
|
|
|
|
dlg->setAcceptMode( QFileDialog::AcceptOpen );
|
2016-07-13 00:16:05 +00:00
|
|
|
dlg->setOption( QFileDialog::HideNameFilterDetails, true );
|
2018-06-21 19:43:11 +00:00
|
|
|
dlg->setFileMode( QFileDialog::ExistingFiles ); // Allow selection of more than one file
|
2016-07-13 00:16:05 +00:00
|
|
|
|
|
|
|
QMimeDatabase mimeDatabase;
|
|
|
|
QSet<QString> globPatterns;
|
2016-08-13 19:57:04 +00:00
|
|
|
QMap<QString, QStringList> namedGlobs;
|
2019-12-12 22:48:27 +00:00
|
|
|
for ( const QString &mimeName : qAsConst(m_fileformats) ) {
|
2016-07-13 00:16:05 +00:00
|
|
|
QMimeType mimeType = mimeDatabase.mimeTypeForName( mimeName );
|
2016-08-13 19:59:17 +00:00
|
|
|
const QStringList globs( mimeType.globPatterns() );
|
|
|
|
if ( globs.isEmpty() ) {
|
|
|
|
continue;
|
|
|
|
}
|
2011-05-05 20:52:46 +00:00
|
|
|
|
2016-08-13 19:59:17 +00:00
|
|
|
globPatterns.unite( globs.toSet() ) ;
|
2016-07-13 00:16:05 +00:00
|
|
|
|
2016-08-13 19:59:17 +00:00
|
|
|
namedGlobs[ mimeType.comment() ].append( globs );
|
2011-05-05 20:52:46 +00:00
|
|
|
|
2012-05-23 21:43:44 +00:00
|
|
|
}
|
2016-08-13 19:57:04 +00:00
|
|
|
QStringList namePatterns;
|
2019-12-12 22:48:27 +00:00
|
|
|
for ( auto it = namedGlobs.cbegin(); it != namedGlobs.cend(); ++it ) {
|
|
|
|
namePatterns.append( it.key() + QLatin1String(" (")
|
|
|
|
+ it.value().join( QLatin1Char(' ') ) + QLatin1Char(')')
|
2016-07-13 00:16:05 +00:00
|
|
|
);
|
|
|
|
}
|
2002-09-02 20:21:47 +00:00
|
|
|
|
2020-02-20 10:22:57 +00:00
|
|
|
const QStringList allGlobPatterns = globPatterns.values();
|
2016-07-13 00:16:05 +00:00
|
|
|
namePatterns.prepend( i18n("All files (*)") );
|
2020-02-20 10:22:57 +00:00
|
|
|
namePatterns.prepend( i18n("All supported files (%1)", allGlobPatterns.join( QLatin1Char(' ') ) ) );
|
2016-07-13 00:16:05 +00:00
|
|
|
dlg->setNameFilters( namePatterns );
|
2011-05-05 20:52:46 +00:00
|
|
|
|
2016-07-13 00:16:05 +00:00
|
|
|
dlg->setWindowTitle( i18n("Open Document") );
|
2016-08-13 20:20:43 +00:00
|
|
|
if ( dlg->exec() && dlg ) {
|
2019-12-12 22:48:27 +00:00
|
|
|
const QList<QUrl> urlList = dlg->selectedUrls();
|
|
|
|
for (const QUrl &url : urlList)
|
2016-08-13 20:20:43 +00:00
|
|
|
{
|
|
|
|
openUrl( url );
|
|
|
|
}
|
|
|
|
}
|
2016-05-30 22:13:36 +00:00
|
|
|
|
2016-08-13 20:20:43 +00:00
|
|
|
if ( dlg ) {
|
|
|
|
delete dlg.data();
|
2012-05-23 21:43:44 +00:00
|
|
|
}
|
2003-09-14 19:04:36 +00:00
|
|
|
}
|
2003-09-15 12:12:53 +00:00
|
|
|
|
2012-08-21 22:41:31 +00:00
|
|
|
void Shell::tryRaise()
|
|
|
|
{
|
2014-04-09 21:29:13 +00:00
|
|
|
KWindowSystem::forceActiveWindow( window()->effectiveWinId() );
|
2012-08-21 22:41:31 +00:00
|
|
|
}
|
|
|
|
|
2004-12-13 00:27:09 +00:00
|
|
|
// only called when starting the program
|
2003-09-15 12:12:53 +00:00
|
|
|
void Shell::setFullScreen( bool useFullScreen )
|
|
|
|
{
|
2003-12-15 16:26:49 +00:00
|
|
|
if( useFullScreen )
|
2008-03-10 23:02:01 +00:00
|
|
|
setWindowState( windowState() | Qt::WindowFullScreen ); // set
|
2003-12-15 16:26:49 +00:00
|
|
|
else
|
2008-03-10 23:02:01 +00:00
|
|
|
setWindowState( windowState() & ~Qt::WindowFullScreen ); // reset
|
2003-12-15 16:26:49 +00:00
|
|
|
}
|
|
|
|
|
2014-05-11 16:21:18 +00:00
|
|
|
void Shell::setCaption( const QString &caption )
|
|
|
|
{
|
|
|
|
bool modified = false;
|
|
|
|
|
|
|
|
const int activeTab = m_tabWidget->currentIndex();
|
|
|
|
if ( activeTab >= 0 && activeTab < m_tabs.size() )
|
|
|
|
{
|
|
|
|
KParts::ReadWritePart* const activePart = m_tabs[activeTab].part;
|
2017-11-13 16:59:13 +00:00
|
|
|
QString tabCaption = activePart->url().fileName();
|
|
|
|
if ( activePart->isModified() ) {
|
2014-05-11 16:21:18 +00:00
|
|
|
modified = true;
|
2017-11-13 16:59:13 +00:00
|
|
|
if ( !tabCaption.isEmpty() ) {
|
|
|
|
tabCaption.append( QStringLiteral( " *" ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
m_tabWidget->setTabText( activeTab, tabCaption );
|
2014-05-11 16:21:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
setCaption( caption, modified );
|
|
|
|
}
|
|
|
|
|
2008-12-18 22:08:39 +00:00
|
|
|
void Shell::showEvent(QShowEvent *e)
|
|
|
|
{
|
2017-07-02 15:58:57 +00:00
|
|
|
if (!menuBar()->isNativeMenuBar() && m_showMenuBarAction)
|
2011-06-02 19:26:20 +00:00
|
|
|
m_showMenuBarAction->setChecked( menuBar()->isVisible() );
|
2008-12-18 22:08:39 +00:00
|
|
|
|
|
|
|
KParts::MainWindow::showEvent(e);
|
|
|
|
}
|
|
|
|
|
2003-12-15 16:26:49 +00:00
|
|
|
void Shell::slotUpdateFullScreen()
|
|
|
|
{
|
2004-12-13 00:27:09 +00:00
|
|
|
if(m_fullScreenAction->isChecked())
|
2003-09-15 12:12:53 +00:00
|
|
|
{
|
2009-01-19 19:13:32 +00:00
|
|
|
m_menuBarWasShown = !menuBar()->isHidden();
|
2004-12-13 00:27:09 +00:00
|
|
|
menuBar()->hide();
|
2015-04-03 20:29:38 +00:00
|
|
|
|
2009-01-19 19:13:32 +00:00
|
|
|
m_toolBarWasShown = !toolBar()->isHidden();
|
2004-12-13 00:27:09 +00:00
|
|
|
toolBar()->hide();
|
2008-03-10 23:02:01 +00:00
|
|
|
|
2015-04-03 20:29:38 +00:00
|
|
|
KToggleFullScreenAction::setFullScreen(this, true);
|
2003-09-15 12:12:53 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-12-13 00:27:09 +00:00
|
|
|
if (m_menuBarWasShown)
|
|
|
|
{
|
|
|
|
menuBar()->show();
|
|
|
|
}
|
|
|
|
if (m_toolBarWasShown)
|
|
|
|
{
|
|
|
|
toolBar()->show();
|
|
|
|
}
|
2015-04-03 20:29:38 +00:00
|
|
|
KToggleFullScreenAction::setFullScreen(this, false);
|
2003-09-15 12:12:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-01-03 15:51:05 +00:00
|
|
|
void Shell::slotShowMenubar()
|
|
|
|
{
|
2009-01-19 19:13:32 +00:00
|
|
|
if ( menuBar()->isHidden() )
|
2005-01-03 15:51:05 +00:00
|
|
|
menuBar()->show();
|
|
|
|
else
|
|
|
|
menuBar()->hide();
|
|
|
|
}
|
|
|
|
|
2009-01-17 13:39:21 +00:00
|
|
|
QSize Shell::sizeHint() const
|
|
|
|
{
|
|
|
|
return QApplication::desktop()->availableGeometry( this ).size() * 0.75;
|
|
|
|
}
|
|
|
|
|
2012-05-23 21:43:44 +00:00
|
|
|
bool Shell::queryClose()
|
|
|
|
{
|
2017-09-12 20:32:36 +00:00
|
|
|
if (m_tabs.count() > 1)
|
|
|
|
{
|
2019-04-25 21:10:48 +00:00
|
|
|
const QString dontAskAgainName = QStringLiteral("ShowTabWarning");
|
2019-07-02 22:15:31 +00:00
|
|
|
KMessageBox::ButtonCode dummy = KMessageBox::Yes;
|
2017-09-12 20:32:36 +00:00
|
|
|
if (shouldBeShownYesNo(dontAskAgainName, dummy))
|
|
|
|
{
|
|
|
|
QDialog *dialog = new QDialog(this);
|
|
|
|
dialog->setWindowTitle(i18n("Confirm Close"));
|
|
|
|
|
|
|
|
QDialogButtonBox *buttonBox = new QDialogButtonBox(dialog);
|
|
|
|
buttonBox->setStandardButtons(QDialogButtonBox::Yes | QDialogButtonBox::No);
|
2019-04-25 21:10:48 +00:00
|
|
|
KGuiItem::assign(buttonBox->button(QDialogButtonBox::Yes), KGuiItem(i18n("Close Tabs"), QStringLiteral("tab-close")));
|
2017-09-12 20:32:36 +00:00
|
|
|
KGuiItem::assign(buttonBox->button(QDialogButtonBox::No), KStandardGuiItem::cancel());
|
|
|
|
|
|
|
|
|
|
|
|
bool checkboxResult = true;
|
|
|
|
const int result = KMessageBox::createKMessageBox(dialog, buttonBox, QMessageBox::Question,
|
2017-09-18 20:20:42 +00:00
|
|
|
i18n("You are about to close %1 tabs. Are you sure you want to continue?", m_tabs.count()), QStringList(),
|
2017-09-12 20:32:36 +00:00
|
|
|
i18n("Warn me when I attempt to close multiple tabs"),
|
|
|
|
&checkboxResult, KMessageBox::Notify);
|
|
|
|
|
|
|
|
if (!checkboxResult)
|
|
|
|
{
|
|
|
|
saveDontShowAgainYesNo(dontAskAgainName, dummy);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (result != QDialogButtonBox::Yes)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-08 10:44:26 +00:00
|
|
|
for( int i = 0; i < m_tabs.size(); ++i )
|
|
|
|
{
|
|
|
|
KParts::ReadWritePart* const part = m_tabs[i].part;
|
|
|
|
|
|
|
|
// To resolve confusion about multiple modified docs, switch to relevant tab
|
|
|
|
if( part->isModified() )
|
|
|
|
setActiveTab( i );
|
|
|
|
|
|
|
|
if( !part->queryClose() )
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Shell::setActiveTab( int tab )
|
|
|
|
{
|
|
|
|
m_tabWidget->setCurrentIndex( tab );
|
|
|
|
createGUI( m_tabs[tab].part );
|
|
|
|
m_printAction->setEnabled( m_tabs[tab].printEnabled );
|
|
|
|
m_closeAction->setEnabled( m_tabs[tab].closeEnabled );
|
|
|
|
}
|
|
|
|
|
|
|
|
void Shell::closeTab( int tab )
|
|
|
|
{
|
|
|
|
KParts::ReadWritePart* const part = m_tabs[tab].part;
|
2020-01-06 22:04:22 +00:00
|
|
|
QUrl url = part->url();
|
2014-02-08 10:44:26 +00:00
|
|
|
if( part->closeUrl() && m_tabs.count() > 1 )
|
|
|
|
{
|
|
|
|
if( part->factory() )
|
|
|
|
part->factory()->removeClient( part );
|
|
|
|
part->disconnect();
|
|
|
|
part->deleteLater();
|
|
|
|
m_tabs.removeAt( tab );
|
|
|
|
m_tabWidget->removeTab( tab );
|
2020-01-06 22:04:22 +00:00
|
|
|
m_undoCloseTab->setEnabled( true );
|
|
|
|
m_closedTabUrls.append( url );
|
2014-02-08 10:44:26 +00:00
|
|
|
|
|
|
|
if( m_tabWidget->count() == 1 )
|
|
|
|
{
|
2014-09-09 15:49:10 +00:00
|
|
|
m_tabWidget->tabBar()->hide();
|
2014-02-08 10:44:26 +00:00
|
|
|
m_nextTabAction->setEnabled( false );
|
|
|
|
m_prevTabAction->setEnabled( false );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-08-14 11:35:43 +00:00
|
|
|
void Shell::openNewTab( const QUrl& url, const QString &serializedOptions )
|
2014-02-08 10:44:26 +00:00
|
|
|
{
|
2020-04-23 07:39:32 +00:00
|
|
|
const int previousActiveTab = m_tabWidget->currentIndex();
|
|
|
|
KParts::ReadWritePart* const activePart = m_tabs[previousActiveTab].part;
|
|
|
|
|
|
|
|
bool activateTabIfAlreadyOpen;
|
|
|
|
QMetaObject::invokeMethod( activePart, "activateTabIfAlreadyOpenFile", Q_RETURN_ARG( bool, activateTabIfAlreadyOpen ) );
|
|
|
|
|
|
|
|
if( activateTabIfAlreadyOpen ){
|
|
|
|
|
|
|
|
const int tabIndex = findTabIndex( url );
|
|
|
|
|
|
|
|
if ( tabIndex >= 0 ) {
|
|
|
|
setActiveTab( tabIndex );
|
|
|
|
m_recent->addUrl( url );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-16 23:33:56 +00:00
|
|
|
// Tabs are hidden when there's only one, so show it
|
|
|
|
if( m_tabs.size() == 1 )
|
|
|
|
{
|
|
|
|
m_tabWidget->tabBar()->show();
|
|
|
|
m_nextTabAction->setEnabled( true );
|
|
|
|
m_prevTabAction->setEnabled( true );
|
|
|
|
}
|
2014-02-08 10:44:26 +00:00
|
|
|
|
|
|
|
const int newIndex = m_tabs.size();
|
|
|
|
|
|
|
|
// Make new part
|
|
|
|
m_tabs.append( m_partFactory->create<KParts::ReadWritePart>(this) );
|
|
|
|
connectPart( m_tabs[newIndex].part );
|
|
|
|
|
2020-02-16 23:33:56 +00:00
|
|
|
// Update GUI
|
2014-02-08 10:44:26 +00:00
|
|
|
KParts::ReadWritePart* const part = m_tabs[newIndex].part;
|
2020-02-16 23:33:56 +00:00
|
|
|
m_tabWidget->addTab( part->widget(), url.fileName() );
|
|
|
|
|
2014-08-08 20:35:53 +00:00
|
|
|
applyOptionsToPart(part, serializedOptions);
|
|
|
|
|
|
|
|
setActiveTab( m_tabs.size() - 1 );
|
|
|
|
|
2014-02-08 10:44:26 +00:00
|
|
|
if( part->openUrl(url) )
|
2020-02-10 23:22:06 +00:00
|
|
|
{
|
2014-02-08 10:44:26 +00:00
|
|
|
m_recent->addUrl( url );
|
2020-02-10 23:22:06 +00:00
|
|
|
}
|
2014-08-08 20:35:53 +00:00
|
|
|
else
|
2020-02-10 23:22:06 +00:00
|
|
|
{
|
2014-08-08 20:35:53 +00:00
|
|
|
setActiveTab( previousActiveTab );
|
2020-02-10 23:22:06 +00:00
|
|
|
closeTab( m_tabs.size() - 1 );
|
|
|
|
m_recent->removeUrl( url );
|
|
|
|
}
|
2014-08-08 20:35:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Shell::applyOptionsToPart( QObject* part, const QString &serializedOptions )
|
|
|
|
{
|
|
|
|
KDocumentViewer* const doc = qobject_cast<KDocumentViewer*>(part);
|
2019-02-13 21:55:02 +00:00
|
|
|
const QString find = ShellUtils::find(serializedOptions);
|
2014-08-08 20:35:53 +00:00
|
|
|
if ( ShellUtils::startInPresentation(serializedOptions) )
|
|
|
|
doc->startPresentation();
|
|
|
|
if ( ShellUtils::showPrintDialog(serializedOptions) )
|
|
|
|
QMetaObject::invokeMethod( part, "enableStartWithPrint" );
|
2018-03-03 16:21:15 +00:00
|
|
|
if ( ShellUtils::showPrintDialogAndExit(serializedOptions) )
|
|
|
|
QMetaObject::invokeMethod( part, "enableExitAfterPrint" );
|
2019-02-13 21:55:02 +00:00
|
|
|
if(!find.isEmpty())
|
2020-02-19 16:45:37 +00:00
|
|
|
QMetaObject::invokeMethod( part, "enableStartWithFind", Q_ARG(QString, find ));
|
2014-02-08 10:44:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Shell::connectPart( QObject* part )
|
|
|
|
{
|
2020-02-20 14:48:08 +00:00
|
|
|
// We're abusing the fact we know the part is our part here
|
|
|
|
connect( this, SIGNAL(moveSplitter(int)), part, SLOT(moveSplitter(int)) ); // clazy:exclude=old-style-connect
|
|
|
|
connect( part, SIGNAL(enablePrintAction(bool)), this, SLOT(setPrintEnabled(bool))); // clazy:exclude=old-style-connect
|
|
|
|
connect( part, SIGNAL(enableCloseAction(bool)), this, SLOT(setCloseEnabled(bool))); // clazy:exclude=old-style-connect
|
|
|
|
connect( part, SIGNAL(mimeTypeChanged(QMimeType)), this, SLOT(setTabIcon(QMimeType))); // clazy:exclude=old-style-connect
|
|
|
|
connect( part, SIGNAL(urlsDropped(QList<QUrl>)), this, SLOT(handleDroppedUrls(QList<QUrl>)) ); // clazy:exclude=old-style-connect
|
|
|
|
connect( part, SIGNAL(fitWindowToPage(QSize,QSize)), this, SLOT(slotFitWindowToPage(QSize,QSize)) ); // clazy:exclude=old-style-connect
|
2014-02-08 10:44:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Shell::print()
|
|
|
|
{
|
|
|
|
QMetaObject::invokeMethod( m_tabs[m_tabWidget->currentIndex()].part, "slotPrint" );
|
|
|
|
}
|
|
|
|
|
|
|
|
void Shell::setPrintEnabled( bool enabled )
|
|
|
|
{
|
|
|
|
int i = findTabIndex( sender() );
|
|
|
|
if( i != -1 )
|
|
|
|
{
|
|
|
|
m_tabs[i].printEnabled = enabled;
|
|
|
|
if( i == m_tabWidget->currentIndex() )
|
|
|
|
m_printAction->setEnabled( enabled );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Shell::setCloseEnabled( bool enabled )
|
|
|
|
{
|
|
|
|
int i = findTabIndex( sender() );
|
|
|
|
if( i != -1 )
|
|
|
|
{
|
|
|
|
m_tabs[i].closeEnabled = enabled;
|
|
|
|
if( i == m_tabWidget->currentIndex() )
|
|
|
|
m_closeAction->setEnabled( enabled );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Shell::activateNextTab()
|
|
|
|
{
|
|
|
|
if( m_tabs.size() < 2 )
|
|
|
|
return;
|
|
|
|
|
|
|
|
const int activeTab = m_tabWidget->currentIndex();
|
|
|
|
const int nextTab = (activeTab == m_tabs.size()-1) ? 0 : activeTab+1;
|
|
|
|
|
|
|
|
setActiveTab( nextTab );
|
|
|
|
}
|
|
|
|
|
|
|
|
void Shell::activatePrevTab()
|
|
|
|
{
|
|
|
|
if( m_tabs.size() < 2 )
|
|
|
|
return;
|
|
|
|
|
|
|
|
const int activeTab = m_tabWidget->currentIndex();
|
|
|
|
const int prevTab = (activeTab == 0) ? m_tabs.size()-1 : activeTab-1;
|
|
|
|
|
|
|
|
setActiveTab( prevTab );
|
|
|
|
}
|
|
|
|
|
2020-01-06 22:04:22 +00:00
|
|
|
void Shell::undoCloseTab()
|
|
|
|
{
|
|
|
|
if ( m_closedTabUrls.isEmpty() )
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const QUrl lastTabUrl = m_closedTabUrls.takeLast();
|
|
|
|
|
|
|
|
if ( m_closedTabUrls.isEmpty() )
|
|
|
|
{
|
|
|
|
m_undoCloseTab->setEnabled(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
openUrl(lastTabUrl);
|
|
|
|
}
|
|
|
|
|
2014-09-11 13:18:05 +00:00
|
|
|
void Shell::setTabIcon( const QMimeType& mimeType )
|
2014-02-08 10:44:26 +00:00
|
|
|
{
|
|
|
|
int i = findTabIndex( sender() );
|
|
|
|
if( i != -1 )
|
|
|
|
{
|
2014-09-11 13:18:05 +00:00
|
|
|
m_tabWidget->setTabIcon( i, QIcon::fromTheme(mimeType.iconName()) );
|
2014-02-08 10:44:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-23 07:39:32 +00:00
|
|
|
int Shell::findTabIndex( QObject* sender ) const
|
2014-02-08 10:44:26 +00:00
|
|
|
{
|
|
|
|
for( int i = 0; i < m_tabs.size(); ++i )
|
|
|
|
{
|
|
|
|
if( m_tabs[i].part == sender )
|
|
|
|
{
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1;
|
2012-05-23 21:43:44 +00:00
|
|
|
}
|
|
|
|
|
2020-04-23 07:39:32 +00:00
|
|
|
int Shell::findTabIndex(const QUrl &url ) const
|
|
|
|
{
|
|
|
|
auto it = std::find_if( m_tabs.begin(), m_tabs.end(),
|
|
|
|
[&url]( const TabState state ){
|
|
|
|
return state.part->url() == url;
|
|
|
|
});
|
|
|
|
return ( it != m_tabs.end() ) ? std::distance( m_tabs.begin(), it ) : -1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-08-13 11:07:44 +00:00
|
|
|
void Shell::handleDroppedUrls( const QList<QUrl>& urls )
|
2014-04-09 21:29:13 +00:00
|
|
|
{
|
2019-12-12 22:48:27 +00:00
|
|
|
for ( const QUrl &url : urls )
|
2014-04-09 21:29:13 +00:00
|
|
|
{
|
|
|
|
openUrl( url );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-30 22:15:21 +00:00
|
|
|
void Shell::moveTabData( int from, int to )
|
|
|
|
{
|
|
|
|
m_tabs.move( from, to );
|
|
|
|
}
|
|
|
|
|
2020-02-20 17:45:46 +00:00
|
|
|
void Shell::slotFitWindowToPage(const QSize pageViewSize, const QSize pageSize )
|
2015-03-16 23:20:11 +00:00
|
|
|
{
|
|
|
|
const int xOffset = pageViewSize.width() - pageSize.width();
|
|
|
|
const int yOffset = pageViewSize.height() - pageSize.height();
|
|
|
|
showNormal();
|
|
|
|
resize( width() - xOffset, height() - yOffset);
|
2020-02-19 15:54:54 +00:00
|
|
|
emit moveSplitter(pageSize.width());
|
2015-03-16 23:20:11 +00:00
|
|
|
}
|
2010-10-14 19:22:55 +00:00
|
|
|
|
|
|
|
/* kate: replace-tabs on; indent-width 4; */
|