kpdf_part.cpp 17.7 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/***************************************************************************
 *   Copyright (C) 2002 by Wilco Greven <greven@kde.org>                   *
 *   Copyright (C) 2002 by Chris Cheney <ccheney@cheney.cx>                *
 *   Copyright (C) 2002 by Malcolm Hunter <malcolm.hunter@gmx.co.uk>       *
 *   Copyright (C) 2003-2004 by Christophe Devriese                        *
 *                         <Christophe.Devriese@student.kuleuven.ac.be>    *
 *   Copyright (C) 2003 by Daniel Molkentin <molkentin@kde.org>            *
 *   Copyright (C) 2003 by Andy Goossens <andygoossens@telenet.be>         *
 *   Copyright (C) 2003 by Dirk Mueller <mueller@kde.org>                  *
 *   Copyright (C) 2003 by Laurent Montel <montel@kde.org>                 *
 *   Copyright (C) 2004 by Dominique Devriese <devriese@kde.org>           *
 *   Copyright (C) 2004 by Christoph Cullmann <crossfire@babylon2k.de>     *
 *   Copyright (C) 2004 by Henrique Pinto <stampede@coltec.ufmg.br>        *
 *   Copyright (C) 2004 by Waldo Bastian <bastian@kde.org>                 *
 *   Copyright (C) 2004 by Albert Astals Cid <tsdgeos@terra.es>            *
16
 *   Copyright (C) 2004 by Antti Markus <antti.markus@starman.ee>          *
17 18 19 20 21 22 23
 *                                                                         *
 *   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.                                   *
 ***************************************************************************/

24
#include <qsplitter.h>
25
#include <qpainter.h>
26 27
#include <qlayout.h>
#include <qlabel.h>
28
#include <qvbox.h>
29
#include <qtoolbox.h>
30
#include <qpushbutton.h>
31

32
#include <dcopobject.h>
33
#include <kaction.h>
Albert Astals Cid's avatar
Albert Astals Cid committed
34
#include <kdirwatch.h>
35
#include <kinstance.h>
36
#include <kprinter.h>
37
#include <kstdaction.h>
Enrico Ros's avatar
Enrico Ros committed
38
#include <kdeversion.h>
39
#include <kparts/genericfactory.h>
Laurent Montel's avatar
Laurent Montel committed
40
#include <kurldrag.h>
41
#include <kfiledialog.h>
Albert Astals Cid's avatar
Albert Astals Cid committed
42
#include <kmessagebox.h>
43 44
#include <kfinddialog.h>
#include <knuminput.h>
45
#include <kiconloader.h>
46
#include <kio/netaccess.h>
47 48 49

#include "GlobalParams.h"

50
#include "kpdf_part.h"
51
#include "pageview.h"
52
#include "thumbnaillist.h"
53
#include "searchwidget.h"
54
#include "document.h"
Albert Astals Cid's avatar
Albert Astals Cid committed
55
#include "page.h"
Albert Astals Cid's avatar
Albert Astals Cid committed
56
#include "toc.h"
Enrico Ros's avatar
Enrico Ros committed
57 58
#include "preferencesdialog.h"
#include "settings.h"
Christophe Devriese's avatar
Christophe Devriese committed
59

60
typedef KParts::GenericFactory<KPDF::Part> KPDFPartFactory;
61
K_EXPORT_COMPONENT_FACTORY(libkpdfpart, KPDFPartFactory)
62 63 64

using namespace KPDF;

65 66
unsigned int Part::m_count = 0;

67 68 69
Part::Part(QWidget *parentWidget, const char *widgetName,
           QObject *parent, const char *name,
           const QStringList & /*args*/ )
70
	: DCOPObject("kpdf"), KParts::ReadOnlyPart(parent, name)
