summaryrefslogtreecommitdiffstats
path: root/kpdf/shell
diff options
context:
space:
mode:
Diffstat (limited to 'kpdf/shell')
-rw-r--r--kpdf/shell/CMakeLists.txt2
-rw-r--r--kpdf/shell/dcop.h27
-rw-r--r--kpdf/shell/main.cpp59
-rw-r--r--kpdf/shell/shell.cpp613
-rw-r--r--kpdf/shell/shell.h82
-rw-r--r--kpdf/shell/shell.rc14
6 files changed, 674 insertions, 123 deletions
diff --git a/kpdf/shell/CMakeLists.txt b/kpdf/shell/CMakeLists.txt
index 30691f02..99ab138c 100644
--- a/kpdf/shell/CMakeLists.txt
+++ b/kpdf/shell/CMakeLists.txt
@@ -34,7 +34,7 @@ install( FILES shell.rc DESTINATION ${DATA_INSTALL_DIR}/kpdf )
##### kpdf (executable) #########################
tde_add_executable( kpdf AUTOMOC
- SOURCES main.cpp shell.cpp
+ SOURCES main.cpp shell.cpp dcop.skel
LINK tdeparts-shared
DESTINATION ${BIN_INSTALL_DIR}
)
diff --git a/kpdf/shell/dcop.h b/kpdf/shell/dcop.h
new file mode 100644
index 00000000..8b352c97
--- /dev/null
+++ b/kpdf/shell/dcop.h
@@ -0,0 +1,27 @@
+/***************************************************************************
+ * Copyright (C) 2025 by Philippe Mavridis <mavridisf@gmail.com> *
+ * *
+ * 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. *
+ ***************************************************************************/
+
+#ifndef KPDF_SHELL_IFACE_H
+#define KPDF_SHELL_IFACE_H
+
+#include <dcopobject.h>
+#include <kurl.h>
+
+class KPDFShellDCOPIface : virtual public DCOPObject
+{
+ K_DCOP
+
+ k_dcop:
+ virtual void openURL(const KURL & url) = 0;
+ virtual void addTab() = 0;
+ virtual void removeTab() = 0;
+ virtual const KURL currentTabURL() = 0;
+};
+
+#endif // KPDF_SHELL_IFACE_H \ No newline at end of file
diff --git a/kpdf/shell/main.cpp b/kpdf/shell/main.cpp
index 9b8d0a18..aa44bca6 100644
--- a/kpdf/shell/main.cpp
+++ b/kpdf/shell/main.cpp
@@ -16,7 +16,11 @@
#include <tdeapplication.h>
#include <tdeaboutdata.h>
#include <tdecmdlineargs.h>
+#include <tdeconfig.h>
#include <tdelocale.h>
+#include <dcopclient.h>
+#include <dcopref.h>
+#include <kdebug.h>
static const char description[] =
I18N_NOOP("KPDF, a TDE PDF viewer based on XPDF");
@@ -25,6 +29,7 @@ static const char version[] = "0.5.10";
static TDECmdLineOptions options[] =
{
+ { "new-instance", I18N_NOOP("Don't reuse existing instance"), 0 },
{ "+[URL]", I18N_NOOP("Document to open"), 0 },
TDECmdLineLastOption
};
@@ -60,18 +65,60 @@ int main(int argc, char** argv)
// no session.. just start up normally
TDECmdLineArgs* args = TDECmdLineArgs::parsedArgs();
- if (args->count() == 0)
+ DCOPClient *client = tdeApp->dcopClient();
+ if (!client->attach())
{
- KPDF::Shell* widget = new KPDF::Shell;
- widget->show();
+ kdError() << "KPDF::Shell cannot attach DCOP client" << endl;
+ return 2;
+ }
+
+ bool reuseKPDF;
+
+ if (args->isSet("new-instance"))
+ {
+ reuseKPDF = false;
}
else
{
- for (int i = 0; i < args->count(); ++i)
+ TDEConfig cfg("kpdfpartrc");
+ cfg.setGroup("General");
+ reuseKPDF = cfg.readBoolEntry("OpenInExistingKPDF", false);
+ }
+
+ TQCString kpdfInstance = "";
+ TQCString regName = client->registerAs(tdeApp->name(), true);
+
+ if (reuseKPDF && args->count())
+ {
+ QCStringList allClients = client->registeredApplications();
+ for (int c = 0; c < allClients.count(); ++c)
+ {
+ if (allClients[c].left(5) == "kpdf-" && allClients[c] != regName)
{
- KPDF::Shell* widget = new KPDF::Shell(args->url(i));
- widget->show();
+ kpdfInstance = allClients[c];
}
+ }
+ }
+
+ if (kpdfInstance.isEmpty())
+ {
+ KPDF::Shell* widget = new KPDF::Shell;
+ for (int i = 0; i < args->count(); ++i)
+ {
+ widget->openURL(args->url(i));
+ }
+ widget->show();
+ }
+ else
+ {
+ for (int i = 0; i < args->count(); ++i)
+ {
+ DCOPRef ref(kpdfInstance, "KPDFShellDCOPIface");
+ ref.call("openURL", args->url(i));
+ }
+ DCOPRef ref(kpdfInstance, "KPDF::Shell");
+ ref.call("raise");
+ return 1;
}
args->clear();
}
diff --git a/kpdf/shell/shell.cpp b/kpdf/shell/shell.cpp
index 209f8760..79d1d83d 100644
--- a/kpdf/shell/shell.cpp
+++ b/kpdf/shell/shell.cpp
@@ -20,18 +20,24 @@
// qt/kde includes
#include <tqcursor.h>
#include <tqtimer.h>
+#include <tqtoolbutton.h>
+#include <ktabwidget.h>
+#include <tqptrlist.h>
#include <tdeaction.h>
+#include <tdeconfig.h>
#include <tdeapplication.h>
#include <kedittoolbar.h>
#include <tdefiledialog.h>
#include <klibloader.h>
#include <tdemessagebox.h>
+#include <kiconloader.h>
#include <kstdaction.h>
#include <kurl.h>
#include <kdebug.h>
#include <tdelocale.h>
#include <tdemenubar.h>
#include <tdeparts/componentfactory.h>
+#include <tdeparts/partmanager.h>
#include <tdeio/netaccess.h>
#include <tdemainwindowiface.h>
@@ -41,13 +47,27 @@
using namespace KPDF;
Shell::Shell()
- : KParts::MainWindow(0, "KPDF::Shell"), m_menuBarWasShown(true), m_toolBarWasShown(true)
+ : DCOPObject("KPDFShellDCOPIface"), KParts::MainWindow(0, "KPDF::Shell"),
+ m_menuBarWasShown(true),
+ m_toolBarWasShown(true),
+ m_showToolBarAction(nullptr),
+ m_tabs(nullptr),
+ m_tabsContextMenu(nullptr),
+ m_manager(nullptr),
+ m_workingTab(-1)
{
init();
}
Shell::Shell(const KURL &url)
- : KParts::MainWindow(0, "KPDF::Shell"), m_menuBarWasShown(true), m_toolBarWasShown(true)
+ : DCOPObject("KPDFShellDCOPIface"), KParts::MainWindow(0, "KPDF::Shell"),
+ m_menuBarWasShown(true),
+ m_toolBarWasShown(true),
+ m_showToolBarAction(nullptr),
+ m_tabs(nullptr),
+ m_tabsContextMenu(nullptr),
+ m_manager(nullptr),
+ m_workingTab(-1)
{
m_openUrl = url;
init();
@@ -55,42 +75,39 @@ Shell::Shell(const KURL &url)
void Shell::init()
{
- // set the shell's ui resource file
- setXMLFile("shell.rc");
-
// 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
- KParts::Factory *factory = (KParts::Factory *) KLibLoader::self()->factory("libkpdfpart");
- if (factory)
- {
- // now that the Part is loaded, we cast it to a Part to get
- // our hands on it
- m_part = (KParts::ReadOnlyPart*) factory->createPart(this, "kpdf_part", TQT_TQOBJECT(this), 0, "KParts::ReadOnlyPart");
- if (m_part)
- {
- // then, setup our actions
- setupActions();
- // tell the KParts::MainWindow that this is indeed the main widget
- setCentralWidget(m_part->widget());
- // and integrate the part's GUI with the shell's
- setupGUI(Keys | Save);
- createGUI(m_part);
- m_showToolBarAction = static_cast<TDEToggleAction*>(toolBarMenuAction());
- }
- }
- else
+ m_factory = (KParts::Factory *) KLibLoader::self()->factory("libkpdfpart");
+ if (!m_factory)
{
// if we couldn't find our Part, we exit since the Shell by
// itself can't do anything useful
KMessageBox::error(this, i18n("Unable to find kpdf part."));
- m_part = 0;
+ TQTimer::singleShot(0, tdeApp, TQ_SLOT(quit()));
return;
}
- connect( this, TQT_SIGNAL( restoreDocument(TDEConfig*) ),m_part, TQT_SLOT( restoreDocument(TDEConfig*)));
- connect( this, TQT_SIGNAL( saveDocumentRestoreInfo(TDEConfig*) ), m_part, TQT_SLOT( saveDocumentRestoreInfo(TDEConfig*)));
- connect( m_part, TQT_SIGNAL( enablePrintAction(bool) ), m_printAction, TQT_SLOT( setEnabled(bool)));
-
+
+ m_tabs = new KTabWidget(this);
+ connect(m_tabs, TQ_SIGNAL(contextMenu(const TQPoint &)),
+ TQ_SLOT(slotTabContextMenu(const TQPoint &)));
+ connect(m_tabs, TQ_SIGNAL(contextMenu(TQWidget*, const TQPoint &)),
+ TQ_SLOT(slotTabContextMenu(TQWidget*, const TQPoint &)));
+ connect(m_tabs, TQ_SIGNAL(closeRequest(TQWidget*)),
+ TQ_SLOT(slotCloseTabRequest(TQWidget*)));
+
+ m_manager = new KParts::PartManager(this, "kpdf part manager");
+ connect(m_manager, TQ_SIGNAL(activePartChanged(KParts::Part*)),
+ this, TQ_SLOT(createGUI(KParts::Part*)));
+ connect(m_manager, TQ_SIGNAL(activePartChanged(KParts::Part*)),
+ this, TQ_SLOT(slotChangeTab(KParts::Part*)));
+
+ setCentralWidget(m_tabs);
+ setXMLFile("shell.rc");
+
+ setupActions();
+ setupGUI(Keys | Save);
+
readSettings();
if (!TDEGlobal::config()->hasGroup("MainWindow"))
{
@@ -98,67 +115,144 @@ void Shell::init()
kmwi.maximize();
}
setAutoSaveSettings();
-
- if (m_openUrl.isValid()) TQTimer::singleShot(0, this, TQT_SLOT(delayedOpen()));
+
+ addTab();
+ if (m_openUrl.isValid())
+ {
+ TQTimer::singleShot(0, this, TQ_SLOT(delayedOpen()));
+ }
+
+ reconfigure();
}
void Shell::delayedOpen()
{
- openURL(m_openUrl);
+ openURL(m_openUrl);
}
Shell::~Shell()
{
- if(m_part) writeSettings();
+ if (m_tabs)
+ {
+ writeSettings();
+ }
+}
+
+void Shell::reconfigure()
+{
+ TDEConfig cfg("kpdfpartrc");
+ cfg.setGroup("General");
+ m_tabs->setHoverCloseButton(cfg.readBoolEntry("TabsHoverCloseButton", false));
}
void Shell::openURL( const KURL & url )
{
- if ( m_part )
+ // if the current part has no url, reuse part
+ KParts::ReadOnlyPart *part = static_cast<KParts::ReadOnlyPart*>(m_manager->activePart());
+ if (!part || !part->url().isEmpty())
+ {
+ part = createTab();
+ }
+
+ if (part)
+ {
+ if (url.isValid())
{
- bool openOk = m_part->openURL( url );
- if ( openOk )
- m_recent->addURL( url );
- else
- m_recent->removeURL( url );
+ m_tabs->changeTab(part->widget(), url.filename());
+ m_tabs->setTabToolTip(part->widget(), url.prettyURL());
+ bool openOk = part->openURL(url);
+ if (openOk)
+ {
+ m_recent->addURL(url);
+ }
+ else
+ {
+ m_recent->removeURL(url);
+ }
}
+ }
}
+const KURL Shell::currentTabURL()
+{
+ KParts::ReadOnlyPart *part = static_cast<KParts::ReadOnlyPart*>(m_manager->activePart());
+ return part->url();
+}
void Shell::readSettings()
{
- m_recent->loadEntries( TDEGlobal::config() );
- m_recent->setEnabled( true ); // force enabling
- m_recent->setToolTip( i18n("Click to open a file\nClick and hold to open a recent file") );
+ m_recent->loadEntries( TDEGlobal::config() );
+ m_recent->setEnabled( true ); // force enabling
+ m_recent->setToolTip( i18n("Click to open a file\nClick and hold to open a recent file") );
- TDEGlobal::config()->setDesktopGroup();
- bool fullScreen = TDEGlobal::config()->readBoolEntry( "FullScreen", false );
- setFullScreen( fullScreen );
+ TDEGlobal::config()->setDesktopGroup();
+ bool fullScreen = TDEGlobal::config()->readBoolEntry( "FullScreen", false );
+ setFullScreen( fullScreen );
}
void Shell::writeSettings()
{
- m_recent->saveEntries( TDEGlobal::config() );
- TDEGlobal::config()->setDesktopGroup();
- TDEGlobal::config()->writeEntry( "FullScreen", m_fullScreenAction->isChecked());
- TDEGlobal::config()->sync();
+ m_recent->saveEntries( TDEGlobal::config() );
+ TDEGlobal::config()->setDesktopGroup();
+ TDEGlobal::config()->writeEntry( "FullScreen", m_fullScreenAction->isChecked());
+ TDEGlobal::config()->sync();
}
void Shell::setupActions()
{
- TDEAction * openAction = KStdAction::open(TQT_TQOBJECT(this), TQT_SLOT(fileOpen()), actionCollection());
- m_recent = KStdAction::openRecent( TQT_TQOBJECT(this), TQT_SLOT( openURL( const KURL& ) ), actionCollection() );
- connect( m_recent, TQT_SIGNAL( activated() ), openAction, TQT_SLOT( activate() ) );
- m_recent->setWhatsThis( i18n( "<b>Click</b> to open a file or <b>Click and hold</b> to select a recent file" ) );
- m_printAction = KStdAction::print( m_part, TQT_SLOT( slotPrint() ), actionCollection() );
- m_printAction->setEnabled( false );
- KStdAction::quit(TQT_TQOBJECT(this), TQT_SLOT(slotQuit()), actionCollection());
+ TDEAction *openAction = KStdAction::open(this, TQ_SLOT(fileOpen()), actionCollection());
+ m_recent = KStdAction::openRecent( this, TQ_SLOT(openURL(const KURL&)), actionCollection());
+ connect(m_recent, TQ_SIGNAL(activated()), openAction, TQ_SLOT( activate()));
+ m_recent->setWhatsThis(i18n("<b>Click</b> to open a file or <b>Click and hold</b> to select a recent file"));
+ m_printAction = KStdAction::print(this, TQ_SLOT(slotPrint()), actionCollection());
+ m_printAction->setEnabled(false);
+ KStdAction::quit(this, TQ_SLOT(slotQuit()), actionCollection());
setStandardToolBarMenuEnabled(true);
- m_showMenuBarAction = KStdAction::showMenubar( TQT_TQOBJECT(this), TQT_SLOT( slotShowMenubar() ), actionCollection());
- KStdAction::configureToolbars(TQT_TQOBJECT(this), TQT_SLOT(optionsConfigureToolbars()), actionCollection());
- m_fullScreenAction = KStdAction::fullScreen( TQT_TQOBJECT(this), TQT_SLOT( slotUpdateFullScreen() ), actionCollection(), this );
+ m_showMenuBarAction = KStdAction::showMenubar(this, TQ_SLOT(slotShowMenubar()), actionCollection());
+ KStdAction::configureToolbars(this, TQ_SLOT(optionsConfigureToolbars()), actionCollection());
+ m_fullScreenAction = KStdAction::fullScreen(this, TQ_SLOT(slotUpdateFullScreen()), actionCollection(), this);
+
+ TDEAction *addTab = new TDEAction(i18n("&New Tab"), SmallIcon("tab_new"), "Ctrl+Shift+N;Ctrl+T",
+ this, TQ_SLOT(addTab()), actionCollection(),
+ "newtab");
+
+ m_addTabButton = new TQToolButton(m_tabs);
+ m_addTabButton->setIconSet(SmallIconSet("tab_new"));
+ m_tabs->setCornerWidget(m_addTabButton, TQt::TopLeft);
+ connect(m_addTabButton, TQ_SIGNAL(clicked()), this, TQ_SLOT(addTab()));
+ m_addTabButton->show();
+
+ TDEAction *removeTab = new TDEAction(i18n("&Close Tab"), SmallIcon("tab_remove"), "Ctrl+W",
+ this, TQ_SLOT(removeTab()), actionCollection(),
+ "removecurrenttab");
+
+ m_removeTabButton = new TQToolButton(m_tabs);
+ m_removeTabButton->setIconSet(SmallIconSet("tab_remove"));
+ m_tabs->setCornerWidget(m_removeTabButton, TQt::TopRight);
+ connect(m_removeTabButton, TQ_SIGNAL(clicked()), this, TQ_SLOT(removeTab()));
+ m_removeTabButton->show();
+
+ TDEAction *duplicateTab = new TDEAction(i18n("&Duplicate Tab"), SmallIcon("tab_duplicate"), "Ctrl+Shift+D",
+ this, TQ_SLOT(slotDuplicateTab()), actionCollection(),
+ "duplicatecurrenttab");
+
+ TDEAction *breakOffTab = new TDEAction(i18n("D&etach Tab"), SmallIcon("tab_breakoff"), TQString::null,
+ this, TQ_SLOT(slotBreakOffTab()), actionCollection(),
+ "breakoffcurrenttab");
+
+ TDEAction *moveTabLeft = new TDEAction(i18n("Move Tab &Left"), SmallIcon("tab_move_left"), "Ctrl+Shift+Left",
+ this, TQ_SLOT(slotMoveTabLeft()), actionCollection(),
+ "tab_move_left");
+
+ TDEAction *moveTabRight = new TDEAction(i18n("Move Tab &Right"), SmallIcon("tab_move_right"), "Ctrl+Shift+Right",
+ this, TQ_SLOT(slotMoveTabRight()), actionCollection(),
+ "tab_move_right");
+
+ TDEAction *removeOtherTabs = new TDEAction(i18n("Close &Other Tabs"), SmallIcon("tab_remove_other"), "Ctrl+Alt+W",
+ this, TQ_SLOT(slotRemoveOtherTabs()), actionCollection(),
+ "removeothertabs");
}
void Shell::saveProperties(TDEConfig* config)
@@ -166,7 +260,7 @@ void Shell::saveProperties(TDEConfig* config)
// the 'config' object points to the session managed
// config file. anything you write here will be available
// later when this app is restored
- emit saveDocumentRestoreInfo(config);
+ emit saveDocumentRestoreInfo(config);
}
void Shell::readProperties(TDEConfig* config)
@@ -175,14 +269,13 @@ void Shell::readProperties(TDEConfig* config)
// config file. this function is automatically called whenever
// the app is being restored. read in here whatever you wrote
// in 'saveProperties'
- if(m_part)
+ if (m_manager->parts()->count() > 0)
{
emit restoreDocument(config);
}
}
- void
-Shell::fileOpen()
+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
@@ -190,26 +283,40 @@ Shell::fileOpen()
KURL url = KFileDialog::getOpenURL( TQString(), "application/pdf application/postscript" );//getOpenFileName();
if (!url.isEmpty())
+ {
openURL(url);
+ }
}
- void
-Shell::optionsConfigureToolbars()
+void Shell::optionsConfigureToolbars()
{
KEditToolbar dlg(factory());
- connect(&dlg, TQT_SIGNAL(newToolbarConfig()), this, TQT_SLOT(applyNewToolbarConfig()));
+ connect(&dlg, TQ_SIGNAL(newToolbarConfig()), this, TQ_SLOT(applyNewToolbarConfig()));
dlg.exec();
}
- void
-Shell::applyNewToolbarConfig()
+void Shell::applyNewToolbarConfig()
{
applyMainWindowSettings(TDEGlobal::config(), "MainWindow");
}
+void Shell::slotSetPrintActionEnabled(bool enabled)
+{
+ const KParts::Part *part = static_cast<const KParts::Part*>(TQObject::sender());
+ if (part == m_manager->activePart())
+ {
+ m_printAction->setEnabled(enabled);
+ }
+}
+
+void Shell::slotPrint()
+{
+ TQTimer::singleShot(0, m_manager->activePart(), TQ_SLOT(slotPrint()));
+}
+
void Shell::slotQuit()
{
- kapp->closeAllWindows();
+ tdeApp->closeAllWindows();
}
// only called when starting the program
@@ -223,40 +330,356 @@ void Shell::setFullScreen( bool useFullScreen )
void Shell::slotUpdateFullScreen()
{
- if(m_fullScreenAction->isChecked())
+ if(m_fullScreenAction->isChecked())
+ {
+ m_menuBarWasShown = m_showMenuBarAction->isChecked();
+ m_showMenuBarAction->setChecked(false);
+ menuBar()->hide();
+
+ m_toolBarWasShown = m_showToolBarAction->isChecked();
+ m_showToolBarAction->setChecked(false);
+ toolBar()->hide();
+
+ showFullScreen();
+ }
+ else
+ {
+ if (m_menuBarWasShown)
{
- m_menuBarWasShown = m_showMenuBarAction->isChecked();
- m_showMenuBarAction->setChecked(false);
- menuBar()->hide();
-
- m_toolBarWasShown = m_showToolBarAction->isChecked();
- m_showToolBarAction->setChecked(false);
- toolBar()->hide();
-
- showFullScreen();
+ m_showMenuBarAction->setChecked(true);
+ menuBar()->show();
}
- else
+ if (m_toolBarWasShown)
{
- if (m_menuBarWasShown)
- {
- m_showMenuBarAction->setChecked(true);
- menuBar()->show();
- }
- if (m_toolBarWasShown)
- {
- m_showToolBarAction->setChecked(true);
- toolBar()->show();
- }
- showNormal();
+ m_showToolBarAction->setChecked(true);
+ toolBar()->show();
}
+ showNormal();
+ }
}
void Shell::slotShowMenubar()
{
- if ( m_showMenuBarAction->isChecked() )
- menuBar()->show();
- else
- menuBar()->hide();
+ if ( m_showMenuBarAction->isChecked() )
+ menuBar()->show();
+ else
+ menuBar()->hide();
+}
+
+KParts::ReadOnlyPart* Shell::createTab()
+{
+ KParts::ReadOnlyPart *part =
+ (KParts::ReadOnlyPart*)m_factory->createPart(m_tabs, "kpdf_part",
+ m_tabs, nullptr,
+ "KParts::ReadOnlyPart");
+ m_tabs->addTab(part->widget(), SmallIcon("application-pdf"), i18n("No file"));
+
+ connect(this, TQ_SIGNAL(restoreDocument(TDEConfig*)),
+ part, TQ_SLOT(restoreDocument(TDEConfig*)));
+ connect(this, TQ_SIGNAL(saveDocumentRestoreInfo(TDEConfig*)),
+ part, TQ_SLOT(saveDocumentRestoreInfo(TDEConfig*)));
+ connect(part, TQ_SIGNAL(enablePrintAction(bool)),
+ this, TQ_SLOT(slotSetPrintActionEnabled(bool)));
+ connect(part, TQ_SIGNAL(setWindowCaption(const TQString&)),
+ this, TQ_SLOT(slotSetTabCaption(const TQString&)));
+
+ part->widget()->show();
+ m_manager->addPart(part, true);
+ if (!m_showToolBarAction)
+ {
+ m_showToolBarAction = static_cast<TDEToggleAction*>(toolBarMenuAction());
+ }
+ return part;
+}
+
+void Shell::addTab()
+{
+ createTab();
+}
+
+void Shell::removeTab()
+{
+ if (m_workingTab == -1)
+ {
+ m_workingTab = m_tabs->currentPageIndex();
+ }
+
+ KParts::ReadOnlyPart *part = findPartForTab(m_workingTab);
+ if (part)
+ {
+ m_tabs->removePage(part->widget());
+ part->deleteLater();
+ }
+
+ m_workingTab = -1;
+}
+
+void Shell::slotChangeTab(KParts::Part *part)
+{
+ if (!part)
+ {
+ part = createTab();
+ }
+
+ m_tabs->showPage(part->widget());
+}
+
+void Shell::initTabContextMenu()
+{
+ if (m_tabsContextMenu) return;
+
+ m_tabsContextMenu = new TQPopupMenu(this);
+ m_tabsContextMenu->insertItem(SmallIcon("tab_new"),
+ i18n("&New Tab"),
+ this, TQ_SLOT(addTab()),
+ action("newtab")->shortcut());
+ m_tabsContextMenu->insertItem(SmallIconSet("tab_duplicate"),
+ i18n("&Duplicate Tab"),
+ this, TQ_SLOT(slotDuplicateTab()),
+ action("duplicatecurrenttab")->shortcut(),
+ TabContextMenuItem::TabDuplicate);
+ m_tabsContextMenu->insertItem(SmallIconSet("tab_breakoff"),
+ i18n("D&etach Tab"),
+ this, TQ_SLOT(slotBreakOffTab()),
+ action("breakoffcurrenttab")->shortcut(),
+ TabContextMenuItem::TabBreakOff);
+ m_tabsContextMenu->insertSeparator();
+ m_tabsContextMenu->insertItem(SmallIconSet("1leftarrow"),
+ i18n("Move Tab &Left"),
+ this, TQ_SLOT(slotMoveTabLeft()),
+ action("tab_move_left")->shortcut(),
+ TabContextMenuItem::TabMoveLeft);
+ m_tabsContextMenu->insertItem(SmallIconSet("1rightarrow"),
+ i18n("Move Tab &Right"),
+ this, TQ_SLOT(slotMoveTabRight()),
+ action("tab_move_right")->shortcut(),
+ TabContextMenuItem::TabMoveRight);
+ m_tabsContextMenu->insertSeparator();
+ m_tabsContextMenu->insertItem(SmallIconSet("tab_remove"),
+ i18n("&Close Tab"),
+ this, TQ_SLOT(removeTab()),
+ action("removecurrenttab")->shortcut(),
+ TabContextMenuItem::TabRemove);
+ m_tabsContextMenu->insertItem(SmallIconSet("tab_remove_other"),
+ i18n("Close &Other Tabs"),
+ this, TQ_SLOT(slotRemoveOtherTabs()),
+ action("removeothertabs")->shortcut(),
+ TabContextMenuItem::TabRemoveOther);
+}
+
+void Shell::slotTabContextMenu(const TQPoint &pos)
+{
+ if (!m_tabsContextMenu)
+ {
+ initTabContextMenu();
+ }
+
+ m_tabsContextMenu->setItemEnabled(TabContextMenuItem::TabDuplicate, false);
+ m_tabsContextMenu->setItemEnabled(TabContextMenuItem::TabBreakOff, false);
+ m_tabsContextMenu->setItemEnabled(TabContextMenuItem::TabMoveLeft, false);
+ m_tabsContextMenu->setItemEnabled(TabContextMenuItem::TabMoveRight, false);
+ m_tabsContextMenu->setItemEnabled(TabContextMenuItem::TabRemove, false);
+ m_tabsContextMenu->setItemEnabled(TabContextMenuItem::TabRemoveOther, false);
+
+
+ m_tabsContextMenu->popup(pos);
+}
+void Shell::slotTabContextMenu(TQWidget *w, const TQPoint &pos)
+{
+ if (!m_tabsContextMenu)
+ {
+ initTabContextMenu();
+ }
+
+ m_tabsContextMenu->setItemEnabled(TabContextMenuItem::TabDuplicate, true);
+ m_tabsContextMenu->setItemEnabled(TabContextMenuItem::TabBreakOff, m_tabs->count() > 1);
+ m_tabsContextMenu->setItemEnabled(TabContextMenuItem::TabRemove, true);
+ m_tabsContextMenu->setItemEnabled(TabContextMenuItem::TabRemoveOther, true);
+
+ int idx = m_tabs->indexOf(w);
+ if (idx > -1)
+ {
+ m_tabsContextMenu->setItemEnabled(TabContextMenuItem::TabMoveLeft, idx > 0);
+ m_tabsContextMenu->setItemEnabled(TabContextMenuItem::TabMoveRight, idx + 1 < m_tabs->count());
+ }
+ else
+ {
+ m_tabsContextMenu->setItemEnabled(TabContextMenuItem::TabMoveLeft, false);
+ m_tabsContextMenu->setItemEnabled(TabContextMenuItem::TabMoveRight, false);
+ }
+
+ m_workingTab = m_tabs->indexOf(w);
+ m_tabsContextMenu->popup(pos);
+}
+
+KParts::ReadOnlyPart* Shell::findPartForTab(int tabIndex)
+{
+ if (tabIndex == -1) return nullptr;
+
+ TQWidget *page = m_tabs->page(tabIndex);
+ if (!page) return nullptr;
+
+ TQPtrList<KParts::Part> *parts = const_cast<TQPtrList<KParts::Part>*>(m_manager->parts());
+ KParts::Part *part;
+ for (part = parts->first(); part; part = parts->next())
+ {
+ if (part->widget() == page)
+ {
+ return static_cast<KParts::ReadOnlyPart*>(part);
+ }
+ }
+ return nullptr;
+}
+
+void Shell::moveTabForward(int tabIndex)
+{
+ if (tabIndex < m_tabs->count() - 1)
+ {
+ m_tabs->moveTab(tabIndex, tabIndex + 1);
+ }
+}
+
+void Shell::moveTabBackward(int tabIndex)
+{
+ if (tabIndex > 0)
+ {
+ m_tabs->moveTab(tabIndex, tabIndex - 1);
+ }
+}
+
+void Shell::slotDuplicateTab()
+{
+ if (m_workingTab == -1)
+ {
+ m_workingTab = m_tabs->currentPageIndex();
+ }
+
+ KParts::ReadOnlyPart *currentTab = findPartForTab(m_workingTab);
+ if (currentTab)
+ {
+ openURL(currentTab->url());
+ }
+
+ m_workingTab = -1;
+}
+
+void Shell::slotBreakOffTab()
+{
+ if (m_workingTab == -1)
+ {
+ m_workingTab = m_tabs->currentPageIndex();
+ }
+
+ KParts::ReadOnlyPart *currentTab = findPartForTab(m_workingTab);
+ if (currentTab)
+ {
+ TQString e;
+ TQStringList args;
+ args << "--new-instance";
+ if (currentTab->url().isValid())
+ {
+ args << currentTab->url().url();
+ }
+ int s = tdeApp->tdeinitExec("kpdf", args, &e, nullptr, "0");
+ if (s != 0)
+ {
+ kdWarning() << "Unable to start new KPDF instance: " << e << endl;
+ }
+ }
+ removeTab();
+ m_workingTab = -1;
+}
+
+void Shell::slotMoveTabLeft()
+{
+ if (m_workingTab == -1)
+ {
+ m_workingTab = m_tabs->currentPageIndex();
+ }
+
+ if (TQApplication::reverseLayout())
+ {
+ moveTabForward(m_workingTab);
+ }
+ else
+ {
+ moveTabBackward(m_workingTab);
+ }
+
+ m_workingTab = -1;
+}
+
+void Shell::slotMoveTabRight()
+{
+ if (m_workingTab == -1)
+ {
+ m_workingTab = m_tabs->currentPageIndex();
+ }
+
+ if (TQApplication::reverseLayout())
+ {
+ moveTabBackward(m_workingTab);
+ }
+ else
+ {
+ moveTabForward(m_workingTab);
+ }
+
+ m_workingTab = -1;
+}
+
+void Shell::slotRemoveOtherTabs()
+{
+ if (m_workingTab == -1)
+ {
+ m_workingTab = m_tabs->currentPageIndex();
+ }
+
+ if (KMessageBox::warningContinueCancel(this,
+ i18n("Do you really want to close all other tabs?"),
+ i18n("Close Other Tabs Confirmation"),
+ KGuiItem(i18n("Close &Other Tabs"), "tab_remove_other"),
+ "CloseOtherTabConfirm") != KMessageBox::Continue)
+ {
+ m_workingTab = -1;
+ return;
+ }
+
+ KParts::ReadOnlyPart *currentPart = findPartForTab(m_workingTab);
+ if (!currentPart) return;
+
+ TQPtrList<KParts::Part> *parts = const_cast<TQPtrList<KParts::Part>*>(m_manager->parts());
+ KParts::Part *part;
+ for (part = parts->first(); part; part = parts->next())
+ {
+ if (part == currentPart) continue;
+ m_tabs->removePage(part->widget());
+ part->deleteLater();
+ }
+}
+
+void Shell::slotSetTabCaption(const TQString &caption)
+{
+ KParts::ReadOnlyPart *part = const_cast<KParts::ReadOnlyPart*>
+ (static_cast<const KParts::ReadOnlyPart*>(TQObject::sender()));
+ if (!part) return;
+
+ m_tabs->changeTab(part->widget(), caption.isEmpty() ? i18n("No file") : caption);
+ if (caption.isEmpty())
+ {
+ m_tabs->removeTabToolTip(part->widget());
+ }
+ else
+ {
+ m_tabs->setTabToolTip(part->widget(), part->url().pathOrURL());
+ }
+}
+
+void Shell::slotCloseTabRequest(TQWidget *w)
+{
+ m_workingTab = m_tabs->indexOf(w);
+ if (m_workingTab == -1) return;
+ removeTab();
}
#include "shell.moc"
diff --git a/kpdf/shell/shell.h b/kpdf/shell/shell.h
index 6c2e4057..d1ace108 100644
--- a/kpdf/shell/shell.h
+++ b/kpdf/shell/shell.h
@@ -21,6 +21,17 @@
#endif
#include <tdeparts/mainwindow.h>
+#include "dcop.h"
+
+class TQToolButton;
+class TQPopupMenu;
+class KTabWidget;
+
+namespace KParts
+{
+ class Factory;
+ class PartManager;
+}
namespace KPDF
{
@@ -33,10 +44,9 @@ namespace KPDF
* @author Wilco Greven <greven@kde.org>
* @version 0.1
*/
- class Shell : public KParts::MainWindow
+ class Shell : public KParts::MainWindow, virtual public KPDFShellDCOPIface
{
- Q_OBJECT
-
+ TQ_OBJECT
public:
/**
@@ -54,6 +64,18 @@ namespace KPDF
*/
virtual ~Shell();
+ enum TabContextMenuItem
+ {
+ TabDuplicate = 100,
+ TabBreakOff,
+ TabMoveLeft,
+ TabMoveRight,
+ TabRemove,
+ TabRemoveOther
+ };
+
+ const KURL currentTabURL();
+
protected:
/**
* This method is called when it is time for the app to save its
@@ -72,6 +94,13 @@ namespace KPDF
void setFullScreen( bool );
public slots:
+ void reconfigure();
+
+ void openURL(const KURL & url);
+ void addTab();
+ void removeTab();
+
+ void slotPrint();
void slotQuit();
private slots:
@@ -81,29 +110,48 @@ namespace KPDF
void applyNewToolbarConfig();
void slotUpdateFullScreen();
void slotShowMenubar();
-
- void openURL( const KURL & url );
void delayedOpen();
+ void slotCloseTabRequest(TQWidget *w);
+ void slotChangeTab(KParts::Part *part);
+ void slotTabContextMenu(const TQPoint &pos);
+ void slotTabContextMenu(TQWidget *w, const TQPoint &pos);
+
+ void slotDuplicateTab();
+ void slotBreakOffTab();
+ void slotMoveTabLeft();
+ void slotMoveTabRight();
+ void slotRemoveOtherTabs();
+ void slotSetTabCaption(const TQString &caption);
+ void slotSetPrintActionEnabled(bool enabled);
+
signals:
- void restoreDocument(TDEConfig* config);
- void saveDocumentRestoreInfo(TDEConfig* config);
-
-
+ void restoreDocument(TDEConfig* config);
+ void saveDocumentRestoreInfo(TDEConfig* config);
+
+
private:
void setupAccel();
void setupActions();
void init();
+ void initTabContextMenu();
+ KParts::ReadOnlyPart *createTab();
+ KParts::ReadOnlyPart *findPartForTab(int tabIndex);
+ void moveTabForward(int tabIndex);
+ void moveTabBackward(int tabIndex);
private:
- KParts::ReadOnlyPart* m_part;
- TDERecentFilesAction* m_recent;
- TDEAction* m_printAction;
- TDEToggleAction* m_fullScreenAction;
- TDEToggleAction* m_showMenuBarAction;
- TDEToggleAction* m_showToolBarAction;
- bool m_menuBarWasShown, m_toolBarWasShown;
- KURL m_openUrl;
+ KTabWidget *m_tabs;
+ KParts::Factory *m_factory;
+ KParts::PartManager *m_manager;
+ TDERecentFilesAction* m_recent;
+ TDEAction *m_printAction, *m_addTabAction, *m_closeTabAction;
+ TDEToggleAction *m_fullScreenAction, *m_showMenuBarAction, *m_showToolBarAction;
+ TQToolButton *m_addTabButton, *m_removeTabButton;
+ TQPopupMenu *m_tabsContextMenu;
+ bool m_menuBarWasShown, m_toolBarWasShown;
+ KURL m_openUrl; // delayed open
+ int m_workingTab;
};
}
diff --git a/kpdf/shell/shell.rc b/kpdf/shell/shell.rc
index 134d34c7..f97cbe0c 100644
--- a/kpdf/shell/shell.rc
+++ b/kpdf/shell/shell.rc
@@ -1,13 +1,19 @@
<!DOCTYPE kpartgui SYSTEM "kpartgui.dtd">
-<kpartgui version="7" name="kpdf_shell" >
+<kpartgui version="8" name="kpdf_shell" >
<MenuBar>
<Menu name="file" >
<DefineGroup append="save_merge" name="file_save" />
<DefineGroup append="print_merge" name="file_print" />
</Menu>
- <!--Menu name="view" >
- <Action name="fullscreen" />
- </Menu-->
+ <Menu name="view" >
+ <Action name="newtab" />
+ <Action name="duplicatecurrenttab" />
+ <Action name="breakoffcurrenttab" />
+ <Separator />
+ <Action name="removecurrenttab" />
+ <Action name="removeothertabs" />
+ <Separator />
+ </Menu>
<Menu name="settings" >
<DefineGroup append="show_merge" name="show_merge" />
</Menu>