PackageInstaller: Cleanup and code simplification
This commit is contained in:
@@ -21,32 +21,37 @@
|
|||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
|
|
||||||
#undef B_TRANSLATION_CONTEXT
|
#undef B_TRANSLATION_CONTEXT
|
||||||
#define B_TRANSLATION_CONTEXT "Packageinstaller main"
|
#define B_TRANSLATION_CONTEXT "Packageinstaller main"
|
||||||
|
|
||||||
|
|
||||||
class PackageInstaller : public BApplication {
|
class PackageInstaller : public BApplication {
|
||||||
public:
|
public:
|
||||||
PackageInstaller();
|
PackageInstaller();
|
||||||
~PackageInstaller();
|
virtual ~PackageInstaller();
|
||||||
|
|
||||||
void RefsReceived(BMessage *msg);
|
virtual void RefsReceived(BMessage* message);
|
||||||
void ArgvReceived(int32 argc, char **argv);
|
virtual void ArgvReceived(int32 argc, char** argv);
|
||||||
void ReadyToRun();
|
virtual void ReadyToRun();
|
||||||
|
|
||||||
void MessageReceived(BMessage *msg);
|
virtual void MessageReceived(BMessage* message);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
BFilePanel *fOpen;
|
void _NewWindow(const entry_ref* ref);
|
||||||
|
|
||||||
|
private:
|
||||||
|
BFilePanel* fOpenPanel;
|
||||||
uint32 fWindowCount;
|
uint32 fWindowCount;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
PackageInstaller::PackageInstaller()
|
PackageInstaller::PackageInstaller()
|
||||||
: BApplication("application/x-vnd.Haiku-PackageInstaller"),
|
:
|
||||||
fOpen(NULL),
|
BApplication("application/x-vnd.Haiku-PackageInstaller"),
|
||||||
|
fOpenPanel(new BFilePanel(B_OPEN_PANEL)),
|
||||||
fWindowCount(0)
|
fWindowCount(0)
|
||||||
{
|
{
|
||||||
fOpen = new BFilePanel(B_OPEN_PANEL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -60,84 +65,72 @@ PackageInstaller::ReadyToRun()
|
|||||||
{
|
{
|
||||||
// We're ready to run - if no windows are yet visible, this means that
|
// We're ready to run - if no windows are yet visible, this means that
|
||||||
// we should show a open panel
|
// we should show a open panel
|
||||||
if (fWindowCount == 0) {
|
if (fWindowCount == 0)
|
||||||
fOpen->Show();
|
fOpenPanel->Show();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
PackageInstaller::RefsReceived(BMessage *msg)
|
PackageInstaller::RefsReceived(BMessage* message)
|
||||||
{
|
{
|
||||||
uint32 type;
|
|
||||||
int32 i, count;
|
|
||||||
status_t ret = msg->GetInfo("refs", &type, &count);
|
|
||||||
if (ret != B_OK || type != B_REF_TYPE)
|
|
||||||
return;
|
|
||||||
|
|
||||||
entry_ref ref;
|
entry_ref ref;
|
||||||
PackageWindow *iter;
|
for (int32 i = 0; message->FindRef("refs", i, &ref) == B_OK; i++)
|
||||||
for (i = 0; i < count; i++) {
|
_NewWindow(&ref);
|
||||||
if (msg->FindRef("refs", i, &ref) == B_OK) {
|
|
||||||
iter = new PackageWindow(&ref);
|
|
||||||
fWindowCount++;
|
|
||||||
iter->Show();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
PackageInstaller::ArgvReceived(int32 argc, char **argv)
|
PackageInstaller::ArgvReceived(int32 argc, char** argv)
|
||||||
{
|
{
|
||||||
int i;
|
for (int i = 1; i < argc; i++) {
|
||||||
BPath path;
|
BPath path;
|
||||||
entry_ref ref;
|
|
||||||
status_t ret = B_OK;
|
|
||||||
PackageWindow *iter = 0;
|
|
||||||
|
|
||||||
for (i = 1; i < argc; i++) {
|
|
||||||
if (path.SetTo(argv[i]) != B_OK) {
|
if (path.SetTo(argv[i]) != B_OK) {
|
||||||
fprintf(stderr,
|
fprintf(stderr, B_TRANSLATE("Error! \"%s\" is not a valid path.\n"),
|
||||||
B_TRANSLATE("Error! \"%s\" is not a valid path.\n"),
|
|
||||||
argv[i]);
|
argv[i]);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = get_ref_for_path(path.Path(), &ref);
|
entry_ref ref;
|
||||||
|
status_t ret = get_ref_for_path(path.Path(), &ref);
|
||||||
if (ret != B_OK) {
|
if (ret != B_OK) {
|
||||||
fprintf(stderr,
|
fprintf(stderr, B_TRANSLATE("Error (%s)! Could not open \"%s\".\n"),
|
||||||
B_TRANSLATE("Error (%s)! Could not open \"%s\".\n"),
|
|
||||||
strerror(ret), argv[i]);
|
strerror(ret), argv[i]);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
iter = new PackageWindow(&ref);
|
_NewWindow(&ref);
|
||||||
fWindowCount++;
|
|
||||||
iter->Show();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
PackageInstaller::MessageReceived(BMessage *msg)
|
PackageInstaller::MessageReceived(BMessage* message)
|
||||||
{
|
{
|
||||||
switch (msg->what) {
|
switch (message->what) {
|
||||||
case P_WINDOW_QUIT:
|
case P_WINDOW_QUIT:
|
||||||
fWindowCount--;
|
fWindowCount--;
|
||||||
|
// fall through
|
||||||
case B_CANCEL:
|
case B_CANCEL:
|
||||||
if (fWindowCount == 0) {
|
if (fWindowCount == 0)
|
||||||
BAutolock lock(this);
|
PostMessage(B_QUIT_REQUESTED);
|
||||||
if (lock.IsLocked())
|
|
||||||
Quit();
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
BApplication::MessageReceived(msg);
|
BApplication::MessageReceived(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
PackageInstaller::_NewWindow(const entry_ref* ref)
|
||||||
|
{
|
||||||
|
PackageWindow* window = new PackageWindow(ref);
|
||||||
|
window->Show();
|
||||||
|
|
||||||
|
fWindowCount++;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
main(void)
|
main(void)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user