71
{
72 73
	// create browser extension (for printing when embedded into browser)
	new BrowserExtension(this);
Wilco Greven's avatar
Wilco Greven committed
74

75
	// xpdf 'extern' global class (m_count is a static instance counter)
76 77
	//if ( m_count ) TODO check if we need to insert these lines..
	//	delete globalParams;
78
	globalParams = new GlobalParams("");
Albert Astals Cid's avatar
Albert Astals Cid committed
79
	globalParams->setupBaseFonts(NULL);
80
	m_count++;
81

82 83
	// we need an instance
	setInstance(KPDFPartFactory::instance());
84

85
	// build the document
86
	m_document = new KPDFDocument();
87

88 89 90 91
	// widgets: ^searchbar (toolbar containing label and SearchWidget)
//	m_searchToolBar = new KToolBar( parentWidget, "searchBar" );
//	m_searchToolBar->boxLayout()->setSpacing( KDialog::spacingHint() );
//	QLabel * sLabel = new QLabel( i18n( "&Search:" ), m_searchToolBar, "kde toolbar widget" );
92
//	m_searchWidget = new SearchWidget( m_searchToolBar, m_document );
93 94 95
//	sLabel->setBuddy( m_searchWidget );
//	m_searchToolBar->setStretchableWidget( m_searchWidget );

96
	// widgets: [] splitter []
97 98 99
	m_splitter = new QSplitter( parentWidget, widgetName );
	m_splitter->setOpaqueResize( true );
	setWidget( m_splitter );
Albert Astals Cid's avatar
Albert Astals Cid committed
100 101
	m_watchFile = new KToggleAction( i18n( "&Watch File" ), 0, this, SLOT( slotWatchFile() ), actionCollection(), "watch_file" );
	m_watchFile->setChecked( Settings::watchFile() );
102

103
	// widgets: [left toolbox] | []
104 105 106
	m_toolBox = new QToolBox( m_splitter );
	m_toolBox->setMinimumWidth( 60 );
	m_toolBox->setMaximumWidth( 200 );
107

108
	TOC * tocFrame = new TOC( m_toolBox, m_document );
109 110
	m_toolBox->addItem( tocFrame, QIconSet(SmallIcon("text_left")), i18n("Contents") );
	connect(tocFrame, SIGNAL(hasTOC(bool)), this, SLOT(enableTOC(bool)));
111
	enableTOC( false );
112

113
	QVBox * thumbsBox = new ThumbnailsBox( m_toolBox );
114 115
    m_searchWidget = new SearchWidget( thumbsBox, m_document );
    m_thumbnailList = new ThumbnailList( thumbsBox, m_document );
116
	connect( m_thumbnailList, SIGNAL( urlDropped( const KURL& ) ), SLOT( openURL( const KURL & )));
117 118
	m_toolBox->addItem( thumbsBox, QIconSet(SmallIcon("thumbnail")), i18n("Thumbnails") );
	m_toolBox->setCurrentItem( thumbsBox );
119

120
	QFrame * bookmarksFrame = new QFrame( m_toolBox );
121 122
	int iIdx = m_toolBox->addItem( bookmarksFrame, QIconSet(SmallIcon("bookmark")), i18n("Bookmarks") );
	m_toolBox->setItemEnabled( iIdx, false );
123

124
	QFrame * editFrame = new QFrame( m_toolBox );
125 126
	iIdx = m_toolBox->addItem( editFrame, QIconSet(SmallIcon("pencil")), i18n("Annotations") );
	m_toolBox->setItemEnabled( iIdx, false );
127 128

	// widgets: [] | [right 'pageView']
129
	m_pageView = new PageView( m_splitter, m_document );
130
        m_pageView->setFocus(); //usability setting
131 132 133 134
	connect( m_pageView, SIGNAL( urlDropped( const KURL& ) ), SLOT( openURL( const KURL & )));
	//connect(m_pageView, SIGNAL( rightClick() ), this, SIGNAL( rightClick() ));

	// add document observers
135 136 137 138
    m_document->addObserver( this );
	m_document->addObserver( m_thumbnailList );
	m_document->addObserver( m_pageView );
	m_document->addObserver( tocFrame );
139 140 141 142 143

	// ACTIONS
	KActionCollection * ac = actionCollection();

	// Page Traversal actions
144
	m_gotoPage = KStdAction::gotoPage( this, SLOT( slotGoToPage() ), ac, "goto_page" );
145
	m_gotoPage->setShortcut( "CTRL+G" );
146 147 148

	m_prevPage = KStdAction::prior(this, SLOT(slotPreviousPage()), ac, "previous_page");
	m_prevPage->setWhatsThis( i18n( "Moves to the previous page of the document" ) );
149
	m_prevPage->setShortcut( "Backspace" );
150 151 152

	m_nextPage = KStdAction::next(this, SLOT(slotNextPage()), ac, "next_page" );
	m_nextPage->setWhatsThis( i18n( "Moves to the next page of the document" ) );
153
	m_nextPage->setShortcut( "Space" );
154

155
	m_firstPage = KStdAction::firstPage( this, SLOT( slotGotoFirst() ), ac, "first_page" );
156 157
	m_firstPage->setWhatsThis( i18n( "Moves to the first page of the document" ) );

158
	m_lastPage = KStdAction::lastPage( this, SLOT( slotGotoLast() ), ac, "last_page" );
159 160
	m_lastPage->setWhatsThis( i18n( "Moves to the last page of the document" ) );

161 162
	// Find and other actions
	m_find = KStdAction::find( this, SLOT( slotFind() ), ac, "find" );
163 164
	m_find->setEnabled(false);

165
	m_findNext = KStdAction::findNext( this, SLOT( slotFindNext() ), ac, "find_next" );
166 167
	m_findNext->setEnabled(false);

168
	KStdAction::saveAs( this, SLOT( slotSaveFileAs() ), ac, "save" );
Enrico Ros's avatar
Enrico Ros committed
169
    KStdAction::preferences( this, SLOT( slotPreferences() ), ac, "preferences" );
170 171
	KStdAction::printPreview( this, SLOT( slotPrintPreview() ), ac );

172
    // attach the actions of the 2 children widgets too
Enrico Ros's avatar
Enrico Ros committed
173
	m_pageView->setupActions( ac );
174

175
	// apply configuration (both internal settings and GUI configured items)
Enrico Ros's avatar
Enrico Ros committed
176
    m_splitter->setSizes( Settings::splitterSizes() );
177
    slotNewConfig();
178

Albert Astals Cid's avatar
Albert Astals Cid committed
179 180 181 182 183
	m_watcher = new KDirWatch( this );
	connect( m_watcher, SIGNAL( dirty( const QString& ) ), this, SLOT( slotFileDirty( const QString& ) ) );
	m_dirtyHandler = new QTimer( this );
	connect( m_dirtyHandler, SIGNAL( timeout() ),this, SLOT( slotDoFileDirty() ) );

184 185 186
	// set our XML-UI resource file
	setXMLFile("kpdf_part.rc");
	updateActions();
Albert Astals Cid's avatar
Albert Astals Cid committed
187
	slotWatchFile();
188 189
}

