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> *
|
|
|
|
* Copyright (C) 2003-2004 by Albert Astals Cid <tsdgeos@terra.es> *
|
|
|
|
* 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> *
|
|
|
|
* *
|
|
|
|
* 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
|
2005-06-24 16:43:45 +00:00
|
|
|
#include <qtimer.h>
|
2002-09-02 21:56:00 +00:00
|
|
|
#include <kaction.h>
|
2004-09-04 22:52:25 +00:00
|
|
|
#include <kapplication.h>
|
2007-01-04 00:20:50 +00:00
|
|
|
#include <kcmdlineargs.h>
|
2004-11-25 22:27:01 +00:00
|
|
|
#include <kedittoolbar.h>
|
2002-09-02 21:56:00 +00:00
|
|
|
#include <kfiledialog.h>
|
2007-08-29 14:16:06 +00:00
|
|
|
#include <kpluginloader.h>
|
2002-09-02 20:21:47 +00:00
|
|
|
#include <kmessagebox.h>
|
2007-01-29 14:55:40 +00:00
|
|
|
#include <kmimetype.h>
|
2006-12-19 12:23:43 +00:00
|
|
|
#include <kstandardaction.h>
|
2006-03-21 20:03:08 +00:00
|
|
|
#include <ktoolbar.h>
|
2002-09-02 21:56:00 +00:00
|
|
|
#include <kurl.h>
|
2003-09-14 19:04:36 +00:00
|
|
|
#include <kdebug.h>
|
2003-09-14 20:23:01 +00:00
|
|
|
#include <klocale.h>
|
2003-09-15 12:12:53 +00:00
|
|
|
#include <kmenubar.h>
|
2003-10-21 08:49:43 +00:00
|
|
|
#include <kio/netaccess.h>
|
2006-05-08 19:26:45 +00:00
|
|
|
#include <krecentfilesaction.h>
|
2006-05-22 14:02:24 +00:00
|
|
|
#include <kservicetypetrader.h>
|
2006-05-08 19:26:45 +00:00
|
|
|
#include <ktoggleaction.h>
|
|
|
|
#include <ktogglefullscreenaction.h>
|
2007-01-09 11:02:04 +00:00
|
|
|
#include <kactioncollection.h>
|
2007-01-29 15:03:22 +00:00
|
|
|
|
2005-01-02 14:29:37 +00:00
|
|
|
// local includes
|
2007-01-04 00:20:50 +00:00
|
|
|
#include "kdocumentviewer.h"
|
2002-09-02 20:21:47 +00:00
|
|
|
|
2007-01-04 00:20:50 +00:00
|
|
|
Shell::Shell(KCmdLineArgs* args, const KUrl &url)
|
|
|
|
: KParts::MainWindow(), m_args(args), m_menuBarWasShown(true), m_toolBarWasShown(true)
|
2005-06-24 16:43:45 +00:00
|
|
|
{
|
|
|
|
m_openUrl = url;
|
|
|
|
init();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Shell::init()
|
2002-09-02 20:21:47 +00:00
|
|
|
{
|
2006-06-19 10:55:13 +00:00
|
|
|
setObjectName( QLatin1String( "okular::Shell" ) );
|
2007-01-04 21:06:44 +00:00
|
|
|
setContextMenuPolicy( Qt::NoContextMenu );
|
2002-09-02 20:21:47 +00:00
|
|
|
// set the shell's ui resource file
|
2005-01-02 14:29:37 +00:00
|
|
|
setXMLFile("shell.rc");
|
2007-01-04 00:20:50 +00:00
|
|
|
m_doc=0L;
|
2007-07-29 21:36:02 +00:00
|
|
|
m_fileformatsscanned = false;
|
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
|
2007-12-02 21:02:57 +00:00
|
|
|
KPluginFactory *factory = KPluginLoader("okularpart").factory();
|
2002-09-02 20:21:47 +00:00
|
|
|
if (factory)
|
|
|
|
{
|
|
|
|
// now that the Part is loaded, we cast it to a Part to get
|
|
|
|
// our hands on it
|
2007-08-29 14:16:06 +00:00
|
|
|
m_part = factory->create< KParts::ReadOnlyPart >( this );
|
2002-09-02 20:21:47 +00:00
|
|
|
if (m_part)
|
|
|
|
{
|
2004-04-27 21:57:30 +00:00
|
|
|
// then, setup our actions
|
|
|
|
setupActions();
|
2002-09-02 20:21:47 +00:00
|
|
|
// 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
|
2004-11-25 22:27:01 +00:00
|
|
|
setupGUI(Keys | Save);
|
2002-09-02 20:21:47 +00:00
|
|
|
createGUI(m_part);
|
2004-12-13 00:27:09 +00:00
|
|
|
m_showToolBarAction = static_cast<KToggleAction*>(toolBarMenuAction());
|
2007-01-04 00:20:50 +00:00
|
|
|
m_doc = qobject_cast<KDocumentViewer*>(m_part);
|
2002-09-02 20:21:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// if we couldn't find our Part, we exit since the Shell by
|
|
|
|
// itself can't do anything useful
|
2006-06-12 18:25:18 +00:00
|
|
|
KMessageBox::error(this, i18n("Unable to find okular part."));
|
2004-11-01 19:06:27 +00:00
|
|
|
m_part = 0;
|
2002-09-02 20:21:47 +00:00
|
|
|
return;
|
|
|
|
}
|
2007-02-21 15:12:57 +00:00
|
|
|
connect( this, SIGNAL( restoreDocument(const KConfigGroup&) ),m_part, SLOT( restoreDocument(const KConfigGroup&)));
|
2007-02-20 15:48:18 +00:00
|
|
|
connect( this, SIGNAL( saveDocumentRestoreInfo(KConfigGroup&) ), m_part, SLOT( saveDocumentRestoreInfo(KConfigGroup&)));
|
2005-11-04 11:59:51 +00:00
|
|
|
connect( m_part, SIGNAL( enablePrintAction(bool) ), m_printAction, SLOT( setEnabled(bool)));
|
2004-08-29 11:24:11 +00:00
|
|
|
|
2003-09-14 17:44:18 +00:00
|
|
|
readSettings();
|
2006-06-05 14:55:36 +00:00
|
|
|
|
2004-12-10 22:27:55 +00:00
|
|
|
if (!KGlobal::config()->hasGroup("MainWindow"))
|
|
|
|
{
|
2006-06-05 14:55:36 +00:00
|
|
|
showMaximized();
|
2004-12-10 22:27:55 +00:00
|
|
|
}
|
2005-06-24 16:43:45 +00:00
|
|
|
setAutoSaveSettings();
|
|
|
|
|
|
|
|
if (m_openUrl.isValid()) QTimer::singleShot(0, this, SLOT(delayedOpen()));
|
|
|
|
}
|
|
|
|
|
|
|
|
void Shell::delayedOpen()
|
|
|
|
{
|
2007-01-04 00:20:50 +00:00
|
|
|
uint page = 0;
|
|
|
|
if (m_args && m_doc)
|
|
|
|
{
|
2007-07-02 08:52:55 +00:00
|
|
|
QString pageopt = m_args->getOption("page");
|
2007-01-04 00:20:50 +00:00
|
|
|
page = pageopt.toUInt();
|
|
|
|
}
|
|
|
|
openUrl(m_openUrl, page);
|
2002-09-02 20:21:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Shell::~Shell()
|
|
|
|
{
|
2005-08-11 03:41:30 +00:00
|
|
|
if ( m_part ) writeSettings();
|
2007-01-03 17:57:03 +00:00
|
|
|
delete m_part;
|
2007-06-06 15:47:58 +00:00
|
|
|
if ( m_args )
|
|
|
|
m_args->clear();
|
2002-09-02 20:21:47 +00:00
|
|
|
}
|
|
|
|
|
2007-01-04 00:20:50 +00:00
|
|
|
void Shell::openUrl( const KUrl & url, uint page )
|
2003-09-14 17:44:18 +00:00
|
|
|
{
|
2005-01-27 17:31:07 +00:00
|
|
|
if ( m_part )
|
|
|
|
{
|
2007-01-04 00:20:50 +00:00
|
|
|
if ( m_doc && m_args && m_args->isSet( "presentation" ) )
|
|
|
|
m_doc->startPresentation();
|
|
|
|
bool openOk = page > 0 && m_doc ? m_doc->openDocument( url, page ) : m_part->openUrl( url );
|
2006-03-23 19:02:55 +00:00
|
|
|
if ( openOk ) m_recent->addUrl( url );
|
|
|
|
else m_recent->removeUrl( url );
|
2005-01-27 17:31:07 +00:00
|
|
|
}
|
2003-09-14 17:44:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Shell::readSettings()
|
2002-09-02 20:21:47 +00:00
|
|
|
{
|
2007-02-20 15:25:05 +00:00
|
|
|
m_recent->loadEntries( KGlobal::config()->group( "Recent Files" ) );
|
2005-01-27 17:31:07 +00:00
|
|
|
m_recent->setEnabled( true ); // force enabling
|
|
|
|
|
2007-02-20 15:25:05 +00:00
|
|
|
const KConfigGroup group = KGlobal::config()->group( "Desktop Entry" );
|
|
|
|
bool fullScreen = group.readEntry( "FullScreen", false );
|
2003-09-15 12:12:53 +00:00
|
|
|
setFullScreen( fullScreen );
|
2002-09-02 20:21:47 +00:00
|
|
|
}
|
|
|
|
|
2003-09-14 17:44:18 +00:00
|
|
|
void Shell::writeSettings()
|
|
|
|
{
|
2007-02-20 15:25:05 +00:00
|
|
|
m_recent->saveEntries( KGlobal::config()->group( "Recent Files" ) );
|
|
|
|
KConfigGroup group = KGlobal::config()->group( "Desktop Entry" );
|
|
|
|
group.writeEntry( "FullScreen", m_fullScreenAction->isChecked() );
|
2003-09-15 12:12:53 +00:00
|
|
|
KGlobal::config()->sync();
|
|
|
|
}
|
|
|
|
|
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());
|
|
|
|
m_recent = KStandardAction::openRecent( this, SLOT( openUrl( const KUrl& ) ), actionCollection() );
|
2006-04-25 12:37:27 +00:00
|
|
|
m_recent->setToolBarMode( KRecentFilesAction::MenuMode );
|
2007-01-29 14:55:40 +00:00
|
|
|
m_recent->setToolButtonPopupMode( QToolButton::DelayedPopup );
|
2006-05-06 17:12:13 +00:00
|
|
|
connect( m_recent, SIGNAL( triggered() ), this, SLOT( fileOpen() ) );
|
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" ) );
|
2006-12-19 12:23:43 +00:00
|
|
|
m_printAction = KStandardAction::print( m_part, SLOT( slotPrint() ), actionCollection() );
|
2005-01-27 17:31:07 +00:00
|
|
|
m_printAction->setEnabled( false );
|
2006-12-19 12:23:43 +00:00
|
|
|
KStandardAction::quit(this, SLOT(slotQuit()), 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
|
|
|
|
2006-12-19 12:23:43 +00:00
|
|
|
m_showMenuBarAction = KStandardAction::showMenubar( this, SLOT( slotShowMenubar() ), actionCollection());
|
|
|
|
KStandardAction::configureToolbars(this, SLOT(optionsConfigureToolbars()), actionCollection());
|
2007-01-09 11:02:04 +00:00
|
|
|
m_fullScreenAction = KStandardAction::fullScreen( this, SLOT( slotUpdateFullScreen() ), this,actionCollection() );
|
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
|
|
|
{
|
|
|
|
// the 'config' object points to the session managed
|
|
|
|
// config file. anything you write here will be available
|
|
|
|
// later when this app is restored
|
2007-02-20 15:48:18 +00:00
|
|
|
emit saveDocumentRestoreInfo(group);
|
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
|
|
|
{
|
|
|
|
// the 'config' object points to the session managed
|
|
|
|
// config file. this function is automatically called whenever
|
|
|
|
// the app is being restored. read in here whatever you wrote
|
|
|
|
// in 'saveProperties'
|
2004-11-01 19:06:27 +00:00
|
|
|
if(m_part)
|
|
|
|
{
|
2007-02-20 15:48:18 +00:00
|
|
|
emit restoreDocument(group);
|
2004-11-01 19:06:27 +00:00
|
|
|
}
|
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
|
|
|
{
|
|
|
|
QString constraint("([X-KDE-Priority] > 0) and (exist Library) ") ;
|
2006-06-12 18:25:18 +00:00
|
|
|
KService::List offers = KServiceTypeTrader::self()->query("okular/Generator",constraint);
|
2007-02-07 17:25:51 +00:00
|
|
|
QStringList supportedPatterns;
|
2005-07-15 17:17:13 +00:00
|
|
|
|
|
|
|
if (offers.isEmpty())
|
2007-02-07 17:25:51 +00:00
|
|
|
{
|
|
|
|
return supportedPatterns;
|
|
|
|
}
|
2005-07-15 17:17:13 +00:00
|
|
|
|
2006-05-22 14:02:24 +00:00
|
|
|
KService::List::ConstIterator iterator = offers.begin();
|
|
|
|
KService::List::ConstIterator end = offers.end();
|
2005-07-15 17:17:13 +00:00
|
|
|
for (; iterator != end; ++iterator)
|
|
|
|
{
|
2007-05-24 20:41:29 +00:00
|
|
|
QStringList mimeTypes = (*iterator)->serviceTypes();
|
|
|
|
foreach (const QString& mimeType, mimeTypes )
|
2005-07-15 17:17:13 +00:00
|
|
|
{
|
2007-05-24 20:41:29 +00:00
|
|
|
if ( !mimeType.contains( "okular" ) )
|
2005-07-15 17:17:13 +00:00
|
|
|
{
|
2007-05-24 20:41:29 +00:00
|
|
|
supportedPatterns.append( mimeType );
|
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
|
2007-07-29 21:36:02 +00:00
|
|
|
if ( !m_fileformatsscanned )
|
2007-05-24 20:41:29 +00:00
|
|
|
{
|
|
|
|
if ( m_doc )
|
|
|
|
m_fileformats = m_doc->supportedMimeTypes();
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
QString startDir;
|
2007-09-20 17:30:41 +00:00
|
|
|
if ( m_part->url().isLocalFile() )
|
|
|
|
startDir = m_part->url().path();
|
2007-07-29 21:36:02 +00:00
|
|
|
KFileDialog dlg( startDir, QString(), this );
|
|
|
|
dlg.setOperationMode( KFileDialog::Opening );
|
|
|
|
if ( m_fileformatsscanned && m_fileformats.isEmpty() )
|
2007-11-02 00:32:22 +00:00
|
|
|
dlg.setFilter( i18n( "*|All Files" ) );
|
2005-07-15 17:17:13 +00:00
|
|
|
else
|
2007-07-29 21:36:02 +00:00
|
|
|
dlg.setMimeFilter( m_fileformats );
|
|
|
|
dlg.setCaption( i18n( "Open a document" ) );
|
|
|
|
if ( !dlg.exec() )
|
|
|
|
return;
|
|
|
|
KUrl url = dlg.selectedUrl();
|
|
|
|
if ( !url.isEmpty() )
|
|
|
|
openUrl( url );
|
2002-09-02 20:21:47 +00:00
|
|
|
}
|
|
|
|
|
2004-11-25 22:27:01 +00:00
|
|
|
void
|
|
|
|
Shell::optionsConfigureToolbars()
|
|
|
|
{
|
2007-11-09 16:16:05 +00:00
|
|
|
KEditToolBar dlg(factory(), this);
|
2007-03-09 16:17:45 +00:00
|
|
|
connect(&dlg, SIGNAL(newToolBarConfig()), this, SLOT(applyNewToolbarConfig()));
|
2004-11-25 22:27:01 +00:00
|
|
|
dlg.exec();
|
|
|
|
}
|
|
|
|
|
2002-09-02 20:21:47 +00:00
|
|
|
void
|
|
|
|
Shell::applyNewToolbarConfig()
|
|
|
|
{
|
2007-02-20 15:25:05 +00:00
|
|
|
applyMainWindowSettings(KGlobal::config()->group("MainWindow"));
|
2002-09-02 20:21:47 +00:00
|
|
|
}
|
|
|
|
|
2003-09-14 19:04:36 +00:00
|
|
|
void Shell::slotQuit()
|
|
|
|
{
|
|
|
|
kapp->closeAllWindows();
|
|
|
|
}
|
2003-09-15 12:12:53 +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 )
|
|
|
|
showFullScreen();
|
|
|
|
else
|
|
|
|
showNormal();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Shell::slotUpdateFullScreen()
|
|
|
|
{
|
2004-12-13 00:27:09 +00:00
|
|
|
if(m_fullScreenAction->isChecked())
|
2003-09-15 12:12:53 +00:00
|
|
|
{
|
2004-12-13 00:27:09 +00:00
|
|
|
m_menuBarWasShown = m_showMenuBarAction->isChecked();
|
|
|
|
m_showMenuBarAction->setChecked(false);
|
|
|
|
menuBar()->hide();
|
|
|
|
|
|
|
|
m_toolBarWasShown = m_showToolBarAction->isChecked();
|
|
|
|
m_showToolBarAction->setChecked(false);
|
|
|
|
toolBar()->hide();
|
|
|
|
|
|
|
|
showFullScreen();
|
2003-09-15 12:12:53 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-12-13 00:27:09 +00:00
|
|
|
if (m_menuBarWasShown)
|
|
|
|
{
|
|
|
|
m_showMenuBarAction->setChecked(true);
|
|
|
|
menuBar()->show();
|
|
|
|
}
|
|
|
|
if (m_toolBarWasShown)
|
|
|
|
{
|
|
|
|
m_showToolBarAction->setChecked(true);
|
|
|
|
toolBar()->show();
|
|
|
|
}
|
|
|
|
showNormal();
|
2003-09-15 12:12:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-01-03 15:51:05 +00:00
|
|
|
void Shell::slotShowMenubar()
|
|
|
|
{
|
|
|
|
if ( m_showMenuBarAction->isChecked() )
|
|
|
|
menuBar()->show();
|
|
|
|
else
|
|
|
|
menuBar()->hide();
|
|
|
|
}
|
|
|
|
|
2005-01-02 14:29:37 +00:00
|
|
|
#include "shell.moc"
|