Skip to content

Commit

Permalink
harden and fix page number handling.
Browse files Browse the repository at this point in the history
  • Loading branch information
grexe authored and humdingerb committed Aug 14, 2024
1 parent a846a32 commit 3c9eae4
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 15 deletions.
30 changes: 17 additions & 13 deletions bepdf/beos/BepdfApplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

#include <locale/Catalog.h>
#include <be/app/Application.h>
#include <be/storage/Entry.h>
#include <be/storage/FilePanel.h>
#include <be/app/Roster.h>
#include <be/interface/Screen.h>
Expand Down Expand Up @@ -60,7 +61,7 @@ static const char * GPLCopyright =
"\n\n"
"This program is free software under the GNU GPL v2, or any later version.\n";

static const char *PAGE_NUM_MSG = "bepdf:page_num";
static const char *PAGE_NUM_MSG_KEY = "bepdf:page_num";

static const char *settingsFilename = "BePDF";

Expand Down Expand Up @@ -528,42 +529,45 @@ bool BepdfApplication::QuitRequested() {
/*
Opens everything.
*/
void BepdfApplication::RefsReceived ( BMessage * msg )
void BepdfApplication::RefsReceived(BMessage *msg)
{
uint32 type;
int32 count;
int32 i;
entry_ref ref;

mReadyToQuit = false;
status_t result;

msg->GetInfo ( "refs", &type, &count );
if ( type != B_REF_TYPE ) {
return;
}
msg->GetInfo("refs", &type, &count);

if (type != B_REF_TYPE) {
BAlert *error = new BAlert(B_TRANSLATE("Error"), B_TRANSLATE("Invalid file reference received!"), B_TRANSLATE("Close"), NULL, NULL, B_WIDTH_AS_USUAL, B_WARNING_ALERT);
error->Go();

return;
}

BString ownerPassword, userPassword;
const char *owner = NULL;
const char *user = NULL;
int32 pageNum = 0;
entry_ref ref;

if (B_OK == msg->FindString("ownerPassword", &ownerPassword)) {
owner = ownerPassword.String();
}
if (B_OK == msg->FindString("userPassword", &userPassword)) {
user = userPassword.String();
}
status_t result = msg->FindInt32(PAGE_NUM_MSG, &pageNum);
result = msg->FindInt32(PAGE_NUM_MSG_KEY, &pageNum);
if (result != B_OK) {
if (result != B_NAME_NOT_FOUND) {
BAlert *error = new BAlert(B_TRANSLATE("Error"), B_TRANSLATE("BePDF: Error getting page number!"), B_TRANSLATE("Close"), NULL, NULL, B_WIDTH_AS_USUAL, B_WARNING_ALERT);
BAlert *error = new BAlert(B_TRANSLATE("Error"), B_TRANSLATE("Error getting page number!"), B_TRANSLATE("Close"), NULL, NULL, B_WIDTH_AS_USUAL, B_WARNING_ALERT);
error->Go();
}
}

Initialize();

for ( i = --count ; i >= 0; i-- ) {
for (int32 i = --count ; i >= 0; i-- ) {
if ( msg->FindRef("refs", i, &ref ) == B_OK ) {
/*
Open the document...
Expand Down Expand Up @@ -688,7 +692,7 @@ BepdfApplication::ArgvReceived (int32 argc, char **argv)
// fprintf(errFile, "%s%s\n", pdfViewerCopyright, GPLCopyright);

BMessage msg(B_REFS_RECEIVED);
msg.AddInt32 (PAGE_NUM_MSG, pg);
msg.AddInt32 (PAGE_NUM_MSG_KEY, pg);
get_ref_for_path (argvCopy[1], &fileToOpen);
msg.AddRef ("refs", &fileToOpen);
PostMessage (&msg);
Expand Down
6 changes: 5 additions & 1 deletion bepdf/beos/PDFWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -973,8 +973,12 @@ PDFWindow::SetZoomSize(float w, float h)
///////////////////////////////////////////////////////////
// update page list and page number item
void
PDFWindow::SetPage(int16 page) {
PDFWindow::SetPage(int32 page) {
char pageStr [64];
if (page <= 0) page = 1;
if (page > mPagesView->CountItems()) {
page = mPagesView->CountItems();
}
snprintf (pageStr, sizeof (pageStr), "%d", page);
mPageNumberItem->SetText (pageStr);
mPagesView->Select(page-1);
Expand Down
2 changes: 1 addition & 1 deletion bepdf/beos/PDFWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ class PDFWindow
void SetZoomSize (float w, float h);
void SetZoom(int16 zoom);
void SetRotation(float rotation);
void SetPage(int16 page);
void SetPage(int32 page);

static void OpenPDF(const char* file);
static bool OpenPDFHelp(const char* name);
Expand Down

0 comments on commit 3c9eae4

Please sign in to comment.