190
Part::~Part()
Laurent Montel's avatar
Laurent Montel committed
191
{
192
    // save internal settings
Enrico Ros's avatar
Enrico Ros committed
193
    Settings::setSplitterSizes( m_splitter->sizes() );
194
    // write to disk config file
Enrico Ros's avatar
Enrico Ros committed
195 196
    Settings::writeConfig();

197
    delete m_document;
Enrico Ros's avatar
Enrico Ros committed
198 199
    if ( --m_count == 0 )
        delete globalParams;
Laurent Montel's avatar
Laurent Montel committed
200 201
}

202 203 204 205 206 207
void Part::pageSetCurrent( int, const QRect & )
{
    // document tells that page has changed, so update actions
    updateActions();
}

208 209
void Part::goToPage(uint i)
{
210 211
    if ( i <= m_document->pages() )
        m_document->setCurrentPage( i - 1 );
212 213 214 215 216 217 218 219 220
}

void Part::openDocument(KURL doc)
{
	openURL(doc);
}

uint Part::pages()
{
221
	return m_document->pages();
222 223
}

224
//this don't go anywhere but is required by genericfactory.h
225
KAboutData* Part::createAboutData()
Laurent Montel's avatar
Laurent Montel committed
226
{
227 228 229 230 231 232
	// the non-i18n name here must be the same as the directory in
	// which the part's rc file is installed ('partrcdir' in the
	// Makefile)
	KAboutData* aboutData = new KAboutData("kpdfpart", I18N_NOOP("KPDF::Part"), "0.1");
	aboutData->addAuthor("Wilco Greven", 0, "greven@kde.org");
	return aboutData;
Laurent Montel's avatar
Laurent Montel committed
233 234
}

235
bool Part::openFile()
Laurent Montel's avatar
Laurent Montel committed
236
{
237
	bool ok = m_document->openDocument( m_file );
Albert Astals Cid's avatar
Albert Astals Cid committed
238
	if ( ok && !m_watcher->contains(m_file)) m_watcher->addFile(m_file);
239
	m_find->setEnabled( ok );
240
	return ok;
Laurent Montel's avatar
Laurent Montel committed
241 242
}

