Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix handling of encryption wrt errors opening PDF file. #119

Merged
merged 7 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 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,22 +592,24 @@ 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();
}
// jump to page if provided
if (pageNum != 0) {
mWindow->LockLooper();
mWindow->SetPage(pageNum);
mWindow->UnlockLooper();
BMessage goToPageMsg(PDFWindow::GOTO_PAGE_CMD);
goToPageMsg.AddInt32("page", pageNum);
mWindow->MessageReceived(&goToPageMsg);
}
// stop after first document
mGotSomething = true;
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
39 changes: 24 additions & 15 deletions bepdf/beos/PDFWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1069,22 +1069,31 @@ PDFWindow::MessageReceived(BMessage* message)
mMainView->MoveToPage (mMainView->GetNumPages());
break;
case GOTO_PAGE_CMD: {
status_t err;
BTextControl * control;
BControl * ptr;

err = message->FindPointer ("source", (void **)&ptr);
control = dynamic_cast <BTextControl *> (ptr);
if (err == B_OK && control != NULL) {
const char *txt = control->Text ();
page = atoi (txt);
mMainView->MoveToPage (page);
mMainView->MakeFocus();
} else {
/* ERROR */
}
}
status_t result;
BTextControl * control;
BControl * ptr;

result = message->FindPointer ("source", (void **)&ptr);
if (result == B_OK) {
control = dynamic_cast <BTextControl *> (ptr);
if (result == B_OK && control != NULL) {
const char *txt = control->Text ();
page = atoi (txt);
}
} else { // may come from external source over page parameter
result = message->FindInt32("page", &page);
if (result == B_OK)
mMainView->WaitForPage();
}

if (result == B_OK) {
LockLooper();
mMainView->MoveToPage (page);
UnlockLooper();
mMainView->MakeFocus();
}
break;
}
case PAGE_SELECTED_CMD:
page = mPagesView->CurrentSelection(0) + 1;
mMainView->MoveToPage(page);
Expand Down
Loading