2003-08-02 20:04:53 +00:00
|
|
|
/*****************************************************************************/
|
|
|
|
|
// ShowImageApp
|
2003-11-06 20:57:04 +00:00
|
|
|
// Written by Fernando Francisco de Oliveira, Michael Wilber, Michael Pfeiffer
|
2003-08-02 20:04:53 +00:00
|
|
|
//
|
|
|
|
|
// ShowImageApp.cpp
|
|
|
|
|
//
|
|
|
|
|
//
|
|
|
|
|
// Copyright (c) 2003 OpenBeOS Project
|
|
|
|
|
//
|
|
|
|
|
// Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
|
// copy of this software and associated documentation files (the "Software"),
|
|
|
|
|
// to deal in the Software without restriction, including without limitation
|
|
|
|
|
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
|
// and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
|
// Software is furnished to do so, subject to the following conditions:
|
|
|
|
|
//
|
|
|
|
|
// The above copyright notice and this permission notice shall be included
|
|
|
|
|
// in all copies or substantial portions of the Software.
|
|
|
|
|
//
|
|
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
|
|
|
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
|
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
|
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
|
|
|
// DEALINGS IN THE SOFTWARE.
|
|
|
|
|
/*****************************************************************************/
|
2002-07-22 23:59:33 +00:00
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <Alert.h>
|
|
|
|
|
#include <FilePanel.h>
|
|
|
|
|
|
|
|
|
|
#include "ShowImageConstants.h"
|
|
|
|
|
#include "ShowImageApp.h"
|
|
|
|
|
#include "ShowImageWindow.h"
|
|
|
|
|
|
2003-08-02 20:04:53 +00:00
|
|
|
int main(int, char **)
|
2002-07-22 23:59:33 +00:00
|
|
|
{
|
|
|
|
|
ShowImageApp theApp;
|
|
|
|
|
theApp.Run();
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2003-08-02 16:53:13 +00:00
|
|
|
#define WINDOWS_TO_IGNORE 1
|
|
|
|
|
|
2002-07-22 23:59:33 +00:00
|
|
|
ShowImageApp::ShowImageApp()
|
2003-08-02 16:53:13 +00:00
|
|
|
: BApplication(APP_SIG)
|
|
|
|
|
{
|
2003-11-04 23:22:01 +00:00
|
|
|
fbPulseStarted = false;
|
|
|
|
|
fpOpenPanel = new BFilePanel(B_OPEN_PANEL);
|
2003-08-02 16:53:13 +00:00
|
|
|
}
|
2002-07-22 23:59:33 +00:00
|
|
|
|
2003-08-02 20:04:53 +00:00
|
|
|
void
|
|
|
|
|
ShowImageApp::AboutRequested()
|
2002-07-22 23:59:33 +00:00
|
|
|
{
|
2003-08-02 16:53:13 +00:00
|
|
|
BAlert* pAlert = new BAlert("About ShowImage",
|
2003-11-06 20:57:04 +00:00
|
|
|
"OBOS ShowImage\n\nby Fernando F. Oliveira, Michael Wilber and Michael Pfeiffer", "OK");
|
2002-07-22 23:59:33 +00:00
|
|
|
pAlert->Go();
|
|
|
|
|
}
|
|
|
|
|
|
2003-08-02 20:04:53 +00:00
|
|
|
void
|
|
|
|
|
ShowImageApp::ReadyToRun()
|
2002-07-22 23:59:33 +00:00
|
|
|
{
|
2003-08-02 16:53:13 +00:00
|
|
|
if (CountWindows() == WINDOWS_TO_IGNORE)
|
2003-11-04 23:22:01 +00:00
|
|
|
fpOpenPanel->Show();
|
2003-08-02 16:53:13 +00:00
|
|
|
else
|
|
|
|
|
// If image windows are already open
|
|
|
|
|
// (paths supplied on the command line)
|
|
|
|
|
// start checking the number of open windows
|
|
|
|
|
StartPulse();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
ShowImageApp::StartPulse()
|
|
|
|
|
{
|
2003-11-04 23:22:01 +00:00
|
|
|
if (!fbPulseStarted) {
|
2003-08-02 16:53:13 +00:00
|
|
|
// Tell the app to begin checking
|
|
|
|
|
// for the number of open windows
|
2003-11-04 23:22:01 +00:00
|
|
|
fbPulseStarted = true;
|
2003-08-02 16:53:13 +00:00
|
|
|
SetPulseRate(250000);
|
|
|
|
|
// Set pulse to every 1/4 second
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
ShowImageApp::Pulse()
|
|
|
|
|
{
|
|
|
|
|
if (!IsLaunching() && CountWindows() <= WINDOWS_TO_IGNORE)
|
|
|
|
|
// If the application is not launching and
|
|
|
|
|
// all windows are closed except for the file open panel,
|
|
|
|
|
// quit the application
|
|
|
|
|
PostMessage(B_QUIT_REQUESTED);
|
2002-07-22 23:59:33 +00:00
|
|
|
}
|
|
|
|
|
|
2003-08-02 20:04:53 +00:00
|
|
|
void
|
|
|
|
|
ShowImageApp::ArgvReceived(int32 argc, char **argv)
|
2002-07-22 23:59:33 +00:00
|
|
|
{
|
2003-08-02 20:04:53 +00:00
|
|
|
BMessage *pmsg = NULL;
|
|
|
|
|
for (int32 i = 1; i < argc; i++) {
|
2002-07-22 23:59:33 +00:00
|
|
|
entry_ref ref;
|
|
|
|
|
status_t err = get_ref_for_path(argv[i], &ref);
|
|
|
|
|
if (err == B_OK) {
|
2003-08-02 20:04:53 +00:00
|
|
|
if (!pmsg) {
|
|
|
|
|
pmsg = new BMessage;
|
|
|
|
|
pmsg->what = B_REFS_RECEIVED;
|
2002-07-22 23:59:33 +00:00
|
|
|
}
|
2003-08-02 20:04:53 +00:00
|
|
|
pmsg->AddRef("refs", &ref);
|
2002-07-22 23:59:33 +00:00
|
|
|
}
|
|
|
|
|
}
|
2003-08-02 20:04:53 +00:00
|
|
|
if (pmsg)
|
|
|
|
|
RefsReceived(pmsg);
|
2002-07-22 23:59:33 +00:00
|
|
|
}
|
|
|
|
|
|
2003-08-02 20:04:53 +00:00
|
|
|
void
|
|
|
|
|
ShowImageApp::MessageReceived(BMessage *pmsg)
|
2002-07-22 23:59:33 +00:00
|
|
|
{
|
2003-08-02 20:04:53 +00:00
|
|
|
switch (pmsg->what) {
|
2003-08-02 16:53:13 +00:00
|
|
|
case MSG_FILE_OPEN:
|
2003-11-04 23:22:01 +00:00
|
|
|
fpOpenPanel->Show();
|
2003-08-02 16:53:13 +00:00
|
|
|
break;
|
2003-08-02 20:04:53 +00:00
|
|
|
|
2003-08-02 16:53:13 +00:00
|
|
|
case MSG_WINDOW_QUIT:
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case B_CANCEL:
|
|
|
|
|
// File open panel was closed,
|
|
|
|
|
// start checking count of open windows
|
|
|
|
|
StartPulse();
|
|
|
|
|
break;
|
2002-07-22 23:59:33 +00:00
|
|
|
|
2003-08-02 16:53:13 +00:00
|
|
|
default:
|
2003-08-02 20:04:53 +00:00
|
|
|
BApplication::MessageReceived(pmsg);
|
2003-08-02 16:53:13 +00:00
|
|
|
break;
|
|
|
|
|
}
|
2002-07-22 23:59:33 +00:00
|
|
|
}
|
|
|
|
|
|
2003-08-02 20:04:53 +00:00
|
|
|
void
|
|
|
|
|
ShowImageApp::RefsReceived(BMessage *pmsg)
|
2002-07-22 23:59:33 +00:00
|
|
|
{
|
|
|
|
|
uint32 type;
|
|
|
|
|
int32 count;
|
2003-08-02 20:04:53 +00:00
|
|
|
status_t ret = pmsg->GetInfo("refs", &type, &count);
|
|
|
|
|
if (ret != B_OK || type != B_REF_TYPE)
|
2002-07-22 23:59:33 +00:00
|
|
|
return;
|
2003-08-02 20:04:53 +00:00
|
|
|
|
|
|
|
|
entry_ref ref;
|
|
|
|
|
for (int32 i = 0; i < count; i++) {
|
|
|
|
|
if (pmsg->FindRef("refs", i, &ref) == B_OK)
|
2002-07-22 23:59:33 +00:00
|
|
|
Open(&ref);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2003-08-02 20:04:53 +00:00
|
|
|
void
|
|
|
|
|
ShowImageApp::Open(const entry_ref *pref)
|
2002-07-22 23:59:33 +00:00
|
|
|
{
|
2003-08-03 02:28:18 +00:00
|
|
|
new ShowImageWindow(pref);
|
2002-07-22 23:59:33 +00:00
|
|
|
}
|