243 244
bool Part::openURL(const KURL &url)
{
245 246 247 248 249 250 251 252 253
    bool b = KParts::ReadOnlyPart::openURL(url);
    // if can't open document, update windows so they display blank contents
    if ( !b )
    {
        m_pageView->updateContents();
        m_thumbnailList->updateContents();
        KMessageBox::error( widget(), i18n("Could not open %1").arg(url.prettyURL()) );
    }
    return b;
254 255
}

Albert Astals Cid's avatar
Albert Astals Cid committed
256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293
void
Part::slotWatchFile()
{
  Settings::setWatchFile(m_watchFile->isChecked());
  if( m_watchFile->isChecked() )
    m_watcher->startScan();
  else
  {
    m_dirtyHandler->stop();
    m_watcher->stopScan();
  }
}

  void
Part::slotFileDirty( const QString& fileName )
{
  // The beauty of this is that each start cancels the previous one.
  // This means that timeout() is only fired when there have
  // no changes to the file for the last 750 milisecs.
  // This is supposed to ensure that we don't update on every other byte
  // that gets written to the file.
  if ( fileName == m_file )
  {
    m_dirtyHandler->start( 750, true );
  }
}

  void
Part::slotDoFileDirty()
{
  uint p = m_document->currentPage() + 1;
  if (openFile())
  {
    if (p > m_document->pages()) p = m_document->pages();
    goToPage(p);
  }
}

294
bool Part::closeURL()
295
{
Albert Astals Cid's avatar
Albert Astals Cid committed
296
	if (!m_file.isEmpty()) m_watcher->removeFile(m_file);
297
	m_document->closeDocument();
298
	return KParts::ReadOnlyPart::closeURL();
299
}
Laurent Montel's avatar
Laurent Montel committed
300

301
void Part::updateActions()
302
{
303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320
    if ( m_document->pages() > 0 )
    {
        bool atBegin = m_document->currentPage() < 1;
        bool atEnd = m_document->currentPage() >= (m_document->pages() - 1);
        m_gotoPage->setEnabled( m_document->pages() > 1 );
        m_firstPage->setEnabled( !atBegin );
        m_prevPage->setEnabled( !atBegin );
        m_lastPage->setEnabled( !atEnd );
        m_nextPage->setEnabled( !atEnd );
    }
    else
    {
        m_gotoPage->setEnabled( false );
        m_firstPage->setEnabled( false );
        m_lastPage->setEnabled( false );
        m_prevPage->setEnabled( false );
        m_nextPage->setEnabled( false );
    }
321
}
Laurent Montel's avatar
Laurent Montel committed
322

323 324 325 326 327
void Part::enableTOC(bool enable)
{
	m_toolBox->setItemEnabled(0, enable);
}

328
//BEGIN go to page dialog
329
class KPDFGotoPageDialog : public KDialogBase
Laurent Montel's avatar
Laurent Montel committed
330
{
331 332 333 334
public:
	KPDFGotoPageDialog(QWidget *p, int current, int max) : KDialogBase(p, 0L, true, i18n("Go to Page"), Ok | Cancel, Ok) {
		QWidget *w = new QWidget(this);
		setMainWidget(w);
335

336 337 338 339
		QVBoxLayout *topLayout = new QVBoxLayout( w, 0, spacingHint() );
		e1 = new KIntNumInput(current, w);
		e1->setRange(1, max);
		e1->setEditFocus(true);
340

341 342 343 344 345 346 347 348 349 350 351 352 353 354 355
		QLabel *label = new QLabel( e1,i18n("&Page:"), w );
		topLayout->addWidget(label);
		topLayout->addWidget(e1);
		topLayout->addSpacing(spacingHint()); // A little bit extra space
		topLayout->addStretch(10);
		e1->setFocus();
	}

	int getPage() {
		return e1->value();
	}

  protected:
    KIntNumInput *e1;
};
356
//END go to page dialog
357 358 359

void Part::slotGoToPage()
{
360 361 362
    KPDFGotoPageDialog pageDialog( m_pageView, m_document->currentPage() + 1, m_document->pages() );
    if ( pageDialog.exec() == QDialog::Accepted )
        m_document->setCurrentPage( pageDialog.getPage() - 1 );
363 364
}

365
void Part::slotPreviousPage()
366
{
367 368
    if ( !m_document->currentPage() < 1 )
        m_document->setCurrentPage( m_document->currentPage() - 1 );
369 370
}

