Skip to content

Commit

Permalink
fix handling of encryption wrt errors opening PDF file. (#119)
Browse files Browse the repository at this point in the history
* fix handling of encryption wrt errors opening PDF file.
* open file panel only when there is no open window yet.
  • Loading branch information
grexe authored Aug 28, 2024
1 parent faed874 commit df2c8a3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
11 changes: 7 additions & 4 deletions bepdf/beos/BepdfApplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,7 @@ void BepdfApplication::RefsReceived(BMessage *msg)
BRect rect(mSettings->GetWindowRect());
bool ok;
bool encrypted = false;

if (mWindow == NULL) {
win = new PDFWindow(&ref, rect, owner, user, &encrypted);
ok = win->IsOk();
Expand All @@ -591,13 +592,15 @@ void BepdfApplication::RefsReceived(BMessage *msg)
if (!encrypted) {
BAlert *error = new BAlert(B_TRANSLATE("Error"), B_TRANSLATE("BePDF: Error opening file!"), B_TRANSLATE("Close"), NULL, NULL, B_WIDTH_AS_USUAL, B_STOP_ALERT);
error->Go();
}

if (mWindow == NULL) { // fixme: always true even if a PDF window is already open!
OpenFilePanel();
}
} else {
new PasswordWindow(&ref, rect, this);
}
if (mWindow == NULL) delete win;

if (encrypted) {
new PasswordWindow(&ref, rect, this);
}
} else if (mWindow == NULL) {
mWindow = win;
win->Show();
Expand Down
10 changes: 5 additions & 5 deletions bepdf/beos/PDFView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,9 @@ PDFView::MakeTitleString(BPath* path) {
bool
PDFView::OpenFile(entry_ref *ref, const char *ownerPassword, const char *userPassword, bool *encrypted) {
BEntry entry (ref, true);
if (!entry.Exists()) {
return false;
}
BPath path;
entry.GetPath (&path);

Expand All @@ -245,11 +248,8 @@ PDFView::OpenFile(entry_ref *ref, const char *ownerPassword, const char *userPas
UpdatePanelDirectory(&path);

bool ok = newDoc->isOk();
// xpdf 3.01 returns false even PDF file is password protected?!?
*encrypted = true; // newDoc->isEncrypted();
// fprintf(stderr, "ok %s encrypted %s\n",
// ok ? "yes" : "no",
// (*encrypted) ? "yes" : "no");
*encrypted = newDoc->isEncrypted();

if (ok) {
delete mDoc;
mDoc = newDoc;
Expand Down

0 comments on commit df2c8a3

Please sign in to comment.