Give a warning when the opened file does not exist

Remove the recent file if the user opens it and it does not exists

svn path=/branches/kpdf_experiments/kdegraphics/kpdf/; revision=347427
This commit is contained in:
Albert Astals Cid 2004-09-18 16:41:23 +00:00
parent b9db06f874
commit 40e5c5e0fe
4 changed files with 29 additions and 19 deletions

View file

@ -68,7 +68,7 @@ Part::Part(QWidget *parentWidget, const char *widgetName,
// create browser extension (for printing when embedded into browser)
new BrowserExtension(this);
// xpdf 'extern' global class (m_count is a static instance counter)
// xpdf 'extern' global class (m_count is a static instance counter)
//if ( m_count ) TODO check if we need to insert these lines..
// delete globalParams;
globalParams = new GlobalParams("");
@ -179,6 +179,13 @@ bool Part::openFile()
return ok;
}
bool Part::openURL(const KURL &url)
{
bool b = KParts::ReadOnlyPart::openURL(url);
if (!b) KMessageBox::error(widget(), i18n("Could not open %1").arg(url.prettyURL()));
return b;
}
bool Part::closeURL()
{
document->closeDocument();
@ -205,19 +212,19 @@ void Part::updateActions()
}
}
//BEGIN go to page dialog
//BEGIN go to page dialog
class KPDFGotoPageDialog : public KDialogBase
{
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);
QVBoxLayout *topLayout = new QVBoxLayout( w, 0, spacingHint() );
e1 = new KIntNumInput(current, w);
e1->setRange(1, max);
e1->setEditFocus(true);
QLabel *label = new QLabel( e1,i18n("&Page:"), w );
topLayout->addWidget(label);
topLayout->addWidget(e1);
@ -233,7 +240,7 @@ public:
protected:
KIntNumInput *e1;
};
//END go to page dialog
//END go to page dialog
void Part::slotGoToPage()
{
@ -439,12 +446,12 @@ void Part::slotPrint()
double width, height;
int landscape, portrait;
KPrinter printer;
printer.setPageSelection(KPrinter::ApplicationSide);
printer.setMinMax(1, m_doc->getNumPages());
printer.setCurrentPage(m_currentPage);
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;
@ -458,7 +465,7 @@ void Part::slotPrint()
else portrait++;
}
if (landscape > portrait) printer.setOrientation(KPrinter::Landscape);
if (printer.setup(widget()))
{
doPrint( printer );
@ -475,11 +482,11 @@ void Part::slotPrintPreview()
double width, height;
int landscape, portrait;
KPrinter printer;
printer.setMinMax(1, m_doc->getNumPages());
printer.setPreviewOnly( true );
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;
@ -493,7 +500,7 @@ void Part::slotPrintPreview()
else portrait++;
}
if (landscape > portrait) printer.setOption("orientation-requested", "4");
doPrint(printer);
*/
}
@ -507,7 +514,7 @@ void Part::doPrint( KPrinter& /*printer*/ )
QOutputDevKPrinter printdev( painter, paperColor, printer );
printdev.startDoc(m_doc->getXRef());
QValueList<int> pages = printer.pageList();
for ( QValueList<int>::ConstIterator i = pages.begin(); i != pages.end();)
{
m_docMutex.lock();
@ -520,7 +527,7 @@ void Part::doPrint( KPrinter& /*printer*/ )
}
/*
/*
* BrowserExtension class
*/
BrowserExtension::BrowserExtension(Part* parent)

View file

@ -75,6 +75,8 @@ namespace KPDF
protected:
// reimplemented from KParts::ReadOnlyPart
virtual bool openFile();
// reimplemented from KParts::ReadOnlyPart
virtual bool openURL(const KURL &url);
void updateAction();
void doPrint( KPrinter& printer );
@ -95,7 +97,7 @@ namespace KPDF
public slots:
// connected to Shell action (and browserExtension), not local one
void slotPrint();
void slotPrint();
private:
// the document

View file

@ -88,13 +88,14 @@ Shell::~Shell()
void Shell::openURL( const KURL & url )
{
if ( m_part && m_part->openURL( url ) ) recent->addURL (url);
if ( m_part && m_part->openURL( url ) ) m_recent->addURL (url);
else m_recent->removeURL(url);
}
void Shell::readSettings()
{
recent->loadEntries( KGlobal::config() );
m_recent->loadEntries( KGlobal::config() );
KGlobal::config()->setDesktopGroup();
bool fullScreen = KGlobal::config()->readBoolEntry( "FullScreen", false );
setFullScreen( fullScreen );
@ -103,7 +104,7 @@ void Shell::readSettings()
void Shell::writeSettings()
{
saveMainWindowSettings(KGlobal::config(), "MainWindow");
recent->saveEntries( KGlobal::config() );
m_recent->saveEntries( KGlobal::config() );
KGlobal::config()->setDesktopGroup();
KGlobal::config()->writeEntry( "FullScreen", m_fullScreenAction->isChecked());
KGlobal::config()->sync();
@ -113,7 +114,7 @@ void Shell::writeSettings()
Shell::setupActions()
{
KStdAction::open(this, SLOT(fileOpen()), actionCollection());
recent = KStdAction::openRecent( this, SLOT( openURL( const KURL& ) ),
m_recent = KStdAction::openRecent( this, SLOT( openURL( const KURL& ) ),
actionCollection() );
KStdAction::print(m_part, SLOT(slotPrint()), actionCollection());
KStdAction::quit(this, SLOT(slotQuit()), actionCollection());

View file

@ -85,7 +85,7 @@ namespace KPDF
private:
KParts::ReadOnlyPart* m_part;
KRecentFilesAction* recent;
KRecentFilesAction* m_recent;
KToggleAction* m_fullScreenAction;
bool m_isFullScreen;
KPopupMenu* m_popup;