371
void Part::slotNextPage()
372
{
373 374
    if ( m_document->currentPage() < (m_document->pages() - 1) )
        m_document->setCurrentPage( m_document->currentPage() + 1 );
375 376
}

377
void Part::slotGotoFirst()
378
{
379
    m_document->setCurrentPage( 0 );
380 381
}

382
void Part::slotGotoLast()
Laurent Montel's avatar
Laurent Montel committed
383
{
384
    m_document->setCurrentPage( m_document->pages() - 1 );
Laurent Montel's avatar
Laurent Montel committed
385 386
}

387
void Part::slotFind()
Laurent Montel's avatar
Laurent Montel committed
388
{
389 390
    KFindDialog dlg( widget() );
    dlg.setHasCursor( false );
Enrico Ros's avatar
Enrico Ros committed
391
#if KDE_IS_VERSION(3,3,90)
392 393 394
    dlg.setSupportsBackwardsFind( false );
    dlg.setSupportsWholeWordsFind( false );
    dlg.setSupportsRegularExpressionFind( false );
Enrico Ros's avatar
Enrico Ros committed
395
#endif
396 397 398 399 400
    if ( dlg.exec() == QDialog::Accepted )
    {
        m_findNext->setEnabled( true );
        m_document->findText( dlg.pattern(), dlg.options() & KFindDialog::CaseSensitive );
    }
401 402
}

403
void Part::slotFindNext()
404
{
405
    m_document->findText();
406 407
}

408
void Part::slotSaveFileAs()
409
{
410 411 412 413 414 415
    KURL saveURL = KFileDialog::getSaveURL( url().isLocalFile() ? url().url() : url().fileName(), QString::null, widget() );
    if ( saveURL.isValid() && !saveURL.isEmpty() )
    {
        if ( !KIO::NetAccess::file_copy( url(), saveURL, -1, true ) )
            KMessageBox::information( 0, i18n("File could not be saved in '%1'. Try to save it to another location.").arg( saveURL.prettyURL() ) );
    }
Albert Astals Cid's avatar
Albert Astals Cid committed
416 417
}

Enrico Ros's avatar
Enrico Ros committed
418
void Part::slotPreferences()
419
{
Enrico Ros's avatar
Enrico Ros committed
420 421 422 423 424 425
    // an instance the dialog could be already created and could be cached,
    // in which case you want to display the cached dialog
    if ( PreferencesDialog::showDialog( "preferences" ) )
        return;

    // we didn't find an instance of this dialog, so lets create it
426
    PreferencesDialog * dialog = new PreferencesDialog( m_pageView, Settings::self() );
Enrico Ros's avatar
Enrico Ros committed
427
    // keep us informed when the user changes settings
428
    connect( dialog, SIGNAL( settingsChanged() ), this, SLOT( slotNewConfig() ) );
Enrico Ros's avatar
Enrico Ros committed
429 430 431 432 433 434

    dialog->show();
}

void Part::slotNewConfig()
{
435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450
    // Apply settings here. A good policy is to check wether the setting has
    // changed before applying changes.

    // Left Panel and search Widget
    bool showLeft = Settings::showLeftPanel();
    if ( m_toolBox->isShown() != showLeft )
    {
        // show/hide left qtoolbox
        m_toolBox->setShown( showLeft );
        // this needs to be hidden explicitly to disable thumbnails gen
        m_thumbnailList->setShown( showLeft );
    }
    bool showSearch = Settings::showSearchBar();
    if ( m_searchWidget->isShown() != showSearch )
        m_searchWidget->setShown( showSearch );

451
    // Main View (pageView)
452 453 454 455 456 457 458
    QScrollView::ScrollBarMode scrollBarMode = Settings::showScrollBars() ?
        QScrollView::AlwaysOn : QScrollView::AlwaysOff;
    if ( m_pageView->hScrollBarMode() != scrollBarMode )
    {
        m_pageView->setHScrollBarMode( scrollBarMode );
        m_pageView->setVScrollBarMode( scrollBarMode );
    }
Enrico Ros's avatar
Enrico Ros committed
459

460 461 462
    // update document settings
    m_document->reparseConfig();

Enrico Ros's avatar
Enrico Ros committed
463 464
    // update Main View and ThumbnailList contents
    // TODO do this only when changing Settings::renderMode()
465
    m_pageView->updateContents();
Enrico Ros's avatar
Enrico Ros committed
466
    if ( showLeft && m_thumbnailList->isShown() )
467
        m_thumbnailList->updateWidgets();
468
}
469

