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

fixes #116 and jumps to page if provided via argument. #117

Merged
merged 2 commits into from
Aug 14, 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
41 changes: 30 additions & 11 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,33 +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();
}
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("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 @@ -589,6 +602,12 @@ void BepdfApplication::RefsReceived ( BMessage * msg )
mWindow = win;
win->Show();
}
// jump to page if provided
if (pageNum != 0) {
mWindow->LockLooper();
mWindow->SetPage(pageNum);
mWindow->UnlockLooper();
}
// stop after first document
mGotSomething = true;
break;
Expand Down Expand Up @@ -673,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