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
|
|
|
|
2002-09-02 20:21:47 +00:00
|
|
|
#include "kpdf_shell.h"
|
|
|
|
#include "kpdf_shell.moc"
|
|
|
|
|
2002-09-02 21:56:00 +00:00
|
|
|
#include <kaction.h>
|
2004-09-04 22:52:25 +00:00
|
|
|
#include <kapplication.h>
|
2002-09-02 21:56:00 +00:00
|
|
|
#include <kfiledialog.h>
|
2002-09-02 20:21:47 +00:00
|
|
|
#include <klibloader.h>
|
|
|
|
#include <kmessagebox.h>
|
2002-09-02 21:56:00 +00:00
|
|
|
#include <kstdaction.h>
|
|
|
|
#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-09-15 12:44:23 +00:00
|
|
|
#include <kpopupmenu.h>
|
2003-09-15 12:12:53 +00:00
|
|
|
#include <kparts/componentfactory.h>
|
2003-10-21 08:49:43 +00:00
|
|
|
#include <kio/netaccess.h>
|
|
|
|
|
2003-09-15 12:44:23 +00:00
|
|
|
#include <qcursor.h>
|
2002-09-02 20:21:47 +00:00
|
|
|
|
|
|
|
using namespace KPDF;
|
|
|
|
|
|
|
|
Shell::Shell()
|
2003-12-15 16:26:49 +00:00
|
|
|
: KParts::MainWindow(0, "KPDF::Shell")
|
2002-09-02 20:21:47 +00:00
|
|
|
{
|
|
|
|
// set the shell's ui resource file
|
|
|
|
setXMLFile("kpdf_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
|
2002-09-14 02:49:16 +00:00
|
|
|
KLibFactory *factory = KLibLoader::self()->factory("libkpdfpart");
|
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
|
|
|
|
m_part = static_cast<KParts::ReadOnlyPart*>(
|
|
|
|
factory->create(this, "kpdf_part", "KParts::ReadOnlyPart"));
|
|
|
|
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-08-26 16:43:52 +00:00
|
|
|
setupGUI(ToolBar | Keys | Save);
|
2002-09-02 20:21:47 +00:00
|
|
|
createGUI(m_part);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// if we couldn't find our Part, we exit since the Shell by
|
|
|
|
// itself can't do anything useful
|
2004-06-26 10:13:01 +00:00
|
|
|
KMessageBox::error(this, i18n("Unable to find kpdf part."));
|
2002-09-02 20:21:47 +00:00
|
|
|
kapp->quit();
|
|
|
|
// we return here, cause kapp->quit() only means "exit the
|
|
|
|
// next time we enter the event loop...
|
|
|
|
return;
|
|
|
|
}
|
2004-09-09 13:25:40 +00:00
|
|
|
//FIXME READD: connect( m_part, SIGNAL( rightClick() ),SLOT( slotRMBClick() ) );
|
2004-08-29 11:24:11 +00:00
|
|
|
|
2003-09-14 17:44:18 +00:00
|
|
|
readSettings();
|
2002-09-02 20:21:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Shell::~Shell()
|
|
|
|
{
|
2003-09-14 17:44:18 +00:00
|
|
|
writeSettings();
|
2002-09-02 20:21:47 +00:00
|
|
|
}
|
|
|
|
|
2003-09-14 17:44:18 +00:00
|
|
|
void Shell::openURL( const KURL & url )
|
|
|
|
{
|
2004-09-18 16:41:23 +00:00
|
|
|
if ( m_part && m_part->openURL( url ) ) m_recent->addURL (url);
|
|
|
|
else m_recent->removeURL(url);
|
2003-09-14 17:44:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Shell::readSettings()
|
2002-09-02 20:21:47 +00:00
|
|
|
{
|
2004-09-18 16:41:23 +00:00
|
|
|
m_recent->loadEntries( KGlobal::config() );
|
2003-09-15 12:12:53 +00:00
|
|
|
KGlobal::config()->setDesktopGroup();
|
|
|
|
bool fullScreen = KGlobal::config()->readBoolEntry( "FullScreen", false );
|
|
|
|
setFullScreen( fullScreen );
|
2002-09-02 20:21:47 +00:00
|
|
|
}
|
|
|
|
|
2003-09-14 17:44:18 +00:00
|
|
|
void Shell::writeSettings()
|
|
|
|
{
|
|
|
|
saveMainWindowSettings(KGlobal::config(), "MainWindow");
|
2004-09-18 16:41:23 +00:00
|
|
|
m_recent->saveEntries( KGlobal::config() );
|
2003-09-15 12:12:53 +00:00
|
|
|
KGlobal::config()->setDesktopGroup();
|
2003-12-15 16:26:49 +00:00
|
|
|
KGlobal::config()->writeEntry( "FullScreen", m_fullScreenAction->isChecked());
|
2003-09-15 12:12:53 +00:00
|
|
|
KGlobal::config()->sync();
|
|
|
|
}
|
|
|
|
|
2002-09-02 20:21:47 +00:00
|
|
|
void
|
|
|
|
Shell::setupActions()
|
|
|
|
{
|
2002-09-02 21:56:00 +00:00
|
|
|
KStdAction::open(this, SLOT(fileOpen()), actionCollection());
|
2004-09-18 16:41:23 +00:00
|
|
|
m_recent = KStdAction::openRecent( this, SLOT( openURL( const KURL& ) ),
|
2003-09-14 17:44:18 +00:00
|
|
|
actionCollection() );
|
2004-09-08 12:41:14 +00:00
|
|
|
KStdAction::print(m_part, SLOT(slotPrint()), actionCollection());
|
2004-04-27 21:57:30 +00:00
|
|
|
KStdAction::quit(this, SLOT(slotQuit()), actionCollection());
|
2002-09-02 20:21:47 +00:00
|
|
|
|
2004-08-29 11:24:11 +00:00
|
|
|
|
2003-03-17 04:10:33 +00:00
|
|
|
setStandardToolBarMenuEnabled(true);
|
2002-09-02 20:21:47 +00:00
|
|
|
|
2004-01-03 10:38:06 +00:00
|
|
|
m_showMenuBarAction = KStdAction::showMenubar( this, SLOT( slotShowMenubar() ), actionCollection(), "options_show_menubar" );
|
2004-04-27 21:57:30 +00:00
|
|
|
m_fullScreenAction = KStdAction::fullScreen( this, SLOT( slotUpdateFullScreen() ), actionCollection(), this );
|
|
|
|
m_popup = new KPopupMenu( this, "rmb popup" );
|
|
|
|
m_popup->insertTitle( i18n( "Full Screen Options" ) );
|
|
|
|
m_fullScreenAction->plug( m_popup );
|
2004-09-06 23:22:36 +00:00
|
|
|
m_popup->insertTitle( i18n( "Tools" ) );
|
|
|
|
m_showMenuBarAction->plug( m_popup );
|
2002-09-02 20:21:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2003-09-14 19:04:36 +00:00
|
|
|
Shell::saveProperties(KConfig* config)
|
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
|
2004-01-25 01:24:26 +00:00
|
|
|
config->writePathEntry( "URL", m_part->url().url() );
|
2002-09-02 20:21:47 +00:00
|
|
|
}
|
|
|
|
|
2003-09-16 21:12:25 +00:00
|
|
|
void Shell::slotShowMenubar()
|
|
|
|
{
|
|
|
|
if ( m_showMenuBarAction->isChecked() )
|
|
|
|
menuBar()->show();
|
|
|
|
else
|
|
|
|
menuBar()->hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-09-14 19:04:36 +00:00
|
|
|
void Shell::readProperties(KConfig* config)
|
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-01-25 01:24:26 +00:00
|
|
|
KURL url ( config->readPathEntry( "URL" ) );
|
2003-09-14 19:04:36 +00:00
|
|
|
if ( url.isValid() )
|
|
|
|
openURL( url );
|
2002-09-02 20:21:47 +00:00
|
|
|
}
|
|
|
|
|
2002-09-02 21:56:00 +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
|
2004-09-07 21:29:44 +00:00
|
|
|
KURL url = KFileDialog::getOpenURL( QString::null, "application/pdf" );//getOpenFileName();
|
2002-09-02 21:56:00 +00:00
|
|
|
|
2003-09-14 17:44:18 +00:00
|
|
|
if (!url.isEmpty())
|
|
|
|
openURL(url);
|
2002-09-02 20:21:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Shell::applyNewToolbarConfig()
|
|
|
|
{
|
|
|
|
applyMainWindowSettings(KGlobal::config(), "MainWindow");
|
|
|
|
}
|
|
|
|
|
2003-09-14 19:04:36 +00:00
|
|
|
void Shell::slotQuit()
|
|
|
|
{
|
|
|
|
kapp->closeAllWindows();
|
|
|
|
}
|
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()
|
|
|
|
{
|
|
|
|
if( m_fullScreenAction->isChecked())
|
2003-09-15 12:12:53 +00:00
|
|
|
{
|
|
|
|
menuBar()->hide();
|
|
|
|
toolBar()->hide();
|
|
|
|
//todo fixme
|
|
|
|
showFullScreen();
|
|
|
|
#if 0
|
|
|
|
kapp->installEventFilter( m_fsFilter );
|
|
|
|
if ( m_gvpart->document()->isOpen() )
|
|
|
|
slotFitToPage();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//kapp->removeEventFilter( m_fsFilter );
|
|
|
|
menuBar()->show();
|
|
|
|
toolBar()->show();
|
|
|
|
showNormal();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-09-15 12:44:23 +00:00
|
|
|
void Shell::slotRMBClick()
|
|
|
|
{
|
|
|
|
m_popup->exec( QCursor::pos() );
|
|
|
|
}
|
|
|
|
|
2003-09-15 12:12:53 +00:00
|
|
|
|
2002-09-02 20:21:47 +00:00
|
|
|
// vim:ts=2:sw=2:tw=78:et
|