470
void Part::slotPrintPreview()
Wilco Greven's avatar
Wilco Greven committed
471
{
472
    if (m_document->pages() == 0) return;
Wilco Greven's avatar
Wilco Greven committed
473

474 475 476
    double width, height;
    int landscape, portrait;
    KPrinter printer;
Albert Astals Cid's avatar
Albert Astals Cid committed
477
    const KPDFPage *page;
478

479
    printer.setMinMax(1, m_document->pages());
480 481
    printer.setPreviewOnly( true );
    printer.setMargins(0, 0, 0, 0);
482

Albert Astals Cid's avatar
Albert Astals Cid committed
483 484
    // if some pages are landscape and others are not the most common win as kprinter does
    // not accept a per page setting
485 486
    landscape = 0;
    portrait = 0;
487
    for (uint i = 0; i < m_document->pages(); i++)
488
    {
489
        page = m_document->page(i);
Albert Astals Cid's avatar
Albert Astals Cid committed
490 491 492 493 494 495
        width = page->width();
        height = page->height();
        if (page->rotation() == 90 || page->rotation() == 270) qSwap(width, height);
        if (width > height) landscape++;
        else portrait++;
    }
496
    if (landscape > portrait) printer.setOption("orientation-requested", "4");
497

498
    doPrint(printer);
Wilco Greven's avatar
Wilco Greven committed
499 500
}

501
void Part::slotPrint()
502
{
503
    if (m_document->pages() == 0) return;
Albert Astals Cid's avatar
Albert Astals Cid committed
504 505 506 507 508 509 510

    double width, height;
    int landscape, portrait;
    KPrinter printer;
    const KPDFPage *page;

    printer.setPageSelection(KPrinter::ApplicationSide);
511 512
    printer.setMinMax(1, m_document->pages());
    printer.setCurrentPage(m_document->currentPage()+1);
Albert Astals Cid's avatar
Albert Astals Cid committed
513 514 515 516 517 518
    printer.setMargins(0, 0, 0, 0);

    // if some pages are landscape and others are not the most common win as kprinter does
    // not accept a per page setting
    landscape = 0;
    portrait = 0;
519
    for (uint i = 0; i < m_document->pages(); i++)
Albert Astals Cid's avatar
Albert Astals Cid committed
520
    {
521
        page = m_document->page(i);
Albert Astals Cid's avatar
Albert Astals Cid committed
522 523 524 525 526 527 528 529 530
        width = page->width();
        height = page->height();
        if (page->rotation() == 90 || page->rotation() == 270) qSwap(width, height);
        if (width > height) landscape++;
        else portrait++;
    }
    if (landscape > portrait) printer.setOrientation(KPrinter::Landscape);

    if (printer.setup(widget())) doPrint( printer );
531 532
}

Albert Astals Cid's avatar
Albert Astals Cid committed
533
void Part::doPrint(KPrinter &printer)
534
{
535
    if (!m_document->okToPrint())
Albert Astals Cid's avatar
Albert Astals Cid committed
536 537 538 539 540
    {
        KMessageBox::error(widget(), i18n("Printing this document is not allowed."));
        return;
    }

541
    if (!m_document->print(printer))
Albert Astals Cid's avatar
Albert Astals Cid committed
542 543 544
    {
        KMessageBox::error(widget(), i18n("Could not print the document. Please report to bugs.kde.org"));	
    }
545 546
}

547 548 549 550 551 552 553 554
void Part::restoreDocument(const KURL &url, int page)
{
  if (openURL(url)) goToPage(page);
}

void Part::saveDocumentRestoreInfo(KConfig* config)
{
  config->writePathEntry( "URL", url().url() );
555
  if (m_document->pages() > 0) config->writeEntry( "Page", m_document->currentPage() + 1 );
556 557
}

558
/*
559 560 561 562
* BrowserExtension class
*/
BrowserExtension::BrowserExtension(Part* parent)
  : KParts::BrowserExtension( parent, "KPDF::BrowserExtension" )
563
{
564 565 566
	emit enableAction("print", true);
	setURLDropHandlingEnabled(true);
}
567

568 569 570
void BrowserExtension::print()
{
	static_cast<Part*>(parent())->slotPrint();
571 572
}

573
#include "kpdf_part.moc"